Dotclear

source: plugins/widgets/_widgets_functions.php @ 851:0993f64c4809

Revision 851:0993f64c4809, 6.5 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

sexy step 2 : no more cats.

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

Sites map