source: extensions/Comments_on_Albums/include/coa_comments_page.php @ 15398

Last change on this file since 15398 was 14528, checked in by mistic100, 12 years ago

update for 2.4
delete useless admin page
now compatible with RV Thumb Scroller

File size: 9.7 KB
Line 
1<?php 
2/* inspired by comments.php */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4load_language('plugin.lang', COA_PATH);
5
6// +-----------------------------------------------------------------------+
7// |                             main page                                 |
8// +-----------------------------------------------------------------------+
9
10if ( !isset($_GET['display_mode']) or $_GET['display_mode'] != 'albums' ) 
11{ 
12  // adds a button for switch page
13  $template->set_prefilter('comments', 'coa_add_button');
14 
15  function coa_add_button($content, &$smarty) 
16  {   
17    $search ="{include file='infos_errors.tpl'}";
18    $replacement = $search.'
19<form class="filter">
20<fieldset>
21  <legend>{\'Display comments on\'|@translate}</legend>
22  <span style="font-size:1.1em;"><a href="#" style="font-weight:bold;">{\'Photos\'|@translate}</a> | <a href="comments.php?display_mode=albums">{\'Albums\'|@translate}</a></span>
23</fieldset>
24</form>';
25
26    return str_replace($search, $replacement, $content);
27  }
28 
29 
30// +-----------------------------------------------------------------------+
31//                        comments on albums page                          |
32// +-----------------------------------------------------------------------+
33
34} 
35else if ($_GET['display_mode'] == 'albums') 
36{
37  include_once(COA_PATH.'include/functions_comment.inc.php'); // custom functions
38 
39  // reset some template vars
40  $template->clear_assign(array('comments', 'navbar', 'sort_by_options'));
41 
42  // sort_by : database fields proposed for sorting comments list
43  $sort_by = array(
44    'date' => l10n('comment date'),
45    'category_id' => l10n('album')
46    );
47  $template->assign('sort_by_options', $sort_by);
48
49  // +-----------------------------------------------------------------------+
50  // |                         comments management                           |
51  // +-----------------------------------------------------------------------+
52  $comment_id = null;
53  $action = null;
54
55  $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process
56  foreach ($actions as $loop_action) 
57  {
58    if (isset($_GET[$loop_action])) 
59    {
60      $action = $loop_action;
61      check_input_parameter($action, $_GET, false, PATTERN_ID);
62      $comment_id = $_GET[$action];
63      break;
64    }
65  }
66
67  if (isset($action)) 
68  {
69    $comment_author_id = get_comment_author_id_albums($comment_id);
70   
71    if (can_manage_comment(str_replace('_albums', null, $action), $comment_author_id)) 
72    {
73      $perform_redirect = false;
74
75      if ('delete_albums' == $action) 
76      {
77        check_pwg_token();
78        delete_user_comment_albums($comment_id);
79        $perform_redirect = true;
80      }
81      if ('validate_albums' == $action) 
82      {
83        check_pwg_token();
84        validate_user_comment_albums($comment_id);
85        $perform_redirect = true;
86      }
87      if ('edit_albums' == $action) 
88      {
89        if (!empty($_POST['content'])) 
90        {
91          check_pwg_token();
92          update_user_comment_albums(
93            array(
94              'comment_id' => $_GET['edit_albums'],
95              'category_id' => $_POST['image_id'],
96              'content' => $_POST['content']
97              ), 
98            $_POST['key']
99            );
100         
101          $perform_redirect = true;
102        } 
103        else 
104        {
105          $edit_comment = $_GET['edit_albums'];
106        }
107      }
108      if ($perform_redirect) 
109      {
110        $redirect_url = 
111          PHPWG_ROOT_PATH
112          .'comments.php'
113          .get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token'));
114       
115        redirect($redirect_url);
116      }
117    }
118  }
119
120  // +-----------------------------------------------------------------------+
121  // |                            navigation bar                             |
122  // +-----------------------------------------------------------------------+
123  if (isset($_GET['start']) and is_numeric($_GET['start'])) 
124  {
125    $start = $_GET['start'];
126  } 
127  else 
128  {
129    $start = 0;
130  }
131
132  $query = '
133SELECT COUNT(DISTINCT(com.id))
134  FROM '.COA_TABLE.' AS com
135  LEFT JOIN '.USERS_TABLE.' As u
136    ON u.'.$conf['user_fields']['id'].' = com.author_id
137  WHERE '.implode('
138    AND ', $page['where_clauses']).'
139;';
140  list($counter) = pwg_db_fetch_row(pwg_query($query));
141
142  $url = PHPWG_ROOT_PATH
143      .'comments.php'
144    .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token'));
145   
146  $navbar = create_navigation_bar(
147    $url, 
148    $counter, 
149    $start, 
150    $page['items_number'], 
151    ''
152    );
153 
154  $template->assign('navbar', $navbar);
155
156  // +-----------------------------------------------------------------------+
157  // |                        last comments display                          |
158  // +-----------------------------------------------------------------------+
159  $comments = array();
160  $element_ids = array();
161  $category_ids = array();
162
163  $query = '
164SELECT
165    com.id AS comment_id,
166    com.category_id,
167    com.author,
168    com.author_id,
169    '.$conf['user_fields']['username'].' AS username,
170    com.date,
171    com.content,
172    com.validated
173  FROM '.COA_TABLE.' AS com
174    LEFT JOIN '.USERS_TABLE.' As u
175      ON u.'.$conf['user_fields']['id'].' = com.author_id
176  WHERE '.implode('
177    AND ', $page['where_clauses']).'
178  GROUP BY
179    comment_id,
180    com.category_id,
181    com.author,
182    com.author_id,
183    com.date,
184    com.content,
185    com.validated
186  ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
187if ('all' != $page['items_number']) 
188{
189  $query.= '
190  LIMIT '.$page['items_number'].' OFFSET '.$start;
191}
192$query.= '
193;';
194  $result = pwg_query($query);
195
196  while ($row = pwg_db_fetch_assoc($result)) 
197  {
198    array_push($comments, $row);
199    array_push($element_ids, $row['category_id']);
200  }
201
202  if (count($comments) > 0) 
203  {
204    // retrieving category informations
205    $query = '
206SELECT
207    cat.id,
208    cat.name,
209    cat.permalink,
210    cat.uppercats,
211    com.id as comment_id,
212    img.id AS image_id,
213    img.path,
214    img.tn_ext
215  FROM '.CATEGORIES_TABLE.' AS cat
216    LEFT JOIN '.COA_TABLE.' AS com
217      ON com.category_id = cat.id
218    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
219      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
220    LEFT JOIN '.IMAGES_TABLE.' AS img
221      ON img.id = ucc.user_representative_picture_id
222  '.get_sql_condition_FandF(
223    array(
224      'forbidden_categories' => 'cat.id',
225      'visible_categories' => 'cat.id'
226      ), 
227    'WHERE'
228    ).'
229    AND cat.id IN ('.implode(',', $element_ids).')
230;';
231    $categories = hash_from_query($query, 'comment_id');
232
233    foreach ($comments as $comment) 
234    {
235      // source of the thumbnail picture
236      $comment['src_image'] = new SrcImage($categories[$comment['comment_id']]);
237   
238      // category url
239      $comment['cat_url'] = duplicate_index_url(
240        array(
241          'category' => array(
242            'id' => $categories[$comment['comment_id']]['id'], 
243            'name' => $categories[$comment['comment_id']]['name'], 
244            'permalink' => $categories[$comment['comment_id']]['permalink'],
245            ),
246          array('start')
247          )
248        );
249     
250      // comment content
251      $tpl_comment = array(
252        'ID' => $comment['comment_id'],
253        'U_PICTURE' => $comment['cat_url'],
254        'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']),
255        'src_image' => $comment['src_image'],
256        'AUTHOR' => trigger_event('render_comment_author', $comment['author']),
257        'DATE' => format_date($comment['date'], true),
258        'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'),
259        );
260
261      // rights
262      if (can_manage_comment('delete', $comment['author_id'])) 
263      {
264        $tpl_comment['U_DELETE'] = add_url_params(
265          $url, 
266          array(
267            'delete_albums' => $comment['comment_id'],
268            'pwg_token' => get_pwg_token(),
269            )
270          );
271      }
272      if (can_manage_comment('edit', $comment['author_id'])) 
273      {
274        $tpl_comment['U_EDIT'] = add_url_params(
275          $url, 
276          array(
277            'edit_albums' => $comment['comment_id'],
278            )
279          );
280
281        if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) 
282        {
283          $tpl_comment['IN_EDIT'] = true;
284          $key = get_ephemeral_key(2, $comment['category_id']);
285          $tpl_comment['KEY'] = $key;
286          $tpl_comment['IMAGE_ID'] = $comment['category_id'];
287          $tpl_comment['CONTENT'] = $comment['content'];
288          $tpl_comment['PWG_TOKEN'] = get_pwg_token();
289        }
290      }
291      if (can_manage_comment('validate', $comment['author_id'])) 
292      {
293        if ('true' != $comment['validated']) 
294        {
295          $tpl_comment['U_VALIDATE'] = add_url_params(
296            $url, 
297            array(
298              'validate_albums'=> $comment['comment_id'],
299              'pwg_token' => get_pwg_token(),
300              )
301            );
302        }
303      }
304     
305      $template->append('comments', $tpl_comment);
306    }
307  }
308
309  // +-----------------------------------------------------------------------+
310  // |                            template                                   |
311  // +-----------------------------------------------------------------------+
312  $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/comments_page.tpl'));
313 
314  // add a line to display category name
315  $template->set_prefilter('comments', 'coa_change_comments_list');
316 
317  function coa_change_comments_list($content, &$smarty) {
318    $search = '<img src="{$pwg->derivative_url($derivative_params, $comment.src_image)}" alt="{$comment.ALT}">';
319    $replacement = $search.'<br/>{$comment.ALT}';
320    return str_replace($search, $replacement, $content);
321  }
322}
323
324?>
Note: See TracBrowser for help on using the repository browser.