FILE: linkchecker.php

[code]<?php
/*****
 *  Copyright 2008 Hoshang Sadiq, Zeryl
 *
 *  For more information on this script, visit:
 *  http://zeryl.net/linkchecker
 *
 *  This file is part of Zeryl Filesharing Link Checker (Z.F.L.C.)
 *
 *  Z.F.L.C. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Z.F.L.C. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Z.F.L.C.  If not, see <http://www.gnu.org/licenses/>.
 *******/
class linkChecker {
	private $links = array();
	private $sites = array();

	function __construct($sites = '') {
		if(is_array($sites)) {
			$this->sites = $sites;
		}
	}

  	function addLink($link) {
	  	$this->links[] = $link;
	}

  	function resetLinks() {
	  	$this->links = array();
	}

  	function addSite($site) {
		if(is_array($sites)) {
			$this->sites[] = $site;
		}
	}

	function checkLink($link) {
		$result = '';
		if(preg_match('/^http:\/\/(www\.)?megaupload\.com\/\?d=([A-Z0-9]{6,8})$/', $link)) {
			$result = $this->megauploadCom($link);
		} elseif(preg_match('/^http:\/\/(www\.)?rapidshare\.com\/files\/([0-9]{7,9})\/(.*?)(\.?h?t?m?l?)?$/', $link)) {
			$result = $this->rapidshareCom($link);
		} elseif(preg_match('/^http:\/\/(www\.)?rapidshare\.de\/files\/([0-9]{7,9})\/(.*?)(\.?h?t?m?l?)?$/', $link)) {
			$result = $this->rapidshareDe($link);
		// Heb dit vanwege phphulp gecomment zodat ik een kon laten zien om nieuwe sites to te voegen!
	//	} elseif(preg_match('/^http:\/\/(www\.)?sendspace\.com\/file\/([a-zA-Z0-9]{4,7})$/', $link)) {
	//		$result = $this->sendspaceCom($link);
	//	} elseif(preg_match('/^http:\/\/(www\.)?turboupload\.com\/download\/([a-zA-Z0-9]{10,14})$/', $link)) {
	//		$result = $this->turbouploadCom($link);
		} else {
			foreach($this->sites as $site => $siteInfo) {
				if(preg_match($siteInfo['regex'], $link)) {
					if($siteInfo['callback']['class'] != '') {
						$result = call_user_func(array($siteInfo['callback']['class'], $siteInfo['callback']['function']), $link); 
					}else{
						$result = call_user_func($siteInfo['callback']['function'], $link);
					}
				}
			}
		}
		if($result != '' && $result['status'] == ('Found' || 'Not Found')) {
			return $result;
		} else {
			return false;
		}
	}

	function readLinks() {
		$allLinks = array();
		foreach($this->links as $lnk) {
			$allLinks[] = $this->checkLink($lnk);
		}
		return $allLinks;
	}


	// In this function '@' is used to make sure that we don't get any php errors if the page couldn't be downloaded..
	function getPage($url) {
		if (function_exists('curl_init')) {
			$ch = @curl_init($url);
			@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$source = @curl_exec($ch);
			@curl_close($ch);
		} else if(function_exists('file_get_contents')) {
			$source = @file_get_contents($url);
		} else {
			$url = str_replace("http://","",$url);
			if (preg_match("#/#","$url")){
				$page = $url;
				$url = @explode("/",$url);
				$url = $url[0];
				$page = str_replace($url,"",$page);
				if (!$page || $page == ""){
					$page = "/";
				}
				$ip = gethostbyname($url);
			}else{
				$ip = gethostbyname($url);
				$page = "/";
			}
			$open = @fsockopen($ip, 80, $errno, $errstr, 60);
			$send = "GET $page HTTP/1.0\r\n";
			$send .= "Host: $url\r\n";
			if ($_SERVER['HTTP_REFERER']){
				$send .= "Referer: {$_SERVER['HTTP_REFERER']}\r\n";
			}
			$send .= "Accept-Language: en-us, en;q=0.50\r\n";
			$send .= "User-Agent: LinkCheckerScript\r\n";
			$send .= "Connection: Close\r\n\r\n";
			@fputs($open, $send);
			while (!feof($open)) {
				$return .= @fgets($open, 4096);
			}
			@fclose($open);
			$return = @explode("\r\n\r\n",$return,2);
			$source = $return[1];
		}
		return $source;
	}
	
	function megauploadCom($link) {
		$fgc = $this->getPage($link);
		preg_match('/\<b\>Filename:\<\/b\> (.*?)\<\/div\>/', $fgc, $matches);
		preg_match('/\<b\>Filesize:\<\/b\> (.*?)\<\/div\>/', $fgc, $matches2);
		preg_match('/\<b\>Description:\<\/b\> (.*?)\<\/div\>/', $fgc, $matches3);
		$ret = array();
		if(isset($matches[1]) && $matches[1] != '') {
			$ret['status'] = 'Found';
			$ret['filename'] = $matches[1];
			$ret['size'] = $matches2[1];
			$ret['desc'] = $matches3[1];
		} else {
			$ret['status'] = 'Not Found';
			$ret['filename'] = '';
			$ret['size'] = '';
			$ret['desc'] = '';
		}
		$ret['url'] = $link;
		return $ret;
	}
	
	function rapidshareDe($link) {
		$fgc = $this->getPage($link);
		preg_match('/\<h3\>You want to download (.*?)\<\/h3\>/', $fgc, $matches);
		$ret = array();
		if(isset($matches[1]) && $matches[1] != '') {
			$ret['status'] = 'Found';
			$ret['filename'] = $matches[1];
			$ret['size'] = 'Unknown Size';
		} else {
			$ret['status'] = 'Not Found';
			$ret['filename'] = '';
			$ret['size'] = '';
		}
	
		$ret['url'] = $link;
		return $ret;
	}
	
	function rapidshareCom($link) {
		$fgc = $this->getPage($link);
		preg_match('/\<p class="downloadlink"\>http:\/\/rapidshare\.com\/files\/([0-9]{0,9})\/(.*?) \<font style="color:#([a-fA-F0-9]{0,6});"\>\| ([0-9]+) (.*?){0,2}\<\/font\>\<\/p\>/', $fgc, $matches);
		$ret = array();
		if(isset($matches[0]) && $matches[0] != '') {
			$ret['status'] = 'Found';
			$ret['filename'] = $matches[2];
			$ret['size'] = $matches[4].' '.$matches[5];
		} else {
			$ret['status'] = 'Not Found';
			$ret['filename'] = '';
			$ret['size'] = '';
		}
	
		$ret['url'] = $link;
		return $ret;
	}

	function turbouploadCom($link) {
		$fgc = $this->getPage($link);
		$fgc = explode('<div id="process">', $fgc);
		$fgc = explode('</table>', $fgc[1]);
		$fgc = $fgc[0];
	
		preg_match_all('#\<tr\>(.*?)\<\/tr\>#s', $fgc, $tr);
		$td = explode('<td', $tr[0][0]);
		preg_match_all('/\<div align="left" class="style47"\>(.*?)\<\/div\>/s', $td[2], $file);
		$file = trim(preg_replace('/\<.*?\>/', '', $file[1][0]));
		$td = explode('<td', $tr[0][1]);
		preg_match_all('/\<div align="left"  class="style47"\>(.*?)\<\/div\>/s', $td[4], $size);
		$size = $size[1][0];
	
		$ret = array();
		if(isset($file) && $file != '') {
			$ret['status'] = 'Found';
			$ret['filename'] = $file;
			$ret['size'] = $size;
			$ret['desc'] = '';
		} else {
			$ret['status'] = 'Not Found';
			$ret['filename'] = '';
			$ret['size'] = '';
			$ret['desc'] = '';
		}
		$ret['url'] = $link;
		return $ret;
	}
}

function sendspaceCom($link) {
	global $linkchecker;
	$fgc = $linkchecker->getPage($link);
	preg_match('/\<b\>Name:\<\/b\> (.*?)\<br\>/', $fgc, $matches);
	preg_match('/\<b\>Size:\<\/b\> (.*?)\<br\>/', $fgc, $matches2);
	preg_match('/\<b\>Description:\<\/b\> (.*?)The download link is located below.\<\/td\>/', $fgc, $matches3);
	$ret = array();
	if(isset($matches[1]) && $matches[1] != '') {
		$ret['status'] = 'Found';
		$ret['filename'] = trim($matches[1]);
		$ret['size'] = trim(isset($matches2[1]) ? $matches2[1] : '');
		$ret['desc'] = trim(isset($matches3[1]) ? $matches3[1] : '');
	} else {
		$ret['status'] = 'Not Found';
		$ret['filename'] = '';
		$ret['size'] = '';
		$ret['desc'] = '';
	}
	$ret['url'] = $link;
	return $ret;
}

?>[/code]


FILE: voorbeeld.php
[code]<?php
/*****
 *  Copyright 2008 Hoshang Sadiq, Zeryl
 *
 *  For more information on this script, visit:
 *  http://zeryl.net/linkchecker
 *
 *  This file is part of Zeryl Filesharing Link Checker (Z.F.L.C.)
 *
 *  Z.F.L.C. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Z.F.L.C. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Z.F.L.C.  If not, see <http://www.gnu.org/licenses/>.
 *******/

include ('linkchecker.php');

$sites = array(
	'turboupload.com' => array(
		'regex' => '/^http:\/\/(www\.)?turboupload\.com\/download\/([a-zA-Z0-9]{10,14})$/',
		'callback' => array(
			'class' => 'linkChecker',
			'function' => 'turbouploadCom'
		)
	),
	'sendspace.com' => array(
		'regex' => '/^http:\/\/(www\.)?sendspace\.com\/file\/([a-zA-Z0-9]{4,7})$/',
		'callback' => array(
			'class' => '',
			'function' => 'sendspaceCom'
		)
	)
);

echo '<h1>Filesharing Link Checker</h1>';

if(isset($_POST['links'])) {
	echo '<pre>';
	$linkchecker = new linkChecker($sites);
	$links = trim(addslashes(htmlspecialchars($_POST['links'])));
	$array = explode("\n", $links);
	echo "Please be patient for the page to load fully. This operation can take a while depending on the number of links and the speed of the filesharing host.<br />";
	for($i=0;$i<count($array);$i++) {
		$lnk = trim($array[$i]);
		if($lnk != '') {
			if(substr($lnk, 0, 7) != 'http://') {
				$lnk = 'http://'.$lnk;
			}
			$result = $linkchecker->checkLink($lnk);
			if($result != '' && $result['status'] == ('Found' || 'Not Found')) {
				echo (($result['status'] == 'Found') ? '<span style="color: green">Found</span> : '.$result['url'].' : '.$result['filename'] .' ('.$result['size'].')' : '<span style="color: red">Not Found</span> : '.$result['url']).'<br>';
				$text2 .= $result['url']."\n";
				flush();
			}
		}
		$lnk = '';
		$result = '';
	}
	echo 'Done<br /><br />';
	echo '</pre>';
}
//print_r($test->checkLink('LINK HIER'));
//$test->addLink('LINK HIER');
//$test->addLink('LINK HIER');
//print_r($test->readLinks());
?>

Put all the links in the box beneath, then click on Check Links
<form action="<?php echo basename(__FILE__); ?>" method="POST">
<textarea cols="100" rows="20" name="links"></textarea>
<br />
<input type="submit" value="Check links">
</form>

This website currently supports <a href="http://www.megaupload.com/">www.megaupload.com</a>, <a href="http://www.rapidshare.com/">www.rapidshare.com</a>, <a href="http://www.rapidshare.de/">www.rapidshare.de</a>, <a href="http://www.sendspace.com/">www.sendspace.com</a>, <a href="http://www.turboupload.com/">www.turboupload.com</a><br />
<a href="http://zeryl.net/linkchecker/download.php">Download this script</a>[/code]