source: extensions/Comments_on_Albums/stuffs_module/main.inc.php @ 12411

Last change on this file since 12411 was 12381, checked in by mistic100, 13 years ago

add a PWG Stuffs module, add menu bar on comments page

File size: 5.4 KB
Line 
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',
48        'visible_categories' => 'category_id',
49        'visible_images' => 'ic.image_id'), '', true);
50
51$query = '
52SELECT
53    com.id AS comment_id,
54    com.category_id,
55    com.author,
56    com.author_id,
57    '.$conf['user_fields']['username'].' AS username,
58    com.date,
59    com.content,
60    com.validated
61  FROM '.COA_TABLE.' AS com
62    LEFT JOIN '.USERS_TABLE.' As u
63      ON u.'.$conf['user_fields']['id'].' = com.author_id
64  WHERE '.implode('
65    AND ', $clauses).'
66  GROUP BY
67    comment_id
68  ORDER BY date DESC
69  LIMIT 0, ' . $datas[0] . '
70;';
71
72$result = pwg_query($query);
73while ($row = mysql_fetch_assoc($result))
74{
75  array_push($comments, $row);
76  array_push($element_ids, $row['category_id']);
77}
78
79if (count($comments) > 0)
80{
81  $block['TITLE_URL'] = 'comments.php?display_mode=albums';
82  $block['comments'] = array();
83
84  // retrieving category informations
85  $query = '
86SELECT
87    cat.id,
88    cat.name,
89    cat.permalink,
90    cat.uppercats,
91    com.id as comment_id,
92    img.id AS image_id,
93    img.path,
94    img.tn_ext
95  FROM '.CATEGORIES_TABLE.' AS cat
96    LEFT JOIN '.COA_TABLE.' AS com
97      ON com.category_id = cat.id
98    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
99      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
100    LEFT JOIN '.IMAGES_TABLE.' AS img
101      ON img.id = ucc.user_representative_picture_id
102  '.get_sql_condition_FandF(
103    array(
104      'forbidden_categories' => 'cat.id',
105      'visible_categories' => 'cat.id'
106      ), 
107    'WHERE'
108    ).'
109    AND cat.id IN ('.implode(',', $element_ids).')
110;';
111  $categories = hash_from_query($query, 'comment_id');
112
113  foreach ($comments as $comment)
114  {
115    // category url
116    $comment['cat_url'] = duplicate_index_url(
117      array(
118        'category' => array(
119          'id' => $categories[$comment['comment_id']]['id'], 
120          'name' => $categories[$comment['comment_id']]['name'], 
121          'permalink' => $categories[$comment['comment_id']]['permalink'],
122          ),
123        array('start')
124        )
125      );
126     
127    // category thumbnail
128    $comment['thumb'] = get_thumbnail_url(
129      array(
130        'id' => $categories[$comment['comment_id']]['image_id'],
131        'path' => $categories[$comment['comment_id']]['path'],
132        'tn_ext' => @$categories[$comment['comment_id']]['tn_ext'],
133        )
134     );
135
136    // author
137    $author = $comment['author'];
138    if (empty($comment['author']))
139    {
140      $author = l10n('guest');
141    }
142   
143    // comment content
144    $tpl_comment = array(
145      'ID' => $comment['comment_id'],
146      'U_PICTURE' => $comment['cat_url'],
147      'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']),
148      'TN_SRC' => $comment['thumb'],
149      'AUTHOR' => trigger_event('render_comment_author', $author),
150      'DATE' => format_date($comment['date'], true),
151      'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'),
152      'WIDTH' => $datas[3],
153      'HEIGHT' => $datas[4],
154      );
155
156    switch ($datas[2])
157    {
158      case 1 :
159        $tpl_comment['CLASS'] = 'one_comment';
160        break;
161      case 2 :
162        $tpl_comment['CLASS'] = 'two_comment';
163        break;
164      case 3 :
165        $tpl_comment['CLASS'] = 'three_comment';
166        break;
167    }
168
169    // actions
170    if ( is_admin() and $datas[1])
171    {
172      $url = get_root_url().'index.php'.get_query_string_diff(array('delete_album','validate_album'));
173      $tpl_comment['U_DELETE'] = add_url_params($url, array(
174            'delete_album' => $comment['comment_id'],
175            'pwg_token' => get_pwg_token()));
176
177      if ($comment['validated'] != 'true')
178      {
179        $tpl_comment['U_VALIDATE'] = add_url_params($url, array(
180            'validate_album' => $comment['comment_id'],
181            'pwg_token' => get_pwg_token()));
182      }
183    }
184   
185    array_push($block['comments'], $tpl_comment);
186  }
187  $block['TEMPLATE'] = dirname(__FILE__).'/stuffs_lastcoms.tpl';
188}
189
190?>
Note: See TracBrowser for help on using the repository browser.