Difference between revisions of "Extension:SimpleCalendar"

From Organic Design wiki
m
m
 
(25 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<?
+
{{svn|extensions|MediaWiki/SimpleCalendar/SimpleCalendar.php}}
# MediaWiki Simple Calendar Extension {{#Security:*|dev}}{{#Security:view|*}}{{php}}
 
# - Version 1.00 (2007-04-24)
 
# - See http://www.mediawiki.org/wiki/Extension:Simple_Calendar for installation and usage details
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Author: http://www.organicdesign.co.nz/nad
 
  
$wgExtensionFunctions[]        = 'wfSetupSimpleCalendar';
+
See [[MW:Extension:Simple Calendar]] for installation and usage instructions.
$wgHooks['LanguageGetMagic'][] = 'wfCalendarLanguageGetMagic';
+
[[Category:Extensions]]
function wfCalendarLanguageGetMagic(&$magicWords,$langCode = 0) {
 
        $magicWords['calendar'] = array(0,'calendar');
 
        return true;
 
        }
 
 
 
function wfSetupSimpleCalendar() {
 
        global $wgParser;
 
        $wgParser->setFunctionHook('calendar','wfRenderCalendar');
 
        return true;
 
        }
 
 
 
# Renders a table of all the individual month tables
 
function wfRenderCalendar(&$parser,$p = '',$y = false) {
 
        if ($p) $p .= '/';
 
        if ($y == false) $y = date('Y');
 
        $m = 1;
 
        $table = "{| border class=\"calendar\">\n";
 
        for ($rows = 3; $rows--; $table .= "|-\n")
 
                for ($cols = 0; $cols < 4; $cols++)
 
                        $table .= '|'.wfRenderMonth($m++,$y,$p)."\n";
 
        return "$table\n|}\n";
 
        }
 
 
 
# Return a calendar table of the passed month and year
 
function wfRenderMonth($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);
 
        $table = "<table class=\"month\"><tr class=\"heading\"><th colspan=\"7\">$month</tr>\n<tr class=\"dow\">";
 
        $table .= "<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>";
 
        if ($d > 1) $table .= "</tr>\n<tr>".str_repeat( '<td>&nbsp;</td>',$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) $table .= "</tr>\n<tr>";
 
                        $t = ($day == $thisDay and $m == $thisMonth and $y == $thisYear) ? ' class="today"' : '';
 
                        $table .= "<td$t>[[$prefix$dd $month $y|$day]]";
 
                        }
 
                }
 
        return "$table\n</table>";
 
        }
 
?>
 

Latest revision as of 15:07, 16 May 2015

Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.

See MW:Extension:Simple Calendar for installation and usage instructions.