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 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` FROM `tovar` WHERE `status`=? AND `ctovar`=? LIMIT " . $start . ', ' . $limit, [1, $_GET['id']]); } else { $array = \DBmysql::getAll("SELECT `id`, `title`, `json`, `cena` FROM `tovar` WHERE `status`=? AND `ctovar`=? LIMIT " . $limit, [1, $_GET['id']]); } $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); file_put_contents($cache, $a); } return $array; } } $limit = 12; //Получаем количество всех товаров этой категории $total = \DBmysql::getAll("SELECT COUNT(*) FROM `tovar` WHERE `status`=? AND `ctovar`=?", [1, $_GET['id']])[0]['COUNT(*)']; $amt = ceil($total / $limit); $smarty->assign('amt', $amt); $smarty->assign('tovar', modClass::getTovar($limit, true)); //} ?>