Changeset 23821
- Timestamp:
- Jul 7, 2013, 1:28:12 PM (11 years ago)
- Location:
- trunk/admin/include
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r23272 r23821 2528 2528 return $sub_dirs; 2529 2529 } 2530 2531 /** 2532 * recursively delete a directory 2533 * @param string $path 2534 * @param string $trash_path, try to move the directory to this path if it cannot be delete 2535 */ 2536 function deltree($path, $trash_path=null) 2537 { 2538 if (is_dir($path)) 2539 { 2540 $fh = opendir($path); 2541 while ($file = readdir($fh)) 2542 { 2543 if ($file != '.' and $file != '..') 2544 { 2545 $pathfile = $path . '/' . $file; 2546 if (is_dir($pathfile)) 2547 { 2548 deltree($pathfile, $trash_path); 2549 } 2550 else 2551 { 2552 @unlink($pathfile); 2553 } 2554 } 2555 } 2556 closedir($fh); 2557 2558 if (@rmdir($path)) 2559 { 2560 return true; 2561 } 2562 elseif (!empty($trash_path)) 2563 { 2564 if (!is_dir($trash_path)) 2565 { 2566 @mkgetdir($trash_path, MKGETDIR_RECURSIVE|MKGETDIR_DIE_ON_ERROR|MKGETDIR_PROTECT_HTACCESS); 2567 } 2568 while ($r = $trash_path . '/' . md5(uniqid(rand(), true))) 2569 { 2570 if (!is_dir($r)) 2571 { 2572 @rename($path, $r); 2573 break; 2574 } 2575 } 2576 } 2577 else 2578 { 2579 return false; 2580 } 2581 } 2582 } 2583 2530 2584 ?> -
trunk/admin/include/languages.class.php
r20449 r23821 113 113 pwg_query($query); 114 114 115 if (!$this->deltree(PHPWG_ROOT_PATH.'language/'.$language_id)) 116 { 117 $this->send_to_trash(PHPWG_ROOT_PATH.'language/'.$language_id); 118 } 115 deltree(PHPWG_ROOT_PATH.'language/'.$language_id, PHPWG_ROOT_PATH.'language/trash'); 119 116 break; 120 117 … … 382 379 elseif (is_dir($path)) 383 380 { 384 if (!$this->deltree($path)) 385 { 386 $this->send_to_trash($path); 387 } 381 deltree($path, PHPWG_ROOT_PATH.'language/trash'); 388 382 } 389 383 } … … 407 401 408 402 /** 409 * delete $path directory410 * @param string - path411 */412 function deltree($path)413 {414 if (is_dir($path))415 {416 $fh = opendir($path);417 while ($file = readdir($fh))418 {419 if ($file != '.' and $file != '..')420 {421 $pathfile = $path . '/' . $file;422 if (is_dir($pathfile))423 {424 $this->deltree($pathfile);425 }426 else427 {428 @unlink($pathfile);429 }430 }431 }432 closedir($fh);433 return @rmdir($path);434 }435 }436 437 /**438 * send $path to trash directory439 * @param string - path440 */441 function send_to_trash($path)442 {443 $trash_path = PHPWG_ROOT_PATH . 'language/trash';444 if (!is_dir($trash_path))445 {446 @mkdir($trash_path);447 $file = @fopen($trash_path . '/.htaccess', 'w');448 @fwrite($file, 'deny from all');449 @fclose($file);450 }451 while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))452 {453 if (!is_dir($r))454 {455 @rename($path, $r);456 break;457 }458 }459 }460 461 /**462 403 * Sort functions 463 404 */ -
trunk/admin/include/plugins.class.php
r20449 r23821 167 167 break; 168 168 } 169 if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id)) 170 { 171 $this->send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id); 172 } 169 deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash'); 173 170 break; 174 171 } … … 515 512 elseif (is_dir($path)) 516 513 { 517 if (!$this->deltree($path)) 518 { 519 $this->send_to_trash($path); 520 } 514 deltree($path, PHPWG_PLUGINS_PATH . 'trash'); 521 515 } 522 516 } … … 554 548 return $merged_extensions; 555 549 } 556 557 /**558 * delete $path directory559 * @param string - path560 */561 function deltree($path)562 {563 if (is_dir($path))564 {565 $fh = opendir($path);566 while ($file = readdir($fh))567 {568 if ($file != '.' and $file != '..')569 {570 $pathfile = $path . '/' . $file;571 if (is_dir($pathfile))572 {573 $this->deltree($pathfile);574 }575 else576 {577 @unlink($pathfile);578 }579 }580 }581 closedir($fh);582 return @rmdir($path);583 }584 }585 586 /**587 * send $path to trash directory588 * @param string - path589 */590 function send_to_trash($path)591 {592 $trash_path = PHPWG_PLUGINS_PATH . 'trash';593 if (!is_dir($trash_path))594 {595 @mkdir($trash_path);596 $file = @fopen($trash_path . '/.htaccess', 'w');597 @fwrite($file, 'deny from all');598 @fclose($file);599 }600 while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))601 {602 if (!is_dir($r))603 {604 @rename($path, $r);605 break;606 }607 }608 }609 550 610 551 /** -
trunk/admin/include/themes.class.php
r23248 r23821 222 222 } 223 223 224 if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id)) 225 { 226 $this->send_to_trash(PHPWG_THEMES_PATH.$theme_id); 227 } 224 deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash'); 228 225 break; 229 226 … … 642 639 elseif (is_dir($path)) 643 640 { 644 if (!$this->deltree($path)) 645 { 646 $this->send_to_trash($path); 647 } 641 deltree($path, PHPWG_THEMES_PATH . 'trash'); 648 642 } 649 643 } … … 665 659 666 660 /** 667 * delete $path directory668 * @param string - path669 */670 function deltree($path)671 {672 if (is_dir($path))673 {674 $fh = opendir($path);675 while ($file = readdir($fh))676 {677 if ($file != '.' and $file != '..')678 {679 $pathfile = $path . '/' . $file;680 if (is_dir($pathfile))681 {682 $this->deltree($pathfile);683 }684 else685 {686 @unlink($pathfile);687 }688 }689 }690 closedir($fh);691 return @rmdir($path);692 }693 }694 695 /**696 * send $path to trash directory697 * @param string - path698 */699 function send_to_trash($path)700 {701 $trash_path = PHPWG_THEMES_PATH . 'trash';702 if (!is_dir($trash_path))703 {704 @mkdir($trash_path);705 $file = @fopen($trash_path . '/.htaccess', 'w');706 @fwrite($file, 'deny from all');707 @fclose($file);708 }709 while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))710 {711 if (!is_dir($r))712 {713 @rename($path, $r);714 break;715 }716 }717 }718 719 /**720 661 * Sort functions 721 662 */ -
trunk/admin/include/updates.class.php
r16179 r23821 34 34 } 35 35 36 function check_piwigo_upgrade()36 static function check_piwigo_upgrade() 37 37 { 38 38 $_SESSION['need_update'] = null; … … 243 243 } 244 244 245 function deltree($path, $move_to_trash=false) 246 { 247 if (is_dir($path)) 248 { 249 $fh = opendir($path); 250 while ($file = readdir($fh)) 251 { 252 if ($file != '.' and $file != '..') 253 { 254 $pathfile = $path . '/' . $file; 255 if (is_dir($pathfile)) 256 { 257 self::deltree($pathfile, $move_to_trash); 258 } 259 else 260 { 261 @unlink($pathfile); 262 } 263 } 264 } 265 closedir($fh); 266 if (@rmdir($path)) 267 { 268 return true; 269 } 270 elseif ($move_to_trash) 271 { 272 $trash = PHPWG_ROOT_PATH.'_trash'; 273 if (!is_dir($trash)) 274 { 275 @mkgetdir($trash); 276 } 277 return @rename($path, $trash . '/'.md5(uniqid(rand(), true))); 278 } 279 else 280 { 281 return false; 282 } 283 } 284 } 285 286 function process_obsolete_list($file) 245 static function process_obsolete_list($file) 287 246 { 288 247 if (file_exists(PHPWG_ROOT_PATH.$file) … … 300 259 elseif (is_dir($path)) 301 260 { 302 self::deltree($path, true);303 } 304 } 305 } 306 } 307 308 function dump_database($include_history=false)261 deltree($path, PHPWG_ROOT_PATH.'_trash'); 262 } 263 } 264 } 265 } 266 267 static function dump_database($include_history=false) 309 268 { 310 269 global $page, $conf, $cfgBase; … … 351 310 352 311 @readfile($backupFile); 353 self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');312 deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update'); 354 313 exit(); 355 314 } … … 360 319 } 361 320 362 function upgrade_to($upgrade_to, &$step, $check_current_version=true)321 static function upgrade_to($upgrade_to, &$step, $check_current_version=true) 363 322 { 364 323 global $page, $conf, $template; … … 450 409 { 451 410 self::process_obsolete_list($obsolete_list); 452 self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');411 deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update'); 453 412 invalidate_user_cache(true); 454 413 $template->delete_compiled_templates(); … … 478 437 else 479 438 { 480 self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');439 deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update'); 481 440 array_push($page['errors'], l10n('An error has occured during upgrade.')); 482 441 }
Note: See TracChangeset
for help on using the changeset viewer.