'index',
'header' => 'common/header',
'footer' => 'common/footer',
'slide' => 'common/slide',
);
if(!empty($mapping[$filename])) {
return $mapping[$filename];
}
return '';
}
function template_page($id, $flag = TEMPLATE_DISPLAY) {
global $_W;
$page = pdo_fetch("SELECT * FROM ".tablename('site_page')." WHERE id = :id LIMIT 1", array(':id' => $id));
if (empty($page)) {
return error(1, 'Error: Page is not found');
}
if (empty($page['html'])) {
return '';
}
$page['html'] = str_replace(array('', '<%', ' $page['description'], 'title' => $page['title'], 'imgUrl' => tomedia($page['params']['0']['params']['thumb']));;
$compile = IA_ROOT . "/data/tpl/app/{$id}.{$_W['template']}.tpl.php";
$path = dirname($compile);
if (!is_dir($path)) {
load()->func('file');
mkdirs($path);
}
$content = template_parse($page['html']);
if (!empty($page['params'][0]['params']['bgColor'])) {
$content .= '';
}
$GLOBALS['bottom_menu'] = $page['params'][0]['property'][0]['params']['bottom_menu'];
file_put_contents($compile, $content);
switch ($flag) {
case TEMPLATE_DISPLAY:
default:
extract($GLOBALS, EXTR_SKIP);
template('common/header');
include $compile;
template('common/footer');
break;
case TEMPLATE_FETCH:
extract($GLOBALS, EXTR_SKIP);
ob_clean();
ob_start();
include $compile;
$contents = ob_get_contents();
ob_clean();
return $contents;
break;
case TEMPLATE_INCLUDEPATH:
return $compile;
break;
}
}
function template($filename, $flag = TEMPLATE_DISPLAY) {
global $_W, $_GPC;
$source = IA_ROOT . "/app/themes/{$_W['template']}/{$filename}.html";
$compile = IA_ROOT . "/data/tpl/app/{$_W['template']}/{$filename}.tpl.php";
if(!is_file($source)) {
$compatFilename = template_compat($filename);
if(!empty($compatFilename)) {
return template($compatFilename, $flag);
}
}
if(!is_file($source)) {
$source = IA_ROOT . "/app/themes/default/{$filename}.html";
$compile = IA_ROOT . "/data/tpl/app/default/{$filename}.tpl.php";
}
if(!is_file($source)) {
exit("Error: template source '{$filename}' is not exist!");
}
$paths = pathinfo($compile);
$compile = str_replace($paths['filename'], $_W['uniacid'] . '_' . intval($_GPC['t']) . '_' . $paths['filename'], $compile);
if(DEVELOPMENT || !is_file($compile) || filemtime($source) > 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_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) {
$path = dirname($to);
if (!is_dir($path)) {
load()->func('file');
mkdirs($path);
}
$content = template_parse(file_get_contents($from));
file_put_contents($to, $content);
}
function template_parse($str) {
$check_repeat_template = array(
"'common\\/header'",
"'common\\/footer'",
);
foreach ($check_repeat_template as $template) {
if (preg_match_all('/{template\s+'.$template.'}/', $str, $match) > 1) {
$replace = stripslashes($template);
$str = preg_replace('/{template\s+'.$template.'}/i', 'template('.$replace.', TEMPLATE_INCLUDEPATH)) : (include template('.$replace.', TEMPLATE_INCLUDEPATH));?>', $str, 1);
$str = preg_replace('/{template\s+'.$template.'}/i', '', $str);
}
}
$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('/{data\s+(.+?)}/s', "moduledata", $str);
$str = preg_replace_callback('/{hook\s+(.+?)}/s', "template_modulehook_parser", $str);
$str = preg_replace('/{\/data}/', '', $str);
$str = preg_replace('/{\/hook}/', '', $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);
$business_stat_script = "