2 rcs_id('$Id: Calendar.php,v 1.26 2003-01-18 21:19:25 carstenklapp 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.26 $");
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 function __header($pagename, $time) {
68 $t = localtime($time - SECONDS_PER_DAY, 1);
69 $prev_url = WikiURL($pagename, array('month' => $t['tm_mon'] + 1,
70 'year' => $t['tm_year'] + 1900));
72 $t = localtime($time + 32 * SECONDS_PER_DAY, 1);
73 $next_url = WikiURL($pagename, array('month' => $t['tm_mon'] + 1,
74 'year' => $t['tm_year'] + 1900));
76 $prev = HTML::a(array('href' => $prev_url,
77 'class' => 'cal-arrow',
78 'title' => _("Previous Month")),
80 $next = HTML::a(array('href' => $next_url,
81 'class' => 'cal-arrow',
82 'title' => _("Next Month")),
86 $row = HTML::tr(HTML::td(array('align' => 'left'), $prev),
87 HTML::td(array('align' => 'center'),
88 HTML::strong(array('class' => 'cal-header'),
89 strftime($args['month_format'],
91 HTML::td(array('align' => 'right'), $next));
93 return HTML::tr(HTML::td(array('colspan' => 7,
95 HTML::table(array('width' => '100%',
96 'class' => 'cal-header'),
101 function __daynames($start_wday) {
102 $time = mktime(12, 0, 0, 1, 1, 2001);
103 $t = localtime($time, 1);
104 $time += (7 + $start_wday - $t['tm_wday']) * SECONDS_PER_DAY;
106 $t = localtime($time, 1);
107 assert($t['tm_wday'] == $start_wday);
109 $fs = $this->args['wday_format'];
111 $row->setattr('class', 'cal-dayname');
112 for ($i = 0; $i < 7; $i++) {
113 $row->pushContent(HTML::td(array('class' => 'cal-dayname',
114 'align' => 'center'),
115 strftime($fs, $time)));
116 $time += SECONDS_PER_DAY;
121 function __date($dbi, $time) {
122 $args = &$this->args;
124 $page_for_date = $args['prefix'] . strftime($args['date_format'],
126 $t = localtime($time, 1);
128 $td = HTML::td(array('align' => 'center'));
130 $mday = $t['tm_mday'];
131 if ($mday == $this->_today) {
132 $mday = HTML::strong($mday);
133 $td->setAttr('class', 'cal-today');
135 else if ($dbi->isWikiPage($page_for_date)) {
136 $td->setAttr('class', 'cal-day');
139 if ($dbi->isWikiPage($page_for_date)) {
140 $date = HTML::a(array('class' => 'cal-day',
141 'href' => WikiURL($page_for_date),
142 'title' => $page_for_date),
146 $date = HTML::a(array('class' => 'cal-hide',
147 'href' => WikiURL($page_for_date,
148 array('action' => 'edit')),
149 'title' => sprintf(_("Edit %s"),
153 $td->pushContent(HTML::raw(' '), $date, HTML::raw(' '));
157 function run($dbi, $argstr, $request) {
158 $this->args = $this->getArgs($argstr, $request);
159 $args = &$this->args;
161 $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
162 foreach ( array('month' => $now['tm_mon'] + 1,
163 'year' => $now['tm_year'] + 1900)
164 as $param => $dflt ) {
166 if (!($args[$param] = intval($args[$param])))
167 $args[$param] = $dflt;
170 $time = mktime(12, 0, 0, // hh, mm, ss,
171 $args['month'] + $args['month_offset'], // month (1-12)
175 $cal = HTML::table(array('cellspacing' => 0,
179 $this->__header($request->getArg('pagename'),
181 $this->__daynames($args['start_wday'])));
183 $t = localtime($time, 1);
185 if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
186 $this->_today = $now['tm_mday'];
188 $this->_today = false;
190 $tbody = HTML::tbody();
193 $col = (7 + $t['tm_wday'] - $args['start_wday']) % 7;
195 $row->pushContent(HTML::td(array('colspan' => $col)));
199 $row->pushContent($this->__date($dbi, $time));
201 if (++$col % 7 == 0) {
202 $tbody->pushContent($row);
207 $time += SECONDS_PER_DAY;
208 $t = localtime($time, 1);
209 $done = $t['tm_mday'] == 1;
212 if ($row->getContent()) {
213 $row->pushContent(HTML::td(array('colspan' => (42 - $col) % 7)));
214 $tbody->pushContent($row);
216 $cal->pushContent($tbody);
221 // $Log: not supported by cvs2svn $
228 // c-hanging-comment-ender-p: nil
229 // indent-tabs-mode: nil