The new php file:
Code: Select all
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
class serendipity_plugin_google_adsense extends serendipity_plugin
{
var $title = PLUGIN_ADSENSE_NAME;
function introspect(&$propbag)
{
global $serendipity;
$this->title = $this->get_config('title', $this->title);
$propbag->add('name', PLUGIN_ADSENSE_NAME);
$propbag->add('description', PLUGIN_ADSENSE_DESC);
$propbag->add('stackable', true);
$propbag->add('author', 'Jim Dabell');
$propbag->add('version', '0.2');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
$propbag->add('configuration', array('client',
'slot',
'format',
'type',
'channel',
'number'));
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'client':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_ADSENSE_CLIENT_NAME);
$propbag->add('description', PLUGIN_ADSENSE_CLIENT_DESCRIPTION);
$propbag->add('default', '');
break;
case 'slot':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_ADSENSE_SLOT_NAME);
$propbag->add('description', PLUGIN_ADSENSE_SLOT_DESCRIPTION);
$propbag->add('default', '');
break;
case 'number':
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_ADSENSE_NUMBER_NAME);
$propbag->add('description', PLUGIN_ADSENSE_NUMBER_DESCRIPTION);
$propbag->add('default', '1');
$propbag->add('select_values', array('1'=>1,
'2'=>2,
'3'=>3,
'4'=>4,
'5'=>5));
break;
case 'format':
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_ADSENSE_FORMAT_NAME);
$propbag->add('description', PLUGIN_ADSENSE_FORMAT_DESCRIPTION);
$propbag->add('default', '160x600_as');
$propbag->add('select_values', array(
'728x90_as'=>PLUGIN_ADSENSE_FORMAT_LEADERBOARD,
'468x60_as'=>PLUGIN_ADSENSE_FORMAT_BANNER,
'300x250_as'=>PLUGIN_ADSENSE_FORMAT_MEDIUM_RECTANGLE,
'160x600_as'=>PLUGIN_ADSENSE_FORMAT_WIDE_SKYSCRAPER,
'120x600_as'=>PLUGIN_ADSENSE_FORMAT_SKYSCRAPER));
break;
case 'type':
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_ADSENSE_TYPE_NAME);
$propbag->add('description', PLUGIN_ADSENSE_TYPE_DESCRIPTION);
$propbag->add('default', 'text_image');
$propbag->add('select_values', array(
'text_image'=>PLUGIN_ADSENSE_TYPE_TEXT_AND_IMAGES,
'text'=>PLUGIN_ADSENSE_TYPE_TEXT_ONLY,
'image'=>PLUGIN_ADSENSE_TYPE_IMAGES_ONLY));
break;
case 'channel':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_ADSENSE_CHANNEL_NAME);
$propbag->add('description', PLUGIN_ADSENSE_CHANNEL_DESCRIPTION);
$propbag->add('default', '');
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
global $serendipity;
$client = $this->get_config('client');
$slot = $this->get_config('slot');
$format = $this->get_config('format');
$width = intval($format, 10);
$height = intval(substr(stristr($format, 'x'), 1), 10);
$type = $this->get_config('type');
$channel = $this->get_config('channel');
$number = $this->get_config('number');
if ($slot == '')
{
for($i = 0; $i < $number ; $i++)
{
echo("<script type='text/javascript'><!--\n");
echo("google_ad_client = '$client';\n");
echo("google_ad_width = $width;\n");
echo("google_ad_height = $height;\n");
echo("google_ad_format = '$format';\n");
echo("google_ad_type = '$type';\n");
echo("google_ad_channel = '$channel';\n");
echo("//--></script>\n");
echo('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
echo('</script>');
echo('<br />');
}
} else {
for($i = 0; $i < $number ; $i++)
{
echo("<script type='text/javascript'><!--\n");
echo("google_ad_client = '$client';\n");
echo("google_ad_slot = '$slot';\n");
echo("google_ad_width = $width;\n");
echo("google_ad_height = $height;\n");
echo("//--></script>\n");
echo('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
echo('</script>');
echo('<br />');
}
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
Code: Select all
<?php
/**
* @version $Revision: 1.2 $
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_ADSENSE_NAME', 'AdSense');
@define('PLUGIN_ADSENSE_DESC', 'Displays adverts from Google.');
@define('PLUGIN_ADSENSE_CLIENT_NAME', 'Client ID');
@define('PLUGIN_ADSENSE_CLIENT_DESCRIPTION', 'This is your client identification that Google gives you, starting with "pub-".');
@define('PLUGIN_ADSENSE_SLOT_NAME', 'SLOT ID');
@define('PLUGIN_ADSENSE_SLOT_DESCRIPTION', 'Optional SLOT id.');
@define('PLUGIN_ADSENSE_WIDTH', 'Width');
@define('PLUGIN_ADSENSE_HEIGHT', 'Height');
@define('PLUGIN_ADSENSE_FORMAT_NAME', 'Format');
@define('PLUGIN_ADSENSE_FORMAT_DESCRIPTION', 'What format ads do you want?');
@define('PLUGIN_ADSENSE_FORMAT_LEADERBOARD', '728 x 90 Leaderboard');
@define('PLUGIN_ADSENSE_FORMAT_BANNER', '468 x 60 Banner');
@define('PLUGIN_ADSENSE_FORMAT_MEDIUM_RECTANGLE', '300 x 250 Medium Rectangle');
@define('PLUGIN_ADSENSE_FORMAT_WIDE_SKYSCRAPER', '160 x 600 Wide Skyscraper');
@define('PLUGIN_ADSENSE_FORMAT_SKYSCRAPER', '120 x 600 Skyscraper');
@define('PLUGIN_ADSENSE_TYPE_NAME', 'Type');
@define('PLUGIN_ADSENSE_TYPE_DESCRIPTION', 'Do you want text ads or image ads?');
@define('PLUGIN_ADSENSE_TYPE_TEXT_AND_IMAGES', 'Text and image ads');
@define('PLUGIN_ADSENSE_TYPE_TEXT_ONLY', 'Text ads only');
@define('PLUGIN_ADSENSE_TYPE_IMAGES_ONLY', 'Images ads only');
@define('PLUGIN_ADSENSE_CHANNEL_NAME', 'Channel');
@define('PLUGIN_ADSENSE_CHANNEL_DESCRIPTION', 'Optionally distinguish between different ads. This should be the number Google gives you, not the name of the channel.');
@define('PLUGIN_ADSENSE_NUMBER_NAME', 'Number');
@define('PLUGIN_ADSENSE_NUMBER_DESCRIPTION', 'Number of ads to show, with a <BR> tag in between');
?>