Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Search_Controller
- * Класс страниц search - поиск на сайте.
- *
- * @package
- * @author TheRabbit
- * @copyright 2013
- * @version $Id$
- * @access public
- */
- class Search_Controller extends Base_Controller {
- /**
- * Search_Controller::action_index()
- * Страница поиска.
- *
- * @return
- */
- public function action_index(){
- $intPage = intval(Input::get('p'));
- if ($intPage <= 0) $intPage = 1;
- $intCountVideoOnPage = Config::get('tube.count_video_on_page');
- $strQuery = str_replace('+', ' ', Str::limit(trim(Input::get('q')), 255));
- // Осуществим поиск по базе. ПОКА ТОЛЬКО СРЕДИ ВИДЕО
- $arrResultSearch = Cache::remember('cache:search5:'.$intPage.':'.$strQuery.':'.$intCountVideoOnPage, function() use ($intPage, $strQuery, $intCountVideoOnPage) {
- $arrResult = array();
- if (strlen($strQuery))
- $arrResult = SphinxContent::search($strQuery, 'video', $intPage, $intCountVideoOnPage);
- $arrResult['videos'] = array();
- if (isset($arrResult['result']['video']) && $arrResult['result']['video'] !== false && count($arrResult['result']['video'])) {
- foreach ($arrResult['result']['video'] as $intVID) {
- $arrResult['videos'][] = Video::get($intVID);
- }//\\ foreach
- }//\\ if
- return $arrResult;
- }, 60);
- // Сделаем иньекции данных в шаблон
- // Установим заголовок
- //if ($intPage > 1)
- Config::set('tube.site.title', 'result search '.$strQuery.' page '.$intPage);
- // Установим каноническую ссылку
- Config::set('tube.site.canonical', URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
- // Отрисуем page navigator
- $arrPages = array(); // Только 11 элементов можно вывести
- $strLinkPrev = '';
- $strLinkNext = '';
- if ($arrResultSearch['count_page'] > 1){
- if ($intPage > 1)
- $strLinkPrev = URL::to_route('search').'?p='.($intPage - 1).'&q='.Str::slug($strQuery, '+');
- if ($intPage < $arrResultSearch['count_page'])
- $strLinkNext = URL::to_route('search').'?p='.($intPage + 1).'&q='.Str::slug($strQuery, '+');
- // Сделаем 11 элементов для листалки
- // 1 2 3 4 5
- // 31 32 33 34 35
- $intCountItems = 11;
- if ($intPage < 6) {
- $intP1 = 1;
- $intP2 = ($arrResultSearch['count_page'] >= 11 ? 11 : $arrResultSearch['count_page']);
- } elseif($intPage + 6 >= $arrResultSearch['count_page']) {
- $intP1 = $intPage - 5;
- $intP2 = $arrResultSearch['count_page'];
- } else {
- $intP1 = $intPage - 5;
- $intP2 = $intPage + 5;
- }//\\ if
- for ($intI = $intP1; $intI < $intPage; $intI++)
- $arrPages[] = array('num' => $intI, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
- $arrPages[] = array('num' => $intPage, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
- for ($intI = ($intPage + 1); $intI <= $intP2; $intI++)
- $arrPages[] = array('num' => $intI, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
- }//\\ if
- return View::make('tube.search', array(
- 'videos' => $arrResultSearch['videos'],
- 'pages' => $arrPages,
- 'count_page' => $arrResultSearch['count_page'],
- 'current_page' => $arrResultSearch['current_page'],
- 'link_prev' => $strLinkPrev,
- 'link_next' => $strLinkNext,
- ));
- }//\\
- }//\\ Search_Controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement