Dotclear

source: plugins/widgets/_widgets_functions.php @ 776:4ce635c0ca26

Revision 776:4ce635c0ca26, 8.1 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

Last updates to getURLFor : removed blog url from function

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 categories($w)
61     {
62          global $core, $_ctx;
63         
64          $rs = $core->blog->getCategories(array('post_type'=>'post'));
65          if ($rs->isEmpty()) {
66               return;
67          }
68         
69          $res =
70          '<div class="categories">'.
71          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '');
72         
73          $ref_level = $level = $rs->level-1;
74          while ($rs->fetch())
75          {
76               $class = '';
77               if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id)
78               || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) {
79                    $class = ' class="category-current"';
80               }
81               
82               if ($rs->level > $level) {
83                    $res .= str_repeat('<ul><li'.$class.'>',$rs->level - $level);
84               } elseif ($rs->level < $level) {
85                    $res .= str_repeat('</li></ul>',-($rs->level - $level));
86               }
87               
88               if ($rs->level <= $level) {
89                    $res .= '</li><li'.$class.'>';
90               }
91               
92               $res .=
93               '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'.
94               html::escapeHTML($rs->cat_title).'</a>'.
95               ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : '');
96               
97               
98               $level = $rs->level;
99          }
100         
101          if ($ref_level - $level < 0) {
102               $res .= str_repeat('</li></ul>',-($ref_level - $level));
103          }
104          $res .= '</div>';
105         
106          return $res;
107     }
108     
109     public static function bestof($w)
110     {
111          global $core;
112         
113          if ($w->homeonly && $core->url->type != 'default') {
114               return;
115          }
116         
117          $params = array(
118               'post_selected'     => true,
119               'no_content'        => true,
120               'order'             => 'post_dt '.strtoupper($w->orderby)
121          );
122         
123          $rs = $core->blog->getPosts($params);
124         
125          if ($rs->isEmpty()) {
126               return;
127          }
128         
129          $res =
130          '<div class="selected">'.
131          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
132          '<ul>';
133         
134          while ($rs->fetch()) {
135               $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> ';
136          }
137         
138          $res .= '</ul></div>';
139         
140          return $res;
141     }
142     
143     public static function langs($w)
144     {
145          global $core, $_ctx;
146         
147          if ($w->homeonly && $core->url->type != 'default' && $core->url->type != 'lang') {
148               return;
149          }
150         
151          $rs = $core->blog->getLangs();
152         
153          if ($rs->count() <= 1) {
154               return;
155          }
156         
157          $langs = l10n::getISOcodes();
158          $res =
159          '<div class="langs">'.
160          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
161          '<ul>';
162         
163          while ($rs->fetch())
164          {
165               $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
166               
167               $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
168               
169               $res .=
170               ' <li>'.
171               sprintf($l,
172                    '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '.
173                    'class="lang-'.$rs->post_lang.'">'.
174                    $lang_name.'</a>').
175               ' </li>';
176          }
177         
178          $res .= '</ul></div>';
179         
180          return $res;
181     }
182     
183     public static function subscribe($w)
184     {
185          global $core;
186         
187          if ($w->homeonly && $core->url->type != 'default') {
188               return;
189          }
190         
191          $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
192          $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
193         
194          $p_title = __('This blog\'s entries %s feed');
195          $c_title = __('This blog\'s comments %s feed');
196         
197          $res =
198          '<div class="syndicate">'.
199          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
200          '<ul>';
201         
202          $res .=
203          '<li><a type="'.$mime.'" '.
204          'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '.
205          'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
206          __('Entries feed').'</a></li>';
207         
208          if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks)
209          {
210               $res .=
211               '<li><a type="'.$mime.'" '.
212               'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '.
213               'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'.
214               __('Comments feed').'</a></li>';
215          }
216         
217          $res .= '</ul></div>';
218         
219          return $res;
220     }
221     
222     public static function feed($w)
223     {
224          if (!$w->url) {
225               return;
226          }
227         
228          global $core;
229         
230          if ($w->homeonly && $core->url->type != 'default') {
231               return;
232          }
233         
234          $limit = abs((integer) $w->limit);
235         
236          try {
237               $feed = feedReader::quickParse($w->url,DC_TPL_CACHE);
238               if ($feed == false || count($feed->items) == 0) {
239                    return;
240               }
241          } catch (Exception $e) {
242               return;
243          }
244         
245          $res =
246          '<div class="feed">'.
247          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
248          '<ul>';
249         
250          $i = 0;
251          foreach ($feed->items as $item) {
252               $li = isset($item->link) ? '<a href="'.html::escapeHTML($item->link).'">'.$item->title.'</a>' : $item->title;
253               $res .= ' <li>'.$li.'</li> ';
254               $i++;
255               if ($i >= $limit) {
256                    break;
257               }
258          }
259         
260          $res .= '</ul></div>';
261         
262          return $res;
263     }
264     
265     public static function text($w)
266     {
267          global $core;
268         
269          if ($w->homeonly && $core->url->type != 'default') {
270               return;
271          }
272         
273          $res =
274          '<div class="text">'.
275          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
276          $w->text.
277          '</div>';
278         
279          return $res;
280     }
281     
282     public static function lastposts($w)
283     {
284          global $core;
285         
286          if ($w->homeonly && $core->url->type != 'default') {
287               return;
288          }
289         
290          $params['limit'] = abs((integer) $w->limit);
291          $params['order'] = 'post_dt desc';
292          $params['no_content'] = true;
293         
294          if ($w->category)
295          {
296               if ($w->category == 'null') {
297                    $params['sql'] = ' AND P.cat_id IS NULL ';
298               } elseif (is_numeric($w->category)) {
299                    $params['cat_id'] = (integer) $w->category;
300               } else {
301                    $params['cat_url'] = $w->category;
302               }
303          }
304         
305          if ($w->tag)
306          {
307               $params['meta_id'] = $w->tag;
308               $rs = $core->meta->getPostsByMeta($params);
309          }
310          else
311          {
312               $rs = $core->blog->getPosts($params);
313          }
314         
315          if ($rs->isEmpty()) {
316               return;
317          }
318         
319          $res =
320          '<div class="lastposts">'.
321          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
322          '<ul>';
323         
324          while ($rs->fetch()) {
325               $res .= '<li><a href="'.$rs->getURL().'">'.
326               html::escapeHTML($rs->post_title).'</a></li>';
327          }
328         
329          $res .= '</ul></div>';
330         
331          return $res;
332     }
333     
334     public static function lastcomments($w)
335     {
336          global $core;
337         
338          if ($w->homeonly && $core->url->type != 'default') {
339               return;
340          }
341         
342          $params['limit'] = abs((integer) $w->limit);
343          $params['order'] = 'comment_dt desc';
344          $rs = $core->blog->getComments($params);
345         
346          if ($rs->isEmpty()) {
347               return;
348          }
349         
350          $res = '<div class="lastcomments">'.
351          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
352          '<ul>';
353         
354          while ($rs->fetch())
355          {
356               $res .= '<li class="'.
357               ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment').
358               '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'.
359               html::escapeHTML($rs->post_title).' - '.
360               html::escapeHTML($rs->comment_author).
361               '</a></li>';
362          }
363         
364          $res .= '</ul></div>';
365         
366          return $res;
367     }
368}
369?>
Note: See TracBrowser for help on using the repository browser.

Sites map