".$url."";
## GET DATA
$s = file_get_contents($url);
//echo $s;
## GZIP DECODE
if ($go=='gzip') {
$s = $server=='144.76.203.145' ? gzinflate(substr($s,10,-8)) :
gzuncompress(preg_replace("/^\\x1f\\x8b\\x08\\x00\\x00\\x00\\x00\\x00/","",$s));
}
$arr = xml2array($s); //die(var_export($arr));
return $arr['aj'][0]['row'];
}
function xml2array($text) { ## CUSTOM XML PARSER
$reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
preg_match_all($reg_exp, $text, $match);
foreach ($match[1] as $key=>$val) {
if ( preg_match($reg_exp, $match[2][$key]) ) {
$array[$val][] = xml2array($match[2][$key]);
} else {
$array[$val] = $match[2][$key];
}
} return $array;
}
## START PAGE
echo "
";
##### 4. LOT BY ID #############
if(isset($_GET['id'])) {
$arr = aj_get("select * from main where id='".$_GET['id']."'");
echo '
';
foreach (explode('#',$arr[0]['IMAGES']) as $key=>$img) {
## AUCTION SHEET CAN BE BIG. OTHER PHOTOS SET TO 320PX
$img = $key==0 ? $img : $img.'&w=320';
echo "";
}
echo '
';
foreach($arr[0] as $key => $val) {
if ($key=='IMAGES'||$key=='AVG_STRING'||$key=='TIME') {continue;}
if ($key=='INFO' && is_array($val)) {$val=var_export($val,true);} ## if INFO array
echo "
$key
$val
\n";
}
echo '
';
}
##### 3. LIST OF CARS ##########
elseif (isset($_GET['model'])) {
## PAGINATION
$num_arr = aj_get("select count(*) from main where model_name='".$_GET['model']."'");
$lots=$num_arr[0]['TAG0'];
echo "
LOTS: $lots
";
for($i=1;$i<=ceil($lots/20);$i++) {
echo "".$i." ";
} echo '';
## SELECT 20 ROWS
$offset = ((int)$_GET['page']-1)*20;
$arr = aj_get("select * from main where model_name='".$_GET['model']."'
order by year desc, mileage desc
limit ".($offset<0?0:$offset).",20");
echo '
'.implode("
\n",array_keys($arr[0])).'
';
foreach($arr as $v) {
list($img1,$img2,$tmp)=explode('#',$v['IMAGES']);
$v['IMAGES'] = ""; // &h=50 can change to &w=320
$v['ID'] = ''.$v['ID'].'';
echo '
'.implode('
',$v)."
\n";
}
echo '
';
}
##### 2. MODELS ################
elseif (isset($_GET['vendor'])) {
$arr = aj_get("select model_name from main where marka_name='".$_GET['vendor']."' group by model_name order by model_name");
foreach($arr as $v) {
echo ''.$v['MODEL_NAME']." \n";
}
}
##### 1. VENDORS ###############
else {
$arr = aj_get("select marka_id,marka_name from main group by marka_id order by marka_name ASC");
foreach($arr as $v) {
echo ''.$v['MARKA_NAME']." \n"; // or use $v['MARKA_ID']
}
}
## END PAGE
$mtime = explode(' ',microtime());
die('
'.round($mtime[1]+$mtime[0]-$start_time,3).' sec
');
##### CACHE ##### change aj_get("select..") to aj_get_cached("select..")
function aj_get_cached($sql,$minutes=30) { ## 30 for main; 1440 for stats;
$file=md5($sql); ## create /aj_cache writable
$dir=dirname(__FILE__).'/aj_cache/'.substr($file,-2);
$f = $dir.'/'.$file;
if (file_exists($f) && (filemtime($f)>(time()-60*$minutes))) {
return unserialize(file_get_contents($f));
} else {
$arr = aj_get($sql);
if (!is_dir($dir)) {mkdir($dir);}
file_put_contents($f,serialize($arr));
return $arr;
}
}