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

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