<?php
die('stub');
require_once('local.inc.php');
require_once('functions.inc.php');
require_once('curl.inc.php');
//set_time_limit(1*60*60); //1 hour
ignore_user_abort(true);
$body='
<div id="flush">
</div>
<SCRIPT>
d = document.getElementById("flush");
d.innerHTML = "";
</SCRIPT>';
main('Scanner', $body);
trq();
//get welcome page
$URL='http://auto.ru';
$cnt = url_get($URL);
if($cnt==''){
exit;
}
//vendors
//<div class="cell-1"><a href="/acura/">ACURA</a></div>
preg_match_all('|<div class="cell-1"><a href="([^"]+)">([^<]+)</a>|Ui',$cnt,$reg,PREG_SET_ORDER);
$founded = false;
foreach($reg as $serie){
if($serie[2]=='PEUGEOT')
die;
$founded = true;
if(!$founded)
continue;
//get vendor id
$sql='select id from v_vendor where name="'.$mysql->escape($serie[2]).'"';
$ret = $mysql->query($sql);
if($ret)
{
$vendor_id = $ret[0]['id'];
}
else
{
$sql='insert into v_vendor set name="'.$mysql->escape($serie[2]).'"';
$vendor_id = $mysql->query($sql);
}
mkdir('../img/car/'.$vendor_id, 0777);
//series
$cnt = url_get('http://auto.ru'.$serie[1]);
//<td><div class="cell-1"><a href=([^>^"]+)>([^<]+)</a></div></td>
preg_match_all('|<td><div class="cell-1"><a href=(http://catalog.auto.ru/catalog/cars/[^>^"]+)>([^<]+)</a></div></td>|Ui',$cnt,$reg2,PREG_SET_ORDER);
foreach($reg2 as $subserie){
//subserie
//<td align=left valign=bottom>
//<b>11113 Ока</b>
//</td>
//<td align=right valign="top">
//<a href="/catalog/cars/model/1889.html"><img src="http://s.auto.ru/catalog_v3/images/2/small/24f73d70.jpg" title="Еще фотографии" border=0>
$cnt = url_get($subserie[1]);
preg_match_all('/<td align=left valign=bottom>[\t\s\n]+<b>([^<]+)<\/b>[\t\s\n]+<\/td>[\t\s\n]+<td align=right valign="top">.+((<a href="[^"]+"><img src="([^"]+)" title="Еще фотографии" border=0>)|(Добавить отзыв))/Uis',$cnt,$reg3,PREG_SET_ORDER);
foreach($reg3 as $subsubserie){
$sql='select id from v_serie where vendor_id="'.$vendor_id.'" and name="'.$mysql->escape($subsubserie[1]).'"';
if(!$mysql->query($sql)){
//insert
$sql='insert into v_serie set vendor_id="'.$vendor_id.'", name="'.$mysql->escape($subsubserie[1]).'"';
$serie_id = $mysql->query($sql);
$filename='';
if(count($subsubserie) == 5)
{
//get image
$img = url_get($subsubserie[4]);
if($img)
{
$filename = $serie_id.'.jpg';
$f=fopen('../img/car/'.$vendor_id.'/'.$filename, "w+");
if($f){
fwrite($f, $img);
fclose($f);
}
$sql='update v_serie set image="'.$filename.'" where id="'.$serie_id.'"';
$mysql->query($sql);
}
//get image2
$fileurl = str_replace('small/', '', $subsubserie[4]);
$img2 = url_get($fileurl);
if($img2)
{
$filename2 = str_replace('.jpg', '_.jpg', $filename);
$f=fopen('../img/car/'.$vendor_id.'/'.$filename2, "w+");
if($f){
fwrite($f, $img2);
fclose($f);
}
}
}
}
}
}
}
?>