| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | /*
 | 
  
    | 4 | 
 | 
  
    | 5 |  Website Baker Project <http://www.websitebaker.org/>
 | 
  
    | 6 |  Copyright (C) 2004-2005, Ryan Djurovich
 | 
  
    | 7 | 
 | 
  
    | 8 |  Website Baker is free software; you can redistribute it and/or modify
 | 
  
    | 9 |  it under the terms of the GNU General Public License as published by
 | 
  
    | 10 |  the Free Software Foundation; either version 2 of the License, or
 | 
  
    | 11 |  (at your option) any later version.
 | 
  
    | 12 | 
 | 
  
    | 13 |  Website Baker is distributed in the hope that it will be useful,
 | 
  
    | 14 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
  
    | 15 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
  
    | 16 |  GNU General Public License for more details.
 | 
  
    | 17 | 
 | 
  
    | 18 |  You should have received a copy of the GNU General Public License
 | 
  
    | 19 |  along with Website Baker; if not, write to the Free Software
 | 
  
    | 20 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
  
    | 21 | 
 | 
  
    | 22 | */
 | 
  
    | 23 | 
 | 
  
    | 24 | // Create admin object
 | 
  
    | 25 | require('../../config.php');
 | 
  
    | 26 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 27 | $admin = new admin('Media', 'media_rename', false);
 | 
  
    | 28 | 
 | 
  
    | 29 | // Include the WB functions file
 | 
  
    | 30 | require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 31 | 
 | 
  
    | 32 | // Include the basic header file
 | 
  
    | 33 | require(ADMIN_PATH.'/media/basic_header.html');
 | 
  
    | 34 | 
 | 
  
    | 35 | // Get the current dir
 | 
  
    | 36 | $directory = $admin->get_post('dir');
 | 
  
    | 37 | if($directory == '/') {
 | 
  
    | 38 | 	$directory = '';
 | 
  
    | 39 | }
 | 
  
    | 40 | // Check to see if it contains ../
 | 
  
    | 41 | if(strstr($directory, '../')) {
 | 
  
    | 42 | 	$admin->print_header();
 | 
  
    | 43 | 	$admin->print_error($MESSAGE['MEDIA']['DIR_DOT_DOT_SLASH']);
 | 
  
    | 44 | }
 | 
  
    | 45 | 
 | 
  
    | 46 | // Get the temp id
 | 
  
    | 47 | if(!is_numeric($admin->get_post('id'))) {
 | 
  
    | 48 | 	header("Location: browse.php?dir=$directory");
 | 
  
    | 49 | } else {
 | 
  
    | 50 | 	$file_id = $admin->get_post('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 | 		foreach($DIR AS $name) {
 | 
  
    | 73 | 			$temp_id++;
 | 
  
    | 74 | 			if($file_id == $temp_id) {
 | 
  
    | 75 | 				$rename_file = $name;
 | 
  
    | 76 | 				$type = 'folder';
 | 
  
    | 77 | 			}
 | 
  
    | 78 | 		}
 | 
  
    | 79 | 	}
 | 
  
    | 80 | 	if(isset($FILE)) {
 | 
  
    | 81 | 		foreach($FILE AS $name) {
 | 
  
    | 82 | 			$temp_id++;
 | 
  
    | 83 | 			if($file_id == $temp_id) {
 | 
  
    | 84 | 				$rename_file = $name;
 | 
  
    | 85 | 				$type = 'file';
 | 
  
    | 86 | 			}
 | 
  
    | 87 | 		}
 | 
  
    | 88 | 	}
 | 
  
    | 89 | }
 | 
  
    | 90 | 
 | 
  
    | 91 | if(!isset($rename_file)) {
 | 
  
    | 92 | 	$admin->print_error($MESSAGE['MEDIA']['FILE_NOT_FOUND'], "browse.php?dir=$directory", false);
 | 
  
    | 93 | }
 | 
  
    | 94 | 
 | 
  
    | 95 | // Check if they entered a new name
 | 
  
    | 96 | if(media_filename($admin->get_post('name')) == "") {
 | 
  
    | 97 | 	$admin->print_error($MESSAGE['MEDIA']['BLANK_NAME'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 98 | } else {
 | 
  
    | 99 | 	$old_name = $admin->get_post('old_name');
 | 
  
    | 100 | 	$new_name =  media_filename($admin->get_post('name'));
 | 
  
    | 101 | }
 | 
  
    | 102 | 
 | 
  
    | 103 | // Check if they entered an extension
 | 
  
    | 104 | if($type == 'file') {
 | 
  
    | 105 | 	if(media_filename($admin->get_post('extension')) == "") {
 | 
  
    | 106 | 		$admin->print_error($MESSAGE['MEDIA']['BLANK_EXTENSION'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 107 | 	} else {
 | 
  
    | 108 | 		$extension = media_filename($admin->get_post('extension'));
 | 
  
    | 109 | 	}
 | 
  
    | 110 | } else {
 | 
  
    | 111 | 	$extension = '';
 | 
  
    | 112 | }
 | 
  
    | 113 | 
 | 
  
    | 114 | // Join new name and extension
 | 
  
    | 115 | $name = $new_name.$extension;
 | 
  
    | 116 | 
 | 
  
    | 117 | // Check if the name contains ..
 | 
  
    | 118 | if(strstr($name, '..')) {
 | 
  
    | 119 | 	$admin->print_error($MESSAGE['MEDIA']['NAME_DOT_DOT_SLASH'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 120 | }
 | 
  
    | 121 | 
 | 
  
    | 122 | // Check if the name is index.php
 | 
  
    | 123 | if($name == 'index.php') {
 | 
  
    | 124 | 	$admin->print_error($MESSAGE['MEDIA']['NAME_INDEX_PHP'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 125 | }
 | 
  
    | 126 | 
 | 
  
    | 127 | // Check that the name still has a value
 | 
  
    | 128 | if($name == '') {
 | 
  
    | 129 | 	$admin->print_error($MESSAGE['MEDIA']['BLANK_NAME'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 130 | }
 | 
  
    | 131 | 
 | 
  
    | 132 | // Check if we should overwrite or not
 | 
  
    | 133 | if($admin->get_post('overwrite') != 'yes' AND file_exists(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name) == true) {
 | 
  
    | 134 | 	if($type == 'folder') {
 | 
  
    | 135 | 		$admin->print_error($MESSAGE['MEDIA']['DIR_EXISTS'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 136 | 	} else {
 | 
  
    | 137 | 		$admin->print_error($MESSAGE['MEDIA']['FILE_EXISTS'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 138 | 	}
 | 
  
    | 139 | }
 | 
  
    | 140 | 
 | 
  
    | 141 | // Try and rename the file/folder
 | 
  
    | 142 | if(rename(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file, WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$name)) {
 | 
  
    | 143 | 	$admin->print_success($MESSAGE['MEDIA']['RENAMED'], "browse.php?dir=$directory");
 | 
  
    | 144 | } else {
 | 
  
    | 145 | 	$admin->print_error($MESSAGE['MEDIA']['CANNOT_RENAME'], "rename.php?dir=$directory&id=$file_id", false);
 | 
  
    | 146 | }
 | 
  
    | 147 | 
 | 
  
    | 148 | ?>
 |