]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/CalendarList.php
added missing 4th basepage arg at plugin->run() to almost all plugins. This caused...
[SourceForge/phpwiki.git] / lib / plugin / CalendarList.php
1 <?php // -*-php-*-
2 rcs_id('$Id: CalendarList.php,v 1.2 2004-02-17 12:11:36 rurban Exp $');
3
4 if (!defined('SECONDS_PER_DAY'))
5 define('SECONDS_PER_DAY', 24 * 3600);
6
7 /**
8  * This is a list of calendar appoinments. 
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>
12  *
13  * Insert this plugin into your Calendar page, for example in:
14  *     WikiUser/Calendar
15  * Add the line: <?plugin CalendarList ?>
16  *
17  */
18 class WikiPlugin_CalendarList
19 extends WikiPlugin
20 {
21     function getName () {
22         return _("CalendarList");
23     }
24
25     function getDescription () {
26         return _("CalendarList");
27     }
28
29     function getDefaultArguments() {
30         return array('prefix'       => '[pagename]',
31                      'date_format'  => '%Y-%m-%d',
32                      'year'         => '',
33                      'month'        => '',
34                      'month_offset' => 0,
35
36                      'month_format' => '%B, %Y',
37                      'wday_format'  => '%a',
38                      'start_wday'   => '0');
39     }
40
41     function __date($dbi, $time) {
42         $args = &$this->args;
43         $date_string = strftime($args['date_format'], $time);
44
45         $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string;
46         $t = localtime($time, 1);
47
48         $td = HTML::td(array('align' => 'center'));
49
50         if ($dbi->isWikiPage($page_for_date)) {
51             // Extract the page contents for this date
52             $p = $dbi->getPage($page_for_date);
53             $r = $p->getCurrentRevision();
54             $c = $r->getContent();
55             include_once('lib/BlockParser.php');
56             $content = TransformText(implode("\n", $c), $r->get('markup'));
57             $link = HTML::a(array('class' => 'cal-hide',
58                                   'href'  => WikiURL($page_for_date,
59                                                      array('action' => 'edit')),
60                                   'title' => sprintf(_("Edit %s"), $page_for_date)),
61                             $date_string);
62             $a = array(HTML::dt($link), HTML::dd($content));
63         } else {
64           $a = array();
65         }
66         return $a;
67     }
68
69     function run($dbi, $argstr, &$request, $basepage) {
70         $this->args = $this->getArgs($argstr, $request);
71         $args       = &$this->args;
72
73         $now = localtime(time() + 3600 * $request->getPref('timeOffset'), 1);
74         foreach ( array('month' => $now['tm_mon'] + 1,
75                         'year'  => $now['tm_year'] + 1900)
76                   as $param => $dflt ) {
77
78             if (!($args[$param] = intval($args[$param])))
79                 $args[$param]   = $dflt;
80         }
81
82         $time = mktime(12, 0, 0,                               // hh, mm, ss,
83                        $args['month'] + $args['month_offset'], // month (1-12)
84                        1,                                      // mday (1-31)
85                        $args['year']);
86
87         $t = localtime($time, 1);
88
89         if ($now['tm_year'] == $t['tm_year'] && $now['tm_mon'] == $t['tm_mon'])
90             $this->_today = $now['tm_mday'];
91         else
92             $this->_today = false;
93
94         $cal = HTML::dl();
95
96         $done = false;
97
98         while (!$done) {
99             $cal->pushContent($this->__date($dbi, $time));
100
101             $time += SECONDS_PER_DAY;
102             $t     = localtime($time, 1);
103             $done  = $t['tm_mday'] == 1;
104         }
105
106         return $cal;
107     }
108 };
109
110
111 // $Log: not supported by cvs2svn $
112 // Revision 1.1  2003/11/18 19:06:03  carstenklapp
113 // New plugin to be used in conjunction with the Calendar plugin.
114 // Upgraded to use SUBPAGE_SEPARATOR for subpages. SF patch tracker
115 // submission 565369.
116 //
117
118
119 // For emacs users
120 // Local Variables:
121 // mode: php
122 // tab-width: 8
123 // c-basic-offset: 4
124 // c-hanging-comment-ender-p: nil
125 // indent-tabs-mode: nil
126 // End:
127 ?>