core/st/1.php

151 lines
5.9 KiB
PHP
Raw Normal View History

2023-07-12 20:02:20 +05:00
<?php
ini_set('display_errors', 0);
require_once('db.php');
DB::$dsn = 'mysql:dbname=yurec_st;host=mysql.yurec.myjino.ru';
DB::$user = '038517005_st';
DB::$pass = 'YurecNT1984!##';
function telclean ($text) { // ФУНКЦИЯ очистки кода
$old1 = array("(", ')', "-", " ");
$new1 = array("", '', "", "");
$text = str_replace($old1, $new1, $text);
return $text; }
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 insert_cagegory($html)
{
//print_r($html);
//print_r($html['children'][1]['children'][9]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][5]['children'][0]['children'][0]['children']);
$ok=0;
$cats = $html['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'];
$check=trim($html['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'][1]['html']);
print_r($check);
if ($check!='Предоставляемые услуги: '){
$cats = $html['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'];
unset( $check);
}else{$ok=1;}
$check=trim($html['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'][1]['html']);
print_r($check);
if ($check!='Предоставляемые услуги: ' AND $ok!=1){
echo 'не то';
}
print_r($cats);
for ($i = 0; $i < count($cats); $i++) {
if ($cats[$i]['href']) {
$txt=$cats[$i]['html'];
echo $txt;
if ($txt){
$id=DB::getValue("SELECT `id` FROM `vid_deyat` WHERE `txt`=? LIMIT 1", $txt);
if (!$id){
DB::add("INSERT INTO `vid_deyat` (`txt`) VALUES (?)", $txt);
$cat[$i]=$txt;
}
}
}
}
return $cat;
}
function org_data($massiv, $cats){
$m['txt']=$massiv['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'];
// if (!$m['txt'])$m['txt']=$massiv['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'];
//print_r($m['txt']=$massiv['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]);
$m['tel']=telclean($massiv['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']);
$adres=explode(", ", $massiv['children'][1]['children'][8]['children'][3]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][3]['html']);
if (!$adres[0])$adres=explode(", ", $massiv['children'][1]['children'][8]['children'][3]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][2]['html']);
$m['cityname']=$adres[0];
$m['streetname']=$adres[1];
$m['dom']=$adres[2];
//print_r($massiv['children'][1]['children'][8]['children'][3]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][3]['html']);
if ($massiv['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']){
$m['site']=$massiv['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'];
}
$id=DB::getValue("SELECT `id` FROM `org` WHERE `txt`=? LIMIT 1", $m['txt']);
//if (!$id)$id=DB::add("")
print_r($m);
}
$htmls = DB::getAll("SELECT `html`, `id` FROM `st` WHERE `status`=2 AND `id`=175 LIMIT 10");
for ($i = 0; $i < count($htmls); $i++) {
$html=html_to_obj($htmls[$i]['html']);
$cats=insert_cagegory($html);
org_data($html, $cats);
unset($html);
}
?>