1 | <?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ |
---|
2 | /***************************************************************\ |
---|
3 | * This is 'Dcom', a plugin for Dotclear 2 * |
---|
4 | * * |
---|
5 | * Copyright (c) 2007-2008 * |
---|
6 | * Oleksandr Syenchuk, Jean-François Michaud and contributors.* |
---|
7 | * * |
---|
8 | * This is an open source software, distributed under the GNU * |
---|
9 | * General Public License (version 2) terms and conditions. * |
---|
10 | * * |
---|
11 | * You should have received a copy of the GNU General Public * |
---|
12 | * License along 'Dcom' (see COPYING.txt); * |
---|
13 | * if not, write to the Free Software Foundation, Inc., * |
---|
14 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
15 | \***************************************************************/ |
---|
16 | if (!defined('DC_RC_PATH')) { return; } |
---|
17 | |
---|
18 | $core->tpl->addValue('showDcom',array('publicDcom','showTpl')); |
---|
19 | |
---|
20 | class publicDcom |
---|
21 | { |
---|
22 | public static function showWidget($w) |
---|
23 | { |
---|
24 | global $core; |
---|
25 | |
---|
26 | if ($w->homeonly && $core->url->type != 'default') { |
---|
27 | return; |
---|
28 | } |
---|
29 | |
---|
30 | $p = array(); |
---|
31 | $p['t_limit'] = $w->t_limit; |
---|
32 | $p['c_limit'] = $w->c_limit; |
---|
33 | $p['co_limit'] = $w->co_limit; |
---|
34 | $p['title'] = $w->title; |
---|
35 | $p['stringformat'] = $w->stringformat; |
---|
36 | $p['dateformat'] = $w->dateformat; |
---|
37 | |
---|
38 | commonDcom::adjustDefaults($p); |
---|
39 | |
---|
40 | $res = '<div class="lastcomments">'. |
---|
41 | ($p['title'] ? '<h2>'.html::escapeHTML($p['title']).'</h2>' : ''). |
---|
42 | self::show($p). |
---|
43 | '</div>'; |
---|
44 | |
---|
45 | return $res; |
---|
46 | } |
---|
47 | |
---|
48 | public static function showTpl($attr) |
---|
49 | { |
---|
50 | commonDcom::adjustDefaults($attr); |
---|
51 | |
---|
52 | return '<?php echo publicDcom::show(unserialize(\''. |
---|
53 | addcslashes(serialize($attr),'\'\\').'\')); ?>'; |
---|
54 | } |
---|
55 | |
---|
56 | public static function show($p) |
---|
57 | { |
---|
58 | global $core; |
---|
59 | |
---|
60 | $params = array(); |
---|
61 | $params['limit'] = $p['c_limit']; |
---|
62 | $params['order'] = 'comment_dt desc'; |
---|
63 | $rs = $core->blog->getComments($params); |
---|
64 | unset($params); |
---|
65 | |
---|
66 | if ($rs->isEmpty()) { |
---|
67 | return; |
---|
68 | } |
---|
69 | |
---|
70 | $res = '<ul>'; |
---|
71 | |
---|
72 | $url = |
---|
73 | $date = $title = $author = $comment = ''; |
---|
74 | $s_url = strpos($p['stringformat'],'%5$s') === false ? false : true; |
---|
75 | $s_date = strpos($p['stringformat'],'%1$s') === false ? false : true; |
---|
76 | $s_title = strpos($p['stringformat'],'%2$s') === false ? false : true; |
---|
77 | $s_author = strpos($p['stringformat'],'%3$s') === false ? false : true; |
---|
78 | $s_comment = strpos($p['stringformat'],'%4$s') === false ? false : true; |
---|
79 | |
---|
80 | while ($rs->fetch()) |
---|
81 | { |
---|
82 | if ($s_url) { |
---|
83 | $url = $rs->getPostURL().'#c'.$rs->comment_id; |
---|
84 | } |
---|
85 | if ($s_date) { |
---|
86 | $date = $rs->getTime($p['dateformat']); |
---|
87 | } |
---|
88 | if ($s_title) { |
---|
89 | $title = self::truncate($rs->post_title,$p['t_limit'],false); |
---|
90 | } |
---|
91 | if ($s_author) { |
---|
92 | $author = html::escapeHTML($rs->comment_author); |
---|
93 | } |
---|
94 | if ($s_comment) { |
---|
95 | $comment = self::truncate($rs->comment_content,$p['co_limit']); |
---|
96 | } |
---|
97 | |
---|
98 | $res .= '<li>'.sprintf($p['stringformat'],$date,$title,$author,$comment,$url).'</li>'; |
---|
99 | } |
---|
100 | |
---|
101 | $res .= '</ul>'; |
---|
102 | |
---|
103 | return $res; |
---|
104 | } |
---|
105 | |
---|
106 | public static function truncate($str,$maxlength,$html=true) |
---|
107 | { |
---|
108 | # On rend la chaîne lisible |
---|
109 | if ($html) { |
---|
110 | $str = html::decodeEntities(html::clean($str)); |
---|
111 | } |
---|
112 | |
---|
113 | # On coupe la chaîne si elle est trop longue |
---|
114 | if (mb_strlen($str) > $maxlength) { |
---|
115 | $str = text::cutString($str,$maxlength).'…'; |
---|
116 | } |
---|
117 | |
---|
118 | # On encode la chaîne pour pouvoir l'insérer dans un document HTML |
---|
119 | return html::escapeHTML($str); |
---|
120 | } |
---|
121 | } |
---|
122 | ?> |
---|