示例#1
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     $replValue = $this->replace($tplEngine, $node->getAttribute('var')->value);
     $replNode = new TextNode($tplEngine->getDomReader());
     $replNode->content = $replValue;
     $node->parentNode->replaceNode($node, $replNode);
 }
示例#2
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $tagNode)
 {
     $format = $tagNode->getAttribute('format')->value;
     $replNode = new TextNode($tplEngine->getDomReader());
     $replNode->content = '<?php echo date(\'' . $format . '\'); ?>';
     $tagNode->parentNode->replaceNode($tagNode, $replNode);
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     $dataKey = $node->getAttribute('tplfile')->value;
     $tplFile = null;
     $tplFile = preg_match('/^\\{(.+)\\}$/', $dataKey, $res) === 1 ? '$this->getData(\'' . $res[1] . '\')' : '\'' . $dataKey . '\'';
     /** @var TextNode */
     $newNode = new TextNode($tplEngine->getDomReader());
     $newNode->content = '<?php ' . __NAMESPACE__ . '\\LoadSubTplTag::requireFile(' . $tplFile . ', $this); ?>';
     //$newTpl->getResultAsHtml();
     $node->parentNode->replaceNode($node, $newNode);
 }
示例#4
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     // DATA
     $value = $node->getAttribute('href')->value;
     $node->removeAttribute('href');
     $node->namespace = null;
     $node->tagName = 'link';
     $cssRevisionData = $tplEngine->getData('css_revision');
     $cssRevision = isset($cssRevisionData) ? '?' . $cssRevisionData : null;
     $node->addAttribute(new HtmlAttribute('href', $value . $cssRevision));
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     // DATA
     $sels = $node->getAttribute('selection')->value;
     $selsStr = '$this->getDataFromSelector(\'' . $sels . '\')';
     $value = $node->getAttribute('value')->value;
     $node->removeAttribute('selection');
     $node->namespace = null;
     $node->tagName = 'input';
     if ($sels !== null) {
         $node->tagExtension = " <?php echo ((is_array({$selsStr}) && in_array({$value}, {$selsStr})) || ({$selsStr} == '{$value}'))?' checked':null; ?>";
     }
     $node->addAttribute(new HtmlAttribute('type', 'checkbox'));
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     $var = $node->getAttribute('var')->value;
     $entryNoArr = explode(':', $var);
     $this->no = $entryNoArr[0];
     $this->var = $entryNoArr[1];
     $tplEngine->checkRequiredAttrs($node, array('var'));
     $replNode = new TextNode($tplEngine->getDomReader());
     $varName = $this->var . $this->no;
     $replNode->content = "<?php \$tmpGrpVal = \$this->getDataFromSelector('{$varName}', true);\n";
     $replNode->content .= " if(\$tmpGrpVal !== null) {\n";
     $replNode->content .= "\$this->addData('{$this->var}', \$tmpGrpVal, true); ?>";
     $replNode->content .= self::prepareHtml($node->getInnerHtml());
     $replNode->content .= "<?php } ?>";
     $node->getParentNode()->replaceNode($node, $replNode);
 }
示例#7
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $tagNode)
 {
     $lastTplTag = $tplEngine->getLastTplTag();
     if ($lastTplTag === null) {
         throw new TemplateEngineException('There is no custom tag that can be followed by an ElseTag');
     }
     /*if($lastTplTag->isElseable() === false)
     		throw new TemplateEngineException('The custom tag "' . get_class($lastTplTag) . '" can not be followed by an ElseTag');*/
     $phpCode = '<?php else: ?>';
     $phpCode .= $tagNode->getInnerHtml();
     $phpCode .= '<?php endif; ?>';
     $textNode = new TextNode($tplEngine->getDomReader());
     $textNode->content = $phpCode;
     $tagNode->parentNode->replaceNode($tagNode, $textNode);
     $tagNode->parentNode->removeNode($tagNode);
 }
示例#8
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     // DATA
     $sels = $node->getAttribute('selection')->value;
     $valueAttr = $node->getAttribute('value')->value;
     $value = is_numeric($valueAttr) ? $valueAttr : "'" . $valueAttr . "'";
     $type = $node->getAttribute('type')->value;
     $node->removeAttribute('selection');
     $node->namespace = null;
     $node->tagName = 'input';
     if ($sels !== null) {
         $node->tagExtension = " <?php echo in_array({$value}, \$this->getData('{$sels}'))?' checked=\"checked\"':null; ?>";
     }
     $node->addAttribute(new HtmlAttribute('type', $type));
 }
示例#9
0
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $tagNode)
 {
     $compareAttr = $tagNode->getAttribute('compare')->value;
     $operatorAttr = $tagNode->getAttribute('operator')->value;
     $againstAttr = $tagNode->getAttribute('against')->value;
     $condAttr = $tagNode->getAttribute('cond')->value;
     if ($condAttr === null) {
         // Check required attrs
         $tplEngine->checkRequiredAttrs($tagNode, array('compare', 'operator', 'against'));
         if (strlen($againstAttr) === 0) {
             $againstAttr = "''";
         } elseif (is_int($againstAttr) === true) {
             $againstAttr = intval($againstAttr);
         } elseif (is_float($againstAttr) === true) {
             $againstAttr = floatval($againstAttr);
         } elseif (is_string($againstAttr) === true) {
             if (strtolower($againstAttr) === 'null') {
                 //$againstAttr = 'null';
             } elseif (strtolower($againstAttr) === 'true' || strtolower($againstAttr) === 'false') {
                 //$againstAttr = ($againstAttr === 'true')?true:false;
             } elseif (StringUtils::startsWith($againstAttr, '{') && StringUtils::endsWith($againstAttr, '}')) {
                 $arr = substr(explode(',', $againstAttr), 1, -1);
                 $againstAttr = array();
                 foreach ($arr as $a) {
                     $againstAttr[] = trim($a);
                 }
             } else {
                 $againstAttr = "'" . $againstAttr . "'";
             }
         }
         $operatorStr = '==';
         switch (strtolower($operatorAttr)) {
             case 'gt':
                 $operatorStr = '>';
                 break;
             case 'ge':
                 $operatorStr = '>=';
                 break;
             case 'lt':
                 $operatorStr = '<';
                 break;
             case 'le':
                 $operatorStr = '<=';
                 break;
             case 'eq':
                 $operatorStr = '==';
                 break;
             case 'ne':
                 $operatorStr = '!=';
                 break;
         }
         $phpCode = '<?php ';
         $phpCode .= 'if($this->getDataFromSelector(\'' . $compareAttr . '\') ' . $operatorStr . ' ' . $againstAttr . '): ?>';
         $phpCode .= $tagNode->getInnerHtml();
         if ($tplEngine->isFollowedBy($tagNode, array('else', 'elseif')) === false) {
             $phpCode .= '<?php endif; ?>';
         }
         $textNode = new TextNode($tplEngine->getDomReader());
         $textNode->content = $phpCode;
         $tagNode->parentNode->replaceNode($tagNode, $textNode);
         $tagNode->parentNode->removeNode($tagNode);
     } else {
         $phpCode = '<?php ';
         $phpCode .= 'if(' . preg_replace_callback('/\\${(.*?)}/i', function ($m) {
             if (strlen($m[1]) === 0) {
                 throw new TemplateEngineException('Empty template data reference');
             }
             return '$this->getDataFromSelector(\'' . $m[1] . '\')';
         }, $condAttr) . '): ?>';
         $phpCode .= $tagNode->getInnerHtml();
         if ($tplEngine->isFollowedBy($tagNode, array('else', 'elseif')) === false) {
             $phpCode .= '<?php endif; ?>';
         }
         $textNode = new TextNode($tplEngine->getDomReader());
         $textNode->content = $phpCode;
         $tagNode->parentNode->replaceNode($tagNode, $textNode);
         $tagNode->parentNode->removeNode($tagNode);
     }
 }
 /**
  * @param ElementNode $contextTag
  * @param string|array $attrs
  *
  * @return bool
  * 
  * @throws TemplateEngineException
  */
 public function checkRequiredAttrs($contextTag, $attrs)
 {
     foreach ((array) $attrs as $a) {
         $val = $contextTag->getAttribute($a)->value;
         if ($val !== null) {
             continue;
         }
         throw new TemplateParseException('Could not parse the template: Missing attribute \'' . $a . '\' for custom tag \'' . $contextTag->tagName . '\' in ' . $this->currentTemplateFile . ' on line ' . $contextTag->line, $this->currentTemplateFile, $contextTag->line);
     }
     return true;
 }