259 lines
11 KiB
PHP
Executable File
259 lines
11 KiB
PHP
Executable File
<?php
|
|
|
|
ini_set('display_errors', 0);
|
|
|
|
if (!@$_SESSION['user_id']) {
|
|
$smarty->caching = true;
|
|
$smarty->cache_lifetime = 86400;
|
|
}
|
|
/*require_once 'api/modules/content/dbl.php';
|
|
DBL::$db = 'api/modules/content/db/' . $_SERVER['SERVER_NAME'] . '.db';
|
|
DBL::set("CREATE TABLE IF NOT EXISTS `content` (
|
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`cache` TEXT,
|
|
`tip` TEXT,
|
|
`time` TEXT)");
|
|
*/
|
|
|
|
class modClass
|
|
{
|
|
static $content = '';
|
|
static $alias = '';
|
|
|
|
static function getListCategory()
|
|
{
|
|
|
|
$list = \DBmysql::getAll("SELECT `id`, `title` FROM `content` WHERE `content_type`=? AND `status`=? ORDER BY `title`", ['tovar_category', 1]);
|
|
|
|
}
|
|
static function getContent()
|
|
{
|
|
$url = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
|
|
//echo $url;
|
|
|
|
if (\core::findtxt($url, '.html'))self::$alias=1;else self::$alias=0;
|
|
|
|
//echo $alias;
|
|
//print_r($_GET);
|
|
//echo "SELECT * FROM `content` WHERE `json` LIKE '%" . $_GET['id'] . "%' LIMIT 1";
|
|
$cache ='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/content_' . $_GET['id'] . '.json';// 'api/modules/content/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '.json';
|
|
if (file_exists($cache)) {
|
|
$text = file_get_contents($cache);
|
|
self::$content = \core::j(\core::unzip($text));
|
|
//Чистим кеш через пять дней
|
|
$r = time() - filemtime($cache);
|
|
if ($r > 432000)
|
|
unlink($cache);
|
|
} else {
|
|
|
|
$row = \DBmysql::getRow("SELECT * FROM `content` WHERE `id`=? LIMIT 1", $_GET['id']);
|
|
|
|
// print_r($row);
|
|
self::$content = $row;
|
|
self::$content['massiv'] = \core::j($row['json']);
|
|
$j = \core::j(self::$content);
|
|
$a = \core::zip($j);
|
|
if (strlen($a)>16) file_put_contents($cache, $a);
|
|
}
|
|
|
|
|
|
}
|
|
static function findChildren()
|
|
{
|
|
\DBmysql::set("UPDATE `content` SET `category`=? WHERE `json` LIKE '%\"parent_category\":" . modClass::$content['massiv']['original_id'] . ",%' AND `category`<>? AND `fix`=?", [$_GET['id'], $_GET['id'], 0]);
|
|
}
|
|
|
|
|
|
static function getTovar($limit, $mini = false, $sort = 'title')
|
|
{
|
|
|
|
$cache = '/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '_' . $_POST['page'] . '_tovar_list.json';
|
|
if (file_exists($cache)) {
|
|
$text = file_get_contents($cache);
|
|
$array = \core::j(\core::unzip($text));
|
|
//Чистим кеш через пять дней
|
|
$r = time() - filemtime($cache);
|
|
if ($r > 432000)
|
|
unlink($cache);
|
|
} else {
|
|
if ($mini == true) {
|
|
$page = intval(@$_POST['page']);
|
|
$page = (empty($page)) ? 1 : $page;
|
|
$start = ($page != 1) ? $page * $limit - $limit : 0;
|
|
$array = \DBmysql::getAll("SELECT `id`, `title`, `json`, `cena`, `content_type` FROM `content` WHERE `status`=? AND `site`=? AND `category`=? AND `content_type`=? LIMIT " . $start . ', ' . $limit, [1, $_SERVER['SERVER_NAME'], $_GET['id'], 'tovar']);
|
|
} else {
|
|
$array = \DBmysql::getAll("SELECT `id`, `title`, `json`, `cena`, `content_type` FROM `content` WHERE `status`=? AND `site`=? AND `category`=? AND `content_type`=? LIMIT " . $limit, [1, $_SERVER['SERVER_NAME'], $_GET['id'], 'tovar']);
|
|
}
|
|
|
|
$c = count($array);
|
|
for ($i = 0; $i < $c; $i++) {
|
|
$m = \core::j($array[$i]['json']);
|
|
$array[$i]['img'] = $m['images'][0];
|
|
$array[$i]['artikul'] = ($m['artikul']) ? $m['artikul'] : $m['code'];
|
|
}
|
|
$j = \core::j($array);
|
|
$a = \core::zip($j);
|
|
if (strlen($a)>16) file_put_contents($cache, $a);
|
|
|
|
}
|
|
|
|
//print_r( $array);
|
|
return $array;
|
|
}
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
02.02.2025
|
|
Получаем список комментариев
|
|
---------------------------------------------------------------------- */
|
|
static function getComments()
|
|
{
|
|
$array = \DBmysql::getAll("SELECT `id`, `txt`, `time`, `json`, `user_id` FROM `content` WHERE `content_type`=? AND `status`=? AND `category`=? ORDER BY `id` DESC", ['comment', 1, self::$content['id']]);
|
|
$c = count($array);
|
|
for ($i = 0; $i < $c; $i++) {
|
|
$array[$i]['fio'] = \core::j($array[$i]['json'])['fio'];
|
|
$array2 = \DBmysql::getAll("SELECT `id`, `txt`, `time`, `json`, `user_id` FROM `content` WHERE `content_type`=? AND `status`=? AND `category`=? ORDER BY `id` DESC", ['comment', 1, $array[$i]['id']]);
|
|
$c2 = count($array2);
|
|
for ($j = 0; $j < $c2; $j++) {
|
|
$array2[$j]['fio'] = \core::j($array2[$j]['json'])['fio'];
|
|
}
|
|
|
|
$array[$i]['otvet'] = $array2;
|
|
}
|
|
return $array;
|
|
}
|
|
|
|
static function img($array)
|
|
{
|
|
|
|
//print_r($array);
|
|
include_once 'api/php/thumbs-master/thumbs.php';
|
|
$wm = 'skin/' . $_SERVER['SERVER_NAME'] . '/img/wm.png';
|
|
@mkdir('img/' . $_SERVER['SERVER_NAME'] . '/content/' . self::$content['id']);
|
|
$c = count($array);
|
|
for ($i = 0; $i < $c; $i++) {
|
|
$source = 'img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . self::$content['massiv']['original_id'] . '/' . $array[$i]['filename'] . '.' . $array[$i]['tip'];
|
|
$target = 'img/' . $_SERVER['SERVER_NAME'] . '/content/' . self::$content['id'] . '/' . $array[$i]['filename'] . '.' . $array[$i]['tip'];
|
|
$target_mini = 'img/' . $_SERVER['SERVER_NAME'] . '/content/' . self::$content['id'] . '/' . $array[$i]['filename'] . "_" . IMG_PRV_W . "_" . IMG_PRV_H . '.' . $array[$i]['tip'];
|
|
copy($source, $target);
|
|
$image = new Thumbs($target);
|
|
$image->thumb(IMG_PRV_W, IMG_PRV_H);
|
|
$image->saveJPG($target_mini);
|
|
unset($image);
|
|
$image = new Thumbs($target_mini);
|
|
if (file_exists($wm))
|
|
$image->watermark($wm, 'bottom-right');
|
|
$image->saveWEBP('img/' . $_SERVER['SERVER_NAME'] . '/content/' . self::$content['id'] . '/' . $array[$i]['filename'] . "_" . IMG_PRV_W . "_" . IMG_PRV_H . '.webp', 50);
|
|
$img[$i] = 'img/' . $_SERVER['SERVER_NAME'] . '/content/' . self::$content['id'] . '/' . $array[$i]['filename'] . "_" . IMG_PRV_W . "_" . IMG_PRV_H . '.webp';
|
|
}
|
|
self::$content['massiv']['images'] = $img;
|
|
\DBmysql::set("UPDATE `content` SET `json`=? WHERE `id`=? LIMIT 1", [\core::j(self::$content['massiv']), self::$content['id']]);
|
|
return $img;
|
|
}
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
02.02.2025
|
|
Получаем список комментариев
|
|
---------------------------------------------------------------------- */
|
|
static function getChildPages()
|
|
{
|
|
|
|
$cache='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/chPages' . $_GET['id'] . '.json';
|
|
if (file_exists($cache)){
|
|
$text = file_get_contents($cache);
|
|
$root=\core::j(\core::unzip($text));
|
|
//Чистим кеш через сутки
|
|
$r=time()-filemtime($cache);
|
|
if ($r>86400)unlink($cache);
|
|
}else{
|
|
$root=\DBmysql::getAll("SELECT `id`, `title`, `time`, `json` FROM `content` WHERE `content_type`='page' AND `site`=? AND `category`=? AND `status`=? ORDER BY `id` DESC", [
|
|
$_SERVER['SERVER_NAME'], $_GET['id'], 1] );
|
|
$c=count($root);
|
|
for($i=0; $i<$c;$i++) {
|
|
$root[$i]['img']=\core::j($root[$i]['json'])['images'][0];
|
|
}
|
|
$j=\core::zip(\core::j($root));
|
|
file_put_contents($cache, $j);
|
|
}
|
|
return $root;
|
|
}
|
|
}
|
|
|
|
modClass::getContent();
|
|
|
|
$limit = 12;
|
|
|
|
//print_r(modClass::$content);
|
|
//Если это категория товара - пробуем найти дочерние категории и отсортировать
|
|
if (modClass::$content['content_type'] == 'tovar_category') {
|
|
//Сортируем дочерние категории и товары
|
|
modClass::findChildren();
|
|
//Получаем дочерние категории
|
|
require_once('api/modules/content/tovar_category_get_children_category.php');
|
|
//Получаем товары
|
|
|
|
|
|
//Получаем количество всех товаров этой категории
|
|
$total = \DBmysql::getAll("SELECT COUNT(*) FROM `content` WHERE `status`=? AND `site`=? AND `category`=? AND `content_type`=?", [1, $_SERVER['SERVER_NAME'], $_GET['id'], 'tovar'])[0]['COUNT(*)'];
|
|
$amt = ceil($total / $limit);
|
|
$smarty->assign('amt', $amt);
|
|
$tovar = ($_POST['mod'] == 'mini') ? modClass::getTovar($limit, true) : $tovar = modClass::getTovar($limit);
|
|
$smarty->assign('tovar', $tovar);
|
|
|
|
//print_r(\DBmysql::getAll("SELECT `id`, `title` FROM `content` WHERE `content_type`=? AND `status`=? AND `site`=? ORDER BY `title`", ['tovar_category', 1, $_SERVER['SERVER_NAME']]));
|
|
if ($_SESSION['dostup'] == 'a') {
|
|
$smarty->assign('all_cats', \DBmysql::getAll("SELECT `id`, `title` FROM `content` WHERE `content_type`=? AND `status`=? AND `site`=? ORDER BY `title`", ['tovar_category', 1, $_SERVER['SERVER_NAME']]));
|
|
$smarty->assign('duble_cats', \DBmysql::getAll("SELECT `id`, `title`, `status` FROM `content` WHERE `content_type`=? AND `site`=? AND `id`<>? AND `title` LIKE '%" . modClass::$content['title'] . "%' ORDER BY `title`", ['tovar_category', $_SERVER['SERVER_NAME'], modClass::$content['id']]));
|
|
}
|
|
}
|
|
|
|
|
|
if (modClass::$content['content_type'] == 'tovar') {
|
|
// echo 1;
|
|
header('HTTP/1.1 301 Moved Permanently');
|
|
header('Location: /tovar/' . $_GET['id']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (modClass::$content['content_type'] == 'page') {
|
|
$smarty->assign('page', modClass::$content);
|
|
//Получаем топ-страницы
|
|
require_once('api/modules/content/page_get_top_pages.php');
|
|
|
|
$smarty->assign('files', \DBmysql::getAll("SELECT `title`, `txt` FROM `content` WHERE `content_type`=? AND `site`=? AND `status`=? AND `category`=? ORDER BY `title`", ['file', $_SERVER['SERVER_NAME'], 1, modClass::$content['id']]));
|
|
$smarty->assign('parent', \DBmysql::getRow("SELECT `id`, `title` FROM `content` WHERE `id`=? LIMIT 1", modClass::$content['category']));
|
|
if (modClass::$alias==0)
|
|
$smarty->assign('childPages', modClass::getChildPages());
|
|
|
|
/*if (modClass::$content['massiv']['images'])
|
|
$smarty->assign('images', modClass::$content['massiv']['images']);
|
|
else
|
|
if (modClass::$content['massiv']['img'])
|
|
$smarty->assign('images', modClass::img(modClass::$content['massiv']['img']));*/
|
|
//print_r(modClass::getChildPages());
|
|
|
|
|
|
}
|
|
|
|
//if ()
|
|
|
|
//print_r(modClass::$content);
|
|
$smarty->assign('content', modClass::$content);
|
|
$smarty->assign('comments', modClass::getComments());
|
|
//$smarty->assign('Breadcrumb', \core::getBreadcrumb('content', modClass::$content['content_type']));
|
|
|
|
//print_r(\core::getBreadcrumb('content', modClass::$content['content_type']));
|
|
if (modClass::$content['id']) {
|
|
|
|
\DBmysql::set("UPDATE `content` SET `see`=" . modClass::$content['see']++ . " WHERE `id`=?", modClass::$content['id']);
|
|
//echo "UPDATE `content` SET `see`=" . modClass::$content['see']++ . " WHERE `id`=" . modClass::$content['id'];
|
|
}
|
|
|
|
?>
|