<?php
include 'head.php';
include 'conf.php';
include 'CurlClass.php';
$conf = new CurlClassConfig;
$conf->userAgent = 'Android';
$conf->referer = 'http://go.mail.ru/mimages';
$conf->timeout = 10;
$conf->cookiesFile = 'cookies.txt';
$conf->followLocations = FALSE;
#$conf->proxy = '';
$curl = new CurlClass;
$sf = htmlspecialchars($_GET['sf']);
$q = htmlspecialchars($_GET['q']);
$ajoyib_ru = htmlspecialchars($_GET['ajoyib_ru']);
switch($ajoyib_ru){
default:
echo '<title>Rasm qidiruv</title>';
echo '<div class="phdr">Rasm qidiruv</div>
<div class="menu">
<form action="'.$papka.'" method="get">
<input type="hidden" name="ajoyib_ru" value="images"/>
So`rovni kiriting:<br/>
<input type="q" name="q"/><br/>
<input type="hidden" name="sf" value="24"/>
<input type="submit" value="Izlash"/>
</form>
</div>';
include 'foot.php';
break; 

case 'images':
$file = $curl->getPage ($conf, 'http://go.mail.ru/mimages?mobile_result=Smartphone&'.$_SERVER['QUERY_STRING'].''); 
$sf = htmlspecialchars($_GET['sf']);
$q = htmlspecialchars($_GET['q']);
preg_match_all('#"imUrl": "(.*)"#sU', $file, $pics);
echo '<title>Qidiruvlar '.$q.' '.$sf.' rasmlar topildi</title>';
if($pics[1]){
echo ''.$div.''.$q.' rasmlari '.$sf.' ta topildi.</div>';
for($i = 0; $i<count($pics[1]); $i++)
{
echo ''.$div2.'<a href="'.$papka.'images/'.base64_encode($pics[1][$i]).'"><img src="'.$papka.'images/'.base64_encode($pics[1][$i]).'" width="'.$wid.'" height="'.$heid.'" /></a></div>';
}

if($sf==24){
$q=str_replace(' ', '+', $q);
$pages = '<a href="'.$papka.'?ajoyib_ru=images&q='.$q.'&sf='.($sf + 24).'">Oldinga &rarr;</a>';
}else{
$q=str_replace(' ', '+', $q);
$pages = '<a href="'.$papka.'?ajoyib_ru=images&q='.$q.'&sf='.($sf - 24).'">&larr; Orqaga</a> <span><b>'.($sf + 0).'</b></span><a href="'.$papka.'?ajoyib_ru=images&q='.$q.'&sf='.($sf + 24).'">Oldinga &rarr;</a>';
}
echo ''.$div2.'<div class="navi"><center>'.$pages.'</center></div></div>';
}else{
echo '<div class="menu">Hech narsa topilmadi!</div>';
}

include 'foot.php';
exit;
break; 
}