prokat/api/modules/page/index.php
2025-06-16 18:28:08 +05:00

86 lines
3.9 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ini_set('display_errors', 0);
if (!@$_SESSION['user_id'])
$smarty->caching = true;
$smarty->cache_lifetime = 3600;
//@mkdir('img/' . $_SERVER['SERVER_NAME'] . '/ava', 0700);
class modClass
{
static function setStat($id)
{
$see = \DBmysql::getValue("SELECT `see` FROM `content` WHERE `id`=? LIMIT 1", $id);
if (!$id) {
$see++;
\DBmysql::set("UPDATE `content` SET `see`=? WHERE `id`=? LIMIT 1", array($see, $id));
}
}
static function redirect301($value)
{
if ($_GET['id'] != $value) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: /' . $value . '.html');
}
}
static function migration($content){
//1) Получаем картинки
$images=\DB::getAll("SELECT `filename`, `tip` FROM `img` WHERE `content_type`=? AND `content_id`=?", ['page', $content['row']['id']]);
$content['json']['images']=$images;
$content['json']['original_id']=$content['row']['id'];
$sql="SELECT `id` FROM `content` WHERE `json` LIKE '%\"original_id\":" . $content['row']['id'] . "%' AND `content_type`='page' LIMIT 1";
// echo $sql;
//Проверяем наличие в БД
$id=\DBmysql::getValue($sql);
if (!$id){
\DBmysql::add("INSERT INTO `content` (`title`, `txt`, `status`, `category`, `site`, `json`, `content_type`, `time`, `user_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [
$content['row']['title'], $content['row']['txt'], 1, $content['row']['category'], $content['row']['site'], \core::j($content['json']),
'page', $content['row']['t'], $content['row']['user_id'] ]);
}
}
}
/* ----------------------------------------------------------------------
11.02.2023
Получаем страницу
---------------------------------------------------------------------- */
$content = \core::getContent($_GET['id'], 'page');
if ($content['row']['id']){
//Пишем в sitemap
$link=($content['json']['alias'])?'https://' . $_SERVER['SERVER_NAME'] . '/' . $content['json']['alias'] . '.html':'https://' . $_SERVER['SERVER_NAME'] . '/page/' . $content['row']['id'];
$sm_id=\DBmysql::getValue("SELECT `id` FROM `sitemap` WHERE `link`=? AND `site`=? LIMIT 1", array($link, $_SERVER['SERVER_NAME']));
if (!$sm_id)\DBmysql::add("INSERT INTO `sitemap` (`link`, `status`, `t`, `site`) VALUES (?,?,?,?)", array($link, 1, time(), $_SERVER['SERVER_NAME']));
$content['row']['img']=\core::getFirstImg($content['row']['id'], 'page', $w=350, $h=350);
}else{
header("HTTP/1.1 404 Not Found");
$content['row']['title']="Страница не существует";
}
$smarty->assign('page', $content['row']);
$smarty->assign('json', $content['json']);
//print_r($content);
//modClass::migration($content);
if ($content['row']['id']==$_GET['id'] && $content['json']['alias']){
header('HTTP/1.1 301 Moved Permanently');
header('Location: /' . $content['json']['alias'] . '.html');
}
/* ----------------------------------------------------------------------
11.02.2023
Получаем данные о пользователе
---------------------------------------------------------------------- */
$autor = \DBmysql::getAll("SELECT * FROM `users` WHERE `id`=? LIMIT 1", $content['row']['user_id']);
//print_r($autor);
if ($autor[0]['dostup'] == 'a')
$autor[0]['dostup'] = 'Администратор сайта';
$smarty->assign('autor', $autor);
/* ----------------------------------------------------------------------
14.02.2023
Пишем статистику
---------------------------------------------------------------------- */
$smarty->assign('see', modClass::setStat($content['row']['id']));
$smarty->assign('childrenPage', \core::getContentList(40, 'page', 2));
?>