Beispiel #1
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)
 {
     $tplEngine->checkRequiredAttrs($node, array('form', 'name'));
     // DATA
     $newNode = new TextNode($tplEngine->getDomReader());
     $newNode->content = '<?= ' . self::class . '::render(\'' . $node->getAttribute('form')->value . '\', \'' . $node->getAttribute('name')->value . '\', $this); ?>';
     $node->parentNode->insertBefore($newNode, $node);
     $node->parentNode->removeNode($node);
 }
 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);
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     $tplEngine->checkRequiredAttrs($node, array('options'));
     // DATA
     $selectionSelector = $node->getAttribute('selected') !== null ? "'{$node->getAttribute('selected')->value}'" : null;
     $optionsSelector = "'{$node->getAttribute('options')->value}'";
     $textContent = '<?php echo ' . __CLASS__ . '::render($this, ' . $optionsSelector . ', ' . $selectionSelector . '); ?>';
     $newNode = new TextNode($tplEngine->getDomReader());
     $newNode->content = $textContent;
     $node->parentNode->insertBefore($newNode, $node);
     $node->parentNode->removeNode($node);
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     $tplEngine->checkRequiredAttrs($node, array('chosen', 'name'));
     // DATA
     $chosenEntriesSelector = $node->getAttribute('chosen')->value;
     $poolEntriesSelector = $node->doesAttributeExist('pool') ? $node->getAttribute('pool')->value : null;
     $nameSelector = $node->getAttribute('name')->value;
     // Generate
     $newNode = new TextNode($tplEngine->getDomReader());
     $newNode->content = '<?= ' . self::class . '::render(\'' . $nameSelector . '\', \'' . $chosenEntriesSelector . '\', \'' . $poolEntriesSelector . '\', $this); ?>';
     $node->parentNode->insertBefore($newNode, $node);
     $node->parentNode->removeNode($node);
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
 {
     // DATA
     $tplEngine->checkRequiredAttrs($node, array('options', 'checked'));
     $checkedSelector = $node->getAttribute('checked')->value;
     $optionsSelector = $node->getAttribute('options')->value;
     $fldName = $node->getAttribute('name')->value;
     $textContent = "<?php print " . __CLASS__ . "::render(\$this, '{$fldName}', '{$optionsSelector}', '{$checkedSelector}'); ?>";
     $newNode = new TextNode($tplEngine->getDomReader());
     $newNode->content = $textContent;
     $node->parentNode->insertBefore($newNode, $node);
     $node->parentNode->removeNode($node);
 }
 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);
 }
Beispiel #8
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);
 }
 public function replaceNode(TemplateEngine $tplEngine, ElementNode $tagNode)
 {
     $tplEngine->checkRequiredAttrs($tagNode, 'cond');
     $condAttr = $tagNode->getAttribute('cond')->value;
     $phpCode = '<?php ';
     $phpCode .= 'elseif(' . 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);
 }
Beispiel #10
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);
     }
 }
Beispiel #11
0
    public function replaceNode(TemplateEngine $tplEngine, ElementNode $node)
    {
        // DATA
        $tplEngine->checkRequiredAttrs($node, array('var', 'as'));
        $dataKeyAttr = $node->getAttribute('var')->value;
        $asVarAttr = $node->getAttribute('as')->value;
        $keyVarAttr = $node->getAttribute('key')->value;
        $counterAttr = $node->getAttribute('counter')->value;
        $oddEvenAttr = $node->getAttribute('odd-even')->value;
        $firstLastAttr = $node->getAttribute('first-last')->value;
        $stepIncrement = $node->getAttribute('step')->value;
        $grabCount = $node->getAttribute('grab')->value;
        if ($stepIncrement === null && $grabCount !== null) {
            $stepIncrement = $grabCount;
        } elseif ($stepIncrement === null) {
            $stepIncrement = 1;
        }
        if ($stepIncrement == 0) {
            throw new TemplateEngineException('Use a step value other than 0. This will end up in an endless loop');
        }
        $for_i = '$for_i_' . $asVarAttr;
        $for_key = '$for_key_' . $asVarAttr;
        $for_val = '$for_val_' . $asVarAttr;
        $for_data = '$for_data_' . $asVarAttr;
        $for_data_count = '$for_data_count_' . $asVarAttr;
        $phpCode = '<?php
			' . $for_data . ' = $this->getDataFromSelector(\'' . $dataKeyAttr . '\');
			' . $for_data_count . ' = count(' . $for_data . ');
			' . $for_i . ' = 0;
			
			';
        if ($tplEngine->isFollowedBy($node, 'else') === true) {
            $phpCode .= 'if(' . $for_data_count . ' > 0):
			';
        }
        $phpCode .= 'for(' . $for_val . ' = current(' . $for_data . '), ' . $for_key . ' = key(' . $for_data . '); ' . $for_val . ';  ' . $for_val . ' = next(' . $for_data . '), ' . $for_key . ' = key(' . $for_data . '), ' . $for_i . ' += ' . $stepIncrement . '):
			' . ($counterAttr !== null ? '$this->addData(\'' . $counterAttr . '\', ' . $for_i . ', true);' : null) . '	
			' . ($keyVarAttr !== null ? '$this->addData(\'' . $keyVarAttr . '\', ' . $for_key . ', true);' : null);
        if ($grabCount === null || $grabCount == 1) {
            $phpCode .= '$this->addData(\'' . $asVarAttr . '\', ' . $for_val . ', true);';
        } else {
            $phpCode .= '$tmpGrabGroup = array(
				key(' . $for_data . ') => current(' . $for_data . ')
			);
			
			for($i = 2; $i <= ' . $grabCount . '; ++$i) {
				if(($tmpNextEntry = next(' . $for_data . ')) === false)
					break;
					
				$tmpGrabGroup[key(' . $for_data . ')] = $tmpNextEntry;
			}
			
			$this->addData(\'' . $asVarAttr . '\', $tmpGrabGroup, true);';
        }
        $phpCode .= ($oddEvenAttr !== null ? '$this->addData(\'' . $oddEvenAttr . '\', (((' . $for_i . '/' . $stepIncrement . ')%2 === 0)?\'odd\':\'even\'), true);' : null) . '	
			' . ($firstLastAttr !== null ? '$this->addData(\'' . $firstLastAttr . '\', ((' . $for_i . ' === 0)?\'first\':(((' . $for_i . '/' . $stepIncrement . ') === ' . $for_data_count . '-1)?\'last\':null)), true);' : null) . '	
		?>
		' . $node->getInnerHtml() . '
		<?php endfor; ?>';
        $newNode = new TextNode($tplEngine->getDomReader());
        $newNode->content = $phpCode;
        $node->parentNode->replaceNode($node, $newNode);
    }