| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | // $Id: delete.php 944 2009-02-22 09:39:58Z Ruebenwurzel $
 | 
  
    | 4 | 
 | 
  
    | 5 | /*
 | 
  
    | 6 | 
 | 
  
    | 7 |  Website Baker Project <http://www.websitebaker.org/>
 | 
  
    | 8 |  Copyright (C) 2004-2009, Ryan Djurovich
 | 
  
    | 9 | 
 | 
  
    | 10 |  Website Baker is free software; you can redistribute it and/or modify
 | 
  
    | 11 |  it under the terms of the GNU General Public License as published by
 | 
  
    | 12 |  the Free Software Foundation; either version 2 of the License, or
 | 
  
    | 13 |  (at your option) any later version.
 | 
  
    | 14 | 
 | 
  
    | 15 |  Website Baker is distributed in the hope that it will be useful,
 | 
  
    | 16 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
  
    | 17 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
  
    | 18 |  GNU General Public License for more details.
 | 
  
    | 19 | 
 | 
  
    | 20 |  You should have received a copy of the GNU General Public License
 | 
  
    | 21 |  along with Website Baker; if not, write to the Free Software
 | 
  
    | 22 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
  
    | 23 | 
 | 
  
    | 24 | */
 | 
  
    | 25 | 
 | 
  
    | 26 | // Create admin object
 | 
  
    | 27 | require('../../config.php');
 | 
  
    | 28 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 29 | $admin = new admin('Media', 'media_delete', false);
 | 
  
    | 30 | 
 | 
  
    | 31 | // Include the WB functions file
 | 
  
    | 32 | require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 33 | 
 | 
  
    | 34 | // Get the current dir
 | 
  
    | 35 | $directory = $admin->get_get('dir');
 | 
  
    | 36 | if($directory == '/') {
 | 
  
    | 37 | 	$directory = '';
 | 
  
    | 38 | }
 | 
  
    | 39 | // Check to see if it contains ../
 | 
  
    | 40 | if(strstr($directory, '../')) {
 | 
  
    | 41 | 	$admin->print_header();
 | 
  
    | 42 | 	$admin->print_error($MESSAGE['MEDIA']['DOT_DOT_SLASH']);
 | 
  
    | 43 | }
 | 
  
    | 44 | 
 | 
  
    | 45 | // Get the temp id
 | 
  
    | 46 | if(!is_numeric($admin->get_get('id'))) {
 | 
  
    | 47 | 	header("Location: browse.php?dir=$directory");
 | 
  
    | 48 | 	exit(0);
 | 
  
    | 49 | } else {
 | 
  
    | 50 | 	$file_id = $admin->get_get('id');
 | 
  
    | 51 | }
 | 
  
    | 52 | 
 | 
  
    | 53 | // Get home folder not to show
 | 
  
    | 54 | $home_folders = get_home_folders();
 | 
  
    | 55 | 
 | 
  
    | 56 | // Figure out what folder name the temp id is
 | 
  
    | 57 | if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
 | 
  
    | 58 | 	// Loop through the files and dirs an add to list
 | 
  
    | 59 |    while (false !== ($file = readdir($handle))) {
 | 
  
    | 60 | 		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
 | 
  
    | 61 | 			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
 | 
  
    | 62 | 				if(!isset($home_folders[$directory.'/'.$file])) {
 | 
  
    | 63 | 					$DIR[] = $file;
 | 
  
    | 64 | 				}
 | 
  
    | 65 | 			} else {
 | 
  
    | 66 | 				$FILE[] = $file;
 | 
  
    | 67 | 			}
 | 
  
    | 68 | 		}
 | 
  
    | 69 | 	}
 | 
  
    | 70 | 	$temp_id = 0;
 | 
  
    | 71 | 	if(isset($DIR)) {
 | 
  
    | 72 | 		sort($DIR);
 | 
  
    | 73 | 		foreach($DIR AS $name) {
 | 
  
    | 74 | 			$temp_id++;
 | 
  
    | 75 | 			if(!isset($delete_file) AND $file_id == $temp_id) {
 | 
  
    | 76 | 				$delete_file = $name;
 | 
  
    | 77 | 				$type = 'folder';
 | 
  
    | 78 | 			}
 | 
  
    | 79 | 		}
 | 
  
    | 80 | 	}
 | 
  
    | 81 | 	if(isset($FILE)) {
 | 
  
    | 82 | 		sort($FILE);
 | 
  
    | 83 | 		foreach($FILE AS $name) {
 | 
  
    | 84 | 			$temp_id++;
 | 
  
    | 85 | 			if(!isset($delete_file) AND $file_id == $temp_id) {
 | 
  
    | 86 | 				$delete_file = $name;
 | 
  
    | 87 | 				$type = 'file';
 | 
  
    | 88 | 			}
 | 
  
    | 89 | 		}
 | 
  
    | 90 | 	}
 | 
  
    | 91 | }
 | 
  
    | 92 | 
 | 
  
    | 93 | // Check to see if we could find an id to match
 | 
  
    | 94 | if(!isset($delete_file)) {
 | 
  
    | 95 | 	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], "browse.php?dir=$directory", false);
 | 
  
    | 96 | }
 | 
  
    | 97 | $relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
 | 
  
    | 98 | // Check if the file/folder exists
 | 
  
    | 99 | if(!file_exists($relative_path)) {
 | 
  
    | 100 | 	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], "browse.php?dir=$directory", false);	
 | 
  
    | 101 | }
 | 
  
    | 102 | 
 | 
  
    | 103 | // Find out whether its a file or folder
 | 
  
    | 104 | if($type == 'folder') {
 | 
  
    | 105 | 	// Try and delete the directory
 | 
  
    | 106 | 	if(rm_full_dir($relative_path)) {
 | 
  
    | 107 | 		$admin->print_success($MESSAGE['MEDIA']['DELETED_DIR'], "browse.php?dir=$directory");
 | 
  
    | 108 | 	} else {
 | 
  
    | 109 | 		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_DIR'], "browse.php?dir=$directory", false);
 | 
  
    | 110 | 	}
 | 
  
    | 111 | } else {
 | 
  
    | 112 | 	// Try and delete the file
 | 
  
    | 113 | 	if(unlink($relative_path)) {
 | 
  
    | 114 | 		$admin->print_success($MESSAGE['MEDIA']['DELETED_FILE'], "browse.php?dir=$directory");
 | 
  
    | 115 | 	} else {
 | 
  
    | 116 | 		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_FILE'], "browse.php?dir=$directory", false);
 | 
  
    | 117 | 	}
 | 
  
    | 118 | }
 | 
  
    | 119 | 
 | 
  
    | 120 | ?>
 |