';
$type_arrow = '';
} else {
if ($sort_dir == 'asc') {
$type_sort_dir = 'desc';
} else {
$type_sort_dir = 'asc';
}
$name_sort_dir = 'asc';
$name_arrow = '';
$type_arrow = '';
}
// make sure its not possible to put anything malicious in the return function
if (isset ($_REQUEST['return_function'])) {
if (wp_return_function_ok($_REQUEST['return_function'])) {
$return_function = $_REQUEST['return_function'];
} else {
$return_function = '';
}
} else {
$return_function = '';
}
// init variables
$message = '';
$name2 = '';
$width = '';
$height = '';
$fsize = '';
//get the folder for us to look inside, we'll also check that there are no ./ or ../ so that we are only ever looking at folders below the $web_directory, I'm sure there is a more secure way to do this?
if (isset ($_GET['folder']) ? $_GET['folder'] : '') {
if (wp_dir_name_ok($_GET['folder'])) {
$directory = $file_directory.$_GET['folder'];
$folderpath = $_GET['folder'];
} else {
$directory = $file_directory;
$folderpath = '';
}
} elseif (isset ($_POST['folder']) ? $_POST['folder'] : '') {
if (wp_dir_name_ok($_POST['folder'])) {
$directory = $file_directory.$_POST['folder'];
$folderpath = $_POST['folder'];
} else {
$directory = $file_directory;
$folderpath = '';
}
} else {
$directory = $file_directory;
$folderpath = '';
}
// check that it exists
if (!file_exists ($directory)) {
image_exit('Warning: this directory does not exist: '.$directory.'. Check that you have set IMAGE_FILE_DIRECTORY correctly in config.php. If you are using the set_img_dir function check that the you have set the $trusted_directories array correctly.');
}
if ($folderpath != '') {
if (substr ($folderpath, strlen ($folderpath) - 1) != '/') {
$folderpath.='/';
}
}
if (substr ($directory, strlen ($directory) - 1) != '/') {
$directory.='/';
}
// query strings
$query_string = '?in_wp='.$in_wp.'&return_function='.$return_function.'&lang='.$lang_include.'&folder='.$folderpath.'&instance_img_dir='.$instance_img_dir.'&sort_by='.$sort_by.'&sort_dir='.$sort_dir;
$query_inputs = '
';
///////////////////
// Functions ... //
///////////////////
function image_exit($message) {
global $lang;
echo '
'.$lang['titles']['image'].'
'; ?>
'.$message.'
';
exit;
}
function display_folders () {
global $directory, $folderpath, $lang, $count, $query_string, $rename_directories, $delete_directories, $web_directory, $rename_files, $delete_files, $sort_by, $sort_dir;
// build array of data, sort the array, loop through building the list
$folderlist = wp_get_folders_in_directory($directory, $sort_by, $sort_dir);
$str = '';
$num = count($folderlist);
for ($i=0; $i<$num; $i++) {
$foldername = $folderlist[$i]['name'];
if (!wp_dir_name_ok($foldername)) {
continue;
}
$count += 1;
$str .= "
';
}
}
// upload files
if (isset($_FILES['image_field']) ? $_FILES['image_field'] : '') {
if (is_uploaded_file($_FILES['image_field']['tmp_name'])) {
$extension = strrchr(strtolower($_FILES['image_field']['name']),'.');
// check filetype against accepted files
if (!wp_extension_ok($extension, $image_types)) {
image_exit ('
');
break;
}
if ($_FILES['image_field']['size'] >= $max_file_size) {
image_exit ('
');
} else {
list ($width, $height) = @getimagesize($_FILES['image_field']['tmp_name']);
if (($width > $max_image_width) || ($height > $max_image_height)) {
image_exit ('
');
} else {
$name=$_FILES['image_field']['name'];
// somepeople like to spit out an error if file have bad characters, I prefer to quetly rename their file.
$name = str_replace( array('/','\\','?','&','%','#','~',':','<','>','*','+','@','"',"'",'|',"\r","\n","\t") , '', $name);
$name = str_replace(' ', '_', $name);
if (empty($name)) {
$name = 'Untitled'.$extension;
}
$just_file_name = $name;
if ($name != $_FILES['image_field']['name']) {
$extra_message = wp_var_replace($lang['but_was_renamed'],array('name'=>$name));
} else {
$extra_message = '';
}
//used later to populate the dialoge with the image they have just uploaded:
$name2 = $folderpath.$name;
$fsize = wp_convert_fsize($_FILES['image_field']['size']);
$name=$directory.$name;
if (file_exists($name)) {
if ($overwrite) {
@move_uploaded_file($_FILES['image_field']['tmp_name'], $name.'.TEMP');
if (defined('FILE_CHMOD_MODE')) {
if (FILE_CHMOD_MODE) {
@chmod($name, FILE_CHMOD_MODE);
}
}
image_exit ('
');
} else {
image_exit ('
');
}
} elseif (@move_uploaded_file($_FILES['image_field']['tmp_name'], $name)) {
// make sure we will be able to delete and re-name this file later
if (defined('FILE_CHMOD_MODE')) {
if (FILE_CHMOD_MODE) {
@chmod($name, FILE_CHMOD_MODE);
}
}
$message= '