<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年2月14日
* 标签解析引擎控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\ParserModel;
use core\basic\Url;
class ParserController extends Controller
{
protected $model;
protected $pre = array();
protected $var = array();
public function __construct()
{
$this->model = new ParserModel();
}
public function _empty()
{
error('您访问的地址有误,请核对后重试!');
}
// 解析全局前置公共标签
public function parserBefore($content)
{
// 处理模板中不需要解析的标签
$content = $this->savePreLabel($content);
return $content;
}
// 解析全局后置公共标签
public function parserAfter($content)
{
// 默认页面信息替换
$content = str_replace('{pboot:pagetitle}', '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content);
$content = str_replace('{pboot:pagedescription}', '{pboot:sitedescription}', $content);
$content = $this->parserSingleLabel($content); // 单标签解析
$content = $this->parserSiteLabel($content); // 站点标签
$content = $this->parserCompanyLabel($content); // 公司标签
$content = $this->parserUserLabel($content); // 自定义标签
$content = $this->parserNavLabel($content); // 分类列表
$content = $this->parserSelectAllLabel($content); // CMS筛选全部标签解析
$content = $this->parserSelectLabel($content); // CMS筛选标签解析
$content = $this->parserSpecifySortLabel($content); // 指定分类
$content = $this->parserListLabel($content); // 指定列表
$content = $this->parserSpecifyContentLabel($content); // 指定内容
$content = $this->parserContentPicsLabel($content); // 内容多图
$content = $this->parserContentCheckboxLabel($content); // 内容多选调取
$content = $this->parserContentTagsLabel($content); // 内容tags调取
$content = $this->parserSlideLabel($content); // 幻灯片
$content = $this->parserLinkLabel($content); // 友情链接
$content = $this->parserMessageLabel($content); // 留言板
$content = $this->parserFormLabel($content); // 自定义表单
$content = $this->parserSubmitFormLabel($content); // 自定义表单提交
$content = $this->parserQrcodeLabel($content); // 二维码生成
$content = $this->parserPageLabel($content); // CMS分页标签解析(需置后)
$content = $this->parserLoopLabel($content); // LOOP语句(需置后)
$content = $this->parserIfLabel($content); // IF语句(需置最后)
$content = $this->restorePreLabel($content); // 还原不需要解析的内容
$content = $this->parserReplaceKeyword($content); // 页面关键词替换
return $content;
}
// 保存保留内容
public function savePreLabel($content)
{
$pattern = '/\{pboot:pre}([\s\S]*?)\{\/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);
$content = 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 ++) {
$content = str_replace($matches[0][$i], $this->pre[$matches[1][$i]], $content);
}
}
return $content;
}
// 解析单标签
public function parserSingleLabel($content)
{
$content = str_replace('{pboot:msgaction}', Url::home('home/Index/addMsg'), $content); // 留言提交路径
$content = str_replace('{pboot:scaction}', Url::home('home/Index/search'), $content); // 搜索提交路径
$content = str_replace('{pboot:checkcode}', CORE_DIR . '/code.php', $content); // 验证码路径
$content = str_replace('{pboot:lgpath}', Url::get('home/Do/area'), $content); // 多语言切换前置路径,如{pboot:lgpath}?lg=cn
$content = str_replace('{pboot:appid}', $this->config('api_appid'), $content); // API认证用户
$content = str_replace('{pboot:timestamp}', time(), $content); // 认证时间戳
$content = str_replace('{pboot:signature}', md5(md5($this->config('api_appid') . $this->config('api_secret') . time())), $content); // API认证密钥
$content = str_replace('{pboot:httpurl}', get_http_url(), $content); // 当前访问的域名地址
$content = str_replace('{pboot:pageurl}', get_current_url(), $content); // 当前页面的地址
$content = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 当前搜索的关键字
$content = str_replace('{pboot:checkcodestatus}', $this->config('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':
$content = str_replace($matches[0][$i], Url::home('home/Index/'), $content);
break;
case 'path':
$content = str_replace($matches[0][$i], SITE_DIR, $content);
break;
case 'logo':
if (isset($data->logo) && $data->logo) {
if (! preg_match('/^http/', $data->logo)) {
$content = str_replace($matches[0][$i], $this->adjustLabelData($params, SITE_DIR . $data->logo), $content);
} else {
$content = str_replace($matches[0][$i], $this->adjustLabelData($params, $data->logo), $content);
}
} else {
$content = str_replace($matches[0][$i], STATIC_DIR . '/images/logo.png', $content);
}
break;
case 'tplpath':
$content = str_replace($matches[0][$i], APP_THEME_DIR, $content);
break;
case 'language':
$content = str_replace($matches[0][$i], get_lg(), $content);
break;
case 'statistical':
if (isset($data->statistical)) {
$content = str_replace($matches[0][$i], decode_string($data->statistical), $content);
} else {
$content = str_replace($matches[0][$i], '', $content);
}
case 'copyright':
if (isset($data->copyright)) {
$content = str_replace($matches[0][$i], decode_string($data->copyright), $content);
} else {
$content = str_replace($matches[0][$i], '', $content);
}
default:
if (isset($data->{$matches
没有合适的资源?快使用搜索试试~ 我知道了~
各行业通用网站开源源码

共1612个文件
png:561个
js:205个
jpg:177个

需积分: 0 15 浏览量
2023-03-21
15:25:31
上传
评论
收藏 65.18MB ZIP 举报
温馨提示
各行业通用企业网站开源源码,互联网软件开发公司官网、设计服务行业企业网站模板源码,开源源码免费
资源推荐
资源详情
资源评论














收起资源包目录





































































































共 1612 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论


海创平承科技
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
