2 rcs_id('$Id: CalendarList.php,v 1.5 2004-12-06 19:15:04 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',
49 * return links (static only as of action=edit)
51 * @param string $argstr The plugin argument string.
52 * @param string $basepage The pagename the plugin is invoked from.
53 * @return array List of pagenames linked to (or false).
55 function getWikiPageLinks ($argstr, $basepage) {
56 if (isset($this->_links))
60 $this->run($request->_dbi, $argstr, &$request, $basepage);
65 function __date($dbi, $time) {
67 $date_string = strftime($args['date_format'], $time);
69 $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
70 $t = localtime($time, 1);
72 $td = HTML::td(array('align' => 'center'));
74 if ($dbi->isWikiPage($page_for_date)) {
75 // Extract the page contents for this date
76 $p = $dbi->getPage($page_for_date);
77 $r = $p->getCurrentRevision();
78 $c = $r->getContent();
79 include_once('lib/BlockParser.php');
80 $content = TransformText(implode("\n", $c), $r->get('markup'));
81 $link = HTML::a(array('class' => 'cal-hide',
82 'href' => WikiURL($page_for_date,
83 array('action' => 'edit')),
84 'title' => sprintf(_("Edit %s"), $page_for_date)),
86 $this->_links[] = $page_for_date;
87 $a = array(HTML::dt($link), HTML::dd($content));
94 function run($dbi, $argstr, &$request, $basepage) {
95 $this->args = $this->getArgs($argstr, $request);
97 $this->_links = array();
99 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
100 foreach ( array('month' => $now['tm_mon'] + 1,
101 'year' => $now['tm_year'] + 1900)
102 as $param => $dflt ) {
104 if (!($args[$param] = intval($args[$param])))
105 $args[$param] = $dflt;
107 if ($args['last_n_days']) {
108 $time = mktime(0, 0, 0, // hh, mm, ss,
109 $args['month'] + $args['month_offset'], // month (1-12)
110 $now['tm_mday'] - $args['last_n_days'],
112 } elseif ($args['next_n_days'] or $args['next_n']
113 or ($args['order'] == 'reverse')
114 /* or $args['last_n']*/) {
115 $time = mktime(0, 0, 0, // hh, mm, ss,
116 $args['month'] + $args['month_offset'], // month (1-12)
117 $now['tm_mday'] , // starting today
120 $time = mktime(12, 0, 0, // hh, mm, ss,
121 $args['month'] + $args['month_offset'], // month (1-12)
122 1, // starting at monday
125 $t = localtime($time, 1);
127 if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
128 $this->_today = $now['tm_mday'];
130 $this->_today = false;
136 if ($args['order'] == "reverse")
137 $max = $time - (180 * SECONDS_PER_DAY);
139 $max = $time + (180 * SECONDS_PER_DAY);
141 $success = $cal->pushContent($this->__date($dbi, $time));
142 if ($args['order'] == "reverse") {
143 $time -= SECONDS_PER_DAY;
144 if ($time <= $max) return $cal;
146 $time += SECONDS_PER_DAY;
147 if ($time >= $max) return $cal;
150 $t = localtime($time, 1);
151 if ($args['next_n_days']) {
152 if ($n == $args['next_n_days']) return $cal;
154 } elseif ($args['next_n']) {
155 if ($n == $args['next_n']) return $cal;
156 if (!empty($success))
158 } elseif ($args['last_n_days']) {
159 $done = ($t['tm_mday'] == $now['tm_mday']);
160 } else { // stop at next/prev month
161 $done = ($t['tm_mon'] != $now['tm_mon']);
169 // $Log: not supported by cvs2svn $
170 // Revision 1.4 2004/12/06 18:32:39 rurban
171 // added order=reverse: feature request from #981109
173 // Revision 1.3 2004/09/22 13:36:45 rurban
174 // Support ranges, based on a simple patch by JoshWand
175 // next_n_days, last_n_days, next_n
178 // Revision 1.2 2004/02/17 12:11:36 rurban
179 // 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, ...)
181 // Revision 1.1 2003/11/18 19:06:03 carstenklapp
182 // New plugin to be used in conjunction with the Calendar plugin.
183 // Upgraded to use SUBPAGE_SEPARATOR for subpages. SF patch tracker
184 // submission 565369.
193 // c-hanging-comment-ender-p: nil
194 // indent-tabs-mode: nil