[839] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 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 | // +-----------------------------------------------------------------------+ |
---|
[839] | 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 30 | |
---|
[25744] | 31 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 32 | { |
---|
| 33 | $page['start'] = $_GET['start']; |
---|
| 34 | } |
---|
| 35 | else |
---|
| 36 | { |
---|
| 37 | $page['start'] = 0; |
---|
| 38 | } |
---|
| 39 | |
---|
[839] | 40 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 41 | // | Check Access and exit when user status is not ok | |
---|
| 42 | // +-----------------------------------------------------------------------+ |
---|
[25744] | 43 | |
---|
[1072] | 44 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 45 | |
---|
| 46 | // +-----------------------------------------------------------------------+ |
---|
[839] | 47 | // | actions | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
| 49 | |
---|
[8126] | 50 | if (!empty($_POST)) |
---|
[839] | 51 | { |
---|
[5381] | 52 | if (empty($_POST['comments'])) |
---|
[1598] | 53 | { |
---|
[25018] | 54 | $page['errors'][] = l10n('Select at least one comment'); |
---|
[839] | 55 | } |
---|
[5381] | 56 | else |
---|
[839] | 57 | { |
---|
[12596] | 58 | include_once( PHPWG_ROOT_PATH .'include/functions_comment.inc.php' ); |
---|
[5381] | 59 | check_input_parameter('comments', $_POST, true, PATTERN_ID); |
---|
| 60 | |
---|
| 61 | if (isset($_POST['validate'])) |
---|
| 62 | { |
---|
[12596] | 63 | validate_user_comment($_POST['comments']); |
---|
[839] | 64 | |
---|
[25018] | 65 | $page['infos'][] = l10n_dec( |
---|
| 66 | '%d user comment validated', '%d user comments validated', |
---|
| 67 | count($_POST['comments']) |
---|
[12596] | 68 | ); |
---|
[5381] | 69 | } |
---|
[839] | 70 | |
---|
[5381] | 71 | if (isset($_POST['reject'])) |
---|
| 72 | { |
---|
[12596] | 73 | delete_user_comment($_POST['comments']); |
---|
[839] | 74 | |
---|
[25018] | 75 | $page['infos'][] = l10n_dec( |
---|
| 76 | '%d user comment rejected', '%d user comments rejected', |
---|
| 77 | count($_POST['comments']) |
---|
[5381] | 78 | ); |
---|
| 79 | } |
---|
[839] | 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // +-----------------------------------------------------------------------+ |
---|
| 84 | // | template init | |
---|
| 85 | // +-----------------------------------------------------------------------+ |
---|
| 86 | |
---|
[2530] | 87 | $template->set_filenames(array('comments'=>'comments.tpl')); |
---|
[839] | 88 | |
---|
[2249] | 89 | $template->assign( |
---|
[839] | 90 | array( |
---|
[2249] | 91 | 'F_ACTION' => get_root_url().'admin.php?page=comments' |
---|
[839] | 92 | ) |
---|
| 93 | ); |
---|
| 94 | |
---|
| 95 | // +-----------------------------------------------------------------------+ |
---|
[13079] | 96 | // | Tabs | |
---|
| 97 | // +-----------------------------------------------------------------------+ |
---|
| 98 | |
---|
| 99 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 100 | |
---|
| 101 | $tabsheet = new tabsheet(); |
---|
[16925] | 102 | $tabsheet->set_id('comments'); |
---|
[13079] | 103 | $tabsheet->select(''); |
---|
| 104 | $tabsheet->assign(); |
---|
| 105 | |
---|
| 106 | // +-----------------------------------------------------------------------+ |
---|
[839] | 107 | // | comments display | |
---|
| 108 | // +-----------------------------------------------------------------------+ |
---|
| 109 | |
---|
[25084] | 110 | $nb_total = 0; |
---|
| 111 | $nb_pending = 0; |
---|
[839] | 112 | |
---|
| 113 | $query = ' |
---|
[25084] | 114 | SELECT |
---|
| 115 | COUNT(*) AS counter, |
---|
| 116 | validated |
---|
| 117 | FROM '.COMMENTS_TABLE.' |
---|
| 118 | GROUP BY validated |
---|
| 119 | ;'; |
---|
| 120 | $result = pwg_query($query); |
---|
| 121 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 122 | { |
---|
| 123 | $nb_total+= $row['counter']; |
---|
| 124 | |
---|
| 125 | if ('false' == $row['validated']) |
---|
| 126 | { |
---|
| 127 | $nb_pending = $row['counter']; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | if (!isset($_GET['filter']) and $nb_pending > 0) |
---|
| 132 | { |
---|
| 133 | $page['filter'] = 'pending'; |
---|
| 134 | } |
---|
| 135 | else |
---|
| 136 | { |
---|
| 137 | $page['filter'] = 'all'; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | if (isset($_GET['filter']) and 'pending' == $_GET['filter']) |
---|
| 141 | { |
---|
| 142 | $page['filter'] = $_GET['filter']; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | $template->assign( |
---|
| 146 | array( |
---|
| 147 | 'nb_total' => $nb_total, |
---|
| 148 | 'nb_pending' => $nb_pending, |
---|
| 149 | 'filter' => $page['filter'], |
---|
| 150 | ) |
---|
| 151 | ); |
---|
| 152 | |
---|
| 153 | $where_clauses = array('1=1'); |
---|
| 154 | |
---|
| 155 | if ('pending' == $page['filter']) |
---|
| 156 | { |
---|
| 157 | $where_clauses[] = 'validated=\'false\''; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | $query = ' |
---|
| 161 | SELECT |
---|
| 162 | c.id, |
---|
| 163 | c.image_id, |
---|
| 164 | c.date, |
---|
| 165 | c.author, |
---|
| 166 | '.$conf['user_fields']['username'].' AS username, |
---|
| 167 | c.content, |
---|
| 168 | i.path, |
---|
| 169 | i.representative_ext, |
---|
| 170 | validated |
---|
[839] | 171 | FROM '.COMMENTS_TABLE.' AS c |
---|
| 172 | INNER JOIN '.IMAGES_TABLE.' AS i |
---|
| 173 | ON i.id = c.image_id |
---|
[3450] | 174 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
[3452] | 175 | ON u.'.$conf['user_fields']['id'].' = c.author_id |
---|
[25084] | 176 | WHERE '.implode(' AND ', $where_clauses).' |
---|
[3122] | 177 | ORDER BY c.date DESC |
---|
[25744] | 178 | LIMIT '.$page['start'].', '.$conf['comments_page_nb_comments'].' |
---|
[839] | 179 | ;'; |
---|
| 180 | $result = pwg_query($query); |
---|
[4325] | 181 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[839] | 182 | { |
---|
[12796] | 183 | $thumb = DerivativeImage::thumb_url( |
---|
[1598] | 184 | array( |
---|
| 185 | 'id'=>$row['image_id'], |
---|
| 186 | 'path'=>$row['path'], |
---|
| 187 | ) |
---|
| 188 | ); |
---|
[3450] | 189 | if (empty($row['author_id'])) |
---|
| 190 | { |
---|
| 191 | $author_name = $row['author']; |
---|
| 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
[4304] | 195 | $author_name = stripslashes($row['username']); |
---|
[3450] | 196 | } |
---|
[2249] | 197 | $template->append( |
---|
| 198 | 'comments', |
---|
[839] | 199 | array( |
---|
[13077] | 200 | 'U_PICTURE' => get_root_url().'admin.php?page=photo-'.$row['image_id'], |
---|
[839] | 201 | 'ID' => $row['id'], |
---|
[1598] | 202 | 'TN_SRC' => $thumb, |
---|
[3450] | 203 | 'AUTHOR' => trigger_event('render_comment_author', $author_name), |
---|
[3122] | 204 | 'DATE' => format_date($row['date'], true), |
---|
[25084] | 205 | 'CONTENT' => trigger_event('render_comment_content',$row['content']), |
---|
| 206 | 'IS_PENDING' => ('false' == $row['validated']), |
---|
[839] | 207 | ) |
---|
| 208 | ); |
---|
| 209 | |
---|
[25018] | 210 | $list[] = $row['id']; |
---|
[839] | 211 | } |
---|
| 212 | |
---|
| 213 | // +-----------------------------------------------------------------------+ |
---|
[25744] | 214 | // | navigation bar | |
---|
| 215 | // +-----------------------------------------------------------------------+ |
---|
| 216 | |
---|
| 217 | $navbar = create_navigation_bar( |
---|
| 218 | get_root_url().'admin.php'.get_query_string_diff(array('start')), |
---|
| 219 | ('pending' == $page['filter'] ? $nb_pending : $nb_total), |
---|
| 220 | $page['start'], |
---|
| 221 | $conf['comments_page_nb_comments'] |
---|
| 222 | ); |
---|
| 223 | |
---|
| 224 | $template->assign('navbar', $navbar); |
---|
| 225 | |
---|
| 226 | // +-----------------------------------------------------------------------+ |
---|
[839] | 227 | // | sending html code | |
---|
| 228 | // +-----------------------------------------------------------------------+ |
---|
| 229 | |
---|
| 230 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
| 231 | |
---|
[1730] | 232 | ?> |
---|