Location: PHPKode > scripts > Usenet Downloader > usenet-downloader/get_group_description.php
<?
set_time_limit(0);

include_once("config.inc.php");

class NNTPGroupDescription
	{
/*****************************************************************************************/		
		function ftp_get_contents($conn_id, $filename) 
			{
		    	//Create temp handler:
		    	$tempHandle = fopen('php://temp', 'r+');
		  
		    	//Get file from FTP:
		    	if (@ftp_fget($conn_id, $tempHandle, $filename, FTP_ASCII, 0)) 
		    		{
		        		rewind($tempHandle);
		        		return stream_get_contents($tempHandle);
		    		} 
		    	else 
		    		{
		        		return false;
		    		}
			} 
/*****************************************************************************************/			
		function GetGroupDetailsFromIcs()
			{	
				$ftp_server = "ftp.isc.org";
				$ftp_user = "anonymous";
				$ftp_pass = "";
						
				$conn_id = $this->ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 		
				$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
				$file_list=ftp_nlist($conn_id,"pub/usenet/news.announce.newgroups/Group_Lists/");
				
				for($count=0;$count<count($file_list);$count++)
					{
						$file_name=$file_list[$count];
						$file_contents=$this->ftp_get_contents($conn_id,$file_name);
						
						$index1=strpos($file_contents,"=========================  cut to");
						$index2=strpos($file_contents,"=========================  cut from");
						$file_contents=substr($file_contents,$index1,$index2-$index1);
						
						$content_arr=explode("\n",$file_contents);
						for($count=1;$count<count($content_arr)-1;$count++)
							{
								$line=$content_arr[$count];
								$line_arr=explode("\t",$line);
								$group_name=$line_arr[0];
								$description=$line_arr[1];
								$update_str="UPDATE mp_usenet_groups SET description='".mysql_escape_string($description)."' WHERE name='".$group_name."'";
								mysql_query($update_str);
								echo $update_str."<br/>";
							}				
					}
			}
/*****************************************************************************************/			
		function GetGroupDetailsFromIbiblio()
			{
				$contents=file_get_contents("http://www.ibiblio.org/usenet-i/hier-s/master.html");
				
				preg_match_all("/<a href=.*\.html\">(.*)<\/a><BR>\n(.*)\n/iU",$contents,$matches);
				for($count=0;$count<count($matches[1]);$count++)
					{
						$group_name=$matches[1][$count];
						$description=$matches[2][$count];
						$update_str="UPDATE mp_usenet_groups SET description='".mysql_escape_string(trim($description))."' WHERE name='".mysql_escape_string(trim($group_name))."'";
						echo $count.") ".$update_str."<br/>";
						mysql_query($update_str);
					}
			}
/*****************************************************************************************/			
		function GetGroupDetailsFromGoogle()
			{		
				$select_str="SELECT * FROM mp_usenet_groups WHERE description='' AND language='' AND is_searched=1";
				$result=mysql_query($select_str);
				
				while($row=mysql_fetch_assoc($result))
					{			 
				  		$name=$row['name'];		  		
				  		
				  		$url="http://groups.google.com/groups/dir?q=".$name."&qt_d=Search+for+a+group";
				  		$file_contents=file_get_contents($url);  		
				
				  		preg_match("/<br>\n(.*)<br>/",$file_contents,$matches);
				  		$description=$matches[1];
		
				  		preg_match("/\n(.*)<\/font><\/A>/",$file_contents,$matches);
				  		$language=$matches[1];
				  		
				  		if($description=='')continue;
				  		
				  		$update_str="UPDATE mp_usenet_groups SET description='".mysql_escape_string(trim($description))."',language='".mysql_escape_string($language)."' WHERE id=".$row['id'];
				  		mysql_query($update_str);		  		
				  		
				  		echo $update_str."<br/>";
				  		flush();
				  		sleep(10);			
					}				
			}
/*****************************************************************************************/			
	}
?>
Return current item: Usenet Downloader