2025-06-16 18:28:08 +05:00

92 lines
3.6 KiB
PHP
Executable File

<?php
/*
Вызывается из ядра, отображает список дочерних категорий товаров или изображений
Входные данные:
$content_type='tovar'|'page',
$parent=0, - вышестоящая категория
$limit=12, - лимит записей
$needImg=true, - искать для категорий изображения в таблице img
$fixImg=true - если истина - при отсутствии изображения - ставит картинку товара из этой категории
$sort = 'title' - сортировка
*/
//echo $parent
$sql = "SELECT * FROM `" . $content_type . "` WHERE `category`=? AND `status`=1 AND `site`=? ORDER BY `" . $sort . "` LIMIT ?";
$sql2 = "SELECT * FROM `" . $content_type . "` WHERE `category`='" . $parent . "' AND `status`=1 AND `site`='" . $_SERVER['SERVER_NAME'] . "' ORDER BY `" . $sort . "` LIMIT " . $limit;
//echo $sql2;
$categoryList = \DB::getAll($sql, array($parent, $_SERVER['SERVER_NAME'], $limit));
//echo $categoryList;
if ($needImg == true) {
$count = count($categoryList);
for ($i = 0; $i < $count; $i++) {
$img = \DB::getRow(
"SELECT `filename`, `tip` FROM `img` WHERE `content_type`=? AND `content_id`=? AND `site`=? LIMIT 1",
array(
$content_type,
$categoryList[$i]['id'],
$_SERVER['SERVER_NAME']
)
);
if (!$img) {
$categoryList[$i]['imgN'] = 'https://static.yurecnt.ru/img/nofoto/no_skin.png';
//Пробуем найти скачанную картинку
//echo self::genpassword();
if ($categoryList[$i]['img']) {
mkdir('img/' . $_SERVER['SERVER_NAME'] . '/' . $content_type . '/' . $categoryList[$i]['id'], 0700);
$tip = pathinfo($categoryList[$i]['img'], PATHINFO_EXTENSION);
$fm = core::genpassword(30);
$prefix = mb_substr($categoryList[$i]['img'], 0, 4);
if ($prefix == 'http') {//Сосем картинку диллера (временный костыль)
exec('wget -O img/' . $_SERVER['SERVER_NAME'] . '/' . $content_type . '/' . $categoryList[$i]['id'] . '/' . $fm . '.' . $tip . ' ' . $categoryList[$i]['img']);
} else {
if (file_exists($categoryList[$i]['img']))
copy($categoryList[$i]['img'], 'img/' . $_SERVER['SERVER_NAME'] . '/' . $content_type . '/' . $categoryList[$i]['id'] . '/' . $fm . '.' . $tip);
}
if (file_exists('img/' . $_SERVER['SERVER_NAME'] . '/' . $content_type . '/' . $categoryList[$i]['id'] . '/' . $fm . '.' . $tip)) {
\DB::add(
"INSERT INTO `img` (`filename`, `tip`, `content_id`, `content_type`, `site`) VALUES(?,?,?,?,?)",
array(
$fm,
$tip,
$categoryList[$i]['id'],
$content_type,
$_SERVER['SERVER_NAME']
)
);
}
}
} else {
if (file_exists('cache/img/' . $img['filename'] . '-' . IMG_PRV_W . '-' . IMG_PRV_H . '.webp')) {
$categoryList[$i]['imgN'] = '/cache/img/' . $img['filename'] . '-' . IMG_PRV_W . '-' . IMG_PRV_H . '.webp';
} else {
$categoryList[$i]['imgN'] = '/img/' . $img['filename'] . '-' . IMG_PRV_W . '-' . IMG_PRV_H . '-1';
}
}
}
}
?>