source: extensions/PWG_Stuffs/modules/LastComs/main.inc.php @ 3609

Last change on this file since 3609 was 3609, checked in by patdenice, 15 years ago

Convert all php and tpl files in Unix format for my plugins.

File size: 4.6 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5// +-----------------------------------------------------------------------+
6// |                         comments management                           |
7// +-----------------------------------------------------------------------+
8// comments deletion
9if (isset($_GET['delete']) and is_numeric($_GET['delete']) and is_admin() and !is_adviser())
10{
11    check_status(ACCESS_ADMINISTRATOR);
12    $query = '
13DELETE FROM ' . COMMENTS_TABLE . '
14  WHERE id=' . $_GET['delete'] . '
15;';
16    pwg_query($query);
17}
18
19// comments validation
20if (isset($_GET['validate']) and is_numeric($_GET['validate']) and is_admin() and !is_adviser())
21{
22    check_status(ACCESS_ADMINISTRATOR);
23    $query = '
24UPDATE ' . COMMENTS_TABLE . '
25  SET validated = \'true\'
26  , validation_date = NOW()
27  WHERE id=' . $_GET['validate'] . '
28;';
29    pwg_query($query);
30}
31
32// +-----------------------------------------------------------------------+
33// |                        last comments display                          |
34// +-----------------------------------------------------------------------+
35$comments = array();
36$element_ids = array();
37$category_ids = array();
38$max_width = 0;
39if (!is_admin())
40{
41  $clauses[] = 'validated="true"';
42}
43$clauses[] = get_sql_condition_FandF (
44    array ('forbidden_categories' => 'category_id',
45        'visible_categories' => 'category_id',
46        'visible_images' => 'ic.image_id'), '', true);
47
48$query = 'SELECT com.id AS comment_id
49   , com.image_id
50   , ic.category_id
51   , com.author
52   , com.date
53   , com.content
54   , com.id AS comment_id
55   , com.validated
56   FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic
57   INNER JOIN ' . COMMENTS_TABLE . ' AS com
58   ON ic.image_id = com.image_id
59   WHERE ' . implode(' AND ', $clauses) . '
60    GROUP BY comment_id
61    ORDER BY date DESC
62    LIMIT 0, ' . $datas[0] . ';';
63
64$result = pwg_query($query);
65while ($row = mysql_fetch_assoc($result))
66{
67  array_push($comments, $row);
68  array_push($element_ids, $row['image_id']);
69  array_push($category_ids, $row['category_id']);
70}
71
72if (count($comments) > 0)
73{
74  $block['TITLE_URL'] = 'comments.php';
75  $block['comments'] = array();
76
77  // retrieving element informations
78  $elements = array();
79  $query = '
80SELECT id, name, file, path, tn_ext
81  FROM '.IMAGES_TABLE.'
82  WHERE id IN ('.implode(',', $element_ids).')
83;';
84  $result = pwg_query($query);
85  while ($row = mysql_fetch_assoc($result))
86  {
87    $elements[$row['id']] = $row;
88  }
89
90  // retrieving category informations
91  $query = '
92SELECT id, name, permalink, uppercats
93  FROM '.CATEGORIES_TABLE.'
94  WHERE id IN ('.implode(',', $category_ids).')
95;';
96  $categories = hash_from_query($query, 'id');
97
98  foreach ($comments as $comment)
99  {
100    if (!empty($elements[$comment['image_id']]['name']))
101    {
102      $name=$elements[$comment['image_id']]['name'];
103    }
104    else
105    {
106      $name=get_name_from_file($elements[$comment['image_id']]['file']);
107    }
108
109    // source of the thumbnail picture
110    $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] );
111
112    // link to the full size picture
113    $url = make_picture_url(
114            array(
115              'category' => $categories[ $comment['category_id'] ],
116              'image_id' => $comment['image_id'],
117              'image_file' => $elements[$comment['image_id']]['file'],
118            )
119          );
120
121    $author = $comment['author'];
122    if (empty($comment['author']))
123    {
124      $author = l10n('guest');
125    }
126
127    $tpl_comment =
128      array(
129        'U_PICTURE' => $url,
130        'TN_SRC' => $thumbnail_src,
131        'ALT' => $name,
132        'AUTHOR' => trigger_event('render_comment_author', $author),
133        'DATE' => format_date($comment['date'],'mysql_datetime',true),
134        'CONTENT' => trigger_event('render_comment_content',$comment['content']),
135        'WIDTH' => $datas[3],
136        'HEIGHT' => $datas[4],
137        );
138
139    switch ($datas[2])
140    {
141      case 1 :
142        $tpl_comment['CLASS'] = 'one_comment';
143        break;
144      case 2 :
145        $tpl_comment['CLASS'] = 'two_comment';
146        break;
147      case 3 :
148        $tpl_comment['CLASS'] = 'three_comment';
149        break;
150    }
151
152    if ( is_admin() )
153    {
154      $url = get_root_url().'index.php'.get_query_string_diff(array('delete','validate'));
155      $tpl_comment['U_DELETE'] = add_url_params($url,
156                          array('delete'=>$comment['comment_id'])
157                         );
158
159      if ($comment['validated'] != 'true')
160      {
161        $tpl_comment['U_VALIDATE'] = add_url_params($url,
162                            array('validate'=>$comment['comment_id'])
163                           );
164      }
165    }
166    array_push($block['comments'], $tpl_comment);
167  }
168}
169else
170{
171  return false;
172}
173
174?>
Note: See TracBrowser for help on using the repository browser.