[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/ -> e_parse_class.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |      Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_handlers/e_parse_class.php,v $
  14  |     $Revision: 1.183 $
  15  |     $Date: 2007/01/24 20:59:23 $
  16  |     $Author: e107steved $
  17  +----------------------------------------------------------------------------+
  18  */
  19  if (!defined('e107_INIT')) { exit; }
  20  
  21  define ("E_NL", chr(2));
  22  class e_parse
  23  {
  24      var $e_sc;
  25      var $e_bb;
  26      var $e_pf;
  27      var $e_emote;
  28      var $e_hook;
  29      var $search = array('&#39;', '&#039;', '&quot;', 'onerror', '&gt;', '&amp;#039;', '&amp;quot;');
  30      var $replace = array("'", "'", '"', 'one<i></i>rror', '>', "'", '"');
  31      var $e_highlighting;        // Set to TRUE or FALSE once it has been calculated
  32      var $e_query;            // Highlight query
  33  
  34          // toHTML Action defaults. For now these match existing convention. 
  35          // Let's reverse the logic on the first set ASAP; too confusing!
  36      var $e_modSet = array();
  37      var    $e_optDefault = array(
  38              'context' => 'olddefault',                // default context: all "opt-out" conversions :(
  39            'fromadmin' => FALSE,
  40  
  41              // Enabled by Default
  42            'value'    => FALSE,                            // Restore entity form of quotes and such to single characters - TRUE disables
  43  
  44            'nobreak' => FALSE,                        // Line break compression - TRUE removes multiple line breaks
  45            'retain_nl' => FALSE,                    // Retain newlines - wraps to \n instead of <br /> if TRUE
  46  
  47            'no_make_clickable' => FALSE,    // URLs etc are clickable - TRUE disables
  48            'no_replace' => FALSE,                // Replace clickable links - TRUE disables (only if no_make_clickable not set)
  49            
  50            'emotes_off' => FALSE,                // Convert emoticons to graphical icons - TRUE disables conversion
  51              'emotes_on'  => FALSE,                // FORCE conversion to emotes, even if syspref is disabled
  52  
  53            'no_hook' => FALSE,                        // Hooked parsers (TRUE disables completely)
  54              
  55              // Disabled by Default
  56              'defs' => FALSE,                            // Convert defines(constants) within text.
  57              'constants' => FALSE,                    // replace all {e_XXX} constants with their e107 value
  58              'parse_sc' => FALSE                        // Parse shortcodes - TRUE enables parsing
  59          );
  60          
  61          // Super modifiers adjust default option values
  62          // First line of adjustments change default-ON options
  63          // Second line changes default-OFF options
  64      var    $e_SuperMods = array(
  65                  'title' =>                //text is part of a title (e.g. news title)
  66                      array( 
  67                          'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
  68                          'defs'=>TRUE,'parse_sc'=>TRUE),
  69  
  70                  'summary' =>            // text is part of the summary of a longer item (e.g. content summary)
  71                      array( 
  72                          // no changes to default-on items
  73                          'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
  74  
  75                  'description' =>    // text is the description of an item (e.g. download, link)
  76                      array( 
  77                          // no changes to default-on items
  78                          'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
  79  
  80                  'body' =>                    // text is 'body' or 'bulk' text (e.g. custom page body, content body)
  81                      array( 
  82                          // no changes to default-on items
  83                          'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
  84  
  85                  'linktext' =>            // text is the 'content' of a link (A tag, etc)
  86                      array( 
  87                          'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
  88                          'defs'=>TRUE,'parse_sc'=>TRUE),
  89  
  90                  'rawtext' =>            // text is used (for admin edit) without fancy conversions
  91                      array( 
  92                          'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
  93                          // leave opt-in options off
  94                          )
  95          );
  96  
  97  	function e_parse()
  98      {
  99          // Preprocess the supermods to be useful default arrays with all values
 100          foreach ($this->e_SuperMods as $key=>$val)
 101          {
 102              $this->e_SuperMods[$key] = array_merge($this->e_optDefault,$this->e_SuperMods[$key]); // precalculate super defaults
 103              $this->e_SuperMods[$key]['context']=$key;
 104          }
 105          foreach ($this->e_optDefault as $key=>$val)
 106          {
 107              $this->e_modSet[$key] = TRUE;
 108          }
 109  
 110      }
 111  
 112  	function toDB($data, $nostrip = false, $no_encode = false, $mod = false)
 113      {
 114          global $pref;
 115          if (is_array($data)) {
 116              // recursively run toDB (for arrays)
 117              foreach ($data as $key => $var) {
 118                  $ret[$key] = $this -> toDB($var, $nostrip, $no_encode);
 119              }
 120          } else {
 121              if (MAGIC_QUOTES_GPC == TRUE && $nostrip == false) {
 122                  $data = stripslashes($data);
 123              }
 124              if(isset($pref['post_html']) && check_class($pref['post_html']))
 125              {
 126                  $no_encode = TRUE;
 127              }
 128              if ($no_encode === TRUE && $mod != 'no_html')
 129              {
 130                  $search = array('$', '"', "'", '\\', '<?');
 131                  $replace = array('&#036;','&quot;','&#039;', '&#092;', '&lt;?');
 132                  $ret = str_replace($search, $replace, $data);
 133              } else {
 134                  $data = htmlspecialchars($data, ENT_QUOTES, CHARSET);
 135                  $data = str_replace('\\', '&#092;', $data);
 136                  $ret = preg_replace("/&amp;#(\d*?);/", "&#\\1;", $data);
 137              }
 138              //If user is not allowed to use [php] change to entities
 139              if(!check_class($pref['php_bbcode']))
 140              {
 141                  $ret = str_replace(array("[php]", "[/php]"), array("&#91;php&#93;", "&#91;/php&#93;"), $ret);
 142              }
 143  
 144          }
 145  
 146          return $ret;
 147      }
 148  
 149  	function toForm($text, $single_quotes = FALSE, $convert_lt_gt = false)
 150      {
 151          if($text == "") { return ""; }
 152          $mode = ($single_quotes ? ENT_QUOTES : ENT_COMPAT);
 153          $search = array('&#036;', '&quot;');
 154          $replace = array('$', '"');
 155          $text = str_replace($search, $replace, $text);
 156          if(e_WYSIWYG !== TRUE){
 157                   $text = str_replace("&nbsp;"," ",$text); // fix for utf-8 issue with html_entity_decode();
 158          }
 159            $text = html_entity_decode($text, $mode, CHARSET);
 160          if($convert_lt_gt)
 161          {
 162              //need to convert < > to entities if this text will be in a textarea, to prevent injection
 163              $text = str_replace(array("<", ">"), array("&lt;", "&gt;"), $text);
 164          }
 165          return $text;
 166      }
 167  
 168  
 169  	function post_toForm($text) {
 170          if (defined("MAGIC_QUOTES_GPC") && (MAGIC_QUOTES_GPC == TRUE)) {
 171              $text = stripslashes($text);
 172          }
 173          // ensure apostrophes are properly converted, or else the form item could break
 174          return str_replace(array( "'", '"'), array("&#039;", "&quot;"), $text);
 175      }
 176  
 177  
 178  	function post_toHTML($text, $modifier = true, $extra = '') {
 179          /*
 180          changes by jalist 30/01/2005:
 181          description had to add modifier to /not/ send formatted text on to this->toHTML at end of method, this was causing problems when MAGIC_QUOTES_GPC == TRUE.
 182          */
 183          global $pref;
 184  
 185          if(isset($pref['post_html']) && check_class($pref['post_html'])) {
 186              $no_encode = true;
 187          }
 188  
 189          if (ADMIN === true || $no_encode === true) {
 190              $search = array('$', '"', "'", '\\', "'&#092;'");
 191              $replace = array('&#036;','&quot;','&#039;','&#092;','&#039;');
 192              $text = str_replace($search, $replace, $text);
 193              /*
 194              changes by jalist 30/01/2005:
 195              description dirty fix for servers with magic_quotes_gpc == true
 196              */
 197              if (MAGIC_QUOTES_GPC) {
 198                  $search = array('&#092;&#092;&#092;&#092;', '&#092;&#039;', '&#092;&quot;');
 199                  $replace = array('&#092;&#092;','&#039;', '&quot;');
 200                  $text = str_replace($search, $replace, $text);
 201              }
 202          } else {
 203  
 204              if (MAGIC_QUOTES_GPC) {
 205                  $text = stripslashes($text);
 206              }
 207                $text = htmlentities($text, ENT_QUOTES, CHARSET);
 208          }
 209  
 210          $text = $this->replaceConstants($text);
 211  
 212          //If user is not allowed to use [php] change to entities
 213          if(!check_class($pref['php_bbcode']))
 214          {
 215              $text = str_replace(array("[php]", "[/php]"), array("&#91;php&#93;", "&#91;/php&#93;"), $text);
 216          }
 217  
 218          return ($modifier ? $this->toHTML($text, true, $extra) : $text);
 219      }
 220  
 221  	function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") {
 222          // Start parse {XXX} codes
 223          if (!is_object($this->e_sc))
 224          {
 225              require_once(e_HANDLER."shortcode_handler.php");
 226              $this->e_sc = new e_shortcode;
 227          }
 228          return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes);
 229          // End parse {XXX} codes
 230      }
 231  
 232  	function htmlwrap($str, $width, $break = "\n", $nobreak = "", $nobr = "pre", $utf = false)
 233      {
 234          /*
 235          * htmlwrap() function - v1.1
 236          * Copyright (c) 2004 Brian Huisman AKA GreyWyvern
 237          * http://www.greywyvern.com/code/php/htmlwrap_1.1.php.txt
 238          *
 239          * This program may be distributed under the terms of the GPL
 240          *   - http://www.gnu.org/licenses/gpl.txt
 241          */
 242  
 243          $content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
 244          $nobreak = explode(" ", $nobreak);
 245          $nobr = explode(" ", $nobr);
 246          $intag = false;
 247          $innbk = array();
 248          $innbr = array();
 249          $drain = "";
 250          $utf = ($utf || CHARSET == 'utf-8') ? "u" : "";
 251          $lbrks = "/?!%)-}]\\\"':;";
 252          if ($break == "\r")
 253          {
 254              $break = "\n";
 255          }
 256          while (list(, $value) = each($content))
 257          {
 258              switch ($value)
 259              {
 260                  case "<": $intag = true; break;
 261                  case ">": $intag = false; break;
 262                  default:
 263                  if ($intag)
 264                  {
 265                      if ($value{0} != "/")
 266                      {
 267                          preg_match('/^(.*?)(\s|$)/'.$utf, $value, $t);
 268                          if ((!count($innbk) && in_array($t[1], $nobreak)) || in_array($t[1], $innbk)) $innbk[] = $t[1];
 269                          if ((!count($innbr) && in_array($t[1], $nobr)) || in_array($t[1], $innbr)) $innbr[] = $t[1];
 270                      } else {
 271                          if (in_array(substr($value, 1), $innbk)) unset($innbk[count($innbk)]);
 272                          if (in_array(substr($value, 1), $innbr)) unset($innbr[count($innbr)]);
 273                      }
 274                  } else if ($value)
 275                  {
 276                      if (!count($innbr)) $value = str_replace("\n", "\r", str_replace("\r", "", $value));
 277                      if (!count($innbk))
 278                      {
 279                          do
 280                          {
 281                              $store = $value;
 282                              if (preg_match("/^(.*?\s|^)(([^\s&]|&(\w{2,5}|#\d{2,4});){".$width."})(?!(".preg_quote($break, "/").'|\s))(.*)$/s'.$utf, $value, $match))
 283                              {
 284                                  for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x}));
 285                                  if (!$ledge) $ledge = strlen($match[2]) - 1;
 286                                  $value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[6];
 287                              }
 288                          }
 289                          while ($store != $value);
 290                      }
 291                      if (!count($innbr)) $value = str_replace("\r", E_NL, $value);
 292                  }
 293              }
 294              $drain .= $value;
 295          }
 296          return $drain;
 297      }
 298  
 299  	function html_truncate ($text, $len = 200, $more = "[more]")
 300      {
 301          $pos = 0;
 302          $curlen = 0;
 303          $tmp_pos = 0;
 304          while($curlen < $len && $curlen < strlen($text))
 305          {
 306              switch($text{$pos})
 307              {
 308                  case "<" :
 309                  if($text{$pos+1} == "/")
 310                  {
 311                      $closing_tag = TRUE;
 312                  }
 313                  $intag = TRUE;
 314                  $tmp_pos = $pos-1;
 315                  $pos++;
 316                  break;
 317                  case ">" :
 318                  if($text{$pos-1} == "/")
 319                  {
 320                      $closing_tag = TRUE;
 321                  }
 322                  if($closing_tag == TRUE)
 323                  {
 324                      $tmp_pos = 0;
 325                      $closing_tag = FALSE;
 326                  }
 327                  $intag = FALSE;
 328                  $pos++;
 329                  break;
 330                  case "&" :
 331                  if($text{$pos+1} == "#")
 332                  {
 333                      $end = strpos(substr($text, $pos, 7), ";");
 334                      if($end !== FALSE)
 335                      {
 336                          $pos+=($end+1);
 337                          if(!$intag) {$curlen++;}
 338                          break;
 339                      }
 340                  }
 341                  else
 342                  {
 343                      $pos++;
 344                      if(!$intag) {$curlen++;}
 345                      break;
 346                  }
 347                  default:
 348                  $pos++;
 349                  if(!$intag) {$curlen++;}
 350                  break;
 351              }
 352          }
 353          $ret = ($tmp_pos > 0 ? substr($text, 0, $tmp_pos) : substr($text, 0, $pos));
 354          if($pos < strlen($text))
 355          {
 356              $ret = $ret.$more;
 357          }
 358          return $ret;
 359      }
 360  
 361  	function text_truncate($text, $len = 200, $more = "[more]") {
 362          if(strlen($text) <= $len) {
 363              return $text;
 364          } else { // utf-8 compatible substr()
 365              return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.
 366                      '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
 367                      '$1',$text).$more;
 368          }
 369      }
 370  
 371  	function textclean ($text, $wrap=100)
 372      {
 373          $text = str_replace ("\n\n\n", "\n\n", $text);
 374          $text = $this -> htmlwrap($text, $wrap);
 375          $text = str_replace (array ("<br /> ", " <br />", " <br /> "), "<br />", $text);
 376          /* we can remove any linebreaks added by htmlwrap function as any \n's will be converted later anyway */
 377          return $text;
 378      }
 379  
 380      //
 381      // Test for text highlighting, and determine the text highlighting transformation
 382      // Returns TRUE if highlighting is active for this page display
 383      //
 384  	function checkHighlighting()
 385      {
 386          global $pref;
 387  
 388          if (!defined('e_SELF'))
 389          {
 390              return FALSE;    // Still in startup, so can't calculate highlighting
 391          }
 392  
 393          if (!isset($this->e_highlighting))
 394          {
 395              $this->e_highlighting = FALSE;
 396              $shr = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
 397              if ($pref['search_highlight'] && (strpos(e_SELF, 'search.php') === FALSE) && ((strpos($shr, 'q=') !== FALSE) || (strpos($shr, 'p=') !== FALSE)))
 398              {
 399                  $this->e_highlighting = TRUE;
 400                  if (!isset($this -> e_query))
 401                  {
 402                      $query = preg_match('#(q|p)=(.*?)(&|$)#', $shr, $matches);
 403                      $this -> e_query = str_replace(array('+', '*', '"', ' '), array('', '.*?', '', '\b|\b'), trim(urldecode($matches[2])));
 404                  }
 405              }
 406          }
 407          return $this->e_highlighting;
 408      }
 409  
 410  	function toHTML($text, $parseBB = FALSE, $modifiers = "", $postID = "", $wrap=FALSE) {
 411          if ($text == '')
 412          {
 413              return $text;
 414          }
 415          global $pref, $fromadmin;
 416          
 417          // 
 418          // SET MODIFIERS
 419          //
 420          
 421          // Get modifier strings for toHTML
 422          // "super" modifiers set a baseline. Recommend entering in UPPER CASE to highlight
 423          // other modifiers override
 424          // modifiers SHOULD be delimited with commas (eventually this will be 'MUST')
 425          // modifiers MAY have spaces in between as desired
 426  
 427          $opts = $this->e_optDefault;
 428          if (strlen($modifiers)) 
 429          {
 430              //
 431              // Yes, the following code is strangely-written. It is one of the MOST used bits in
 432              // all of e107. We "inlined" the assignments to optimize speed through 
 433              // some careful testing (19 Jan 2007).
 434              //
 435              // Some alternatives that do NOT speed things up (they make it slower)
 436              //  - use of array_intersect, array_walk, preg_replace, intermediate variables, etc etc etc.
 437              //            
 438      
 439              if (1) // php 4 code
 440              {
 441                  $opts = $this->e_optDefault;
 442                  $aMods = explode( ',',
 443                                          // convert blanks to comma, then comma-comma (from blank-comma) to single comma
 444                                          str_replace(array(' ', ',,'),    array(',', ',' ), 
 445                                              // work with all lower case
 446                                              strtolower($modifiers) 
 447                                          )
 448          );
 449  
 450                  foreach ($aMods as $mod)
 451          {
 452                    if (isset($this->e_SuperMods[$mod]))
 453                    {    
 454                        $opts = $this->e_SuperMods[$mod];  
 455                    }
 456          }
 457  
 458                  // Find any regular mods
 459                  foreach ($aMods as $mod)
 460                  {
 461                    $opts[$mod] = TRUE;  // Change mods as spec'd
 462                  }
 463              }
 464              if (0) // php 5 code - not tested, and may not be faster anyway
 465              {
 466                  $aMods = array_flip(
 467                                      explode( ',',
 468                                          // convert blanks to comma, then comma-comma (from blank-comma) to single comma
 469                                          str_replace(array(' ', ',,'),    array(',', ',' ), 
 470                                              // work with all lower case
 471                                              strtolower($modifiers) 
 472                                          )
 473                                      )
 474                                   );
 475                  $opts = array_merge($opts, array_intersect_key($this->e_SuperMods,$aMods)); // merge in any supermods found
 476                  $opts = array_merge($opts, array_intersect_key($this->modSet, $aMods)); // merge in any other mods found
 477              }
 478          }
 479      
 480  //        $fromadmin = strpos($modifiers, "fromadmin");
 481          $fromadmin = $opts['fromadmin'];
 482  
 483          // Convert defines(constants) within text. eg. Lan_XXXX - must be the entire text string (i.e. not embedded)
 484  //        if(strpos($modifiers,"defs") !== FALSE && strlen($text) < 25 && defined(trim($text)))
 485          if ($opts['defs'] && (strlen($text) < 25) && defined(trim($text)))
 486          {
 487  //           echo "Modifiers: ".$modifiers."<br />";
 488              return constant(trim($text));
 489          }
 490  
 491  
 492          // replace all {e_XXX} constants with their e107 value
 493  //        if(strpos($modifiers, "constants") !== FALSE)
 494          if ($opts['constants'])
 495          {
 496              $text = $this->replaceConstants($text);
 497          }
 498  
 499  
 500         if(!$wrap && $pref['main_wordwrap']) $wrap = $pref['main_wordwrap'];
 501          $text = " ".$text;
 502  
 503  
 504              // Prepare for line-break compression. Avoid compressing newlines in embedded scripts and CSS
 505  //        if (strpos($modifiers, 'nobreak') === FALSE) 
 506          if (!$opts['nobreak'])
 507          {
 508              $text = preg_replace("#>\s*[\r]*\n[\r]*#", ">", $text);
 509              preg_match_all("#<(script|style)[^>]+>.*?</(script|style)>#is", $text, $embeds);
 510              $text = preg_replace("#<(script|style)[^>]+>.*?</(script|style)>#is", "<|>", $text);
 511          }
 512  
 513  
 514              // Convert URL's to clickable links, unless modifiers or prefs override
 515  //        if($pref['make_clickable'] && strpos($modifiers, 'no_make_clickable') === FALSE) 
 516          if ($pref['make_clickable'] && !$opts['no_make_clickable']) 
 517          {
 518  //            if($pref['link_replace'] && strpos($modifiers, 'no_replace') === FALSE) 
 519              if ($pref['link_replace'] && !$opts['no_replace']) 
 520              {
 521                  $_ext = ($pref['links_new_window'] ? " rel=\"external\"" : "");
 522                  $text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
 523                  $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
 524                  if(CHARSET != "utf-8" && CHARSET != "UTF-8"){
 525                      $email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2&copy;\\3";
 526                  }else{
 527                      $email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2©\\3";
 528                  }
 529                  $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a rel='external' href='javascript:window.location=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\";self.close();' onmouseover='window.status=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\"; return true;' onmouseout='window.status=\"\";return true;'>".$email_text."</a>", $text);
 530              }
 531              else 
 532              {
 533                  $text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1<a href=\"\\2\" rel=\"external\">\\2</a>", $text);
 534                  $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<,]*)#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $text);
 535                  $text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a rel='external' href='javascript:window.location=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\";self.close();' onmouseover='window.status=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\"; return true;' onmouseout='window.status=\"\";return true;'>-email-</a>", $text);
 536              }
 537          }
 538  
 539  
 540              // Convert emoticons to graphical icons, unless modifiers override
 541  //        if (strpos($modifiers, 'emotes_off') === FALSE) {
 542          if (!$opts['emotes_off']) 
 543          {
 544  //            if ($pref['smiley_activate'] || strpos($modifiers,'emotes_on') !== FALSE) {
 545              if ($pref['smiley_activate'] || $opts['emotes_on']) 
 546              {
 547                  if (!is_object($this->e_emote)) {
 548                      require_once(e_HANDLER.'emote_filter.php');
 549                      $this->e_emote = new e_emoteFilter;
 550                  }
 551                  $text = $this->e_emote->filterEmotes($text);
 552              }
 553          }
 554  
 555  
 556              // Reduce multiple newlines in all forms to a single newline character, except for embedded scripts and CSS
 557  //        if (strpos($modifiers, 'nobreak') === FALSE) {
 558          if (!$opts['nobreak']) 
 559          {
 560              $text = preg_replace("#[\r]*\n[\r]*#", E_NL, $text);
 561              foreach ($embeds[0] as $embed) {
 562                  $text = preg_replace("#<\|>#", $embed, $text, 1);
 563              }
 564          }
 565  
 566  
 567          // Restore entity form of quotes and such to single characters, except for text destined for tag attributes or JS.
 568  //        if (strpos($modifiers, 'value') === FALSE) { // output not used for attribute values.
 569          if (!$opts['value']) 
 570          { // output not used for attribute values.
 571                 $text = str_replace($this -> search, $this -> replace, $text);
 572          }
 573          else
 574          {                                       // output used for attribute values.
 575              $text = str_replace($this -> replace, $this -> search, $text);
 576          }
 577  
 578  
 579          // Start parse [bb][/bb] codes
 580          if ($parseBB === TRUE) 
 581          {
 582              if (!is_object($this->e_bb)) {
 583                  require_once(e_HANDLER.'bbcode_handler.php');
 584                  $this->e_bb = new e_bbcode;
 585              }
 586              $text = $this->e_bb->parseBBCodes($text, $postID);
 587          }
 588          // End parse [bb][/bb] codes
 589  
 590  
 591          // profanity filter
 592          if ($pref['profanity_filter']) {
 593              if (!is_object($this->e_pf)) {
 594                  require_once(e_HANDLER."profanity_filter.php");
 595                  $this->e_pf = new e_profanityFilter;
 596              }
 597              $text = $this->e_pf->filterProfanities($text);
 598          }
 599  
 600  
 601              // Optional short-code conversion
 602  //        if (strpos($modifiers,'parse_sc') !== FALSE)
 603          if ($opts['parse_sc'])
 604          {
 605              $text = $this->parseTemplate($text, TRUE);
 606          }
 607  
 608  
 609          //Run any hooked in parsers
 610          if (!$opts['no_hook'] && varset($pref['tohtml_hook']))
 611          {
 612            foreach(explode(",",$pref['tohtml_hook']) as $hook)
 613            {
 614              if (!is_object($this->e_hook[$hook]))
 615              {
 616                require_once(e_PLUGIN.$hook."/".$hook.".php");
 617                $hook_class = "e_".$hook;
 618                $this->e_hook[$hook] = new $hook_class;
 619              }
 620            $text = $this->e_hook[$hook]->$hook($text,$opts['context']);
 621            }
 622          }
 623  
 624  
 625  //        if (strpos($modifiers, 'nobreak') === FALSE) 
 626          if (!$opts['nobreak']) 
 627          {
 628              $text = $this -> textclean($text, $wrap);
 629          }
 630  
 631  
 632          // Search Highlight
 633  //        if (strpos($modifiers, 'emotes_off') === FALSE) 
 634          if (!$opts['emotes_off']) 
 635          {
 636            if ($this->checkHighlighting())
 637            {
 638              $text = $this -> e_highlight($text, $this -> e_query);
 639            }
 640          }
 641  
 642  
 643          $nl_replace = "<br />";
 644  //        if (strpos($modifiers, 'nobreak') !== FALSE)
 645          if ($opts['nobreak'])
 646          {
 647              $nl_replace = '';
 648          }
 649  //        elseif (strpos($modifiers, 'retain_nl') !== FALSE)
 650          elseif ($opts['retain_nl'])
 651          {
 652              $nl_replace = "\n";
 653          }
 654          $text = str_replace(E_NL, $nl_replace, $text);
 655  
 656          return trim($text);
 657      }
 658  
 659  
 660  	function toAttribute($text) {
 661          $text = str_replace("&amp;","&",$text); // URLs posted without HTML access may have an &amp; in them.
 662          $text = htmlspecialchars($text); // Xhtml compliance.
 663          if (!preg_match('/&#|\'|"|\(|\)|<|>/s', $text)) {
 664              $text = $this->replaceConstants($text);
 665              return $text;
 666          } else {
 667              return '';
 668          }
 669      }
 670  
 671  	function toJS($stringarray) {
 672          $search = array("\r\n","\r","<br />","'");
 673          $replace = array("\\n","","\\n","\'");
 674          $stringarray = str_replace($search, $replace, $stringarray);
 675          $stringarray = strip_tags($stringarray);
 676  
 677          $trans_tbl = get_html_translation_table (HTML_ENTITIES);
 678          $trans_tbl = array_flip ($trans_tbl);
 679  
 680          return strtr ($stringarray, $trans_tbl);
 681      }
 682  
 683  	function toRss($text,$tags=FALSE)
 684      {
 685  
 686          if($tags != TRUE)
 687          {
 688              $text = $this -> toHTML($text,TRUE);
 689              $text = strip_tags($text);
 690          }
 691  
 692          $text = $this->toEmail($text);
 693             $search = array("&amp;#039;", "&amp;#036;", "&#039;", "&#036;"," & ", e_BASE, "href='request.php");
 694             $replace = array("'", '$', "'", '$',' &amp; ', SITEURL, "href='".SITEURL."request.php" );
 695             $text = str_replace($search, $replace, $text);
 696  
 697          if($tags == TRUE && ($text))
 698          {
 699              $text = "<![CDATA[".$text."]]>";
 700          }
 701  
 702          return $text;
 703      }
 704  
 705      //Convert specific characters back to original form, for use in storing code (or regex) values in the db.
 706  	function toText($text)
 707      {
 708          $search = array("&amp;#039;", "&amp;#036;", "&#039;", "&#036;", "&#092;", "&amp;#092;");
 709          $replace = array("'", '$', "'", '$', "\\", "\\");
 710          $text = str_replace($search, $replace, $text);
 711          return $text;
 712      }
 713  
 714  //
 715  // $nonrelative:
 716  //   "full" = produce absolute URL path, e.g. http://sitename.com/e107_plugins/etc
 717  //   TRUE = produce truncated URL path, e.g. e107plugins/etc
 718  //   "" (default) = URL's get relative path e.g. ../e107_plugins/etc
 719  //
 720  // $all - if TRUE, then
 721  //        when $nonrelative is "full" or TRUE, USERID is also replaced...
 722  //        when $nonrelative is "" (default), ALL other e107 constants are replaced
 723  //
 724  // only an ADMIN user can convert {e_ADMIN}
 725  //
 726  	function replaceConstants($text, $nonrelative = "", $all = false)
 727      {
 728          if($nonrelative != "")
 729          {
 730              global $IMAGES_DIRECTORY, $PLUGINS_DIRECTORY, $FILES_DIRECTORY, $THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY,$ADMIN_DIRECTORY;
 731              $replace_relative = array("",$IMAGES_DIRECTORY,$PLUGINS_DIRECTORY,$FILES_DIRECTORY,$THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY);
 732              $replace_absolute = array(SITEURL,SITEURL.$IMAGES_DIRECTORY,SITEURL.$PLUGINS_DIRECTORY,SITEURL.$FILES_DIRECTORY,SITEURL.$THEMES_DIRECTORY,SITEURL.$DOWNLOADS_DIRECTORY);
 733              $search = array("{e_BASE}","{e_IMAGE}","{e_PLUGIN}","{e_FILE}","{e_THEME}","{e_DOWNLOAD}");
 734              if (ADMIN) {
 735                  $replace_relative[] = $ADMIN_DIRECTORY;
 736                  $replace_absolute[] = SITEURL.$ADMIN_DIRECTORY;
 737                  $search[] = "{e_ADMIN}";
 738              }
 739              if ($all) {
 740                  $replace_relative[] = USERID;
 741                  $replace_absolute[] = USERID;
 742                  $search[] = "{USERID}";
 743              }
 744              $replace = ((string)$nonrelative == "full" ) ? $replace_absolute : $replace_relative;
 745              return str_replace($search,$replace,$text);
 746          }
 747          $pattern = ($all ? "#\{([A-Za-z_0-9]*)\}#s" : "#\{(e_[A-Z]*)\}#s");
 748           $text = preg_replace_callback($pattern, array($this, 'doReplace'), $text);
 749          $theme_path = (defined("THEME")) ? constant("THEME") : "";
 750          $text = str_replace("{THEME}",$theme_path,$text);
 751  
 752          return $text;
 753      }
 754  
 755  	function doReplace($matches)
 756      {
 757          if(defined($matches[1]) && ($matches[1] != 'e_ADMIN' || ADMIN))
 758          {
 759              return constant($matches[1]);
 760          }
 761          return $matches[1];
 762      }
 763  
 764      function createConstants($url,$mode=0){
 765          global $IMAGES_DIRECTORY,$PLUGINS_DIRECTORY,$FILES_DIRECTORY,$THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY,$ADMIN_DIRECTORY;
 766  
 767          if($mode == 0) // folder name only.
 768          {
 769              $tmp = array(
 770                  "{"."e_IMAGE"."}"=>$IMAGES_DIRECTORY,
 771                  "{"."e_PLUGIN"."}"=>$PLUGINS_DIRECTORY,
 772                  "{"."e_FILE"."}"=>$FILES_DIRECTORY,
 773                  "{"."e_THEME"."}"=>$THEMES_DIRECTORY,
 774                  "{"."e_DOWNLOAD"."}"=>$DOWNLOADS_DIRECTORY,
 775                  "{"."e_ADMIN"."}"=>$ADMIN_DIRECTORY,
 776                );
 777          }
 778          elseif($mode == 1)  // relative path
 779          {
 780              $tmp = array(
 781                  "{"."e_IMAGE"."}"=>e_IMAGE,
 782                  "{"."e_PLUGIN"."}"=>e_PLUGIN,
 783                  "{"."e_FILE"."}"=>e_FILE,
 784                  "{"."e_THEME"."}"=>e_THEME,
 785                  "{"."e_DOWNLOAD"."}"=>e_DOWNLOAD,
 786                  "{"."e_ADMIN"."}"=>e_ADMIN
 787              );
 788          }
 789          foreach($tmp as $key=>$val)
 790          {
 791              $len = strlen($val);
 792              if(substr($url,0,$len) == $val)
 793              {
 794                  return substr_replace($url,$key,0,$len); // replace the first instance only
 795              }
 796          }
 797  
 798          return $url;
 799      }
 800  
 801  
 802  	function e_highlight($text, $match) {
 803          preg_match_all("#<[^>]+>#", $text, $tags);
 804          $text = preg_replace("#<[^>]+>#", "<|>", $text);
 805          $text = preg_replace("#(\b".$match."\b)#i", "<span class='searchhighlight'>\\1</span>", $text);
 806          foreach ($tags[0] as $tag) {
 807              $text = preg_replace("#<\|>#", $tag, $text, 1);
 808          }
 809          return $text;
 810      }
 811  
 812      function toEmail($text,$posted="")
 813      {
 814          if ($posted === TRUE && MAGIC_QUOTES_GPC) {
 815              $text = stripslashes($text);
 816          }
 817  
 818            $text = $this->replaceConstants($text,"full");
 819          $text = $this->toHTML($text,TRUE,"parse_sc, no_make_clickable");
 820          return $text;
 821      }
 822  
 823  }
 824  
 825  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7