. The effect is that it'll clear the right-justification of the block of calendars. Here are some other switches that are recognized, along with their default values (if none is specified by the user): 'months' => '1' 'year' => {{current year}} 'month' => {{current month}} 'offset' => '0' 'wrap' => '4' 'align' => '' 'width' => '' 'links' => 'true' 'group' => 'Calendar' * History * May 26, 2004 - Added 'offset' feature to start calendar at the current month plus/minus any number of months. May 10, 2004 - Beta - Ready for public tesing. - Added "group" directive. Now you can link to any calendar from any group/page simply by including the group= parameter in the [[calendar:]] directive. Apr 30, 2004 - Alpha, not release to public. /*--------------------------------------------------------------- USER DEFINED VARIABLES /*--------------------------------------------------------------- To save memory and cpu time, and also to keep the script's variables seperate from PmWiki's global scope, I decided to put them in their own function which is only called when the [[calendar:]] directive is encountered. You can check that function (below)if you really want to over-ride the defaults, but there's really no need since you can easily do so by using the available switches. /*--------------------------------------------------------------- This is the beginning of the script's php code. You should'nt need to modify anything below this point. /*-------------------------------------------------------------*/ //---------------------------------------------------------------------- function xCal_SetParams(& $xCalParams, & $WikiParams, & $xCalVars){ //---------------------------------------------------------------------- global $pagename; $title = FmtPageName('$Title', $pagename); $group = FmtPageName('$Group', $pagename); $today = getdate(); $pieces = explode(" ", $WikiParams); // passed by the user in [[x-calendar:]] directive foreach($pieces as $apart) { list($key,$value) = explode("=", $apart); $xCalParams["$key"] = $value; } $xCalVars['title'] = $title; $xCalVars['titleprefix'] = 'Diary'; // user defineable $xCalVars['date_separator'] = ''; // typical seperators might include: - . / _ //$pattern_date = "([0-9]{4})" . $date_separator . "([0-9]{1,2})" . $date_separator . "([0-9]{1,2})"; $pattern_year = "([0-9]{4})"; $pattern_day = "([0-9]{1,2})"; // could be improved [0-3][0-9] eg. 01 .. 31 $pattern_month = $pattern_day; // could be improved [0-1][0-9] eg. 01 .. 12 $pattern_date = "$pattern_year" . $xCalVars['date_seperator'] . "$pattern_month" . $xCalVars['date_seperator'] . "$pattern_day" . $xCalVars['date_seperator']; /*If the page being viewed is a calendar entry (eg. the title is a valid date), then the calendars to display (if any) should start from the entry date +/- the offset (not today's date). */ SDV($xCalParams['offset'],0); if (ereg($pattern_date, $title, $regs)) { $year = $regs[1]; $month = $regs[2]; $day = $regs[3]; $display_date = getdate(mktime(0,0,0,$month, $day, $year)); $start_date = getdate(mktime(0,0,0,$month + $xCalParams['offset'], $day, $year)); $xCalVars['fancytitle'] = "

" . $display_date['weekday'] . ", " . $display_date['month'] . " " . $display_date['mday'] . ", " . $display_date['year'] . "

"; } else { $start_date = getdate(mktime(0,0,0, $today['mon'] + $xCalParams['offset'], $today['mday'], $today['year'])); $xCalVars['fancytitle'] = ''; } // $date = getdate(mktime(,0,0,$year,$month,$day); // what ever is left that hasn't yet been set SDVA($xCalParams, array( 'months' => '1', 'year' => $start_date['year'], 'month' => $start_date['mon'], 'offset' => '0', // redundant, previously set 'wrap' => '4', 'align' => '', 'width' => '', 'links' => 'true', 'group' => $group)); if ($xCalVars['titleprefix'] == '') { // Only enable this chunk of code below if you need pagenames that start with a digit. // Note that this change is site-wide .. so it affects your entire wiki, not just // Calendar pages. It's suggested to use Calendar Prefix instead (see options below) //global $TitlePattern, $PageTitlePattern, $GroupFreeLinkPattern; $AnyLetter = "[A-Za-z0-9]"; $TitlePattern = "[A-Z0-9]$AnyLetter*"; //$PageTitlePattern = "$TitlePattern(-$AnyLetter+)*(~$TitlePattern)?"; global $PageTitlePattern; $PageTitlePattern = "$TitlePattern(?:-$AnyLetter+)*(?:~$TitlePattern)?"; global $GroupFreeLinkPattern; $GroupFreeLinkPattern="{{(?>(?:($GroupNamePattern)([.\\/]))?([[:alnum:]]+(?:(?:[\\s_]*|[-~])[[:alnum:]]+)*)(?:\\|((?:(?:[\\s_]*|[-~])[[:alnum:]])*))?)}}((?:-?[[:alnum:]]+)*)"; global $FreeLinkPattern; $FreeLinkPattern="{{($AnyLetter+(?:(?:\s*|[-~])$AnyLetter+)*)(?:\\|((?:(?:\s*|[-~])$AnyLetter)*))?}}((-?$AnyLetter)*)"; } } //---------------------------------------------------------------------- function xCalendar($UserPreferences) { //---------------------------------------------------------------------- global $HTMLHeaderFmt, $PubDirUrl; xCal_SetParams($xCalParams, $UserPreferences, $xCalVars); if ($xCalParams['months'] == 0) return; // doesn't print calendar on every page unless a valid date is detected. $html = "\n\n\n"; $html .= "\n "; $cal_count = 0; while ($cal_count < $xCalParams['months']) { // $month = $xCalParams['month'] + $cal_count; $epoch_date = mktime(0,0,0,($xCalParams['month'] + $cal_count),1,$xCalParams['year']); $showlinks = $xCalParams['links']; $html .= "\n"; $html .= gen_calendar($epoch_date, $xCalParams, $xCalVars); $html .= "\n\n "; $cal_count++; if ( (($cal_count % $xCalParams['wrap']) == 0) && ($cal_count < $xCalParams['months']) ) {$html .= "\n ";} } // while $html .= " \n"; if (isset($xCalVars['fancytitle']) && $xCalParams['links'] == 'true') {$html .= "\n" . $xCalVars['fancytitle'];} $html .= "\n\n\n"; return Keep($html); } //---------------------------------------------------------------------- function gen_calendar($epochdate, & $xCalParams, & $xCalVars){ //---------------------------------------------------------------------- global $ScriptUrl; $weekdays = array('S','M','T','W','T','F','S'); // will move this to xCalVar later $num_days_in_month = date('t', $epochdate); $today = getdate(); $date = getdate($epochdate); // $month = date('n', $epochdate); // $date['month']; $showlinks = $xCalParams['links']; // start the calendar, and label the month/year $html = "\n \n" . " \n" . " "; // label the week days (S M T W T F S) foreach($weekdays as $dayofweek) {$html .= "";} // pad empty days (before 1st day of month) $html .= "\n "; $current_day = 1; $current_week_day = $date['wday']; if ($current_week_day > 0) {$html .= "";} // for each day of the month, do the following ... while ($current_day <= $num_days_in_month){ if($current_week_day == 7){ $current_week_day = 0; $html .= "\n "; } $date_separator = $xCalVars['date_separator']; $PageName = $xCalParams['group'] . "/" . $xCalVars['titleprefix'] . $date['year'] . $dateseparator . ( ($date['mon'] < 10) ? ("0" . $date['mon']) : ($date['mon']) ) . $date_separator . ( ($current_day < 10) ? ("0" . $current_day) : ($current_day) ); $is_date_today = false; if ( ($date['year']==$today['year']) && ($date['mon']==$today['mon']) && ($current_day==$today['mday'])) {$is_date_today = true;} if ($showlinks==true or $showlinks=='yes') { // set $Url Class if (PageExists($PageName)) // expensive! 30 disk reads per calendar {$is_date_today ? $UrlClass = "x-calendar-link-today-exists" : $UrlClass = "x-calendar-link-day-exists";} else {$is_date_today ? $UrlClass = "x-calendar-link-today-empty" : $UrlClass = "x-calendar-link-day-empty";} } // if showlinks == false, then set the $UrlClass simply else {($is_date_today) ? $UrlClass = "x-calendar-link-today-empty" : $UrlClass= "x-calendar-link-day-empty";} $html .= ""; $current_day++; $current_week_day++; } // pad empty days (after last day of month) if ($current_week_day < 7) {$html .= "";} // finish of the table $html .= "\n
" . date('F', $epochdate) . " " . date('Y', $epochdate) . "
$dayofweek
 
"; if ($showlinks == 'true') {$html .= "";} if ($current_day < 10) {$html .= "0";} $html .= $current_day; if ($showlinks == 'true') {$html .= "";} $html .= " 
"; return $html; } /*---------------------------------------------------------------------- //function xCal_PageTitle($PageTitle){ //---------------------------------------------------------------------- If I ever figure out regexp, then I'll implement this. I'll add a variety of options for valid dates later, examples: $DatePattern2 = "([0-9]{4})[-([0-9]{1,2})"; // Match four digits, followed by -, followed by atleast one but no more than two digits $DatePattern3 = "([0-9]{4})"; // Match four digits } */ $HTMLHeaderFmt[] = "\n"; $DoubleBrackets["/\\[\\[x-calendar:(.*?)\\]\\]/e"] = 'xCalendar("$1");'; ?>