Автор:
Jack Dan
Добрый день! Раньше код работал, а потом перестал. Когда понадобилась выгрузка на infoline, снова пришлось обратиться к коду.
infoline прислали требование к xml, прикрепляю его (infoline_xml.rtf). Вот код php файла по адресу https://мой_сайт/infoline/parser/yandex_infoline_convert.php:
<?php
include(dirname(__FILE__).'/func.php');
@unlink(dirname(__FILE__).'/tmp/log.html');
header("Content-type: text/html; charset=utf-8");
error_reporting (E_ALL &~ E_DEPRECATED &~E_NOTICE);
ini_set("pcre.backtrack_limit", "99999999999");
comment('<html lang="ru"><head><meta charset="utf-8">');
//mb_internal_encoding("UTF-8");
$test = 9999999; // кол-во для теста, чтобы выгружало все поставьте большое число любое, 9999999
$filename = 'infoline_export.xml';
$phone1 = '89065808308';
$phone2 = '';
$email = 'infoline@dvm-vrn.ru';
$infoline = 1; // затем поставьте значения соответствующее значению поля infoline в БД.
//print_R($cats); die();
$in_file = 'yandexrealty.xml';
$in_file = 'https://gm36.ru/yandexrealty';
//$p = get_page($in_file);
$p = file_get_contents($in_file);
$to = '<?xml version="1.0" encoding="UTF-8"?>
<realty-feed>
<generation-date>'.date('Y-m-d+H:i').'</generation-date>';
preg_match_all('/<offer.*<\/offer>/isU', $p, $offers, $o);
//print_r($offers[0]); print_r($offers[1]);print_r($offers[110]);print_r($offers[1110]); die();
//unset($offers[0]);
$ii = 0;
$q = db_query("select * from `re_data` where `infoline` = '".$infoline."' and `active` = '1' ");
while($qr = mysql_fetch_assoc($q))
{
$ids[] = $qr['id'];
$data[$qr['id']] = $qr;
}
//print_r($ids); die();
$temp = file(dirname(__FILE__).'/replaces.txt');
unset($temp[0]);
foreach($temp as $tt)
{ $t = explode('~~', $tt);
$replaces[trim($t[0])]=trim($t[1]);}
$bath = array(0=>'совмещенный',1=>'раздельный',2=>'два и больше');
$balc = array(0=>'выбрать',1=>'Лоджия',2=>'Отсутствует', 3=>'Есть');
//print_r($replaces); die();
//echo $st.'___'.$end; die();
foreach($offers as $it)
{ unset($res);
//comment($ii.'__'.$st.'__'.$end);
preg_match('/internal\-id="([^"]+)"/iU', $it[0], $t);
$res['id'] = $t[1];
if(!in_array($res['id'], $ids)) comment($res['id']. ' - не выгружаем.');
else{
preg_match('/<category>(.*)<\/category>/iU', $it[0], $t);
$res['category'] = $t[1];
preg_match('/<rooms>(.*)<\/rooms>/iU', $it[0], $t);
$res['rooms'] = $t[1];
preg_match('/<area>[^<>]*<value>([^<>]+)</isU', $it[0], $t);
$res['area'] = $t[1];
preg_match('/<living-space>[^<>]*<value>([^<>]+)</isU', $it[0], $t);
$res['living-space'] = $t[1];
preg_match('/<kitchen-space>[^<>]*<value>([^<>]+)</isU', $it[0], $t);
$res['kitchen-space'] = $t[1];
$res['floors-total'] = $data[$res['id']]['floor_count'];
$res['floor'] = $data[$res['id']]['floor'];
preg_match('/<country>(.*)<\/country>/iU', $it[0], $t);
$res['country'] = $t[1];
preg_match('/<region>(.*)<\/region>/iU', $it[0], $t);
$res['region'] = $t[1];
preg_match('/<locality\-name>(.*)<\/locality\-name>/iU', $it[0], $t);
$res['locality-name'] = $t[1];
preg_match('/<sub\-locality\-name>(.*)</iU', $it[0], $t);
$res['sub-locality-name'] = $t[1];
preg_match('/<address>(.*)<\/address>/iU', $it[0], $t);
$res['address'] = $t[1];
$t = explode(',', $res['address']);
$res['street'] = trim($t[0]);
$res['house'] = trim($t[1]);
preg_match('/<latitude>(.*)<\/latitude>/iU', $it[0], $t);
$res['latitude'] = $t[1];
preg_match('/<longitude>(.*)<\/longitude>/iU', $it[0], $t);
$res['longitude'] = $t[1];
preg_match('/<price>[^<>]*<value>(.*)</isU', $it[0], $t);
$res['price'] = $t[1];
preg_match('/<currency>(.*)<\/currency>/iU', $it[0], $t);
$res['currency'] = $t[1];
//print_r($res);print_r($it); die();
if(preg_match_all('/<picture>([^<>]+)<\/picture>/iU', $it[0], $temp, $o))
{ foreach($temp as $t)
{
$res['image_str_ar'][] = '<Image url="'.$t[1].'" />';
}
$res['image_str'] = '<Images>'.implode("\n", $res['image_str_ar']).'</Images>'; }
foreach($cats as $k=>$v)
{
if($res['type_id'] == '' and preg_match('/'.str_replace("/", "\/", $k).'/iU', mb_strtolower($res['name'], 'UTF-8')))
{
//comment($c);
$res['type_id'] = $v;
$res['type_key'] = $k;
}
//comment($k);
}
if($res['type_id'] == '') $res['type_id'] = '11-623';
// print_r($cats); print_r($res);print_r($it); die();
$res['name'] = preg_replace('/\&.{2,6};/iU', '', htmlentities($res['name'], null, 'utf-8'));
$res['name_to'] = mb_substr($res['name'], 0, 50, 'UTF-8');
if($replaces[$data[$res['id']]['walls']] != '') $res['mat'] = $replaces[$data[$res['id']]['walls']];
else $res['mat']= '';
$q = db_query("select `developer_id` from `re_complex` where `complex_id` = '".$data[$res['id']]['complex_id']."'");
while($qr = mysql_fetch_assoc($q))
{ $qq = db_query("select `name` from `re_developer` where `developer_id` = '".$qr['developer_id']."'");
while($qqr = mysql_fetch_assoc($qq)) $res['dev'] = $qqr['name']; }
$q = db_query("select `fio` from `re_user` where `user_id` = '".$data[$res['id']]['user_id']."'");
while($qr = mysql_fetch_assoc($q)) $res['user'] = $qr['fio'];
$q = db_query("select `name` from `re_district` where `id` = '".$data[$res['id']]['district_id']."'");
while($qr = mysql_fetch_assoc($q)) $res['district'] = $qr['name'];
$res['image_ar'] = unserialize($data[$res['id']]['image']);
foreach($res['image_ar'] as $im) $res['images'][] = '<foto>http://gm36.ru/img/data/'.$im['normal'].'</foto>';
$res['im'] = implode("\n", $res['images']);
$data[$res['id']]['text'] = '<![CDATA['.$data[$res['id']]['text'].']]>';
//$res['name_to']=$res['name'];
// print_r($res);print_r($it);print_r($data[$res['id']]);print_r($replaces); die();
$to = $to.'<offer internal-id="'.$res['id'].'" types="open">
<apptype>1</apptype>
<folder>2</folder>
<obj>'.$res['category'].'</obj>
<rooms>'.$res['rooms'].'</rooms>
<areas>
<total>'.$res['area'].'</total>
<living>'.$res['living-space'].'</living>
<kitchen>'.$res['kitchen-space'].'</kitchen>
<lot></lot>
</areas>
<floor>'.$res['floor'].'</floor>
<floors>'.$res['floors-total'].'</floors>
<mat>'.$res['mat'].'</mat>
<housetype>Современная</housetype>
<klass>Современная</klass>
<zastroishik>'.$res['dev'].'</zastroishik>
<declaration></declaration>
<location>
<country>'.$res['country'].'</country>
<region>'.$res['region'].'</region>
<raion></raion>
<gorod>'.$res['locality-name'].'</gorod>
<selo></selo>
<street>'.$res['street'].'</street>
<district>'.$res['district'].'</district>
<place></place>
<numhouse>'.$res['house'].'</numhouse>
<latitude>'.$res['latitude'].'</latitude>
<longitude>'.$res['longitude'].'</longitude>
</location>
<price>
<value>'.$res['price'].'</value>
<currency>'.$res['currency'].'</currency>
<unit>все</unit>
<period></period>
<ipoteka></ipoteka>
<ischp></ischp>
<obmen></obmen>
</price>
<agent internal-id="'.$res['user_id'].'">
<name>'.$res['user'] .'</name>
<phone>'.$phone1.'</phone>
<phone>'.$phone2.'</phone>
<mails>'.$email.'</mails>
<skype></skype>
<icq></icq>
</agent>
<bathroom>'.$bath[$data[$res['id']]['bathroom']].'</bathroom>
<balcon>'.$balc[$data[$res['id']]['balcony']].'</balcon>
<comment>'.$data[$res['id']]['text'].'</comment>
<fotos>
'.$res['im'].'
</fotos>
</offer>
';
if($ii >= $test){ $to = $to.'</realty-feed>';
file_put_contents(dirname(__FILE__).'/tmp/'.$filename, $to);
echo "<a href='tmp/".$filename."'>FILE</a>";
die(); }
}
$ii++;}
$to = $to.'</realty-feed>';
file_put_contents(dirname(__FILE__).'/tmp/'.$filename, $to);
echo "<a href='tmp/".$filename."'>FILE</a>";
comment('DONE');
?>
По запуску получаю только дату (смотреть картинку).
Что не так с кодом?
infoline_xml.rtf