1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class defaultWidgets |
---|
15 | { |
---|
16 | public static function search($w) |
---|
17 | { |
---|
18 | global $core; |
---|
19 | |
---|
20 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
21 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
22 | return; |
---|
23 | } |
---|
24 | |
---|
25 | $value = isset($GLOBALS['_search']) ? html::escapeHTML($GLOBALS['_search']) : ''; |
---|
26 | |
---|
27 | return |
---|
28 | ($w->content_only ? '' : '<div id="search"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). |
---|
29 | ($w->title ? '<h2><label for="q">'.html::escapeHTML($w->title).'</label></h2>' : ''). |
---|
30 | '<form action="'.$core->blog->url.'" method="get">'. |
---|
31 | '<p><input type="text" size="10" maxlength="255" id="q" name="q" value="'.$value.'" /> '. |
---|
32 | '<input type="submit" class="submit" value="ok" /></p>'. |
---|
33 | '</form>'. |
---|
34 | ($w->content_only ? '' : '</div>'); |
---|
35 | } |
---|
36 | |
---|
37 | public static function navigation($w) |
---|
38 | { |
---|
39 | global $core; |
---|
40 | |
---|
41 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
42 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
43 | return; |
---|
44 | } |
---|
45 | |
---|
46 | $res = |
---|
47 | ($w->content_only ? '' : '<div id="topnav"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). |
---|
48 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
49 | '<ul>'; |
---|
50 | |
---|
51 | if ($core->url->type != 'default') { |
---|
52 | $res .= |
---|
53 | '<li class="topnav-home">'. |
---|
54 | '<a href="'.$core->blog->url.'">'.__('Home').'</a>'. |
---|
55 | '<span> - </span></li>'; |
---|
56 | } |
---|
57 | |
---|
58 | $res .= |
---|
59 | '<li class="topnav-arch">'. |
---|
60 | '<a href="'.$core->blog->url.$core->url->getURLFor("archive").'">'. |
---|
61 | __('Archives').'</a></li>'. |
---|
62 | '</ul>'. |
---|
63 | ($w->content_only ? '' : '</div>'); |
---|
64 | |
---|
65 | return $res; |
---|
66 | } |
---|
67 | |
---|
68 | public static function categories($w) |
---|
69 | { |
---|
70 | global $core, $_ctx; |
---|
71 | |
---|
72 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
73 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
74 | return; |
---|
75 | } |
---|
76 | |
---|
77 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
78 | if ($rs->isEmpty()) { |
---|
79 | return; |
---|
80 | } |
---|
81 | |
---|
82 | $res = |
---|
83 | ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
84 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''); |
---|
85 | |
---|
86 | $ref_level = $level = $rs->level-1; |
---|
87 | while ($rs->fetch()) |
---|
88 | { |
---|
89 | $class = ''; |
---|
90 | if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id) |
---|
91 | || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) { |
---|
92 | $class = ' class="category-current"'; |
---|
93 | } |
---|
94 | |
---|
95 | if ($rs->level > $level) { |
---|
96 | $res .= str_repeat('<ul><li'.$class.'>',$rs->level - $level); |
---|
97 | } elseif ($rs->level < $level) { |
---|
98 | $res .= str_repeat('</li></ul>',-($rs->level - $level)); |
---|
99 | } |
---|
100 | |
---|
101 | if ($rs->level <= $level) { |
---|
102 | $res .= '</li><li'.$class.'>'; |
---|
103 | } |
---|
104 | |
---|
105 | $res .= |
---|
106 | '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'. |
---|
107 | html::escapeHTML($rs->cat_title).'</a>'. |
---|
108 | ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : ''); |
---|
109 | |
---|
110 | |
---|
111 | $level = $rs->level; |
---|
112 | } |
---|
113 | |
---|
114 | if ($ref_level - $level < 0) { |
---|
115 | $res .= str_repeat('</li></ul>',-($ref_level - $level)); |
---|
116 | } |
---|
117 | $res .= ($w->content_only ? '' : '</div>'); |
---|
118 | |
---|
119 | return $res; |
---|
120 | } |
---|
121 | |
---|
122 | public static function bestof($w) |
---|
123 | { |
---|
124 | global $core; |
---|
125 | |
---|
126 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
127 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
128 | return; |
---|
129 | } |
---|
130 | |
---|
131 | $params = array( |
---|
132 | 'post_selected' => true, |
---|
133 | 'no_content' => true, |
---|
134 | 'order' => 'post_dt '.strtoupper($w->orderby) |
---|
135 | ); |
---|
136 | |
---|
137 | $rs = $core->blog->getPosts($params); |
---|
138 | |
---|
139 | if ($rs->isEmpty()) { |
---|
140 | return; |
---|
141 | } |
---|
142 | |
---|
143 | $res = |
---|
144 | ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
145 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
146 | '<ul>'; |
---|
147 | |
---|
148 | while ($rs->fetch()) { |
---|
149 | $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> '; |
---|
150 | } |
---|
151 | |
---|
152 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
153 | |
---|
154 | return $res; |
---|
155 | } |
---|
156 | |
---|
157 | public static function langs($w) |
---|
158 | { |
---|
159 | global $core, $_ctx; |
---|
160 | |
---|
161 | if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') || |
---|
162 | ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) { |
---|
163 | return; |
---|
164 | } |
---|
165 | |
---|
166 | $rs = $core->blog->getLangs(); |
---|
167 | |
---|
168 | if ($rs->count() <= 1) { |
---|
169 | return; |
---|
170 | } |
---|
171 | |
---|
172 | $langs = l10n::getISOcodes(); |
---|
173 | $res = |
---|
174 | ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
175 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
176 | '<ul>'; |
---|
177 | |
---|
178 | while ($rs->fetch()) |
---|
179 | { |
---|
180 | $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s'; |
---|
181 | |
---|
182 | $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang; |
---|
183 | |
---|
184 | $res .= |
---|
185 | ' <li>'. |
---|
186 | sprintf($l, |
---|
187 | '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '. |
---|
188 | 'class="lang-'.$rs->post_lang.'">'. |
---|
189 | $lang_name.'</a>'). |
---|
190 | ' </li>'; |
---|
191 | } |
---|
192 | |
---|
193 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
194 | |
---|
195 | return $res; |
---|
196 | } |
---|
197 | |
---|
198 | public static function subscribe($w) |
---|
199 | { |
---|
200 | global $core; |
---|
201 | |
---|
202 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
203 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
204 | return; |
---|
205 | } |
---|
206 | |
---|
207 | $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2'; |
---|
208 | $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml'; |
---|
209 | |
---|
210 | $p_title = __('This blog\'s entries %s feed'); |
---|
211 | $c_title = __('This blog\'s comments %s feed'); |
---|
212 | |
---|
213 | $res = |
---|
214 | ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
215 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
216 | '<ul>'; |
---|
217 | |
---|
218 | $res .= |
---|
219 | '<li><a type="'.$mime.'" '. |
---|
220 | 'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '. |
---|
221 | 'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. |
---|
222 | __('Entries feed').'</a></li>'; |
---|
223 | |
---|
224 | if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks) |
---|
225 | { |
---|
226 | $res .= |
---|
227 | '<li><a type="'.$mime.'" '. |
---|
228 | 'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '. |
---|
229 | 'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. |
---|
230 | __('Comments feed').'</a></li>'; |
---|
231 | } |
---|
232 | |
---|
233 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
234 | |
---|
235 | return $res; |
---|
236 | } |
---|
237 | |
---|
238 | public static function feed($w) |
---|
239 | { |
---|
240 | if (!$w->url) { |
---|
241 | return; |
---|
242 | } |
---|
243 | |
---|
244 | global $core; |
---|
245 | |
---|
246 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
247 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
248 | return; |
---|
249 | } |
---|
250 | |
---|
251 | $limit = abs((integer) $w->limit); |
---|
252 | |
---|
253 | try { |
---|
254 | $feed = feedReader::quickParse($w->url,DC_TPL_CACHE); |
---|
255 | if ($feed == false || count($feed->items) == 0) { |
---|
256 | return; |
---|
257 | } |
---|
258 | } catch (Exception $e) { |
---|
259 | return; |
---|
260 | } |
---|
261 | |
---|
262 | $res = |
---|
263 | ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
264 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
265 | '<ul>'; |
---|
266 | |
---|
267 | $i = 0; |
---|
268 | foreach ($feed->items as $item) { |
---|
269 | $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : ''; |
---|
270 | $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : ''; |
---|
271 | |
---|
272 | if (!$link && !$title) { |
---|
273 | continue; |
---|
274 | } |
---|
275 | |
---|
276 | if (!$title) { |
---|
277 | $title = substr($link,0,25).'...'; |
---|
278 | } |
---|
279 | |
---|
280 | $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title; |
---|
281 | $res .= ' <li>'.$li.'</li> '; |
---|
282 | $i++; |
---|
283 | if ($i >= $limit) { |
---|
284 | break; |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
289 | |
---|
290 | return $res; |
---|
291 | } |
---|
292 | |
---|
293 | public static function text($w) |
---|
294 | { |
---|
295 | global $core; |
---|
296 | |
---|
297 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
298 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
299 | return; |
---|
300 | } |
---|
301 | |
---|
302 | $res = |
---|
303 | ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
304 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
305 | $w->text. |
---|
306 | ($w->content_only ? '' : '</div>'); |
---|
307 | |
---|
308 | return $res; |
---|
309 | } |
---|
310 | |
---|
311 | public static function lastposts($w) |
---|
312 | { |
---|
313 | global $core; |
---|
314 | |
---|
315 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
316 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | $params['limit'] = abs((integer) $w->limit); |
---|
321 | $params['order'] = 'post_dt desc'; |
---|
322 | $params['no_content'] = true; |
---|
323 | |
---|
324 | if ($w->category) |
---|
325 | { |
---|
326 | if ($w->category == 'null') { |
---|
327 | $params['sql'] = ' AND P.cat_id IS NULL '; |
---|
328 | } elseif (is_numeric($w->category)) { |
---|
329 | $params['cat_id'] = (integer) $w->category; |
---|
330 | } else { |
---|
331 | $params['cat_url'] = $w->category; |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | if ($w->tag) |
---|
336 | { |
---|
337 | $params['meta_id'] = $w->tag; |
---|
338 | $rs = $core->meta->getPostsByMeta($params); |
---|
339 | } |
---|
340 | else |
---|
341 | { |
---|
342 | $rs = $core->blog->getPosts($params); |
---|
343 | } |
---|
344 | |
---|
345 | if ($rs->isEmpty()) { |
---|
346 | return; |
---|
347 | } |
---|
348 | |
---|
349 | $res = |
---|
350 | ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
351 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
352 | '<ul>'; |
---|
353 | |
---|
354 | while ($rs->fetch()) { |
---|
355 | $res .= '<li><a href="'.$rs->getURL().'">'. |
---|
356 | html::escapeHTML($rs->post_title).'</a></li>'; |
---|
357 | } |
---|
358 | |
---|
359 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
360 | |
---|
361 | return $res; |
---|
362 | } |
---|
363 | |
---|
364 | public static function lastcomments($w) |
---|
365 | { |
---|
366 | global $core; |
---|
367 | |
---|
368 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
369 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
370 | return; |
---|
371 | } |
---|
372 | |
---|
373 | $params['limit'] = abs((integer) $w->limit); |
---|
374 | $params['order'] = 'comment_dt desc'; |
---|
375 | $rs = $core->blog->getComments($params); |
---|
376 | |
---|
377 | if ($rs->isEmpty()) { |
---|
378 | return; |
---|
379 | } |
---|
380 | |
---|
381 | $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
382 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
383 | '<ul>'; |
---|
384 | |
---|
385 | while ($rs->fetch()) |
---|
386 | { |
---|
387 | $res .= '<li class="'. |
---|
388 | ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment'). |
---|
389 | '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'. |
---|
390 | html::escapeHTML($rs->post_title).' - '. |
---|
391 | html::escapeHTML($rs->comment_author). |
---|
392 | '</a></li>'; |
---|
393 | } |
---|
394 | |
---|
395 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
396 | |
---|
397 | return $res; |
---|
398 | } |
---|
399 | } |
---|
400 | ?> |
---|