init
This commit is contained in:
@@ -0,0 +1,297 @@
|
||||
<?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\Config;
|
||||
use core\basic\Url;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
protected $parser;
|
||||
|
||||
protected $model;
|
||||
|
||||
protected $htmldir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = new ParserController();
|
||||
$this->model = new ParserModel();
|
||||
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
|
||||
}
|
||||
|
||||
// 空拦截器, 实现文章路由转发
|
||||
public function _empty()
|
||||
{
|
||||
// 地址类型
|
||||
$url_rule_type = $this->config('url_rule_type') ?: 3;
|
||||
|
||||
if (P) { // 采用pathinfo模式及p参数伪静态模式
|
||||
if ($url_rule_type == 2 && stripos(URL, $_SERVER['SCRIPT_NAME']) !== false) { // 禁止伪静态时带index.php访问
|
||||
_404('您访问的内容不存在,请核对后重试!');
|
||||
}
|
||||
$path = explode('/', P);
|
||||
if (! defined('URL_BIND')) {
|
||||
array_shift($path); // 去除模块部分
|
||||
}
|
||||
} elseif ($url_rule_type == 3 && isset($_SERVER["QUERY_STRING"]) && $qs = $_SERVER["QUERY_STRING"]) { // 采用简短传参模式
|
||||
parse_str($qs, $output);
|
||||
unset($output['page']); // 去除分页
|
||||
if ($output && ! current($output)) { // 第一个路径参数不能有值,否则非标准路径参数
|
||||
$path = key($output); // 第一个参数为路径信息,注意PHP数组会自动将key点符号转换下划线
|
||||
$path = trim($path, '/'); // 去除两端斜杠
|
||||
$url_rule_suffix = substr($this->config('url_rule_suffix'), 1);
|
||||
if (preg_match('/_' . $url_rule_suffix . '$/', $path) && (! ! $pos = strripos($path, '_' . $url_rule_suffix))) {
|
||||
$path = substr($path, 0, $pos); // 去扩展
|
||||
}
|
||||
$path = explode('/', $path);
|
||||
} elseif (get('tag')) { // 对于兼容模式tag需要自动跳转tag独立页面
|
||||
$tag = new TagController();
|
||||
$tag->index();
|
||||
} elseif (get('keyword')) { // 兼容模式搜索处理
|
||||
$search = new SearchController();
|
||||
$search->index();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($path) && is_array($path)) {
|
||||
|
||||
// 地址分隔符
|
||||
$url_break_char = $this->config('url_break_char') ?: '_';
|
||||
|
||||
// 判断第一个参数中组合信息
|
||||
if (strpos($path[0], $url_break_char)) {
|
||||
$param = explode($url_break_char, $path[0]);
|
||||
} else {
|
||||
$param[] = $path[0];
|
||||
}
|
||||
|
||||
// 判断第一个参数是模型还是自定义分类
|
||||
if (! ! ($model = $this->model->checkModelUrlname($param[0])) || preg_match('/^(list_[0-9]+)|(^about_[0-9]+)/', $path[0])) {
|
||||
$scode = $param[1];
|
||||
if (isset($param[2])) {
|
||||
$_GET['page'] = $param[2]; // 分页
|
||||
}
|
||||
} else {
|
||||
define('CMS_PAGE_CUSTOM', true); // 自定义名称后分页比正常少了一个参数 (list_1_1=>product_1)
|
||||
$scode = $param[0];
|
||||
if (isset($param[1])) {
|
||||
$_GET['page'] = $param[1]; // 分页
|
||||
}
|
||||
}
|
||||
|
||||
// 路由
|
||||
switch ($param[0]) {
|
||||
case 'search':
|
||||
case 'keyword':
|
||||
$search = new SearchController();
|
||||
$search->index();
|
||||
break;
|
||||
case 'message':
|
||||
$msg = new MessageController();
|
||||
$msg->index();
|
||||
break;
|
||||
case 'form':
|
||||
$_GET['fcode'] = $path[1];
|
||||
$form = new FormController();
|
||||
$form->index();
|
||||
break;
|
||||
case 'sitemap':
|
||||
case 'Sitemap':
|
||||
$sitemap = new SitemapController();
|
||||
$sitemap->index();
|
||||
break;
|
||||
case 'tag':
|
||||
$tag = new TagController();
|
||||
$tag->index();
|
||||
break;
|
||||
case 'member':
|
||||
$member = new MemberController();
|
||||
$member->{$path[1]}();
|
||||
break;
|
||||
case 'comment':
|
||||
$comment = new CommentController();
|
||||
$comment->{$path[1]}();
|
||||
break;
|
||||
default:
|
||||
if (get($param[0])) {
|
||||
$this->getIndex();
|
||||
} else {
|
||||
|
||||
if (count($path) > 1) {
|
||||
define('CMS_PAGE', false); // 使用普通分页处理模型
|
||||
if (! ! ($data = $this->model->getContent($path[1])) && ($data->scode == $scode || $data->sortfilename == $scode) && $data->type == 2) {
|
||||
if ($data->acode != get_lg() && Config::get('lgautosw') !== '0') {
|
||||
cookie('lg', $data->acode); // 调用内容语言与当前语言不一致时,自动切换语言
|
||||
}
|
||||
$this->getContent($data);
|
||||
} else {
|
||||
_404('您访问的内容不存在,请核对后重试!');
|
||||
}
|
||||
} else {
|
||||
define('CMS_PAGE', true); // 使用cms分页处理模型
|
||||
if (! ! $sort = $this->model->getSort($scode)) {
|
||||
if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
|
||||
cookie('lg', $sort->acode); // 调用栏目语言与当前语言不一致时,自动切换语言
|
||||
}
|
||||
if ($sort->type == 1) {
|
||||
$this->getAbout($sort);
|
||||
} else {
|
||||
$this->getList($sort);
|
||||
}
|
||||
} else {
|
||||
_404('您访问的栏目不存在,请核对后重试!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->getIndex();
|
||||
}
|
||||
}
|
||||
|
||||
// 首页
|
||||
private function getIndex()
|
||||
{
|
||||
$content = parent::parser($this->htmldir . 'index.html'); // 框架标签解析
|
||||
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
|
||||
$content = str_replace('{pboot:pagetitle}', $this->config('index_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
|
||||
$content = $this->parser->parserPositionLabel($content, - 1, '首页', SITE_INDEX_DIR . '/'); // CMS当前位置标签解析
|
||||
$content = $this->parser->parserSpecialPageSortLabel($content, 0, '', SITE_INDEX_DIR . '/'); // 解析分类标签
|
||||
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
|
||||
$this->cache($content, true);
|
||||
}
|
||||
|
||||
// 列表
|
||||
private function getList($sort)
|
||||
{
|
||||
if ($sort->listtpl) {
|
||||
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
|
||||
$content = parent::parser($this->htmldir . $sort->listtpl); // 框架标签解析
|
||||
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
|
||||
$pagetitle = $sort->title ? "{sort:title}" : "{sort:name}"; // 页面标题
|
||||
$content = str_replace('{pboot:pagetitle}', $this->config('list_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
|
||||
$content = str_replace('{pboot:pagekeywords}', '{sort:keywords}', $content);
|
||||
$content = str_replace('{pboot:pagedescription}', '{sort:description}', $content);
|
||||
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
|
||||
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
|
||||
$content = $this->parser->parserListLabel($content, $sort->scode); // CMS分类列表标签解析
|
||||
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
|
||||
} else {
|
||||
error('请到后台设置分类栏目列表页模板!');
|
||||
}
|
||||
$this->cache($content, true);
|
||||
}
|
||||
|
||||
// 详情页
|
||||
private function getContent($data)
|
||||
{
|
||||
// 读取模板
|
||||
if (! ! $sort = $this->model->getSort($data->scode)) {
|
||||
if ($sort->contenttpl) {
|
||||
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote); // 检查栏目权限
|
||||
$this->checkPageLevel($data->gcode, $data->gtype, $data->gnote); // 检查内容权限
|
||||
$content = parent::parser($this->htmldir . $sort->contenttpl); // 框架标签解析
|
||||
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
|
||||
$content = str_replace('{pboot:pagetitle}', $this->config('content_title') ?: '{content:title}-{sort:name}-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
|
||||
$content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
|
||||
$content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
|
||||
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
|
||||
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
|
||||
$content = $this->parser->parserCurrentContentLabel($content, $sort, $data); // CMS内容标签解析
|
||||
$content = $this->parser->parserCommentLabel($content); // 文章评论
|
||||
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
|
||||
} else {
|
||||
error('请到后台设置分类栏目内容页模板!');
|
||||
}
|
||||
} else {
|
||||
_404('您访问内容的分类已经不存在,请核对后再试!');
|
||||
}
|
||||
$this->cache($content, true);
|
||||
}
|
||||
|
||||
// 单页
|
||||
private function getAbout($sort)
|
||||
{
|
||||
// 读取数据
|
||||
if (! $data = $this->model->getAbout($sort->scode)) {
|
||||
_404('您访问的内容不存在,请核对后重试!');
|
||||
}
|
||||
|
||||
if ($sort->contenttpl) {
|
||||
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
|
||||
$content = parent::parser($this->htmldir . $sort->contenttpl); // 框架标签解析
|
||||
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
|
||||
$pagetitle = $sort->title ? "{sort:title}" : "{content:title}"; // 页面标题
|
||||
$content = str_replace('{pboot:pagetitle}', $this->config('about_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
|
||||
$content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
|
||||
$content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
|
||||
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
|
||||
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
|
||||
$content = $this->parser->parserCurrentContentLabel($content, $sort, $data); // CMS内容标签解析
|
||||
$content = $this->parser->parserCommentLabel($content); // 文章评论
|
||||
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
|
||||
} else {
|
||||
error('请到后台设置分类栏目内容页模板!');
|
||||
}
|
||||
|
||||
$this->cache($content, true);
|
||||
}
|
||||
|
||||
// 检查页面权限
|
||||
private function checkPageLevel($gcode, $gtype, $gnote)
|
||||
{
|
||||
if ($gcode) {
|
||||
$deny = false;
|
||||
$gtype = $gtype ?: 4;
|
||||
switch ($gtype) {
|
||||
case 1:
|
||||
if ($gcode <= session('pboot_gcode')) {
|
||||
$deny = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ($gcode < session('pboot_gcode')) {
|
||||
$deny = true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ($gcode != session('pboot_gcode')) {
|
||||
$deny = true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if ($gcode > session('pboot_gcode')) {
|
||||
$deny = true;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ($gcode >= session('pboot_gcode')) {
|
||||
$deny = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($deny) {
|
||||
$gnote = $gnote ?: '您的权限不足,无法浏览本页面!';
|
||||
if (session('pboot_uid')) { // 已经登录
|
||||
error($gnote);
|
||||
} else {
|
||||
if ($this->config('login_no_wait')) {
|
||||
location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
|
||||
} else {
|
||||
error($gnote, Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,982 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2018年2月14日
|
||||
* 标签解析引擎模型
|
||||
*/
|
||||
namespace app\home\model;
|
||||
|
||||
use core\basic\Model;
|
||||
|
||||
class ParserModel extends Model
|
||||
{
|
||||
|
||||
// 存储分类及子编码
|
||||
protected $scodes = array();
|
||||
|
||||
// 存储分类查询数据
|
||||
protected $sorts;
|
||||
|
||||
// 存储栏目位置
|
||||
protected $position = array();
|
||||
|
||||
// 上一篇
|
||||
protected $pre;
|
||||
|
||||
// 下一篇
|
||||
protected $next;
|
||||
|
||||
// 获取模型数据
|
||||
public function checkModelUrlname($urlname)
|
||||
{
|
||||
return parent::table('ay_model')->where("urlname='$urlname'")->find();
|
||||
}
|
||||
|
||||
// 站点配置信息
|
||||
public function getSite()
|
||||
{
|
||||
return parent::table('ay_site')->where("acode='" . get_lg() . "'")->find();
|
||||
}
|
||||
|
||||
// 公司信息
|
||||
public function getCompany()
|
||||
{
|
||||
return parent::table('ay_company')->where("acode='" . get_lg() . "'")->find();
|
||||
}
|
||||
|
||||
// 自定义标签,不区分语言,兼容跨语言
|
||||
public function getLabel()
|
||||
{
|
||||
return parent::table('ay_label')->decode()->column('value,type', 'name');
|
||||
}
|
||||
|
||||
// 单个分类信息,不区分语言,兼容跨语言
|
||||
public function getSort($scode)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'c.name AS parentname',
|
||||
'b.type',
|
||||
'b.urlname',
|
||||
'd.gcode'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_model b',
|
||||
'a.mcode=b.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.pcode=c.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member_group d',
|
||||
'a.gid=d.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
return parent::table('ay_content_sort a')->field($field)
|
||||
->where("a.scode='$scode' OR a.filename='$scode'")
|
||||
->join($join)
|
||||
->find();
|
||||
}
|
||||
|
||||
// 多个分类信息,不区分语言,兼容跨语言
|
||||
public function getMultSort($scodes)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'c.name AS parentname',
|
||||
'b.type',
|
||||
'b.urlname'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_model b',
|
||||
'a.mcode=b.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.pcode=c.scode',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
return parent::table('ay_content_sort a')->field($field)
|
||||
->in('a.scode', $scodes)
|
||||
->join($join)
|
||||
->order('a.sorting,a.id')
|
||||
->select();
|
||||
}
|
||||
|
||||
// 指定分类数量
|
||||
public function getSortRows($scode)
|
||||
{
|
||||
$this->scodes = array(); // 先清空
|
||||
|
||||
// 获取多分类子类
|
||||
$arr = explode(',', $scode);
|
||||
foreach ($arr as $value) {
|
||||
$scodes = $this->getSubScodes(trim($value));
|
||||
}
|
||||
|
||||
// 拼接条件
|
||||
$where1 = array(
|
||||
"scode in (" . implode_quot(',', $scodes) . ")",
|
||||
"subscode='$scode'"
|
||||
);
|
||||
$where2 = array(
|
||||
"acode='" . get_lg() . "'",
|
||||
'status=1',
|
||||
"date<'" . date('Y-m-d H:i:s') . "'"
|
||||
);
|
||||
|
||||
$result = parent::table('ay_content')->where($where1, 'OR')
|
||||
->where($where2)
|
||||
->column('id');
|
||||
return count($result);
|
||||
}
|
||||
|
||||
// 分类栏目列表关系树
|
||||
public function getSortsTree()
|
||||
{
|
||||
$fields = array(
|
||||
'a.*',
|
||||
'b.type',
|
||||
'b.urlname'
|
||||
);
|
||||
$join = array(
|
||||
'ay_model b',
|
||||
'a.mcode=b.mcode',
|
||||
'LEFT'
|
||||
);
|
||||
$result = parent::table('ay_content_sort a')->where("a.acode='" . get_lg() . "'")
|
||||
->where('a.status=1')
|
||||
->join($join)
|
||||
->order('a.pcode,a.sorting,a.id')
|
||||
->column($fields, 'scode');
|
||||
|
||||
foreach ($result as $key => $value) {
|
||||
if ($value['pcode']) {
|
||||
$result[$value['pcode']]['son'][] = $value; // 记录到关系树
|
||||
} else {
|
||||
$data['top'][] = $value; // 记录顶级菜单
|
||||
}
|
||||
}
|
||||
$data['tree'] = $result;
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 获取分类名称
|
||||
public function getSortName($scode)
|
||||
{
|
||||
$result = $this->getSortList();
|
||||
return $result[$scode]['name'];
|
||||
}
|
||||
|
||||
// 分类顶级编码
|
||||
public function getSortTopScode($scode)
|
||||
{
|
||||
$result = $this->getSortList();
|
||||
return $this->getTopParent($scode, $result);
|
||||
}
|
||||
|
||||
// 获取位置
|
||||
public function getPosition($scode)
|
||||
{
|
||||
$result = $this->getSortList();
|
||||
$this->position = array(); // 重置
|
||||
$this->getTopParent($scode, $result);
|
||||
return array_reverse($this->position);
|
||||
}
|
||||
|
||||
// 分类顶级编码
|
||||
private function getTopParent($scode, $sorts)
|
||||
{
|
||||
if (! $scode || ! $sorts) {
|
||||
return;
|
||||
}
|
||||
$this->position[] = $sorts[$scode];
|
||||
if ($sorts[$scode]['pcode']) {
|
||||
return $this->getTopParent($sorts[$scode]['pcode'], $sorts);
|
||||
} else {
|
||||
return $sorts[$scode]['scode'];
|
||||
}
|
||||
}
|
||||
|
||||
// 分类子类集
|
||||
private function getSubScodes($scode)
|
||||
{
|
||||
if (! $scode) {
|
||||
return;
|
||||
}
|
||||
$this->scodes[] = $scode;
|
||||
$subs = parent::table('ay_content_sort')->where("pcode='$scode'")->column('scode');
|
||||
if ($subs) {
|
||||
foreach ($subs as $value) {
|
||||
$this->getSubScodes($value);
|
||||
}
|
||||
}
|
||||
return $this->scodes;
|
||||
}
|
||||
|
||||
// 获取栏目清单
|
||||
private function getSortList()
|
||||
{
|
||||
if (! isset($this->sorts)) {
|
||||
$fields = array(
|
||||
'a.id',
|
||||
'a.pcode',
|
||||
'a.scode',
|
||||
'a.name',
|
||||
'a.filename',
|
||||
'a.outlink',
|
||||
'b.type',
|
||||
'b.urlname'
|
||||
);
|
||||
$join = array(
|
||||
'ay_model b',
|
||||
'a.mcode=b.mcode',
|
||||
'LEFT'
|
||||
);
|
||||
$this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . get_lg() . "'")
|
||||
->join($join)
|
||||
->column($fields, 'scode');
|
||||
}
|
||||
return $this->sorts;
|
||||
}
|
||||
|
||||
// 获取筛选字段数据
|
||||
public function getSelect($field)
|
||||
{
|
||||
return parent::table('ay_extfield')->where("name='$field'")->value('value');
|
||||
}
|
||||
|
||||
// 列表内容,带分页,不区分语言,兼容跨语言
|
||||
public function getLists($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)
|
||||
{
|
||||
$ext_table = false;
|
||||
if ($lfield) {
|
||||
$lfield .= ',id,outlink,type,scode,sortfilename,filename,urlname'; // 附加必须字段
|
||||
$fields = explode(',', $lfield);
|
||||
$fields = array_unique($fields); // 去重
|
||||
foreach ($fields as $key => $value) {
|
||||
if (strpos($value, 'ext_') === 0) {
|
||||
$ext_table = true;
|
||||
$fields[$key] = 'e.' . $value;
|
||||
} elseif ($value == 'sortname') {
|
||||
$fields[$key] = 'b.name as sortname';
|
||||
} elseif ($value == 'sortfilename') {
|
||||
$fields[$key] = 'b.filename as sortfilename';
|
||||
} elseif ($value == 'subsortname') {
|
||||
$fields[$key] = 'c.name as subsortname';
|
||||
} elseif ($value == 'subfilename') {
|
||||
$fields[$key] = 'c.filename as subfilename';
|
||||
} elseif ($value == 'type' || $value == 'urlname') {
|
||||
$fields[$key] = 'd.' . $value;
|
||||
} elseif ($value == 'modelname') {
|
||||
$fields[$key] = 'd.name as modelname';
|
||||
} else {
|
||||
$fields[$key] = 'a.' . $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ext_table = true;
|
||||
$fields = array(
|
||||
'a.*',
|
||||
'b.name as sortname',
|
||||
'b.filename as sortfilename',
|
||||
'c.name as subsortname',
|
||||
'c.filename as subfilename',
|
||||
'd.type',
|
||||
'd.name as modelname',
|
||||
'd.urlname',
|
||||
'e.*',
|
||||
'f.gcode'
|
||||
);
|
||||
}
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.subscode=c.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model d',
|
||||
'b.mcode=d.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member_group f',
|
||||
'a.gid=f.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
|
||||
// 加载扩展字段表
|
||||
if ($ext_table) {
|
||||
$join[] = array(
|
||||
'ay_content_ext e',
|
||||
'a.id=e.contentid',
|
||||
'LEFT'
|
||||
);
|
||||
}
|
||||
|
||||
$scode_arr = array();
|
||||
if ($scode) {
|
||||
// 获取所有子类分类编码
|
||||
$this->scodes = array(); // 先清空
|
||||
$arr = explode(',', $scode); // 传递有多个分类时进行遍历
|
||||
foreach ($arr as $value) {
|
||||
$scodes = $this->getSubScodes(trim($value));
|
||||
}
|
||||
// 拼接条件
|
||||
$scode_arr = array(
|
||||
"a.scode in (" . implode_quot(',', $scodes) . ")",
|
||||
"a.subscode='$scode'"
|
||||
);
|
||||
}
|
||||
|
||||
$where = array(
|
||||
'a.status=1',
|
||||
'd.type=2',
|
||||
"a.date<'" . date('Y-m-d H:i:s') . "'"
|
||||
);
|
||||
|
||||
if ($lg) {
|
||||
$where['a.acode'] = $lg;
|
||||
}
|
||||
|
||||
// 筛选条件支持模糊匹配
|
||||
return parent::table('ay_content a')->field($fields)
|
||||
->where($scode_arr, 'OR')
|
||||
->where($where)
|
||||
->where($select, 'AND', 'AND', $fuzzy)
|
||||
->where($filter, 'OR')
|
||||
->where($tags, 'OR')
|
||||
->join($join)
|
||||
->order($order)
|
||||
->page(1, $num, $start)
|
||||
->decode()
|
||||
->select();
|
||||
}
|
||||
|
||||
// 列表内容,不带分页,不区分语言,兼容跨语言
|
||||
public function getList($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)
|
||||
{
|
||||
$ext_table = false;
|
||||
if ($lfield) {
|
||||
$lfield .= ',id,outlink,type,scode,sortfilename,filename,urlname'; // 附加必须字段
|
||||
$fields = explode(',', $lfield);
|
||||
$fields = array_unique($fields); // 去重
|
||||
foreach ($fields as $key => $value) {
|
||||
if (strpos($value, 'ext_') === 0) {
|
||||
$ext_table = true;
|
||||
$fields[$key] = 'e.' . $value;
|
||||
} elseif ($value == 'sortname') {
|
||||
$fields[$key] = 'b.name as sortname';
|
||||
} elseif ($value == 'sortfilename') {
|
||||
$fields[$key] = 'b.filename as sortfilename';
|
||||
} elseif ($value == 'subsortname') {
|
||||
$fields[$key] = 'c.name as subsortname';
|
||||
} elseif ($value == 'subfilename') {
|
||||
$fields[$key] = 'c.filename as subfilename';
|
||||
} elseif ($value == 'type' || $value == 'urlname') {
|
||||
$fields[$key] = 'd.' . $value;
|
||||
} elseif ($value == 'modelname') {
|
||||
$fields[$key] = 'd.name as modelname';
|
||||
} else {
|
||||
$fields[$key] = 'a.' . $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ext_table = true;
|
||||
$fields = array(
|
||||
'a.*',
|
||||
'b.name as sortname',
|
||||
'b.filename as sortfilename',
|
||||
'c.name as subsortname',
|
||||
'c.filename as subfilename',
|
||||
'd.type',
|
||||
'd.name as modelname',
|
||||
'd.urlname',
|
||||
'e.*',
|
||||
'f.gcode'
|
||||
);
|
||||
}
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.subscode=c.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model d',
|
||||
'b.mcode=d.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member_group f',
|
||||
'a.gid=f.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
|
||||
// 加载扩展字段表
|
||||
if ($ext_table) {
|
||||
$join[] = array(
|
||||
'ay_content_ext e',
|
||||
'a.id=e.contentid',
|
||||
'LEFT'
|
||||
);
|
||||
}
|
||||
|
||||
$scode_arr = array();
|
||||
if ($scode) {
|
||||
// 获取所有子类分类编码
|
||||
$this->scodes = array(); // 先清空
|
||||
$arr = explode(',', $scode); // 传递有多个分类时进行遍历
|
||||
foreach ($arr as $value) {
|
||||
$scodes = $this->getSubScodes(trim($value));
|
||||
}
|
||||
// 拼接条件
|
||||
$scode_arr = array(
|
||||
"a.scode in (" . implode_quot(',', $scodes) . ")",
|
||||
"a.subscode='$scode'"
|
||||
);
|
||||
}
|
||||
|
||||
$where = array(
|
||||
'a.status=1',
|
||||
'd.type=2',
|
||||
"a.date<'" . date('Y-m-d H:i:s') . "'"
|
||||
);
|
||||
|
||||
if ($lg) {
|
||||
$where['a.acode'] = $lg;
|
||||
}
|
||||
|
||||
// 筛选条件支持模糊匹配
|
||||
return parent::table('ay_content a')->field($fields)
|
||||
->where($scode_arr, 'OR')
|
||||
->where($where)
|
||||
->where($select, 'AND', 'AND', $fuzzy)
|
||||
->where($filter, 'OR')
|
||||
->where($tags, 'OR')
|
||||
->join($join)
|
||||
->order($order)
|
||||
->limit($start - 1, $num)
|
||||
->decode()
|
||||
->select();
|
||||
}
|
||||
|
||||
// 内容详情,不区分语言,兼容跨语言
|
||||
public function getContent($id)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'b.name as sortname',
|
||||
'b.filename as sortfilename',
|
||||
'b.outlink as sortoutlink',
|
||||
'c.name as subsortname',
|
||||
'c.filename as subfilename',
|
||||
'd.type',
|
||||
'd.name as modelname',
|
||||
'd.urlname',
|
||||
'e.*',
|
||||
'f.gcode'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.subscode=c.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model d',
|
||||
'b.mcode=d.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_ext e',
|
||||
'a.id=e.contentid',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member_group f',
|
||||
'a.gid=f.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
$result = parent::table('ay_content a')->field($field)
|
||||
->where("a.id='$id' OR a.filename='$id'")
|
||||
->where('a.status=1')
|
||||
->join($join)
|
||||
->decode()
|
||||
->find();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 单篇详情,不区分语言,兼容跨语言
|
||||
public function getAbout($scode)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'b.name as sortname',
|
||||
'b.filename as sortfilename',
|
||||
'c.name as subsortname',
|
||||
'c.filename as subfilename',
|
||||
'd.type',
|
||||
'd.name as modelname',
|
||||
'd.urlname',
|
||||
'e.*',
|
||||
'f.gcode'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_sort c',
|
||||
'a.subscode=c.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model d',
|
||||
'b.mcode=d.mcode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content_ext e',
|
||||
'a.id=e.contentid',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member_group f',
|
||||
'a.gid=f.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
$result = parent::table('ay_content a')->field($field)
|
||||
->where("a.scode='$scode' OR b.filename='$scode'")
|
||||
->where('a.status=1')
|
||||
->join($join)
|
||||
->decode()
|
||||
->order('id DESC')
|
||||
->find();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 指定内容多图
|
||||
public function getContentPics($id)
|
||||
{
|
||||
$result = parent::table('ay_content')->field("pics,picstitle")
|
||||
->where("id='$id'")
|
||||
->where('status=1')
|
||||
->find();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 指定内容多选调用
|
||||
public function getContentCheckbox($id, $field)
|
||||
{
|
||||
$result = parent::table('ay_content_ext')->where("contentid='$id'")->value($field);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 指定内容标签调用
|
||||
public function getContentTags($id)
|
||||
{
|
||||
$result = parent::table('ay_content')->field('scode,tags')
|
||||
->where("id='$id'")
|
||||
->where('status=1')
|
||||
->find();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 指定分类标签调用
|
||||
public function getSortTags($scode)
|
||||
{
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model c',
|
||||
'b.mcode=c.mcode',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
|
||||
$scode_arr = array();
|
||||
if ($scode) {
|
||||
// 获取所有子类分类编码
|
||||
$this->scodes = array(); // 先清空
|
||||
$scodes = $this->getSubScodes(trim($scode)); // 获取子类
|
||||
|
||||
// 拼接条件
|
||||
$scode_arr = array(
|
||||
"a.scode in (" . implode_quot(',', $scodes) . ")",
|
||||
"a.subscode='$scode'"
|
||||
);
|
||||
}
|
||||
|
||||
$result = parent::table('ay_content a')->where("c.type=2 AND a.tags<>''")
|
||||
->where($scode_arr, 'OR')
|
||||
->join($join)
|
||||
->where('a.status=1')
|
||||
->order('a.visits DESC')
|
||||
->column('a.tags');
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 上一篇内容
|
||||
public function getContentPre($scode, $id)
|
||||
{
|
||||
if (! $this->pre) {
|
||||
$this->scodes = array();
|
||||
$scodes = $this->getSubScodes($scode);
|
||||
|
||||
$field = array(
|
||||
'a.id',
|
||||
'a.title',
|
||||
'a.filename',
|
||||
'a.ico',
|
||||
'a.scode',
|
||||
'b.filename as sortfilename',
|
||||
'c.type',
|
||||
'c.urlname'
|
||||
);
|
||||
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model c',
|
||||
'b.mcode=c.mcode',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
|
||||
$this->pre = parent::table('ay_content a')->field($field)
|
||||
->where("a.id<$id")
|
||||
->join($join)
|
||||
->in('a.scode', $scodes)
|
||||
->where("a.acode='" . get_lg() . "'")
|
||||
->where('a.status=1')
|
||||
->order('a.id DESC')
|
||||
->find();
|
||||
}
|
||||
return $this->pre;
|
||||
}
|
||||
|
||||
// 下一篇内容
|
||||
public function getContentNext($scode, $id)
|
||||
{
|
||||
if (! $this->next) {
|
||||
$this->scodes = array();
|
||||
$scodes = $this->getSubScodes($scode);
|
||||
|
||||
$field = array(
|
||||
'a.id',
|
||||
'a.title',
|
||||
'a.filename',
|
||||
'a.ico',
|
||||
'a.scode',
|
||||
'b.filename as sortfilename',
|
||||
'c.type',
|
||||
'c.urlname'
|
||||
);
|
||||
|
||||
$join = array(
|
||||
array(
|
||||
'ay_content_sort b',
|
||||
'a.scode=b.scode',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_model c',
|
||||
'b.mcode=c.mcode',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
|
||||
$this->next = parent::table('ay_content a')->field($field)
|
||||
->where("a.id>$id")
|
||||
->join($join)
|
||||
->in('a.scode', $scodes)
|
||||
->where("a.acode='" . get_lg() . "'")
|
||||
->where('a.status=1')
|
||||
->order('a.id ASC')
|
||||
->find();
|
||||
}
|
||||
return $this->next;
|
||||
}
|
||||
|
||||
// 幻灯片
|
||||
public function getSlides($gid, $num, $start = 1)
|
||||
{
|
||||
$result = parent::table('ay_slide')->where("gid='$gid'")
|
||||
->order('sorting ASC,id ASC')
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 友情链接
|
||||
public function getLinks($gid, $num, $start = 1)
|
||||
{
|
||||
$result = parent::table('ay_link')->where("gid='$gid'")
|
||||
->order('sorting ASC,id ASC')
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 获取留言
|
||||
public function getMessage($num, $page = true, $start = 1, $lg = null)
|
||||
{
|
||||
if ($lg == 'all') {
|
||||
$where = array();
|
||||
} elseif ($lg) {
|
||||
$where = array(
|
||||
'a.acode' => $lg
|
||||
);
|
||||
} else {
|
||||
$where = array(
|
||||
'a.acode' => get_lg()
|
||||
);
|
||||
}
|
||||
|
||||
$field = array(
|
||||
'a.*',
|
||||
'b.username',
|
||||
'b.nickname',
|
||||
'b.headpic'
|
||||
);
|
||||
$join = array(
|
||||
'ay_member b',
|
||||
'a.uid=b.id',
|
||||
'LEFT'
|
||||
);
|
||||
|
||||
if ($page) {
|
||||
return parent::table('ay_message a')->field($field)
|
||||
->join($join)
|
||||
->where("a.status=1")
|
||||
->where($where)
|
||||
->order('a.id DESC')
|
||||
->decode(false)
|
||||
->page(1, $num, $start)
|
||||
->select();
|
||||
} else {
|
||||
return parent::table('ay_message a')->field($field)
|
||||
->join($join)
|
||||
->where("a.status=1")
|
||||
->where($where)
|
||||
->order('a.id DESC')
|
||||
->decode(false)
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
}
|
||||
}
|
||||
|
||||
// 新增留言
|
||||
public function addMessage($data)
|
||||
{
|
||||
return parent::table('ay_message')->autoTime()->insert($data);
|
||||
}
|
||||
|
||||
// 获取表单字段
|
||||
public function getFormField($fcode)
|
||||
{
|
||||
$field = array(
|
||||
'a.table_name',
|
||||
'a.form_name',
|
||||
'b.name',
|
||||
'b.required',
|
||||
'b.description'
|
||||
);
|
||||
|
||||
$join = array(
|
||||
'ay_form_field b',
|
||||
'a.fcode=b.fcode',
|
||||
'LEFT'
|
||||
);
|
||||
|
||||
return parent::table('ay_form a')->field($field)
|
||||
->where("a.fcode='$fcode'")
|
||||
->join($join)
|
||||
->order('b.sorting ASC,b.id ASC')
|
||||
->select();
|
||||
}
|
||||
|
||||
// 获取表单表名称
|
||||
public function getFormTable($fcode)
|
||||
{
|
||||
return parent::table('ay_form')->where("fcode='$fcode'")->value('table_name');
|
||||
}
|
||||
|
||||
// 获取表单数据
|
||||
public function getForm($table, $num, $page = true, $start = 1)
|
||||
{
|
||||
if ($page) {
|
||||
return parent::table($table)->order('id DESC')
|
||||
->decode(false)
|
||||
->page(1, $num, $start)
|
||||
->select();
|
||||
} else {
|
||||
return parent::table($table)->order('id DESC')
|
||||
->decode(false)
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
}
|
||||
}
|
||||
|
||||
// 新增表单数据
|
||||
public function addForm($table, $data)
|
||||
{
|
||||
return parent::table($table)->insert($data);
|
||||
}
|
||||
|
||||
// 文章内链
|
||||
public function getTags()
|
||||
{
|
||||
return parent::table('ay_tags')->field('name,link')
|
||||
->where("acode='" . get_lg() . "'")
|
||||
->order('length(name) desc')
|
||||
->select();
|
||||
}
|
||||
|
||||
// 新增评论
|
||||
public function addComment($data)
|
||||
{
|
||||
return parent::table('ay_member_comment')->insert($data);
|
||||
}
|
||||
|
||||
// 文章评论
|
||||
public function getComment($contentid, $pid, $num, $order, $page = false, $start = 1)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'b.username',
|
||||
'b.nickname',
|
||||
'b.headpic',
|
||||
'c.username as pusername',
|
||||
'c.nickname as pnickname',
|
||||
'c.headpic as pheadpic'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_member b',
|
||||
'a.uid=b.id',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member c',
|
||||
'a.puid=c.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
if ($page) {
|
||||
return parent::table('ay_member_comment a')->field($field)
|
||||
->join($join)
|
||||
->where("a.contentid='$contentid'")
|
||||
->where('a.pid=' . $pid)
|
||||
->where("a.status=1")
|
||||
->order($order)
|
||||
->page(1, $num, $start)
|
||||
->select();
|
||||
} else {
|
||||
return parent::table('ay_member_comment a')->field($field)
|
||||
->join($join)
|
||||
->where("a.contentid='$contentid'")
|
||||
->where('a.pid=' . $pid)
|
||||
->where("a.status=1")
|
||||
->order($order)
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
}
|
||||
}
|
||||
|
||||
// 我的评论
|
||||
public function getMyComment($num, $order, $page = false, $start = 1)
|
||||
{
|
||||
$field = array(
|
||||
'a.*',
|
||||
'b.username',
|
||||
'b.nickname',
|
||||
'b.headpic',
|
||||
'c.username as pusername',
|
||||
'c.nickname as pnickname',
|
||||
'c.headpic as pheadpic',
|
||||
'd.title'
|
||||
);
|
||||
$join = array(
|
||||
array(
|
||||
'ay_member b',
|
||||
'a.uid=b.id',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_member c',
|
||||
'a.puid=c.id',
|
||||
'LEFT'
|
||||
),
|
||||
array(
|
||||
'ay_content d',
|
||||
'a.contentid=d.id',
|
||||
'LEFT'
|
||||
)
|
||||
);
|
||||
if ($page) {
|
||||
return parent::table('ay_member_comment a')->field($field)
|
||||
->join($join)
|
||||
->where("uid='" . session('pboot_uid') . "'")
|
||||
->order($order)
|
||||
->page(1, $num, $start)
|
||||
->select();
|
||||
} else {
|
||||
return parent::table('ay_member_comment a')->field($field)
|
||||
->join($join)
|
||||
->where("uid='" . session('pboot_uid') . "'")
|
||||
->order($order)
|
||||
->limit($start - 1, $num)
|
||||
->select();
|
||||
}
|
||||
}
|
||||
|
||||
// 删除评论
|
||||
public function delComment($id)
|
||||
{
|
||||
return parent::table('ay_member_comment')->where("uid='" . session('pboot_uid') . "'")
|
||||
->where("id=$id")
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user