Dotclear

source: plugins/widgets/_widgets_functions.php @ 904:f1fd70475361

Revision 904:f1fd70475361, 8.8 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Add class attribute (applied to encapsulated div) for standard widgets - Fixes #1230

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class 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'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
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'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
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->getURLFor("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'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
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->getURLFor('category', $rs->cat_url).'">'.
94               html::escapeHTML($rs->cat_title).'</a>'.
95               ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : '');
96               
97               
98               $level = $rs->level;
99          }
100         
101          if ($ref_level - $level < 0) {
102               $res .= str_repeat('</li></ul>',-($ref_level - $level));
103          }
104          $res .= '</div>';
105         
106          return $res;
107     }
108     
109     public static function bestof($w)
110     {
111          global $core;
112         
113          if ($w->homeonly && $core->url->type != 'default') {
114               return;
115          }
116         
117          $params = array(
118               'post_selected'     => true,
119               'no_content'        => true,
120               'order'             => 'post_dt '.strtoupper($w->orderby)
121          );
122         
123          $rs = $core->blog->getPosts($params);
124         
125          if ($rs->isEmpty()) {
126               return;
127          }
128         
129          $res =
130          '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
131          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
132          '<ul>';
133         
134          while ($rs->fetch()) {
135               $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> ';
136          }
137         
138          $res .= '</ul></div>';
139         
140          return $res;
141     }
142     
143     public static function langs($w)
144     {
145          global $core, $_ctx;
146         
147          if ($w->homeonly && $core->url->type != 'default' && $core->url->type != 'lang') {
148               return;
149          }
150         
151          $rs = $core->blog->getLangs();
152         
153          if ($rs->count() <= 1) {
154               return;
155          }
156         
157          $langs = l10n::getISOcodes();
158          $res =
159          '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
160          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
161          '<ul>';
162         
163          while ($rs->fetch())
164          {
165               $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
166               
167               $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
168               
169               $res .=
170               ' <li>'.
171               sprintf($l,
172                    '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '.
173                    'class="lang-'.$rs->post_lang.'">'.
174                    $lang_name.'</a>').
175               ' </li>';
176          }
177         
178          $res .= '</ul></div>';
179         
180          return $res;
181     }
182     
183     public static function subscribe($w)
184     {
185          global $core;
186         
187          if ($w->homeonly && $core->url->type != 'default') {
188               return;
189          }
190         
191          $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
192          $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
193         
194          $p_title = __('This blog\'s entries %s feed');
195          $c_title = __('This blog\'s comments %s feed');
196         
197          $res =
198          '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
199          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
200          '<ul>';
201         
202          $res .=
203          '<li><a type="'.$mime.'" '.
204          'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '.
205          'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
206          __('Entries feed').'</a></li>';
207         
208          if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks)
209          {
210               $res .=
211               '<li><a type="'.$mime.'" '.
212               'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '.
213               'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
214               __('Comments feed').'</a></li>';
215          }
216         
217          $res .= '</ul></div>';
218         
219          return $res;
220     }
221     
222     public static function feed($w)
223     {
224          if (!$w->url) {
225               return;
226          }
227         
228          global $core;
229         
230          if ($w->homeonly && $core->url->type != 'default') {
231               return;
232          }
233         
234          $limit = abs((integer) $w->limit);
235         
236          try {
237               $feed = feedReader::quickParse($w->url,DC_TPL_CACHE);
238               if ($feed == false || count($feed->items) == 0) {
239                    return;
240               }
241          } catch (Exception $e) {
242               return;
243          }
244         
245          $res =
246          '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
247          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
248          '<ul>';
249         
250          $i = 0;
251          foreach ($feed->items as $item) {
252               $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : '';
253               $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : '';
254               
255               if (!$link && !$title) {
256                    continue;
257               }
258               
259               if (!$title) {
260                    $title = substr($link,0,25).'...';
261               }
262               
263               $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title;
264               $res .= ' <li>'.$li.'</li> ';
265               $i++;
266               if ($i >= $limit) {
267                    break;
268               }
269          }
270         
271          $res .= '</ul></div>';
272         
273          return $res;
274     }
275     
276     public static function text($w)
277     {
278          global $core;
279         
280          if ($w->homeonly && $core->url->type != 'default') {
281               return;
282          }
283         
284          $res =
285          '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
286          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
287          $w->text.
288          '</div>';
289         
290          return $res;
291     }
292     
293     public static function lastposts($w)
294     {
295          global $core;
296         
297          if ($w->homeonly && $core->url->type != 'default') {
298               return;
299          }
300         
301          $params['limit'] = abs((integer) $w->limit);
302          $params['order'] = 'post_dt desc';
303          $params['no_content'] = true;
304         
305          if ($w->category)
306          {
307               if ($w->category == 'null') {
308                    $params['sql'] = ' AND P.cat_id IS NULL ';
309               } elseif (is_numeric($w->category)) {
310                    $params['cat_id'] = (integer) $w->category;
311               } else {
312                    $params['cat_url'] = $w->category;
313               }
314          }
315         
316          if ($w->tag)
317          {
318               $params['meta_id'] = $w->tag;
319               $rs = $core->meta->getPostsByMeta($params);
320          }
321          else
322          {
323               $rs = $core->blog->getPosts($params);
324          }
325         
326          if ($rs->isEmpty()) {
327               return;
328          }
329         
330          $res =
331          '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
332          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
333          '<ul>';
334         
335          while ($rs->fetch()) {
336               $res .= '<li><a href="'.$rs->getURL().'">'.
337               html::escapeHTML($rs->post_title).'</a></li>';
338          }
339         
340          $res .= '</ul></div>';
341         
342          return $res;
343     }
344     
345     public static function lastcomments($w)
346     {
347          global $core;
348         
349          if ($w->homeonly && $core->url->type != 'default') {
350               return;
351          }
352         
353          $params['limit'] = abs((integer) $w->limit);
354          $params['order'] = 'comment_dt desc';
355          $rs = $core->blog->getComments($params);
356         
357          if ($rs->isEmpty()) {
358               return;
359          }
360         
361          $res = '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
362          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
363          '<ul>';
364         
365          while ($rs->fetch())
366          {
367               $res .= '<li class="'.
368               ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment').
369               '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'.
370               html::escapeHTML($rs->post_title).' - '.
371               html::escapeHTML($rs->comment_author).
372               '</a></li>';
373          }
374         
375          $res .= '</ul></div>';
376         
377          return $res;
378     }
379}
380?>
Note: See TracBrowser for help on using the repository browser.

Sites map