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