/**
  * Delete messages from a topic
  *
  * @access	public
  * @param	array 		Array of message IDs to remove
  * @param	int			Deleted by member ID
  * @return	boolean		Deleted
  */
 public function deleteMessages($msgIDs = array(), $deletedByMemberID)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $idsToDelete = array();
     $topics = array();
     $unread = array();
     $deletedByMember = IPSMember::load(intval($deletedByMemberID), 'all');
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if (!is_array($msgIDs) or !count($msgIDs)) {
         return FALSE;
     }
     //-----------------------------------------
     // Fetch all posts...
     //-----------------------------------------
     $this->DB->build(array('select' => 'msg.msg_id, msg.msg_topic_id, msg.msg_author_id', 'from' => array('message_posts' => 'msg'), 'where' => 'msg.msg_id IN (' . implode(',', IPSLib::cleanIntArray($msgIDs)) . ') AND msg.msg_is_first_post != 1', 'add_join' => array(array('select' => 'mt.*', 'from' => array('message_topics' => 'mt'), 'where' => 'mt.mt_id=msg.msg_topic_id', 'type' => 'left'))));
     $this->DB->execute();
     while ($msg = $this->DB->fetch()) {
         if ($this->_conversationCanDelete($msg, $msg, $deletedByMember) === TRUE) {
             $idsToDelete[$msg['msg_id']] = $msg['msg_id'];
             $topics[$msg['msg_topic_id']] = $msg['msg_topic_id'];
         }
     }
     //-----------------------------------------
     // Got anything?
     //-----------------------------------------
     if (!count($idsToDelete)) {
         return FALSE;
     }
     //-----------------------------------------
     // Is there an attachment to these messages??
     //-----------------------------------------
     require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
     $class_attach = new class_attach($this->registry);
     $class_attach->type = 'msg';
     $class_attach->init();
     $class_attach->bulkRemoveAttachment($idsToDelete);
     //-----------------------------------------
     // Delete the messages
     //-----------------------------------------
     $this->DB->delete('message_posts', 'msg_id IN (' . implode(',', IPSLib::cleanIntArray($msgIDs)) . ')');
     //-----------------------------------------
     // Rebuild member's new message count
     // This MUST go before we rebuild the topic
     // so we get all those who haven't yet read
     // the last replies...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'message_topic_user_map', 'where' => 'map_user_active=1 AND map_topic_id IN (' . implode(",", array_keys($topics)) . ') AND map_has_unread=1'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $unread[$row['map_user_id']] = $row['map_user_id'];
     }
     //-----------------------------------------
     // Update all relevant topics
     //-----------------------------------------
     foreach (array_keys($topics) as $topicID) {
         $this->rebuildTopic($topicID);
     }
     /* Update member counts */
     if (count($unread)) {
         $this->resetMembersNewTopicCount($unread);
     }
     return TRUE;
 }
コード例 #2
0
 /**
  * Delete a topic
  *
  * @access	public
  * @param	mixed 		Topic id | Array of topic ids
  * @param	boolean		Skip updating the stats
  * @return	boolean
  */
 public function topicDelete($id, $nostats = 0)
 {
     $posts = array();
     $attach = array();
     $this->error = "";
     if (is_array($id)) {
         $id = IPSLib::cleanIntArray($id);
         if (count($id) > 0) {
             $tid = " IN(" . implode(",", $id) . ")";
         } else {
             return false;
         }
     } else {
         if (intval($id)) {
             $tid = "={$id}";
         } else {
             return false;
         }
     }
     //-----------------------------------------
     // Remove polls assigned to this topic
     //-----------------------------------------
     $this->DB->delete('polls', "tid" . $tid);
     $this->DB->delete('voters', "tid" . $tid);
     $this->DB->delete('tracker', "topic_id" . $tid);
     $this->DB->delete('topic_ratings', "rating_tid" . $tid);
     $this->DB->delete('topic_views', "views_tid" . $tid);
     $this->DB->delete('topics', "tid" . $tid);
     //-----------------------------------------
     // Get PIDS for attachment deletion
     //-----------------------------------------
     $this->DB->build(array('select' => 'pid', 'from' => 'posts', 'where' => "topic_id" . $tid));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $posts[] = $r['pid'];
     }
     /* Remove cache content */
     IPSContentCache::drop('post', $posts);
     //-----------------------------------------
     // Remove the attachments
     //-----------------------------------------
     require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
     $class_attach = new class_attach($this->registry);
     $class_attach->type = 'post';
     $class_attach->init();
     $class_attach->bulkRemoveAttachment($posts);
     //-----------------------------------------
     // Remove the posts
     //-----------------------------------------
     $this->DB->delete('posts', "topic_id" . $tid);
     $this->DB->delete('search_index', "type='forum' AND type_2='topic' AND type_id_2 " . $tid);
     $this->DB->delete('reputation_cache', "app='forums' AND type='pid' AND type_id " . $tid);
     $this->DB->delete('reputation_index', "app='forums' AND type='pid' AND type_id " . $tid);
     //-----------------------------------------
     // Recount forum...
     //-----------------------------------------
     if (!$nostats) {
         if ($this->forum['id']) {
             $this->registry->class_forums->allForums[$this->forum['id']]['_update_deletion'] = 1;
             $this->forumRecount($this->forum['id']);
         }
         $this->statsRecount();
     }
     return TRUE;
 }
 /**
  * XMLRPC_server::deletePost()
  *
  * Deletes a Blog entry.
  *
  * @access	public
  * @param	string	$appkey			Appkey (ignored)
  * @param	int		$postid			Entry ID
  * @param	string	$username		Username
  * @param	string	$password		Password
  * @param	bool	$publish		Publish (ignored)
  * @return	string	xml
  **/
 public function deletePost($appkey, $postid, $username, $password, $publish)
 {
     $this->registry->class_localization->loadLanguageFile(array('public_portal'), 'blog');
     //-----------------------------------------
     // Authenticate
     //-----------------------------------------
     if ($this->_authenticate($username, $password)) {
         if (!$this->registry->blog_std->allowDelEntry($this->blog)) {
             $this->classApiServer->apiSendError(100, $this->registry->class_localization->words['blogger_error_1']);
             exit;
         }
         //-----------------------------------------
         // find the entry
         //-----------------------------------------
         $eid = intval($postid);
         $entry = $this->registry->DB()->buildAndFetch(array('select' => '*', 'from' => 'blog_entries', 'where' => "entry_id = " . $eid));
         if (!$entry['entry_id']) {
             $this->classApiServer->apiSendError(100, sprintf($this->registry->class_localization->words['blogger_error_2'], $eid));
             exit;
         }
         //-----------------------------------------
         // delete the entry
         //-----------------------------------------
         $this->registry->DB()->delete('blog_comments', "entry_id=" . $eid);
         require_once IPSLib::getAppDir('core') . 'sources/classes/attach/class_attach.php';
         $class_attach = new class_attach($this->registry);
         $class_attach->type = 'blogentry';
         $class_attach->init();
         $class_attach->bulkRemoveAttachment(array($eid));
         $this->registry->DB()->delete('blog_trackback', "entry_id = {$eid}");
         $this->registry->DB()->delete('blog_polls', "entry_id = {$eid}");
         $this->registry->DB()->delete('blog_voters', "entry_id = {$eid}");
         $this->registry->DB()->delete('blog_entries', "entry_id = {$eid}");
         $this->registry->blog_std->rebuildBlog($this->blog['blog_id']);
         $this->registry->DB()->update('blog_blogs', array('blog_last_delete' => time()), "blog_id={$this->blog['blog_id']}");
         //-------------------------------------------------
         // Update the Blog stats
         //-------------------------------------------------
         $r = $this->registry->cache()->getCache('blog_stats');
         $r['blog_stats']['stats_num_entries']--;
         $r['blog_stats']['stats_num_comments'] -= $entry['entry_num_comments'];
         $this->registry->cache()->setCache('blog_stats', $r, array('array' => 1, 'deletefirst' => 0, 'donow' => 1));
         $this->addModlog($this->registry->class_localization->words['blogger_blog_prefix'] . "({$this->blog['blog_id']}) '{$this->blog['blog_name']}': {$this->registry->class_localization->words['blogger_deleted_log']} '{$entry['entry_name']}'");
         //-------------------------------------------------
         // Return
         //-------------------------------------------------
         $this->classApiServer->apiSendReply();
         exit;
     } else {
         $this->classApiServer->apiSendError(100, $this->error);
         exit;
     }
 }
コード例 #4
0
 /**
  * Post multi-mod: Merge posts
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _multiMergePost()
 {
     $this->_resetModerator($this->topic['forum_id']);
     $this->_genericPermissionCheck('delete_post');
     if (count($this->pids) < 2) {
         $this->_showError('mod_only_one_pid', 10383);
     }
     //-----------------------------------------
     // Form or print?
     //-----------------------------------------
     if (!$this->request['checked']) {
         //-----------------------------------------
         // Get post data
         //-----------------------------------------
         $master_post = "";
         $dropdown = array();
         $authors = array();
         $seen_author = array();
         $upload_html = "";
         $seoTitle = '';
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id, t.title_seo', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             if (IPSMember::checkPermissions('read', $p['forum_id']) == TRUE) {
                 $master_post .= "<br /><br />" . $p['post'];
                 $dropdown[] = array($p['pid'], ipsRegistry::getClass('class_localization')->getDate($p['post_date'], 'LONG') . " (#{$p['pid']})");
                 if (!in_array($p['author_id'], $seen_author)) {
                     $authors[] = array($p['author_id'], "{$p['author_name']} (#{$p['pid']})");
                     $seen_author[] = $p['author_id'];
                 }
                 $seoTitle = $p['title_seo'];
             }
         }
         //-----------------------------------------
         // Get Attachment Data
         //-----------------------------------------
         $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='post' AND attach_rel_id IN (" . implode(",", $this->pids) . ")"));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $row['image'] = $this->caches['attachtypes'][$row['attach_ext']]['atype_img'];
             $row['size'] = IPSLib::sizeFormat($row['attach_filesize']);
             $row['attach_file'] = IPSText::truncate($row['attach_file'], 50);
             $attachments[] = $row;
         }
         //-----------------------------------------
         // Print form
         //-----------------------------------------
         if (IPSText::getTextClass('editor')->method == 'rte') {
             IPSText::getTextClass('bbcode')->parse_wordwrap = 0;
             IPSText::getTextClass('bbcode')->parse_html = 0;
             $master_post = IPSText::getTextClass('bbcode')->convertForRTE(trim($master_post));
         } else {
             IPSText::getTextClass('bbcode')->parse_html = 0;
             IPSText::getTextClass('bbcode')->parse_nl2br = 0;
             IPSText::getTextClass('bbcode')->parse_smilies = 1;
             IPSText::getTextClass('bbcode')->parse_bbcode = 1;
             IPSText::getTextClass('bbcode')->parsing_section = 'topics';
             if (IPSText::getTextClass('bbcode')->parse_html) {
                 if (!IPSText::getTextClass('bbcode')->parse_nl2br) {
                     $master_post = str_replace(array('<br />', '<br>'), "", trim($master_post));
                 }
             }
             $master_post = IPSText::getTextClass('bbcode')->preEditParse($master_post);
         }
         $editor = IPSText::getTextClass('editor')->showEditor($master_post, 'Post');
         $this->output .= $this->registry->getClass('output')->getTemplate('mod')->mergePostForm($editor, $dropdown, $authors, $attachments, $seoTitle);
         if ($this->topic['tid']) {
             $this->registry->getClass('output')->addNavigation($this->topic['title'], "{$this->settings['_base_url']}showtopic={$this->topic['tid']}");
         }
         $this->registry->getClass('output')->addNavigation($this->lang->words['cm_title'], '');
         $this->registry->getClass('output')->setTitle($this->lang->words['cm_title']);
         $this->registry->output->addContent($this->output);
         $this->registry->getClass('output')->sendOutput();
     } else {
         //-----------------------------------------
         // DO THE THING, WITH THE THING!!
         //-----------------------------------------
         $this->request['postdate'] = intval($this->request['postdate']);
         if (!$this->request['selectedpids'] or !$this->request['postdate'] or !$this->request['postauthor'] or !$this->request['Post']) {
             $this->_showError('mod_merge_posts', 10384);
         }
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_html = 0;
         IPSText::getTextClass('bbcode')->parse_bbcode = 1;
         IPSText::getTextClass('bbcode')->parsing_section = 'topics';
         $post = IPSText::getTextClass('editor')->processRawPost('Post');
         $post = IPSText::getTextClass('bbcode')->preDbParse($post);
         //-----------------------------------------
         // Post to keep...
         //-----------------------------------------
         $posts = array();
         $author = array();
         $post_to_delete = array();
         $new_post_key = md5(time());
         $topics = array();
         $forums = array();
         $append_edit = 0;
         //-----------------------------------------
         // Grab teh posts
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN (" . implode(",", $this->pids) . ")", 'add_join' => array(array('select' => 't.forum_id', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($p = $this->DB->fetch($outer)) {
             $posts[$p['pid']] = $p;
             $topics[$p['topic_id']] = $p['topic_id'];
             $forums[$p['forum_id']] = $p['forum_id'];
             if ($p['author_id'] == $this->request['postauthor']) {
                 $author = array('id' => $p['author_id'], 'name' => $p['author_name']);
             }
             if ($p['pid'] != $this->request['postdate']) {
                 $post_to_delete[] = $p['pid'];
             }
             if ($p['append_edit']) {
                 $append_edit = 1;
             }
         }
         //-----------------------------------------
         // Update main post...
         //-----------------------------------------
         $this->DB->update('posts', array('author_id' => $author['id'], 'author_name' => $author['name'], 'post' => $post, 'post_key' => $new_post_key, 'post_parent' => 0, 'edit_time' => time(), 'edit_name' => $this->memberData['members_display_name'], 'append_edit' => ($append_edit or !$this->memberData['g_append_edit']) ? 1 : 0), 'pid=' . $this->request['postdate']);
         //-----------------------------------------
         // Fix attachments
         //-----------------------------------------
         $attach_keep = array();
         $attach_kill = array();
         foreach ($_POST as $key => $value) {
             if (preg_match("/^attach_(\\d+)\$/", $key, $match)) {
                 if ($this->request[$match[0]] == 'keep') {
                     $attach_keep[] = $match[1];
                 } else {
                     $attach_kill[] = $match[1];
                 }
             }
         }
         $attach_keep = IPSLib::cleanIntArray($attach_keep);
         $attach_kill = IPSLib::cleanIntArray($attach_kill);
         //-----------------------------------------
         // Keep
         //-----------------------------------------
         if (count($attach_keep)) {
             $this->DB->update('attachments', array('attach_rel_id' => $this->request['postdate'], 'attach_post_key' => $new_post_key, 'attach_member_id' => $author['id']), 'attach_id IN(' . implode(",", $attach_keep) . ')');
         }
         //-----------------------------------------
         // Kill Attachments
         //-----------------------------------------
         if (count($attach_kill)) {
             require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
             $class_attach = new class_attach($this->registry);
             $class_attach->type = $rel_module;
             $class_attach->attach_post_key = $post_key;
             $class_attach->attach_rel_id = $rel_id;
             $class_attach->init();
             $class_attach->bulkRemoveAttachment($attach_kill, 'attach_id');
         }
         //-----------------------------------------
         // Kill old posts
         //-----------------------------------------
         if (count($post_to_delete)) {
             $this->DB->delete('posts', 'pid IN(' . implode(",", $post_to_delete) . ')');
         }
         foreach ($topics as $t) {
             $this->modLibrary->rebuildTopic($t, 0);
         }
         foreach ($forums as $f) {
             $this->modLibrary->forumRecount($f);
         }
         $this->modLibrary->statsRecount();
         /* Clear the content cache */
         IPSContentCache::drop('post', $this->pids);
         $this->_addModeratorLog(sprintf($this->lang->words['acp_merged_posts'], implode(", ", $this->pids)));
     }
 }