2009-05-10 10:50:39 +03:00
|
|
|
|
<?php
|
2014-10-08 08:20:29 +03:00
|
|
|
|
/*
|
2014-04-29 09:08:15 +03:00
|
|
|
|
* LiveStreet CMS
|
|
|
|
|
* Copyright © 2013 OOO "ЛС-СОФТ"
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Official site: www.livestreetcms.com
|
|
|
|
|
* Contact e-mail: office@livestreetcms.com
|
|
|
|
|
*
|
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*
|
2014-04-29 09:08:15 +03:00
|
|
|
|
* @link http://www.livestreetcms.com
|
2014-10-08 08:20:29 +03:00
|
|
|
|
* @copyright 2013 OOO "ЛС-СОФТ"
|
2014-04-29 09:08:15 +03:00
|
|
|
|
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обработка основного поиска
|
2014-10-08 08:20:29 +03:00
|
|
|
|
*
|
|
|
|
|
* @package application.actions
|
|
|
|
|
* @since 1.0
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
|
class ActionSearch extends Action
|
|
|
|
|
{
|
2012-04-29 20:11:53 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
public function Init()
|
|
|
|
|
{
|
|
|
|
|
$this->SetDefaultEvent('index');
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('search.search'));
|
|
|
|
|
}
|
2014-04-29 09:08:15 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent()
|
|
|
|
|
{
|
|
|
|
|
$this->AddEvent('index', 'EventIndex');
|
|
|
|
|
$this->AddEventPreg('/^topics$/i', '/^(page([1-9]\d{0,5}))?$/i', 'EventTopics');
|
|
|
|
|
$this->AddEventPreg('/^comments$/i', '/^(page([1-9]\d{0,5}))?$/i', 'EventComments');
|
|
|
|
|
$this->AddEvent('opensearch', 'EventOpenSearch');
|
|
|
|
|
}
|
2014-04-29 09:08:15 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Главная страница поиска
|
|
|
|
|
*/
|
|
|
|
|
protected function EventIndex()
|
|
|
|
|
{
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обработка стандарта для браузеров Open Search
|
|
|
|
|
*/
|
|
|
|
|
function EventOpenSearch()
|
|
|
|
|
{
|
|
|
|
|
Router::SetIsShowStats(false);
|
|
|
|
|
header('Content-type: text/xml; charset=utf-8');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обработка поиска топиков
|
|
|
|
|
*/
|
|
|
|
|
protected function EventTopics()
|
|
|
|
|
{
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
$sSearchType = $this->sCurrentEvent;
|
|
|
|
|
$iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список слов для поиска
|
|
|
|
|
*/
|
|
|
|
|
$aWords = $this->Search_GetWordsForSearch(getRequestStr('q'));
|
|
|
|
|
if (!$aWords) {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('search.alerts.query_incorrect'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$sQuery = join(' ', $aWords);
|
|
|
|
|
/**
|
|
|
|
|
* Формируем регулярное выражение для поиска
|
|
|
|
|
*/
|
|
|
|
|
$sRegexp = $this->Search_GetRegexpForWords($aWords);
|
|
|
|
|
/**
|
|
|
|
|
* Выполняем поиск
|
|
|
|
|
*/
|
|
|
|
|
$aResult = $this->Search_SearchTopics($sRegexp, $iPage, Config::Get('module.topic.per_page'));
|
|
|
|
|
$aResultItems = $aResult['collection'];
|
|
|
|
|
/**
|
|
|
|
|
* Конфигурируем парсер jevix
|
|
|
|
|
*/
|
|
|
|
|
$this->Text_LoadJevixConfig('search');
|
|
|
|
|
/**
|
|
|
|
|
* Делаем сниппеты
|
|
|
|
|
*/
|
|
|
|
|
foreach ($aResultItems AS $oItem) {
|
|
|
|
|
/**
|
|
|
|
|
* Т.к. текст в сниппетах небольшой, то можно прогнать через парсер
|
|
|
|
|
*/
|
|
|
|
|
$oItem->setTextShort($this->Text_JevixParser($this->Search_BuildExcerpts($oItem->getText(), $aWords)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Формируем постраничность
|
|
|
|
|
*/
|
|
|
|
|
$aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'),
|
|
|
|
|
Config::Get('pagination.pages.count'), Router::GetPath('search') . $sSearchType, array('q' => $sQuery));
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('aResultItems', $aResultItems);
|
|
|
|
|
$this->Viewer_Assign('aPaging', $aPaging);
|
|
|
|
|
$this->Viewer_Assign('sSearchType', $sSearchType);
|
|
|
|
|
$this->Viewer_Assign('sQuery', $sQuery);
|
|
|
|
|
$this->Viewer_Assign('aTypeCounts', array($sSearchType => $aResult['count']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обработка поиска комментариев
|
|
|
|
|
*/
|
|
|
|
|
protected function EventComments()
|
|
|
|
|
{
|
|
|
|
|
$this->SetTemplateAction('index');
|
|
|
|
|
$sSearchType = $this->sCurrentEvent;
|
|
|
|
|
$iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1;
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список слов для поиска
|
|
|
|
|
*/
|
|
|
|
|
$aWords = $this->Search_GetWordsForSearch(getRequestStr('q'));
|
|
|
|
|
if (!$aWords) {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('search.alerts.query_incorrect'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$sQuery = join(' ', $aWords);
|
|
|
|
|
/**
|
|
|
|
|
* Формируем регулярное выражение для поиска
|
|
|
|
|
*/
|
|
|
|
|
$sRegexp = $this->Search_GetRegexpForWords($aWords);
|
|
|
|
|
/**
|
|
|
|
|
* Выполняем поиск
|
|
|
|
|
*/
|
|
|
|
|
$aResult = $this->Search_SearchComments($sRegexp, $iPage, 4, 'topic');
|
|
|
|
|
$aResultItems = $aResult['collection'];
|
|
|
|
|
/**
|
|
|
|
|
* Конфигурируем парсер jevix
|
|
|
|
|
*/
|
|
|
|
|
$this->Text_LoadJevixConfig('search');
|
|
|
|
|
/**
|
|
|
|
|
* Делаем сниппеты
|
|
|
|
|
*/
|
|
|
|
|
foreach ($aResultItems AS $oItem) {
|
|
|
|
|
/**
|
|
|
|
|
* Т.к. текст в сниппетах небольшой, то можно прогнать через парсер
|
|
|
|
|
*/
|
|
|
|
|
$oItem->setText($this->Text_JevixParser($this->Search_BuildExcerpts($oItem->getText(), $aWords)));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Формируем постраничность
|
|
|
|
|
*/
|
|
|
|
|
$aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, 4, Config::Get('pagination.pages.count'),
|
|
|
|
|
Router::GetPath('search') . $sSearchType, array('q' => $sQuery));
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('aResultItems', $aResultItems);
|
|
|
|
|
$this->Viewer_Assign('aPaging', $aPaging);
|
|
|
|
|
$this->Viewer_Assign('sSearchType', $sSearchType);
|
|
|
|
|
$this->Viewer_Assign('sQuery', $sQuery);
|
|
|
|
|
$this->Viewer_Assign('aTypeCounts', array($sSearchType => $aResult['count']));
|
|
|
|
|
}
|
2008-12-21 16:36:00 +02:00
|
|
|
|
}
|