Difference between revisions of "My Calendar"

From Organic Design wiki
(Created page with '<big>'''2010'''</big> {{#calendar:year=2010}}')
 
Line 1: Line 1:
<big>'''2010'''</big>
+
Return a calendar table of the passed month and year
{{#calendar:year=2010}}
+
function wfRenderMonth($m,$y,$prefix = '',$query = '',$format = '%e %B %Y',$dayformat = false) {
 +
$thisDay  = date('d');
 +
$thisMonth = date('n');
 +
$thisYear  = date('Y');
 +
if (!$d = date('w',$ts = mktime(0,0,0,$m,1,$y))) $d = 7;
 +
$month = wfMsg(strtolower(strftime('%B',$ts)));
 +
$days = array();
 +
foreach (array('M','T','W','T','F','S','S') as $i => $day)
 +
$days[] = $dayformat ? wfMsg(strftime($dayformat,mktime(0,0,0,2,$i,2000))) : $day;
 +
$table = "\n{| class=\"month\"\n|- class=\"heading\"\n|colspan=\"7\"|$month\n|- class=\"dow\"\n";
 +
$table .= '|'.join('||',$days)."\n";
 +
if ($d > 1) $table .= "|-".str_repeat("\n|&nbsp;\n",$d-1);
 +
for ($i = $day = $d; $day < 32; $i++) {
 +
$day = $i - $d + 1;
 +
if ($day < 29 or checkdate($m,$day,$y)) {
 +
if ($i%7 == 1) $table .= "\n|-\n";
 +
$t = ($day == $thisDay and $m == $thisMonth and $y == $thisYear) ? ' class="today"' : '';
 +
$ttext = $prefix.trim(strftime($format,mktime(0,0,0,$m,$day,$y)));
 +
$title = Title::newFromText($ttext);
 +
if (is_object($title)) {
 +
$class = $title->exists() ? 'day-active' : 'day-empty';
 +
$url = $title->getFullURL($title->exists() ? '' : $query);
 +
} else $url = $ttext;
 +
$table .= "|$t|[$url <span class='$class'>$day</span>]\n";
 +
}
 +
}
 +
return "$table\n|}";
 +
}

Revision as of 12:31, 27 March 2010

Return a calendar table of the passed month and year

function wfRenderMonth($m,$y,$prefix = ,$query = ,$format = '%e %B %Y',$dayformat = false) { $thisDay = date('d'); $thisMonth = date('n'); $thisYear = date('Y'); if (!$d = date('w',$ts = mktime(0,0,0,$m,1,$y))) $d = 7; $month = wfMsg(strtolower(strftime('%B',$ts))); $days = array(); foreach (array('M','T','W','T','F','S','S') as $i => $day) $days[] = $dayformat ? wfMsg(strftime($dayformat,mktime(0,0,0,2,$i,2000))) : $day; $table = "\n{| class=\"month\"\n|- class=\"heading\"\n|colspan=\"7\"|$month\n|- class=\"dow\"\n"; $table .= '|'.join('||',$days)."\n"; if ($d > 1) $table .= "|-".str_repeat("\n| \n",$d-1); for ($i = $day = $d; $day < 32; $i++) { $day = $i - $d + 1; if ($day < 29 or checkdate($m,$day,$y)) { if ($i%7 == 1) $table .= "\n|-\n"; $t = ($day == $thisDay and $m == $thisMonth and $y == $thisYear) ? ' class="today"' : ; $ttext = $prefix.trim(strftime($format,mktime(0,0,0,$m,$day,$y))); $title = Title::newFromText($ttext); if (is_object($title)) { $class = $title->exists() ? 'day-active' : 'day-empty'; $url = $title->getFullURL($title->exists() ?  : $query); } else $url = $ttext; $table .= "|$t|[$url $day]\n"; } } return "$table\n|}"; }