Revision [16257]

This is an old revision of CalendarLinkAction made by MasinAlDujaili on 2007-03-05 19:53:31.

 


This is the development page for the Calendar Link action. The code still needs some cleanup.
 

<?php                                        
/**
 * Displays a link to a calendar entry based on parameter or current calendar entry
 *
 * @package Actions
 * @subpackage  Date and Time
 * @name    calendarlink
 *
 * @authors {@link http://wikkawiki.org/MasinAlDujaili Masin Al-Dujaili}
 * @version 0.1
 * @since   Wikka 1.1.6.2
 *
 * @input   string  $calendarname  optional: prefix for the calendar pages to be created - Must be a CamelCase word;
 *          default: WikiName from the user if logged on, else it's checked if the action sits on a calendar page
 * @input   string  $link optional: one of the following keywords: 'next', 'prev', 'following'
 *          default: 'next' if action sits on a calendar page else 'following'
 *          'next': only available if action sits on a calendar page. Returns the entry in the future relative to the current entry.
 *          'prev': only available if action sits on a calendar page. Returns the entry in the past relative to the current entry.
 *          'following': Returns the next entry in the future relative to the current date.
 * @input   int $scope optional: maximum number of days to search for desired entry
 *          default: 28
 *
 * @output  Link according to selection in parameter 'link'
 */


// l10n strings
define('LAST_ENTRY','Last entry');
define('FIRST_ENTRY','First entry');

// format string for locale-specific month (%B) + 4-digit year (%Y) used for caption and title attributes
// NOTE: monthname is locale-specific but order of month and year may need to be switched: hence the double quotes!
define ('USER_NAME',$this->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;
    print_r($cal_date);
    $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 = 'next';
//echo $mode."<br />"; //debug command
$mode=mb_strtolower($mode);
// END link mode acquisition

//echo count($tags)."<br />"; // debug command
$result = $this->Query('SELECT tag, body 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($vars['link']=='following')
{
    $today = getdate();
    $entry = sprintf("%s%4d%02d%02d",$cal_name,$today['year'],$today['mon'],$today['mday']);
    $tags[] = $entry;
}
else
{
    $entry = $this->GetPageTag();
}

// echo $this->Format($entry); //debug command

sort($tags);
//echo $mode."<br />"; //debug command
//foreach ($tags as $key => $value) echo $key."=".$value."<br />"; //debug command
$key = array_search($entry,$tags);
if($mode=='next'||$mode=='following')
{
    if($key!=(count($tags)-1))
    {
        echo $this->Link($tags[$key+1]);
    }
    else
    {
        echo $this->Format(LAST_ENTRY);
    }
}
elseif($mode=='prev')
{
    if($key!=(count($tags)-1))
    {
        echo $this->Link($tags[$key-1]);
    }
    else
    {
        echo $this->Format(FIRST_ENTRY);
    }
}


CategoryDevelopmentActions
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki