[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/mods/bbcode/ -> bbcode.php (source)

   1  <?php
   2  
   3  if(!defined("PHORUM")) return;
   4  
   5  // BB Code Phorum Mod
   6  function phorum_bb_code($data)
   7  {
   8      $PHORUM = $GLOBALS["PHORUM"];
   9  
  10      $search = array(
  11          "/\[img\]((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\[\/img\]/is",
  12          "/\[url\]((http|https|ftp|mailto):\/\/([a-z0-9\.\-@:]+)[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),\#%~ ]*?)\[\/url\]/is",
  13          "/\[url=((http|https|ftp|mailto):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\](.+?)\[\/url\]/is",
  14          "/\[email\]([a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+?)\[\/email\]/ies",
  15          "/\[color=([\#a-z0-9]+?)\](.+?)\[\/color\]/is",
  16          "/\[size=([+\-\da-z]+?)\](.+?)\[\/size\]/is",
  17          "/\[b\](.+?)\[\/b\]/is",
  18          "/\[u\](.+?)\[\/u\]/is",
  19          "/\[i\](.+?)\[\/i\]/is",
  20          "/\[s\](.+?)\[\/s\]/is",
  21          "/\[center\](.+?)\[\/center\]/is",
  22          "/\[hr\]/i",
  23          "/\[code\](.+?)\[\/code\]/is",
  24          "/\[sub\](.+?)\[\/sub\]/is",
  25          "/\[sup\](.+?)\[\/sup\]/is",
  26      );
  27  
  28      // add extra tags to links, if enabled in the admin settings page
  29  
  30      $extra_link_tags = "";
  31  
  32      if(isset($PHORUM["mod_bb_code"])){ // check for settings file before using settings-dependent variables
  33          if ($PHORUM["mod_bb_code"]["links_in_new_window"]){
  34              $extra_link_tags .= "target=\"_blank\" ";
  35          }
  36          if ($PHORUM["mod_bb_code"]["rel_no_follow"]){
  37              $extra_link_tags .= "rel=\"nofollow\" ";
  38          }
  39      }
  40  
  41      $replace = array(
  42          "<img src=\"$1\" border=\"0\" alt=\"$1\" />",
  43          "[<a $extra_link_tags href=\"$1\">$3</a>]",
  44          "<a $extra_link_tags href=\"$1\">$3</a>",
  45          "'<a $extra_link_tags href=\"'.phorum_html_encode('mailto:$1').'\">'.phorum_html_encode('$1').'</a>'",
  46          "<span style=\"color: $1\">$2</span>",
  47          "<span style=\"font-size: $1\">$2</span>",
  48          "<strong>$1</strong>",
  49          "<u>$1</u>",
  50          "<i>$1</i>",
  51          "<s>$1</s>",
  52          "<center class=\"bbcode\">$1</center>",
  53          "<hr class=\"bbcode\" />",
  54          "<pre class=\"bbcode\">$1</pre>",
  55          "<sub class=\"bbcode\">$1</sub>",
  56          "<sup class=\"bbcode\">$1</sup>",
  57      );
  58  
  59      $quote_search = array(
  60          "/\[quote\]/is",
  61          "/\[quote ([^\]]+?)\]/is",
  62          "/\[quote=([^\]]+?)\]/is",
  63          "/\[\/quote\]/is"
  64      );
  65  
  66      $quote_replace = array(
  67          "<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div>",
  68          "<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
  69          "<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
  70          "</div></blockquote>"
  71      );
  72  
  73      foreach($data as $message_id => $message){
  74  
  75          if(isset($message["body"])){
  76  
  77              // do BB Code here
  78              $body = $message["body"];
  79  
  80              $rnd=substr(md5($body.time()), 0, 4);
  81  
  82              // convert bare urls into bbcode tags as best we can
  83              // the haystack has to have a space in front of it for the preg to work.
  84              $body = preg_replace("/([^='\"(\[url\]|\[img\])])((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%#]+)/i", "$1:$rnd:$2:/$rnd:", " $body");
  85  
  86              // stip puncuation from urls
  87              if(preg_match_all("!:$rnd:(.+?):/$rnd:!i", $body, $match)){
  88  
  89                  $urls = array_unique($match[1]);
  90  
  91                  foreach($urls as $key => $url){
  92                      // stip puncuation from urls
  93                      if(preg_match("|[^a-z0-9=&/\+_]+$|i", $url, $match)){
  94  
  95                          $extra = $match[0];
  96                          $true_url = substr($url, 0, -1 * (strlen($match[0])));
  97  
  98                          $body = str_replace("$url:/$rnd:", "$true_url:/$rnd:$extra", $body);
  99  
 100                          $url = $true_url;
 101                      }
 102  
 103                      $body = str_replace(":$rnd:$url:/$rnd:", "[url]{$url}[/url]", $body);
 104                  }
 105  
 106              }
 107  
 108              // convert bare email addresses into bbcode tags as best we can.
 109              $body = preg_replace("/(^|[\s])([a-z0-9][a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+[a-z0-9])([\?\!\.,;:\s]|$)/i", "$1[email]$2[/email]$3", $body);
 110  
 111              // no sense doing any of this if there is no [ in the body
 112              if(strstr($body, "[")){
 113  
 114                  // clean up any BB code we stepped on.
 115                  // Most probably not needed anymore, due to some changes in
 116                  // the above code (introduced $1 and $3 to match the 
 117                  // surroundings of the email address).
 118                  //$body = str_replace("[email][email]", "[email]", $body);
 119                  //$body = str_replace("[/email][/email]", "[/email]", $body);
 120  
 121                  // fiddle with white space around quote and code tags.
 122                  $body=preg_replace("/\s*(\[\/*(code|quote)\])\s*/", "$1", $body);
 123  
 124                  // run the pregs defined above
 125                  $body = preg_replace($search, $replace, $body);
 126  
 127                  // quote has to be handled differently because they can be embedded.
 128                  // we only do quote replacement if we have matching start and end tags
 129                  if(preg_match_all('/\[quote([\s=][^\]]+?)?\]/', $body, $m) && count($m[0])==substr_count($body, "[/quote]")){
 130                      $body = preg_replace($quote_search, $quote_replace, $body);
 131                  }
 132              }
 133  
 134  
 135              $data[$message_id]["body"] = $body;
 136          }
 137      }
 138  
 139      return $data;
 140  }
 141  
 142  
 143  function phorum_bb_code_quote ($array)
 144  {
 145      $PHORUM = $GLOBALS["PHORUM"];
 146  
 147      if(isset($PHORUM["mod_bb_code"]) && $PHORUM["mod_bb_code"]["quote_hook"]){
 148          return "[quote $array[0]]$array[1][/quote]";
 149      } else {
 150          return $array;
 151      }
 152  }
 153  ?>


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics