Difference between revisions of "Calendar.php"

From Organic Design wiki
m
({{legacy}})
 
(36 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<?
+
{{legacy}}
 
+
<php><?
function month( $m, $y ) {
+
# Return a calendar table of the passed month and year
$c = ' align=center';
+
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;
 
if ( !$d = date( 'w', $ts = mktime( 0, 0, 0, $m, 1, $y) ) ) $d = 7;
 
$month = date( 'F', $ts );
 
$month = date( 'F', $ts );
$article = "<table border=0><tr><th colspan=7$c><h2>$month</h2>\n<tr>";
+
$article = "<table><tr><th colspan=7><h3>$month</h3>\n<tr>";
$article .= "<th$c>Mon<th$c>Tue<th$c>Wed<th$c>Thu<th$c>Fri<th$c>Sat<th$c>Sun\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>&nbsp;</td>', $d-1 );
for ( $i = $d; $i < 39; $i++ ) {
+
for ( $i = $day = $d; $day < 32; $i++ ) {
 
$day = $i - $d + 1;
 
$day = $i - $d + 1;
$day = $day < 10 ? "0$day" : $day;
+
$dd = $day < 10 ? "0$day" : $day;
if ( 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>";
$article .= "<td$c><b>[[$day $month $y|$day]]</b>";
+
$t = ( $day == $thisDay and $m == $thisMonth and $y == $thisYear ) ? ' class=xwToday' : '';
 +
$article .= "<td$t>[[$prefix$dd $month $y|$day]]";
 
}
 
}
 
}
 
}
Line 20: Line 24:
 
}
 
}
  
$article = "<table border=0 cellpadding=5 cellspacing=5><tr><td>\n";
+
# 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;
 
$m = 1;
$y = date( 'Y' );
+
for ( $rows = 3; $rows--; $article .= "\n<tr>" )
for ( $rows = 0; $rows < 3; $rows++ ) {
 
$article .= "\n<tr>";
 
 
for ( $cols = 0; $cols < 4; $cols++ )
 
for ( $cols = 0; $cols < 4; $cols++ )
$article .= "\n<td align=top style='border:groove 2px #eeeeee'>".month( $m++, $y );
+
$article .= "\n<td>".month( $m++, $y, $p );
 
 
      }
 
 
$article .= '</table>';
 
$article .= '</table>';
?>
+
?></php>

Latest revision as of 02:13, 24 April 2007

Legacy.svg 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, now this page is for historic record only.

<php><?

  1. 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 = "

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

$month

\n
MTWTFSS
 

";

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 .= '

';

?></php>