2 rcs_id('$Id: CalendarList.php,v 1.9 2006-05-14 17:40:31 rurban Exp $');
5 Copyright 1999,2000,2001,2002,2005 $ThePhpWikiProgrammingTeam
7 This file is part of PhpWiki.
9 PhpWiki is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 PhpWiki is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 // if not defined in config.ini
25 if (!defined('PLUGIN_CALENDARLIST_ORDER'))
26 define('PLUGIN_CALENDARLIST_ORDER', 'normal');
27 if (!defined('PLUGIN_CALENDARLIST_NEXT_N_DAYS'))
28 define('PLUGIN_CALENDARLIST_NEXT_N_DAYS','');
29 if (!defined('PLUGIN_CALENDARLIST_NEXT_N'))
30 define('PLUGIN_CALENDARLIST_NEXT_N', '');
31 if (!defined('PLUGIN_CALENDARLIST_LAST_N_DAYS'))
32 define('PLUGIN_CALENDARLIST_LAST_N_DAYS','');
33 if (!defined('PLUGIN_CALENDARLIST_LAST_N'))
34 define('PLUGIN_CALENDARLIST_LAST_N', '');
37 * This is a list of calendar appointments.
38 * Same arguments as Calendar, so no one is confused
39 * Uses <dl><dd>DATE<dt>page contents...
40 * Derived from Calendar.php by Martin Norbäck <martin@safelogic.se>
42 * Insert this plugin into your Calendar page, for example in:
44 * Add the line: <?plugin CalendarList ?>
47 class WikiPlugin_CalendarList
51 return _("CalendarList");
54 function getDescription () {
55 return _("CalendarList");
58 function getDefaultArguments() {
59 return array('prefix' => '[pagename]',
60 'date_format' => '%Y-%m-%d',
61 'order' => PLUGIN_CALENDARLIST_ORDER, // normal or reverse (report sequence)
65 //support ranges: next n days/events
66 'next_n_days' => PLUGIN_CALENDARLIST_NEXT_N_DAYS, // one or the other, not both
67 'next_n' => PLUGIN_CALENDARLIST_NEXT_N,
68 // last n days/entries:
69 'last_n_days' => PLUGIN_CALENDARLIST_LAST_N_DAYS, // one or the other, not both
70 'last_n' => PLUGIN_CALENDARLIST_LAST_N,
72 'month_format' => '%B, %Y',
73 'wday_format' => '%a',
78 * return links (static only as of action=edit)
80 * @param string $argstr The plugin argument string.
81 * @param string $basepage The pagename the plugin is invoked from.
82 * @return array List of pagenames linked to (or false).
84 function getWikiPageLinks ($argstr, $basepage) {
85 if (isset($this->_links))
89 $this->run($request->_dbi, $argstr, $request, $basepage);
94 function _count_events($dbi, $n = 7, $direction = 1) {
95 // This is used by the last_n/next_n options to determine the date that
96 // accounts for the number of N events in the past/future.
97 // RETURNS: date of N-th event or the last item found
98 $args = &$this->args; // gather the args array
99 $timeTMP = time(); // start with today's date
100 $t = $timeTMP; // init the control date variable to now
102 for ($i=0; $i<=180; $i++) { // loop thru 180 days, past or future
103 $date_string = strftime($args['date_format'], $t);
104 $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
105 if ($dbi->isWikiPage($page_for_date)) { // if this date has any comments/events
106 $timeTMP = $t; // capture the date of this event for return
107 if ($n-- <= 0) break; // if we reached the limit, return the date
109 $t += 24 * 3600 * $direction; // advance one day back or forward
112 // return the date of the N-th or last, most past/future event in the range
116 function _date($dbi, $time) {
117 $args = &$this->args;
118 $date_string = strftime($args['date_format'], $time);
120 $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
121 $t = localtime($time, 1);
123 $td = HTML::td(array('align' => 'center'));
125 if ($dbi->isWikiPage($page_for_date)) {
126 // Extract the page contents for this date
127 $p = $dbi->getPage($page_for_date);
128 $r = $p->getCurrentRevision();
129 $c = $r->getContent();
130 include_once('lib/BlockParser.php');
131 $content = TransformText(implode("\n", $c), $r->get('markup'));
132 $link = HTML::a(array('class' => 'cal-hide',
133 'href' => WikiURL($page_for_date,
134 array('action' => 'edit')),
135 'title' => sprintf(_("Edit %s"), $page_for_date)),
137 $this->_links[] = $page_for_date;
138 $a = array(HTML::dt($link), HTML::dd($content));
145 function run($dbi, $argstr, &$request, $basepage) {
146 $this->args = $this->getArgs($argstr, $request);
147 $args = &$this->args;
148 $this->_links = array();
150 // default to this month
151 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
152 foreach ( array('month' => $now['tm_mon'] + 1,
153 'year' => $now['tm_year'] + 1900)
154 as $param => $dflt ) {
156 if (!($args[$param] = intval($args[$param])))
157 $args[$param] = $dflt;
160 // ***************************************************
161 // start of Plugin CalendarList display logic
162 // determine start date
163 if ($args['last_n_days']) {
164 // n days ago (should not be affected by month or month_offset)
165 $start = mktime(0, 0, 0, // h, m, s
166 $now['tm_mon'] + 1, // month (1-12)
167 $now['tm_mday'] - $args['last_n_days'], // days prior
168 $now['tm_year'] + 1900);
170 elseif ($args['last_n']) {
171 // get date for last nth event
172 $start = $this->_count_events($dbi, $args['last_n'], -1);
175 // start of requested month
176 $start = mktime(0, 0, 0, // h, m, s
177 $args['month'] + $args['month_offset'], // month (1-12)
182 // determine end date
183 if ($args['next_n_days']) {
184 // n days from now (should not be affected by month or month_offset)
185 $end = mktime(23, 59, 59, // h, m, s
186 $now['tm_mon'] + 1, // month (1-12)
187 $now['tm_mday'] + $args['next_n_days'], // days prior
188 $now['tm_year'] + 1900);
190 elseif ($args['last_n']) {
191 // get date for next nth event
192 $end = $this->_count_events($dbi, $args['next_n'], 1);
195 // trick to get last day of requested month
196 $end = mktime(0, 0, -1, // h, m, s
197 $args['month'] + 1 + $args['month_offset'], // month (1-12)
202 // switch values for reverse order
204 if ($args['order'] == 'reverse') {
211 // style tag on wiki description but not in here
214 // loop through dates and create list
215 for ($i = $start; ($step > 0) ? $i < $end : $i > $end; $i += $step) {
216 $cal->pushContent($this->_date($dbi, $i));
218 // end of Plugin CalendarList display logic
219 // ***************************************************
226 // $Log: not supported by cvs2svn $
227 // Revision 1.8 2005/10/12 06:18:31 rurban
228 // dont overdo constants
230 // Revision 1.7 2005/07/21 18:55:55 rurban
231 // applied mpullen patch (Revised to work on all date range combinations...),
232 // but still does not work as documented.
234 // Revision 1.6.2 2005/06/24 12:00:00 mpullen
235 // Corrected bug in the main WHILE loop to detect proper termination point in time
236 // {it was stopping one day too soon in either direction}.
238 // Revision 1.6.1 2005/06/23 12:00:00 mpullen
239 // Revised to work on all date range combinations (past and future, by days or count of events)
240 // Externalized five control parameter constants to the config.ini file (new section 8 for PLUGINs)
242 // Revision 1.6 2005/04/02 03:05:44 uckelman
243 // Removed & from vars passed by reference (not needed, causes PHP to complain).
245 // Revision 1.5 2004/12/06 19:15:04 rurban
246 // save edit-time links as requested in #946679
248 // Revision 1.4 2004/12/06 18:32:39 rurban
249 // added order=reverse: feature request from #981109
251 // Revision 1.3 2004/09/22 13:36:45 rurban
252 // Support ranges, based on a simple patch by JoshWand
253 // next_n_days, last_n_days, next_n
256 // Revision 1.2 2004/02/17 12:11:36 rurban
257 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far,
258 // because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed.
259 // (InterWikiSearch, IncludeSiteMap, ...)
261 // Revision 1.1 2003/11/18 19:06:03 carstenklapp
262 // New plugin to be used in conjunction with the Calendar plugin.
263 // Upgraded to use SUBPAGE_SEPARATOR for subpages. SF patch tracker
264 // submission 565369.
273 // c-hanging-comment-ender-p: nil
274 // indent-tabs-mode: nil