Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,479 @@
|
||||
<?php namespace Phpcmf\Admin;
|
||||
|
||||
// 内容模块表单操作类 基于 Ftable
|
||||
class Mform extends \Phpcmf\Table
|
||||
{
|
||||
public $cid; // 内容id
|
||||
public $index; //
|
||||
public $form; // 表单信息
|
||||
public $is_verify; // 判断是否来自审核控制器
|
||||
protected $is_add_menu = 1; //允许有添加菜单
|
||||
|
||||
// 上级公共类
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->_Extend_Init();
|
||||
$this->fix_admin_tpl_path = dr_get_app_dir('mform').'Views/';
|
||||
}
|
||||
|
||||
// 继承类初始化
|
||||
protected function _Extend_Init() {
|
||||
// 初始化模块
|
||||
$this->_module_init(APP_DIR);
|
||||
// 判断是否来自审核控制器
|
||||
$this->is_verify = strpos(\Phpcmf\Service::L('Router')->class, '_verify') !== false;
|
||||
// 判断表单是否操作
|
||||
$this->form = $this->module['form'][str_replace('_verify', '',\Phpcmf\Service::L('Router')->class)];
|
||||
if (!$this->form) {
|
||||
$this->_admin_msg(0, dr_lang('模块表单【%s】不存在', str_replace('_verify', '',\Phpcmf\Service::L('Router')->class)));
|
||||
}
|
||||
// 支持附表存储
|
||||
$this->is_data = 1;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->tpl_prefix = 'share_mform_';
|
||||
// 单独模板命名
|
||||
$this->tpl_name = $this->form['table'];
|
||||
// 模块显示名称
|
||||
$this->name = dr_lang('内容模块[%s]表单(%s)', APP_DIR, $this->form['name']);
|
||||
// 获取父级内容
|
||||
$this->url_params['cid'] = $this->cid = intval(\Phpcmf\Service::L('input')->get('cid'));
|
||||
$this->index = $this->cid ? $this->content_model->get_data( $this->cid) : [];
|
||||
// 自定义条件
|
||||
$where = $this->is_verify ? 'status<>1' : 'status=1';
|
||||
$this->cid && $where.= ' and cid='. $this->cid;
|
||||
$cwhere = $this->content_model->get_admin_list_where();
|
||||
$cwhere && $where.= ' AND '. $cwhere;
|
||||
$sysfield = ['inputtime', 'inputip', 'displayorder', 'uid', 'status'];
|
||||
if ($this->is_verify) {
|
||||
if (is_array($this->form['setting']['list_field'])) {
|
||||
$this->form['setting']['list_field']['status'] = [
|
||||
'use' => '1', // 1是显示,0是不显示
|
||||
'name' => dr_lang('状态'), //显示名称
|
||||
'width' => '100', // 显示宽度
|
||||
'func' => 'dr_mform_status_name', // 回调函数见:http://help.xunruicms.com/463.html
|
||||
'center' => '1', // 1是居中,0是默认
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'field' => $this->form['field'],
|
||||
'table' => SITE_ID.'_'.APP_DIR.'_form_'.$this->form['table'],
|
||||
'sys_field' => $sysfield,
|
||||
'date_field' => $this->form['setting']['search_time'] ? $this->form['setting']['search_time'] : 'inputtime',
|
||||
'show_field' => 'title',
|
||||
'list_field' => $this->form['setting']['list_field'],
|
||||
'order_by' => $this->form['setting']['order'] ? dr_safe_replace($this->form['setting']['order']) : 'displayorder DESC,inputtime DESC',
|
||||
'where_list' => $where,
|
||||
]);
|
||||
|
||||
// 写入模板
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => $this->_get_menu(),
|
||||
'mform' => $this->form,
|
||||
'index' => $this->index,
|
||||
'field' => $this->init['field'],
|
||||
'form_url' => \Phpcmf\Service::L('Router')->url(APP_DIR.'/'.$this->form['table'].'/index', ['cid' => $this->cid]),
|
||||
'is_verify' => $this->is_verify,
|
||||
'form_table' => $this->form['table'],
|
||||
]);
|
||||
|
||||
if ($this->module['setting']['is_hide_search_bar']) {
|
||||
$this->is_show_search_bar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected function _get_menu() {
|
||||
if ($this->is_verify) {
|
||||
if ($this->cid) {
|
||||
$menu = [
|
||||
dr_lang('%s管理', $this->module['name']) => [MOD_DIR.'/home/index', dr_icon($this->module['setting']['icon'])],
|
||||
dr_lang('%s管理', $this->form['name']) => [MOD_DIR.'/'.$this->form['table'].'/index{cid='.$this->cid.'}', dr_icon($this->form['setting']['icon'])],
|
||||
dr_lang('%s审核', $this->form['name']) => [MOD_DIR.'/'.$this->form['table'].'_verify/index{cid='.$this->cid.'}', dr_icon($this->form['setting']['icon'])],
|
||||
];
|
||||
} else {
|
||||
$menu = [
|
||||
dr_lang('%s审核', $this->form['name']) => [MOD_DIR.'/'.$this->form['table'].'/index', 'fa fa-edit'],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$menu = [
|
||||
dr_lang('%s管理', $this->module['name']) => [MOD_DIR.'/home/index', dr_icon($this->module['setting']['icon'])],
|
||||
dr_lang('%s管理', $this->form['name']) => [MOD_DIR.'/'.$this->form['table'].'/index{cid='.$this->cid.'}', dr_icon($this->form['setting']['icon'])],
|
||||
dr_lang('%s审核', $this->form['name']) => [MOD_DIR.'/'.$this->form['table'].'_verify/index{cid='.$this->cid.'}', dr_icon($this->form['setting']['icon'])],
|
||||
];
|
||||
if ($this->cid && $this->is_add_menu) {
|
||||
$menu[dr_lang('添加')] = [APP_DIR.'/'.$this->form['table'].'/add{cid='.$this->cid.'}', 'fa fa-plus'];
|
||||
$menu[dr_lang('修改')] = ['hide:'.APP_DIR.'/'.$this->form['table'].'/edit', 'fa fa-edit'];
|
||||
}
|
||||
}
|
||||
return \Phpcmf\Service::M('auth')->_admin_menu($menu);
|
||||
}
|
||||
|
||||
// ========================
|
||||
|
||||
// 后台查看列表
|
||||
protected function _Admin_List() {
|
||||
|
||||
$this->init['table'] = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
list($tpl) = $this->_List(['cid' => $this->cid]);
|
||||
|
||||
if ($this->_is_admin_auth('edit')) {
|
||||
if ($this->is_verify) {
|
||||
} else {
|
||||
$this->mytable['link_var'].= 'html = html.replace(/\{cid\}/g, "'.$this->index['id'].'");';
|
||||
$this->mytable['link_var'].= 'html = html.replace(/\{mid\}/g, "'.APP_DIR.'");';
|
||||
$this->mytable['link_var'].= 'html = html.replace(/\{fid\}/g, "'.$this->form['table'].'");';
|
||||
$clink = $this->_app_clink('mform');
|
||||
if ($clink) {
|
||||
foreach ($clink as $a) {
|
||||
if ($a['model'] && $a['check']
|
||||
&& method_exists($a['model'], $a['check'])
|
||||
&& call_user_func(array($a['model'], $a['check']), APP_DIR, []) == 0) {
|
||||
continue;
|
||||
}
|
||||
$this->mytable['link_tpl'].= ' <label><a class="btn '.$a['color'].' btn-xs" href="'.$a['url'].'"><i class="'.$a['icon'].'"></i> '.dr_lang($a['name']);
|
||||
if ($a['field'] && \Phpcmf\Service::M()->is_field_exists($this->init['table'], $a['field'])) {
|
||||
$this->mytable['link_tpl'].= '({'.$a['field'].'})';
|
||||
$this->mytable['link_var'].= 'html = html.replace(/\{'.$a['field'].'\}/g, row.'.$a['field'].');';
|
||||
}
|
||||
$this->mytable['link_tpl'].= '</a></label>';
|
||||
}
|
||||
}
|
||||
|
||||
$cbottom = $this->_app_cbottom('mform');
|
||||
if ($cbottom) {
|
||||
$this->mytable['foot_tpl'].= '<label>
|
||||
<div class="btn-group dropup">
|
||||
<a class="btn blue btn-sm dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true" aria-expanded="false" href="javascript:;"> '.dr_lang('批量').'
|
||||
<i class="fa fa-angle-up"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu">';
|
||||
foreach ($cbottom as $a) {
|
||||
$this->mytable['foot_tpl'].= '<li>
|
||||
<a href="'.urldecode($a['url']).'"> <i class="'.$a['icon'].'"></i> '.dr_lang($a['name']).' </a>
|
||||
</li>';
|
||||
}
|
||||
$this->mytable['foot_tpl'].= '
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</label>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mytable' => $this->mytable,
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'p' => ['cid' => $this->cid],
|
||||
]);
|
||||
return \Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 后台添加内容
|
||||
protected function _Admin_Add() {
|
||||
|
||||
if (!$this->cid) {
|
||||
$this->_admin_msg(0, dr_lang('缺少cid参数'));
|
||||
}
|
||||
|
||||
list($tpl) = $this->_Post(0);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 后台修改内容
|
||||
protected function _Admin_Edit() {
|
||||
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
list($tpl, $data) = $this->_Post($id);
|
||||
|
||||
|
||||
if (!$this->cid) {
|
||||
$this->_admin_msg(0, dr_lang('缺少cid参数'));
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据不存在: '.$id));
|
||||
} elseif ($this->cid != $data['cid']) {
|
||||
$this->_admin_msg(0, dr_lang('cid不匹配'));
|
||||
} elseif ($this->is_verify && $data['status'] == 1) {
|
||||
$this->_admin_msg(0, dr_lang('已经通过了审核'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 后台查看内容
|
||||
protected function _Admin_Show() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
list($tpl, $data) = $this->_Show($id);
|
||||
|
||||
if (!$this->cid) {
|
||||
$this->_admin_msg(0, dr_lang('缺少cid参数'));
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('数据不存在: '.$id));
|
||||
} elseif ($this->cid != $data['cid']) {
|
||||
$this->_admin_msg(0, dr_lang('cid不匹配'));
|
||||
} elseif ($this->is_verify && $data['status']) {
|
||||
$this->_admin_msg(0, dr_lang('已经通过了审核'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 后台批量保存排序值
|
||||
protected function _Admin_Order() {
|
||||
$this->_Display_Order(
|
||||
intval(\Phpcmf\Service::L('input')->get('id')),
|
||||
intval(\Phpcmf\Service::L('input')->get('value')),
|
||||
function ($t) {
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $t['cid']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
\Phpcmf\Service::M()->table($table)->update($t['id'], ['displayorder' => $value]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 后台删除内容
|
||||
protected function _Admin_Del() {
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('input')->get_post_ids(),
|
||||
null,
|
||||
function ($rows) {
|
||||
// 对应删除提醒
|
||||
foreach ($rows as $t) {
|
||||
\Phpcmf\Service::M('member')->delete_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$t['cid'].'/id/'.$t['id'], SITE_ID);// clear
|
||||
\Phpcmf\Service::L('cache')->clear('module_'.MOD_DIR.'_from_'.$this->form['table'].'_show_id_'.$t['id']);
|
||||
// 统计数量
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total($t['cid'], $this->form['table']);
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $t['cid']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
\Phpcmf\Service::M()->table($table)->delete($t['id']);
|
||||
}
|
||||
}
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
// 后台批量审核
|
||||
protected function _Admin_Status() {
|
||||
|
||||
$tid = intval(\Phpcmf\Service::L('input')->get('tid'));
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('所选数据不存在'));
|
||||
}
|
||||
|
||||
// 格式化
|
||||
$in = [];
|
||||
foreach ($ids as $i) {
|
||||
$i && $in[] = intval($i);
|
||||
}
|
||||
if (!$in) {
|
||||
$this->_json(0, dr_lang('所选数据不存在'));
|
||||
}
|
||||
|
||||
$rows = \Phpcmf\Service::M()->db->table($this->init['table'])->whereIn('id', $in)->get()->getResultArray();
|
||||
if (!$rows) {
|
||||
$this->_json(0, dr_lang('所选数据不存在'));
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['status'] != 1) {
|
||||
if ($tid) {
|
||||
// 拒绝
|
||||
$this->_verify_refuse($row);
|
||||
} else {
|
||||
// 通过
|
||||
$this->_verify($row);
|
||||
}
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total($row['cid'], $this->form['table']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
// ===========================
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
|
||||
$row = $this->content_model->get_form_row($id, $this->form['table']);
|
||||
if (!$row) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->cid = $row['cid'];
|
||||
if (!$this->index) {
|
||||
$this->index = $this->content_model->get_data($row['cid']);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => $this->_get_menu(),
|
||||
'index' => $this->index,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
// 格式化保存数据 保存之前
|
||||
protected function _Format_Data($id, $data, $old) {
|
||||
|
||||
// 验证父数据
|
||||
if (!$this->index) {
|
||||
$this->_json(0, dr_lang('关联内容不存在'));
|
||||
}
|
||||
|
||||
// 默认数据
|
||||
$data[1]['uid'] = intval($data[1]['uid']);
|
||||
$data[0]['uid'] = (int)$data[1]['uid'];
|
||||
$data[1]['cid'] = $data[0]['cid'] = $this->cid;
|
||||
$data[1]['catid'] = $data[0]['catid'] = (int)$this->index['catid'];
|
||||
|
||||
// 后台添加时默认通过
|
||||
if (!$id) {
|
||||
// !$this->is_verify &&
|
||||
$data[1]['status'] = 1;
|
||||
$data[1]['tableid'] = 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
* $id 内容id,新增为0
|
||||
* $data 提交内容数组,留空为自动获取
|
||||
* $func 格式化提交的数据
|
||||
* */
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
|
||||
return parent::_Save($id, $data, $old, null,
|
||||
function ($id, $data, $old) {
|
||||
if ($this->is_verify) {
|
||||
if ($data[1]['status'] == 1) {
|
||||
// 审核通过时
|
||||
$data[1]['status'] = 0;
|
||||
$this->_verify($data[1]);
|
||||
} elseif ($data[1]['status'] == 2) {
|
||||
$data[1]['status'] = 0;
|
||||
$this->_verify_refuse($data[1]);
|
||||
}
|
||||
}
|
||||
// 保存之后的更新total字段
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total( $this->cid, $this->form['table']);
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$old['cid'].'/id/'.$old['id'], SITE_ID);
|
||||
// clear
|
||||
\Phpcmf\Service::L('cache')->clear('module_'.MOD_DIR.'_from_'.$this->form['table'].'_show_id_'.$id);
|
||||
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
\Phpcmf\Service::M()->table($table)->replace($data[1]);
|
||||
}
|
||||
|
||||
$row = dr_array2array($data[1], $data[0]);
|
||||
$row['index'] = $this->index;
|
||||
if (!$old) {
|
||||
// 挂钩点
|
||||
\Phpcmf\Hooks::trigger('module_form_post_after', $row);
|
||||
} else {
|
||||
\Phpcmf\Hooks::trigger('module_form_edit_after', $row, $old);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 审核拒绝
|
||||
protected function _verify_refuse($row) {
|
||||
|
||||
if ($row['status'] == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$row['form'] = $this->form;
|
||||
$row['index'] = $this->index;
|
||||
$row['module'] = $this->module;
|
||||
\Phpcmf\Service::M()->db->table($this->init['table'])->where('id', $row['id'])->update(['status' => 2]);
|
||||
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
\Phpcmf\Service::M()->table($table)->update($row['id'], ['status' => 2]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$row['cid'].'/id/'.$row['id'], SITE_ID);
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_verify_0', $row);
|
||||
}
|
||||
|
||||
// 审核通过
|
||||
protected function _verify($row) {
|
||||
|
||||
if ($row['status'] == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
// 增减金币
|
||||
$score = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'score', $this->member);
|
||||
$score && \Phpcmf\Service::M('member')->add_score($row['uid'], $score, dr_lang('%s: %s发布', MODULE_NAME, $this->form['name']), $row['curl']);
|
||||
|
||||
// 增减经验
|
||||
$exp = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'exp', $this->member);
|
||||
$exp && \Phpcmf\Service::M('member')->add_experience($row['uid'], $exp, dr_lang('%s: %s发布', MODULE_NAME, $this->form['name']), $row['curl']);
|
||||
*/
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$row['cid'].'/id/'.$row['id'], SITE_ID);
|
||||
|
||||
\Phpcmf\Service::M()->db->table($this->init['table'])->where('id', $row['id'])->update(['status' => 1]);
|
||||
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
\Phpcmf\Service::M()->table($table)->update($row['id'], ['status' => 1]);
|
||||
}
|
||||
|
||||
if (!$this->index) {
|
||||
$this->index = $this->content_model->get_data($row['cid']);
|
||||
}
|
||||
|
||||
|
||||
$row['form'] = $this->form;
|
||||
$row['index'] = $this->index;
|
||||
$row['module'] = $this->module;
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_verify_1', $row);
|
||||
|
||||
$row['muid'] = $row['uid'];
|
||||
$row['uid'] = $this->index['uid'];
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_verify_2', $row);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
<?php namespace Phpcmf\Home;
|
||||
|
||||
/**
|
||||
* http://www.xunruicms.com
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
// 内容模块表单操作类 基于 Ftable
|
||||
class Mform extends \Phpcmf\Table
|
||||
{
|
||||
public $cid; // 内容id
|
||||
public $form; // 表单信息
|
||||
public $index; // 模块内容信息
|
||||
|
||||
// 上级公共类
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->_Extend_Init();
|
||||
}
|
||||
|
||||
// 继承类初始化
|
||||
protected function _Extend_Init() {
|
||||
// 初始化模块
|
||||
$this->_module_init(APP_DIR);
|
||||
|
||||
// 判断表单是否操作
|
||||
$this->form = $this->module['form'][\Phpcmf\Service::L('Router')->class];
|
||||
if (!$this->form) {
|
||||
$this->_msg(0, dr_lang('模块表单【%s】不存在',\Phpcmf\Service::L('Router')->class));
|
||||
}
|
||||
|
||||
// 支持附表存储
|
||||
$this->is_data = 1;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->tpl_name = $this->form['table'];
|
||||
$this->tpl_prefix = 'mform_';
|
||||
// 预留cid
|
||||
$this->cid = intval(\Phpcmf\Service::L('input')->get('cid'));
|
||||
\Phpcmf\Service::V()->module(MOD_DIR);
|
||||
}
|
||||
|
||||
// ========================
|
||||
|
||||
// 内容列表
|
||||
protected function _Home_List() {
|
||||
|
||||
// 无权限访问表单
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'show', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无权限访问表单'), $this->uid ? '' : dr_member_url('login/index'));
|
||||
return;
|
||||
}*/
|
||||
|
||||
// 获取父级内容
|
||||
$this->index = $this->_Module_Row($this->cid);
|
||||
if (!$this->index) {
|
||||
$this->_msg(0, dr_lang('模块内容【id#%s】不存在', $this->cid));
|
||||
}
|
||||
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['cid']),
|
||||
'field' => $this->form['field'],
|
||||
'show_field' => 'title'
|
||||
]);
|
||||
|
||||
// 写入模板
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form_name' => $this->form['name'],
|
||||
'form_table' => $this->form['table'],
|
||||
]);
|
||||
|
||||
// seo
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'meta_title' => dr_lang($this->form['name']).SITE_SEOJOIN.$this->index['title'],
|
||||
'meta_keywords' => $this->index['keywords'],
|
||||
'meta_description' => $this->index['description'],
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'index' => $this->index,
|
||||
'catid' => intval($this->index['catid']),
|
||||
'markid' => 'module-'.MOD_DIR.'-'.intval($this->index['catid']),
|
||||
'urlrule' =>\Phpcmf\Service::L('Router')->mform_list_url($this->form['table'], $this->index['id'], MOD_DIR, '[page]'),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($this->_tpl_filename('list'));
|
||||
}
|
||||
|
||||
// 添加内容
|
||||
protected function _Home_Post() {
|
||||
|
||||
if ($this->form['setting']['is_close_post']) {
|
||||
$this->_msg(0, dr_lang('禁止前端提交表单'));
|
||||
}
|
||||
|
||||
// 无权限访问表单
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'add', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无发布权限'), $this->uid ? '' : dr_member_url('login/index'));
|
||||
return;
|
||||
}*/
|
||||
|
||||
// 判断会员权限
|
||||
//$this->member && $this->_member_option(0);
|
||||
|
||||
// 是否有验证码
|
||||
$this->is_post_code = $this->form['setting']['is_post_code'] ? 0 : 1;
|
||||
|
||||
// 获取父级内容
|
||||
$this->index = $this->_Module_Row($this->cid);
|
||||
if (!$this->index) {
|
||||
$this->_msg(0, dr_lang('所属主题【cid#%s】不存在', $this->cid));
|
||||
};
|
||||
|
||||
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['cid']),
|
||||
'field' => $this->form['field'],
|
||||
'show_field' => 'title'
|
||||
]);
|
||||
list($tpl) = $this->_Post(0);
|
||||
|
||||
// seo
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'meta_title' => dr_lang($this->form['name']).SITE_SEOJOIN.$this->index['title'],
|
||||
'meta_keywords' => $this->index['keywords'],
|
||||
'meta_description' => $this->index['description'],
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'index' => $this->index,
|
||||
'catid' => intval($this->index['catid']),
|
||||
'markid' => 'module-'.MOD_DIR.'-'.intval($this->index['catid']),
|
||||
'rt_url' => $this->form['setting']['rt_url'] ? '' : dr_now_url(),
|
||||
'is_post_code' => $this->is_post_code,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 显示内容
|
||||
protected function _Home_Show() {
|
||||
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'show', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无权限访问表单'), $this->uid ? '' : dr_member_url('login/index'));
|
||||
return;
|
||||
}*/
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$name = 'module_'.MOD_DIR.'_form_'.$this->form['table'].'_show_id_'.$id;
|
||||
$cache = \Phpcmf\Service::L('cache')->get_data($name);
|
||||
if (!$cache) {
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => dr_mform_ctable(APP_DIR, $this->form['table'], 0),
|
||||
'field' => $this->form['field'],
|
||||
'show_field' => 'title'
|
||||
]);
|
||||
list($tpl, $data) = $this->_Show($id);
|
||||
if (!$data) {
|
||||
$this->_msg(0, dr_lang('表单内容【id#%s】不存在', $id));
|
||||
}
|
||||
// 获取父级内容
|
||||
$this->cid = intval($data['cid']);
|
||||
$this->index = $this->_Module_Row($this->cid);
|
||||
if (!$this->index) {
|
||||
$this->_msg(0, dr_lang('模块内容【id#%s】不存在', $this->cid));
|
||||
}
|
||||
// 模块的处理
|
||||
$data = $this->_Call_Show($data);
|
||||
$cache = [
|
||||
$tpl,
|
||||
$data,
|
||||
$this->cid,
|
||||
$this->index,
|
||||
];
|
||||
// 缓存结果
|
||||
if ($data['uid'] != $this->uid && SYS_CACHE) {
|
||||
if ($this->member && $this->member['is_admin']) {
|
||||
// 管理员时不进行缓存
|
||||
\Phpcmf\Service::L('cache')->init()->delete($name);
|
||||
} else {
|
||||
\Phpcmf\Service::L('cache')->set_data($name, $cache, SYS_CACHE_SHOW * 3600);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list($tpl, $data, $this->cid, $this->index) = $cache;
|
||||
}
|
||||
|
||||
// 无权限访问表单
|
||||
if ($this->form['setting']['is_read'] && !in_array($this->uid, [$data['uid'], $this->index['uid']])) {
|
||||
$this->_msg(0, dr_lang('无权限访问表单'));
|
||||
}
|
||||
|
||||
if ($data['status'] != 1) {
|
||||
$this->_msg(0, dr_lang('内容正在审核中'));
|
||||
}
|
||||
|
||||
$data['cat'] = [];
|
||||
if (isset($data['catid']) && $data['catid']) {
|
||||
$data['cat'] = dr_cat_value($this->module['mid'], $data['catid']);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign($data);
|
||||
|
||||
$data['cat'] = [];
|
||||
$data['catname'] = $data['catpname'] = '';
|
||||
if (isset($data['catid']) && $data['catid']) {
|
||||
$data['cat'] = dr_cat_value($this->module['mid'], $data['catid']);
|
||||
$data['catname'] = $data['cat']['name'];
|
||||
$data['catpname'] = dr_get_cat_pname($this->module, $data['catid'], SITE_SEOJOIN);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
$data['formname'] = dr_lang($this->form['name']);
|
||||
$data['modulename'] = $data['modname'] = dr_lang($this->module['name']);
|
||||
|
||||
// seo
|
||||
\Phpcmf\Service::V()->assign(\Phpcmf\Service::L('Seo')->get_seo_value($data, [
|
||||
'meta_title' => isset($this->form['setting']['seo']['title']) && $this->form['setting']['seo']['title'] ? $this->form['setting']['seo']['title'] : $data['title'].SITE_SEOJOIN.dr_lang($this->form['name']),
|
||||
'meta_keywords' => isset($this->form['setting']['seo']['keywords']) && $this->form['setting']['seo']['keywords'] ? $this->form['setting']['seo']['keywords'] : $data['title'].SITE_SEOJOIN.dr_lang($this->form['name']),
|
||||
'meta_description' => isset($this->form['setting']['seo']['description']) && $this->form['setting']['seo']['description'] ? $this->form['setting']['seo']['description'] : $data['title'].SITE_SEOJOIN.dr_lang($this->form['name']),
|
||||
]));
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'index' => $this->index,
|
||||
'catid' => intval($this->index['catid']),
|
||||
'markid' => 'module-'.MOD_DIR.'-'.intval($this->index['catid']),
|
||||
'urlrule' =>\Phpcmf\Service::L('Router')->mform_show_url($this->form['table'], $this->index['id'], MOD_DIR, '[page]'),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
/*
|
||||
protected function _Data($id = 0) {
|
||||
|
||||
if (!$id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$name = 'module_'.MOD_DIR.'_formxx_'.$this->form['table'].'_show_id_'.$id;
|
||||
$data = \Phpcmf\Service::L('cache')->get_data($name);
|
||||
if (!$data) {
|
||||
// 处理缓存机制
|
||||
$data = $this->content_model->get_form_row($id, $this->form['table']);
|
||||
if (!$data) {
|
||||
return [];
|
||||
}
|
||||
if ($data['uid'] != $this->uid && SYS_CACHE) {
|
||||
if ($this->member && $this->member['is_admin']) {
|
||||
// 管理员时不进行缓存
|
||||
\Phpcmf\Service::L('cache')->init()->delete($name);
|
||||
} else {
|
||||
\Phpcmf\Service::L('cache')->set_data($name, $data, SYS_CACHE_SHOW * 3600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}*/
|
||||
|
||||
// 格式化保存数据 保存之前
|
||||
protected function _Format_Data($id, $data, $old) {
|
||||
|
||||
// 验证父数据
|
||||
if (!$this->index) {
|
||||
$this->_json(0, dr_lang('关联内容不存在'));
|
||||
}
|
||||
|
||||
if ($this->uid) {
|
||||
|
||||
// 判断日发布量
|
||||
/*
|
||||
$day_post = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'day_post', $this->member);
|
||||
if ($day_post && \Phpcmf\Service::M()->db
|
||||
->table($this->init['table'])
|
||||
->where('uid', $this->uid)
|
||||
->where('DATEDIFF(from_unixtime(inputtime),now())=0')
|
||||
->countAllResults() >= $day_post) {
|
||||
$this->_json(0, dr_lang('每天发布数量不能超过%s个', $day_post));
|
||||
}
|
||||
|
||||
// 判断发布总量
|
||||
$total_post = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'total_post', $this->member);
|
||||
if ($total_post && \Phpcmf\Service::M()->db
|
||||
->table($this->init['table'])
|
||||
->where('uid', $this->uid)
|
||||
->countAllResults() >= $total_post) {
|
||||
$this->_json(0, dr_lang('发布数量不能超过%s个', $total_post));
|
||||
}*/
|
||||
}
|
||||
|
||||
// 审核状态
|
||||
$data[1]['status'] = $this->form['setting']['is_verify'] ? 1 : 0;
|
||||
|
||||
// 默认数据
|
||||
$data[0]['uid'] = $data[1]['uid'] = (int)$this->member['uid'];
|
||||
//$data[1]['author'] = $this->member['username'] ? $this->member['username'] : 'guest';
|
||||
$data[1]['cid'] = $data[0]['cid'] = $this->cid;
|
||||
$data[1]['catid'] = $data[0]['catid'] = (int)$this->index['catid'];
|
||||
$data[1]['inputip'] = \Phpcmf\Service::L('input')->ip_info();
|
||||
$data[1]['inputtime'] = SYS_TIME;
|
||||
$data[1]['tableid'] = $data[1]['displayorder'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
* $id 内容id,新增为0
|
||||
* $data 提交内容数组,留空为自动获取
|
||||
* $func 格式化提交的数据
|
||||
* */
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
|
||||
return parent::_Save($id, $data, $old, null,
|
||||
function ($id, $data, $old) {
|
||||
// 保存之后
|
||||
//审核通知
|
||||
if ($data[1]['status']) {
|
||||
/*
|
||||
// 增减金币
|
||||
$score = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'score', $this->member);
|
||||
$score && \Phpcmf\Service::M('member')->add_score($this->member['uid'], $score, dr_lang('%s[%s]: %s发布', MODULE_NAME, $this->index['title'], $this->form['name']), $this->index['curl']);
|
||||
// 增减经验
|
||||
$exp = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'exp', $this->member);
|
||||
$exp && \Phpcmf\Service::M('member')->add_experience($this->member['uid'], $exp, dr_lang('%s[%s]: %s发布', MODULE_NAME, $this->index['title'], $this->form['name']), $this->index['curl']);
|
||||
*/
|
||||
$row = dr_array2array($data[1], $data[0]);
|
||||
$row['muid'] = $row['uid'];
|
||||
$row['form'] = $this->form;
|
||||
$row['index'] = $this->index;
|
||||
$row['module'] = $this->module;
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_post_1', $row);
|
||||
$row['uid'] = $this->index['uid'];
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_post_2', $row);
|
||||
} else {
|
||||
\Phpcmf\Service::M('member')->admin_notice(SITE_ID, 'content', $this->member, dr_lang('%s[%s]: %s提交内容审核', MODULE_NAME, $this->index['title'], $this->form['name']), MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'. $this->cid.'/id/'.$id);
|
||||
}
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
\Phpcmf\Service::M()->table($table)->replace($data[1]);
|
||||
}
|
||||
//更新total字段
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total( $this->cid, $this->form['table']);
|
||||
// 挂钩点
|
||||
$row = dr_array2array($data[1], $data[0]);
|
||||
$row['index'] = $this->index;
|
||||
\Phpcmf\Hooks::trigger('module_form_post_after', $row);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 操作主内容
|
||||
protected function _Module_Row($id) {
|
||||
|
||||
$data = \Phpcmf\Service::L('cache')->get_data('module_'.MOD_DIR.'_show_id_'.$id);
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = $this->content_model->get_data($id);
|
||||
if (!$data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 格式化输出自定义字段
|
||||
$cat = dr_cat_value($this->module['mid'], $data['catid']);
|
||||
$fields = $cat['field'] ? array_merge($this->module['field'], $cat['field']) : $this->module['field'];
|
||||
$fields['inputtime'] = ['fieldtype' => 'Date'];
|
||||
$fields['updatetime'] = ['fieldtype' => 'Date'];
|
||||
|
||||
$data['url'] = dr_url_prefix($data['url'], MOD_DIR);
|
||||
return \Phpcmf\Service::L('Field')->app(MOD_DIR)->format_value($fields, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调处理结果
|
||||
* $data
|
||||
* */
|
||||
protected function _Call_Post($data) {
|
||||
|
||||
$data['url'] = $this->form['setting']['rt_url'] ? str_replace(['{id}', '{cid}'], [$data[1]['id'], $data[1]['cid']], $this->form['setting']['rt_url']) : '';
|
||||
if ($data[1]['status']) {
|
||||
return dr_return_data($data[1]['id'], dr_lang($this->form['setting']['rt_text'] ? $this->form['setting']['rt_text'] : '操作成功'), $data);
|
||||
} else {
|
||||
return dr_return_data($data[1]['id'], dr_lang($this->form['setting']['rt_text2'] ? $this->form['setting']['rt_text2'] : '操作成功,等待管理员审核'), $data);
|
||||
}
|
||||
}
|
||||
|
||||
// 前端回调处理类
|
||||
protected function _Call_Show($data) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
<?php namespace Phpcmf\Member;
|
||||
|
||||
/**
|
||||
* http://www.xunruicms.com
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
// 内容模块表单操作类 基于 Ftable
|
||||
class Mform extends \Phpcmf\Table
|
||||
{
|
||||
public $cid; // 内容id
|
||||
public $form; // 表单信息
|
||||
public $index; // 模块内容信息
|
||||
protected $is_verify; // 判断是否来自审核控制器
|
||||
protected $is_add_menu = 1; //允许有添加菜单
|
||||
|
||||
// 上级公共类
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->_Extend_Init();
|
||||
}
|
||||
|
||||
// 继承类初始化
|
||||
protected function _Extend_Init() {
|
||||
// 初始化模块
|
||||
$this->_module_init(APP_DIR);
|
||||
// 判断表单是否操作
|
||||
$this->form = $this->module['form'][\Phpcmf\Service::L('Router')->class];
|
||||
if (!$this->form) {
|
||||
$this->_msg(0, dr_lang('模块表单【%s】不存在', \Phpcmf\Service::L('Router')->class));
|
||||
} elseif (!$this->form['setting']['is_member']) {
|
||||
$this->_msg(0, dr_lang('模块表单【%s】没有开启管理内容功能', \Phpcmf\Service::L('Router')->class));
|
||||
}
|
||||
// 支持附表存储
|
||||
$this->is_data = 1;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->tpl_prefix = 'mform_';
|
||||
// 单独模板命名
|
||||
$this->tpl_name = $this->form['table'];
|
||||
// 模块显示名称
|
||||
$this->name = dr_lang('内容模块[%s]表单(%s)', APP_DIR, $this->form['name']);
|
||||
// 获取父级内容
|
||||
$this->url_params['cid'] = $this->cid = intval(\Phpcmf\Service::L('input')->get('cid'));
|
||||
if ($this->cid) {
|
||||
$this->index = $this->content_model->get_data($this->cid);
|
||||
} else {
|
||||
//$this->_msg(0, dr_lang('模块表单【%s】没有cid参数', $this->form['name']));
|
||||
}
|
||||
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'field' => $this->form['field'],
|
||||
'table' => dr_mform_ctable(APP_DIR, $this->form['table'], $this->cid),
|
||||
'date_field' => 'inputtime',
|
||||
'show_field' => 'title',
|
||||
'list_field' => $this->form['setting']['list_field'],
|
||||
'order_by' => 'displayorder DESC,inputtime DESC',
|
||||
'where_list' => $this->cid ? 'cid='. $this->cid : ($this->form['setting']['is_member_user'] ? ' cid in (select id from '.
|
||||
\Phpcmf\Service::M()->dbprefix(SITE_ID.'_'.APP_DIR.'_index').' where uid='.$this->uid.')' : 'uid='.$this->uid), // 自定义条件,显示本内容的表单
|
||||
]);
|
||||
$this->edit_where = $this->delete_where = $this->cid ? 'cid='. $this->cid : 'uid='.$this->uid;
|
||||
// 是否有验证码
|
||||
$this->is_post_code = $this->form['setting']['is_post_code'] ? 0 : 1;
|
||||
|
||||
// 写入模板
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mform' => $this->form,
|
||||
'index' => $this->index,
|
||||
'field' => $this->init['field'],
|
||||
'form_url' => dr_member_url(APP_DIR.'/'.$this->form['table'].'/index', ['cid' => $this->cid]),
|
||||
'is_verify' => $this->is_verify,
|
||||
'is_post_code' => $this->is_post_code,
|
||||
]);
|
||||
}
|
||||
|
||||
// ========================
|
||||
|
||||
// 查看列表
|
||||
protected function _Member_List() {
|
||||
|
||||
if ($this->cid) {
|
||||
if ($this->index) {
|
||||
if (!$this->form['setting']['is_member_user'] && $this->index['uid'] != $this->uid) {
|
||||
$this->_msg(0, dr_lang('模块表单【%s】父内容[%s]不是你创建', $this->form['name'], $this->cid));
|
||||
}
|
||||
} else {
|
||||
$this->_msg(0, dr_lang('模块表单【%s】父内容[%s]不存在', $this->form['name'], $this->cid));
|
||||
}
|
||||
}
|
||||
|
||||
$this->init['table'] = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
list($tpl) = $this->_List(['cid' => $this->cid]);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'p' => ['cid' => $this->cid],
|
||||
'is_delete' => 0,
|
||||
]);
|
||||
return \Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 添加内容
|
||||
protected function _Member_Add() {
|
||||
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'add', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无发布权限'));
|
||||
}*/
|
||||
|
||||
list($tpl) = $this->_Post(0);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 修改内容
|
||||
protected function _Member_Edit() {
|
||||
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'edit', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无修改权限'));
|
||||
}*/
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
list($tpl, $data) = $this->_Post($id);
|
||||
|
||||
if (!$data) {
|
||||
$this->_msg(0, dr_lang('数据不存在: '.$id));
|
||||
} elseif ($this->cid != $data['cid']) {
|
||||
$this->_msg(0, dr_lang('所属主题cid不匹配'));
|
||||
}
|
||||
if ($this->form['setting']['is_member_user']) {
|
||||
if (!in_array($this->uid, [$data['uid'], $this->index['uid']])) {
|
||||
$this->_msg(0, dr_lang('无权限修改'));
|
||||
}
|
||||
} elseif ($this->uid != $data['uid']) {
|
||||
$this->_msg(0, dr_lang('无权限修改'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 批量保存排序值
|
||||
protected function _Member_Order() {
|
||||
$this->_Display_Order(
|
||||
intval(\Phpcmf\Service::L('input')->get('id')),
|
||||
intval(\Phpcmf\Service::L('input')->get('value')),
|
||||
function ($t) {
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $t['cid']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
\Phpcmf\Service::M()->table($table)->update($t['id'], ['displayorder' => $value]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 删除内容
|
||||
protected function _Member_Del() {
|
||||
|
||||
/*
|
||||
if (!\Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'del', $this->member)) {
|
||||
$this->_msg(0, dr_lang('您的用户组无删除权限'));
|
||||
}*/
|
||||
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('input')->get_post_ids(),
|
||||
null,
|
||||
function ($rows) {
|
||||
// 对应删除提醒
|
||||
foreach ($rows as $t) {
|
||||
\Phpcmf\Service::M('member')->delete_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$t['cid'].'/id/'.$t['id'], SITE_ID);// clear
|
||||
\Phpcmf\Service::L('cache')->clear('module_'.MOD_DIR.'_from_'.$this->form['table'].'_show_id_'.$t['id']);
|
||||
// 统计数量
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total($t['cid'], $this->form['table']);
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $t['cid']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
\Phpcmf\Service::M()->table($table)->delete($t['id']);
|
||||
}
|
||||
}
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
|
||||
$row = $this->content_model->get_form_row($id, $this->form['table']);
|
||||
if (!$row) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
// 格式化保存数据 保存之前
|
||||
protected function _Format_Data($id, $data, $old) {
|
||||
|
||||
if (!$this->cid) {
|
||||
$this->_json(0, dr_lang('所属主题cid参数不能为空'));
|
||||
}
|
||||
|
||||
// 默认数据
|
||||
$data[0]['uid'] = (int)$data[1]['uid'];
|
||||
$data[1]['cid'] = $data[0]['cid'] = $this->cid;
|
||||
$data[1]['catid'] = $data[0]['catid'] = (int)$this->index['catid'];
|
||||
|
||||
if (!$id) {
|
||||
// 发布时
|
||||
|
||||
if ($this->uid) {
|
||||
/*
|
||||
// 判断日发布量
|
||||
$day_post = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'day_post', $this->member);
|
||||
if ($day_post && \Phpcmf\Service::M()->db
|
||||
->table($this->init['table'])
|
||||
->where('uid', $this->uid)
|
||||
->where('DATEDIFF(from_unixtime(inputtime),now())=0')
|
||||
->countAllResults() >= $day_post) {
|
||||
$this->_json(0, dr_lang('每天发布数量不能超过%s个', $day_post));
|
||||
}
|
||||
|
||||
// 判断发布总量
|
||||
$total_post = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'total_post', $this->member);
|
||||
if ($total_post && \Phpcmf\Service::M()->db
|
||||
->table($this->init['table'])
|
||||
->where('uid', $this->uid)
|
||||
->countAllResults() >= $total_post) {
|
||||
$this->_json(0, dr_lang('发布数量不能超过%s个', $total_post));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// 审核状态
|
||||
$data[1]['status'] = $this->form['setting']['is_verify'] ? 1 : 0;
|
||||
|
||||
// 默认数据
|
||||
$data[0]['uid'] = $data[1]['uid'] = (int)$this->member['uid'];
|
||||
//$data[1]['author'] = $this->member['username'] ? $this->member['username'] : 'guest';
|
||||
$data[1]['cid'] = $data[0]['cid'] = $this->cid;
|
||||
$data[1]['catid'] = $data[0]['catid'] = (int)$this->index['catid'];
|
||||
$data[1]['inputip'] = \Phpcmf\Service::L('input')->ip_info();
|
||||
$data[1]['inputtime'] = SYS_TIME;
|
||||
$data[1]['tableid'] = $data[1]['displayorder'] = 0;
|
||||
} else {
|
||||
// 修改时
|
||||
// 审核状态
|
||||
$data[1]['status'] = $this->form['setting']['is_verify'] ? 1 : 0;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
* $id 内容id,新增为0
|
||||
* $data 提交内容数组,留空为自动获取
|
||||
* $func 格式化提交的数据
|
||||
* */
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
|
||||
return parent::_Save($id, $data, $old, null,
|
||||
function ($id, $data, $old) {
|
||||
// 保存之后
|
||||
$member = dr_member_info($data[1]['uid']);
|
||||
//审核通知
|
||||
if ($data[1]['status']) {
|
||||
// 增减金币
|
||||
/*
|
||||
$score = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'score', $member);
|
||||
$score && \Phpcmf\Service::M('member')->add_score($member['uid'], $score, dr_lang('%s[%s]: %s发布', MODULE_NAME, $this->index['title'], $this->form['name']), $this->index['curl']);
|
||||
// 增减经验
|
||||
$exp = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'exp', $member);
|
||||
$exp && \Phpcmf\Service::M('member')->add_experience($member['uid'], $exp, dr_lang('%s[%s]: %s发布', MODULE_NAME, $this->index['title'], $this->form['name']), $this->index['curl']);
|
||||
*/
|
||||
$row = dr_array2array($data[1], $data[0]);
|
||||
$row['muid'] = $row['uid'];
|
||||
$row['form'] = $this->form;
|
||||
$row['index'] = $this->index;
|
||||
$row['module'] = $this->module;
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_post_1', $row);
|
||||
$row['uid'] = $this->index['uid'];
|
||||
\Phpcmf\Service::L('Notice')->send_notice('module_form_post_2', $row);
|
||||
} else {
|
||||
\Phpcmf\Service::M('member')->admin_notice(SITE_ID, 'content', $member, dr_lang('%s[%s]: %s提交内容审核', MODULE_NAME, $this->index['title'], $this->form['name']), MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'. $this->cid.'/id/'.$id);
|
||||
}
|
||||
$table = dr_mform_ctable(APP_DIR, $this->form['table'], $this->index['id']);
|
||||
if ($table != $this->init['table']) {
|
||||
// 备用表
|
||||
\Phpcmf\Service::M()->table($table)->replace($data[1]);
|
||||
}
|
||||
|
||||
//更新total字段
|
||||
\Phpcmf\Service::M('mform', 'mform')->update_form_total( $this->cid, $this->form['table']);
|
||||
$row = dr_array2array($data[1], $data[0]);
|
||||
$row['index'] = $this->index;
|
||||
if (!$old) {
|
||||
// 挂钩点
|
||||
\Phpcmf\Hooks::trigger('module_form_post_after', $row);
|
||||
} else {
|
||||
\Phpcmf\Hooks::trigger('module_form_edit_after', $row, $old);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调处理结果
|
||||
* $data
|
||||
* */
|
||||
protected function _Call_Post($data) {
|
||||
|
||||
$data['url'] = $this->form['setting']['rt_url'] ? str_replace(['{id}', '{cid}'], [$data[1]['id'], $data[1]['cid']], $this->form['setting']['rt_url']) : '';
|
||||
if ($data[1]['status']) {
|
||||
return dr_return_data($data[1]['id'], dr_lang($this->form['setting']['rt_text'] ? $this->form['setting']['rt_text'] : '操作成功'), $data);
|
||||
} else {
|
||||
return dr_return_data($data[1]['id'], dr_lang($this->form['setting']['rt_text2'] ? $this->form['setting']['rt_text2'] : '操作成功,等待管理员审核'), $data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user