Exemplo n.º 1
0
 public function searchAction()
 {
     $request = $this->getRequest();
     $keyword = $request->getRequest('keyword_comment');
     $keyword = trim(mb_strtolower(urldecode($keyword), 'UTF-8'));
     $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')), array('name' => $this->translate('Search')));
     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->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('name' => $this->translate('All Topics'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum'))), $this->view->mainCategories);
     $this->view->headline = $this->translate('All Topics');
     $this->view->sel_thread = -1;
     $this->view->headline = $this->translate('Search') . ': ' . $keyword;
     $threads = Model_Forum::getSearch($keyword);
     $total_records = count($threads);
     if ($threads) {
         $model_images = new Model_Images();
         $page = (int) $request->getRequest('page', 1);
         if ($page < 1) {
             $page = 1;
         }
         $limit = JO_Registry::get('front_limit');
         $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);
         $this->view->smiles = Model_Smiles::getSmilesImages();
         $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'] = $thread_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($thread['cnt'] / $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';
 }