Difference between revisions of "Calendar.php"
From Organic Design wiki
(Keeping double-digit day or have to rename all current articles with days<10) |
(Make just anchor double-digit) |
||
Line 12: | Line 12: | ||
for ( $i = $day = $d; $day < 32; $i++ ) { | for ( $i = $day = $d; $day < 32; $i++ ) { | ||
$day = $i - $d + 1; | $day = $i - $d + 1; | ||
− | $ | + | $dd = $day < 10 ? "0$day" : $day; |
if ( $day < 29 or checkdate( $m, $day, $y ) ) { | if ( $day < 29 or checkdate( $m, $day, $y ) ) { | ||
if ( $i%7 == 1 ) $article .= "\n<tr>"; | if ( $i%7 == 1 ) $article .= "\n<tr>"; | ||
$t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : ''; | $t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : ''; | ||
− | $article .= "<td$t> [[$prefix$day $month $y|$ | + | $article .= "<td$t> [[$prefix$day $month $y|$dd]] "; |
} | } | ||
} | } |
Revision as of 10:21, 13 March 2006
<?
- Return a calendar table of the passed month and year
function month( $m, $y, $prefix = ) { $thisDay = date('d'); $thisMonth = date('n'); if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7; $month = date( 'F', $ts );
$article = "
"; $article .= "'.str_repeat( '"; $t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : ; $article .= "<td$t> $dd "; } } $article .= "\n$month\n | ||||||
---|---|---|---|---|---|---|
M | T | W | T | F | S | S\n"; if ( $d > 1 ) $article .= ' |
', $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 | ||||||
";
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 .= "
";$m = 1;
for ( $rows = 3; $rows--; $article .= "\n" ) for ( $cols = 0; $cols < 4; $cols++ ) $article .= "\n\n |
".month( $m++, $y, $p ); $article .= ' |
';
?>