private function parseEyouInclude(&$content)
{
$regex = $this->getRegex('eyou:include');
$func = function ($template) use (&$func, &$regex, &$content) {
if (preg_match_all($regex, $template, $matches, PREG_SET_ORDER)) {
$tpl_theme = trim(TPL_THEME, '/');
/*會員中心模板切換*/
static $web_users_tpl_theme = null;
if (null == $web_users_tpl_theme) {
$web_users_tpl_theme = config('ey_config.web_users_tpl_theme');
}
static $users_wap_tpl_dir = null;
if (null == $users_wap_tpl_dir) {
$users_wap_tpl_dir = config('ey_config.users_wap_tpl_dir');
}
static $is_mobile = null;
if (null == $is_mobile) {
$is_mobile = isMobile();
}
static $city_switch_on = null;
if (null == $city_switch_on) {
$city_switch_on = config('city_switch_on');
}
static $site_template = null;
if ($city_switch_on && null == $site_template) {
$site_template = config('tpcache.site_template');
}
static $home_site = null;
if (null == $home_site) {
$home_site = get_home_site();
}
/*end*/
foreach ($matches as $match) {
$array = $this->parseAttr($match[0]);
$file = $array['file'];
if ( (defined('MODULE_NAME') && 'admin' != MODULE_NAME) || !defined('MODULE_NAME') && 'admin' != Request::instance()->module() ) {
if (!empty($is_mobile)) {
if (file_exists('./template/'.TPL_THEME.'pc/'.$web_users_tpl_theme.'/'.$users_wap_tpl_dir.'/users_login.htm') && preg_match('/^users(_([^\/]*))?\//i', $file)) {
$file = str_ireplace("{$web_users_tpl_theme}/", "{$web_users_tpl_theme}/{$users_wap_tpl_dir}/", $file);
}
else if (!is_dir('./weapp/Ask/') && file_exists('./template/'.TPL_THEME.'pc/ask/'.$users_wap_tpl_dir) && preg_match('/^ask(_([^\/]*))?\//i', $file)) {
$file = str_ireplace("ask/", "ask/{$users_wap_tpl_dir}/", $file);
}
}
$file = preg_replace('/^users(_([^\/]*))?\//', $web_users_tpl_theme.'/', $file); // 支持會員中心模板切換
}
if (preg_match('/^([^\\/]+)(.*)\.'.$this->config['view_suffix'].'$/i', $file) === 1) {
$file = str_replace('.'.$this->config['view_suffix'], '', $file);
// 多城市站點的獨立模板
if ($city_switch_on && !empty($site_template) && !empty($home_site) && !preg_match('/^users(_([^\/]*))?\//i', $file)) {
if (file_exists('./template/'.THEME_STYLE_PATH.'/city/'.$home_site)) {
$file = 'city/'.$home_site.'/'.$file;
} else if (file_exists('./template/'.THEME_STYLE_PATH.'/'.$home_site)) {
$file = $home_site.'/'.$file;
}
}
} else if (stristr($file, '.'.$this->config['view_suffix']) && (stristr($file, '/') || stristr($file, '\\'))) {
$file = '.'.$file;
if (preg_match('/\/template\/(pc|mobile)\//i', $file)) {
$file = str_replace('./template/', './template/'.TPL_THEME, $file);
}
// 支持會員中心模板切換
$file = preg_replace('/\/template\/'.$tpl_theme.'\/(pc|mobile)\/users(_([^\/]*))?\//', '/template/'.$tpl_theme.'/${1}/'.$web_users_tpl_theme.'/', $file);
}
unset($array['file']);
// 分析模板文件名并讀取內(nèi)容
$parseStr = $this->parseTemplateName($file);
foreach ($array as $k => $v) {
// 以$開頭字符串轉(zhuǎn)換成模板變量
if (0 === strpos($v, '$')) {
$v = $this->get(substr($v, 1));
}
$parseStr = str_replace('[' . $k . ']', $v, $parseStr);
}
$content = str_replace($match[0], $parseStr, $content);
// 再次對包含文件進行模板分析
$func($parseStr);
}
unset($matches);
}
};
// 替換模板中的include標(biāo)簽
$func($content);
return;
}