Example #1
0
 /**
  * Merge two or more topics
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _multiTopicMerge()
 {
     $this->_genericPermissionCheck('split_merge');
     if (count($this->tids) < 2) {
         $this->_showError('mod_topics_merge_two', 103107);
     }
     //-----------------------------------------
     // Get the topics in ascending date order
     //-----------------------------------------
     $topics = array();
     $tids = array();
     $merge_ids = array();
     $newViews = 0;
     $this->DB->build(array('select' => 'tid, forum_id, approved, views', 'from' => 'topics', 'where' => 'tid IN (' . implode(",", $this->tids) . ')', 'order' => 'start_date asc'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $topics[] = $r;
         $tids[] = $r['tid'];
         $newViews += $r['views'];
     }
     //-----------------------------------------
     // Check...
     //-----------------------------------------
     if (count($topics) < 2) {
         $this->_showError('mod_topics_merge_two', 103108);
     }
     //-----------------------------------------
     // Make sure we can moderate EACH topic
     //-----------------------------------------
     foreach ($topics as $topic) {
         $this->_resetModerator($topic['forum_id']);
         $this->_genericPermissionCheck('split_merge');
     }
     //-----------------------------------------
     // Get topic ID for first topic 'master'
     //-----------------------------------------
     $first_topic = array_shift($topics);
     $main_topic_id = $first_topic['tid'];
     $unapproved = array();
     foreach ($topics as $t) {
         /* Add to unapproved array */
         if (!$t['approved']) {
             $unapproved[] = $t['tid'];
         }
         $merge_ids[] = $t['tid'];
     }
     //-----------------------------------------
     // Sort out polls
     //-----------------------------------------
     $polls = array();
     /* Who has a poll? */
     $this->DB->build(array('select' => '*', 'from' => 'polls', 'where' => "tid={$main_topic_id} OR tid IN(" . implode(',', $merge_ids) . ")"));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $polls[$row['tid']] = $row;
     }
     /* We have one poll */
     if (count($polls) == 1) {
         /* Update the poll ONLY if it's not our main one */
         if (empty($polls[$main_topic_id])) {
             $this->DB->update('polls', array('tid' => $main_topic_id), "tid IN(" . implode(',', $merge_ids) . ")");
             $this->DB->update('voters', array('tid' => $main_topic_id), "tid IN(" . implode(',', $merge_ids) . ")");
             $this->DB->update('topics', array('poll_state' => 1), "tid={$main_topic_id}");
         }
     } elseif (count($polls) > 1) {
         // Have we selected one?
         $chosenTid = intval($this->request['chosenpolltid']);
         if ($chosenTid) {
             /* Chosen one is not from the main topic? */
             if ($chosenTid != $main_topic_id) {
                 $this->DB->delete('polls', "tid={$main_topic_id}");
                 $this->DB->delete('voters', "tid={$main_topic_id}");
                 // Update poll status here if the chosen poll is not from the main topic otherwise there's no need to.. right? ;P
                 $this->DB->update('topics', array('poll_state' => 1), "tid={$main_topic_id}");
             }
             // Remove the non chosen ones
             $this->DB->delete('polls', "tid IN(" . implode(',', $merge_ids) . ")" . " AND tid <> {$chosenTid}");
             $this->DB->delete('voters', "tid IN(" . implode(',', $merge_ids) . ")" . " AND tid <> {$chosenTid}");
             // Update the master topic
             $this->DB->update('polls', array('tid' => $main_topic_id), "tid={$chosenTid}");
             $this->DB->update('voters', array('tid' => $main_topic_id), "tid={$chosenTid}");
         } else {
             ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_topic'));
             $this->output .= $this->registry->getClass('output')->getTemplate('mod')->mergeMultiplePolls($polls, $this->request['selectedtids']);
             return false;
         }
     }
     //-----------------------------------------
     // Update the posts, subs and topic
     //-----------------------------------------
     /* Bug #20829: If the topic is not approved, set all the posts unapproved so that they are not displayed after the merge */
     if (is_array($unapproved) && count($unapproved)) {
         $this->DB->update('posts', array('queued' => 1), 'topic_id IN (' . implode(",", $unapproved) . ")");
     }
     $this->DB->update('posts', array('topic_id' => $main_topic_id, 'new_topic' => 0), 'topic_id IN (' . implode(",", $merge_ids) . ")");
     $this->DB->update('topics', array('views' => $newViews), 'tid=' . $main_topic_id);
     /* @Link http://community.invisionpower.com/resources/bugs.html/_/ip-board/merging-topics-does-not-update-attach-parent-id-for-attachments-r41886 */
     $this->DB->update('attachments', array('attach_parent_id' => $main_topic_id), 'attach_parent_id IN(' . implode(",", $merge_ids) . ") AND attach_rel_module='post'");
     $this->DB->delete('voters', "tid IN (" . implode(",", $merge_ids) . ")");
     $this->DB->delete('topics', "tid IN (" . implode(",", $merge_ids) . ")");
     /* Bug #38221: Set the new first post in topic */
     $first_post = $this->DB->buildAndFetch(array('select' => 'pid', 'from' => 'posts', 'where' => "topic_id={$main_topic_id}", 'order' => "pid ASC", 'limit' => array(0, 1)));
     $this->DB->update('posts', array('new_topic' => 1), 'pid = ' . $first_post['pid']);
     //-----------------------------------------
     // Update followers
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php';
     /*noLibHook*/
     $_like = classes_like::bootstrap('forums', 'topics');
     foreach ($merge_ids as $mid) {
         $_like->merge($mid, $main_topic_id);
     }
     //-----------------------------------------
     // Remove from delete log
     //-----------------------------------------
     IPSDeleteLog::removeEntries($merge_ids, 'topic', TRUE);
     //-----------------------------------------
     // Update the newly merged topic
     //-----------------------------------------
     $this->modLibrary->rebuildTopic($main_topic_id);
     $this->registry->class_forums->allForums[$this->forum['id']]['_update_deletion'] = 1;
     $this->modLibrary->forumRecount($this->forum['id']);
     $this->cache->rebuildCache('stats', 'global');
     /* Tags */
     $this->registry->tags->moveTagsByMetaId($tids, $main_topic_id);
     /* Run Sync */
     foreach ($merge_ids as $mid) {
         $this->modLibrary->runModSync('topicMerge', $mid, $main_topic_id);
     }
     /* Log */
     $this->_addModeratorLog(sprintf($this->lang->words['multi_topic_merge_mod_log'], count($topics)));
 }
Example #2
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;
 }
 /**
  * Execute plugin
  *
  * @param	array 	$permissions	Moderator permissions
  * @return	@e string
  */
 public function executePlugin($permissions)
 {
     //-----------------------------------------
     // Check permissions
     //-----------------------------------------
     if (!$this->canView($permissions)) {
         return '';
     }
     //-----------------------------------------
     // Get forum class
     //-----------------------------------------
     if (!$this->registry->isClassLoaded('topics')) {
         $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums');
         $this->registry->setClass('topics', new $classToLoad($this->registry));
     }
     //-----------------------------------------
     // Get results
     //-----------------------------------------
     $st = intval($this->request['st']);
     $_filters = $this->_getFilters();
     $_filters = array_merge($_filters, array('postType' => array('sdelete', 'pdelete', 'oktoremove'), 'getCount' => true, 'sortField' => 'pid', 'sortOrder' => 'desc', 'parse' => true, 'limit' => 10, 'offset' => $st));
     $this->registry->getClass('topics')->setPermissionData();
     $posts = $this->registry->getClass('topics')->getPosts($_filters);
     $total = $this->registry->getClass('topics')->getPostsCount();
     /* Got soft delete pids? */
     $other_data = array();
     if (is_array($posts) and count($posts)) {
         $other_data = IPSDeleteLog::fetchEntries(array_keys($posts), 'post', false);
     }
     //-----------------------------------------
     // Page links
     //-----------------------------------------
     $pages = $this->registry->output->generatePagination(array('totalItems' => $total, 'itemsPerPage' => 10, 'currentStartValue' => $st, 'baseUrl' => "app=core&amp;module=modcp&amp;fromapp=forums&amp;tab=deletedposts"));
     return $this->registry->output->getTemplate('modcp')->deletedPosts($posts, $other_data, $pages);
 }
 /**
  * Execute plugin
  *
  * @param	array 	$permissions	Moderator permissions
  * @return	@e string
  */
 public function executePlugin($permissions)
 {
     //-----------------------------------------
     // Check permissions
     //-----------------------------------------
     if (!$this->canView($permissions)) {
         return '';
     }
     //-----------------------------------------
     // Get forum class
     //-----------------------------------------
     if (!$this->registry->isClassLoaded('topics')) {
         $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums');
         $this->registry->setClass('topics', new $classToLoad($this->registry));
     }
     //-----------------------------------------
     // Get forum class
     //-----------------------------------------
     $classToLoad = IPSLib::loadActionOverloader(IPSLib::getAppDir('forums') . '/modules_public/forums/forums.php', 'public_forums_forums_forums');
     $this->forums = new $classToLoad($this->registry);
     $this->forums->makeRegistryShortcuts($this->registry);
     $st = intval($this->request['st']);
     $_filters = $this->_getFilters();
     $_filters = array_merge($_filters, array('topicType' => array('sdelete', 'pdelete', 'oktoremove'), 'getCount' => true, 'sortField' => 'tid', 'sortOrder' => 'desc', 'limit' => 10, 'offset' => $st));
     $this->registry->getClass('topics')->setPermissionData();
     $topics = $this->registry->getClass('topics')->getTopics($_filters);
     $total = $this->registry->getClass('topics')->getTopicsCount();
     $final = array();
     //-----------------------------------------
     // Format data
     //-----------------------------------------
     if (count($topics)) {
         foreach ($topics as $tid => $topic) {
             /* Have to preserve original forum id for linked topics */
             if ($topic['state'] == 'link') {
                 $_originalForum = $topic['forum_id'];
             }
             $topic = $this->_checkPermissions($topic);
             $topic = $this->forums->renderEntry($topic);
             $topic['forum'] = $this->registry->class_forums->getForumById($topic['forum_id']);
             if ($topic['state'] == 'link') {
                 $topic['_toForum'] = $this->registry->class_forums->getForumById($_originalForum);
             }
             $final[$tid] = $topic;
         }
     }
     $other_data = array();
     if (is_array($topics) and count($topics)) {
         $other_data = IPSDeleteLog::fetchEntries(array_keys($topics), 'topic', false);
     }
     //-----------------------------------------
     // Page links
     //-----------------------------------------
     $pages = $this->registry->output->generatePagination(array('totalItems' => $total, 'itemsPerPage' => 10, 'currentStartValue' => $st, 'baseUrl' => "app=core&amp;module=modcp&amp;fromapp=forums&amp;tab=deletedtopics"));
     return $this->registry->output->getTemplate('modcp')->deletedTopics($final, $other_data, $pages);
 }
Example #5
0
 /**
  * Builds an array of forum data for use in the output template
  *
  * @return	array
  */
 public function renderForum()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['page'] = $this->request['changefilters'] ? 0 : (isset($this->request['page']) ? intval($this->request['page']) : 0);
     $announce_data = array();
     $topic_data = array();
     $other_data = array();
     $multi_mod_data = array();
     $footer_filter = array();
     $member_ids = array();
     //-----------------------------------------
     // Show?
     //-----------------------------------------
     if (isset($this->request['show']) and $this->request['show'] == 'sinceLastVisit') {
         $this->request['prune_day'] = 200;
     }
     //-----------------------------------------
     // Are we actually a moderator for this forum?
     //-----------------------------------------
     $mod = $this->memberData['forumsModeratorData'];
     if (!$this->memberData['g_is_supmod']) {
         if (!isset($mod[$this->forum['id']]) or !is_array($mod[$this->forum['id']])) {
             $this->memberData['is_mod'] = 0;
         }
     }
     //-----------------------------------------
     // Announcements
     //-----------------------------------------
     if (is_array($this->registry->cache()->getCache('announcements')) and count($this->registry->cache()->getCache('announcements'))) {
         $announcements = array();
         foreach ($this->registry->cache()->getCache('announcements') as $announce) {
             $order = $announce['announce_start'] ? $announce['announce_start'] . ',' . $announce['announce_id'] : $announce['announce_id'];
             if ($announce['announce_forum'] == '*') {
                 $announcements[$order] = $announce;
             } else {
                 if (strstr(',' . $announce['announce_forum'] . ',', ',' . $this->forum['id'] . ',')) {
                     $announcements[$order] = $announce;
                 }
             }
         }
         if (count($announcements)) {
             //-----------------------------------------
             // sort by start date
             //-----------------------------------------
             krsort($announcements);
             foreach ($announcements as $announce) {
                 if ($announce['announce_start']) {
                     $announce['announce_start'] = $this->lang->getDate($announce['announce_start'], 'date');
                 } else {
                     $announce['announce_start'] = '--';
                 }
                 $announce['announce_title'] = IPSText::stripslashes($announce['announce_title']);
                 $announce['forum_id'] = $this->forum['id'];
                 $announce['announce_views'] = intval($announce['announce_views']);
                 $announce_data[] = $announce;
                 $member_ids[$announce['member_id']] = $announce['member_id'];
             }
             $this->forum['_showAnnouncementsBar'] = 1;
         }
     }
     //-----------------------------------------
     // Read topics
     //-----------------------------------------
     $First = $this->registry->class_forums->pageToSt(intval($this->request['page']));
     //-----------------------------------------
     // Sort options
     //-----------------------------------------
     $cookie_prune = IPSCookie::get($this->forum['id'] . "_prune_day");
     $cookie_sort = IPSCookie::get($this->forum['id'] . "_sort_key");
     $cookie_sortb = IPSCookie::get($this->forum['id'] . "_sort_by");
     $cookie_fill = IPSCookie::get($this->forum['id'] . "_topicfilter");
     $prune_value = $this->selectVariable(array(1 => !empty($this->request['prune_day']) ? $this->request['prune_day'] : NULL, 2 => !empty($cookie_prune) ? $cookie_prune : NULL, 3 => $this->forum['prune'], 4 => '100'));
     $sort_key = $this->selectVariable(array(1 => !empty($this->request['sort_key']) ? $this->request['sort_key'] : NULL, 2 => !empty($cookie_sort) ? $cookie_sort : NULL, 3 => $this->forum['sort_key'], 4 => 'last_post'));
     $sort_by = $this->selectVariable(array(1 => !empty($this->request['sort_by']) ? $this->request['sort_by'] : NULL, 2 => !empty($cookie_sortb) ? $cookie_sortb : NULL, 3 => $this->forum['sort_order'], 4 => 'Z-A'));
     $topicfilter = $this->selectVariable(array(1 => !empty($this->request['topicfilter']) ? $this->request['topicfilter'] : NULL, 2 => !empty($cookie_fill) ? $cookie_fill : NULL, 3 => $this->forum['topicfilter'], 4 => 'all'));
     if (!empty($this->request['remember'])) {
         if ($this->request['prune_day']) {
             IPSCookie::set($this->forum['id'] . "_prune_day", $this->request['prune_day']);
         }
         if ($this->request['sort_key']) {
             IPSCookie::set($this->forum['id'] . "_sort_key", $this->request['sort_key']);
         }
         if ($this->request['sort_by']) {
             IPSCookie::set($this->forum['id'] . "_sort_by", $this->request['sort_by']);
         }
         if ($this->request['topicfilter']) {
             IPSCookie::set($this->forum['id'] . "_topicfilter", $this->request['topicfilter']);
         }
     }
     //-----------------------------------------
     // Figure out sort order, day cut off, etc
     //-----------------------------------------
     $Prune = $prune_value < 100 ? time() - $prune_value * 60 * 60 * 24 : (($prune_value == 200 and $this->memberData['member_id']) ? $this->memberData['last_visit'] : 0);
     $sort_keys = array('last_post' => 'sort_by_date', 'last_poster_name' => 'sort_by_last_poster', 'title' => 'sort_by_topic', 'starter_name' => 'sort_by_poster', 'start_date' => 'sort_by_start', 'topic_hasattach' => 'sort_by_attach', 'posts' => 'sort_by_replies', 'views' => 'sort_by_views');
     $prune_by_day = array('1' => 'show_today', '5' => 'show_5_days', '7' => 'show_7_days', '10' => 'show_10_days', '15' => 'show_15_days', '20' => 'show_20_days', '25' => 'show_25_days', '30' => 'show_30_days', '60' => 'show_60_days', '90' => 'show_90_days', '100' => 'show_all', '200' => 'show_last_visit');
     $sort_by_keys = array('Z-A' => 'descending_order', 'A-Z' => 'ascending_order');
     $filter_keys = array('all' => 'topicfilter_all', 'open' => 'topicfilter_open', 'hot' => 'topicfilter_hot', 'poll' => 'topicfilter_poll', 'locked' => 'topicfilter_locked', 'moved' => 'topicfilter_moved');
     if ($this->memberData['member_id']) {
         $filter_keys['istarted'] = 'topicfilter_istarted';
         $filter_keys['ireplied'] = 'topicfilter_ireplied';
     }
     //-----------------------------------------
     // check for any form funny business by wanna-be hackers
     //-----------------------------------------
     if (!isset($filter_keys[$topicfilter]) or !isset($sort_keys[$sort_key]) or !isset($prune_by_day[$prune_value]) or !isset($sort_by_keys[strtoupper($sort_by)])) {
         $this->registry->getClass('output')->showError('forums_bad_filter', 10339);
     }
     $r_sort_by = $sort_by == 'A-Z' ? 'ASC' : 'DESC';
     //-----------------------------------------
     // If sorting by starter, add secondary..
     //-----------------------------------------
     $sort_key_chk = $sort_key;
     if ($sort_key == 'starter_name') {
         $sort_key = "starter_name {$r_sort_by}, t.last_post DESC";
         $r_sort_by = '';
     }
     //-----------------------------------------
     // Additional queries?
     //-----------------------------------------
     $add_query_array = array();
     $add_query = "";
     switch ($topicfilter) {
         case 'all':
             break;
         case 'open':
             $add_query_array[] = "t.state='open'";
             break;
         case 'hot':
             $add_query_array[] = "t.state='open' AND t.posts + 1 >= " . intval($this->settings['hot_topic']);
             break;
         case 'locked':
             $add_query_array[] = "t.state='closed'";
             break;
         case 'moved':
             $add_query_array[] = "t.state='link'";
             break;
         case 'poll':
             $add_query_array[] = "(t.poll_state='open' OR t.poll_state=1)";
             break;
         default:
             break;
     }
     if (!$this->memberData['g_other_topics'] or $topicfilter == 'istarted' or !$this->forum['can_view_others'] and !$this->memberData['is_mod']) {
         $add_query_array[] = "t.starter_id='" . $this->memberData['member_id'] . "'";
     }
     /* Answered / unanswered */
     if (isset($this->request['answered']) && $this->registry->class_forums->answerTopicsEnabled($this->forum['id'])) {
         if ($this->request['answered'] == 'true') {
             $add_query_array[] = 't.topic_answered_pid != 0';
         } else {
             if ($this->request['answered'] == 'false') {
                 $add_query_array[] = 't.topic_answered_pid = 0';
             }
         }
     }
     $_SQL_EXTRA = '';
     $_SQL_APPROVED = '';
     $_SQL_AGE_PRUNE = '';
     if (count($add_query_array)) {
         $_SQL_EXTRA = ' AND ' . implode(' AND ', $add_query_array);
     }
     //-----------------------------------------
     // Moderator?
     //-----------------------------------------
     $this->request['modfilter'] = isset($this->request['modfilter']) ? $this->request['modfilter'] : '';
     $modFilter = '';
     if ($this->memberData['is_mod']) {
         if ($this->request['modfilter'] == 'unapproved') {
             $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('hidden'), 't.') . ' OR t.topic_queuedposts';
         } elseif ($this->permissions['TopicSoftDeleteSee']) {
             if ($this->request['modfilter'] == 'hidden') {
                 $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('sdeleted'), 't.') . ' OR t.topic_deleted_posts';
             } else {
                 $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('visible', 'hidden', 'sdeleted'), 't.');
             }
         } else {
             $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('visible', 'hidden'), 't.');
         }
     } else {
         if ($this->permissions['TopicSoftDeleteSee']) {
             $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('visible', 'sdeleted'), 't.');
         } else {
             $modFilter = $this->registry->class_forums->fetchTopicHiddenQuery(array('visible'), 't.');
         }
     }
     if ($modFilter) {
         $_SQL_APPROVED = ' AND (' . $modFilter . ')';
     }
     if ($Prune) {
         if ($prune_value == 200) {
             /* Just new content, don't show pinned, please */
             if ($modFilter) {
                 $_SQL_AGE_PRUNE = " AND (t.last_post > {$Prune} AND ( {$modFilter} ) )";
             } else {
                 $_SQL_AGE_PRUNE = " AND (t.last_post > {$Prune})";
             }
         } else {
             if ($modFilter) {
                 $_SQL_AGE_PRUNE = " AND (t.pinned=1 or t.last_post > {$Prune} AND ( {$modFilter} ) )";
             } else {
                 $_SQL_AGE_PRUNE = " AND (t.pinned=1 or t.last_post > {$Prune})";
             }
         }
     }
     //-----------------------------------------
     // Query the database to see how many topics there are in the forum
     //-----------------------------------------
     if ($topicfilter == 'ireplied') {
         //-----------------------------------------
         // Checking topics we've replied to?
         //-----------------------------------------
         $this->DB->build(array('select' => 'COUNT(' . $this->DB->buildDistinct('p.topic_id') . ') as max', 'from' => array('topics' => 't'), 'where' => "t.forum_id={$this->forum['id']} AND p.author_id=" . $this->memberData['member_id'] . " AND p.new_topic=0" . $_SQL_APPROVED . $_SQL_AGE_PRUNE, 'add_join' => array(array('from' => array('posts' => 'p'), 'where' => 'p.topic_id=t.tid'))));
         $this->DB->execute();
         $total_possible = $this->DB->fetch();
     } else {
         if ($_SQL_EXTRA or $_SQL_AGE_PRUNE or $this->request['modfilter']) {
             $this->DB->build(array('select' => 'COUNT(*) as max', 'from' => 'topics t', 'where' => "t.forum_id=" . $this->forum['id'] . $_SQL_APPROVED . $_SQL_AGE_PRUNE . $_SQL_EXTRA));
             $this->DB->execute();
             $total_possible = $this->DB->fetch();
         } else {
             $total_possible['max'] = $this->memberData['is_mod'] ? $this->forum['topics'] + $this->forum['queued_topics'] : $this->forum['topics'];
             if ($this->permissions['TopicSoftDeleteSee'] and $this->forum['deleted_topics']) {
                 $total_possible['max'] += intval($this->forum['deleted_topics']);
             }
             $Prune = 0;
         }
     }
     //-----------------------------------------
     // Generate the forum page span links
     //-----------------------------------------
     $_extraStuff = '';
     if ($this->request['modfilter']) {
         $_extraStuff .= "&amp;modfilter=" . $this->request['modfilter'];
     }
     if (isset($this->request['answered']) && $this->registry->class_forums->answerTopicsEnabled($this->forum['id'])) {
         $_extraStuff .= "&amp;answered=" . $this->request['answered'];
     }
     $this->forum['SHOW_PAGES'] = $this->registry->getClass('output')->generatePagination(array('totalItems' => $total_possible['max'], 'itemsPerPage' => $this->settings['display_max_topics'], 'currentStartValue' => intval($this->request['page']), 'isPagesMode' => true, 'seoTitle' => $this->forum['name_seo'], 'disableSinglePage' => false, 'baseUrl' => "showforum=" . $this->forum['id'] . "&amp;prune_day={$prune_value}&amp;sort_by={$sort_by}&amp;sort_key={$sort_key_chk}&amp;topicfilter={$topicfilter}{$_extraStuff}"));
     //-----------------------------------------
     // Start printing the page
     //-----------------------------------------
     $other_data = array('forum_data' => $this->forum, 'hasMore' => $this->registry->class_forums->pageToSt($this->request['page']) + $this->settings['display_max_topics'] > $total_possible['max'] ? false : true, 'can_edit_topics' => $this->can_edit_topics, 'can_open_topics' => $this->can_open_topics, 'can_close_topics' => $this->can_close_topics, 'can_move_topics' => $this->can_move_topics);
     $total_topics_printed = 0;
     //-----------------------------------------
     // Get main topics
     //-----------------------------------------
     $topic_array = array();
     $topic_ids = array();
     $topic_sort = "";
     //-----------------------------------------
     // Cut off?
     //-----------------------------------------
     $modAll = ($this->memberData['g_is_supmod'] or isset($this->memberData['forumsModeratorData'][$this->forum['id']]) and ($this->memberData['forumsModeratorData'][$this->forum['id']]['delete_topic'] or $this->memberData['forumsModeratorData'][$this->forum['id']]['move_topic'] or $this->memberData['forumsModeratorData'][$this->forum['id']]['split_merge']));
     $parse_dots = 1;
     if ($topicfilter == 'ireplied') {
         //-----------------------------------------
         // Checking topics we've replied to?
         // No point in getting dots again...
         //-----------------------------------------
         $parse_dots = 0;
         $_joins = array(array('select' => 't.*', 'from' => array('posts' => 'p'), 'where' => 'p.topic_id=t.tid AND p.author_id=' . $this->memberData['member_id']));
         if ($this->settings['tags_enabled'] and !$this->forum['bw_disable_tagging']) {
             $_joins[] = $this->registry->tags->getCacheJoin(array('meta_id_field' => 't.tid'));
         }
         // For some reason, mySQL doesn't like the distinct + t.* being in reverse order...
         $this->DB->build(array('select' => $this->DB->buildDistinct('p.author_id'), 'from' => array('topics' => 't'), 'where' => "t.forum_id=" . $this->forum['id'] . " AND t.pinned IN (0,1)" . $_SQL_APPROVED . $_SQL_AGE_PRUNE . " AND p.new_topic=0", 'order' => "t.pinned desc,{$topic_sort} t.{$sort_key} {$r_sort_by}", 'limit' => array(intval($First), intval($this->settings['display_max_topics'])), 'add_join' => $_joins));
         $this->DB->execute();
     } else {
         $this->DB->build(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => "t.forum_id=" . $this->forum['id'] . " AND t.pinned IN (0,1)" . $_SQL_APPROVED . $_SQL_AGE_PRUNE . $_SQL_EXTRA, 'order' => 't.pinned DESC, ' . $topic_sort . ' t.' . $sort_key . ' ' . $r_sort_by, 'limit' => array(intval($First), $this->settings['display_max_topics']), 'add_join' => ($this->settings['tags_enabled'] and !$this->forum['bw_disable_tagging']) ? array($this->registry->tags->getCacheJoin(array('meta_id_field' => 't.tid'))) : array()));
         $this->DB->execute();
     }
     while ($t = $this->DB->fetch()) {
         /* Should we display the moderate checkbox for this post? */
         $t['moddable'] = FALSE;
         if ($modAll or isset($this->memberData['forumsModeratorData'][$this->forum['id']]) and ($t['pinned'] == 0 and $this->memberData['forumsModeratorData'][$this->forum['id']]['pin_topic'] or $t['pinned'] == 1 and $this->memberData['forumsModeratorData'][$this->forum['id']]['unpin_topic'] or $t['state'] == 'open' and $this->memberData['forumsModeratorData'][$this->forum['id']]['close_topic'] or $t['state'] == 'closed' and $this->memberData['forumsModeratorData'][$this->forum['id']]['open_topic'])) {
             $t['moddable'] = TRUE;
         }
         /* Add to array */
         $topic_array[$t['tid']] = $t;
         $topic_ids[$t['tid']] = $t['tid'];
         if ($t['last_poster_id']) {
             $member_ids[$t['last_poster_id']] = $t['last_poster_id'];
         }
         if ($t['starter_id']) {
             $member_ids[$t['starter_id']] = $t['starter_id'];
         }
     }
     ksort($topic_ids);
     //-----------------------------------------
     // Are we dotty?
     //-----------------------------------------
     if ($this->settings['show_user_posted'] == 1 and $this->memberData['member_id'] and count($topic_ids) and $parse_dots) {
         $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), '');
         $this->DB->build(array('select' => $this->DB->buildDistinct('topic_id'), 'from' => 'posts', 'where' => $_queued . ' AND author_id=' . $this->memberData['member_id'] . ' AND topic_id IN(' . implode(',', $topic_ids) . ')'));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             if (is_array($topic_array[$p['topic_id']])) {
                 $topic_array[$p['topic_id']]['author_id'] = $this->memberData['member_id'];
             }
         }
     }
     //-----------------------------------------
     // Get needed members
     //-----------------------------------------
     if (count($member_ids)) {
         $_members = IPSMember::load($member_ids);
         //-----------------------------------------
         // Add member data to announcements
         //-----------------------------------------
         $new_announces = array();
         foreach ($announce_data as $announce) {
             $announce = array_merge($announce, IPSMember::buildDisplayData($_members[$announce['member_id']]));
             $new_announces[] = $announce;
         }
         $announce_data = $new_announces;
     }
     //-----------------------------------------
     // Show meh the topics!
     //-----------------------------------------
     $adCodeSet = false;
     foreach ($topic_array as $topic) {
         /* Add member */
         if ($topic['last_poster_id']) {
             $topic = array_merge(IPSMember::buildDisplayData($_members[$topic['last_poster_id']]), $topic);
         } else {
             $topic = array_merge(IPSMember::buildProfilePhoto(array()), $topic);
         }
         if ($topic['starter_id']) {
             $topic['_starter'] = $_members[$topic['starter_id']];
         }
         /* AD Code */
         if ($this->registry->getClass('IPSAdCode')->userCanViewAds() && !$adCodeSet) {
             $topic['_adCode'] = $this->registry->getClass('IPSAdCode')->getAdCode('ad_code_forum_view_topic_code');
             if ($topic['_adCode']) {
                 $adCodeSet = true;
             }
         }
         if ($topic['pinned']) {
             $this->pinned_topic_count++;
         }
         $topic_data[$topic['tid']] = $this->renderEntry($topic);
         $total_topics_printed++;
     }
     //-----------------------------------------
     // Finish off the rest of the page  $filter_keys[$topicfilter]))
     //-----------------------------------------
     $sort_by_html = "";
     $sort_key_html = "";
     $prune_day_html = "";
     $filter_html = "";
     foreach ($sort_by_keys as $k => $v) {
         $sort_by_html .= $k == $sort_by ? "<option value='{$k}' selected='selected'>{$this->lang->words[$sort_by_keys[$k]]}</option>\n" : "<option value='{$k}'>{$this->lang->words[$sort_by_keys[$k]]}</option>\n";
     }
     foreach ($sort_keys as $k => $v) {
         $sort_key_html .= $k == $sort_key_chk ? "<option value='{$k}' selected='selected'>{$this->lang->words[$sort_keys[$k]]}</option>\n" : "<option value='{$k}'>{$this->lang->words[$sort_keys[$k]]}</option>\n";
     }
     foreach ($prune_by_day as $k => $v) {
         $prune_day_html .= $k == $prune_value ? "<option value='{$k}' selected='selected'>{$this->lang->words[$prune_by_day[$k]]}</option>\n" : "<option value='{$k}'>{$this->lang->words[$prune_by_day[$k]]}</option>\n";
     }
     foreach ($filter_keys as $k => $v) {
         $filter_html .= $k == $topicfilter ? "<option value='{$k}' selected='selected'>{$this->lang->words[$filter_keys[$k]]}</option>\n" : "<option value='{$k}'>{$this->lang->words[$filter_keys[$k]]}</option>\n";
     }
     $footer_filter['sort_by'] = $sort_key_html;
     $footer_filter['sort_order'] = $sort_by_html;
     $footer_filter['sort_prune'] = $prune_day_html;
     $footer_filter['topic_filter'] = $filter_html;
     if ($this->memberData['is_mod']) {
         $count = 0;
         $other_pages = 0;
         if ($this->request['selectedtids'] != "") {
             $tids = explode(",", $this->request['selectedtids']);
             if (is_array($tids) and count($tids)) {
                 foreach ($tids as $tid) {
                     if ($tid != '') {
                         if (!isset($topic_array[$tid])) {
                             $other_pages++;
                         }
                         $count++;
                     }
                 }
             }
         }
         $this->lang->words['f_go'] .= " ({$count})";
         if ($other_pages) {
             $this->lang->words['f_go'] .= " ({$other_pages} " . $this->lang->words['jscript_otherpage'] . ")";
         }
     }
     //-----------------------------------------
     // Multi-moderation?
     //-----------------------------------------
     if ($this->memberData['is_mod']) {
         $mm_array = $this->registry->getClass('class_forums')->getMultimod($this->forum['id']);
         if (is_array($mm_array) and count($mm_array)) {
             foreach ($mm_array as $m) {
                 $multi_mod_data[] = $m;
             }
         }
     }
     //-----------------------------------------
     // Need to update topics?
     //-----------------------------------------
     if (count($this->update_topics_open)) {
         $this->DB->update('topics', array('state' => 'open'), 'tid IN (' . implode(",", $this->update_topics_open) . ')');
     }
     if (count($this->update_topics_close)) {
         $this->DB->update('topics', array('state' => 'closed'), 'tid IN (' . implode(",", $this->update_topics_close) . ')');
     }
     /* Got soft delete tids? */
     if (is_array($this->_sdTids) and count($this->_sdTids)) {
         $other_data['sdData'] = IPSDeleteLog::fetchEntries($this->_sdTids, 'topic', false);
     }
     /* Fetch follow data */
     $other_data['follow_data'] = $this->_like->render('summary', $this->forum['id']);
     return array('announce_data' => $announce_data, 'topic_data' => $topic_data, 'other_data' => $other_data, 'multi_mod_data' => $multi_mod_data, 'footer_filter' => $footer_filter, 'active_users' => $this->_generateActiveUserData());
 }
Example #6
0
 /**
  * Formats / grabs extra data for results
  * Takes an array of IDS (can be IDs from anything) and returns an array of expanded data.
  *
  * @param	array 	$ids			Ids
  * @param	array	$followData		Retrieve the follow meta data
  * @return array
  */
 public function processResults($ids, $followData = array())
 {
     /* INIT */
     $sort_by = IPSSearchRegistry::get('in.search_sort_by');
     $sort_order = IPSSearchRegistry::get('in.search_sort_order');
     $search_term = IPSSearchRegistry::get('in.clean_search_term');
     $content_title_only = IPSSearchRegistry::searchTitleOnly();
     $_post_joins = array();
     $members = array();
     $results = array();
     $topicIds = array();
     $dots = array();
     $sortKey = '';
     $sortType = '';
     $_sdTids = array();
     $_sdPids = array();
     /* Set up some basic permissions */
     $permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts(0);
     $permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics(0);
     $permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts(0);
     $permissions['SoftDeleteReason'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteReason(0);
     $permissions['SoftDeleteContent'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteContent(0);
     $permissions['PostSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeletePosts(0);
     $permissions['TopicSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeleteTopics(0);
     /* Got some? */
     if (count($ids)) {
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'p.' . $this->table['pid']);
             }
             if (IPSContentCache::fetchSettingValue('sig')) {
                 $_post_joins[] = IPSContentCache::join('sig', 'p.' . $this->table['author_id'], 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
             }
         }
         if ($this->registry->tags->isEnabled()) {
             $_post_joins[] = $this->registry->tags->getCacheJoin(array('meta_id_field' => 't.tid'));
         }
         /* Sorting */
         switch ($sort_by) {
             default:
             case 'date':
                 $sortKey = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_post' : $this->table['post_date'];
                 $sortType = 'numerical';
                 break;
             case 'title':
                 $sortKey = 'title';
                 $sortType = 'string';
                 break;
             case 'posts':
                 $sortKey = 'posts';
                 $sortType = 'numerical';
                 break;
             case 'views':
                 $sortKey = 'views';
                 $sortType = 'numerical';
                 break;
         }
         /* Set vars */
         IPSSearch::$ask = $sortKey;
         IPSSearch::$aso = strtolower($sort_order);
         IPSSearch::$ast = $sortType;
         /* If we are search in titles only, then the ID array will be TIDs */
         if (IPSSearchRegistry::get('set.returnType') == 'tids') {
             $k = 'tid';
             $this->DB->build(array('select' => "t.*", 'from' => array('topics' => 't'), 'where' => 't.tid IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 'p.*', 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . '=t.topic_firstpost', 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         } else {
             $k = $this->table['pid'];
             $this->DB->build(array('select' => "p.*", 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . ' IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.' . $this->table['topic_id'], 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         }
         /* Grab data */
         $this->DB->execute();
         /* Grab the results */
         while ($row = $this->DB->fetch()) {
             $_rows[$row[$k]] = $this->searchArchives ? $this->archiveReader->archiveToNativeFields($row) : $row;
         }
         /* Get the 'follow' meta data? */
         if (count($followData)) {
             $followData = classes_like_meta::get($followData);
             /* Merge the data from the follow class into the results */
             foreach ($followData as $_formatted) {
                 $_rows[$_formatted['like_rel_id']]['_followData'] = $_formatted;
             }
         }
         /* Sort */
         if (count($_rows)) {
             usort($_rows, array("IPSSearch", "usort"));
             foreach ($_rows as $id => $row) {
                 /* Prevent member from stepping on it */
                 $row['topic_title'] = $row['title'];
                 /* Get author data? */
                 if ($k == 'tid') {
                     if (!empty($row['last_poster_id'])) {
                         $members[$row['last_poster_id']] = $row['last_poster_id'];
                     }
                 } else {
                     if (!empty($row['author_id'])) {
                         $members[$row['author_id']] = $row['author_id'];
                     }
                 }
                 /* Topic ids? */
                 if (!empty($row['topic_id'])) {
                     $topicIds[$row['topic_id']] = $row['topic_id'];
                 }
                 /* If we're using sphinx, check forum permissions again as the 15 minute delta rebuild could expose a moved topic before deltas rebuild.
                    We don't need to do this for SQL search as the results are delivered live and lets face it, we can do without the load  */
                 if ($this->settings['search_method'] != 'traditional') {
                     /* Can we read? */
                     if (!$this->registry->permissions->check('view', $this->registry->class_forums->forum_by_id[$row['forum_id']])) {
                         continue;
                     }
                     /* Can read, but is it password protected, etc? */
                     if (!$this->registry->class_forums->forumsCheckAccess($row['forum_id'], 0, 'forum', array(), true)) {
                         continue;
                     }
                 }
                 $row['cleanSearchTerm'] = urlencode($search_term);
                 $row['topicPrefix'] = $row['pinned'] ? $this->registry->getClass('output')->getTemplate('forum')->topicPrefixWrap($this->lang->words['pre_pinned']) : '';
                 $row['_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'visible' ? true : false;
                 $row['_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'hidden' ? true : false;
                 $row['_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'sdelete' ? true : false;
                 $row['_p_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'visible' ? true : false;
                 $row['_p_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'hidden' ? true : false;
                 $row['_p_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'sdelete' ? true : false;
                 /* Hidden and we do not have permission? */
                 if ($row['_isHidden'] and !$permissions['canQueue']) {
                     continue;
                 }
                 /* Is the topic deleted? If so, then the first post will appear as such */
                 if ($row['_isDeleted'] and $permissions['TopicSoftDeleteSee']) {
                     $row['_p_isDeleted'] = true;
                     $_sdPids[$row['pid']] = $row['pid'];
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_isDeleted']) {
                     if ($permissions['TopicSoftDeleteSee']) {
                         $_sdTids[$row['tid']] = $row['tid'];
                     } else {
                         continue;
                     }
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_p_isDeleted']) {
                     if ($permissions['PostSoftDeleteSee']) {
                         $_sdPids[$row['pid']] = $row['pid'];
                     } else {
                         continue;
                     }
                 }
                 /* Tags */
                 if (!empty($row['tag_cache_key'])) {
                     $row['tags'] = $this->registry->tags->formatCacheJoinData($row);
                 }
                 $results[$k == 'tid' ? $row['tid'] : $row['pid']] = $this->genericizeResults($row);
             }
         }
         /* Need to load members? */
         if (count($members)) {
             $mems = IPSMember::load($members, 'all');
             $mems[0] = array();
             foreach ($results as $id => $r) {
                 $_memberIdColumn = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_poster_id' : 'author_id';
                 if (isset($mems[$r[$_memberIdColumn]])) {
                     $mems[$r[$_memberIdColumn]]['m_posts'] = $mems[$r[$_memberIdColumn]]['posts'];
                     unset($mems[$r[$_memberIdColumn]]['last_post']);
                     if (isset($r['cache_content_sig'])) {
                         $mems[$r[$_memberIdColumn]]['cache_content'] = $r['cache_content_sig'];
                         $mems[$r[$_memberIdColumn]]['cache_updated'] = $r['cache_updated_sig'];
                     }
                     $_mem = IPSMember::buildDisplayData($mems[$r[$_memberIdColumn]], array('reputation' => 0, 'warn' => 0));
                     unset($_mem['cache_content'], $_mem['cache_updated']);
                     $results[$id]['_realPosts'] = $results[$id]['posts'];
                     $results[$id] = array_merge($results[$id], $_mem);
                     $results[$id]['posts'] = $results[$id]['_realPosts'];
                 }
             }
         }
         /* Generate 'dot' folder icon */
         if ($this->settings['show_user_posted'] and count($topicIds)) {
             $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), '');
             $this->DB->build(array('select' => 'author_id, topic_id', 'from' => 'posts', 'where' => $_queued . ' AND author_id=' . $this->memberData['member_id'] . ' AND topic_id IN(' . implode(',', $topicIds) . ')'));
             $this->DB->execute();
             while ($p = $this->DB->fetch()) {
                 $dots[$p['topic_id']] = 1;
             }
             /* Merge into results */
             foreach ($results as $id => $r) {
                 if (isset($dots[$r['topic_id']])) {
                     $results[$id]['_hasPosted'] = 1;
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdTids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdTids, 'topic', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdTids[$data['tid']])) {
                         $results[$id]['sData'] = $sData[$data['tid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdPids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdPids, 'post', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdPids[$data['pid']]) and !isset($results[$id]['sData'])) {
                         $results[$id]['sData'] = $sData[$data['pid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
     }
     return $results;
 }
Example #7
0
 /**
  * Unhide a comment
  *
  * @param	int			Parent ID
  * @param	int|array	Comment IDs
  * @param	int|array	Member Data
  * @return	bool|string	TRUE on sucess, error string on error
  */
 public function unhide($parentId, $commentIds, $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('unhide', 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 */
     IPSDeleteLog::removeEntries($commentIds, $this->whoAmI());
     return true;
 }
Example #8
0
 /**
  * Main Execution Function
  *
  * @param	object		Registry reference
  * @return	@e void		[Outputs to screen/redirects]
  */
 public function doExecute(ipsRegistry $registry)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $post_data = array();
     $poll_data = '';
     $function = '';
     /* Print CSS */
     $this->registry->output->addToDocumentHead('raw', "<link rel='stylesheet' type='text/css' title='Main' media='print' href='{$this->settings['css_base_url']}style_css/{$this->registry->output->skin['_csscacheid']}/ipb_print.css' />");
     /* Followed stuffs */
     require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php';
     /*noLibHook*/
     $this->_like = classes_like::bootstrap('forums', 'topics');
     /* Init */
     if (!$this->registry->isClassLoaded('topics')) {
         $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums');
         $this->registry->setClass('topics', new $classToLoad($this->registry));
     }
     try {
         /* Load up the data dudes */
         $this->registry->getClass('topics')->autoPopulate(null, false);
     } catch (Exception $crowdCheers) {
         $msg = str_replace('EX_', '', $crowdCheers->getMessage());
         $this->registry->output->showError($msg, 10340, null, null, 404);
     }
     /* Shortcut */
     $this->forumClass = $this->registry->getClass('class_forums');
     /* Setup basics for this method */
     $topicData = $this->registry->getClass('topics')->getTopicData();
     $forumData = $this->forumClass->getForumById($topicData['forum_id']);
     /* VigLink */
     if (!$forumData['viglink']) {
         $this->settings['viglink_enabled'] = FALSE;
     }
     /* Rating */
     $this->can_rate = $this->memberData['member_id'] ? intval($this->memberData['g_topic_rate_setting']) : 0;
     /* Set up topic */
     $topicData = $this->topicSetUp($topicData);
     /* Specific view? */
     $this->_doViewCheck();
     /* Get Posts */
     $_NOW = IPSDebug::getMemoryDebugFlag();
     if ($this->registry->getClass('topics')->isArchived($topicData) && $this->registry->class_forums->fetchArchiveTopicType($topicData) != 'working') {
         /* Load up archive class */
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/archive/reader.php', 'classes_archive_reader');
         $this->archiveReader = new $classToLoad();
         $this->archiveReader->setApp('forums');
         $postData = $this->archiveReader->get(array('parentData' => $topicData, 'goNative' => true, 'offset' => intval($this->registry->getClass('topics')->pageToSt($this->request['page'])), 'limit' => intval($this->settings['display_max_posts']), 'sortKey' => $this->settings['post_order_column'], 'sortOrder' => $this->settings['post_order_sort']));
     } else {
         $postData = $this->_getPosts();
     }
     /* Finish off post Data */
     if (count($postData)) {
         foreach ($postData as $pid => $data) {
             $postData[$pid] = $this->parsePostRow($data);
         }
     }
     /* Do we have a P parameter, and if so, is it actually in this set of results? */
     if (!$this->request['view'] && ($this->request['p'] && !in_array($this->request['p'], array_keys($postData)))) {
         /* Go find it */
         $this->request['view'] = 'findpost';
         $this->_doViewCheck();
         /* Exits above */
     }
     unset($this->cached_members);
     /* Status? */
     if ($topicData['_ppd_ok'] === TRUE) {
         /* status from PPD */
         if ($this->forumClass->ppdStatusMessage) {
             $topicData['_fastReplyStatusMessage'][] = $this->forumClass->ppdStatusMessage;
         }
     }
     $topicData['_fastReplyModAll'] = FALSE;
     switch (intval($forumData['preview_posts'])) {
         case 1:
         case 3:
             $topicData['_fastReplyModAll'] = TRUE;
             break;
     }
     //-----------------------------------------
     // Update the item marker
     //-----------------------------------------
     if (!$this->request['view'] && !$this->registry->getClass('topics')->isArchived($topicData)) {
         /* If we marked page 2 but land back on page 1 again we don't want to unmark it! */
         $lastMarked = $this->registry->classItemMarking->fetchTimeLastMarked(array('forumID' => $forumData['id'], 'itemID' => $topicData['tid']));
         /* is this the very last page? */
         if ($this->registry->getClass('topics')->isOnLastPage()) {
             /* ...then make the timestamp 'NOW' so polls will be cleared correctly */
             $this->_maxPostDate = IPS_UNIX_TIME_NOW;
         }
         if ($lastMarked < $this->_maxPostDate) {
             $this->registry->getClass('classItemMarking')->markRead(array('forumID' => $forumData['id'], 'itemID' => $topicData['tid'], 'markDate' => $this->_maxPostDate, 'containerLastActivityDate' => $forumData['last_post']));
         }
     }
     /* add meta update time */
     if ($this->_maxPostDate) {
         $this->registry->output->addMetaTag('og:updated_time', $this->_maxPostDate, false);
     }
     /* Set has unread flag */
     $forumData['_hasUnreadTopics'] = $this->registry->getClass('class_forums')->getHasUnread($forumData['id']);
     IPSDebug::setMemoryDebugFlag("TOPICS: Parsed Posts - Completed", $_NOW);
     //-----------------------------------------
     // Generate template
     //-----------------------------------------
     $topicData['id'] = $topicData['forum_id'];
     //-----------------------------------------
     // This has to be called first to set $this->poll_only
     //-----------------------------------------
     $poll_data = $topicData['poll_state'] ? $this->_generatePollOutput() : array('html' => '', 'poll' => '');
     $displayData = array('fast_reply' => $this->_getFastReplyData(), 'multi_mod' => $this->registry->getClass('topics')->getMultiModerationData(), 'reply_button' => $this->_getReplyButtonData(), 'active_users' => $this->_getActiveUserData(), 'mod_links' => $this->registry->getClass('topics')->isArchived($topicData) ? '' : $this->_generateModerationPanel(), 'follow_data' => ($this->registry->getClass('topics')->isArchived($topicData) or $topicData['_isDeleted']) ? '' : $this->_like->render('summary', $topicData['tid']), 'same_tagged' => $this->registry->getClass('topics')->isArchived($topicData) ? '' : $this->_getSameTaggedData(), 'poll_data' => $poll_data, 'load_editor_js' => $this->_getFastReplyData() && $topicData['_isDeleted'] ? true : false, 'smilies' => '', 'best_answer_post_data' => $this->_getBestAnswerFeature($postData, $topicData));
     //-----------------------------------------
     // If we can edit, but not reply, load JS still
     //-----------------------------------------
     if (!($displayData['fast_reply'] and $displayData['reply_button']['url']) and $this->_canEditAPost) {
         $displayData['load_editor_js'] = true;
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
         $editor = new $classToLoad();
         $displayData['smilies'] = $editor->fetchEmoticons();
     }
     $postData = $this->_parseAttachments($postData);
     /* Rules */
     if ($forumData['show_rules'] == 2) {
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_html = 1;
         IPSText::getTextClass('bbcode')->parse_nl2br = 1;
         IPSText::getTextClass('bbcode')->parse_bbcode = 1;
         IPSText::getTextClass('bbcode')->parsing_section = 'topics';
         IPSText::getTextClass('bbcode')->parsing_mgroup = $this->memberData['member_group_id'];
         IPSText::getTextClass('bbcode')->parsing_mgroup_others = $this->memberData['mgroup_others'];
         $forumData['rules_text'] = IPSText::getTextClass('bbcode')->preDisplayParse($forumData['rules_text']);
     }
     /* Got soft delete pids? */
     if (is_array($this->_sdPids) and count($this->_sdPids)) {
         $displayData['sdData'] = IPSDeleteLog::fetchEntries($this->_sdPids, 'post', false);
     }
     if ($topicData['_isDeleted']) {
         $topicData['sdData'] = IPSDeleteLog::fetchEntries(array($topicData['tid']), 'topic', false);
         $topicData['sdData'] = $topicData['sdData'][$topicData['tid']];
     }
     if ($topicData['starter_id']) {
         $topicData['_starter'] = IPSMember::buildDisplayData(IPSMember::load($topicData['starter_id']));
     } else {
         $topicData['_starter'] = IPSMember::buildDisplayData(IPSMember::setUpGuest($topicData['starter_name'] ? $this->settings['guest_name_pre'] . $topicData['starter_name'] . $this->settings['guest_name_suf'] : ''));
     }
     /* Can we report? */
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary', 'core');
     $reports = new $classToLoad($this->registry);
     $topicData['_canReport'] = $reports->canReport('post');
     /* No likey no lighty */
     require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php';
     /*noLibHook*/
     $_like = classes_like::bootstrap('forums', 'topics');
     $topicData['_isLiked'] = $this->memberData['member_id'] ? $_like->isLiked($topicData['tid'], $this->memberData['member_id']) : false;
     $template = $this->registry->output->getTemplate('topic')->topicViewTemplate($forumData, $topicData, $postData, $displayData);
     //-----------------------------------------
     // Send for output
     //-----------------------------------------
     $this->registry->output->setTitle(strip_tags($topicData['title']) . '<%pageNumber%> - ' . $forumData['name'] . ' - ' . $this->settings['board_name']);
     $this->registry->output->addContent($template);
     if (is_array($this->nav) and count($this->nav)) {
         foreach ($this->nav as $_nav) {
             $this->registry->output->addNavigation($_nav[0], $_nav[1], $_nav[2], $_nav[3]);
         }
     }
     /**
      * Add navigational links
      */
     $this->registry->output->addToDocumentHead('raw', "<link rel='up' href='" . $this->registry->output->buildSEOUrl('showforum=' . $topicData['forum_id'], 'publicNoSession', $forumData['name_seo'], 'showforum') . "' />");
     $this->registry->output->addToDocumentHead('raw', "<link rel='author' href='" . $this->registry->output->buildSEOUrl('showuser='******'starter_id'], 'publicNoSession', $topicData['seo_first_name'], 'showuser') . "' />");
     /* Add Meta Content */
     if ($this->_firstPostContent) {
         /* Strip tags on title to ensure multi-mod added code isn't displayed */
         $this->registry->output->addMetaTag('keywords', strip_tags(trim($topicData['title']) . ' ' . str_replace("\n", " ", str_replace("\r", "", strip_tags($this->_firstPostContent)))), TRUE);
     }
     $pageData = $this->registry->output->getPaginationProcessedData();
     $pageMeta = $pageData['pages'] > 1 ? sprintf($this->lang->words['topic_meta_pages'], $pageData['current_page'], $pageData['pages']) . ' ' : '';
     # Trim to 155 chars based on Dan's recommendation
     $this->registry->output->addMetaTag('description', trim($pageMeta . sprintf($this->lang->words['topic_meta_description'], strip_tags($topicData['title']), $forumData['name'], str_replace("\r", "", $this->_firstPostContent))), FALSE);
     /* Set Ad code for the board index */
     if ($this->registry->getClass('IPSAdCode')->userCanViewAds()) {
         $this->registry->getClass('IPSAdCode')->setGlobalCode('header', 'ad_code_topic_view_header');
         $this->registry->getClass('IPSAdCode')->setGlobalCode('footer', 'ad_code_topic_view_footer');
     }
     $this->registry->output->sendOutput();
 }