Dotclear

source: plugins/widgets/_widgets_functions.php @ 2668:3d0ad13e89b4

Revision 2668:3d0ad13e89b4, 9.7 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

No more " - " after "home" link in navigation widget. So long and die hard, welcome modern CSS \o/

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

Sites map