コード例 #1
0
ファイル: VisitorUrl.php プロジェクト: youthweb/bbcode-parser
 public function visitTextNode(TextNode $text_node)
 {
     $urllinker = new UrlLinker();
     // Email-Adressen sollen nicht verlinkt werden
     $urllinker->setEmailLinkCreator(function ($email, $content) {
         return $email;
     });
     $urllinker->setHtmlLinkCreator(function ($url, $content) {
         // Wir vergeben extra zweimal $url, weil $content durch UrlLinker gekürzt wird
         return Html::anchorFromConfig($url, $url, $this->config);
     });
     $text_node->setValue($urllinker->linkUrlsAndEscapeHtml($text_node->getValue()));
 }
コード例 #2
0
ファイル: SmileyVisitor.php プロジェクト: jasonbb/Haruko
 function visitTextNode(\JBBCode\TextNode $textNode)
 {
     /* Convert :) into an image tag. */
     $textNode->setValue(str_replace(':)', '<img src="/smiley.png" alt=":)" />', $textNode->getValue()));
 }
コード例 #3
0
ファイル: Parser.php プロジェクト: jensdoecke/responsive-pot
 /**
  * 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 the newly created TextNode
  */
 protected function createTextNode(ElementNode $parent, $string)
 {
     $textNode = new TextNode($string);
     $textNode->setNodeId(++$this->nextNodeid);
     $parent->addChild($textNode);
     return $textNode;
 }
コード例 #4
0
ファイル: HTMLSafeVisitor.php プロジェクト: rhymix/rhymix
 public function visitTextNode(\JBBCode\TextNode $textNode)
 {
     $textNode->setValue($this->htmlSafe($textNode->getValue()));
 }
コード例 #5
0
ファイル: Parser.php プロジェクト: diamondo25/mapler.me
 /**
  * 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();
     }
 }
コード例 #6
0
 public function visitTextNode(TextNode $text_node)
 {
     $smiley_rules = $this->getSmileyRules();
     $text_node->setValue(str_replace($smiley_rules[0], $smiley_rules[1], $text_node->getValue()));
 }
コード例 #7
0
ファイル: Parser.php プロジェクト: jwest00724/mtg-engine
 /**
  * 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 TextNode($string);
     $textNode->setNodeId(++$this->nextNodeid);
     $parent->addChild($textNode);
     return $textNode;
 }