Location: PHPKode > scripts > Article Archive Addon > article-archive-addon/archive.php
<?php
/**
  * archive.php - Display All/Monthly Articles addon v1.2 
  * 
  * Placed in your menu, it will by default display all
  * articles, when invoked from article_block,php it will
  * display articles by month/year.
  *
  * This addon inspired by the All Stories Addon fro PHPNuke by
  * Ralph Roberts <hide@address.com>. It has since grown into
  * it's own beast though.
  * 
  * Works with phpWebSite 0.8.2
  * 
  * This program 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 2 of the License.  
  * 
  * @author Edward Ritter <hide@address.com>
  * @version $Id: archive.php,v 1.1 2002/08/23 18:15:33 esritter Exp $
  * @module archive
  * @modulegroup addons
  * @package phpWebSite
  */

// Normal includes
if (!isset ($mainfile)) { 
	include_once ('mainfile.php');
	include_once ('config.php');
}

$index = 0; // 0 for no right blocks, 2 for right blocks.

/**
  * show_dates - Show list of month/year dates that contain articles.
  * Clicking on an entry will display that month's articles.
  *
  * @author Edward Ritter
  */
function show_dates() {
	global $table_prefix, $phpws_url;
	$boxtitle = "Article Archives";
	$result = mysql_query ("SELECT DISTINCT SUBSTRING_INDEX(time,'-','2') 
		FROM ".$table_prefix."stories ORDER BY time DESC")
		or die ("Can't open stories table");
	if ($result) {
		while (list ($time) = mysql_fetch_row ($result)) {
			$tempdate = explode ('-', $time);
			$thedate = date ("F Y", mktime (0,0,0,$tempdate[1]+1,0,$tempdate[0]));
			$content .= "&middot;&nbsp;<a href=\"$phpws_url/archive.php?op=showmonth&amp;date=$time\">$thedate</a><br/>";
		}
	}
	thememainbox($boxtitle,$content);
}

/**
  * show_all - by default, shows all articles. If date given, shows
  * only articles for that month/year.
  * 
  * @author Edward Ritter
  * @param string date: year/month combo
  */
function show_all($date = '') {
	global $table_prefix, $sitename, $phpws_url;
	$count = 0;
	$acount = 0;
	$boxtitle = "View All Articles";
	if ($date) {
		$sql = "WHERE time LIKE '%$date%'";
		$tempdate = explode ('-', $date);
		$thedate = date ("F Y", mktime (0,0,0,$tempdate[1]+1,0, $tempdate[0]));
		$boxtitle = "View Articles for $thedate";
	}

	$results = mysql_query ("SELECT sid, title, time, counter 
		FROM ".$table_prefix."stories $sql") or die ("Can't open stories table");
	if ($results) {
		$content = " <br /><table align=\"center\" padding=\"10\" width=\"75%\">
    		<tr class=\"type2\" align=\"center\"><td>Article</td><td>Read</td>
    		<td>Posted</td></tr>";
    	$i = 0;
		while (@extract (mysql_fetch_array($results))) {
			$bgcolor = ($i++%2)?"type2":"type4";
    		$content .= " <tr class=\"$bgcolor\"><td>
    			<a href=\"$phpws_url/article.php?sid=$sid&mode=&order=0\">
    			<b>$title</b></td><td align=\"center\">$counter</td>
    			<td>$time</td></tr>";
    		$acount = $acount + $counter;
    		$count ++;
		}
		$content .= "</table>";
	}
	$content .= "<div class=\"type5\" align=\"center\">$count 
		article".(($count > 1)?'s':'')." total - read $acount 
		times total</div>";

	thememainbox($boxtitle,$content);
}	

/**
  * This handles the main display of the page
  * use archive.php?op= to invoke options
  */
include('header.php');

switch($op) {
	case "showdates":
		show_dates();
        break;
	case "showmonth":
		show_all($date);
		break;
    default:
    	show_all();
    	break;
}

include('footer.php');		
?>
Return current item: Article Archive Addon