=====Calendar Link Action===== >>==See also:== Documentation: CalendarLinkActionInfo.>>This is the development page for the Calendar Link action. The code still needs some cleanup.::c:: %%(php) GetUserName()); define ('BASE_URL',$this->config['base_url']); # i18n define ('REGEX_CAMEL_WORD','([A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*)'); define ('REGEX_CAL_DATE', '([0-9]{8,8})'); define ('REGEX_CAL_ENTRY', REGEX_CAMEL_WORD.REGEX_CAL_ENTRY); // ***** END CONSTANTS section ***** // Get name of calendar to work with $current_page = $this->GetPageTag(); if($this->getUser()) // Initialize $calendarname with current user's name if logged in { $cal_name = $this->getUser(); } else // use current page tag { $cal_name = $current_page; } if(isset($vars['calendarname'])) // Check for parameter calendarname { $cal_name = $vars['calendarname']; } elseif(preg_match(REGEX_CAL_DATE,$current_page,$cal_date)) // Check if current page is a calendar entry and use the corresponding calendar. { // echo 'currentpage='.$current_page; // debug // print_r($cal_date); // debug $cal_name = substr($current_page,0,strpos($current_page, $cal_date[0])); } else // don't change prior init { $cal_name = $cal_name; } // END of getting calendar name // Get link mode and convert to lower case if(isset($vars['link'])) $mode = $vars['link']; else $mode = 'today'; $mode=mb_strtolower($mode); // END link mode acquisition // check parameter date has been provided if(isset($vars['date']) && preg_match(REGEX_CAL_DATE,$vars['date'],$cal_date)) { $date = $cal_date[0]; } else // it has not been provided so we will use today as date { $cal_date = getdate(); $date = sprintf("%4d%02d%02d",$cal_date['year'],$cal_date['mon'],$cal_date['mday']); } if(isset($vars['offset'])) { $offset = $vars['offset']; list($year, $mon, $mday) = sscanf($date, "%4d%02d%02d"); $cal_date = getdate(mktime(0,0,0,$mon, $mday+$offset, $year)); $date = sprintf("%4d%02d%02d",$cal_date['year'],$cal_date['mon'],$cal_date['mday']); } if($mode!='today') // we only need the list of calendar entries if we want some other day than (calculated) today { $result = $this->Query('SELECT tag FROM ' . $this->config['table_prefix'] . "pages WHERE tag REGEXP('^$cal_name\[0-9]{8,8}') AND latest = 'Y'"); if (mysql_num_rows($result)) while ($row = mysql_fetch_array($result)) $tags[] = $row['tag']; } if($mode=='following'||$mode=='latest'||$mode=='today') { // creating a virtual calendar entry to use the code for $link=='next' or $link=='prev' on this virtual entry $entry = sprintf("%s%8d",$cal_name,$date); // picking the relative origin based on calculated date $tags[] = $entry; } else { $entry = $this->GetPageTag(); // picking the relative origin based on current page assuming it is calendar page } sort($tags); //sorting tags -- in case of a virtual calendar entry this will be now be in order, else the calendar entries are just sorted $key = array_search($entry,$tags); // getting position of our relative origin in the array $date_found = FALSE; if($mode=='next'||$mode=='following') { if($key<(count($tags)-1)) { $target_date = $tags[$key+1]; $date_found = TRUE; } else { $target_date = LAST_ENTRY; $date_found = FALSE; } } elseif($mode=='prev'||$mode=='latest') { if($key>0) { $target_date = $tags[$key-1]; $date_found = TRUE; } else { $target_date = FIRST_ENTRY; $date_found = FALSE; } } elseif($mode=='today') { $target_date = $entry; $date_found = TRUE; } if ($date_found) { echo $this->Link($target_date); } else { echo $target_date; } %% ---- CategoryDevelopmentActions