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

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
[0]28          return
[1063]29          ($w->content_only ? '' : '<div id="search"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>').
[2662]30          ($w->title ? $w->renderTitle('<label for="q">'.html::escapeHTML($w->title).'</label>') : '').
[2605]31          '<form action="'.$core->blog->url.'" method="get" role="search">'.
[1280]32          '<fieldset>'.
[0]33          '<p><input type="text" size="10" maxlength="255" id="q" name="q" value="'.$value.'" /> '.
[75]34          '<input type="submit" class="submit" value="ok" /></p>'.
[1280]35          '</fieldset>'.
[0]36          '</form>'.
[1063]37          ($w->content_only ? '' : '</div>');
[0]38     }
[2565]39
[0]40     public static function navigation($w)
41     {
42          global $core;
[2565]43
[945]44          if (($w->homeonly == 1 && $core->url->type != 'default') ||
45               ($w->homeonly == 2 && $core->url->type == 'default')) {
46               return;
47          }
48
[0]49          $res =
[1063]50          ($w->content_only ? '' : '<div id="topnav"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>').
[2662]51          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[2605]52          '<ul role="navigation">';
[2565]53
[0]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          }
[2565]60
[0]61          $res .=
62          '<li class="topnav-arch">'.
[776]63          '<a href="'.$core->blog->url.$core->url->getURLFor("archive").'">'.
[0]64          __('Archives').'</a></li>'.
65          '</ul>'.
[1063]66          ($w->content_only ? '' : '</div>');
[2565]67
[0]68          return $res;
69     }
[2565]70
[0]71     public static function categories($w)
72     {
73          global $core, $_ctx;
[2565]74
[945]75          if (($w->homeonly == 1 && $core->url->type != 'default') ||
76               ($w->homeonly == 2 && $core->url->type == 'default')) {
77               return;
78          }
79
[1610]80          $rs = $core->blog->getCategories(array('post_type'=>'post','without_empty'=> !$w->with_empty));
[0]81          if ($rs->isEmpty()) {
82               return;
83          }
[2565]84
[0]85          $res =
[1063]86          ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]87          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '');
[2565]88
[0]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               }
[2565]97
[0]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               }
[2565]103
[0]104               if ($rs->level <= $level) {
105                    $res .= '</li><li'.$class.'>';
106               }
[2565]107
[0]108               $res .=
[776]109               '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'.
[0]110               html::escapeHTML($rs->cat_title).'</a>'.
[2198]111               ($w->postcount ? ' <span>('.($w->subcatscount ? $rs->nb_total : $rs->nb_post).')</span>' : '');
[2565]112
113
[0]114               $level = $rs->level;
115          }
[2565]116
[0]117          if ($ref_level - $level < 0) {
118               $res .= str_repeat('</li></ul>',-($ref_level - $level));
119          }
[1063]120          $res .= ($w->content_only ? '' : '</div>');
[2565]121
[0]122          return $res;
123     }
[2565]124
[0]125     public static function bestof($w)
126     {
[2653]127          global $core, $_ctx;
[2565]128
[945]129          if (($w->homeonly == 1 && $core->url->type != 'default') ||
130               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]131               return;
132          }
[2565]133
[0]134          $params = array(
135               'post_selected'     => true,
136               'no_content'        => true,
137               'order'             => 'post_dt '.strtoupper($w->orderby)
138          );
[2565]139
[0]140          $rs = $core->blog->getPosts($params);
[2565]141
[0]142          if ($rs->isEmpty()) {
143               return;
144          }
[2565]145
[0]146          $res =
[1063]147          ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]148          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]149          '<ul>';
[2565]150
[0]151          while ($rs->fetch()) {
[2653]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> ';
[0]157          }
[2565]158
[1063]159          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]160
[0]161          return $res;
162     }
[2565]163
[0]164     public static function langs($w)
165     {
166          global $core, $_ctx;
[2565]167
[945]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'))) {
[0]170               return;
171          }
[2565]172
[0]173          $rs = $core->blog->getLangs();
[2565]174
[0]175          if ($rs->count() <= 1) {
176               return;
177          }
[2565]178
[0]179          $langs = l10n::getISOcodes();
180          $res =
[1063]181          ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]182          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]183          '<ul>';
[2565]184
[0]185          while ($rs->fetch())
186          {
187               $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
[2565]188
[0]189               $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
[2565]190
[0]191               $res .=
192               ' <li>'.
193               sprintf($l,
[2565]194                    '<a href="'.$core->blog->url.$core->url->getURLFor('lang',$rs->post_lang).'" '.
[0]195                    'class="lang-'.$rs->post_lang.'">'.
196                    $lang_name.'</a>').
197               ' </li>';
198          }
[2565]199
[1063]200          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]201
[0]202          return $res;
203     }
[2565]204
[0]205     public static function subscribe($w)
206     {
207          global $core;
[2565]208
[945]209          if (($w->homeonly == 1 && $core->url->type != 'default') ||
210               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]211               return;
212          }
[2565]213
[0]214          $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
215          $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
[2565]216
[0]217          $p_title = __('This blog\'s entries %s feed');
218          $c_title = __('This blog\'s comments %s feed');
[2565]219
[0]220          $res =
[1063]221          ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]222          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]223          '<ul>';
[2565]224
[0]225          $res .=
226          '<li><a type="'.$mime.'" '.
[776]227          'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '.
[0]228          'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
229          __('Entries feed').'</a></li>';
[2565]230
[0]231          if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks)
232          {
233               $res .=
234               '<li><a type="'.$mime.'" '.
[776]235               'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '.
[0]236               'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
237               __('Comments feed').'</a></li>';
238          }
[2565]239
[1063]240          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]241
[0]242          return $res;
243     }
[2565]244
[0]245     public static function feed($w)
246     {
247          if (!$w->url) {
248               return;
249          }
[2565]250
[0]251          global $core;
[2565]252
[945]253          if (($w->homeonly == 1 && $core->url->type != 'default') ||
254               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]255               return;
256          }
[2565]257
[0]258          $limit = abs((integer) $w->limit);
[2565]259
[0]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          }
[2565]268
[0]269          $res =
[1063]270          ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]271          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]272          '<ul>';
[2565]273
[0]274          $i = 0;
275          foreach ($feed->items as $item) {
[862]276               $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : '';
277               $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : '';
[2565]278
[862]279               if (!$link && !$title) {
280                    continue;
281               }
[2565]282
[862]283               if (!$title) {
284                    $title = substr($link,0,25).'...';
285               }
[2565]286
[862]287               $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title;
[0]288               $res .= ' <li>'.$li.'</li> ';
289               $i++;
290               if ($i >= $limit) {
291                    break;
292               }
293          }
[2565]294
[1063]295          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]296
[0]297          return $res;
298     }
[2565]299
[0]300     public static function text($w)
301     {
302          global $core;
[2565]303
[945]304          if (($w->homeonly == 1 && $core->url->type != 'default') ||
305               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]306               return;
307          }
[2565]308
[0]309          $res =
[1063]310          ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]311          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]312          $w->text.
[1063]313          ($w->content_only ? '' : '</div>');
[2565]314
[0]315          return $res;
316     }
[2565]317
[0]318     public static function lastposts($w)
319     {
[2653]320          global $core, $_ctx;
[2565]321
[945]322          if (($w->homeonly == 1 && $core->url->type != 'default') ||
323               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]324               return;
325          }
[2565]326
[0]327          $params['limit'] = abs((integer) $w->limit);
328          $params['order'] = 'post_dt desc';
329          $params['no_content'] = true;
[2565]330
[0]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          }
[2565]341
[0]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          }
[2565]351
[0]352          if ($rs->isEmpty()) {
353               return;
354          }
[2565]355
[0]356          $res =
[1063]357          ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]358          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]359          '<ul>';
[2565]360
[0]361          while ($rs->fetch()) {
[2653]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().'">'.
[0]367               html::escapeHTML($rs->post_title).'</a></li>';
368          }
[2565]369
[1063]370          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]371
[0]372          return $res;
373     }
[2565]374
[0]375     public static function lastcomments($w)
376     {
377          global $core;
[2565]378
[945]379          if (($w->homeonly == 1 && $core->url->type != 'default') ||
380               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]381               return;
382          }
[2565]383
[0]384          $params['limit'] = abs((integer) $w->limit);
385          $params['order'] = 'comment_dt desc';
386          $rs = $core->blog->getComments($params);
[2565]387
[0]388          if ($rs->isEmpty()) {
389               return;
390          }
[2565]391
[1063]392          $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
[2662]393          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
[0]394          '<ul>';
[2565]395
[0]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          }
[2565]405
[1063]406          $res .= '</ul>'.($w->content_only ? '' : '</div>');
[2565]407
[0]408          return $res;
409     }
410}
Note: See TracBrowser for help on using the repository browser.

Sites map