<?php
namespace apphomecontroller;
use corebasicController;
use apphomemodelParserModel;
use corebasicUrl;
class ParserCo
ntroller extends Co
ntroller
{
protected $model;
protected $pre = array();
protected $var = array();
public function __co
nstruct()
{
$this->model = new ParserModel();
}
public function _empty()
{
error('您访问的地址有误,请核对后重试!');
}
// 解析全局前置公共标签
public function parserBefore($content)
{
// 处理模板中不需要解析的标签
$co
ntent = $this->savePreLabel($content);
return $content;
}
// 解析全局后置公共标签
public function parserAfter($content)
{
// 默认页面信息替换
$co
ntent = str_replace('{pboot:pagetitle}', '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$co
ntent = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content);
$co
ntent = str_replace('{pboot:pagedes
cription}', '{pboot:sitedes
cription}', $content);
$co
ntent = $this->parserSingleLabel($content); // 单标签解析
$co
ntent = $this->parserSiteLabel($content); // 站点标签
$co
ntent = $this->parserCompanyLabel($content); // 公司标签
$co
ntent = $this->parserUserLabel($content); // 自定义标签
$co
ntent = $this->parserNavLabel($content); // 分类列表
$co
ntent = $this->parserSelectAllLabel($content); // CMS筛选全部标签解析
$co
ntent = $this->parserSelectLabel($content); // CMS筛选标签解析
$co
ntent = $this->parserSpecifySortLabel($content); // 指定分类
$co
ntent = $this->parserListLabel($content); // 指定列表
$co
ntent = $this->parserSpecifyCo
ntentLabel($content); // 指定内容
$co
ntent = $this->parserCo
ntentPicsLabel($content); // 内容多图
$co
ntent = $this->parserCo
ntentCheckboxLabel($content); // 内容多选调取
$co
ntent = $this->parserCo
ntentTagsLabel($content); // 内容tags调取
$co
ntent = $this->parserSlideLabel($content); // 幻灯片
$co
ntent = $this->parserl
inkLabel($content); // 友情链接
$co
ntent = $this->parserMessageLabel($content); // 留言板
$co
ntent = $this->parserFormLabel($content); // 自定义表单
$co
ntent = $this->parserSubmitFormLabel($content); // 自定义表单提交
$co
ntent = $this->parserQrcodeLabel($content); // 二维码生成
$co
ntent = $this->parserPageLabel($content); // CMS分页标签解析(需置后)
$co
ntent = $this->parserLoopLabel($content); // LOOP语句(需置后)
$co
ntent = $this->parserIfLabel($content); // IF语句(需置最后)
$co
ntent = $this->restorePreLabel($content); // 还原不需要解析的内容
$co
ntent = $this->parserReplaceKeywor
d($content); // 页面关键词替换
return $content;
}
// 保存保留内容
public function savePreLabel($content)
{
$pattern = '/{pboot:pre}([sS]*?){/pboot:pre}/';
if (preg_match_all($pattern, $content, $matches)) {
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$this->pre[] = $matches[1][$i];
end($this->pre);
$co
ntent = str_replace($matches[0][$i], '#pre:' . key($this->pre) . '#', $content);
}
}
return $content;
}
// 还原保留内容
public function restorePreLabel($content)
{
$pattern = '/#pre:([0-9]+)#/';
if (preg_match_all($pattern, $content, $matches)) {
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$co
ntent = str_replace($matches[0][$i], $this->pre[$matches[1][$i]], $content);
}
}
return $content;
}
// 解析单标签
public function parserSingleLabel($content)
{
$co
ntent = str_replace('{pboot:msgaction}', Url::home('home/Index/addMsg'), $content); // 留言提交路径
$co
ntent = str_replace('{pboot:scaction}', Url::home('home/Index/search'), $content); // 搜索提交路径
$co
ntent = str_replace('{pboot:checkcode}', CORE_DIR . '/code.php', $content); // 验证码路径
$co
ntent = str_replace('{pboot:lgpath}', Url::get('home/Do/area'), $content); // 多语言切换前置路径,如{pboot:lgpath}?lg=cn
$co
ntent = str_replace('{pboot:appid}', $this->co
nfig('api_appid'), $content); // API认证用户
$co
ntent = str_replace('{pboot:timestamp}', time(), $content); // 认证时间戳
$co
ntent = str_replace('{pboot:signature}', md5(md5($this->co
nfig('api_appid') . $this->co
nfig('api_secret') . time())), $content); // API认证密钥
$co
ntent = str_replace('{pboot:httpurl}', get_http_url(), $content); // 当前访问的域名地址
$co
ntent = str_replace('{pboot:pageurl}', get_current_url(), $content); // 当前页面的地址
$co
ntent = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 当前搜索的关键字
$co
ntent = str_replace('{pboot:checkcodestatus}', $this->co
nfig('message_check_code'), $content); // 是否开启验证码
return $content;
}
// 解析站点标签
public function parserSiteLabel($content)
{
$pattern = '/{pboot:site([w]+)(s+[^}]+)?}/';
if (preg_match_all($pattern, $content, $matches)) {
$data = $this->model->getSite();
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$params = $this->parserParam($matches[2][$i]);
switch ($matches[1][$i]) {
case 'index':
$co
ntent = str_replace($matches[0][$i], Url::home('home/Index/'), $content);
break;
case 'path':
$co
ntent = str_replace($matches[0][$i], SITE_DIR, $content);
break;
case 'logo':
if (isset($data->logo) && $data->logo) {
if (! preg_match('/^http/', $data->logo)) {
$co
ntent = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->logo), $content);
} else {
$co
ntent = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->logo), $content);
}
} else {
$co
ntent = str_replace($matches[0][$i], STATIC_DIR . '/images/logo.png', $content);
}
break;
case 'tplpath':
$co
ntent = str_replace($matches[0][$i], APP_THEME_DIR, $content);
break;
case 'language':
$co
ntent = str_replace($matches[0][$i], get_lg(), $content);
break;
case 'statistical':
if (isset($data->statistical)) {
$co
ntent = str_replace($matches[0][$i], decode_string($data->statistical), $content);
} else {
$co
ntent = str_replace($matches[0][$i], '', $content);
}
case 'copyright':
if (isset($data->copyright)) {
$co
ntent = str_replace($matches[0][$i], decode_string($data->copyright), $content);
} else {
$co
ntent = str_replace($matches[0][$i], '', $content);
}
default: