Ejemplo n.º 1
0
 public function process()
 {
     if ($this->request()->segment(2) == 'search') {
         return false;
     }
     $title = '';
     $threads = [];
     $type = 'threads';
     if (Phpfox_Module::instance()->getFullControllerName() == 'forum.forum') {
         $title = 'Recent Posts';
         $threads = Forum_Service_Post_Post::instance()->getRecentForForum($this->request()->segment(2));
         $type = 'posts';
     } else {
         $title = 'Recent Discussions';
         $ids = [];
         $forums = Forum_Service_Forum::instance()->getForums();
         foreach ($forums as $forum) {
             $ids[] = $forum['forum_id'];
             $childs = Forum_Service_Forum::instance()->id($forum['forum_id'])->getChildren();
             if ($childs) {
                 foreach ($childs as $id) {
                     $ids[] = $id;
                 }
             }
         }
         $cond[] = 'ft.forum_id IN(' . implode(',', $ids) . ') AND ft.group_id = 0 AND ft.view_id >= 0';
         list($cnt, $threads) = Forum_Service_Thread_Thread::instance()->get($cond, 'ft.time_update DESC', 0, 20);
     }
     $this->template()->assign(['sHeader' => $title, 'threads' => $threads, 'type' => $type]);
     return 'block';
 }
Ejemplo n.º 2
0
 public function process()
 {
     header('Content-type: application/javascript');
     $ids = [];
     $forums = Forum_Service_Forum::instance()->getForums();
     foreach ($forums as $forum) {
         $ids[] = $forum['forum_id'];
         $childs = Forum_Service_Forum::instance()->id($forum['forum_id'])->getChildren();
         if ($childs) {
             foreach ($childs as $id) {
                 $ids[] = $id;
             }
         }
     }
     $cond[] = 'ft.forum_id IN(' . implode(',', $ids) . ') AND ft.group_id = 0 AND ft.view_id >= 0';
     list($cnt, $threads) = Forum_Service_Thread_Thread::instance()->get($cond, 'ft.time_update DESC', 0, 20);
     $json = [];
     foreach ($threads as $thread) {
         $json[] = (object) ['thread_id' => $thread['thread_id'], 'title' => $thread['title'], 'permalink' => Phpfox::permalink('forum.thread', $thread['thread_id'], $thread['title']), 'user' => htmlspecialchars($thread['full_name']), 'created' => Phpfox::getLib('date')->convertTime($thread['time_stamp'])];
     }
     echo ';function __Threads(callback) { var threads = ' . json_encode($json) . '; if (typeof(callback) == \'function\') { callback(threads); } };';
     exit;
 }
Ejemplo n.º 3
0
 /**
  * Controller
  */
 public function process()
 {
     Phpfox::isUser(true);
     $bCanEditPersonalData = true;
     $aCallback = false;
     if ($this->request()->get('module')) {
         $this->template()->assign(array('bIsGroup' => '1'));
     }
     if (($sModule = $this->request()->get('module')) && Phpfox::isModule($sModule) && ($iItemId = $this->request()->getInt('item')) && Phpfox::hasCallback($sModule, 'addForum')) {
         $aCallback = Phpfox::callback($sModule . '.addForum', $iItemId);
         $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.pages'), $this->url()->makeUrl('pages'));
         $this->template()->setBreadcrumb($aCallback['title'], $aCallback['url_home']);
         $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.discussions'), $aCallback['url_home'] . 'forum/');
         if ($sModule == 'pages' && !Phpfox::getService('pages')->hasPerm($iItemId, 'forum.share_forum')) {
             return Phpfox_Error::display(Phpfox::getPhrase('forum.unable_to_view_this_item_due_to_privacy_settings'));
         }
     } else {
         $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.forum'), $this->url()->makeUrl('forum'));
     }
     $iId = $this->request()->getInt('id');
     $aAccess = Forum_Service_Forum::instance()->getUserGroupAccess($iId, Phpfox::getUserBy('user_group_id'));
     if ($aAccess['can_view_thread_content']['value'] != true) {
         return Phpfox_Error::display(Phpfox::getPhrase('forum.unable_to_view_this_item_due_to_privacy_settings'));
     }
     if (Phpfox::isModule('poll')) {
         $this->template()->setHeader('cache', array('poll.js' => 'module_poll', '<script type="text/javascript">$Behavior.loadSortableAnswers = function() {$(".sortable").sortable({placeholder: "placeholder", axis: "y"});}</script>'));
     }
     $this->template()->setEditor()->setTitle(Phpfox::getPhrase('forum.forum'))->setHeader('cache', array('switch_legend.js' => 'static_script', 'switch_menu.js' => 'static_script', 'pager.css' => 'style_css', 'forum.css' => 'style_css'));
     $bIsEdit = false;
     if ($this->request()->get('req3') == 'thread') {
         if ($iEditId = $this->request()->getInt('edit')) {
             $aThread = Forum_Service_Thread_Thread::instance()->getForEdit($iEditId);
             if (!isset($aThread['thread_id'])) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_thread'));
             }
             if (Phpfox::getUserParam('forum.can_edit_own_post') && $aThread['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_edit_other_posts') || Phpfox::getService('forum.moderate')->hasAccess($aThread['forum_id'], 'edit_post')) {
                 $bIsEdit = true;
                 if (Phpfox::getUserParam('forum.can_edit_other_posts') && Phpfox::getUserId() != $aThread['user_id']) {
                     $bCanEditPersonalData = false;
                 }
                 $iId = $aThread['forum_id'];
                 if (Phpfox::isModule('tag')) {
                     $aThread['tag_list'] = Tag_Service_Tag::instance()->getForEdit('forum', $aThread['thread_id']);
                 }
                 $this->template()->assign(array('aForms' => $aThread, 'iEditId' => $aThread['thread_id']));
             } else {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_edit_this_thread'));
             }
         }
         if ($aCallback === false) {
             $aForum = Phpfox::getService('forum')->id($iId)->getForum();
             if (!isset($aForum['forum_id'])) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_forum'));
             }
             if ($aForum['is_closed']) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.forum_is_closed'));
             }
         }
         if (!$bIsEdit) {
             $bPass = false;
             if (Phpfox::getUserParam('forum.can_add_new_thread') || Phpfox::getService('forum.moderate')->hasAccess($aForum['forum_id'], 'add_thread')) {
                 $bPass = true;
             }
             if ($bPass === false) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_reply_to_this_thread'));
             }
         }
         if (!Forum_Service_Forum::instance()->hasAccess($iId, 'can_start_thread')) {
             return Phpfox_Error::display('You are unable to create a new post in this forum.');
         }
         $aValidation = array('title' => Phpfox::getPhrase('forum.provide_a_title_for_your_thread'), 'text' => Phpfox::getPhrase('forum.provide_some_text'));
         if (Phpfox::isModule('captcha') && Phpfox::getUserParam('forum.enable_captcha_on_posting')) {
             $aValidation['image_verification'] = Phpfox::getPhrase('captcha.complete_captcha_challenge');
         }
         $oValid = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation));
         $bPosted = false;
         if ($aVals = $this->request()->getArray('val')) {
             if (isset($aVals['type_id']) && $aVals['type_id'] == 'announcement') {
                 $bPosted = true;
             }
             if ($oValid->isValid($aVals)) {
                 if ($bIsEdit) {
                     $aVals['post_id'] = $aThread['start_id'];
                     $aVals['was_announcement'] = $aThread['is_announcement'];
                     $aVals['forum_id'] = $aThread['forum_id'];
                     if (Phpfox::getService('forum.thread.process')->update($aThread['thread_id'], $aThread['user_id'], $aVals)) {
                         $this->url()->permalink('forum.thread', $aThread['thread_id'], Phpfox::getLib('parse.input')->clean($aVals['title'], 255), true, Phpfox::getPhrase('forum.thread_successfully_updated'));
                     }
                 } else {
                     if (($iFlood = Phpfox::getUserParam('forum.forum_thread_flood_control')) !== 0) {
                         $aFlood = array('action' => 'last_post', 'params' => array('field' => 'time_stamp', 'table' => Phpfox::getT('forum_thread'), 'condition' => 'user_id = ' . Phpfox::getUserId(), 'time_stamp' => $iFlood * 60));
                         // actually check if flooding
                         if (Phpfox::getLib('spam')->check($aFlood)) {
                             Phpfox_Error::set(Phpfox::getPhrase('forum.posting_a_new_thread_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime());
                         }
                     }
                     if (Phpfox_Error::isPassed() && ($iId = Phpfox::getService('forum.thread.process')->add($aVals, $aCallback))) {
                         $this->url()->permalink('forum.thread', $iId, Phpfox::getLib('parse.input')->clean($aVals['title'], 255), true);
                     }
                 }
             }
         }
         if ($aCallback === false) {
             $this->template()->setBreadcrumb($aForum['breadcrumb'])->setBreadcrumb($aForum['name'], $this->url()->permalink('forum', $aForum['forum_id'], $aForum['name']))->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_thread') . ': ' . $aThread['title'] : Phpfox::getPhrase('forum.post_new_thread'), $this->url()->makeUrl('forum.post.thread'), true);
         } else {
             $this->template()->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_thread') . ': ' . $aThread['title'] : Phpfox::getPhrase('forum.post_new_thread'), $this->url()->makeUrl('forum.post.thread'), true);
         }
         $this->template()->assign(array('iForumId' => $iId, 'iActualForumId' => $iId, 'sFormLink' => $aCallback == false ? $this->url()->makeUrl('forum.post.thread', array('id' => $iId)) : $this->url()->makeUrl('forum.post.thread', array('module' => $sModule, 'item' => $iItemId)), 'sCreateJs' => $oValid->createJS(), 'sGetJsForm' => $oValid->getJsForm(), 'sForumParents' => $aCallback === false ? Phpfox::getUserParam('forum.can_post_announcement') || Phpfox::getService('forum.moderate')->hasAccess($aForum['forum_id'], 'post_announcement') ? Phpfox::getService('forum')->active($aForum['forum_id'])->getJumpTool(true) : '' : '', 'bPosted' => $bPosted, 'sReturnLink' => $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aForum['name_url'] . '-' . $aForum['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']) : '', 'bIsEdit' => $bIsEdit, 'aCallback' => $aCallback));
         if (Phpfox::getUserParam('forum.can_add_forum_attachments')) {
             $this->setParam('attachment_share', array('type' => 'forum', 'id' => 'js_forum_form'));
         }
     } else {
         if ($iEditId = $this->request()->getInt('edit')) {
             $aPost = Phpfox::getService('forum.post')->getForEdit($iEditId);
             if (!isset($aPost['post_id'])) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_post'));
             }
             $bCanEditPost = Phpfox::getUserParam('forum.can_edit_own_post') && $aPost['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_edit_other_posts') || Phpfox::getService('forum.moderate')->hasAccess($aPost['forum_id'], 'edit_post');
             if ($bCanEditPost) {
                 $bIsEdit = true;
                 if (Phpfox::getUserParam('forum.can_edit_other_posts') && Phpfox::getUserId() != $aPost['user_id']) {
                     $bCanEditPersonalData = false;
                 }
                 $iId = $aPost['thread_id'];
                 $this->template()->assign(array('aForms' => $aPost, 'iEditId' => $aPost['post_id']));
                 if (PHPFOX_IS_AJAX) {
                     Phpfox_Ajax::instance()->setTitle(Phpfox::getPhrase('forum.editing_post') . ': ' . (empty($aPost['title']) ? '#' . $aPost['post_id'] : Phpfox::getLib('parse.output')->shorten($aPost['title'], 80, '...')));
                 }
             } else {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_edit_this_thread'));
             }
         }
         $aThread = Forum_Service_Thread_Thread::instance()->getActualThread($iId, $aCallback);
         if (!isset($aThread['thread_id'])) {
             return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_thread'));
         }
         if ($aThread['is_closed'] && (isset($bCanEditPost) && !$bCanEditPost || !isset($bCanEditPost))) {
             return Phpfox_Error::display(Phpfox::getPhrase('forum.thread_is_closed'));
         }
         if ($aCallback === false && $aThread['forum_is_closed']) {
             return Phpfox_Error::display(Phpfox::getPhrase('forum.forum_is_closed'));
         }
         if (!$iEditId && $aThread['is_announcement']) {
             return Phpfox_Error::display(Phpfox::getPhrase('forum.thread_is_an_announcement_not_allowed_to_leave_a_reply'));
         }
         if (!$bIsEdit) {
             $bPass = false;
             if (Phpfox::getUserParam('forum.can_reply_to_own_thread') && $aThread['user_id'] == Phpfox::getUserId() || Phpfox::getUserParam('forum.can_reply_on_other_threads') || Phpfox::getService('forum.moderate')->hasAccess($aThread['forum_id'], 'can_reply')) {
                 $bPass = true;
             }
             if ($bPass === false) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.insufficient_permission_to_reply_to_this_thread'));
             }
         }
         $sExtraText = '';
         if ($sSavedText = $this->request()->get('save_text')) {
             $sExtraText .= Phpfox::getLib('parse.output')->clean($sSavedText);
         }
         if (Phpfox::getUserParam('forum.can_multi_quote_forum') && (($iQuote = $this->request()->getInt('quote')) || ($sCookie = Phpfox::getCookie('forum_quote')) && !empty($sCookie))) {
             $sCookie = Phpfox::getCookie('forum_quote');
             if (!empty($sCookie)) {
                 $iQuote = $sCookie . $iQuote;
             }
             $sExtraText .= Phpfox::getService('forum.post')->getQuotes($aThread['thread_id'], $iQuote);
         }
         if (($iQuoteId = $this->request()->getInt('quote')) && ($aQuotePost = Phpfox::getService('forum.post')->getForEdit($iQuoteId))) {
             Phpfox_Ajax::instance()->setTitle(Phpfox::getPhrase('forum.replying_to_a_post_by_full_name', array('full_name' => Phpfox::getLib('parse.output')->shorten($aQuotePost['full_name'], 80, '...'))));
         }
         $aSubForms = array();
         if (isset($aThread['is_subscribed'])) {
             $aSubForms['is_subscribed'] = $aThread['is_subscribed'];
         }
         if (!empty($sExtraText)) {
             $aSubForms['text'] = $sExtraText;
         }
         if (isset($bCanEditPost) && $bCanEditPost) {
             $aSubForms = array_merge($aSubForms, $aPost);
         }
         $this->template()->assign('aForms', $aSubForms);
         $aValidation = array('text' => Phpfox::getPhrase('forum.provide_some_text'));
         if (Phpfox::isModule('captcha') && Phpfox::getUserParam('forum.enable_captcha_on_posting')) {
             $aValidation['image_verification'] = Phpfox::getPhrase('captcha.complete_captcha_challenge');
         }
         $oValid = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation));
         $aForum = Phpfox::getService('forum')->id($aThread['forum_id'])->getForum();
         if ($aVals = $this->request()->getArray('val')) {
             $aVals['forum_id'] = $aThread['forum_id'];
             if ($oValid->isValid($aVals)) {
                 Phpfox::setCookie('forum_quote', '', -1);
                 if ($bIsEdit) {
                     if (Phpfox::getService('forum.post.process')->update($aPost['post_id'], $aPost['user_id'], $aVals)) {
                         $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, null, array('post' => $aPost['post_id']));
                     }
                 } else {
                     if (($iFlood = Phpfox::getUserParam('forum.forum_post_flood_control')) !== 0) {
                         $aFlood = array('action' => 'last_post', 'params' => array('field' => 'time_stamp', 'table' => Phpfox::getT('forum_post'), 'condition' => 'user_id = ' . Phpfox::getUserId(), 'time_stamp' => $iFlood * 60));
                         // actually check if flooding
                         if (Phpfox::getLib('spam')->check($aFlood)) {
                             Phpfox_Error::set(Phpfox::getPhrase('forum.posting_a_reply_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime());
                         }
                     }
                     if (Phpfox_Error::isPassed()) {
                         if ($iId = Phpfox::getService('forum.post.process')->add($aVals, $aCallback)) {
                             $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, null, array('post' => $iId));
                         } else {
                             if (Phpfox::getUserParam('forum.approve_forum_post')) {
                                 $this->url()->permalink('forum', $aThread['thread_id'], $aThread['title'], true, Phpfox::getPhrase('forum.your_post_has_successfully_been_added_however_it_is_pending_an_admins_approval_before_it_can_be_displayed_publicly'), array('post' => $iId));
                             }
                         }
                     }
                 }
             }
         }
         if ($aCallback === false) {
             $this->template()->setBreadcrumb($aForum['breadcrumb'])->setBreadcrumb($aForum['name'], $this->url()->makeUrl('forum', $aForum['name_url'] . '-' . $aForum['forum_id']));
         } else {
         }
         $this->template()->setBreadcrumb($aThread['title'], $aCallback === false ? $this->url()->makeUrl('forum', array($aForum['name_url'] . '-' . $aForum['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']))->setBreadcrumb($bIsEdit ? Phpfox::getPhrase('forum.editing_post') . ': ' . (empty($aPost['title']) ? '#' . $aPost['post_id'] : $aPost['title']) : Phpfox::getPhrase('forum.post_new_reply'), $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'], 'post_' . $aPost['post_id'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', array($aThread['title_url'], 'post' => $aPost['post_id'])) : null, true)->assign(array('iThreadId' => $iId, 'iActualForumId' => $aForum['forum_id'], 'sFormLink' => $aCallback === false ? $this->url()->makeUrl('forum.post.reply', array('id' => $iId)) : $this->url()->makeUrl('forum.post.reply', array('id' => $iId, 'module' => $sModule, 'item' => $iItemId)), 'sCreateJs' => $oValid->createJS(), 'sGetJsForm' => $oValid->getJsForm(PHPFOX_IS_AJAX ? false : true), 'sReturnLink' => $bIsEdit ? $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'], 'post_' . $aPost['post_id'])) : $this->url()->makeUrl($aCallback['url_home'] . '.forum', $aThread['title_url']) : '', 'sThreadReturnLink' => $aCallback === false ? $this->url()->makeUrl('forum', array($aThread['forum_url'] . '-' . $aThread['forum_id'], $aThread['title_url'])) : $this->url()->makeUrl($aCallback['url_home'], array('forum', $aThread['title_url'])), 'aPreviews' => Phpfox::getService('forum.post')->getPreview($aThread['thread_id']), 'iTotalPosts' => $aThread['total_post'], 'bIsEdit' => $bIsEdit, 'aCallback' => $aCallback, 'iTotalPostPreview' => Phpfox::getParam('forum.total_forum_post_preview')));
         if (Phpfox::getUserParam('forum.can_add_forum_attachments')) {
             $this->setParam('attachment_share', array('type' => 'forum', 'inline' => PHPFOX_IS_AJAX ? true : false, 'id' => 'js_forum_form', 'edit_id' => $bIsEdit ? $aPost['post_id'] : ''));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Controller
  */
 public function process()
 {
     if (Phpfox::isMobile() && Phpfox_Module::instance()->getFullControllerName() == 'forum.forum' && !$this->request()->getInt('req2') && !in_array($this->request()->get('view'), array('subscribed', 'new', 'my-thread'))) {
         return Phpfox_Module::instance()->setController('forum.index');
     }
     Phpfox::getUserParam('forum.can_view_forum', true);
     $aParentModule = $this->getParam('aParentModule');
     $bIsSearch = $this->request()->get('search') ? true : false;
     $aCallback = $this->getParam('aCallback', null);
     $sView = $this->request()->get('view');
     $bShowPosts = false;
     $bIsTagSearch = false;
     $bIsModuleTagSearch = false;
     if ($this->request()->get('req2') == 'tag' && $this->request()->get('req3')) {
         $bIsSearch = true;
         $bIsTagSearch = true;
     }
     if ($this->request()->get('req2') == 'tag' && $this->request()->get('req5') && $this->request()->get('module')) {
         if ($aCallback = Phpfox::getService('group')->getGroup($this->request()->get('item'))) {
             $bIsSearch = true;
             $bIsTagSearch = true;
             $bIsModuleTagSearch = true;
             $aCallback['url_home'] = 'group.' . $aCallback['title_url'] . '.forum';
         }
     }
     $oSearch = Forum_Service_Forum::instance()->getSearchFilter($this->getParam('bIsSearchQuery', false), $this->request()->get('forum_id') ? $this->request()->get('forum_id') : $this->request()->getInt('req2'));
     if ($oSearch->isSearch() && $this->request()->getInt('req2') == 'search') {
         $aIds = [];
         $aForums = $this->request()->get('forum_id') ? Forum_Service_Forum::instance()->id($this->request()->get('forum_id'))->live()->getForums() : Forum_Service_Forum::instance()->live()->getForums();
         if ($this->request()->get('forum_id')) {
             $aIds[] = $this->request()->get('forum_id');
         }
         foreach ($aForums as $aForum) {
             $aIds[] = $aForum['forum_id'];
             $aChilds = (array) Forum_Service_Forum::instance()->id($aForum['forum_id'])->getChildren();
             foreach ($aChilds as $iId) {
                 $aIds[] = $iId;
             }
         }
         $oSearch->setCondition('AND ft.forum_id IN(' . implode(',', $aIds) . ')');
     }
     define('PHPFOX_PAGER_FORCE_COUNT', true);
     $iPage = $this->request()->getInt('page');
     $iPageSize = $oSearch->getDisplay();
     $sViewId = 'ft.view_id = 0';
     if ($aCallback === null) {
         $iForumId = $this->request()->getInt('req2');
         if (Phpfox::getUserParam('forum.can_approve_forum_thread') || Phpfox::getService('forum.moderate')->hasAccess($iForumId, 'approve_thread')) {
             $sViewId = 'ft.view_id >= 0';
         }
     }
     if ($aParentModule == null) {
         $iForumId = $this->request()->getInt('req2');
         $aForums = Forum_Service_Forum::instance()->live()->id($iForumId)->getForums();
         // $aForums = array();
         $aForum = Forum_Service_Forum::instance()->id($iForumId)->getForum();
         $this->template()->assign('isSubForumList', true);
     } else {
         $aForum = array();
         $aForums = array();
     }
     if (!$bIsSearch && $this->request()->get('view') != 'pending-post') {
         if ($aParentModule === null) {
             if (!isset($aForum['forum_id']) && empty($sView)) {
                 return Phpfox_Error::display(Phpfox::getPhrase('forum.not_a_valid_forum'));
             }
             if (isset($aForum['forum_id'])) {
                 $this->setParam('iActiveForumId', $aForum['forum_id']);
             }
             if (!empty($sView)) {
                 switch ($sView) {
                     case 'my-thread':
                         $oSearch->setCondition('AND ft.user_id = ' . Phpfox::getUserId());
                         // $bShowPosts = true;
                         break;
                     case 'pending-thread':
                         if (Phpfox::getUserParam('forum.can_approve_forum_thread')) {
                             $sViewId = 'ft.view_id = 1';
                         }
                         break;
                     default:
                         break;
                 }
                 $oSearch->setCondition('AND ft.group_id = 0 AND ' . $sViewId . ' AND ft.is_announcement = 0');
                 $bIsSearch = true;
             } else {
                 $oSearch->setCondition('AND ft.forum_id = ' . $aForum['forum_id'] . ' AND ft.group_id = 0 AND ' . $sViewId . ' AND ft.is_announcement = 0');
             }
         } else {
             $oSearch->setCondition('AND ft.forum_id = 0 AND ft.group_id = ' . $aParentModule['item_id'] . ' AND ' . $sViewId . ' AND ft.is_announcement = 0');
         }
         // get the forums that we cant access
         $aForbiddenForums = Forum_Service_Forum::instance()->getForbiddenForums();
         if (!empty($aForbiddenForums)) {
             $oSearch->setCondition(' AND ft.forum_id NOT IN (' . implode(',', $aForbiddenForums) . ')');
         }
     }
     if ($oSearch->get('result') || $this->request()->get('view') == 'pending-post') {
         if ($this->request()->get('view') == 'pending-post') {
             $bIsSearch = true;
             $bForceResult = true;
             $oSearch->setCondition('AND fp.view_id = 1');
         }
         list($iCnt, $aThreads) = Phpfox::getService('forum.post')->callback($aCallback)->get($oSearch->getConditions(), $oSearch->getSort(), $oSearch->getPage(), $iPageSize);
     } else {
         if (($iDaysPrune = $oSearch->get('days_prune')) && $iDaysPrune != '-1') {
             $oSearch->setCondition('AND ft.time_stamp >= ' . (PHPFOX_TIME - $iDaysPrune * 86400));
         }
         if ($bIsTagSearch === true) {
             if ($bIsModuleTagSearch) {
                 $oSearch->setCondition("AND ft.group_id = " . (int) $aCallback['group_id'] . " AND tag.tag_url = '" . Phpfox_Database::instance()->escape($this->request()->get('req5')) . "'");
             } else {
                 $oSearch->setCondition("AND ft.group_id = 0 AND tag.tag_url = '" . Phpfox_Database::instance()->escape($this->request()->get('req3')) . "'");
             }
         }
         list($iCnt, $aThreads) = Forum_Service_Thread_Thread::instance()->isSearch($bIsSearch)->isTagSearch($bIsTagSearch)->isNewSearch($sView == 'new' ? true : false)->isSubscribeSearch($sView == 'subscribed' ? true : false)->isModuleSearch($bIsModuleTagSearch)->get($oSearch->getConditions(), 'ft.order_id DESC, ' . $oSearch->getSort(), $oSearch->getPage(), $iPageSize);
     }
     $aAccess = Forum_Service_Forum::instance()->getUserGroupAccess($iForumId, Phpfox::getUserBy('user_group_id'));
     Phpfox_Pager::instance()->set(array('page' => $iPage, 'size' => $iPageSize, 'count' => $iCnt));
     $this->template()->assign(array('aThreads' => $aThreads, 'iSearchId' => $this->request()->getInt('search-id'), 'aCallback' => $aParentModule, 'sView' => $sView, 'aPermissions' => $aAccess))->setHeader('cache', array('forum.css' => 'style_css', 'pager.css' => 'style_css', 'selector.js' => 'static_script'));
     if ($bIsSearch && !isset($aForum['forum_id'])) {
         if (is_array($aCallback)) {
             $this->template()->setBreadcrumb('Pages', $this->url()->makeUrl('pages'))->setBreadcrumb($aCallback['title'], $aCallback['url_home']);
         } else {
             $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.forum'), $this->url()->makeUrl('forum'));
         }
         if ($bIsTagSearch) {
             $aTag = Tag_Service_Tag::instance()->getTagInfo('forum', $bIsModuleTagSearch ? $this->request()->get('req5') : $this->request()->get('req3'));
             if (!empty($aTag['tag_text'])) {
                 if ($bIsModuleTagSearch) {
                     $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.threads_tagged_with') . ': ' . $aTag['tag_text'], $this->url()->makeUrl('forum.tag.module_group.item_' . $this->request()->get('item') . '.' . $this->request()->get('req5')), true);
                 } else {
                     $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.tags'), $this->url()->makeUrl('forum.tag'))->setBreadcrumb(Phpfox::getPhrase('forum.threads_tagged_with') . ': ' . $aTag['tag_text'], $this->url()->makeUrl('forum.tag.' . $this->request()->get('req3')), true);
                 }
             }
         } else {
             if (is_array($aCallback)) {
                 // $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.search'), $this->url()->makeUrl('forum.search', array('module' => 'pages', 'item' => $aCallback['group_id'])));
             } else {
                 // $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.search'), $this->url()->makeUrl('forum.search'));
             }
         }
         $this->template()->assign(array('bIsSearch' => true, 'bResult' => isset($bForceResult) ? true : $oSearch->get('result'), 'aForumResults' => $oSearch->get('forum'), 'bIsTagSearch' => $bIsTagSearch));
     } else {
         if (Phpfox::getParam('forum.rss_feed_on_each_forum')) {
             if ($aParentModule === null) {
                 $this->template()->setHeader('<link rel="alternate" type="application/rss+xml" title="' . Phpfox::getPhrase('forum.forum') . ': ' . $aForum['name'] . '" href="' . $this->url()->makeUrl('forum', array('rss', 'forum' => $aForum['forum_id'])) . '" />');
             } else {
                 $this->template()->setHeader('<link rel="alternate" type="application/rss+xml" title="' . Phpfox::getPhrase('forum.group_forum') . ': ' . $aCallback['title'] . '" href="' . $this->url()->makeUrl('forum', array('rss', 'group' => $aCallback['group_id'])) . '" />');
             }
         }
         if ($aCallback === null && $aParentModule === null) {
             if (!$aForum['is_closed'] && Phpfox::getUserParam('forum.can_add_new_thread') || Phpfox::getService('forum.moderate')->hasAccess($aForum['forum_id'], 'add_thread')) {
                 $this->template()->setMenu(['forum.forum' => ['menu_id' => null, 'module' => 'forum', 'url' => $this->url()->makeUrl('forum.post.thread', ['id' => $aForum['forum_id']]), 'var_name' => 'new_thread']]);
             }
         } else {
             if ($aParentModule !== null) {
                 $this->template()->setMenu(['forum.forum' => ['menu_id' => null, 'module' => 'forum', 'url' => $this->url()->makeUrl('forum.post.thread', ['module' => $aParentModule['module_id'], 'item' => $aParentModule['item_id']]), 'var_name' => 'new_thread']]);
                 // d($aParentModule); exit;
             }
         }
         /*
         {if !$aForumData.is_closed && Phpfox::getUserParam('forum.can_add_new_thread') || Phpfox::getService('forum.moderate')->hasAccess('' . $aForumData.forum_id . '', 'add_thread')}
         <div class="sub_menu_bar_main"><a href="{url link='forum.post.thread' id=$aForumData.forum_id}">{phrase var='forum.new_thread'}</a></div>
         		{/if}
         	{else}
         		<div class="sub_menu_bar_main"><a href="{url link='forum.post.thread' module=$aCallback.module_id item=$aCallback.item_id}">{phrase var='forum.new_thread'}</a></div>
         	{/if}
         */
         if ($aParentModule === null) {
             if (!Forum_Service_Forum::instance()->hasAccess($aForum['forum_id'], 'can_view_forum')) {
                 $this->url()->send('forum');
             }
             $this->template()->setTitle(Phpfox_Locale::instance()->convert($aForum['name']))->setBreadcrumb($aForum['breadcrumb'])->setBreadcrumb(Phpfox_Locale::instance()->convert($aForum['name']), $this->url()->permalink('forum', $aForum['forum_id'], $aForum['name']), true)->assign(array('bDisplayThreads' => true, 'aAnnouncements' => Forum_Service_Thread_Thread::instance()->getAnnoucements($iForumId), 'aForums' => $aForums, 'aForumData' => $aForum, 'bHasCategory' => false, 'bIsSubForum' => true, 'bIsSearch' => false, 'bIsTagSearch' => false));
         } else {
             $this->template()->setBreadcrumb(Phpfox::getPhrase('forum.forum'), $this->url()->makeUrl(''))->setTitle(Phpfox::getPhrase('forum.discussions'))->assign(array('bDisplayThreads' => true, 'bHasCategory' => false, 'bIsSubForum' => true, 'bIsSearch' => false, 'bIsTagSearch' => false, 'aAnnouncements' => Forum_Service_Thread_Thread::instance()->getAnnoucements(null, isset($aParentModule['item_id']) ? $aParentModule['item_id'] : 1)));
         }
     }
     if ($bIsSearch && (isset($bForceResult) || $oSearch->get('result'))) {
         if (isset($bForceResult)) {
             $this->setParam('global_moderation', array('name' => 'forumpost', 'ajax' => 'forum.postModeration', 'menu' => array(array('phrase' => Phpfox::getPhrase('forum.delete'), 'action' => 'delete'), array('phrase' => Phpfox::getPhrase('forum.approve'), 'action' => 'approve'))));
         } else {
             $this->template()->assign('bIsPostSearch', true);
         }
     } else {
         $this->setParam('global_moderation', array('name' => 'forum', 'ajax' => 'forum.moderation', 'menu' => array(array('phrase' => Phpfox::getPhrase('forum.delete'), 'action' => 'delete'), array('phrase' => Phpfox::getPhrase('forum.approve'), 'action' => 'approve'))));
     }
 }