core/parcer/virtual/nix.php

104 lines
2.4 KiB
PHP
Raw Normal View History

2023-02-25 22:58:56 +05:00
<?php
ini_set( 'display_errors', 0 );
$_SERVER['SERVER_NAME']='v.yurecnt.ru';
require_once('/home/cloud/core/set/v.yurecnt.ru.php');
require_once('/home/cloud/core/api/php/db.php');
require_once('/home/cloud/core/api/php/json.php');
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;
}
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;}
$a=file_get_contents('nix.xml');
#print_r(html_to_obj($a['children'][0]['children'][0])); 337854
$b=html_to_obj($a);
//print_r($b['children'][0]['children'][0]['children'][0]['children'][5]['children']);
$tovar_massiv=$b['children'][0]['children'][0]['children'][0]['children'][5]['children'];
for ($i=0; $i<count($tovar_massiv); $i++){
$artikul=$tovar_massiv[$i]['id'];
$id_tovar=DB::getValue("SELECT `id` FROM `tovar` WHERE `artikul`=?", $artikul);
if ($id_tovar){
//Находим и удаляем картинки.....
DB::set("DELETE FROM `tovar_img` WHERE `tovar_id`=?", $id_tovar);
$f_pic=$tovar_massiv[$i]['children'];
for ($j=0; $j<count($f_pic); $j++){
$tip=$f_pic[$j]['tag'];
if ($tip=='picture'){
$link[$i][$j]=$f_pic[$j]['html'];
$filename[$i][$j] = generate_password(30);
exec("wget " . $link[$i][$j] . " -O /home/cloud/core/img/o.yurecnt.ru/tovar/" . $filename[$i][$j] . ".jpg");
DB::add("INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?)", array( $filename[$i][$j], $id_tovar ) );
}
}
}
//echo $artikul;
}
?>