Difference between revisions of "Calendar.php"

From Organic Design wiki
("or" is short-circuit, remove test)
(Allow many calendars - too easy!)
Line 1: Line 1:
 
<?
 
<?
 +
 
# Return a calendar table of the passed month and year
 
# Return a calendar table of the passed month and year
function month( $m, $y ) {
+
function month( $m, $y, $prefix = '' ) {
 
$thisDay = date ( 'd' );
 
$thisDay = date ( 'd' );
 
$thisMonth = date ( 'n' );
 
$thisMonth = date ( 'n' );
Line 16: Line 17:
 
if ( $i%7 == 1 ) $article .= "\n<tr>";
 
if ( $i%7 == 1 ) $article .= "\n<tr>";
 
$t = ( $day == $thisDay and $m == $thisMonth ) ? ' bgcolor=white' : '';
 
$t = ( $day == $thisDay and $m == $thisMonth ) ? ' bgcolor=white' : '';
$article .= "<td$t$c><b>&nbsp;[[$day $month $y|$day]]&nbsp;</b>";
+
$article .= "<td$t$c><b>&nbsp;[[$prefix$day $month $y|$day]]&nbsp;</b>";
 
}
 
}
 
}
 
}
Line 22: Line 23:
 
return $article;
 
return $article;
 
}
 
}
 +
 +
# Use everything before "Calendar" in name as prefix
 +
$p = preg_replace( '/calender.+$/i', '', $title );
 +
 
# Append the article content with a table of all the month-tables
 
# Append the article content with a table of all the month-tables
 
$article .= "<table border=0 cellpadding=5 cellspacing=5><tr><td>\n<tr>";
 
$article .= "<table border=0 cellpadding=5 cellspacing=5><tr><td>\n<tr>";
Line 28: Line 33:
 
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
 
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
 
for ( $cols = 0; $cols < 4; $cols++ )
 
for ( $cols = 0; $cols < 4; $cols++ )
$article .= "\n<td valign=top style='border:groove 2px #eeeeee'>".month( $m++, $y );
+
$article .= "\n<td valign=top style='border:groove 2px #eeeeee'>".month( $m++, $y, $p );
 
$article .= '</table>';
 
$article .= '</table>';
 +
 
?>
 
?>

Revision as of 21:59, 7 March 2006

<?

  1. Return a calendar table of the passed month and year

function month( $m, $y, $prefix = ) { $thisDay = date ( 'd' ); $thisMonth = date ( 'n' ); $c = ' style="font-size:8pt"'; if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7; $month = date( 'F', $ts );

$article = "

";

$article .= "<th$c>M<th$c>T<th$c>W<th$c>T<th$c>F<th$c>S<th$c>S\n";

if ( $d > 1 ) $article .= ''.str_repeat( '"; $t = ( $day == $thisDay and $m == $thisMonth ) ? ' bgcolor=white' : ; $article .= "<td$t$c> $day "; } } $article .= "\n

$month

\n
', $d-1 );

for ( $i = $day = $d; $day < 32; $i++ ) { $day = $i - $d + 1; $day = $day < 10 ? "0$day" : $day; if ( $day < 29 or checkdate( $m, $day, $y ) ) {

if ( $i%7 == 1 ) $article .= "\n

";

return $article; }

  1. Use everything before "Calendar" in name as prefix

$p = preg_replace( '/calender.+$/i', , $title );

  1. Append the article content with a table of all the month-tables

$article .= "

";

$m = 1; $y = date( 'Y' );

for ( $rows = 3; $rows--; $article .= "\n" ) for ( $cols = 0; $cols < 4; $cols++ ) $article .= "\n
\n
".month( $m++, $y, $p ); $article .= '

';

?>