Browse Source

Fix cache

master
M@dD3n 5 years ago
parent
commit
1b4c6c41d1
  1. 114
      class/class.core.php
  2. 28
      class/class.database.php
  3. 30
      class/class.docs.php
  4. 23
      functions/func.common.php
  5. 2
      functions/func.documents.php
  6. 2
      inc/config.php

114
class/class.core.php

@ -732,8 +732,8 @@
$main_content
);
$main_content = str_replace('[tag:docdate]', pretty_date(strftime(DATE_FORMAT, $this->curentdoc->document_published)), $main_content);
$main_content = str_replace('[tag:doctime]', pretty_date(strftime(TIME_FORMAT, $this->curentdoc->document_published)), $main_content);
$main_content = str_replace('[tag:docdate]', translate_date(strftime(DATE_FORMAT, $this->curentdoc->document_published)), $main_content);
$main_content = str_replace('[tag:doctime]', translate_date(strftime(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);
@ -758,7 +758,7 @@
*
* @return string
*/
function _get_cache_hash()
function _get_cache_hash ()
{
$hash = 'g-' . UGROUP; // Группа пользователей
$hash .= 'r-' . RUB_ID; // ID Рубрики
@ -774,7 +774,7 @@
*
* @return array|bool
*/
function _get_cache_id()
function _get_cache_id ()
{
$cache = array();
@ -1593,6 +1593,10 @@
{
global $AVE_DB;
$document_id = null;
$cache_time = 0;
//-- Если нужны параметры GET, можно отключить
$get_url = (strpos($get_url, ABS_PATH . '?') === 0
? ''
@ -1640,7 +1644,8 @@
preg_replace_callback('/(page|apage|artpage)-(\d+)/i',
function ($matches)
{
$_GET[$matches[1]] = $matches[2]; $_REQUEST[$matches[1]] = $matches[2];;
$_GET[$matches[1]] = $matches[2];
$_REQUEST[$matches[1]] = $matches[2];
},
$pages);
}
@ -1649,7 +1654,7 @@
{
$get_url = implode('/', $get_url);
}
var_dump($get_url);
//-- Страница тегов
preg_match('/^tags(|(\/.*))+$/is', $get_url, $match);
@ -1695,10 +1700,13 @@
//-- Экранируем поступающий URL
$get_url = $AVE_DB->ClearUrl($get_url);
//-- Заглушка для главной страницы
if ($get_url == '')
$get_url = '/';
//-- Проверяем есть ли данный URL в таблице алиасов модулей
$sql = "
SELECT
# MODULE LINK
document_id,
module_name,
module_action,
@ -1707,10 +1715,12 @@
" . PREFIX . "_modules_aliases
WHERE
module_url = '" . str_ireplace("'", "\'", $get_url) . "'
# MODULE LINK
";
$module = $AVE_DB->Query($sql)->FetchAssocArray();
//-- Если модуль есть, переназначаем URL и переменные
if ($module)
{
//-- Передаем глобальные перемененные
@ -1721,64 +1731,63 @@
//-- Если есть document_id, назначем его
if ($module['document_id'])
$_REQUEST['id'] = (int)$module['document_id'];
$document_id = $_REQUEST['id'] = (int)$module['document_id'];
else
$document_id = $_REQUEST['id'] = 1;
}
//-- УБираем лишнее
unset ($sql, $module);
//-- Проверка на наличие id в запросе
if (! empty($_REQUEST['id']))
//-- Если пришел $_REQUEST['id'] документа, получаем URL для проверки
if (! empty($_REQUEST['id']) && is_numeric($_REQUEST['id']))
{
$get_url = $AVE_DB->Query("
$sql = "
SELECT
document_alias
FROM
" . PREFIX . "_documents
WHERE
Id = '" . (int)$_REQUEST['id'] . "'
")->GetCell();
}
Id = '" . intval($_REQUEST['id']) . "'
# FIND DOCID
";
// Выполняем запрос к БД на получение всей необходимой
// информации о документе
$document_id = intval($_REQUEST['id']);
$document_id = (! empty($_REQUEST['id'])
? intval($_REQUEST['id'])
: 1);
$get_url = $AVE_DB->Query($sql)->GetCell();
}
// Иначе пробуем получить ID по URL
else
{
$sql = "
SELECT
Id
FROM
" . PREFIX . "_documents
WHERE
document_alias = '" . str_ireplace("'", "\'", $get_url) . "'
# FIND DOCURL
";
//-- Забираем нужные данные
$sql = "
SELECT
# URL FETCH = $get_url
*
FROM
" . PREFIX . "_documents
WHERE
" . (! empty ($get_url) && ! isset($_REQUEST['module'])
? "document_alias = '" . str_ireplace("'", "\'", $get_url) . "'"
: (! empty($_REQUEST['id'])
? "Id =" . intval($_REQUEST['id'])
: "Id = 1")) . "
LIMIT 1
";
$document_id = intval($AVE_DB->Query($sql)->GetCell());
}
$hash_url = md5($get_url);
//-- УБираем лишнее
unset ($sql);
$cache_time = 0;
//-- Выполняем запрос к БД на получение всей необходимой
//-- информации о документе
$this->curentdoc = getDocument($document_id);
if (defined('CACHE_DOC_FILE') && CACHE_DOC_FILE)
$cache_time = -1;
else
$AVE_DB->clearCacheUrl('url_' . $hash_url);
$this->curentdoc = $AVE_DB->Query($sql, $cache_time, 'url_' . $hash_url, true, '.url')->FetchRow();
// Если данные документа получены
if ($this->curentdoc)
{
// Получить шаблон рубрики
$sql = "
SELECT STRAIGHT_JOIN
# FETCH RUB = " . $this->curentdoc->rubric_id . "
prm.rubric_permission,
rub.rubric_template,
rub.rubric_meta_gen,
@ -1801,6 +1810,7 @@
prm.user_group_id = '" . UGROUP . "'
AND
rub.Id = '" . $this->curentdoc->rubric_id . "'
# FETCH RUB = " . $this->curentdoc->rubric_id . "
";
$query = $AVE_DB->Query($sql, $cache_time, 'rub_' . $this->curentdoc->rubric_id, true, '.rubric')->FetchRow();
@ -1816,7 +1826,7 @@
unset ($this->curentdoc->template);
}
//-- Глобальные переменные
//-- Переназначем глобальные переменные
$_GET['id'] = $_REQUEST['id'] = $this->curentdoc->Id;
$_GET['doc'] = $_REQUEST['doc'] = $this->curentdoc->document_alias;
@ -1850,18 +1860,17 @@
header('Location:' . ABS_PATH);
else
header('Location:' . ABS_PATH . $get_url . URL_SUFF);
exit();
exit;
}
}
// Иначе ищем URL в редиректах
else
{
$AVE_DB->clearCacheUrl('url_' . $hash_url);
$sql = "
SELECT
# REDIRECT = $get_url
a.document_alias
a.document_alias,
h.document_alias_header
FROM
".PREFIX."_document_alias_history AS h,
".PREFIX."_documents AS a
@ -1871,16 +1880,15 @@
h.document_alias = '" . $get_url . "'
";
$redirect_alias = $AVE_DB->Query($sql)->GetCell();
$redirect_alias = $AVE_DB->Query($sql)->FetchRow();
if ($redirect_alias && ! empty($redirect_alias))
if ($redirect_alias->document_alias && ! empty($redirect_alias->document_alias))
{
$redirect_alias = ABS_PATH . $redirect_alias . URL_SUFF;
$redirect_alias = ABS_PATH . $redirect_alias->document_alias . URL_SUFF;
$redirect_alias = str_replace('//', '/', $redirect_alias);
header('HTTP/1.1 301 Moved Permanently');
header('Location:' . $redirect_alias);
exit();
header('Location:' . $redirect_alias, true, $redirect_alias->document_alias_header);
exit;
}
if (! (! empty($_REQUEST['sysblock']) || ! empty($_REQUEST['module']) || ! empty($_REQUEST['request'])))

28
class/class.database.php

@ -820,13 +820,6 @@
return $cache_id = 'documents/' . (floor($cache_id / 1000)) . '/' . $cache_id;
}
//-- Сборка страницы
if (substr($cache_id, 0, 3) == 'url')
{
$cache_id = str_replace('url_', '', $cache_id);
return $cache_id = 'documents/urls/' . substr($cache_id, 0, 3);
}
//-- Если это хлебные крошки, то меняем расположение
if (substr($cache_id, 0, 3) == 'brd')
{
@ -895,7 +888,7 @@
if (defined(SQL_QUERY_SANITIZE) && SQL_QUERY_SANITIZE)
$query = filter_var($query, FILTER_SANITIZE_STRING);
$result = array();
$result = [];
// Если это SELECT - то отслеживаем кеширование
$TTL = strtoupper(substr(trim($query), 0, 6)) == 'SELECT'
@ -917,14 +910,18 @@
if (! file_exists($cache_dir))
mkdir($cache_dir, 0766, true);
if (! (file_exists($cache_dir . $cache_file) && ($TTL == -1 ? true : time() - filemtime($cache_dir . $cache_file) < $TTL)))
$TTL = ($TTL == -1)
? true
: time() - filemtime($cache_dir . $cache_file) < $TTL;
if (! (file_exists($cache_dir . $cache_file) && $TTL))
{
$res = $this->Real_Query($query, $log);
while ($mfa = $res->FetchAssocArray())
$result[] = $mfa;
file_put_contents($cache_dir . $cache_file, serialize($result));
file_put_contents($cache_dir . $cache_file, _base64_encode(serialize($result)));
}
else
{
@ -933,15 +930,15 @@
{
$_caller = $this->getCaller();
$this->_query_list[] = array(
$this->_query_list[] = [
'caller' => $_caller,
'query' => $query,
'ttl' => $TTL,
'cache' => $cache_dir . $cache_file
);
];
}
$result = unserialize(file_get_contents($cache_dir . $cache_file));
$result = unserialize(_base64_decode(file_get_contents($cache_dir . $cache_file)));
}
return new AVE_DB_Result($result);
@ -1551,16 +1548,13 @@
* @param $doc_id
* @param $hash
*/
public function clearDocument($doc_id, $hash = null)
public function clearDocument($doc_id)
{
$this->clearCache('doc_' . $doc_id); // Прочее
$this->clearCache('fld_' . $doc_id); // Поля
$this->clearCache('cmd_' . $doc_id); // Компиляция
$this->clearCache('brd_' . $doc_id); // Хлебные крошки
$this->clearCache('rqe_' . $doc_id); // Элемент запроса
if ($hash)
$this->clearCacheUrl('url_' . $hash); // ЮРЛ
}

30
class/class.docs.php

@ -1829,13 +1829,9 @@
if ($rubric_code)
eval (' ?'.'>' . $_rubric->rubric_code_end . '<?'.'php ');
if ($document_id == 1)
$hash_url = md5('');
else
$hash_url = md5($data['document_alias']);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
unset ($_rubric, $fields);
@ -2818,10 +2814,8 @@
Id = '" . $document_id . "'
");
$hash_url = md5($row->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
// Сохраняем системное сообщение в журнал
reportLog('Положил документ в корзину (' . $document_id . ')');
@ -2862,10 +2856,8 @@
// Сохраняем системное сообщение в журнал
reportLog('Восстановил удаленный документ (' . $document_id . ')');
$hash_url = md5($row->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
// Выполняем обновление страницы
header('Location:index.php?do=docs'.(empty($_REQUEST['rubric_id']) ? '' : '&rubric_id='.$_REQUEST['rubric_id']).'&cp=' . SESSION);
@ -2914,10 +2906,8 @@
f2.document_id = f1.document_id
");
$hash_url = md5($row->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
// Сохраняем системное сообщение в журнал
reportLog('Удалил документ <strong>'. $row->document_title . ' (ID: ' . $document_id . ')</strong>');
@ -3029,10 +3019,8 @@
Id = '" . $document_id . "'
");
$hash_url = md5($document->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
// Сохраняем системное сообщение в журнал
reportLog($_SESSION['user_name'] . ' - ' . (($openclose==1) ? $AVE_Template->get_config_vars('DOC_DOCUMENT_ACT') : $AVE_Template->get_config_vars('DOC_DOCUMENT_DISACT')) . ' ' . $AVE_Template->get_config_vars('DOC_DOCUMENT_DOC') . ' (' . $document_id . ')', 2, 2);
@ -3063,20 +3051,16 @@
}
$hash_url = md5($document->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
exit;
}
else
{
$hash_url = md5($document->document_alias);
// Чистим кеш
$AVE_DB->clearDocument($document_id, $hash_url);
$AVE_DB->clearDocument($document_id);
// Выполняем обновление страницы
header('Location:index.php?do=docs'.(empty($_REQUEST['rubric_id']) ? '' : '&rubric_id='.$_REQUEST['rubric_id']).'&cp=' . SESSION);

23
functions/func.common.php

@ -1267,4 +1267,27 @@
if ($exit)
exit;
}
/**
* _base64_encode()
*
* @param string $input
* @return
*/
function _base64_encode($input)
{
return strtr(base64_encode($input), '+/=', '-_,');
}
/**
* _base64_decode()
*
* @param string $input
* @return
*/
function _base64_decode($input)
{
return base64_decode(strtr($input, '-_,', '+/='));
}
?>

2
functions/func.documents.php

@ -99,7 +99,7 @@
$get_documents_data[$doc_id] = object2array($get_documents_data[$doc_id]);
$get_documents_data[$doc_id]['doc_title'] = $get_documents_data[$doc_id]['document_title'];
$get_documents_data[$doc_id]['feld'] = array();
$get_documents_data[$doc_id]['feld'] = [];
}
if (isset($key) && $key != '')

2
inc/config.php

@ -12,7 +12,7 @@
*/
@define('APP_NAME', 'AVE.cms');
@define('APP_VERSION', '3.25');
@define('APP_VERSION', '3.26');
@define('APP_INFO', '<a target="_blank" href="https://www.ave-cms.ru/">Ave-Cms.Ru</a> '.'&copy; 2007-' . date('Y'));
$themes = array();

Loading…
Cancel
Save