コード例 #1
0
ファイル: CodeGenerator.php プロジェクト: rafalenden/KioCMS
 public function generateCode(PHPTAL_Dom_Element $treeGen)
 {
     $codewriter = new PHPTAL_Php_CodeWriter($this->_state);
     $codewriter->doComment("\n*** DO NOT EDIT THIS FILE ***\n\nGenerated by PHPTAL from " . $this->_sourceFile . " (edit that file instead)");
     $codewriter->doFunction($this->_functionName, '$tpl, $ctx');
     $codewriter->setFunctionPrefix($this->_functionName . "_");
     $codewriter->doSetVar('$_thistpl', '$tpl');
     $codewriter->doSetVar('$_translator', '$tpl->getTranslator()');
     $treeGen->generateCode($codewriter);
     $codewriter->doEnd();
     return $codewriter->getResult();
 }
コード例 #2
0
ファイル: Repeat.php プロジェクト: rafalenden/KioCMS
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     $this->var = $codewriter->createTempVariable();
     // alias to repeats handler to avoid calling extra getters on each variable access
     $codewriter->doSetVar($this->var, '$ctx->repeat');
     list($varName, $expression) = $this->parseSetExpression($this->expression);
     $code = $codewriter->evaluateExpression($expression);
     // instantiate controller using expression
     $codewriter->doSetVar($this->var . '->' . $varName, 'new PHPTAL_RepeatController(' . $code . ')' . "\n");
     $codewriter->pushContext();
     // Lets loop the iterator with a foreach construct
     $codewriter->doForeach('$ctx->' . $varName, $this->var . '->' . $varName);
 }
コード例 #3
0
ファイル: FillSlot.php プロジェクト: palmic/lbox
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     if ($this->shouldUseCallback()) {
         $function_base_name = 'slot_' . preg_replace('/[^a-z0-9]/', '_', $this->expression) . '_' . self::$uid++;
         $codewriter->doFunction($function_base_name, 'PHPTAL $_thistpl, PHPTAL $tpl');
         $this->function_name = $codewriter->getFunctionPrefix() . $function_base_name;
         $codewriter->doSetVar('$ctx', '$tpl->getContext()');
         $codewriter->doSetVar('$_translator', '$tpl->getTranslator()');
     } else {
         $codewriter->pushCode('ob_start()');
         $this->function_name = NULL;
     }
 }
コード例 #4
0
ファイル: DefineMacro.php プロジェクト: indynagpal/MateCat
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     $macroname = strtr(trim($this->expression), '-', '_');
     if (!preg_match('/^[a-z0-9_]+$/i', $macroname)) {
         throw new PHPTAL_ParserException('Bad macro name "' . $macroname . '"', $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
     }
     if ($codewriter->functionExists($macroname)) {
         throw new PHPTAL_TemplateException("Macro {$macroname} is defined twice", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
     }
     $codewriter->doFunction($macroname, 'PHPTAL $_thistpl, PHPTAL $tpl');
     $codewriter->doSetVar('$tpl', 'clone $tpl');
     $codewriter->doSetVar('$ctx', '$tpl->getContext()');
     $codewriter->doInitTranslator();
     $codewriter->doXmlDeclaration(true);
     $codewriter->doDoctype(true);
 }
コード例 #5
0
ファイル: DefineSlot.php プロジェクト: indynagpal/MateCat
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     $this->tmp_var = $codewriter->createTempVariable();
     $codewriter->doSetVar($this->tmp_var, $codewriter->interpolateTalesVarsInString($this->expression));
     $codewriter->doIf('$ctx->hasSlot(' . $this->tmp_var . ')');
     $codewriter->pushCode('$ctx->echoSlot(' . $this->tmp_var . ')');
     $codewriter->doElse();
 }
コード例 #6
0
ファイル: Id.php プロジェクト: rafalenden/KioCMS
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     // retrieve trigger
     $this->var = $codewriter->createTempVariable();
     $codewriter->doSetVar($this->var, '$tpl->getTrigger(' . $codewriter->str($this->expression) . ')');
     // if trigger found and trigger tells to proceed, we execute
     // the node content
     $codewriter->doIf($this->var . ' &&
         ' . $this->var . '->start(' . $codewriter->str($this->expression) . ', $tpl) === PHPTAL_Trigger::PROCEED');
 }
コード例 #7
0
ファイル: Cache.php プロジェクト: jo-m/ecamp3
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     // number or variable name followed by time unit
     // optional per expression
     if (!preg_match('/^\\s*([0-9]+\\s*|[a-zA-Z][\\/a-zA-Z0-9_]*\\s+)([dhms])\\s*(?:\\;?\\s*per\\s+([^;]+)|)\\s*$/', $this->expression, $matches)) {
         throw new PHPTAL_ParserException("Cache attribute syntax error: " . $this->expression, $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
     }
     $cache_len = $matches[1];
     if (!is_numeric($cache_len)) {
         $cache_len = $codewriter->evaluateExpression($cache_len);
         if (is_array($cache_len)) {
             throw new PHPTAL_ParserException("Chained expressions in cache length are not supported", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
         }
     }
     switch ($matches[2]) {
         case 'd':
             $cache_len .= '*24';
             /* no break */
         /* no break */
         case 'h':
             $cache_len .= '*60';
             /* no break */
         /* no break */
         case 'm':
             $cache_len .= '*60';
             /* no break */
     }
     $cache_tag = '"' . addslashes($this->phpelement->getQualifiedName() . ':' . $this->phpelement->getSourceLine()) . '"';
     $cache_per_expression = isset($matches[3]) ? trim($matches[3]) : null;
     if ($cache_per_expression == 'url') {
         $cache_tag .= '.$_SERVER["REQUEST_URI"]';
     } elseif ($cache_per_expression == 'nothing') {
         /* do nothing */
     } elseif ($cache_per_expression) {
         $code = $codewriter->evaluateExpression($cache_per_expression);
         if (is_array($code)) {
             throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
         }
         $cache_tag = '(' . $code . ')."@".' . $cache_tag;
     }
     $this->cache_filename_var = $codewriter->createTempVariable();
     $codewriter->doSetVar($this->cache_filename_var, $codewriter->str($codewriter->getCacheFilesBaseName()) . '.md5(' . $cache_tag . ')');
     $cond = '!file_exists(' . $this->cache_filename_var . ') || time() - ' . $cache_len . ' >= filemtime(' . $this->cache_filename_var . ')';
     $codewriter->doIf($cond);
     $codewriter->doEval('ob_start()');
 }
コード例 #8
0
ファイル: Define.php プロジェクト: palmic/lbox
 private function doDefineVarWith(PHPTAL_Php_CodeWriter $codewriter, $code)
 {
     if ($this->_defineScope == 'global') {
         $codewriter->doSetVar('$tpl->getGlobalContext()->' . $this->_defineVar, $code);
     } else {
         $codewriter->doSetVar('$ctx->' . $this->_defineVar, $code);
     }
 }
コード例 #9
0
ファイル: Element.php プロジェクト: rafalenden/KioCMS
 public function generateCode(PHPTAL_Php_CodeWriter $codewriter)
 {
     // For backwards compatibility only!
     self::$_codewriter_bc_hack_ = $codewriter;
     // FIXME
     try {
         /// self-modifications
         $this->replacePHPAttributes();
         if ($codewriter->getOutputMode() === PHPTAL::XHTML) {
             $this->replaceTextWithCDATA();
         }
         /// code generation
         if ($codewriter->isDebugOn()) {
             $codewriter->doSetVar('$ctx->_line', $this->getSourceLine());
             $codewriter->doComment('tag "' . $this->qualifiedName . '" from line ' . $this->getSourceLine());
         }
         $this->generateSurroundHead($codewriter);
         if (count($this->replaceAttributes)) {
             foreach ($this->replaceAttributes as $att) {
                 $att->before($codewriter);
                 $att->after($codewriter);
             }
         } elseif (!$this->hidden) {
             // a surround tag may decide to hide us (tal:define for example)
             $this->generateHead($codewriter);
             $this->generateContent($codewriter);
             $this->generateFoot($codewriter);
         }
         $this->generateSurroundFoot($codewriter);
     } catch (PHPTAL_TemplateException $e) {
         $e->hintSrcPosition($this->getSourceFile(), $this->getSourceLine());
         throw $e;
     }
 }