Esempio n. 1
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $config = DiscussHelper::getConfig();
     // Sorting and filters.
     $sort = JRequest::getString('sort', DiscussHelper::getDefaultRepliesSorting());
     $filteractive = JRequest::getString('filter', 'allposts');
     $id = JRequest::getInt('id');
     $acl = DiscussHelper::getHelper('ACL');
     // Add noindex for print view by default.
     if (JRequest::getInt('print') == 1) {
         $doc->setMetadata('robots', 'noindex,follow');
     }
     // Get current logged in user.
     $my = JFactory::getUser();
     // Determine if the logged in user is an admin.
     $isAdmin = DiscussHelper::isSiteAdmin();
     // Load the post table out.
     $post = DiscussHelper::getTable('Post');
     $state = $post->load($id);
     // Need raw content for later use
     $post->content_raw = $post->content;
     // If id is not found, we need to redirect gracefully.
     if (!$state || !$post->published || !$id) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
     }
     if ($post->private && $my->id != $post->user_id && !$isAdmin && !DiscussHelper::isModerator($post->category_id, $my->id)) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
     }
     // Check whether this is a valid discussion
     if ($post->parent_id != 0 || $post->published == DISCUSS_ID_PENDING && (!$isAdmin && $post->user_id != $my->id)) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
     }
     // check the discussion is under moderation
     if ($post->published == 4 && !DiscussHelper::isModerator($post->category_id, $my->id) && !$isAdmin) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOTICE_POST_SUBMITTED_UNDER_MODERATION'), 'error');
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
     }
     // Load the category.
     $category = DiscussHelper::getTable('Category');
     $category->load((int) $post->category_id);
     if ($post->category_id && !$category->canAccess()) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_SYSTEM_POST_NOT_FOUND'));
     }
     // Add pathway for category here.
     DiscussHelper::getHelper('Pathway')->setCategoryPathway($category);
     // Set breadcrumbs for this discussion.
     $this->setPathway($this->escape($post->title));
     // Mark as viewed for notifications.
     $this->logView();
     // Update hit count for this discussion.
     $post->hit();
     // Set page headers
     $this->setPageHeaders($post);
     // Before sending the title and content to be parsed, we need to store this temporarily in case it needs to be accessed.
     $post->title_clear = $post->title;
     // Filter badwords
     $post->title = DiscussHelper::wordFilter($post->title);
     $post->content = DiscussHelper::wordFilter($post->content);
     // Get the tags for this discussion
     $postsTagsModel = $this->getModel('PostsTags');
     $tags = $postsTagsModel->getPostTags($id);
     // Get adsense codes here.
     $adsense = DiscussHelper::getAdsense();
     $postsModel = DiscussHelper::getModel('Posts');
     // Get the answer for this discussion.
     $answer = $postsModel->getAcceptedReply($post->id);
     // Format the answer object.
     if ($answer) {
         $answer = DiscussHelper::formatReplies($answer, $category);
         $answer = $answer[0];
     }
     // Get a list of replies for this post.
     $data = $this->getReplies($category, $post, $sort, $answer);
     $replies = $data->replies;
     $totalReplies = $data->total;
     $hasMoreReplies = $data->more;
     $readMoreURI = $data->readmore;
     // Get comments for the post
     $commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
     $post->comments = false;
     if ($config->get('main_commentpost')) {
         $comments = $post->getComments($commentLimit);
         $post->comments = DiscussHelper::formatComments($comments);
     }
     // get reply comments count
     $post->commentsCount = $post->getTotalComments();
     // Get the post access object here.
     $access = $post->getAccess($category);
     $post->access = $access;
     // Add custom values.
     $postOwner = $post->getOwner();
     $profileTable = DiscussHelper::getTable('Profile');
     if ($postOwner->id) {
         $profileTable->load($postOwner->id);
     }
     $post->user = $profileTable;
     // update user's post read flag
     if ($my->id != 0) {
         $profile = DiscussHelper::getTable('Profile');
         $profile->load($my->id);
         $profile->read($post->id);
     }
     $badgesTable = DiscussHelper::getTable('Profile');
     $badgesTable->load($post->user->id);
     $postBadges = $badgesTable->getBadges();
     // Get Likes model here.
     $post->likesAuthor = DiscussHelper::getHelper('Likes')->getLikesHTML($post->id, $my->id, 'post');
     $post->isVoted = DiscussHelper::getHelper('Post')->isVoted($post->id);
     // Format the content.
     $post->content = DiscussHelper::formatContent($post);
     // Test if trigger is necessary here.
     if ($config->get('main_content_trigger_posts')) {
         // Move aside the original content_raw
         $content_raw_temp = $post->content_raw;
         // Add the br tags in the content, we do it here so that the content triggers's javascript will not get added with br tags
         $post->content_raw = DiscussHelper::formatContent($post);
         $post->event = new stdClass();
         // Triger onContentPrepare here. Since it doesn't have any return value, just ignore this.
         DiscussHelper::triggerPlugins('content', 'onContentPrepare', $post);
         $post->event->afterDisplayTtle = DiscussHelper::triggerPlugins('content', 'onContentAfterTitle', $post, true);
         $post->event->beforeDisplayContent = DiscussHelper::triggerPlugins('content', 'onContentBeforeDisplay', $post, true);
         $post->event->afterDisplayContent = DiscussHelper::triggerPlugins('content', 'onContentAfterDisplay', $post, true);
         // Assign the processed content back
         $post->content = $post->content_raw;
         // Move back the original content_raw
         $post->content_raw = $content_raw_temp;
     }
     $theme = new DiscussThemes();
     // Get list of moderators from the site.
     $moderators = array();
     $composer = new DiscussComposer("replying", $post);
     // Set the discussion object.
     $theme->set('post', $post);
     $theme->set('composer', $composer);
     $theme->set('replies', $replies);
     $theme->set('answer', $answer);
     $theme->set('sort', $sort);
     $theme->set('adsense', $adsense);
     $theme->set('tags', $tags);
     $theme->set('totalReplies', $totalReplies);
     $theme->set('hasMoreReplies', $hasMoreReplies);
     $theme->set('access', $access);
     $theme->set('category', $category);
     $theme->set('moderators', $moderators);
     $theme->set('readMoreURI', $readMoreURI);
     $theme->set('postBadges', $postBadges);
     echo $theme->fetch('post.php');
 }
Esempio n. 2
0
 /**
  * Get replies based on pagination load more
  *
  * @since   3.0
  * @access  public
  * @param   null
  * @author  Jason Rey <*****@*****.**>
  */
 public function getReplies()
 {
     $theme = new DiscussThemes();
     $ajax = DiscussHelper::getHelper('Ajax');
     $model = DiscussHelper::getModel('Posts');
     $config = DiscussHelper::getConfig();
     $id = JRequest::getInt('id', 0);
     $sort = JRequest::getString('sort', DiscussHelper::getDefaultRepliesSorting());
     $start = JRequest::getInt('start', 0);
     $total = $model->getTotalReplies($id);
     if ($start >= $total) {
         return $ajax->reject();
     }
     $replies = $model->getReplies($id, $sort, $start, $config->get('layout_replies_list_limit'));
     if (empty($replies)) {
         return $ajax->reject();
     }
     $count = count($replies);
     $nextCycle = $start + $count < $total;
     // Load the category
     $post = DiscussHelper::getTable('Posts');
     $post->load($id);
     $category = DiscussHelper::getTable('Category');
     $category->load((int) $post->category_id);
     $replies = DiscussHelper::formatReplies($replies, $category);
     $html = '';
     foreach ($replies as $reply) {
         $theme->set('category', $category);
         $theme->set('question', $post);
         $theme->set('post', $reply);
         $html .= '<li>' . $theme->fetch('post.reply.item.php') . '</li>';
     }
     return $ajax->resolve($html, $nextCycle);
 }