b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/_texturize.plugin.php - 141 lines - 4495 bytes - Summary - Text - Print

Description: This file implements the Texturize plugin for b2evolution

   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 = '5.0.0';
  21      var $group = 'rendering';
  22      var $short_desc;
  23      var $long_desc;
  24      var $number_of_installs = 1;
  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       * Define here default collection/blog settings that are to be made available in the backoffice.
  45       *
  46       * @param array Associative array of parameters.
  47       * @return array See {@link Plugin::get_coll_setting_definitions()}.
  48       */
  49  	function get_coll_setting_definitions( & $params )
  50      {
  51          $default_params = array_merge( $params, array(
  52                  'default_post_rendering' => 'opt-in',
  53                  'default_comment_rendering' => 'stealth',
  54              ) );
  55          return parent::get_coll_setting_definitions( $default_params );
  56      }
  57  
  58  
  59      /**
  60       * Perform rendering
  61       *
  62       * @param array Associative array of parameters
  63       *   'data': the data (by reference). You probably want to modify this.
  64       *   'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.
  65       * @return boolean true if we can render something for the required output format
  66       */
  67  	function RenderItemAsHtml( & $params )
  68      {
  69          // texturize all content not in code/pre blocks
  70          $params['data'] = callback_on_non_matching_blocks( $params['data'], '#<(pre|code)[\s\S]+?/\1>#i', array( $this, 'texturize_block' ) );
  71      }
  72  
  73  
  74      /**
  75       * Texturize content
  76       *
  77       * @param string $content
  78       * @return string texturized content
  79       */
  80  	function texturize_block( $content )
  81      {
  82          $output = '';
  83          $textarr = preg_split("/(<.*>)/Us", $content, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
  84          $stop = count($textarr); $next = true; // loop stuff
  85          for ($i = 0; $i < $stop; $i++) {
  86              $curl = $textarr[$i];
  87  
  88              if (strlen($curl) && '<' != $curl{0} && $next) { // If it's not a tag
  89                  $curl = str_replace('---', '&#8212;', $curl);
  90                  $curl = str_replace('--', '&#8211;', $curl);
  91                  $curl = str_replace("...", '&#8230;', $curl);
  92                  $curl = str_replace('``', '&#8220;', $curl);
  93  
  94                  // This is a hack, look at this more later. It works pretty well though.
  95                  $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
  96                  $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round");
  97                  $curl = str_replace($cockney, $cockneyreplace, $curl);
  98  
  99                  $curl = preg_replace("/'s/", '&#8217;s', $curl);
 100                  $curl = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#8217;$1", $curl);
 101                  $curl = preg_replace('/(\s|\A|")\'/', '$1&#8216;', $curl);
 102                  $curl = preg_replace('/(\d+)"/', '$1&Prime;', $curl);
 103                  $curl = preg_replace("/(\d+)'/", '$1&prime;', $curl);
 104                  $curl = preg_replace("/(\S)'([^'\s])/", "$1&#8217;$2", $curl);
 105                  $curl = preg_replace('/(\s|\A)"(?!\s)/', '$1&#8220;$2', $curl);
 106                  $curl = preg_replace('/"(\s|\Z)/', '&#8221;$1', $curl);
 107                  $curl = preg_replace("/'([\s.]|\Z)/", '&#8217;$1', $curl);
 108                  $curl = preg_replace("/\(tm\)/i", '&#8482;', $curl);
 109                  $curl = preg_replace("/\(c\)/i", '&#169;', $curl);
 110                  $curl = preg_replace("/\(r\)/i", '&#174;', $curl);
 111                  $curl = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $curl);
 112                  $curl = str_replace("''", '&#8221;', $curl);
 113  
 114                  $curl = preg_replace('/(d+)x(\d+)/', "$1&#215;$2", $curl);
 115  
 116              } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
 117                  // strstr is fast
 118                  $next = false;
 119              } else {
 120                  $next = true;
 121              }
 122              $output .= $curl;
 123          }
 124          $content = $output;
 125  
 126          return $content;
 127      }
 128  
 129  
 130      /**
 131       * The same as for HTML.
 132       *
 133       * @uses RenderItemAsHtml()
 134       */
 135  	function RenderItemAsXml( & $params )
 136      {
 137          $this->RenderItemAsHtml( $params );
 138      }
 139  }
 140  
 141  ?>

title

Description

title

Description

title

Description

title

title

Body