170 lines
6.4 KiB
PHP
Executable File
170 lines
6.4 KiB
PHP
Executable File
<?php
|
|
ini_set('display_errors', 0);
|
|
$_SERVER['SERVER_NAME'] = 'tk-ligat.ru';
|
|
|
|
|
|
require_once('/home/cloud/core/set/tk-ligat.ru.php');
|
|
|
|
//print_r($db);
|
|
|
|
require_once('/home/cloud/core/api/php/db.php');
|
|
require_once('/home/cloud/core/api/php/json.php');
|
|
|
|
|
|
|
|
|
|
//define("SITE", "https://www.bober-stroy.ru");
|
|
|
|
|
|
function html_to_obj($html)
|
|
{
|
|
$dom = new DOMDocument();
|
|
// $dom->loadHTML($html);
|
|
@$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;
|
|
}
|
|
// https://www.bober-stroy.ru//stroymaterialy/izolyatsionnye_materialy_1/paklya_dzhut_mezhventsovyy_uteplitel_1/
|
|
|
|
/* ищет str в txt если находит, возвращает единичку */
|
|
function findtxt($txt, $str)
|
|
{
|
|
$pos1 = stripos($txt, $str);
|
|
if ($pos1 === false)
|
|
return 0;
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
|
|
function add_link($html)
|
|
{
|
|
preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $html, $matches);
|
|
$urls = $matches[1]; // Берём то место, где сама ссылка (благодаря группирующим скобкам в регулярном выражении)
|
|
/* Выводим все ссылки */
|
|
for ($j = 0; $j < count($urls); $j++) {
|
|
$link = $urls[$j];
|
|
if (findtxt($link, 'https://www.deznet.ru') == 0)
|
|
$link = 'https://www.deznet.ru' . leopak($link);
|
|
$id = DB::getValue("SELECT `id` FROM `sm2` WHERE `link` LIKE '%" . $link . "' LIMIT 1");
|
|
if (!$id)
|
|
DB::add("INSERT INTO `sm2` (`link`, `status`) VALUES (?, ?)", array($link, 1));
|
|
}
|
|
}
|
|
|
|
function generate_password($number)
|
|
{
|
|
$arr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
|
|
$pass = "";
|
|
for ($i = 0; $i < $number; $i++) {
|
|
$index = rand(0, count($arr) - 1);
|
|
$pass .= $arr[$index];
|
|
}
|
|
return $pass;
|
|
}
|
|
|
|
function setTovarCategory($massiv)
|
|
{
|
|
$idp = 0;
|
|
for ($i = 0; $i < count($massiv); $i++) {
|
|
unset($id);
|
|
if ($massiv[$i]['children'][1]['children'][0]['html'])
|
|
$cat = $massiv[$i]['children'][1]['children'][0]['html'];
|
|
//echo $cat . "\n";
|
|
if ($cat) {
|
|
$id = DB::getValue("SELECT `id` FROM `tovar_category` WHERE `title`='" . $cat . "' LIMIT 1");
|
|
if (!$id) {
|
|
// echo "no\n";
|
|
$idp = DB::add("INSERT INTO `tovar_category` (`title`, `category`) VALUES (?, ?)", array($cat, $idp));
|
|
}
|
|
}
|
|
}
|
|
$id = DB::getValue("SELECT `id` FROM `tovar_category` WHERE `title`='" . $cat . "' LIMIT 1");
|
|
//echo $id;
|
|
return $id;
|
|
}
|
|
|
|
|
|
$LinkList = DB::getAll("SELECT `id`, `link`, `html` FROM `donorLinks` WHERE `status`=0 AND `html` IS NOT NULL AND LINK LIKE 'https://market.leopak.ru/products/%-%' ORDER BY RAND() LIMIT 7000");
|
|
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($LinkList); $i++) {
|
|
$html = gzuncompress(base64_decode($LinkList[$i]['html']));
|
|
|
|
//$html=file_get_contents('9022-01');
|
|
$a = html_to_obj($html);
|
|
|
|
$category = setTovarCategory($a['children'][1]['children'][0]['children'][13]['children'][1]['children'][0]['children'][0]['children'][2]['children'][1]['children'][0]['children']);
|
|
|
|
$title = $a['children'][1]['children'][0]['children'][13]['children'][1]['children'][0]['children'][0]['children'][2]['children'][0]['children'][0]['children'][0]['html'];
|
|
$artikul = trim($a['children'][1]['children'][0]['children'][13]['children'][1]['children'][0]['children'][0]['children'][2]['children'][2]['children'][0]['children'][0]['children'][1]['children'][1]['html']);
|
|
$cena = $a['children'][1]['children'][0]['children'][13]['children'][1]['children'][0]['children'][0]['children'][2]['children'][3]['children'][1]['children'][0]['children'][0]['children'][3]['children'][0]['children'][0]['children'][0]['content'];
|
|
$img = $a['children'][1]['children'][0]['children'][13]['children'][1]['children'][0]['children'][0]['children'][2]['children'][3]['children'][0]['children'][0]['children'][0]['children'][0]['href'];
|
|
if ($cena && $title) {
|
|
|
|
$cena = $cena * 1.5;
|
|
$tovar_id=DB::getValue("SELECT `id` FROM `tovar` WHERE `title`=? AND `artikul`=?", array($title, $artikul));
|
|
if ($tovar_id){//Есть, обновляем инфу - цену, картинку, категорию
|
|
|
|
DB::set("DELETE FROM `tovar_img` WHERE `tovar_id`=?", $tovar_id);
|
|
$fn=generate_password(30);
|
|
//$dst='/home/cloud/core/img/tk-ligat.ru/tovar' . $fn . '.jpg';
|
|
//$src=$img;
|
|
exec("wget " . $img . " -O /home/cloud/core/img/tk-ligat.ru/tovar/" . $fn . ".jpg");
|
|
DB::add("INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?)", array($fn, $tovar_id));
|
|
|
|
|
|
DB::set("UPDATE `tovar` SET `status`=1, `category`=? WHERE `id`=?", array($category, $tovar_id));
|
|
|
|
|
|
|
|
}else{//Добавляем
|
|
$tovar_id=DB::add("INSERT INTO `tovar` (`title`, `artikul`, `donor`, `status`, `category`) VALUES (?, ?, ?, 1, ?)", array($title, $artikul, $LinkList[$i]['link'], $category));
|
|
//Загружаем картинку:
|
|
$fn=generate_password(30);
|
|
//$dst='/home/cloud/core/img/tk-ligat.ru/tovar' . $fn . '.jpg';
|
|
//$src=$img;
|
|
exec("wget " . $img . " -O /home/cloud/core/img/tk-ligat.ru/tovar/" . $fn . ".jpg");
|
|
DB::add("INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?)", array($fn, $tovar_id));
|
|
|
|
//Сверяем цену, если не совпадает - обновляем
|
|
|
|
// $cena_id=DB::getValue("SELECT `id` FROM `tovar_price_history` WHERE `tovar_id`=? AND `cena`=? AND `status`=1 ORDER BY `t` DESC LIMIT 1", array($tovar_id, $cena));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ищем товар, если не находим, добавляем
|
|
|
|
|
|
|
|
}
|
|
|
|
DB::set("UPDATE `donorLinks` SET `status`=2 WHERE `id`=?", $LinkList[$i]['id']);
|
|
|
|
}
|
|
|
|
?>
|