function processor_tpl_(&$formatter, $source, $params = array()) { global $Config; #if (!$Config['use_tpl']) return $source; $cache = new Cache_text("tpl_"); if (!empty($source)) { $id = md5($source); $mtime = $formatter->page->mtime(); } else { if ($params['path']) { $id = md5_file($params['path']); $mtime = filemtime($params['path']); } } $params['uniq'] = $id; $params['formatter'] =& $formatter; $params['cache_head'] = '/* Template_ ' . __TEMPLATE_UNDERSCORE_VER__ . ' ' . $id . (!empty($params['path']) ? ' ' . $params['path'] : '') . ' */'; $TPL_VAR =& $formatter->_vars; if (empty($formatter->preview) and $cache->exists($id) and $cache->mtime($id) > $mtime) { $params['_vars'] =& $formatter->_vars; $ret = $cache->fetch($id, $mtime, $params); if ($ret === true) { return ''; } if (!empty($params['print'])) { return eval('?' . '>' . $ret . '<' . '?php '); } if (!empty($params['raw'])) { return $ret; } ob_start(); eval('?' . '>' . $ret . '<' . '?php '); $fetch = ob_get_contents(); ob_end_clean(); return $fetch; } $formatter->plugin_dir = 'plugin'; # $formatter->safe_mode = 1; # XXX $compiler = new Template_Compiler_(); if ($source[0] == '#' and $source[1] == '!') { list($line, $source) = explode("\n", $source, 2); } //if (!empty($line)) list($tag,$args)=explode(' ',$line,2); $out = $compiler->_compile_template($formatter, $source, $params); if (!$formatter->preview) { $cache->update($id, $out, 0, array('type' => 'php')); } if (!empty($params['print'])) { return eval('?' . '>' . $out . '<' . '?php '); } if (!empty($params['raw'])) { return $out; } #print '<pre>'.(preg_replace('/</','<',$out)).'</pre>'; ob_start(); eval('?' . '>' . $out . '<' . '?php '); $fetch = ob_get_contents(); ob_end_clean(); return $fetch; }
function _get_compile_path($rel_path) { $compile_ext = $this->compile_ext; if ($R = strpos($rel_path, '?')) { $compile_ext = substr($rel_path, $R + 1) . '.' . $compile_ext; // $compile_ext contains division id. $rel_path = substr($rel_path, 0, $R); } if (!$this->compile_dir) { $this->compile_dir = '.'; } $compile_base = $this->compile_dir . '/' . ($this->skin ? $this->skin . '/' : '') . $rel_path; // $compile_base is compile path without [ extension and division id ] and passed over to compiler if ($this->path_digest) { // enable path_digest to use abs path for $compile_dir and rel path for $template_dir $compile_base = $this->compile_dir . '/@digest/' . basename($rel_path) . '_' . md5($compile_base); } $compile_path = $compile_base . '.' . $compile_ext; if (!$this->compile_check) { return $compile_path; } $template_path = $this->template_dir . '/' . ($this->skin ? $this->skin . '/' : '') . $rel_path; if (@(!is_file($template_path))) { $this->exit_('Error #1', 'cannot find defined template <b>' . $template_path . '</b>'); } $template_path = realpath($template_path); $filemtime = @date('Y/m/d H:i:s', filemtime($template_path)); $compile_header = '<?php /* Template_ 2.2.8 ' . $filemtime . ' ' . $template_path . ' '; if ($this->compile_check !== 'dev' && @is_file($compile_path)) { $fp = fopen($compile_path, 'rb'); $head = fread($fp, strlen($compile_header) + 9); fclose($fp); if (strlen($head) > 9 && $compile_header == substr($head, 0, -9) && filesize($compile_path) == (int) substr($head, -9)) { return $compile_path; } } include_once dirname(__FILE__) . '/Template_Compiler_.php'; $compiler = new Template_Compiler_(); $compiler->_compile_template($this, $template_path, $compile_base, $compile_header); return $compile_path; }
function _get_compile_path($rpath) { $cpl_ext = $this->compile_ext; if ($R = strpos($rpath, '?')) { $cpl_ext = substr($rpath, $R + 1) . '.' . $cpl_ext; $rpath = substr($rpath, 0, $R); } if (!$this->compile_dir) { $this->compile_dir = '.'; } $cpl_base = $this->compile_dir . '/' . ($this->skin ? $this->skin . '/' : '') . $rpath; if ($this->path_digest) { $cpl_base = $this->compile_dir . '/@digest/' . basename($rpath) . '_' . md5($cpl_base); } $cpl_path = $cpl_base . '.' . $cpl_ext; if (!$this->compile_check) { return $cpl_path; } $tpl_path = $this->template_dir . '/' . ($this->skin ? $this->skin . '/' : '') . $rpath; if (@(!is_file($tpl_path))) { $this->exit_('Error #1', 'cannot find defined template <b>' . $tpl_path . '</b>'); } $tpl_path = realpath($tpl_path); $cpl_head = '<?php /* Template_ 2.2.4 ' . date('Y/m/d H:i:s', filemtime($tpl_path)) . ' ' . $tpl_path . ' '; if ($this->compile_check !== 'dev' && @is_file($cpl_path)) { $fp = fopen($cpl_path, 'rb'); $head = fread($fp, strlen($cpl_head) + 9); fclose($fp); if (strlen($head) > 9 && $cpl_head == substr($head, 0, -9) && filesize($cpl_path) == (int) substr($head, -9)) { return $cpl_path; } } // echo "<code>-=-=- Compiling ${tpl_path} -=-=-</code>"; include_once dirname(__FILE__) . '/Template_.compiler.php'; $compiler = new Template_Compiler_(); $compiler->_compile_template($this, $tpl_path, $cpl_base, $cpl_head); return $cpl_path; }