Advertisement
mr_therabbit

Untitled

Dec 1st, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Search_Controller
  5.  * Класс страниц search - поиск на сайте.
  6.  *
  7.  * @package
  8.  * @author TheRabbit
  9.  * @copyright 2013
  10.  * @version $Id$
  11.  * @access public
  12.  */
  13. class Search_Controller extends Base_Controller {
  14.  
  15.     /**
  16.      * Search_Controller::action_index()
  17.      * Страница поиска.
  18.      *
  19.      * @return
  20.      */
  21.     public function action_index(){
  22.         $intPage = intval(Input::get('p'));
  23.         if ($intPage <= 0) $intPage = 1;
  24.         $intCountVideoOnPage = Config::get('tube.count_video_on_page');
  25.        
  26.         $strQuery = str_replace('+', ' ', Str::limit(trim(Input::get('q')), 255));
  27.        
  28.         // Осуществим поиск по базе. ПОКА ТОЛЬКО СРЕДИ ВИДЕО
  29.         $arrResultSearch = Cache::remember('cache:search5:'.$intPage.':'.$strQuery.':'.$intCountVideoOnPage, function() use ($intPage, $strQuery, $intCountVideoOnPage) {
  30.             $arrResult = array();
  31.            
  32.             if (strlen($strQuery))
  33.                 $arrResult = SphinxContent::search($strQuery, 'video', $intPage, $intCountVideoOnPage);
  34.            
  35.             $arrResult['videos'] = array();
  36.            
  37.             if (isset($arrResult['result']['video']) && $arrResult['result']['video'] !== false && count($arrResult['result']['video'])) {
  38.                 foreach ($arrResult['result']['video'] as $intVID) {
  39.                     $arrResult['videos'][] = Video::get($intVID);
  40.                 }//\\ foreach
  41.             }//\\ if
  42.            
  43.             return $arrResult;
  44.         }, 60);
  45.        
  46.        
  47.         // Сделаем иньекции данных в шаблон
  48.         // Установим заголовок
  49.         //if ($intPage > 1)
  50.         Config::set('tube.site.title', 'result search '.$strQuery.' page '.$intPage);
  51.  
  52.         // Установим каноническую ссылку
  53.         Config::set('tube.site.canonical', URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
  54.  
  55.  
  56.         // Отрисуем page navigator
  57.         $arrPages = array(); // Только 11 элементов можно вывести
  58.         $strLinkPrev = '';
  59.         $strLinkNext = '';
  60.         if ($arrResultSearch['count_page'] > 1){
  61.             if ($intPage > 1)
  62.                 $strLinkPrev = URL::to_route('search').'?p='.($intPage - 1).'&q='.Str::slug($strQuery, '+');
  63.             if ($intPage < $arrResultSearch['count_page'])
  64.                 $strLinkNext = URL::to_route('search').'?p='.($intPage + 1).'&q='.Str::slug($strQuery, '+');
  65.        
  66.             // Сделаем 11 элементов для листалки
  67.             // 1   2    3   4   5
  68.             // 31  32  33  34  35
  69.             $intCountItems = 11;
  70.             if ($intPage < 6) {
  71.                 $intP1 = 1;
  72.                 $intP2 = ($arrResultSearch['count_page'] >= 11 ? 11 : $arrResultSearch['count_page']);
  73.             } elseif($intPage + 6 >= $arrResultSearch['count_page']) {
  74.                 $intP1 = $intPage - 5;
  75.                 $intP2 = $arrResultSearch['count_page'];
  76.             } else {
  77.                 $intP1 = $intPage - 5;
  78.                 $intP2 = $intPage + 5;
  79.             }//\\ if
  80.  
  81.             for ($intI = $intP1; $intI < $intPage; $intI++)
  82.                 $arrPages[] = array('num' => $intI, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
  83.             $arrPages[] = array('num' => $intPage, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
  84.             for ($intI = ($intPage + 1); $intI <= $intP2; $intI++)
  85.                 $arrPages[] = array('num' => $intI, 'url' => URL::to_route('search').'?p='.$intPage.'&q='.Str::slug($strQuery, '+'));
  86.  
  87.         }//\\ if
  88.        
  89.         return View::make('tube.search', array(
  90.             'videos' => $arrResultSearch['videos'],
  91.             'pages' => $arrPages,
  92.             'count_page' => $arrResultSearch['count_page'],
  93.             'current_page' => $arrResultSearch['current_page'],
  94.             'link_prev' => $strLinkPrev,
  95.             'link_next' => $strLinkNext,
  96.         ));
  97.     }//\\
  98.    
  99.    
  100. }//\\ Search_Controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement