b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _smilies.renderer.php

Documentation is available at _smilies.renderer.php

  1. <?php
  2. /**
  3.  * This file implements the Image Smilies Renderer 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-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package plugins
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__).'/../renderer.class.php';
  17.  
  18. /**
  19.  * @package plugins
  20.  */
  21. {
  22.     var $code = 'b2evSmil';
  23.     var $name = 'Smilies';
  24.     var $priority = 80;
  25.     var $apply_when = 'opt-out';
  26.     var $apply_to_html = true
  27.     var $apply_to_xml = false// Leave the smilies alone
  28.     var $short_desc;
  29.     var $long_desc;
  30.  
  31.     /**
  32.      * Text similes search array
  33.      *
  34.      * @access private
  35.      */
  36.     var $search;
  37.     
  38.     /**
  39.      * IMG replace array
  40.      *
  41.      * @access private
  42.      */
  43.     var $replace;
  44.  
  45.     /**
  46.      * Smiley definitions
  47.      *
  48.      * @access private
  49.      */
  50.     var $smilies;
  51.  
  52.     /**
  53.      * Path to images
  54.      *
  55.      * @access private
  56.      */
  57.     var $smilies_path;
  58.  
  59.  
  60.     /**
  61.      * Constructor
  62.      *
  63.      * {@internal smilies_Rendererplugin::smilies_Rendererplugin(-)}}
  64.      */
  65.     function smilies_Rendererplugin()
  66.     {
  67.         $this->short_desc = T_('Convert text smilies to icons');
  68.         $this->long_desc = T_('No description available');
  69.  
  70.         require dirname(__FILE__)'/../_smilies.conf.php';
  71.     }
  72.  
  73.  
  74.     /**
  75.      * Perform rendering
  76.      *
  77.      * {@internal smilies_Rendererplugin::render(-)}}
  78.      *
  79.      * @param string content to render (by reference) / rendered content
  80.      * @param string Output format, see {@link format_to_output()}
  81.      * @return boolean true if we can render something for the required output format
  82.      */
  83.     function render$content$format )
  84.     {
  85.         ifparent::render$content$format ) )
  86.         {    // We cannot render the required format
  87.             return false;
  88.         }
  89.     
  90.         ifisset$this->search ) )
  91.         {    // We haven't prepared the smilies yet
  92.             $this->search array();
  93.  
  94.  
  95.             $tmpsmilies $this->smilies;
  96.             uksort($tmpsmilies'smiliescmp');
  97.     
  98.             foreach($tmpsmilies as $smiley => $img)
  99.             {
  100.                 $this->search[$smiley;
  101.                 $smiley_masked '';
  102.                 for ($i 0$i strlen($smiley)$i++ )
  103.                 {
  104.                     $smiley_masked .=  '&#'.ord(substr($smiley$i1)).';';
  105.                 }
  106.     
  107.                 // We don't use getimagesize() here until we have a mean
  108.                 // to preprocess smilies. It takes up to much time when
  109.                 // processing them at display time.
  110.                 $this->replace['<img src="'.$this->smilies_path.'/'.$img.'" alt="'.$smiley_masked.'" class="middle" />';
  111.             }
  112.         }
  113.  
  114.  
  115.         // REPLACE:  But not in code blocks.
  116.         ifstrpos$content '<code>' !== false )
  117.         // If there are code tags run this substitution
  118.             $content_parts preg_split("/<\/?code>/"$content);
  119.             $content '';
  120.             for $x $x count$content_parts $x++ )
  121.             {
  122.                 if ( ( $x == )
  123.                 // If x is even then it's not code and replace any smiles
  124.                     $content .= str_replace$this->search$this->replace$content_parts[$x);
  125.                 }
  126.                 else
  127.                 // If x is odd don't replace smiles. and put code tags back in.
  128.                     $content .= '<code>' $content_parts[$x'</code>';
  129.                 }
  130.             }
  131.         }
  132.         else
  133.         // No code blocks, replace on the whole thing
  134.             $content str_replace$this->search$this->replace$content);
  135.         }
  136.     
  137.         return true;
  138.     }
  139. }
  140.  
  141. /**
  142.  * sorts the smilies' array by length
  143.  * this is important if you want :)) to superseede :) for example
  144.  */
  145. function smiliescmp($a$b)
  146. {
  147.     if(($diff strlen($bstrlen($a)) == 0)
  148.     {
  149.         return strcmp($a$b);
  150.     }
  151.     return $diff;
  152. }
  153.  
  154.  
  155.  
  156. // Register the plugin:
  157. $this->registernew smilies_Rendererplugin() );
  158.  
  159. ?>

Documentation generated on Tue, 20 May 2008 01:55:45 +0200 by phpDocumentor 1.4.2