Beispiel #1
0
 /**
  * Parse le content et retourne du HTML valide
  *
  */
 public function getContentHtml()
 {
     $code = new Decoda\Decoda($this->content);
     $code->defaults();
     $code->setXhtml(false);
     $code->setStrict(false);
     $code->setLineBreaks(true);
     return $code->parse();
 }
Beispiel #2
0
 /**
  * Affiche le contenue 
  *
  * @access public
  * @return HTML
  */
 public function getPreview()
 {
     $code = new Decoda\Decoda(Input::get('content'));
     $code->defaults();
     $code->setXhtml(false);
     $code->setStrict(false);
     $code->setLineBreaks(true);
     return $code->parse();
 }
Beispiel #3
0
 public function filter($text)
 {
     $config = array('escapeHtml' => false);
     $decoda = new Decoda\Decoda($text, $config);
     $decoda->setStrict(false);
     // $decoda->defaults();
     $decoda->addFilter(new \Decoda\Filter\DefaultFilter());
     $decoda->addFilter(new \Decoda\Filter\EmailFilter());
     $decoda->addFilter(new \Decoda\Filter\ImageFilter());
     $decoda->addFilter(new \Decoda\Filter\UrlFilter());
     $decoda->addFilter(new \Decoda\Filter\TextFilter());
     $decoda->addFilter(new \Decoda\Filter\VideoFilter());
     $decoda->addFilter(new \Decoda\Filter\CodeFilter());
     $decoda->addFilter(new \Decoda\Filter\QuoteFilter());
     $decoda->addFilter(new \Decoda\Filter\ListFilter());
     $decoda->addFilter(new \Decoda\Filter\TableFilter());
     $decoda->addFilter(new ComForumsBlock());
     $decoda->addHook(new \Decoda\Hook\ClickableHook());
     $parsed = $decoda->parse();
     $html = str_replace('<br />', '', $parsed);
     $nesting = array();
     $closing = array();
     $scope = array();
     $errors = array();
     foreach ($decoda->getErrors() as $error) {
         switch ($error['type']) {
             case Decoda\Decoda::ERROR_NESTING:
                 $nesting[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_CLOSING:
                 $closing[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_SCOPE:
                 $scope[] = $error['child'] . ' in ' . $error['parent'];
                 break;
         }
     }
     if (!empty($nesting)) {
         $errors[] = sprintf('The following tags have been nested in the wrong order: %s', implode(', ', $nesting));
     }
     if (!empty($closing)) {
         $errors[] = sprintf('The following tags have no closing tag: %s', implode(', ', $closing));
     }
     if (!empty($scope)) {
         $errors[] = sprintf('The following tags can not be placed within a specific tag: %s', implode(', ', $scope));
     }
     foreach ($errors as $error) {
         $string = '<div class="alert alert-error">';
         $string .= $error;
         $string .= '</div>';
         echo $string;
     }
     return $html;
 }
Beispiel #4
0
[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):
http://domain.com
Beispiel #5
0
 /**
  * Formate la sortie de la description
  *
  */
 public function getDescriptionHtml()
 {
     $code = new Decoda\Decoda($this->description);
     $code->defaults();
     return $code->parse();
 }
Beispiel #6
0
 public function bbcode($text)
 {
     $decoda = new Decoda\Decoda($text);
     $decoda->defaults();
     $decoda->setStrict(false);
     // $decoda->removeFilter('Video');
     $decoda->removeHook('Censor');
     //$decoda->removeFilter('Url');
     $html = $decoda->parse();
     // $errors = $decoda->getErrors();
     // foreach($errors as $error) {
     //     $string = "";
     //     foreach($error as $key => $value) {
     //         $string = $key . ":" . $value . ", ";
     //     }
     //     error_log($string);
     // }
     // print_r($errors);
     $nesting = array();
     $closing = array();
     $scope = array();
     $errors = array();
     foreach ($decoda->getErrors() as $error) {
         switch ($error['type']) {
             case Decoda\Decoda::ERROR_NESTING:
                 $nesting[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_CLOSING:
                 $closing[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_SCOPE:
                 $scope[] = $error['child'] . ' in ' . $error['parent'];
                 break;
         }
     }
     if (!empty($nesting)) {
         $errors[] = sprintf('The following tags have been nested in the wrong order: %s', implode(', ', $nesting));
     }
     if (!empty($closing)) {
         $errors[] = sprintf('The following tags have no closing tag: %s', implode(', ', $closing));
     }
     if (!empty($scope)) {
         $errors[] = sprintf('The following tags can not be placed within a specific tag: %s', implode(', ', $scope));
     }
     foreach ($errors as $error) {
         $string = '<div class="alert alert-error">';
         $string .= $error;
         $string .= '</div>';
         echo $string;
     }
     return $html;
     // return $decoda->parse();
     // return $text;
 }
Beispiel #7
0
 /**
  * Edit le post de l'utilisateur
  *
  * @param $slug Slug du topic
  * @param $id Id du topic
  * @param $postId Id du post
  */
 public function postEdit($slug, $id, $postId)
 {
     $user = Auth::user();
     $topic = Topic::find($id);
     $forum = $topic->forum;
     $category = $forum->getCategory();
     $post = Post::find($postId);
     $parsedContent = null;
     if ($user->group->is_modo == false) {
         if ($post->user_id != $user->id) {
             return Redirect::route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with('message', 'You can\'t edit this post');
         }
     }
     // Prévisualisation du post
     if (Request::getMethod() == 'POST' && Input::get('preview') == true) {
         $post->content = Input::get('content');
         $code = new Decoda\Decoda($post->content);
         $code->defaults();
         $parsedContent = $code->parse();
     }
     if (Request::isMethod('post') && Input::get('post') == true) {
         $post->content = Input::get('content');
         $post->save();
         return Redirect::route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id]);
     }
     return View::make('forum.post_edit', ['user' => $user, 'topic' => $topic, 'forum' => $forum, 'post' => $post, 'category' => $category, 'parsedContent' => $parsedContent]);
 }
 /**
  * @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;
 }