source: extensions/Comments_on_Albums/trunk/stuffs_module/main.inc.php @ 26110

Last change on this file since 26110 was 26110, checked in by mistic100, 10 years ago

use new trigger methods and add extra param

File size: 7.1 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4include_once(COA_PATH.'include/functions_comment.inc.php');
5
6global $user, $conf;
7
8// +-----------------------------------------------------------------------+
9// |                         comments management                           |
10// +-----------------------------------------------------------------------+
11
12$comment_id = null;
13$action = null;
14
15$actions = array('delete_comment_album', 'validate_comment_album', 'edit_comment_album');
16foreach ($actions as $loop_action)
17{
18  if (isset($_GET[$loop_action]))
19  {
20    $action = $loop_action;
21    check_input_parameter($action, $_GET, false, PATTERN_ID);
22    $comment_id = $_GET[$action];
23    break;
24  }
25}
26
27if (isset($action))
28{
29  check_pwg_token();
30
31  $comment_author_id = get_comment_author_id_albums($comment_id);
32  $action = str_replace('_comment_album', '', $action);
33
34  if (can_manage_comment($action, $comment_author_id))
35  {
36    $perform_redirect = false;
37
38    if ('delete' == $action)
39    {
40      delete_user_comment_albums($comment_id);
41      $perform_redirect = true;
42    }
43
44    if ('validate' == $action)
45    {
46      validate_user_comment_albums($comment_id);
47      $perform_redirect = true;
48    }
49
50    if ('edit' == $action)
51    {
52      if (!empty($_POST['content']))
53      {
54        update_user_comment_albums(
55          array(
56            'comment_id' => $_GET['edit_comment_album'],
57            'category_id' => $_POST['image_id'],
58            'content' => $_POST['content']
59            ),
60          $_POST['key']
61          );
62
63        $perform_redirect = true;
64      }
65      else
66      {
67        $edit_comment = $_GET['edit_comment_album'];
68      }
69    }
70
71    if ($perform_redirect)
72    {
73      $redirect_url =
74        PHPWG_ROOT_PATH
75        .'index.php'
76        .get_query_string_diff(array('delete_comment_album','validate_comment_album','edit_comment_album','pwg_token'));
77
78      redirect(rtrim($redirect_url, '='));
79    }
80  }
81}
82
83// +-----------------------------------------------------------------------+
84// |                        last comments display                          |
85// +-----------------------------------------------------------------------+
86if ( !is_admin() )
87{
88  $page['where_clauses'][] = 'validated=\'true\'';
89}
90
91$page['where_clauses'][] = get_sql_condition_FandF
92  (
93    array
94      (
95        'forbidden_categories' => 'category_id',
96        'visible_categories' => 'category_id',
97      ),
98    '', true
99  );
100
101$comments = array();
102$element_ids = array();
103$category_ids = array();
104
105$query = '
106SELECT com.id AS comment_id,
107       com.category_id,
108       com.author,
109       com.author_id,
110       com.date,
111       com.content,
112       com.validated
113  FROM '.COA_TABLE.' AS com
114    LEFT JOIN '.USERS_TABLE.' AS u
115    ON u.'.$conf['user_fields']['id'].' = com.author_id
116  WHERE '.implode('
117    AND ', $page['where_clauses']).'
118  GROUP BY comment_id,
119       com.category_id,
120       com.author,
121       com.author_id,
122       com.date,
123       com.content,
124       com.validated
125  ORDER BY date DESC
126  LIMIT 0, ' . $datas[0] . ';';
127
128$query.= '
129;';
130$result = pwg_query($query);
131while ($row = pwg_db_fetch_assoc($result))
132{
133  array_push($comments, $row);
134  array_push($element_ids, $row['category_id']);
135}
136
137if (count($comments) > 0)
138{
139  $block['TEMPLATE'] = 'stuffs_lastcoms.tpl';
140  $block['TITLE_URL'] = 'comments.php?display_mode=albums';
141  $block['comments'] = array();
142  $block['MAX_WIDTH'] = $datas[3];
143  $block['MAX_HEIGHT'] = $datas[4];
144  switch ($datas[2])
145  {
146    case 1 :
147      $block['NB_COMMENTS_LINE'] = '99%';
148      break;
149    case 2 :
150      $block['NB_COMMENTS_LINE'] = '49%';
151      break;
152    case 3 :
153      $block['NB_COMMENTS_LINE'] = '32.4%';
154      break;
155  }
156 
157  // retrieving category informations
158  $query = '
159SELECT
160    cat.id,
161    cat.name,
162    cat.permalink,
163    cat.uppercats,
164    com.id as comment_id,
165    img.id AS image_id,
166    img.path
167  FROM '.CATEGORIES_TABLE.' AS cat
168    LEFT JOIN '.COA_TABLE.' AS com
169      ON com.category_id = cat.id
170    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
171      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
172    LEFT JOIN '.IMAGES_TABLE.' AS img
173      ON img.id = ucc.user_representative_picture_id
174  '.get_sql_condition_FandF(
175    array(
176      'forbidden_categories' => 'cat.id',
177      'visible_categories' => 'cat.id'
178      ), 
179    'WHERE'
180    ).'
181    AND cat.id IN ('.implode(',', $element_ids).')
182;';
183  $categories = hash_from_query($query, 'comment_id');
184
185  foreach ($comments as $comment)
186  {
187    // category url
188    $comment['cat_url'] = duplicate_index_url(
189      array(
190        'category' => $categories[$comment['comment_id']],
191        array('start')
192        )
193      );
194
195    // source of the thumbnail picture
196    $src_image = new SrcImage(array(
197      'id' => $categories[$comment['comment_id']]['image_id'],
198      'path' => $categories[$comment['comment_id']]['path'],
199      ));
200
201    // author
202    if (empty($comment['author']))
203    {
204      $comment['author'] = l10n('guest');
205    }
206
207    $tpl_comment = array(
208      'ID' => $comment['comment_id'],
209      'U_PICTURE' => $comment['cat_url'],
210      'src_image' => $src_image,
211      'ALT' => trigger_change('render_category_name', $categories[$comment['comment_id']]['name']),
212      'AUTHOR' => trigger_change('render_comment_author', $comment['author']),
213      'DATE'=> format_date($comment['date'], true),
214      'CONTENT'=> trigger_change('render_comment_content',$comment['content'], 'album'),
215      'WIDTH' => $datas[3],
216      'HEIGHT' => $datas[4],
217      );
218   
219    if ($datas[1] == 'on')
220    {
221      $url =
222        get_root_url()
223        .'index.php'
224        .get_query_string_diff(array('edit_comment_album', 'delete_comment_album','validate_comment_album', 'pwg_token'));
225
226      if (can_manage_comment('delete', $comment['author_id']))
227      {
228        $tpl_comment['U_DELETE'] = add_url_params(
229          $url,
230          array(
231            'delete_comment_album' => $comment['comment_id'],
232            'pwg_token' => get_pwg_token(),
233            )
234          );
235      }
236
237      if (can_manage_comment('edit', $comment['author_id']))
238      {
239        $tpl_comment['U_EDIT'] = add_url_params(
240          $url,
241          array(
242            'edit_comment_album' => $comment['comment_id'],
243            'pwg_token' => get_pwg_token(),
244            )
245          );
246
247        if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment))
248        {
249          $tpl_comment['IN_EDIT'] = true;
250          $key = get_ephemeral_key(2, $comment['category_id']);
251          $tpl_comment['KEY'] = $key;
252          $tpl_comment['IMAGE_ID'] = $comment['category_id'];
253          $tpl_comment['CONTENT'] = $comment['content'];
254          $tpl_comment['PWG_TOKEN'] = get_pwg_token();
255        }
256      }
257
258      if (can_manage_comment('validate', $comment['author_id']))
259      {
260        if ('true' != $comment['validated'])
261        {
262          $tpl_comment['U_VALIDATE'] = add_url_params(
263            $url,
264            array(
265              'validate_comment_album'=> $comment['comment_id'],
266              'pwg_token' => get_pwg_token(),
267              )
268            );
269        }
270      }
271    }
272   
273    array_push($block['comments'], $tpl_comment);
274  }
275  $block['derivative_params'] = ImageStdParams::get_by_type(IMG_THUMB);
276}
277
278?>
Note: See TracBrowser for help on using the repository browser.