Location: PHPKode > scripts > Google Hacks > google-hacks/GoogleHacks.inc.php
<?php
/**
 * This class hacks google for specific and/or hidden information
 * 
 * @author Rochak Chauhan
 * @version beta
 * @todo This beta version only return top 10 results. More customizations in final release version
 */
class GoogleHacks {
	private $keyword="rochakchauhan";
	
	private $lyricsWebsite="www.lyrics.com";
	private $googleUrl="http://www.google.com/search?&q=";
	
	private $regpattern='/<h2 class=r\>(.*)\<\/h2>/Us';
	private $musicURL='-inurl:(htm|html|php) intitle:"index of" +"last modified" +"parent directory" +description +size +(.mp3|.wma|.ogg) ';
	private $ebooksURL='-inurl:(htm|html|php) intitle:"index of" +"last modified" +"parent directory" +description +size +(.txt|.pps|.lit|.odt|.doc|.rtf|.rar|.pdf|.chm) ';
	private $videoURL='-inurl:(htm|html|php) intitle:"index of" +"last modified" +"parent directory" +description +size +(.mpg|.avi|.flv|.wmv|.di) ';
	private $appsURL='-inurl:(htm|html|php) intitle:"index of" +"last modified" +"parent directory" +description +size +(.exe|.rar|.zip|.ddl) ';
	private $fontUrl="space site:http://www.searchfreefonts.com/font OR site:www.dafont.com OR site:http://www.searchfreefonts.com/   -comments -categories.php -comment.php";
	
	/**
	 * constructor function
	 * @param string $keywork
	 * @return class resource
	 */
	public function __construct($keyword){
		$this->keyword=$this->handleKeyword($keyword);
	}

	/**
	 * Function to handle keyword
	 *
	 * @param string $keyword
	 * @return string
	 */
	private function handleKeyword($keyword){
		if (trim(strip_tags($keyword))!=""){
			return $keyword;
		}
		else {
			return $this->keyword;
		}
	}

	/**
	 * function to return content from an url
	 *
	 * @param string $url
	 * @return string
	 */
	private function getHtmlCode($url){
		$url=$this->googleUrl.$url;
		@ini_set("allow_url_fopen","Off");
		$returnStr="";
		$fp=fopen($url, "r");
		while (!feof($fp)) {
			$returnStr.=fgetc($fp);
		}
		fclose($fp);
		return $returnStr;
	}

	private function getLinkArray($str){
		$returnArray=array();
		preg_match_all($this->regpattern, $str, $returnArray, PREG_SET_ORDER);
		
		$links=array();
		for($i=0;$i<count($returnArray);$i++){
			$links[]=$returnArray[$i][1];
		}
		$buffer="";
		for($i=0;$i<count($links);$i++){
			$buffer.=$links[$i]."\r\n";
		}
		$returnArray=array();
		for ($i=0;$i<count($links);$i++){
			$returnArray[]=array("label"=>strip_tags($links[$i]),"link"=>$links[$i]);
		}
		return $returnArray;
	}

	/**
	 * function to return results only from music sites
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachMusic($keyword=""){
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->musicURL.'"'.$this->keyword.'"');
		$str=$this->getHtmlCode($url);
		return $this->getLinkArray($str);
	}

	/**
	 * function to return results only from ebooks sites
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachBooks($keyword=""){
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->ebooksURL.'"'.$this->keyword.'"');
		$str=$this->getHtmlCode($url);
		return $this->getLinkArray($str);
	}

	/**
	 * function to return results only from videos
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachVideos($keyword=""){
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->videoURL.'"'.$this->keyword.'"');
		$str=$this->getHtmlCode($url);
		return $this->getLinkArray($str);
	}
	
	/**
	 * function to return results only from applications
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachApplications($keyword=""){
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->appsURL.'"'.$this->keyword.'"');
		$str=$this->getHtmlCode($url);
		return $this->getLinkArray($str);
	}
	
	/**
	 * function to return results only from lyrics
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachLyrics($keyword=""){		
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode("site:".$this->lyricsWebsite.' '.$this->keyword);		
		$str=$this->getHtmlCode($url);		
		return $this->getLinkArray($str);
	}
	
	/**
	 * function to return results only from torrent
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachTorrents($keyword=""){		
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->keyword." filetype:torrent");		
		$str=$this->getHtmlCode($url);		
		return $this->getLinkArray($str);
	}
	
	/**
	 * function to return results only from font websites
	 *
	 * @param string $keyword
	 * @return array
	 */
	public function seachFonts($keyword=""){
		$this->keyword=$this->handleKeyword($keyword);
		$url=urlencode($this->fontUrl.$this->keyword);
		$str=$this->getHtmlCode($url);
		return $this->getLinkArray($str);
	}	
}
?>
Return current item: Google Hacks