File:  [mozdev] / cdn / www / b2-include / b2calendar.php
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Thu Mar 13 14:54:53 2003 UTC (16 years, 5 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
try calendar

    1: <?php
    2: 
    3: /* customize these as you wish */
    4: 
    5: $calendarmonthdisplay = 1;	// set this to 0 if you don't want to display the month name
    6: $calendarmonthformat = 'F Y';
    7: $calendarmonthstart = '<caption class="b2calendarmonth">';
    8: $calendarmonthend = '</caption>';
    9: 
   10: $calendartablestart = '<table class="b2calendartable" summary="Monthly calendar with links to each day\'s posts">';
   11: $calendartableend = '</table>';
   12: 
   13: $calendarrowstart = '<tr class="b2calendarrow">';
   14: $calendarrowend = '</tr>';
   15: 
   16: $calendarheaderdisplay = 1;	// set this to 0 if you don't want to display the "Mon Tue Wed..." header
   17: $calendarheadercellstart = '<th class="b2calendarheadercell" abbr="$abbr">';	// please leave $abbr there !
   18: $calendarheadercellend = '</th>';
   19: $calendarheaderabbrlenght = 3;	// length of the shortened weekday
   20: 
   21: $calendarcellstart = '<td class="b2calendarcell">';
   22: $calendarcellend = '</td>';
   23: 
   24: $calendaremptycellstart = '<td class="b2calendaremptycell">';
   25: $calendaremptycellend = '</td>';
   26: 
   27: $calendaremptycellcontent = '&nbsp;';
   28: 
   29: 
   30: /* stop customizing (unless you really know what you're doing) */
   31: 
   32: 
   33: include_once(PROJECT_PATH  . '/b2config.php');
   34: require_once("$b2blah$b2inc/b2template.functions.php");
   35: require_once("$b2blah$b2inc/b2functions.php");
   36: require_once("$b2blah$b2inc/b2vars.php");
   37: dbconnect();
   38: 
   39: if (isset($calendar) && ($calendar != '')) {
   40: 	$thisyear = substr($calendar,0,4);
   41: 	$thismonth = substr($calendar,4,2);
   42: } else {
   43: 	if (isset($m) && ($m != '')) {
   44: 		$calendar = substr($m,0,6);
   45: 		$thisyear = substr($m,0,4);
   46: 		if (strlen($m) < 6) {
   47: 			$thismonth = '01';
   48: 		} else {
   49: 			$thismonth = substr($m,4,2);
   50: 		}
   51: 	} else {
   52: 		$thisyear = date('Y');
   53: 		$thismonth = date('m');
   54: 	}
   55: }
   56: 
   57: // original arrow hack by Alex King
   58: $archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal;
   59: $ak_date = mktime(0,0,0,$thismonth,1,$thisyear);
   60: $ak_previous_month = date("m", $ak_date - ((date("t", $ak_date) * 86400) + 86400));
   61: $ak_next_month = date("m", $ak_date + ((date("t", $ak_date) * 86400) + 86400));
   62: $ak_first_post = mysql_query("SELECT MONTH(MIN(post_date)), YEAR(MIN(post_date)) FROM $tableposts");
   63: $ak_first_post = mysql_fetch_array($ak_first_post);
   64: // using text links by default
   65: $ak_previous_month_dim = '<span>&lt;</span>&nbsp;&nbsp;';
   66: $ak_previous_month_active = '<a href="'.$archive_link_m.$thisyear.$ak_previous_month.'" style="text-decoration: none;">&lt;</a>&nbsp;&nbsp;';
   67: $ak_next_month_dim = '&nbsp;&nbsp;<span>&gt;</span>';
   68: $ak_next_month_active = '&nbsp;&nbsp;<a href="'.$archive_link_m.$thisyear.$ak_next_month.'" style="text-decoration: none;">&gt;</a>';
   69: $ak_previous_month_link = (mktime(0,0,0,$ak_previous_month,0,$thisyear) < mktime(0,0,0,$ak_first_post[0],0,$ak_first_post[1])) ? $ak_previous_month_dim : $ak_previous_month_active;
   70: $ak_next_month_link = (mktime(0,0,0,$ak_next_month,0,$thisyear)> mktime()) ? $ak_next_month_dim : $ak_next_month_active;
   71: 
   72: $end_of_week = (($start_of_week + 7) % 7);
   73: 
   74: $calendarmonthwithpost = 0;
   75: while($calendarmonthwithpost == 0) {
   76: 	$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE MONTH(post_date) = '$thismonth' AND YEAR(post_date) = '$thisyear' ORDER BY post_date DESC";
   77: 	$querycount++;
   78: 	$arc_result=mysql_query($arc_sql) or die($arc_sql."<br />".mysql_error());
   79: 	if (mysql_num_rows($arc_result) > 0) {
   80: 		$daysinmonthwithposts = '-';
   81: 		while($arc_row = mysql_fetch_array($arc_result)) {
   82: 			$daysinmonthwithposts .= $arc_row["DAYOFMONTH(post_date)"].'-';
   83: 		}
   84: 		$calendarmonthwithpost = 1;
   85: 	} elseif ($calendar != '') {
   86: 		$daysinmonthwithposts = '';
   87: 		$calendarmonthwithpost = 1;
   88: 	} else {
   89: 		$thismonth = zeroise(intval($thismonth)-1,2);
   90: 		if ($thismonth == '00') {
   91: 			$thismonth = '12';
   92: 			$thisyear = ''.(intval($thisyear)-1);
   93: 		}
   94: 	}
   95: }
   96: 
   97: $daysinmonth = intval(date('t', mktime(0,0,0,$thismonth,1,$thisyear)));
   98: $datestartofmonth = $thisyear.'-'.$thismonth.'-01';
   99: $dateendofmonth = $thisyear.'-'.$thismonth.'-'.$daysinmonth;
  100: 
  101: // caution: offset bug inside
  102: $calendarblah = get_weekstartend($datestartofmonth, $start_of_week);
  103: if (mysql2date('w', $datestartofmonth) == $start_of_week) {
  104: 	$calendarfirst = $calendarblah['start']+1+3600;	//	adjust for daylight savings time
  105: } else {
  106: 	$calendarfirst = $calendarblah['end']-604799+3600;	//	adjust for daylight savings time
  107: }
  108: 
  109: $calendarblah = get_weekstartend($dateendofmonth, $end_of_week);
  110: if (mysql2date('w', $dateendofmonth) == $end_of_week) {
  111: 	$calendarlast = $calendarblah['start']+1;
  112: } else {
  113: 	$calendarlast = $calendarblah['end']+10000;
  114: }
  115: 
  116: $beforethismonth = zeroise(intval($thismonth)-1,2);
  117: $afterthismonth = zeroise(intval($thismonth)-1,2);
  118: 
  119: // here the offset bug is corrected
  120: if ((intval(date('d', $calendarfirst)) > 1) && (intval(date('m', $calendarfirst)) == intval($thismonth))) {
  121: 	$calendarfirst = $calendarfirst - 604800;
  122: }
  123: 
  124: 
  125: // displays everything
  126: 
  127: echo $calendartablestart."\n";
  128: 
  129: if ($calendarmonthdisplay) {
  130: 	echo $calendarmonthstart;
  131: 	echo $ak_previous_month_link;
  132: 	echo date_i18n($calendarmonthformat, mktime(0, 0, 0, $thismonth, 1, $thisyear));
  133: 	echo $ak_next_month_link;
  134: 	echo $calendarmonthend."\n";
  135: }
  136: 
  137: if ($calendarheaderdisplay) {
  138: 	echo $calendarrowstart."\n";
  139: 
  140: 	for ($i = $start_of_week; $i<($start_of_week+7); $i = $i + 1) {
  141: 		echo str_replace('$abbr', $weekday[($i % 7)], $calendarheadercellstart);
  142: 		echo ucwords(substr($weekday[($i % 7)], 0, $calendarheaderabbrlenght));
  143: 		echo $calendarheadercellend;
  144: 	}
  145: 
  146: 	echo $calendarrowend."\n";
  147: }
  148: 
  149: echo $calendarrowstart."\n";
  150: 
  151: $newrow = 0;
  152: $j = 0;
  153: $k = 1;
  154: for($i = $calendarfirst; $i<($calendarlast+86400); $i = $i + 86400) {
  155: 	if ($newrow == 1) {
  156: 		if ($k > $daysinmonth) {
  157: 			break;
  158: 		}
  159: 		echo $calendarrowend."\n";
  160: 		if (($i+86400) < ($calendarlast+86400)) {
  161: 			echo $calendarrowstart."\n";
  162: 		}
  163: 		$newrow = 0;
  164: 	}
  165: 	if (date('m',$i) != $thismonth) {
  166: 		echo $calendaremptycellstart;
  167: 		echo $calendaremptycellcontent;
  168: 		echo $calendaremptycellend;
  169: 	} else {
  170: 		$k = $k + 1;
  171: 		echo $calendarcellstart;
  172: 		$calendarblah = '-'.date('j',$i).'-';
  173: 		$calendarthereisapost = ereg($calendarblah, $daysinmonthwithposts);
  174: 		$calendartoday = (date('Ymd',$i) == date('Ymd', (time() + ($time_difference * 3600))));
  175: 
  176: 		if ($calendarthereisapost) {
  177: 			echo '<a href="'.$siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$thisyear.$thismonth.date('d',$i).'" class="b2calendarlinkpost">';
  178: 		}
  179: 		if ($calendartoday) {
  180: 			echo '<span class="b2calendartoday">';
  181: 		}
  182: 		echo date('j',$i);
  183: 		if ($calendartoday) {
  184: 			echo '</span>';
  185: 		}
  186: 		if ($calendarthereisapost) {
  187: 			echo '</a>';
  188: 		}
  189: 		echo $calendarcellend."\n";
  190: 	}
  191: 	$j = $j + 1;
  192: 	if ($j == 7) {
  193: 		$j = 0;
  194: 		$newrow = 1;
  195: 	}
  196: }
  197: 
  198: echo $calendarrowend."\n";
  199: echo $calendartableend;
  200: 
  201: ?>

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