User:Eric Bouliane/MWCalendar

=MediaWiki Calendar=

Installation
require_once("extensions/MWCalendar.php");
 * Save MWCalendar.php to ./extensions folder.
 * Open LocalSettings.php and append :

Hook

 *  ... Data ... 

Arguments

 * Display: Integer. This will show X number of months. (Default 1)
 * MonthSkip: Integer. Skip X number of months. (Default 1)


 * Year: Integer. Which Year to start with. (Default Current)
 * TitleYear: Boolean. Show year title or not. (Default True)


 * Month: Integer. Which Month to start with. (Default Current)
 * TitleMonth: Boolean. Show month title or not. (Default True)


 * MonthNames: String. Comma delimited values for all 12 months. (Default January,February,March,April,May,June,July,August,September,October,November,December)
 * DaysOfWeek: String. Comma delimited values for all 7 days of the week. (Default Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)
 * StartDay: Integer. Value between 0 and 6. 0=Sunday..6=Saturday for start of week. (Default 0)


 * Classes: All Strings. Value for given item. (Default Blank)
 * ClassTable: Entire Table
 * ClassTableRow: All Rows
 * ClassTableCell: All Cells
 * ClassTableCellToday: Today's Cell
 * ClassTableDOW: Days of Week row.
 * ClassTableMonth: Month row.
 * ClassTableYear: Year row.


 * Styles: All Strings. Value for given item. (Default Blank)
 * StyleTable: Entire Table
 * StyleTableRow: All Rows
 * StyleTableCell: All Cells
 * StyleTableCellToday: Today's Cell (Default Red Text)
 * StyleTableDOW: Days of Week row.
 * StyleTableMonth: Month row.
 * StyleTableYear: Year row.


 * TableBorder: Integer. Size of border. (Default 1)
 * TableCellSpacing: Integer. Spacing between cells. (Default 0)
 * TableCellPadding: Integer. Spacing within cell. (Default 1)


 * DayUnderline: Boolean. Underline day in calender. (Default true)

Data

 * YYYY-MM-DD ::: Data: For One Day
 * YYYY-MM-DD ::: YYYY-MM-DD ::: Data: For Range Of Days
 * %YYYY-MM-DD ::: Data: To omit one day of data.
 * YYYY-MM-DD E xD ::: YYYY-MM-DD ::: Data: Every x days within range.
 * YYYY-MM-DD E xW ::: YYYY-MM-DD ::: Data: Every x week(s) within range.
 * YYYY-MM-DD E xM ::: YYYY-MM-DD ::: Data: Every x month(s) within range.

Examples
''Examples only show images as the extension is not installed here. The output will be HTML, and linking and data can include html, it just cannot show up here.''

Example 1
 1978-08-13:::Eric's Birthday! 

Example 2


Holidays 2016-06-03 ::: Sorin



Example 3
 2007-07-19 E 2D ::: 2007-07-25 ::: In Oshawa %2007-07-21 ::: In Oshawa 2007-07-21 ::: Marcia's Wedding 

MWCalendar.php
";	}

return $retval; }

function MWCalendar_ConvertData($input) { // $day,$month,$year,$data settype($retval,"Array"); // Convert Each New Line Into Array $lines = explode("\n",$input); foreach($lines as $line) { $range = false; // Range Variable $line = ltrim($line); // Trim Whitespace // Verify If First Character Is Numeric if( is_numeric( $line[0] )) { $data = explode(":::",$line); //Explode Line foreach($data as $key=>$value) $data[$key] = trim($value); //Trim WhiteSpace if(is_numeric(substr($data[1],0,1)) && isset($data[2])) $range = true;

//Format Date Variables $dataInterval = strtoupper( trim( substr($data[0],11) ) ); $data[0] = date('Y-m-d',strtotime(substr($data[0],0,10))); $data[1] = (sizeof($data)==3) ? date('Y-m-d',strtotime($data[1])) : $data[1];

// Set Temporary Date Variables $date1 = strtotime($data[0]); //Set Date 1 $date2 = ($range) ? strtotime($data[1]) : strtotime($data[0]); //Set Date 2 with Range If Not Default Date 1 $calData = ($range) ? $data[2] : $data[1];

//Loop Date Range $interval=0; for( $x=$date1 ; $x<=$date2 ; $x=mktime(0,0,0,date('m',$date1),date('d',$date1)+$interval,date('Y',$date1)) ) { $retval[] = Array("day"=>date('d',$x),"month"=>date('m',$x),"year"=>date('Y',$x),"data"=>$calData); $interval = MWCalendar_SetInterval($interval,$dataInterval);

}		}		// Verify If First Character Is % (To Ommit Range) elseif( $line[0] == "%" ) { $data = explode(":::",$line); foreach($data as $key=>$value) $data[$key]=trim($value); //Trim WhiteSpace if(sizeof($data)==2) { $data[0] = date('Y-m-d',strtotime(substr($data[0],1))); //Format Date Variables foreach($retval as $key=>$value) { if($value['year']."-".$value['month']."-".$value['day'] == $data[0] && $value['data']==$data[1]) unset($retval[$key]); }			}		}		unset($range); }	return $retval; }

function MWCalendar_SetInterval($current, $dataInterval) { $newInterval = $current + 1;

$id = substr($dataInterval,0,1); $modifier = substr($dataInterval,-1,1); $count = substr($dataInterval, 2, -1);

if( $id == "E" ) { switch( $modifier ) { case "M": if(is_numeric($count)) $newInterval = $current + 30 * $count; break; case "W": if(is_numeric($count)) $newInterval = $current + 7 * $count; break; case "D": if(is_numeric($count)) $newInterval = $current + 1 * $count; break; }	}

return $newInterval; }

class MWCalendar { #####################################	# Public Methods #####################################	public function setDayNames($names) { $this->dayNames = $names; } public function setHTMLClasses($table="", $table_row="", $table_cell="", $table_cell_today="", $table_dow="", $table_year="", $table_month="") { $this->class_table = (strlen($table)>0) ? "class=\"".$table."\"" : ""; $this->class_table_row = (strlen($table_row)>0) ? "class=\"".$table_row."\"" : ""; $this->class_table_cell = (strlen($table_cell)>0) ? "class=\"".$table_cell."\"" : ""; $this->class_table_cell_today = (strlen($table_cell_today)>0) ? "class=\"".$table_cell_today."\"" : ""; $this->class_table_dow = (strlen($table_dow)>0) ? "class=\"".$table_dow."\"" : ""; $this->class_table_month = (strlen($table_month)>0) ? "class=\"".$table_month."\"" : ""; $this->class_table_year = (strlen($table_year)>0) ? "class=\"".$table_year."\"" : ""; }	public function setHTMLStyles($table="", $table_row="", $table_cell="", $table_cell_today="", $table_dow="", $table_year="", $table_month="") { $this->style_table = (strlen($table)>0) ? "style=\"".$table."\"" : ""; $this->style_table_row = (strlen($table_row)>0) ? "style=\"".$table_row."\"" : ""; $this->style_table_cell = (strlen($table_cell)>0) ? "style=\"".$table_cell."\"" : ""; $this->style_table_cell_today = (strlen($table_cell_today)>0) ? "style=\"".$table_cell_today."\"" : ""; $this->style_table_dow = (strlen($table_dow)>0) ? "style=\"".$table_dow."\"" : ""; $this->style_table_month = (strlen($table_month)>0) ? "style=\"".$table_month."\"" : ""; $this->style_table_year = (strlen($table_year)>0) ? "style=\"".$table_year."\"" : ""; }	public function setDayUnderline($value) { $this->dayUnderline = ($value==1) ? true : false; } public function setMonthNames($names) { $this->monthNames = $names; } public function setStartDay($day) { $this->startDay = $day; } public function setStartMonth($month) { $this->startMonth=$month; } public function setIncludeData($day,$month,$year,$data) { $this->includeData[$this->includeDataCount]['day'] = $day; $this->includeData[$this->includeDataCount]['month'] = $month; $this->includeData[$this->includeDataCount]['year'] = $year; $this->includeData[$this->includeDataCount]['data'] = $data; $this->includeDataCount++; }

#####################################	# Private Methods #####################################	private function getDayNames { return $this->dayNames; } private function getMonthNames { return $this->monthNames; } private function getStartDay { return $this->startDay; } private function getStartMonth { return $this->startMonth; } private function getCurrentMonthView { $d = getdate(time); return $this->getMonthView($d["mon"], $d["year"]); } private function getMonthView($month, $year) { return $this->getMonthHTML($month, $year); } public function Calendar { $this->setStartMonth(date("m")); }

private function getDaysInMonth($month, $year) { if ($month < 1 || $month > 12) return 0; $d = $this->daysInMonth[$month - 1]; if ($month == 2) $d = checkdate($month, 29, $year) ? 29 : 28;		return $d; }

private function adjustDate($month, $year) { $a = array; $a[0] = $month; $a[1] = $year; while ($a[0] > 12) { $a[0] -= 12; $a[1]++; }		while ($a[0] <= 0) { $a[0] += 12; $a[1]--; }		return $a; }

public function getMonthHTML($m, $y) { $s = ""; $a = $this->adjustDate($m, $y); $month = $a[0]; $year = $a[1]; $daysInMonth = $this->getDaysInMonth($month, $year); $date = getdate(mktime(12, 0, 0, $month, 1, $year)); $first = $date["wday"]; $monthName = $this->monthNames[$month - 1];

return $s; }
 * 1) 		$s .= " \n";

var $startDay = 0; var $startMonth; var $dayNames = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var $monthNames = array("January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"); var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var $showYear = true; var $showMonth = true; var $showDaysOfWeek = true; var $includeData = Array; var $includeDataCount = 0; var $class_table, $class_table_row, $class_table_cell, $class_table_dow, $class_table_month, $class_table_year, $class_table_cell_today; var $style_table, $style_table_row, $style_table_cell, $style_table_dow, $style_table_month, $style_table_year, $style_table_cell_today; var $dayUnderline = true;

}

$wgExtensionCredits['parserhook'][] = array(		'name' => 'MWCalendar',		'version' => '1.0.7',		'author' => 'Eric Bouliane (ebouliane@gmail.com)',		'url' => 'http://www.cosil.ca',		'description' => 'Mediawiki Calendar Extension' );

?>