=====JW Calendar action reviewed===== >>Working for 1.1.6.0 to 1.1.6.4 (latest)>>{{lastedit show="2"}} I like the idea of WikiCalendar, but I would like to get more from this. I have been reworking this code to trigger the opening/creation of a dedicated WikiPage when you click on any day. The idea is to be able to use **personal calendars** as well as **project type calendars**. So you can allocate a **calendar name** (must be a CamelCase name) and call the action like this: ""{{calendar month="11" year="2004" calendarname="MyProject"}}"" The optional calendarname is defaulted to the user WikiName. When you then click on the 30th of November, the system will open a page named MyProject20041130. It would be a good idea to group such pages under a dedicated category like CategoryCalendarMyProject. //I would like to improve this further on by checking if a page already exists for each day and have a different style or an icon pointing this.// //I would also allow as an option to include the page of the selected day close to the calendar itself.// ~& I noticed that the code is already doing this. However, it was using the ExistsPage() method which means it was sending one query per date. A much more efficient solution follows. It should be inserted into the code around line 86 (where the todo for the camel case check is). -- DennyShimkoski %%(php) $existingPages = array(); $result = $this->Query('SELECT tag FROM ' . $this->config['table_prefix'] . "pages WHERE tag REGEXP('$calendar_name\[0-9]{8,8}')"); if (mysql_num_rows($result)) while ($row = mysql_fetch_array($result)) $existingPages[] = $row['tag']; %% Then line 216 (call to ExistsPage()) should be replace with %%(php) if (in_array($pagename, $existingPages)) %% The CSS should probably be changed too. For instance, in line 232, the $dayclass is being applied to the anchor tag. It would probably give the CSS wizards more room to fly if we changed it to %%(php) echo ' '.$day."\n"; %% Then we can change the CSS definition from table.calendar a.created to table.calendar td.created. The end result is the full cell being colored in, rather than just the area of the anchor tag. ... Just added some more calendar ideas to DennysCalendarExperiments. Added in the header: %%(php) * @input string $calendarname optional: prefix for the calendar pages to be created - Must be a CamelCase word; * default: WikiName from the user %% Added in the constants section: %%(php) define ('USER_NAME',$this->GetUserName()); define ('BASE_URL',$this->config['base_url']); %% Added in the PARAMETERS Interface %%(php) $calendarname = USER_NAME; %% Added a few lines after in the PARAMETERS Interface part 1) %%(php) $uCalendarname = $vars['calendarname']; if ($uCalendarname) $calendarname = $uCalendarname; //ToDo: check that it is a CamelCase word %% Changed in the output section (provided that the [[WikkaDevelopment ExistsPage()]] function is part of the Wikka object in wikka.php) %%(php) Old: // handle markup for current day or any other day $calday = sprintf('%4d:%02d:%02d',$year,$month,$day); if ($calday == $today) { echo ' '.$day."\n"; } else { echo ' '.$day."\n"; } // end week row New: // handle markup for current day or any other day $calday = sprintf('%4d:%02d:%02d',$year,$month,$day); $pagename = sprintf('%s%4d%02d%02d', $calendarname,$year,$month,$day); if ($this->ExistsPage($pagename)) { $pagename = BASE_URL.$pagename; $dayclass = '"created"'; } else { $pagename = sprintf('%s%s/edit', BASE_URL,$pagename); $dayclass = '"new"'; } if ($calday == $today) { echo ' '.''.$day."\n"; } else { echo ' '.''.$day."\n"; } // end week row %% Added in the CSS file something like this with less awful colors :-( %%(css) table.calendar a.created { color: #AABBFF; background-color: #00CCCC; text-decoration: none; } %% In case you just want the full code after modification: ---- %%(php) GetUserName()); define ('BASE_URL',$this->config['base_url']); # i18n // ***** END CONSTANTS section ***** // ***** (ACTION) PARAMETERS Interface ***** // set parameter defaults: current year and month $year = CUR_YEAR; $month = CUR_MONTH; $calendarname = USER_NAME; // get and interpret parameters // 1) overrride defaults with parameters provided in URL (accept only valid values) if (isset($_GET['year'])) { $uYear = (int)$_GET['year']; if ($uYear >= MIN_YEAR && $uYear <= MAX_YEAR) $year = $uYear; } if (isset($_GET['month'])) { $uMonth = (int)$_GET['month']; if ($uMonth >= 1 && $uMonth <= 12) $month = $uMonth; } $uCalendarname = $vars['calendarname']; if ($uCalendarname) $calendarname = $uCalendarname; //ToDo: check that it is a CamelCase word // 2) override with parameters provided in action itself (accept only valid values) $hasActionParams = FALSE; if (is_array($vars)) { foreach ($vars as $param => $value) { switch ($param) { case 'year': $uYear = (int)trim($value); if ($uYear >= MIN_YEAR && $uYear <= MAX_YEAR) { $year = $uYear; $hasActionParams = TRUE; } break; case 'month': $uMonth = (int)trim($value); if ($uMonth >= 1 && $uMonth <= 12) { $month = $uMonth; $hasActionParams = TRUE; } break; } } } // ***** (ACTION) PARAMETERS Interface ***** // ***** DERIVED VARIABLES ***** // derive which weekday the first is on $datemonthfirst = sprintf('%4d-%02d-%02d',$year,$month,1); $firstwday = strftime('%w',strtotime($datemonthfirst)); # i18n // derive (locale-specific) caption text $monthYear = strftime(LOC_MON_YEAR,strtotime($datemonthfirst)); # i18n $summary = sprintf(FMT_SUMMARY, $monthYear); # i18n // derive last day of month $lastmday = $daysInMonth[$month - 1]; if (2 == $month) # correct for leap year if necessary { if (1 == date('L',strtotime(sprintf('%4d-%02d-%02d',$year,1,1)))) $lastmday++; } // derive "today" to detect when to mark this up in the calendar face $today = date("Y:m:d",mktime()); // build navigation variables - locale-specific (%B gets full month name) // FIXME: @@@ take care we don't go over date limits for PHP if (!$hasActionParams) { // previous month $monthPrev = ($month-1 < 1) ? 12 : $month-1; $yearPrev = ($month-1 < 1) ? $year-1 : $year; $parPrev = "month=$monthPrev&year=$yearPrev"; $urlPrev = $this->Href('', '', $parPrev); $titlePrev = strftime(LOC_MON_YEAR,strtotime(sprintf('%4d-%02d-%02d',$yearPrev,$monthPrev,1)));# i18n // current month $parCur = 'month='.CUR_MONTH.'&year='.CUR_YEAR; $urlCur = $this->Href('', '', $parCur); $titleCur = strftime(LOC_MON_YEAR,strtotime(sprintf('%4d-%02d-%02d',CUR_YEAR,CUR_MONTH,1))); # i18n // next month $monthNext = ($month+1 > 12) ? 1 : $month+1; $yearNext = ($month+1 > 12) ? $year+1 : $year; $parNext = "month=$monthNext&year=$yearNext"; $urlNext = $this->Href('', '', $parNext); $titleNext = strftime(LOC_MON_YEAR,strtotime(sprintf('%4d-%02d-%02d',$yearNext,$monthNext,1)));# i18n } // build array with names of weekdays (locale-specific) $tmpTime = strtotime("this Sunday"); # get a starting date that is a Sunday $tmpDate = date('d',$tmpTime); $tmpMonth = date('m',$tmpTime); $tmpYear = date('Y',$tmpTime); for ($i=0; $i<=6; $i++) { $aWeekdaysShort[$i] = strftime('%a',mktime(0,0,0,$tmpMonth,$tmpDate+$i,$tmpYear)); $aWeekdaysLong[$i] = strftime('%A',mktime(0,0,0,$tmpMonth,$tmpDate+$i,$tmpYear)); } // ***** END DERIVED VARIABLES ***** // ***** OUTPUT SECTION ***** ?> 0) { echo " \n"; } // fill start of first week with blank cells before start of month for ($i=1; $i<=$firstwday; $i++) { echo ' '."\n"; } // loop through all the days of the month $day = 1; $wday = $firstwday; while ($day <= $lastmday) { // start week row if ($wday == 0) { echo " \n"; } // handle markup for current day or any other day $calday = sprintf('%4d:%02d:%02d',$year,$month,$day); $pagename = sprintf('%s%4d%02d%02d', $calendarname,$year,$month,$day); if ($this->ExistsPage($pagename)) { $pagename = BASE_URL.$pagename; $dayclass = '"created"'; } else { $pagename = sprintf('%s%s/edit', BASE_URL,$pagename); $dayclass = '"new"'; } if ($calday == $today) { echo ' \n"; } else { echo ' \n"; } // end week row if ($wday == 6) { echo " \n"; } // next day $wday = ++$wday % 7; $day++; } // fill week with blank cells after end of month if ($wday > 0) { for ($i=$wday; $i<=6; $i++) { echo ' '."\n"; } } // end row for last week if ($wday < 6) { echo " \n"; } ?>
 
'.''.$day."'.''.$day."
 
<< = >>
%% ---- CategoryUserContributions