filemtime($compile)) { template_compile($source, $compile); } switch ($flag) { case TEMPLATE_DISPLAY: default: extract($GLOBALS, EXTR_SKIP); include $compile; break; case TEMPLATE_FETCH: extract($GLOBALS, EXTR_SKIP); ob_flush(); ob_clean(); ob_start(); include $compile; $contents = ob_get_contents(); ob_clean(); return $contents; break; case TEMPLATE_INCLUDEPATH: return $compile; break; } } function template_compile($from, $to, $inmodule = false) { $path = dirname($to); if (!is_dir($path)) { load()->func('file'); mkdirs($path); } $content = template_parse(file_get_contents($from), $inmodule); if (IMS_FAMILY == 'x' && !preg_match('/(footer|header|account\/welcome|login|register)+/', $from)) { $content = str_replace('餐饮', '系统', $content); } file_put_contents($to, $content); } function template_parse($str, $inmodule = false) { $str = preg_replace('//s', '{$1}', $str); $str = preg_replace('/{template\s+(.+?)}/', 'template($1, TEMPLATE_INCLUDEPATH)) : (include template($1, TEMPLATE_INCLUDEPATH));?>', $str); $str = preg_replace('/{php\s+(.+?)}/', '', $str); $str = preg_replace('/{if\s+(.+?)}/', '', $str); $str = preg_replace('/{else}/', '', $str); $str = preg_replace('/{else ?if\s+(.+?)}/', '', $str); $str = preg_replace('/{\/if}/', '', $str); $str = preg_replace('/{loop\s+(\S+)\s+(\S+)}/', '', $str); $str = preg_replace('/{loop\s+(\S+)\s+(\S+)\s+(\S+)}/', ' $3) { ?>', $str); $str = preg_replace('/{\/loop}/', '', $str); $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)}/', '', $str); $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\[\]\'\"\$]*)}/', '', $str); $str = preg_replace('/{url\s+(\S+)}/', '', $str); $str = preg_replace('/{url\s+(\S+)\s+(array\(.+?\))}/', '', $str); $str = preg_replace('/{media\s+(\S+)}/', '', $str); $str = preg_replace_callback('/<\?php([^\?]+)\?>/s', "template_addquote", $str); $str = preg_replace('/{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)}/s', '', $str); $str = str_replace('{##', '{', $str); $str = str_replace('##}', '}', $str); if (!empty($GLOBALS['_W']['setting']['remote']['type'])) { $str = str_replace('', "", $str); } $str = "" . $str; return $str; } function template_addquote($matchs) { $code = ""; $code = preg_replace('/\[([a-zA-Z0-9_\-\.\x7f-\xff]+)\](?![a-zA-Z0-9_\-\.\x7f-\xff\[\]]*[\'"])/s', "['$1']", $code); return str_replace('\\\"', '\"', $code); }