[ PHPXref.com ] [ Generated: Sun Jul 20 16:35:25 2008 ] [ bBlog 0.7.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/bblog/bBlog_plugins/ -> modifier.texturize.php (source)

   1  <?php
   2  // by photomatt : http://photomatt.net/tools/texturize
   3  function identify_modifier_texturize () {
   4    return array (
   5      'name'           =>'texturize',
   6      'type'           =>'modifier',
   7      'nicename'       =>'Texturize',
   8      'description'    =>'Makes quotes curly',
   9      'authors'         =>'photomatt',
  10      'licence'         =>'GPL',
  11      'help'            => '<p>See <A href="http://photomatt.net/tools/texturize">http://photomatt.net/tools/texturize</a>'
  12    );
  13  }
  14  
  15  function smarty_modifier_texturize($text) {
  16      $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
  17      $stop = count($textarr); $next = true; // loop stuff
  18      for ($i = 0; $i < $stop; $i++) {
  19          $curl = $textarr[$i];
  20          if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
  21              $curl = str_replace('<q>', '&#8220;', $curl);
  22              $curl = str_replace('</q>', '&#8221;', $curl);
  23          }
  24          if ('<' != $curl{0} && $next) { // If it's not a tag
  25              $curl = str_replace('---', '&#8212;', $curl);
  26              $curl = str_replace('--', '&#8211;', $curl);
  27              $curl = str_replace("...", '&#8230;', $curl);
  28              $curl = str_replace('``', '&#8220;', $curl);
  29  
  30              // This is a hack, look at this more later. It works pretty well though.
  31              $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round", "'em");
  32              $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round","&#8217;em");
  33              $curl = str_replace($cockney, $cockneyreplace, $curl);
  34  
  35  
  36              $curl = preg_replace("/'s/", "&#8217;s", $curl);
  37              $curl = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#8217;$1", $curl);
  38              $curl = preg_replace('/(\s|\A|")\'/', '$1&#8216;', $curl);
  39              $curl = preg_replace("/(\d+)\"/", "$1&Prime;", $curl);
  40              $curl = preg_replace("/(\d+)'/", "$1&prime;", $curl);
  41              $curl = preg_replace("/(\S)'([^'\s])/", "$1&#8217;$2", $curl);
  42              $curl = preg_replace('/"([\s.]|\Z)/', '&#8221;$1', $curl);
  43              $curl = preg_replace('/(\s|\A)"/', '$1&#8220;', $curl);
  44              $curl = preg_replace("/'([\s.]|\Z)/", '&#8217;$1', $curl);
  45              $curl = preg_replace("/\(tm\)/i", '&#8482;', $curl);
  46              $curl = preg_replace("/\(c\)/i", '&#169;', $curl);
  47              $curl = preg_replace("/\(r\)/i", '&#174;', $curl);
  48  
  49              $curl = str_replace("''", '&#8221;', $curl);
  50              $curl = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $curl);
  51  
  52              $curl = preg_replace('/(d+)x(\d+)/', "$1&#215;$2", $curl);
  53  
  54          } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
  55              // strstr is fast
  56              $next = false;
  57          } else {
  58              $next = true;
  59          }
  60          $output .= $curl;
  61      }
  62  
  63      return $output;
  64  
  65  }
  66  
  67  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]