Exemplo n.º 1
0
 public function cache($file)
 {
     $tplfile = $this->_getTplFile($file);
     if (!is_readable($tplfile)) {
         $this->_throwException("throwException \"{$tplfile}\" throwException");
     }
     $template = file_get_contents($tplfile);
     for ($i = 1; $i <= 3; $i++) {
         if (GlobalFunc::strexists($template, '{subtemplate')) {
             $template = preg_replace("/[\n\r\t]*\\{subtemplate\\s+([a-z0-9_]+)\\}[\n\r\t]*/ies", "loadsubtemplate('\\1')", $template);
         }
     }
     $template = preg_replace("/\\<\\!\\-\\-\\{(.+?)\\}\\-\\-\\>/s", "{\\1}", $template);
     $template = str_replace("{LF}", "<?=\"\\n\"?>", $template);
     $varRegexp = "((\\\$[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*)" . "(\\[[a-zA-Z0-9_\\-\\.\"\\'\\[\\]\$-ÿ]+\\])*)";
     $template = preg_replace("/\\{(\\\$[a-zA-Z0-9_\\[\\]\\'\"\$\\.-ÿ]+)\\}/s", "<?=\\1?>", $template);
     $template = preg_replace("/{$varRegexp}/es", "addquote('<?=\\1?>')", $template);
     $template = preg_replace("/\\<\\?\\=\\<\\?\\={$varRegexp}\\?\\>\\?\\>/es", "addquote('<?=\\1?>')", $template);
     $template = preg_replace("/[\n\r\t]*\\{template\\s+([a-z0-9_]+)\\}[\n\r\t]*/is", "\r\n<? include(\$template->getfile('\\1')); ?>\r\n", $template);
     $template = preg_replace("/[\n\r\t]*\\{template\\s+(.+?)\\}[\n\r\t]*/is", "\r\n<? include(\$template->getfile(\\1)); ?>\r\n", $template);
     $template = preg_replace("/[\n\r\t]*\\{eval\\s+(.+?)\\}[\n\r\t]*/ies", "stripvtags('<? \\1 ?>','')", $template);
     $template = preg_replace("/[\n\r\t]*\\{echo\\s+(.+?)\\}[\n\r\t]*/ies", "stripvtags('<? echo \\1; ?>','')", $template);
     $template = preg_replace("/([\n\r\t]*)\\{elseif\\s+(.+?)\\}([\n\r\t]*)/ies", "stripvtags('\\1<? } elseif(\\2) { ?>\\3','')", $template);
     $template = preg_replace("/([\n\r\t]*)\\{else\\}([\n\r\t]*)/is", "\\1<? } else { ?>\\2", $template);
     $nest = 5;
     for ($i = 0; $i < $nest; $i++) {
         $template = preg_replace("/[\n\r\t]*\\{loop\\s+(\\S+)\\s+(\\S+)\\}[\n\r]*(.+?)[\n\r]*\\{\\/loop\\}[\n\r\t]*/ies", "stripvtags('<? if(is_array(\\1)) { foreach(\\1 as \\2) { ?>','\\3<? } } ?>')", $template);
         $template = preg_replace("/[\n\r\t]*\\{loop\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\}[\n\r\t]*(.+?)[\n\r\t]*\\{\\/loop\\}[\n\r\t]*/ies", "stripvtags('<? if(is_array(\\1)) { foreach(\\1 as \\2 => \\3) { ?>','\\4<? } } ?>')", $template);
         $template = preg_replace("/([\n\r\t]*)\\{if\\s+(.+?)\\}([\n\r]*)(.+?)([\n\r]*)\\{\\/if\\}([\n\r\t]*)/ies", "stripvtags('\\1<? if(\\2) { ?>\\3','\\4\\5<? } ?>\\6')", $template);
     }
     $template = preg_replace("/\\{([a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*)\\}/s", "<?=\\1?>", $template);
     $template = preg_replace("/ \\?\\>[\n\r]*\\<\\? /s", " ", $template);
     $template = preg_replace("/\"(http)?[\\w\\.\\/:]+\\?[^\"]+?&[^\"]+?\"/e", "transamp('\\0')", $template);
     $template = preg_replace("/\\<script[^\\>]*?src=\"(.+?)\".*?\\>\\s*\\<\\/script\\>/ise", "stripscriptamp('\\1')", $template);
     $template = preg_replace("/[\n\r\t]*\\{block\\s+([a-zA-Z0-9_]+)\\}(.+?)\\{\\/block\\}/ies", "stripblock('\\1', '\\2')", $template);
     $md5data = md5_file($tplfile);
     $expireTime = time();
     $template = "<? if (!class_exists('template')) die('Access Denied');" . "\$template->getInstance()->check('{$file}', '{$md5data}', {$expireTime});" . "?>\r\n{$template}";
     $cachefile = $this->_getCacheFile($file);
     $makepath = $this->_makepath($cachefile);
     if ($makepath !== true) {
         $this->_throwException("throwException \"{$makepath}\"");
     }
     file_put_contents($cachefile, $template);
 }