2 rcs_id('$Id: Calendar.php,v 1.28 2004-05-08 14:06:13 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 if (!defined('SECONDS_PER_DAY'))
24 define('SECONDS_PER_DAY', 24 * 3600);
26 // FIXME: Still needs:
28 // o Better way to navigate to distant months.
29 // (Maybe a form with selectors for month and year)?
31 // It would be nice to have some way to get from the individual date
32 // pages back to the calendar page. (Subpage support might make this
37 class WikiPlugin_Calendar
44 function getDescription () {
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
50 "\$Revision: 1.28 $");
53 function getDefaultArguments() {
54 return array('prefix' => '[pagename]' . SUBPAGE_SEPARATOR,
55 'date_format' => '%Y-%m-%d',
60 'month_format' => '%B, %Y',
61 'wday_format' => '%a',
65 /** Get wiki-pages linked to by plugin invocation.
67 * A plugin may override this method to add pages to the
68 * link database for the invoking page.
70 * For example, the IncludePage plugin should override this so
71 * that the including page shows up in the backlinks list for the
74 * Not all plugins which generate links to wiki-pages need list
77 * Note also that currently the links are calculated at page save
78 * time, so only static page links (e.g. those dependent on the PI
79 * args, not the rest of the wikidb state or any request query args)
80 * will work correctly here.
82 * @param string $argstr The plugin argument string.
83 * @param string $basepage The pagename the plugin is invoked from.
84 * @return array List of pagenames linked to (or false).
86 function getWikiPageLinks ($argstr, $basepage) {
87 if (isset($this->_links)) return $this->_links;
91 function __header($pagename, $time) {
94 $t = localtime($time - SECONDS_PER_DAY, 1);
95 $prev_url = WikiURL($pagename, array('month' => $t['tm_mon'] + 1,
96 'year' => $t['tm_year'] + 1900));
98 $t = localtime($time + 32 * SECONDS_PER_DAY, 1);
99 $next_url = WikiURL($pagename, array('month' => $t['tm_mon'] + 1,
100 'year' => $t['tm_year'] + 1900));
102 $prev = HTML::a(array('href' => $prev_url,
103 'class' => 'cal-arrow',
104 'title' => _("Previous Month")),
106 $next = HTML::a(array('href' => $next_url,
107 'class' => 'cal-arrow',
108 'title' => _("Next Month")),
112 $row = HTML::tr(HTML::td(array('align' => 'left'), $prev),
113 HTML::td(array('align' => 'center'),
114 HTML::strong(array('class' => 'cal-header'),
115 strftime($args['month_format'],
117 HTML::td(array('align' => 'right'), $next));
119 return HTML::tr(HTML::td(array('colspan' => 7,
120 'align' => 'center'),
121 HTML::table(array('width' => '100%',
122 'class' => 'cal-header'),
127 function __daynames($start_wday) {
128 $time = mktime(12, 0, 0, 1, 1, 2001);
129 $t = localtime($time, 1);
130 $time += (7 + $start_wday - $t['tm_wday']) * SECONDS_PER_DAY;
132 $t = localtime($time, 1);
133 assert($t['tm_wday'] == $start_wday);
135 $fs = $this->args['wday_format'];
137 $row->setattr('class', 'cal-dayname');
138 for ($i = 0; $i < 7; $i++) {
139 $row->pushContent(HTML::td(array('class' => 'cal-dayname',
140 'align' => 'center'),
141 strftime($fs, $time)));
142 $time += SECONDS_PER_DAY;
147 function __date($dbi, $time) {
148 $args = &$this->args;
150 $page_for_date = $args['prefix'] . strftime($args['date_format'],
152 $t = localtime($time, 1);
154 $td = HTML::td(array('align' => 'center'));
156 $mday = $t['tm_mday'];
157 if ($mday == $this->_today) {
158 $mday = HTML::strong($mday);
159 $td->setAttr('class', 'cal-today');
161 else if ($dbi->isWikiPage($page_for_date)) {
162 $this->_links[] = $page_for_date;
163 $td->setAttr('class', 'cal-day');
166 if ($dbi->isWikiPage($page_for_date)) {
167 $this->_links[] = $page_for_date;
168 $date = HTML::a(array('class' => 'cal-day',
169 'href' => WikiURL($page_for_date),
170 'title' => $page_for_date),
174 $date = HTML::a(array('class' => 'cal-hide',
175 'href' => WikiURL($page_for_date,
176 array('action' => 'edit')),
177 'title' => sprintf(_("Edit %s"),
181 $td->pushContent(HTML::raw(' '), $date, HTML::raw(' '));
185 function run($dbi, $argstr, &$request, $basepage) {
186 $this->args = $this->getArgs($argstr, $request);
187 $args = &$this->args;
188 $this->_links = array();
190 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
191 foreach ( array('month' => $now['tm_mon'] + 1,
192 'year' => $now['tm_year'] + 1900)
193 as $param => $dflt ) {
195 if (!($args[$param] = intval($args[$param])))
196 $args[$param] = $dflt;
199 $time = mktime(12, 0, 0, // hh, mm, ss,
200 $args['month'] + $args['month_offset'], // month (1-12)
204 $cal = HTML::table(array('cellspacing' => 0,
208 $this->__header($request->getArg('pagename'),
210 $this->__daynames($args['start_wday'])));
212 $t = localtime($time, 1);
214 if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
215 $this->_today = $now['tm_mday'];
217 $this->_today = false;
219 $tbody = HTML::tbody();
222 $col = (7 + $t['tm_wday'] - $args['start_wday']) % 7;
224 $row->pushContent(HTML::td(array('colspan' => $col)));
228 $row->pushContent($this->__date($dbi, $time));
230 if (++$col % 7 == 0) {
231 $tbody->pushContent($row);
236 $time += SECONDS_PER_DAY;
237 $t = localtime($time, 1);
238 $done = $t['tm_mday'] == 1;
241 if ($row->getContent()) {
242 $row->pushContent(HTML::td(array('colspan' => (42 - $col) % 7)));
243 $tbody->pushContent($row);
245 $cal->pushContent($tbody);
250 // $Log: not supported by cvs2svn $
251 // Revision 1.27 2004/02/17 12:11:36 rurban
252 // 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, ...)
254 // Revision 1.26 2003/01/18 21:19:25 carstenklapp
256 // Reformatting; added copyleft, getVersion, getDescription
264 // c-hanging-comment-ender-p: nil
265 // indent-tabs-mode: nil