147 lines
5.2 KiB
PHP
147 lines
5.2 KiB
PHP
|
<?php
|
||
|
ini_set('display_errors', 0);
|
||
|
$_SERVER['SERVER_NAME'] = 'v.yurecnt.ru';
|
||
|
require_once('/home/cloud/core/set/v.yurecnt.ru.php');
|
||
|
//print_r($db);
|
||
|
|
||
|
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 ekr ($text) { // ФУНКЦИЯ очистки кода
|
||
|
|
||
|
$old1 = array("(", ')', "-", " ");#Ищем вредное ">",, "<"
|
||
|
|
||
|
$new1 = array("", '', "", "");#Меняем на полезное">", , "<"
|
||
|
|
||
|
$text = str_replace($old1, $new1, $text);#Собсно сама замена =)
|
||
|
|
||
|
return $text; }#
|
||
|
|
||
|
|
||
|
$htmls = DB::getAll("SELECT `html` FROM `st` WHERE `html` IS NOT NULL AND `link` LIKE 'https://stroykabaza.ru%'");
|
||
|
|
||
|
|
||
|
for ($i = 0; $i < count($htmls); $i++) {
|
||
|
$a = html_to_obj($htmls[$i]['html']);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
print_r($a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][3]['children'][0]['children'][0]['children'][0]['children'][1]['html']);
|
||
|
|
||
|
$email=$a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][3]['children'][0]['children'][0]['children'][0]['children'][1]['html'];
|
||
|
|
||
|
|
||
|
if (!$email)
|
||
|
$www=$a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][3]['children'][0]['children'][0]['children'][0]['href'];
|
||
|
else
|
||
|
$www=$a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][4]['children'][0]['children'][0]['children'][0]['href'];
|
||
|
|
||
|
//номер телефона:
|
||
|
$tel = $a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][1]['children'][0]['children'][0]['children'][0]['children'][1]['html'];
|
||
|
|
||
|
|
||
|
//виды работ:
|
||
|
//print_r($a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//Имя
|
||
|
$txt = $a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['html'];
|
||
|
|
||
|
|
||
|
//Находим адрес
|
||
|
$m = $a['children'][1]['children'][8]['children'][3]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'];
|
||
|
//print_r($m);
|
||
|
$count = count($m) - 1;
|
||
|
$adres = mb_split(', ', $m[$count]['html']);
|
||
|
$cityname = $adres[0];
|
||
|
$streetname = $adres[1];
|
||
|
$dom = $adres[2];
|
||
|
|
||
|
$org_id = DB::getValue("SELECT `id` FROM `org` WHERE `txt`=? AND `streetname`=? AND `cityname`=? LIMIT 1", array($txt, $streetname, $cityname));
|
||
|
if (!$org_id && $txt) {
|
||
|
if ($www=="Наш сайт")$www='';
|
||
|
$aaa = array($txt, $streetname, $cityname, $dom, ekr($tel), $www, $email);
|
||
|
print_r($aaa);
|
||
|
$org_id=DB::add("INSERT INTO `org` (`txt`, `streetname`, `cityname`, `dom`, `tel`, `site`, `email`) VALUES (?, ?, ?, ?, ?, ?, ?)", $aaa);
|
||
|
}
|
||
|
|
||
|
|
||
|
//виды работ:
|
||
|
if ($email && $www)$vr = $a['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][6]['children'][0]['children'][0]['children'];
|
||
|
print_r($vr);
|
||
|
//Наполняем справочник видами работ
|
||
|
for ($j = 0; $j < count($vr); $j++) {
|
||
|
if ($vr[$j]['href']) {
|
||
|
$vid_r = trim($vr[$j]['html']);
|
||
|
//Узнаем есть ли в БД, если есть хорошо, если нет - добавляем
|
||
|
$id = DB::getValue("SELECT `id` FROM `vid_deyat` WHERE `txt`=? LIMIT 1", $vid_r);
|
||
|
if (!$id && $vid_r)$id=DB::add("INSERT INTO `vid_deyat` (`txt`) VALUES (?)", $vid_r);
|
||
|
|
||
|
//Пишем в таблицу связей:
|
||
|
|
||
|
$svayz_id=DB::getValue("SELECT `id` FROM `org_vr` WHERE `org`=? AND `vid_deyat`=? LIMIT 1", array($org_id, $id));
|
||
|
if (!$svayz_id)DB::add("INSERT INTO `org_vr` (`org`, `vid_deyat`) VALUES (?, ?)", array($org_id, $id));
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
unset($a);
|
||
|
unset($txt);
|
||
|
unset($www);
|
||
|
unset($email);
|
||
|
unset($txt);
|
||
|
unset($adres);
|
||
|
unset($streetname);
|
||
|
unset($cityname);
|
||
|
unset($dom);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
?>
|