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

218 lines
9.5 KiB
PHP
Executable File
Raw 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);
$smarty->caching = true;
$smarty->cache_lifetime = 3600;
class modClass
{
/* ----------------------------------------------------------------------
14.03.2025
Получаем новости
---------------------------------------------------------------------- */
static function getNews()
{
$cache='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/main_mod_news.json';
if (file_exists($cache)){
$text = file_get_contents($cache);
$news=\core::j(\core::unzip($text));
//Чистим кеш через сутки
$r=time()-filemtime($cache);
if ($r>86400)unlink($cache);
}else{
$news=\DBmysql::getAll("SELECT `id`, `title`, `txt`, `json`, `time`, `user_id` FROM `content` WHERE `status`=? AND (`category`=? OR `tonews`=1) ORDER BY `time` DESC LIMIT 12", [1, IDNEWS]);
$c=count($news);
for($i=0; $i<$c;$i++) $news[$i]['img']=\core::j($news[$i]['json'])['images'][0];
$j=\core::zip(\core::j($news));
file_put_contents($cache, $j);
}
return $news;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем то что подешевело
---------------------------------------------------------------------- */
static function getBonusPrice($limit = 12)
{
$array = \DBmysql::getAll("SELECT `title`, `id`, `cena`, `oldcena` FROM `tovar` WHERE `status`=1 AND `cena`<`oldcena` ORDER BY RAND() LIMIT " . $limit);
$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'];
}
return $array;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем товары в соответствии с сортировкой и лимитом
---------------------------------------------------------------------- */
static function getTovar($limit = 12, $sort = 'id')
{
$array=\DBmysql::getAll("SELECT tovar.title, tovar.id, cenaarendy.ch4 as cena, tovar.json FROM tovar JOIN cenaarendy ON tovar.id=cenaarendy.tovar_id WHERE `status`=1 ORDER BY `" . $sort . "` DESC LIMIT " . $limit);
for ($i = 0; $i < count($array); $i++) $array[$i]['images'] = \core::j($array[$i]['json'])['images'][0];
return $array;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем категории товаров
---------------------------------------------------------------------- */
static function getCategory($limit = 12)
{
$array=\DBmysql::getAll("SELECT `title`, `id`, `json` FROM `ctovar` WHERE `status`=1 AND `cat`=? ORDER BY `title` LIMIT " . $limit, 0);
for ($i = 0; $i < count($array); $i++) $array[$i]['images'] = \core::j($array[$i]['json'])['images'][0];
return $array;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем мета-теги
---------------------------------------------------------------------- */
static function getMeta()
{
$meta = \DB::getAll("SELECT `txt` FROM `keywords` WHERE `content_type`=? AND `site`=?", ['main', $_SERVER['SERVER_NAME']]);
$count = count($meta);
for ($i = 0; $i < $count; $i++)
@$txt = @$txt . $meta[$i]['txt'] . ', ';
return substr(@$txt, 0, -2);
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем сезонные товары
---------------------------------------------------------------------- */
static function tovarSezons()
{
$mes = date('n');
$str = '"' . $mes . '":"1"';
$tovar_sezon = \DBmysql::getAll("SELECT `title`, `id`, `cena`, `linkimg` FROM `tovar` WHERE `status`=1 AND `sezon` LIKE '%" . $str . "%' ORDER BY RAND() LIMIT 30");
for ($i = 0; $i < count($tovar_sezon); $i++) {
$tovar_sezon[$i]['img'] = \DB::getValue("SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1", $tovar_sezon[$i]['id']);
if ($tovar_sezon[$i]['img'])
$tovar_sezon[$i]['img'] = '/img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $tovar_sezon[$i]['img'] . '.jpg';
else
$tovar_sezon[$i]['img'] = $tovar_sezon[$i]['linkimg'];
}
$massiv['mes'] = $mes;
$massiv['tovar_sezon'] = $tovar_sezon;
return $massiv;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем корневые категории
---------------------------------------------------------------------- */
static function getNullCategory($limit = 12)
{
return \DB::getAll("SELECT `id`, `title`, `img` FROM `ctovar` WHERE `category`=0 LIMIT ?", $limit);
}
static function getLostPages($limit=12)
{
$lastBlogs = \DBmysql::getAll(
"SELECT `id`, `title`, `json` FROM `content` WHERE `site`=? AND `status`=? AND `content_type`=? AND `category`<>3931 ORDER BY `id` DESC LIMIT " . $limit,
[$_SERVER['SERVER_NAME'], 1, 'page']
);
$c=count($lastBlogs);
for ($i = 0; $i < $c; $i++){
$lastBlogs[$i]['massiv']=\core::j($lastBlogs[$i]['json']);
$lastBlogs[$i]['img'] = $lastBlogs[$i]['massiv']['images'][0];
}
return $lastBlogs;
}
/* ----------------------------------------------------------------------
05.01.2024
Получаем корневые категории
---------------------------------------------------------------------- */
static function getNullCategoryPages()
{
$cache='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/listpages.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`, `img` FROM `content` WHERE `content_type`='page' AND `site`=? AND `status`=? AND `id`<>? AND `showOnRight`=? ORDER BY `sort`, `title`", [$_SERVER['SERVER_NAME'], 1, 108590, 1] );
$c=count($root);
for ($i=0; $i<$c; $i++)
$root[$i]['sub']=\DBmysql::getAll("SELECT `id`, `title`, `img` FROM `content` WHERE `content_type`='page' AND `site`=? AND `category`=? AND `status`=? AND `showOnRight`=? ORDER BY `sort`, `title`", [$_SERVER['SERVER_NAME'], $root[$i]['id'], 1, 1] );
$j=\core::zip(\core::j($root));
file_put_contents($cache, $j);
}
return $root;
}
/* ----------------------------------------------------------------------
30.03.2024
Получаем слайды
---------------------------------------------------------------------- */
static function getSliders($category=NULL)
{
$list=\DBmysql::getAll("SELECT `id`, `title`, `txt`, `json` FROM `content` WHERE `status`=? AND `site`=? AND `content_type`=? AND `category`=? ORDER BY `sort`",[
1, $_SERVER['SERVER_NAME'], 'slider', $category
]);
$c=count($list);
for ($i=0; $i<$c; $i++){
$arr=\core::j($list[$i]['json']);
$list[$i]['link']=$arr['link'];
$list[$i]['img']=$arr['fm'];
}
return $list;
}
/* ----------------------------------------------------------------------
30.03.2024
Получаем категории сатов
---------------------------------------------------------------------- */
static function getslideCategory()
{
$list=\DBmysql::getAll("SELECT `id`, `title` FROM `content` WHERE `status`=? AND `content_type`=? ORDER BY `sort`",[
1, 'slideCategory'
]);
$c=count($list);
for($i=0; $i<$c; $i++) $list[$i]['sliders']=self::getSliders($list[$i]['id']);
return $list;
}
}
/* ----------------------------------------------------------------------
14.03.2025
Получаем новости
---------------------------------------------------------------------- */
$smarty->assign('news', modClass::getNews());
/* ----------------------------------------------------------------------
30.03.2024
Получаем слайды
---------------------------------------------------------------------- */
$smarty->assign('sliders', modClass::getSliders());
$smarty->assign('lostTovar', modClass::getTovar());
$smarty->assign('cTovar', modClass::getCategory(24));
$smarty->assign('slideCategory', modClass::getslideCategory());
$smarty->assign('listpages', modClass::getNullCategoryPages());
/* ----------------------------------------------------------------------
28.12.2022
Получаем теги
---------------------------------------------------------------------- */
$smarty->assign('lostPages', modClass::getLostPages(361));
//print_r(\core::getContentList($limit=40, $content_type='page', $sort=1, $content_category=0));
#$smarty->assign('keywordsSQL', modClass::getMeta());
$smarty->assign('childrenPage', \core::getContentList($limit=140, $content_type='page', $sort=1, $content_category=0));
?>