function net2ftp_module_printBody()
{
// --------------
// This function prints the browse screen ($state2=="main") or the directory popup screen ($state2=="popup")
// For the browse screen ($state2=="main"), 2 template files are called
// --------------
// -------------------------------------------------------------------------
// Global variables
// -------------------------------------------------------------------------
global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
// -------------------------------------------------------------------------
// Check if the directory name contains \' and if it does, print an error message
// Note: these directories cannot be browsed, but can be deleted
// -------------------------------------------------------------------------
// if (strstr($directory, "\'") != false) {
// $errormessage = __("Directories with names containing \' cannot be displayed correctly. They can only be deleted. Please go back and select another subdirectory.");
// setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
// return false;
// }
// -------------------------------------------------------------------------
// Variables
// With status update if $state2=="main"
// -------------------------------------------------------------------------
// ------------------------------------
// Open connection
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
setStatus(2, 10, __("Connecting to the FTP server"));
}
$conn_id = ftp_openconnection();
if ($net2ftp_result["success"] == false) {
return false;
}
// ------------------------------------
// Get raw list of directories and files; parse the raw list and return a nice list
// This function may change the current $directory; a warning message is returned in that case
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
setStatus(4, 10, __("Getting the list of directories and files"));
}
$list = ftp_getlist($conn_id, $net2ftp_globals["directory"]);
if ($net2ftp_result["success"] == false) {
return false;
}
// ------------------------------------
// Close connection
// ------------------------------------
ftp_closeconnection($conn_id);
// ------------------------------------
// Sort the list
// ------------------------------------
$list_directories = sort_list($list["directories"]);
$list_files = sort_list($list["files"]);
$list_symlinks = sort_list($list["symlinks"]);
$list_unrecognized = sort_list($list["unrecognized"]);
$warning_directory = $list["stats"]["warnings"];
$directory = $list["stats"]["newdirectory"];
$directory_html = htmlEncode2($directory);
$directory_url = urlEncode2($directory);
$directory_js = javascriptEncode2($directory);
$updirectory = upDir($directory);
$updirectory_html = htmlEncode2($updirectory);
$updirectory_url = urlEncode2($updirectory);
$updirectory_js = javascriptEncode2($updirectory);
// ------------------------------------
// Calculate the list of HTTP URLs
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
$list_links_js = ftp2http($net2ftp_globals["directory"], $list_files, "no");
$list_links_url = ftp2http($net2ftp_globals["directory"], $list_files, "yes");
}
// ------------------------------------
// Consumption message
// ------------------------------------
$warning_consumption = "";
if (checkConsumption() == false) {
$warning_consumption .= "<b>" . __("Daily limit reached: you will not be able to transfer data") . "</b><br /><br />\n";
$warning_consumption .= __("In order to guarantee the fair use of the web server for everyone, the data transfer volume and script execution time are limited per user, and per day. Once this limit is reached, you can still browse the FTP server but not transfer data to/from it.") . "<br /><br />\n";
$warning_consumption .= __("If you need unlimited usage, please install net2ftp on your own web server.") . "<br />\n";
}
// ------------------------------------
// Browse message
// ------------------------------------
if ($net2ftp_settings["message_browse"] != "" && $net2ftp_settings["message_browse"] != "Setting message_browse does not exist") {
$warning_message = $net2ftp_settings["message_browse"];
}
// ------------------------------------
// Directory tree
// ------------------------------------
$directory_exploded = explode("/", stripDirectory($directory));
if ($directory != "/" && checkAuthorizedDirectory("/") == true) {
$directory_tree = "<a href=\"javascript:submitBrowseForm('/','','browse','main');\">root</a> ";
} else {
$directory_tree = "root ";
}
$directory_goto = "";
for ($i = 0; $i < sizeof($directory_exploded) - 1; $i++) {
$directory_goto = glueDirectories($directory_goto, $directory_exploded[$i]);
$directory_goto_url = urlEncode2($directory_goto);
if (checkAuthorizedDirectory($directory_goto) == true) {
//.........这里部分代码省略.........
//.........这里部分代码省略.........
$searchoptions["modified_from"] = "";
}
if (isset($searchoptions["modified_to"]) == false) {
$searchoptions["modified_to"] = "";
}
// -------------------------------------------------------------------------
// Variables for all screens
// -------------------------------------------------------------------------
// Title
// See below
// Form name, back and forward buttons
$formname = "FindstringForm";
$back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
$forward_onclick = "document.forms['" . $formname . "'].submit();";
// Next screen
$nextscreen = 2;
// -------------------------------------------------------------------------
// Variables for screen 1
// -------------------------------------------------------------------------
if ($net2ftp_globals["screen"] == 1) {
// Title
$title = __("Search directories and files");
// From and to dates
$tomorrow = date("Y-m-d", time() + 3600 * 24);
$oneweekago = date("Y-m-d", time() - 3600 * 24 * 7);
$modified_from = $oneweekago;
$modified_to = $tomorrow;
} elseif ($net2ftp_globals["screen"] == 2) {
// Title
$title = __("Search results");
// Check if $searchoptions["string"] is a valid string
if (is_string($searchoptions["string"]) == false) {
$errormessage = __("Please enter a valid search word or phrase.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
// Check if $searchoptions["filename"] is a valid filename with a possible wildcard character *
if ($searchoptions["filename"] != "" && preg_match("/^[a-zA-Z0-9_ *\\.-]*\$/", $searchoptions["filename"]) == 0) {
$errormessage = __("Please enter a valid filename.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
// Check if $searchoptions["size_from"] and $searchoptions["size_to"] are valid numbers
if ($searchoptions["size_from"] != "" && is_numeric($searchoptions["size_from"]) == false) {
$errormessage = __("Please enter a valid file size in the \"from\" textbox, for example 0.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
if ($searchoptions["size_to"] != "" && is_numeric($searchoptions["size_to"]) == false) {
$errormessage = __("Please enter a valid file size in the \"to\" textbox, for example 500000.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
// Check if $searchoptions["modified_from"] and $searchoptions["modified_to"] are valid dates
if ($searchoptions["modified_from"] != "" && preg_match("/^[0-9-]*\$/", $searchoptions["modified_from"]) == 0) {
$errormessage = __("Please enter a valid date in Y-m-d format in the \"from\" textbox.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
if ($searchoptions["modified_to"] != "" && preg_match("/^[0-9-]*\$/", $searchoptions["modified_to"]) == 0) {
$errormessage = __("Please enter a valid date in Y-m-d format in the \"to\" textbox.");
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
return false;
}
// ------------
// CONVERSIONS
// ------------
// Convert the wildcard character * in the filename by the wildcard .* that can be read by preg_match
// So this *.* becomes this .*..*
$searchoptions["filename"] = str_replace("*", ".*", $searchoptions["filename"]);
// Convert the mtime to a unix timestamp
$searchoptions["modified_from"] = strtotime($searchoptions["modified_from"]);
$searchoptions["modified_to"] = strtotime($searchoptions["modified_to"]);
// Open connection
setStatus(2, 10, __("Connecting to the FTP server"));
$conn_id = ftp_openconnection();
if ($net2ftp_result["success"] == false) {
return false;
}
// Find the files
$result = array();
setStatus(4, 10, __("Searching the files..."));
$result = ftp_processfiles("findstring", $conn_id, $net2ftp_globals["directory"], $list, $searchoptions, $result, 0);
if ($net2ftp_result["success"] == false) {
return false;
}
// Close connection
ftp_closeconnection($conn_id);
if (sizeof($result) == 0) {
$net2ftp_output["findstring"][] = __("The word <b>%1\$s</b> was not found in the selected directories and files.", $searchoptions["string"]);
} else {
$net2ftp_output["findstring"][] = __("The word <b>%1\$s</b> was found in the following files:", $searchoptions["string"]);
}
}
// end if
// -------------------------------------------------------------------------
// Print the output
// -------------------------------------------------------------------------
require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
function net2ftp_module_printBody()
{
// --------------
// This function prints the unzip screen
// --------------
// -------------------------------------------------------------------------
// Global variables
// -------------------------------------------------------------------------
global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result, $net2ftp_output;
if (isset($_POST["list"]) == true) {
$list = getSelectedEntries($_POST["list"]);
} else {
$list = "";
}
// -------------------------------------------------------------------------
// Variables for all screens
// -------------------------------------------------------------------------
// Title
$title = __("Unzip archives");
// Form name, back and forward buttons
$formname = "UnzipForm";
$back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();";
$forward_onclick = "document.forms['" . $formname . "'].submit();";
// -------------------------------------------------------------------------
// Variables for screen 1
// -------------------------------------------------------------------------
if ($net2ftp_globals["screen"] == 1) {
// Next screen
$nextscreen = 2;
} elseif ($net2ftp_globals["screen"] == 2) {
$net2ftp_output["unzip"] = array();
$net2ftp_output["ftp_unziptransferfiles"] = array();
// ---------------------------------------
// Initialize variables
// ---------------------------------------
$moved_ok = 0;
// Index of the archives that have been treated successfully
$moved_notok = 0;
// Index of the archives that have been treated unsuccessfully
// ---------------------------------------
// Open connection to the FTP server
// ---------------------------------------
setStatus(2, 10, __("Connecting to the FTP server"));
$conn_id = ftp_openconnection();
if ($net2ftp_result["success"] == false) {
return false;
}
// ---------------------------------------
// Get the archives from the FTP server
// ---------------------------------------
for ($i = 1; $i <= $list["stats"]["files"]["total_number"]; $i = $i + 1) {
// Set the status
$message = __("Getting archive %1\$s of %2\$s from the FTP server", $i, $list["stats"]["files"]["total_number"]);
setStatus($i, $list["stats"]["files"]["total_number"], $message);
// Get the archive from the FTP server
$localtargetdir = $net2ftp_globals["application_tempdir"];
$localtargetfile = $list["files"][$i]["dirfilename"] . ".txt";
$remotesourcedir = $net2ftp_globals["directory"];
$remotesourcefile = $list["files"][$i]["dirfilename"];
$ftpmode = ftpAsciiBinary($list["files"][$i]["dirfilename"]);
$copymove = "copy";
ftp_getfile($conn_id, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove);
if ($net2ftp_result["success"] == false) {
setErrorVars(true, "", "", "", "");
$net2ftp_output["unzip"][] = __("Unable to get the archive <b>%1\$s</b> from the FTP server", htmlEncode2($list["files"][$i]["dirfilename"]));
$moved_notok = $moved_notok + 1;
continue;
}
// Register the temporary file
registerTempfile("register", glueDirectories($localtargetdir, $localtargetfile));
// Enter the temporary filename and the real filename in the array
$moved_ok = $moved_ok + 1;
$acceptedArchivesArray[$moved_ok]["name"] = $list["files"][$i]["dirfilename"];
$acceptedArchivesArray[$moved_ok]["tmp_name"] = glueDirectories($localtargetdir, $localtargetfile);
$acceptedArchivesArray[$moved_ok]["targetdirectory"] = $list["files"][$i]["targetdirectory"];
$acceptedArchivesArray[$moved_ok]["use_folder_names"] = $list["files"][$i]["use_folder_names"];
}
// end for
// ---------------------------------------
// Unzip archives and transfer the files (create subdirectories if needed)
// ---------------------------------------
if (isset($acceptedArchivesArray) == true && sizeof($acceptedArchivesArray) > 0) {
ftp_unziptransferfiles($acceptedArchivesArray);
$net2ftp_output["unzip"] = $net2ftp_output["unzip"] + $net2ftp_output["ftp_unziptransferfiles"];
if ($net2ftp_result["success"] == false) {
return false;
}
}
// ---------------------------------------
// Close the connection to the FTP server
// ---------------------------------------
ftp_closeconnection($conn_id);
}
// end elseif
// -------------------------------------------------------------------------
// Print the output
// -------------------------------------------------------------------------
require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php";
}
请发表评论