Index: trunk/core/kernel/parser/template.php =================================================================== diff -u -N -r4971 -r6093 --- trunk/core/kernel/parser/template.php (.../template.php) (revision 4971) +++ trunk/core/kernel/parser/template.php (.../template.php) (revision 6093) @@ -53,6 +53,10 @@ } else { if ($silent != 2) { + $application =& kApplication::Instance(); + if ($application->isDebugMode()) { + $application->Debugger->appendTrace(); + } trigger_error("File or block not found: $filename", ($silent ? E_USER_NOTICE : E_USER_ERROR) ); } return false; @@ -124,7 +128,7 @@ $path = isset($base) ? $base : $this->BasePath; $module_filename = $first_dir.'/'.$module_filename; } - return $path.'/'.$module_filename; + return $path.'/'.trim($module_filename, '/'); } function SetTemplate($title, &$template, $filename=null) @@ -175,6 +179,61 @@ $real_file = $this->GetRealFilename($filename); return file_exists($real_file); } + + + function GetPreParsed($template) + { + $real_name = $this->GetRealFilename($template); + $fname = $real_name.'.php'; + $fname = str_replace(FULL_PATH, FULL_PATH.'/kernel/cache', $fname); + + $tname = $real_name.'.tpl'; + if (defined('SAFE_MODE') && SAFE_MODE) { + $conn =& $this->Application->GetADODBConnection(); + $cached = $conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$fname.'"'); + if ($cached !== false && $cached['Cached'] > filemtime($tname)) { + return array('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'db', 'content' => $cached['Data']); + } + } + else { + if (file_exists($fname) && file_exists($tname) && filemtime($fname) > filemtime($tname)) { + return array('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'file'); + } + if (!file_exists($fname)) { + // make sure to create directory if pre-parsed file does not exist + $this->CheckDir(dirname($fname), FULL_PATH.'/kernel/cache'); + } + } + return array('active' => 0, 'fname' => $fname, 'tname' => $tname); + } + + /** + * Recursive mkdir + * + * @param string $dir + * @param string $base_path base path to directory where folders should be created in + */ + function CheckDir($dir, $base_path = '') + { + if (file_exists($dir)) { + return; + } + else { + // remove $base_path from beggining because it is already created during install + $dir = preg_replace('/^'.preg_quote($base_path.'/', '/').'/', '', $dir, 1); + $segments = explode('/', $dir); + $cur_path = $base_path; + + foreach ($segments as $segment) { + // do not add leading / for windows paths (c:\...) + $cur_path .= preg_match('/^[a-zA-Z]{1}:/', $segment) ? $segment : '/'.$segment; + if (!file_exists($cur_path)) { + mkdir($cur_path); + } + } + } + } + }