/** * Displays a topic preview * * @return @e void */ protected function _topicPreview() { /* INIT */ $tid = intval($this->request['tid']); $pid = intval($this->request['pid']); $sTerm = trim($this->request['searchTerm']); $topic = array(); $posts = array(); $permissions = array(); $query = ''; /* Topic visibility */ $_perms = array('visible'); if ($this->registry->getClass('class_forums')->canSeeSoftDeletedTopics(false)) { $_perms[] = 'sdelete'; } if ($this->registry->getClass('class_forums')->canQueuePosts(false)) { $_perms[] = 'hidden'; } /* Grab topic data and first post */ $topic = $this->DB->buildAndFetch(array('select' => '*, title as topic_title, posts as topic_posts, last_post as topic_last_post', 'from' => 'topics', 'where' => $this->registry->class_forums->fetchTopicHiddenQuery($_perms) . ' AND tid=' . $tid)); if (!$topic['tid']) { return $this->returnString('no_topic'); } /* Permission check */ if ($this->registry->class_forums->forumsCheckAccess($topic['forum_id'], 0, 'topic', $topic, true) !== true) { return $this->returnString('no_permission'); } /* is archived? */ $isArchived = $this->registry->topics->isArchived($topic); /* Build permissions */ $permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts($topic['forum_id']); $permissions['SoftDeleteContent'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteContent($topic['forum_id']); $permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics($topic['forum_id']); $permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts($topic['forum_id']); /* Boring old boringness */ if ($permissions['canQueue']) { if ($permissions['PostSoftDeleteSee']) { $query = $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden', 'sdeleted'), $this->registry->topics->getPostTableField('_prefix_', $isArchived)) . ' AND '; } else { $query = $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden'), $this->registry->topics->getPostTableField('_prefix_', $isArchived)) . ' AND '; } } else { if ($permissions['PostSoftDeleteSee']) { $query = $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'sdeleted'), $this->registry->topics->getPostTableField('_prefix_', $isArchived)) . ' AND '; } else { $query = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), $this->registry->topics->getPostTableField('_prefix_', $isArchived)) . ' AND '; } } /* Get first post */ $_post = $this->registry->topics->getPosts(array('onlyViewable' => true, 'skipForumCheck' => true, 'sortField' => $this->settings['post_order_column'], 'sortOrder' => 'asc', 'topicId' => array($topic['tid']), 'limit' => 1, 'archiveToNative' => true, 'isArchivedTopic' => $this->registry->topics->isArchived($topic))); $posts['first'] = array_pop($_post); /* Archived? Get last post */ if ($topic['topic_posts'] && $isArchived) { /* Get last post */ $_post = $this->registry->topics->getPosts(array('onlyViewable' => true, 'skipForumCheck' => true, 'sortField' => $this->settings['post_order_column'], 'sortOrder' => 'desc', 'topicId' => array($topic['tid']), 'limit' => 1, 'archiveToNative' => true, 'isArchivedTopic' => $this->registry->topics->isArchived($topic))); $posts['last'] = array_pop($_post); } else { if ($topic['topic_posts'] && !$isArchived) { /* Grab number of unread posts? */ $last_time = $this->registry->classItemMarking->fetchTimeLastMarked(array('forumID' => $topic['forum_id'], 'itemID' => $tid)); if ($last_time and $last_time < $topic['topic_last_post']) { $count = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count, MAX(' . $this->registry->topics->getPostTableField($this->settings['post_order_column'], $isArchived) . ') as max, MIN(' . $this->settings['post_order_column'] . ') as min', 'from' => $this->registry->topics->getPostTableField('_table_', $isArchived), 'where' => $query . $this->registry->topics->getPostTableField('topic_id', $isArchived) . "={$tid} AND " . $this->registry->topics->getPostTableField('post_date', $isArchived) . " > " . intval($last_time))); } else { $count = $this->DB->buildAndFetch(array('select' => 'MAX(' . $this->registry->topics->getPostTableField($this->settings['post_order_column'], $isArchived) . ') as max', 'from' => $this->registry->topics->getPostTableField('_table_', $isArchived), 'where' => $query . $this->registry->topics->getPostTableField('topic_id', $isArchived) . "={$tid}")); $count['min'] = 0; $count['count'] = 0; } $topic['_lastRead'] = $last_time; $topic['_unreadPosts'] = intval($count['count']); /* Got a max and min */ if ($count['max']) { $_posts = $this->registry->topics->getPosts(array('onlyViewable' => true, 'postId' => $this->settings['post_order_column'] == 'pid' ? array(intval($count['min']), intval($count['max'])) : array(), 'postDate' => $this->settings['post_order_column'] == 'post_date' ? array(intval($count['min']), intval($count['max'])) : array(), 'archiveToNative' => true, 'isArchivedTopic' => $this->registry->topics->isArchived($topic))); foreach ($_posts as $pid => $r) { $r['tid'] = $topic['tid']; $r['title_seo'] = $topic['title_seo']; if ($r[$this->settings['post_order_column']] == $count['max']) { $posts['last'] = $r; } else { $posts['unread'] = $r; } } } if (is_array($posts['unread']) and is_array($posts['last'])) { if ($posts['unread']['pid'] == $posts['last']['pid']) { unset($posts['unread']); } else { if ($posts['unread']['pid'] == $posts['first']['pid']) { unset($posts['unread']); } } } } } /* Search? */ if ($pid and $sTerm) { $_posts = $this->registry->topics->getPosts(array('onlyViewable' => true, 'postId' => array($pid), 'archiveToNative' => true, 'isArchivedTopic' => $this->registry->topics->isArchived($topic))); $posts['search'] = array_pop($_posts); } $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser'); $parser = new $classToLoad(); /* Set up some settings */ $parser->set(array('parseArea' => 'topics', 'memberData' => $this->memberData, 'parseBBCode' => $this->registry->class_forums->forum_by_id[$topic['forum_id']]['use_ibc'], 'parseHtml' => ($this->registry->class_forums->forum_by_id[$topic['forum_id']]['use_html'] and $this->caches['group_cache'][$data['member_group_id']]['g_dohtml'] and $data['post_htmlstate']) ? 1 : 0, 'parseEmoticons' => $data['use_emo'])); /* Still here? */ foreach ($posts as $k => $data) { $data = IPSMember::buildDisplayData($data); $data['post'] = $parser->stripQuotes($data['post']); $data['post'] = $parser->display($data['post']); /* Search term? */ if ($k == 'search' and $pid and $sTerm) { $data['post'] = IPSText::truncateTextAroundPhrase(IPSText::getTextClass('bbcode')->stripAllTags(str_replace('<br />', ' ', strip_tags($data['post'], '<br>'))), $sTerm); $data['post'] = IPSText::searchHighlight($data['post'], $sTerm); } else { $data['post'] = IPSText::truncate(IPSText::getTextClass('bbcode')->stripAllTags(strip_tags($data['post'], '<br>')), 500); } $data['_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenType($data) == 'visible' ? true : false; $data['_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenType($data) == 'hidden' ? true : false; $data['_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenType($data) == 'sdelete' ? true : false; $posts[$k] = $data; } $topic['_key'] = uniqid(microtime()); return $this->returnHtml($this->registry->output->getTemplate('topic')->topicPreview($topic, $posts)); }