Difference between revisions of "Calendar.php"

From Organic Design wiki
m (Remove <tr><td> redundant tag)
m (try completing <th>'s)
Line 8: Line 8:
 
$month = date( 'F', $ts );
 
$month = date( 'F', $ts );
 
$article = "<table><tr><th colspan=7><h3>$month</h3>\n<tr>";
 
$article = "<table><tr><th colspan=7><h3>$month</h3>\n<tr>";
$article .= "<th>M<th>T<th>W<th>T<th>F<th>S<th>S\n";
+
$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>', $d-1 );
 
if ( $d > 1 ) $article .= '<tr>'.str_repeat( '<td>', $d-1 );
 
for ( $i = $day = $d; $day < 32; $i++ ) {
 
for ( $i = $day = $d; $day < 32; $i++ ) {

Revision as of 10:36, 13 May 2006

<?

  1. 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 .= "\n"; if ( $d > 1 ) $article .= ''.str_repeat( '"; $t = ( $day == $thisDay and $m == $thisMonth ) ? ' class=xwToday' : ; $article .= "<td$t>$day"; } } $article .= "\n

$month

\n
MTWTFSS
', $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; }

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

$p = preg_replace( '/calendar.*$/i', , $title );

  1. If cal name ends with a year, use that instead of current

$y = ereg( '([0-9]{4})$', $title, $m ) ? $m[1] : date( 'Y' );

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

$article .= "

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

';

?>