home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / newslister.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  3.8 KB  |  97 lines

  1. News lister 
  2.  
  3. This scripts collects the filenames in a specified directory and outputs a link to each file with date and timestamp taken from the filename. 
  4.  
  5. <?php 
  6. /* 
  7. Newslister v. 0.02 
  8.  
  9. This newslister is based on another script I've made called File lister. 
  10. This scripts collects the filenames in a specified directory and outputs a link to each file with 
  11. date and timestamp taken from the filename. 
  12. It also outputs a header for each month, so all ads during a month is collected on one place. 
  13. Its also sorted in descending order, with the newest ads first. 
  14.  
  15. The only variable you would need to change is the $newsdir(use a trailing slash) to get it working. 
  16.  
  17. Copyleft(L) 1999 Eric Persson, eric@persson.tm, http://www.persson.tm/scripts/ 
  18.  
  19. */ 
  20.  
  21. /* 
  22. This is the code I used to create the filenames with. To make it easy I suggest you to make a 
  23. small textbox on a page and let the script take care of writing it to a suitable directory. 
  24.  
  25. $fileyear=date(Y); 
  26. $filemonth=date(m); 
  27. $fileday=date(d); 
  28. $filehour=date(H); 
  29. $fileminute=date(i); 
  30. $filesecond=date(s); 
  31. $completefilename="$fileyear-$filemonth-$fileday.$filehour-$fileminute-$filesecond"; 
  32. */ 
  33.  
  34.  
  35. Function searchdir($basedir) 
  36. global $filelisting, $number;  //defines the two variables as global so they can be accessed from outside the function 
  37.     unset($filelisting);  //kills $filelisting in case it have been used earlier in the script 
  38.     unset($number);  //same as above 
  39.     $handle=opendir($basedir); 
  40.         while ($file = readdir($handle)) { 
  41.             if ($file== "." or $file== "..") { 
  42.             } else { 
  43.             $filelisting[]= "$basedir$file"; 
  44.             }; 
  45.         }; 
  46.  
  47.     $number=sizeof($filelisting);  //gets the size of the array 
  48. }; 
  49.  
  50. //variables to change... 
  51. $newsdir= "../news/";  //Set the path where the newsfiles is located 
  52. //stop here 
  53.  
  54.  
  55. searchdir($newsdir); 
  56. $number=$number-1; 
  57.  
  58. sort($filelisting);  //sorts the array $filelisting 
  59. $otheryear= "0";  //sets $otheryear to zero 
  60.  
  61.     while($number>= "0"){ 
  62.     $file=$filelisting[$number]; 
  63.     $linkfile=$file;  //saves the correct path to the linkfile for future use. 
  64.     $file=ereg_replace(  "$newsdir",  '', $file );  //Strips the $newsdir from $file 
  65.  
  66.      //Script below extracts the correct date and time from the filename 
  67.      //The script suspects the format of the filename should be Y-m-d.H-m-s for example 1999-08-11.18-00-11 
  68.      //In case you have an extension(for example .html) on your newsfiles it will be putted in  $file[2] 
  69.     $file=split( "\.",$file,3);  //Splits the $file by the . 
  70.     $date=split( "-",$file[0],3);  //splits the date in $file[0] by the - 
  71.     $year=$date[0];  //year is the first part of the date in $date[0] 
  72.     $month=$date[1];  //month is the second part of the date in $date[1] 
  73.     $day=$date[2];  //day is the third part of the date in $date[2] 
  74.     $time=ereg_replace(  '-',  ':', $file[1] );  //To make the time string look good you only have to replace the - with : 
  75.  
  76.     $number=$number-1;  //decrements the variable $number to make the while function to end in a reasonable amount of time 
  77.     $yearmonth= "$year-$month";  
  78.  
  79.         if($yearmonth!=$otheryear){ 
  80.         echo  "<BR><B><U>"; 
  81.         echo date( "F", mktime(0,0,0,$month,1,$year));  //outputs the correct month in characters  
  82.         echo  " $yearmonth[0]"; 
  83.         echo  "</U></B><BR>"; 
  84.         echo  "<A HREF=\"$linkfile\">$year-$month-$day $time</A><BR>"; 
  85.         $otheryear=$yearmonth;  //Makes $otheryear equals to $yearmonth to stop the script from printing headers more than once. 
  86.         $inc=$inc+1; 
  87.         }else{ 
  88.         echo  "<A HREF=\"$linkfile\">$year-$month-$day $time</A><BR>"; 
  89.         $inc=$inc+1; 
  90.         };  //end of if statement 
  91.  
  92.     };  //end of while statement 
  93.  
  94. ?> 
  95.  
  96.