[ Index ] |
PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12) |
[Summary view] [Print] [Text view]
1 <?php 2 3 //////////////////////////////////////////////////////// 4 5 // PHP Calendar (version 2.3), written by Keith Devens 6 // http://keithdevens.com/software/php_calendar 7 // see example at http://keithdevens.com/weblog 8 // License: http://keithdevens.com/software/license 9 10 // enhanced by Oliver Georgi for phpwcms 11 12 13 function generate_calendar($param=array()){ 14 15 if(!defined('THIS_YEAR')) define('THIS_YEAR', date('Y') ); 16 if(!defined('THIS_MONTH')) define('THIS_MONTH', date('n') ); 17 if(!defined('THIS_DAY')) define('THIS_DAY', date('j') ); 18 19 $year = empty($param['year']) ? THIS_YEAR : $param['year']; 20 $month = empty($param['month']) ? THIS_MONTH : $param['month']; 21 $day_name_length = empty($param['day_name_length']) ? 3 : $param['day_name_length']; 22 $month_href = empty($param['month_href']) ? NULL : $param['month_href']; 23 $first_day = empty($param['first_day']) ? 0 : $param['first_day']; 24 $weekNr = empty($param['weekNr']) ? true : $param['weekNr']; 25 $weekNrTitle = empty($param['weekNrTitle']) ? 'Wno' : $param['weekNrTitle']; 26 $styleAdd = empty($param['styleAdd']) ? '' : $param['styleAdd']; 27 $pn = isset($param['pn']) && is_array($param['pn']) ? $param['pn'] : array(); 28 $days = isset($param['days']) && is_array($param['days']) ? $param['days'] : array(); 29 $locale = empty($param['locale']) ? false : $param['locale']; 30 31 // set correct locale 32 if($locale) { 33 $_oldLocale = setlocale(LC_TIME, NULL); //save current locale 34 setlocale(LC_TIME, $locale); 35 } 36 37 38 $first_of_month = gmmktime(0,0,0,$month,1,$year); 39 //remember that mktime will automatically correct if invalid dates are entered 40 // for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998 41 // this provides a built in "rounding" feature to generate_calendar() 42 43 $day_names = array(); //generate all the day names according to the current locale 44 for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) {//January 4, 1970 was a Sunday 45 $day_names[$n] = ucfirst(gmstrftime('%A',$t)); //%A means full textual day name 46 } 47 48 @list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month)); 49 $weekday = ($weekday + 7 - $first_day) % 7; //adjust for $first_day 50 $title = htmlentities(ucfirst($month_name)).' '.$year; //note that some locales don't capitalize month and day names 51 $YYYYmm = $year.$month; 52 53 //Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03 54 @list($p, $pl) = each($pn); 55 @list($n, $nl) = each($pn); //previous and next links, if applicable 56 if($p) $p = '<span class="calendarPrev'.$styleAdd.'">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> '; 57 if($n) $n = ' <span class="calendarNext'.$styleAdd.'">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>'; 58 $calendar = '<table class="calendar'.$styleAdd.'" summary="Calendar">'."\n"; 59 60 $calendar .= "<tr>\n"; 61 if($weekNr) { 62 $calendar .= "\t".'<td colspan="8" align="center" class="calendarMonth'.$styleAdd.'"><strong>'; 63 } else { 64 $calendar .= "\t".'<td colspan="7" align="center" class="calendarMonth'.$styleAdd.'"><strong>'; 65 } 66 $calendar .= $p; 67 $calendar .= $month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title; 68 $calendar .= $n; 69 $calendar .= "</strong></td>\n</tr>\n<tr>\n"; 70 71 if($weekNr) { 72 $calendar .= "\t".'<td class="calendarWeekNoTitle'.$styleAdd.'">'.$weekNrTitle."</td>\n"; 73 $weekStart = date('W', $first_of_month); 74 } 75 76 if($day_name_length){ //if the day names should be shown ($day_name_length > 0) 77 //if day_name_length is >3, the full name of the day will be printed 78 foreach($day_names as $d) { 79 $calendar .= "\t".'<td class="calendarDayName'.$styleAdd.'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d)."</td>\n"; 80 } 81 $calendar .= "</tr>\n<tr>\n"; 82 } 83 84 if($weekday > 0) { 85 if($weekNr) { 86 $calendar .= "\t".'<td class="calendarWeek'.$styleAdd.'">'.$weekStart."</td>\n"; 87 $weekStart++; 88 } 89 $calendar .= "\t".'<td colspan="'.$weekday.'"> </td>'."\n"; //initial 'empty' days 90 } 91 for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++) { 92 93 if($weekday == 7) { 94 $weekday = 0; //start a new week 95 $calendar .= "</tr>\n<tr>\n"; 96 } 97 if($weekNr && $weekday == 0) { 98 $calendar .= "\t".'<td class="calendarWeek'.$styleAdd.'">'.$weekStart."</td>\n"; 99 $weekStart++; 100 } 101 102 $thisSelected = (intval($year) == THIS_YEAR && intval($month) == THIS_MONTH && $day == THIS_DAY) ? true : false; 103 104 $checkDay = $YYYYmm . substr('0'.$day, -2); 105 if(isset($days[$checkDay]) && is_array($days[$checkDay])){ 106 @list($link, $classes, $content) = $days[$checkDay]; 107 @list($link, $target) = explode(' ', trim($link)); 108 $target = $target ? ' target="'.$target.'"' : ''; 109 if(is_null($content)) { 110 $content = $day; 111 } 112 if($thisSelected) { 113 $content = '<span class="calendarSelectedDay'.$styleAdd.'">'.$content.'</span>'; 114 } 115 $calendar .= "\t<td"; 116 if($classes) { 117 $calendar .= ' class="'.htmlspecialchars($classes).'"'; 118 } 119 $calendar .= '>'; 120 $calendar .= $link ? '<a href="'.htmlspecialchars($link).'"'.$target.'>'.$content.'</a>' : $content; 121 $calendar .= "</td>\n"; 122 } else { 123 $calendar .= "\t"; 124 $calendar .= $thisSelected ? '<td class="calendarSelectedDay'.$styleAdd.'">' : '<td>'; 125 $calendar .= $day."</td>\n"; 126 } 127 } 128 if($weekday != 7) { 129 $calendar .= "\t".'<td colspan="'.(7-$weekday).'"> </td>'."\n"; //remaining "empty" days 130 } 131 132 if($locale) { 133 setlocale(LC_TIME, $_oldLocale); //switch current locale back to old value 134 } 135 136 return $calendar."</tr>\n</table>\n"; 137 } 138 139 function tzdelta ( $iTime = 0 ) { 140 if ( 0 == $iTime ) { $iTime = time(); } 141 $ar = localtime ( $iTime ); 142 $ar[5] += 1900; $ar[4]++; 143 $iTztime = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] ); 144 return ( $iTztime - $iTime ); 145 } 146 147 148 ///////////////////////////////////////////////////////////////////////////////////// 149 150 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 29 16:31:14 2012 | Cross-referenced by PHPXref 0.7.1 |