<?php namespace Phpcmf\Admin;
class Comment extends \Phpcmf\Table
{
public $cid; public $module; public $module_menu; public $is_verify;
public function __construct(...$params) {
parent::__construct(...$params);
$this->_module_init(APP_DIR);
!$this->module['comment'] && $this->_admin_msg(0, dr_lang('模块【%s】没有启用评论', APP_DIR));
$this->is_data = 0;
$this->tpl_prefix = 'share_comment_';
$this->tpl_name = 'comment_content';
$this->name = dr_lang('内容模块[%s]评论', APP_DIR);
$this->cid = intval(\Phpcmf\Service::L('input')->get('cid'));
$this->cid && $this->index = $this->content_model->get_row( $this->cid);
if (!$this->module['setting']['comment_list_field']) {
$this->module['setting']['comment_list_field'] = [
'content' => [
'use' => 1,
'name' => dr_lang('内容'),
'func' => 'comment',
'width' => 0,
],
];
}
$this->module['comment']['field'] = dr_array22array(
[
'content' => [
'name' => dr_lang('内容'),
'ismain' => 1,
'fieldtype' => 'Ueditor',
'fieldname' => 'content',
'setting' => array(
'option' => array(
'height' => 250,
'mode' => 1,
'width' => '100%'
)
),
]
],
$this->module['comment']['field']
);
$this->is_verify = strpos(\Phpcmf\Service::L('Router')->class, '_verify') !== false;
$where = $this->is_verify ? 'status=0' : 'status=1';
$this->cid && $where.= ' and cid='. $this->cid;
$sysfield = ['inputtime', 'inputip', 'author'];
$this->is_verify && $sysfield[] = 'status';
$this->_init([
'table' => dr_module_table_prefix(APP_DIR).'_comment',
'field' => $this->module['comment']['field'],
'sys_field' => $sysfield,
'date_field' => 'inputtime',
'show_field' => 'id',
'list_field' => $this->module['setting']['comment_list_field'],
'order_by' => 'inputtime desc',
'where_list' => $where,
]);
$menu = $this->is_verify ? \Phpcmf\Service::M('auth')->_admin_menu([
'审核管理' => [MOD_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-edit'],
]) : \Phpcmf\Service::M('auth')->_module_menu(
$this->module,
' <i class="fa fa-comments"></i> '.dr_lang('评论管理'),
\Phpcmf\Service::L('Router')->url(APP_DIR.'/comment/index', ['cid' => $this->cid]),
$this->cid ?\Phpcmf\Service::L('Router')->url(APP_DIR.'/comment/add', ['cid' => $this->cid]) : ''
).($this->module['comment']['review'] && $this->cid ? '<li> <a href="javascript:dr_iframe_show(\'show\', \''.\Phpcmf\Service::L('Router')->url(APP_DIR.'/comment/review_index', ['cid' => $this->cid]).'\', \'30%\', \'50%\');"> <i class="fa fa-thumbs-o-up"></i> '.dr_lang('查看评分').'</a> <i class="fa fa-circle"></i> </li>' : '');
\Phpcmf\Service::V()->assign([
'menu' => $menu,
'field' => $this->init['field'],
'index' => $this->index,
'is_verify' => $this->is_verify,
'comment_url' =>\Phpcmf\Service::L('Router')->url(APP_DIR.'/comment/index', ['cid' => $this->cid]),
]);
}
protected function _Admin_List() {
list($tpl) = $this->_List(['cid' => $this->cid]);
\Phpcmf\Service::V()->assign([
'p' => ['cid' => $this->cid],
]);
\Phpcmf\Service::V()->display($tpl);
}
protected function _Admin_Add() {
if (!$this->cid) {
$this->_admin_msg(0, dr_lang('缺少cid参数'));
}
list($tpl, $data) = $this->_Post();
\Phpcmf\Service::V()->assign([
'data' => $data,
'form' => dr_form_hidden(),
'review' => $this->module['comment']['review'],
]);
\Phpcmf\Service::V()->display($tpl);
}
protected function _Admin_Edit() {
if (!$this->cid) {
$this->_admin_msg(0, dr_lang('缺少cid参数'));
}
$id = intval(\Phpcmf\Service::L('input')->get('id'));
list($tpl, $data) = $this->_Post($id);
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([
'data' => $data,
'form' => dr_form_hidden(),
'review' => $this->module['comment']['review'],
]);
\Phpcmf\Service::V()->display($tpl);
}
protected function _Admin_Review() {
\Phpcmf\Service::V()->assign([
'review' => $this->module['comment']['review'],
'comment' => $this->content_model->get_comment_index( $this->cid, $this->index['catid']),
]);
\Phpcmf\Service::V()->display('share_comment_review.html');exit;
}
protected function _Admin_Show() {
if (!$this->cid) {
$this->_admin_msg(0, dr_lang('缺少cid参数'));
}
$id = intval(\Phpcmf\Service::L('input')->get('id'));
list($tpl, $data) = $this->_Show($id);
if (!$data) {
$this->_admin_msg(0, dr_lang('数据不存在: '.$id));
} elseif ($this->cid != $data['cid']) {
$this->_admin_msg(0, dr_lang('cid不匹配'));
}
\Phpcmf\Service::V()->display($tpl);
}
protected function _Admin_Status() {
$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()->init($this->init)->where_in('id', $in)->getAll();
if (!$rows) {
$this->_json(0, dr_lang('所选数据不存在'));
}
foreach ($rows as $row) {
!$row['status'] && $this->content_model->verify_comment($row);
}
$this->_json(1, dr_lang('操作成功'));
}
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.'/comment_verify/edit:cid/'.$t['cid'].'/id/'.$t['id'], SITE_ID);
$this->content_model->comment_update_total($t);
$this->content_model->comment_update_review($t);
}
},
\Phpcmf\Service::M()->dbprefix($this->init['table'])
);
}
protected function _Data($id = 0) {
$row = $this->content_model->table($this->content_model->mytable.'_comment')->get($id);
if (!$row) {
return [];
}
return $row;
}
protected function _Format_Data($id, $data, $old) {
if (!$this->index) {
$this->_json(0, dr_lang('关联内容不存在'));
}
$data[1]['cid'] = $this->cid;
if (!$id) {
$data[1]['status'] = 1;
$data[1]['cuid'] = $this->index['uid'];
$data[1]['catid'] = $this->index['catid'];
$data[1]['orderid'] = 0;
}
$review = \Phpcmf\Service::L('input')->post('review');
if ($review) {
foreach ($review as $i => $v) {
$data[1]['sort'.$i] = $v;
}
}
return $data;
}
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 && $data[1]['status']) {
$this->content_model->verify_comment($old);
} elseif (!$id) {
$this->content_model->verify_comment($data[1]);
} else {
$this->content_model->comment_update_total($data[1]);
$this->content_model->comment_update_review($data[1]);
}
}
);
}
}