Skip to content

Commit

Permalink
Add function: mark status of multi posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Nov 26, 2018
1 parent 586492e commit 26b70e2
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
2 changes: 2 additions & 0 deletions admin/manage-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确认要删除这些页面吗?'); ?>" href="<?php $security->index('/action/contents-page-edit?do=delete'); ?>"><?php _e('删除'); ?></a></li>
<li><a href="<?php $security->index('/action/contents-page-edit?do=mark&status=publish'); ?>"><?php _e('标记为<strong>%s</strong>', _t('公开')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-page-edit?do=mark&status=hidden'); ?>"><?php _e('标记为<strong>%s</strong>', _t('隐藏')); ?></a></li>
</ul>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions admin/manage-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<button class="btn dropdown-toggle btn-s" type="button"><i class="sr-only"><?php _e('操作'); ?></i><?php _e('选中项'); ?> <i class="i-caret-down"></i></button>
<ul class="dropdown-menu">
<li><a lang="<?php _e('你确认要删除这些文章吗?'); ?>" href="<?php $security->index('/action/contents-post-edit?do=delete'); ?>"><?php _e('删除'); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=publish'); ?>"><?php _e('标记为<strong>%s</strong>', _t('公开')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=waiting'); ?>"><?php _e('标记为<strong>%s</strong>', _t('待审核')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=hidden'); ?>"><?php _e('标记为<strong>%s</strong>', _t('隐藏')); ?></a></li>
<li><a href="<?php $security->index('/action/contents-post-edit?do=mark&status=private'); ?>"><?php _e('标记为<strong>%s</strong>', _t('私密')); ?></a></li>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Attachment/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function deleteAttachment()
->where('table.contents.cid = ?', $post)
->limit(1), array($this, 'push'));

if ($this->isWriteable($condition) && $this->delete($condition)) {
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
/** 删除文件 */
Widget_Upload::deleteHandle($row);

Expand Down Expand Up @@ -285,7 +285,7 @@ public function clearAttachment()
->where('table.contents.cid = ?', $post)
->limit(1), array($this, 'push'));

if ($this->isWriteable($condition) && $this->delete($condition)) {
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
/** 删除文件 */
Widget_Upload::deleteHandle($row);

Expand Down
45 changes: 45 additions & 0 deletions var/Widget/Contents/Page/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,50 @@ public function writePage()
}
}

/**
* 标记页面
*
* @access public
* @return void
*/
public function markPage()
{
$status = $this->request->get('status');
$statusList = array(
'publish' => _t('公开'),
'hidden' => _t('隐藏')
);

if (!isset($statusList[$status])) {
$this->response->goBack();
}

$pages = $this->request->filter('int')->getArray('cid');
$markCount = 0;

foreach ($pages as $page) {
// 标记插件接口
$this->pluginHandle()->mark($page, $this);
$condition = $this->db->sql()->where('cid = ?', $page);

if ($this->db->query($condition->update('table.contents')->rows(array('status' => $status)))) {
// 完成标记插件接口
$this->pluginHandle()->finishMark($page, $this);

$markCount ++;
}

unset($condition);
}

/** 设置提示信息 */
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('页面已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有页面被标记'),
$deleteCount > 0 ? 'success' : 'notice');

/** 返回原网页 */
$this->response->goBack();
}

/**
* 删除页面
*
Expand Down Expand Up @@ -256,6 +300,7 @@ public function action()
$this->security->protect();
$this->on($this->request->is('do=publish') || $this->request->is('do=save'))->writePage();
$this->on($this->request->is('do=delete'))->deletePage();
$this->on($this->request->is('do=mark'))->markPage();
$this->on($this->request->is('do=deleteDraft'))->deletePageDraft();
$this->on($this->request->is('do=sort'))->sortPage();
$this->response->redirect($this->options->adminUrl);
Expand Down
57 changes: 56 additions & 1 deletion var/Widget/Contents/Post/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,60 @@ public function writePost()
}
}

/**
* 标记文章
*
* @access public
* @return void
*/
public function markPost()
{
$status = $this->request->get('status');
$statusList = array(
'publish' => _t('公开'),
'private' => _t('私密'),
'hidden' => _t('隐藏'),
'waiting' => _t('待审核')
);

if (!isset($statusList[$status])) {
$this->response->goBack();
}

$posts = $this->request->filter('int')->getArray('cid');
$markCount = 0;

foreach ($posts as $post) {
// 标记插件接口
$this->pluginHandle()->mark($post, $this);

$condition = $this->db->sql()->where('cid = ?', $post);
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
->from('table.contents')->where('cid = ? AND type = ?', $post, 'post'));

if ($this->isWriteable(clone $condition) &&
$postObject) {

/** 标记状态 */
$this->db->query($condition->update('table.contents')->rows(array('status' => $status)));

// 完成标记插件接口
$this->pluginHandle()->finishMark($post, $this);

$markCount ++;
}

unset($condition);
}

/** 设置提示信息 */
$this->widget('Widget_Notice')->set($markCount > 0 ? _t('文章已经被标记为<strong>%s</strong>', $statusList[$status]) : _t('没有文章被标记'),
$deleteCount > 0 ? 'success' : 'notice');

/** 返回原网页 */
$this->response->goBack();
}

/**
* 删除文章
*
Expand All @@ -804,7 +858,7 @@ public function deletePost()
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
->from('table.contents')->where('cid = ? AND type = ?', $post, 'post'));

if ($this->isWriteable($condition) &&
if ($this->isWriteable(clone $condition) &&
$postObject &&
$this->delete($condition)) {

Expand Down Expand Up @@ -905,6 +959,7 @@ public function action()
$this->security->protect();
$this->on($this->request->is('do=publish') || $this->request->is('do=save'))->writePost();
$this->on($this->request->is('do=delete'))->deletePost();
$this->on($this->request->is('do=mark'))->markPost();
$this->on($this->request->is('do=deleteDraft'))->deletePostDraft();

$this->response->redirect($this->options->adminUrl);
Expand Down

0 comments on commit 26b70e2

Please sign in to comment.