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