/** * Launch the compilation of a template * * Store the result (a php content) into a cache file given by the selector. * @param jSelectorTpl $selector the template selector * @return boolean true if ok */ public function compile($selector) { $this->_sourceFile = $selector->getPath(); $cachefile = $selector->getCompiledFilePath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $this->_modifier = array_merge($this->_modifier, $selector->userModifiers); $this->_userFunctions = $selector->userFunctions; jContext::push($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $result = $this->compileContent(file_get_contents($this->_sourceFile)); $header = "<?php \n"; foreach ($this->_pluginPath as $path => $ok) { $header .= ' require_once(\'' . $path . "');\n"; } $header .= 'function template_meta_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){'; $header .= "\n" . $this->_metaBody . "\n}\n"; $header .= 'function template_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){' . "\n?>"; $result = $header . $result . "<?php \n}\n?>"; jFile::write($cachefile, $result); jContext::pop(); return true; }
/** * Launch the compilation of a template * * Store the result (a php content) into a cache file given by the selector. * @param jSelectorTpl $selector the template selector * @return boolean true if ok */ public function compile($selector) { $this->_sourceFile = $selector->getPath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $md5 = md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')); jApp::pushCurrentModule($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $header = "if (jApp::config()->compilation['checkCacheFiletime'] &&\n"; $header .= "filemtime('" . $this->_sourceFile . '\') > ' . filemtime($this->_sourceFile) . "){ return false;\n} else {\n"; $footer = "return true;}\n"; $this->compileString(file_get_contents($this->_sourceFile), $selector->getCompiledFilePath(), $selector->userModifiers, $selector->userFunctions, $md5, $header, $footer); jApp::popCurrentModule(); return true; }
function testPlugin() { foreach ($this->templates as $k => $t) { // we delete the cache because it won't be updated // if changes are made in jTpl itself or plugins $sel = new jSelectorTpl($t[0]); //, $outputtype='', $trusted = true $cache = $sel->getCompiledFilePath(); if (file_exists($cache)) { unlink($cache); } $tpl = new jTpl(); $tpl->assign('i', 0); // Pour les boucles for. $output = $tpl->fetch($t[0]); //, $outputtype='', $trusted = true, $callMeta=true $expected = $t[1]; if (strpos($t[1], '%BASEPATH%') !== false) { $expected = str_replace('%BASEPATH%', $GLOBALS['gJConfig']->urlengine['basePath'], $expected); } $this->assertEqualOrDiff($output, $expected, 'testplugin[' . $k . '], %s'); } }