prokat/api/modules/tovar_show/111/pre_tavrnt.ru.php
2025-06-16 18:28:08 +05:00

84 lines
3.7 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);
function html_to_obj($html)
{
$dom = new DOMDocument();
@$dom->loadHTML(mb_convert_encoding(@$html, 'HTML-ENTITIES', 'UTF-8'));
return element_to_obj($dom->documentElement);
}
function element_to_obj($element)
{
@$obj = array("tag" => @$element->tagName);
foreach (@$element->attributes as $attribute) {
$obj[$attribute->name] = $attribute->value;
}
foreach ($element->childNodes as $subElement) {
if ($subElement->nodeType == XML_TEXT_NODE) {
$obj["html"] = $subElement->wholeText;
} else {
$obj["children"][] = element_to_obj($subElement);
}
}
return $obj;
}
function getImgHidrootvet($link)
{
require_once '/www/core/api/soft/phpQuery-master/phpQuery/phpQuery.php';
$html = \core::get_page($link)['html'];
$a = html_to_obj($html)['children'][1]['children'][1]['children'][1]['children'][1]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'];
$mainimg = $a[0]['children'][0]['href'];
if (!$mainimg) $mainimg=$a[0]['children'][0]['children'][0]['srcset'];
$r = pathinfo($mainimg, PATHINFO_EXTENSION);
$s=mb_stripos($r,'@');
if ($s!=0)$r=mb_substr($r,0,$s);
mkdir('img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $_GET['id'], 0777);
$filename = \core::genpassword(30);
exec("wget " . $mainimg . " -O img/tavrnt.ru/tovar/" . $_GET['id'] . '/' . $filename . "." . $r);
if (file_exists("img/tavrnt.ru/tovar/" . $_GET['id'] . '/' . $filename . "." . $r))
\DB::add("INSERT INTO `img` (`content_id`, `content_type`, `site`, `filename`, `tip`) VALUES (?, ?, ?, ?, ?)", [$_GET['id'], 'tovar', $_SERVER['SERVER_NAME'], $filename, $r]);
else
\DB::set("DELETE FROM `img` WHERE `content_id`=? AND `content_type`=? AND `site`=?", array( $res['tovar']['id'], 'tovar', $_SERVER['SERVER_NAME'] ) );
}
$idimg = \DB::getValue("SELECT `filename` FROM `img` WHERE `content_id`=? AND `site`=? AND `content_type`=?", [$_GET['id'], 'tavrnt.ru', 'tovar']);
if (!$idimg) {
$row = \DB::getRow("SELECT `partner`, `donor` FROM `tovar` WHERE `id`=?", $_GET['id']);
if ($row['partner'] == 'hydrootvet')
getImgHidrootvet($row['donor']);
}
//if ()
//Сосем страницу с донора:
/*$pizdesh = \DB::getRow("SELECT `partner`, `donor`, `code` FROM `tovar` WHERE `id`=? LIMIT 1", $_GET['id']);
$h=\DB::getValue("SELECT `id` FROM `tovar_har` WHERE `tovar_id`=? LIMIT 1", $_GET['id']);
if ($pizdesh['partner'] == 'hydrootvet' && !$h) {
require_once '/www/core/api/soft/phpQuery-master/phpQuery/phpQuery.php';
$html = \core::get_page($pizdesh['donor'])['html'];
$doc = phpQuery::newDocument($html);
$entry = $doc->find('.product__property-name');
foreach ($entry as $row) $data['list'][] = pq($row)->text();
$data['list2'] = [];
$entry = $doc->find('.product__property-value');
foreach ($entry as $row) $data['list2'][] = trim(pq($row)->text());
$count = count($data['list']);
for ($i; $i < $count; $i++) {
$idhs = \DB::getValue("SELECT `id` FROM `tovar_har_sp` WHERE `txt`=? LIMIT 1", $data['list'][$i]);
if (!$idhs)
$idhs = \DB::add("INSERT INTO `tovar_har_sp` (`txt`) VALUES (?)", $data['list'][$i]);
$idh = \DB::getValue("SELECT `id` FROM `tovar_har` WHERE `txt`=? AND `tovar_id`=? AND `tovar_har_sp_id`=? LIMIT 1", [$data['list2'][$i], $_GET['id'], $idhs]);
if (!$idh)
$idhs = \DB::add("INSERT INTO `tovar_har` (`txt`, `tovar_id`, `tovar_har_sp_id`) VALUES (?,?,?)", [$data['list2'][$i], $_GET['id'], $idhs]);
}
}*/
?>