function cs_subtemplate($source, $data, $mod, $action = 'list', $navfiles = 0) { global $account, $cs_lang, $cs_main; $cs_lang = cs_translate($mod); $data = is_array($data) ? $data : array(); $string = cs_cache_theme($mod, $action, $navfiles); $string = cs_conditiontemplate($string, $data); $string = cs_looptemplate($source, $string, $data); $string = preg_replace_callback("={lang:([\\S]*?)}=i", 'cs_templatelang', $string); if ($cs_main['xsrf_protection'] === true) { $string = preg_replace_callback("/<form(.*?)method=\"post\"(.*?)>/i", 'cs_xsrf_protection_field', $string); } if (!empty($navfiles)) { $string = cs_tokenizer_split($string); $theme = cs_tokenizer_parse($string); $string = ''; foreach ($theme as $num => $content) { $string .= $content; } } if (!empty($cs_main['themebar']) and (!empty($cs_main['developer']) or $account['access_clansphere'] > 4)) { include_once 'mods/clansphere/themebar.php'; $string = cs_themebar($source, $string, $mod, $action); } return $string; }
function cs_cache_template($filename) { global $cs_main; $tpl_real = 'templates/' . $cs_main['template'] . '/' . $filename; $tpl_temp = 'tpl_' . $cs_main['template'] . '_' . $cs_main['php_self']['filename'] . '_' . $filename; $tpl_data = cs_cache_load($tpl_temp); if ($tpl_data != false) { if ($cs_main['cache_mode'] != 'file' or filemtime($tpl_real) < filemtime('uploads/cache/' . $tpl_temp . '.tmp')) { return $tpl_data; } } $tpl_data = file_get_contents($tpl_real); $tpl_path = $cs_main['php_self']['dirname'] . 'templates/' . $cs_main['template']; $tpl_data = str_replace('{func:path}', $cs_main['php_self']['dirname'], $tpl_data); if (strpos($tpl_data, 'id="csp_content"') !== false) { cs_error($tpl_real, 'cs_cache_template - The ID tag "csp_content" is reserved for AJAX'); } if (strpos($tpl_data, '{func:stylesheet}') === false) { $tpl_data = str_ireplace('</head>', '{func:stylesheet}</head>', $tpl_data); } if (strpos($tpl_data, '{func:javascript}') === false) { $tpl_data = str_ireplace('</body>', '{func:javascript}</body>', $tpl_data); } if (strpos($tpl_data, '{func:debug}') === false) { $tpl_data = preg_replace('=\\<body(.*?)\\>=si', "<body\\1{func:body_add}>\n{func:debug}", $tpl_data, 1); } else { $tpl_data = preg_replace('=\\<body(.*?)\\>=si', '<body\\1{func:body_add}>', $tpl_data, 1); } $pattern = "=\\<link(.*?)href\\=\"(?!http|\\/)(.*?)\"(.*?)\\>=i"; $tpl_data = preg_replace($pattern, "<link\\1href=\"" . $tpl_path . "/\\2\"\\3>", $tpl_data); $pattern = "=(background|src)\\=\"(?!http|\\/)(.*?)\"=i"; $tpl_data = preg_replace($pattern, "\\1=\"" . $tpl_path . "/\\2\"", $tpl_data); $tpl_data = preg_replace_callback('={url(?:_([\\w]*?))?:([\\w]*?)(?:_([\\w]*?)((?::(?:(?:[\\S]*?{[\\S]*?}[\\S]*?)*?|[\\S]*?))*?))?}=i', 'cs_templateurl', $tpl_data); $tpl_data = str_replace('{func:charset}', $cs_main['charset'], $tpl_data); $tpl_data = cs_tokenizer_split($tpl_data); return cs_cache_save($tpl_temp, $tpl_data); }