=====Oh No! Not more calendar experiments!===== ====Why This Page?==== I've already been to JwCalendarWithPageCreation a few times tonight, and rather than clutter up the page, I decided to post ideas here. ====Idea Number One==== It would be nice if the created pages could include an overview for the calendar display. This overview would be ideal if it was relatively transparent to the user and also allowed for wiki text formatting. However, the problem with this is that we don't want to run the wiki engine's Format() method 28+ times. Have you seen that thing? Monster! Rarrrr! Fortunately, there is workaround. Instead of calling it a thousand times, we simply gather everything into one big text variable, pass it through the formatter, and then split it back into individual items. Here is the first attempt, which should be inserted around line 87... %%(php) $existingPages = array(); $result = $this->Query('SELECT tag, body FROM ' . $this->config['table_prefix'] . "pages WHERE tag REGEXP('$calendar_name\[0-9]{8,8}') AND latest = 'Y'"); if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $tags[] = $row['tag']; $bodies[] = preg_match('/(=){3,5}overview(=){3,5}(.*)(\n\n)/ismU', $row['body'], $matches) ? $matches[3] : 'empty_body'; } } if (count($tags)) { $glue = '#&#&#&SEPARATE_SECTIONS&#&#&#'; $bodies = split($glue, $this->Format(join($glue, $bodies))); for ($i = 0; $i < count($tags); $i++) $existingPages[$tags[$i]] = ($bodies[$i] != 'empty_body') ? $bodies[$i] : null; } %% As you can see from the code listing, we loop through all potential calendar entries, pulling any blocks of text that have an Overview header. This means a user can click on a calendar entry, have a page created if it doesn't already exist, include an Overview section anywhere, click store and have the calendar display update automatically. A sample entry for clarification purposes: %% =====Overview===== This will be included in the calendar CamelCaseWorks [[http://google.com Everything Wiki as a matter of fact!]] This text will be excluded though... And so will this. %% The only optimization I can see off the bat is that we're not restricting by the month and year being viewed. In a large calendar, this will be an unnecessary burden. So... that's a definite todo (just not a todo right now). I think it might be handy if the wiki developers worked this method into the core. Something like -- fetchSection($heading). It should undoubtedly be divorced from the data source as it is above. The next bit of replacement code starts around line 229: %%(php) if (in_array($pagename, array_keys($existingPages))) { $url = BASE_URL.$pagename; $dayclass = 'created'; } else { $url = sprintf('%s%s/edit', BASE_URL,$pagename); $dayclass = 'new'; } $attr = ($calday == $today) ? 'title="'.TODAY.'" class="currentday"' : 'class="'.$dayclass.'"'; $overview = $vars['overviews'] && $existingPages[$pagename] ? "
$existingPages[$pagename]
" : ''; echo " $day$overview\n"; %% The check for existing pages has been optimized, a new parameter called "overviews" has been introduced, and an "overview" div has been added for CSS styling purposes. The overviews parameter defaults to false, so if you want to try it out, you'll need to do something like this: %% {{calendar overviews="true"}} %% Some CSS that works okay for testing purposes is: %%(css) table.calendar div.overview { text-align:left; } table.calendar div.overview a { font-size: 80%; } %% And here's the whole calendar.php action for your copy and pasting pleasure: %%(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 $existingPages = array(); $result = $this->Query('SELECT tag, body FROM ' . $this->config['table_prefix'] . "pages WHERE tag REGEXP('$calendar_name\[0-9]{8,8}') AND latest = 'Y'"); if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $tags[] = $row['tag']; $bodies[] = preg_match('/(=){3,5}overview(=){3,5}(.*)(\n\n)/ismU', $row['body'], $matches) ? $matches[3] : 'empty_body'; } } if (count($tags)) { $glue = '#&#&#&SEPARATE_SECTIONS&#&#&#'; $bodies = split($glue, $this->Format(join($glue, $bodies))); for ($i = 0; $i < count($tags); $i++) $existingPages[$tags[$i]] = ($bodies[$i] != 'empty_body') ? $bodies[$i] : null; } // 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 (in_array($pagename, array_keys($existingPages))) { $url = BASE_URL.$pagename; $dayclass = 'created'; } else { $url = sprintf('%s%s/edit', BASE_URL,$pagename); $dayclass = 'new'; } $attr = ($calday == $today) ? 'title="'.TODAY.'" class="currentday"' : 'class="'.$dayclass.'"'; $overview = $vars['overviews'] && $existingPages[$pagename] ? "
$existingPages[$pagename]
" : ''; 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$overview
 
<< = >>
%% ====Authors==== DennyShimkoski ---- CategoryUserContributions