Dotclear

source: plugins/widgets/_widgets_functions.php @ 2662:87748fd865ef

Revision 2662:87748fd865ef, 10.6 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

New rendering method (renderTitle) for widget title, fixes #1827

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

Sites map