Dotclear

source: plugins/widgets/_widgets_functions.php @ 2565:b4e45fdd906b

Revision 2565:b4e45fdd906b, 10.2 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add blog URL before relative lang URL in lang widget, fixes #1871

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 ? '<h2><label for="q">'.html::escapeHTML($w->title).'</label></h2>' : '').
31          '<form action="'.$core->blog->url.'" method="get">'.
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 ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
52          '<ul>';
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 ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '');
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;
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 ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
149          '<ul>';
150
151          while ($rs->fetch()) {
152               $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> ';
153          }
154
155          $res .= '</ul>'.($w->content_only ? '' : '</div>');
156
157          return $res;
158     }
159
160     public static function langs($w)
161     {
162          global $core, $_ctx;
163
164          if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') ||
165               ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) {
166               return;
167          }
168
169          $rs = $core->blog->getLangs();
170
171          if ($rs->count() <= 1) {
172               return;
173          }
174
175          $langs = l10n::getISOcodes();
176          $res =
177          ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
178          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
179          '<ul>';
180
181          while ($rs->fetch())
182          {
183               $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
184
185               $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
186
187               $res .=
188               ' <li>'.
189               sprintf($l,
190                    '<a href="'.$core->blog->url.$core->url->getURLFor('lang',$rs->post_lang).'" '.
191                    'class="lang-'.$rs->post_lang.'">'.
192                    $lang_name.'</a>').
193               ' </li>';
194          }
195
196          $res .= '</ul>'.($w->content_only ? '' : '</div>');
197
198          return $res;
199     }
200
201     public static function subscribe($w)
202     {
203          global $core;
204
205          if (($w->homeonly == 1 && $core->url->type != 'default') ||
206               ($w->homeonly == 2 && $core->url->type == 'default')) {
207               return;
208          }
209
210          $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
211          $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
212
213          $p_title = __('This blog\'s entries %s feed');
214          $c_title = __('This blog\'s comments %s feed');
215
216          $res =
217          ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
218          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
219          '<ul>';
220
221          $res .=
222          '<li><a type="'.$mime.'" '.
223          'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '.
224          'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
225          __('Entries feed').'</a></li>';
226
227          if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks)
228          {
229               $res .=
230               '<li><a type="'.$mime.'" '.
231               'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '.
232               'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
233               __('Comments feed').'</a></li>';
234          }
235
236          $res .= '</ul>'.($w->content_only ? '' : '</div>');
237
238          return $res;
239     }
240
241     public static function feed($w)
242     {
243          if (!$w->url) {
244               return;
245          }
246
247          global $core;
248
249          if (($w->homeonly == 1 && $core->url->type != 'default') ||
250               ($w->homeonly == 2 && $core->url->type == 'default')) {
251               return;
252          }
253
254          $limit = abs((integer) $w->limit);
255
256          try {
257               $feed = feedReader::quickParse($w->url,DC_TPL_CACHE);
258               if ($feed == false || count($feed->items) == 0) {
259                    return;
260               }
261          } catch (Exception $e) {
262               return;
263          }
264
265          $res =
266          ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
267          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
268          '<ul>';
269
270          $i = 0;
271          foreach ($feed->items as $item) {
272               $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : '';
273               $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : '';
274
275               if (!$link && !$title) {
276                    continue;
277               }
278
279               if (!$title) {
280                    $title = substr($link,0,25).'...';
281               }
282
283               $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title;
284               $res .= ' <li>'.$li.'</li> ';
285               $i++;
286               if ($i >= $limit) {
287                    break;
288               }
289          }
290
291          $res .= '</ul>'.($w->content_only ? '' : '</div>');
292
293          return $res;
294     }
295
296     public static function text($w)
297     {
298          global $core;
299
300          if (($w->homeonly == 1 && $core->url->type != 'default') ||
301               ($w->homeonly == 2 && $core->url->type == 'default')) {
302               return;
303          }
304
305          $res =
306          ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
307          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
308          $w->text.
309          ($w->content_only ? '' : '</div>');
310
311          return $res;
312     }
313
314     public static function lastposts($w)
315     {
316          global $core;
317
318          if (($w->homeonly == 1 && $core->url->type != 'default') ||
319               ($w->homeonly == 2 && $core->url->type == 'default')) {
320               return;
321          }
322
323          $params['limit'] = abs((integer) $w->limit);
324          $params['order'] = 'post_dt desc';
325          $params['no_content'] = true;
326
327          if ($w->category)
328          {
329               if ($w->category == 'null') {
330                    $params['sql'] = ' AND P.cat_id IS NULL ';
331               } elseif (is_numeric($w->category)) {
332                    $params['cat_id'] = (integer) $w->category;
333               } else {
334                    $params['cat_url'] = $w->category;
335               }
336          }
337
338          if ($w->tag)
339          {
340               $params['meta_id'] = $w->tag;
341               $rs = $core->meta->getPostsByMeta($params);
342          }
343          else
344          {
345               $rs = $core->blog->getPosts($params);
346          }
347
348          if ($rs->isEmpty()) {
349               return;
350          }
351
352          $res =
353          ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
354          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
355          '<ul>';
356
357          while ($rs->fetch()) {
358               $res .= '<li><a href="'.$rs->getURL().'">'.
359               html::escapeHTML($rs->post_title).'</a></li>';
360          }
361
362          $res .= '</ul>'.($w->content_only ? '' : '</div>');
363
364          return $res;
365     }
366
367     public static function lastcomments($w)
368     {
369          global $core;
370
371          if (($w->homeonly == 1 && $core->url->type != 'default') ||
372               ($w->homeonly == 2 && $core->url->type == 'default')) {
373               return;
374          }
375
376          $params['limit'] = abs((integer) $w->limit);
377          $params['order'] = 'comment_dt desc';
378          $rs = $core->blog->getComments($params);
379
380          if ($rs->isEmpty()) {
381               return;
382          }
383
384          $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
385          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
386          '<ul>';
387
388          while ($rs->fetch())
389          {
390               $res .= '<li class="'.
391               ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment').
392               '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'.
393               html::escapeHTML($rs->post_title).' - '.
394               html::escapeHTML($rs->comment_author).
395               '</a></li>';
396          }
397
398          $res .= '</ul>'.($w->content_only ? '' : '</div>');
399
400          return $res;
401     }
402}
Note: See TracBrowser for help on using the repository browser.

Sites map