Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// 栏目
|
||||
|
||||
if (!$dirname) {
|
||||
$dirname = 'share';
|
||||
}
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$dirname);
|
||||
if (!$module) {
|
||||
return $this->_return($system['return'], "模块({$dirname})尚未安装");
|
||||
} elseif (!$module['category']) {
|
||||
return $this->_return($system['return'], "模块({$dirname})没有栏目数据");
|
||||
}
|
||||
|
||||
$show = isset($param['show']) && $param['show'] ? 1 : 0; // 有show参数表示显示隐藏栏目
|
||||
$return = [];
|
||||
|
||||
if (isset($param['pid'])) {
|
||||
$param['pid'] = explode(',', (string)$param['pid']);
|
||||
}
|
||||
if (isset($param['catid']) && $param['catid']) {
|
||||
$param['id'] = $param['catid'];
|
||||
}
|
||||
if (isset($param['id']) && $param['id']) {
|
||||
$arr = explode(',', $param['id']);
|
||||
if ($arr) {
|
||||
$new = [];
|
||||
foreach ($arr as $t) {
|
||||
if ($t && isset($module['category'][$t]) && $module['category'][$t]) {
|
||||
$new[$t] = $module['category'][$t];
|
||||
}
|
||||
}
|
||||
$module['category'] = $new;
|
||||
}
|
||||
}
|
||||
|
||||
if ($module['category']) {
|
||||
foreach ($module['category'] as $t) {
|
||||
if (!$t['show'] && !$show) {
|
||||
continue;
|
||||
} elseif (isset($param['pid']) && !dr_in_array($t['pid'], $param['pid'])) {
|
||||
continue;
|
||||
} elseif (isset($param['mid']) && $t['mid'] != $param['mid']) {
|
||||
continue;
|
||||
} elseif (isset($param['tid']) && $t['tid'] != (int)$param['tid']) {
|
||||
continue;
|
||||
} elseif (isset($param['child']) && $t['child'] != (int)$param['child']) {
|
||||
continue;
|
||||
} elseif (isset($system['more']) && !$system['more']) {
|
||||
unset($t['field'], $t['setting']);
|
||||
}
|
||||
if ($t['tid'] == 2) {
|
||||
// 外链栏目
|
||||
} else {
|
||||
$t['url'] = dr_url_rel(dr_url_prefix($t['url'], $module['mid'], $system['site'], $this->_is_mobile));
|
||||
}
|
||||
$return[] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
// order
|
||||
if ($system['order']) {
|
||||
$arr = explode(',', $system['order']);
|
||||
foreach ($arr as $t) {
|
||||
$a = explode('_', $t);
|
||||
$b = strtolower(end($a));
|
||||
if (in_array($b, ['desc', 'asc', 'instr'])) {
|
||||
$a = str_replace('_'.$b, '', $t);
|
||||
} else {
|
||||
$a = $t;
|
||||
$b = 'desc';
|
||||
}
|
||||
if ($b == 'instr') {
|
||||
|
||||
} else {
|
||||
$return = dr_array_sort($return, $a, $b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// num参数
|
||||
if ($system['num']) {
|
||||
if (is_numeric($system['num'])) {
|
||||
$return = array_slice($return, 0, $system['num']);
|
||||
} elseif (strpos($system['num'], ',') !== false) {
|
||||
list($a, $b) = explode(',', $system['num']);
|
||||
$return = array_slice($return, max(0, $a - 1), $b);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$return) {
|
||||
return $this->_return($system['return'], '没有匹配到内容');
|
||||
}
|
||||
|
||||
return $this->_return($system['return'], $return, '');
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// 栏目搜索字段筛选
|
||||
|
||||
$catid = $system['catid'];
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$dirname);
|
||||
if (!$module) {
|
||||
return $this->_return($system['return'], '模块('.$dirname.')未安装');
|
||||
} elseif (!$catid) {
|
||||
return $this->_return($system['return'], '没有catid值无法显示结果');
|
||||
} elseif (!isset($module['category'][$catid])) {
|
||||
return $this->_return($system['return'], '模块('.$dirname.')的栏目('.$catid.')不存在');
|
||||
} elseif (dr_count($module['category'][$catid]['field']) == 0) {
|
||||
return $this->_return($system['return'], '模块('.$dirname.')的栏目('.$catid.')没有分配模型字段');
|
||||
}
|
||||
|
||||
$return = [];
|
||||
|
||||
foreach ($module['category'][$catid]['field'] as $field) {
|
||||
$t = $module['category_data_field'][$field];
|
||||
if ($t) {
|
||||
$data = dr_format_option_array($t['setting']['option']['options']);
|
||||
if ($t['issearch'] && in_array($t['fieldtype'], ['Select', 'Selects', 'Radio', 'Checkbox']) && $data) {
|
||||
$list = [];
|
||||
foreach ($data as $value => $name) {
|
||||
$name && !is_null($value) && $list[] = array(
|
||||
'name' => trim($name),
|
||||
'value' => trim($value)
|
||||
);
|
||||
}
|
||||
$list && $return[] = array(
|
||||
'data' => $list,
|
||||
'name' => $t['name'],
|
||||
'field' => $t['fieldname'],
|
||||
'displayorder' => $t['displayorder'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$system['order'] && $return = dr_array_sort($return, 'displayorder');
|
||||
|
||||
return $this->_return($system['return'], $return, '');
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// 模块内容详细页面
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$dirname);
|
||||
if (!$module) {
|
||||
return $this->_return($system['return'], "模块({$dirname})未安装");
|
||||
} elseif (!$param['id']) {
|
||||
return $this->_return($system['return'], "模块({$dirname})缺少id参数");
|
||||
}
|
||||
|
||||
$tableinfo = \Phpcmf\Service::L('cache')->get('table-'.$system['site']);
|
||||
if (!$tableinfo) {
|
||||
// 没有表结构缓存时返回空
|
||||
return $this->_return($system['return'], '表结构缓存不存在');
|
||||
}
|
||||
|
||||
$table = \Phpcmf\Service::M()->dbprefix(dr_module_table_prefix($module['dirname'], $system['site'])); // 模块主表`
|
||||
if (!isset($tableinfo[$table])) {
|
||||
return $this->_return($system['return'], '表('.$table.')结构缓存不存在');
|
||||
}
|
||||
|
||||
// 初始化数据表
|
||||
$db = \Phpcmf\Service::M('Content', $dirname);
|
||||
$db->_init($dirname, $system['site']);
|
||||
if ($module['category_data_field']) {
|
||||
$system['more'] = 1;
|
||||
}
|
||||
$data = $db->get_data(intval($param['id']), 0, [], $system['more']);
|
||||
|
||||
// 缓存查询结果
|
||||
if (is_array($data) && $data) {
|
||||
// 模块表的系统字段
|
||||
$fields = $module['field']; // 主表的字段
|
||||
if ($module['category_data_field']) {
|
||||
$fields = dr_array2array($fields, $module['category_data_field']);
|
||||
}
|
||||
$fields['inputtime'] = array('fieldtype' => 'Date');
|
||||
$fields['updatetime'] = array('fieldtype' => 'Date');
|
||||
// 格式化显示自定义字段内容
|
||||
$dfield = \Phpcmf\Service::L('Field')->app($module['dirname']);
|
||||
$data['url'] = dr_url_rel(dr_url_prefix($data['url'], $dirname, $system['site'], $this->_is_mobile));
|
||||
$data = $dfield->format_value($fields, $data, 1);
|
||||
|
||||
// 存储缓存
|
||||
$system['cache'] && $this->_save_cache_data($cache_name, [
|
||||
'data' => [$data],
|
||||
'sql' => '',
|
||||
'total' => 0,
|
||||
'pages' => 0,
|
||||
'pagesize' => 0,
|
||||
'page_used' => $this->_page_used,
|
||||
'page_urlrule' => $this->_page_urlrule,
|
||||
], $system['cache']);
|
||||
|
||||
}
|
||||
return $this->_return($system['return'], [$data]);
|
||||
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
// 模块数据
|
||||
|
||||
|
||||
// 通过栏目识别共享模块目录
|
||||
if ((!$dirname || $dirname == 'share') && $system['catid']) {
|
||||
$cat = dr_share_cat_value($system['catid']);
|
||||
if ($cat && $cat['mid']) {
|
||||
$dirname = $cat['mid'];
|
||||
unset($cat);
|
||||
}
|
||||
}
|
||||
if (!$dirname) {
|
||||
$return_data = $this->_return($system['return'], '模块参数module未填写');
|
||||
return;
|
||||
}
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$dirname);
|
||||
if (!$module) {
|
||||
if (strpos($system['module'], ',') || $system['module'] == 'all') {
|
||||
require 'Modules.php';
|
||||
return;
|
||||
}
|
||||
$return_data = $this->_return($system['return'], '模块('.$dirname.')未安装');
|
||||
return;
|
||||
}
|
||||
|
||||
$tableinfo = \Phpcmf\Service::L('cache')->get('table-'.$system['site']);
|
||||
|
||||
// 没有表结构缓存时返回空
|
||||
if (!$tableinfo) {
|
||||
$return_data = $this->_return($system['return'], '表结构缓存不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
$table = \Phpcmf\Service::M()->dbprefix(dr_module_table_prefix($module['dirname'], $system['site'])); // 模块主表`
|
||||
if (!isset($tableinfo[$table])) {
|
||||
$return_data = $this->_return($system['return'], '表('.$table.')结构缓存不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 加上状态判断
|
||||
//$where[] = ['adj' => '', 'name' => 'status', 'value' => 9];
|
||||
|
||||
// 是否操作自定义where
|
||||
if ($param['where']) {
|
||||
$where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => urldecode($param['where'])
|
||||
];
|
||||
unset($param['where']);
|
||||
}
|
||||
|
||||
$fields = $module['field']; // 主表的字段
|
||||
|
||||
// 排序操作
|
||||
if (!$system['order'] && isset($where['id']) && $where['id']['adj'] == 'IN' && $where['id']['value']) {
|
||||
// 按id序列来排序
|
||||
$system['order'] = strlen($where['id']['value']) < 10000 && $where['id']['value'] ? 'FIELD(`'.$table.'`.`id`, '.$where['id']['value'].')' : 'NULL';
|
||||
} else {
|
||||
// 默认排序参数
|
||||
!$system['order'] && ($system['order'] = $system['flag'] ? 'updatetime_desc' : ($action == 'hits' ? 'hits' : 'updatetime'));
|
||||
}
|
||||
|
||||
// 栏目筛选
|
||||
if ($system['catid']) {
|
||||
$fwhere = [];
|
||||
if (strpos($system['catid'], ',') !== FALSE) {
|
||||
$temp = explode(',', $system['catid']);
|
||||
if ($temp) {
|
||||
$catids = [];
|
||||
foreach ($temp as $i) {
|
||||
$catids = $module['category'][$i]['child'] ? array_merge($catids, $module['category'][$i]['catids']) : array_merge($catids, array($i));
|
||||
}
|
||||
$catids && $fwhere[] = '`'.$table.'`.`catid` IN ('.implode(',', $catids).')';
|
||||
}
|
||||
unset($temp);
|
||||
} elseif ($module['category'][$system['catid']]['child']) {
|
||||
$catids = explode(',', $module['category'][$system['catid']]['childids']);
|
||||
$fwhere[] = '`'.$table.'`.`catid` IN ('.$module['category'][$system['catid']]['childids'].')';
|
||||
} else {
|
||||
$fwhere[] = '`'.$table.'`.`catid` = '.(int)$system['catid'];
|
||||
$catids = [$system['catid']];
|
||||
}
|
||||
|
||||
// 副栏目判断
|
||||
if (isset($fields['catids']) && $fields['catids']['fieldtype'] = 'Catids') {
|
||||
foreach ($catids as $c) {
|
||||
$fwhere[] = \Phpcmf\Service::M()->where_json($table, 'catids', intval($c));
|
||||
}
|
||||
}
|
||||
$fwhere && $where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => urldecode(count($fwhere) == 1 ? $fwhere[0] : '('.implode(' OR ', $fwhere).')')
|
||||
];
|
||||
unset($fwhere);
|
||||
unset($catids);
|
||||
}
|
||||
|
||||
// 查找mwhere目录
|
||||
$mwhere = \Phpcmf\Service::Mwhere_Apps();
|
||||
if ($mwhere) {
|
||||
$mid = $dirname;
|
||||
$field = $tableinfo[$table];
|
||||
$siteid = $system['site'];
|
||||
foreach ($mwhere as $mapp) {
|
||||
$w = require dr_get_app_dir($mapp).'Config/Mwhere.php';
|
||||
if ($w) {
|
||||
$where[] = ['adj' => 'sql', 'value' => $w];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// groupid查询
|
||||
if (isset($param['groupid']) && $param['groupid']) {
|
||||
|
||||
if (strpos($param['groupid'], ',') !== false) {
|
||||
$gwhere = ' `'.$table.'`.`uid` in (select uid from `'.\Phpcmf\Service::M()->dbprefix('member').'_group_index` where `gid` in ('.dr_safe_replace($param['groupid']).'))';
|
||||
} elseif (strpos($param['groupid'], '-') !== false) {
|
||||
$arr = explode('-', $param['groupid']);
|
||||
$gwhere = [];
|
||||
foreach ($arr as $t) {
|
||||
$t = intval($t);
|
||||
$t && $gwhere[] = ' `'.$table.'`.`uid` in (select uid from `'.\Phpcmf\Service::M()->dbprefix('member').'_group_index` where `gid` = '. $t.')';
|
||||
}
|
||||
$gwhere = $gwhere ? '('.implode(' AND ', $gwhere).')' : '';
|
||||
} else {
|
||||
$gwhere = ' `'.$table.'`.`uid` in (select uid from `'.\Phpcmf\Service::M()->dbprefix('member').'_group_index` where `gid` = '. intval($param['groupid']).')';
|
||||
}
|
||||
$gwhere && $where['id'] = [
|
||||
'adj' => 'SQL',
|
||||
'name' => 'id',
|
||||
'value' => $gwhere
|
||||
];
|
||||
unset($param['groupid']);
|
||||
}
|
||||
|
||||
$where = $this->_set_where_field_prefix($where, $tableinfo[$table], $table, $fields); // 给条件字段加上表前缀
|
||||
$system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table], $table); // 给显示字段加上表前缀
|
||||
|
||||
// 多表组合排序
|
||||
$_order = [];
|
||||
$_order[$table] = $tableinfo[$table];
|
||||
|
||||
// sql的from子句
|
||||
if ($action == 'hits') {
|
||||
$sql_from = '`'.$table.'` LEFT JOIN `'.$table.'_hits` ON `'.$table.'`.`id`=`'.$table.'_hits`.`id`';
|
||||
$table_more = $table.'_hits'; // hits表
|
||||
$system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table_more], $table_more); // 给显示字段加上表前缀
|
||||
$_order[$table_more] = $tableinfo[$table_more];
|
||||
if (!$system['field']) {
|
||||
$system['field'] = '`'.$table.'`.*';
|
||||
$fields_more = \Phpcmf\Service::M()->db->getFieldNames($table_more);
|
||||
if ($fields_more) {
|
||||
foreach ($fields_more as $f) {
|
||||
if (!in_array($f, ['id', 'catid', 'uid'])) {
|
||||
$system['field'].= ',`'.$table_more.'`.`'.$f.'`';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sql_from = '`'.$table.'`';
|
||||
}
|
||||
|
||||
// 关联栏目模型表
|
||||
if ($system['more']) {
|
||||
$table_more = $table.'_category_data'; // 栏目模型表
|
||||
if (isset($module['category_data_field']) && $module['category_data_field']) {
|
||||
$fields = array_merge($fields, $module['category_data_field']);
|
||||
$where = $this->_set_where_field_prefix($where, $tableinfo[$table_more], $table_more, $fields); // 给条件字段加上表前缀
|
||||
$system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table_more], $table_more); // 给显示字段加上表前缀
|
||||
$_order[$table_more] = $tableinfo[$table_more];
|
||||
}
|
||||
$sql_from.= " LEFT JOIN $table_more ON `$table_more`.`id`=`$table`.`id`"; // sql的from子句
|
||||
if (!$system['field']) {
|
||||
$system['field'] = '`'.$table.'`.*';
|
||||
$fields_more = \Phpcmf\Service::M()->db->getFieldNames($table_more);
|
||||
if ($fields_more) {
|
||||
foreach ($fields_more as $f) {
|
||||
if (!in_array($f, ['id', 'catid', 'uid'])) {
|
||||
$system['field'].= ',`'.$table_more.'`.`'.$f.'`';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关联表
|
||||
if ($system['join'] && $system['on']) {
|
||||
$rt = $this->_join_table($table, $system, $where, $_order, $sql_from);
|
||||
if (!$rt['code']) {
|
||||
$return_data = $this->_return($system['return'], $rt['msg']);
|
||||
return;
|
||||
}
|
||||
list($system, $where, $_order, $sql_from) = $rt['data'];
|
||||
}
|
||||
|
||||
$sql_limit = $pages = '';
|
||||
$sql_where = $this->_get_where($where); // sql的where子句
|
||||
|
||||
// 商品有效期
|
||||
// isset($fields['order_etime']) && ($system['oot'] ? $sql_where.= ' AND `order_etime` BETWEEN 1 AND '.SYS_TIME : $sql_where.= ' AND NOT (`order_etime` BETWEEN 1 AND '.SYS_TIME.')');
|
||||
|
||||
// 推荐位调用
|
||||
if ($system['flag']) {
|
||||
if ($system['show_flag']) {
|
||||
$sql_from.= ' LEFT JOIN `'.$table.'_flag'.'` ON `'.$table.'`.`id`=`'.$table.'_flag`.`id`';
|
||||
$sql_where = ($sql_where ? $sql_where.' AND' : '').' `'.$table.'_flag`.'.(strpos($system['flag'], ',') ? '`flag` IN ('.$this->_get_where_in($system['flag']).')' : '`flag`='.(int)$system['flag']);
|
||||
} else {
|
||||
$flag = "select `id` from `{$table}_flag` where ".(strpos($system['flag'], ',') ? '`flag` IN ('.$this->_get_where_in($system['flag']).')' : '`flag`='.(int)$system['flag']);
|
||||
$sql_where = ($sql_where ? $sql_where.' AND' : '')." `$table`.`id` IN (".$flag.")";
|
||||
unset($flag);
|
||||
}
|
||||
}
|
||||
// 排除推荐位
|
||||
if ($system['not_flag']) {
|
||||
$flag = "select `id` from `{$table}_flag` where ".(strpos($system['not_flag'], ',') ? '`flag` IN ('.$this->_get_where_in($system['not_flag']).')' : '`flag`='.(int)$system['not_flag']);
|
||||
$sql_where = ($sql_where ? $sql_where.' AND' : '')." `$table`.`id` NOT IN (".$flag.")";
|
||||
unset($flag);
|
||||
}
|
||||
|
||||
// 统计标签
|
||||
if ($this->_return_sql) {
|
||||
$sql = "SELECT ".$this->_select_rt_name." FROM $sql_from ".($sql_where ? "WHERE $sql_where" : "")." ORDER BY NULL";
|
||||
} else {
|
||||
$first_url = $system['firsturl'];
|
||||
if ($system['page']) {
|
||||
$page = $this->_get_page_id($system['page']);
|
||||
if ($system['catid'] && is_numeric($system['catid'])) {
|
||||
if (!$system['sbpage']) {
|
||||
if ($system['pagesize']) {
|
||||
$this->_list_error[] = '存在catid参数和page参数时,pagesize参数将会无效';
|
||||
}
|
||||
if ($system['urlrule']) {
|
||||
$this->_list_error[] = '存在catid参数和page参数时,urlrule参数将会无效';
|
||||
}
|
||||
if ($this->_is_mobile) {
|
||||
$system['pagesize'] = (int)$module['category'][$system['catid']]['setting']['template']['mpagesize'];
|
||||
} else {
|
||||
$system['pagesize'] = (int)$module['category'][$system['catid']]['setting']['template']['pagesize'];
|
||||
}
|
||||
// 防止栏目生成第一页问题
|
||||
if ($system['action'] == 'module') {
|
||||
$first_url = \Phpcmf\Service::L('router')->category_url($module, $module['category'][$system['catid']]);
|
||||
if (!$this->_is_pc || SITE_ID > 1) {
|
||||
$first_url = dr_url_prefix($first_url, $module['dirname']);
|
||||
}
|
||||
}
|
||||
$system['urlrule'] = \Phpcmf\Service::L('router')->category_url($module, $module['category'][$system['catid']], '{page}');
|
||||
if (!$this->_is_pc || SITE_ID > 1) {
|
||||
$system['urlrule'] = dr_url_prefix($system['urlrule'], $module['dirname']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($system['num']) {
|
||||
$this->_list_error[] = '存在page参数时,num参数将会无效';
|
||||
}
|
||||
$pagesize = (int)$system['pagesize'];
|
||||
!$pagesize && $pagesize = 10;
|
||||
// 数据量
|
||||
$sql = "SELECT count(*) as c FROM $sql_from " . ($sql_where ? "WHERE $sql_where" : "") . " ORDER BY NULL";
|
||||
$row = $this->_query($sql, $system, FALSE);
|
||||
$total = (int)$row['c'];
|
||||
if ($system['maxlimit'] && $total > $system['maxlimit']) {
|
||||
$total = $system['maxlimit']; // 最大限制
|
||||
if ($page * $pagesize > $total) {
|
||||
$return_data = $this->_return($system['return'], 'maxlimit设置最大显示'.$system['maxlimit'].'条,当前('.$total.')已超出', $sql, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 没有数据时返回空
|
||||
if (!$total) {
|
||||
$return_data = $this->_return($system['return'], '没有查询到内容', $sql, 0);
|
||||
return;
|
||||
}
|
||||
$system['firsturl'] = $first_url;
|
||||
$pages = $this->_new_pagination($system, $pagesize, $total);
|
||||
$sql_limit = 'LIMIT ' . intval($pagesize * ($page - 1)) . ',' . $pagesize;
|
||||
} elseif ($system['num']) {
|
||||
$pages = '';
|
||||
$sql_limit = "LIMIT {$system['num']}";
|
||||
}
|
||||
|
||||
$system['order'] = $this->_set_orders_field_prefix($system['order'], $_order); // 给排序字段加上表前缀
|
||||
$sql = "SELECT " .$this->_get_select_field($system['field'] ? $system['field'] : '*') . " FROM $sql_from " . ($sql_where ? "WHERE $sql_where" : "") . ($system['order'] == "null" || !$system['order'] ? "" : " ORDER BY {$system['order']}") . " $sql_limit";
|
||||
}
|
||||
|
||||
$data = $this->_query($sql, $system);
|
||||
|
||||
// 缓存查询结果
|
||||
if (is_array($data) && $data) {
|
||||
// 模块表的系统字段
|
||||
$fields['inputtime'] = ['fieldtype' => 'Date'];
|
||||
$fields['updatetime'] = ['fieldtype' => 'Date'];
|
||||
// 格式化显示自定义字段内容
|
||||
$dfield = \Phpcmf\Service::L('Field')->app($module['dirname']);
|
||||
foreach ($data as $i => $t) {
|
||||
$t['url'] = dr_url_rel(dr_url_prefix($t['url'], $dirname, $system['site'], $this->_is_mobile));
|
||||
$data[$i] = $dfield->format_value($fields, $t, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 存储缓存
|
||||
$system['cache'] && $this->_save_cache_data($cache_name, [
|
||||
'data' => $data,
|
||||
'sql' => $sql,
|
||||
'total' => $total,
|
||||
'pages' => $pages,
|
||||
'pagesize' => $pagesize,
|
||||
'page_used' => $this->_page_used,
|
||||
'page_urlrule' => $this->_page_urlrule,
|
||||
], $system['cache']);
|
||||
|
||||
$return_data = $this->_return($system['return'], $data, $sql, $total, $pages, $pagesize);
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
// 多模块合并查询
|
||||
|
||||
$modules = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-content');
|
||||
if (!$modules) {
|
||||
return $return_data = $this->_return($system['return'], '站点('.$system['site'].')没有安装内容模块');
|
||||
}
|
||||
|
||||
if ($system['module'] == 'all') {
|
||||
$system['module'] = '';
|
||||
foreach ($modules as $t) {
|
||||
$system['module'].= $t['dirname'].',';
|
||||
$module_all[] = $t['dirname'];
|
||||
}
|
||||
$system['module'] = trim($system['module'], ',');
|
||||
} else {
|
||||
$module_all = explode(',', $system['module']);
|
||||
if (dr_count($module_all) == 1) {
|
||||
$rt = require 'Module.php';
|
||||
return $rt;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_return_sql) {
|
||||
$system['field'].= ',id,'.$system['sum'];
|
||||
}
|
||||
|
||||
if (!$system['field']) {
|
||||
return $return_data = $this->_return($system['return'], '必须传入field参数来指定显示字段');
|
||||
}
|
||||
|
||||
if ($system['more']) {
|
||||
$this->_list_error[] = '多模块查询时more参数将会无效';
|
||||
}
|
||||
|
||||
if ($system['join']) {
|
||||
$this->_list_error[] = '多模块查询时join参数将会无效';
|
||||
}
|
||||
|
||||
$system['field'] = trim($system['field'], ',');
|
||||
$field = explode(',', $system['field']);
|
||||
|
||||
// 是否操作自定义where
|
||||
if ($param['where']) {
|
||||
$where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => urldecode($param['where'])
|
||||
];
|
||||
unset($param['where']);
|
||||
}
|
||||
|
||||
$form = [];
|
||||
|
||||
// 验证模块的有效性
|
||||
foreach ($module_all as $m) {
|
||||
if (!isset($modules[$m])) {
|
||||
return $return_data = $this->_return($system['return'], '站点('.$system['site'].')没有安装内容模块('.$m.')');
|
||||
}
|
||||
$table = \Phpcmf\Service::M()->dbprefix($system['site'].'_'.$m);
|
||||
$mfield = \Phpcmf\Service::M()->db->getFieldNames($table);
|
||||
$infield = array_diff($field, $mfield);
|
||||
if ($infield) {
|
||||
return $return_data = $this->_return($system['return'], '站点('.$system['site'].')的内容模块('.$m.')不存在的字段:'.implode(',', $infield));
|
||||
}
|
||||
$mywhere = [
|
||||
// '`status` = 9',
|
||||
];
|
||||
// 推荐位调用
|
||||
if ($system['flag']) {
|
||||
$mywhere[] = "`$table`.`id` IN (".("select `id` from `{$table}_flag` where ".(strpos($system['flag'], ',') ? '`flag` IN ('.$this->_get_where_in($system['flag']).')' : '`flag`='.(int)$system['flag'])).")";
|
||||
}
|
||||
// 排除推荐位
|
||||
if ($system['not_flag']) {
|
||||
$mywhere[] = "`$table`.`id` NOT IN (".("select `id` from `{$table}_flag` where ".(strpos($system['not_flag'], ',') ? '`flag` IN ('.$this->_get_where_in($system['not_flag']).')' : '`flag`='.(int)$system['not_flag'])).")";
|
||||
}
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$m);
|
||||
$fields = $module['field'];
|
||||
// 栏目筛选
|
||||
if ($system['catid']) {
|
||||
$fwhere = [];
|
||||
if (strpos($system['catid'], ',') !== FALSE) {
|
||||
$temp = explode(',', $system['catid']);
|
||||
if ($temp) {
|
||||
$catids = [];
|
||||
foreach ($temp as $i) {
|
||||
$cat = dr_cat_value($system['site'], $module['mid'], $i);
|
||||
$catids = $cat['child'] ? array_merge($catids, $cat['catids']) : array_merge($catids, array($i));
|
||||
}
|
||||
$catids && $fwhere[] = '`'.$table.'`.`catid` IN ('.implode(',', $catids).')';
|
||||
}
|
||||
unset($temp);
|
||||
} else {
|
||||
$cat = dr_cat_value($system['site'], $module['mid'], $system['catid']);
|
||||
if ($cat['child']) {
|
||||
$catids = explode(',', $cat['childids']);
|
||||
$fwhere[] = '`'.$table.'`.`catid` IN ('.$cat['childids'].')';
|
||||
} else {
|
||||
$fwhere[] = '`'.$table.'`.`catid` = '.(int)$system['catid'];
|
||||
$catids = [$system['catid']];
|
||||
}
|
||||
}
|
||||
|
||||
// 副栏目判断
|
||||
if (isset($fields['catids']) && $fields['catids']['fieldtype'] = 'Catids') {
|
||||
foreach ($catids as $c) {
|
||||
$fwhere[] = \Phpcmf\Service::M()->where_json($table, 'catids', intval($c));
|
||||
}
|
||||
}
|
||||
if ($fwhere) {
|
||||
$mywhere[] = ''.(count($fwhere) == 1 ? $fwhere[0] : '('.implode(' OR ', $fwhere).')');
|
||||
}
|
||||
unset($fwhere);
|
||||
unset($catids);
|
||||
}
|
||||
if ($mywhere) {
|
||||
$form[] = 'SELECT '.$system['field'].',\''.$m.'\' AS mid FROM `'.$table.'` WHERE '.implode(' AND ', $mywhere);
|
||||
} else {
|
||||
$form[] = 'SELECT '.$system['field'].',\''.$m.'\' AS mid FROM `'.$table.'`';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql_limit = $pages = '';
|
||||
$where = $this->_set_where_field_prefix($where, $field, 'my', $fields); // 给条件字段加上表前缀
|
||||
$sql_where = $this->_get_where($where); // sql的where子句
|
||||
|
||||
|
||||
$sql_from = '('. implode(' UNION ALL ', $form).') as my';
|
||||
|
||||
// 统计标签
|
||||
if ($this->_return_sql) {
|
||||
$sql = "SELECT ".$this->_select_rt_name." FROM $sql_from ".($sql_where ? "WHERE $sql_where" : "")." ORDER BY NULL";
|
||||
} else {
|
||||
if ($system['page']) {
|
||||
$page = $this->_get_page_id($system['page']);
|
||||
$pagesize = (int)$system['pagesize'];
|
||||
!$pagesize && $pagesize = 10;
|
||||
// 统计数量
|
||||
$sql = "SELECT count(*) as c FROM $sql_from " . ($sql_where ? "WHERE $sql_where" : "") . " ORDER BY NULL";
|
||||
$row = $this->_query($sql, $system, FALSE);
|
||||
$total = (int)$row['c'];
|
||||
if ($system['maxlimit'] && $total > $system['maxlimit']) {
|
||||
$total = $system['maxlimit']; // 最大限制
|
||||
if ($page * $pagesize > $total) {
|
||||
$return_data = $this->_return($system['return'], 'maxlimit设置最大显示'.$system['maxlimit'].'条,当前('.$total.')已超出', $sql, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 没有数据时返回空
|
||||
if (!$total) {
|
||||
return $return_data = $this->_return($system['return'], '没有查询到内容', $sql, 0);
|
||||
}
|
||||
// 计算分页标签
|
||||
$pages = $this->_new_pagination($system, $pagesize, $total);
|
||||
$sql_limit = 'LIMIT ' . intval($pagesize * ($page - 1)) . ',' . $pagesize;
|
||||
} elseif ($system['num']) {
|
||||
$pages = '';
|
||||
$sql_limit = "LIMIT {$system['num']}";
|
||||
}
|
||||
|
||||
$system['order'] = $this->_set_order_field_prefix($system['order'], $field, 'my'); // 给排序字段加上表前缀
|
||||
$sql = "SELECT " .$system['field'] . ",mid FROM $sql_from " . ($sql_where ? "WHERE $sql_where" : "") . ($system['order'] == "null" || !$system['order'] ? "" : " ORDER BY {$system['order']}") . " $sql_limit";
|
||||
}
|
||||
|
||||
$data = $this->_query($sql, $system);
|
||||
|
||||
// 缓存查询结果
|
||||
if (is_array($data) && $data) {
|
||||
// 模块表的系统字段
|
||||
$fields['inputtime'] = ['fieldtype' => 'Date'];
|
||||
$fields['updatetime'] = ['fieldtype' => 'Date'];
|
||||
// 格式化显示自定义字段内容
|
||||
$dfield = \Phpcmf\Service::L('Field')->app($m);
|
||||
foreach ($data as $i => $t) {
|
||||
$t['url'] = dr_url_rel(dr_url_prefix($t['url'], $t['mid'], $system['site'], $this->_is_mobile));
|
||||
$data[$i] = $dfield->format_value($fields, $t, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 存储缓存
|
||||
$system['cache'] && $this->_save_cache_data($cache_name, [
|
||||
'data' => $data,
|
||||
'sql' => $sql,
|
||||
'total' => $total,
|
||||
'pages' => $pages,
|
||||
'pagesize' => $pagesize,
|
||||
'page_used' => $this->_page_used,
|
||||
'page_urlrule' => $this->_page_urlrule,
|
||||
], $system['cache']);
|
||||
|
||||
$return_data = $this->_return($system['return'], $data, $sql, $total, $pages, $pagesize);
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// 模块的相关文章
|
||||
|
||||
if (!$param['tag']) {
|
||||
$return_data = $this->_return($system['return'], '没有传入tag参数的内容'); // 没有查询到内容
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = [];
|
||||
$array = explode(',', urldecode($param['tag']));
|
||||
$tfield = 'keywords';
|
||||
if (isset($param['tfield']) && $param['tfield']) {
|
||||
$tfield = $param['tfield'];
|
||||
unset($param['tfield']);
|
||||
}
|
||||
foreach ($array as $name) {
|
||||
$name && $sql[] = '(`title` LIKE "%'.dr_safe_replace($name).'%" OR `'.$tfield.'` LIKE "%'.dr_safe_replace($name).'%")';
|
||||
}
|
||||
$sql && $where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => '('.implode(' OR ', $sql).')'
|
||||
];
|
||||
unset($param['tag']);
|
||||
if (isset($where['tag'])) {
|
||||
unset($where['tag']);
|
||||
}
|
||||
if (method_exists($this, 'add_load_tips')) {
|
||||
$this->add_load_tips('', 'Related标签适用于一万条数据以内的小数据量关联查询');
|
||||
}
|
||||
// 跳转到module方法
|
||||
if (strpos($system['module'], ',') || $system['module'] == 'all') {
|
||||
if (!$system['field']) {
|
||||
$system['field'] = 'id,title,url,'.$tfield;
|
||||
} elseif (strpos($system['field'], $tfield) === false) {
|
||||
$system['field'] = trim($system['field'], ',');
|
||||
$system['field'].= ','.$tfield;
|
||||
}
|
||||
require 'Modules.php';
|
||||
} else {
|
||||
require 'Module.php';
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
// 模块的搜索
|
||||
|
||||
$this->_is_list_search = 1;
|
||||
|
||||
$total = (int)$system['total'];
|
||||
unset($system['total']);
|
||||
|
||||
// 没有数据时返回空
|
||||
if (!$total) {
|
||||
return $this->_return($system['return'], 'total参数为空', '', 0);
|
||||
} elseif (!$dirname) {
|
||||
return $this->_return($system['return'], 'module参数不能为空');
|
||||
} elseif (!$param['id']) {
|
||||
return $this->_return($system['return'], 'id参数为空', '', 0);
|
||||
}
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$dirname);
|
||||
if (!$module) {
|
||||
return $this->_return($system['return'], '模块('.$dirname.')未安装');
|
||||
}
|
||||
|
||||
$tableinfo = \Phpcmf\Service::L('cache')->get('table-'.$system['site']);
|
||||
// 没有表结构缓存时返回空
|
||||
if (!$tableinfo) {
|
||||
return $this->_return($system['return'], '表结构缓存不存在');
|
||||
}
|
||||
|
||||
$table = \Phpcmf\Service::M()->dbprefix(dr_module_table_prefix($module['dirname'], $system['site'])); // 模块主表`
|
||||
if (!isset($tableinfo[$table])) {
|
||||
return $this->_return($system['return'], '表('.$table.')结构缓存不存在');
|
||||
}
|
||||
|
||||
if ($where) {
|
||||
foreach ($where as $i => $t) {
|
||||
if ($t['name'] == 'id') {
|
||||
unset($where[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$index = \Phpcmf\Service::L('cache')->get_data('module-search-'.$dirname.'-'.$param['id']);
|
||||
if (!$index) {
|
||||
$index = $this->_query('SELECT `params` FROM `'.$table.'_search` WHERE `id`="'.$param['id'].'"', $system, 0);
|
||||
if ($index) {
|
||||
$p = dr_string2array($index['params']);
|
||||
$index['sql'] = $p['sql'];
|
||||
$index['where'] = $p['where'];
|
||||
} else {
|
||||
return $this->_return($system['return'], '没有搜索结果', '', 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($index['where']) && $index['where']) {
|
||||
$where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => $index['where']
|
||||
];
|
||||
} elseif (isset($index['sql']) && $index['sql']) {
|
||||
$where[] = [
|
||||
'adj' => 'SQL',
|
||||
'value' => '(`'.$table.'`.`id` IN('.$index['sql'].'))'
|
||||
];
|
||||
} else {
|
||||
return $this->_return($system['return'], '没有查询到内容', $index['sql'], 0);
|
||||
}
|
||||
|
||||
unset($param['id']);
|
||||
|
||||
// 排序操作
|
||||
if (!$system['order'] && isset($where['id']) && $where['id']['adj'] == 'IN' && $where['id']['value']) {
|
||||
// 按id序列来排序
|
||||
$system['order'] = strlen($where['id']['value']) < 10000 && $where['id']['value'] ? 'FIELD(`'.$table.'`.`id`, '.$where['id']['value'].')' : 'NULL';
|
||||
} else {
|
||||
// 默认排序参数
|
||||
!$system['order'] && ($system['order'] = $system['flag'] ? 'updatetime_desc' : ($action == 'hits' ? 'hits' : 'updatetime'));
|
||||
}
|
||||
|
||||
$fields = $module['field']; // 主表的字段
|
||||
$_order = [$table => $tableinfo[$table]];
|
||||
$sql_from = '`'.$table.'`';
|
||||
$sql_where = $this->_get_where($where); // sql的where子句
|
||||
|
||||
// 关联栏目模型表
|
||||
if ($system['more'] && isset($module['category_data_field']) && $module['category_data_field']) {
|
||||
$fields = array_merge($fields, $module['category_data_field']);
|
||||
$table_more = $table.'_category_data'; // 栏目模型表
|
||||
$sql_from.= " LEFT JOIN $table_more ON `$table_more`.`id`=`$table`.`id`"; // sql的from子句
|
||||
$_order[$table_more] = $tableinfo[$table_more];
|
||||
if (!$system['field']) {
|
||||
$system['field'] = '`'.$table.'`.*';
|
||||
$fields_more = \Phpcmf\Service::M()->db->getFieldNames($table_more);
|
||||
if ($fields_more) {
|
||||
foreach ($fields_more as $f) {
|
||||
if (!in_array($f, ['id', 'catid', 'uid'])) {
|
||||
$system['field'].= ',`'.$table_more.'`.`'.$f.'`';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$system['order'] = $this->_set_orders_field_prefix($system['order'], $_order); // 给排序字段加上表前缀
|
||||
|
||||
// 分页处理
|
||||
$page = $this->_get_page_id($system['page']);
|
||||
$pagesize = (int)$system['pagesize'];
|
||||
!$pagesize && $pagesize = 10;
|
||||
if ($module['setting']['search']['max'] && $page * $pagesize > $module['setting']['search']['max']) {
|
||||
$return_data = $this->_return($system['return'], '搜索设置最大显示'.$module['setting']['search']['max'].'条,当前('.($page * $pagesize).')已超出', '', 0);
|
||||
return;
|
||||
}
|
||||
isset($index['params']) && $index['params'] && $system['firsturl'] = \Phpcmf\Service::L('Router')->search_url($index['params']);
|
||||
$pages = $this->_new_pagination($system, $pagesize, $total);
|
||||
$sql_limit = 'LIMIT ' . intval($pagesize * ($page - 1)) . ',' . $pagesize;
|
||||
|
||||
// 查询结果
|
||||
$sql = "SELECT " .$this->_get_select_field($system['field'] ? $system['field'] : '*') . " FROM $sql_from " . ($sql_where ? "WHERE $sql_where" : "") . ($system['order'] == "null" || !$system['order'] ? "" : " ORDER BY {$system['order']}") . " $sql_limit";
|
||||
$data = $this->_query($sql, $system);
|
||||
|
||||
// 缓存查询结果
|
||||
if (is_array($data) && $data) {
|
||||
// 模块表的系统字段
|
||||
$fields['inputtime'] = ['fieldtype' => 'Date'];
|
||||
$fields['updatetime'] = ['fieldtype' => 'Date'];
|
||||
// 格式化显示自定义字段内容
|
||||
$dfield = \Phpcmf\Service::L('Field')->app($module['dirname']);
|
||||
foreach ($data as $i => $t) {
|
||||
$t['url'] = dr_url_rel(dr_url_prefix($t['url'], $dirname, $system['site'], $this->_is_mobile));
|
||||
$data[$i] = $dfield->format_value($fields, $t, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 存储缓存
|
||||
$system['cache'] && $this->_save_cache_data($cache_name, [
|
||||
'data' => $data,
|
||||
'sql' => $sql,
|
||||
'total' => $total,
|
||||
'pages' => $pages,
|
||||
'pagesize' => $pagesize,
|
||||
'page_used' => $this->_page_used,
|
||||
'page_urlrule' => $this->_page_urlrule,
|
||||
], $system['cache']);
|
||||
|
||||
return $this->_return($system['return'], $data, $sql, $total, $pages, $pagesize);
|
||||
Reference in New Issue
Block a user