фиксим вывод тегов дат в запросах 2.09 и рубриках и документах
This commit is contained in:
@@ -760,8 +760,9 @@
|
||||
);
|
||||
|
||||
// ИСПРАВЛЕНИЕ DEPRECATED: strftime() заменена на date()
|
||||
$main_content = str_replace('[tag:docdate]', translate_date(date(DATE_FORMAT, $this->curentdoc->document_published)), $main_content);
|
||||
$main_content = str_replace('[tag:doctime]', translate_date(date(TIME_FORMAT, $this->curentdoc->document_published)), $main_content);
|
||||
|
||||
$main_content = str_replace('[tag:docdate]', ave_date_format(DATE_FORMAT, $this->curentdoc->document_published), $main_content);
|
||||
$main_content = str_replace('[tag:doctime]', ave_date_format(TIME_FORMAT, $this->curentdoc->document_published), $main_content);
|
||||
|
||||
$main_content = str_replace('[tag:humandate]', human_date($this->curentdoc->document_published), $main_content);
|
||||
$main_content = str_replace('[tag:docauthorid]', $this->curentdoc->document_author_id, $main_content);
|
||||
|
||||
@@ -852,4 +852,78 @@
|
||||
? 2
|
||||
: $cases[min($number % 10, 5)]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Преобразует strftime-формат в date()-формат,
|
||||
* используя только те символы, которые translate_date() умеет переводить (на английском).
|
||||
*
|
||||
* @param string $format strftime формат (например, '%d %B %Y')
|
||||
* @return string date() формат (например, 'd F Y')
|
||||
*/
|
||||
function strftime_to_date_format($format)
|
||||
{
|
||||
if (empty($format) || !is_string($format)) {
|
||||
return 'Y-m-d H:i:s'; // Безопасный дефолт
|
||||
}
|
||||
|
||||
// Карта замены strftime-символов на date()-символы для перевода
|
||||
$map = array(
|
||||
'%A' => 'l', // Full weekday name (Monday)
|
||||
'%a' => 'D', // Abbreviated weekday name (Mon)
|
||||
'%B' => 'F', // Full month name (January)
|
||||
'%b' => 'M', // Abbreviated month name (Jan)
|
||||
'%d' => 'd', // Day of the month
|
||||
'%m' => 'm', // Month as a number
|
||||
'%Y' => 'Y', // Year with century
|
||||
'%H' => 'H', // Hour (24-hour)
|
||||
'%M' => 'i', // Minute
|
||||
'%S' => 's', // Second
|
||||
);
|
||||
|
||||
return strtr($format, $map);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Универсальная функция форматирования даты,
|
||||
* использующая strftime() (если доступна) или безопасный аналог для PHP 8.1+.
|
||||
*
|
||||
* @param string $format strftime формат
|
||||
* @param int $timestamp UNIX метка времени
|
||||
* @param bool $do_translate Выполнять ли внутренний translate_date(). По умолчанию - ДА.
|
||||
* @return string
|
||||
*/
|
||||
function ave_date_format($format, $timestamp, $do_translate = true)
|
||||
{
|
||||
// Убедимся, что формат — строка и не пустой
|
||||
if (empty($format) || !is_string($format)) {
|
||||
$format = '%d %B %Y г.'; // Безопасный дефолт
|
||||
}
|
||||
|
||||
// --- ПОПЫТКА ИСПОЛЬЗОВАТЬ СТАРЫЙ МЕТОД (для PHP < 8.1) ---
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '<') && function_exists('strftime')) {
|
||||
|
||||
$formatted_date = strftime($format, $timestamp);
|
||||
|
||||
// Условный вызов translate_date
|
||||
return $do_translate
|
||||
? translate_date($formatted_date)
|
||||
: $formatted_date;
|
||||
}
|
||||
|
||||
// --- РЕЗЕРВНЫЙ БЕЗОПАСНЫЙ МЕХАНИЗМ (для PHP 8.1+) ---
|
||||
|
||||
// 1. Преобразуем strftime-формат в date()-формат
|
||||
$date_format_php = strftime_to_date_format($format);
|
||||
|
||||
// 2. Генерируем дату на АНГЛИЙСКОМ языке (используя date() )
|
||||
$formatted_date = date($date_format_php, (int)$timestamp);
|
||||
|
||||
// 3. Условный вызов translate_date
|
||||
return $do_translate
|
||||
? translate_date($formatted_date)
|
||||
: $formatted_date;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -553,9 +553,9 @@ function showrequestelement ($mixed, $template = '', $tparams = '', $req_item_nu
|
||||
$item = str_replace('[tag:doctitle]', stripslashes(htmlspecialchars_decode($row->document_title)), $item);
|
||||
$item = str_replace('[tag:docparent]', $row->document_parent, $item);
|
||||
$item = str_replace('[tag:doclang]', $row->document_lang, $item);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() на date() (PHP 8.1+)
|
||||
$item = str_replace('[tag:docdate]', translate_date(date(DATE_FORMAT, $row->document_published)), $item);
|
||||
$item = str_replace('[tag:doctime]', translate_date(date(TIME_FORMAT, $row->document_published)), $item);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() (PHP 8.1+) Используем универсальную глобальную функцию
|
||||
$item = str_replace('[tag:docdate]', ave_date_format(DATE_FORMAT, $row->document_published), $item);
|
||||
$item = str_replace('[tag:doctime]', ave_date_format(TIME_FORMAT, $row->document_published), $item);
|
||||
$item = str_replace('[tag:humandate]', human_date($row->document_published), $item);
|
||||
|
||||
$item = preg_replace_callback('/\[tag:date:([a-zA-Z0-9-. \/]+)\]/',
|
||||
@@ -813,9 +813,9 @@ function request_parse($id)
|
||||
$main_template = str_replace('[tag:pages:total]', $num_pages, $main_template);
|
||||
$main_template = str_replace('[tag:doctotal]', $num_items, $main_template);
|
||||
$main_template = str_replace('[tag:doconpage]', $x, $main_template);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() на date() для основного документа в запросе
|
||||
$main_template = str_replace('[tag:docdate]', pretty_date(date(DATE_FORMAT, $AVE_Core->curentdoc->document_published)), $main_template);
|
||||
$main_template = str_replace('[tag:doctime]', pretty_date(date(TIME_FORMAT, $AVE_Core->curentdoc->document_published)), $main_template);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() для основного шаблона в запросе
|
||||
$main_template = str_replace('[tag:docdate]', pretty_date(translate_date(ave_date_format(DATE_FORMAT, $AVE_Core->curentdoc->document_published, false))), $main_template);
|
||||
$main_template = str_replace('[tag:doctime]', pretty_date(translate_date(ave_date_format(TIME_FORMAT, $AVE_Core->curentdoc->document_published, false))), $main_template);
|
||||
$main_template = str_replace('[tag:docauthor]', get_username_by_id($AVE_Core->curentdoc->document_author_id), $main_template);
|
||||
$main_template = preg_replace_callback('/\[tag:dropdown:([,0-9]+)\]/', function($m) use ($request) {
|
||||
return request_get_dropdown($m[1], (int)$request->rubric_id, (int)$request->Id);
|
||||
|
||||
@@ -553,9 +553,9 @@ function showrequestelement ($mixed, $template = '', $tparams = '', $req_item_nu
|
||||
$item = str_replace('[tag:doctitle]', stripslashes(htmlspecialchars_decode($row->document_title)), $item);
|
||||
$item = str_replace('[tag:docparent]', $row->document_parent, $item);
|
||||
$item = str_replace('[tag:doclang]', $row->document_lang, $item);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() на date() (PHP 8.1+)
|
||||
$item = str_replace('[tag:docdate]', translate_date(date(DATE_FORMAT, $row->document_published)), $item);
|
||||
$item = str_replace('[tag:doctime]', translate_date(date(TIME_FORMAT, $row->document_published)), $item);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() (PHP 8.1+) Используем универсальную глобальную функцию
|
||||
$item = str_replace('[tag:docdate]', ave_date_format(DATE_FORMAT, $row->document_published), $item);
|
||||
$item = str_replace('[tag:doctime]', ave_date_format(TIME_FORMAT, $row->document_published), $item);
|
||||
$item = str_replace('[tag:humandate]', human_date($row->document_published), $item);
|
||||
|
||||
$item = preg_replace_callback('/\[tag:date:([a-zA-Z0-9-. \/]+)\]/',
|
||||
@@ -813,9 +813,9 @@ function request_parse($id)
|
||||
$main_template = str_replace('[tag:pages:total]', $num_pages, $main_template);
|
||||
$main_template = str_replace('[tag:doctotal]', $num_items, $main_template);
|
||||
$main_template = str_replace('[tag:doconpage]', $x, $main_template);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() на date() для основного документа в запросе
|
||||
$main_template = str_replace('[tag:docdate]', pretty_date(date(DATE_FORMAT, $AVE_Core->curentdoc->document_published)), $main_template);
|
||||
$main_template = str_replace('[tag:doctime]', pretty_date(date(TIME_FORMAT, $AVE_Core->curentdoc->document_published)), $main_template);
|
||||
// ИСПРАВЛЕНИЕ: Замена strftime() для основного шаблона в запросе
|
||||
$main_template = str_replace('[tag:docdate]', pretty_date(translate_date(ave_date_format(DATE_FORMAT, $AVE_Core->curentdoc->document_published, false))), $main_template);
|
||||
$main_template = str_replace('[tag:doctime]', pretty_date(translate_date(ave_date_format(TIME_FORMAT, $AVE_Core->curentdoc->document_published, false))), $main_template);
|
||||
$main_template = str_replace('[tag:docauthor]', get_username_by_id($AVE_Core->curentdoc->document_author_id), $main_template);
|
||||
$main_template = preg_replace_callback('/\[tag:dropdown:([,0-9]+)\]/', function($m) use ($request) {
|
||||
return request_get_dropdown($m[1], (int)$request->rubric_id, (int)$request->Id);
|
||||
|
||||
Reference in New Issue
Block a user