2 rcs_id('$Id: CalendarList.php,v 1.4 2004-12-06 18:32:39 rurban Exp $');
4 if (!defined('SECONDS_PER_DAY'))
5 define('SECONDS_PER_DAY', 24 * 3600);
8 * This is a list of calendar appointments.
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',
32 'order' => 'normal', // or reverse (counting backwards)
36 //support ranges, based on a simple patch by JoshWand
39 // next or last n entries:
41 //'last_n' => '', // not yet
43 'month_format' => '%B, %Y',
44 'wday_format' => '%a',
48 function __date($dbi, $time) {
50 $date_string = strftime($args['date_format'], $time);
52 $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
53 $t = localtime($time, 1);
55 $td = HTML::td(array('align' => 'center'));
57 if ($dbi->isWikiPage($page_for_date)) {
58 // Extract the page contents for this date
59 $p = $dbi->getPage($page_for_date);
60 $r = $p->getCurrentRevision();
61 $c = $r->getContent();
62 include_once('lib/BlockParser.php');
63 $content = TransformText(implode("\n", $c), $r->get('markup'));
64 $link = HTML::a(array('class' => 'cal-hide',
65 'href' => WikiURL($page_for_date,
66 array('action' => 'edit')),
67 'title' => sprintf(_("Edit %s"), $page_for_date)),
69 $a = array(HTML::dt($link), HTML::dd($content));
76 function run($dbi, $argstr, &$request, $basepage) {
77 $this->args = $this->getArgs($argstr, $request);
80 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
81 foreach ( array('month' => $now['tm_mon'] + 1,
82 'year' => $now['tm_year'] + 1900)
83 as $param => $dflt ) {
85 if (!($args[$param] = intval($args[$param])))
86 $args[$param] = $dflt;
88 if ($args['last_n_days']) {
89 $time = mktime(0, 0, 0, // hh, mm, ss,
90 $args['month'] + $args['month_offset'], // month (1-12)
91 $now['tm_mday'] - $args['last_n_days'],
93 } elseif ($args['next_n_days'] or $args['next_n']
94 or ($args['order'] == 'reverse')
95 /* or $args['last_n']*/) {
96 $time = mktime(0, 0, 0, // hh, mm, ss,
97 $args['month'] + $args['month_offset'], // month (1-12)
98 $now['tm_mday'] , // starting today
101 $time = mktime(12, 0, 0, // hh, mm, ss,
102 $args['month'] + $args['month_offset'], // month (1-12)
103 1, // starting at monday
106 $t = localtime($time, 1);
108 if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
109 $this->_today = $now['tm_mday'];
111 $this->_today = false;
117 if ($args['order'] == "reverse")
118 $max = $time - (180 * SECONDS_PER_DAY);
120 $max = $time + (180 * SECONDS_PER_DAY);
122 $success = $cal->pushContent($this->__date($dbi, $time));
123 if ($args['order'] == "reverse") {
124 $time -= SECONDS_PER_DAY;
125 if ($time <= $max) return $cal;
127 $time += SECONDS_PER_DAY;
128 if ($time >= $max) return $cal;
131 $t = localtime($time, 1);
132 if ($args['next_n_days']) {
133 if ($n == $args['next_n_days']) return $cal;
135 } elseif ($args['next_n']) {
136 if ($n == $args['next_n']) return $cal;
137 if (!empty($success))
139 } elseif ($args['last_n_days']) {
140 $done = ($t['tm_mday'] == $now['tm_mday']);
141 } else { // stop at next/prev month
142 $done = ($t['tm_mon'] != $now['tm_mon']);
150 // $Log: not supported by cvs2svn $
151 // Revision 1.3 2004/09/22 13:36:45 rurban
152 // Support ranges, based on a simple patch by JoshWand
153 // next_n_days, last_n_days, next_n
156 // Revision 1.2 2004/02/17 12:11:36 rurban
157 // 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, ...)
159 // Revision 1.1 2003/11/18 19:06:03 carstenklapp
160 // New plugin to be used in conjunction with the Calendar plugin.
161 // Upgraded to use SUBPAGE_SEPARATOR for subpages. SF patch tracker
162 // submission 565369.
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil