1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | global $user, $conf; |
---|
5 | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | comments management | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // comments deletion |
---|
10 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) and is_admin() and !is_adviser()) |
---|
11 | { |
---|
12 | check_status(ACCESS_ADMINISTRATOR); |
---|
13 | check_pwg_token(); |
---|
14 | $query = ' |
---|
15 | DELETE FROM ' . COMMENTS_TABLE . ' |
---|
16 | WHERE id=' . $_GET['delete'] . ' |
---|
17 | ;'; |
---|
18 | pwg_query($query); |
---|
19 | } |
---|
20 | |
---|
21 | // comments validation |
---|
22 | if (isset($_GET['validate']) and is_numeric($_GET['validate']) and is_admin() and !is_adviser()) |
---|
23 | { |
---|
24 | check_status(ACCESS_ADMINISTRATOR); |
---|
25 | check_pwg_token(); |
---|
26 | $query = ' |
---|
27 | UPDATE ' . COMMENTS_TABLE . ' |
---|
28 | SET validated = \'true\' |
---|
29 | , validation_date = NOW() |
---|
30 | WHERE id=' . $_GET['validate'] . ' |
---|
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; |
---|
42 | if (!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 = 'SELECT com.id AS comment_id |
---|
52 | , com.image_id |
---|
53 | , ic.category_id |
---|
54 | , com.author |
---|
55 | , com.date |
---|
56 | , com.content |
---|
57 | , com.id AS comment_id |
---|
58 | , com.validated |
---|
59 | FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic |
---|
60 | INNER JOIN ' . COMMENTS_TABLE . ' AS com |
---|
61 | ON ic.image_id = com.image_id |
---|
62 | WHERE ' . implode(' AND ', $clauses) . ' |
---|
63 | GROUP BY comment_id |
---|
64 | ORDER BY date DESC |
---|
65 | LIMIT 0, ' . $datas[0] . ';'; |
---|
66 | |
---|
67 | $result = pwg_query($query); |
---|
68 | while ($row = mysql_fetch_assoc($result)) |
---|
69 | { |
---|
70 | array_push($comments, $row); |
---|
71 | array_push($element_ids, $row['image_id']); |
---|
72 | array_push($category_ids, $row['category_id']); |
---|
73 | } |
---|
74 | |
---|
75 | if (count($comments) > 0) |
---|
76 | { |
---|
77 | $block['TITLE_URL'] = 'comments.php'; |
---|
78 | $block['comments'] = array(); |
---|
79 | |
---|
80 | // retrieving element informations |
---|
81 | $elements = array(); |
---|
82 | $query = ' |
---|
83 | SELECT id, name, file, path, tn_ext |
---|
84 | FROM '.IMAGES_TABLE.' |
---|
85 | WHERE id IN ('.implode(',', $element_ids).') |
---|
86 | ;'; |
---|
87 | $result = pwg_query($query); |
---|
88 | while ($row = mysql_fetch_assoc($result)) |
---|
89 | { |
---|
90 | $elements[$row['id']] = $row; |
---|
91 | } |
---|
92 | |
---|
93 | // retrieving category informations |
---|
94 | $query = ' |
---|
95 | SELECT id, name, permalink, uppercats |
---|
96 | FROM '.CATEGORIES_TABLE.' |
---|
97 | WHERE id IN ('.implode(',', $category_ids).') |
---|
98 | ;'; |
---|
99 | $categories = hash_from_query($query, 'id'); |
---|
100 | |
---|
101 | foreach ($comments as $comment) |
---|
102 | { |
---|
103 | if (!empty($elements[$comment['image_id']]['name'])) |
---|
104 | { |
---|
105 | $name=$elements[$comment['image_id']]['name']; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | $name=get_name_from_file($elements[$comment['image_id']]['file']); |
---|
110 | } |
---|
111 | |
---|
112 | // source of the thumbnail picture |
---|
113 | $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] ); |
---|
114 | |
---|
115 | // link to the full size picture |
---|
116 | $url = make_picture_url( |
---|
117 | array( |
---|
118 | 'category' => $categories[ $comment['category_id'] ], |
---|
119 | 'image_id' => $comment['image_id'], |
---|
120 | 'image_file' => $elements[$comment['image_id']]['file'], |
---|
121 | ) |
---|
122 | ); |
---|
123 | |
---|
124 | $author = $comment['author']; |
---|
125 | if (empty($comment['author'])) |
---|
126 | { |
---|
127 | $author = l10n('guest'); |
---|
128 | } |
---|
129 | |
---|
130 | $tpl_comment = |
---|
131 | array( |
---|
132 | 'U_PICTURE' => $url, |
---|
133 | 'TN_SRC' => $thumbnail_src, |
---|
134 | 'ALT' => $name, |
---|
135 | 'AUTHOR' => trigger_event('render_comment_author', $author), |
---|
136 | 'DATE' => format_date($comment['date'],'mysql_datetime',true), |
---|
137 | 'CONTENT' => trigger_event('render_comment_content',$comment['content']), |
---|
138 | 'WIDTH' => $datas[3], |
---|
139 | 'HEIGHT' => $datas[4], |
---|
140 | ); |
---|
141 | |
---|
142 | switch ($datas[2]) |
---|
143 | { |
---|
144 | case 1 : |
---|
145 | $tpl_comment['CLASS'] = 'one_comment'; |
---|
146 | break; |
---|
147 | case 2 : |
---|
148 | $tpl_comment['CLASS'] = 'two_comment'; |
---|
149 | break; |
---|
150 | case 3 : |
---|
151 | $tpl_comment['CLASS'] = 'three_comment'; |
---|
152 | break; |
---|
153 | } |
---|
154 | |
---|
155 | if ( is_admin() ) |
---|
156 | { |
---|
157 | $url = get_root_url().'index.php'.get_query_string_diff(array('delete','validate')); |
---|
158 | $tpl_comment['U_DELETE'] = add_url_params($url, array( |
---|
159 | 'delete' => $comment['comment_id'], |
---|
160 | 'pwg_token' => get_pwg_token())); |
---|
161 | |
---|
162 | if ($comment['validated'] != 'true') |
---|
163 | { |
---|
164 | $tpl_comment['U_VALIDATE'] = add_url_params($url, array( |
---|
165 | 'validate' => $comment['comment_id'], |
---|
166 | 'pwg_token' => get_pwg_token())); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | // Show comment editor link |
---|
171 | if (defined('CE_PATH') and ((!is_a_guest() and ($user[$conf['user_fields']['username']] == $author)) or is_admin())) |
---|
172 | { |
---|
173 | load_language('plugin.lang', CE_PATH); |
---|
174 | $tpl_comment['U_EDIT'] = add_url_params(get_root_url() . 'index.php', array( |
---|
175 | CE_ACTION => CE_ACTION_EDIT, |
---|
176 | CE_ID => $comment['comment_id'], |
---|
177 | 'pwg_token' => get_pwg_token())); |
---|
178 | } |
---|
179 | array_push($block['comments'], $tpl_comment); |
---|
180 | } |
---|
181 | $block['TEMPLATE'] = 'stuffs_lastcoms.tpl'; |
---|
182 | } |
---|
183 | |
---|
184 | ?> |
---|