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