Exemplo n.º 1
0
 /**
  * Delete / undelete posts
  *
  * @param	array 		Array of Post IDs
  * @param	boolean		Approve (TRUE) / Unapprove (FALSE)
  * @return	boolean
  */
 public function topicToggleSoftDelete($topicIds, $delete = FALSE, $reason = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $_restoreTopic = 1;
     if ($delete === TRUE) {
         $_restoreTopic = -1;
     }
     $_topics = array();
     $_forumIDs = array();
     $_tids = IPSLib::cleanIntArray($topicIds);
     //-----------------------------------------
     // Fetch distinct topic IDs
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'topics', 'where' => 'tid IN (' . implode(',', $_tids) . ')'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         if (!$this->registry->getClass('topics')->isArchived($row)) {
             $_topics[$row['tid']] = $row;
             $_forumIDs[$row['forum_id']] = $row['forum_id'];
         }
     }
     //-----------------------------------------
     // Did we get the first post too?
     //-----------------------------------------
     foreach ($_topics as $tid => $topicData) {
         $this->DB->update('topics', array('approved' => $_restoreTopic), 'tid=' . $tid);
         if ($delete) {
             IPSDeleteLog::addEntry($tid, 'topic', $reason, $this->memberData);
         }
         /* Rebuild topic */
         $this->rebuildTopic($tid);
         /* Mod log */
         $this->addModerateLog($topicData['forum_id'], $tid, 0, $topicData['title'], sprintf($this->lang->words['acp_altered_topics'], "approved={$_restoreTopic}", $topicData['title']));
     }
     /* Restoring */
     if (!$delete) {
         /* Un-deleting, so delete */
         IPSDeleteLog::removeEntries($_tids, 'post');
         /* Delete from recent posts */
         $this->registry->topics->restoreRecentPost(array('post_topic_id' => $_tids));
         /* Run moderation sync */
         $this->runModSync('topicUnhide', $_tids);
     } else {
         /* Delete from recent posts */
         $this->registry->topics->deleteRecentPost(array('post_topic_id' => $_tids));
         /* Run moderation sync */
         $this->runModSync('topicHide', $_tids);
     }
     if (count($_forumIDs)) {
         foreach ($_forumIDs as $_fid) {
             $this->forumRecount($_fid);
         }
     }
     /* Tagging */
     $this->registry->tags->updateVisibilityByMetaId($_tids, $delete ? 0 : 1);
     /* Likes */
     require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php';
     /*noLibHook*/
     $_like = classes_like::bootstrap('forums', 'topics');
     $_like->toggleVisibility($_tids, $delete ? 0 : 1);
     $this->cache->rebuildCache('stats', 'global');
     return TRUE;
 }
Exemplo n.º 2
0
 /**
  * Post multi-mod: Split topic
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _multiSplitTopic()
 {
     $this->_resetModerator($this->topic['forum_id']);
     $this->_genericPermissionCheck('split_merge');
     if (!$this->fromSearch and !$this->topic['tid']) {
         $this->_showError('mod_no_tid', 10377, 404);
     }
     //-----------------------------------------
     // Show the form
     //-----------------------------------------
     if ($this->request['checked'] != 1) {
         $jump_html = $this->registry->getClass('class_forums')->buildForumJump(0, 1, 1);
         $posts = array();
         //-----------------------------------------
         // Display the posty wosty's
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.post, p.pid, p.post_date, p.author_id, p.author_name, p.use_emo, p.post_htmlstate', 'from' => array('posts' => 'p'), 'where' => 'p.topic_id=' . $this->topic['tid'] . ' AND p.pid IN (' . implode(',', $this->pids) . ')', 'order' => 'p.post_date', 'add_join' => array(array('select' => 'm.member_group_id, m.mgroup_others', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id'))));
         $post_query = $this->DB->execute();
         while ($row = $this->DB->fetch($post_query)) {
             // This causes HTML to get cut off sometimes
             //$row['post']	= IPSText::truncate( $row['post'], 800 );
             $row['date'] = ipsRegistry::getClass('class_localization')->getDate($row['post_date'], 'LONG');
             IPSText::getTextClass('bbcode')->parse_smilies = $row['use_emo'];
             IPSText::getTextClass('bbcode')->parse_html = ($this->forum['use_html'] and $row['post_htmlstate']) ? 1 : 0;
             IPSText::getTextClass('bbcode')->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
             IPSText::getTextClass('bbcode')->parse_bbcode = $this->forum['use_ibc'];
             IPSText::getTextClass('bbcode')->parsing_section = 'topics';
             IPSText::getTextClass('bbcode')->parsing_mgroup = $row['member_group_id'];
             IPSText::getTextClass('bbcode')->parsing_mgroup_others = $row['mgroup_others'];
             $row['post'] = IPSText::getTextClass('bbcode')->preDisplayParse($row['post']);
             $posts[] = $row;
         }
         /* Pass back for templates */
         $this->request['selectedpids'] = $this->pids;
         //-----------------------------------------
         // print my bottom, er, the bottom
         //-----------------------------------------
         $this->output .= $this->registry->getClass('output')->getTemplate('mod')->splitPostForm($this->forum, $this->topic, $posts, $jump_html);
         $this->registry->getClass('output')->addNavigation($this->forum['name'], "showforum={$this->forum['id']}", $this->forum['name_seo'], 'showforum');
         $this->registry->getClass('output')->addNavigation($this->topic['title'], "showtopic={$this->topic['tid']}", $this->topic['title_seo'], 'showtopic');
         $this->registry->getClass('output')->setTitle($this->lang->words['st_top'] . ": " . $this->topic['title'] . ' - ' . ipsRegistry::$settings['board_name']);
         $this->registry->output->addContent($this->output);
         $this->registry->getClass('output')->sendOutput();
     } else {
         /* INIT */
         $topics = array();
         $topic = array();
         $forum = array();
         $pids = array();
         $tids = array();
         /* As of 3.1, posts can come from multiple topics due to the mod options on searching */
         $this->DB->build(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'add_join' => array(array('select' => 'p.pid', 'from' => array('posts' => 'p'), 'where' => "pid IN(" . implode(",", $this->pids) . ")"))));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $pids[$row['pid']] = $row;
             $tids[$row['tid']][] = $row['pid'];
             $topics[$row['tid']] = $row;
         }
         //-----------------------------------------
         // PROCESS Check the input
         //-----------------------------------------
         if ($this->request['title'] == "") {
             $this->_showError('mod_need_title', 10378);
         }
         $affected_ids = count($this->pids);
         //-----------------------------------------
         // Do we have enough?
         //-----------------------------------------
         if ($affected_ids < 1) {
             $this->_showError('mod_not_enough_split', 10379);
         }
         //-----------------------------------------
         // Do we choose too many?
         //-----------------------------------------
         if ($this->topic['tid']) {
             $count = $this->DB->buildAndFetch(array('select' => 'count(pid) as cnt', 'from' => 'posts', 'where' => "topic_id={$this->topic['tid']}"));
             if ($affected_ids >= $count['cnt']) {
                 $this->_showError('mod_too_much_split', 10380);
             }
         }
         //-----------------------------------------
         // Check the forum we're moving this too
         //-----------------------------------------
         if ($this->forum['id']) {
             $this->request['fid'] = intval($this->request['fid']);
             if ($this->request['fid'] != $this->forum['id']) {
                 $f = $this->registry->class_forums->allForums[$this->request['fid']];
                 if (!$f['id']) {
                     $this->_showError('mod_no_forum_move', 10381, 404);
                 }
                 if (!$f['sub_can_post']) {
                     $this->_showError('mod_forum_no_posts', 10382);
                 }
             }
         }
         /* Loop */
         foreach ($tids as $_tid => $pids) {
             //-----------------------------------------
             // Is first post queued?
             //-----------------------------------------
             $topic_approved = 1;
             $topic = $topics[$_tid];
             /* Reset topic */
             if ($this->fromSearch) {
                 $this->request['title'] = $this->lang->words['mod_from'] . " " . $topic['title'];
             }
             $first_post = $this->DB->buildAndFetch(array('select' => 'pid, queued', 'from' => 'posts', 'where' => 'topic_id=' . $_tid . " AND pid IN(" . implode(",", $pids) . ")", 'order' => $this->settings['post_order_column'] . ' ASC', 'limit' => array(0, 1)));
             if ($first_post['queued']) {
                 $topic_approved = $first_post['queued'] == ipsRegistry::getClass('class_forums')->fetchPostHiddenFlag('hidden') ? ipsRegistry::getClass('class_forums')->fetchTopicHiddenFlag('queued') : ipsRegistry::getClass('class_forums')->fetchTopicHiddenFlag('sdeleted');
                 $this->DB->update('posts', array('queued' => 0), 'pid=' . $first_post['pid']);
             }
             //-----------------------------------------
             // Complete a new dummy topic
             //-----------------------------------------
             if ($this->settings['etfilter_shout']) {
                 if (function_exists('mb_convert_case')) {
                     if (in_array(strtolower($this->settings['gb_char_set']), array_map('strtolower', mb_list_encodings()))) {
                         $this->request['title'] = mb_convert_case($this->request['title'], MB_CASE_TITLE, $this->settings['gb_char_set']);
                     } else {
                         $this->request['title'] = ucwords(strtolower($this->request['title']));
                     }
                 } else {
                     $this->request['title'] = ucwords(strtolower($this->request['title']));
                 }
             }
             $this->DB->insert('topics', array('title' => $this->request['title'], 'state' => 'open', 'posts' => 0, 'starter_id' => 0, 'starter_name' => 0, 'start_date' => time(), 'last_poster_id' => 0, 'last_poster_name' => 0, 'last_post' => time(), 'author_mode' => 1, 'poll_state' => 0, 'last_vote' => 0, 'views' => 0, 'forum_id' => $this->request['fid'], 'approved' => $topic_approved, 'pinned' => 0));
             $new_topic_id = $this->DB->getInsertId();
             //-----------------------------------------
             // Add to delete log if we've hidden the new topic
             //-----------------------------------------
             if ($topic_approved == ipsRegistry::getClass('class_forums')->fetchTopicHiddenFlag('sdeleted')) {
                 IPSDeleteLog::addEntry($new_topic_id, 'topic', '', $this->memberData);
             }
             //-----------------------------------------
             // Move the posts
             //-----------------------------------------
             $this->DB->update('posts', array('topic_id' => $new_topic_id, 'new_topic' => 0), 'topic_id=' . $_tid . " AND pid IN(" . implode(",", $pids) . ")");
             //-----------------------------------------
             // Move the posts
             //-----------------------------------------
             $this->DB->update('posts', array('new_topic' => 0), "topic_id={$_tid}");
             //-----------------------------------------
             // Update attachments
             //-----------------------------------------
             $this->DB->update('attachments', array('attach_parent_id' => $new_topic_id), "attach_rel_module='post' AND attach_rel_id IN(" . implode(",", $pids) . ")");
             $_cnt = $this->DB->getAffectedRows();
             $this->DB->update('topics', array('topic_hasattach' => $_cnt), 'tid=' . $new_topic_id);
             //-----------------------------------------
             // Rebuild the topics
             //-----------------------------------------
             $this->modLibrary->rebuildTopic($new_topic_id);
             $this->modLibrary->rebuildTopic($_tid);
             //-----------------------------------------
             // Update the forum(s)
             //-----------------------------------------
             $this->modLibrary->forumRecount($topic['forum_id']);
             if ($topic['forum_id'] != $this->request['fid']) {
                 $this->modLibrary->forumRecount($this->request['fid']);
             }
             /* Run moderation sync */
             $this->modLibrary->runModSync('topicSplit', $pids, $topic['tid'], $new_topic_id);
             /* link http://community.invisionpower.com/tracker/issue-37361-when-splitting-topic-404/ */
             $this->request['st'] = 0;
             $this->_addModeratorLog($this->lang->words['acp_split_topic'] . " '{$topic['title']}'");
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Hide a comment
  *
  * @param	int			Parent ID
  * @param	int|array	Comment IDs
  * @param	string		Reason
  * @param	int|array	Member Data
  * @return	bool|string	TRUE on sucess, error string on error
  */
 public function hide($parentId, $commentIds, $reason, $memberData)
 {
     /* Init */
     if (is_numeric($memberData)) {
         $memberData = IPSMember::load($memberData, 'all');
     }
     /* Check */
     if (!is_array($commentIds)) {
         $commentIds = array($commentIds);
     }
     if (!$memberData['member_id'] or !$parentId) {
         return 'MISSING_DATA';
     }
     /* Permission Check */
     foreach ($commentIds as $k) {
         $permCheck = $this->can('hide', array('comment_id' => $k, 'comment_parent_id' => $parentId));
         if ($permCheck !== TRUE) {
             return $permCheck;
         }
     }
     /* Do it */
     $_remap = $this->remapKeys();
     $array = array('comment_approved' => -1);
     $update = $this->preVisibility(-1, $commentIds, $parentId, $array);
     $save = $this->remapToLocal($update);
     $this->DB->update($this->table(), $save, $this->DB->buildWherePermission($commentIds, $_remap['comment_id'], FALSE));
     $this->postVisibility(-1, $commentIds, $parentId);
     /* Log */
     foreach ($commentIds as $k) {
         IPSDeleteLog::addEntry($k, $this->whoAmI(), $reason, $memberData);
     }
     return true;
 }