[1082] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[19703] | 5 | // | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 23 | |
---|
| 24 | /** |
---|
| 25 | * This file is included by the picture page to manage user comments |
---|
[1090] | 26 | * |
---|
[1082] | 27 | */ |
---|
[1737] | 28 | |
---|
[1610] | 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) |
---|
[1082] | 33 | { |
---|
[18747] | 34 | if ($category['commentable']=='true') |
---|
[1082] | 35 | { |
---|
[1610] | 36 | $page['show_comments'] = true; |
---|
| 37 | break; |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
[10122] | 41 | if ( $page['show_comments'] and isset( $_POST['content'] ) ) |
---|
[1610] | 42 | { |
---|
[10122] | 43 | if ( is_a_guest() and !$conf['comments_forall'] ) |
---|
[1610] | 44 | { |
---|
[10122] | 45 | die ('Session expired'); |
---|
| 46 | } |
---|
[1610] | 47 | |
---|
[10122] | 48 | $comm = array( |
---|
| 49 | 'author' => trim( @$_POST['author'] ), |
---|
| 50 | 'content' => trim( $_POST['content'] ), |
---|
[17351] | 51 | 'website_url' => trim( $_POST['website_url'] ), |
---|
[18164] | 52 | 'email' => trim( @$_POST['email'] ), |
---|
[10122] | 53 | 'image_id' => $page['image_id'], |
---|
| 54 | ); |
---|
[1610] | 55 | |
---|
[10122] | 56 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
[2101] | 57 | |
---|
[18164] | 58 | $comment_action = insert_user_comment($comm, @$_POST['key'], $page['errors']); |
---|
[1610] | 59 | |
---|
[10122] | 60 | switch ($comment_action) |
---|
| 61 | { |
---|
| 62 | case 'moderate': |
---|
[12764] | 63 | array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.') ); |
---|
[10122] | 64 | case 'validate': |
---|
[12764] | 65 | array_push($page['infos'], l10n('Your comment has been registered')); |
---|
[10122] | 66 | break; |
---|
| 67 | case 'reject': |
---|
| 68 | set_status_header(403); |
---|
[12764] | 69 | array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules') ); |
---|
[10122] | 70 | break; |
---|
| 71 | default: |
---|
| 72 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
| 73 | } |
---|
[10097] | 74 | |
---|
[10122] | 75 | // allow plugins to notify what's going on |
---|
| 76 | trigger_action( 'user_comment_insertion', |
---|
| 77 | array_merge($comm, array('action'=>$comment_action) ) |
---|
| 78 | ); |
---|
[1082] | 79 | } |
---|
[10122] | 80 | elseif ( isset($_POST['content']) ) |
---|
| 81 | { |
---|
| 82 | set_status_header(403); |
---|
| 83 | die('ugly spammer'); |
---|
| 84 | } |
---|
[1082] | 85 | |
---|
| 86 | if ($page['show_comments']) |
---|
| 87 | { |
---|
[5654] | 88 | if ( !is_admin() ) |
---|
| 89 | { |
---|
| 90 | $validated_clause = ' AND validated = \'true\''; |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | $validated_clause = ''; |
---|
| 95 | } |
---|
| 96 | |
---|
[3145] | 97 | // number of comments for this picture |
---|
| 98 | $query = ' |
---|
[5654] | 99 | SELECT |
---|
| 100 | COUNT(*) AS nb_comments |
---|
[3145] | 101 | FROM '.COMMENTS_TABLE.' |
---|
[5654] | 102 | WHERE image_id = '.$page['image_id'] |
---|
| 103 | .$validated_clause.' |
---|
| 104 | ;'; |
---|
[4325] | 105 | $row = pwg_db_fetch_assoc( pwg_query( $query ) ); |
---|
[1082] | 106 | |
---|
| 107 | // navigation bar creation |
---|
[1084] | 108 | if (!isset($page['start'])) |
---|
[1082] | 109 | { |
---|
| 110 | $page['start'] = 0; |
---|
| 111 | } |
---|
[1090] | 112 | |
---|
[2227] | 113 | $navigation_bar = create_navigation_bar( |
---|
[1503] | 114 | duplicate_picture_url(array(), array('start')), |
---|
[1082] | 115 | $row['nb_comments'], |
---|
| 116 | $page['start'], |
---|
| 117 | $conf['nb_comment_page'], |
---|
[1084] | 118 | true // We want a clean URL |
---|
[1082] | 119 | ); |
---|
[1090] | 120 | |
---|
[2227] | 121 | $template->assign( |
---|
[1082] | 122 | array( |
---|
[2227] | 123 | 'COMMENT_COUNT' => $row['nb_comments'], |
---|
[3172] | 124 | 'navbar' => $navigation_bar, |
---|
[1082] | 125 | ) |
---|
| 126 | ); |
---|
| 127 | |
---|
| 128 | if ($row['nb_comments'] > 0) |
---|
| 129 | { |
---|
[12894] | 130 | // comments order (get, session, conf) |
---|
[13021] | 131 | if (!empty($_GET['comments_order']) && in_array(strtoupper($_GET['comments_order']), array('ASC', 'DESC'))) |
---|
[12894] | 132 | { |
---|
[13021] | 133 | pwg_set_session_var('comments_order', $_GET['comments_order']); |
---|
[12894] | 134 | } |
---|
[13021] | 135 | $comments_order = pwg_get_session_var('comments_order', $conf['comments_order']); |
---|
| 136 | |
---|
[12894] | 137 | $template->assign(array( |
---|
[13156] | 138 | 'COMMENTS_ORDER_URL' => add_url_params( duplicate_picture_url(), array('comments_order'=> ($comments_order == 'ASC' ? 'DESC' : 'ASC') ) ), |
---|
[13225] | 139 | 'COMMENTS_ORDER_TITLE' => $comments_order == 'ASC' ? l10n('Show latest comments first') : l10n('Show oldest comments first'), |
---|
[12894] | 140 | )); |
---|
[18950] | 141 | |
---|
[1082] | 142 | $query = ' |
---|
[5654] | 143 | SELECT |
---|
| 144 | com.id, |
---|
| 145 | author, |
---|
| 146 | author_id, |
---|
[18164] | 147 | u.'.$conf['user_fields']['email'].' AS user_email, |
---|
[5654] | 148 | date, |
---|
| 149 | image_id, |
---|
[17351] | 150 | website_url, |
---|
[18164] | 151 | com.email, |
---|
[5654] | 152 | content, |
---|
| 153 | validated |
---|
[3450] | 154 | FROM '.COMMENTS_TABLE.' AS com |
---|
| 155 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
[3452] | 156 | ON u.'.$conf['user_fields']['id'].' = author_id |
---|
[5654] | 157 | WHERE image_id = '.$page['image_id'].' |
---|
| 158 | '.$validated_clause.' |
---|
[12894] | 159 | ORDER BY date '.$comments_order.' |
---|
[4607] | 160 | LIMIT '.$conf['nb_comment_page'].' OFFSET '.$page['start'].' |
---|
[1082] | 161 | ;'; |
---|
| 162 | $result = pwg_query( $query ); |
---|
| 163 | |
---|
[4325] | 164 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1082] | 165 | { |
---|
[18164] | 166 | if ($row['author'] == 'guest') |
---|
[3450] | 167 | { |
---|
[18164] | 168 | $row['author'] = l10n('guest'); |
---|
[3450] | 169 | } |
---|
[18950] | 170 | |
---|
[18164] | 171 | $email = null; |
---|
| 172 | if (!empty($row['user_email'])) |
---|
[3450] | 173 | { |
---|
[18164] | 174 | $email = $row['user_email']; |
---|
[3450] | 175 | } |
---|
[18950] | 176 | elseif (!empty($row['email'])) |
---|
[18164] | 177 | { |
---|
| 178 | $email = $row['email']; |
---|
| 179 | } |
---|
[3450] | 180 | |
---|
[3122] | 181 | $tpl_comment = |
---|
[1082] | 182 | array( |
---|
[11236] | 183 | 'ID' => $row['id'], |
---|
[18164] | 184 | 'AUTHOR' => trigger_event('render_comment_author', $row['author']), |
---|
[11236] | 185 | 'DATE' => format_date($row['date'], true), |
---|
[2227] | 186 | 'CONTENT' => trigger_event('render_comment_content',$row['content']), |
---|
[17351] | 187 | 'WEBSITE_URL' => $row['website_url'], |
---|
[1082] | 188 | ); |
---|
| 189 | |
---|
[3450] | 190 | if (can_manage_comment('delete', $row['author_id'])) |
---|
[3445] | 191 | { |
---|
[5195] | 192 | $tpl_comment['U_DELETE'] = add_url_params( |
---|
| 193 | $url_self, |
---|
| 194 | array( |
---|
| 195 | 'action'=>'delete_comment', |
---|
| 196 | 'comment_to_delete'=>$row['id'], |
---|
| 197 | 'pwg_token' => get_pwg_token(), |
---|
| 198 | ) |
---|
| 199 | ); |
---|
[3445] | 200 | } |
---|
[3450] | 201 | if (can_manage_comment('edit', $row['author_id'])) |
---|
[3445] | 202 | { |
---|
[8600] | 203 | $tpl_comment['U_EDIT'] = add_url_params( |
---|
[5195] | 204 | $url_self, |
---|
| 205 | array( |
---|
| 206 | 'action'=>'edit_comment', |
---|
| 207 | 'comment_to_edit'=>$row['id'], |
---|
| 208 | ) |
---|
| 209 | ); |
---|
[8600] | 210 | if (isset($edit_comment) and ($row['id'] == $edit_comment)) |
---|
| 211 | { |
---|
| 212 | $tpl_comment['IN_EDIT'] = true; |
---|
| 213 | $key = get_ephemeral_key(2, $page['image_id']); |
---|
| 214 | $tpl_comment['KEY'] = $key; |
---|
| 215 | $tpl_comment['CONTENT'] = $row['content']; |
---|
[13865] | 216 | $tpl_comment['PWG_TOKEN'] = get_pwg_token(); |
---|
[15924] | 217 | $tpl_comment['U_CANCEL'] = $url_self; |
---|
[8600] | 218 | } |
---|
[3445] | 219 | } |
---|
[1082] | 220 | if (is_admin()) |
---|
| 221 | { |
---|
[18164] | 222 | $tpl_comment['EMAIL'] = $email; |
---|
[18950] | 223 | |
---|
[8600] | 224 | if ($row['validated'] != 'true') |
---|
| 225 | { |
---|
| 226 | $tpl_comment['U_VALIDATE'] = add_url_params( |
---|
| 227 | $url_self, |
---|
| 228 | array( |
---|
| 229 | 'action' => 'validate_comment', |
---|
| 230 | 'comment_to_validate' => $row['id'], |
---|
| 231 | 'pwg_token' => get_pwg_token(), |
---|
| 232 | ) |
---|
| 233 | ); |
---|
| 234 | } |
---|
[1082] | 235 | } |
---|
[2227] | 236 | $template->append('comments', $tpl_comment); |
---|
[1082] | 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
[5649] | 240 | $show_add_comment_form = true; |
---|
| 241 | if (isset($edit_comment)) |
---|
[1082] | 242 | { |
---|
[5649] | 243 | $show_add_comment_form = false; |
---|
| 244 | } |
---|
| 245 | if (is_a_guest() and !$conf['comments_forall']) |
---|
| 246 | { |
---|
| 247 | $show_add_comment_form = false; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if ($show_add_comment_form) |
---|
| 251 | { |
---|
[7495] | 252 | $key = get_ephemeral_key(3, $page['image_id']); |
---|
[18950] | 253 | |
---|
| 254 | $tpl_var = array( |
---|
| 255 | 'F_ACTION' => $url_self, |
---|
| 256 | 'KEY' => $key, |
---|
| 257 | 'CONTENT' => '', |
---|
| 258 | 'SHOW_AUTHOR' => !is_classic_user(), |
---|
| 259 | 'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'], |
---|
| 260 | 'AUTHOR' => '', |
---|
| 261 | 'WEBSITE_URL' => '', |
---|
| 262 | 'SHOW_EMAIL' => !is_classic_user() or empty($user['email']), |
---|
| 263 | 'EMAIL_MANDATORY' => $conf['comments_email_mandatory'], |
---|
| 264 | 'EMAIL' => '', |
---|
| 265 | ); |
---|
| 266 | |
---|
| 267 | if ('reject'==@$comment_action) |
---|
| 268 | { |
---|
| 269 | foreach( array('content', 'author', 'website_url', 'email') as $k) |
---|
| 270 | { |
---|
| 271 | $tpl_var[strtoupper($k)] = htmlspecialchars( stripslashes(@$_POST[$k]) ); |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | $template->assign('comment_add', $tpl_var); |
---|
[1082] | 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | ?> |
---|