source: extensions/Comments_on_Albums/stuffs_module/main.inc.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: 5.4 KB
RevLine 
[12381]1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4global $user, $conf;
5
6// +-----------------------------------------------------------------------+
7// |                         comments management                           |
8// +-----------------------------------------------------------------------+
9// comments deletion
10if (isset($_GET['delete_album']) and is_numeric($_GET['delete_album']) and is_admin())
11{
12    check_status(ACCESS_ADMINISTRATOR);
13    check_pwg_token();
14    $query = '
15DELETE FROM ' . COA_TABLE . '
16  WHERE id=' . $_GET['delete_album'] . '
17;';
18    pwg_query($query);
19}
20
21// comments validation
22if (isset($_GET['validate_album']) and is_numeric($_GET['validate_album']) and is_admin())
23{
24    check_status(ACCESS_ADMINISTRATOR);
25    check_pwg_token();
26    $query = '
27UPDATE ' . COA_TABLE . '
28  SET validated = \'true\'
29  , validation_date = NOW()
30  WHERE id=' . $_GET['validate_album'] . '
31;';
32    pwg_query($query);
33}
34
35// +-----------------------------------------------------------------------+
36// |                        last comments display                          |
37// +-----------------------------------------------------------------------+
38$comments = array();
39$element_ids = array();
40$category_ids = array();
41$max_width = 0;
42if (!is_admin())
43{
44  $clauses[] = 'validated="true"';
45}
46$clauses[] = get_sql_condition_FandF (
47    array ('forbidden_categories' => 'category_id',
[12562]48        'visible_categories' => 'category_id'), '', true);
[12381]49
50$query = '
51SELECT
52    com.id AS comment_id,
53    com.category_id,
54    com.author,
55    com.author_id,
56    '.$conf['user_fields']['username'].' AS username,
57    com.date,
58    com.content,
59    com.validated
60  FROM '.COA_TABLE.' AS com
61    LEFT JOIN '.USERS_TABLE.' As u
62      ON u.'.$conf['user_fields']['id'].' = com.author_id
63  WHERE '.implode('
64    AND ', $clauses).'
65  GROUP BY
66    comment_id
67  ORDER BY date DESC
68  LIMIT 0, ' . $datas[0] . '
69;';
70
71$result = pwg_query($query);
72while ($row = mysql_fetch_assoc($result))
73{
74  array_push($comments, $row);
75  array_push($element_ids, $row['category_id']);
76}
77
78if (count($comments) > 0)
79{
80  $block['TITLE_URL'] = 'comments.php?display_mode=albums';
81  $block['comments'] = array();
82
83  // retrieving category informations
84  $query = '
85SELECT
86    cat.id,
87    cat.name,
88    cat.permalink,
89    cat.uppercats,
90    com.id as comment_id,
91    img.id AS image_id,
92    img.path,
93    img.tn_ext
94  FROM '.CATEGORIES_TABLE.' AS cat
95    LEFT JOIN '.COA_TABLE.' AS com
96      ON com.category_id = cat.id
97    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
98      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
99    LEFT JOIN '.IMAGES_TABLE.' AS img
100      ON img.id = ucc.user_representative_picture_id
101  '.get_sql_condition_FandF(
102    array(
103      'forbidden_categories' => 'cat.id',
104      'visible_categories' => 'cat.id'
105      ), 
106    'WHERE'
107    ).'
108    AND cat.id IN ('.implode(',', $element_ids).')
109;';
110  $categories = hash_from_query($query, 'comment_id');
111
112  foreach ($comments as $comment)
113  {
114    // category url
115    $comment['cat_url'] = duplicate_index_url(
116      array(
117        'category' => array(
118          'id' => $categories[$comment['comment_id']]['id'], 
119          'name' => $categories[$comment['comment_id']]['name'], 
120          'permalink' => $categories[$comment['comment_id']]['permalink'],
121          ),
122        array('start')
123        )
124      );
125     
126    // category thumbnail
127    $comment['thumb'] = get_thumbnail_url(
128      array(
129        'id' => $categories[$comment['comment_id']]['image_id'],
130        'path' => $categories[$comment['comment_id']]['path'],
131        'tn_ext' => @$categories[$comment['comment_id']]['tn_ext'],
132        )
133     );
134
135    // author
136    $author = $comment['author'];
137    if (empty($comment['author']))
138    {
139      $author = l10n('guest');
140    }
141   
142    // comment content
143    $tpl_comment = array(
144      'ID' => $comment['comment_id'],
145      'U_PICTURE' => $comment['cat_url'],
146      'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']),
147      'TN_SRC' => $comment['thumb'],
148      'AUTHOR' => trigger_event('render_comment_author', $author),
149      'DATE' => format_date($comment['date'], true),
150      'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'),
151      'WIDTH' => $datas[3],
152      'HEIGHT' => $datas[4],
153      );
154
155    switch ($datas[2])
156    {
157      case 1 :
158        $tpl_comment['CLASS'] = 'one_comment';
159        break;
160      case 2 :
161        $tpl_comment['CLASS'] = 'two_comment';
162        break;
163      case 3 :
164        $tpl_comment['CLASS'] = 'three_comment';
165        break;
166    }
167
168    // actions
169    if ( is_admin() and $datas[1])
170    {
171      $url = get_root_url().'index.php'.get_query_string_diff(array('delete_album','validate_album'));
172      $tpl_comment['U_DELETE'] = add_url_params($url, array(
173            'delete_album' => $comment['comment_id'],
174            'pwg_token' => get_pwg_token()));
175
176      if ($comment['validated'] != 'true')
177      {
178        $tpl_comment['U_VALIDATE'] = add_url_params($url, array(
179            'validate_album' => $comment['comment_id'],
180            'pwg_token' => get_pwg_token()));
181      }
182    }
183   
184    array_push($block['comments'], $tpl_comment);
185  }
186  $block['TEMPLATE'] = dirname(__FILE__).'/stuffs_lastcoms.tpl';
187}
188
189?>
Note: See TracBrowser for help on using the repository browser.