<?php
###########
# Для xwab.ru
# by wapoleg
# icq: 3628900
###########
$folder = 'http://kazfan.ru/photo_izdeu'; //Путь к скрипту
$height = '48'; // ширина превьюшек
$widtht = '48'; // длина превьюшек

include 'CurlClass.php';
$conf = new CurlClassConfig;
$conf->userAgent = $_SERVER['USER_AGENT'];
$conf->referer = 'http://rap.ru';
$conf->timeout = 10;
$conf->cookiesFile = 'cookies.txt';
$conf->followLocations = FALSE;
#$conf->proxy = '';
$curl = new CurlClass;

$p = $_GET['p'];
$q = $_GET['q'];
$url = $_GET['url'];
$do = $_GET['do'];
switch($do){
default:
$title[1] = 'Поиск картинок';
include '../inc/head.php';
echo '
<div class="menu1">
<form action="" method="get">
<input type="hidden" name="do" value="search"/>
Введите запрос:<br/>
<input type="text" name="q"/><br/>
<input type="submit" value="Искать"/>
</form>
</div>
';
break;
case 'get':
$pic = base64_decode($_GET['url']);
$size = getimagesize($pic);
if ($size['mime'] == "image/jpeg") $src = ImageCreateFromJpeg($pic);
if ($size['mime'] == "image/gif") $src = ImageCreateFromGif($pic);
if ($size['mime'] == "image/png") $src = ImageCreateFromPng($pic);
$w = $size[0];
$h = $size[1];
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: image/gif");
ImageGif($src);
break;
case 'search':
$file = $curl->getPage ($conf, 'http://m.images.yandex.ru/search?p='.$p.'&text='.$q);
preg_match_all('#<b><a href="/search\?(.*)img_url=(.*)&(.*)"><img src="(.*)" width="48" height="48" alt=""/></a></b>#sU', $file, $r);
$title[1] = 'Поиск: '.$q;
include '../inc/head.php';
if($r[2]){
for($i = 0; $i<count($r[1]); $i++)
{
echo '<div class="l"><a href="'.$folder.'?do=load&amp;q='.$q.'&amp;url='.$r[2][$i].'"><img src="'.$folder.'?do=get&amp;url='.base64_encode($r[4][$i]).'" alt="*" width="'.$width.'" height="'.$height.'"/></a><br/></div>';
}
if($p==0){
$page = '<a class="button" href="'.$folder.'?do=search&amp;q='.$q.'&amp;p='.($p + 1).'">Далее &rarr;</a><br/>';
}else{
$page = '<a class="button" href="'.$folder.'?do=search&amp;q='.$q.'&amp;p='.($p - 1).'">&larr; Назад</a><b>['.($p + 1).']</b><a class="button" href="'.$folder.'?do=search&amp;q='.$q.'&amp;p='.($p + 1).'">Далее &rarr;</a><br/>';
}
echo '<div class="menu1">'.$page.'</div>';
}else{
echo '<div class="err">Не найдено</div>';
}
break;
case 'load':
header('Location: '.$folder.'?do=get&url='.base64_encode($url));
exit;
break;
}
include '../inc/foot.php';