File:  [mozdev] / cdn / www / b2archives.php
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Fri Mar 7 01:21:49 2003 UTC (16 years, 5 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
shouldn't have to code around things ...

    1: <?php
    2: 
    3: // *** b2 Archive file
    4: 
    5: //require_once('./b2config.php');
    6: require_once (dirname(__FILE__).'/b2config.php');
    7: require_once($b2blah.$b2inc.'/b2functions.php');
    8: 
    9: dbconnect();
   10: 
   11: // this is what will separate your archive links
   12: $archive_line_separator = '<br />';
   13: // this is what will separate dates on weekly archive links
   14: $archive_week_separator = ' - ';
   15: 
   16: 
   17: // archive link url
   18: $archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal;	# monthly archive
   19: $archive_link_w = $siteurl.'/'.$blogfilename.$querystring_start.'w'.$querystring_equal;	# weekly archive
   20: $archive_link_p = $siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal;	# post-by-post archive
   21: 
   22: 
   23: // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
   24: $archive_date_format_over_ride = 0;
   25: 
   26: 
   27: // options for daily archive (only if you over-ride the general date format)
   28: $archive_day_date_format = 'Y/m/d';
   29: 
   30: // options for weekly archive (only if you over-ride the general date format)
   31: $archive_week_start_date_format = 'Y/m/d';
   32: $archive_week_end_date_format   = 'Y/m/d';
   33: 
   34: 
   35: // --- //
   36: 
   37: 
   38: $dateformat=get_settings('date_format');
   39: $time_difference=get_settings('time_difference');
   40: 
   41: if (!$archive_date_format_over_ride) {
   42: 	$archive_day_date_format = $dateformat;
   43: 	$archive_week_start_date_format = $dateformat;
   44: 	$archive_week_end_date_format   = $dateformat;
   45: }
   46: 
   47: if (basename($HTTP_SERVER_VARS['SCRIPT_FILENAME']) == 'b2archives.php')
   48: 	include ('blog.header.php');
   49: 
   50: if (!isset($querycount)) {
   51: 	$querycount = 0;
   52: }
   53: 
   54: $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
   55: 
   56: if ($archive_mode == 'monthly') { // echo '<p>Monthly</p>';
   57: 	$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
   58: 	$querycount++;
   59: 	$arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
   60: 	while($arc_row = mysql_fetch_array($arc_result)) {
   61: 		$arc_year  = $arc_row['YEAR(post_date)'];
   62: 		$arc_month = $arc_row['MONTH(post_date)'];
   63: 		$_date = $_date_;
   64: 		$_date_ = "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).'">';
   65: 		$_date_ .= $month[zeroise($arc_month,2)].' '.$arc_year;
   66: 		$_date_ .= '</a>';
   67: 		if ($_date_ != $_date) {
   68: 		  echo $_date_; 
   69: 		  echo $archive_line_separator."\n";
   70: 		}
   71: 	}
   72: } elseif ($archive_mode == 'daily') {
   73: 	$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
   74: 	$querycount++;
   75: 	$arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
   76: 	while($arc_row = mysql_fetch_array($arc_result)) {
   77: 		$arc_year  = $arc_row['YEAR(post_date)'];
   78: 		$arc_month = $arc_row['MONTH(post_date)'];
   79: 		$arc_dayofmonth = $arc_row['DAYOFMONTH(post_date)'];
   80: 		echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).zeroise($arc_dayofmonth,2).'">';
   81: 		echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00');
   82: #		echo $month[zeroise($arc_month,2)]." $arc_year";
   83: 		echo '</a>';
   84: 		echo $archive_line_separator."\n";
   85: 	}
   86: } elseif ($archive_mode == 'weekly') {
   87: 	if (!isset($start_of_week)) {
   88: 		$start_of_week = 1;
   89: 	}
   90: 	$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
   91: 	$querycount++;
   92: 	$arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
   93: 	$arc_w_last = '';
   94: 	while($arc_row = mysql_fetch_array($arc_result)) {
   95: 		$arc_year = $arc_row['YEAR(post_date)'];
   96: 		$arc_w = $arc_row['WEEK(post_date)'];
   97: 		if ($arc_w != $arc_w_last) {
   98: 			$arc_w_last = $arc_w;
   99: 			$arc_ymd = $arc_year.'-'.zeroise($arc_row['MONTH(post_date)'],2).'-' .zeroise($arc_row['DAYOFMONTH(post_date)'],2);
  100: 			$arc_week = get_weekstartend($arc_ymd, $start_of_week);
  101: 			$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
  102: 			$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
  103: 			echo "<a href=\"$siteurl/".$blogfilename."?m=$arc_year&amp;w=$arc_w\">";
  104: 			echo $arc_week_start.$archive_week_separator.$arc_week_end;
  105: 			echo '</a>';
  106: 			echo $archive_line_separator."\n";
  107: 		}
  108: 	}
  109: } elseif ($archive_mode == 'postbypost') {
  110: 	$requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC";
  111: 	$querycount++;
  112: 	$resultarc = mysql_query($requestarc);
  113: 	while($row=mysql_fetch_object($resultarc)) {
  114: 		if ($row->post_date != '0000-00-00 00:00:00') {
  115: 			echo "<a href=\"$archive_link_p".$row->ID.'">';
  116: 			$arc_title = stripslashes($row->post_title);
  117: 			if ($arc_title) {
  118: 				echo strip_tags($arc_title);
  119: 			} else {
  120: 				echo $row->ID;
  121: 			}
  122: 			echo '</a>';
  123: 			echo $archive_line_separator."\n";
  124: 		}
  125: 	}
  126: }
  127: 
  128: #echo $querycount."<br />\n";
  129: #timer_stop(1,8);
  130: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>