All pastes #2049492 Raw Edit

Anonymous

public text v1 · immutable
#2049492 ·published 2011-04-22 22:01 UTC
rendered paste body
<?
$next = 'http://www.funpic.hu/en/';
while(true){
	$page = LoadHTML(GetHTTP($next));
	
	foreach($page->query('//ul[@class="gallery"]/li/a/img') as $pic){
		$title = $pic->getAttribute('alt');
		$imsrc = str_replace('/pictures/100/', '/pictures/original/', $pic->getAttribute('src'));
		
		$image = @imagecreatefromstring(GetHTTP($imsrc, 'http://www.funpic.hu/en/')); // fontos! hotlinkelés ellen védnek, kell referrer.
		if ($image == null) continue;
		
		$image = CropLogo($image, 18);
		
		/*
			$title cím, opcionális
			$image kép, tárold valahova így: imagejpeg($image, 'pics/'.$id.'.jpg')
		*/
	}
	
	$next = 'http://www.funpic.hu'.$page->query('//li[@class="nextPage"]/a/@href')->item(0)->nodeValue;
	
	if(!$next){
		break;
	}
}

function GetHTTP($url, $referer = ''){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_REFERER, $referer);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.35 Version/10.70');
	$http = curl_exec($ch);
	curl_close($ch);
	
	return $http;
}

function LoadHTML($src){
	libxml_use_internal_errors(true); 
	libxml_clear_errors();
	
	if(($enc = mb_detect_encoding($src)) != 'UTF-8'){
		$src = mb_convert_encoding($src, 'UTF-8', $enc);
	}
	
	$html = new DOMDocument();
	$html->loadHtml('<?xml encoding="UTF-8">'.$src);
	
	return new DOMXPath($html); 
}

function CropLogo($img, $crop){
	$w = imagesx($img);
	$h = imagesy($img) - $crop;
	$im2 = imagecreatetruecolor($w, $h);
	
	imagecopy($im2, $img, 0, 0, 0, 0, $w, $h);
	
	return $im2;
}
?>