- Timestamp:
- Dec 22, 2013, 8:30:51 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Comments_on_Albums/trunk/include/coa_comments_page.php
r24609 r26089 1 <?php 1 <?php 2 2 /* inspired by comments.php */ 3 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 load_language('plugin.lang', COA_PATH); 3 defined('COA_ID') or die('Hacking attempt!'); 4 5 global $template, $page, $conf, $user; 5 6 6 7 // +-----------------------------------------------------------------------+ … … 10 11 $template->set_prefilter('comments', 'coa_add_button'); 11 12 12 function coa_add_button($content, &$smarty) 13 { 13 function coa_add_button($content, &$smarty) 14 { 14 15 $search ='<form class="filter" action="{$F_ACTION}" method="get">'; 15 $replacement = ' 16 <form class="filter"> 16 17 $add = ' 17 18 <fieldset> 18 <legend>{\'Display comments on\'|@translate}</legend> 19 <span style="font-size:1.1em;"><a href="comments.php" {if $COA_MODE=="photos"}style="font-weight:bold;"{/if}>{\'Photos\'|@translate}</a> | 20 <a href="comments.php?display_mode=albums" {if $COA_MODE=="albums"}style="font-weight:bold;"{/if}>{\'Albums\'|@translate}</a></span> 21 </fieldset> 22 </form>'; 23 24 return str_replace($search, $replacement.$search, $content); 19 <legend>{\'Display comments on\'|@translate}</legend> 20 <span style="font-size:1.1em;"><a href="comments.php" {if $COA_MODE=="photos"}style="font-weight:bold;"{/if}>{\'Photos\'|@translate}</a> | 21 <a href="comments.php?display_mode=albums" {if $COA_MODE=="albums"}style="font-weight:bold;"{/if}>{\'Albums\'|@translate}</a></span> 22 </fieldset>'; 23 24 return str_replace($search, $add.$search, $content); 25 25 } 26 26 … … 29 29 // comments on albums page | 30 30 // +-----------------------------------------------------------------------+ 31 if ( isset($_GET['display_mode']) and $_GET['display_mode'] == 'albums' ) 32 { 33 include_once(COA_PATH.'include/functions_comment.inc.php'); // custom functions 34 35 // reset some template vars 36 $template->clear_assign(array('comments', 'navbar', 'sort_by_options')); 37 38 // sort_by : database fields proposed for sorting comments list 39 $sort_by = array( 40 'date' => l10n('comment date'), 41 'category_id' => l10n('album') 42 ); 43 $template->assign('sort_by_options', $sort_by); 44 45 // clean where_clauses from unknown column 46 foreach ($page['where_clauses'] as &$cond) 47 { 48 if (strpos($cond, 'ic.image_id') !== false) 49 { 50 $cond = get_sql_condition_FandF(array( 31 if (!isset($_GET['display_mode']) or $_GET['display_mode'] != 'albums') 32 { 33 return; 34 } 35 36 $url_self = PHPWG_ROOT_PATH.'comments.php' 37 .get_query_string_diff(array('edit_albums','delete_albums','validate_albums','pwg_token')); 38 39 // reset some template vars 40 $template->clear_assign(array('F_ACTION', 'comments', 'navbar', 'sort_by_options')); 41 42 // sort_by : database fields proposed for sorting comments list 43 global $sort_by; 44 $sort_by = array( 45 'date' => l10n('comment date'), 46 'category_id' => l10n('Album') 47 ); 48 $template->assign(array( 49 'F_ACTION' => PHPWG_ROOT_PATH.'comments.php?display_mode=albums', 50 'sort_by_options' => $sort_by, 51 )); 52 53 // clean where_clauses from unknown column 54 foreach ($page['where_clauses'] as &$cond) 55 { 56 if (strpos($cond, 'ic.image_id') !== false) 57 { 58 $cond = get_sql_condition_FandF( 59 array( 51 60 'forbidden_categories' => 'category_id', 52 61 'visible_categories' => 'category_id' 53 62 ), 54 '', true); 55 } 56 } 57 unset($cond); 58 59 // +-----------------------------------------------------------------------+ 60 // | comments management | 61 // +-----------------------------------------------------------------------+ 62 $comment_id = null; 63 $action = null; 64 65 $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process 66 foreach ($actions as $loop_action) 67 { 68 if (isset($_GET[$loop_action])) 69 { 70 $action = $loop_action; 71 check_input_parameter($action, $_GET, false, PATTERN_ID); 72 $comment_id = $_GET[$action]; 73 break; 74 } 75 } 76 77 if (isset($action)) 78 { 79 $comment_author_id = get_comment_author_id_albums($comment_id); 80 81 if (can_manage_comment(str_replace('_albums', null, $action), $comment_author_id)) 82 { 83 $perform_redirect = false; 84 85 if ('delete_albums' == $action) 63 '', true 64 ); 65 } 66 } 67 unset($cond); 68 69 // +-----------------------------------------------------------------------+ 70 // | comments management | 71 // +-----------------------------------------------------------------------+ 72 73 $comment_id = null; 74 $action = null; 75 76 $actions = array('delete_albums', 'validate_albums', 'edit_albums'); 77 foreach ($actions as $loop_action) 78 { 79 if (isset($_GET[$loop_action])) 80 { 81 $action = $loop_action; 82 check_input_parameter($action, $_GET, false, PATTERN_ID); 83 $comment_id = $_GET[$action]; 84 break; 85 } 86 } 87 88 if (isset($action)) 89 { 90 include_once(COA_PATH.'include/functions_comment.inc.php'); 91 92 $comment_author_id = get_comment_author_id_albums($comment_id); 93 94 if (can_manage_comment(str_replace('_albums', null, $action), $comment_author_id)) 95 { 96 $perform_redirect = false; 97 98 if ('delete_albums' == $action) 99 { 100 check_pwg_token(); 101 delete_user_comment_albums($comment_id); 102 $perform_redirect = true; 103 } 104 if ('validate_albums' == $action) 105 { 106 check_pwg_token(); 107 validate_user_comment_albums($comment_id); 108 $perform_redirect = true; 109 } 110 if ('edit_albums' == $action) 111 { 112 if (!empty($_POST['content'])) 86 113 { 87 114 check_pwg_token(); 88 delete_user_comment_albums($comment_id); 89 $perform_redirect = true; 90 } 91 if ('validate_albums' == $action) 92 { 93 check_pwg_token(); 94 validate_user_comment_albums($comment_id); 95 $perform_redirect = true; 96 } 97 if ('edit_albums' == $action) 98 { 99 if (!empty($_POST['content'])) 115 $comment_action = update_user_comment_albums( 116 array( 117 'comment_id' => $_GET['edit_albums'], 118 'category_id' => $_POST['image_id'], 119 'content' => $_POST['content'], 120 'website_url' => @$_POST['website_url'], 121 ), 122 $_POST['key'] 123 ); 124 125 switch ($comment_action) 100 126 { 101 check_pwg_token(); 102 update_user_comment_albums( 103 array( 104 'comment_id' => $_GET['edit_albums'], 105 'category_id' => $_POST['image_id'], 106 'content' => $_POST['content'] 107 ), 108 $_POST['key'] 109 ); 110 111 $perform_redirect = true; 112 } 113 else 114 { 115 $edit_comment = $_GET['edit_albums']; 127 case 'moderate': 128 $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.'); 129 case 'validate': 130 $_SESSION['page_infos'][] = l10n('Your comment has been registered'); 131 $perform_redirect = true; 132 break; 133 case 'reject': 134 $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules'); 135 break; 136 default: 137 trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); 116 138 } 117 139 } 118 if ($perform_redirect)140 else 119 141 { 120 $redirect_url = 121 PHPWG_ROOT_PATH 122 .'comments.php' 123 .get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token')); 124 125 redirect($redirect_url); 142 $edit_comment = $_GET['edit_albums']; 126 143 } 127 144 } 128 } 129 130 // +-----------------------------------------------------------------------+ 131 // | navigation bar | 132 // +-----------------------------------------------------------------------+ 133 if (isset($_GET['start']) and is_numeric($_GET['start'])) 134 { 135 $start = $_GET['start']; 136 } 137 else 138 { 139 $start = 0; 140 } 141 142 $query = ' 145 if ($perform_redirect) 146 { 147 redirect($url_self); 148 } 149 } 150 } 151 152 // +-----------------------------------------------------------------------+ 153 // | navigation bar | 154 // +-----------------------------------------------------------------------+ 155 156 if (isset($_GET['start']) and is_numeric($_GET['start'])) 157 { 158 $start = $_GET['start']; 159 } 160 else 161 { 162 $start = 0; 163 } 164 165 $query = ' 143 166 SELECT COUNT(DISTINCT(com.id)) 144 FROM '.COA_TABLE.' AS com 145 LEFT JOIN '.USERS_TABLE.' As u 167 FROM '.CATEGORIES_TABLE.' AS cat 168 INNER JOIN '.COA_TABLE.' AS com 169 ON cat.id = com.category_id 170 LEFT JOIN '.USERS_TABLE.' AS u 146 171 ON u.'.$conf['user_fields']['id'].' = com.author_id 147 172 WHERE '.implode(' 148 173 AND ', $page['where_clauses']).' 149 174 ;'; 150 151 152 $url = PHPWG_ROOT_PATH 153 .'comments.php'154 .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token')); 155 156 $ navbar = create_navigation_bar(157 $url,158 $counter,159 $start,160 $page['items_number'],161 ''162 ); 163 164 $template->assign('navbar', $navbar); 165 166 // +-----------------------------------------------------------------------+ 167 // | last comments display | 168 // +-----------------------------------------------------------------------+ 169 170 171 172 173 175 list($counter) = pwg_db_fetch_row(pwg_query($query)); 176 177 $url = PHPWG_ROOT_PATH.'comments.php' 178 .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token')); 179 180 $navbar = create_navigation_bar( 181 $url, 182 $counter, 183 $start, 184 $page['items_number'], 185 '' 186 ); 187 188 $template->assign('navbar', $navbar); 189 190 // +-----------------------------------------------------------------------+ 191 // | last comments display | 192 // +-----------------------------------------------------------------------+ 193 194 $comments = array(); 195 $element_ids = array(); 196 $category_ids = array(); 197 198 $query = ' 174 199 SELECT 175 200 com.id AS comment_id, … … 184 209 com.content, 185 210 com.validated 186 FROM '.COA_TABLE.' AS com 211 FROM '.CATEGORIES_TABLE.' AS cat 212 INNER JOIN '.COA_TABLE.' AS com 213 ON cat.id = com.category_id 187 214 LEFT JOIN '.USERS_TABLE.' As u 188 215 ON u.'.$conf['user_fields']['id'].' = com.author_id … … 198 225 com.validated 199 226 ORDER BY '.$page['sort_by'].' '.$page['sort_order']; 200 if ('all' != $page['items_number']) 201 {202 $query.= '203 LIMIT '.$page['items_number'].' OFFSET '.$start;204 }227 if ('all' != $page['items_number']) 228 { 229 $query.= ' 230 LIMIT '.$page['items_number'].' OFFSET '.$start; 231 } 205 232 $query.= ' 206 233 ;'; 207 208 209 while ($row = pwg_db_fetch_assoc($result)) 210 211 array_push($comments, $row);212 array_push($element_ids, $row['category_id']);213 214 215 if (count($comments) > 0) 216 217 218 219 SELECT 220 cat.id, 221 cat.name, 222 cat.permalink, 223 cat.uppercats, 234 $result = pwg_query($query); 235 236 while ($row = pwg_db_fetch_assoc($result)) 237 { 238 $comments[] = $row; 239 $element_ids[] = $row['category_id']; 240 } 241 242 if (count($comments) > 0) 243 { 244 // retrieving category informations 245 $query = ' 246 SELECT 247 cat.id, 248 cat.name, 249 cat.permalink, 250 cat.uppercats, 224 251 com.id as comment_id, 225 252 img.id AS image_id, … … 228 255 LEFT JOIN '.COA_TABLE.' AS com 229 256 ON com.category_id = cat.id 230 LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc 257 LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc 231 258 ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].' 232 259 LEFT JOIN '.IMAGES_TABLE.' AS img … … 236 263 'forbidden_categories' => 'cat.id', 237 264 'visible_categories' => 'cat.id' 238 ), 265 ), 239 266 'WHERE' 240 267 ).' 241 268 AND cat.id IN ('.implode(',', $element_ids).') 242 269 ;'; 243 $categories = hash_from_query($query, 'comment_id'); 244 245 foreach ($comments as $comment) 246 { 247 // source of the thumbnail picture 248 $comment['src_image'] = new SrcImage($categories[$comment['comment_id']]); 249 250 // category url 251 $comment['cat_url'] = duplicate_index_url( 270 $categories = hash_from_query($query, 'comment_id'); 271 272 foreach ($comments as $comment) 273 { 274 // source of the thumbnail picture 275 $comment['src_image'] = new SrcImage($categories[$comment['comment_id']]); 276 277 // category url 278 $comment['cat_url'] = make_index_url( 279 array( 280 'section' => 'categories', 281 'category' => $categories[$comment['comment_id']], 282 ) 283 ); 284 285 $email = null; 286 if (!empty($comment['user_email'])) 287 { 288 $email = $comment['user_email']; 289 } 290 else if (!empty($comment['email'])) 291 { 292 $email = $comment['email']; 293 } 294 295 // comment content 296 $tpl_comment = array( 297 'ID' => $comment['comment_id'], 298 'U_PICTURE' => $comment['cat_url'], 299 'src_image' => $comment['src_image'], 300 'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']), 301 'AUTHOR' => trigger_event('render_comment_author', $comment['author']), 302 'WEBSITE_URL' => $comment['website_url'], 303 'DATE' => format_date($comment['date'], true), 304 'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'), 305 ); 306 307 if (is_admin()) 308 { 309 $tpl_comment['EMAIL'] = $email; 310 } 311 312 // rights 313 if (can_manage_comment('delete', $comment['author_id'])) 314 { 315 $tpl_comment['U_DELETE'] = add_url_params( 316 $url_self, 252 317 array( 253 'category' => array( 254 'id' => $categories[$comment['comment_id']]['id'], 255 'name' => $categories[$comment['comment_id']]['name'], 256 'permalink' => $categories[$comment['comment_id']]['permalink'], 257 ), 258 array('start') 318 'delete_albums' => $comment['comment_id'], 319 'pwg_token' => get_pwg_token(), 259 320 ) 260 321 ); 261 262 $email = null; 263 if (!empty($comment['user_email'])) 322 } 323 if (can_manage_comment('edit', $comment['author_id'])) 324 { 325 $tpl_comment['U_EDIT'] = add_url_params( 326 $url_self, 327 array( 328 'edit_albums' => $comment['comment_id'], 329 ) 330 ); 331 332 if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) 264 333 { 265 $email = $comment['user_email']; 334 $tpl_comment['IN_EDIT'] = true; 335 $key = get_ephemeral_key(2, $comment['category_id']); 336 $tpl_comment['KEY'] = $key; 337 $tpl_comment['IMAGE_ID'] = $comment['category_id']; 338 $tpl_comment['CONTENT'] = $comment['content']; 339 $tpl_comment['PWG_TOKEN'] = get_pwg_token(); 340 $tpl_comment['U_CANCEL'] = $url_self; 266 341 } 267 else if (!empty($comment['email'])) 342 } 343 if (can_manage_comment('validate', $comment['author_id'])) 344 { 345 if ('true' != $comment['validated']) 268 346 { 269 $email = $comment['email']; 270 } 271 272 // comment content 273 $tpl_comment = array( 274 'ID' => $comment['comment_id'], 275 'U_PICTURE' => $comment['cat_url'], 276 'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']), 277 'src_image' => $comment['src_image'], 278 'AUTHOR' => trigger_event('render_comment_author', $comment['author']), 279 'WEBSITE_URL' => $comment['website_url'], 280 'DATE' => format_date($comment['date'], true), 281 'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'), 282 ); 283 284 if (is_admin()) 285 { 286 $tpl_comment['EMAIL'] = $email; 287 } 288 289 // rights 290 if (can_manage_comment('delete', $comment['author_id'])) 291 { 292 $tpl_comment['U_DELETE'] = add_url_params( 293 $url, 347 $tpl_comment['U_VALIDATE'] = add_url_params( 348 $url_self, 294 349 array( 295 ' delete_albums'=> $comment['comment_id'],350 'validate_albums'=> $comment['comment_id'], 296 351 'pwg_token' => get_pwg_token(), 297 352 ) 298 353 ); 299 354 } 300 if (can_manage_comment('edit', $comment['author_id'])) 301 { 302 $tpl_comment['U_EDIT'] = add_url_params( 303 $url, 304 array( 305 'edit_albums' => $comment['comment_id'], 306 ) 307 ); 308 309 if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) 310 { 311 $tpl_comment['IN_EDIT'] = true; 312 $key = get_ephemeral_key(2, $comment['category_id']); 313 $tpl_comment['KEY'] = $key; 314 $tpl_comment['IMAGE_ID'] = $comment['category_id']; 315 $tpl_comment['CONTENT'] = $comment['content']; 316 $tpl_comment['PWG_TOKEN'] = get_pwg_token(); 317 } 318 } 319 if (can_manage_comment('validate', $comment['author_id'])) 320 { 321 if ('true' != $comment['validated']) 322 { 323 $tpl_comment['U_VALIDATE'] = add_url_params( 324 $url, 325 array( 326 'validate_albums'=> $comment['comment_id'], 327 'pwg_token' => get_pwg_token(), 328 ) 329 ); 330 } 331 } 332 333 $template->append('comments', $tpl_comment); 334 } 335 } 336 337 // +-----------------------------------------------------------------------+ 338 // | template | 339 // +-----------------------------------------------------------------------+ 340 // add a line to display category name 341 $template->set_prefilter('comments', 'coa_change_comments_list'); 342 343 function coa_change_comments_list($content, &$smarty) { 344 $search[0] = '<a href="{$comment.U_PICTURE}">'; 345 $replacement[0] = $search[0].'{$comment.ALT}<br/>'; 346 $search[1] = '<input type="submit"'; 347 $replacement[1] = '<input type=hidden name=display_mode value=albums>'.$search[1]; 348 return str_replace($search, $replacement, $content); 349 } 350 } 351 352 ?> 355 } 356 357 $template->append('comments', $tpl_comment); 358 } 359 } 360 361 // +-----------------------------------------------------------------------+ 362 // | template | 363 // +-----------------------------------------------------------------------+ 364 // add a line to display category name 365 $template->set_prefilter('comments', 'coa_change_comments_list'); 366 367 function coa_change_comments_list($content, &$smarty) { 368 $search = '<a href="{$comment.U_PICTURE}">'; 369 $replacement = $search.'{$comment.ALT}<br>'; 370 return str_replace($search, $replacement, $content); 371 }
Note: See TracChangeset
for help on using the changeset viewer.