3
* This file implements the AdSense plugin for Quam Plures
5
* Quam Plures - {@link http://quamplures.net/}
6
* Released under GNU GPL License - {@link http://quamplures.net/license.html}
7
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
8
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
10
* @todo (legacy): Remove it in XML Feeds?
15
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
22
class adsense_plugin extends Plugin
24
var $apply_rendering = 'opt-out';
25
var $code = 'adsense';
26
var $group = 'toolbars';
27
var $number_of_installs = 1;
33
* @see Plugin::PluginInit()
35
function PluginInit( & $params )
37
$this->name = $this->T_('AdSense');
38
$this->short_desc = $this->T_('Easy AdSense insertion into posts.');
39
$this->long_desc = $this->T_('<p>This plugin allows you to easily insert AdSense into your posts (simply type [adsense:], or use the toolbar button in expert mode).</p>
40
<p>The plugin will stop expanding AdSense blocks when a limit is reached (3 by default).</p>
41
<p>Look for version 2.0 for multiple AdSense format support.</p>');
46
* @see Plugin::GetDefaultSettings()
48
function GetDefaultSettings( & $params )
50
$default_settings = array(
51
'enable_user' => array(
52
'label' => $this->T_('enable user option'),
54
'defaultvalue' => '1',
55
'note' => $this->T_('If checked, users can turn off this toolbar.'),
57
'toolbar_location' => array(
58
'label' => $this->T_('toolbar location'),
61
'above' => $this->T_('above post textarea'),
62
'below' => $this->T_('below post textarea'),
63
'right' => $this->T_('top of the sidebar'),
65
'defaultvalue' => 'right',
66
'note' => $this->T_('Users will not be able to select where this toolbar goes.'),
69
'adsense_block' => array(
70
'label' => $this->T_('AdSense block'),
71
'type' => 'html_textarea',
74
'defaultvalue' => '<div style="float:right; clear:both; margin:5px;">
76
<!-- Paste from here... -->
77
<div style="border:1px solid red; width:150px; padding:3px;"><strong>You must copy/paste your AdSense code in here.</strong> You can do this on the Plugin config page.</div>
81
'note' => $this->T_('Copy/Paste your AdSense code from Google into here. You can surround it with some CSS for decoration and/or positioning.'),
83
'max_blocks_in_content' => array(
84
'label' => $this->T_('Max # of blocks'),
89
'note' => $this->T_('Maximum number of AdSense blocks the plugin should expand in post contents. Google terms typically set the limit to 3. You may wish to set it to less if you add blocks into the sidebar.'),
92
return $default_settings;
97
* @see Plugin::GetDefaultUserSettings()
99
function GetDefaultUserSettings( & $params )
101
if( ! $this->Settings->get( 'enable_user' ) )
105
$user_settings = array(
106
'use_toolbar' => array(
107
'label' => sprintf( $this->T_('"%s" toolbar'), $this->name ),
108
'defaultvalue' => '1',
109
'type' => 'checkbox',
110
'note' => sprintf( $this->T_('Check this to enable the "%s" toolbar.'), $this->name ),
113
return $user_settings;
118
* @see Plugin::AdminDisplayToolbarAbove()
120
function AdminDisplayToolbarAbove( & $params )
122
$show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
123
if( ($this->Settings->get('toolbar_location') == 'above') && $show_toolbar )
125
return $this->make_the_toolbar( $params );
132
* @see Plugin::AdminDisplayToolbarBelow()
134
function AdminDisplayToolbarBelow( & $params )
136
$show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
137
if( ($this->Settings->get('toolbar_location') == 'below') && $show_toolbar )
139
return $this->make_the_toolbar( $params );
146
* @see Plugin::AdminDisplayToolbarSidebar()
148
function AdminDisplayToolbarSidebar( & $params )
150
$show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
151
if( ($this->Settings->get('toolbar_location') == 'right') && $show_toolbar )
153
return $this->make_the_toolbar( $params );
160
* @see Plugin::FilterItemContents()
162
function FilterItemContents( & $params )
164
$content = & $params['content'];
166
$content = preg_replace( '�\[(adsense:)\]�', '<!-- [$1] -->', $content );
173
* @see Plugin::UnfilterItemContents()
175
function UnfilterItemContents( & $params )
177
$content = & $params['content'];
179
$content = preg_replace( '�<!-- \[(adsense:)\] -->�', '[$1]', $content );
186
* @see Plugin::RenderItemAsHtml()
188
function RenderItemAsHtml( & $params )
190
// Dummy placeholder. Without it the plugin would ne be considered to be a renderer...
196
* @see Plugin::DisplayItemAsHtml()
198
function DisplayItemAsHtml( & $params )
200
$content = & $params['data'];
202
$content = preg_replace_callback( '�<!-- \[adsense:\] -->�', array( $this, 'DisplayItem_callback' ), $content );
209
* dummy docblock makes error-free autodocs
211
function DisplayItem_callback( $matches )
214
* How many blocks already displayed?
216
static $adsense_blocks_counter = 0;
218
$adsense_blocks_counter++;
220
if( $adsense_blocks_counter > $this->Settings->get( 'max_blocks_in_content' ) )
222
return '<!-- Adsense block #'.$adsense_blocks_counter.' not displayed since it exceed the limit of '
223
.$this->Settings->get( 'max_blocks_in_content' ).' -->';
226
return $this->Settings->get( 'adsense_block' );
231
* @see Plugin::DisplayItemAsXml()
233
function DisplayItemAsXml( & $params )
235
$content = & $params['data'];
237
$content = preg_replace( '�\[adsense:\]�', '', $content );
244
* actually finally create the toolbar :)
246
function make_the_toolbar( $params )
248
echo '<div class="edit_toolbar">';
249
echo '<input type="button" id="adsense_default" title="'.$this->T_('Insert AdSense block').'" class="quicktags" onclick="textarea_wrap_selection( app_Canvas, \'[adsense:]\', \'\', 1 );" value="'.$this->T_('AdSense').'" />';