[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/plugins/adsense_plugin/ -> _adsense.plugin.php (source)

   1  <?php
   2  /**

   3   * This file implements the AdSense plugin for b2evolution

   4   *

   5   * b2evolution - {@link http://b2evolution.net/}

   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   7   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   8   *

   9   * @package plugins

  10   */
  11  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  12  
  13  /**

  14   * Replaces AdSense markup in HTML.

  15   *

  16   * @todo Remove it in XML Feeds?

  17   *

  18   * @package plugins

  19   */
  20  class adsense_plugin extends Plugin
  21  {
  22      var $code = 'evo_adsense';
  23      var $name = 'AdSense';
  24      var $priority = 10;
  25      var $apply_rendering = 'opt-out';
  26      var $group = 'rendering';
  27      var $help_url = 'http://b2evolution.net/blog-ads/adsense-plugin.php';
  28      var $short_desc;
  29      var $long_desc;
  30      var $version = '0.9.1';
  31      var $number_of_installs = 1;
  32  
  33      /**

  34       * Init

  35       */
  36  	function PluginInit( & $params )
  37      {
  38          $this->short_desc = T_('Easy AdSense insertion into posts.');
  39          $this->long_desc = 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       * Get the settings that the plugin can use.

  47       *

  48       * Those settings are transfered into a Settings member object of the plugin

  49       * and can be edited in the backoffice (Settings / Plugins).

  50       *

  51       * @see Plugin::GetDefaultSettings()

  52       * @see PluginSettings

  53       * @see Plugin::PluginSettingsValidateSet()

  54       * @return array

  55       */
  56  	function GetDefaultSettings( & $params )
  57      {
  58          $r = array(
  59              'adsense_block' => array(
  60                      'label' => 'AdSense block',
  61                      'type' => 'html_textarea',
  62                      'cols' => 60,
  63                      'rows' => 10,
  64                      'defaultvalue' => '<div style="float:right; clear:both; margin:5px;">
  65  
  66  <!-- Paste from here... -->
  67  <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>
  68  <!-- ...to here -->
  69  
  70  </div>',
  71                      'note' => 'Copy/Paste your AdSense code from Google into here. You can surround it with some CSS for decoration and/or positionning.',
  72                  ),
  73              'max_blocks_in_content' => array(
  74                      'label' => 'Max # of blocks',
  75                      'type' => 'integer',
  76                      'size' => 2,
  77                      'maxlength' => 2,
  78                      'defaultvalue' => 3,
  79                      'note' => 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.'),
  80                  ),
  81              );
  82  
  83          return $r;
  84      }
  85  
  86  
  87    /**

  88     * Comments out the adsense tags so that they don't get worked on by other renderers like Auto-P

  89     *

  90       * @param mixed $params

  91       */
  92  	function FilterItemContents( & $params )
  93      {
  94          $content = & $params['content'];
  95  
  96          $content = preg_replace( '¤\[(adsense:)\]¤', '<!-- [$1] -->', $content );
  97  
  98          return true;
  99      }
 100  
 101  
 102      /**

 103       * Changes the commented out tags into something that is visible to the editor

 104       *

 105       * @param mixed $params

 106       */
 107  	function UnfilterItemContents( & $params )
 108      {
 109          $content = & $params['content'];
 110  
 111          $content = preg_replace( '¤<!-- \[(adsense:)\] -->¤', '[$1]', $content );
 112  
 113          return true;
 114      }
 115  
 116  
 117      /**

 118       * Event handler: Called when rendering item/post contents as HTML. (CACHED)

 119       *

 120       * The rendered content will be *cached* and the cached content will be reused on subsequent displays.

 121       * Use {@link DisplayItemAsHtml()} instead if you want to do rendering at display time.

 122       *

 123        * Note: You have to change $params['data'] (which gets passed by reference).

 124       *

 125       * @param array Associative array of parameters

 126       *   - 'data': the data (by reference). You probably want to modify this.

 127       *   - 'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.

 128       *   - 'Item': the {@link Item} object which gets rendered.

 129       * @return boolean Have we changed something?

 130       */
 131  	function RenderItemAsHtml( & $params )
 132      {
 133          // Dummy placeholder. Without it the plugin would ne be considered to be a renderer...

 134          return false;
 135      }
 136  
 137  
 138      /**

 139       * Perform rendering (at display time, i-e: NOT cached)

 140       *

 141       * @see Plugin::DisplayItemAsHtml()

 142       */
 143  	function DisplayItemAsHtml( & $params )
 144      {
 145          $content = & $params['data'];
 146  
 147          $content = preg_replace_callback( '¤<!-- \[adsense:\] -->¤', array( $this, 'DisplayItem_callback' ), $content );
 148  
 149          return true;
 150      }
 151  
 152  
 153    /**

 154       *

 155       */
 156  	function DisplayItem_callback( $matches )
 157      {
 158        /**

 159           * How many blocks already displayed?

 160           */
 161          static $adsense_blocks_counter = 0;
 162  
 163          $adsense_blocks_counter++;
 164  
 165          if( $adsense_blocks_counter > $this->Settings->get( 'max_blocks_in_content' ) )
 166          {
 167              return '<!-- Adsense block #'.$adsense_blocks_counter.' not displayed since it exceed the limit of '
 168                              .$this->Settings->get( 'max_blocks_in_content' ).' -->';
 169          }
 170  
 171          return $this->Settings->get( 'adsense_block' );
 172      }
 173  
 174      /**

 175       * Filter out adsense tags from XML content.

 176       *

 177       * @see Plugin::RenderItemAsXml()

 178       */
 179  	function DisplayItemAsXml( & $params )
 180      {
 181          $content = & $params['data'];
 182  
 183          $content = preg_replace( '¤\[adsense:\]¤', '', $content );
 184  
 185          return true;
 186      }
 187  
 188      /**

 189       * Display a toolbar in admin

 190       *

 191       * @param array Associative array of parameters

 192       * @return boolean did we display a toolbar?

 193       */
 194  	function AdminDisplayToolbar( & $params )
 195      {
 196          if( $params['edit_layout'] == 'simple' )
 197          {    // This is too complex for simple mode, don't display it:
 198              return false;
 199          }
 200  
 201          echo '<div class="edit_toolbar">';
 202          echo '<input type="button" id="adsense_default" title="'.T_('Insert AdSense block').'" class="quicktags" onclick="textarea_wrap_selection( b2evoCanvas, \'[adsense:]\', \'\', 1 );" value="'.T_('AdSense').'" />';
 203          echo '</div>';
 204  
 205          return true;
 206      }
 207  
 208  }
 209  
 210  
 211  /*

 212   * $Log: _adsense.plugin.php,v $

 213   * Revision 1.1  2007/10/08 22:50:09  fplanque

 214   * integrated adsense plugin

 215   *

 216   */
 217  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics