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

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

minor changes for Piwigo 2.3.1 and Subscribe To Comments plugin

File size: 10.8 KB
RevLine 
[9634]1<?php 
[11267]2/* inspired by comments.php */
[9634]3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
[9641]5load_language('plugin.lang', COA_PATH);
6$conf['comments_on_albums'] = unserialize($conf['comments_on_albums']);
7
[11267]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  );
[9634]15
[9641]16
17// +-----------------------------------------------------------------------+
[11267]18// |                             main page                                 |
[9641]19// +-----------------------------------------------------------------------+
20
[11267]21if (!isset($_GET['display_mode'])) 
22{ 
[10984]23  // adds a button for switch page
24  $template->set_prefilter('comments', 'coa_add_button');
[11267]25 
26  function coa_add_button($content, &$smarty) 
27  {
[10984]28    $search = '<ul class="categoryActions">';
[9634]29
[9641]30$replacement = '
31{html_head}
[10984]32  <style type="text/css">
33    .pwg-icon-comments-albums {ldelim}
34      background-image: url({$COA_PATH}template/s26/{$ICON_COLOR});
35      background-position: -26px 0;
36    }
37    a:hover .pwg-icon-comments-albums {ldelim}
38      background-image: url({$COA_PATH}template/s26/{$ICON_COLOR_OVER});
39      background-position: -26px 0;
40    }
41  </style>
[9641]42{/html_head}
[9634]43
[11267]44  '.$search.'
[11874]45    <li><a href="comments.php?display_mode=albums" title="' . l10n('Comments on albums') . '" class="pwg-state-default pwg-button">
46      <span class="pwg-icon pwg-icon-comments-albums">&nbsp;</span><span class="pwg-button-text">' . l10n('Comments on albums') . '</span>
[10984]47    </a></li>';
[9634]48
[10984]49    return str_replace($search, $replacement, $content);
50  }
51 
52 
[9641]53// +-----------------------------------------------------------------------+
[11267]54//                        comments on albums page                          |
[9641]55// +-----------------------------------------------------------------------+
56
[11267]57} 
58else if ($_GET['display_mode'] == 'albums') 
59{
[10984]60  // reset some template vars
61  $template->clear_assign(array('comments', 'navbar', 'sort_by_options'));
62 
63  // sort_by : database fields proposed for sorting comments list
64  $sort_by = array(
65    'date' => l10n('comment date'),
66    'category_id' => l10n('album')
[11267]67    );
[10984]68  $template->assign('sort_by_options', $sort_by);
[9634]69
[10984]70  // +-----------------------------------------------------------------------+
71  // |                         comments management                           |
72  // +-----------------------------------------------------------------------+
73  $comment_id = null;
74  $action = null;
[9634]75
[10984]76  $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process
[11267]77  foreach ($actions as $loop_action) 
78  {
79    if (isset($_GET[$loop_action])) 
80    {
[10984]81      $action = $loop_action;
82      check_input_parameter($action, $_GET, false, PATTERN_ID);
83      $comment_id = $_GET[$action];
84      break;
85    }
86  }
[9634]87
[11267]88  if (isset($action)) 
89  {
[10984]90    include_once(COA_PATH.'include/functions_comment.inc.php');
[11267]91   
[10984]92    check_pwg_token();
[11267]93   
[10984]94    $comment_author_id = get_comment_author_id_albums($comment_id);
[11267]95   
[10984]96    $true_action = str_replace('_albums', null, $action); // but we must check true action names
[9634]97
[11267]98    if (can_manage_comment($true_action, $comment_author_id)) 
99    {
[10984]100      $perform_redirect = false;
[9634]101
[11267]102      if ('delete_albums' == $action) 
103      {
[10984]104        delete_user_comment_albums($comment_id);
105        $perform_redirect = true;
106      }
[11267]107      if ('validate_albums' == $action) 
108      {
[10984]109        validate_user_comment_albums($comment_id);
110        $perform_redirect = true;
111      }
[11267]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'],
[12562]119              'category_id' => $_POST['image_id'],
[11267]120              'content' => $_POST['content']
121              ), 
122            $_POST['key']
123            );
124          //$perform_redirect = true;
125          $edit_comment = null;
126        } 
127        else 
128        {
[10984]129          $edit_comment = $_GET['edit_albums'];
130        }
131      }
[11267]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       
[10984]139        redirect($redirect_url);
140      }
141    }
142  }
[9634]143
[10984]144  // +-----------------------------------------------------------------------+
145  // |                            navigation bar                             |
146  // +-----------------------------------------------------------------------+
[11267]147  if (isset($_GET['start']) and is_numeric($_GET['start'])) 
148  {
[10984]149    $start = $_GET['start'];
[11267]150  } 
151  else 
152  {
[10984]153    $start = 0;
154  }
[9634]155
[11267]156  $query = '
157SELECT
158    COUNT(DISTINCT(com.id))
159  FROM '.COA_TABLE.' AS com
160  LEFT JOIN '.USERS_TABLE.' As u
[10984]161    ON u.'.$conf['user_fields']['id'].' = com.author_id
[11267]162  WHERE '.implode('
[10984]163    AND ', $page['where_clauses']).'
[11267]164;';
[10984]165  list($counter) = pwg_db_fetch_row(pwg_query($query));
[9634]166
[11267]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    );
[10984]179  $template->assign('navbar', $navbar);
[9634]180
[10984]181  // +-----------------------------------------------------------------------+
182  // |                        last comments display                          |
183  // +-----------------------------------------------------------------------+
184  $comments = array();
185  $element_ids = array();
186  $category_ids = array();
[9634]187
[11267]188  $query = '
189SELECT
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
[11327]199    LEFT JOIN '.USERS_TABLE.' As u
200      ON u.'.$conf['user_fields']['id'].' = com.author_id
[11267]201  WHERE '.implode('
[10984]202    AND ', $page['where_clauses']).'
[11267]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  {
[10984]214    $query.= '
[11267]215  LIMIT '.$page['items_number'].' OFFSET '.$start;
216  }
217  $query.= '
218;';
[10984]219  $result = pwg_query($query);
[9634]220
[11267]221  while ($row = pwg_db_fetch_assoc($result)) 
222  {
[10984]223    array_push($comments, $row);
224    array_push($element_ids, $row['category_id']);
225  }
[9634]226
[11267]227  if (count($comments) > 0) 
228  {
[10984]229    // retrieving category informations
[11267]230    $query = '
231SELECT
232    cat.id,
233    cat.name,
234    cat.permalink,
235    cat.uppercats,
[11327]236    com.id as comment_id,
237    img.id AS image_id,
238    img.path,
239    img.tn_ext
[11267]240  FROM '.CATEGORIES_TABLE.' AS cat
[11327]241    LEFT JOIN '.COA_TABLE.' AS com
242      ON com.category_id = cat.id
243    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
244      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
245    LEFT JOIN '.IMAGES_TABLE.' AS img
246      ON img.id = ucc.user_representative_picture_id
[11267]247  '.get_sql_condition_FandF(
248    array(
249      'forbidden_categories' => 'cat.id',
250      'visible_categories' => 'cat.id'
251      ), 
252    'WHERE'
253    ).'
254    AND cat.id IN ('.implode(',', $element_ids).')
255;';
[10984]256    $categories = hash_from_query($query, 'comment_id');
[9634]257
[11267]258    foreach ($comments as $comment) 
259    {
[11327]260      // category url
261      $comment['cat_url'] = duplicate_index_url(
[11267]262        array(
263          'category' => array(
264            'id' => $categories[$comment['comment_id']]['id'], 
265            'name' => $categories[$comment['comment_id']]['name'], 
266            'permalink' => $categories[$comment['comment_id']]['permalink'],
267            ),
268          array('start')
269          )
270        );
[11327]271       
272      // category thumbnail
273      $comment['thumb'] = get_thumbnail_url(
274        array(
275          'id' => $categories[$comment['comment_id']]['image_id'],
276          'path' => $categories[$comment['comment_id']]['path'],
277          'tn_ext' => @$categories[$comment['comment_id']]['tn_ext'],
278          )
279       );
[10984]280     
281      // comment content
282      $tpl_comment = array(
[11251]283        'ID' => $comment['comment_id'],
[11327]284        'U_PICTURE' => $comment['cat_url'],
285        'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']),
286        'TN_SRC' => $comment['thumb'],
[10984]287        'AUTHOR' => trigger_event('render_comment_author', $comment['author']),
288        'DATE' => format_date($comment['date'], true),
[11417]289        'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'),
[11267]290        );
[9634]291
[10984]292      // rights
[11267]293      if (can_manage_comment('delete', $comment['author_id'])) 
294      {
295        $url = 
296          get_root_url()
297          .'comments.php'
298          .get_query_string_diff(array('delete','validate','edit', 'pwg_token'));
[9634]299
[11267]300        $tpl_comment['U_DELETE'] = add_url_params(
301          $url, 
302          array(
303            'delete_albums' => $comment['comment_id'],
304            'pwg_token' => get_pwg_token(),
305            )
306          );
[10984]307      }
[11267]308      if (can_manage_comment('edit', $comment['author_id'])) 
309      {
310        $url = 
311          get_root_url()
312          .'comments.php'
313          .get_query_string_diff(array('edit', 'delete','validate', 'pwg_token'));
[9641]314
[11267]315        $tpl_comment['U_EDIT'] = add_url_params(
316          $url, 
317          array(
318            'edit_albums' => $comment['comment_id'],
319            'pwg_token' => get_pwg_token(),
320            )
321          );
[9641]322
[11267]323        if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) 
324        {
[10984]325          $key = get_ephemeral_key(2, $comment['category_id']);
326          $tpl_comment['IN_EDIT'] = true;
327          $tpl_comment['KEY'] = $key;
328          $tpl_comment['IMAGE_ID'] = $comment['category_id'];
329          $tpl_comment['CONTENT'] = $comment['content'];
330        }
331      }
[11267]332      if (can_manage_comment('validate', $comment['author_id'])) 
333      {
334        if ('true' != $comment['validated']) 
335        {
336          $tpl_comment['U_VALIDATE'] = add_url_params(
337            $url, 
338            array(
339              'validate_albums'=> $comment['comment_id'],
340              'pwg_token' => get_pwg_token(),
341              )
342            );
[10984]343        }
344      }
345     
346      $template->append('comments', $tpl_comment);
347    }
348  }
[9634]349
[10984]350  // +-----------------------------------------------------------------------+
[11267]351  // |                            template                                   |
[10984]352  // +-----------------------------------------------------------------------+
[11267]353  $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/comments_page.tpl'));
[10984]354 
[11267]355  // add a line to display category name
[10984]356  $template->set_prefilter('comments', 'coa_change_comments_list');
[11267]357 
[10984]358  function coa_change_comments_list($content, &$smarty) {
[11327]359    $search = '<img src="{$comment.TN_SRC}" alt="{$comment.ALT}">';
360    $replacement = $search.'<br/>{$comment.ALT}';
[10984]361    return str_replace($search, $replacement, $content);
362  }
[9634]363}
364
365?>
Note: See TracBrowser for help on using the repository browser.