Beispiel #1
0
 /**
  * 删除文章
  *
  * @access public
  * @return void
  */
 public function deleteAttachment()
 {
     $cid = $this->request->filter('int')->cid;
     $deleteCount = 0;
     $status = 'publish';
     if ($cid) {
         /** 格式化文章主键 */
         $posts = is_array($cid) ? $cid : array($cid);
         foreach ($posts as $post) {
             $condition = $this->db->sql()->where('cid = ?', $post);
             $row = $this->db->fetchRow($this->select()->where('table.contents.type = ?', 'attachment')->where('table.contents.cid = ?', $post)->limit(1), array($this, 'push'));
             if ($this->isWriteable($condition) && $this->delete($condition)) {
                 /** 删除文件 */
                 Widget_Upload::deleteHandle($row);
                 /** 删除评论 */
                 $this->db->query($this->db->delete('table.comments')->where('cid = ?', $post));
                 $status = $this->status;
                 $deleteCount++;
             }
             unset($condition);
         }
     }
     if ($this->request->isAjax()) {
         $this->response->throwJson($deleteCount > 0 ? array('code' => 200, 'message' => _t('文件已经被删除')) : array('code' => 500, 'message' => _t('没有文件被删除')));
     } else {
         /** 设置提示信息 */
         $this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('文件已经被删除') : _t('没有文件被删除'), $deleteCount > 0 ? 'success' : 'notice');
         /** 返回原网页 */
         $this->response->redirect(Typecho_Common::url('manage-medias.php', $this->options->adminUrl));
     }
 }
Beispiel #2
0
 /**
  * clearAttachment  
  * 
  * @access public
  * @return void
  */
 public function clearAttachment()
 {
     $page = 1;
     $deleteCount = 0;
     do {
         $posts = Typecho_Common::arrayFlatten($this->db->fetchAll($this->select('cid')->from('table.contents')->where('type = ? AND parent = ?', 'attachment', 0)->page($page, 100)), 'cid');
         $page++;
         foreach ($posts as $post) {
             // 删除插件接口
             $this->pluginHandle()->delete($post, $this);
             $condition = $this->db->sql()->where('cid = ?', $post);
             $row = $this->db->fetchRow($this->select()->where('table.contents.type = ?', 'attachment')->where('table.contents.cid = ?', $post)->limit(1), array($this, 'push'));
             if ($this->isWriteable($condition) && $this->delete($condition)) {
                 /** 删除文件 */
                 Widget_Upload::deleteHandle($row);
                 /** 删除评论 */
                 $this->db->query($this->db->delete('table.comments')->where('cid = ?', $post));
                 $status = $this->status;
                 // 完成删除插件接口
                 $this->pluginHandle()->finishDelete($post, $this);
                 $deleteCount++;
             }
             unset($condition);
         }
     } while (count($posts) == 100);
     /** 设置提示信息 */
     $this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('未归档文件已经被清理') : _t('没有未归档文件被清理'), $deleteCount > 0 ? 'success' : 'notice');
     /** 返回原网页 */
     $this->response->redirect(Typecho_Common::url('manage-medias.php', $this->options->adminUrl));
 }