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