Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,489 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
// 栏目模型类
|
||||
|
||||
class Category extends \Phpcmf\Model {
|
||||
|
||||
protected $tablename;
|
||||
protected $categorys;
|
||||
protected $categorys_dir;
|
||||
|
||||
// 初始化模型
|
||||
public function init($data) {
|
||||
parent::init($data);
|
||||
$this->tablename = $data['table'];
|
||||
return $this;
|
||||
}
|
||||
|
||||
// 检查目录是否可用
|
||||
public function check_dirname($id, $pid, $value) {
|
||||
|
||||
if (!$value) {
|
||||
return dr_return_data(0, dr_lang('目录不能为空'));
|
||||
} elseif (!preg_match('/^[a-z0-9 \_\-]*$/i', $value)) {
|
||||
return dr_return_data(0, dr_lang('目录格式不能包含特殊符号或文字'));
|
||||
} elseif ($this->table($this->tablename)->counts() > MAX_CATEGORY) {
|
||||
return dr_return_data(0, dr_lang('网站栏目数量已达到上限'));
|
||||
} elseif (defined('SYS_CAT_RNAME') && SYS_CAT_RNAME) {
|
||||
return dr_return_data(1);
|
||||
} else {
|
||||
if ($pid) {
|
||||
$pcat = $this->table($this->tablename)->get($pid);
|
||||
if ($pcat && $this->table($this->tablename)->where('id<>'.$id)
|
||||
->where('pdirname', $pcat['dirname'].'/')
|
||||
->where('dirname', $value)->counts()) {
|
||||
return dr_return_data(0, dr_lang('目录不能重复(可以在栏目属性设置中关闭重复验证)'));
|
||||
}
|
||||
} elseif ($this->table($this->tablename)->where('id<>'.$id)
|
||||
->where('pdirname=""')->where('dirname', $value)->counts()) {
|
||||
return dr_return_data(0, dr_lang('目录不能重复(可以在栏目属性设置中关闭重复验证)'));
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data(1);
|
||||
}
|
||||
|
||||
// 检查栏目上限
|
||||
public function check_counts($id, $fix = 0) {
|
||||
|
||||
if ($id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找出子目录列表
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function get_categorys($data = array()) {
|
||||
|
||||
if (is_array($data) && !empty($data)) {
|
||||
foreach ($data as $catid => $c) {
|
||||
$result = [];
|
||||
$this->categorys[$catid] = $c;
|
||||
foreach ($this->categorys as $_k => $_v) {
|
||||
if ($_v['pid']) {
|
||||
$result[] = $_v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父栏目ID列表
|
||||
*
|
||||
* @param integer $catid 栏目ID
|
||||
* @param array $pids 父目录ID
|
||||
* @param integer $n 查找的层次
|
||||
* @return string
|
||||
*/
|
||||
protected function get_pids($catid, $pids = '', $n = 1) {
|
||||
|
||||
if ($n > 100 || !is_array($this->categorys)
|
||||
|| !isset($this->categorys[$catid])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$pid = $this->categorys[$catid]['pid'];
|
||||
$pids = $pids ? $pid.','.$pids : $pid;
|
||||
if ($pid) {
|
||||
$pids = $this->get_pids($pid, $pids, ++$n);
|
||||
}
|
||||
// : $this->categorys[$catid]['pids'] = $pids;
|
||||
|
||||
return $pids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子栏目ID列表
|
||||
*
|
||||
* @param $catid 栏目ID
|
||||
* @return string
|
||||
*/
|
||||
protected function get_childids($catid, $n = 1) {
|
||||
|
||||
$childids = $catid;
|
||||
|
||||
if ($n > 100 || !is_array($this->categorys) || !isset($this->categorys[$catid])) {
|
||||
return $childids;
|
||||
}
|
||||
|
||||
if (is_array($this->categorys)) {
|
||||
foreach ($this->categorys as $id => $cat) {
|
||||
if ($cat['pid'] && $id != $catid && $cat['pid'] == $catid) {
|
||||
$childids.= ','.$this->get_childids($id, ++$n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $childids;
|
||||
}
|
||||
|
||||
// 获取栏目下级ids
|
||||
protected function _get_next_ids($catid) {
|
||||
|
||||
$rt = [];
|
||||
|
||||
if (is_array($this->categorys)) {
|
||||
foreach ($this->categorys as $id => $cat) {
|
||||
if ($cat['pid'] == $catid) {
|
||||
$rt[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有父目录
|
||||
*
|
||||
* @param $catid ��ĿID
|
||||
* @return string
|
||||
*/
|
||||
public function get_pdirname($catid) {
|
||||
|
||||
if ($this->categorys[$catid]['pid']==0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$t = $this->categorys[$catid];
|
||||
$pids = $t['pids'];
|
||||
$pids = explode(',', $pids);
|
||||
$catdirs = [];
|
||||
krsort($pids);
|
||||
|
||||
foreach ($pids as $id) {
|
||||
if ($id == 0) {
|
||||
continue;
|
||||
}
|
||||
$catdirs[] = $this->categorys[$id]['dirname'];
|
||||
if ($this->categorys[$id]['pdirname'] == '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
krsort($catdirs);
|
||||
|
||||
return implode('/', $catdirs).'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部父级的mid值, 或者更新
|
||||
*/
|
||||
public function get_parent_mid($category, $id, $update = 0) {
|
||||
|
||||
if (!isset($category[$id])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$mid = '';
|
||||
$ids = dr_array2array(explode(',', $category[$id]['childids']), explode(',', $category[$id]['pids']));
|
||||
foreach ($ids as $id) {
|
||||
if ($id && $category[$id] && $category[$id]['mid']) {
|
||||
$mid = $category[$id]['mid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [$mid, $ids];
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化父级栏目模块mid
|
||||
*/
|
||||
public function update_parent_mid($category, $catid) {
|
||||
|
||||
if (!isset($category[$catid])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ids = explode(',', $category[$catid]['childids']);
|
||||
if (!$ids) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mid = [];
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$id
|
||||
&& $category[$id]
|
||||
&& $category[$id]['tid'] == 1
|
||||
&& $category[$id]['mid']
|
||||
&& $mid[] = $category[$id]['mid'];
|
||||
}
|
||||
|
||||
/* 当栏目下面存在多个模块时
|
||||
$mid && dr_count(array_unique($mid)) > 1 && $this->table($this->tablename)->update((int)$catid, array(
|
||||
'mid' => '',
|
||||
'tid' => 0
|
||||
));*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单数据
|
||||
*/
|
||||
public function cat_data($pid) {
|
||||
return $this->table($this->tablename)->where('pid', $pid)->order_by('displayorder ASC,id ASC')->getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复菜单数据
|
||||
*/
|
||||
public function repair($_data = [], $dirname = '') {
|
||||
|
||||
$this->categorys = $this->categorys_dir = $categorys = [];
|
||||
!$_data && $_data = $this->table($this->tablename)->where('disabled', 0)->order_by('displayorder ASC,id ASC')->getAll();
|
||||
if (!$_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 全部栏目数据
|
||||
foreach ($_data as $t) {
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
$this->categorys[$t['id']] = $categorys[$t['id']] = $t;
|
||||
}
|
||||
|
||||
foreach ($this->categorys as $catid => $cat) {
|
||||
|
||||
$this->categorys[$catid]['pids'] = $this->get_pids($catid);
|
||||
$this->categorys[$catid]['childids'] = $this->get_childids($catid);
|
||||
$this->categorys[$catid]['child'] = is_numeric($this->categorys[$catid]['childids']) ? 0 : 1;
|
||||
$this->categorys[$catid]['pdirname'] = $this->get_pdirname($catid);
|
||||
//$this->categorys[$catid]['next_ids'] = $this->_get_next_ids($catid);
|
||||
|
||||
if ($cat['pdirname'] != $this->categorys[$catid]['pdirname']
|
||||
|| $cat['pids'] != $this->categorys[$catid]['pids']
|
||||
|| $cat['childids'] != $this->categorys[$catid]['childids']
|
||||
|| $cat['child'] != $this->categorys[$catid]['child']) {
|
||||
// 当库中与实际不符合才更新数据表
|
||||
// 更新数据库
|
||||
$this->table($this->tablename)->update($cat['id'], [
|
||||
'pids' => $this->categorys[$catid]['pids'],
|
||||
'child' => $this->categorys[$catid]['child'],
|
||||
'childids' => $this->categorys[$catid]['childids'],
|
||||
'pdirname' => $this->categorys[$catid]['pdirname']
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->categorys[$catid]['child'] == 1 && $this->categorys[$catid]['catids']) {
|
||||
$ispost = 0;
|
||||
foreach ($t['catids'] as $i) {
|
||||
// 当此栏目还存在下级栏目时,逐步判断全部下级栏目是否具备发布权限
|
||||
if (isset($cat[$i]) && $cat[$i]['child'] == 0) {
|
||||
$ispost = 1; // 可以发布 表示此栏目可用
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$ispost) {
|
||||
// ispost = 0 表示此栏目没有发布权限
|
||||
//$is_cks = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 共享栏目是更新mid值
|
||||
if ($dirname == 'share' && $this->categorys[$catid]['child']) {
|
||||
$this->update_parent_mid($this->categorys, $catid);
|
||||
}
|
||||
$this->categorys_dir[$t['dirname']] = $t['id'];
|
||||
}
|
||||
|
||||
return $this->categorys;
|
||||
}
|
||||
|
||||
// 用于删除时获取的数据
|
||||
public function data_for_delete() {
|
||||
|
||||
$cache = [];
|
||||
// 全部栏目
|
||||
$data = $this->db->table($this->tablename)->orderBy('displayorder ASC,id ASC')->get()->getResultArray();
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
$cache[$t['id']] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
// 用于移动时获取的数据
|
||||
public function data_for_move() {
|
||||
|
||||
$cache = [];
|
||||
// 全部栏目
|
||||
$data = $this->db->table($this->tablename)->orderBy('displayorder ASC,id ASC')->get()->getResultArray();
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
$cache[$t['id']] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
// 复制属性
|
||||
public function copy_value($at, $setting, $id) {
|
||||
|
||||
$row = $this->table($this->tablename)->get($id);
|
||||
if (!$row) {
|
||||
return;
|
||||
}
|
||||
|
||||
$save = $row['setting'] = dr_string2array($row['setting']);
|
||||
$arr = explode(',', $at);
|
||||
foreach ($arr as $at) {
|
||||
if ($at == 'tpl') {
|
||||
$save['template'] = $setting['template'];
|
||||
$save['template']['pagesize'] = $row['setting']['template']['pagesize'];
|
||||
$save['template']['mpagesize'] = $row['setting']['template']['mpagesize'];
|
||||
} elseif ($at == 'url') {
|
||||
$save['urlrule'] = $setting['urlrule'];
|
||||
} elseif ($at == 'html') {
|
||||
$save['html'] = $setting['html'];
|
||||
$save['chtml'] = $setting['chtml'];
|
||||
} elseif ($at == 'seo') {
|
||||
$save['seo'] = $setting['seo'];
|
||||
} elseif ($at == 'size') {
|
||||
$save['template']['pagesize'] = $setting['template']['pagesize'];
|
||||
$save['template']['mpagesize'] = $setting['template']['mpagesize'];
|
||||
} elseif ($at == 'cat_field') {
|
||||
$save['cat_field'] = $setting['cat_field'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->table($this->tablename)->update($id, [
|
||||
'setting' => dr_array2string($save),
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除内容模块
|
||||
public function delete_content($cats, $module) {
|
||||
|
||||
if (!$cats) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($module['share']) {
|
||||
// 共享模块单独删除
|
||||
foreach ($cats as $t) {
|
||||
$mod = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content', $t['mid']);
|
||||
if ($mod && $t['mid']) {
|
||||
// 删除栏目模型字段
|
||||
$this->db->table('field')->where('relatedid', $t['id'])
|
||||
->where('relatedname', 'share-'.SITE_ID)->delete();
|
||||
if (!$this->db->tableExists($this->dbprefix(dr_module_table_prefix($t['mid'])))) {
|
||||
continue;
|
||||
}
|
||||
// 删除内容
|
||||
$this->table(dr_module_table_prefix($t['mid']))->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_draft')->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_flag')->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_index')->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_time')->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_verify')->where('catid', $t['id'])->delete();
|
||||
$this->table(dr_module_table_prefix($t['mid']).'_category_data')->where('catid', $t['id'])->delete();
|
||||
// 附表分表删除
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix(dr_module_table_prefix($t['mid']).'_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where('catid', $t['id'])->delete();
|
||||
}
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix(dr_module_table_prefix($t['mid']).'_category_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where('catid', $t['id'])->delete();
|
||||
}
|
||||
// 删除表单
|
||||
if ($mod['form']) {
|
||||
foreach ($mod['form'] as $form) {
|
||||
$ftable = dr_module_table_prefix($t['mid']).'_form_'.$form['table'];
|
||||
$this->table($ftable)->where('catid', $t['id'])->delete();
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix($ftable.'_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where('catid', $t['id'])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// 独立模块批量删除
|
||||
$catids = [];
|
||||
foreach ($cats as $t) {
|
||||
$catids[] = $t['id'];
|
||||
// 删除栏目模型字段
|
||||
$this->db->table('field')->where('relatedid', $t['id'])
|
||||
->where('relatedname', APP_DIR.'-'.SITE_ID)->delete();
|
||||
}
|
||||
// 批量删除
|
||||
$this->table(dr_module_table_prefix(APP_DIR))->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_draft')->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_flag')->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_index')->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_time')->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_verify')->where_in('catid', $catids)->delete();
|
||||
$this->table(dr_module_table_prefix(APP_DIR).'_category_data')->where_in('catid', $catids)->delete();
|
||||
// 附表分表删除
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix(dr_module_table_prefix(APP_DIR).'_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where_in('catid', $catids)->delete();
|
||||
}
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix(dr_module_table_prefix(APP_DIR).'_category_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where_in('catid', $catids)->delete();
|
||||
}
|
||||
// 删除表单
|
||||
if ($module['form']) {
|
||||
foreach ($module['form'] as $form) {
|
||||
$ftable = dr_module_table_prefix(APP_DIR).'_form_'.$form['table'];
|
||||
$this->table($ftable)->where_in('catid', $catids)->delete();
|
||||
for ($i = 0; $i <= 255 ;$i++) {
|
||||
$table = $this->dbprefix($ftable.'_data_'.$i);
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->table($table)->where_in('catid', $catids)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 兼容老版本
|
||||
public function get_tree_category($data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 找到主栏目id
|
||||
public function get_ismain_id($cats, $id) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,139 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
|
||||
/**
|
||||
* 内容权限(站点 / 模块 / 栏目)
|
||||
* 调用:\Phpcmf\Service::M('member_auth', 'cms')
|
||||
*/
|
||||
class Member_auth extends \Phpcmf\Model {
|
||||
|
||||
public $auth;
|
||||
public $auth_type;
|
||||
public $is_category_public;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->_reload_auth();
|
||||
}
|
||||
|
||||
// 每次从会员缓存重新读取,避免单例构造过早导致 auth 为空
|
||||
protected function _reload_auth() {
|
||||
$this->auth = isset(\Phpcmf\Service::C()->member_cache['auth2'][SITE_ID])
|
||||
? \Phpcmf\Service::C()->member_cache['auth2'][SITE_ID] : [];
|
||||
$auth_type = \Phpcmf\Service::C()->member_cache['auth_type'] ?? 0;
|
||||
// [] / null / "" 都按全局 0 处理(dr_string2array("0") 会得到 [])
|
||||
$this->auth_type = is_numeric($auth_type) ? intval($auth_type) : 0;
|
||||
}
|
||||
|
||||
// 当前登录会员的权限标识
|
||||
protected function _get_groupid($member) {
|
||||
|
||||
$auth_type = is_numeric($this->auth_type) ? intval($this->auth_type) : 0;
|
||||
|
||||
if ($auth_type == 1) {
|
||||
$groupid = $member && !empty($member['groupid']) ? $member['groupid'] : [0];
|
||||
} elseif ($auth_type == 2) {
|
||||
$groupid = $member && !empty($member['authid']) ? $member['authid'] : [0];
|
||||
} else {
|
||||
$groupid = ['public'];
|
||||
}
|
||||
|
||||
if (!is_array($groupid)) {
|
||||
$groupid = [$groupid];
|
||||
}
|
||||
|
||||
return $groupid ? array_values($groupid) : [0];
|
||||
}
|
||||
|
||||
// 取某一 aid 下的栏目权限配置
|
||||
protected function _category_auth_row($gid, $module, $catid) {
|
||||
|
||||
$mid = isset($module['dirname']) ? $module['dirname'] : '';
|
||||
if (!$mid && defined('APP_DIR')) {
|
||||
$mid = APP_DIR;
|
||||
}
|
||||
|
||||
if (!empty($module['share'])) {
|
||||
if (!empty($this->auth[$gid]['home']['is_category'])) {
|
||||
$this->is_category_public = 0;
|
||||
return isset($this->auth[$gid]['share_category'][$catid])
|
||||
? $this->auth[$gid]['share_category'][$catid] : [];
|
||||
}
|
||||
$this->is_category_public = 1;
|
||||
return isset($this->auth[$gid]['share_category_public'])
|
||||
? $this->auth[$gid]['share_category_public'] : [];
|
||||
}
|
||||
|
||||
if (!empty($this->auth[$gid]['module'][$mid]['is_category'])) {
|
||||
$this->is_category_public = 0;
|
||||
return isset($this->auth[$gid]['category'][$mid][$catid])
|
||||
? $this->auth[$gid]['category'][$mid][$catid] : [];
|
||||
}
|
||||
$this->is_category_public = 1;
|
||||
return isset($this->auth[$gid]['category_public'][$mid])
|
||||
? $this->auth[$gid]['category_public'][$mid] : [];
|
||||
}
|
||||
|
||||
// 站点权限
|
||||
public function home_auth($name, $member = []) {
|
||||
|
||||
$this->_reload_auth();
|
||||
$values = [];
|
||||
foreach ($this->_get_groupid($member) as $gid) {
|
||||
if (isset($this->auth[$gid]['home'][$name])) {
|
||||
$values[] = $this->auth[$gid]['home'][$name];
|
||||
}
|
||||
}
|
||||
|
||||
return $values ? max($values) : null;
|
||||
}
|
||||
|
||||
// 模块权限
|
||||
public function module_auth($mid, $name, $member = []) {
|
||||
|
||||
$this->_reload_auth();
|
||||
$values = [];
|
||||
foreach ($this->_get_groupid($member) as $gid) {
|
||||
if (isset($this->auth[$gid]['module'][$mid][$name])) {
|
||||
$values[] = $this->auth[$gid]['module'][$mid][$name];
|
||||
}
|
||||
}
|
||||
|
||||
return $values ? max($values) : null;
|
||||
}
|
||||
|
||||
// 栏目权限
|
||||
public function category_auth($module, $catid, $name, $member = []) {
|
||||
|
||||
$this->_reload_auth();
|
||||
$values = [];
|
||||
$this->is_category_public = 0;
|
||||
$groupid = $this->_get_groupid($member);
|
||||
$has_config = false;
|
||||
|
||||
foreach ($groupid as $gid) {
|
||||
$auth = $this->_category_auth_row($gid, $module, $catid);
|
||||
if ($auth) {
|
||||
// 本组已有栏目权限配置:未勾选的项视为关闭,不能再回退 public
|
||||
$has_config = true;
|
||||
if (isset($auth[$name])) {
|
||||
$values[] = $auth[$name];
|
||||
}
|
||||
} elseif ($name === 'show') {
|
||||
$values[] = 1; // 默认没勾选时访问开放
|
||||
}
|
||||
}
|
||||
|
||||
// 按用户组/等级时,仅当本组完全没有栏目权限配置,才回退 public
|
||||
if (!$has_config && !$values && !in_array('public', $groupid, true) && isset($this->auth['public'])) {
|
||||
$auth = $this->_category_auth_row('public', $module, $catid);
|
||||
if (isset($auth[$name])) {
|
||||
$values[] = $auth[$name];
|
||||
} elseif (!$auth && $name === 'show') {
|
||||
$values[] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $values ? max($values) : null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
|
||||
// 菜单控制模型
|
||||
|
||||
class Menu extends \Phpcmf\Model {
|
||||
|
||||
// 变更模块名称
|
||||
public function update_module_name($mid, $old, $new, $icon) {
|
||||
|
||||
$replace = '`icon`="'.$icon.'", `name`=REPLACE(`name`, \''.addslashes($old).'\', \''.addslashes($new).'\')';
|
||||
|
||||
$this->is_table_exists('member_menu') && $this->db->query('UPDATE `'.$this->dbprefix('member_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/home/index"');
|
||||
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/home/index"');
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/verify/index"');
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/comment_verify/index"');
|
||||
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_min_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/home/index"');
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_min_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/verify/index"');
|
||||
$this->db->query('UPDATE `'.$this->dbprefix('admin_min_menu').'` SET '.$replace.' WHERE uri="'.$mid.'/comment_verify/index"');
|
||||
}
|
||||
|
||||
// 从模块中更新菜单
|
||||
public function update_module($mdir, $config, $form) {
|
||||
|
||||
// 作为应用模块时且不操作menu.php时,不需要菜单
|
||||
if (isset($config['ftpye']) && $config['ftpye'] == 'module'
|
||||
&& is_file(dr_get_app_dir($mdir).'Config/Menu.php')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 内容模块 入库后台菜单
|
||||
if ($config['system'] == 1) {
|
||||
foreach (['admin', 'admin_min'] as $table) {
|
||||
$left = $this->db->table($table.'_menu')->where('mark', 'content-module')->get()->getRowArray();
|
||||
if ($left) {
|
||||
// 查询模块菜单
|
||||
$menu = $this->db->table($table.'_menu')->where('mark', 'module-'.$mdir)->get()->getRowArray();
|
||||
$save = [
|
||||
'uri' => $mdir.'/home/index',
|
||||
'mark' => 'module-'.$mdir,
|
||||
'name' => $menu && $menu['name'] ? $menu['name'] : dr_lang('%s管理', $config['name']),
|
||||
'icon' => $menu && $menu['icon'] ? $menu['icon'] : dr_icon($config['icon']),
|
||||
'displayorder' => $menu ? intval($menu['displayorder']) : '-1',
|
||||
];
|
||||
$menu ? \Phpcmf\Service::M('menu')->_edit($table, $menu['id'], $save) : \Phpcmf\Service::M('menu')->_add($table, $left['id'], $save);
|
||||
}
|
||||
// 入库后台审核菜单
|
||||
$left = $this->db->table($table.'_menu')->where('mark', 'content-verify')->get()->getRowArray();
|
||||
if ($left) {
|
||||
// 内容模块入库
|
||||
if ($config['system'] == 1) {
|
||||
$menu = $this->db->table($table.'_menu')->where('mark', 'verify-module-'.$mdir)->get()->getRowArray();
|
||||
$save = [
|
||||
'uri' => $mdir.'/verify/index',
|
||||
'mark' => 'verify-module-'.$mdir,
|
||||
'name' => $menu && $menu['name'] ? $menu['name'] : dr_lang('%s审核', $config['name']),
|
||||
'icon' => $menu && $menu['icon'] ? $menu['icon'] : dr_icon($config['icon']),
|
||||
'displayorder' => $menu ? intval($menu['displayorder']) : '-1',
|
||||
];
|
||||
$menu ? \Phpcmf\Service::M('menu')->_edit($table, $menu['id'], $save) : \Phpcmf\Service::M('menu')->_add($table, $left['id'], $save);
|
||||
}
|
||||
// 表单入库
|
||||
if ($form && dr_is_app('mform')) {
|
||||
\Phpcmf\Service::M('mform', 'mform')->link_menu($form, $table, $mdir, $config, $left);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 内容模块入库用户菜单
|
||||
if ($config['system'] == 1 && $this->is_table_exists('member_menu')) {
|
||||
$left = $this->db->table('member_menu')->where('mark', 'content-module')->get()->getRowArray();
|
||||
if ($left) {
|
||||
// 查询模块菜单
|
||||
$menu = $this->db->table('member_menu')->where('mark', 'module-'.$mdir)->get()->getRowArray();
|
||||
$save = [
|
||||
'uri' => $mdir.'/home/index',
|
||||
'mark' => 'module-'.$mdir,
|
||||
'name' => $menu && $menu['name'] ? $menu['name'] : dr_lang('%s管理', $config['name']),
|
||||
'icon' => $menu && $menu['icon'] ? $menu['icon'] : dr_icon($config['icon']),
|
||||
'displayorder' => $menu ? intval($menu['displayorder']) : '-1',
|
||||
];
|
||||
$menu ? \Phpcmf\Service::M('menu')->_edit('member', $menu['id'], $save) : \Phpcmf\Service::M('menu')->_add('member', $left['id'], $save);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,345 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
|
||||
// 模块搜索类
|
||||
class Search extends \Phpcmf\Model {
|
||||
|
||||
public $mytable; // 模块表名称
|
||||
public $module; // 模块属性
|
||||
public $catid; // 栏目id
|
||||
public $get; // 搜索参数
|
||||
|
||||
// 初始化搜索主表
|
||||
public function init($table) {
|
||||
$this->mytable = dr_module_table_prefix($table, SITE_ID);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// 获取搜索参数
|
||||
public function get_param($module) {
|
||||
|
||||
$get = $_GET;
|
||||
$get = isset($get['rewrite']) ? dr_search_rewrite_decode($get['rewrite'], $module['setting']['search']) : $get;
|
||||
if ($get) {
|
||||
$get = \Phpcmf\Service::L('input')->xss_clean($get);
|
||||
}
|
||||
|
||||
$get['s'] = $get['c'] = $get['m'] = $get['id'] = null;
|
||||
unset($get['s'], $get['c'], $get['m'], $get['id']);
|
||||
if (!$get && IS_API_HTTP) {
|
||||
$get = \Phpcmf\Service::L('input')->xss_clean($_POST);
|
||||
}
|
||||
|
||||
$_GET['page'] = $get['page'] = (int)$get['page'];
|
||||
if (isset($get['catdir']) && $get['catdir']) {
|
||||
$catid = (int)$module['category_dir'][$get['catdir']];
|
||||
unset($get['catid']);
|
||||
} else {
|
||||
$catid = (int)$get['catid'];
|
||||
isset($get['catid']) && $get['catid'] = $catid;
|
||||
}
|
||||
|
||||
// 固定模式下的填充
|
||||
if ($get && $this->module['setting']['search']['param_rule']) {
|
||||
foreach ($get as $i => $t) {
|
||||
if ((string)$this->module['setting']['search']['param_join_default_value'] === $t) {
|
||||
unset($get[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->get = $get;
|
||||
$this->catid = $catid;
|
||||
$this->module = $module;
|
||||
|
||||
// 挂钩点 搜索之前对参数处理
|
||||
\Phpcmf\Hooks::trigger('search_param', $get);
|
||||
|
||||
return [$catid, $get];
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据并设置缓存
|
||||
*/
|
||||
public function get_data() {
|
||||
|
||||
// 模块表名称
|
||||
$table = $this->dbprefix($this->mytable);
|
||||
|
||||
// 挂钩点 自定义返回数据
|
||||
$rt2 = \Phpcmf\Hooks::trigger_callback('module_search_get_data');
|
||||
if ($rt2 && isset($rt2['code']) && $rt2['code']) {
|
||||
return $rt2['data'];
|
||||
}
|
||||
|
||||
// 排序查询参数
|
||||
ksort($this->get);
|
||||
$param = $this->get;
|
||||
$catid = $this->catid;
|
||||
$param_new = [];
|
||||
$this->get['order'] = $this->get['page'] = null;
|
||||
unset($this->get['order'], $this->get['page']);
|
||||
|
||||
// 查询缓存
|
||||
$id = md5($table.dr_array2string($this->get).$catid);
|
||||
if (!IS_DEV && SYS_CACHE_SEARCH) {
|
||||
$data = $this->db->table($this->mytable.'_search')->where('id', $id)->get()->getRowArray();
|
||||
$time = SYS_CACHE_SEARCH * 3600;
|
||||
if ($data && $data['inputtime'] + $time < SYS_TIME) {
|
||||
$data = [];
|
||||
}
|
||||
$this->db->table($this->mytable.'_search')->where('inputtime <'. (SYS_TIME - $time))->delete();
|
||||
} else {
|
||||
$data = [];
|
||||
$this->db->table($this->mytable.'_search')->where('inputtime <'. (SYS_TIME - 3600))->delete();
|
||||
}
|
||||
|
||||
$is_like = intval($this->module['setting']['search']['is_like']);
|
||||
|
||||
// 缓存不存在重新入库更新缓存
|
||||
if (!$data) {
|
||||
|
||||
$this->get['keyword'] = $this->get['catid'] = null;
|
||||
unset($this->get['keyword'], $this->get['catid']);
|
||||
|
||||
// 主表的字段
|
||||
$field = \Phpcmf\Service::L('cache')->get('table-'.SITE_ID, $this->dbprefix($this->mytable));
|
||||
if (!$field) {
|
||||
return dr_return_data(0, dr_lang('主表【%s】字段不存在', $this->mytable));
|
||||
}
|
||||
|
||||
$mod_field = $this->module['field'];
|
||||
foreach ($field as $i) {
|
||||
if (!isset($mod_field[$i])) {
|
||||
$mod_field[$i] = ['ismain' => 1];
|
||||
}
|
||||
}
|
||||
|
||||
// 默认搜索条件
|
||||
$where = [
|
||||
//'status' => '`'.$table.'`.`status` = 9'
|
||||
];
|
||||
|
||||
// 栏目的字段
|
||||
if ($catid) {
|
||||
$more = 0;
|
||||
$cat_field = $this->module['category'][$catid]['field'];
|
||||
// 副栏目判断
|
||||
if (isset($this->module['field']['catids']) && $this->module['field']['catids']['fieldtype'] == 'Catids') {
|
||||
$fwhere = [];
|
||||
if ($this->module['category'][$catid]['child'] && $this->module['category'][$catid]['childids']) {
|
||||
$fwhere[] = '`'.$table.'`.`catid` IN ('.$this->module['category'][$catid]['childids'].')';
|
||||
$catids = explode(',', $this->module['category'][$catid]['childids']);
|
||||
} else {
|
||||
$fwhere[] = '`'.$table.'`.`catid` = '.$catid;
|
||||
$catids = [ $catid ];
|
||||
}
|
||||
foreach ($catids as $c) {
|
||||
$fwhere[] = \Phpcmf\Service::M()->where_json($table, 'catids', intval($c));
|
||||
}
|
||||
$fwhere && $where['catid'] = '('.implode(' OR ', $fwhere).')';
|
||||
} else {
|
||||
// 无副栏目时
|
||||
$where['catid'] = '`'.$table.'`.`catid`'.($this->module['category'][$catid]['child'] ? 'IN ('.$this->module['category'][$catid]['childids'].')' : '='.(int)$catid);
|
||||
}
|
||||
|
||||
if ($cat_field) {
|
||||
// 栏目模型表
|
||||
$more_where = [];
|
||||
$table_more = $this->dbprefix($this->mytable.'_category_data');
|
||||
foreach ($cat_field as $name) {
|
||||
if (isset($this->get[$name]) && strlen($this->get[$name])) {
|
||||
$more = 1;
|
||||
$r = $this->mywhere($table_more, $name, $this->get[$name], $this->module['category_data_field'][$name], $is_like);
|
||||
if ($r) {
|
||||
$more_where[] = $r;
|
||||
$param_new[$name] = $this->get[$name];
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (isset($_order_by[$name])) {
|
||||
$more = 1;
|
||||
$order_by[] = '`'.$table.'`.`'.$name.'` '.$_order_by[$name];
|
||||
}*/
|
||||
}
|
||||
$more && $where[] = '`'.$table.'`.`id` IN (SELECT `id` FROM `'.$table_more.'` WHERE '.implode(' AND ', $more_where).')';
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (dr_is_app('fstatus') && isset($this->module['field']['fstatus']) && $this->module['field']['fstatus']['ismain']) {
|
||||
$where[] = [ '`'.$table.'`.`fstatus` = 1' ];
|
||||
}*/
|
||||
// 查找mwhere目录
|
||||
$mwhere = \Phpcmf\Service::Mwhere_Apps();
|
||||
if ($mwhere) {
|
||||
list($siteid, $mid) = explode('_', $this->mytable);
|
||||
foreach ($mwhere as $mapp) {
|
||||
$w = require dr_get_app_dir($mapp).'Config/Mwhere.php';
|
||||
if ($w) {
|
||||
$where[] = $w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关键字匹配条件
|
||||
if ($param['keyword'] != '') {
|
||||
$temp = [];
|
||||
$sfield = explode(',', $this->module['setting']['search']['field'] ? $this->module['setting']['search']['field'] : 'title,keywords');
|
||||
$search_keyword = explode('|', addslashes((string)$param['keyword']));
|
||||
foreach ($search_keyword as $kw) {
|
||||
$is = 0;
|
||||
if ($sfield) {
|
||||
foreach ($sfield as $t) {
|
||||
if ($t && dr_in_array($t, $field)) {
|
||||
$is = 1;
|
||||
$temp[] = $this->module['setting']['search']['complete'] ? '`'.$table.'`.`'.$t.'` = "'.$kw.'"' : '`'.$table.'`.`'.$t.'` LIKE "%'.$kw.'%"';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$is) {
|
||||
$temp[] = $this->module['setting']['search']['complete'] ? '`'.$table.'`.`title` = "'.$kw.'"' : '`'.$table.'`.`title` LIKE "%'.$kw.'%"';
|
||||
}
|
||||
}
|
||||
$where['keyword'] = $temp ? '('.implode(' OR ', $temp).')' : '';
|
||||
$param_new['keyword'] = $search_keyword;
|
||||
}
|
||||
|
||||
// 模块字段过滤
|
||||
foreach ($mod_field as $name => $field) {
|
||||
if (isset($field['ismain']) && !$field['ismain']) {
|
||||
continue;
|
||||
}
|
||||
if (isset($this->get[$name]) && strlen($this->get[$name])) {
|
||||
$r = $this->mywhere($table, $name, $this->get[$name], $field, $is_like);
|
||||
if ($r) {
|
||||
$where[$name] = $r;
|
||||
$param_new[$name] = $this->get[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_USE_MEMBER) {
|
||||
// 会员字段过滤
|
||||
$member_where = [];
|
||||
if (\Phpcmf\Service::C()->member_cache['field']) {
|
||||
foreach (\Phpcmf\Service::C()->member_cache['field'] as $name => $field) {
|
||||
if (isset($field['ismain']) && !$field['ismain']) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($mod_field[$name]) && isset($this->get[$name]) && strlen($this->get[$name])) {
|
||||
$r = $this->mywhere($this->dbprefix('member_data'), $name, $this->get[$name], $field, $is_like);
|
||||
if ($r) {
|
||||
$member_where[] = $r;
|
||||
$param_new[$name] = $this->get[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按会员组搜索时
|
||||
if ($param['groupid'] != '') {
|
||||
$member_where[] = '`'.$this->dbprefix('member_data').'`.`id` IN (SELECT `uid` FROM `'.$this->dbprefix('member').'_group_index` WHERE gid='.intval($param['groupid']).')';
|
||||
$param_new['groupid'] = $this->get['groupid'];
|
||||
}
|
||||
// 组合会员字段
|
||||
if ($member_where) {
|
||||
$where[] = '`'.$table.'`.`uid` IN (select `id` from `'.$this->dbprefix('member_data').'` where '.implode(' AND ', $member_where).')';
|
||||
}
|
||||
}
|
||||
|
||||
// flag
|
||||
if (isset($param['flag']) && $param['flag']) {
|
||||
$wh = [];
|
||||
$arr = explode('|', $param['flag']);
|
||||
foreach ($arr as $k) {
|
||||
$wh[] = intval($k);
|
||||
}
|
||||
$where[] = '`'.$table.'`.`id` IN (select `id` from `'.$table.'_flag` where `flag` in ('.implode(',', $wh).'))';
|
||||
$param_new['flag'] = $param['flag'];
|
||||
}
|
||||
|
||||
// 筛选空值
|
||||
foreach ($where as $i => $t) {
|
||||
if (dr_strlen($t) == 0) {
|
||||
unset($where[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义组合查询
|
||||
isset($param['catid']) && $param_new['catid'] = $param['catid'];
|
||||
isset($param['catdir']) && $param_new['catdir'] = $param['catdir'];
|
||||
isset($param['keyword']) && $param_new['keyword'] = $param['keyword'];
|
||||
$param_new = $this->myparam($param_new);
|
||||
$where = $this->mysearch($this->module, $where, $param_new);
|
||||
$where = $where ? implode(' AND ', $where) : '';
|
||||
$where_sql = $where ? 'WHERE '.$where : '';
|
||||
|
||||
// 组合sql查询结果
|
||||
$sql = "SELECT `{$table}`.`id` FROM `".$table."` {$where_sql} ORDER BY NULL ";
|
||||
|
||||
// 统计搜索数量
|
||||
$ct = $this->db->query("SELECT count(*) as t FROM `".$table."` {$where_sql} ORDER BY NULL ")->getRowArray();
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'catid' => intval($catid),
|
||||
'params' => dr_array2string(['param' => $param_new, 'sql' => $sql, 'where' => $where]),
|
||||
'keyword' => $param['keyword'] ? $param['keyword'] : '',
|
||||
'contentid' => intval($ct['t']),
|
||||
'inputtime' => SYS_TIME
|
||||
];
|
||||
if ($ct['t']) {
|
||||
// 存储数据
|
||||
$this->db->table($this->mytable.'_search')->replace($data);
|
||||
}
|
||||
} else {
|
||||
$this->db->table($this->mytable.'_search')->where('id', $data['id'])->update([
|
||||
'inputtime' => SYS_TIME
|
||||
]);
|
||||
}
|
||||
|
||||
// 格式化值
|
||||
$p = dr_string2array($data['params']);
|
||||
$data['sql'] = $p['sql'];
|
||||
$data['where'] = $p['where'];
|
||||
$data['params'] = $p['param'];
|
||||
if (isset($param['catdir']) && $param['catdir'] && $catid) {
|
||||
# 目录栏目模式
|
||||
unset($data['params']['catid']);
|
||||
} elseif ($catid) {
|
||||
$data['params']['catid'] = $catid;
|
||||
}
|
||||
// order 参数
|
||||
if (isset($param['order']) && $param['order']) {
|
||||
$data['params']['order'] = dr_rp(dr_safe_filename($param['order']), '`', '');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 重组搜索条件
|
||||
protected function mywhere($table, $name, $value, $field, $is_like = false) {
|
||||
$is_double_like = intval($this->module['setting']['search']['is_double_like']);
|
||||
if ($is_double_like && isset($field['fieldtype']) && in_array($field['fieldtype'], [
|
||||
'Selects' , 'Checkbox', 'Cats', 'Radio', 'Select', 'Linkages', 'Linkage'
|
||||
])) {
|
||||
$value.= '||';
|
||||
}
|
||||
$where = $this->_where($table, $name, $value, $field, $is_like);
|
||||
return $where;
|
||||
}
|
||||
|
||||
// 自定义组合参数
|
||||
protected function myparam($get) {
|
||||
return $get;
|
||||
}
|
||||
|
||||
// 自定义组合查询条件
|
||||
protected function mysearch($module, $where, $get) {
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace Phpcmf\Model;
|
||||
class Search extends \Phpcmf\Model\Cms\Search {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
|
||||
|
||||
class Site extends \Phpcmf\Model {
|
||||
|
||||
// 设置风格
|
||||
public function set_theme($name, $siteid) {
|
||||
|
||||
$site = $this->table('site')->get($siteid);
|
||||
if (!$site) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$site['setting'] = dr_string2array($site['setting']);
|
||||
$site['setting']['config']['SITE_THEME'] = $name;
|
||||
|
||||
$this->table('site')->update($siteid, [
|
||||
'setting' => dr_array2string($site['setting']),
|
||||
]);
|
||||
}
|
||||
|
||||
// 设置模板
|
||||
public function set_template($name, $siteid) {
|
||||
|
||||
$site = $this->table('site')->get($siteid);
|
||||
if (!$site) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$site['setting'] = dr_string2array($site['setting']);
|
||||
$site['setting']['config']['SITE_TEMPLATE'] = $name;
|
||||
|
||||
$this->table('site')->update($siteid, [
|
||||
'setting' => dr_array2string($site['setting']),
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取网站配置
|
||||
public function config($siteid, $name = '', $data = []) {
|
||||
|
||||
!$siteid && $siteid = SITE_ID;
|
||||
$site = $this->table('site')->get($siteid);
|
||||
if (!$site) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$site['setting'] = dr_string2array($site['setting']);
|
||||
$site['setting']['config']['SITE_NAME'] = $site['name'];
|
||||
$site['setting']['config']['SITE_DOMAIN'] = strtolower((string)$site['domain']);
|
||||
|
||||
if ($name && $data) {
|
||||
// 更新数据
|
||||
if ($data['SITE_NAME']) {
|
||||
$site['name'] = $data['SITE_NAME'];
|
||||
}
|
||||
if ($data['SITE_DOMAIN']) {
|
||||
$site['domain'] = $data['SITE_DOMAIN'];
|
||||
}
|
||||
$site['setting'][$name] = $data;
|
||||
$this->table('site')->update($siteid, [
|
||||
'name' => $site['name'],
|
||||
'domain' => strtolower((string)$site['domain']),
|
||||
'setting' => dr_array2string($site['setting']),
|
||||
]);
|
||||
}
|
||||
|
||||
return $site['setting'];
|
||||
}
|
||||
|
||||
// 存储网站配置
|
||||
public function save_config($siteid, $name, $data) {
|
||||
|
||||
!$siteid && $siteid = SITE_ID;
|
||||
$site = $this->table('site')->get($siteid);
|
||||
if (!$site) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$site['setting'] = dr_string2array($site['setting']);
|
||||
$site['setting']['config']['SITE_NAME'] = $site['name'];
|
||||
$site['setting']['config']['SITE_DOMAIN'] = strtolower((string)$site['domain']);
|
||||
|
||||
// 更新数据
|
||||
if ($data['SITE_NAME']) {
|
||||
$site['name'] = $data['SITE_NAME'];
|
||||
}
|
||||
if ($data['SITE_DOMAIN']) {
|
||||
$site['domain'] = $data['SITE_DOMAIN'];
|
||||
}
|
||||
$site['setting'][$name] = $data;
|
||||
$this->table('site')->update($siteid, [
|
||||
'name' => $site['name'],
|
||||
'domain' => strtolower((string)$site['domain']),
|
||||
'setting' => dr_array2string($site['setting']),
|
||||
]);
|
||||
|
||||
return $site['setting'];
|
||||
}
|
||||
|
||||
// 设置网站单个配置
|
||||
public function config_value($siteid, $group, $value) {
|
||||
|
||||
!$siteid && $siteid = SITE_ID;
|
||||
$site = $this->table('site')->get($siteid);
|
||||
if (!$site || !$value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$site['setting'] = dr_string2array($site['setting']);
|
||||
|
||||
foreach ($value as $n => $v) {
|
||||
$site['setting'][$group][$n] = $v;
|
||||
}
|
||||
|
||||
$this->table('site')->update($siteid, [
|
||||
'setting' => dr_array2string($site['setting']),
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 新增
|
||||
public function create($data) {
|
||||
|
||||
$save = [
|
||||
'name' => $data['name'],
|
||||
'domain' => (string)$data['domain'],
|
||||
'setting' => dr_array2string([
|
||||
'webpath' => $data['webpath'],
|
||||
]),
|
||||
'disabled' => 0,
|
||||
'displayorder' => 0,
|
||||
];
|
||||
if (defined('IS_INSTALL')) {
|
||||
$save['id'] = 1;
|
||||
}
|
||||
$this->db->table('site')->replace($save);
|
||||
|
||||
$siteid = $this->db->insertID();
|
||||
|
||||
if ($siteid == 1) {
|
||||
return $siteid; // 安装不执行后面操作
|
||||
}
|
||||
|
||||
if (dr_is_app('sites')) {
|
||||
$obj = \Phpcmf\Service::M('sites', 'sites');
|
||||
if (method_exists($obj, 'create')) {
|
||||
$obj->create($siteid, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $siteid;
|
||||
}
|
||||
|
||||
// 变更主域名
|
||||
public function edit_domain($value) {
|
||||
|
||||
$site = $this->config(1);
|
||||
$value = trim(strtolower($value), '/');
|
||||
$this->db->table('site')->where('id', 1)->update([
|
||||
'domain' => $value,
|
||||
'setting' => dr_array2string($site),
|
||||
]);
|
||||
// 替换栏目编辑器域名
|
||||
$table = $this->dbprefix(SITE_ID.'_share_category');
|
||||
if ($this->is_table_exists($table)) {
|
||||
$this->db->query('UPDATE `'.$table.'` SET `content`=REPLACE(`content`, \''.$site['config']['SITE_DOMAIN'].'\', \''.$value.'\')');
|
||||
}
|
||||
}
|
||||
|
||||
// 设置域名
|
||||
public function domain($value = []) {
|
||||
|
||||
$data = [];
|
||||
$site = $this->config(SITE_ID);
|
||||
if ($value) {
|
||||
$site['webpath'] = $value['webpath'];
|
||||
$this->db->table('site')->where('id', SITE_ID)->update([
|
||||
'domain' => trim(strtolower($value['site_domain'] ? $value['site_domain'] : $site['domain']), '/'),
|
||||
'setting' => dr_array2string($site),
|
||||
]);
|
||||
}
|
||||
|
||||
$data['webpath'] = $site['webpath'];
|
||||
$data['site_domain'] = strtolower((string)$site['config']['SITE_DOMAIN']);
|
||||
|
||||
// 识别手机域名
|
||||
if (isset($site['mobile']['mode']) && $site['mobile']['mode'] != -1) {
|
||||
if (!$site['mobile']['mode']) {
|
||||
$data['mobile_domain'] = $site['mobile']['domain'];
|
||||
} else {
|
||||
$data['mobile_domain'] = $site['config']['SITE_DOMAIN'].'/'.trim($site['mobile']['dirname'] ? $site['mobile']['dirname'] : 'mobile');
|
||||
}
|
||||
} else {
|
||||
$data['mobile_domain'] = $site['mobile']['domain'];
|
||||
}
|
||||
|
||||
if ($site['client']) {
|
||||
foreach ($site['client'] as $c) {
|
||||
if ($c['name'] && $c['domain']) {
|
||||
$data['client_'.$c['name']] = $c['domain'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 模块域名
|
||||
$my = [];
|
||||
if (IS_USE_MODULE) {
|
||||
list($my, $data) = \Phpcmf\Service::M('module', 'cms')->domian($value, $my, $data);
|
||||
}
|
||||
|
||||
return [$my, $data];
|
||||
}
|
||||
|
||||
// 站点缓存缓存
|
||||
public function cache($siteid = null, $data = null, $module = null) {
|
||||
|
||||
!$data && $data = $this->table('site')->where('disabled', 0)->order_by('displayorder ASC,id ASC')->getAll();
|
||||
$sso_domain = $client_domain = $webpath = $app_domain = $site_domain = $config = $cache = [];
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
if ($t['id'] > 1 && !dr_is_app('sites')) {
|
||||
break;
|
||||
}
|
||||
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
$mobile_dirname = 'mobile';
|
||||
|
||||
// 识别手机域名
|
||||
if (isset($t['setting']['mobile']['mode']) && $t['setting']['mobile']['mode'] != -1) {
|
||||
if (!$t['setting']['mobile']['mode']) {
|
||||
$mobile_domain = (string)$t['setting']['mobile']['domain'];
|
||||
} else {
|
||||
$mobile_dirname = trim($t['setting']['mobile']['dirname'] ? $t['setting']['mobile']['dirname'] : 'mobile');
|
||||
$mobile_domain = $t['domain'].'/'.$mobile_dirname;
|
||||
}
|
||||
} else {
|
||||
$mobile_domain = (string)$t['setting']['mobile']['domain'];
|
||||
}
|
||||
|
||||
$config[$t['id']] = [
|
||||
'SITE_NAME' => $t['name'],
|
||||
'SITE_DOMAIN' => strtolower($t['domain']),
|
||||
'SITE_LOGO' => $t['setting']['config']['logo'] ? dr_get_file($t['setting']['config']['logo']) : ROOT_THEME_PATH.'assets/logo-web.png',
|
||||
'SITE_MOBILE' => $mobile_domain,
|
||||
'SITE_MOBILE_DIR' => $mobile_dirname,
|
||||
'SITE_AUTO' => (string)$t['setting']['mobile']['auto'],
|
||||
'SITE_IS_MOBILE_HTML' => (string)$t['setting']['mobile']['tohtml'],
|
||||
'SITE_MOBILE_NOT_PAD' => (string)$t['setting']['mobile']['not_pad'],
|
||||
'SITE_CLOSE' => $t['setting']['config']['SITE_CLOSE'],
|
||||
'SITE_THEME' => $t['setting']['config']['SITE_THEME'],
|
||||
'SITE_TEMPLATE' => $t['setting']['config']['SITE_TEMPLATE'],
|
||||
'SITE_REWRITE' => $t['setting']['seo']['SITE_REWRITE'],
|
||||
'SITE_SEOJOIN' => $t['setting']['seo']['SITE_SEOJOIN'],
|
||||
'SITE_LANGUAGE' => $t['setting']['config']['SITE_LANGUAGE'],
|
||||
'SITE_TIMEZONE' => $t['setting']['config']['SITE_TIMEZONE'],
|
||||
'SITE_TIME_FORMAT' => $t['setting']['config']['SITE_TIME_FORMAT'],
|
||||
'SITE_INDEX_HTML' => (string)$t['setting']['config']['SITE_INDEX_HTML'],
|
||||
'SITE_THUMB_WATERMARK' => (int)$t['setting']['watermark']['thumb'],
|
||||
];
|
||||
unset($t['setting']['mobile']['auto'],
|
||||
$t['setting']['mobile']['domain'],
|
||||
$t['setting']['seo']['SITE_REWRITE'],
|
||||
$t['setting']['seo']['SITE_SEOJOIN'],
|
||||
$t['setting']['config']['SITE_THEME'],
|
||||
$t['setting']['config']['SITE_TEMPLATE'],
|
||||
$t['setting']['config']['SITE_LANGUAGE'],
|
||||
$t['setting']['config']['SITE_TIME_FORMAT'],
|
||||
$t['setting']['config']['SITE_NAME'],
|
||||
$t['setting']['config']['SITE_TIMEZONE'],
|
||||
$t['setting']['config']['SITE_DOMAIN'],
|
||||
$t['setting']['config']['SITE_CLOSE']
|
||||
);
|
||||
// 本站的全部域名归属
|
||||
$site_domain[$t['domain']] = $t['id'];
|
||||
$sso_domain[] = $t['domain'];
|
||||
if ($config[$t['id']]['SITE_MOBILE']) {
|
||||
$site_domain[$config[$t['id']]['SITE_MOBILE']] = $t['id'];
|
||||
$client_domain[$t['domain']] = $config[$t['id']]['SITE_MOBILE'];
|
||||
$sso_domain[] = $config[$t['id']]['SITE_MOBILE'];
|
||||
}
|
||||
// 自定义终端
|
||||
if ($t['setting']['client']) {
|
||||
$_save = [];
|
||||
foreach ($t['setting']['client'] as $c) {
|
||||
$site_domain[$c['domain']] = $t['id'];
|
||||
$_save[$c['name']] = $sso_domain[] = $c['domain'];
|
||||
}
|
||||
$t['setting']['client'] = $_save;
|
||||
}
|
||||
|
||||
// 网站路径
|
||||
$webpath[$t['id']] = [
|
||||
'site' => ROOTPATH,
|
||||
];
|
||||
if ($t['id'] > 1 && $t['setting']['webpath']) {
|
||||
$webpath[$t['id']]['site'] = dr_get_dir_path($t['setting']['webpath']);
|
||||
if (!is_dir($webpath[$t['id']]['site'])) {
|
||||
log_message('error', '多站点:站点【'.$t['id'].'】目录【'.$webpath[$t['id']]['site'].'】不存在');
|
||||
//continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义站点字段
|
||||
$field = \Phpcmf\Service::M('field')->get_mysite_field($t['id']);
|
||||
if ($field && $t['setting']['param']) {
|
||||
$t['setting']['param'] = \Phpcmf\Service::L('Field')->app('')->format_value($field, $t['setting']['param'], 1);
|
||||
}
|
||||
|
||||
// 删除首页静态文件
|
||||
//unlink($webpath[$t['id']]['site'].'index.html');
|
||||
//unlink($webpath[$t['id']]['site'].$mobile_dirname.'/index.html');
|
||||
|
||||
$cache[$t['id']] = $t['setting'];
|
||||
}
|
||||
|
||||
list($webpath, $site_domain, $app_domain, $sso_domain, $client_domain) = \Phpcmf\Service::M('module', 'cms')->sync_site_cache(
|
||||
$module,
|
||||
$webpath,
|
||||
$site_domain,
|
||||
$app_domain,
|
||||
$sso_domain,
|
||||
$client_domain,
|
||||
[],
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Cache')->set_file('site', $cache);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/site.php', '站点配置文件', 32)->to_require($config);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/domain_sso.php', '同步域名配置文件', 32)->to_require_one($sso_domain);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/domain_app.php', '网站域名配置文件', 32)->to_require_one($app_domain);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/domain_site.php', '站点域名配置文件', 32)->to_require_one($site_domain);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/domain_client.php', '客户端域名配置文件', 32)->to_require_one($client_domain);
|
||||
\Phpcmf\Service::L('Config')->file(WRITEPATH.'config/webpath.php', '入口文件目录配置文件', 32)->to_require($webpath);
|
||||
}
|
||||
|
||||
|
||||
// 更新全部网站缓存
|
||||
public function update_site_cache() {
|
||||
|
||||
$site_cache = $this->table('site')->where('disabled', 0)->order_by('displayorder ASC,id ASC')->getAll();
|
||||
$module_cache = $this->table('module')->order_by('displayorder ASC,id ASC')->getAll();
|
||||
|
||||
// 按网站更新的缓存
|
||||
$cache = [];
|
||||
|
||||
if (is_file(MYPATH.'/Config/Cache.php')) {
|
||||
$_cache = require MYPATH.'/Config/Cache.php';
|
||||
$_cache && $cache = dr_array22array($cache, $_cache);
|
||||
}
|
||||
|
||||
// 执行插件自己的缓存程序
|
||||
$menu = \Phpcmf\Service::M('menu');
|
||||
$local = \Phpcmf\Service::Apps(1);
|
||||
$app_cache = [];
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file($path.'Config/Cache.php')) {
|
||||
$_cache = require $path.'Config/Cache.php';
|
||||
$_cache && $app_cache[$dir] = $_cache;
|
||||
}
|
||||
// 更新新增菜单
|
||||
if (method_exists($menu, 'update_app')) {
|
||||
$menu->update_app($dir);
|
||||
}
|
||||
}
|
||||
|
||||
$page = intval($_GET['page']);
|
||||
$tpage = dr_count($site_cache);
|
||||
|
||||
if (!$page) {
|
||||
// 全局系统缓存
|
||||
#dr_dir_delete(WRITEPATH.'data');
|
||||
\Phpcmf\Service::M('site')->cache(0, $site_cache, $module_cache);
|
||||
foreach (['auth', 'email', 'member', 'attachment', 'system'] as $m) {
|
||||
\Phpcmf\Service::M($m)->cache();
|
||||
}
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('正在缓存数据'), 1);
|
||||
}
|
||||
|
||||
$key = $page - 1;
|
||||
if (!isset($site_cache[$key])) {
|
||||
\Phpcmf\Service::M('menu')->cache();
|
||||
\Phpcmf\Service::M('cache')->update_data_cache();
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('更新完成'));
|
||||
}
|
||||
|
||||
foreach ([ $site_cache[$key] ] as $t) {
|
||||
|
||||
\Phpcmf\Service::M('table')->cache($t['id'], $module_cache);
|
||||
\Phpcmf\Service::M('module')->cache($t['id'], $module_cache);
|
||||
|
||||
foreach ($cache as $m => $namespace) {
|
||||
\Phpcmf\Service::M($m, $namespace)->cache($t['id']);
|
||||
}
|
||||
|
||||
// 插件缓存
|
||||
$apps = [];
|
||||
if ($app_cache) {
|
||||
foreach ($app_cache as $namespace => $c) {
|
||||
\Phpcmf\Service::C()->init_file($namespace);
|
||||
foreach ($c as $i => $apt) {
|
||||
$class = is_numeric($i) ? $apt : $i;
|
||||
$apps[] = '['.$namespace.'-'.$class.']';
|
||||
\Phpcmf\Service::M($class, $namespace)->cache($t['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
CI_DEBUG && \Phpcmf\Service::L('input')->system_log('更新[网站#'.$t['id'].']缓存: '.implode(' - ', $apps));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('正在更新中(%s/%s)', $page+1, $tpage), $page + 1);
|
||||
}
|
||||
|
||||
// 更新当前网站缓存
|
||||
public function update_cache() {
|
||||
|
||||
$site_cache = $this->table('site')->where('disabled', 0)->order_by('displayorder ASC,id ASC')->getAll();
|
||||
$module_cache = $this->table('module')->order_by('displayorder ASC,id ASC')->getAll();
|
||||
\Phpcmf\Service::M('site')->cache(0, $site_cache, $module_cache);
|
||||
|
||||
// 全局缓存
|
||||
foreach (['auth', 'email', 'member', 'attachment', 'system'] as $m) {
|
||||
\Phpcmf\Service::M($m)->cache();
|
||||
}
|
||||
|
||||
// 按网站更新的缓存
|
||||
$cache = [];
|
||||
|
||||
if (is_file(MYPATH.'/Config/Cache.php')) {
|
||||
$_cache = require MYPATH.'/Config/Cache.php';
|
||||
$_cache && $cache = dr_array22array($cache, $_cache);
|
||||
}
|
||||
|
||||
// 执行插件自己的缓存程序
|
||||
$menu = \Phpcmf\Service::M('menu');
|
||||
$local = \Phpcmf\Service::Apps(1);
|
||||
$app_cache = [];
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file($path.'Config/Cache.php')) {
|
||||
$_cache = require $path.'Config/Cache.php';
|
||||
$_cache && $app_cache[$dir] = $_cache;
|
||||
}
|
||||
// 更新新增菜单
|
||||
if (method_exists($menu, 'update_app')) {
|
||||
$menu->update_app($dir);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($site_cache as $t) {
|
||||
|
||||
if (!in_array($t['id'], [SITE_ID, 1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('table')->cache($t['id'], $module_cache);
|
||||
\Phpcmf\Service::M('module')->cache($t['id'], $module_cache);
|
||||
|
||||
if ($cache) {
|
||||
foreach ($cache as $m => $namespace) {
|
||||
$obj = \Phpcmf\Service::M($m, $namespace);
|
||||
if ($obj && method_exists($obj, 'cache')) {
|
||||
$obj->cache($t['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 插件缓存
|
||||
$apps = [];
|
||||
if ($app_cache) {
|
||||
foreach ($app_cache as $namespace => $c) {
|
||||
\Phpcmf\Service::C()->init_file($namespace);
|
||||
foreach ($c as $i => $apt) {
|
||||
$class = is_numeric($i) ? $apt : $i;
|
||||
$obj = \Phpcmf\Service::M($class, $namespace);
|
||||
if ($obj && method_exists($obj, 'cache')) {
|
||||
$apps[] = '['.$namespace.'-'.$class.']';
|
||||
$obj->cache($t['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
CI_DEBUG && \Phpcmf\Service::L('input')->system_log('更新[网站#'.$t['id'].']缓存: '.implode(' - ', $apps));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('menu')->cache();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 重建索引
|
||||
public function update_search_index() {
|
||||
|
||||
$site_cache = $this->table('site')->where('disabled', 0)->getAll();
|
||||
$module_cache = $this->table('module')->getAll();
|
||||
if (!$module_cache) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($site_cache as $t) {
|
||||
foreach ($module_cache as $m ) {
|
||||
$table = dr_module_table_prefix($m['dirname'], $t['id']);
|
||||
// 判断是否存在表
|
||||
if (!$this->db->tableExists($table)) {
|
||||
continue;
|
||||
}
|
||||
$this->db->table($table.'_search')->truncate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 重建子站配置文件
|
||||
public function update_site_config() {
|
||||
|
||||
$page = intval($_GET['page']);
|
||||
if (!$page) {
|
||||
$site_cache = $this->table('site')->where('disabled', 0)->getAll();
|
||||
foreach ($site_cache as $t) {
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
if ($t['id'] > 1 && $t['setting']['webpath']) {
|
||||
$rt = $this->update_webpath('Web', $t['setting']['webpath'], [
|
||||
'SITE_ID' => $t['id'],
|
||||
'FIX_WEB_DIR' => strpos($t['setting']['webpath'], '/') === false && strpos($t['domain'], $t['setting']['webpath']) !== false ? $t['setting']['webpath'] : '',
|
||||
'MOBILE_DIR' => $t['setting']['mobile']['mode'] == 1 ? $t['setting']['mobile']['dirname'] : '',
|
||||
]);
|
||||
if ($rt) {
|
||||
$this->_error_msg('网站['.$t['domain'].']: '.$rt);
|
||||
}
|
||||
$path = rtrim($t['setting']['webpath'], '/').'/';
|
||||
} else {
|
||||
$path = ROOTPATH;
|
||||
}
|
||||
if ($t['setting']['client'] && !dr_is_app('client')) {
|
||||
foreach ($t['setting']['client'] as $c) {
|
||||
if ($c['name'] && $c['domain']) {
|
||||
$rt = $this->update_webpath('Client', $path.$c['name'].'/', [
|
||||
'CLIENT' => $c['name'],
|
||||
'SITE_ID' => $t['id'],
|
||||
'FIX_WEB_DIR' => $c['domain'] == $t['domain'].'/'.$c['name'] ? $c['name'] : '',
|
||||
'SITE_FIX_WEB_DIR' => $t['setting']['webpath'] && strpos($t['setting']['webpath'], '/') === false && strpos($t['domain'], $t['setting']['webpath']) !== false ? $t['setting']['webpath'] : '',
|
||||
]);
|
||||
if ($rt) {
|
||||
$this->_error_msg('网站['.$t['domain'].']的终端['.$c['name'].']: '.$rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::L('cache')->set_auth_data('update_site_config', $this->table('module')->where('share', 0)->getAll());
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('正在准备更新'), 1);
|
||||
}
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get_auth_data('update_site_config');
|
||||
if (!$module) {
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('无可用更新'), 0);
|
||||
}
|
||||
|
||||
$key = $page - 1;
|
||||
if (!isset($module[$key])) {
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('更新完成'), 0);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('module', 'cms')->update_site_config($module[$key]);
|
||||
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('正在更新中(%s)', $page), $page + 1);
|
||||
}
|
||||
|
||||
// 生成目录式手机目录
|
||||
public function update_mobile_webpath($path, $dirname) {
|
||||
|
||||
foreach (['api.php', 'index.php'] as $file) {
|
||||
if (is_file(IS_USE_MODULE.'Temps/Web/mobile/'.$file)) {
|
||||
$dst = $path.$dirname.'/'.$file;
|
||||
dr_mkdirs(dirname($dst));
|
||||
$size = file_put_contents($dst, str_replace([
|
||||
'{FIX_WEB_DIR}'
|
||||
], [
|
||||
(defined('FIX_WEB_DIR') && FIX_WEB_DIR ? FIX_WEB_DIR.'/' : '').$dirname
|
||||
], file_get_contents(IS_USE_MODULE.'Temps/Web/mobile/'.$file)));
|
||||
if (!$size) {
|
||||
return '文件['.$dst.']无法写入';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新网站
|
||||
public function update_webpath($name, $path, $value, $root = IS_USE_MODULE.'Temps/') {
|
||||
|
||||
if (!$path) {
|
||||
return '目录为空';
|
||||
} elseif (strpos($path, ' ') === 0) {
|
||||
return '不能用空格开头';
|
||||
}
|
||||
|
||||
$path = dr_get_dir_path($path);
|
||||
if (!$path) {
|
||||
return '目录为空';
|
||||
}
|
||||
|
||||
dr_mkdirs($path);
|
||||
if (!is_dir($path)) {
|
||||
return '目录['.$path.']不存在';
|
||||
}
|
||||
|
||||
// 创建入口文件
|
||||
//(defined('FIX_WEB_DIR') && FIX_WEB_DIR ? FIX_WEB_DIR.'/' : '').
|
||||
|
||||
foreach ([
|
||||
'admin.php',
|
||||
'index.php',
|
||||
'api.php',
|
||||
'mobile/api.php',
|
||||
'mobile/index.php',
|
||||
] as $file) {
|
||||
if (is_file($root.$name.'/'.$file)) {
|
||||
if ($file == 'admin.php') {
|
||||
$dst = $path.(SELF == 'index.php' ? 'admin.php' : SELF);
|
||||
} else {
|
||||
$dst = $path.$file;
|
||||
}
|
||||
$fix_web_dir = isset($value['FIX_WEB_DIR']) && $value['FIX_WEB_DIR'] ? $value['FIX_WEB_DIR'] : '';
|
||||
if (isset($value['SITE_ID']) && $value['SITE_ID'] > 1) {
|
||||
if (strpos($file, 'mobile') !== false
|
||||
&& isset($value['MOBILE_DIR']) && $value['MOBILE_DIR']) {
|
||||
$fix_web_dir.= '/'.$value['MOBILE_DIR'];
|
||||
} elseif ($fix_web_dir) {
|
||||
// 移动端加二级
|
||||
if (strpos($file, 'mobile/') !== false) {
|
||||
$fix_web_dir.= '/mobile';
|
||||
}
|
||||
// 终端加二级
|
||||
if ( $name == 'Client') {
|
||||
$fix_web_dir= (isset($value['SITE_FIX_WEB_DIR']) && $value['SITE_FIX_WEB_DIR'] ? $value['SITE_FIX_WEB_DIR'].'/' : '').$fix_web_dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
dr_mkdirs(dirname($dst));
|
||||
$size = file_put_contents($dst, str_replace([
|
||||
'{CLIENT}',
|
||||
'{ROOTPATH}',
|
||||
'{MOD_DIR}',
|
||||
'{SITE_ID}',
|
||||
'{FIX_WEB_DIR}'
|
||||
], [
|
||||
$value['CLIENT'],
|
||||
ROOTPATH,
|
||||
$value['MOD_DIR'],
|
||||
$value['SITE_ID'],
|
||||
trim($fix_web_dir, '/')
|
||||
], file_get_contents($root.$name.'/'.$file)));
|
||||
if (!$size) {
|
||||
return '文件['.$dst.']无法写入';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 复制百度编辑器到当前目录
|
||||
//$this->cp_ueditor_file($path);
|
||||
|
||||
// 复制百度编辑器到移动端网站
|
||||
//if (is_dir($path.'mobile')) {
|
||||
//$this->cp_ueditor_file($path.'mobile/');
|
||||
//}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// 错误输出
|
||||
public function _error_msg($msg) {
|
||||
echo dr_array2string(dr_return_data(0, $msg));exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
// 模型类
|
||||
|
||||
class Urlrule extends \Phpcmf\Model {
|
||||
|
||||
// 缓存
|
||||
public function cache($site = SITE_ID) {
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php namespace Phpcmf\Model\Cms;
|
||||
/**
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
// 审核类
|
||||
class Verify extends \Phpcmf\Model {
|
||||
|
||||
// 验证是否具有审核状态
|
||||
public function _get_verify_status_edit($vid, $status) {
|
||||
|
||||
if (dr_in_array(1, $this->admin['roleid'])) {
|
||||
return 1; // 超管用户
|
||||
} elseif ($status == 0) {
|
||||
return 1; // 退稿的可以看到
|
||||
} elseif (\Phpcmf\Service::M('auth')->is_post_user()) {
|
||||
return 0; // 投稿者不允许编辑审核
|
||||
}
|
||||
|
||||
if (!IS_USE_MEMBER) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$verify = \Phpcmf\Service::C()->get_cache('verify');
|
||||
if (!$verify) {
|
||||
return 0; // 没有审核流程时
|
||||
}
|
||||
|
||||
$my = [];
|
||||
foreach ($verify as $t) {
|
||||
if ($t['value']['role']) {
|
||||
$rid = [];
|
||||
foreach ($t['value']['role'] as $c) {
|
||||
if (is_array($c)) {
|
||||
$rid = array_merge($rid, $c);
|
||||
} elseif (is_numeric($c)) {
|
||||
$rid[] = $c;
|
||||
}
|
||||
}
|
||||
if (dr_array_intersect($rid, $this->admin['roleid'])) {
|
||||
$my[] = $t['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my) {
|
||||
// 此管理员没有管理权限
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 有权限了
|
||||
if (dr_in_array($vid, $my)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取当前栏目的时候流程
|
||||
public function _get_verify($vid) {
|
||||
|
||||
$rt = [];
|
||||
$cache = \Phpcmf\Service::C()->get_cache('verify');
|
||||
if ($cache && $vid && $cache[$vid]) {
|
||||
$verify = $cache[$vid];
|
||||
if ($verify['value']['role']) {
|
||||
$role = \Phpcmf\Service::C()->get_cache('auth');
|
||||
foreach ($verify['value']['role'] as $id => $rid) {
|
||||
if (!is_array($rid)) {
|
||||
if (isset($role[$rid]) && $role[$rid]) {
|
||||
$rt[$id] = [
|
||||
'rid' => $rid,
|
||||
'name' => dr_lang($role[$rid]['name'] ? $role[$rid]['name'] : '管理员'),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$ns = [];
|
||||
foreach ($rid as $r) {
|
||||
if (isset($role[$r]) && $role[$r]) {
|
||||
$ns[] = dr_lang($role[$r]['name'] ? $role[$r]['name'] : '管理员');
|
||||
}
|
||||
}
|
||||
if ($ns) {
|
||||
$ns = array_unique($ns);
|
||||
$rt[$id] = [
|
||||
'rid' => $r,
|
||||
'name' => implode('、', $ns),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rt[9] = [
|
||||
'name' => dr_lang('完成'),
|
||||
];
|
||||
|
||||
return $rt;
|
||||
}
|
||||
|
||||
// 审核时候的权限组,返回可用权限组的id
|
||||
// array(
|
||||
// * to_uid 指定人
|
||||
// * to_rid 指定角色组
|
||||
// * )
|
||||
public function _get_verify_roleid($catid, $status, $member) {
|
||||
|
||||
$verify = \Phpcmf\Service::C()->get_cache('verify');
|
||||
if (!$verify) {
|
||||
return ['to_uid' => 0, 'to_rid' => 0, 'verify_id' => 0];
|
||||
}
|
||||
|
||||
if (IS_MEMBER) {
|
||||
// 前端找用户设置
|
||||
$auth = \Phpcmf\Service::M('member_auth', 'cms')->category_auth(\Phpcmf\Service::C()->module, $catid, 'verify', $member);
|
||||
} else {
|
||||
// 后台投稿者
|
||||
$auth = \Phpcmf\Service::M('auth')->is_post_user_status();
|
||||
}
|
||||
|
||||
if ($auth && isset($verify[$auth]) && $verify[$auth]) {
|
||||
$v = $verify[$auth];
|
||||
$status = max(1, $status);
|
||||
if (isset($v['value']['role'][$status]) && $v['value']['role'][$status]) {
|
||||
if (is_array($v['value']['role'][$status])) {
|
||||
return ['to_uid' => 0, 'to_rid' => implode(',', $v['value']['role'][$status]), 'verify_id' => $v['id']];
|
||||
} else {
|
||||
return ['to_uid' => 0, 'to_rid' => $v['value']['role'][$status], 'verify_id' => $v['id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['to_uid' => 0, 'to_rid' => 0, 'verify_id' => 0];
|
||||
}
|
||||
|
||||
// 后台内容审核列表的权限的sql语句
|
||||
public function get_admin_verify_status_list() {
|
||||
|
||||
if (dr_in_array(1, \Phpcmf\Service::C()->admin['roleid'])) {
|
||||
return '`status`>=0'; // 超管用户
|
||||
} elseif (!IS_USE_MEMBER && !\Phpcmf\Service::M('auth')->is_post_user()) {
|
||||
return '`status`>=0'; // 普通管理员
|
||||
}
|
||||
|
||||
$verify = \Phpcmf\Service::C()->get_cache('verify');
|
||||
if (!$verify) {
|
||||
return '`status`=0'; // 没有审核流程时
|
||||
}
|
||||
|
||||
$where = [];
|
||||
foreach ($verify as $t) {
|
||||
if ($t['value']['role']) {
|
||||
foreach ($t['value']['role'] as $status => $rid) {
|
||||
if (is_array($rid)) {
|
||||
if (dr_array_intersect($rid, \Phpcmf\Service::C()->admin['roleid'])) {
|
||||
$where[] = '(`status`='.$status.' and `vid`='.$t['id'].')';
|
||||
}
|
||||
} else {
|
||||
if (dr_in_array($rid, \Phpcmf\Service::C()->admin['roleid'])) {
|
||||
$where[] = '(`status`='.$status.' and `vid`='.$t['id'].')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 此管理员没有管理权限
|
||||
if (!$where) {
|
||||
return 'status=0';
|
||||
}
|
||||
|
||||
return '`status` = 0 OR '.implode(' OR ', $where);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user