Разбиение документа на части, отдаем 404 ошибку для несуществующих частей
По умолчанию система отдает элемент информационной системы с частью документа с кодом ответа 200 ОК, даже если разбиения на подстраницы не производится url получается следующего вида
Задача: необходимо, чтобы отдавалась 404 ошибка и страница при обращении к элементу без разделителя или к при обращении к несуществующей части документа (три разделителя пытаемся открыть /part-10/)
Меняем код типовой динамической страницы "Информационная система"
в настройках страницы ищем часть
в конце секции, после строк
добавляем проверку
Задача: необходимо, чтобы отдавалась 404 ошибка и страница при обращении к элементу без разделителя или к при обращении к несуществующей части документа (три разделителя пытаемся открыть /part-10/)
Меняем код типовой динамической страницы "Информационная система"
в настройках страницы ищем часть
/* Если вывод информационного элемента */
if ($GLOBALS['INFSYS_result']['item'])
if ($GLOBALS['INFSYS_result']['item'])
в конце секции, после строк
/* проверяем если seo_title непустой, то в заголовок страницы подставляем его */
if (trim($row_item['information_items_seo_title']) != '')
{
$item_name = $property['separator'].trim($row_item['information_items_seo_title']);
}
else
{
if (trim($row_item['information_items_seo_title']) != '')
{
$item_name = $property['separator'].trim($row_item['information_items_seo_title']);
}
else
{
добавляем проверку
// search for page break in item text
$item_text_part=$row_item['information_items_text'];
$fix_needle='<!-- pagebreak -->';
$fix_item_part_count=substr_count($item_text_part,$fix_needle);
// for one page break we have two pages
$fix_item_part=$fix_item_part_count+1;
// if part in request url is higher then page break qty. show 404 header
if($GLOBALS['part_ii']>$fix_item_part){
// Элемент/группа не найдены, возвращаем 404 ошибку.
ShowHeader404();
// Запрещаем отдавать 200-й заголовок
if (!defined('IS_ERROR_404'))
{
define('IS_ERROR_404', true);
}
$site = & singleton('site');
$site_row = $site->GetSite(CURRENT_SITE);
if ($site_row['site_error404'])
{
$structure = & singleton('Structure');
$structure_id = intval($site_row['site_error404']);
$structure_row = $structure->GetStructureItem($structure_id);
// Если тип - страница
if ($structure_row['structure_type'] == 0)
{
$documents = & singleton('documents');
$documents_version_row = $documents->GetCurrentDocumentVersion($structure_row['documents_id']);
$documents_version_id = $documents_version_row['documents_version_id'];
// Текущая страница
$kernel->set_current_page($documents->GetDocumentVersionPath($documents_version_id));
}
elseif ($structure_row['structure_type'] == 1)
{
// Текущая страница - модуль
$kernel->set_current_page($structure->GetStructureFilesPath() . "/Structure{$structure_id}.php");
}
else
{
// Типовая динамическая страница
$lib_id = intval($structure_row['lib_id']);
// Получаем параметры типовой динамической страницы
$lib = new lib();
$GLOBALS['LA'] = $lib->LoadLibPropertiesValue($lib_id, $structure_id);
$kernel->set_current_page($lib->GetLibPath($lib_id) . "/lib_{$lib_id}.php");
}
// Шаблон вывода для страницы
$kernel->set_current_page_data_template($structure_row['data_templates_id']);
}
elseif (to_str($_SERVER['REQUEST_URI']) != '/')
{
header('Location: /');
// Прекращаем выполнение
exit();
}
}
$item_text_part=$row_item['information_items_text'];
$fix_needle='<!-- pagebreak -->';
$fix_item_part_count=substr_count($item_text_part,$fix_needle);
// for one page break we have two pages
$fix_item_part=$fix_item_part_count+1;
// if part in request url is higher then page break qty. show 404 header
if($GLOBALS['part_ii']>$fix_item_part){
// Элемент/группа не найдены, возвращаем 404 ошибку.
ShowHeader404();
// Запрещаем отдавать 200-й заголовок
if (!defined('IS_ERROR_404'))
{
define('IS_ERROR_404', true);
}
$site = & singleton('site');
$site_row = $site->GetSite(CURRENT_SITE);
if ($site_row['site_error404'])
{
$structure = & singleton('Structure');
$structure_id = intval($site_row['site_error404']);
$structure_row = $structure->GetStructureItem($structure_id);
// Если тип - страница
if ($structure_row['structure_type'] == 0)
{
$documents = & singleton('documents');
$documents_version_row = $documents->GetCurrentDocumentVersion($structure_row['documents_id']);
$documents_version_id = $documents_version_row['documents_version_id'];
// Текущая страница
$kernel->set_current_page($documents->GetDocumentVersionPath($documents_version_id));
}
elseif ($structure_row['structure_type'] == 1)
{
// Текущая страница - модуль
$kernel->set_current_page($structure->GetStructureFilesPath() . "/Structure{$structure_id}.php");
}
else
{
// Типовая динамическая страница
$lib_id = intval($structure_row['lib_id']);
// Получаем параметры типовой динамической страницы
$lib = new lib();
$GLOBALS['LA'] = $lib->LoadLibPropertiesValue($lib_id, $structure_id);
$kernel->set_current_page($lib->GetLibPath($lib_id) . "/lib_{$lib_id}.php");
}
// Шаблон вывода для страницы
$kernel->set_current_page_data_template($structure_row['data_templates_id']);
}
elseif (to_str($_SERVER['REQUEST_URI']) != '/')
{
header('Location: /');
// Прекращаем выполнение
exit();
}
}
Авторизация