6 |
kaklik |
1 |
<?php
|
|
|
2 |
// +-----------------------------------------------------------------------+
|
|
|
3 |
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
4 |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
|
|
5 |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
|
|
|
6 |
// +-----------------------------------------------------------------------+
|
|
|
7 |
// | branch : BSF (Best So Far)
|
|
|
8 |
// | file : $RCSfile: update.php,v $
|
|
|
9 |
// | last update : $Date: 2005/04/20 19:09:50 $
|
|
|
10 |
// | last modifier : $Author: plg $
|
|
|
11 |
// | revision : $Revision: 1.47.2.1 $
|
|
|
12 |
// +-----------------------------------------------------------------------+
|
|
|
13 |
// | This program is free software; you can redistribute it and/or modify |
|
|
|
14 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
15 |
// | the Free Software Foundation |
|
|
|
16 |
// | |
|
|
|
17 |
// | This program is distributed in the hope that it will be useful, but |
|
|
|
18 |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
19 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
20 |
// | General Public License for more details. |
|
|
|
21 |
// | |
|
|
|
22 |
// | You should have received a copy of the GNU General Public License |
|
|
|
23 |
// | along with this program; if not, write to the Free Software |
|
|
|
24 |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
25 |
// | USA. |
|
|
|
26 |
// +-----------------------------------------------------------------------+
|
|
|
27 |
|
|
|
28 |
if (!defined('PHPWG_ROOT_PATH'))
|
|
|
29 |
{
|
|
|
30 |
die ('Hacking attempt!');
|
|
|
31 |
}
|
|
|
32 |
include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
|
|
|
33 |
|
|
|
34 |
define('CURRENT_DATE', date('Y-m-d'));
|
|
|
35 |
$error_labels = array('PWG-UPDATE-1' => $lang['update_wrong_dirname_short'],
|
|
|
36 |
'PWG-UPDATE-2' => $lang['update_missing_tn_short']);
|
|
|
37 |
$errors = array();
|
|
|
38 |
$infos = array();
|
|
|
39 |
// +-----------------------------------------------------------------------+
|
|
|
40 |
// | directories / categories |
|
|
|
41 |
// +-----------------------------------------------------------------------+
|
|
|
42 |
if (isset($_POST['submit'])
|
|
|
43 |
and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
|
|
|
44 |
{
|
|
|
45 |
$counts['new_categories'] = 0;
|
|
|
46 |
$counts['del_categories'] = 0;
|
|
|
47 |
$counts['del_elements'] = 0;
|
|
|
48 |
$counts['new_elements'] = 0;
|
|
|
49 |
|
|
|
50 |
// shall we simulate only
|
|
|
51 |
if (isset($_POST['simulate']) and $_POST['simulate'] == 1)
|
|
|
52 |
{
|
|
|
53 |
$simulate = true;
|
|
|
54 |
}
|
|
|
55 |
else
|
|
|
56 |
{
|
|
|
57 |
$simulate = false;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
$start = get_moment();
|
|
|
61 |
// which categories to update ?
|
|
|
62 |
$cat_ids = array();
|
|
|
63 |
|
|
|
64 |
$query = '
|
|
|
65 |
SELECT id, uppercats, global_rank, status, visible
|
|
|
66 |
FROM '.CATEGORIES_TABLE.'
|
|
|
67 |
WHERE dir IS NOT NULL
|
|
|
68 |
AND site_id = 1';
|
|
|
69 |
if (isset($_POST['cat']) and is_numeric($_POST['cat']))
|
|
|
70 |
{
|
|
|
71 |
if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
|
|
|
72 |
{
|
|
|
73 |
$query.= '
|
|
|
74 |
AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\'
|
|
|
75 |
';
|
|
|
76 |
}
|
|
|
77 |
else
|
|
|
78 |
{
|
|
|
79 |
$query.= '
|
|
|
80 |
AND id = '.$_POST['cat'].'
|
|
|
81 |
';
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
$query.= '
|
|
|
85 |
;';
|
|
|
86 |
$result = pwg_query($query);
|
|
|
87 |
|
|
|
88 |
$db_categories = array();
|
|
|
89 |
while ($row = mysql_fetch_array($result))
|
|
|
90 |
{
|
|
|
91 |
$db_categories[$row['id']] = $row;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
// get categort full directories in an array for comparison with file
|
|
|
95 |
// system directory tree
|
|
|
96 |
$db_fulldirs = get_fulldirs(array_keys($db_categories));
|
|
|
97 |
|
|
|
98 |
// what is the base directory to search file system sub-directories ?
|
|
|
99 |
if (isset($_POST['cat']) and is_numeric($_POST['cat']))
|
|
|
100 |
{
|
|
|
101 |
$basedir = $db_fulldirs[$_POST['cat']];
|
|
|
102 |
}
|
|
|
103 |
else
|
|
|
104 |
{
|
|
|
105 |
$query = '
|
|
|
106 |
SELECT galleries_url
|
|
|
107 |
FROM '.SITES_TABLE.'
|
|
|
108 |
WHERE id = 1
|
|
|
109 |
;';
|
|
|
110 |
list($galleries_url) = mysql_fetch_array(pwg_query($query));
|
|
|
111 |
$basedir = preg_replace('#/*$#', '', $galleries_url);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
// we need to have fulldirs as keys to make efficient comparison
|
|
|
115 |
$db_fulldirs = array_flip($db_fulldirs);
|
|
|
116 |
|
|
|
117 |
// finding next rank for each id_uppercat
|
|
|
118 |
$next_rank['NULL'] = 1;
|
|
|
119 |
|
|
|
120 |
$query = '
|
|
|
121 |
SELECT id_uppercat, MAX(rank)+1 AS next_rank
|
|
|
122 |
FROM '.CATEGORIES_TABLE.'
|
|
|
123 |
GROUP BY id_uppercat
|
|
|
124 |
;';
|
|
|
125 |
$result = pwg_query($query);
|
|
|
126 |
while ($row = mysql_fetch_array($result))
|
|
|
127 |
{
|
|
|
128 |
// for the id_uppercat NULL, we write 'NULL' and not the empty string
|
|
|
129 |
if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
|
|
|
130 |
{
|
|
|
131 |
$row['id_uppercat'] = 'NULL';
|
|
|
132 |
}
|
|
|
133 |
$next_rank[$row['id_uppercat']] = $row['next_rank'];
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
// next category id available
|
|
|
137 |
$query = '
|
|
|
138 |
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
|
|
|
139 |
FROM '.CATEGORIES_TABLE.'
|
|
|
140 |
;';
|
|
|
141 |
list($next_id) = mysql_fetch_array(pwg_query($query));
|
|
|
142 |
|
|
|
143 |
// retrieve file system sub-directories fulldirs
|
|
|
144 |
$fs_fulldirs = get_fs_directories($basedir);
|
|
|
145 |
// get_fs_directories doesn't include the base directory, so if it's a
|
|
|
146 |
// category directory, we need to include it in our array
|
|
|
147 |
if (isset($_POST['cat']))
|
|
|
148 |
{
|
|
|
149 |
array_push($fs_fulldirs, $basedir);
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
$inserts = array();
|
|
|
153 |
// new categories are the directories not present yet in the database
|
|
|
154 |
foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
|
|
|
155 |
{
|
|
|
156 |
$dir = basename($fulldir);
|
|
|
157 |
if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
|
|
|
158 |
{
|
|
|
159 |
$insert = array();
|
|
|
160 |
|
|
|
161 |
$insert{'id'} = $next_id++;
|
|
|
162 |
$insert{'dir'} = $dir;
|
|
|
163 |
$insert{'name'} = str_replace('_', ' ', $dir);
|
|
|
164 |
$insert{'site_id'} = 1;
|
|
|
165 |
$insert{'commentable'} = $conf['newcat_default_commentable'];
|
|
|
166 |
$insert{'uploadable'} = $conf['newcat_default_uploadable'];
|
|
|
167 |
$insert{'status'} = $conf{'newcat_default_status'};
|
|
|
168 |
$insert{'visible'} = $conf{'newcat_default_visible'};
|
|
|
169 |
|
|
|
170 |
if (isset($db_fulldirs[dirname($fulldir)]))
|
|
|
171 |
{
|
|
|
172 |
$parent = $db_fulldirs[dirname($fulldir)];
|
|
|
173 |
|
|
|
174 |
$insert{'id_uppercat'} = $parent;
|
|
|
175 |
$insert{'uppercats'} =
|
|
|
176 |
$db_categories[$parent]['uppercats'].','.$insert{'id'};
|
|
|
177 |
$insert{'rank'} = $next_rank[$parent]++;
|
|
|
178 |
$insert{'global_rank'} =
|
|
|
179 |
$db_categories[$parent]['global_rank'].'.'.$insert{'rank'};
|
|
|
180 |
if ('private' == $db_categories[$parent]['status'])
|
|
|
181 |
{
|
|
|
182 |
$insert{'status'} = 'private';
|
|
|
183 |
}
|
|
|
184 |
if ('false' == $db_categories[$parent]['visible'])
|
|
|
185 |
{
|
|
|
186 |
$insert{'visible'} = 'false';
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
else
|
|
|
190 |
{
|
|
|
191 |
$insert{'uppercats'} = $insert{'id'};
|
|
|
192 |
$insert{'rank'} = $next_rank['NULL']++;
|
|
|
193 |
$insert{'global_rank'} = $insert{'rank'};
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
array_push($inserts, $insert);
|
|
|
197 |
array_push($infos, array('path' => $fulldir,
|
|
|
198 |
'info' => $lang['update_research_added']));
|
|
|
199 |
|
|
|
200 |
// add the new category to $db_categories and $db_fulldirs array
|
|
|
201 |
$db_categories[$insert{'id'}] =
|
|
|
202 |
array(
|
|
|
203 |
'id' => $insert{'id'},
|
|
|
204 |
'status' => $insert{'status'},
|
|
|
205 |
'visible' => $insert{'visible'},
|
|
|
206 |
'uppercats' => $insert{'uppercats'},
|
|
|
207 |
'global_rank' => $insert{'global_rank'}
|
|
|
208 |
);
|
|
|
209 |
$db_fulldirs[$fulldir] = $insert{'id'};
|
|
|
210 |
$next_rank[$insert{'id'}] = 1;
|
|
|
211 |
}
|
|
|
212 |
else
|
|
|
213 |
{
|
|
|
214 |
array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1'));
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
if (count($inserts) > 0)
|
|
|
219 |
{
|
|
|
220 |
if (!$simulate)
|
|
|
221 |
{
|
|
|
222 |
$dbfields = array(
|
|
|
223 |
'id','dir','name','site_id','id_uppercat','uppercats','commentable',
|
|
|
224 |
'uploadable','visible','status','rank','global_rank'
|
|
|
225 |
);
|
|
|
226 |
mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
$counts['new_categories'] = count($inserts);
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
// to delete categories
|
|
|
233 |
$to_delete = array();
|
|
|
234 |
foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
|
|
|
235 |
{
|
|
|
236 |
array_push($to_delete, $db_fulldirs[$fulldir]);
|
|
|
237 |
unset($db_fulldirs[$fulldir]);
|
|
|
238 |
array_push($infos, array('path' => $fulldir,
|
|
|
239 |
'info' => $lang['update_research_deleted']));
|
|
|
240 |
}
|
|
|
241 |
if (count($to_delete) > 0)
|
|
|
242 |
{
|
|
|
243 |
if (!$simulate)
|
|
|
244 |
{
|
|
|
245 |
delete_categories($to_delete);
|
|
|
246 |
}
|
|
|
247 |
$counts['del_categories'] = count($to_delete);
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
echo '<!-- scanning dirs : ';
|
|
|
251 |
echo get_elapsed_time($start, get_moment());
|
|
|
252 |
echo ' -->'."\n";
|
|
|
253 |
}
|
|
|
254 |
// +-----------------------------------------------------------------------+
|
|
|
255 |
// | files / elements |
|
|
|
256 |
// +-----------------------------------------------------------------------+
|
|
|
257 |
if (isset($_POST['submit']) and $_POST['sync'] == 'files')
|
|
|
258 |
{
|
|
|
259 |
$start_files = get_moment();
|
|
|
260 |
$start= $start_files;
|
|
|
261 |
|
|
|
262 |
$fs = get_fs($basedir);
|
|
|
263 |
|
|
|
264 |
echo '<!-- get_fs : '.get_elapsed_time($start, get_moment()).' -->'."\n";
|
|
|
265 |
|
|
|
266 |
$cat_ids = array_diff(array_keys($db_categories), $to_delete);
|
|
|
267 |
|
|
|
268 |
$db_elements = array();
|
|
|
269 |
$db_unvalidated = array();
|
|
|
270 |
|
|
|
271 |
if (count($cat_ids) > 0)
|
|
|
272 |
{
|
|
|
273 |
$query = '
|
|
|
274 |
SELECT id, path
|
|
|
275 |
FROM '.IMAGES_TABLE.'
|
|
|
276 |
WHERE storage_category_id IN (
|
|
|
277 |
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
|
|
|
278 |
;';
|
|
|
279 |
$result = pwg_query($query);
|
|
|
280 |
while ($row = mysql_fetch_array($result))
|
|
|
281 |
{
|
|
|
282 |
$db_elements[$row['id']] = $row['path'];
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
// searching the unvalidated waiting elements (they must not be taken into
|
|
|
286 |
// account)
|
|
|
287 |
$query = '
|
|
|
288 |
SELECT file,storage_category_id
|
|
|
289 |
FROM '.WAITING_TABLE.'
|
|
|
290 |
WHERE storage_category_id IN (
|
|
|
291 |
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
|
|
|
292 |
AND validated = \'false\'
|
|
|
293 |
;';
|
|
|
294 |
$result = pwg_query($query);
|
|
|
295 |
while ($row = mysql_fetch_array($result))
|
|
|
296 |
{
|
|
|
297 |
array_push(
|
|
|
298 |
$db_unvalidated,
|
|
|
299 |
array_search($row['storage_category_id'],
|
|
|
300 |
$db_fulldirs).'/'.$row['file']
|
|
|
301 |
);
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
// next element id available
|
|
|
306 |
$query = '
|
|
|
307 |
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
|
|
|
308 |
FROM '.IMAGES_TABLE.'
|
|
|
309 |
;';
|
|
|
310 |
list($next_element_id) = mysql_fetch_array(pwg_query($query));
|
|
|
311 |
|
|
|
312 |
$start = get_moment();
|
|
|
313 |
|
|
|
314 |
// because isset is one hundred time faster than in_array
|
|
|
315 |
$fs['thumbnails'] = array_flip($fs['thumbnails']);
|
|
|
316 |
$fs['representatives'] = array_flip($fs['representatives']);
|
|
|
317 |
|
|
|
318 |
$inserts = array();
|
|
|
319 |
$insert_links = array();
|
|
|
320 |
|
|
|
321 |
foreach (array_diff($fs['elements'], $db_elements, $db_unvalidated) as $path)
|
|
|
322 |
{
|
|
|
323 |
$insert = array();
|
|
|
324 |
// storage category must exist
|
|
|
325 |
$dirname = dirname($path);
|
|
|
326 |
if (!isset($db_fulldirs[$dirname]))
|
|
|
327 |
{
|
|
|
328 |
continue;
|
|
|
329 |
}
|
|
|
330 |
$filename = basename($path);
|
|
|
331 |
if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
|
|
|
332 |
{
|
|
|
333 |
array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1'));
|
|
|
334 |
continue;
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
// searching the thumbnail
|
|
|
338 |
$filename_wo_ext = get_filename_wo_extension($filename);
|
|
|
339 |
$tn_ext = '';
|
|
|
340 |
$base_test = $dirname.'/thumbnail/';
|
|
|
341 |
$base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
|
|
|
342 |
foreach ($conf['picture_ext'] as $ext)
|
|
|
343 |
{
|
|
|
344 |
$test = $base_test.$ext;
|
|
|
345 |
if (isset($fs['thumbnails'][$test]))
|
|
|
346 |
{
|
|
|
347 |
$tn_ext = $ext;
|
|
|
348 |
break;
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
// 2 cases : the element is a picture or not. Indeed, for a picture
|
|
|
353 |
// thumbnail is mandatory and for non picture element, thumbnail and
|
|
|
354 |
// representative are optionnal
|
|
|
355 |
if (in_array(get_extension($filename), $conf['picture_ext']))
|
|
|
356 |
{
|
|
|
357 |
// if we found a thumnbnail corresponding to our picture...
|
|
|
358 |
if ($tn_ext != '')
|
|
|
359 |
{
|
|
|
360 |
$insert{'id'} = $next_element_id++;
|
|
|
361 |
$insert{'file'} = $filename;
|
|
|
362 |
$insert{'storage_category_id'} = $db_fulldirs[$dirname];
|
|
|
363 |
$insert{'date_available'} = CURRENT_DATE;
|
|
|
364 |
$insert{'tn_ext'} = $tn_ext;
|
|
|
365 |
$insert{'path'} = $path;
|
|
|
366 |
|
|
|
367 |
array_push($inserts, $insert);
|
|
|
368 |
array_push($insert_links,
|
|
|
369 |
array('image_id' => $insert{'id'},
|
|
|
370 |
'category_id' => $insert{'storage_category_id'}));
|
|
|
371 |
array_push($infos, array('path' => $insert{'path'},
|
|
|
372 |
'info' => $lang['update_research_added']));
|
|
|
373 |
}
|
|
|
374 |
else
|
|
|
375 |
{
|
|
|
376 |
array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2'));
|
|
|
377 |
}
|
|
|
378 |
}
|
|
|
379 |
else
|
|
|
380 |
{
|
|
|
381 |
// searching a representative
|
|
|
382 |
$representative_ext = '';
|
|
|
383 |
$base_test = $dirname.'/pwg_representative/'.$filename_wo_ext.'.';
|
|
|
384 |
foreach ($conf['picture_ext'] as $ext)
|
|
|
385 |
{
|
|
|
386 |
$test = $base_test.$ext;
|
|
|
387 |
if (isset($fs['representatives'][$test]))
|
|
|
388 |
{
|
|
|
389 |
$representative_ext = $ext;
|
|
|
390 |
break;
|
|
|
391 |
}
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
$insert{'id'} = $next_element_id++;
|
|
|
395 |
$insert{'file'} = $filename;
|
|
|
396 |
$insert{'storage_category_id'} = $db_fulldirs[$dirname];
|
|
|
397 |
$insert{'date_available'} = CURRENT_DATE;
|
|
|
398 |
$insert{'path'} = $path;
|
|
|
399 |
|
|
|
400 |
if ($tn_ext != '')
|
|
|
401 |
{
|
|
|
402 |
$insert{'tn_ext'} = $tn_ext;
|
|
|
403 |
}
|
|
|
404 |
if ($representative_ext != '')
|
|
|
405 |
{
|
|
|
406 |
$insert{'representative_ext'} = $representative_ext;
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
array_push($inserts, $insert);
|
|
|
410 |
array_push($insert_links,
|
|
|
411 |
array('image_id' => $insert{'id'},
|
|
|
412 |
'category_id' => $insert{'storage_category_id'}));
|
|
|
413 |
array_push($infos, array('path' => $insert{'path'},
|
|
|
414 |
'info' => $lang['update_research_added']));
|
|
|
415 |
}
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
if (count($inserts) > 0)
|
|
|
419 |
{
|
|
|
420 |
if (!$simulate)
|
|
|
421 |
{
|
|
|
422 |
// inserts all new elements
|
|
|
423 |
$dbfields = array(
|
|
|
424 |
'id','file','storage_category_id','date_available','tn_ext'
|
|
|
425 |
,'representative_ext','path'
|
|
|
426 |
);
|
|
|
427 |
mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
|
|
|
428 |
|
|
|
429 |
// insert all links between new elements and their storage category
|
|
|
430 |
$dbfields = array('image_id','category_id');
|
|
|
431 |
mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links);
|
|
|
432 |
}
|
|
|
433 |
$counts['new_elements'] = count($inserts);
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
// delete elements that are in database but not in the filesystem
|
|
|
437 |
$to_delete_elements = array();
|
|
|
438 |
foreach (array_diff($db_elements, $fs['elements']) as $path)
|
|
|
439 |
{
|
|
|
440 |
array_push($to_delete_elements, array_search($path, $db_elements));
|
|
|
441 |
array_push($infos, array('path' => $path,
|
|
|
442 |
'info' => $lang['update_research_deleted']));
|
|
|
443 |
}
|
|
|
444 |
if (count($to_delete_elements) > 0)
|
|
|
445 |
{
|
|
|
446 |
if (!$simulate)
|
|
|
447 |
{
|
|
|
448 |
delete_elements($to_delete_elements);
|
|
|
449 |
}
|
|
|
450 |
$counts['del_elements'] = count($to_delete_elements);
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
echo '<!-- scanning files : ';
|
|
|
454 |
echo get_elapsed_time($start_files, get_moment());
|
|
|
455 |
echo ' -->'."\n";
|
|
|
456 |
|
|
|
457 |
// retrieving informations given by uploaders
|
|
|
458 |
if (!$simulate)
|
|
|
459 |
{
|
|
|
460 |
$query = '
|
|
|
461 |
SELECT id,file,storage_category_id,infos
|
|
|
462 |
FROM '.WAITING_TABLE.'
|
|
|
463 |
WHERE storage_category_id IN (
|
|
|
464 |
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
|
|
|
465 |
AND validated = \'true\'
|
|
|
466 |
;';
|
|
|
467 |
$result = pwg_query($query);
|
|
|
468 |
|
|
|
469 |
$datas = array();
|
|
|
470 |
$fields =
|
|
|
471 |
array(
|
|
|
472 |
'primary' => array('id'),
|
|
|
473 |
'update' => array('date_creation', 'author', 'name', 'comment')
|
|
|
474 |
);
|
|
|
475 |
|
|
|
476 |
$waiting_to_delete = array();
|
|
|
477 |
|
|
|
478 |
while ($row = mysql_fetch_array($result))
|
|
|
479 |
{
|
|
|
480 |
$data = array();
|
|
|
481 |
|
|
|
482 |
$query = '
|
|
|
483 |
SELECT id
|
|
|
484 |
FROM '.IMAGES_TABLE.'
|
|
|
485 |
WHERE storage_category_id = \''.$row['storage_category_id'].'\'
|
|
|
486 |
AND file = \''.$row['file'].'\'
|
|
|
487 |
;';
|
|
|
488 |
list($data['id']) = mysql_fetch_array(pwg_query($query));
|
|
|
489 |
|
|
|
490 |
foreach ($fields['update'] as $field)
|
|
|
491 |
{
|
|
|
492 |
$data[$field] = getAttribute($row['infos'], $field);
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
array_push($datas, $data);
|
|
|
496 |
array_push($waiting_to_delete, $row['id']);
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
if (count($datas) > 0)
|
|
|
500 |
{
|
|
|
501 |
mass_updates(IMAGES_TABLE, $fields, $datas);
|
|
|
502 |
|
|
|
503 |
// delete now useless waiting elements
|
|
|
504 |
$query = '
|
|
|
505 |
DELETE
|
|
|
506 |
FROM '.WAITING_TABLE.'
|
|
|
507 |
WHERE id IN ('.implode(',', $waiting_to_delete).')
|
|
|
508 |
;';
|
|
|
509 |
pwg_query($query);
|
|
|
510 |
}
|
|
|
511 |
}
|
|
|
512 |
}
|
|
|
513 |
// +-----------------------------------------------------------------------+
|
|
|
514 |
// | template initialization |
|
|
|
515 |
// +-----------------------------------------------------------------------+
|
|
|
516 |
$template->set_filenames(array('update'=>'admin/update.tpl'));
|
|
|
517 |
|
|
|
518 |
$result_title = '';
|
|
|
519 |
if (isset($simulate) and $simulate)
|
|
|
520 |
{
|
|
|
521 |
$result_title.= $lang['update_simulation_title'].' ';
|
|
|
522 |
}
|
|
|
523 |
$result_title.= $lang['update_part_research'];
|
|
|
524 |
|
|
|
525 |
// used_metadata string is displayed to inform admin which metadata will be
|
|
|
526 |
// used from files for synchronization
|
|
|
527 |
$used_metadata = $lang['metadata_basic'].' (filesize, width, height)';
|
|
|
528 |
|
|
|
529 |
if ($conf['use_exif'])
|
|
|
530 |
{
|
|
|
531 |
$used_metadata.= ', '.$lang['metadata_exif'].' (date_creation)';
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
if ($conf['use_iptc'])
|
|
|
535 |
{
|
|
|
536 |
$used_metadata.= ', '.$lang['metadata_iptc'];
|
|
|
537 |
$used_metadata.= '(';
|
|
|
538 |
$used_metadata.= implode(', ', array_keys($conf['use_iptc_mapping']));
|
|
|
539 |
$used_metadata.= ')';
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
$template->assign_vars(
|
|
|
543 |
array(
|
|
|
544 |
'L_SUBMIT'=>$lang['submit'],
|
|
|
545 |
'L_RESET'=>$lang['reset'],
|
|
|
546 |
'L_UPDATE_TITLE'=>$lang['update_default_title'],
|
|
|
547 |
'L_UPDATE_SYNC_FILES'=>$lang['update_sync_files'],
|
|
|
548 |
'L_UPDATE_SYNC_DIRS'=>$lang['update_sync_dirs'],
|
|
|
549 |
'L_UPDATE_SYNC_ALL'=>$lang['update_sync_all'],
|
|
|
550 |
'L_UPDATE_SYNC_METADATA'=>$lang['update_sync_metadata'],
|
|
|
551 |
'L_UPDATE_SYNC_METADATA_NEW'=>$lang['update_sync_metadata_new'],
|
|
|
552 |
'L_UPDATE_SYNC_METADATA_ALL'=>$lang['update_sync_metadata_all'],
|
|
|
553 |
'L_UPDATE_CATS_SUBSET'=>$lang['update_cats_subset'],
|
|
|
554 |
'L_RESULT_UPDATE'=>$result_title,
|
|
|
555 |
'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'],
|
|
|
556 |
'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'],
|
|
|
557 |
'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'],
|
|
|
558 |
'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'],
|
|
|
559 |
'L_UPDATE_NB_ERRORS'=>$lang['update_nb_errors'],
|
|
|
560 |
'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'],
|
|
|
561 |
'L_UPDATE_WRONG_DIRNAME_INFO'=>$lang['update_wrong_dirname_info'],
|
|
|
562 |
'L_UPDATE_MISSING_TN_INFO'=>$lang['update_missing_tn_info'],
|
|
|
563 |
'PICTURE_EXT_LIST'=>implode(',', $conf['picture_ext']),
|
|
|
564 |
'L_UPDATE_ERROR_LIST_TITLE'=>$lang['update_error_list_title'],
|
|
|
565 |
'L_UPDATE_ERRORS_CAPTION'=>$lang['update_errors_caption'],
|
|
|
566 |
'L_UPDATE_DISPLAY_INFO'=>$lang['update_display_info'],
|
|
|
567 |
'L_UPDATE_SIMULATE'=>$lang['update_simulate'],
|
|
|
568 |
'L_UPDATE_INFOS_TITLE'=>$lang['update_infos_title'],
|
|
|
569 |
'L_RESULT_METADATA'=>$lang['update_result_metadata'],
|
|
|
570 |
'L_ELEMENTS_METADATA_SYNC'=>$lang['update_elements_metadata_sync'],
|
|
|
571 |
'L_USED_METADATA'=>$lang['update_used_metadata'],
|
|
|
572 |
'METADATA_LIST' => $used_metadata
|
|
|
573 |
));
|
|
|
574 |
// +-----------------------------------------------------------------------+
|
|
|
575 |
// | introduction : choices |
|
|
|
576 |
// +-----------------------------------------------------------------------+
|
|
|
577 |
if (!isset($_POST['submit']) or (isset($simulate) and $simulate))
|
|
|
578 |
{
|
|
|
579 |
$template->assign_block_vars('introduction', array());
|
|
|
580 |
|
|
|
581 |
if (isset($simulate) and $simulate)
|
|
|
582 |
{
|
|
|
583 |
switch ($_POST['sync'])
|
|
|
584 |
{
|
|
|
585 |
case 'dirs' :
|
|
|
586 |
{
|
|
|
587 |
$template->assign_vars(
|
|
|
588 |
array('SYNC_DIRS_CHECKED'=>'checked="checked"'));
|
|
|
589 |
break;
|
|
|
590 |
}
|
|
|
591 |
case 'files' :
|
|
|
592 |
{
|
|
|
593 |
$template->assign_vars(
|
|
|
594 |
array('SYNC_ALL_CHECKED'=>'checked="checked"'));
|
|
|
595 |
break;
|
|
|
596 |
}
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
if (isset($_POST['display_info']) and $_POST['display_info'] == 1)
|
|
|
600 |
{
|
|
|
601 |
$template->assign_vars(
|
|
|
602 |
array('DISPLAY_INFO_CHECKED'=>'checked="checked"'));
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
|
|
|
606 |
{
|
|
|
607 |
$template->assign_vars(
|
|
|
608 |
array('SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
if (isset($_POST['cat']) and is_numeric($_POST['cat']))
|
|
|
612 |
{
|
|
|
613 |
$cat_selected = array($_POST['cat']);
|
|
|
614 |
}
|
|
|
615 |
else
|
|
|
616 |
{
|
|
|
617 |
$cat_selected = array();
|
|
|
618 |
}
|
|
|
619 |
}
|
|
|
620 |
else
|
|
|
621 |
{
|
|
|
622 |
$template->assign_vars(
|
|
|
623 |
array('SYNC_DIRS_CHECKED' => 'checked="checked"',
|
|
|
624 |
'SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
|
|
|
625 |
|
|
|
626 |
$cat_selected = array();
|
|
|
627 |
}
|
|
|
628 |
|
|
|
629 |
$query = '
|
|
|
630 |
SELECT id,name,uppercats,global_rank
|
|
|
631 |
FROM '.CATEGORIES_TABLE.'
|
|
|
632 |
WHERE site_id = 1
|
|
|
633 |
;';
|
|
|
634 |
display_select_cat_wrapper($query,
|
|
|
635 |
$cat_selected,
|
|
|
636 |
'introduction.category_option',
|
|
|
637 |
false);
|
|
|
638 |
}
|
|
|
639 |
// +-----------------------------------------------------------------------+
|
|
|
640 |
// | synchronize files |
|
|
|
641 |
// +-----------------------------------------------------------------------+
|
|
|
642 |
if (isset($_POST['submit'])
|
|
|
643 |
and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
|
|
|
644 |
{
|
|
|
645 |
$template->assign_block_vars(
|
|
|
646 |
'update',
|
|
|
647 |
array(
|
|
|
648 |
'NB_NEW_CATEGORIES'=>$counts['new_categories'],
|
|
|
649 |
'NB_DEL_CATEGORIES'=>$counts['del_categories'],
|
|
|
650 |
'NB_NEW_ELEMENTS'=>$counts['new_elements'],
|
|
|
651 |
'NB_DEL_ELEMENTS'=>$counts['del_elements'],
|
|
|
652 |
'NB_ERRORS'=>count($errors),
|
|
|
653 |
));
|
|
|
654 |
|
|
|
655 |
if (count($errors) > 0)
|
|
|
656 |
{
|
|
|
657 |
$template->assign_block_vars('update.errors', array());
|
|
|
658 |
foreach ($errors as $error)
|
|
|
659 |
{
|
|
|
660 |
$template->assign_block_vars(
|
|
|
661 |
'update.errors.error',
|
|
|
662 |
array(
|
|
|
663 |
'ELEMENT' => $error['path'],
|
|
|
664 |
'LABEL' => $error['type'].' ('.$error_labels[$error['type']].')'
|
|
|
665 |
));
|
|
|
666 |
}
|
|
|
667 |
}
|
|
|
668 |
if (count($infos) > 0
|
|
|
669 |
and isset($_POST['display_info'])
|
|
|
670 |
and $_POST['display_info'] == 1)
|
|
|
671 |
{
|
|
|
672 |
$template->assign_block_vars('update.infos', array());
|
|
|
673 |
foreach ($infos as $info)
|
|
|
674 |
{
|
|
|
675 |
$template->assign_block_vars(
|
|
|
676 |
'update.infos.info',
|
|
|
677 |
array(
|
|
|
678 |
'ELEMENT' => $info['path'],
|
|
|
679 |
'LABEL' => $info['info']
|
|
|
680 |
));
|
|
|
681 |
}
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
if (!$simulate)
|
|
|
685 |
{
|
|
|
686 |
$start = get_moment();
|
|
|
687 |
update_category('all');
|
|
|
688 |
echo '<!-- update_category(all) : ';
|
|
|
689 |
echo get_elapsed_time($start,get_moment());
|
|
|
690 |
echo ' -->'."\n";
|
|
|
691 |
$start = get_moment();
|
|
|
692 |
ordering();
|
|
|
693 |
update_global_rank();
|
|
|
694 |
echo '<!-- ordering categories : ';
|
|
|
695 |
echo get_elapsed_time($start, get_moment());
|
|
|
696 |
echo ' -->'."\n";
|
|
|
697 |
}
|
|
|
698 |
}
|
|
|
699 |
// +-----------------------------------------------------------------------+
|
|
|
700 |
// | synchronize metadata |
|
|
|
701 |
// +-----------------------------------------------------------------------+
|
|
|
702 |
else if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync']))
|
|
|
703 |
{
|
|
|
704 |
// sync only never synchronized files ?
|
|
|
705 |
if ($_POST['sync'] == 'metadata_new')
|
|
|
706 |
{
|
|
|
707 |
$opts['only_new'] = true;
|
|
|
708 |
}
|
|
|
709 |
else
|
|
|
710 |
{
|
|
|
711 |
$opts['only_new'] = false;
|
|
|
712 |
}
|
|
|
713 |
$opts['category_id'] = '';
|
|
|
714 |
$opts['recursive'] = true;
|
|
|
715 |
|
|
|
716 |
if (isset($_POST['cat']))
|
|
|
717 |
{
|
|
|
718 |
$opts['category_id'] = $_POST['cat'];
|
|
|
719 |
// recursive ?
|
|
|
720 |
if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
|
|
|
721 |
{
|
|
|
722 |
$opts['recursive'] = false;
|
|
|
723 |
}
|
|
|
724 |
}
|
|
|
725 |
$start = get_moment();
|
|
|
726 |
$files = get_filelist($opts['category_id'],
|
|
|
727 |
$opts['recursive'],
|
|
|
728 |
$opts['only_new']);
|
|
|
729 |
|
|
|
730 |
echo '<!-- get_filelist : ';
|
|
|
731 |
echo get_elapsed_time($start, get_moment());
|
|
|
732 |
echo ' -->'."\n";
|
|
|
733 |
|
|
|
734 |
$start = get_moment();
|
|
|
735 |
update_metadata($files);
|
|
|
736 |
echo '<!-- metadata update : ';
|
|
|
737 |
echo get_elapsed_time($start, get_moment());
|
|
|
738 |
echo ' -->'."\n";
|
|
|
739 |
|
|
|
740 |
$template->assign_block_vars(
|
|
|
741 |
'metadata_result',
|
|
|
742 |
array(
|
|
|
743 |
'NB_ELEMENTS' => count($files),
|
|
|
744 |
));
|
|
|
745 |
}
|
|
|
746 |
// +-----------------------------------------------------------------------+
|
|
|
747 |
// | sending html code |
|
|
|
748 |
// +-----------------------------------------------------------------------+
|
|
|
749 |
$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
|
|
|
750 |
?>
|