- Timestamp:
- May 22, 2011, 12:34:18 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Comments_on_Albums/include/coa_comments_page.php
r9766 r10984 7 7 8 8 $template->assign(array( 9 10 11 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 12 )); 13 13 14 14 15 15 // +-----------------------------------------------------------------------+ 16 // 17 // +-----------------------------------------------------------------------+ 18 19 if (!isset($_GET['display_mode'])) { 20 21 22 23 16 // Main page (comments on photos) 17 // +-----------------------------------------------------------------------+ 18 19 if (!isset($_GET['display_mode'])) { 20 // adds a button for switch page 21 $template->set_prefilter('comments', 'coa_add_button'); 22 function coa_add_button($content, &$smarty) { 23 $search = '<ul class="categoryActions">'; 24 24 25 25 $replacement = ' 26 26 {html_head} 27 28 29 30 31 32 33 34 35 36 27 <style type="text/css"> 28 .pwg-icon-comments-albums {ldelim} 29 background-image: url({$COA_PATH}template/s26/{$ICON_COLOR}); 30 background-position: -26px 0; 31 } 32 a:hover .pwg-icon-comments-albums {ldelim} 33 background-image: url({$COA_PATH}template/s26/{$ICON_COLOR_OVER}); 34 background-position: -26px 0; 35 } 36 </style> 37 37 {/html_head} 38 38 39 40 41 42 43 44 45 46 47 48 // +-----------------------------------------------------------------------+ 49 // 39 <ul class="categoryActions"> 40 <li><a href="comments.php?display_mode=albums" title="' . l10n('COA_comments_albums') . '" class="pwg-state-default pwg-button"> 41 <span class="pwg-icon pwg-icon-comments-albums"> </span><span class="pwg-button-text">' . l10n('COA_comments_albums') . '</span> 42 </a></li>'; 43 44 return str_replace($search, $replacement, $content); 45 } 46 47 48 // +-----------------------------------------------------------------------+ 49 // Second page (comments on albums) 50 50 // +-----------------------------------------------------------------------+ 51 51 52 52 } else if ($_GET['display_mode'] == 'albums') { 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 53 // reset some template vars 54 $template->clear_assign(array('comments', 'navbar', 'sort_by_options')); 55 56 // sort_by : database fields proposed for sorting comments list 57 $sort_by = array( 58 'date' => l10n('comment date'), 59 'category_id' => l10n('album') 60 ); 61 $template->assign('sort_by_options', $sort_by); 62 63 // +-----------------------------------------------------------------------+ 64 // | comments management | 65 // +-----------------------------------------------------------------------+ 66 $comment_id = null; 67 $action = null; 68 69 $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])) { 72 $action = $loop_action; 73 check_input_parameter($action, $_GET, false, PATTERN_ID); 74 $comment_id = $_GET[$action]; 75 break; 76 } 77 } 78 79 if (isset($action)) { 80 include_once(COA_PATH.'include/functions_comment.inc.php'); 81 check_pwg_token(); 82 $comment_author_id = get_comment_author_id_albums($comment_id); 83 $true_action = str_replace('_albums', null, $action); // but we must check true action names 84 85 if (can_manage_comment($true_action, $comment_author_id)) { 86 $perform_redirect = false; 87 88 if ('delete_albums' == $action) { 89 delete_user_comment_albums($comment_id); 90 $perform_redirect = true; 91 } 92 if ('validate_albums' == $action) { 93 validate_user_comment_albums($comment_id); 94 $perform_redirect = true; 95 } 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 { 106 $edit_comment = $_GET['edit_albums']; 107 } 108 } 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')); 111 redirect($redirect_url); 112 } 113 } 114 } 115 116 // +-----------------------------------------------------------------------+ 117 // | navigation bar | 118 // +-----------------------------------------------------------------------+ 119 if (isset($_GET['start']) and is_numeric($_GET['start'])) { 120 $start = $_GET['start']; 121 } else { 122 $start = 0; 123 } 124 125 $query = 'SELECT COUNT(DISTINCT(com.id)) 126 FROM '.COA_TABLE.' AS com 127 LEFT JOIN '.USERS_TABLE.' As u 128 ON u.'.$conf['user_fields']['id'].' = com.author_id 129 WHERE '.implode(' 130 AND ', $page['where_clauses']).' 131 ;'; 132 list($counter) = pwg_db_fetch_row(pwg_query($query)); 133 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'], ''); 136 $template->assign('navbar', $navbar); 137 138 // +-----------------------------------------------------------------------+ 139 // | last comments display | 140 // +-----------------------------------------------------------------------+ 141 $comments = array(); 142 $element_ids = array(); 143 $category_ids = array(); 144 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 156 ON u.'.$conf['user_fields']['id'].' = com.author_id 157 WHERE '.implode(' 158 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 } 172 $query.= ' 173 ;'; 174 $result = pwg_query($query); 175 176 while ($row = pwg_db_fetch_assoc($result)) { 177 array_push($comments, $row); 178 array_push($element_ids, $row['category_id']); 179 } 180 181 if (count($comments) > 0) { 182 // 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 ;'; 198 $categories = hash_from_query($query, 'comment_id'); 199 200 foreach ($comments as $comment) { 201 // category 202 $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 )); 210 211 // comment content 212 $tpl_comment = array( 213 'CAT_URL' => $url, 214 'CAT_NAME' => $name, 215 'AUTHOR' => trigger_event('render_comment_author', $comment['author']), 216 'DATE' => format_date($comment['date'], true), 217 'CONTENT' => trigger_event('render_comment_content',$comment['content']), 218 ); 219 220 // rights 221 if (can_manage_comment('delete', $comment['author_id'])) { 222 $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate','edit', 'pwg_token')); 223 224 $tpl_comment['U_DELETE'] = add_url_params($url, array( 225 'delete_albums' => $comment['comment_id'], 226 'pwg_token' => get_pwg_token(), 227 )); 228 } 229 if (can_manage_comment('edit', $comment['author_id'])) { 230 $url = get_root_url().'comments.php'.get_query_string_diff(array('edit', 'delete','validate', 'pwg_token')); 231 232 $tpl_comment['U_EDIT'] = add_url_params($url, array( 233 'edit_albums' => $comment['comment_id'], 234 'pwg_token' => get_pwg_token(), 235 )); 236 237 if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) { 238 $key = get_ephemeral_key(2, $comment['category_id']); 239 $tpl_comment['IN_EDIT'] = true; 240 $tpl_comment['KEY'] = $key; 241 $tpl_comment['IMAGE_ID'] = $comment['category_id']; 242 $tpl_comment['CONTENT'] = $comment['content']; 243 } 244 } 245 if (can_manage_comment('validate', $comment['author_id'])) { 246 if ('true' != $comment['validated']) { 247 $tpl_comment['U_VALIDATE'] = add_url_params($url, array( 248 'validate_albums'=> $comment['comment_id'], 249 'pwg_token' => get_pwg_token(), 250 )); 251 } 252 } 253 254 $template->append('comments', $tpl_comment); 255 } 256 } 257 258 // +-----------------------------------------------------------------------+ 259 // | template | 260 // +-----------------------------------------------------------------------+ 261 $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/coa_comments_page.tpl')); 262 263 // add a layer for display category name 264 $template->set_prefilter('comments', 'coa_change_comments_list'); 265 function coa_change_comments_list($content, &$smarty) { 266 $search = '<div class="description"{if isset($comment.IN_EDIT)} style="height:200px"{/if}>'; 267 267 268 268 $replacement = '<div class="category-title"> 269 269 <a href="{$comment.CAT_URL}">{$comment.CAT_NAME}</a> 270 270 </div> 271 271 <div class="description"{if isset($comment.IN_EDIT)} style="height:220px"{/if}>'; 272 272 273 274 273 return str_replace($search, $replacement, $content); 274 } 275 275 } 276 276
Note: See TracChangeset
for help on using the changeset viewer.