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) { global $_W; $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|home\/welcome|cloud\/upgrade|cloud\/sms)+/', $from)) { $content = str_replace('微擎', '系统', $content); } if (defined('IN_MODULE') && module_get_direct_enter_status($_W['current_module']['name']) == STATUS_ON && !preg_match('/\var we7CommonForModule.*document\.body\.appendChild\(we7CommonForModule\)\<\/script\>/', $content) && !preg_match('/(footer|header|account\/welcome|module\/welcome)+/', $from)) { $extra_code = ""; $content .= $extra_code; } 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_callback('/{hook\s+(.+?)}/s', "template_modulehook_parser", $str); $str = preg_replace('/{\/hook}/', '', $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); } function template_modulehook_parser($params = array()) { load()->model('module'); if (empty($params[1])) { return ''; } $params = explode(' ', $params[1]); if (empty($params)) { return ''; } $plugin = array(); foreach ($params as $row) { $row = explode('=', $row); $plugin[$row[0]] = str_replace(array("'", '"'), '', $row[1]); $row[1] = urldecode($row[1]); } $plugin_info = module_fetch($plugin['module']); if (empty($plugin_info)) { return false; } if (empty($plugin['return']) || $plugin['return'] == 'false') { } else { } if (empty($plugin['func']) || empty($plugin['module'])) { return false; } if (defined('IN_SYS')) { $plugin['func'] = "hookWeb{$plugin['func']}"; } else { $plugin['func'] = "hookMobile{$plugin['func']}"; } $plugin_module = WeUtility::createModuleHook($plugin_info['name']); if (method_exists($plugin_module, $plugin['func']) && $plugin_module instanceof WeModuleHook) { $hookparams = var_export($plugin, true); if (!empty($hookparams)) { $hookparams = preg_replace("/'(\\$[a-zA-Z_\x7f-\xff\[\]\']*?)'/", '$1', $hookparams); } else { $hookparams = 'array()'; } $php = " {$hookparams})); ?>"; return $php; } else { $php = ""; return $php; } }