private static function createElement($seletor, $data)
 {
     if (preg_match('/^\\{(.+)\\}$/is', trim($seletor), $content)) {
         return new TextElement(self::replaceVars($content[1], $data));
     }
     if (preg_match_all('/([a-z0-9]+)(#[^\\.\\[\\{]+)?(\\.[^\\[\\{]+)?(\\[.+\\])?(?:\\{(.+)\\})?/is', $seletor, $matches, PREG_SET_ORDER)) {
         /*
          * 1 - tagName
          * 2 - id
          * 3 - classes
          * 4 - attributes
          * 5 - content
          * */
         $matches = $matches[0];
         $htmlTag = $matches[1];
         $element = new Element($htmlTag, null, self::isEmptyTag($htmlTag));
         if (isset($matches[2]) && !empty($matches[2])) {
             $element->attr('id', trim($matches[2], '#'));
         }
         if (isset($matches[3]) && !empty($matches[3])) {
             $classes = implode(' ', explode('.', trim($matches[3], '.')));
             $element->attr('class', $classes);
         }
         if (isset($matches[4]) && !empty($matches[4])) {
             if (!preg_match_all('/\\[([^=]+)=(.*?)\\]/is', $matches[4], $attrs, PREG_SET_ORDER)) {
                 return null;
             }
             foreach ($attrs as $attr) {
                 $value = self::replaceVars($attr[2], $data);
                 $element->attr($attr[1], $value);
             }
         }
         if (isset($matches[5]) && !empty($matches[5])) {
             $content = self::replaceVars($matches[5], $data);
             $element->addChild(new TextElement($content));
         }
         return $element;
     }
     return null;
 }
Esempio n. 2
0
 protected function addElementsInOl($arr)
 {
     $li = new Element('li');
     foreach ($arr as $el) {
         $li->addChild($el);
     }
     $this->ol->addChild($li);
 }
Esempio n. 3
0
 public function parseBody(Element $node)
 {
     $nodeName = $node->getName();
     do {
         if ($this->current() != "<" || $nodeName == "script" && !$this->equal("</script>")) {
             $text = "";
             while ($this->current() != "<" || $nodeName == "script" && !$this->equal("</script>")) {
                 $text .= $this->current();
                 $this->next();
             }
             if (trim($text)) {
                 $textNode = new Text($text);
                 $node->addChild($textNode);
             }
         } elseif ($this->current() == "<" && $this->getNext() != "/") {
             $childNode = $this->parseNode();
             $node->addChild($childNode);
         } else {
             $this->next(2);
             $endName = $this->parseName();
             if ($endName != $nodeName) {
                 echo "unexpected end of '{$endName}', {$nodeName} expected at {$this->ccline}:{$this->ccpos}\n";
                 $this->back(strlen("</{$endName}"));
             } else {
                 $this->skipWhiteSpaces();
                 $this->next();
             }
             break;
         }
     } while (true);
 }