Example #1
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if ($this->hasAttribute('NAME')) {
         $name = $this->getAttribute('NAME');
         $mode = $this->hasAttribute('MODE') ? $this->getAttribute('MODE') : 'replace';
         foreach ($this->findAll('BLOCK', array('NAME' => $this->getAttribute('NAME'))) as $result) {
             if ($result instanceof BlockElement && $result->isTarget()) {
                 switch ($mode) {
                     default:
                     case 'replace':
                         $result->setChildren(array($this));
                         break;
                     case 'append':
                         $result->addChild($this);
                         break;
                     case 'prepend':
                         $result->prependChild($this);
                         break;
                 }
             }
         }
         if (!$this->getParent() instanceof self) {
             $this->setAsTarget();
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #2
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->hasParent() && $this->getParent() instanceof IfElement) {
             $this->prependPhp("else:");
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #3
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->hasAttribute('EXTENDS')) {
             $extendPath = $cwd . DIRECTORY_SEPARATOR . $this->getAttribute('EXTENDS');
             $xtpl = $compiler->compileFile($extendPath);
             //Incorporate trees
             $xtpl->addChild($this);
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #4
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         $expr = '';
         if ($this->hasAttribute('COND')) {
             $expr = $this->getAttribute('COND');
         } else {
             if ($this->hasAttribute('NOT-COND')) {
                 $expr = '!( ' . $this->getAttribute('NOT-COND') . ' )';
             } else {
                 if ($this->hasAttribute('EMPTY')) {
                     $expr = 'empty( $' . str_replace('.', '->', $this->getAttribute('EMPTY')) . ' )';
                 } else {
                     if ($this->hasAttribute('NOT-EMPTY')) {
                         $expr = '!empty( $' . str_replace('.', '->', $this->getAttribute('NOT-EMPTY')) . ' )';
                     } else {
                         if ($this->hasAttribute('SET')) {
                             $expr = 'isset( $' . str_replace('.', '->', $this->getAttribute('SET')) . ' )';
                         } else {
                             if ($this->hasAttribute('NOT-SET')) {
                                 $expr = '!isset( $' . str_replace('.', '->', $this->getAttribute('NOT-SET')) . ' )';
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($expr)) {
             switch ($this->getTagName()) {
                 default:
                 case 'IF':
                     $this->prependPhp("if( {$expr} ):");
                     //Make sure elses and ifelses are the very last children
                     $else = $this->find('ELSE');
                     $elseIf = $this->find('ELSE-IF');
                     if (!empty($elseIf)) {
                         $this->addChild($elseIf[0]);
                     }
                     if (!empty($else)) {
                         $this->addChild($else[0]);
                     }
                     $this->addPhp('endif;');
                     break;
                 case 'ELSE-IF':
                     //make sure this one is at the end the children of its parent, but before the closing php
                     $this->prependPhp("elseif( {$expr} ):");
                     break;
             }
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #5
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->hasAttribute('FILE')) {
             $includePath = $cwd . DIRECTORY_SEPARATOR . $this->getAttribute('FILE');
             $xtpl = $compiler->compileFile($includePath);
             //Apply arguments on templates (Even on extended ones, yay!)
             $this->applyArgs($xtpl);
             $this->addChild($xtpl);
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #6
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->hasAttribute('NAME')) {
             if ($this->hasAttribute('VALUE')) {
                 $this->addPhp('$' . $this->getAttribute('NAME') . ' = \'' . $this->getAttribute('VALUE') . '\';');
             } else {
                 $this->addPhp('echo $' . $this->getAttribute('NAME') . ';');
             }
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #7
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->getParent() instanceof PanelElement) {
             $this->setTagName('DIV');
             $this->addClass('panel-body');
             //Check if this is an accordion
             if ($this->getParent(2) instanceof AccordionElement) {
                 $this->wrap(new Panel\CollapseElement());
             }
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #8
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->getParent() instanceof PanelElement) {
             if ($this->hasAttribute('SIZE') || $this->getParent(2) instanceof AccordionElement) {
                 $this->ignoreAttribute('SIZE');
                 $size = $this->hasAttribute('SIZE') ? intval($this->getAttribute('SIZE')) : 4;
                 $h = $this->wrapInner(new TitleElement(array('SIZE' => $size)));
                 if ($this->getParent(2) instanceof AccordionElement) {
                     $a = new AElement(array('DATA-TOGGLE' => 'collapse', 'DATA-PARENT' => '#' . $this->getParent(2)->getAttribute('ID')));
                     $h->wrapInner($a);
                 }
             }
             $this->setTagName('DIV');
             $this->addClass('panel-heading');
         }
     }
     return parent::compile($compiler, $cwd);
 }
Example #9
0
 public function compile(\Xtpl\Compiler $compiler, $cwd)
 {
     if (!$this->isCompiled()) {
         if ($this->hasAttribute('EACH') && $this->hasAttribute('AS')) {
             //it's a foreach( $arr as $key => $val ) loop
             $as = $this->hasAttribute('KEY') ? '$' . $this->getAttribute('KEY') . ' => $' . $this->getAttribute('AS') : '$' . $this->getAttribute('AS');
             $this->prependPhp('foreach( $' . $this->getAttribute('EACH') . ' as ' . $as . ' ):');
             $this->addPhp('endforeach;');
         }
         if ($this->hasAttribute('TIMES')) {
             $start = $this->hasAttribute('FIRST') ? intval($this->getAttribute('FIRST')) : 0;
             $as = $this->hasAttribute('AS') ? $this->getAttribute('AS') : '_xtplLoopCounter';
             $end = $start + intval($this->getAttribute('TIMES'));
             $this->prependPhp('for( $' . $as . ' = ' . $start . '; $' . $as . ' < ' . $end . '; $' . $as . '++ ):');
             $this->addPhp('endfor;');
         }
     }
     return parent::compile($compiler, $cwd);
 }