示例#1
0
 public function topicAction()
 {
     $request = $this->getRequest();
     $thread_id = $request->getRequest('topic');
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Forum'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum')));
     $thread = Model_Forum::getThread($thread_id);
     $this->view->sel_thread = $thread['thread_id'];
     $this->view->headline = $thread['name'];
     $this->view->mainCategories = array();
     $this->view->mainCategories = Model_Forum::getAll();
     foreach ($this->view->mainCategories as $k => $v) {
         $this->view->mainCategories[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=thread/' . $this->view->mainCategories[$k]['id'] . '/' . WM_Router::clearName($this->view->mainCategories[$k]['name']));
     }
     $this->view->mainCategories = array_merge(array(0 => array('id' => 0, 'name' => $this->translate('All Topics'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum'))), $this->view->mainCategories);
     if ($thread) {
         JO_Session::set('redirect', $request->getBaseUrl() . $request->getUri());
         $model_images = new Model_Images();
         $page = (int) $request->getRequest('page', 1);
         if ($page < 1) {
             $page = 1;
         }
         $limit = JO_Registry::get('front_limit');
         if (JO_Session::get('msg_success')) {
             $this->view->msg_success = JO_Session::get('msg_success');
             JO_Session::clear('msg_success');
         }
         if (JO_Session::get('msg_error')) {
             $this->view->error = JO_Session::get('msg_error');
             $this->view->data = JO_Session::get('data');
             JO_Session::clear('msg_error');
             JO_Session::clear('data');
         }
         $this->view->crumbs[] = array('name' => $thread['name']);
         $threads = Model_Forum::getSubComments($thread['id']);
         $this->view->smiles = Model_Smiles::getSmilesImages();
         if ($threads) {
             $total_records = count($threads);
             $start = $page * $limit - $limit;
             if ($start > $total_records) {
                 $page = max(ceil($total_records / $limit), 1);
                 $start = $page * $limit - $limit;
             } elseif ($start < 0) {
                 $start = 0;
             }
             $threads = array_slice($threads, $start, $limit);
             $bbcode_parser = new WM_BBCode_Parser();
             $bbcode_parser->loadDefaultCodes();
             foreach ($threads as $th) {
                 if ($th['avatar']) {
                     $th['avatar'] = $model_images->resize($th['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
                 } else {
                     $th['avatar'] = 'data/themes/images/noavatar.png';
                 }
                 $th['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'username']));
                 $th_link = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=topic/' . $th['id'] . '/' . WM_Router::clearName($th['name']));
                 $th['threadhref'] = $th_link;
                 $th['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=report/' . $th['id']);
                 $th['recent_link'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=recents_for_user&username='******'username']));
                 $th['threads_user_link'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=threads_for_user&username='******'username']));
                 $bbcode_parser->parse($th['comment']);
                 $th['comment_formated'] = Model_Comments::replaceEmoticons($bbcode_parser->getAsHtml());
                 $last_page = ceil($total_records / $limit);
                 $th['datetime'] = WM_Date::format($th['datetime'], 'dd M yy H:i');
                 $th['badges'] = Helper_Author::userBadges($th['badges']);
                 $this->view->threads[] = $th;
             }
         }
         $pagination = new Model_Pagination();
         $pagination->setLimit($limit);
         $pagination->setPage($page);
         $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
         $pagination->setTotal($total_records);
         $pagination->setUrl(WM_Router::create($request->getBaseUrl() . '?controller=forum&action=index&page={page}'));
         $this->view->pagination = $pagination->render();
         if (!empty($this->view->pagination)) {
             $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
         }
     }
     $this->view->add_comment_link = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=add_new_comment');
     $this->view->children = array();
     $this->view->children['rightside'] = 'forum/rightside';
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }