1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of yafr, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2010 Osku and contributors |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # |
---|
12 | # -- END LICENSE BLOCK ------------------------------------ |
---|
13 | if (!defined('DC_RC_PATH')) { return; } |
---|
14 | |
---|
15 | class publicyafr |
---|
16 | { |
---|
17 | public static function Widget($w) |
---|
18 | { |
---|
19 | global $core; |
---|
20 | if (!$w->url) { |
---|
21 | return; |
---|
22 | } |
---|
23 | |
---|
24 | if ($w->homeonly && $core->url->type != 'default') { |
---|
25 | return; |
---|
26 | } |
---|
27 | |
---|
28 | $limit = abs((integer) $w->f_limit); |
---|
29 | |
---|
30 | try { |
---|
31 | $feed = feedReader::quickParse($w->url,DC_TPL_CACHE); |
---|
32 | if ($feed == false || count($feed->items) == 0) { |
---|
33 | return; |
---|
34 | } |
---|
35 | } catch (Exception $e) { |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | $url = $date = $title = $author = $content = $description = ''; |
---|
40 | $res = |
---|
41 | '<div class="feed '.html::escapeHTML($w->CSS).'">'. |
---|
42 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
43 | ($w->showtitle ? '<h3>'.html::escapeHTML($feed->title).'</h3>' : ''). |
---|
44 | ($w->showdesc ? '<p>'.html::escapeHTML($feed->description).'</p>' : ''). |
---|
45 | '<ul>'; |
---|
46 | |
---|
47 | $s_url = strpos($w->stringformat,'%5$s') === false ? false : true; |
---|
48 | $s_date = strpos($w->stringformat,'%1$s') === false ? false : true; |
---|
49 | $s_title = strpos($w->stringformat,'%2$s') === false ? false : true; |
---|
50 | $s_author = strpos($w->stringformat,'%3$s') === false ? false : true; |
---|
51 | $s_content = strpos($w->stringformat,'%4$s') === false ? false : true; |
---|
52 | $s_desc= strpos($w->stringformat,'%6$s') === false ? false : true; |
---|
53 | |
---|
54 | $i = 0; |
---|
55 | foreach ($feed->items as $item) { |
---|
56 | if ($s_url) { |
---|
57 | $url = $item->link; |
---|
58 | } |
---|
59 | if ($s_date) { |
---|
60 | $date = dt::dt2str($w->dateformat,$item->pubdate); |
---|
61 | } |
---|
62 | if ($s_title) { |
---|
63 | $title = self::truncateclean($item->title,$w->t_limit,false); |
---|
64 | } |
---|
65 | if ($s_author) { |
---|
66 | $author = html::escapeHTML($item->creator); |
---|
67 | } |
---|
68 | if ($s_content) { |
---|
69 | $content = ($w->cleancontent)? self::truncateclean($item->content,$w->fe_limit) : $item->content; |
---|
70 | } |
---|
71 | if ($s_desc) { |
---|
72 | $description = ($w->cleancontent)? self::truncateclean($item->description,$w->fe_limit) : $item->description; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | $res .= '<li>'.sprintf($w->stringformat,$date,$title,$author,$content,$url,$description).'</li>'; |
---|
77 | |
---|
78 | $i++; |
---|
79 | if ($i >= $limit) { |
---|
80 | break; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | $res .= '</ul></div>'; |
---|
85 | |
---|
86 | return $res; |
---|
87 | } |
---|
88 | |
---|
89 | public static function truncateclean($str,$maxlength,$html=true) |
---|
90 | { |
---|
91 | # On rend la chaîne lisible |
---|
92 | if ($html) { |
---|
93 | $str = html::decodeEntities(html::clean($str)); |
---|
94 | } |
---|
95 | |
---|
96 | if ($maxlength > 0) |
---|
97 | { |
---|
98 | # On coupe la chaîne si elle est trop longue |
---|
99 | if (mb_strlen($str) > $maxlength) { |
---|
100 | $str = text::cutString($str,$maxlength).'…'; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | # On encode la chaîne pour pouvoir l'insérer dans un document HTML |
---|
105 | return html::escapeHTML($str); |
---|
106 | } |
---|
107 | } |
---|
108 | ?> |
---|