Dotclear

source: plugins/widgets/_widgets_functions.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 12.6 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Simplify licence block at the beginning of each file

RevLine 
[0]1<?php
[3731]2/**
3 * @brief widgets, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
[2565]11
[3730]12if (!defined('DC_RC_PATH')) {return;}
[0]13
14class defaultWidgets
15{
[3730]16    public static function search($w)
17    {
18        global $core;
[2565]19
[3730]20        if ($core->blog->settings->system->no_search) {
21            return;
22        }
[3030]23
[3730]24        if ($w->offline) {
25            return;
26        }
[2778]27
[3730]28        if (($w->homeonly == 1 && $core->url->type != 'default') ||
29            ($w->homeonly == 2 && $core->url->type == 'default')) {
30            return;
31        }
[945]32
[3730]33        $value = isset($GLOBALS['_search']) ? html::escapeHTML($GLOBALS['_search']) : '';
[2565]34
[3730]35        return $w->renderDiv($w->content_only, $w->class, 'id="search"',
36            ($w->title ? $w->renderTitle('<label for="q">' . html::escapeHTML($w->title) . '</label>') : '') .
37            '<form action="' . $core->blog->url . '" method="get" role="search">' .
38            '<fieldset>' .
39            '<p><input type="text" size="10" maxlength="255" id="q" name="q" value="' . $value . '" ' .
40            ($w->placeholder ? 'placeholder="' . html::escapeHTML($w->placeholder) . '"' : '') . '/> ' .
41            '<input type="submit" class="submit" value="ok" /></p>' .
42            '</fieldset>' .
43            '</form>');
44    }
[2565]45
[3730]46    public static function navigation($w)
47    {
48        global $core;
[2565]49
[3730]50        if ($w->offline) {
51            return;
52        }
[2778]53
[3730]54        if (($w->homeonly == 1 && $core->url->type != 'default') ||
55            ($w->homeonly == 2 && $core->url->type == 'default')) {
56            return;
57        }
[945]58
[3730]59        $res =
60            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
61            '<nav role="navigation"><ul>';
[2565]62
[3730]63        if ($core->url->type != 'default') {
64            $res .=
65            '<li class="topnav-home">' .
66            '<a href="' . $core->blog->url . '">' . __('Home') . '</a>' .
67                '</li>';
68        }
[2565]69
[3730]70        $res .=
71        '<li class="topnav-arch">' .
72        '<a href="' . $core->blog->url . $core->url->getURLFor("archive") . '">' .
73        __('Archives') . '</a></li>' .
74            '</ul></nav>';
[2565]75
[3730]76        return $w->renderDiv($w->content_only, $w->class, 'id="topnav"', $res);
77    }
[2565]78
[3730]79    public static function categories($w)
80    {
81        global $core, $_ctx;
[2565]82
[3730]83        if ($w->offline) {
84            return;
85        }
[2778]86
[3730]87        if (($w->homeonly == 1 && $core->url->type != 'default') ||
88            ($w->homeonly == 2 && $core->url->type == 'default')) {
89            return;
90        }
[945]91
[3730]92        $rs = $core->blog->getCategories(array('post_type' => 'post', 'without_empty' => !$w->with_empty));
93        if ($rs->isEmpty()) {
94            return;
95        }
[2565]96
[3730]97        $res =
98            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '');
[2565]99
[3730]100        $ref_level = $level = $rs->level - 1;
101        while ($rs->fetch()) {
102            $class = '';
103            if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id)
104                || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) {
105                $class = ' class="category-current"';
106            }
[2565]107
[3730]108            if ($rs->level > $level) {
109                $res .= str_repeat('<ul><li' . $class . '>', $rs->level - $level);
110            } elseif ($rs->level < $level) {
111                $res .= str_repeat('</li></ul>', -($rs->level - $level));
112            }
[2565]113
[3730]114            if ($rs->level <= $level) {
115                $res .= '</li><li' . $class . '>';
116            }
[2565]117
[3730]118            $res .=
119            '<a href="' . $core->blog->url . $core->url->getURLFor('category', $rs->cat_url) . '">' .
120            html::escapeHTML($rs->cat_title) . '</a>' .
121                ($w->postcount ? ' <span>(' . ($w->subcatscount ? $rs->nb_total : $rs->nb_post) . ')</span>' : '');
[2565]122
[3730]123            $level = $rs->level;
124        }
[2565]125
[3730]126        if ($ref_level - $level < 0) {
127            $res .= str_repeat('</li></ul>', -($ref_level - $level));
128        }
[2565]129
[3730]130        return $w->renderDiv($w->content_only, 'categories ' . $w->class, '', $res);
131    }
[2565]132
[3730]133    public static function bestof($w)
134    {
135        global $core, $_ctx;
[2565]136
[3730]137        if ($w->offline) {
138            return;
139        }
[2565]140
[3730]141        if (($w->homeonly == 1 && $core->url->type != 'default') ||
142            ($w->homeonly == 2 && $core->url->type == 'default')) {
143            return;
144        }
[2778]145
[3730]146        $params = array(
147            'post_selected' => true,
148            'no_content'    => true,
149            'order'         => 'post_dt ' . strtoupper($w->orderby)
150        );
[2565]151
[3730]152        $rs = $core->blog->getPosts($params);
[2565]153
[3730]154        if ($rs->isEmpty()) {
155            return;
156        }
[2565]157
[3730]158        $res =
159            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
160            '<ul>';
[2565]161
[3730]162        while ($rs->fetch()) {
163            $class = '';
164            if ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id) {
165                $class = ' class="post-current"';
166            }
167            $res .= ' <li' . $class . '><a href="' . $rs->getURL() . '">' . html::escapeHTML($rs->post_title) . '</a></li> ';
168        }
[2565]169
[3730]170        $res .= '</ul>';
[2565]171
[3730]172        return $w->renderDiv($w->content_only, 'selected ' . $w->class, '', $res);
173    }
[2565]174
[3730]175    public static function langs($w)
176    {
177        global $core, $_ctx;
[2565]178
[3730]179        if ($w->offline) {
180            return;
181        }
[2565]182
[3730]183        if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') ||
184            ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) {
185            return;
186        }
[2778]187
[3730]188        $rs = $core->blog->getLangs();
[2565]189
[3730]190        if ($rs->count() <= 1) {
191            return;
192        }
[2565]193
[3730]194        $langs = l10n::getISOcodes();
195        $res   =
196            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
197            '<ul>';
[2565]198
[3730]199        while ($rs->fetch()) {
200            $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s';
[2565]201
[3730]202            $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang;
[2565]203
[3730]204            $res .=
205            ' <li>' .
206            sprintf($l,
207                '<a href="' . $core->blog->url . $core->url->getURLFor('lang', $rs->post_lang) . '" ' .
208                'class="lang-' . $rs->post_lang . '">' .
209                $lang_name . '</a>') .
210                ' </li>';
211        }
[2565]212
[3730]213        $res .= '</ul>';
[2565]214
[3730]215        return $w->renderDiv($w->content_only, 'langs ' . $w->class, '', $res);
216    }
[2565]217
[3730]218    public static function subscribe($w)
219    {
220        global $core;
[2565]221
[3730]222        if ($w->offline) {
223            return;
224        }
[2565]225
[3730]226        if (($w->homeonly == 1 && $core->url->type != 'default') ||
227            ($w->homeonly == 2 && $core->url->type == 'default')) {
228            return;
229        }
[2778]230
[3730]231        $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2';
232        $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml';
[2565]233
[3730]234        $p_title = __('This blog\'s entries %s feed');
235        $c_title = __('This blog\'s comments %s feed');
[2565]236
[3730]237        $res =
238            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
239            '<ul>';
[2565]240
[3730]241        $res .=
242        '<li><a type="' . $mime . '" ' .
243        'href="' . $core->blog->url . $core->url->getURLFor('feed', $type) . '" ' .
244        'title="' . sprintf($p_title, ($type == 'atom' ? 'Atom' : 'RSS')) . '" class="feed">' .
245        __('Entries feed') . '</a></li>';
[2565]246
[3730]247        if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks) {
248            $res .=
249            '<li><a type="' . $mime . '" ' .
250            'href="' . $core->blog->url . $core->url->getURLFor('feed', $type . '/comments') . '" ' .
251            'title="' . sprintf($c_title, ($type == 'atom' ? 'Atom' : 'RSS')) . '" class="feed">' .
252            __('Comments feed') . '</a></li>';
253        }
[2565]254
[3730]255        $res .= '</ul>';
[2565]256
[3730]257        return $w->renderDiv($w->content_only, 'syndicate ' . $w->class, '', $res);
258    }
[2565]259
[3730]260    public static function feed($w)
261    {
262        global $core;
[2565]263
[3730]264        if (!$w->url) {
265            return;
266        }
[2778]267
[3730]268        if ($w->offline) {
269            return;
270        }
[2565]271
[3730]272        if (($w->homeonly == 1 && $core->url->type != 'default') ||
273            ($w->homeonly == 2 && $core->url->type == 'default')) {
274            return;
275        }
[2565]276
[3730]277        $limit = abs((integer) $w->limit);
[2565]278
[3730]279        try {
280            $feed = feedReader::quickParse($w->url, DC_TPL_CACHE);
281            if ($feed == false || count($feed->items) == 0) {
282                return;
283            }
284        } catch (Exception $e) {
285            return;
286        }
[2565]287
[3730]288        $res =
289            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
290            '<ul>';
[2565]291
[3730]292        $i = 0;
293        foreach ($feed->items as $item) {
294            $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : '';
295            $link  = isset($item->link) && strlen(trim($item->link)) ? $item->link : '';
[2565]296
[3730]297            if (!$link && !$title) {
298                continue;
299            }
[2565]300
[3730]301            if (!$title) {
302                $title = substr($link, 0, 25) . '...';
303            }
[2565]304
[3730]305            $li = $link ? '<a href="' . html::escapeHTML($item->link) . '">' . $title . '</a>' : $title;
306            $res .= ' <li>' . $li . '</li> ';
307            $i++;
308            if ($i >= $limit) {
309                break;
310            }
311        }
[2565]312
[3730]313        $res .= '</ul>';
[2565]314
[3730]315        return $w->renderDiv($w->content_only, 'feed ' . $w->class, '', $res);
316    }
[2565]317
[3730]318    public static function text($w)
319    {
320        global $core;
[2565]321
[3730]322        if ($w->offline) {
323            return;
324        }
[2565]325
[3730]326        if (($w->homeonly == 1 && $core->url->type != 'default') ||
327            ($w->homeonly == 2 && $core->url->type == 'default')) {
328            return;
329        }
[2778]330
[3730]331        $res = ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . $w->text;
[2565]332
[3730]333        return $w->renderDiv($w->content_only, 'text ' . $w->class, '', $res);
334    }
[2565]335
[3730]336    public static function lastposts($w)
337    {
338        global $core, $_ctx;
[2565]339
[3730]340        if ($w->offline) {
341            return;
342        }
[2565]343
[3730]344        if (($w->homeonly == 1 && $core->url->type != 'default') ||
345            ($w->homeonly == 2 && $core->url->type == 'default')) {
346            return;
347        }
[2778]348
[3730]349        $params['limit']      = abs((integer) $w->limit);
350        $params['order']      = 'post_dt desc';
351        $params['no_content'] = true;
[2565]352
[3730]353        if ($w->category) {
354            if ($w->category == 'null') {
355                $params['sql'] = ' AND P.cat_id IS NULL ';
356            } elseif (is_numeric($w->category)) {
357                $params['cat_id'] = (integer) $w->category;
358            } else {
359                $params['cat_url'] = $w->category;
360            }
361        }
[2565]362
[3730]363        if ($w->tag) {
364            $params['meta_id'] = $w->tag;
365            $rs                = $core->meta->getPostsByMeta($params);
366        } else {
367            $rs = $core->blog->getPosts($params);
368        }
[2565]369
[3730]370        if ($rs->isEmpty()) {
371            return;
372        }
[2565]373
[3730]374        $res =
375            ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
376            '<ul>';
[2565]377
[3730]378        while ($rs->fetch()) {
379            $class = '';
380            if ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id) {
381                $class = ' class="post-current"';
382            }
383            $res .= '<li' . $class . '><a href="' . $rs->getURL() . '">' .
384            html::escapeHTML($rs->post_title) . '</a></li>';
385        }
[2565]386
[3730]387        $res .= '</ul>';
[2565]388
[3730]389        return $w->renderDiv($w->content_only, 'lastposts ' . $w->class, '', $res);
390    }
[2565]391
[3730]392    public static function lastcomments($w)
393    {
394        global $core;
[2565]395
[3730]396        if ($w->offline) {
397            return;
398        }
[2565]399
[3730]400        if (($w->homeonly == 1 && $core->url->type != 'default') ||
401            ($w->homeonly == 2 && $core->url->type == 'default')) {
402            return;
403        }
[2778]404
[3730]405        $params['limit'] = abs((integer) $w->limit);
406        $params['order'] = 'comment_dt desc';
407        $rs              = $core->blog->getComments($params);
[2565]408
[3730]409        if ($rs->isEmpty()) {
410            return;
411        }
[2565]412
[3730]413        $res = ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . '<ul>';
[2565]414
[3730]415        while ($rs->fetch()) {
416            $res .= '<li class="' .
417            ((boolean) $rs->comment_trackback ? 'last-tb' : 'last-comment') .
418            '"><a href="' . $rs->getPostURL() . '#c' . $rs->comment_id . '">' .
419            html::escapeHTML($rs->post_title) . ' - ' .
420            html::escapeHTML($rs->comment_author) .
421                '</a></li>';
422        }
[2565]423
[3730]424        $res .= '</ul>';
[2565]425
[3730]426        return $w->renderDiv($w->content_only, 'lastcomments ' . $w->class, '', $res);
427    }
[0]428}
Note: See TracBrowser for help on using the repository browser.

Sites map