b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.9) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _texturize.plugin.php

Documentation is available at _texturize.plugin.php

  1. <?php
  2. /**
  3.  * This file implements the Texturize plugin for b2evolution
  4.  *
  5.  * @author WordPress team - http://sourceforge.net/project/memberlist.php?group_id=51422
  6.  *  b2evo: 1 notice fix.
  7.  *
  8.  * @package plugins
  9.  */
  10. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  11.  
  12. /**
  13.  * @package plugins
  14.  */
  15. class texturize_plugin extends Plugin
  16. {
  17.     var $code = 'b2WPTxrz';
  18.     var $name = 'Texturize';
  19.     var $priority = 90;
  20.     var $version = '1.9-dev';
  21.     var $apply_rendering = 'opt-in';
  22.     var $group = 'rendering';
  23.     var $short_desc;
  24.     var $long_desc;
  25.  
  26.  
  27.     /**
  28.      * Init
  29.      */
  30.     function PluginInit$params )
  31.     {
  32.         $this->short_desc = T_('Smart quotes + additional typographic replacements.');
  33.         $this->long_desc = T_('This renderer will replace standard and double quotes with typographic quotes were appropriate.<br />
  34.          It will also perform the following replacements:
  35.          <ul>
  36.              <li>--- to &#8212;</li>
  37.             <li>-- to &#8211;</li>
  38.             <li>... to &#8230;</li>
  39.         </ul>' );
  40.     }
  41.  
  42.  
  43.     /**
  44.      * Perform rendering
  45.      *
  46.      * @param array Associative array of parameters
  47.      *    'data': the data (by reference). You probably want to modify this.
  48.      *    'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.
  49.      * @return boolean true if we can render something for the required output format
  50.      */
  51.     function RenderItemAsHtml$params )
  52.     {
  53.         $content $params['data'];
  54.  
  55.         $output '';
  56.         $textarr preg_split("/(<.*>)/Us"$content-1PREG_SPLIT_DELIM_CAPTURE)// capture the tags as well as in between
  57.         $stop count($textarr)$next true// loop stuff
  58.         for ($i 0$i $stop$i++{
  59.             $curl $textarr[$i];
  60.  
  61.             if (strlen($curl&& '<' != $curl{0&& $next// If it's not a tag
  62.                 $curl str_replace('---''&#8212;'$curl);
  63.                 $curl str_replace('--''&#8211;'$curl);
  64.                 $curl str_replace("..."'&#8230;'$curl);
  65.                 $curl str_replace('``''&#8220;'$curl);
  66.  
  67.                 // This is a hack, look at this more later. It works pretty well though.
  68.                 $cockney array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
  69.                 $cockneyreplace array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round");
  70.                 $curl str_replace($cockney$cockneyreplace$curl);
  71.  
  72.                 $curl preg_replace("/'s/"'&#8217;s'$curl);
  73.                 $curl preg_replace("/'(\d\d(?:&#8217;|')?s)/""&#8217;$1"$curl);
  74.                 $curl preg_replace('/(\s|\A|")\'/''$1&#8216;'$curl);
  75.                 $curl preg_replace('/(\d+)"/''$1&Prime;'$curl);
  76.                 $curl preg_replace("/(\d+)'/"'$1&prime;'$curl);
  77.                 $curl preg_replace("/(\S)'([^'\s])/""$1&#8217;$2"$curl);
  78.                 $curl preg_replace('/(\s|\A)"(?!\s)/''$1&#8220;$2'$curl);
  79.                 $curl preg_replace('/"(\s|\Z)/''&#8221;$1'$curl);
  80.                 $curl preg_replace("/'([\s.]|\Z)/"'&#8217;$1'$curl);
  81.                 $curl preg_replace("/\(tm\)/i"'&#8482;'$curl);
  82.                 $curl preg_replace("/\(c\)/i"'&#169;'$curl);
  83.                 $curl preg_replace("/\(r\)/i"'&#174;'$curl);
  84.                 $curl preg_replace('/&([^#])(?![a-z]{1,8};)/''&#038;$1'$curl);
  85.                 $curl str_replace("''"'&#8221;'$curl);
  86.  
  87.                 $curl preg_replace('/(d+)x(\d+)/'"$1&#215;$2"$curl);
  88.  
  89.             elseif (strstr($curl'<code'|| strstr($curl'<pre'|| strstr($curl'<kbd' || strstr($curl'<style'|| strstr($curl'<script'))) {
  90.                 // strstr is fast
  91.                 $next false;
  92.             else {
  93.                 $next true;
  94.             }
  95.             $output .= $curl;
  96.         }
  97.         $content $output;
  98.  
  99.         return true;
  100.     }
  101.  
  102.  
  103.     /**
  104.      * The same as for HTML.
  105.      *
  106.      * @uses RenderItemAsHtml()
  107.      */
  108.     function RenderItemAsXml$params )
  109.     {
  110.         $this->RenderItemAsHtml$params );
  111.     }
  112. }
  113.  
  114.  
  115.  
  116. /*
  117.  * $Log: _texturize.plugin.php,v $
  118.  * Revision 1.13.2.3  2006/12/26 03:18:51  fplanque
  119.  * assigned a few significant plugin groups
  120.  *
  121.  * Revision 1.13.2.2  2006/11/04 19:55:12  fplanque
  122.  * Reinjected old Log blocks. Removing them from CVS was a bad idea -- especially since Daniel has decided branch 1.9 was his HEAD...
  123.  *
  124.  * Revision 1.13  2006/07/10 20:19:30  blueyed
  125.  * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
  126.  *
  127.  * Revision 1.12  2006/07/07 21:26:49  blueyed
  128.  * Bumped to 1.9-dev
  129.  *
  130.  * Revision 1.11  2006/06/16 21:30:57  fplanque
  131.  * Started clean numbering of plugin versions (feel free do add dots...)
  132.  *
  133.  * Revision 1.10  2006/05/30 19:39:55  fplanque
  134.  * plugin cleanup
  135.  *
  136.  * Revision 1.9  2006/04/11 21:22:26  fplanque
  137.  * partial cleanup
  138.  *
  139.  */
  140. ?>

Documentation generated on Tue, 18 Dec 2007 22:53:22 +0100 by phpDocumentor 1.4.0