Team:Leicester/extensions/calendar extension.php
From 2012.igem.org
(Difference between revisions)
Ladybird136 (Talk | contribs) (Created page with "<?php # Calendar Extension # Creates a calendar of the month and year. # # Example Code # # <calendar>05 2006</calendar> # $wgExtensionFunctions[] = "wfCalendarExtension"; $wgEx...") |
Ladybird136 (Talk | contribs) |
||
Line 10: | Line 10: | ||
$wgExtensionFunctions[] = "wfCalendarExtension"; | $wgExtensionFunctions[] = "wfCalendarExtension"; | ||
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
- | 'name' => 'Calendar', | + | 'name' => 'Lab Calendar', |
- | 'author' => ' | + | 'author' => 'Team Leicester', |
'description' => 'adds <nowiki><calender></nowiki> tag, for calender creation', | 'description' => 'adds <nowiki><calender></nowiki> tag, for calender creation', | ||
'url' => 'http://meta.wikimedia.org/wiki/Calendar_extension' | 'url' => 'http://meta.wikimedia.org/wiki/Calendar_extension' |
Latest revision as of 09:39, 16 July 2012
<?php
- Calendar Extension
- Creates a calendar of the month and year.
- Example Code
- <calendar>05 2006</calendar>
$wgExtensionFunctions[] = "wfCalendarExtension"; $wgExtensionCredits['parserhook'][] = array(
'name' => 'Lab Calendar', 'author' => 'Team Leicester', 'description' => 'adds <calender> tag, for calender creation', 'url' => 'http://meta.wikimedia.org/wiki/Calendar_extension'
);
/* DO NOT EDIT BEYOND THIS LINE */
function wfCalendarExtension() {
global $wgParser; $wgParser->setHook( "calendar", "createmwCalendar" );
}
- The callback function for converting the input text to HTML output
function createmwCalendar($input) {
global $wgOut; $input = $wgOut->parse($input, false); $array = explode(' ', $input); $month = $array[0]; $year = $array[1]; $mwCalendar = new mwCalendar(); $mwCalendar->dateNow($month, $year); return $mwCalendar->showThisMonth();
}
class mwCalendar {
var $cal = "CAL_GREGORIAN"; var $format = "%Y%m%d"; var $today; var $day; var $month; var $year; var $pmonth; var $pyear; var $nmonth; var $nyear; var $wday_names = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); var $wmonth_names = array("January","Febuary","March","April","May","June","July","August","September","October","November","December"); function mwCalendar() { $this->day = "1"; $today = ""; $month = ""; $year = ""; $pmonth = ""; $pyear = ""; $nmonth = ""; $nyear = ""; } function dateNow($month,$year) { $this->month = $month; $this->year = $year; $this->today = strftime("%d",time()); $this->pmonth = $this->month - 1; $this->pyear = $this->year - 1; $this->nmonth = $this->month + 1; $this->nyear = $this->year + 1; } function daysInMonth($month,$year) { if (empty($year)) { $year = mwCalendar::dateNow("%Y"); } if (empty($month)) { $month = mwCalendar::dateNow("%m"); } if($month == "2") { if(mwCalendar::isLeapYear($year)) { return 29; } else { return 28; } } else if ($month == "4" || $month == "6" || $month == "9" || $month == "11") { return 30; } else { return 31; } } function isLeapYear($year) { return (($year % 4 == "0" && $year % 100 != "0") || $year % 400 == "0"); } function dayOfWeek($month,$year) { if ($month > 2) { $month -= 2; } else { $month += 10; $year--; } $day = ( floor((13 * $month - 1) / 5) + $this->day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * floor($year / 100) + 77); $weekday_number = (($day - 7 * floor($day / 7))); return $weekday_number; } function getWeekDay() { $week_day = mwCalendar::dayOfWeek($this->month,$this->year); //return $this->wday_names[$week_day]; return $week_Day; } function showThisMonth() { $output = ; // reset var$output = '
'. $this->wmonth_names[$this->pmonth] . " " .$this->year .' | ||||||
'. $this->wday_names[$i]. ' | '; $output .= '||||||
'; | ' . $i . ' | ' . $i . ' | </tr>';' . $i . ' | ';' . $i . ' | ';
return $output; }
}
?>