Dotclear

source: plugins/widgets/_widgets_functions.php @ 1107:3943962d69b8

Revision 1107:3943962d69b8, 8.1 KB checked in by JcDenis, 12 years ago (diff)

merge with default branch in 2.5-RC

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          if (($w->homeonly == 1 && $core->url->type != 'default') ||
21               ($w->homeonly == 2 && $core->url->type == 'default')) {
22               return;
23          }
24
25          $value = isset($GLOBALS['_search']) ? html::escapeHTML($GLOBALS['_search']) : '';
26         
27          return
28          ($w->content_only ? '' : '<div id="search"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>').
29          ($w->title ? '<h2><label for="q">'.html::escapeHTML($w->title).'</label></h2>' : '').
30          '<form action="'.$core->blog->url.'" method="get">'.
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>'.
36          ($w->content_only ? '' : '</div>');
37     }
38     
39     public static function navigation($w)
40     {
41          global $core;
42         
43          if (($w->homeonly == 1 && $core->url->type != 'default') ||
44               ($w->homeonly == 2 && $core->url->type == 'default')) {
45               return;
46          }
47
48          $res =
49          ($w->content_only ? '' : '<div id="topnav"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>').
50          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
51          '<ul>';
52         
53          if ($core->url->type != 'default') {
54               $res .=
55               '<li class="topnav-home">'.
56               '<a href="'.$core->blog->url.'">'.__('Home').'</a>'.
57               '<span> - </span></li>';
58          }
59         
60          $res .=
61          '<li class="topnav-arch">'.
62          '<a href="'.$core->blog->url.$core->url->getURLFor("archive").'">'.
63          __('Archives').'</a></li>'.
64          '</ul>'.
65          ($w->content_only ? '' : '</div>');
66         
67          return $res;
68     }
69     
70
71     public static function bestof($w)
72     {
73          global $core;
74         
75          if (($w->homeonly == 1 && $core->url->type != 'default') ||
76               ($w->homeonly == 2 && $core->url->type == 'default')) {
77               return;
78          }
79         
80          $params = array(
81               'post_selected'     => true,
82               'no_content'        => true,
83               'order'             => 'post_dt '.strtoupper($w->orderby)
84          );
85         
86          $rs = $core->blog->getPosts($params);
87         
88          if ($rs->isEmpty()) {
89               return;
90          }
91         
92          $res =
93          ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
94          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
95          '<ul>';
96         
97          while ($rs->fetch()) {
98               $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> ';
99          }
100         
101          $res .= '</ul>'.($w->content_only ? '' : '</div>');
102         
103          return $res;
104     }
105     
106     public static function langs($w)
107     {
108          global $core, $_ctx;
109         
110          if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') ||
111               ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) {
112               return;
113          }
114         
115          $rs = $core->blog->getLangs();
116         
117          if ($rs->count() <= 1) {
118               return;
119          }
120         
121          $langs = l10n::getISOcodes();
122          $res =
123          ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
124          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
125          '<ul>';
126         
127          while ($rs->fetch())
128          {
129               $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
130               
131               $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
132               
133               $res .=
134               ' <li>'.
135               sprintf($l,
136                    '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '.
137                    'class="lang-'.$rs->post_lang.'">'.
138                    $lang_name.'</a>').
139               ' </li>';
140          }
141         
142          $res .= '</ul>'.($w->content_only ? '' : '</div>');
143         
144          return $res;
145     }
146     
147     public static function subscribe($w)
148     {
149          global $core;
150         
151          if (($w->homeonly == 1 && $core->url->type != 'default') ||
152               ($w->homeonly == 2 && $core->url->type == 'default')) {
153               return;
154          }
155         
156          $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
157          $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
158         
159          $p_title = __('This blog\'s entries %s feed');
160         
161          $res =
162          ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
163          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
164          '<ul>';
165         
166          $res .=
167          '<li><a type="'.$mime.'" '.
168          'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '.
169          'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
170          __('Entries feed').'</a></li>';
171         
172          $res .= '</ul>'.($w->content_only ? '' : '</div>');
173         
174          return $res;
175     }
176     
177     public static function feed($w)
178     {
179          if (!$w->url) {
180               return;
181          }
182         
183          global $core;
184         
185          if (($w->homeonly == 1 && $core->url->type != 'default') ||
186               ($w->homeonly == 2 && $core->url->type == 'default')) {
187               return;
188          }
189         
190          $limit = abs((integer) $w->limit);
191         
192          try {
193               $feed = feedReader::quickParse($w->url,DC_TPL_CACHE);
194               if ($feed == false || count($feed->items) == 0) {
195                    return;
196               }
197          } catch (Exception $e) {
198               return;
199          }
200         
201          $res =
202          ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
203          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
204          '<ul>';
205         
206          $i = 0;
207          foreach ($feed->items as $item) {
208               $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : '';
209               $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : '';
210               
211               if (!$link && !$title) {
212                    continue;
213               }
214               
215               if (!$title) {
216                    $title = substr($link,0,25).'...';
217               }
218               
219               $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title;
220               $res .= ' <li>'.$li.'</li> ';
221               $i++;
222               if ($i >= $limit) {
223                    break;
224               }
225          }
226         
227          $res .= '</ul>'.($w->content_only ? '' : '</div>');
228         
229          return $res;
230     }
231     
232     public static function text($w)
233     {
234          global $core;
235         
236          if (($w->homeonly == 1 && $core->url->type != 'default') ||
237               ($w->homeonly == 2 && $core->url->type == 'default')) {
238               return;
239          }
240         
241          $res =
242          ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
243          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
244          $w->text.
245          ($w->content_only ? '' : '</div>');
246         
247          return $res;
248     }
249     
250     public static function lastposts($w)
251     {
252          global $core;
253         
254          if (($w->homeonly == 1 && $core->url->type != 'default') ||
255               ($w->homeonly == 2 && $core->url->type == 'default')) {
256               return;
257          }
258         
259          $params['limit'] = abs((integer) $w->limit);
260          $params['order'] = 'post_dt desc';
261          $params['no_content'] = true;
262         
263          if ($w->tag)
264          {
265               $params['meta_id'] = $w->tag;
266               $rs = $core->meta->getPostsByMeta($params);
267          }
268          else
269          {
270               $rs = $core->blog->getPosts($params);
271          }
272         
273          if ($rs->isEmpty()) {
274               return;
275          }
276         
277          $res =
278          ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
279          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
280          '<ul>';
281         
282          while ($rs->fetch()) {
283               $res .= '<li><a href="'.$rs->getURL().'">'.
284               html::escapeHTML($rs->post_title).'</a></li>';
285          }
286         
287          $res .= '</ul>'.($w->content_only ? '' : '</div>');
288         
289          return $res;
290     }
291     
292     public static function lastcomments($w)
293     {
294          global $core;
295         
296          if (($w->homeonly == 1 && $core->url->type != 'default') ||
297               ($w->homeonly == 2 && $core->url->type == 'default')) {
298               return;
299          }
300         
301          $params['limit'] = abs((integer) $w->limit);
302          $params['order'] = 'comment_dt desc';
303          $rs = $core->blog->getComments($params);
304         
305          if ($rs->isEmpty()) {
306               return;
307          }
308         
309          $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
310          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
311          '<ul>';
312         
313          while ($rs->fetch())
314          {
315               $res .= '<li class="'.
316               ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment').
317               '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'.
318               html::escapeHTML($rs->post_title).' - '.
319               html::escapeHTML($rs->comment_author).
320               '</a></li>';
321          }
322         
323          $res .= '</ul>'.($w->content_only ? '' : '</div>');
324         
325          return $res;
326     }
327}
328?>
Note: See TracBrowser for help on using the repository browser.

Sites map