1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
25 | { |
---|
26 | die ("Hacking attempt!"); |
---|
27 | } |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
31 | load_language('plugin.lang', COMMUNITY_PATH); |
---|
32 | |
---|
33 | $admin_base_url = get_root_url().'admin.php?page=plugin-community-pendings'; |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | |
---|
39 | check_status(ACCESS_ADMINISTRATOR); |
---|
40 | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | // | actions | |
---|
43 | // +-----------------------------------------------------------------------+ |
---|
44 | |
---|
45 | if (!empty($_POST)) |
---|
46 | { |
---|
47 | if (empty($_POST['photos'])) |
---|
48 | { |
---|
49 | array_push( |
---|
50 | $page['errors'], |
---|
51 | l10n('Select at least one photo') |
---|
52 | ); |
---|
53 | } |
---|
54 | else |
---|
55 | { |
---|
56 | check_input_parameter('photos', $_POST, true, PATTERN_ID); |
---|
57 | check_input_parameter('level', $_POST, false, PATTERN_ID); |
---|
58 | |
---|
59 | if (isset($_POST['validate'])) |
---|
60 | { |
---|
61 | $query = ' |
---|
62 | UPDATE '.COMMUNITY_PENDINGS_TABLE.' |
---|
63 | SET state = \'validated\', |
---|
64 | validated_by = '.$user['id'].' |
---|
65 | WHERE image_id IN ('.implode(',', $_POST['photos']).') |
---|
66 | ;'; |
---|
67 | pwg_query($query); |
---|
68 | |
---|
69 | $query = ' |
---|
70 | UPDATE '.IMAGES_TABLE.' |
---|
71 | SET level = '.$_POST['level'].', |
---|
72 | date_available = NOW() |
---|
73 | WHERE id IN ('.implode(',', $_POST['photos']).') |
---|
74 | ;'; |
---|
75 | pwg_query($query); |
---|
76 | |
---|
77 | array_push( |
---|
78 | $page['infos'], |
---|
79 | sprintf( |
---|
80 | l10n('%d photos validated'), |
---|
81 | count($_POST['photos']) |
---|
82 | ) |
---|
83 | ); |
---|
84 | } |
---|
85 | |
---|
86 | if (isset($_POST['reject'])) |
---|
87 | { |
---|
88 | $query = ' |
---|
89 | DELETE |
---|
90 | FROM '.COMMUNITY_PENDINGS_TABLE.' |
---|
91 | WHERE image_id IN ('.implode(',', $_POST['photos']).') |
---|
92 | ;'; |
---|
93 | pwg_query($query); |
---|
94 | |
---|
95 | delete_elements($_POST['photos'], true); |
---|
96 | |
---|
97 | array_push( |
---|
98 | $page['infos'], |
---|
99 | sprintf( |
---|
100 | l10n('%d photos rejected'), |
---|
101 | count($_POST['photos']) |
---|
102 | ) |
---|
103 | ); |
---|
104 | } |
---|
105 | |
---|
106 | invalidate_user_cache(); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | // +-----------------------------------------------------------------------+ |
---|
111 | // | template init | |
---|
112 | // +-----------------------------------------------------------------------+ |
---|
113 | |
---|
114 | $template->set_filenames( |
---|
115 | array( |
---|
116 | 'plugin_admin_content' => dirname(__FILE__).'/admin_pendings.tpl' |
---|
117 | ) |
---|
118 | ); |
---|
119 | |
---|
120 | // +-----------------------------------------------------------------------+ |
---|
121 | // | pending photos list | |
---|
122 | // +-----------------------------------------------------------------------+ |
---|
123 | |
---|
124 | // just in case (because we had a bug in Community plugin up to version |
---|
125 | // 2.5.c) let's remove rows in community_pendings table if related photos |
---|
126 | // has been deleted |
---|
127 | $query = ' |
---|
128 | SELECT |
---|
129 | image_id |
---|
130 | FROM '.COMMUNITY_PENDINGS_TABLE.' |
---|
131 | LEFT JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
132 | WHERE id IS NULL |
---|
133 | ;'; |
---|
134 | $to_delete = array_from_query($query, 'image_id'); |
---|
135 | |
---|
136 | if (count($to_delete) > 0) |
---|
137 | { |
---|
138 | $query = ' |
---|
139 | DELETE |
---|
140 | FROM '.COMMUNITY_PENDINGS_TABLE.' |
---|
141 | WHERE image_id IN ('.implode(',', $to_delete).') |
---|
142 | ;'; |
---|
143 | pwg_query($query); |
---|
144 | } |
---|
145 | |
---|
146 | $list = array(); |
---|
147 | |
---|
148 | $query = ' |
---|
149 | SELECT |
---|
150 | image_id, |
---|
151 | added_on, |
---|
152 | |
---|
153 | i.id, |
---|
154 | path, |
---|
155 | date_creation, |
---|
156 | name, |
---|
157 | comment, |
---|
158 | added_by, |
---|
159 | file, |
---|
160 | name, |
---|
161 | filesize, |
---|
162 | width, |
---|
163 | height, |
---|
164 | rotation, |
---|
165 | representative_ext, |
---|
166 | |
---|
167 | '.$conf['user_fields']['username'].' AS username |
---|
168 | |
---|
169 | FROM '.COMMUNITY_PENDINGS_TABLE.' AS cp |
---|
170 | INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = cp.image_id |
---|
171 | LEFT JOIN '.USERS_TABLE.' AS u ON u.'.$conf['user_fields']['id'].' = i.added_by |
---|
172 | |
---|
173 | WHERE state = \'moderation_pending\' |
---|
174 | |
---|
175 | ORDER BY image_id DESC |
---|
176 | ;'; |
---|
177 | $result = pwg_query($query); |
---|
178 | $rows = array(); |
---|
179 | $image_ids = array(); |
---|
180 | while ($row = pwg_db_fetch_assoc($result)) |
---|
181 | { |
---|
182 | array_push($rows, $row); |
---|
183 | array_push($image_ids, $row['id']); |
---|
184 | } |
---|
185 | |
---|
186 | $category_for_image = array(); |
---|
187 | |
---|
188 | if (count($image_ids) > 0) |
---|
189 | { |
---|
190 | $query = ' |
---|
191 | SELECT |
---|
192 | id, |
---|
193 | image_id, |
---|
194 | uppercats |
---|
195 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
196 | JOIN '.CATEGORIES_TABLE.' ON id = category_id |
---|
197 | WHERE image_id IN ('.implode(',', $image_ids).') |
---|
198 | ;'; |
---|
199 | $result = pwg_query($query); |
---|
200 | |
---|
201 | while ($row = pwg_db_fetch_assoc($result)) |
---|
202 | { |
---|
203 | $category_for_image[ $row['image_id'] ] = get_cat_display_name_cache( |
---|
204 | $row['uppercats'], |
---|
205 | 'admin.php?page=album-', |
---|
206 | false, |
---|
207 | true, |
---|
208 | 'externalLink' |
---|
209 | ); |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | foreach ($rows as $row) |
---|
214 | { |
---|
215 | $src_image = new SrcImage($row); |
---|
216 | $thumb_url = DerivativeImage::url(IMG_THUMB, $src_image); |
---|
217 | $medium_url = DerivativeImage::url(IMG_MEDIUM, $src_image); |
---|
218 | |
---|
219 | // file properties |
---|
220 | $dimensions = null; |
---|
221 | $websize_props = $row['width'].'x'.$row['height'].' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['filesize']); |
---|
222 | if (!empty($row['has_high']) and get_boolean($row['has_high'])) |
---|
223 | { |
---|
224 | $high_path = get_high_path($row); |
---|
225 | list($high_width, $high_height) = getimagesize($high_path); |
---|
226 | $high_props = $high_width.'x'.$high_height.' '.l10n('pixels').', '.sprintf(l10n('%d Kb'), $row['high_filesize']); |
---|
227 | |
---|
228 | $dimensions = $high_props.' ('.l10n('web size').' '.$websize_props.')'; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | $dimensions = $websize_props; |
---|
233 | } |
---|
234 | |
---|
235 | $album = null; |
---|
236 | if (isset($category_for_image[ $row['id'] ])) |
---|
237 | { |
---|
238 | $album = $category_for_image[ $row['id'] ]; |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $album = '<em>'.l10n('No album, this photo is orphan').'</em>'; |
---|
243 | } |
---|
244 | |
---|
245 | $template->append( |
---|
246 | 'photos', |
---|
247 | array( |
---|
248 | 'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['image_id'], |
---|
249 | 'ID' => $row['image_id'], |
---|
250 | 'TN_SRC' => $thumb_url, |
---|
251 | 'MEDIUM_SRC' => $medium_url, |
---|
252 | 'ADDED_BY' => $row['username'], |
---|
253 | 'ADDED_ON' => format_date($row['added_on'], true), |
---|
254 | 'NAME' => $row['name'], |
---|
255 | 'DIMENSIONS' => $dimensions, |
---|
256 | 'FILE' => $row['file'], |
---|
257 | 'DATE_CREATION' => empty($row['date_creation']) ? l10n('N/A') : format_date($row['date_creation']), |
---|
258 | 'ALBUM' => $album, |
---|
259 | ) |
---|
260 | ); |
---|
261 | } |
---|
262 | |
---|
263 | // +-----------------------------------------------------------------------+ |
---|
264 | // | form options | |
---|
265 | // +-----------------------------------------------------------------------+ |
---|
266 | |
---|
267 | // image level options |
---|
268 | $selected_level = isset($_POST['level']) ? $_POST['level'] : 0; |
---|
269 | $template->assign( |
---|
270 | array( |
---|
271 | 'level_options'=> get_privacy_level_options(), |
---|
272 | 'level_options_selected' => array($selected_level) |
---|
273 | ) |
---|
274 | ); |
---|
275 | |
---|
276 | |
---|
277 | // +-----------------------------------------------------------------------+ |
---|
278 | // | sending html code | |
---|
279 | // +-----------------------------------------------------------------------+ |
---|
280 | |
---|
281 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
282 | ?> |
---|