2 rcs_id('$Id: CalendarList.php,v 1.3 2004-09-22 13:36:45 rurban Exp $');
4 if (!defined('SECONDS_PER_DAY'))
5 define('SECONDS_PER_DAY', 24 * 3600);
8 * This is a list of calendar appoinments.
9 * Same arguments as Calendar, so no one is confused
10 * Uses <dl><dd>DATE<dt>page contents...
11 * Derived from Calendar.php by Martin Norbäck <martin@safelogic.se>
13 * Insert this plugin into your Calendar page, for example in:
15 * Add the line: <?plugin CalendarList ?>
18 class WikiPlugin_CalendarList
22 return _("CalendarList");
25 function getDescription () {
26 return _("CalendarList");
29 function getDefaultArguments() {
30 return array('prefix' => '[pagename]',
31 'date_format' => '%Y-%m-%d',
35 //support ranges, based on a simple patch by JoshWand
38 // next or last n entries:
40 //'last_n' => '', // not yet
42 'month_format' => '%B, %Y',
43 'wday_format' => '%a',
47 function __date($dbi, $time) {
49 $date_string = strftime($args['date_format'], $time);
51 $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
52 $t = localtime($time, 1);
54 $td = HTML::td(array('align' => 'center'));
56 if ($dbi->isWikiPage($page_for_date)) {
57 // Extract the page contents for this date
58 $p = $dbi->getPage($page_for_date);
59 $r = $p->getCurrentRevision();
60 $c = $r->getContent();
61 include_once('lib/BlockParser.php');
62 $content = TransformText(implode("\n", $c), $r->get('markup'));
63 $link = HTML::a(array('class' => 'cal-hide',
64 'href' => WikiURL($page_for_date,
65 array('action' => 'edit')),
66 'title' => sprintf(_("Edit %s"), $page_for_date)),
68 $a = array(HTML::dt($link), HTML::dd($content));
75 function run($dbi, $argstr, &$request, $basepage) {
76 $this->args = $this->getArgs($argstr, $request);
79 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
80 foreach ( array('month' => $now['tm_mon'] + 1,
81 'year' => $now['tm_year'] + 1900)
82 as $param => $dflt ) {
84 if (!($args[$param] = intval($args[$param])))
85 $args[$param] = $dflt;
87 if ($args['last_n_days']) {
88 $time = mktime(0, 0, 0, // hh, mm, ss,
89 $args['month'] + $args['month_offset'], // month (1-12)
90 $now['tm_mday'] - $args['last_n_days'],
92 } elseif ($args['next_n_days'] || $args['next_n']/* || $args['last_n']*/) {
93 $time = mktime(0, 0, 0, // hh, mm, ss,
94 $args['month'] + $args['month_offset'], // month (1-12)
95 $now['tm_mday'] , // starting today
98 $time = mktime(12, 0, 0, // hh, mm, ss,
99 $args['month'] + $args['month_offset'], // month (1-12)
100 1, // starting at monday
103 $t = localtime($time, 1);
105 if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
106 $this->_today = $now['tm_mday'];
108 $this->_today = false;
113 $n = 0; $max = (180 * SECONDS_PER_DAY) + $time;
115 $success = $cal->pushContent($this->__date($dbi, $time));
116 $time += SECONDS_PER_DAY;
117 if ($time >= $max) return $cal;
119 $t = localtime($time, 1);
120 if ($args['next_n_days']) {
121 if ($n == $args['next_n_days']) return $cal;
123 } elseif ($args['next_n']) {
124 if ($n == $args['next_n']) return $cal;
125 if (!empty($success))
127 } elseif ($args['last_n_days']) {
128 $done = ($t['tm_mday'] == $now['tm_mday']);
130 $done = ($t['tm_mday'] == 1);
138 // $Log: not supported by cvs2svn $
139 // Revision 1.2 2004/02/17 12:11:36 rurban
140 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
142 // Revision 1.1 2003/11/18 19:06:03 carstenklapp
143 // New plugin to be used in conjunction with the Calendar plugin.
144 // Upgraded to use SUBPAGE_SEPARATOR for subpages. SF patch tracker
145 // submission 565369.
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil