b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 2.4) [ 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 = '2.2-dev';
  21.     var $apply_rendering = 'opt-in';
  22.     var $group = 'rendering';
  23.     var $short_desc;
  24.     var $long_desc;
  25.     var $number_of_installs = 1;
  26.  
  27.  
  28.     /**
  29.      * Init
  30.      */
  31.     function PluginInit$params )
  32.     {
  33.         $this->short_desc = T_('Smart quotes + additional typographic replacements.');
  34.         $this->long_desc = T_('This renderer will replace standard and double quotes with typographic quotes were appropriate.<br />
  35.          It will also perform the following replacements:
  36.          <ul>
  37.              <li>--- to &#8212;</li>
  38.             <li>-- to &#8211;</li>
  39.             <li>... to &#8230;</li>
  40.         </ul>' );
  41.     }
  42.  
  43.  
  44.     /**
  45.      * Perform rendering
  46.      *
  47.      * @param array Associative array of parameters
  48.      *    'data': the data (by reference). You probably want to modify this.
  49.      *    'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.
  50.      * @return boolean true if we can render something for the required output format
  51.      */
  52.     function RenderItemAsHtml$params )
  53.     {
  54.         // texturize all content not in code/pre blocks
  55.         $params['data'callback_on_non_matching_blocks$params['data']'#<(pre|code)[\s\S]+?/\1>#i'array$this'texturize_block' ) );
  56.     }
  57.  
  58.  
  59.     /**
  60.      * Texturize content
  61.      *
  62.      * @param string $content 
  63.      * @return string texturized content
  64.      */
  65.     function texturize_block$content )
  66.     {
  67.         $output '';
  68.         $textarr preg_split("/(<.*>)/Us"$content-1PREG_SPLIT_DELIM_CAPTURE)// capture the tags as well as in between
  69.         $stop count($textarr)$next true// loop stuff
  70.         for ($i 0$i $stop$i++{
  71.             $curl $textarr[$i];
  72.  
  73.             if (strlen($curl&& '<' != $curl{0&& $next// If it's not a tag
  74.                 $curl str_replace('---''&#8212;'$curl);
  75.                 $curl str_replace('--''&#8211;'$curl);
  76.                 $curl str_replace("..."'&#8230;'$curl);
  77.                 $curl str_replace('``''&#8220;'$curl);
  78.  
  79.                 // This is a hack, look at this more later. It works pretty well though.
  80.                 $cockney array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
  81.                 $cockneyreplace array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round");
  82.                 $curl str_replace($cockney$cockneyreplace$curl);
  83.  
  84.                 $curl preg_replace("/'s/"'&#8217;s'$curl);
  85.                 $curl preg_replace("/'(\d\d(?:&#8217;|')?s)/""&#8217;$1"$curl);
  86.                 $curl preg_replace('/(\s|\A|")\'/''$1&#8216;'$curl);
  87.                 $curl preg_replace('/(\d+)"/''$1&Prime;'$curl);
  88.                 $curl preg_replace("/(\d+)'/"'$1&prime;'$curl);
  89.                 $curl preg_replace("/(\S)'([^'\s])/""$1&#8217;$2"$curl);
  90.                 $curl preg_replace('/(\s|\A)"(?!\s)/''$1&#8220;$2'$curl);
  91.                 $curl preg_replace('/"(\s|\Z)/''&#8221;$1'$curl);
  92.                 $curl preg_replace("/'([\s.]|\Z)/"'&#8217;$1'$curl);
  93.                 $curl preg_replace("/\(tm\)/i"'&#8482;'$curl);
  94.                 $curl preg_replace("/\(c\)/i"'&#169;'$curl);
  95.                 $curl preg_replace("/\(r\)/i"'&#174;'$curl);
  96.                 $curl preg_replace('/&([^#])(?![a-z]{1,8};)/''&#038;$1'$curl);
  97.                 $curl str_replace("''"'&#8221;'$curl);
  98.  
  99.                 $curl preg_replace('/(d+)x(\d+)/'"$1&#215;$2"$curl);
  100.  
  101.             elseif (strstr($curl'<code'|| strstr($curl'<pre'|| strstr($curl'<kbd' || strstr($curl'<style'|| strstr($curl'<script'))) {
  102.                 // strstr is fast
  103.                 $next false;
  104.             else {
  105.                 $next true;
  106.             }
  107.             $output .= $curl;
  108.         }
  109.         $content $output;
  110.  
  111.         return $content;
  112.     }
  113.  
  114.  
  115.     /**
  116.      * The same as for HTML.
  117.      *
  118.      * @uses RenderItemAsHtml()
  119.      */
  120.     function RenderItemAsXml$params )
  121.     {
  122.         $this->RenderItemAsHtml$params );
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. /*
  129.  * $Log: _texturize.plugin.php,v $
  130.  * Revision 1.17  2007/12/22 21:02:50  fplanque
  131.  * minor
  132.  *
  133.  * Revision 1.16  2007/05/04 20:43:08  fplanque
  134.  * MFB
  135.  *
  136.  * Revision 1.13.2.3.2.3  2007/04/24 11:44:42  yabs
  137.  * minor doc, renamed test function
  138.  *
  139.  * Revision 1.13.2.3.2.2  2007/04/22 16:44:46  yabs
  140.  * testing - ignores code/pre blocks
  141.  *
  142.  * Revision 1.13.2.3.2.1  2007/04/20 02:52:01  fplanque
  143.  * limited number of installs
  144.  *
  145.  * Revision 1.14  2006/12/26 03:19:12  fplanque
  146.  * assigned a few significant plugin groups
  147.  *
  148.  * Revision 1.13  2006/07/10 20:19:30  blueyed
  149.  * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
  150.  *
  151.  * Revision 1.12  2006/07/07 21:26:49  blueyed
  152.  * Bumped to 1.9-dev
  153.  *
  154.  * Revision 1.11  2006/06/16 21:30:57  fplanque
  155.  * Started clean numbering of plugin versions (feel free do add dots...)
  156.  *
  157.  * Revision 1.10  2006/05/30 19:39:55  fplanque
  158.  * plugin cleanup
  159.  *
  160.  * Revision 1.9  2006/04/11 21:22:26  fplanque
  161.  * partial cleanup
  162.  *
  163.  */
  164. ?>

Documentation generated on Sat, 06 Mar 2010 03:41:07 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).