~quam-plures-gatekeepers/quam-plures/trunk

« back to all changes in this revision

Viewing changes to qp_plugins/adsense_plugin/_adsense.plugin.php

  • Committer: EdB
  • Author(s): Lee Turner
  • Date: 2012-08-02 14:54:29 UTC
  • mfrom: (7641.6.1 remove_plugins)
  • Revision ID: 1912webworks@gmail.com-20120802145429-oafd8tkppoz7b5lk
Removed the plugins voted out on the forums

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * This file implements the AdSense plugin for Quam Plures
4
 
 *
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/}
9
 
 *
10
 
 * @todo (legacy): Remove it in XML Feeds?
11
 
 *
12
 
 * @package plugins
13
 
 * @subpackage AdSense
14
 
 */
15
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
16
 
 
17
 
 
18
 
/**
19
 
 * @package plugins
20
 
 * @subpackage AdSense
21
 
 */
22
 
class adsense_plugin extends Plugin
23
 
{
24
 
        var $apply_rendering = 'opt-out';
25
 
        var $code = 'adsense';
26
 
        var $group = 'toolbars';
27
 
        var $number_of_installs = 1;
28
 
        var $priority = 10;
29
 
        var $version = '0.1';
30
 
 
31
 
 
32
 
        /**
33
 
         * @see Plugin::PluginInit()
34
 
         */
35
 
        function PluginInit( & $params )
36
 
        {
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>');
42
 
        }
43
 
 
44
 
 
45
 
        /**
46
 
         * @see Plugin::GetDefaultSettings()
47
 
         */
48
 
        function GetDefaultSettings( & $params )
49
 
        {
50
 
                $default_settings = array(
51
 
                        'enable_user' => array(
52
 
                                'label' => $this->T_('enable user option'),
53
 
                                'type' => 'checkbox',
54
 
                                'defaultvalue' => '1',
55
 
                                'note' => $this->T_('If checked, users can turn off this toolbar.'),
56
 
                        ),
57
 
                        'toolbar_location' => array(
58
 
                                'label' => $this->T_('toolbar location'),
59
 
                                'type' => 'select',
60
 
                                'options' => array(
61
 
                                        'above' => $this->T_('above post textarea'),
62
 
                                        'below' => $this->T_('below post textarea'),
63
 
                                        'right' => $this->T_('top of the sidebar'),
64
 
                                ),
65
 
                                'defaultvalue' => 'right',
66
 
                                'note' => $this->T_('Users will not be able to select where this toolbar goes.'),
67
 
                        ),
68
 
 
69
 
                        'adsense_block' => array(
70
 
                                        'label' => $this->T_('AdSense block'),
71
 
                                        'type' => 'html_textarea',
72
 
                                        'cols' => 60,
73
 
                                        'rows' => 10,
74
 
                                        'defaultvalue' => '<div style="float:right; clear:both; margin:5px;">
75
 
 
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>
78
 
<!-- ...to here -->
79
 
 
80
 
</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.'),
82
 
                                ),
83
 
                        'max_blocks_in_content' => array(
84
 
                                        'label' => $this->T_('Max # of blocks'),
85
 
                                        'type' => 'integer',
86
 
                                        'size' => 2,
87
 
                                        'maxlength' => 2,
88
 
                                        'defaultvalue' => 3,
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.'),
90
 
                                ),
91
 
                        );
92
 
                return $default_settings;
93
 
        }
94
 
 
95
 
 
96
 
        /**
97
 
         * @see Plugin::GetDefaultUserSettings()
98
 
         */
99
 
        function GetDefaultUserSettings( & $params )
100
 
        {
101
 
                if( ! $this->Settings->get( 'enable_user' ) )
102
 
                {
103
 
                        return false;
104
 
                }
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 ),
111
 
                        ),
112
 
                );
113
 
                return $user_settings;
114
 
        }
115
 
 
116
 
 
117
 
        /**
118
 
         * @see Plugin::AdminDisplayToolbarAbove()
119
 
         */
120
 
        function AdminDisplayToolbarAbove( & $params )
121
 
        {
122
 
                $show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
123
 
                if( ($this->Settings->get('toolbar_location') == 'above') && $show_toolbar )
124
 
                {
125
 
                        return $this->make_the_toolbar( $params );
126
 
                }
127
 
                return false;
128
 
        }
129
 
 
130
 
 
131
 
        /**
132
 
         * @see Plugin::AdminDisplayToolbarBelow()
133
 
         */
134
 
        function AdminDisplayToolbarBelow( & $params )
135
 
        {
136
 
                $show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
137
 
                if( ($this->Settings->get('toolbar_location') == 'below') && $show_toolbar )
138
 
                {
139
 
                        return $this->make_the_toolbar( $params );
140
 
                }
141
 
                return false;
142
 
        }
143
 
 
144
 
 
145
 
        /**
146
 
         * @see Plugin::AdminDisplayToolbarSidebar()
147
 
         */
148
 
        function AdminDisplayToolbarSidebar( & $params )
149
 
        {
150
 
                $show_toolbar = ( $this->Settings->get('enable_user') ? $this->UserSettings->get('use_toolbar') : true );
151
 
                if( ($this->Settings->get('toolbar_location') == 'right') && $show_toolbar )
152
 
                {
153
 
                        return $this->make_the_toolbar( $params );
154
 
                }
155
 
                return false;
156
 
        }
157
 
 
158
 
 
159
 
  /**
160
 
         * @see Plugin::FilterItemContents()
161
 
         */
162
 
        function FilterItemContents( & $params )
163
 
        {
164
 
                $content = & $params['content'];
165
 
 
166
 
                $content = preg_replace( '�\[(adsense:)\]�', '<!-- [$1] -->', $content );
167
 
 
168
 
                return true;
169
 
        }
170
 
 
171
 
 
172
 
  /**
173
 
         * @see Plugin::UnfilterItemContents()
174
 
         */
175
 
        function UnfilterItemContents( & $params )
176
 
        {
177
 
                $content = & $params['content'];
178
 
 
179
 
                $content = preg_replace( '�<!-- \[(adsense:)\] -->�', '[$1]', $content );
180
 
 
181
 
                return true;
182
 
        }
183
 
 
184
 
 
185
 
        /**
186
 
         * @see Plugin::RenderItemAsHtml()
187
 
         */
188
 
        function RenderItemAsHtml( & $params )
189
 
        {
190
 
                // Dummy placeholder. Without it the plugin would ne be considered to be a renderer...
191
 
                return false;
192
 
        }
193
 
 
194
 
 
195
 
        /**
196
 
         * @see Plugin::DisplayItemAsHtml()
197
 
         */
198
 
        function DisplayItemAsHtml( & $params )
199
 
        {
200
 
                $content = & $params['data'];
201
 
 
202
 
                $content = preg_replace_callback( '�<!-- \[adsense:\] -->�', array( $this, 'DisplayItem_callback' ), $content );
203
 
 
204
 
                return true;
205
 
        }
206
 
 
207
 
 
208
 
  /**
209
 
         * dummy docblock makes error-free autodocs
210
 
         */
211
 
        function DisplayItem_callback( $matches )
212
 
        {
213
 
          /**
214
 
                 * How many blocks already displayed?
215
 
                 */
216
 
                static $adsense_blocks_counter = 0;
217
 
 
218
 
                $adsense_blocks_counter++;
219
 
 
220
 
                if( $adsense_blocks_counter > $this->Settings->get( 'max_blocks_in_content' ) )
221
 
                {
222
 
                        return '<!-- Adsense block #'.$adsense_blocks_counter.' not displayed since it exceed the limit of '
223
 
                                                        .$this->Settings->get( 'max_blocks_in_content' ).' -->';
224
 
                }
225
 
 
226
 
                return $this->Settings->get( 'adsense_block' );
227
 
        }
228
 
 
229
 
 
230
 
        /**
231
 
         * @see Plugin::DisplayItemAsXml()
232
 
         */
233
 
        function DisplayItemAsXml( & $params )
234
 
        {
235
 
                $content = & $params['data'];
236
 
 
237
 
                $content = preg_replace( '�\[adsense:\]�', '', $content );
238
 
 
239
 
                return true;
240
 
        }
241
 
 
242
 
 
243
 
        /**
244
 
         * actually finally create the toolbar :)
245
 
         */
246
 
        function make_the_toolbar( $params )
247
 
        {
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').'" />';
250
 
                echo '</div>';
251
 
 
252
 
                return true;
253
 
        }
254
 
 
255
 
}
256
 
 
257
 
?>