| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        admin
 | 
  
    | 5 |  * @package         admintools
 | 
  
    | 6 |  * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2009-2012, WebsiteBaker Org. e.V.
 | 
  
    | 8 |  * @link			http://www.websitebaker2.org/
 | 
  
    | 9 |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
  
    | 10 |  * @platform        WebsiteBaker 2.8.x
 | 
  
    | 11 |  * @requirements    PHP 5.2.2 and higher
 | 
  
    | 12 |  * @version         $Id: delete.php 1824 2012-11-20 17:41:22Z Luisehahne $
 | 
  
    | 13 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/media/delete.php $
 | 
  
    | 14 |  * @lastmodified    $Date: 2012-11-20 18:41:22 +0100 (Tue, 20 Nov 2012) $
 | 
  
    | 15 |  *
 | 
  
    | 16 |  */
 | 
  
    | 17 | 
 | 
  
    | 18 | if(!defined('WB_URL'))
 | 
  
    | 19 | {
 | 
  
    | 20 |     $config_file = realpath('../../config.php');
 | 
  
    | 21 |     if(file_exists($config_file) && !defined('WB_URL'))
 | 
  
    | 22 |     {
 | 
  
    | 23 |     	require($config_file);
 | 
  
    | 24 |     }
 | 
  
    | 25 | }
 | 
  
    | 26 | if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
 | 
  
    | 27 | 
 | 
  
    | 28 | $admin = new admin('Media', 'media', false);
 | 
  
    | 29 | 
 | 
  
    | 30 | // Include the WB functions file
 | 
  
    | 31 | if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
 | 
  
    | 32 | 
 | 
  
    | 33 | // Get the current dir
 | 
  
    | 34 | $directory = $admin->get_get('dir');
 | 
  
    | 35 | $directory = ($directory == '/') ?  '' : $directory;
 | 
  
    | 36 | 
 | 
  
    | 37 | $dirlink = 'browse.php?dir='.$directory;
 | 
  
    | 38 | $rootlink = 'browse.php?dir=';
 | 
  
    | 39 | 
 | 
  
    | 40 | // Get the current dir
 | 
  
    | 41 | $currentHome = $admin->get_home_folder();
 | 
  
    | 42 | // check for correct directory
 | 
  
    | 43 | if ($currentHome && stripos(WB_PATH.MEDIA_DIRECTORY.$rootlink,WB_PATH.MEDIA_DIRECTORY.$currentHome)===false) {
 | 
  
    | 44 | 	$rootlink = $currentHome;
 | 
  
    | 45 | }
 | 
  
    | 46 | 
 | 
  
    | 47 | // Check to see if it contains ..
 | 
  
    | 48 | if (!check_media_path($directory)) {
 | 
  
    | 49 | 	// $admin->print_header();
 | 
  
    | 50 | 	$admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH'],$rootlink,false );
 | 
  
    | 51 | }
 | 
  
    | 52 | 
 | 
  
    | 53 | // Get the file id
 | 
  
    | 54 | $file_id = $admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']);
 | 
  
    | 55 | if (!$file_id) {
 | 
  
    | 56 | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $dirlink,false);
 | 
  
    | 57 | }
 | 
  
    | 58 | 
 | 
  
    | 59 | // Get home folder not to show
 | 
  
    | 60 | $home_folders = get_home_folders();
 | 
  
    | 61 | $usedFiles = array();
 | 
  
    | 62 | // feature freeze
 | 
  
    | 63 | // require_once(ADMIN_PATH.'/media/dse.php');
 | 
  
    | 64 | /*
 | 
  
    | 65 | 
 | 
  
    | 66 | if(!empty($currentdir)) {
 | 
  
    | 67 | 	$usedFiles = $Dse->getMatchesFromDir( $directory, DseTwo::RETURN_USED);
 | 
  
    | 68 | }
 | 
  
    | 69 | */
 | 
  
    | 70 | // Figure out what folder name the temp id is
 | 
  
    | 71 | if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
 | 
  
    | 72 | 	// Loop through the files and dirs an add to list
 | 
  
    | 73 |    while (false !== ($file = readdir($handle))) {
 | 
  
    | 74 | 		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
 | 
  
    | 75 | 			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
 | 
  
    | 76 | 				if(!isset($home_folders[$directory.'/'.$file])) {
 | 
  
    | 77 | 					$DIR[] = $file;
 | 
  
    | 78 | 				}
 | 
  
    | 79 | 			} else {
 | 
  
    | 80 | 				$FILE[] = $file;
 | 
  
    | 81 | 			}
 | 
  
    | 82 | 		}
 | 
  
    | 83 | 	}
 | 
  
    | 84 | 	$temp_id = 0;
 | 
  
    | 85 | 	if(isset($DIR)) {
 | 
  
    | 86 | 		sort($DIR);
 | 
  
    | 87 | 		foreach($DIR AS $name) {
 | 
  
    | 88 | 			$temp_id++;
 | 
  
    | 89 | 			if(!isset($delete_file) AND $file_id == $temp_id) {
 | 
  
    | 90 | 				$delete_file = $name;
 | 
  
    | 91 | 				$type = 'folder';
 | 
  
    | 92 | 			}
 | 
  
    | 93 | 		}
 | 
  
    | 94 | 	}
 | 
  
    | 95 | 	if(isset($FILE)) {
 | 
  
    | 96 | 		sort($FILE);
 | 
  
    | 97 | 		foreach($FILE AS $name) {
 | 
  
    | 98 | 			$temp_id++;
 | 
  
    | 99 | 			if(!isset($delete_file) AND $file_id == $temp_id) {
 | 
  
    | 100 | 				$delete_file = $name;
 | 
  
    | 101 | 				$type = 'file';
 | 
  
    | 102 | 			}
 | 
  
    | 103 | 		}
 | 
  
    | 104 | 	}
 | 
  
    | 105 | }
 | 
  
    | 106 | 
 | 
  
    | 107 | // Check to see if we could find an id to match
 | 
  
    | 108 | if(!isset($delete_file)) {
 | 
  
    | 109 | 	$admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
 | 
  
    | 110 | }
 | 
  
    | 111 | $relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
 | 
  
    | 112 | // Check if the file/folder exists
 | 
  
    | 113 | if(!file_exists($relative_path)) {
 | 
  
    | 114 | 	$admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
 | 
  
    | 115 | }
 | 
  
    | 116 | 
 | 
  
    | 117 | // Find out whether its a file or folder
 | 
  
    | 118 | if($type == 'folder') {
 | 
  
    | 119 | 	// Try and delete the directory
 | 
  
    | 120 | 	if(rm_full_dir($relative_path)) {
 | 
  
    | 121 | 		$admin->print_success($MESSAGE['MEDIA_DELETED_DIR'], $dirlink);
 | 
  
    | 122 | 	} else {
 | 
  
    | 123 | 		$admin->print_error($MESSAGE['MEDIA_CANNOT_DELETE_DIR'], $dirlink, false);
 | 
  
    | 124 | 	}
 | 
  
    | 125 | } else {
 | 
  
    | 126 | 	// Try and delete the file
 | 
  
    | 127 | 	if(unlink($relative_path)) {
 | 
  
    | 128 | 		$admin->print_success($MESSAGE['MEDIA_DELETED_FILE'], $dirlink);
 | 
  
    | 129 | 	} else {
 | 
  
    | 130 | 		$admin->print_error($MESSAGE['MEDIA_CANNOT_DELETE_FILE'], $dirlink, false);
 | 
  
    | 131 | 	}
 | 
  
    | 132 | }
 |