1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | /** |
---|
25 | * This file is included by the picture page to manage user comments |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | // the picture is commentable if it belongs at least to one category which |
---|
30 | // is commentable |
---|
31 | $page['show_comments'] = false; |
---|
32 | foreach ($related_categories as $category) |
---|
33 | { |
---|
34 | if ($category['commentable'] == 'true') |
---|
35 | { |
---|
36 | $page['show_comments'] = true; |
---|
37 | break; |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | if ( $page['show_comments'] and isset( $_POST['content'] ) ) |
---|
42 | { |
---|
43 | if ( is_a_guest() and !$conf['comments_forall'] ) |
---|
44 | { |
---|
45 | die ('Session expired'); |
---|
46 | } |
---|
47 | |
---|
48 | $comm = array( |
---|
49 | 'author' => trim( stripslashes(@$_POST['author']) ), |
---|
50 | 'content' => trim( stripslashes($_POST['content']) ), |
---|
51 | 'image_id' => $page['image_id'], |
---|
52 | ); |
---|
53 | |
---|
54 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
55 | |
---|
56 | $comment_action = insert_user_comment($comm, @$_POST['key'], $infos ); |
---|
57 | |
---|
58 | switch ($comment_action) |
---|
59 | { |
---|
60 | case 'moderate': |
---|
61 | array_push( $infos, l10n('comment_to_validate') ); |
---|
62 | case 'validate': |
---|
63 | array_push( $infos, l10n('comment_added')); |
---|
64 | break; |
---|
65 | case 'reject': |
---|
66 | set_status_header(403); |
---|
67 | array_push($infos, l10n('comment_not_added') ); |
---|
68 | break; |
---|
69 | default: |
---|
70 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
71 | } |
---|
72 | |
---|
73 | $template->assign( |
---|
74 | ($comment_action=='reject') ? 'errors' : 'infos', |
---|
75 | $infos |
---|
76 | ); |
---|
77 | |
---|
78 | // allow plugins to notify what's going on |
---|
79 | trigger_action( 'user_comment_insertion', |
---|
80 | array_merge($comm, array('action'=>$comment_action) ) |
---|
81 | ); |
---|
82 | } |
---|
83 | elseif ( isset($_POST['content']) ) |
---|
84 | { |
---|
85 | set_status_header(403); |
---|
86 | die('ugly spammer'); |
---|
87 | } |
---|
88 | |
---|
89 | if ($page['show_comments']) |
---|
90 | { |
---|
91 | // number of comments for this picture |
---|
92 | $query = ' |
---|
93 | SELECT COUNT(*) AS nb_comments |
---|
94 | FROM '.COMMENTS_TABLE.' |
---|
95 | WHERE image_id='.$page['image_id']." AND validated = 'true'"; |
---|
96 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
97 | |
---|
98 | // navigation bar creation |
---|
99 | if (!isset($page['start'])) |
---|
100 | { |
---|
101 | $page['start'] = 0; |
---|
102 | } |
---|
103 | |
---|
104 | $navigation_bar = create_navigation_bar( |
---|
105 | duplicate_picture_url(array(), array('start')), |
---|
106 | $row['nb_comments'], |
---|
107 | $page['start'], |
---|
108 | $conf['nb_comment_page'], |
---|
109 | true // We want a clean URL |
---|
110 | ); |
---|
111 | |
---|
112 | $template->assign( |
---|
113 | array( |
---|
114 | 'COMMENT_COUNT' => $row['nb_comments'], |
---|
115 | 'COMMENT_NAV_BAR' => $navigation_bar, |
---|
116 | ) |
---|
117 | ); |
---|
118 | |
---|
119 | if ($row['nb_comments'] > 0) |
---|
120 | { |
---|
121 | $query = ' |
---|
122 | SELECT id,author,date,image_id,content |
---|
123 | FROM '.COMMENTS_TABLE.' |
---|
124 | WHERE image_id = '.$page['image_id'].' |
---|
125 | AND validated = \'true\' |
---|
126 | ORDER BY date ASC |
---|
127 | LIMIT '.$page['start'].', '.$conf['nb_comment_page'].' |
---|
128 | ;'; |
---|
129 | $result = pwg_query( $query ); |
---|
130 | |
---|
131 | while ($row = mysql_fetch_array($result)) |
---|
132 | { |
---|
133 | $tpl_comment = |
---|
134 | array( |
---|
135 | 'AUTHOR' => trigger_event('render_comment_author', |
---|
136 | empty($row['author']) |
---|
137 | ? l10n('guest') |
---|
138 | : $row['author']), |
---|
139 | |
---|
140 | 'DATE' => format_date( $row['date'], true), |
---|
141 | |
---|
142 | 'CONTENT' => trigger_event('render_comment_content',$row['content']), |
---|
143 | ); |
---|
144 | |
---|
145 | if (is_admin()) |
---|
146 | { |
---|
147 | $tpl_comment['U_DELETE'] = |
---|
148 | add_url_params( |
---|
149 | $url_self, |
---|
150 | array( |
---|
151 | 'action'=>'delete_comment', |
---|
152 | 'comment_to_delete'=>$row['id'], |
---|
153 | 'pwg_token'=>get_pwg_token(), |
---|
154 | ) |
---|
155 | ); |
---|
156 | } |
---|
157 | $template->append('comments', $tpl_comment); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | if (!is_a_guest() |
---|
162 | or (is_a_guest() and $conf['comments_forall'])) |
---|
163 | { |
---|
164 | $key = get_comment_post_key($page['image_id']); |
---|
165 | $content = ''; |
---|
166 | if ('reject'===@$comment_action) |
---|
167 | { |
---|
168 | $content = htmlspecialchars($comm['content']); |
---|
169 | } |
---|
170 | $template->assign('comment_add', |
---|
171 | array( |
---|
172 | 'F_ACTION' => $url_self, |
---|
173 | 'KEY' => $key, |
---|
174 | 'CONTENT' => $content, |
---|
175 | 'SHOW_AUTHOR' => !is_classic_user() |
---|
176 | )); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | ?> |
---|