1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-05-07 19:38:19 +03:00

Рефакторинг

This commit is contained in:
Mzhelskiy Maxim 2015-03-19 09:40:22 +07:00
parent 8abbcb779e
commit 1e24708ca4
4 changed files with 10 additions and 18 deletions

View file

@ -722,11 +722,10 @@ class ActionBlog extends Action
protected function EventInternalShowTopicByUrl()
{
$sTopicUrl = Config::Get('module.topic._router_topic_original_url');
$sSecurityHash = Config::Get('module.topic._router_topic_security_hash');
/**
* Проверяем ключ
*/
if ($sSecurityHash != Config::Get('module.security.hash')) {
if (is_null($sTopicUrl)) {
return $this->EventErrorDebug();
}
/**

View file

@ -1870,7 +1870,7 @@ class ModuleTopic extends Module
'%blog%' => '',
'%id%' => $oTopic->getId(),
'%title%' => $oTopic->getSlug(),
'%type%' => $oTopic->getType(),
'%type%' => $oTopic->getType(),
);
/**
@ -1915,7 +1915,7 @@ class ModuleTopic extends Module
/**
* Возвращает URL с учетом уникалькости по всем топикам
*
* @param string$sSlug
* @param string $sSlug
* @param int|null $iSkipTopicId
* @return string
*/
@ -1923,15 +1923,10 @@ class ModuleTopic extends Module
{
$iPostfix = 0;
do {
$oTopic = $this->GetTopicBySlug($sSlug . ($iPostfix ? '-' . $iPostfix : ''));
if ($oTopic and (is_null($iSkipTopicId) or $iSkipTopicId != $oTopic->getId())) {
$iPostfix++;
$bNeedNext = true;
} else {
$bNeedNext = false;
}
} while ($bNeedNext);
$sUrl = $sSlug . ($iPostfix ? '-' . $iPostfix : '');
$iPostfix++;
} while ($oTopic = $this->GetTopicBySlug($sUrl) and (is_null($iSkipTopicId) or $iSkipTopicId != $oTopic->getId()));
return $sSlug . ($iPostfix ? '-' . $iPostfix : '');
return $sUrl;
}
}

View file

@ -166,10 +166,10 @@ $config['module']['topic']['default_preview_size'] = '900x300crop'; // Дефо
*
* В шаблоне обязательно должен быть %id% или %title%, это необходимо для точной идентификации топика
*/
$config['module']['topic']['url'] = '%year%/%month%/%day%/%id%.html';
$config['module']['topic']['url'] = '%year%/%month%/%day%/%title%.html';
/**
* Список регулярных выражений для частей URL топика
* Без необходмых навыков лучше этот параметр не менять
* Без необходимых навыков лучше этот параметр не менять
*/
$config['module']['topic']['url_preg'] = array(
'%year%' => '\d{4}',

View file

@ -67,8 +67,7 @@ $aRouterParams = array(
/**
* Логика по ЧПУ топиков
* Если URL соответствует шаблону ЧПУ топика, перенаправляем обработку на экшен/евент /blog/_show_topic_url/
* Через свои параметры конфига передаем исходный URL и ключ из конфига 'module.security.hash', ключ нужен для проверки валидности запроса.
* Если ключ верный, то 100% это внутренняя обработка, а не произвольное внешнее обращение к URL
* Через свои параметры конфига передаем исходный URL
* Суть обработки _show_topic_url в том, чтобы определить ID топика и корректность его URL, если он некорректен, то произвести его корректировку через внешний редирект на правильный URL
* Если удалось определить топик и URL корректный, то происходит внутренний редирект на стандартный евент отображения топика по ID (/blog/12345.html)
*/
@ -103,7 +102,6 @@ $aRouterParams = array(
* Модуль кеша здесь нельзя использовать, т.к. еще не произошло инициализации ядра
*/
Config::Set('module.topic._router_topic_original_url', $sUrlRequest);
Config::Set('module.topic._router_topic_security_hash', Config::Get('module.security.hash'));
}
}
)