private function parse($content)
 {
     $parser = new BBCodeParser();
     $parser->set_content($content);
     $parser->parse();
     return $parser->get_content();
 }
Exemple #2
0
 function Content()
 {
     if (self::$allow_wysiwyg_editing) {
         return $this->getField('Content');
     } else {
         $parser = new BBCodeParser($this->Content);
         $content = new HTMLText('Content');
         $content->value = $parser->parse();
         return $content;
     }
 }
 /**
  * Parses a message.
  * 
  * @param	string		$message
  * @param	boolean		$enableSmilies
  * @param	boolean		$enableHtml
  * @param	boolean		$enableBBCodes
  * @return	string		parsed message
  */
 public function parse($message, $enableSmilies = true, $enableHtml = false, $enableBBCodes = true, $doKeywordHighlighting = true)
 {
     $this->cachedCodes = array();
     if ($this->getOutputType() != 'text/plain') {
         if ($enableBBCodes) {
             // cache codes
             $message = $this->cacheCodes($message);
         }
         if (!$enableHtml) {
             // encode html
             $message = StringUtil::encodeHTML($message);
             // converts newlines to <br />'s
             $message = nl2br($message);
         }
     }
     // parse bbcodes
     if ($enableBBCodes) {
         $message = parent::parse($message);
     }
     if ($this->getOutputType() != 'text/plain') {
         // parse smilies
         if ($enableSmilies) {
             $message = $this->parseSmilies($message, $enableHtml);
         }
         if ($enableBBCodes && count($this->cachedCodes) > 0) {
             // insert cached codes
             $message = $this->insertCachedCodes($message);
         }
         // highlight search query
         if ($doKeywordHighlighting) {
             $message = KeywordHighlighter::doHighlight($message);
         }
         // replace bad html tags (script etc.)
         $badSearch = array('/javascript:/i', '/about:/i', '/vbscript:/i');
         $badReplace = array('javascript<b></b>:', 'about<b></b>:', 'vbscript<b></b>:');
         $message = preg_replace($badSearch, $badReplace, $message);
         // wrap text
         //$message = $this->wrap($message);
     }
     return $message;
 }
Exemple #4
0
 /**
  * Обработка BB-кодов
  * @param  string  $text  Необработанный текст
  * @param  boolean $parse Обрабатывать или вырезать код
  * @return string         Обработанный текст
  */
 public static function bbCode($text, $parse = true)
 {
     $bbcode = new BBCodeParser();
     if (!$parse) {
         return $bbcode->clear($text);
     }
     $text = $bbcode->parse($text);
     $text = $bbcode->parseSmiles($text);
     return $text;
 }
Exemple #5
0
[code]
#include <iostream>
 
int main() {
    using std::cout;
    cout << "Hello, new world !"
         << std::endl;
}
[/code]

[url=http://www.w3.org]Nam ullamcorper[/url]
[url]www.w3.org[/url]

[img=300]http://www.w3.org/html/logo/img/html5-display.png[/img]';
$content = isset($_POST['content']) ? $_POST['content'] : $default_content;
$parsed_content = $bbcode->parse($content);
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <title>PHP Shortcodes</title>

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
</head>

<body class="container">

<div class="page-header">
 /**
  * Return the parsed content and the information for the 
  * RSS feed
  */
 function getRSSContent()
 {
     $parser = new BBCodeParser($this->Content);
     $html = $parser->parse();
     if ($this->Thread()) {
         $html .= '<br><br>' . sprintf(_t('Post.POSTEDTO', "Posted to: %s"), $this->Thread()->Title);
     }
     $html .= " " . $this->ShowLink() . " | " . $this->ReplyLink();
     return $html;
 }
Exemple #7
0
 function ParsedBBCode()
 {
     $parser = new BBCodeParser($this->Comment);
     return $parser->parse();
 }
 public function action_postedit($topic_slug, $topic_id, $message_id)
 {
     $topic = Forumtopic::find($topic_id);
     if (is_null($topic)) {
         return Event::first('404');
     }
     $category = $topic->category;
     $message = Forummessage::find($message_id);
     if (is_null($message)) {
         return Event::first('404');
     }
     if ($message->user->id != Auth::user()->id && !Auth::user()->is('Forumer')) {
         return Event::first('404');
     }
     $rules = array('content' => 'required|min:30');
     $content = trim(Input::get('content'));
     $toValidate = compact('content');
     $editTitle = false;
     if ($topic->messages[0]->id == $message->id && trim(Input::get('title')) != $topic->title) {
         $editTitle = true;
         $rules['title'] = 'required|min:2';
         $title = trim(Input::get('title'));
         $toValidate['title'] = $title;
     }
     $validator = Validator::make($toValidate, $rules);
     if ($validator->fails()) {
         return Redirect::back()->with_errors($validator)->with_input();
     }
     if ($editTitle) {
         $topic->title = $toValidate['title'];
         $topic->slug = Str::slug($toValidate['title']);
         $originalSlug = $topic->slug;
         $incSlug = 0;
         do {
             try {
                 $topic->save();
                 $incSlug = 0;
             } catch (Exception $e) {
                 if ($e->getCode() == 23000) {
                     $incSlug++;
                 }
                 $topic->slug = $originalSlug . '-' . $incSlug;
             }
         } while ($incSlug != 0);
     }
     $message->content = BBCodeParser::parse($content);
     $message->content_bbcode = $content;
     $message->save();
     $topic->touch();
     $topic_id = $topic->id;
     $topic_slug = $topic->slug;
     $url = URL::to_action('forums::topic@index', compact('topic_slug', 'topic_id')) . '?page=last#message' . $message->id;
     return Redirect::to($url);
 }