Esempio n. 1
0
 /**
  * 删除回复
  */
 public function deletePostAction()
 {
     $tuduId = $this->_request->getParam('tid');
     $postId = $this->_request->getParam('pid');
     // 参数:图度ID必须存在
     if (!$tuduId) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     // 参数:回复ID必须存在
     if (!$postId) {
         return $this->json(false, $this->lang['invalid_postid']);
     }
     // 删除回复权限
     if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_DELETE_POST)) {
         return $this->json(false, $this->lang['perm_deny_delete_post']);
     }
     $post = $this->manager->getPostById($tuduId, $postId);
     // 回复必须存在
     if (!$post) {
         return $this->json(true, $this->lang['post_delete_success']);
     }
     // 提交删除回复不能是图度内容
     if ($post->isFirst) {
         return $this->json(false, $this->lang['forbid_delete_first_post']);
     }
     // 非回复者,检查版主权限
     if ($post->uniqueId != $this->_user->uniqueId) {
         $boards = $this->getBoards(false);
         if (!isset($boards[$post->boardId]) || !array_key_exists($this->_user->userId, $boards[$post->boardId]['moderators'])) {
             return $this->json(false, $this->lang['perm_deny_delete_post']);
         }
     }
     $ret = $this->manager->deletePost($tuduId, $postId);
     if (!$ret) {
         return $this->json(true, $this->lang['post_delete_failure']);
     }
     // 添加操作日志
     $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, Dao_Td_Log_Log::ACTION_DELETE);
     return $this->json(true, $this->lang['post_delete_success']);
 }