Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 审核流程
|
||||
class Admin_verify extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public $role;
|
||||
public $type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'审核流程' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-sort-numeric-asc'],
|
||||
'添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
|
||||
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
'help' => ['825'],
|
||||
]
|
||||
),
|
||||
'is_vip' => is_file(IS_USE_MODULE.'/Models/Verify.php'),
|
||||
]);
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
$this->my_field = array(
|
||||
'name' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('名称'),
|
||||
'fieldname' => 'name',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// url显示名称
|
||||
$this->name = dr_lang('审核流程');
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'admin_verify',
|
||||
'field' => $this->my_field,
|
||||
'order_by' => 'id desc',
|
||||
]);
|
||||
$this->role = \Phpcmf\Service::M('Auth')->get_role_all();
|
||||
}
|
||||
|
||||
// 后台查看url列表
|
||||
public function index() {
|
||||
|
||||
$this->_List([], -1);
|
||||
\Phpcmf\Service::V()->display('verify_index.html');
|
||||
}
|
||||
|
||||
// 后台添加url内容
|
||||
public function add() {
|
||||
$this->_Post(0);
|
||||
\Phpcmf\Service::V()->display('verify_add.html');
|
||||
}
|
||||
|
||||
// 后台修改url内容
|
||||
public function edit() {
|
||||
$this->_Post(intval(\Phpcmf\Service::L('input')->get('id')));
|
||||
\Phpcmf\Service::V()->display('verify_add.html');
|
||||
}
|
||||
|
||||
// 复制
|
||||
public function copy_edit() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$data = \Phpcmf\Service::M()->db->table('admin_verify')->where('id', $id)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
unset($data['id']);
|
||||
$data['name'].= '_copy';
|
||||
|
||||
$rt = \Phpcmf\Service::M()->table('admin_verify')->insert($data);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, dr_lang($rt['msg']));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('复制成功'));
|
||||
}
|
||||
|
||||
|
||||
// 保存
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
return parent::_Save($id, $data, $old, function($id, $data){
|
||||
// 保存前的格式化
|
||||
$value = \Phpcmf\Service::L('input')->post('value');
|
||||
if ($value['role']) {
|
||||
foreach ($value['role'] as $i => $ids) {
|
||||
if (!$ids) {
|
||||
unset($value['role'][$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$data[1]['verify'] = dr_array2string($value);
|
||||
return dr_return_data(1, 'ok', $data);
|
||||
}, function ($id, $data, $old) {
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
|
||||
$data = parent::_Data($id);
|
||||
$data['value'] = dr_string2array($data['verify']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 后台删除url内容
|
||||
public function del() {
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('input')->get_post_ids(),
|
||||
null,
|
||||
function ($r) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Api extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function __construct($object = NULL)
|
||||
{
|
||||
parent::__construct();
|
||||
if ($object) {
|
||||
foreach ($object as $var => $value) {
|
||||
$this->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 统计
|
||||
public function mtotal() {
|
||||
|
||||
$t1 = $t2 = $t3 = $t4 = $t5 = 0;
|
||||
$dir = dr_safe_filename(\Phpcmf\Service::L('input')->get('dir'));
|
||||
$prefix = dr_module_table_prefix($dir);
|
||||
if (is_dir(dr_get_app_dir($dir))) {
|
||||
$this->_module_init($dir);
|
||||
$t1 = \Phpcmf\Service::M()->table($prefix)->where($this->content_model->get_admin_list_where($prefix))->where('DATEDIFF(from_unixtime(inputtime),now())=0')->counts();
|
||||
$t2 = \Phpcmf\Service::M()->table($prefix)->where($this->content_model->get_admin_list_where($prefix))->counts();
|
||||
$t3 = \Phpcmf\Service::M()->table($prefix.'_verify')->where($this->content_model->get_admin_list_verify_where($this->content_model->get_admin_list_where($prefix.'_verify')))->counts();
|
||||
$t4 = \Phpcmf\Service::M()->table($prefix.'_recycle')->where($this->content_model->get_admin_list_where($prefix.'_recycle'))->counts();
|
||||
$t5 = \Phpcmf\Service::M()->table($prefix.'_time')->where($this->content_model->get_admin_list_where($prefix.'_time'))->counts();
|
||||
}
|
||||
echo '$("#'.$dir.'_today").html('.$t1.');';
|
||||
echo '$("#'.$dir.'_all").html('.$t2.');';
|
||||
echo '$("#'.$dir.'_verify").html('.$t3.');';
|
||||
echo '$("#'.$dir.'_recycle").html('.$t4.');';
|
||||
echo '$("#'.$dir.'_timing").html('.$t5.');';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 更新url
|
||||
public function update_url() {
|
||||
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
if (!$mid) {
|
||||
$this->_html_msg(0, dr_lang('mid参数不能为空'));
|
||||
}
|
||||
|
||||
$this->_module_init($mid);
|
||||
|
||||
$page = (int)\Phpcmf\Service::L('input')->get('page');
|
||||
$total = (int)\Phpcmf\Service::L('input')->get('total');
|
||||
|
||||
if (!$page) {
|
||||
// 计算数量
|
||||
$total = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->countAllResults();
|
||||
if (!$total) {
|
||||
$this->_html_msg(0, dr_lang('无可用内容更新'));
|
||||
}
|
||||
|
||||
$url = dr_url('module/api/'.\Phpcmf\Service::L('Router')->method, ['mid' => $mid]);
|
||||
$this->_html_msg(1, dr_lang('正在执行中...'), $url.'&total='.$total.'&page='.($page+1));
|
||||
}
|
||||
|
||||
$psize = 300; // 每页处理的数量
|
||||
if (isset($this->module['setting']['update_psize'])) {
|
||||
$psize = max((int)$this->module['setting']['update_psize'], 100);
|
||||
}
|
||||
|
||||
$tpage = ceil($total / $psize); // 总页数
|
||||
|
||||
// 更新完成
|
||||
if ($page > $tpage) {
|
||||
\Phpcmf\Service::M('cache')->update_data_cache();
|
||||
$this->_html_msg(1, dr_lang('更新完成'));
|
||||
}
|
||||
|
||||
$update = [];
|
||||
$data = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->limit($psize, $psize * ($page - 1))->orderBy('id DESC')->get()->getResultArray();
|
||||
foreach ($data as $t) {
|
||||
if ($t['link_id'] && $t['link_id'] >= 0) {
|
||||
// 同步栏目的数据
|
||||
$i = $t['id'];
|
||||
$t = \Phpcmf\Service::M()->db->table($this->content_model->mytable)->where('id', (int)$t['link_id'])->get()->getRowArray();
|
||||
if (!$t) {
|
||||
continue;
|
||||
}
|
||||
$url = \Phpcmf\Service::L('Router')->show_url($this->module, $t);
|
||||
$t['id'] = $i; // 替换成当前id
|
||||
} else {
|
||||
$url = \Phpcmf\Service::L('Router')->show_url($this->module, $t);
|
||||
}
|
||||
$t['url'] != $url && $update[] = [
|
||||
'id' => (int)$t['id'],
|
||||
'url'=> $url,
|
||||
];
|
||||
}
|
||||
$update && \Phpcmf\Service::M()->table($this->content_model->mytable)->update_batch($update);
|
||||
|
||||
$this->_html_msg( 1, dr_lang('正在执行中【%s】...', "$tpage/$page"),
|
||||
dr_url('module/api/'.\Phpcmf\Service::L('Router')->method, ['mid' => $mid,'total' => $total, 'page' => $page + 1])
|
||||
);
|
||||
}
|
||||
|
||||
// 统计栏目
|
||||
public function ctotal() {
|
||||
|
||||
$rt = '';
|
||||
if (IS_POST) {
|
||||
$ids = dr_string2array(\Phpcmf\Service::L('input')->post('cid'));
|
||||
if ($ids) {
|
||||
foreach ($ids as $t) {
|
||||
list($id, $mid) = explode('-', $t);
|
||||
if ($id && $mid && dr_is_module($mid) ) {
|
||||
$db = \Phpcmf\Service::M()->table(dr_module_table_prefix($mid).'_index');
|
||||
$mod = $this->get_cache('module-'.SITE_ID.'-'.$mid);
|
||||
if ($mod['category'][$id]['childids']) {
|
||||
$db->where('catid in ('.$mod['category'][$id]['childids'].')');
|
||||
} else {
|
||||
$db->where('catid', $id);
|
||||
}
|
||||
$num = $db->where('status=9')->counts();
|
||||
if ($num) {
|
||||
$rt.= '$(".cat-total-'.$id.'").html("'.dr_lang('(约%s)', $num).'");';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_json(1, $rt);
|
||||
}
|
||||
|
||||
// 更新栏目缓存配置
|
||||
public function update_category_repair() {
|
||||
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
if (!$mid) {
|
||||
$cdir = 'share';
|
||||
} else {
|
||||
$cdir = $mid;
|
||||
}
|
||||
if (\Phpcmf\Service::M()->table(SITE_ID.'_'.$cdir.'_category')->counts() > MAX_CATEGORY) {
|
||||
\Phpcmf\Service::M('module')->update_category_cache(SITE_ID, $cdir);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache();
|
||||
|
||||
$this->_html_msg(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
public function update_category_cache() {
|
||||
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
if (!$mid) {
|
||||
$cdir = 'share';
|
||||
} else {
|
||||
$cdir = $mid;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('module')->update_category_cache(SITE_ID, $cdir);
|
||||
\Phpcmf\Service::M('cache')->sync_cache();
|
||||
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-'.$cdir.'-child');
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-'.$cdir.'-data');
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-'.$cdir.'-min');
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-'.$cdir.'-main');
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-'.$cdir.'-select');
|
||||
dr_dir_delete(WRITEPATH.'module/category-'.SITE_ID.'-share-select');
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
// 查看审核流程
|
||||
public function verify() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$id) {
|
||||
$this->_json(0, dr_lang('审核流程id不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('admin_verify')->where('id', $id)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'role' => \Phpcmf\Service::M('Auth')->get_role_all(),
|
||||
'value' => dr_string2array($data['verify']),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('verify_show.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,981 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
/**
|
||||
* 内容权限设置(模块 / 栏目)
|
||||
* 用户侧权限仍在 Member 插件 member/auth
|
||||
*/
|
||||
class Auth extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if (!IS_USE_MEMBER) {
|
||||
$this->_admin_msg(0, dr_lang('未安装用户系统,无法设置内容权限'));
|
||||
}
|
||||
}
|
||||
|
||||
// 当前可配置的内容模块
|
||||
protected function _content_modules() {
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
if (!$module) {
|
||||
return [];
|
||||
}
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($t['hlist'] == 1) {
|
||||
unset($module[$dir]);
|
||||
}
|
||||
}
|
||||
return $module;
|
||||
}
|
||||
|
||||
// 构建用户组 / 等级列
|
||||
protected function _auth_columns($auth_type) {
|
||||
|
||||
$group = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$group[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => dr_lang($t['name']),
|
||||
'use' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
$level = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
'group_name' => '',
|
||||
'level_name' => dr_lang('游客'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$gname = dr_lang($t['name']);
|
||||
$level[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => $gname,
|
||||
'group_name' => '',
|
||||
'level_name' => $gname,
|
||||
'use' => 1,
|
||||
];
|
||||
if ($t['level']) {
|
||||
foreach ($t['level'] as $lv) {
|
||||
$lname = dr_lang($lv['name']);
|
||||
$level[$t['id'].'-'.$lv['id']] = [
|
||||
'id' => $t['id'].'-'.$lv['id'],
|
||||
'name' => $gname.' / '.$lname,
|
||||
'group_name' => $gname,
|
||||
'level_name' => $lname,
|
||||
'use' => 1,
|
||||
];
|
||||
$level[$t['id']]['use'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($auth_type == 1) {
|
||||
return $group;
|
||||
}
|
||||
if ($auth_type == 2) {
|
||||
$columns = [];
|
||||
foreach ($level as $i => $t) {
|
||||
if ($t['use']) {
|
||||
$columns[$i] = $t;
|
||||
}
|
||||
}
|
||||
return $columns;
|
||||
}
|
||||
return [
|
||||
'public' => [
|
||||
'id' => 'public',
|
||||
'name' => dr_lang('全局'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
protected function _get_auth_row($auth_data, $aid) {
|
||||
$key = (string)$aid;
|
||||
if (isset($auth_data[$aid]) && is_array($auth_data[$aid])) {
|
||||
return $auth_data[$aid];
|
||||
}
|
||||
if (isset($auth_data[$key]) && is_array($auth_data[$key])) {
|
||||
return $auth_data[$key];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function _get_post_row($post, $aid) {
|
||||
$key = (string)$aid;
|
||||
if (isset($post[$aid]) && is_array($post[$aid])) {
|
||||
return $post[$aid];
|
||||
}
|
||||
if (isset($post[$key]) && is_array($post[$key])) {
|
||||
return $post[$key];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// 未勾选的 checkbox 不会出现在 POST 中,显式写成 0,避免关闭验证码等无效
|
||||
protected function _normalize_category_auth_flags($auth) {
|
||||
if (!is_array($auth)) {
|
||||
$auth = [];
|
||||
}
|
||||
foreach (['show', 'add', 'edit', 'del', 'code'] as $f) {
|
||||
$auth[$f] = empty($auth[$f]) ? 0 : 1;
|
||||
}
|
||||
return $auth;
|
||||
}
|
||||
|
||||
// 表头:用户组 / 等级列
|
||||
protected function _auth_thead_html($columns) {
|
||||
$html = '<th class="fc-auth-name">'.dr_lang('权限项').'</th>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
if ($key === '0') {
|
||||
$title = '<span class="font-red">'.htmlspecialchars((string)$col['name']).'</span>';
|
||||
} elseif (!empty($col['group_name'])) {
|
||||
$title = '<span class="fc-auth-gname">'.htmlspecialchars((string)$col['group_name']).'</span>'
|
||||
.'<span class="fc-auth-lname">'.htmlspecialchars((string)$col['level_name']).'</span>';
|
||||
} else {
|
||||
$title = htmlspecialchars((string)$col['name']);
|
||||
}
|
||||
$html .= '<th class="fc-auth-col">'.$title.'</th>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function _auth_form_switch($label, $input_name, $checked, $help = '') {
|
||||
$html = '<div class="form-group">'
|
||||
.'<label class="col-md-2 control-label">'.$label.'</label>'
|
||||
.'<div class="col-md-9">'
|
||||
.'<input type="checkbox" name="'.$input_name.'" value="1"'
|
||||
.($checked ? ' checked' : '')
|
||||
.' data-on-text="'.dr_lang('禁止').'" data-off-text="'.dr_lang('开放').'"'
|
||||
.' data-on-color="danger" data-off-color="success" class="make-switch" data-size="small">';
|
||||
if ($help) {
|
||||
$html .= '<span class="help-block">'.$help.'</span>';
|
||||
}
|
||||
$html .= '</div></div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function _auth_matrix_wrap($thead, $tbody) {
|
||||
return '<div class="table-scrollable fc-auth-wrap">'
|
||||
.'<table class="table table-striped table-bordered table-hover fc-auth-table">'
|
||||
.'<thead><tr class="heading">'.$thead.'</tr></thead>'
|
||||
.'<tbody>'.$tbody.'</tbody>'
|
||||
.'</table></div>';
|
||||
}
|
||||
|
||||
// 栏目权限弹窗按钮
|
||||
protected function _auth_category_btn($aid, $page, $title, $btn_class = 'btn blue btn-xs', $btn_text = '') {
|
||||
$url = dr_url('cms/auth/add', ['aid' => $aid, 'page' => $page]);
|
||||
$js_title = str_replace(["\\", "'"], ["\\\\", "\\'"], (string)$title);
|
||||
if ($btn_text === '') {
|
||||
$btn_text = dr_lang('设置');
|
||||
}
|
||||
return '<button type="button" class="'.$btn_class.'" onclick="dr_iframe_show(\''.$js_title.'\', \''.$url.'\', \'85%\', \'90%\')">'
|
||||
.'<i class="fa fa-cog"></i> '.$btn_text
|
||||
.'</button>';
|
||||
}
|
||||
|
||||
// 栏目权限入口(全局表单)
|
||||
protected function _auth_category_form($columns, $page = 'cms') {
|
||||
$aid = 'public';
|
||||
$name = dr_lang('全局');
|
||||
foreach ($columns as $k => $col) {
|
||||
$aid = (string)$k;
|
||||
$name = (string)$col['name'];
|
||||
break;
|
||||
}
|
||||
return '<div class="form-group">'
|
||||
.'<label class="col-md-2 control-label">'.dr_lang('栏目权限').'</label>'
|
||||
.'<div class="col-md-9">'
|
||||
.$this->_auth_category_btn($aid, $page, dr_lang('[%s]栏目权限', $name), 'btn blue btn-sm', dr_lang('设置栏目发布/审核等权限'))
|
||||
.'<span class="help-block">'.dr_lang('访问、发布、修改、删除及投稿限制等').'</span>'
|
||||
.'</div></div>';
|
||||
}
|
||||
|
||||
// 栏目权限矩阵行
|
||||
protected function _auth_category_row($columns, $page = 'cms') {
|
||||
$html = '<tr><td class="fc-auth-name">'.dr_lang('栏目权限').'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$html .= '<td class="fc-auth-col">'
|
||||
.$this->_auth_category_btn($key, $page, dr_lang('[%s]栏目权限', $col['name']))
|
||||
.'</td>';
|
||||
}
|
||||
$html .= '</tr>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth_type')->get()->getRowArray();
|
||||
$auth_type = intval($v['value']);
|
||||
$columns = $this->_auth_columns($auth_type);
|
||||
$modules = $this->_content_modules();
|
||||
|
||||
$row = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$value = $row ? dr_string2array($row['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$auth_data = isset($value[SITE_ID]) && is_array($value[SITE_ID]) ? $value[SITE_ID] : [];
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!is_array($post)) {
|
||||
$post = [];
|
||||
}
|
||||
|
||||
foreach ($columns as $aid => $col) {
|
||||
$old = $this->_get_auth_row($auth_data, $aid);
|
||||
$post_row = $this->_get_post_row($post, $aid);
|
||||
|
||||
$home = isset($old['home']) && is_array($old['home']) ? $old['home'] : [];
|
||||
$home['show'] = empty($post_row['home']['show']) ? 0 : 1;
|
||||
$old['home'] = $home;
|
||||
|
||||
$mod = isset($old['module']) && is_array($old['module']) ? $old['module'] : [];
|
||||
foreach ($modules as $mid => $m) {
|
||||
if (!isset($mod[$mid]) || !is_array($mod[$mid])) {
|
||||
$mod[$mid] = [];
|
||||
}
|
||||
$mod[$mid]['show'] = empty($post_row['module'][$mid]['show']) ? 0 : 1;
|
||||
$mod[$mid]['search'] = empty($post_row['module'][$mid]['search']) ? 0 : 1;
|
||||
}
|
||||
$old['module'] = $mod;
|
||||
|
||||
$auth_data[$aid] = $old;
|
||||
}
|
||||
|
||||
$value[SITE_ID] = $auth_data;
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$is_single = dr_count($columns) <= 1;
|
||||
$page = \Phpcmf\Service::L('input')->get('page');
|
||||
if (!$page) {
|
||||
$page = 'site';
|
||||
}
|
||||
if ($page !== 'site' && !isset($modules[$page])) {
|
||||
$page = 'site';
|
||||
}
|
||||
|
||||
$tabs = [];
|
||||
|
||||
// —— 整站 ——
|
||||
$site_html = '';
|
||||
if ($is_single) {
|
||||
$aid = 'public';
|
||||
foreach ($columns as $k => $col) {
|
||||
$aid = (string)$k;
|
||||
break;
|
||||
}
|
||||
$data = $this->_get_auth_row($auth_data, $aid);
|
||||
$aid_attr = htmlspecialchars($aid);
|
||||
$site_html .= $this->_auth_form_switch(
|
||||
dr_lang('禁止整站访问'),
|
||||
'data['.$aid_attr.'][home][show]',
|
||||
!empty($data['home']['show']),
|
||||
dr_lang('针对整个网站的前端界面访问权限')
|
||||
);
|
||||
$site_html .= $this->_auth_category_form($columns, 'cms');
|
||||
} else {
|
||||
$tbody = '<tr><td class="fc-auth-name">'.dr_lang('禁止整站访问').'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$data = $this->_get_auth_row($auth_data, $aid);
|
||||
$checked = !empty($data['home']['show']) ? ' checked' : '';
|
||||
$tbody .= '<td class="fc-auth-col">'
|
||||
.'<input type="checkbox" class="fc-auth-check" name="data['.htmlspecialchars($key).'][home][show]" value="1"'.$checked.' />'
|
||||
.'</td>';
|
||||
}
|
||||
$tbody .= '</tr>';
|
||||
$tbody .= $this->_auth_category_row($columns, 'cms');
|
||||
$site_html .= $this->_auth_matrix_wrap($this->_auth_thead_html($columns), $tbody);
|
||||
}
|
||||
$tabs['site'] = [
|
||||
'id' => 'site',
|
||||
'name' => dr_lang('整站'),
|
||||
'dirname' => '',
|
||||
'icon' => 'fa fa-globe',
|
||||
'html' => $site_html,
|
||||
];
|
||||
|
||||
// —— 各内容模块 ——
|
||||
foreach ($modules as $mid => $m) {
|
||||
$mname = dr_lang($m['name']);
|
||||
$icon = !empty($m['icon']) ? $m['icon'] : 'fa fa-folder';
|
||||
$mod_html = '';
|
||||
if ($is_single) {
|
||||
$aid = 'public';
|
||||
foreach ($columns as $k => $col) {
|
||||
$aid = (string)$k;
|
||||
break;
|
||||
}
|
||||
$data = $this->_get_auth_row($auth_data, $aid);
|
||||
$aid_attr = htmlspecialchars($aid);
|
||||
$mid_attr = htmlspecialchars($mid);
|
||||
$mod_html .= $this->_auth_form_switch(
|
||||
dr_lang('禁止访问'),
|
||||
'data['.$aid_attr.'][module]['.$mid_attr.'][show]',
|
||||
!empty($data['module'][$mid]['show']),
|
||||
dr_lang('禁止后无法访问本模块前台')
|
||||
);
|
||||
$mod_html .= $this->_auth_form_switch(
|
||||
dr_lang('禁止搜索'),
|
||||
'data['.$aid_attr.'][module]['.$mid_attr.'][search]',
|
||||
!empty($data['module'][$mid]['search']),
|
||||
dr_lang('禁止后无法使用本模块搜索')
|
||||
);
|
||||
if (empty($m['share'])) {
|
||||
$mod_html .= $this->_auth_category_form($columns, $mid);
|
||||
} else {
|
||||
$mod_html .= '<div class="form-group"><label class="col-md-2 control-label">'.dr_lang('栏目权限').'</label>'
|
||||
.'<div class="col-md-9"><span class="help-block" style="margin-top:8px;">'
|
||||
.dr_lang('本模块使用共享栏目,请到「整站」中设置栏目权限')
|
||||
.'</span></div></div>';
|
||||
}
|
||||
} else {
|
||||
$tbody = '';
|
||||
$tbody .= '<tr><td class="fc-auth-name">'.dr_lang('禁止访问').'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$data = $this->_get_auth_row($auth_data, $aid);
|
||||
$checked = !empty($data['module'][$mid]['show']) ? ' checked' : '';
|
||||
$tbody .= '<td class="fc-auth-col">'
|
||||
.'<input type="checkbox" class="fc-auth-check" name="data['.htmlspecialchars($key).'][module]['.htmlspecialchars($mid).'][show]" value="1"'.$checked.' />'
|
||||
.'</td>';
|
||||
}
|
||||
$tbody .= '</tr>';
|
||||
$tbody .= '<tr><td class="fc-auth-name">'.dr_lang('禁止搜索').'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$data = $this->_get_auth_row($auth_data, $aid);
|
||||
$checked = !empty($data['module'][$mid]['search']) ? ' checked' : '';
|
||||
$tbody .= '<td class="fc-auth-col">'
|
||||
.'<input type="checkbox" class="fc-auth-check" name="data['.htmlspecialchars($key).'][module]['.htmlspecialchars($mid).'][search]" value="1"'.$checked.' />'
|
||||
.'</td>';
|
||||
}
|
||||
$tbody .= '</tr>';
|
||||
if (empty($m['share'])) {
|
||||
$tbody .= $this->_auth_category_row($columns, $mid);
|
||||
}
|
||||
$mod_html .= $this->_auth_matrix_wrap($this->_auth_thead_html($columns), $tbody);
|
||||
if (!empty($m['share'])) {
|
||||
$mod_html .= '<p class="help-block" style="margin-top:12px;">'
|
||||
.dr_lang('本模块使用共享栏目,请到「整站」中设置栏目权限')
|
||||
.'</p>';
|
||||
}
|
||||
}
|
||||
$tabs[$mid] = [
|
||||
'id' => $mid,
|
||||
'name' => $mname,
|
||||
'dirname' => $mid,
|
||||
'icon' => $icon,
|
||||
'html' => $mod_html,
|
||||
];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'内容权限' => ['cms/auth/index', 'fa fa-table'],
|
||||
'help' => [801],
|
||||
]
|
||||
),
|
||||
'auth_type' => $auth_type,
|
||||
'page' => $page,
|
||||
'tabs' => $tabs,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_index.html');
|
||||
}
|
||||
|
||||
// 存储模式值
|
||||
public function save_edit() {
|
||||
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
if (!$value) {
|
||||
$msg = dr_lang('已切换至按全局配置模式');
|
||||
} elseif ($value == 1) {
|
||||
$msg = dr_lang('已切换至按用户组配置模式');
|
||||
} elseif ($value == 2) {
|
||||
$msg = dr_lang('已切换至按用户组等级配置模式');
|
||||
} else {
|
||||
$this->_json(0, dr_lang('未知模式'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth_type',
|
||||
'value' => $value
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
|
||||
$this->_json(1, $msg);
|
||||
}
|
||||
|
||||
// 初始化组权限(仅清空内容相关配置,保留用户权限)
|
||||
public function init_edit() {
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
if ($aid === null || $aid === false || $aid === '') {
|
||||
$this->_json(0, dr_lang('参数错误'));
|
||||
}
|
||||
if ($aid !== 'public' && $aid !== '0' && $aid !== 0
|
||||
&& !preg_match('/^\d+(-\d+)?$/', (string)$aid)) {
|
||||
$this->_json(0, dr_lang('参数错误'));
|
||||
}
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$old = isset($value[SITE_ID][$aid]) && is_array($value[SITE_ID][$aid]) ? $value[SITE_ID][$aid] : [];
|
||||
if (!$old && is_numeric($aid) && isset($value[SITE_ID][intval($aid)]) && is_array($value[SITE_ID][intval($aid)])) {
|
||||
$old = $value[SITE_ID][intval($aid)];
|
||||
}
|
||||
$keep = [];
|
||||
if (isset($old['member'])) {
|
||||
$keep['member'] = $old['member'];
|
||||
}
|
||||
if (isset($old['app'])) {
|
||||
$keep['app'] = $old['app'];
|
||||
}
|
||||
$value[SITE_ID][$aid] = $keep;
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
|
||||
$this->_json(1, dr_lang('本组内容权限初始化完成'));
|
||||
}
|
||||
|
||||
// 栏目等详细权限设置
|
||||
public function add() {
|
||||
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
if ($aid == 'public') {
|
||||
$name = dr_lang('全局');
|
||||
} elseif (!$aid && $aid !== '0' && $aid !== 0) {
|
||||
$aid = 0;
|
||||
$name = dr_lang('游客');
|
||||
} elseif (strpos((string)$aid, '-') !== false) {
|
||||
list($gid, $lid) = explode('-', $aid);
|
||||
if (!$this->member_cache['group'][$gid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组不存在'));
|
||||
} elseif (!$this->member_cache['group'][$gid]['level'][$lid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组等级不存在'));
|
||||
}
|
||||
$name = $this->member_cache['group'][$gid]['name'].'-'.$this->member_cache['group'][$gid]['level'][$lid]['name'];
|
||||
} else {
|
||||
if ($aid !== '0' && $aid !== 0 && !$this->member_cache['group'][$aid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组不存在'));
|
||||
}
|
||||
$name = ($aid === '0' || $aid === 0) ? dr_lang('游客') : $this->member_cache['group'][$aid]['name'];
|
||||
}
|
||||
|
||||
// 共享栏目
|
||||
$share_module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-share');
|
||||
$share_categroy = [];
|
||||
if (is_file(dr_get_app_dir('module').'Libraries/Category.php')) {
|
||||
$share_module['category'] = \Phpcmf\Service::L('category', 'module')->get_category('share');
|
||||
}
|
||||
if ($share_module['category']) {
|
||||
foreach ($share_module['category'] as $t) {
|
||||
if ($t['tid'] != 2) {
|
||||
$t['is_post'] = 0;
|
||||
if (!$t['child'] && $t['tid'] == 1) {
|
||||
$t['is_post'] = 1;
|
||||
}
|
||||
$share_categroy[$t['id']] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 模块部分
|
||||
$module = $this->_content_modules();
|
||||
if ($module) {
|
||||
foreach ($module as $dir => $t) {
|
||||
if (is_file(dr_get_app_dir('module').'Libraries/Category.php')) {
|
||||
$module[$dir]['category'] = \Phpcmf\Service::L('tree', 'module')
|
||||
->init(\Phpcmf\Service::L('category', 'module')->get_category($dir))
|
||||
->html_icon()->get_tree_array(0);
|
||||
} else {
|
||||
$module[$dir]['category'] = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$dir, 'category');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$data = isset($value[SITE_ID][$aid]) && is_array($value[SITE_ID][$aid]) ? $value[SITE_ID][$aid] : [];
|
||||
$auth = [
|
||||
'share_category' => is_array($data['share_category_public'] ?? null) ? $data['share_category_public'] : [],
|
||||
'category' => is_array($data['category_public'] ?? null) ? $data['category_public'] : [],
|
||||
];
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!is_array($post)) {
|
||||
$post = [];
|
||||
}
|
||||
$save = $data;
|
||||
|
||||
// 栏目模式与统一栏目权限
|
||||
if (isset($post['home']['is_category'])) {
|
||||
if (!isset($save['home']) || !is_array($save['home'])) {
|
||||
$save['home'] = [];
|
||||
}
|
||||
$save['home']['is_category'] = empty($post['home']['is_category']) ? 0 : 1;
|
||||
}
|
||||
$share_public = \Phpcmf\Service::L('input')->post('share_category');
|
||||
if (is_array($share_public)) {
|
||||
$save['share_category_public'] = $this->_normalize_category_auth_flags($share_public);
|
||||
}
|
||||
$cat_public = \Phpcmf\Service::L('input')->post('category');
|
||||
if (is_array($cat_public)) {
|
||||
if (!isset($save['category_public']) || !is_array($save['category_public'])) {
|
||||
$save['category_public'] = [];
|
||||
}
|
||||
foreach ($cat_public as $cmid => $crow) {
|
||||
// 模板里的 hidden test 字段不算权限配置
|
||||
if (!is_array($crow) || (dr_count($crow) === 1 && isset($crow['test']))) {
|
||||
continue;
|
||||
}
|
||||
$save['category_public'][$cmid] = $this->_normalize_category_auth_flags($crow);
|
||||
}
|
||||
}
|
||||
if (isset($post['module']) && is_array($post['module'])) {
|
||||
if (!isset($save['module']) || !is_array($save['module'])) {
|
||||
$save['module'] = [];
|
||||
}
|
||||
foreach ($post['module'] as $mid => $row) {
|
||||
if (!isset($save['module'][$mid]) || !is_array($save['module'][$mid])) {
|
||||
$save['module'][$mid] = [];
|
||||
}
|
||||
if (isset($row['is_category'])) {
|
||||
$save['module'][$mid]['is_category'] = empty($row['is_category']) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保留用户权限 / 应用权限 / 访问禁止项 / 按栏目独立设置
|
||||
if (isset($data['member'])) {
|
||||
$save['member'] = $data['member'];
|
||||
}
|
||||
if (isset($data['app'])) {
|
||||
$save['app'] = $data['app'];
|
||||
}
|
||||
if (isset($data['home']['show'])) {
|
||||
if (!isset($save['home']) || !is_array($save['home'])) {
|
||||
$save['home'] = [];
|
||||
}
|
||||
$save['home']['show'] = $data['home']['show'];
|
||||
}
|
||||
if (isset($data['module']) && is_array($data['module'])) {
|
||||
foreach ($data['module'] as $mid => $row) {
|
||||
if (!isset($save['module'][$mid]) || !is_array($save['module'][$mid])) {
|
||||
$save['module'][$mid] = [];
|
||||
}
|
||||
if (isset($row['show'])) {
|
||||
$save['module'][$mid]['show'] = $row['show'];
|
||||
}
|
||||
if (isset($row['search'])) {
|
||||
$save['module'][$mid]['search'] = $row['search'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($data['share_category'])) {
|
||||
$save['share_category'] = $data['share_category'];
|
||||
}
|
||||
if (isset($data['category'])) {
|
||||
$save['category'] = $data['category'];
|
||||
}
|
||||
|
||||
$value[SITE_ID][$aid] = $save;
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = trim(\Phpcmf\Service::L('input')->get('page'));
|
||||
if (!$page) {
|
||||
$page = 'cms';
|
||||
}
|
||||
|
||||
// 弹窗只展示当前入口对应的栏目(共享 / 单个模块)
|
||||
$is_share_page = ($page === 'cms' || $page === 'site');
|
||||
$mid = '';
|
||||
$m = [];
|
||||
if ($is_share_page) {
|
||||
$page = 'cms';
|
||||
$page_name = dr_lang('共享栏目');
|
||||
} elseif (isset($module[$page])) {
|
||||
$mid = $page;
|
||||
$m = $module[$page];
|
||||
$page_name = dr_lang($m['name']);
|
||||
// 共享型模块无独立栏目,回退到共享栏目
|
||||
if (!empty($m['share'])) {
|
||||
$is_share_page = true;
|
||||
$page = 'cms';
|
||||
$mid = '';
|
||||
$m = [];
|
||||
$page_name = dr_lang('共享栏目');
|
||||
}
|
||||
} else {
|
||||
$this->_admin_msg(0, dr_lang('模块不存在'));
|
||||
}
|
||||
|
||||
$verify = [];
|
||||
if (\Phpcmf\Service::M()->is_table_exists('admin_verify')) {
|
||||
$verify = \Phpcmf\Service::M()->table('admin_verify')->getAll();
|
||||
}
|
||||
|
||||
$diy = $this->_get_diy();
|
||||
if ($is_share_page) {
|
||||
$diy['module'] = [];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'aid' => $aid,
|
||||
'diy' => $diy,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
dr_lang('%s:%s栏目权限', $name, $page_name) => ['cms/auth/add{aid='.$aid.'&page='.$page.'}', 'fa fa-table'],
|
||||
'help' => [801],
|
||||
]
|
||||
),
|
||||
'page' => $page,
|
||||
'page_name' => $page_name,
|
||||
'is_share_page' => $is_share_page,
|
||||
'mid' => $mid,
|
||||
'm' => $m,
|
||||
'data' => $data,
|
||||
'auth' => $auth,
|
||||
'verify' => $verify,
|
||||
'is_ajax_edit' => 0,
|
||||
'share_categroy' => \Phpcmf\Service::L('tree')->init($share_categroy)->html_icon()->get_tree_array(0),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_setting.html');
|
||||
}
|
||||
|
||||
// 弹出设置单独权限
|
||||
public function edit() {
|
||||
|
||||
$at = dr_safe_filename(\Phpcmf\Service::L('input')->get('at'));
|
||||
if (!$at || !in_array($at, ['share_category', 'category'])) {
|
||||
$this->_json(0, dr_lang('at参数错误'));
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
!$aid && $aid !== '0' && $aid = 0;
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$id) {
|
||||
$this->_json(0, dr_lang('id参数错误'));
|
||||
}
|
||||
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
if ($at == 'category') {
|
||||
$post = \Phpcmf\Service::L('input')->post($at);
|
||||
$row = is_array($post[$mid] ?? null) ? $post[$mid] : [];
|
||||
$value[SITE_ID][$aid][$at][$mid][$id] = $this->_normalize_category_auth_flags($row);
|
||||
} else {
|
||||
$row = \Phpcmf\Service::L('input')->post($at);
|
||||
$value[SITE_ID][$aid][$at][$id] = $this->_normalize_category_auth_flags($row);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
if ($at == 'category') {
|
||||
$auth = [$at => [$mid => $value[SITE_ID][$aid][$at][$mid][$id]]];
|
||||
} else {
|
||||
$auth = [$at => $value[SITE_ID][$aid][$at][$id]];
|
||||
}
|
||||
|
||||
$verify = [];
|
||||
if (\Phpcmf\Service::M()->is_table_exists('admin_verify')) {
|
||||
$verify = \Phpcmf\Service::M()->table('admin_verify')->getAll();
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mid' => $mid,
|
||||
'diy' => $this->_get_diy(),
|
||||
'auth' => $auth,
|
||||
'verify' => $verify,
|
||||
'is_ajax_edit' => 1,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_'.$at.'.html');
|
||||
}
|
||||
|
||||
// 复制动作
|
||||
public function copy_edit() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$at = dr_safe_filename(\Phpcmf\Service::L('input')->get('at'));
|
||||
if (!$at) {
|
||||
$this->_json(0, dr_lang('at参数错误'));
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
!$aid && $aid !== '0' && $aid = 0;
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
|
||||
switch ($at) {
|
||||
|
||||
case 'level':
|
||||
case 'group':
|
||||
$group = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
],
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
if ($at == 'level') {
|
||||
$group[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => dr_lang($t['name']),
|
||||
];
|
||||
if ($t['level']) {
|
||||
foreach ($t['level'] as $lv) {
|
||||
$group[$t['id'].'-'.$lv['id']] = [
|
||||
'id' => $t['id'].'-'.$lv['id'],
|
||||
'name' => ' └ '.dr_lang($lv['name']),
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$group[$t['id']] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$auth = $value[SITE_ID][$aid];
|
||||
if (!$auth) {
|
||||
$this->_json(0, dr_lang('当前用户组没有配置权限规则'));
|
||||
}
|
||||
|
||||
$catids = \Phpcmf\Service::L('input')->post('catid');
|
||||
if (!$catids) {
|
||||
$this->_json(0, dr_lang('你还没有选择用户组呢'));
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
if (isset($catids[0]) && $catids[0] == 0) {
|
||||
foreach ($group as $gid => $t) {
|
||||
$c++;
|
||||
$value[SITE_ID][$gid] = $auth;
|
||||
}
|
||||
} else {
|
||||
foreach ($catids as $gid) {
|
||||
$c++;
|
||||
$value[SITE_ID][$gid] = $auth;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('共复制%s个用户组', $c));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'select' => \Phpcmf\Service::L('tree')->select_category(
|
||||
$group,
|
||||
0,
|
||||
'id=\'dr_catid\' name=\'catid[]\' multiple="multiple" style="height:200px"',
|
||||
'',
|
||||
0,
|
||||
0
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_copy_group.html');exit;
|
||||
|
||||
case 'share_category':
|
||||
$share_module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-share');
|
||||
if (is_file(dr_get_app_dir('module').'Libraries/Category.php')) {
|
||||
$share_module['category'] = \Phpcmf\Service::L('category', 'module')->get_category('share');
|
||||
}
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$auth = $value[SITE_ID][$aid]['share_category'][$id];
|
||||
if (!$auth) {
|
||||
$this->_json(0, dr_lang('当前栏目没有配置权限规则'));
|
||||
}
|
||||
|
||||
$catids = \Phpcmf\Service::L('input')->post('catid');
|
||||
if (!$catids) {
|
||||
$this->_json(0, dr_lang('你还没有选择栏目呢'));
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
if (isset($catids[0]) && $catids[0] == 0) {
|
||||
foreach ($share_module['category'] as $cid => $t) {
|
||||
$c++;
|
||||
$value[SITE_ID][$aid]['share_category'][$cid] = $auth;
|
||||
}
|
||||
} else {
|
||||
foreach ($catids as $cid) {
|
||||
$c++;
|
||||
$value[SITE_ID][$aid]['share_category'][$cid] = $auth;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('共复制%s个栏目', $c));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'select' => \Phpcmf\Service::L('tree')->select_category(
|
||||
$share_module['category'],
|
||||
0,
|
||||
'id=\'dr_catid\' name=\'catid[]\' multiple="multiple" style="height:200px"',
|
||||
dr_lang('全部栏目'),
|
||||
0,
|
||||
0
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_copy_category.html');exit;
|
||||
|
||||
case 'category':
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$mid);
|
||||
if (is_file(dr_get_app_dir('module').'Libraries/Category.php')) {
|
||||
$module['category'] = \Phpcmf\Service::L('category', 'module')->get_category($mid);
|
||||
}
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$auth = $value[SITE_ID][$aid]['category'][$mid][$id];
|
||||
if (!$auth) {
|
||||
$this->_json(0, dr_lang('当前栏目没有配置权限规则'));
|
||||
}
|
||||
|
||||
$catids = \Phpcmf\Service::L('input')->post('catid');
|
||||
if (!$catids) {
|
||||
$this->_json(0, dr_lang('你还没有选择栏目呢'));
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
if (isset($catids[0]) && $catids[0] == 0) {
|
||||
foreach ($module['category'] as $cid => $t) {
|
||||
$c++;
|
||||
$value[SITE_ID][$aid]['category'][$mid][$cid] = $auth;
|
||||
}
|
||||
} else {
|
||||
foreach ($catids as $cid) {
|
||||
$c++;
|
||||
$value[SITE_ID][$aid]['category'][$mid][$cid] = $auth;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('共复制%s个栏目', $c));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'select' => \Phpcmf\Service::L('category', 'module')->select(
|
||||
$module['mid'],
|
||||
0,
|
||||
'id=\'dr_catid\' name=\'catid[]\' multiple="multiple" style="height:200px"',
|
||||
dr_lang('全部栏目'),
|
||||
0,
|
||||
0
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('auth_copy_category.html');exit;
|
||||
}
|
||||
|
||||
$this->_json(0, dr_lang('未知类型'));
|
||||
}
|
||||
|
||||
private function _get_diy() {
|
||||
|
||||
$diy = [
|
||||
'module' => [],
|
||||
'category' => [],
|
||||
];
|
||||
|
||||
$local = \Phpcmf\Service::Apps(1);
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file($path.'Config/Auth.php')) {
|
||||
$_data = require $path.'Config/Auth.php';
|
||||
if ($_data) {
|
||||
foreach ($_data as $key => $val) {
|
||||
if ($val && isset($diy[$key])) {
|
||||
foreach ($val as $file) {
|
||||
if (is_file($path.'Views/auth/'.$file)) {
|
||||
$diy[$key][] = [
|
||||
'app' => $dir,
|
||||
'file' => $path.'Views/auth/'.$file,
|
||||
];
|
||||
} else {
|
||||
log_message('error', '应用插件['.$dir.']权限模板文件不存在:'.$path.'Views/auth/'.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $diy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Field extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
$list = [];
|
||||
$local = \Phpcmf\Service::Apps();
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file(dr_get_app_dir($dir).'Config/App.php')) {
|
||||
$key = strtolower($dir);
|
||||
$cfg = require dr_get_app_dir($dir).'Config/App.php';
|
||||
if ($cfg['type'] == 'module' || $cfg['ftype'] == 'module') {
|
||||
if (isset($cfg['hlist']) && $cfg['hlist']) {
|
||||
// 不在列表显示
|
||||
continue;
|
||||
}
|
||||
$cfg['dirname'] = $key;
|
||||
$list[$key] = $cfg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$my = [];
|
||||
$module = \Phpcmf\Service::M('Module')->All(); // 库中已安装模块
|
||||
if ($module) {
|
||||
foreach ($module as $t) {
|
||||
$dir = $t['dirname'];
|
||||
if ($list[$dir]) {
|
||||
$t['name'] = dr_lang($list[$dir]['name']);
|
||||
$t['mtype'] = $list[$dir]['mtype'];
|
||||
$t['system'] = $list[$dir]['system'];
|
||||
$t['version'] = $list[$dir]['version'];
|
||||
$site = dr_string2array($t['site']);
|
||||
$t['install'] = isset($site[SITE_ID]) && $site[SITE_ID] ? 1 : 0;
|
||||
$my[$dir] = $t;
|
||||
unset($list[$dir]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'my' => $my,
|
||||
'list' => $list,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'自定义字段' => [APP_DIR.'/field/index', 'fa fa-code'],
|
||||
]
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('field.html');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
// 操作指南
|
||||
class Help extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
$page = max(0, (int)\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu([
|
||||
'基础操作' => [APP_DIR.'/help/index', 'fa fa-book'],
|
||||
]),
|
||||
'title' => dr_lang('建站系统 - 基础操作'),
|
||||
'page' => $page,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('help_index.html');
|
||||
}
|
||||
|
||||
public function template() {
|
||||
|
||||
$page = max(0, (int)\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu([
|
||||
'模板制作' => [APP_DIR.'/help/template', 'fa fa-code'],
|
||||
]),
|
||||
'title' => dr_lang('建站系统 - 模板制作'),
|
||||
'page' => $page,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('help_template.html');
|
||||
}
|
||||
|
||||
public function seo() {
|
||||
|
||||
$page = max(0, (int)\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu([
|
||||
'SEO用法' => [APP_DIR.'/help/seo', 'fa fa-internet-explorer'],
|
||||
]),
|
||||
'title' => dr_lang('建站系统 - SEO用法'),
|
||||
'page' => $page,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('help_seo.html');
|
||||
}
|
||||
|
||||
public function url() {
|
||||
|
||||
$page = max(0, (int)\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu([
|
||||
'自定义URL用法' => [APP_DIR.'/help/url', 'fa fa-link'],
|
||||
]),
|
||||
'title' => dr_lang('建站系统 - 自定义URL用法'),
|
||||
'page' => $page,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('help_url.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Module extends \Phpcmf\Common {
|
||||
|
||||
private $dir;
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->dir = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir'));
|
||||
$menu = [
|
||||
'内容模块' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-cogs'],
|
||||
'创建模块' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'_create/index', 'fa fa-plus'],
|
||||
'模块配置' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-cog'],
|
||||
'推荐位配置' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/flag_edit', 'fa fa-flag'],
|
||||
'help' => [57]
|
||||
];
|
||||
if (!IS_DEV) {
|
||||
unset($menu['创建模块']);
|
||||
}
|
||||
if (strpos(\Phpcmf\Service::L('Router')->method, 'flag') !== false) {
|
||||
$menu['help'] = [440];
|
||||
} elseif (strpos(\Phpcmf\Service::L('Router')->method, 'edit') !== false) {
|
||||
$menu['help'] = [1040];
|
||||
}
|
||||
\Phpcmf\Service::V()->assign('menu', \Phpcmf\Service::M('auth')->_admin_menu($menu));
|
||||
}
|
||||
|
||||
// 安装模块
|
||||
public function install() {
|
||||
|
||||
$dir = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir'));
|
||||
$type = (int)\Phpcmf\Service::L('input')->get('type');
|
||||
|
||||
if (!preg_match('/^[a-z]+$/U', $dir)) {
|
||||
$this->_json(0, dr_lang('模块目录[%s]格式不正确', $dir));
|
||||
} elseif (\Phpcmf\Service::M('app')->is_sys_dir($dir)) {
|
||||
$this->_json(0, dr_lang('模块目录[%s]名称是系统保留名称,请重命名', $dir));
|
||||
}
|
||||
|
||||
$path = dr_get_app_dir($dir);
|
||||
if (!is_dir($path)) {
|
||||
$this->_json(0, dr_lang('模块目录[%s]不存在', $path));
|
||||
}
|
||||
|
||||
// 对当前模块属性判断
|
||||
$cfg = require $path.'Config/App.php';
|
||||
if (!$cfg) {
|
||||
$this->_json(0, dr_lang('文件[%s]不存在', 'App/'.ucfirst($dir).'/Config/App.php'));
|
||||
}
|
||||
|
||||
$cfg['share'] = $type ? 0 : 1;
|
||||
|
||||
$rt = \Phpcmf\Service::M('module')->install($dir, $cfg);
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json($rt['code'], $rt['msg'], $rt['data']);
|
||||
}
|
||||
|
||||
// 卸载模块
|
||||
public function uninstall() {
|
||||
|
||||
$dir = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir'));
|
||||
if (!preg_match('/^[a-z]+$/U', $dir)) {
|
||||
$this->_json(0, dr_lang('模块目录[%s]格式不正确', $dir));
|
||||
}
|
||||
|
||||
$path = dr_get_app_dir($dir);
|
||||
if (!is_dir($path)) {
|
||||
$this->_json(0, dr_lang('模块目录[%s]不存在', $path));
|
||||
}
|
||||
|
||||
$cfg = require $path.'Config/App.php';
|
||||
if (!$cfg) {
|
||||
$this->_json(0, dr_lang('文件[%s]不存在', 'App/'.ucfirst($dir).'/Config/App.php'));
|
||||
}
|
||||
|
||||
$rt = \Phpcmf\Service::M('Module')->uninstall($dir, $cfg);
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json($rt['code'], $rt['msg']);
|
||||
|
||||
}
|
||||
|
||||
// 模块管理
|
||||
public function index() {
|
||||
|
||||
$list = [];
|
||||
$local = \Phpcmf\Service::Apps();
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file(dr_get_app_dir($dir).'Config/App.php')) {
|
||||
$key = strtolower($dir);
|
||||
$cfg = require dr_get_app_dir($dir).'Config/App.php';
|
||||
if ($cfg['type'] == 'module' || $cfg['ftype'] == 'module') {
|
||||
if (isset($cfg['hlist']) && $cfg['hlist']) {
|
||||
// 不在列表显示
|
||||
continue;
|
||||
}
|
||||
$cfg['dirname'] = $key;
|
||||
$list[$key] = $cfg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$my = [];
|
||||
$module = \Phpcmf\Service::M('Module')->All(); // 库中已安装模块
|
||||
if ($module) {
|
||||
foreach ($module as $t) {
|
||||
$dir = $t['dirname'];
|
||||
if ($list[$dir]) {
|
||||
$t['name'] = dr_lang($list[$dir]['name']);
|
||||
$t['mtype'] = $list[$dir]['mtype'];
|
||||
$t['system'] = $list[$dir]['system'];
|
||||
$t['version'] = $list[$dir]['version'];
|
||||
$site = dr_string2array($t['site']);
|
||||
$t['install'] = isset($site[SITE_ID]) && $site[SITE_ID] ? 1 : 0;
|
||||
$my[$dir] = $t;
|
||||
unset($list[$dir]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'my' => $my,
|
||||
'list' => $list,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_list.html');
|
||||
}
|
||||
|
||||
// 重命名
|
||||
public function name_edit() {
|
||||
|
||||
$mid = dr_safe_filename($_GET['dir']);
|
||||
$file = dr_get_app_dir($mid).'Config/App.php';
|
||||
if (!is_file($file)) {
|
||||
$this->_json(0, dr_lang('当前模块配置文件不存在'));
|
||||
}
|
||||
|
||||
$config = require $file;
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$data = \Phpcmf\Service::L('input')->post('data');
|
||||
|
||||
// 参数判断
|
||||
if (!$data['name']) {
|
||||
$this->_json(0, dr_lang('名称不能为空'), ['field' => 'name']);
|
||||
} elseif (!$data['icon']) {
|
||||
$this->_json(0, dr_lang('模块图标不能为空'), ['field' => 'icon']);
|
||||
} elseif (!dr_check_put_path(dirname($file))) {
|
||||
$this->_json(0, dr_lang('目录[%s]没有创建文件权限', dirname($file)), ['field' => 'dirname']);
|
||||
}
|
||||
|
||||
$old = $config['name'];
|
||||
$config['name'] = dr_safe_filename($data['name']);
|
||||
$config['icon'] = dr_safe_replace($data['icon']);
|
||||
file_put_contents($file, '<?php return '.var_export($config, true).';');
|
||||
|
||||
// 变更菜单
|
||||
\Phpcmf\Service::M('menu', 'module')->update_module_name($mid, $old, $config['name'], $config['icon']);
|
||||
|
||||
// 重置Zend OPcache
|
||||
function_exists('opcache_reset') && opcache_reset();
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
|
||||
\Phpcmf\Service::L('input')->system_log('模块['.$mid.']名称变更');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'config' => $config,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_name_edit.html');exit;
|
||||
}
|
||||
|
||||
// 排序
|
||||
public function displayorder_edit() {
|
||||
|
||||
// 查询数据
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$row = \Phpcmf\Service::M('Module')->table('module')->get($id);
|
||||
if (!$row) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
$value = (int)\Phpcmf\Service::L('input')->get('value');
|
||||
$rt = \Phpcmf\Service::M('Module')->table('module')->save($id, 'displayorder', $value);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
\Phpcmf\Service::L('input')->system_log('修改模块('.$row['dirname'].')的排序值为'.$value);
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
// 隐藏或者启用
|
||||
public function hidden_edit() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$row = \Phpcmf\Service::M('Module')->table('module')->get($id);
|
||||
if (!$row) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
$v = $row['disabled'] ? 0 : 1;
|
||||
\Phpcmf\Service::M('Module')->table('module')->update($id, ['disabled' => $v]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang($v ? '模块已被禁用' : '模块已被启用'), ['value' => $v]);
|
||||
}
|
||||
|
||||
// 模块配置
|
||||
public function edit() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if ($this->dir) {
|
||||
$data = \Phpcmf\Service::M()->table('module')->where('dirname', $this->dir)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
$id = $data['id'];
|
||||
} else {
|
||||
$data = \Phpcmf\Service::M()->table('module')->get($id);
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
}
|
||||
|
||||
// 格式转换
|
||||
$data['site'] = dr_string2array($data['site']);
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
|
||||
// 判断站点
|
||||
if (!$data['site'][SITE_ID]) {
|
||||
$this->_admin_msg(0, dr_lang('当前站点尚未安装'));
|
||||
}
|
||||
|
||||
// 主表字段
|
||||
$field = \Phpcmf\Service::M()->db->table('field')
|
||||
->where('disabled', 0)
|
||||
->where('ismain', 1)
|
||||
->where('relatedname', 'module')
|
||||
->where('relatedid', $id)
|
||||
->orderBy('displayorder ASC,id ASC')
|
||||
->get()->getResultArray();
|
||||
$sys_field = \Phpcmf\Service::L('Field')->sys_field(['id', 'catid', 'uid', 'inputtime', 'inputip', 'updatetime', 'hits', 'displayorder']);
|
||||
$field = dr_list_field_value($data['setting']['list_field'], $sys_field, $field);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$this->init_file($data['dirname']);
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if ($post['setting']['list_field']) {
|
||||
foreach ($post['setting']['list_field'] as $t) {
|
||||
if ($t['func']) {
|
||||
if (method_exists(\Phpcmf\Service::L('Function_list'), $t['func'])) {
|
||||
} elseif (!function_exists($t['func'])) {
|
||||
$this->_json(0, dr_lang('列表回调函数[%s]未定义', $t['func']));
|
||||
} elseif (strpos($t['func'], 'dr_') === false && strpos($t['func'], 'my_') === false) {
|
||||
$this->_json(0, '函数【'.$t['func'].'】必须以dr_或者my_开头');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($post['setting']['search_time'] && !isset($field[$post['setting']['search_time']])) {
|
||||
$this->_json(0, dr_lang('后台列表时间搜索字段%s不存在', $post['setting']['search_time']));
|
||||
}
|
||||
if ($post['setting']['order']) {
|
||||
if (strpos($post['setting']['order'], '(') or strpos($post['setting']['order'], ')')) {
|
||||
$this->_json(0, dr_lang('后台列表的默认排序字段不允许特殊符号'));
|
||||
}
|
||||
$arr = explode(',', trim($post['setting']['order']));
|
||||
foreach ($arr as $t) {
|
||||
list($a) = explode(' ', trim($t));
|
||||
if ($a && !isset($field[$a])) {
|
||||
$this->_json(0, dr_lang('后台列表的默认排序字段%s不存在', $a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rt = \Phpcmf\Service::M('Module')->config($data, $post);
|
||||
if ($rt['code']) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, '操作成功');
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$config = require dr_get_app_dir($data['dirname']).'Config/App.php';
|
||||
|
||||
if (!$data['site'][SITE_ID]['title']) {
|
||||
$data['site'][SITE_ID]['title'] = $config['name'];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data,
|
||||
'site' => $data['site'][SITE_ID],
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'field' => $field,
|
||||
'is_hcategory' => isset($config['hcategory']) && $config['hcategory'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_edit.html');
|
||||
}
|
||||
|
||||
// 推荐位
|
||||
public function flag_edit() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if ($this->dir) {
|
||||
$data = \Phpcmf\Service::M()->table('module')->where('dirname', $this->dir)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
} else {
|
||||
$data = \Phpcmf\Service::M()->table('module')->get($id);
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
}
|
||||
|
||||
// 格式转换
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('flag');
|
||||
if ($post) {
|
||||
$role = \Phpcmf\Service::L('input')->post('role');
|
||||
foreach ($post as $fid => $t) {
|
||||
$post[$fid]['role'] = [];
|
||||
if (isset($role[$fid]) && $role[$fid]) {
|
||||
foreach ($role[$fid] as $fid2 => $aid) {
|
||||
$post[$fid]['role'][$aid] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('Module')->config($data, null, [
|
||||
'flag' => $post,
|
||||
]);
|
||||
if ($rt['code']) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, '操作成功');
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'flag' => $data['setting']['flag'],
|
||||
'form' => dr_form_hidden(),
|
||||
'role' => \Phpcmf\Service::C()->get_cache('auth'),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_flag.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Module_category extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$mid = \Phpcmf\Service::L('input')->get('dir');
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('系统没有安装内容模块'), dr_url('module/module/index'));
|
||||
}
|
||||
|
||||
$share = 0;
|
||||
|
||||
// 设置url
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($t['share']) {
|
||||
$share = 1;
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
} elseif ($t['system'] == 2) {
|
||||
// 自定义菜单的
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
} elseif ($t['hcategory']) {
|
||||
// 禁止使用栏目
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
if ($mid && $mid != $dir) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
$module[$dir]['name'] = dr_lang('%s栏目', $t['name']);
|
||||
$module[$dir]['url'] = \Phpcmf\Service::L('Router')->url($dir.'/category/index');
|
||||
}
|
||||
|
||||
if ($share) {
|
||||
$tmp['share'] = [
|
||||
'name' => '共享栏目',
|
||||
'icon' => 'fa fa-share-alt',
|
||||
'title' => '共享',
|
||||
'url' => \Phpcmf\Service::L('Router')->url('category/index'),
|
||||
'dirname' => 'share',
|
||||
];
|
||||
$one = $tmp['share'];
|
||||
$module = dr_array22array($tmp, $module);
|
||||
} else {
|
||||
$one = reset($module);
|
||||
}
|
||||
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('系统没有可用内容模块'), dr_url('module/module/index'));
|
||||
}
|
||||
|
||||
// 只存在一个项目
|
||||
dr_count($module) == 1 && dr_redirect($one['url']);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'url' => $one['url'],
|
||||
'menu' => \Phpcmf\Service::M('auth')->_iframe_menu($module, $one['dirname']),
|
||||
'module' => $module,
|
||||
'dirname' => $one['dirname'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('iframe_content.html');exit;
|
||||
}
|
||||
|
||||
public function field_index() {
|
||||
|
||||
$dir = dr_safe_replace(\Phpcmf\Service::L('input')->get('dir'));
|
||||
if (!$dir) {
|
||||
$this->_admin_msg(0, dr_lang('系统没有可用内容模块'));
|
||||
}
|
||||
|
||||
$module = \Phpcmf\Service::M()->table('module')->where('dirname', $dir)->getRow();
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('数据#%s不存在', $dir));
|
||||
}
|
||||
|
||||
$list = [];
|
||||
|
||||
// 字段查询
|
||||
$mid = $dir;
|
||||
$like = ['catmodule-'.$dir];
|
||||
if ($module['share']) {
|
||||
$like[] = 'catmodule-share';
|
||||
$mid = 'share';
|
||||
}
|
||||
$setting = dr_string2array($module['setting']);
|
||||
$field = \Phpcmf\Service::M()->db->table('field')
|
||||
->where('ismain', 1)
|
||||
->where('disabled', 0)
|
||||
->whereIn('relatedname', $like)
|
||||
->orderBy('displayorder ASC, id ASC')->get()->getResultArray();
|
||||
if ($field) {
|
||||
$module['category'] = $this->get_cache('module-'.SITE_ID.'-'.$dir, 'category');
|
||||
foreach ($field as $f) {
|
||||
/*
|
||||
$f['setting'] = dr_string2array($f['setting']);
|
||||
if ($f['relatedid']) {
|
||||
$f['setting']['diy']['cat_field_catids'][] = $f['relatedid'];
|
||||
}*/
|
||||
$catids = [];
|
||||
foreach ($module['category'] as $t) {
|
||||
if ($t['setting']['module_field'] && isset($t['setting']['module_field'][$f['fieldname']])) {
|
||||
$catids[] = $t['id'];
|
||||
}
|
||||
}
|
||||
$f['select'] = \Phpcmf\Service::L('Tree')->ismain(1)->select_category(
|
||||
$module['category'],
|
||||
$catids,
|
||||
'name=\'data['.$f['fieldname'].'][]\' multiple="multiple" data-actions-box="true"',
|
||||
'',
|
||||
0,
|
||||
0
|
||||
);
|
||||
$list[$f['id']] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
$setting['module_category_hide'] = (int)\Phpcmf\Service::L('input')->post('hide');
|
||||
\Phpcmf\Service::M()->table('module')->update($module['id'], ['setting' => dr_array2string($setting)]);
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$table = $module['share'] ? 'share_category' : $module['dirname'].'_category';
|
||||
foreach ($module['category'] as $t) {
|
||||
//if ($t['ismain']) {
|
||||
$setting = dr_string2array($t['setting']);
|
||||
$setting['module_field'] = [];
|
||||
if ($post) {
|
||||
foreach ($post as $fname => $catids) {
|
||||
if (in_array($t['id'], $catids)) {
|
||||
$setting['module_field'][$fname] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::M()->table_site($table)->update($t['id'], ['setting' => dr_array2string($setting)]);
|
||||
//}
|
||||
}
|
||||
// 自动更新缓存
|
||||
\Phpcmf\Service::M('cache')->sync_cache();
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mid' => $mid,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'内容模块' => ['module/module/index', 'fa fa-cogs'],
|
||||
'模块【'.$module['dirname'].'】栏目模型字段' => ['module/module_category/field_index{dir='.$dir.'}', 'fa fa-code', 'module_category/field_index'],
|
||||
'自定义字段' => ['url:'.\Phpcmf\Service::L('Router')->url('field/index', ['rname'=>'catmodule-'.$dir, 'rid'=>0]), 'fa fa-code', 'field/add'],
|
||||
'help' => [798],
|
||||
]
|
||||
),
|
||||
'list' => $list,
|
||||
'hide' => $setting['module_category_hide'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_category_field.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Module_create extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
// 创建模块
|
||||
public function index() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
if (!IS_DEV) {
|
||||
$this->_json(0, '禁止操作');
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::L('input')->post('data');
|
||||
|
||||
// 参数判断
|
||||
if (!$data['name']) {
|
||||
$this->_json(0, dr_lang('名称不能为空'), ['field' => 'name']);
|
||||
} elseif (!$data['dirname']) {
|
||||
$this->_json(0, dr_lang('目录不能为空'), ['field' => 'dirname']);
|
||||
}
|
||||
|
||||
$data['dirname'] = strtolower($data['dirname']);
|
||||
if (!preg_match('/^[a-z]+$/i', $data['dirname'])) {
|
||||
$this->_json(0, dr_lang('目录只能是英文字母'), ['field' => 'dirname']);
|
||||
} elseif (is_dir(APPSPATH.ucfirst($data['dirname']))) {
|
||||
$this->_json(0, dr_lang('此目录已经存在'), ['field' => 'dirname']);
|
||||
} elseif (!$data['icon']) {
|
||||
$this->_json(0, dr_lang('模块图标不能为空'), ['field' => 'icon']);
|
||||
} elseif (!dr_check_put_path(APPSPATH)) {
|
||||
$this->_json(0, dr_lang('服务器没有创建目录的权限'), ['field' => 'dirname']);
|
||||
} elseif (\Phpcmf\Service::M('app')->is_sys_dir($data['dirname'])) {
|
||||
$this->_json(0, dr_lang('目录[%s]名称是系统保留名称,请重命名', $data['dirname']));
|
||||
}
|
||||
|
||||
// 开始复制到指定目录
|
||||
$path = APPSPATH.ucfirst($data['dirname']).'/';
|
||||
\Phpcmf\Service::L('File')->copy_file(APPPATH.'Temps/Module/', $path);
|
||||
if (!is_file($path.'Config/App.php')) {
|
||||
$this->_json(0, dr_lang('目录创建失败,请检查文件权限'), ['field' => 'dirname']);
|
||||
}
|
||||
|
||||
// 替换模块配置文件
|
||||
$app = file_get_contents($path.'Config/App.php');
|
||||
$app = str_replace(['{name}', '{icon}'], [dr_safe_filename($data['name']), dr_safe_replace($data['icon'])], $app);
|
||||
file_put_contents($path.'Config/App.php', $app);
|
||||
|
||||
$this->_json(1, dr_lang('模块创建成功'), [
|
||||
'url' => dr_url('module/module/index')
|
||||
]);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu([
|
||||
'模块管理' => [APP_DIR.'/module/index', 'fa fa-cogs'],
|
||||
'创建模块' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-plus'],
|
||||
'help' => [24]
|
||||
])
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_create.html');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Module_param extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Module_search extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$mid = \Phpcmf\Service::L('input')->get('dir');
|
||||
$all = \Phpcmf\Service::M('Module')->get_module_info();
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
|
||||
// 设置url
|
||||
if ($module) {
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($t['hlist'] == 1) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
if (!$all[$dir]) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
if ($mid && $mid != $dir) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
$data = $all[$dir];
|
||||
|
||||
// 搜索字段
|
||||
$data['search_field'] = [
|
||||
'catid' => dr_lang('栏目'),
|
||||
'keyword' => dr_lang('搜索词'),
|
||||
'order' => dr_lang('排序'),
|
||||
'page' => dr_lang('分页'),
|
||||
];
|
||||
if (!$data['setting']['search']['field']) {
|
||||
$data['setting']['search']['field'] = 'title,keywords';
|
||||
}
|
||||
$field = \Phpcmf\Service::M()->db->table('field')
|
||||
->where('disabled', 0)
|
||||
->where('ismain', 1)
|
||||
->where('relatedname', 'module')
|
||||
->where('relatedid', $data['id'])
|
||||
->orderBy('displayorder ASC,id ASC')
|
||||
->get()->getResultArray();
|
||||
foreach ($field as $f) {
|
||||
$data['search_field'][$f['fieldname']] = $f['name'];
|
||||
}
|
||||
$module[$dir] = $data;
|
||||
$module[$dir]['field'] = $field;
|
||||
$module[$dir]['save_url'] = dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', ['dir' => $dir]);
|
||||
}
|
||||
} else {
|
||||
$this->_admin_msg(0, dr_lang('系统没有安装内容模块'));
|
||||
}
|
||||
|
||||
|
||||
$one = reset($module);
|
||||
$page = \Phpcmf\Service::L('input')->get('page');
|
||||
if (!$page) {
|
||||
$page = $one['dirname'];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'模块搜索设置' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-search'],
|
||||
'help' => [1041],
|
||||
]
|
||||
),
|
||||
'module' => $module,
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('module_search.html');
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
|
||||
$dir = \Phpcmf\Service::L('input')->get('dir');
|
||||
$cache = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
if (!$cache[$dir]) {
|
||||
$this->_json(0, dr_lang('模块#%s不存在', $dir));
|
||||
}
|
||||
|
||||
$all = \Phpcmf\Service::M('Module')->get_module_info();
|
||||
if (!$all[$dir]) {
|
||||
$this->_json(0, dr_lang('模块#%s不存在', $dir));
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
foreach ($post as $dir => $t) {
|
||||
$all[$dir]['setting']['search'] = $t;
|
||||
$all[$dir]['setting']['search']['field'] = implode(',', $_POST['search_field'][$dir]);
|
||||
\Phpcmf\Service::M()->db->table('module')->where('dirname', $dir)->update([
|
||||
'setting' => dr_array2string($all[$dir]['setting']),
|
||||
]);
|
||||
}
|
||||
|
||||
// 自动更新缓存
|
||||
\Phpcmf\Service::M('cache')->sync_cache();
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'), [
|
||||
'url' => dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', ['page' => $dir])
|
||||
]);
|
||||
}
|
||||
|
||||
$this->_json(0, dr_lang('请求错误'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Seo extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$rt = \Phpcmf\Service::M('Site')->config(
|
||||
SITE_ID,
|
||||
'seo',
|
||||
\Phpcmf\Service::L('input')->post('data', true)
|
||||
);
|
||||
\Phpcmf\Service::M('Site')->config_value(SITE_ID, 'config', [
|
||||
'SITE_INDEX_HTML' => intval(\Phpcmf\Service::L('input')->post('SITE_INDEX_HTML'))
|
||||
]);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站SEO(#%s)不存在', SITE_ID));
|
||||
}
|
||||
\Phpcmf\Service::L('input')->system_log('设置网站SEO');
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$data = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data['seo'],
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'站点SEO' => [APP_DIR.'/seo/index', 'fa fa-cog'],
|
||||
'help' => [494],
|
||||
]
|
||||
),
|
||||
'module' => \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content'),
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
'SITE_INDEX_HTML' => $data['config']['SITE_INDEX_HTML'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo.html');
|
||||
}
|
||||
|
||||
public function sync_index() {
|
||||
|
||||
$url = dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/'.\Phpcmf\Service::L('Router')->method);
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
if (!$page) {
|
||||
// 计算数量
|
||||
$total = \Phpcmf\Service::M()->db->table('module')->countAllResults();
|
||||
if (!$total) {
|
||||
$this->_html_msg(0, dr_lang('无可用模块更新'));
|
||||
}
|
||||
$this->_html_msg(1, dr_lang('正在执行中...'), $url.'&total='.$total.'&page=1');
|
||||
}
|
||||
|
||||
$psize = 100; // 每页处理的数量
|
||||
$total = (int)\Phpcmf\Service::L('input')->get('total');
|
||||
$tpage = ceil($total / $psize); // 总页数
|
||||
|
||||
// 更新完成
|
||||
if ($page > $tpage) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_html_msg(1, dr_lang('更新完成'));
|
||||
}
|
||||
|
||||
$category = \Phpcmf\Service::M()->db->table('module')->limit($psize, $psize * ($page - 1))->orderBy('id DESC')->get()->getResultArray();
|
||||
if ($category) {
|
||||
$site = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
$update = [];
|
||||
foreach ($category as $data) {
|
||||
$data['site'] = dr_string2array($data['site']);
|
||||
$data['site'][SITE_ID]['show_title'] = $site['seo']['show_title'];
|
||||
$data['site'][SITE_ID]['show_keywords'] = $site['seo']['show_keywords'];
|
||||
$data['site'][SITE_ID]['show_description'] = $site['seo']['show_description'];
|
||||
$update[] = [
|
||||
'id' => (int)$data['id'],
|
||||
'site'=> dr_array2string($data['site']),
|
||||
];
|
||||
}
|
||||
$update && \Phpcmf\Service::M()->table('module')->update_batch($update);
|
||||
}
|
||||
|
||||
$this->_html_msg(1, dr_lang('正在执行中【%s】...', "$tpage/$page"), $url.'&total='.$total.'&page='.($page+1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Seo_category extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('系统没有安装内容模块'));
|
||||
}
|
||||
|
||||
$page = \Phpcmf\Service::L('input')->get('page');
|
||||
$share = 0;
|
||||
|
||||
// 设置url
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($t['share']) {
|
||||
$share = 1;
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
} elseif ($t['hlist'] == 1) {
|
||||
//1表示不出现在模块管理、评论tab、搜索tab、内容维护tab的列表之中
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
} elseif ($t['hcategory']) {
|
||||
//1表示不使用栏目功能和发布权限功能
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
$cache = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$dir);
|
||||
if (!$cache) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
} elseif ($cache['setting']['search']['catsync']) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
if (!isset($cache['site'][SITE_ID]['is_cat']) || !$cache['site'][SITE_ID]['is_cat']) {
|
||||
if ($page && $page == $dir) {
|
||||
$this->_admin_msg(0, dr_lang('此模块没有开启按栏目分别设置SEO选项'));
|
||||
}
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$module[$dir]['name'] = dr_lang('%s栏目', $t['name']);
|
||||
$module[$dir]['list'] = $this->_get_tree_list(
|
||||
$dir,
|
||||
\Phpcmf\Service::M('category')->init(['table' => dr_module_table_prefix($dir).'_category'])->cat_data(0)
|
||||
);
|
||||
$module[$dir]['save_url'] = dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', ['dir' => $dir]);
|
||||
}
|
||||
|
||||
if ($share) {
|
||||
$tmp['share'] = [
|
||||
'name' => '共享栏目',
|
||||
'icon' => 'fa fa-share-alt',
|
||||
'title' => '共享',
|
||||
'save_url' => dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', ['dir' => 'share']),
|
||||
'dirname' => 'share',
|
||||
'list' => $this->_get_tree_list(
|
||||
'share',
|
||||
\Phpcmf\Service::M('category')->init(['table' => dr_module_table_prefix('share').'_category'])->cat_data(0)
|
||||
),
|
||||
];
|
||||
$module = dr_array22array($tmp, $module);
|
||||
}
|
||||
|
||||
$one = reset($module);
|
||||
if (!$page) {
|
||||
$page = $one['dirname'];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'栏目SEO' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-reorder'],
|
||||
'help' => [496],
|
||||
]
|
||||
),
|
||||
'module' => $module,
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo_category.html');
|
||||
}
|
||||
|
||||
// 选择规则
|
||||
private function _select_rule($dir, $rule, $t) {
|
||||
|
||||
if ($dir != 'share') {
|
||||
if ($t['setting']['urlrule']
|
||||
&& isset($rule[$t['setting']['urlrule']])
|
||||
&& $rule[$t['setting']['urlrule']]) {
|
||||
$html = '<label class="label label-success">'.dr_lang($rule[$t['setting']['urlrule']]['name']).'</label>';
|
||||
} else {
|
||||
$html = '<label class="label label-default">'.dr_lang('动态地址').'</label>';
|
||||
}
|
||||
} else {
|
||||
$html = '<label>';
|
||||
$html.= '<select class="form-control" onchange="dr_save_urlrule(\''.$dir.'\', \''.$t['id'].'\', this.value)">';
|
||||
$html.= '<option value="0"> '.dr_lang('动态地址').' </option>';
|
||||
if ($rule) {
|
||||
foreach ($rule as $b) {
|
||||
$select = isset($t['setting']['urlrule']) && $t['setting']['urlrule'] == $b['id'] ? 'selected' : '';
|
||||
if ($dir == 'share') {
|
||||
if ($b['type'] == 3) {
|
||||
$html.= '<option '.$select.' value="'.$b['id'].'"> '.dr_lang($b['name']).' </option>';
|
||||
}
|
||||
} elseif ($b['type'] == 1) {
|
||||
$html.= '<option '.$select.' value="'.$b['id'].'"> '.dr_lang($b['name']).' </option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$html.= '</select>';
|
||||
$html.= '</label>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// 获取树形结构列表
|
||||
private function _get_tree_list($dir, $data) {
|
||||
|
||||
$str = "<tr class='\$class'>";
|
||||
$str.= "<td style='text-align:center'>\$id</td>";
|
||||
$str.= "<td>\$spacer<a target='_blank' href='\$url'>\$name</a> </td>";
|
||||
$str.= "<td>\$html</td>";
|
||||
if (dr_is_app('chtml')) {
|
||||
$str .= "<td style='text-align:center'>\$is_page_html</td>";
|
||||
$str .= "<td style='text-align:center'>\$is_page_html2</td>";
|
||||
}
|
||||
$str.= "<td>\$option</td>";
|
||||
$str.= "</tr>";
|
||||
|
||||
$rule = $this->get_cache('urlrule');
|
||||
if ($dir != 'share') {
|
||||
$mod = \Phpcmf\Service::M()->table('module')->where('dirname', $dir)->getRow();
|
||||
if (!$mod) {
|
||||
$this->_admin_msg(0, dr_lang('模块#%s不存在', $dir));
|
||||
}
|
||||
$mod['site'] = dr_string2array($mod['site']);
|
||||
} else {
|
||||
$mod = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-share');
|
||||
}
|
||||
|
||||
$tree = '';
|
||||
foreach($data as $t) {
|
||||
$t['name'] = dr_strcut($t['name'], 30);
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
$t['option'] = '<a class="btn btn-xs green" href="javascript:edit_seo('.$t['id'].', \''.$t['name'].'\', \''.$dir.'\');"> <i class="fa fa-edit"></i> '.dr_lang('设置SEO').'</a>';
|
||||
$t['option'].= '<a class="btn btn-xs red" href="javascript:dr_iframe(\''.dr_lang('复制').'\', \''.dr_url(($dir == 'share' ? '' : $dir).'/category/copy_edit').'&at=seo&catid='.$t['id'].'\', \'\', \'500px\', \'nogo\');"> <i class="fa fa-copy"></i> '.dr_lang('同步到其他栏目').'</a>';
|
||||
// 判断是否生成静态
|
||||
if (dr_is_app('chtml')) {
|
||||
$is_html = intval($t['setting']['html']);
|
||||
$is_html2 = intval($t['setting']['chtml']);
|
||||
$t['is_page_html'] = '<a href="javascript:;" onclick="dr_cat_ajax_open_close(this, \''.\Phpcmf\Service::L('Router')->url(($dir == 'share' ? '' : $dir).'/category/html_edit', ['id'=>$t['id']]).'\', 0);" class="dr_is_page_html badge badge-'.(!$is_html ? 'no' : 'yes').'"><i class="fa fa-'.(!$is_html ? 'times' : 'check').'"></i></a>';
|
||||
$t['is_page_html2'] = '<a href="javascript:;" onclick="dr_cat_ajax_open_close(this, \''.\Phpcmf\Service::L('Router')->url(($dir == 'share' ? '' : $dir).'/category/html_edit', ['tid'=>1, 'id'=>$t['id']]).'\', 0);" class="dr_is_page_html badge badge-'.(!$is_html2 ? 'no' : 'yes').'"><i class="fa fa-'.(!$is_html2 ? 'times' : 'check').'"></i></a>';
|
||||
}
|
||||
if ($mod && isset($mod['site'][SITE_ID]['urlrule'])) {
|
||||
$t['setting']['urlrule'] = $mod['site'][SITE_ID]['urlrule'];
|
||||
}
|
||||
$t['html'] = $this->_select_rule($dir, $rule, $t);
|
||||
|
||||
$pid = explode(',', $t['pids']);
|
||||
$mod['category'][$t['id']]['topid'] = $t['topid'] = isset($pid[1]) ? $pid[1] : $t['id'];
|
||||
$t['url'] = $t['tid'] == 2 && $t['setting']['linkurl'] ? dr_url_prefix($t['setting']['linkurl']) : dr_url_prefix(\Phpcmf\Service::L('router')->category_url($mod, $t));
|
||||
|
||||
if ($t['child'] || $t['pcatpost']) {
|
||||
$t['spacer'] = $this->_get_spacer($t['pids']).'<a href="javascript:dr_tree_data(\''.$dir.'\', '.$t['id'].');" class="blue select-cat-'.$dir.'-'.$t['id'].'">[+]</a> ';
|
||||
} else {
|
||||
$t['spacer'] = $this->_get_spacer($t['pids']);
|
||||
}
|
||||
|
||||
$t['class'] = 'dr_catid_'.$dir.'_'.$t['id']. ' dr_pid_'.$dir.'_'.$t['pid'];
|
||||
$arr = explode(',', $t['pids']);
|
||||
if ($arr) {
|
||||
foreach ($arr as $a) {
|
||||
$t['class'].= ' dr_pid_'.$dir.'_'.$a;
|
||||
}
|
||||
}
|
||||
extract($t);
|
||||
eval("\$nstr = \"$str\";");
|
||||
$tree.= $nstr;
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public function list_index() {
|
||||
$pid = intval(\Phpcmf\Service::L('input')->get('pid'));
|
||||
$mid = dr_safe_filename(\Phpcmf\Service::L('input')->get('mid'));
|
||||
$b = $this->_get_tree_list($mid, \Phpcmf\Service::M('category')->init(['table' => dr_module_table_prefix($mid).'_category'])->cat_data($pid));
|
||||
$this->_json(1, $b);
|
||||
}
|
||||
|
||||
// 替换空格填充符号
|
||||
private function _get_spacer($str) {
|
||||
$rt = '';
|
||||
$num = substr_count((string)$str, ',') * 2;
|
||||
if ($num) {
|
||||
for ($i = 0; $i < $num; $i ++) {
|
||||
$rt.= ' ';
|
||||
}
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
||||
|
||||
public function show_index() {
|
||||
|
||||
$dir = \Phpcmf\Service::L('input')->get('dir');
|
||||
$this->module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$dir);
|
||||
if (!$this->module) {
|
||||
$this->_admin_msg(0, dr_lang('模块[%s]缓存不存在', $dir));
|
||||
return;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'list' => $this->_get_tree_list($this->module['category']),
|
||||
'dirname' => $dir,
|
||||
'save_url' => dr_url('module/'.\Phpcmf\Service::L('Router')->class.'/edit', ['dir' => $dir]),
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo_category.html');
|
||||
}
|
||||
|
||||
public function rule_edit() {
|
||||
|
||||
$dir = \Phpcmf\Service::L('input')->get('dir');
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$dir);
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('模块[%s]缓存不存在', $dir));
|
||||
return;
|
||||
}
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$value = (int)\Phpcmf\Service::L('input')->get('value');
|
||||
|
||||
if ($dir == 'share') {
|
||||
$data = \Phpcmf\Service::M()->table(dr_module_table_prefix($dir).'_category')->where('id', $id)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('栏目#%s不存在', $id));
|
||||
}
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
$data['setting']['urlrule'] = $value;
|
||||
\Phpcmf\Service::M()->db->table(dr_module_table_prefix($dir).'_category')->where('id', $id)->update([
|
||||
'setting' => dr_array2string($data['setting']),
|
||||
]);
|
||||
} else {
|
||||
$data = \Phpcmf\Service::M()->table('module')->where('dirname', $dir)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('模块#%s不存在', $dir));
|
||||
}
|
||||
|
||||
$data['site'] = dr_string2array($data['site']);
|
||||
$data['site'][SITE_ID]['urlrule'] = $value;
|
||||
|
||||
\Phpcmf\Service::M()->db->table('module')->where('dirname', $dir)->update([
|
||||
'site' => dr_array2string($data['site']),
|
||||
]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, '操作成功,更新缓存生效');
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
|
||||
$dir = \Phpcmf\Service::L('input')->get('dir');
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$dir);
|
||||
if (!$module) {
|
||||
$this->_admin_msg(0, dr_lang('模块[%s]缓存不存在', $dir));
|
||||
return;
|
||||
}
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M()->table(dr_module_table_prefix($dir).'_category')->where('id', $id)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('栏目#%s不存在', $id));
|
||||
}
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$seo = \Phpcmf\Service::L('input')->post('seo');
|
||||
$set = \Phpcmf\Service::L('input')->post('setting');
|
||||
if (!isset($data['setting']['seo']) || !$data['setting']['seo']) {
|
||||
$data['setting']['seo'] = [];
|
||||
}
|
||||
foreach (['list_title', 'list_keywords', 'list_description'] as $name) {
|
||||
$data['setting']['seo'][$name] = isset($seo[$name]) ? $seo[$name] : '';
|
||||
}
|
||||
$data['setting']['html'] = isset($set['html']) ? (int)$set['html'] : 0;
|
||||
$data['setting']['chtml'] = isset($set['chtml']) ? (int)$set['chtml'] : 0;
|
||||
$data['setting']['urlrule'] = isset($set['urlrule']) ? (int)$set['urlrule'] : 0;
|
||||
\Phpcmf\Service::M()->db->table(dr_module_table_prefix($dir).'_category')->where('id', $id)->update([
|
||||
'setting' => dr_array2string($data['setting']),
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, '操作成功,更新缓存生效');
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'data' => $data,
|
||||
'dirname' => $dir,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo_category_edit.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Seo_module extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
$mid = \Phpcmf\Service::L('input')->get('dir');
|
||||
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content');
|
||||
|
||||
// 设置url
|
||||
if ($module) {
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($t['hlist'] == 1) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
if ($mid && $mid != $dir) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
$data = \Phpcmf\Service::M()->table('module')->where('dirname', $dir)->getRow();
|
||||
if (!$data) {
|
||||
unset($module[$dir]);
|
||||
continue;
|
||||
}
|
||||
$site = dr_string2array($data['site']);
|
||||
$module[$dir]['site'] = $site[SITE_ID];
|
||||
$module[$dir]['setting'] = dr_string2array($data['setting']);
|
||||
$module[$dir]['save_url'] = dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', ['dir' => $dir]);
|
||||
}
|
||||
} else {
|
||||
$this->_admin_msg(0, dr_lang('系统没有安装内容模块'));
|
||||
}
|
||||
|
||||
$one = reset($module);
|
||||
$page = \Phpcmf\Service::L('input')->get('page');
|
||||
if (!$page) {
|
||||
$page = $one['dirname'];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'内容模块SEO' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-cogs'],
|
||||
'help' => [398],
|
||||
]
|
||||
),
|
||||
'module' => $module,
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo_module.html');
|
||||
}
|
||||
|
||||
// 存储指定的模块
|
||||
public function edit() {
|
||||
|
||||
$dir = \Phpcmf\Service::L('input')->get('dir');
|
||||
$data = \Phpcmf\Service::M()->table('module')->where('dirname', $dir)->getRow();
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('模块#%s不存在', $dir));
|
||||
}
|
||||
|
||||
$data['site'] = dr_string2array($data['site']);
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$site = \Phpcmf\Service::L('input')->post('site');
|
||||
foreach (['html', 'urlrule', 'is_cat',
|
||||
'show_title', 'show_keywords', 'show_description',
|
||||
'list_title', 'list_keywords', 'list_description',
|
||||
'search_title', 'search_keywords', 'search_description',
|
||||
'module_title', 'module_keywords', 'module_description'] as $name) {
|
||||
$data['site'][SITE_ID][$name] = $site[$name];
|
||||
}
|
||||
$data['setting']['module_index_html'] = intval($_POST['module_index_html']);
|
||||
\Phpcmf\Service::M()->db->table('module')->where('dirname', $dir)->update([
|
||||
'site' => dr_array2string($data['site']),
|
||||
'setting' => dr_array2string($data['setting']),
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'), [
|
||||
'url' => dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', ['page' => $dir])
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Seo_site extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$rt = \Phpcmf\Service::M('Site')->config(
|
||||
SITE_ID,
|
||||
'seo',
|
||||
\Phpcmf\Service::L('input')->post('data', true)
|
||||
);
|
||||
\Phpcmf\Service::M('Site')->config_value(SITE_ID, 'config', [
|
||||
'SITE_INDEX_HTML' => intval(\Phpcmf\Service::L('input')->post('SITE_INDEX_HTML'))
|
||||
]);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站SEO(#%s)不存在', SITE_ID));
|
||||
}
|
||||
\Phpcmf\Service::L('input')->system_log('设置网站SEO');
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$data = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data['seo'],
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'站点SEO' => [APP_DIR.'/'.'seo_site/index', 'fa fa-cog'],
|
||||
'help' => [494],
|
||||
]
|
||||
),
|
||||
'module' => \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-content'),
|
||||
'site_name' => $this->site_info[SITE_ID]['SITE_NAME'],
|
||||
'SITE_INDEX_HTML' => $data['config']['SITE_INDEX_HTML'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('seo_site.html');
|
||||
}
|
||||
|
||||
public function sync_index() {
|
||||
|
||||
$ct = intval(\Phpcmf\Service::L('input')->get('ct'));
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
$url = dr_url(APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/'.\Phpcmf\Service::L('Router')->method, ['ct' => $ct, 'value' => $value]);
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
if (!$page) {
|
||||
// 计算数量
|
||||
$total = \Phpcmf\Service::M()->db->table(SITE_ID.'_share_category')->countAllResults();
|
||||
if (!$total) {
|
||||
$this->_html_msg(0, dr_lang('无可用栏目更新'));
|
||||
}
|
||||
$this->_html_msg(1, dr_lang('正在执行中...'), $url.'&total='.$total.'&page=1');
|
||||
}
|
||||
|
||||
$psize = 100; // 每页处理的数量
|
||||
$total = (int)\Phpcmf\Service::L('input')->get('total');
|
||||
$tpage = ceil($total / $psize); // 总页数
|
||||
|
||||
// 更新完成
|
||||
if ($page > $tpage) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_html_msg(1, dr_lang('更新完成'));
|
||||
}
|
||||
|
||||
$category = \Phpcmf\Service::M()->db->table(SITE_ID.'_share_category')->limit($psize, $psize * ($page - 1))->orderBy('id DESC')->get()->getResultArray();
|
||||
if ($category) {
|
||||
$update = [];
|
||||
foreach ($category as $data) {
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
if ($ct == 1) {
|
||||
$data['setting']['urlrule'] = $value;
|
||||
} elseif ($ct == 2) {
|
||||
$data['setting']['template']['pagesize'] = $value;
|
||||
} elseif ($ct == 3) {
|
||||
$data['setting']['template']['mpagesize'] = $value;
|
||||
}
|
||||
$update[] = [
|
||||
'id' => (int)$data['id'],
|
||||
'setting'=> dr_array2string($data['setting']),
|
||||
];
|
||||
}
|
||||
$update && \Phpcmf\Service::M()->table_site('share_category')->update_batch($update);
|
||||
}
|
||||
|
||||
$this->_html_msg(1, dr_lang('正在执行中【%s】...', "$tpage/$page"), $url.'&total='.$total.'&page='.($page+1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Site_config extends \Phpcmf\Common
|
||||
{
|
||||
public function index() {
|
||||
|
||||
$data = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (isset($_POST['theme']) && $_POST['theme']) {
|
||||
// 远程资源
|
||||
$post['SITE_THEME'] = $post['SITE_THEME2'];
|
||||
} else {
|
||||
// 本地资源
|
||||
}
|
||||
|
||||
// 防止参数丢失
|
||||
$data['config']['SITE_NAME'] = $post['SITE_NAME'];
|
||||
$data['config']['SITE_CLOSE'] = $post['SITE_CLOSE'];
|
||||
$data['config']['SITE_INDEX_HTML'] = $post['SITE_INDEX_HTML'];
|
||||
$data['config']['SITE_CLOSE_MSG'] = $post['SITE_CLOSE_MSG'];
|
||||
$data['config']['SITE_LANGUAGE'] = $post['SITE_LANGUAGE'];
|
||||
$data['config']['SITE_TEMPLATE'] = $post['SITE_TEMPLATE'];
|
||||
$data['config']['SITE_TIMEZONE'] = $post['SITE_TIMEZONE'];
|
||||
$data['config']['SITE_TIME_FORMAT'] = $post['SITE_TIME_FORMAT'];
|
||||
$data['config']['SITE_THEME'] = $post['SITE_THEME'];
|
||||
$data['config']['SITE_INDEX_TIME'] = $post['SITE_INDEX_TIME'];
|
||||
|
||||
$rt = \Phpcmf\Service::M('Site')->config(SITE_ID, 'config', $data['config']);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站信息(#%s)不存在', SITE_ID));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('input')->system_log('设置网站参数');
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$run_time = '';
|
||||
if (is_file(WRITEPATH.'config/run_time.php')) {
|
||||
$run_time = file_get_contents(WRITEPATH.'config/run_time.php');
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data['config'],
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'lang' => dr_dir_map(ROOTPATH.'api/language/', 1),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'网站设置' => ['module/site_config/index', 'fa fa-cog'],
|
||||
'help' => [505],
|
||||
]
|
||||
),
|
||||
'theme' => dr_get_theme(),
|
||||
'run_time' => $run_time,
|
||||
'is_theme' => dr_strpos($data['config']['SITE_THEME'], '/') !== false ? 1 : 0,
|
||||
'template_path' => dr_dir_map(TPLPATH.'pc/', 1),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('site_config.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Site_domain extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$data = $post = \Phpcmf\Service::L('input')->post('data');
|
||||
if ($data['site_domain'] == $data['mobile_domain']) {
|
||||
$this->_json(0, dr_lang('手机域名不能与电脑相同'));
|
||||
}
|
||||
foreach ($post as $name => $value) {
|
||||
unset($data[$name]);
|
||||
if ($value) {
|
||||
if (strpos($name, 'webpath') === 0) {
|
||||
// 目录不验证
|
||||
} elseif ($name == 'site_domain') {
|
||||
if (!\Phpcmf\Service::L('Form')->check_domain_dir($value)) {
|
||||
$this->_json(0, dr_lang('域名(%s)格式不正确', $value));
|
||||
}
|
||||
} else {
|
||||
// 验证域名可用性
|
||||
if (dr_in_array($value, $data)) {
|
||||
$this->_json(0, dr_lang('域名(%s)绑定重复', $value));
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_domain($value)) {
|
||||
$this->_json(0, dr_lang('域名(%s)格式不正确', $value));
|
||||
}
|
||||
list($cname, $mid) = explode('_', $name);
|
||||
if ($cname == 'module' && $mid != 'mobile' && $post['module_'.$mid] && !$post['webpath_'.$mid]) {
|
||||
$this->_json(0, dr_lang('模块(%s)的Web目录必须填写', $mid));
|
||||
}
|
||||
}
|
||||
}
|
||||
$data[$name] = $value;
|
||||
}
|
||||
\Phpcmf\Service::M('Site')->domain($post);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
\Phpcmf\Service::L('input')->system_log('设置域名参数');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
list($module, $data) = \Phpcmf\Service::M('Site')->domain();
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data,
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'域名设置' => ['module/site_domain/index', 'fa fa-cog'],
|
||||
'help' => ['407'],
|
||||
]
|
||||
),
|
||||
'module' => $module,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('site_domain.html');
|
||||
}
|
||||
|
||||
public function bang_index() {
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
|
||||
$name = '';
|
||||
$is_fclient = is_file(ROOTPATH.'api/fclient/index.php');
|
||||
if ($is_fclient && is_file(MYPATH . 'Config/License.php')) {
|
||||
$license = require MYPATH . 'Config/License.php';
|
||||
$name = $license['name'];
|
||||
}
|
||||
|
||||
!$name && $name = dr_lang('软件服务商');
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
if ($is_fclient) {
|
||||
$this->_json(0, dr_lang('当前网站不能修改主域名'));
|
||||
}
|
||||
|
||||
$domain = trim(\Phpcmf\Service::L('input')->post('domain'));
|
||||
if (!\Phpcmf\Service::L('Form')->check_domain($domain)) {
|
||||
$this->_json(0, dr_lang('域名(%s)格式不正确', $domain));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('Site')->edit_domain($domain);
|
||||
\Phpcmf\Service::L('input')->system_log('变更网站主域名');
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
|
||||
$this->_json(1, dr_lang('操作成功,请更新全站缓存'), [
|
||||
'tourl' => dr_url('cache/index')
|
||||
]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'fcname' => $name,
|
||||
'is_fclient' => $is_fclient,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('site_domain_edit.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
require CMSPATH.'Control/Admin/Site_image.php';
|
||||
|
||||
class Site_image extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$obj = new \Phpcmf\Control\Admin\Site_image();
|
||||
$obj->index();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Site_mobile extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!$post['mode']) {
|
||||
if (!\Phpcmf\Service::L('Form')->check_domain($post['domain'])) {
|
||||
$this->_json(0, dr_lang('域名(%s)格式不正确', $post['domain']));
|
||||
} elseif ($this->site_info[SITE_ID]['SITE_DOMAIN'] == $post['domain']) {
|
||||
$this->_json(0, dr_lang('手机域名不能与电脑相同'));
|
||||
}
|
||||
}
|
||||
if ($post['mode'] == -1) {
|
||||
$post['auto'] = $post['auto2'];
|
||||
$post['tohtml'] = 0;
|
||||
$post['dirname'] = $post['domain'] = '';
|
||||
} elseif ($post['mode'] == 1) {
|
||||
// 生成手机目录
|
||||
$rt = \Phpcmf\Service::M('cache')->update_mobile_webpath(WEBPATH, $post['dirname']);
|
||||
if ($rt) {
|
||||
$this->_json(0, dr_lang($rt));
|
||||
}
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('Site')->config(SITE_ID, 'mobile', $post);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站信息(#%s)不存在', SITE_ID));
|
||||
}
|
||||
\Phpcmf\Service::L('input')->system_log('设置手机网站参数');
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$data = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
|
||||
if (!isset($data['mobile']['dirname']) || !$data['mobile']['dirname']) {
|
||||
$data['mobile']['dirname'] = 'mobile';
|
||||
}
|
||||
if (!isset($data['mobile']['mode']) || (!$data['mobile']['mode'] && !$data['mobile']['domain'])) {
|
||||
$data['mobile']['mode'] = -1;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'data' => $data['mobile'],
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'手机网站' => ['module/site_mobile/index', 'fa fa-mobile'],
|
||||
'help' => [506],
|
||||
]
|
||||
),
|
||||
'is_tpl' => is_file(TPLPATH.'mobile/'.SITE_TEMPLATE.'/home/index.html'),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('site_mobile.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Site_param extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
$logo = [
|
||||
'logo' => [
|
||||
'ismain' => 1,
|
||||
'fieldtype' => 'File',
|
||||
'fieldname' => 'logo',
|
||||
'setting' => ['option' => ['ext' => 'jpg,gif,png,jpeg,webp,svg', 'size' => 10, 'input' => 1]]
|
||||
]
|
||||
];
|
||||
|
||||
$data = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
$field = \Phpcmf\Service::M('field')->get_mysite_field(SITE_ID);
|
||||
|
||||
// 初始化自定义字段类
|
||||
\Phpcmf\Service::L('Field')->app('');
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data', false);
|
||||
|
||||
// param
|
||||
if ($field) {
|
||||
list($save, $return, $attach, $notfield) = \Phpcmf\Service::L('form')->validation($post, null, $field, $data['param']);
|
||||
// 输出错误
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
if ($notfield) {
|
||||
// 保留无权限的字段值
|
||||
foreach ($notfield as $t) {
|
||||
$save[1][$t] = $data['param'][$t];
|
||||
}
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('Site')->config(
|
||||
SITE_ID,
|
||||
'param',
|
||||
$save[1]
|
||||
);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站信息(#%s)不存在', SITE_ID));
|
||||
}
|
||||
// 附件归档
|
||||
if (SYS_ATTACHMENT_DB) {
|
||||
$attach && \Phpcmf\Service::M('Attachment')->handle($this->member['id'], \Phpcmf\Service::M()->dbprefix('site'), $attach);
|
||||
}
|
||||
foreach ($field as $t) {
|
||||
if (isset($post[$t['fieldname']])) {
|
||||
unset($post[$t['fieldname']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// config
|
||||
$config = \Phpcmf\Service::L('input')->post('data');
|
||||
$config['SITE_TONGJI'] = isset($_POST['data']['SITE_TONGJI']) ? trim($_POST['data']['SITE_TONGJI']) : '';
|
||||
// 防止参数丢失
|
||||
$config['SITE_CLOSE'] = $data['config']['SITE_CLOSE'];
|
||||
$config['SITE_INDEX_HTML'] = $data['config']['SITE_INDEX_HTML'];
|
||||
$config['SITE_CLOSE_MSG'] = $data['config']['SITE_CLOSE_MSG'];
|
||||
$config['SITE_LANGUAGE'] = $data['config']['SITE_LANGUAGE'];
|
||||
$config['SITE_TEMPLATE'] = $data['config']['SITE_TEMPLATE'];
|
||||
$config['SITE_TIMEZONE'] = $data['config']['SITE_TIMEZONE'];
|
||||
$config['SITE_TIME_FORMAT'] = $data['config']['SITE_TIME_FORMAT'];
|
||||
$config['SITE_THEME'] = $data['config']['SITE_THEME'];
|
||||
$rt = \Phpcmf\Service::M('Site')->config(SITE_ID, 'config', $config);
|
||||
if (!is_array($rt)) {
|
||||
$this->_json(0, dr_lang('网站信息(#%s)不存在', SITE_ID));
|
||||
}
|
||||
// 附件归档
|
||||
if (SYS_ATTACHMENT_DB) {
|
||||
list($post, $return, $attach) = \Phpcmf\Service::L('form')->validation($config, null, $logo);
|
||||
$attach && \Phpcmf\Service::M('Attachment')->handle($this->member['id'], \Phpcmf\Service::M()->dbprefix('site'), $attach);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('input')->system_log('设置网站自定义参数');
|
||||
\Phpcmf\Service::M('cache')->sync_cache('');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'网站信息' => ['module/site_param/index', 'fa fa-edit'],
|
||||
'自定义字段' => ['url:'.\Phpcmf\Service::L('Router')->url('field/index', ['rname' => 'site', 'rid' => SITE_ID]), 'fa fa-code'],
|
||||
'help' => [1125],
|
||||
]
|
||||
),
|
||||
'data' => $data['config'],
|
||||
'field' => $field,
|
||||
'myfield' => $field ? \Phpcmf\Service::L('Field')->toform(0, $field, $data['param']) : '',
|
||||
'mymerge' => $field ? \Phpcmf\Service::L('Field')->merge : '',
|
||||
'logofield' => dr_fieldform($logo['logo'], $data['config']['logo']),
|
||||
'my_site_info' => is_file(MYPATH.'View/site_info.html') ? MYPATH.'View/site_info.html' : '',
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->display('site_param.html');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,767 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
// URL规则
|
||||
class Urlrule extends \Phpcmf\Table
|
||||
{
|
||||
public $type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->type = array(
|
||||
//0 => dr_lang('自定义页面插件'),
|
||||
1 => dr_lang('独立模块'),
|
||||
2 => dr_lang('共享模块搜索'),
|
||||
3 => dr_lang('共享栏目和内容页'),
|
||||
//5 => dr_lang('模块表单'),
|
||||
);
|
||||
if (!dr_is_app('page')) {
|
||||
unset($this->type[0]);
|
||||
}
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'URL规则' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-link'],
|
||||
'添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
|
||||
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
'伪静态' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/rewrite_index', 'fa fa-cog'],
|
||||
'导入' => ['add:'.APP_DIR.'/urlrule/import_add', 'fa fa-sign-in', '60%', '70%'],
|
||||
'help' => [418],
|
||||
]
|
||||
),
|
||||
]);
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
$this->my_field = array(
|
||||
'name' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('名称'),
|
||||
'fieldname' => 'name',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// url显示名称
|
||||
$this->name = dr_lang('URL规则');
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'urlrule',
|
||||
'field' => $this->my_field,
|
||||
'order_by' => 'id desc',
|
||||
]);
|
||||
}
|
||||
|
||||
// 后台查看url列表
|
||||
public function index() {
|
||||
|
||||
$this->_List([], -1);
|
||||
\Phpcmf\Service::V()->assign('color', [
|
||||
0 => 'default',
|
||||
1 => 'info',
|
||||
2 => 'success',
|
||||
3 => 'warning',
|
||||
4 => 'danger',
|
||||
5 => '',
|
||||
6 => 'primary',
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('urlrule_index.html');
|
||||
}
|
||||
|
||||
// 伪静态
|
||||
public function rewrite_index() {
|
||||
|
||||
$domain = [];
|
||||
list($module, $site) = \Phpcmf\Service::M('Site')->domain();
|
||||
$domain[$site['site_domain']] = dr_lang('本站电脑域名');
|
||||
$site['mobile_domain'] && $domain[$site['mobile_domain']] = dr_lang('本站手机域名');
|
||||
if ($module) {
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($site['module_'.$dir]) {
|
||||
$domain[$site['module_'.$dir]] = dr_lang('%s电脑域名', $t['name']);
|
||||
}
|
||||
if ($site['module_mobile_'.$dir]) {
|
||||
$domain[$site['module_mobile_'.$dir]] = dr_lang('%s手机域名', $t['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$site = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
if ($site['client']) {
|
||||
foreach ($site['client'] as $t) {
|
||||
if ($t['domain']) {
|
||||
$domain[$t['domain']] = dr_lang('%s终端域名', $t['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($site['config']['SITE_DOMAIN'], '/') !== false) {
|
||||
list($a, $b) = explode('/', $site['config']['SITE_DOMAIN']);
|
||||
$root = '/'.$b;
|
||||
} else {
|
||||
$root = '';
|
||||
}
|
||||
$server = strtolower($_SERVER['SERVER_SOFTWARE']);
|
||||
if (strpos($server, 'apache') !== FALSE) {
|
||||
$name = 'Apache';
|
||||
$note = '<font color=red><b>'.dr_lang('将以下内容保存为.htaccess文件,放到每个域名所绑定的根目录').'</b></font>';
|
||||
$code = '';
|
||||
|
||||
// 子目录
|
||||
$code.= '###当存在多个子目录格式的域名时,需要多写几组RewriteBase标签:RewriteBase /目录/ '.PHP_EOL;
|
||||
if (isset($site['mobile']['mode']) && $site['mobile']['mode'] && $site['mobile']['dirname']) {
|
||||
$code.= 'RewriteEngine On'.PHP_EOL.PHP_EOL;
|
||||
$code.= 'RewriteBase /'.$site['mobile']['dirname'].'/'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ /'.$site['mobile']['dirname'].'/index.php [NC,L]'.PHP_EOL.PHP_EOL;
|
||||
$code.= '####以上目录需要单独保持到/'.$site['mobile']['dirname'].'/.htaccess文件中';
|
||||
}
|
||||
// 主目录
|
||||
$code.= 'RewriteEngine On'.PHP_EOL.PHP_EOL;
|
||||
$code.= 'RewriteBase '.$root.'/'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ '.$root.'/index.php [NC,L]'.PHP_EOL.PHP_EOL;
|
||||
} elseif (strpos($server, 'nginx') !== FALSE) {
|
||||
$name = $server;
|
||||
$note = '<font color=red><b>'.dr_lang('将以下代码放到Nginx配置文件中去(如果是绑定了域名,所绑定目录也要配置下面的代码)').'</b></font>';
|
||||
// 子目录
|
||||
$code = '###当存在多个子目录格式的域名时,需要多写几组location标签:location /目录/ '.PHP_EOL;
|
||||
if (isset($site['mobile']['mode']) && $site['mobile']['mode'] && $site['mobile']['dirname']) {
|
||||
$code.= 'location '.$root.'/'.$site['mobile']['dirname'].'/ { '.PHP_EOL
|
||||
.' if (-f $request_filename) {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if (!-e $request_filename) {'.PHP_EOL
|
||||
.' rewrite . '.$root.'/'.$site['mobile']['dirname'].'/index.php last;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.'}'.PHP_EOL.PHP_EOL;
|
||||
}
|
||||
// 主目录
|
||||
$code.= 'location '.$root.'/ { '.PHP_EOL
|
||||
.' if (-f $request_filename) {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if (!-e $request_filename) {'.PHP_EOL
|
||||
.' rewrite . '.$root.'/index.php last;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.'}'.PHP_EOL;
|
||||
} else {
|
||||
$name = $server;
|
||||
$note = '<font color=red><b>'.dr_lang('无法为此服务器提供伪静态规则,建议让运营商帮你把下面的Apache规则做转换').'</b></font>';
|
||||
$code = 'RewriteEngine On'.PHP_EOL
|
||||
.'RewriteBase /'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ /index.php [NC,L]';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
'note' => $note,
|
||||
'site' => $site,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'URL规则' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-link'],
|
||||
'伪静态' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/rewrite_index', 'fa fa-cog'],
|
||||
'help' => [21],
|
||||
]
|
||||
),
|
||||
'count' => $code ? dr_count(explode(PHP_EOL, $code)) : 0,
|
||||
'domain' => $domain,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('urlrule_rewrite.html');
|
||||
}
|
||||
|
||||
// 后台添加url内容
|
||||
public function add() {
|
||||
$this->_Post(0);
|
||||
\Phpcmf\Service::V()->display('urlrule_add.html');
|
||||
}
|
||||
|
||||
// 后台修改url内容
|
||||
public function edit() {
|
||||
$this->_Post(intval(\Phpcmf\Service::L('input')->get('id')));
|
||||
\Phpcmf\Service::V()->display('urlrule_add.html');
|
||||
}
|
||||
|
||||
// 复制url
|
||||
public function copy_edit() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$data = \Phpcmf\Service::M()->db->table('urlrule')->where('id', $id)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
unset($data['id']);
|
||||
$data['name'].= '_copy';
|
||||
|
||||
$rt = \Phpcmf\Service::M()->table('urlrule')->insert($data);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, dr_lang($rt['msg']));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('urlrule', 'module');
|
||||
$this->_json(1, dr_lang('复制成功'));
|
||||
}
|
||||
|
||||
// 保存
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
return parent::_Save($id, $data, $old, function($id, $data){
|
||||
// 保存前的格式化
|
||||
$type = (int)\Phpcmf\Service::L('input')->post('type');
|
||||
$value = \Phpcmf\Service::L('input')->post('value');
|
||||
if ($value[$type]) {
|
||||
foreach ($value[$type] as $i => $t) {
|
||||
if (strpos($t, '?') !== false) {
|
||||
$this->_json(0, dr_lang('URL规则中不能包含%s号', '?'));
|
||||
} elseif (strpos($t, '#') !== false) {
|
||||
$this->_json(0, dr_lang('URL规则中不能包含%s号', '#'));
|
||||
} elseif (strpos($t, '(')
|
||||
&& preg_match('/\{([a-z0-9_]+)\(\$data\)\}/iU', $t, $mt)) {
|
||||
if (!function_exists($mt[1])) {
|
||||
$this->_json(0, dr_lang('URL规则中函数%s未定义', $mt[1]));
|
||||
}
|
||||
}
|
||||
$value[$type][$i] = trim($t);
|
||||
}
|
||||
}
|
||||
$data[1]['type'] = $type;
|
||||
$join = \Phpcmf\Service::L('input')->post('catjoin');
|
||||
$value[$type]['catjoin'] = $join ? $join : '/';
|
||||
$data[1]['value'] = dr_array2string($value[$type]);
|
||||
return dr_return_data(1, 'ok', $data);
|
||||
}, function ($id, $data, $old) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('urlrule', 'module');
|
||||
});
|
||||
}
|
||||
|
||||
// 导出
|
||||
public function export_edit() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$data = \Phpcmf\Service::M()->table('urlrule')->get($id);
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('URL规则(%s)不存在', $id));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'data' => dr_array2string($data),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('api_export_code.html');exit;
|
||||
}
|
||||
|
||||
// 导入
|
||||
public function import_add() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$data = \Phpcmf\Service::L('input')->post('code');
|
||||
$data = dr_string2array($data);
|
||||
if (!is_array($data)) {
|
||||
$this->_json(0, dr_lang('导入信息验证失败'));
|
||||
} elseif (!$data['value']) {
|
||||
$this->_json(0, dr_lang('导入信息不完整'));
|
||||
}
|
||||
unset($data['id']);
|
||||
$rt = \Phpcmf\Service::M()->table('urlrule')->insert($data);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
\Phpcmf\Service::M('cache')->sync_cache('urlrule', 'module');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'data' => '',
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('api_export_code.html');
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
$data = parent::_Data($id);
|
||||
$data['value'] = dr_string2array($data['value']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 后台删除url内容
|
||||
public function del() {
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('input')->get_post_ids(),
|
||||
null,
|
||||
function ($r) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('urlrule', 'module');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 生成伪静态解析文件规则
|
||||
public function rewrite_add() {
|
||||
$rt = $this->get_rewrite_code();
|
||||
$this->_json($rt['code'], $rt['msg'], $rt['data']);
|
||||
}
|
||||
|
||||
// 生成伪静态解析代码
|
||||
private function get_rewrite_code() {
|
||||
|
||||
$data = \Phpcmf\Service::M()->table('urlrule')->getAll();
|
||||
if (!$data) {
|
||||
return dr_return_data(0, dr_lang('你没有设置URL规则'));
|
||||
}
|
||||
|
||||
$code = '';
|
||||
$error = '';
|
||||
$write = []; // 防止重复
|
||||
foreach ($data as $r) {
|
||||
$value = dr_string2array($r['value']);
|
||||
if ($r['type'] == 1) {
|
||||
// 独立模块
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----开始'.PHP_EOL;
|
||||
if ($value['module']) {
|
||||
$rule = $value['module'];
|
||||
$cname = "【".$r['name']."】模块首页({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rule = 'index.php?s=手动填写模块目录';
|
||||
} else {
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'];
|
||||
}
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname.'(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['list_page']) {
|
||||
$rule = $value['list_page'];
|
||||
$cname = "【".$r['name']."】模块栏目列表(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{page}'])) {
|
||||
$error.= "<p>".$cname."缺少{page}标签,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{dirname}']) && !isset($rname['{id}']) && !isset($rname['{pdirname}'])) {
|
||||
$error.= "<p>".$cname."缺少{dirname}或{id}或{pdirname}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
if (isset($rname['{dirname}'])) {
|
||||
// 目录格式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&dir=$'.$rname['{dirname}'].'&page=$'.$rname['{page}'];
|
||||
} elseif (isset($rname['{pdirname}'])) {
|
||||
// 层次目录格式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&dir=$'.$rname['{pdirname}'].'&page=$'.$rname['{page}'];
|
||||
} else {
|
||||
// id模式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&id=$'.$rname['{id}'].'&page=$'.$rname['{page}'];
|
||||
}
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname.'(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['list']) {
|
||||
$rule = $value['list'];
|
||||
$cname = "【".$r['name']."】模块栏目列表({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{dirname}']) && !isset($rname['{id}']) && !isset($rname['{pdirname}'])) {
|
||||
$error.= "<p>".$cname."缺少{dirname}或{id}或{pdirname}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
if (isset($rname['{dirname}'])) {
|
||||
// 目录格式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&dir=$'.$rname['{dirname}'];
|
||||
} elseif (isset($rname['{pdirname}'])) {
|
||||
// 层次目录格式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&dir=$'.$rname['{pdirname}'];
|
||||
} else {
|
||||
// id模式
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=category&id=$'.$rname['{id}'];
|
||||
}
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['show_page']) {
|
||||
$rule = $value['show_page'];
|
||||
$cname = "【".$r['name']."】模块内容页(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{id}'])) {
|
||||
$error.= "<p>".$cname."缺少{id}标签,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{page}'])) {
|
||||
$error.= "<p>".$cname."缺少{page}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=show&id=$'.$rname['{id}'].'&page=$'.$rname['{page}'];
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['show']) {
|
||||
$rule = $value['show'];
|
||||
$cname = "【".$r['name']."】模块内容页({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{id}'])) {
|
||||
$error.= "<p>".$cname."缺少{id}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=show&id=$'.$rname['{id}'];
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['search_page']) {
|
||||
$rule = $value['search_page'];
|
||||
$cname = "【".$r['name']."】模块搜索页(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{param}']) && !isset($rname['{rewrite}'])) {
|
||||
$error.= "<p>".$cname."缺少{param}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=search&rewrite=$'.($rname['{param}'] ? $rname['{param}'] : $rname['{rewrite}']);
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['search']) {
|
||||
$rule = $value['search'];
|
||||
$cname = "【".$r['name']."】模块搜索页({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (!isset($rname['{modname}'])) {
|
||||
$rname['{modname}'] = '{modname}';
|
||||
}
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=search';
|
||||
$rule = str_replace('${modname}', '手动填写模块目录', $rule);
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----结束'.PHP_EOL;
|
||||
} elseif ($r['type'] == 3 ) {
|
||||
// 共享栏目
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----开始'.PHP_EOL;
|
||||
if ($value['list_page']) {
|
||||
$rule = $value['list_page'];
|
||||
$cname = "【".$r['name']."】模块栏目列表(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{page}'])) {
|
||||
$error.= "<p>".$cname."缺少{page}标签,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{dirname}']) && !isset($rname['{id}']) && !isset($rname['{pdirname}'])) {
|
||||
$error.= "<p>".$cname."缺少{dirname}或{id}或{pdirname}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (isset($rname['{dirname}'])) {
|
||||
// 目录格式
|
||||
$rule = 'index.php?c=category&dir=$'.$rname['{dirname}'].'&page=$'.$rname['{page}'];
|
||||
} elseif (isset($rname['{pdirname}'])) {
|
||||
// 层次目录格式
|
||||
$rule = 'index.php?c=category&dir=$'.$rname['{pdirname}'].'&page=$'.$rname['{page}'];
|
||||
} else {
|
||||
// id模式
|
||||
$rule = 'index.php?c=category&id=$'.$rname['{id}'].'&page=$'.$rname['{page}'];
|
||||
}
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['list']) {
|
||||
$rule = $value['list'];
|
||||
$cname = "【".$r['name']."】模块栏目列表({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{dirname}']) && !isset($rname['{id}']) && !isset($rname['{pdirname}'])) {
|
||||
$error.= "<p>".$cname."缺少{dirname}或{id}或{pdirname}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
if (isset($rname['{dirname}'])) {
|
||||
// 目录格式
|
||||
$rule = 'index.php?c=category&dir=$'.$rname['{dirname}'];
|
||||
} elseif (isset($rname['{pdirname}'])) {
|
||||
// 层次目录格式
|
||||
$rule = 'index.php?c=category&dir=$'.$rname['{pdirname}'];
|
||||
} else {
|
||||
// id模式
|
||||
$rule = 'index.php?c=category&id=$'.$rname['{id}'];
|
||||
}
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['show_page']) {
|
||||
$rule = $value['show_page'];
|
||||
$cname = "【".$r['name']."】模块内容页(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{page}'])) {
|
||||
$error.= "<p>".$cname."缺少{page}标签,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{id}'])) {
|
||||
$error.= "<p>".$cname."缺少{id}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$rule = 'index.php?c=show&id=$'.$rname['{id}'].'&page=$'.$rname['{page}'];
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['show']) {
|
||||
$rule = $value['show'];
|
||||
$cname = "【".$r['name']."】模块内容页({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{id}'])) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$rule = 'index.php?c=show&id=$'.$rname['{id}'];
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----结束'.PHP_EOL;
|
||||
} elseif ($r['type'] == 2 ) {
|
||||
// 共享模块
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----开始'.PHP_EOL;
|
||||
if ($value['search_page']) {
|
||||
$rule = $value['search_page'];
|
||||
$cname = "【".$r['name']."】模块搜索页(分页)({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{modname}'])) {
|
||||
$error.= "<p>".$cname."缺少{modname}标签,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{param}'])) {
|
||||
$error.= "<p>".$cname."缺少{param}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=search&rewrite=$'.$rname['{param}'];
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($value['search']) {
|
||||
$rule = $value['search'];
|
||||
$cname = "【".$r['name']."】模块搜索页({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{modname}'])) {
|
||||
$error.= "<p>".$cname."缺少{modname}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$rule = 'index.php?s=$'.$rname['{modname}'].'&c=search';
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----结束'.PHP_EOL;
|
||||
} elseif ($r['type'] == 4 ) {
|
||||
// 关键词库插件
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----开始'.PHP_EOL;
|
||||
if ($value['tag']) {
|
||||
$rule = $value['tag'];
|
||||
$cname = "【".$r['name']."】TagURL({$rule})";
|
||||
list($preg, $rname) = $this->_rule_preg_value($rule);
|
||||
if (!$preg || !$rname) {
|
||||
$error.= "<p>".$cname."无法识别,需要手动写解析规则</p>";
|
||||
} elseif (!isset($rname['{tag}'])) {
|
||||
$error.= "<p>".$cname."缺少{tag}标签,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$rule = 'index.php?s=tag&name=$'.$rname['{tag}'];
|
||||
if (isset($write[$preg])) {
|
||||
$error.= "<p>".$cname."与".$write[$preg]."规则存在冲突,需要手动写解析规则</p>";
|
||||
} else {
|
||||
$write[$preg] = $cname;
|
||||
$code.= '<textarea class="form-control" rows="1"> "'.$preg.'" => "'.$rule.'", //'.$cname."(此规则由系统生成,不一定会准确,请开发者自行调整)</textarea>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$code.= PHP_EOL.' // '.$r['name'].'---解析规则----结束'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data(1, dr_lang('生成成功'), [
|
||||
'code' => nl2br($code),
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// 正则解析
|
||||
private function _rule_preg_value($rule) {
|
||||
|
||||
$rule = trim(trim($rule, '/'));
|
||||
|
||||
if (preg_match_all('/\{(.*)\}/U', $rule, $match)) {
|
||||
|
||||
$value = [];
|
||||
foreach ($match[0] as $k => $v) {
|
||||
$value[$v] = ($k + 1);
|
||||
}
|
||||
|
||||
$preg = preg_replace(
|
||||
[
|
||||
'#\{id\}#U',
|
||||
'#\{uid\}#U',
|
||||
'#\{mid\}#U',
|
||||
'#\{fid\}#U',
|
||||
'#\{page\}#U',
|
||||
|
||||
'#\{pdirname\}#Ui',
|
||||
'#\{dirname\}#Ui',
|
||||
'#\{opdirname\}#Ui',
|
||||
'#\{otdirname\}#Ui',
|
||||
'#\{modname\}#Ui',
|
||||
'#\{name\}#Ui',
|
||||
|
||||
'#\{tag\}#U',
|
||||
'#\{param\}#U',
|
||||
'#\{rewrite\}#U',
|
||||
|
||||
'#\{y\}#U',
|
||||
'#\{m\}#U',
|
||||
'#\{d\}#U',
|
||||
|
||||
'#\{\.+}#U',
|
||||
'#/#'
|
||||
],
|
||||
[
|
||||
'([0-9]+)',
|
||||
'([0-9]+)',
|
||||
'(\d+)',
|
||||
'(\w+)',
|
||||
'([0-9]+)',
|
||||
|
||||
'([\w\/]+)',
|
||||
'([A-za-z0-9 \-\_]+)',
|
||||
'([A-za-z0-9 \-\_]+)',
|
||||
'([A-za-z0-9 \-\_]+)',
|
||||
'([a-z]+)',
|
||||
'([a-z]+)',
|
||||
|
||||
'(.+)',
|
||||
'(.+)',
|
||||
'(.+)',
|
||||
|
||||
'([0-9]{4})',
|
||||
'([0-9]{2})',
|
||||
'([0-9]{2})',
|
||||
|
||||
'(.+)',
|
||||
'\/'
|
||||
],
|
||||
$rule
|
||||
);
|
||||
|
||||
// 替换特殊的结果
|
||||
$preg = str_replace(
|
||||
['(.+))}-', '.html'],
|
||||
['(.+)-', '\.html'],
|
||||
$preg
|
||||
);
|
||||
|
||||
return [$preg, $value];
|
||||
}
|
||||
|
||||
return [$rule, []];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
class Urlrule_code extends \Phpcmf\App
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$domain = [];
|
||||
list($module, $site) = \Phpcmf\Service::M('Site')->domain();
|
||||
$domain[$site['site_domain']] = dr_lang('本站电脑域名');
|
||||
$site['mobile_domain'] && $domain[$site['mobile_domain']] = dr_lang('本站手机域名');
|
||||
if ($module) {
|
||||
foreach ($module as $dir => $t) {
|
||||
if ($site['module_'.$dir]) {
|
||||
$domain[$site['module_'.$dir]] = dr_lang('%s电脑域名', $t['name']);
|
||||
}
|
||||
if ($site['module_mobile_'.$dir]) {
|
||||
$domain[$site['module_mobile_'.$dir]] = dr_lang('%s手机域名', $t['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$site = \Phpcmf\Service::M('Site')->config(SITE_ID);
|
||||
if ($site['client']) {
|
||||
foreach ($site['client'] as $t) {
|
||||
if ($t['domain']) {
|
||||
$domain[$t['domain']] = dr_lang('%s终端域名', $t['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strpos($site['config']['SITE_DOMAIN'], '/') !== false) {
|
||||
list($a, $b) = explode('/', $site['config']['SITE_DOMAIN']);
|
||||
$root = '/'.$b;
|
||||
} else {
|
||||
$root = '';
|
||||
}
|
||||
$server = strtolower($_SERVER['SERVER_SOFTWARE']);
|
||||
if (strpos($server, 'apache') !== FALSE) {
|
||||
$name = 'Apache';
|
||||
$note = '<font color=red><b>将以下内容保存为.htaccess文件,放到每个域名所绑定的根目录</b></font>';
|
||||
$code = '';
|
||||
|
||||
// 子目录
|
||||
$code.= '###当存在多个子目录格式的域名时,需要多写几组RewriteBase标签:RewriteBase /目录/ '.PHP_EOL;
|
||||
if (isset($site['mobile']['mode']) && $site['mobile']['mode'] && $site['mobile']['dirname']) {
|
||||
$code.= 'RewriteEngine On'.PHP_EOL.PHP_EOL;
|
||||
$code.= 'RewriteBase /'.$site['mobile']['dirname'].'/'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ /'.$site['mobile']['dirname'].'/index.php [NC,L]'.PHP_EOL.PHP_EOL;
|
||||
$code.= '####以上目录需要单独保持到/'.$site['mobile']['dirname'].'/.htaccess文件中';
|
||||
}
|
||||
// 主目录
|
||||
$code.= 'RewriteEngine On'.PHP_EOL.PHP_EOL;
|
||||
$code.= 'RewriteBase '.$root.'/'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ '.$root.'/index.php [NC,L]'.PHP_EOL.PHP_EOL;
|
||||
} elseif (strpos($server, 'nginx') !== FALSE) {
|
||||
$name = $server;
|
||||
$note = '<font color=red><b>将以下代码放到Nginx配置文件中去(如果是绑定了域名,所绑定目录也要配置下面的代码)</b></font>';
|
||||
// 子目录
|
||||
$code = '###当存在多个子目录格式的域名时,需要多写几组location标签:location /目录/ '.PHP_EOL;
|
||||
if (isset($site['mobile']['mode']) && $site['mobile']['mode'] && $site['mobile']['dirname']) {
|
||||
$code.= 'location '.$root.'/'.$site['mobile']['dirname'].'/ { '.PHP_EOL
|
||||
.' if (-f $request_filename) {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if (!-e $request_filename) {'.PHP_EOL
|
||||
.' rewrite . '.$root.'/'.$site['mobile']['dirname'].'/index.php last;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.'}'.PHP_EOL.PHP_EOL;
|
||||
}
|
||||
// 主目录
|
||||
$code.= 'location '.$root.'/ { '.PHP_EOL
|
||||
.' if (-f $request_filename) {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {'.PHP_EOL
|
||||
.' break;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.' if (!-e $request_filename) {'.PHP_EOL
|
||||
.' rewrite . '.$root.'/index.php last;'.PHP_EOL
|
||||
.' }'.PHP_EOL
|
||||
.'}'.PHP_EOL;
|
||||
} else {
|
||||
$name = $server;
|
||||
$note = '<font color=red><b>无法为此服务器提供伪静态规则,建议让运营商帮你把下面的Apache规则做转换</b></font>';
|
||||
$code = 'RewriteEngine On'.PHP_EOL
|
||||
.'RewriteBase /'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-f'.PHP_EOL
|
||||
.'RewriteCond %{REQUEST_FILENAME} !-d'.PHP_EOL
|
||||
.'RewriteRule !.(js|ico|gif|jpe?g|bmp|png|css)$ /index.php [NC,L]';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
'note' => $note,
|
||||
'domain' => $domain,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'伪静态代码' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-link'],
|
||||
]
|
||||
),
|
||||
'count' => $code ? dr_count(explode(PHP_EOL, $code)) : 0,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('urlrule_code.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user