Personal tools

Calendar.php

From OrganicDesign Wiki

Jump to: navigation, search
Image:legacy.png
Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.


<?
# Return a calendar table of the passed month and year
function month( $m, $y, $prefix = '' ) {
	$thisDay     = date('d');
	$thisMonth = date('n');
        $thisYear    = date('Y');
	if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7;
	$month = date( 'F', $ts );
	$article = "<table><tr><th colspan=7><h3>$month</h3>\n<tr>";
	$article .= "<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>\n";
	if ( $d > 1 ) $article .= '<tr>'.str_repeat( '<td>&nbsp;</td>', $d-1 );
	for ( $i = $day = $d; $day < 32; $i++ ) {
		$day = $i - $d + 1;
		$dd = $day < 10 ? "0$day" : $day;
		if ( $day < 29 or checkdate( $m, $day, $y ) ) {
			if ( $i%7 == 1 ) $article .= "\n<tr>";
			$t = ( $day == $thisDay and $m == $thisMonth and $y == $thisYear ) ? ' class=xwToday' : '';
			$article .= "<td$t>[[$prefix$dd $month $y|$day]]";
			}
		}
	$article .= "\n</table>";
	return $article;
	}
 
# Use everything before "Calendar" in name as prefix
$p = preg_replace( '/calendar.*$/i', '', $title );
 
# If cal name ends with a year, use that instead of current
$y = ereg( '([0-9]{4})$', $title, $m ) ? $m[1] : date( 'Y' );
 
# Append the article content with a table of all the month-tables
$article .= "<table class=xwCalendar>\n<tr>";
$m = 1;
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
	for ( $cols = 0; $cols < 4; $cols++ )
		$article .= "\n<td>".month( $m++, $y, $p );
$article .= '</table>';
?>

The GNU Project Debian Linux Ubuntu Linux Wikipedia online encycopedia MediaWiki