- Timestamp:
- Jun 7, 2011, 9:44:37 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Comments_on_Albums/include/coa_comments_page.php
r11251 r11267 1 1 <?php 2 /* inspired by include/comments.php */2 /* inspired by comments.php */ 3 3 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 4 … … 6 6 $conf['comments_on_albums'] = unserialize($conf['comments_on_albums']); 7 7 8 $template->assign(array( 9 'COA_PATH' => COA_PATH, 10 'ICON_COLOR' => $conf['comments_on_albums']['icon_color'], 11 'ICON_COLOR_OVER' => $conf['comments_on_albums']['icon_color_over'], 12 )); 8 $template->assign( 9 array( 10 'COA_PATH' => COA_PATH, 11 'ICON_COLOR' => $conf['comments_on_albums']['icon_color'], 12 'ICON_COLOR_OVER' => $conf['comments_on_albums']['icon_color_over'], 13 ) 14 ); 13 15 14 16 15 17 // +-----------------------------------------------------------------------+ 16 // Main page (comments on photos)18 // | main page | 17 19 // +-----------------------------------------------------------------------+ 18 20 19 if (!isset($_GET['display_mode'])) { 21 if (!isset($_GET['display_mode'])) 22 { 20 23 // adds a button for switch page 21 24 $template->set_prefilter('comments', 'coa_add_button'); 22 function coa_add_button($content, &$smarty) { 25 26 function coa_add_button($content, &$smarty) 27 { 23 28 $search = '<ul class="categoryActions">'; 24 29 … … 37 42 {/html_head} 38 43 39 <ul class="categoryActions">44 '.$search.' 40 45 <li><a href="comments.php?display_mode=albums" title="' . l10n('COA_comments_albums') . '" class="pwg-state-default pwg-button"> 41 46 <span class="pwg-icon pwg-icon-comments-albums"> </span><span class="pwg-button-text">' . l10n('COA_comments_albums') . '</span> … … 47 52 48 53 // +-----------------------------------------------------------------------+ 49 // Second page (comments on albums)54 // comments on albums page | 50 55 // +-----------------------------------------------------------------------+ 51 56 52 } else if ($_GET['display_mode'] == 'albums') { 57 } 58 else if ($_GET['display_mode'] == 'albums') 59 { 53 60 // reset some template vars 54 61 $template->clear_assign(array('comments', 'navbar', 'sort_by_options')); … … 58 65 'date' => l10n('comment date'), 59 66 'category_id' => l10n('album') 60 );67 ); 61 68 $template->assign('sort_by_options', $sort_by); 62 69 … … 68 75 69 76 $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process 70 foreach ($actions as $loop_action) { 71 if (isset($_GET[$loop_action])) { 77 foreach ($actions as $loop_action) 78 { 79 if (isset($_GET[$loop_action])) 80 { 72 81 $action = $loop_action; 73 82 check_input_parameter($action, $_GET, false, PATTERN_ID); … … 77 86 } 78 87 79 if (isset($action)) { 88 if (isset($action)) 89 { 80 90 include_once(COA_PATH.'include/functions_comment.inc.php'); 91 81 92 check_pwg_token(); 93 82 94 $comment_author_id = get_comment_author_id_albums($comment_id); 95 83 96 $true_action = str_replace('_albums', null, $action); // but we must check true action names 84 97 85 if (can_manage_comment($true_action, $comment_author_id)) { 98 if (can_manage_comment($true_action, $comment_author_id)) 99 { 86 100 $perform_redirect = false; 87 101 88 if ('delete_albums' == $action) { 102 if ('delete_albums' == $action) 103 { 89 104 delete_user_comment_albums($comment_id); 90 105 $perform_redirect = true; 91 106 } 92 if ('validate_albums' == $action) { 107 if ('validate_albums' == $action) 108 { 93 109 validate_user_comment_albums($comment_id); 94 110 $perform_redirect = true; 95 111 } 96 if ('edit_albums' == $action) { 97 if (!empty($_POST['content'])) { 98 update_user_comment_albums(array( 99 'comment_id' => $_GET['edit_albums'], 100 'image_id' => $_POST['image_id'], 101 'content' => $_POST['content'] 102 ), $_POST['key'] 103 ); 104 $perform_redirect = true; 105 } else { 112 if ('edit_albums' == $action) 113 { 114 if (!empty($_POST['content'])) 115 { 116 update_user_comment_albums( 117 array( 118 'comment_id' => $_GET['edit_albums'], 119 'image_id' => $_POST['image_id'], 120 'content' => $_POST['content'] 121 ), 122 $_POST['key'] 123 ); 124 //$perform_redirect = true; 125 $edit_comment = null; 126 } 127 else 128 { 106 129 $edit_comment = $_GET['edit_albums']; 107 130 } 108 131 } 109 if ($perform_redirect) { 110 $redirect_url = PHPWG_ROOT_PATH.'comments.php'.get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token')); 132 if ($perform_redirect) 133 { 134 $redirect_url = 135 PHPWG_ROOT_PATH 136 .'comments.php' 137 .get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token')); 138 111 139 redirect($redirect_url); 112 140 } … … 117 145 // | navigation bar | 118 146 // +-----------------------------------------------------------------------+ 119 if (isset($_GET['start']) and is_numeric($_GET['start'])) { 147 if (isset($_GET['start']) and is_numeric($_GET['start'])) 148 { 120 149 $start = $_GET['start']; 121 } else { 150 } 151 else 152 { 122 153 $start = 0; 123 154 } 124 155 125 $query = 'SELECT COUNT(DISTINCT(com.id)) 126 FROM '.COA_TABLE.' AS com 127 LEFT JOIN '.USERS_TABLE.' As u 156 $query = ' 157 SELECT 158 COUNT(DISTINCT(com.id)) 159 FROM '.COA_TABLE.' AS com 160 LEFT JOIN '.USERS_TABLE.' As u 128 161 ON u.'.$conf['user_fields']['id'].' = com.author_id 129 162 WHERE '.implode(' 130 163 AND ', $page['where_clauses']).' 131 164 ;'; 132 165 list($counter) = pwg_db_fetch_row(pwg_query($query)); 133 166 134 $url = PHPWG_ROOT_PATH . 'comments.php' . get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token')); 135 $navbar = create_navigation_bar($url, $counter, $start, $page['items_number'], ''); 167 $url = 168 PHPWG_ROOT_PATH 169 .'comments.php' 170 .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token')); 171 172 $navbar = create_navigation_bar( 173 $url, 174 $counter, 175 $start, 176 $page['items_number'], 177 '' 178 ); 136 179 $template->assign('navbar', $navbar); 137 180 … … 143 186 $category_ids = array(); 144 187 145 $query = 'SELECT 146 com.id AS comment_id, 147 com.category_id, 148 com.author, 149 com.author_id, 150 '.$conf['user_fields']['username'].' AS username, 151 com.date, 152 com.content, 153 com.validated 154 FROM '.COA_TABLE.' AS com 155 LEFT JOIN '.USERS_TABLE.' As u 188 $query = ' 189 SELECT 190 com.id AS comment_id, 191 com.category_id, 192 com.author, 193 com.author_id, 194 '.$conf['user_fields']['username'].' AS username, 195 com.date, 196 com.content, 197 com.validated 198 FROM '.COA_TABLE.' AS com 199 LEFT JOIN '.USERS_TABLE.' As u 156 200 ON u.'.$conf['user_fields']['id'].' = com.author_id 157 201 WHERE '.implode(' 158 202 AND ', $page['where_clauses']).' 159 GROUP BY 160 comment_id, 161 com.category_id, 162 com.author, 163 com.author_id, 164 com.date, 165 com.content, 166 com.validated 167 ORDER BY '.$page['sort_by'].' '.$page['sort_order']; 168 if ('all' != $page['items_number']) { 169 $query.= ' 170 LIMIT '.$page['items_number'].' OFFSET '.$start; 171 } 203 GROUP BY 204 comment_id, 205 com.category_id, 206 com.author, 207 com.author_id, 208 com.date, 209 com.content, 210 com.validated 211 ORDER BY '.$page['sort_by'].' '.$page['sort_order']; 212 if ('all' != $page['items_number']) 213 { 172 214 $query.= ' 173 ;'; 215 LIMIT '.$page['items_number'].' OFFSET '.$start; 216 } 217 $query.= ' 218 ;'; 174 219 $result = pwg_query($query); 175 220 176 while ($row = pwg_db_fetch_assoc($result)) { 221 while ($row = pwg_db_fetch_assoc($result)) 222 { 177 223 array_push($comments, $row); 178 224 array_push($element_ids, $row['category_id']); 179 225 } 180 226 181 if (count($comments) > 0) { 227 if (count($comments) > 0) 228 { 182 229 // retrieving category informations 183 $query = 'SELECT 184 cat.id, 185 cat.name, 186 cat.permalink, 187 cat.uppercats, 188 com.id as comment_id 189 FROM '.CATEGORIES_TABLE.' AS cat 190 LEFT JOIN '.COA_TABLE.' AS com 191 ON cat.id=com.category_id 192 '.get_sql_condition_FandF(array( 193 'forbidden_categories' => 'cat.id', 194 'visible_categories' => 'cat.id' 195 ), 'WHERE').' 196 AND cat.id IN ('.implode(',', $element_ids).') 197 ;'; 230 $query = ' 231 SELECT 232 cat.id, 233 cat.name, 234 cat.permalink, 235 cat.uppercats, 236 com.id as comment_id 237 FROM '.CATEGORIES_TABLE.' AS cat 238 LEFT JOIN '.COA_TABLE.' AS com 239 ON cat.id=com.category_id 240 '.get_sql_condition_FandF( 241 array( 242 'forbidden_categories' => 'cat.id', 243 'visible_categories' => 'cat.id' 244 ), 245 'WHERE' 246 ).' 247 AND cat.id IN ('.implode(',', $element_ids).') 248 ;'; 198 249 $categories = hash_from_query($query, 'comment_id'); 199 250 200 foreach ($comments as $comment) { 251 foreach ($comments as $comment) 252 { 201 253 // category 202 254 $name = $categories[$comment['comment_id']]['name']; 203 $url = duplicate_index_url(array( 204 'category' => array( 205 'id' => $categories[$comment['comment_id']]['id'], 206 'name' => $categories[$comment['comment_id']]['name'], 207 'permalink' => $categories[$comment['comment_id']]['permalink'], 208 ),array('start') 209 )); 255 $url = duplicate_index_url( 256 array( 257 'category' => array( 258 'id' => $categories[$comment['comment_id']]['id'], 259 'name' => $categories[$comment['comment_id']]['name'], 260 'permalink' => $categories[$comment['comment_id']]['permalink'], 261 ), 262 array('start') 263 ) 264 ); 210 265 211 266 // comment content … … 217 272 'DATE' => format_date($comment['date'], true), 218 273 'CONTENT' => trigger_event('render_comment_content',$comment['content']), 219 );274 ); 220 275 221 276 // rights 222 if (can_manage_comment('delete', $comment['author_id'])) { 223 $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate','edit', 'pwg_token')); 224 225 $tpl_comment['U_DELETE'] = add_url_params($url, array( 226 'delete_albums' => $comment['comment_id'], 227 'pwg_token' => get_pwg_token(), 228 )); 229 } 230 if (can_manage_comment('edit', $comment['author_id'])) { 231 $url = get_root_url().'comments.php'.get_query_string_diff(array('edit', 'delete','validate', 'pwg_token')); 232 233 $tpl_comment['U_EDIT'] = add_url_params($url, array( 234 'edit_albums' => $comment['comment_id'], 235 'pwg_token' => get_pwg_token(), 236 )); 237 238 if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) { 277 if (can_manage_comment('delete', $comment['author_id'])) 278 { 279 $url = 280 get_root_url() 281 .'comments.php' 282 .get_query_string_diff(array('delete','validate','edit', 'pwg_token')); 283 284 $tpl_comment['U_DELETE'] = add_url_params( 285 $url, 286 array( 287 'delete_albums' => $comment['comment_id'], 288 'pwg_token' => get_pwg_token(), 289 ) 290 ); 291 } 292 if (can_manage_comment('edit', $comment['author_id'])) 293 { 294 $url = 295 get_root_url() 296 .'comments.php' 297 .get_query_string_diff(array('edit', 'delete','validate', 'pwg_token')); 298 299 $tpl_comment['U_EDIT'] = add_url_params( 300 $url, 301 array( 302 'edit_albums' => $comment['comment_id'], 303 'pwg_token' => get_pwg_token(), 304 ) 305 ); 306 307 if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) 308 { 239 309 $key = get_ephemeral_key(2, $comment['category_id']); 240 310 $tpl_comment['IN_EDIT'] = true; … … 244 314 } 245 315 } 246 if (can_manage_comment('validate', $comment['author_id'])) { 247 if ('true' != $comment['validated']) { 248 $tpl_comment['U_VALIDATE'] = add_url_params($url, array( 249 'validate_albums'=> $comment['comment_id'], 250 'pwg_token' => get_pwg_token(), 251 )); 316 if (can_manage_comment('validate', $comment['author_id'])) 317 { 318 if ('true' != $comment['validated']) 319 { 320 $tpl_comment['U_VALIDATE'] = add_url_params( 321 $url, 322 array( 323 'validate_albums'=> $comment['comment_id'], 324 'pwg_token' => get_pwg_token(), 325 ) 326 ); 252 327 } 253 328 } … … 258 333 259 334 // +-----------------------------------------------------------------------+ 260 // | template|261 // +-----------------------------------------------------------------------+ 262 $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/co a_comments_page.tpl'));263 264 // add a l ayer fordisplay category name335 // | template | 336 // +-----------------------------------------------------------------------+ 337 $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/comments_page.tpl')); 338 339 // add a line to display category name 265 340 $template->set_prefilter('comments', 'coa_change_comments_list'); 341 266 342 function coa_change_comments_list($content, &$smarty) { 267 343 $search = '<div class="description"{if isset($comment.IN_EDIT)} style="height:200px"{/if}>'; 268 344 269 $replacement = '<div class="category-title">345 $replacement = '<div class="category-title"> 270 346 <a href="{$comment.CAT_URL}">{$comment.CAT_NAME}</a> 271 347 </div> 272 <div class="description"{if isset($comment.IN_EDIT)} style="height:220px"{/if}>';348 '.$search; 273 349 274 350 return str_replace($search, $replacement, $content);
Note: See TracChangeset
for help on using the changeset viewer.