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