[10] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-12-30 07:59:46 +0000 (Thu, 30 Dec 2004) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 666 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[10] | 27 | |
---|
[659] | 28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
[520] | 29 | { |
---|
[659] | 30 | die ('Hacking attempt!'); |
---|
[520] | 31 | } |
---|
[466] | 32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
[486] | 33 | |
---|
[606] | 34 | define('CURRENT_DATE', date('Y-m-d')); |
---|
[659] | 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(); |
---|
[589] | 39 | // +-----------------------------------------------------------------------+ |
---|
[659] | 40 | // | directories / categories | |
---|
[589] | 41 | // +-----------------------------------------------------------------------+ |
---|
[659] | 42 | if (isset($_POST['submit']) |
---|
| 43 | and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) |
---|
[10] | 44 | { |
---|
[659] | 45 | $counts['new_categories'] = 0; |
---|
| 46 | $counts['del_categories'] = 0; |
---|
| 47 | $counts['del_elements'] = 0; |
---|
| 48 | $counts['new_elements'] = 0; |
---|
[228] | 49 | |
---|
[659] | 50 | // shall we simulate only |
---|
| 51 | if (isset($_POST['simulate']) and $_POST['simulate'] == 1) |
---|
[345] | 52 | { |
---|
[659] | 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(); |
---|
[228] | 63 | |
---|
[659] | 64 | $query = ' |
---|
| 65 | SELECT id, uppercats, global_rank, status, visible |
---|
[642] | 66 | FROM '.CATEGORIES_TABLE.' |
---|
[659] | 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) |
---|
[345] | 72 | { |
---|
[659] | 73 | $query.= ' |
---|
| 74 | AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\' |
---|
| 75 | '; |
---|
[345] | 76 | } |
---|
[659] | 77 | else |
---|
[466] | 78 | { |
---|
[659] | 79 | $query.= ' |
---|
| 80 | AND id = '.$_POST['cat'].' |
---|
| 81 | '; |
---|
[345] | 82 | } |
---|
[10] | 83 | } |
---|
[466] | 84 | $query.= ' |
---|
| 85 | ;'; |
---|
[587] | 86 | $result = pwg_query($query); |
---|
[659] | 87 | |
---|
| 88 | $db_categories = array(); |
---|
[466] | 89 | while ($row = mysql_fetch_array($result)) |
---|
| 90 | { |
---|
[659] | 91 | $db_categories[$row['id']] = $row; |
---|
[10] | 92 | } |
---|
[659] | 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)); |
---|
[345] | 97 | |
---|
[659] | 98 | // what is the base directory to search file system sub-directories ? |
---|
| 99 | if (isset($_POST['cat']) and is_numeric($_POST['cat'])) |
---|
[466] | 100 | { |
---|
[659] | 101 | $basedir = $db_fulldirs[$_POST['cat']]; |
---|
[345] | 102 | } |
---|
[659] | 103 | else |
---|
[486] | 104 | { |
---|
[659] | 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); |
---|
[486] | 112 | } |
---|
[345] | 113 | |
---|
[659] | 114 | // we need to have fulldirs as keys to make efficient comparison |
---|
| 115 | $db_fulldirs = array_flip($db_fulldirs); |
---|
[642] | 116 | |
---|
[659] | 117 | // finding next rank for each id_uppercat |
---|
[660] | 118 | $next_rank['NULL'] = 1; |
---|
| 119 | |
---|
[659] | 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)) |
---|
[642] | 127 | { |
---|
[659] | 128 | // for the id_uppercat NULL, we write 'NULL' and not the empty string |
---|
| 129 | if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') |
---|
[642] | 130 | { |
---|
[659] | 131 | $row['id_uppercat'] = 'NULL'; |
---|
[642] | 132 | } |
---|
[659] | 133 | $next_rank[$row['id_uppercat']] = $row['next_rank']; |
---|
[642] | 134 | } |
---|
[345] | 135 | |
---|
[659] | 136 | // next category id available |
---|
| 137 | $query = ' |
---|
[660] | 138 | SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id |
---|
[659] | 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); |
---|
[666] | 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 | } |
---|
[659] | 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) |
---|
[466] | 155 | { |
---|
[659] | 156 | $dir = basename($fulldir); |
---|
| 157 | if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir)) |
---|
[10] | 158 | { |
---|
[642] | 159 | $insert = array(); |
---|
| 160 | |
---|
[659] | 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)])) |
---|
[10] | 171 | { |
---|
[659] | 172 | $parent = $db_fulldirs[dirname($fulldir)]; |
---|
[345] | 173 | |
---|
[659] | 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']) |
---|
[466] | 181 | { |
---|
[659] | 182 | $insert{'status'} = 'private'; |
---|
[466] | 183 | } |
---|
[659] | 184 | if ('false' == $db_categories[$parent]['visible']) |
---|
| 185 | { |
---|
| 186 | $insert{'visible'} = 'false'; |
---|
| 187 | } |
---|
[10] | 188 | } |
---|
[345] | 189 | else |
---|
| 190 | { |
---|
[659] | 191 | $insert{'uppercats'} = $insert{'id'}; |
---|
| 192 | $insert{'rank'} = $next_rank['NULL']++; |
---|
| 193 | $insert{'global_rank'} = $insert{'rank'}; |
---|
[345] | 194 | } |
---|
| 195 | |
---|
[659] | 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; |
---|
[466] | 211 | } |
---|
| 212 | else |
---|
| 213 | { |
---|
[659] | 214 | array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1')); |
---|
[466] | 215 | } |
---|
[10] | 216 | } |
---|
[345] | 217 | |
---|
[659] | 218 | if (count($inserts) > 0) |
---|
[589] | 219 | { |
---|
[659] | 220 | if (!$simulate) |
---|
[589] | 221 | { |
---|
[659] | 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); |
---|
[589] | 227 | } |
---|
[659] | 228 | |
---|
| 229 | $counts['new_categories'] = count($inserts); |
---|
[466] | 230 | } |
---|
[345] | 231 | |
---|
[659] | 232 | // to delete categories |
---|
| 233 | $to_delete = array(); |
---|
| 234 | foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir) |
---|
[345] | 235 | { |
---|
[659] | 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'])); |
---|
[10] | 240 | } |
---|
[659] | 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 get_elapsed_time($start, get_moment()); |
---|
| 251 | echo ' for new method scanning directories<br />'; |
---|
[10] | 252 | } |
---|
[659] | 253 | // +-----------------------------------------------------------------------+ |
---|
| 254 | // | files / elements | |
---|
| 255 | // +-----------------------------------------------------------------------+ |
---|
| 256 | if (isset($_POST['submit']) and $_POST['sync'] == 'files') |
---|
| 257 | { |
---|
| 258 | $start_files = get_moment(); |
---|
| 259 | $start= $start_files; |
---|
[345] | 260 | |
---|
[659] | 261 | $fs = get_fs($basedir); |
---|
| 262 | |
---|
| 263 | echo get_elapsed_time($start, get_moment()); |
---|
| 264 | echo ' for get_fs<br />'; |
---|
| 265 | |
---|
| 266 | $cat_ids = array_diff(array_keys($db_categories), $to_delete); |
---|
[10] | 267 | |
---|
[659] | 268 | $db_elements = array(); |
---|
| 269 | $db_unvalidated = array(); |
---|
| 270 | |
---|
| 271 | if (count($cat_ids) > 0) |
---|
| 272 | { |
---|
| 273 | $query = ' |
---|
| 274 | SELECT id, path |
---|
[466] | 275 | FROM '.IMAGES_TABLE.' |
---|
[659] | 276 | WHERE storage_category_id IN ( |
---|
| 277 | '.wordwrap(implode(', ', $cat_ids), 80, "\n").') |
---|
[466] | 278 | ;'; |
---|
[659] | 279 | $result = pwg_query($query); |
---|
| 280 | while ($row = mysql_fetch_array($result)) |
---|
[10] | 281 | { |
---|
[659] | 282 | $db_elements[$row['id']] = $row['path']; |
---|
[10] | 283 | } |
---|
[659] | 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\' |
---|
[466] | 293 | ;'; |
---|
[659] | 294 | $result = pwg_query($query); |
---|
| 295 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 296 | { |
---|
[659] | 297 | array_push( |
---|
| 298 | $db_unvalidated, |
---|
| 299 | array_search($row['storage_category_id'], |
---|
| 300 | $db_fulldirs).'/'.$row['file'] |
---|
| 301 | ); |
---|
[345] | 302 | } |
---|
[10] | 303 | } |
---|
[345] | 304 | |
---|
[659] | 305 | // next element id available |
---|
[466] | 306 | $query = ' |
---|
[660] | 307 | SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id |
---|
[659] | 308 | FROM '.IMAGES_TABLE.' |
---|
[466] | 309 | ;'; |
---|
[659] | 310 | list($next_element_id) = mysql_fetch_array(pwg_query($query)); |
---|
[345] | 311 | |
---|
[659] | 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']); |
---|
[345] | 317 | |
---|
| 318 | $inserts = array(); |
---|
[659] | 319 | $insert_links = array(); |
---|
[345] | 320 | |
---|
[659] | 321 | foreach (array_diff($fs['elements'], $db_elements, $db_unvalidated) as $path) |
---|
[466] | 322 | { |
---|
[659] | 323 | $insert = array(); |
---|
| 324 | // storage category must exist |
---|
| 325 | $dirname = dirname($path); |
---|
| 326 | if (!isset($db_fulldirs[$dirname])) |
---|
[10] | 327 | { |
---|
[659] | 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])) |
---|
[466] | 346 | { |
---|
[659] | 347 | $tn_ext = $ext; |
---|
| 348 | break; |
---|
[345] | 349 | } |
---|
[659] | 350 | } |
---|
[466] | 351 | |
---|
[659] | 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 != '') |
---|
[10] | 359 | { |
---|
[659] | 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; |
---|
[160] | 366 | |
---|
[659] | 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'])); |
---|
[466] | 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
[659] | 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])) |
---|
[466] | 388 | { |
---|
[659] | 389 | $representative_ext = $ext; |
---|
| 390 | break; |
---|
[466] | 391 | } |
---|
[659] | 392 | } |
---|
[466] | 393 | |
---|
[659] | 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; |
---|
[10] | 403 | } |
---|
[659] | 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'])); |
---|
[10] | 415 | } |
---|
| 416 | } |
---|
[659] | 417 | |
---|
[466] | 418 | if (count($inserts) > 0) |
---|
[345] | 419 | { |
---|
[659] | 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); |
---|
[486] | 428 | |
---|
[659] | 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); |
---|
[345] | 432 | } |
---|
[659] | 433 | $counts['new_elements'] = count($inserts); |
---|
| 434 | } |
---|
[345] | 435 | |
---|
[659] | 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) |
---|
[345] | 447 | { |
---|
[659] | 448 | delete_elements($to_delete_elements); |
---|
[345] | 449 | } |
---|
[659] | 450 | $counts['del_elements'] = count($to_delete_elements); |
---|
[345] | 451 | } |
---|
[659] | 452 | |
---|
| 453 | echo get_elapsed_time($start_files, get_moment()); |
---|
| 454 | echo ' for new method scanning files<br />'; |
---|
[10] | 455 | } |
---|
[589] | 456 | // +-----------------------------------------------------------------------+ |
---|
| 457 | // | template initialization | |
---|
| 458 | // +-----------------------------------------------------------------------+ |
---|
[466] | 459 | $template->set_filenames(array('update'=>'admin/update.tpl')); |
---|
[393] | 460 | |
---|
[659] | 461 | $result_title = ''; |
---|
| 462 | if (isset($simulate) and $simulate) |
---|
| 463 | { |
---|
| 464 | $result_title.= $lang['update_simulation_title'].' '; |
---|
| 465 | } |
---|
| 466 | $result_title.= $lang['update_part_research']; |
---|
[589] | 467 | |
---|
| 468 | $template->assign_vars( |
---|
| 469 | array( |
---|
| 470 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 471 | 'L_UPDATE_TITLE'=>$lang['update_default_title'], |
---|
| 472 | 'L_UPDATE_SYNC_FILES'=>$lang['update_sync_files'], |
---|
| 473 | 'L_UPDATE_SYNC_DIRS'=>$lang['update_sync_dirs'], |
---|
| 474 | 'L_UPDATE_SYNC_ALL'=>$lang['update_sync_all'], |
---|
| 475 | 'L_UPDATE_SYNC_METADATA'=>$lang['update_sync_metadata'], |
---|
| 476 | 'L_UPDATE_SYNC_METADATA_NEW'=>$lang['update_sync_metadata_new'], |
---|
| 477 | 'L_UPDATE_SYNC_METADATA_ALL'=>$lang['update_sync_metadata_all'], |
---|
| 478 | 'L_UPDATE_CATS_SUBSET'=>$lang['update_cats_subset'], |
---|
[659] | 479 | 'L_RESULT_UPDATE'=>$result_title, |
---|
[589] | 480 | 'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'], |
---|
| 481 | 'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'], |
---|
| 482 | 'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'], |
---|
| 483 | 'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'], |
---|
[659] | 484 | 'L_UPDATE_NB_ERRORS'=>$lang['update_nb_errors'], |
---|
[589] | 485 | 'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'], |
---|
[659] | 486 | 'L_UPDATE_WRONG_DIRNAME_INFO'=>$lang['update_wrong_dirname_info'], |
---|
| 487 | 'L_UPDATE_MISSING_TN_INFO'=>$lang['update_missing_tn_info'], |
---|
| 488 | 'PICTURE_EXT_LIST'=>implode(',', $conf['picture_ext']), |
---|
| 489 | 'L_UPDATE_ERROR_LIST_TITLE'=>$lang['update_error_list_title'], |
---|
| 490 | 'L_UPDATE_ERRORS_CAPTION'=>$lang['update_errors_caption'], |
---|
| 491 | 'L_UPDATE_DISPLAY_INFO'=>$lang['update_display_info'], |
---|
| 492 | 'L_UPDATE_SIMULATE'=>$lang['update_simulate'], |
---|
| 493 | 'L_UPDATE_INFOS_TITLE'=>$lang['update_infos_title'] |
---|
[589] | 494 | )); |
---|
| 495 | // +-----------------------------------------------------------------------+ |
---|
| 496 | // | introduction : choices | |
---|
| 497 | // +-----------------------------------------------------------------------+ |
---|
| 498 | if (!isset($_POST['submit'])) |
---|
[10] | 499 | { |
---|
[589] | 500 | $template->assign_block_vars('introduction', array()); |
---|
| 501 | |
---|
| 502 | $query = ' |
---|
[614] | 503 | SELECT id,name,uppercats,global_rank |
---|
[589] | 504 | FROM '.CATEGORIES_TABLE.' |
---|
[614] | 505 | WHERE site_id = 1 |
---|
[589] | 506 | ;'; |
---|
[614] | 507 | display_select_cat_wrapper($query, |
---|
| 508 | array(), |
---|
| 509 | 'introduction.category_option', |
---|
| 510 | false); |
---|
[10] | 511 | } |
---|
[589] | 512 | // +-----------------------------------------------------------------------+ |
---|
| 513 | // | synchronize files | |
---|
| 514 | // +-----------------------------------------------------------------------+ |
---|
| 515 | else if (isset($_POST['submit']) |
---|
| 516 | and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) |
---|
[10] | 517 | { |
---|
[498] | 518 | $template->assign_block_vars( |
---|
| 519 | 'update', |
---|
| 520 | array( |
---|
| 521 | 'NB_NEW_CATEGORIES'=>$counts['new_categories'], |
---|
| 522 | 'NB_DEL_CATEGORIES'=>$counts['del_categories'], |
---|
| 523 | 'NB_NEW_ELEMENTS'=>$counts['new_elements'], |
---|
[659] | 524 | 'NB_DEL_ELEMENTS'=>$counts['del_elements'], |
---|
| 525 | 'NB_ERRORS'=>count($errors), |
---|
[498] | 526 | )); |
---|
[659] | 527 | |
---|
| 528 | if (count($errors) > 0) |
---|
| 529 | { |
---|
| 530 | $template->assign_block_vars('update.errors', array()); |
---|
| 531 | foreach ($errors as $error) |
---|
| 532 | { |
---|
| 533 | $template->assign_block_vars( |
---|
| 534 | 'update.errors.error', |
---|
| 535 | array( |
---|
| 536 | 'ELEMENT' => $error['path'], |
---|
| 537 | 'LABEL' => $error['type'].' ('.$error_labels[$error['type']].')' |
---|
| 538 | )); |
---|
| 539 | } |
---|
| 540 | } |
---|
| 541 | if (count($infos) > 0 |
---|
| 542 | and isset($_POST['display_info']) |
---|
| 543 | and $_POST['display_info'] == 1) |
---|
| 544 | { |
---|
| 545 | $template->assign_block_vars('update.infos', array()); |
---|
| 546 | foreach ($infos as $info) |
---|
| 547 | { |
---|
| 548 | $template->assign_block_vars( |
---|
| 549 | 'update.infos.info', |
---|
| 550 | array( |
---|
| 551 | 'ELEMENT' => $info['path'], |
---|
| 552 | 'LABEL' => $info['info'] |
---|
| 553 | )); |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | if (!$simulate) |
---|
| 558 | { |
---|
| 559 | $start = get_moment(); |
---|
| 560 | update_category('all'); |
---|
| 561 | echo get_elapsed_time($start,get_moment()); |
---|
| 562 | echo ' for update_category(all)<br />'; |
---|
| 563 | $start = get_moment(); |
---|
| 564 | ordering(); |
---|
| 565 | update_global_rank(); |
---|
| 566 | echo get_elapsed_time($start, get_moment()); |
---|
| 567 | echo ' for ordering categories<br />'; |
---|
| 568 | } |
---|
[345] | 569 | } |
---|
[589] | 570 | // +-----------------------------------------------------------------------+ |
---|
| 571 | // | synchronize metadata | |
---|
| 572 | // +-----------------------------------------------------------------------+ |
---|
| 573 | else if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])) |
---|
[486] | 574 | { |
---|
[589] | 575 | // sync only never synchronized files ? |
---|
| 576 | if ($_POST['sync'] == 'metadata_new') |
---|
[486] | 577 | { |
---|
[589] | 578 | $opts['only_new'] = true; |
---|
[486] | 579 | } |
---|
[589] | 580 | else |
---|
[486] | 581 | { |
---|
[589] | 582 | $opts['only_new'] = false; |
---|
[486] | 583 | } |
---|
[589] | 584 | $opts['category_id'] = ''; |
---|
| 585 | $opts['recursive'] = true; |
---|
| 586 | |
---|
| 587 | if (isset($_POST['cat'])) |
---|
[486] | 588 | { |
---|
[589] | 589 | $opts['category_id'] = $_POST['cat']; |
---|
| 590 | // recursive ? |
---|
| 591 | if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) |
---|
| 592 | { |
---|
| 593 | $opts['recursive'] = false; |
---|
| 594 | } |
---|
[486] | 595 | } |
---|
[589] | 596 | $start = get_moment(); |
---|
| 597 | $files = get_filelist($opts['category_id'], |
---|
| 598 | $opts['recursive'], |
---|
| 599 | $opts['only_new']); |
---|
[486] | 600 | echo get_elapsed_time($start, get_moment()).' for get_filelist<br />'; |
---|
| 601 | |
---|
| 602 | $start = get_moment(); |
---|
| 603 | update_metadata($files); |
---|
| 604 | echo get_elapsed_time($start, get_moment()).' for metadata update<br />'; |
---|
| 605 | } |
---|
[589] | 606 | // +-----------------------------------------------------------------------+ |
---|
| 607 | // | sending html code | |
---|
| 608 | // +-----------------------------------------------------------------------+ |
---|
[393] | 609 | $template->assign_var_from_handle('ADMIN_CONTENT', 'update'); |
---|
[486] | 610 | ?> |
---|