Location: PHPKode > projects > PHP Newsgroup Reader > right.php
<link href="javascript/style1.css" type=text/css rel=stylesheet>
<body bgcolor="#f3f3f3">
<?php
	include("init.inc");
	include("decode_mime.inc");
	if ( isset($_GET['n']) )
	{
			$fp = fopen("file/tmp.html", 'r');
			$server = fgets($fp);
			$newsgroup = fgets($fp);
			$replace1 = array(chr(13), chr(10));
			$replace2 = array('', '');
			$server = str_replace($replace1, $replace2, $server);
			$newsgroup = str_replace($replace1, $replace2, $newsgroup);
			fclose($fp);
			
			$n = $_GET['n'];
			
//print("$server||$newsgroup||$n");


			$fp = fsockopen($server, 119);
			$string = fgets($fp);
			fputs($fp, "GROUP ".$newsgroup."\n");
//211 n f l s group selected (n = estimated number of articles in group, f = first article number in the group,
//                            l = last article number in the group, s = name of the group.)
			list($code, $tmp, $first, $last, $tmp) = split(" ", fgets($fp) );
			if ($code != "211")
					die("Newsgroup selection fails");



			$t='.'.chr(13).chr(10);

			fputs($fp, "head ".$n."\r\n");
			include("msgheader.php");

			@mkdir("file",0755);
			@mkdir("file/".$server,0755);
			$fp_reply = fopen("file/".$server."/reply.".$newsgroup.".html", 'wb');

			fputs($fp, "body ".$n."\r\n");
			$temp = fgets($fp);
			$st = fgets($fp);

			$num_file = 0;
			$is_uue_file = false;
			$is_base64_file = false;
			
			fputs($fp_reply, $title."\r\n");
			fputs($fp_reply, $refid."\r\n");
//			fputs($fp_reply, $n."\r\n");
			fputs($fp_reply, $wrote_name."\r\n");
			fputs($fp_reply, $wrote_email."\r\n");
?>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<table width="100%" cellpadding=0 cellspacing=0 align="center" border=1 bordercolor=#BECCE7>
<TR><TD><div align="center"><a href="post.php?reply=1&server=<? print("$server");?>&newsgroup=<? print("$newsgroup");?>">REPLY</a><BR></div></TD></TR>
<TR><TD>
<font color=000000>
<?
			while ( $st!=$t )
			{
					$temp = "";

					if ( substr($st,0,3)=="end" )// uue_file
					{
							$is_uue_file = false;
							include("file_save.inc");
					}


                   if ( $is_uue_file&&!$file_exist )// begin.........end
                   {
                           $st1 = $st;

                           if ( $st[0]=='M' )//60 chars lines
                                   $st1 = substr($st,1,60);
                           else
                                   $st1 = substr($st1,1,strlen($st1)-3);


                           if (strlen($st1)>0)    //not the last line
                           for ($i=0;$i<strlen($st1);++$i)
                                   if ( $st1[$i]!=chr(96) )  //not `
                                   {
                                           $temp1 = decbin(ord($st1[$i])-32);   //52 -> 010100
                                           $x = strlen($temp1);
                                           for ($j=1;$j<=6-$x;++$j)
                                                   $temp1 = '0'.$temp1;

                                           $temp = $temp.$temp1;    //glue these 6-bit binaries

                                   }else    //char = ~
                                           $temp = $temp."000000";    //96 -> 000000

                           for ($i=0;$i<strlen($st1)/4*3;++$i)   //8-bit binaries -> decemials
                                   fwrite( $file_save,chr(bindec(substr($temp,8*$i,8))) );



                   }//if ( $is_uue_file&&!$file_exist )

                   if ( substr($st,0,10)=="begin 666 " )// uue_file
                   {
                           $is_uue_file = true;
                           list($temp2,$temp3,$file_name[$num_file]) = split(" ",$st,3);
                           $file_name[$num_file] = substr($file_name[$num_file],0,strlen($file_name[$num_file])-2);
                   }

                   if( strlen($st)==45&&substr($st,0,7)=="------="||strlen($st)==40&&substr($st,0,14)=="--------------" )
                   {
                        $type1=$type2=false;

                        if ( substr($st,0,14)=="--------------"&&!$type1&&!$type2 )  //netscape
                             $type1 = true;
                        if ( substr($st,0,7)=="------="&&!$type1&&!$type2 )  //outlook express
                             $type2 = true;
                        $boundary = $st;//substr($st,0,strlen($st)-2);
//                        print("boundary=$boundary");
                        $st = fgets($fp);
                        while( $st[0]!='.' )
                        {
                             if( substr($st,0,20)=="Content-Type: image/"||substr($st,0,20)=="Content-Type: audio/"||substr($st,0,20)=="Content-Type: video/"||substr($st,0,26)=="Content-Type: application/" )
							 /* file save */
                             {
                                  $st = fgets($fp);

                                  list($z,$file_name[$num_file+1],$z) = split("\"",$st,3);
//                                  print("$file_name[$num_file]<BR>");

                                  include("file_open.inc");

                                  while ( strlen(fgets($fp))!=2 );
                                  while ( strlen($st=fgets($fp))==2 );
                                  if ( !$file_exist )
                                  while ( strlen($st)!=2&&$st!=$boundary )
                                  {
                                        $st = substr($st,0,strlen($st)-2);
                                        @list($st,$z) = split("=",$st,2);
                                        fwrite($file_save,base64_decode($st));
                                        $st = fgets($fp);
                                  }
                                  include("file_save.inc");

                             }else if( substr($st,0,23)=="Content-Type: text/html")
                             {
                                  while ( strlen(fgets($fp))!=2 );

                                  while ( substr($st=fgets($fp),0,14)!="--------------"&&$type1||substr($st,0,7)!="------="&&$type2 )
                                      print(quoted_printable_decode($st));
                             }else if( substr($st,0,24)=="Content-Type: text/plain" )
                             {
                                  while ( strlen(fgets($fp))!=2 );
                                  while ( strlen($st=fgets($fp))==2 );
                                  while ( strlen($st)!=2&&$st!=$boundary )
                                  {
                                      print(quoted_printable_decode($st)."<BR>");
                                      $st = fgets($fp);
                                  }
                             }
                             else if( $st==($boundary."--") )
                             {
                                  while ( $st[0]!='.' )
                                  {
									  fputs($fp_reply, "> ".$st=fgets($fp));
                                      print("$st<BR>");
                                  }
                                  fputs($fp, "QUIT"."\n");
                                  fclose($fp);
                                  exit();
                             }else
                                  $st = fgets($fp);
                        }
                        fputs($fp, "QUIT"."\n");
                        fclose($fp);
                        exit();
                   }

                   if ( substr($st,0,10)=="begin 666 " )
                   {
                          $st = substr($st,0,strlen($st)-2);
                          @list($z,$z,$file_name[$num_file+1]) = split(" ",$st);
//                          print($file_name[$num_file+1]);
                          include("file_open.inc");
                   }

                   if ( !$is_uue_file&&substr($st,0,3)!="end" )
				   
//				   			if ( !lnk($st) )
{		
//print(stristr("asjfljhttp://fuckyouforever", 'ttp://')."/");
								if ( substr($st, 0, 44)!="This is a multi-part message in MIME format." )
								{
									  fputs($fp_reply, "> ".$st);
		                           print(/*strlen($st).*/"$st<BR>");
								}
}

                   $st = fgets($fp);


          }
		  fclose($fp_reply);
			fputs($fp, "QUIT"."\n");
		  fclose($fp);
	}else//if
	{
			include("intro_r.php");
			exit(0);
	}

function lnk($st)
{
//		if ( !strpos( ($tmp=stristr( $st, $st1)) , $st1 )===false )
//print("**st=$st*st1=$st1**<BR>");
		$st1 = array("http://", "ftp://", "news://");
		$st = strtolower($st);
		$i = $no = 0;
		for ( $k=0; $k<=count($st1)-1; ++$k)
			$tmp2[$k] = "";
		do{
			for ( $k=0; $k<=count($st1)-1; ++$k)
			{
				$j = $count = 0;
				//print("/".strlen($st1[$k])."/");
				while ( ($j<=strlen($st1[$k])-1)&&$st1[$k][$j]==$st[$i+$j] )
						$j++;
				if ( $j==strlen($st1[$k]) )
				{
						while (  ($tmp1=$st[$i+$j+$count])<=126&&($tmp1!=32)&&($tmp1!=13)&&($tmp1!=10)&&($tmp1!=0)  )
								$count++;
						$tmp2[$k][++$no] = substr($st, $i, $j+$count);
				}
			}
		}while ( $i++<strlen($st)-1 );
		if ( $no==0 )
				return false;
		else
		{
				for ( $k=0; $k<=count($st1)-1; ++$k)
					if ( $tmp2[$k]!="" )
						str_replace( $tmp2[$k], "<a href=javascript:window.open(\"".$tmp2[$k]."\")>".$tmp2[$k]."</a>", $st);
				print("$st<BR>");
				return true;
		}
/*
		if ( !($tmp=strstr( $st, $st1)===false) )
		{
				$count = strlen($st1)-1;
				while ( ($tmp1=$tmp[++$count])<=126&&($tmp1!=32)&&($tmp1!=13)&&($tmp1!=10)&&($tmp1!=0) );
				$tmp2 = substr($tmp, 0, $count);
				str_replace( $tmp2, "<a href=javascript:window.open(\"".$tmp2."\")>$tmp2</a>", $st);
		}else{
		print($tmp ."/");
				return false;}
		print("$st<BR>");
		return true;
*/
}



//  print("</HTML>");
?>
</font></TD></TR>
</table>
Return current item: PHP Newsgroup Reader