Beispiel #1
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsHTML();
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $param = trim($param);
     if ($content == '' and $param == '') {
         return '';
     }
     // Erlaubte Farbnamen
     $allowed_colors = (array) $this->config->get('callbacks.color_param.allowed_colors');
     $color = mb_convert_case($param, MB_CASE_TITLE);
     // Wenn im Parameter keine erlaubte Farbe steht
     if (!in_array($color, $allowed_colors)) {
         // Prüfen, ob eine hexadezimale Farbe angegeben wurde
         if (strlen($param) == 7 && $param[0] == '#' and preg_match('~#[a-f0-9]{6}~i', $param)) {
             $color = $param;
         } else {
             $color = $this->config->get('callbacks.color_param.default_color');
         }
     }
     // Ansonsten ist der Farbnamen gülig
     return Html::span($content, ['style' => 'color:' . $color . ';']);
 }
 public function visitElementNode(ElementNode $element_node)
 {
     if ($element_node->getCodeDefinition()->parseContent()) {
         foreach ($element_node->getChildren() as $child) {
             $child->accept($this);
         }
     }
 }
Beispiel #3
0
 public function visitElementNode(ElementNode $element_node)
 {
     // Nur nach Urls suchen, wenn nicht in URL-Tag und der Content geparst werden soll
     if ($element_node->getCodeDefinition()->getTagName() !== 'url' and $element_node->getCodeDefinition()->parseContent()) {
         foreach ($element_node->getChildren() as $child) {
             $child->accept($this);
         }
     }
 }
 function visitElementNode(\JBBCode\ElementNode $elementNode)
 {
     if ($elementNode->getCodeDefinition()->parseContent()) {
         /* We only want to visit text nodes within elements if the element's code definition allows for its content to be parsed. */
         foreach ($elementNode->getChildren() as $child) {
             $child->accept($this);
         }
     }
 }
 public function asHtml(\JBBCode\ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsBBCode();
     }
     if ($el->getAttribute()['file'] == 'image') {
         return '<img src="' . base_url($content) . '"/>';
     }
 }
Beispiel #6
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsHTML();
     }
     $flags = ENT_COMPAT | ENT_HTML401;
     $encoding = ini_get("default_charset");
     $double_encode = false;
     // Do not double encode
     return '<!-- no_p --><pre><code>' . htmlspecialchars($content, $flags, $encoding, $double_encode) . '</code></pre><!-- no_p -->';
 }
Beispiel #7
0
 public function visitElementNode(\JBBCode\ElementNode $elementNode)
 {
     $attrs = $elementNode->getAttribute();
     if (is_array($attrs)) {
         foreach ($attrs as &$el) {
             $el = $this->htmlSafe($el);
         }
         $elementNode->setAttribute($attrs);
     }
     foreach ($elementNode->getChildren() as $child) {
         $child->accept($this);
     }
 }
 public function asHtml(ElementNode $el)
 {
     $bodyHtml = '';
     foreach ($el->getChildren() as $child) {
         $bodyHtml .= $child->getAsHTML();
     }
     $listPieces = explode('[*]', $bodyHtml);
     unset($listPieces[0]);
     $listPieces = array_map(function ($li) {
         return Html::tag('li', $li);
     }, $listPieces);
     return Html::tag('ul', implode('', $listPieces));
 }
Beispiel #9
0
 public function asHtml(\JBBCode\ElementNode $el)
 {
     $bodyHtml = '';
     foreach ($el->getChildren() as $child) {
         $bodyHtml .= $child->getAsHTML();
     }
     $list = array();
     preg_match_all('#\\[li\\](.*?)\\[\\/li\\]#is', $bodyHtml, $list);
     $list = array_map(function ($li) {
         return '<li>' . $li . '</li>';
     }, $list[1]);
     return '<ul>' . implode('', $list) . '</ul>';
 }
Beispiel #10
0
 public function visitElementNode(\JBBCode\ElementNode $elementNode)
 {
     $tagName = strtolower($elementNode->getTagName());
     // Update this tag name's frequency
     if (isset($this->frequencies[$tagName])) {
         $this->frequencies[$tagName]++;
     } else {
         $this->frequencies[$tagName] = 1;
     }
     // Visit all the node's childrens
     foreach ($elementNode->getChildren() as $child) {
         $child->accept($this);
     }
 }
 public function asHtml(\JBBCode\ElementNode $el)
 {
     $url = '';
     foreach ($el->getChildren() as $child) {
         $url .= $child->getAsText();
     }
     // Split the argument on the pipe character
     $argPieces = explode('|', $el->getAttribute());
     $altText = $argPieces[0];
     $class = 'default-class';
     if (count($argPieces) > 1) {
         $class = $argPieces[1];
     }
     return '<img src="' + $url + '" alt="' + $altText + '" class="' + $class + '" />';
 }
 public function asHtml(\JBBCode\ElementNode $el)
 {
     $bodyHtml = '';
     foreach ($el->getChildren() as $child) {
         $bodyHtml .= $child->getAsHTML();
     }
     $trList = array();
     preg_match_all('#\\[tr\\](.*?)\\[\\/tr\\]#is', $bodyHtml, $trList);
     $trList = array_map(function ($tr) {
         $tdList = array();
         preg_match_all('#\\[td\\](.*?)\\[\\/td\\]#is', $tr, $tdList);
         $tdList = array_map(function ($td) {
             return '<td>' . $td . '</td>';
         }, $tdList[1]);
         return '<tr>' . implode('', $tdList) . '</tr>';
     }, $trList[1]);
     return '<table class="table table-hover table-bordered table-striped"><tbody>' . implode('', $trList) . '</tbody></table>';
 }
 public function asHtml(ElementNode $el)
 {
     $bodyHtml = '';
     foreach ($el->getChildren() as $child) {
         $bodyHtml .= $child->getAsHTML();
     }
     $trList = array();
     preg_match_all('#\\[tr\\](.*?)\\[\\/tr\\]#is', $bodyHtml, $trList);
     $trList = array_map(function ($tr) {
         $tdList = array();
         preg_match_all('#\\[td\\](.*?)\\[\\/td\\]#is', $tr, $tdList);
         $tdList = array_map(function ($td) {
             return Html::tag('td', $td);
         }, $tdList[1]);
         return Html::tag('tr', implode('', $tdList));
     }, $trList[1]);
     return Html::tag('table', implode('', $trList), ['class' => 'bb-table']);
 }
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsHTML();
     }
     $content = trim($content);
     if ($content == '') {
         return '';
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $list_type = false;
     $list_attr = array();
     if (in_array($param, array('a', 'A', 'i', 'I'))) {
         $list_type = 'ol';
         $list_attr['type'] = $param;
     }
     if (!$list_type) {
         //Wir prüfen, ob eine Zahl angegeben wurde
         if (preg_match('/^(-){0,1}[0-9]+$/', $param)) {
             $list_type = 'ol';
             $list_attr['start'] = intval($param);
         }
     }
     //Default ist ul, $param ist dann egal
     if (!$list_type) {
         $list_type = 'ul';
         $list_attr['type'] = 'disc';
     }
     $delimiter = '[*]';
     if (substr($content, 0, strlen($delimiter)) === $delimiter) {
         $content = substr_replace($content, '', 0, strlen($delimiter));
     }
     //Text in Lines aufteilen; jede Line ist ein neuer Listenpunkt
     $lines = explode($delimiter, $content);
     $items = array();
     foreach ($lines as $line) {
         $items[] = trim($line);
     }
     return '<!-- no_p -->' . Html::$list_type($items, $list_attr) . '<!-- no_p -->';
 }
 public function visitElementNode(\JBBCode\ElementNode $elementNode)
 {
     $tagName = strtolower($elementNode->getTagName());
     if (isset($this->depth[$tagName])) {
         /* Update the current depth for this tag name. */
         $this->depth[$tagName]++;
     } else {
         $this->depth[$tagName] = 1;
     }
     if ($elementNode->getCodeDefinition()->getNestLimit() != -1 && $elementNode->getCodeDefinition()->getNestLimit() < $this->depth[$tagName]) {
         /* Check if $elementNode is nested too deeply. */
         $elementNode->getParent()->removeChild($elementNode);
     } else {
         foreach ($elementNode->getChildren() as $child) {
             /* This element is not nested too deeply. Visit all of its children. */
             $child->accept($this);
         }
     }
     $this->depth[$tagName]--;
     /* Now that we're done visiting this node, decrement the depth. */
 }
Beispiel #16
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsText();
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $param = trim($param);
     if ($content == '' and $param == '') {
         return '';
     }
     $short_url = $this->config->get('callbacks.url_content.short_url');
     // Url finden
     if ($param == '') {
         // Die Url steht im Content
         $url = $content;
         // In der anzuzeigenden URL kein &amp; anzeigen
         $content = str_replace('&amp;', '&', $content);
     } else {
         // Die Url steht im Parameter
         $url = $param;
         $short_url = false;
         $content = '';
         foreach ($el->getChildren() as $child) {
             $content .= $child->getAsHTML();
         }
     }
     // http:// voranstellen, wenn nichts angegeben
     if (!preg_match('~^[a-z]+://~i', $url)) {
         $url = "http://" . $url;
     }
     // Wenn die URL nicht gültig ist, zeigen wir nur den Text
     if (!$this->config->getValidation()->isValidUrl($url)) {
         return $content;
     }
     return Html::anchorFromConfig($url, $content, $this->config);
 }
Beispiel #17
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsHTML();
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $param = (string) trim($param);
     if (preg_match('/^\\<blockquote/', trim($content)) == 0) {
         $content = "<cite>" . $param . "</cite>" . $content;
     } else {
         $search = '</blockquote>';
         $replace = "</blockquote><cite>" . $param . "</cite>";
         $len = strlen($search);
         $pos = strrpos($content, $search);
         $content = substr_replace($content, $replace, $pos, $len);
     }
     return '<blockquote title="Zitat">' . $content . '</blockquote>';
 }
Beispiel #18
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsText();
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $param = trim($param);
     if ($content == '' and $param == '') {
         return '';
     }
     if ($param == '') {
         // Die Email steht im Content
         $email = '';
         foreach ($el->getChildren() as $child) {
             $email .= $child->getAsText();
         }
     } else {
         // Die Email steht im Parameter
         $email = $param;
         $content = '';
         foreach ($el->getChildren() as $child) {
             $content .= $child->getAsHTML();
         }
     }
     // Nur Content anzeigen, wenn keine gültige Email angegeben wurde
     if (!$this->config->getValidation()->isValidEmail($email)) {
         return $content;
     }
     // Mail vor Bots schützen?
     if ($this->config->get('callbacks.email_content.protect_email')) {
         return Html::mail_to_safe($email, $content);
     }
     return Html::mail_to($email, $content);
 }
Beispiel #19
0
 public function asHtml(ElementNode $el)
 {
     $content = '';
     foreach ($el->getChildren() as $child) {
         $content .= $child->getAsHTML();
     }
     $param = $el->getAttribute();
     if (is_array($param)) {
         $param = array_shift($param);
     }
     $param = trim($param);
     if ($content == '') {
         return '';
     }
     $size = intval($param);
     if ($size == 0) {
         $size = 100;
     }
     // Mindestgröße: 75%
     $size = max($size, $this->config->get('callbacks.size_param.min_size'));
     // Maximale Größe: 150%
     $size = min($size, $this->config->get('callbacks.size_param.max_size'));
     return Html::span($content, ['style' => 'font-size:' . $size . '%;']);
 }
Beispiel #20
0
 /**
  * This is the next step in parsing a tag. It's possible for it to still be invalid at this
  * point but many of the basic invalid tag name conditions have already been handled.
  *
  * @param $parent  the current parent element
  * @param $tokenizer  the tokenizer we're using
  * @param $tagContent  the text between the [ and the ], assuming there is actually a ]
  *
  * @return the new parent element
  */
 protected function parseTag(ElementNode $parent, Tokenizer $tokenizer, $tagContent)
 {
     $next;
     if (!$tokenizer->hasNext() || ($next = $tokenizer->next()) != ']') {
         /* This is a malformed tag. Both the previous [ and the tagContent
          * is really just plain text. */
         $this->createTextNode($parent, '[');
         $this->createTextNode($parent, $tagContent);
         return $parent;
     }
     /* This is a well-formed tag consisting of [something] or [/something], but
      * we still need to ensure that 'something' is a valid tag name. Additionally,
      * if it's a closing tag, we need to ensure that there was a previous matching
      * opening tag.
      */
     /* There could be an attribute. */
     $tagPieces = explode('=', $tagContent);
     $tmpTagName = $tagPieces[0];
     $actualTagName;
     if ('/' == $tmpTagName[0]) {
         /* This is a closing tag name. */
         $actualTagName = substr($tmpTagName, 1);
     } else {
         $actualTagName = $tmpTagName;
     }
     if ('/' == $tmpTagName[0]) {
         /* This is attempting to close an open tag. We must verify that there exists an
          * open tag of the same type and that there is no option (options on closing
          * tags don't make any sense). */
         $elToClose = $parent->closestParentOfType($actualTagName);
         if (null == $elToClose || count($tagPieces) > 1) {
             /* Closing an unopened tag or has an option. Treat everything as plain text. */
             $this->createTextNode($parent, '[');
             $this->createTextNode($parent, $tagContent);
             $this->createTextNode($parent, ']');
             return $parent;
         } else {
             /* We're closing $elToClose. In order to do that, we just need to return
              * $elToClose's parent, since that will change our effective parent to be
              * elToClose's parent. */
             return $elToClose->getParent();
         }
     }
     /* Verify that this is a known bbcode tag name. */
     if ('' == $actualTagName || !$this->codeExists($actualTagName, count($tagPieces) > 1)) {
         /* This is an invalid tag name! Treat everything we've seen as plain text. */
         $this->createTextNode($parent, '[');
         $this->createTextNode($parent, $tagContent);
         $this->createTextNode($parent, ']');
         return $parent;
     }
     /* If we're here, this is a valid opening tag. Let's make a new node for it. */
     $el = new ElementNode();
     $el->setNodeId(++$this->nextNodeid);
     $code = $this->getCode($actualTagName, count($tagPieces) > 1);
     $el->setCodeDefinition($code);
     if (count($tagPieces) > 1) {
         /* We have an attribute we should save. */
         unset($tagPieces[0]);
         $el->setAttribute(implode('=', $tagPieces));
     }
     $parent->addChild($el);
     return $el;
 }
Beispiel #21
0
 /**
  * Constructs the parse tree from a string of bbcode markup.
  * 
  * @param string $str   the bbcode markup to parse
  */
 public function parse($str)
 {
     $this->reset();
     $parent = $this->treeRoot;
     $tokenManager = new TokenManager($str);
     $nodeid = 1;
     $inTag = false;
     while ($tokenManager->hasCurrent()) {
         // tokens are either "[", "]" or a string that contains neither a opening bracket nor a closing bracket
         if ($inTag) {
             // this token should be a tag name
             // explode by = in case there's an attribute
             $pieces = explode('=', $tokenManager->getCurrent(), 2);
             // check if it's a closing tag
             if (substr($pieces[0], 0, 1) == "/") {
                 $tagName = substr($pieces[0], 1);
                 $closing = true;
             } else {
                 $tagName = $pieces[0];
                 $closing = false;
             }
             if (($this->codeExists($tagName, isset($pieces[1])) || $closing && $this->codeExists($tagName, true)) && $tokenManager->hasNext() && $tokenManager->next() == "]") {
                 if ($closing) {
                     $closestParent = $parent->closestParentOfType($tagName);
                     if ($closestParent != null && $closestParent->hasParent()) {
                         // closing an element... move to this element's parent
                         $parent->getCodeDefinition()->decrementCounter();
                         $parent = $closestParent->getParent();
                         $tokenManager->advance();
                         $tokenManager->advance();
                         $inTag = false;
                         continue;
                     }
                 } else {
                     // new element
                     $el = new ElementNode();
                     $code = $this->getCode($tagName, isset($pieces[1]));
                     $code->incrementCounter();
                     $el->setNestDepth($code->getCounter());
                     $el->setCodeDefinition($code);
                     $el->setTagName($tagName);
                     $el->setNodeId($nodeid++);
                     if (isset($pieces[1])) {
                         $el->setAttribute($pieces[1]);
                     }
                     $parent->addChild($el);
                     $parent = $el;
                     $tokenManager->advance();
                     $tokenManager->advance();
                     $inTag = false;
                     continue;
                 }
             }
             // the opening bracket that sent us in here was really just plain text
             $node = new TextNode("[");
             $node->setNodeId($nodeid++);
             $parent->addChild($node);
             $inTag = false;
             // treat this token as regular text, and let the next if...else structure handle it as regular text
         }
         if ($tokenManager->getCurrent() == "[") {
             $inTag = true;
         } else {
             $node = new TextNode($tokenManager->getCurrent());
             $node->setNodeId($nodeid++);
             $parent->addChild($node);
         }
         $tokenManager->advance();
     }
 }
 /**
  * Creates a new text node with the given parent and text string.
  *
  * @param $parent  the parent of the text node
  * @param $string  the text of the text node
  *
  * @return TextNode the newly created TextNode
  */
 protected function createTextNode(ElementNode $parent, $string)
 {
     if (count($parent->getChildren())) {
         $children = $parent->getChildren();
         $lastElement = end($children);
         reset($children);
         if ($lastElement->isTextNode()) {
             $lastElement->setValue($lastElement->getValue() . $string);
             return $lastElement;
         }
     }
     $textNode = new $this->textNodeClassName($string);
     $textNode->setNodeId(++$this->nextNodeid);
     $parent->addChild($textNode);
     return $textNode;
 }