1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of eventdata, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) return; |
---|
14 | |
---|
15 | $core->addBehavior('initWidgets',array('eventdataWidget','eventdataInitListWidget')); |
---|
16 | $core->addBehavior('initWidgets',array('eventdataWidget','eventdataInitMetaWidget')); |
---|
17 | //$core->addBehavior('initWidgets',array('eventdataWidget','eventdataInitCalendardWidget')); |
---|
18 | |
---|
19 | class eventdataWidget |
---|
20 | { |
---|
21 | public static function eventdataInitListWidget(&$w) |
---|
22 | { |
---|
23 | global $core; |
---|
24 | |
---|
25 | # Create widget |
---|
26 | $w->create('eventdatalist',__('Events'), |
---|
27 | array('eventdataWidget','evendataParseListWidget')); |
---|
28 | # Title |
---|
29 | $w->eventdatalist->setting('title',__('Title:'), |
---|
30 | __('Events'),'text'); |
---|
31 | # Category |
---|
32 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
33 | $categories = array('' => '', __('Uncategorized') => 'null'); |
---|
34 | while ($rs->fetch()) { |
---|
35 | $categories[str_repeat(' ',$rs->level-1).'• '. |
---|
36 | html::escapeHTML($rs->cat_title)] = $rs->cat_id; |
---|
37 | } |
---|
38 | $w->eventdatalist->setting('category',__('Category:'),'','combo',$categories); |
---|
39 | unset($rs,$categories); |
---|
40 | # Tag |
---|
41 | if ($core->plugins->moduleExists('metadata')) |
---|
42 | $w->eventdatalist->setting('tag',__('Tag:'),''); |
---|
43 | |
---|
44 | # Entries limit |
---|
45 | $w->eventdatalist->setting('limit',__('Entries limit:'),10); |
---|
46 | # Sort type |
---|
47 | $w->eventdatalist->setting('sortby',__('Order by:'),'event_start','combo',array( |
---|
48 | __('Date') => 'post_dt', |
---|
49 | __('Title') => 'post_title', |
---|
50 | __('Event start') => 'event_start', |
---|
51 | __('Event end') => 'event_end')); |
---|
52 | # Sort order |
---|
53 | $w->eventdatalist->setting('sort',__('Sort:'),'asc','combo',array( |
---|
54 | __('Ascending') => 'asc', |
---|
55 | __('Descending') => 'desc')); |
---|
56 | # Selected entries only |
---|
57 | $w->eventdatalist->setting('selectedonly',__('Selected entries only'),0,'check'); |
---|
58 | # Period |
---|
59 | $w->eventdatalist->setting('period',__('Period:'),'notfinished','combo',array( |
---|
60 | '' => '', |
---|
61 | __('Not started') => 'notstarted', |
---|
62 | __('Started') => 'started', |
---|
63 | __('Finished') => 'finished', |
---|
64 | __('Not finished') => 'notfinished', |
---|
65 | __('Ongoing') => 'ongoing', |
---|
66 | __('Outgoing') => 'outgoing')); |
---|
67 | # Date format |
---|
68 | $w->eventdatalist->setting('date_format',__('Date format of items:'), |
---|
69 | __('%Y-%m-%d %H:%M'),'text'); |
---|
70 | # Item format |
---|
71 | $w->eventdatalist->setting('item_format',__('Text format of items:'), |
---|
72 | __('%T (%C)'),'text'); |
---|
73 | # Item mouseover format |
---|
74 | $w->eventdatalist->setting('over_format',__('Mouseover format of items:'), |
---|
75 | __('From %S to %E'),'text'); |
---|
76 | # Home only |
---|
77 | $w->eventdatalist->setting('homeonly',__('Home page only'),1,'check'); |
---|
78 | } |
---|
79 | |
---|
80 | public static function evendataParseListWidget(&$w) |
---|
81 | { |
---|
82 | global $core; |
---|
83 | $E = new eventdata($core); |
---|
84 | |
---|
85 | # Plugin active |
---|
86 | if (!$E->S->event_option_active) return; |
---|
87 | # Home only |
---|
88 | if ($w->homeonly && $core->url->type != 'default') return; |
---|
89 | # Period |
---|
90 | $params['period'] = $w->period; |
---|
91 | # Sort field |
---|
92 | $params['order'] = ($w->sortby && in_array($w->sortby,array('post_title','post_dt','event_start','event_end'))) ? |
---|
93 | $w->sortby.' ' : 'post_dt '; |
---|
94 | # Sort order |
---|
95 | $params['order'] .= $w->sort == 'asc' ? 'asc' : 'desc'; |
---|
96 | # Rows number |
---|
97 | $params['limit'] = abs((integer) $w->limit); |
---|
98 | # No post content |
---|
99 | $params['no_content'] = true; |
---|
100 | # Event type |
---|
101 | $params['event_type'] = 'event'; |
---|
102 | # Post type |
---|
103 | $params['post_type'] = ''; |
---|
104 | # Selected post only |
---|
105 | if ($w->selectedonly) { $params['post_selected'] = 1; } |
---|
106 | # Category |
---|
107 | if ($w->category) { |
---|
108 | if ($w->category == 'null') |
---|
109 | $params['sql'] = ' AND p.cat_id IS NULL '; |
---|
110 | elseif (is_numeric($w->category)) |
---|
111 | $params['cat_id'] = (integer) $w->category; |
---|
112 | else |
---|
113 | $params['cat_url'] = $w->category; |
---|
114 | # If no paricular category is selected, remove unlisted categories |
---|
115 | } else { |
---|
116 | $cats_unlisted = @unserialize($E->S->event_no_cats); |
---|
117 | if (is_array($cats_unlisted) && !empty($cats_unlisted)) { |
---|
118 | $params['sql'] = ''; |
---|
119 | foreach($cats_unlisted AS $k => $cat_id) { |
---|
120 | $params['sql'] = " AND P.cat_id != '$cat_id'"; |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | # Tag |
---|
125 | if ($core->plugins->moduleExists('metadata') && $w->tag) |
---|
126 | $params['meta_id'] = $w->tag; |
---|
127 | # Get posts |
---|
128 | $rs = $E->getPostsByEvent($params); |
---|
129 | # No result |
---|
130 | if ($rs->isEmpty()) return; |
---|
131 | # Display |
---|
132 | $res = |
---|
133 | '<div class="eventslist">'. |
---|
134 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
135 | '<ul>'; |
---|
136 | while ($rs->fetch()) { |
---|
137 | # Format items |
---|
138 | $fs = dt::dt2str($w->date_format,$rs->event_start); |
---|
139 | $fe = dt::dt2str($w->date_format,$rs->event_end); |
---|
140 | $fc = html::escapeHTML($rs->cat_title); |
---|
141 | $ft = html::escapeHTML($rs->post_title); |
---|
142 | $over = str_replace(array('%S','%E','%C','%T','%%'),array($fs,$fe,$fc,$ft,'%'),$w->over_format); |
---|
143 | $item = str_replace(array('%S','%E','%C','%T','%%'),array($fs,$fe,$fc,$ft,'%'),$w->item_format); |
---|
144 | |
---|
145 | $res .= '<li><a href="'.$rs->getURL().'" title="'.$over.'">'.$item.'</a></li>'; |
---|
146 | } |
---|
147 | $res .= '</ul></div>'; |
---|
148 | |
---|
149 | return $res; |
---|
150 | } |
---|
151 | |
---|
152 | public static function eventdataInitMetaWidget(&$w) |
---|
153 | { |
---|
154 | # Create widget |
---|
155 | $w->create('eventdatameta',__('Post Events'), |
---|
156 | array('eventdataWidget','evendataParseMetaWidget')); |
---|
157 | # Title |
---|
158 | $w->eventdatameta->setting('title',__('Title:'), |
---|
159 | __('Linked events'),'text'); |
---|
160 | # Rows number |
---|
161 | $params['limit'] = abs((integer) $w->limit); |
---|
162 | # Date format |
---|
163 | $w->eventdatameta->setting('date_format',__('Date format of items:'), |
---|
164 | __('%Y-%m-%d %H:%M'),'text'); |
---|
165 | # Item format |
---|
166 | $w->eventdatameta->setting('item_format',__('Text format of items:'), |
---|
167 | __('From %S to %E'),'text'); |
---|
168 | } |
---|
169 | |
---|
170 | public static function evendataParseMetaWidget(&$w) |
---|
171 | { |
---|
172 | global $core, $_ctx; |
---|
173 | $E = new eventdata($core); |
---|
174 | |
---|
175 | # Plugin active and on post page |
---|
176 | if (!$E->S->event_option_active |
---|
177 | || 'post.html' != $_ctx->current_tpl |
---|
178 | || !$_ctx->posts->post_id) return; |
---|
179 | |
---|
180 | # Rows number |
---|
181 | $limit = $w->limit ? abs((integer) $w->limit) : null; |
---|
182 | # Get posts |
---|
183 | $rs = $E->getEvent('event',$limit,null,null,$_ctx->posts->post_id,null); |
---|
184 | # No result |
---|
185 | if ($rs->isEmpty()) return; |
---|
186 | # Display |
---|
187 | $res = |
---|
188 | '<div class="eventslist">'. |
---|
189 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
190 | '<ul>'; |
---|
191 | while ($rs->fetch()) { |
---|
192 | # Format items |
---|
193 | $fs = dt::dt2str($w->date_format,$rs->event_start); |
---|
194 | $fe = dt::dt2str($w->date_format,$rs->event_end); |
---|
195 | $item = str_replace(array('%S','%E','%%'),array($fs,$fe,'%'),$w->item_format); |
---|
196 | |
---|
197 | $res .= '<li>'.html::escapeHTML($item).'</li>'; |
---|
198 | } |
---|
199 | $res .= '</ul></div>'; |
---|
200 | |
---|
201 | return $res; |
---|
202 | } |
---|
203 | } |
---|
204 | ?> |
---|