Description:
Ad Manager - Control Panel. See the install instructions in the code to set up the database then click on "help" once you get it up.
You will need the adman_showads box to complete this feature.
Box Code:
# ============================================================
# INSTALL INSTRUCTIONS
# ============================================================
#
# ------------------------------------------------------------
# STEP 1: Create Database Schema
# ------------------------------------------------------------
#
# CREATE TABLE adman_positions (
# adman_position_id int not null auto_increment primary key,
# name varchar(20) not null
#);
# CREATE TABLE adman_content (
# adman_content_id int not null auto_increment primary key,
# name varchar(20),
# content_reg text,
# content_anon text
#);
#
# CREATE TABLE adman_position_content (
# id int not null auto_increment primary key,
# adman_position_id int not null,
# adman_content_id int not null,
# impressions bigint not null default 0,
# enabled tinyint not null default 1,
# last_seen datetime
#);
#
# CREATE INDEX idx_adman_pc on adman_position_content (adman_position_id,adman_content_id);
# INSERT INTO ops (op, template, func, is_box, enabled) VALUES('adman_admin', 'default_template', 'adman_admin', 1, 1);
# INSERT INTO admin_tools VALUES('adman_admin', 40, 'Ad Manager', 'Ad Manager', 'ad_admin', 'adman_admin', 1);
my $help=q{
============================================================
ABOUT
============================================================
Project Name: Adman, your friendly scoop ad manager
Author: Cory R. King - coryking@photographica.org
============================================================
INTRODUCTION
============================================================
Ad Manager (adman) is an attempt to help manage all the
different ad slots, or positions, on your scoop site.
Adman allows you to have chunks of content that you can call
from a box. You can also rotate through many chunks on the
same position. For now, Adman keeps a count of the number
of impressions each position recives.
One interesting feature provided by adman is the ability to
deliver a different chunk of content for anonymous users
then you deliver for registered users.
Through experimentation with adsense, the original author of
Adman found that his registered users rarely clicked on any
ads. Most of the revenue generated was through anonymous
clicks. Using Adman, he can now target a different set
of ads that registered users will hopefully click on.
============================================================
USING ADMAN ON YOUR WEBSITE
============================================================
Adman has been designed to be __somewhat__ easy to use.
While we feel your pain, this program is designed to be
more of a quick hack then a full fledged ad management system.
Don't scare yourself though, adman is pretty slick!
Hopefully this documentation will help you plow into the
wonderful world of advertising. May you make much moola!
------------------------------------------------------------
Creating an ad position.
------------------------------------------------------------
An ad position is a slot in which to place one or more
chunks of content. You can create as many positions are you
require for your website; for example you can create a
position for your left nav column, and one for your footer.
To create a position:
1) goto http://"yoursite"/adman_admin
2) click "add new position"
3) type a name for your position ("left_column") and click "add"
4) add content using one of the methods outlined below
------------------------------------------------------------
Creating content
------------------------------------------------------------
Content is what fills positions on your website. You can
have many content chunks per position, and you have a chunk
of content used in many positions.
To create new content:
1) You must first create at least one ad position
2) Next to the position you want, click
"Add new content."
3) Give the content a unique name, and add the raw HTML
you want to use for the ad. For more info on anonymous
vs registered user content, see the introduction
To add content to a position:
1) You must first create at least one ad position
2) You must have at least one chunks of content
3) Next to the position you want, click
"Add Existing Content."
4) Pick the content you want to add and click "Add"
------------------------------------------------------------
Creating rotating content
------------------------------------------------------------
You can rotate through muplitple chunks of content on a
given position. You can set this rotation up by using a
combination of the methods for creating content.
The system will automatically rotate through the content.
------------------------------------------------------------
Adding positions to your website
------------------------------------------------------------
You can add many positions to any block. The box that
inserts the HTML does not do anything to the content
chunk you want added.
To add a position to a block:
1) You must remember the name you gave the position
2) In the block tool, load the block you wish to edit
3) In the location you want the content chunk add the
following:
|BOX,adman_showads,"position_name"|
4) Replace "position_name" with the name of your position.
5) Save the box and enjoy!
};
my $content = "<h1>Your Friendly Ad Manager</h1>";
my $action = $S->{CGI}->param('action') || 'main';
return "You need the ad_admin permission to use this box" unless($S->have_perm('ad_admin'));
# ===========================================
# Default Action (also the last in the list)
# ===========================================
if($action eq 'help')
{
return "$content<pre>$help</pre><a href='$S->{UI}->{VARS}->{site_url}/adman_admin'>Return</a> ";
}
$content .= "<a href='?action=help'>Help</a><p>";
if($action eq 'addposition')
{
if($S->{CGI}->param('name'))
{
my $qn=$S->{DBH}->quote($S->{CGI}->param('name'));
$S->db_insert({
INTO=>'adman_positions',
COLS=>'name',
VALUES=>$qn
});
# jump back to the main screen
$action='main';
} else {
$content .= qq(
<form action='$S->{UI}->{VARS}->{site_url}/adman_admin/' method='post'>
<input type='hidden' name='action' value='addposition'>
Pick a name, any name: <input type='text' value='' name='name'> <input type='submit' value='Add' name='go'>
</form>
);
}
}
if($action eq 'addoldcontent')
{
my $pos_id=$S->{CGI}->param('ad_position_id');
if($S->{CGI}->param('ad_content_id'))
{
my $new_id=$S->{CGI}->param('ad_content_id');
# now link this up with our position
$S->db_insert({
INTO=>'adman_position_content',
COLS=>'adman_position_id, adman_content_id',
VALUES=>"$pos_id, $new_id",
});
$action = 'main';
} else {
my ($rv, $sth) = $S->db_select({
WHAT=>'adman_content_id, name',
FROM=>'adman_content',
ORDER_BY=>'name'
});
$content .= qq(
<form action='$S->{UI}->{VARS}->{site_url}/adman_admin/' method='post'>
<input type='hidden' name='action' value='addoldcontent'>
<input type='hidden' name='ad_position_id' value='$pos_id'>
Pick an ad: <select name='ad_content_id'>
);
while(my $ad = $sth->fetchrow_hashref())
{
$content .= qq(<option value='$$ad{adman_content_id}'>$$ad{name}</option>);
}
$content .= "</select><input name='go' value='Add me!!' type='submit'></form>";
}
}
if($action eq 'addnewcontent')
{
my $pos_id=$S->{CGI}->param('ad_position_id');
if($S->{CGI}->param('name'))
{
my $qn=$S->{DBH}->quote($S->{CGI}->param('name'));
my $qa=$S->{DBH}->quote($S->{CGI}->param('content_anon'));
my $qr=$S->{DBH}->quote($S->{CGI}->param('content_reg'));
my ($rv, $sth) = $S->db_insert({
INTO => 'adman_content',
COLS => 'name, content_anon, content_reg',
VALUES =>"$qn, $qa, $qr",
});
($rv, $sth) = $S->db_select({
WHAT => 'LAST_INSERT_ID()',
FROM => 'adman_content'});
my $new_id = $sth->fetchrow();
# now link this up with our position
$S->db_insert({
INTO=>'adman_position_content',
COLS=>'adman_position_id, adman_content_id',
VALUES=>"$pos_id, $new_id",
});
$action='main';
} else {
$content = qq(
<form action='$S->{UI}->{VARS}->{site_url}/adman_admin/' method='post'>
<input type='hidden' name='action' value='addnewcontent'>
<input type='hidden' name='ad_position_id' value='$pos_id'>
Name me: <input type='text' value='' name='name'><p>
<h2>Anonymous Content</h2>
<textarea name='content_anon' wrap='virtual'></textarea>
<h2>Registered User Content</h2>
<textarea name='content_reg' wrap='virtual'></textarea>
<p><input type='submit' value='Add me!' name='go'>
</form>
);
}
}
if($action eq 'edit')
{
my $cid=$S->{CGI}->param('adman_content_id');
if($S->{CGI}->param('go'))
{
my $qa=$S->{DBH}->quote($S->{CGI}->param('content_anon'));
my $qr=$S->{DBH}->quote($S->{CGI}->param('content_reg'));
my ($rv, $sth) = $S->db_update({
WHAT => 'adman_content',
SET => "content_anon=$qa, content_reg=$qr",
WHERE=>"adman_content_id=$cid",
});
$action='main';
} else {
my ($rv, $sth) = $S->db_select({
WHAT=>'name, content_anon, content_reg',
FROM=>'adman_content',
WHERE=>"adman_content_id=$cid",
});
my $row = $sth->fetchrow_hashref();
$content = qq(
<form action='$S->{UI}->{VARS}->{site_url}/adman_admin/' method='post'>
<input type='hidden' name='action' value='edit'>
<input type='hidden' name='adman_content_id' value='$cid'>
Editing $$row{name}:
<h2>Anonymous Content</h2>
<textarea name='content_anon' wrap='virtual'>$$row{content_anon}</textarea>
<h2>Registered User Content</h2>
<textarea name='content_reg' wrap='virtual'>$$row{content_reg}</textarea>
<p><input type='submit' value='Add me!' name='go'>
</form>
);
}
}
if($action eq 'main') {
# get a list of all the ads and their content info
my ($rv, $sth) = $S->db_select({
WHAT=>'ap.*, apc.impressions, apc.adman_content_id, ac.name as content_name',
FROM=>q(
adman_positions ap
LEFT JOIN adman_position_content apc ON ap.adman_position_id=apc.adman_position_id AND apc.enabled=1
LEFT JOIN adman_content ac ON apc.adman_content_id = ac.adman_content_id
),
ORDER_BY=>'ap.name, ac.name',
DEBUG=>1
});
my $row_content;
my $last_apname;
my $total;
while(my $row = $sth->fetchrow_hashref())
{
# ---------------------------------------------------------
if($$row{adman_position_id} != $last_apname)
{
if($last_apname)
{
$row_content .= qq(</table></td></tr><tr><td bgcolor='#DDDDDD'><small>$total</small></td><td bgcolor='#DDDDDD'><small><a href="$S->{UI}->{VARS}->{site_url}/adman_admin/?action=addnewcontent&ad_position_id=$last_apname">Add New Content</a> - <a href="$S->{UI}->{VARS}->{site_url}/adman_admin/?action=addoldcontent&ad_position_id=$last_apname">Add Existing Content</a></small></td></tr></table><p>) if($row_content);
}
# do the shindig..
$row_content .= qq(
<table cellspacing='0' width='100%' style='border: 1px solid #AAA;'>
<tr><td valign='top' width='125' bgcolor='#DDDDDD'><b>$$row{name}</b></td><td valign='top'>
<table cellspacing='0' width="100%">
); # ... to be continued below
$last_apname = $$row{adman_position_id};
$total=0;
}
# ---------------------------------------------------------
# now actually render a row
$row_content .= qq(
<tr><td width='125'>$$row{content_name}</td><td><small>$$row{impressions}</small></td><td align='right'><small><a href="$S->{UI}->{VARS}->{root_dir}/adman_admin/?action=edit&adman_content_id=$$row{adman_content_id}">edit</a> - <a href="$S->{UI}->{VARS}->{root_dir}/adman_admin/?action=hide&adman_content_id=$$row{adman_content_id}">remove</a></small></td></tr>
) if($$row{content_name});
$total += $$row{impressions};
}
$content .= qq($row_content</table></td></tr>
<tr><td bgcolor='#DDDDDD'><small>$total</small></td><td bgcolor='#DDDDDD'><small><a href="$S->{UI}->{VARS}->{site_url}/adman_admin/?action=addnewcontent&ad_position_id=$last_apname">Add New Content</a> - <a href="$S->{UI}->{VARS}->{site_url}/adman_admin/?action=addoldcontent&ad_position_id=$last_apname">Add Existing Content</a></small></td></tr></table>) if($row_content);
$content .= qq(<p><a href="$S->{UI}->{VARS}->{site_url}/adman_admin/?action=addposition">add new position</a>);
}
return $content;
|