/** * 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'); } }
/** * return the generated content from the given template * @param string $tpl template selector * @param string $outputtype the type of output (html, text etc..) * @param boolean $trusted says if the template file is trusted or not * @param boolean $callMeta false if meta should not be called * @return string the generated content */ public function fetch($tpl, $outputtype = '', $trusted = true, $callMeta = true) { $sel = new jSelectorTpl($tpl, $outputtype, $trusted); $tpl = $sel->toString(); return $this->_fetch($tpl, $sel, $outputtype, $trusted, $callMeta); }
/** * */ protected function _otherthings() { // overlays // browser sniffing, because "&" should be escaped in a xul-overlay PI in gecko 1.9+ $escape = false; if (preg_match('!^Mozilla/5.0 \\(.* rv:(\\d)\\.(\\d).*\\) Gecko/\\d+.*$!', $_SERVER["HTTP_USER_AGENT"], $m)) { if (version_compare($m[1] . '.' . $m[2], '1.9') >= 0) { $escape = true; } } if ($this->fetchOverlays) { $sel = new jSelectorTpl($this->bodyTpl); $eventresp = jEvent::notify('FetchXulOverlay', array('tpl' => $sel->toString())); foreach ($eventresp->getResponse() as $rep) { if (is_array($rep)) { $this->_overlays[jUrl::get($rep[0], $rep[1])] = true; } elseif (is_string($rep)) { $this->_overlays[jUrl::get($rep)] = true; } } } foreach ($this->_overlays as $src => $ok) { echo '<?xul-overlay href="', $escape ? htmlspecialchars($src) : $src, '" ?>', "\n"; } $this->rootAttributes['title'] = $this->title; }
/** * return the generated content from the given template * @param string $tpl template selector * @param string $outputtype the type of output (html, text etc..) * @param boolean $trusted says if the template file is trusted or not * @param boolean $callMeta false if meta should not be called * @return string the generated content */ public function fetch($tpl, $outputtype = '', $trusted = true, $callMeta = true) { $content = ''; ob_start(); try { #ifnot JTPL_STANDALONE $sel = new jSelectorTpl($tpl, $outputtype, $trusted); $tpl = $sel->toString(); #endif $previousTpl = $this->_templateName; $this->_templateName = $tpl; $this->processedMeta[] = $tpl; $this->recursiveTpl[] = $tpl; #ifnot JTPL_STANDALONE $md = $this->getTemplate($sel, $outputtype, $trusted); #else $md = $this->getTemplate($tpl, $outputtype, $trusted); #endif if ($callMeta) { $fct = 'template_meta_' . $md; $fct($this); } $fct = 'template_' . $md; $fct($this); array_pop($this->recursiveTpl); $this->_templateName = $previousTpl; $content = ob_get_clean(); } catch (Exception $e) { ob_end_clean(); throw $e; } return $content; }