Beispiel #1
0
[url]https://securesite.com[/url]
[url]ftp://ftpsite.com[/url]
[url]irc://ircsite.com[/url]
[url]telnet://telnetsite.com[/url]
[url="http://domain.com"]Linked URL[/url]

Valid websites (auto-linked with hook):
http://domain.com
http://sub.domain.com/?with=param
http://user:pass@domain.com:80/?with=param

Invalid websites:
[url]domain.com[/url]
[url]www.domain.com[/url]
[url]wtf://unsupportedprotocol.com/[/url]';
$code->reset($string);
echo $code->parse();
?>

<h2>Link</h2>

<?php 
$string = 'Valid websites:
[link]http://domain.com[/link]
[link]https://securesite.com[/link]
[link]ftp://ftpsite.com[/link]
[link]irc://ircsite.com[/link]
[link]telnet://telnetsite.com[/link]
[link="http://domain.com"]Linked URL[/link]

Valid websites (auto-linked with hook):
 /**
  * @static
  * @param string $text
  * @param bool $allow_html
  * @return string
  */
 static function bbcode2html($text, $allow_html = false)
 {
     $debug = false;
     /*
     $text = preg_replace_callback("/(\[quote[^\]]*\])(.*)(\[\/o?quote\])/siuU", function ($matches) {
     	$first_open  = mb_stripos($matches[2], "[LIST");
     	$first_close = mb_stripos($matches[2], "[/LIST]");
     
     	if ($first_close !== false && ($first_open === false || $first_close < $first_open)) $matches[2] = trim(mb_substr($matches[2], 0, $first_close) . "\n" . mb_substr($matches[2], $first_close + 7));
     	return $matches[1] . $matches[2] . $matches[3];
     }, $text);
     */
     if ($debug) {
         //require_once("/var/www/antragsgruen-v2/vendor/mjohnson/decoda/examples/list.php");
         echo "<br>IN========<br>";
         echo CHtml::encode($text);
     }
     $text = preg_replace_callback("/(\\[quote[^\\]]*\\])(.*)(\\[\\/o?quote\\])/siuU", function ($matches) {
         if (mb_stripos($matches[2], "[li]") === false && mb_stripos($matches[2], "[*]") === false) {
             return $matches[1] . $matches[2] . $matches[3];
         }
         if (mb_stripos($matches[2], "[list]") === false) {
             return "[list]\n[*]" . $matches[2] . "\n[/list]";
         } else {
             return $matches[2];
         }
     }, $text);
     $text = preg_replace_callback("/(\\[o?list[^\\]]*\\])(.*)(\\[\\/o?list\\])/siuU", function ($matches) use($debug) {
         $parts = explode("[*]", trim($matches[2]));
         $str = $matches[1];
         foreach ($parts as $part) {
             if ($part != "") {
                 $str .= "[LI]" . trim($part) . "[/LI]";
             }
         }
         $str .= $matches[3];
         return $str;
     }, $text);
     $text = preg_replace_callback("/(?<pre>\\[url=)(?<url>[^\"\\]]+)(?<post>\\])/siu", function ($matches) {
         return $matches["pre"] . "\"" . $matches["url"] . "\"" . $matches["post"];
     }, $text);
     $code = new \Decoda\Decoda();
     $code->setEscaping(!$allow_html);
     $code->addFilter(new AntraegeBBCodeFilter());
     $code->addFilter(new \Decoda\Filter\UrlFilter());
     if ($debug) {
         //require_once("/var/www/antragsgruen-v2/vendor/mjohnson/decoda/examples/list.php");
         echo "<br>IN========<br>";
         echo CHtml::encode($text);
     }
     $code->reset($text);
     $text = $code->parse();
     if ($debug) {
         echo "<br>OUT========<br>";
         echo CHtml::encode($text);
     }
     $text = str_replace("<br>\n", "<br>", $text);
     $text = str_replace("\n", "<br>", $text);
     $text = preg_replace("/<br *\\/>/siu", "<br>", $text);
     $text = preg_replace("/<ul>[<br>\\n]*<li>/siu", "<ul>\n<li>", $text);
     $text = preg_replace("/<\\/li>[<br>\\n]*<li>/siu", "</li>\n<li>", $text);
     $text = preg_replace("/<\\/li>[<br>\\n]*<\\/ul>/siu", "</li>\n</ul>", $text);
     return $text;
 }