| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        admin
 
     | 
  
  
    | 
      5
     | 
    
       * @package         admintools
 
     | 
  
  
    | 
      6
     | 
    
       * @author          WebsiteBaker Project
 
     | 
  
  
    | 
      7
     | 
    
       * @copyright       2004-2009, Ryan Djurovich
 
     | 
  
  
    | 
      8
     | 
    
       * @copyright       2009-2011, Website Baker Org. e.V.
 
     | 
  
  
    | 
      9
     | 
    
       * @link			http://www.websitebaker2.org/
 
     | 
  
  
    | 
      10
     | 
    
       * @license         http://www.gnu.org/licenses/gpl.html
 
     | 
  
  
    | 
      11
     | 
    
       * @platform        WebsiteBaker 2.8.x
 
     | 
  
  
    | 
      12
     | 
    
       * @requirements    PHP 5.2.2 and higher
 
     | 
  
  
    | 
      13
     | 
    
       * @version         $Id: delete.php 1425 2011-02-03 23:16:12Z Luisehahne $
 
     | 
  
  
    | 
      14
     | 
    
       * @filesource		$HeadURL:  $
 
     | 
  
  
    | 
      15
     | 
    
       * @lastmodified    $Date:  $
 
     | 
  
  
    | 
      16
     | 
    
       *
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      // Create admin object
 
     | 
  
  
    | 
      20
     | 
    
      require('../../config.php');
     | 
  
  
    | 
      21
     | 
    
      require_once(WB_PATH.'/framework/class.admin.php');
 
     | 
  
  
    | 
      22
     | 
    
      $admin = new admin('Media', 'media_delete', false);
     | 
  
  
    | 
      23
     | 
    
      
 
     | 
  
  
    | 
      24
     | 
    
      // Include the WB functions file
 
     | 
  
  
    | 
      25
     | 
    
      require_once(WB_PATH.'/framework/functions.php');
 
     | 
  
  
    | 
      26
     | 
    
      
 
     | 
  
  
    | 
      27
     | 
    
      // Get the current dir
 
     | 
  
  
    | 
      28
     | 
    
      $directory = $admin->get_get('dir');
     | 
  
  
    | 
      29
     | 
    
      if($directory == '/') {
     | 
  
  
    | 
      30
     | 
    
      	$directory = '';
 
     | 
  
  
    | 
      31
     | 
    
      }
 
     | 
  
  
    | 
      32
     | 
    
      
 
     | 
  
  
    | 
      33
     | 
    
      // Check to see if it contains ..
 
     | 
  
  
    | 
      34
     | 
    
      if (!check_media_path($directory)) {
     | 
  
  
    | 
      35
     | 
    
      	// $admin->print_header();
 
     | 
  
  
    | 
      36
     | 
    
      	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH'],WB_URL.'/admin/media/browse.php?dir=',false );
 
     | 
  
  
    | 
      37
     | 
    
      }
 
     | 
  
  
    | 
      38
     | 
    
      
 
     | 
  
  
    | 
      39
     | 
    
      // Get the temp id
 
     | 
  
  
    | 
      40
     | 
    
      $file_id = $admin->checkIDKEY('id', false, 'GET');
     | 
  
  
    | 
      41
     | 
    
      if (!$file_id) {
     | 
  
  
    | 
      42
     | 
    
      	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL.'/admin/media/browse.php?dir=',false);
 
     | 
  
  
    | 
      43
     | 
    
      }
 
     | 
  
  
    | 
      44
     | 
    
      
 
     | 
  
  
    | 
      45
     | 
    
      // Get home folder not to show
 
     | 
  
  
    | 
      46
     | 
    
      $home_folders = get_home_folders();
 
     | 
  
  
    | 
      47
     | 
    
      
 
     | 
  
  
    | 
      48
     | 
    
      // Figure out what folder name the temp id is
 
     | 
  
  
    | 
      49
     | 
    
      if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
     | 
  
  
    | 
      50
     | 
    
      	// Loop through the files and dirs an add to list
 
     | 
  
  
    | 
      51
     | 
    
         while (false !== ($file = readdir($handle))) {
     | 
  
  
    | 
      52
     | 
    
      		if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
     | 
  
  
    | 
      53
     | 
    
      			if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
     | 
  
  
    | 
      54
     | 
    
      				if(!isset($home_folders[$directory.'/'.$file])) {
     | 
  
  
    | 
      55
     | 
    
      					$DIR[] = $file;
 
     | 
  
  
    | 
      56
     | 
    
      				}
 
     | 
  
  
    | 
      57
     | 
    
      			} else {
     | 
  
  
    | 
      58
     | 
    
      				$FILE[] = $file;
 
     | 
  
  
    | 
      59
     | 
    
      			}
 
     | 
  
  
    | 
      60
     | 
    
      		}
 
     | 
  
  
    | 
      61
     | 
    
      	}
 
     | 
  
  
    | 
      62
     | 
    
      	$temp_id = 0;
 
     | 
  
  
    | 
      63
     | 
    
      	if(isset($DIR)) {
     | 
  
  
    | 
      64
     | 
    
      		sort($DIR);
 
     | 
  
  
    | 
      65
     | 
    
      		foreach($DIR AS $name) {
     | 
  
  
    | 
      66
     | 
    
      			$temp_id++;
 
     | 
  
  
    | 
      67
     | 
    
      			if(!isset($delete_file) AND $file_id == $temp_id) {
     | 
  
  
    | 
      68
     | 
    
      				$delete_file = $name;
 
     | 
  
  
    | 
      69
     | 
    
      				$type = 'folder';
 
     | 
  
  
    | 
      70
     | 
    
      			}
 
     | 
  
  
    | 
      71
     | 
    
      		}
 
     | 
  
  
    | 
      72
     | 
    
      	}
 
     | 
  
  
    | 
      73
     | 
    
      	if(isset($FILE)) {
     | 
  
  
    | 
      74
     | 
    
      		sort($FILE);
 
     | 
  
  
    | 
      75
     | 
    
      		foreach($FILE AS $name) {
     | 
  
  
    | 
      76
     | 
    
      			$temp_id++;
 
     | 
  
  
    | 
      77
     | 
    
      			if(!isset($delete_file) AND $file_id == $temp_id) {
     | 
  
  
    | 
      78
     | 
    
      				$delete_file = $name;
 
     | 
  
  
    | 
      79
     | 
    
      				$type = 'file';
 
     | 
  
  
    | 
      80
     | 
    
      			}
 
     | 
  
  
    | 
      81
     | 
    
      		}
 
     | 
  
  
    | 
      82
     | 
    
      	}
 
     | 
  
  
    | 
      83
     | 
    
      }
 
     | 
  
  
    | 
      84
     | 
    
      
 
     | 
  
  
    | 
      85
     | 
    
      // Check to see if we could find an id to match
 
     | 
  
  
    | 
      86
     | 
    
      if(!isset($delete_file)) {
     | 
  
  
    | 
      87
     | 
    
      	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], "browse.php?dir=$directory", false);
 
     | 
  
  
    | 
      88
     | 
    
      }
 
     | 
  
  
    | 
      89
     | 
    
      $relative_path = WB_PATH.MEDIA_DIRECTORY.'/'.$directory.'/'.$delete_file;
 
     | 
  
  
    | 
      90
     | 
    
      // Check if the file/folder exists
 
     | 
  
  
    | 
      91
     | 
    
      if(!file_exists($relative_path)) {
     | 
  
  
    | 
      92
     | 
    
      	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], "browse.php?dir=$directory", false);	
 
     | 
  
  
    | 
      93
     | 
    
      }
 
     | 
  
  
    | 
      94
     | 
    
      
 
     | 
  
  
    | 
      95
     | 
    
      // Find out whether its a file or folder
 
     | 
  
  
    | 
      96
     | 
    
      if($type == 'folder') {
     | 
  
  
    | 
      97
     | 
    
      	// Try and delete the directory
 
     | 
  
  
    | 
      98
     | 
    
      	if(rm_full_dir($relative_path)) {
     | 
  
  
    | 
      99
     | 
    
      		$admin->print_success($MESSAGE['MEDIA']['DELETED_DIR'], "browse.php?dir=$directory");
 
     | 
  
  
    | 
      100
     | 
    
      	} else {
     | 
  
  
    | 
      101
     | 
    
      		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_DIR'], "browse.php?dir=$directory", false);
 
     | 
  
  
    | 
      102
     | 
    
      	}
 
     | 
  
  
    | 
      103
     | 
    
      } else {
     | 
  
  
    | 
      104
     | 
    
      	// Try and delete the file
 
     | 
  
  
    | 
      105
     | 
    
      	if(unlink($relative_path)) {
     | 
  
  
    | 
      106
     | 
    
      		$admin->print_success($MESSAGE['MEDIA']['DELETED_FILE'], "browse.php?dir=$directory");
 
     | 
  
  
    | 
      107
     | 
    
      	} else {
     | 
  
  
    | 
      108
     | 
    
      		$admin->print_error($MESSAGE['MEDIA']['CANNOT_DELETE_FILE'], "browse.php?dir=$directory", false);
 
     | 
  
  
    | 
      109
     | 
    
      	}
 
     | 
  
  
    | 
      110
     | 
    
      }
 
     | 
  
  
    | 
      111
     | 
    
      
 
     | 
  
  
    | 
      112
     | 
    
      ?>
 
     |