Advertisement
Flips

Forum.php

May 19th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.81 KB | None | 0 0
  1.  <?php
  2. error_reporting (E_ALL ^ E_NOTICE);
  3. ini_set('display_errors','On');
  4. ini_set('memory_limit', '-1');
  5. /**
  6.  * Controller for handling actions on forums.
  7.  *
  8.  * @package XenForo_Forum
  9.  */
  10. class XenForo_ControllerPublic_Forum extends XenForo_ControllerPublic_Abstract
  11. {
  12.         protected function _postDispatch($controllerResponse, $controllerName, $action)
  13.         {
  14.                 if (isset($controllerResponse->params['forum']))
  15.                 {
  16.                         $controllerResponse->containerParams['forum'] = $controllerResponse->params['forum'];
  17.                 }
  18.         }
  19.  
  20.         /**
  21.          * Displays the contents of a forum.
  22.          *
  23.          * @return XenForo_ControllerResponse_Abstract
  24.          */
  25.         public function actionIndex()
  26.         {
  27.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  28.                 $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
  29.                 if (!$forumId && !$forumName)
  30.                 {
  31.                         if ($this->_routeMatch->getResponseType() == 'rss')
  32.                         {
  33.                                 return $this->getGlobalForumRss();
  34.                         }
  35.                         else
  36.                         {
  37.                                 return $this->responseRedirect(
  38.                                         XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL_PERMANENT,
  39.                                         XenForo_Link::buildPublicLink('index')
  40.                                 );
  41.                         }
  42.                 }
  43.  
  44.                 $ftpHelper = $this->getHelper('ForumThreadPost');
  45.                 $forum = $this->getHelper('ForumThreadPost')->assertForumValidAndViewable(
  46.                         $forumId ? $forumId : $forumName,
  47.                         $this->_getForumFetchOptions()
  48.                 );
  49.                 $forumId = $forum['node_id'];
  50.  
  51.                 $visitor = XenForo_Visitor::getInstance();
  52.                 $threadModel = $this->_getThreadModel();
  53.                 $forumModel = $this->_getForumModel();
  54.  
  55.                 $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
  56.                 $threadsPerPage = XenForo_Application::get('options')->discussionsPerPage;
  57.  
  58.                 $this->canonicalizeRequestUrl(
  59.                         XenForo_Link::buildPublicLink('forums', $forum, array('page' => $page))
  60.                 );
  61.  
  62.                 list($defaultOrder, $defaultOrderDirection) = $this->_getDefaultThreadSort($forum);
  63.  
  64.                 $order = $this->_input->filterSingle('order', XenForo_Input::STRING, array('default' => $defaultOrder));
  65.                 $orderDirection = $this->_input->filterSingle('direction', XenForo_Input::STRING, array('default' => $defaultOrderDirection));
  66.  
  67.                 $displayConditions = $this->_getDisplayConditions($forum);
  68.  
  69.                 $fetchElements = $this->_getThreadFetchElements(
  70.                         $forum, $displayConditions,
  71.                         $threadsPerPage, $page, $order, $orderDirection
  72.                 );
  73.                 $threadFetchConditions = $fetchElements['conditions'];
  74.                 $threadFetchOptions = $fetchElements['options'] + array(
  75.                         'perPage' => $threadsPerPage,
  76.                         'page' => $page,
  77.                         'order' => $order,
  78.                         'orderDirection' => $orderDirection
  79.                 );
  80.                 unset($fetchElements);
  81.  
  82.                 $totalThreads = $threadModel->countThreadsInForum($forumId, $threadFetchConditions);
  83.  
  84.                 $this->canonicalizePageNumber($page, $threadsPerPage, $totalThreads, 'forums', $forum);
  85.  
  86.                 $threads = $threadModel->getThreadsInForum($forumId, $threadFetchConditions, $threadFetchOptions);
  87.  
  88.                 if ($page == 1)
  89.                 {
  90.                         $stickyThreadFetchOptions = $threadFetchOptions;
  91.                         unset($stickyThreadFetchOptions['perPage'], $stickyThreadFetchOptions['page']);
  92.  
  93.                         $stickyThreads = $threadModel->getStickyThreadsInForum($forumId, $threadFetchConditions, $stickyThreadFetchOptions);
  94.                 }
  95.                 else
  96.                 {
  97.                         $stickyThreads = array();
  98.                 }
  99.  
  100.                 // prepare all threads for the thread list
  101.                 $inlineModOptions = array();
  102.                 $permissions = $visitor->getNodePermissions($forumId);
  103.  
  104.                 foreach ($threads AS &$thread)
  105.                 {
  106.                         $threadModOptions = $threadModel->addInlineModOptionToThread($thread, $forum, $permissions);
  107.                         $inlineModOptions += $threadModOptions;
  108.  
  109.                         $thread = $threadModel->prepareThread($thread, $forum, $permissions);
  110.                 }
  111.                 foreach ($stickyThreads AS &$thread)
  112.                 {
  113.                         $threadModOptions = $threadModel->addInlineModOptionToThread($thread, $forum, $permissions);
  114.                         $inlineModOptions += $threadModOptions;
  115.  
  116.                         $thread = $threadModel->prepareThread($thread, $forum, $permissions);
  117.                 }
  118.                 unset($thread);
  119.  
  120.                 // if we've read everything on the first page of a normal sort order, probably need to mark as read
  121.                 if ($visitor['user_id'] && $page == 1 && !$displayConditions
  122.                         && $order == 'last_post_date' && $orderDirection == 'desc'
  123.                         && $forum['forum_read_date'] < $forum['last_post_date']
  124.                 )
  125.                 {
  126.                         $hasNew = false;
  127.                         foreach ($threads AS $thread)
  128.                         {
  129.                                 if ($thread['isNew'] && !$thread['isIgnored'])
  130.                                 {
  131.                                         $hasNew = true;
  132.                                         break;
  133.                                 }
  134.                         }
  135.  
  136.                         if (!$hasNew)
  137.                         {
  138.                                 // everything read, but forum not marked as read. Let's check.
  139.                                 $this->_getForumModel()->markForumReadIfNeeded($forum);
  140.                         }
  141.                 }
  142.  
  143.                 // get the ordering params set for the header links
  144.                 $orderParams = array();
  145.                 foreach ($this->_getThreadSortFields($forum) AS $field)
  146.                 {
  147.                         $orderParams[$field] = $displayConditions;
  148.                         $orderParams[$field]['order'] = ($field != $defaultOrder ? $field : false);
  149.                         if ($order == $field)
  150.                         {
  151.                                 $orderParams[$field]['direction'] = ($orderDirection == 'desc' ? 'asc' : 'desc');
  152.                         }
  153.                 }
  154.  
  155.                 $pageNavParams = $displayConditions;
  156.                 $pageNavParams['order'] = ($order != $defaultOrder ? $order : false);
  157.                 $pageNavParams['direction'] = ($orderDirection != $defaultOrderDirection ? $orderDirection : false);
  158.  
  159.                 $viewParams = array(
  160.                         'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay($forum, 0),
  161.                         'forum' => $forum,
  162.                         'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum, false),
  163.  
  164.                         'canPostThread' => $forumModel->canPostThreadInForum($forum),
  165.                         'canSearch' => $visitor->canSearch(),
  166.  
  167.                         'inlineModOptions' => $inlineModOptions,
  168.                         'threads' => $threads,
  169.                         'stickyThreads' => $stickyThreads,
  170.  
  171.                         'ignoredNames' => $this->_getIgnoredContentUserNames($threads) + $this->_getIgnoredContentUserNames($stickyThreads),
  172.  
  173.                         'order' => $order,
  174.                         'orderDirection' => $orderDirection,
  175.                         'orderParams' => $orderParams,
  176.                         'displayConditions' => $displayConditions,
  177.  
  178.                         'pageNavParams' => $pageNavParams,
  179.                         'page' => $page,
  180.                         'threadStartOffset' => ($page - 1) * $threadsPerPage + 1,
  181.                         'threadEndOffset' => ($page - 1) * $threadsPerPage + count($threads) ,
  182.                         'threadsPerPage' => $threadsPerPage,
  183.                         'totalThreads' => $totalThreads,
  184.  
  185.                         'showPostedNotice' => $this->_input->filterSingle('posted', XenForo_Input::UINT)
  186.                 );
  187.  
  188.                 return $this->responseView('XenForo_ViewPublic_Forum_View', 'forum_view', $viewParams);
  189.         }
  190.  
  191.         protected function _getForumFetchOptions()
  192.         {
  193.                 return array('readUserId' => XenForo_Visitor::getUserId());
  194.         }
  195.  
  196.         protected function _getDisplayConditions(array $forum)
  197.         {
  198.                 $displayConditions = array();
  199.  
  200.                 $prefixId = $this->_input->filterSingle('prefix_id', XenForo_Input::UINT);
  201.                 if ($prefixId)
  202.                 {
  203.                         $displayConditions['prefix_id'] = $prefixId;
  204.                 }
  205.  
  206.                 return $displayConditions;
  207.         }
  208.  
  209.         protected function _getThreadFetchElements(array $forum, array $displayConditions)
  210.         {
  211.                 $threadModel = $this->_getThreadModel();
  212.                 $visitor = XenForo_Visitor::getInstance();
  213.  
  214.                 $threadFetchConditions = $displayConditions + $threadModel->getPermissionBasedThreadFetchConditions($forum);
  215.  
  216.                 if ($this->_routeMatch->getResponseType() != 'rss')
  217.                 {
  218.                         $threadFetchConditions += array('sticky' => 0);
  219.                 }
  220.  
  221.                 $threadFetchOptions = array(
  222.                         'join' => XenForo_Model_Thread::FETCH_USER,
  223.                         'readUserId' => $visitor['user_id'],
  224.                         'postCountUserId' => $visitor['user_id'],
  225.                 );
  226.                 if (!empty($threadFetchConditions['deleted']))
  227.                 {
  228.                         $threadFetchOptions['join'] |= XenForo_Model_Thread::FETCH_DELETION_LOG;
  229.                 }
  230.  
  231.                 return array(
  232.                         'conditions' => $threadFetchConditions,
  233.                         'options' => $threadFetchOptions
  234.                 );
  235.         }
  236.  
  237.         protected function _getDefaultThreadSort(array $forum)
  238.         {
  239.                 return array('last_post_date',  'desc');
  240.         }
  241.  
  242.         protected function _getThreadSortFields(array $forum)
  243.         {
  244.                 return array('title', 'post_date', 'reply_count', 'view_count', 'last_post_date');
  245.         }
  246.  
  247.         /**
  248.          * Gets the data for the global forum RSS feed.
  249.          *
  250.          * @return XenForo_ControllerResponse_Abstract
  251.          */
  252.         public function getGlobalForumRss()
  253.         {
  254.                 $threadModel = $this->_getThreadModel();
  255.                 $visitor = XenForo_Visitor::getInstance();
  256.  
  257.                 $threadsPerPage = max(1, XenForo_Application::get('options')->discussionsPerPage);
  258.                 $autoReadDate = XenForo_Application::$time - (XenForo_Application::get('options')->readMarkingDataLifetime * 86400);
  259.  
  260.                 $threads = $threadModel->getThreads(
  261.                         array('find_new' => true, 'last_post_date' => array('>', $autoReadDate)),
  262.                         array(
  263.                                 'limit' => $threadsPerPage * 3, // to filter
  264.                                 'order' => 'last_post_date',
  265.                                 'join' =>
  266.                                         XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_FORUM_OPTIONS |
  267.                                         XenForo_Model_Thread::FETCH_USER,
  268.                                 'permissionCombinationId' => $visitor['permission_combination_id']
  269.                         )
  270.                 );
  271.                 foreach ($threads AS $key => $thread)
  272.                 {
  273.                         $thread['permissions'] = XenForo_Permission::unserializePermissions($thread['node_permission_cache']);
  274.  
  275.                         if (!$threadModel->canViewThreadAndContainer($thread, $thread, $null, $thread['permissions']))
  276.                         {
  277.                                 unset($threads[$key]);
  278.                         }
  279.                 }
  280.                 $threads = array_slice($threads, 0, $threadsPerPage, true);
  281.  
  282.                 $viewParams = array(
  283.                         'threads' => $threads
  284.                 );
  285.                 return $this->responseView('XenForo_ViewPublic_Forum_GlobalRss', '', $viewParams);
  286.         }
  287.  
  288.         /**
  289.          * Displays a form to create a new thread in this forum.
  290.          *
  291.          * @return XenForo_ControllerResponse_Abstract
  292.          */
  293.         public function actionCreateThread()
  294.         {
  295.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  296.                 $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
  297.  
  298.                 $ftpHelper = $this->getHelper('ForumThreadPost');
  299.                 $forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName);
  300.  
  301.                 $forumId = $forum['node_id'];
  302.  
  303.                 $this->_assertCanPostThreadInForum($forum);
  304.  
  305.                 $attachmentParams = $this->getModelFromCache('XenForo_Model_Forum')->getAttachmentParams($forum, array(
  306.                         'node_id' => $forum['node_id']
  307.                 ));
  308.  
  309.                 $maxResponses = XenForo_Application::get('options')->pollMaximumResponses;
  310.                 if ($maxResponses == 0)
  311.                 {
  312.                         $maxResponses = 10; // number to create for non-JS users
  313.                 }
  314.                 if ($maxResponses > 2)
  315.                 {
  316.                         $pollExtraArray = array_fill(0, $maxResponses - 2, true);
  317.                 }
  318.                 else
  319.                 {
  320.                         $pollExtraArray = array();
  321.                 }
  322.  
  323.                 $viewParams = array(
  324.                         'thread' => array(
  325.                                 'discussion_open' => 1,
  326.                                 'prefix_id' => $forum['default_prefix_id'],
  327.                         ),
  328.                         'forum' => $forum,
  329.                         'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum),
  330.  
  331.                         'prefixes' => $this->_getPrefixModel()->getUsablePrefixesInForums($forumId),
  332.  
  333.                         'attachmentParams' => $attachmentParams,
  334.  
  335.                         'watchState' => $this->_getThreadWatchModel()->getThreadWatchStateForVisitor(false),
  336.  
  337.                         'captcha' => XenForo_Captcha_Abstract::createDefault(),
  338.  
  339.                         'pollExtraArray' => $pollExtraArray,
  340.  
  341.                         'canLockUnlockThread' => $this->_getForumModel()->canLockUnlockThreadInForum($forum),
  342.                         'canStickUnstickThread' => $this->_getForumModel()->canStickUnstickThreadInForum($forum),
  343.  
  344.                         'attachmentConstraints' => $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentConstraints(),
  345.                 );
  346.                 return $this->responseView('XenForo_ViewPublic_Thread_Create', 'thread_create', $viewParams);
  347.         }
  348.  
  349.         /**
  350.          * Inserts a new thread into this forum.
  351.          *
  352.          * @return XenForo_ControllerResponse_Abstract
  353.          */
  354.         public function actionAddThread()
  355.         {
  356.                 $this->_assertPostOnly();
  357.  
  358.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  359.                 $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
  360.  
  361.                 $ftpHelper = $this->getHelper('ForumThreadPost');
  362.                 $forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName);
  363.  
  364.                 $forumId = $forum['node_id'];
  365.  
  366.                 $this->_assertCanPostThreadInForum($forum);
  367.  
  368.                 if (!XenForo_Captcha_Abstract::validateDefault($this->_input))
  369.                 {
  370.                         return $this->responseCaptchaFailed();
  371.                 }
  372.  
  373.                 $visitor = XenForo_Visitor::getInstance();
  374.  
  375.                 $input = $this->_input->filter(array(
  376.                         'title' => XenForo_Input::STRING,
  377.                         'prefix_id' => XenForo_Input::UINT,
  378.                         'attachment_hash' => XenForo_Input::STRING,
  379.  
  380.                         'watch_thread_state' => XenForo_Input::UINT,
  381.                         'watch_thread' => XenForo_Input::UINT,
  382.                         'watch_thread_email' => XenForo_Input::UINT,
  383.  
  384.                         '_set' => array(XenForo_Input::UINT, 'array' => true),
  385.                         'discussion_open' => XenForo_Input::UINT,
  386.                         'sticky' => XenForo_Input::UINT,
  387.  
  388.                         'poll' => XenForo_Input::ARRAY_SIMPLE, // filtered below
  389.                 ));
  390.                 $input['message'] = $this->getHelper('Editor')->getMessageText('message', $this->_input);
  391.                 $input['message'] = XenForo_Helper_String::autoLinkBbCode($input['message']);
  392.  
  393.                 if (!$this->_getPrefixModel()->verifyPrefixIsUsable($input['prefix_id'], $forumId))
  394.                 {
  395.                         $input['prefix_id'] = 0; // not usable, just blank it out
  396.                 }
  397.  
  398.                 $pollInputHandler = new XenForo_Input($input['poll']);
  399.                 $pollInput = $pollInputHandler->filter(array(
  400.                         'question' => XenForo_Input::STRING,
  401.                         'responses' => array(XenForo_Input::STRING, 'array' => true),
  402.                         'multiple' => XenForo_Input::UINT,
  403.                         'public_votes' => XenForo_Input::UINT,
  404.                         'close' => XenForo_Input::UINT,
  405.                         'close_length' => XenForo_Input::UNUM,
  406.                         'close_units' => XenForo_Input::STRING
  407.                 ));
  408.  
  409.                 // note: assumes that the message dw will pick up the username issues
  410.                 $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
  411.                 $writer->bulkSet(array(
  412.                         'user_id' => $visitor['user_id'],
  413.                         'username' => $visitor['username'],
  414.                         'title' => $input['title'],
  415.                         'prefix_id' => $input['prefix_id'],
  416.                         'node_id' => $forumId
  417.                 ));
  418.  
  419.                 // discussion state changes instead of first message state
  420.                 $writer->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $forum));
  421.  
  422.                 // discussion open state - moderator permission required
  423.                 if (!empty($input['_set']['discussion_open']) && $this->_getForumModel()->canLockUnlockThreadInForum($forum))
  424.                 {
  425.                         $writer->set('discussion_open', $input['discussion_open']);
  426.                 }
  427.  
  428.                 // discussion sticky state - moderator permission required
  429.                 if (!empty($input['_set']['sticky']) && $this->_getForumModel()->canStickUnstickThreadInForum($forum))
  430.                 {
  431.                         $writer->set('sticky', $input['sticky']);
  432.                 }
  433.  
  434.                 $postWriter = $writer->getFirstMessageDw();
  435.                 $postWriter->set('message', $input['message']);
  436.                 $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage::DATA_ATTACHMENT_HASH, $input['attachment_hash']);
  437.                 $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum);
  438.  
  439.                 $writer->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
  440.  
  441.                 $writer->preSave();
  442.  
  443.                 if ($pollInput['question'] !== '')
  444.                 {
  445.                         $pollWriter = XenForo_DataWriter::create('XenForo_DataWriter_Poll');
  446.                         $pollWriter->bulkSet(
  447.                                 XenForo_Application::arrayFilterKeys($pollInput, array('question', 'multiple', 'public_votes'))
  448.                         );
  449.                         $pollWriter->set('content_type', 'thread');
  450.                         $pollWriter->set('content_id', 0); // changed before saving
  451.                         if ($pollInput['close'])
  452.                         {
  453.                                 if (!$pollInput['close_length'])
  454.                                 {
  455.                                         $pollWriter->error(new XenForo_Phrase('please_enter_valid_length_of_time'));
  456.                                 }
  457.                                 else
  458.                                 {
  459.                                         $pollWriter->set('close_date', $pollWriter->preVerifyCloseDate(strtotime('+' . $pollInput['close_length'] . ' ' . $pollInput['close_units'])));
  460.                                 }
  461.                         }
  462.                         $pollWriter->addResponses($pollInput['responses']);
  463.                         $pollWriter->preSave();
  464.                         $writer->mergeErrors($pollWriter->getErrors());
  465.  
  466.                         $writer->set('discussion_type', 'poll', '', array('setAfterPreSave' => true));
  467.                 }
  468.                 else
  469.                 {
  470.                         $pollWriter = false;
  471.  
  472.                         foreach ($pollInput['responses'] AS $response)
  473.                         {
  474.                                 if ($response !== '')
  475.                                 {
  476.                                         $writer->error(new XenForo_Phrase('you_entered_poll_response_but_no_question'));
  477.                                         break;
  478.                                 }
  479.                         }
  480.                 }
  481.  
  482.                 // TODO: check for required prefix in this node
  483.  
  484.                 if (!$writer->hasErrors())
  485.                 {
  486.                         $this->assertNotFlooding('post');
  487.                 }
  488.  
  489.                 $writer->save();
  490.  
  491.                 $thread = $writer->getMergedData();
  492.  
  493.                 if ($pollWriter)
  494.                 {
  495.                         $pollWriter->set('content_id', $thread['thread_id'], '', array('setAfterPreSave' => true));
  496.                         $pollWriter->save();
  497.                 }
  498.  
  499.                 $this->_getThreadWatchModel()->setVisitorThreadWatchStateFromInput($thread['thread_id'], $input);
  500.  
  501.                 $this->_getThreadModel()->markThreadRead($thread, $forum, XenForo_Application::$time);
  502.  
  503.                 if (!$this->_getThreadModel()->canViewThread($thread, $forum))
  504.                 {
  505.                         $return = XenForo_Link::buildPublicLink('forums', $forum, array('posted' => 1));
  506.                 }
  507.                 else
  508.                 {
  509.                         $return = XenForo_Link::buildPublicLink('threads', $thread);
  510.                 }
  511.  
  512.                 return $this->responseRedirect(
  513.                         XenForo_ControllerResponse_Redirect::SUCCESS,
  514.                         $return,
  515.                         new XenForo_Phrase('your_thread_has_been_posted')
  516.                 );
  517.         }
  518.  
  519.         /**
  520.          * Shows a preview of the thread creation.
  521.          *
  522.          * @return XenForo_ControllerResponse_Abstract
  523.          */
  524.         public function actionCreateThreadPreview()
  525.         {
  526.                 $this->_assertPostOnly();
  527.  
  528.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  529.                 $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
  530.  
  531.                 $ftpHelper = $this->getHelper('ForumThreadPost');
  532.                 $forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName);
  533.  
  534.                 $forumId = $forum['node_id'];
  535.  
  536.                 $this->_assertCanPostThreadInForum($forum);
  537.  
  538.                 $message = $this->getHelper('Editor')->getMessageText('message', $this->_input);
  539.                 $message = XenForo_Helper_String::autoLinkBbCode($message);
  540.  
  541.                 $viewParams = array(
  542.                         'forum' => $forum,
  543.                         'message' => $message
  544.                 );
  545.  
  546.                 return $this->responseView('XenForo_ViewPublic_Thread_CreatePreview', 'thread_create_preview', $viewParams);
  547.         }
  548.  
  549.         public function actionMarkRead()
  550.         {
  551.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  552.                 $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
  553.  
  554.                 $visitor = XenForo_Visitor::getInstance();
  555.  
  556.                 $markDate = $this->_input->filterSingle('date', XenForo_Input::UINT);
  557.                 if (!$markDate)
  558.                 {
  559.                         $markDate = XenForo_Application::$time;
  560.                 }
  561.  
  562.                 $forumModel = $this->_getForumModel();
  563.  
  564.                 if ($forumId || $forumName)
  565.                 {
  566.                         // mark individual forum read
  567.                         $ftpHelper = $this->getHelper('ForumThreadPost');
  568.                         $forum = $ftpHelper->assertForumValidAndViewable(
  569.                                 $forumId ? $forumId : $forumName, array('readUserId' => $visitor['user_id'])
  570.                         );
  571.  
  572.                         $forumId = $forum['node_id'];
  573.  
  574.                         if ($this->isConfirmedPost())
  575.                         {
  576.                                 $forumModel->markForumTreeRead($forum, $markDate);
  577.  
  578.                                 return $this->responseRedirect(
  579.                                         XenForo_ControllerResponse_Redirect::SUCCESS,
  580.                                         XenForo_Link::buildPublicLink('forums', $forum),
  581.                                         new XenForo_Phrase('forum_x_marked_as_read', array('forum' => $forum['title']))
  582.                                 );
  583.                         }
  584.                         else
  585.                         {
  586.                                 $viewParams = array(
  587.                                         'forum' => $forum,
  588.                                         'markDate' => $markDate
  589.                                 );
  590.  
  591.                                 return $this->responseView('XenForo_ViewPublic_Forum_MarkRead', 'forum_mark_read', $viewParams);
  592.                         }
  593.                 }
  594.                 else
  595.                 {
  596.                         // mark all forums read
  597.                         if ($this->isConfirmedPost())
  598.                         {
  599.                                 $forumModel->markForumTreeRead(null, $markDate);
  600.  
  601.                                 return $this->responseRedirect(
  602.                                         XenForo_ControllerResponse_Redirect::SUCCESS,
  603.                                         XenForo_Link::buildPublicLink('index'),
  604.                                         new XenForo_Phrase('all_forums_marked_as_read')
  605.                                 );
  606.                         }
  607.                         else
  608.                         {
  609.                                 $viewParams = array(
  610.                                         'forum' => false,
  611.                                         'markDate' => $markDate
  612.                                 );
  613.  
  614.                                 return $this->responseView('XenForo_ViewPublic_Forum_MarkRead', 'forum_mark_read', $viewParams);
  615.                         }
  616.                 }
  617.         }
  618.  
  619.         /**
  620.          * Fetches a grouped list of all prefixes available to the specified forum
  621.          *
  622.          * @return XenForo_ControllerResponse_Abstract
  623.          */
  624.         public function actionPrefixes()
  625.         {
  626.                 $this->_assertPostOnly();
  627.  
  628.                 $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  629.                 $forum = $this->getHelper('ForumThreadPost')->assertForumValidAndViewable($forumId);
  630.  
  631.                 $viewParams = array(
  632.                         'forum' => $forum,
  633.                         'prefixGroups' => $this->_getPrefixModel()->getUsablePrefixesInForums($forum['node_id']),
  634.                 );
  635.  
  636.                 return $this->responseView('XenForo_ViewPublic_Forum_Prefixes', '', $viewParams);
  637.         }
  638.  
  639.         /**
  640.          * Session activity details.
  641.          * @see XenForo_Controller::getSessionActivityDetailsForList()
  642.          */
  643.         public static function getSessionActivityDetailsForList(array $activities)
  644.         {
  645.                 $forumIds = array();
  646.                 $nodeNames = array();
  647.                 foreach ($activities AS $activity)
  648.                 {
  649.                         if (!empty($activity['params']['node_id']))
  650.                         {
  651.                                 $forumIds[$activity['params']['node_id']] = intval($activity['params']['node_id']);
  652.                         }
  653.                         else if (!empty($activity['params']['node_name']))
  654.                         {
  655.                                 $nodeNames[$activity['params']['node_name']] = $activity['params']['node_name'];
  656.                         }
  657.                 }
  658.  
  659.                 if ($nodeNames)
  660.                 {
  661.                         $nodeNames = XenForo_Model::create('XenForo_Model_Node')->getNodeIdsFromNames($nodeNames);
  662.  
  663.                         foreach ($nodeNames AS $nodeName => $nodeId)
  664.                         {
  665.                                 $forumIds[$nodeName] = $nodeId;
  666.                         }
  667.                 }
  668.  
  669.                 $forumData = array();
  670.  
  671.                 if ($forumIds)
  672.                 {
  673.                         /* @var $forumModel XenForo_Model_Forum */
  674.                         $forumModel = XenForo_Model::create('XenForo_Model_Forum');
  675.  
  676.                         $visitor = XenForo_Visitor::getInstance();
  677.                         $permissionCombinationId = $visitor['permission_combination_id'];
  678.  
  679.                         $forums = $forumModel->getForumsByIds($forumIds, array(
  680.                                 'permissionCombinationId' => $permissionCombinationId
  681.                         ));
  682.                         foreach ($forums AS $forum)
  683.                         {
  684.                                 $visitor->setNodePermissions($forum['node_id'], $forum['node_permission_cache']);
  685.                                 if ($forumModel->canViewForum($forum))
  686.                                 {
  687.                                         $forumData[$forum['node_id']] = array(
  688.                                                 'title' => $forum['title'],
  689.                                                 'url' => XenForo_Link::buildPublicLink('forums', $forum)
  690.                                         );
  691.                                 }
  692.                         }
  693.                 }
  694.  
  695.                 $output = array();
  696.                 foreach ($activities AS $key => $activity)
  697.                 {
  698.                         $forum = false;
  699.                         if (!empty($activity['params']['node_id']))
  700.                         {
  701.                                 $nodeId = $activity['params']['node_id'];
  702.                                 if (isset($forumData[$nodeId]))
  703.                                 {
  704.                                         $forum = $forumData[$nodeId];
  705.                                 }
  706.                         }
  707.                         else if (!empty($activity['params']['node_name']))
  708.                         {
  709.                                 $nodeName = $activity['params']['node_name'];
  710.                                 if (isset($nodeNames[$nodeName]))
  711.                                 {
  712.                                         $nodeId = $nodeNames[$nodeName];
  713.                                         if (isset($forumData[$nodeId]))
  714.                                         {
  715.                                                 $forum = $forumData[$nodeId];
  716.                                         }
  717.                                 }
  718.                         }
  719.  
  720.                         if ($forum)
  721.                         {
  722.                                 $output[$key] = array(
  723.                                         new XenForo_Phrase('viewing_forum'),
  724.                                         $forum['title'],
  725.                                         $forum['url'],
  726.                                         false
  727.                                 );
  728.                         }
  729.                         else
  730.                         {
  731.                                 $output[$key] = new XenForo_Phrase('viewing_forum');
  732.                         }
  733.                 }
  734.  
  735.                 return $output;
  736.         }
  737.  
  738.         /**
  739.          * Asserts that the currently browsing user can post a thread in
  740.          * the specified forum.
  741.          *
  742.          * @param array $forum
  743.          */
  744.         protected function _assertCanPostThreadInForum(array $forum)
  745.         {
  746.                 if (!$this->_getForumModel()->canPostThreadInForum($forum, $errorPhraseKey))
  747.                 {
  748.                         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  749.                 }
  750.         }
  751.  
  752.         /**
  753.          * @return XenForo_Model_Forum
  754.          */
  755.         protected function _getForumModel()
  756.         {
  757.                 return $this->getModelFromCache('XenForo_Model_Forum');
  758.         }
  759.  
  760.         /**
  761.          * @return XenForo_Model_Node
  762.          */
  763.         protected function _getNodeModel()
  764.         {
  765.                 return $this->getModelFromCache('XenForo_Model_Node');
  766.         }
  767.  
  768.         /**
  769.          * @return XenForo_Model_Thread
  770.          */
  771.         protected function _getThreadModel()
  772.         {
  773.                 return $this->getModelFromCache('XenForo_Model_Thread');
  774.         }
  775.  
  776.         /**
  777.          * @return XenForo_Model_ThreadWatch
  778.          */
  779.         protected function _getThreadWatchModel()
  780.         {
  781.                 return $this->getModelFromCache('XenForo_Model_ThreadWatch');
  782.         }
  783.  
  784.         /**
  785.          * @return XenForo_Model_ThreadPrefix
  786.          */
  787.         protected function _getPrefixModel()
  788.         {
  789.                 return $this->getModelFromCache('XenForo_Model_ThreadPrefix');
  790.         }
  791. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement