caching = true; $smarty->cache_lifetime = 86400; } class modClass { static $content = ''; static $user = ''; 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() { $cache ='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/tovar_' . $_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 > 259200) unlink($cache); } else { $row = \DBmysql::getRow("SELECT * FROM `tovar` WHERE `id`=? LIMIT 1", $_GET['id']); self::$content = $row; self::$content['massiv'] = \core::j($row['json']); self::$content['arr'] = self::$content['massiv']; $j = \core::j(self::$content); $a = \core::zip($j); if (strlen($a)>16) file_put_contents($cache, $a); } } /* ---------------------------------------------------------------------- 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; } /* ---------------------------------------------------------------------- 13.04.2025 Получаем хлебные крошки ---------------------------------------------------------------------- */ static function getBreadcrumb() { $id=self::$content['ctovar']; $i=0; while ($id!=0) { $row=\DBmysql::getRow("SELECT `id`, `cat`, `title` FROM `ctovar` WHERE `id`=?", $id); $array[$i]['id']=$row['id']; $array[$i]['cat']=$row['cat']; $array[$i]['title']=$row['title']; $id=$array[$i]['cat']; $i++; } return array_reverse($array); } static function getCatInfo($id){ $array=DBmysql::getRow("SELECT `id`, `title`, `json` FROM `ctovar` WHERE `id`=? LIMIT 1", $id); $array['arr']=core::j($array['json']); return $array; } static function getHistory(){ $array=\DBmysql::getAll("SELECT `id`, `title`, `json`, `cena` FROM `tovar` WHERE `id` IN(SELECT `content_id` FROM `history` WHERE `user_id`=? AND `content_type`='tovar') AND `status`=1 LIMIT 8", self::$user); $c = count($array); for ($i = 0; $i < $c; $i++) { $m = \core::j($array[$i]['json']); $array[$i]['img'] = $m['images'][0]; } return $array; } static function getRndThisCat(){ $r=rand(10, 99); $cache ='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/random_' . self::$content['ctovar'] . '_' . $r . '.json';// 'api/modules/content/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '.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 { $array=\DBmysql::getAll("SELECT `id`, `title`, `json`, `cena` FROM `tovar` WHERE `ctovar` =? AND `status`=1 ORDER BY RAND() LIMIT 8", self::$content['ctovar']); $c = count($array); for ($i = 0; $i < $c; $i++) { $m = \core::j($array[$i]['json']); $array[$i]['img'] = $m['images'][0]; } $a = \core::zip(\core::j($array)); if (strlen($a)>16) file_put_contents($cache, $a); } return $array; } static function getPriceArenda(){ return DBmysql::getRow("SELECT * FROM `cenaarendy` WHERE `tovar_id`=? LIMIT 1", $_GET['id']); } } modClass::$user=($_SESSION['user_id'])?$_SESSION['user_id']:session_id(); modClass::getContent(); if (modClass::$content['status']==0)header("HTTP/1.1 404 Not Found"); $smarty->assign('history', modClass::getHistory()); $smarty->assign('priceArenda', modClass::getPriceArenda()); $smarty->assign('getRndThisCat', modClass::getRndThisCat()); $smarty->assign('content', modClass::$content); //print_r(modClass::$content); $smarty->assign('comments', modClass::getComments()); //Инфо этой категории $smarty->assign('catInfo', modClass::getCatInfo(modClass::$content['ctovar'])); $url='https://' . $_SERVER['SERVER_NAME'] . '/tovar/' . $_GET['id']; if (modClass::$content['title']&&modClass::$content['status']==1){ //Пишем в сайтмап $id=\DBmysql::getValue("SELECT `id` FROM `sitemap` WHERE `link`=? LIMIT 1", $url); if (!$id)\DBmysql::add("INSERT INTO `sitemap` (`link`, `t`, `site`, `status`) VALUES (?,?,?,?)", [$url, time(), $_SERVER['SERVER_NAME'], 1]); //Пишем в историю unset($id); $id=\DBmysql::getValue("SELECT `id` FROM `history` WHERE `content_type`=? AND `content_id`=? AND `user_id`=? LIMIT 1", ['tovar', $_GET['id'], modClass::$user]); if (!$id)\DBmysql::add("INSERT INTO `history` (`content_type`, `content_id`, `t`, `user_id`) VALUES (?,?,?,?)", ['tovar', $_GET['id'], time(), modClass::$user]); } if (modClass::$content['status']==0) DBmysql::set("DELETE FROM `sitemap` WHERE `link`=? LIMIT 1", $url); $smarty->assign('getBreadcrumb', modClass::getBreadcrumb()); ?>