';
}
private function sanitizeStr($str) {
$str = trim($str);
$str = str_replace("&","&",$str);
$str = str_replace('"','"',$str);
$str = str_replace("<","<",$str);
$str = str_replace(">",">",$str);
return $str;
}
//##############################################
// GET MAX STR LENGTH FROM ARRAY
//##############################################
private function getMaxStrLen($array) {
$maxLen = 0;
foreach ($array AS $str) {
$thisLen = strlen($str);
if ($thisLen > $maxLen)
$maxLen = $thisLen;
}
return $maxLen;
}
//##############################################
// GET FILE/FOLDER NAME
//##############################################
private function getFileFromPath($str) {
$str = preg_replace("/^(.)+\//","",$str);
$str = preg_replace("/^~/","",$str);
return $str;
}
//##############################################
// PARENT OPEN FOLDER
//##############################################
public function parentOpenFolder() {
return "";
}
private function replaceTilde($str) {
$str = str_replace("~","/",$str);
$str = str_replace("//","/",$str);
return $str;
}
public function displayFtpHistory() {
$return = '
';
return $return;
}
private function getFtpRawList($folder_path) {
global $lang_folder_cant_access;
if ($this->loggedIn === true) {
$isError=0;
if (!@ftp_chdir($this->ftpConnection, $folder_path)) {
if ($this->checkFirstCharTilde($folder_path) == 1) {
if (!@ftp_chdir($this->ftpConnection, $this->replaceTilde($folder_path))) {
$this->recordFileError("folder",$folder_path,$lang_folder_cant_access);
$isError=1;
}
} else {
$this->recordFileError("folder",$folder_path,$lang_folder_cant_access);
$isError=1;
}
}
if ($isError == 0) {
return ftp_rawlist($this->ftpConnection, ".");
}
}
return false;
}
//##############################################
// CHECK FIRST CHAR IS TILDE
//##############################################
private function checkFirstCharTilde($str) {
return (substr($str,0,1) == "~") ? 1 : 0;
}
//##############################################
// RECORD FILE/FOLDER ERROR
//##############################################
private function recordFileError($str,$file_name,$error) {
$_SESSION["monstaftp"][$this->serverID]["errors"][] = str_replace("[".$str."]","
".$file_name."",$error);
}
private function getFtpColumnSpan($sort,$name) {
global $ui;
// Check current column
$ord = ($ui->w('sort', 1, 'post') == $sort and $ui->w('ord', 4, 'post') == 'desc') ? 'asc' : 'desc';
return "
serverID]["dir_current"])."&sort=".$sort."&ord=".$ord."')\" class=\"cursorPointer\">".$name."";
}
public function displayFiles() {
global $lang_table_name, $lang_table_size, $lang_table_date, $lang_table_time;
$ftp_rawlist = $this->getFtpRawList($_SESSION["monstaftp"][$this->serverID]["dir_current"]);
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# FOLDER/FILES TABLE HEADER
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$return = "
";
return $return;
}
###############################################
# CREATE FILE/FOLDER ARRAY FOR LINUX
###############################################
private function createFileFolderArrayLin($ftp_rawlist, $type) {
global $ui;
// set and correct to avoid php notice
$foldAllAr = false;
$linkAllAr = false;
$fileAllAr = false;
if (!is_array($ftp_rawlist)) {
$ftp_rawlist = (array) $ftp_rawlist;
}
// Go through array of files/folders
foreach($ftp_rawlist AS $ff) {
// Reset values
$time="";
$year="";
// Split up array into values
$ff = preg_split("/[\s]+/", $ff, 9);
$perms = $ff[0];
if (!isset($ff[2])) {
continue;
}
$user = $ff[2];
$group = $ff[3];
$size = $ff[4];
$month = $ff[5];
$day = $ff[6];
$file = $ff[8];
// Check if file starts with a dot
$dot_prefix = 0;
if (preg_match("/^\.+/",$file) && $_SESSION["monstaftp"][$this->serverID]["interface"] == "bas") {
$dot_prefix = 1;
}
if ($file != "." && $file != ".." && $dot_prefix == 0) {
// Where the last mod date is the previous year, the year will be displayed in place of the time
if (preg_match("/:/",$ff[7]))
$time = $ff[7];
else
$year = $ff[7];
// Set date
$date = $this->formatFtpDate($day,$month,$year);
// Reset user and group
if ($user == "0")
$user = "-";
if ($group == "0")
$group = "-";
// Add folder to array
if ($this->getFileType($perms) == "d") {
$foldAllAr[] = $file."|d|".$date."|".$time."|".$user."|".$group."|".$perms;
$foldNameAr[] = $file;
$foldDateAr[] = $date;
$foldTimeAr[] = $time;
$foldUserAr[] = $user;
$foldGroupAr[] = $group;
$foldPermsAr[] = $perms;
}
// Add link to array
if ($this->getFileType($perms) == "l") {
$linkAllAr[] = $file."|l|".$date."|".$time."|".$user."|".$group."|".$perms;
$linkNameAr[] = $file;
$linkDateAr[] = $date;
$linkTimeAr[] = $time;
$linkUserAr[] = $user;
$linkGroupAr[] = $group;
$linkPermsAr[] = $perms;
}
// Add file to array
if ($this->getFileType($perms) == "f") {
$fileAllAr[] = $file."|".$size."|".$date."|".$time."|".$user."|".$group."|".$perms;
$fileNameAr[] = $file;
$fileSizeAr[] = $size;
$fileDateAr[] = $date;
$fileTimeAr[] = $time;
$fileUserAr[] = $user;
$fileGroupAr[] = $group;
$filePermsAr[] = $perms;
}
}
}
// Check there are files and/or folders to display
if (is_array($foldAllAr) || is_array($linkAllAr) || is_array($fileAllAr)) {
// Set sorting order
if ($ui->w('sort', 1, 'post') == "")
$sort = "n";
else
$sort = $ui->w('sort', 1, 'post');
if ($ui->w('ord', 4, 'post') == "")
$ord = "asc";
else
$ord = $ui->w('ord', 4, 'post');
// Return folders
if ($type == "folders") {
if (is_array($foldAllAr)) {
// Set the folder arrays to sort
if ($sort == "n") $sortAr = $foldNameAr;
if ($sort == "d") $sortAr = $foldDateAr;
if ($sort == "t") $sortAr = $foldTimeAr;
if ($sort == "u") $sortAr = $foldUserAr;
if ($sort == "g") $sortAr = $foldGroupAr;
if ($sort == "p") $sortAr = $foldPermsAr;
// Multisort array
if (is_array($sortAr)) {
if ($ord == "asc")
array_multisort($sortAr, SORT_ASC, $foldAllAr);
else
array_multisort($sortAr, SORT_DESC, $foldAllAr);
}
// Format and display folder content
return $this->getFileListHtml($foldAllAr, "
");
}
}
// Return links
if ($type == "links") {
if (is_array($linkAllAr)) {
// Set the folder arrays to sort
if ($sort == "n") $sortAr = $linkNameAr;
if ($sort == "d") $sortAr = $linkDateAr;
if ($sort == "t") $sortAr = $linkTimeAr;
if ($sort == "u") $sortAr = $linkUserAr;
if ($sort == "g") $sortAr = $linkGroupAr;
if ($sort == "p") $sortAr = $linkPermsAr;
// Multisort array
if (is_array($sortAr)) {
if ($ord == "asc")
array_multisort($sortAr, SORT_ASC, $linkAllAr);
else
array_multisort($sortAr, SORT_DESC, $linkAllAr);
}
// Format and display folder content
return $this->getFileListHtml($linkAllAr, "
");
}
}
// Return files
if ($type == "files") {
if (is_array($fileAllAr)) {
// Set the folder arrays to sort
if ($sort == "n") $sortAr = $fileNameAr;
if ($sort == "s") $sortAr = $fileSizeAr;
if ($sort == "d") $sortAr = $fileDateAr;
if ($sort == "t") $sortAr = $fileTimeAr;
if ($sort == "u") $sortAr = $fileUserAr;
if ($sort == "g") $sortAr = $fileGroupAr;
if ($sort == "p") $sortAr = $filePermsAr;
// Multisort folders
if ($ord == "asc")
array_multisort($sortAr, SORT_ASC, $fileAllAr);
else
array_multisort($sortAr, SORT_DESC, $fileAllAr);
// Format and display file content
return $this->getFileListHtml($fileAllAr, "
");
}
}
}
return '';
}
###############################################
# CREATE FILE/FOLDER ARRAY FOR WINDOWS
###############################################
private function createFileFolderArrayWin($ftp_rawlist,$type) {
global $ui;
$foldAllAr = false;
$fileAllAr = false;
if (!is_array($ftp_rawlist)) {
$ftp_rawlist = (array) $ftp_rawlist;
}
// Go through array of files/folders
foreach($ftp_rawlist AS $ff) {
// Split up array into values
$ff = preg_split("/[\s]+/",$ff,4);
$date = $ff[0];
$time = $ff[1];
$size = $ff[2];
$file = $ff[3];
if ($size == "
") $size = "d";
// Format date
$day = substr($date,3,2);
$month = substr($date,0,2);
$year = substr($date,6,2);
$date = $this->formatFtpDate($day,$month,$year);
// Format time
$time = $this->formatWinFtpTime($time);
// Add folder to array
if ($size == "d") {
$foldAllAr[] = $file."|d|".$date."|".$time."|||";
$foldNameAr[] = $file;
$foldDateAr[] = $date;
$foldTimeAr[] = $time;
}
// Add file to array
if ($size != "d") {
$fileAllAr[] = $file."|".$size."|".$date."|".$time."|||";
$fileNameAr[] = $file;
$fileSizeAr[] = $size;
$fileDateAr[] = $date;
$fileTimeAr[] = $time;
}
}
// Check there are files and/or folders to display
if (is_array($foldAllAr) || is_array($fileAllAr)) {
// Set sorting order
if ($ui->w('sort', 1, 'post') == "")
$sort = "n";
else
$sort = $ui->w('sort', 1, 'post');
if ($ui->w('ord', 4, 'post') == "")
$ord = "asc";
else
$ord = $ui->w('ord', 4, 'post');
// Return folders
if ($type == "folders") {
if (is_array($foldAllAr)) {
// Set the folder arrays to sort
if ($sort == "n") $sortAr = $foldNameAr;
if ($sort == "d") $sortAr = $foldDateAr;
if ($sort == "t") $sortAr = $foldTimeAr;
// Multisort array
if (is_array($sortAr)) {
if ($ord == "asc")
array_multisort($sortAr, SORT_ASC, $foldAllAr);
else
array_multisort($sortAr, SORT_DESC, $foldAllAr);
}
// Format and display folder content
return $this->getFileListHtml($foldAllAr, "");
}
}
// Return files
if ($type == "files") {
if (is_array($fileAllAr)) {
// Set the folder arrays to sort
if ($sort == "n") $sortAr = $fileNameAr;
if ($sort == "s") $sortAr = $fileSizeAr;
if ($sort == "d") $sortAr = $fileDateAr;
if ($sort == "t") $sortAr = $fileTimeAr;
// Multisort folders
if ($ord == "asc")
array_multisort($sortAr, SORT_ASC, $fileAllAr);
else
array_multisort($sortAr, SORT_DESC, $fileAllAr);
// Format and display file content
return $this->getFileListHtml($fileAllAr, "");
}
}
}
return '';
}
###############################################
# FORMAT FTP DATE
###############################################
private function formatFtpDate($day,$month,$year) {
if (strlen($day) == 1)
$day = "0".$day;
if ($year == "")
$year = date("Y");
if (strlen($year) == 2) {
// To avoid a future Y2K problem, check the first two digits of year on Windows
if ($year > 00 && $year < 99)
$year = substr(date("Y"),0,2).$year;
else
$year = (substr(date("Y"),0,2)-1).$year;
}
if ($month == "Jan") $month = "01";
if ($month == "Feb") $month = "02";
if ($month == "Mar") $month = "03";
if ($month == "Apr") $month = "04";
if ($month == "May") $month = "05";
if ($month == "Jun") $month = "06";
if ($month == "Jul") $month = "07";
if ($month == "Aug") $month = "08";
if ($month == "Sep") $month = "09";
if ($month == "Oct") $month = "10";
if ($month == "Nov") $month = "11";
if ($month == "Dec") $month = "12";
$date = $year.$month.$day;
return $date;
}
###############################################
# FORMAT WINDOWS FTP TIME
###############################################
private function formatWinFtpTime($time) {
$h = substr($time,0,2);
$m = substr($time,3,2);
$am_pm = substr($time,5,2);
if ($am_pm == "PM")
$h = $h + 12;
$time = $h.":".$m;
return $time;
}
###############################################
# GET FILE TYPE
###############################################
function getFileType($perms) {
if (substr($perms,0,1) == "d")
return "d"; // directory
if (substr($perms,0,1) == "l")
return "l"; // link
if (substr($perms,0,1) == "-")
return "f"; // file
return '';
}
###############################################
# GET FTP COLUMN SPAN
###############################################
private function getFileListHtml($array,$image) {
global $ui;
$html = '';
if ($this->trCount == 1)
$this->trCount=1;
else
$this->trCount=0;
$i=1;
foreach ($array AS $file) {
list($file,$size,$date,$time,$user,$group,$perms) = explode("|",$file);
$action = '';
// Folder check (lin/win)
if ($size == "d")
$action = "folderAction";
// Link check (lin/win)
if ( $size == "l")
$action = "linkAction";
// File check (lin/win)
if ($size != "d" && $size != "l")
$action = "fileAction";
// Set file path
if ($size == "l") {
$file_path = $this->getPathFromLink($file);
$file = preg_replace("/ -> .*/","",$file);
} else {
if ($_SESSION["monstaftp"][$this->serverID]["dir_current"] == "/")
$file_path = "/".$file;
else
$file_path = $_SESSION["monstaftp"][$this->serverID]["dir_current"]."/".$file;
}
if ($this->trCount == 0) {
$trClass = "trBg0";
$this->trCount=1;
} else {
$trClass = "trBg1";
$this->trCount=0;
}
/**
// Check for checkbox check (only if action button clicked"
if ($ui->w('ftpAction', 255, 'post') != "") {
if (isset($_SESSION["monstaftp"][$this->serverID]["clipboard_rename"]) and sizeof($_SESSION["monstaftp"][$this->serverID]["clipboard_rename"]) > 1 and in_array($file,$_SESSION["monstaftp"][$this->serverID]["clipboard_rename"]))
$checked = "checked";
else
$checked = "";
} else {
$checked = "";
}
**/
// Set the date
if ($this->dateFormatUsa == 1)
$date = substr($date,4,2)."/".substr($date,6,2)."/".substr($date,2,2);
else
$date = substr($date,6,2)."/".substr($date,4,2)."/".substr($date,2,2);
$html .= ""."\n";
/** $html .= ""."\n";
if ($action != "linkAction")
$html .= ""."\n";
$html .= " | "."\n";**/
$html .= "".$image." | "."\n";
$html .= ""."\n";
// Display Folders
if ($action == "folderAction")
$html .= ""."\n";
// Display Links
if ($action == "linkAction")
$html .= ""."\n";
// Display files
if ($action == "fileAction")
$html .= "actionTarget."&dl=".rawurlencode($file_path)."\" id=\"file".$i."\" target=\"ajaxIframe\" onContextMenu=\"selectFile(this.id,1); displayContextMenu(event,'".rawurlencode($file_path)."','',".$this->assignWinLinNum().")\" draggable=\"true\" onDragStart=\"selectFile(this.id,1); setDragFile('".rawurlencode($file_path)."','')\">".$this->sanitizeStr($file).""."\n";
$html .= " | "."\n";
$html .= "".$this->formatFileSize($size)." | "."\n";
$html .= "".$date." | "."\n";
$html .= "".$time." | "."\n";
$html .= "
"."\n";
$i++;
}
return $html;
}
###############################################
# GET PATH FROM LINK
###############################################
private function getPathFromLink($file) {
$file_path = preg_replace("/.* -> /","",$file);
// Check if path is not absolute
if (substr($file_path,0,1) != "/") {
// Count occurances of ../
$i=0;
while (substr($file_path,0,3) == "../") {
$i++;
$file_path = substr($file_path,3,strlen($file_path));
}
$dir_current = $_SESSION["monstaftp"][$this->serverID]["dir_current"];
// Get the real parent
for ($j=0;$j<$i;$j++) {
$path_parts = pathinfo($dir_current);
$dir_current = $path_parts['dirname'];
}
// Set the path
if ($dir_current == "/")
$file_path = "/".$file_path;
else
$file_path = $dir_current."/".$file_path;
}
if ($file_path == "~/")
$file_path = "~";
return $file_path;
}
//##############################################
// GET PARENT DIRECTORY
//##############################################
private function getParentDir() {
if ($_SESSION["monstaftp"][$this->serverID]["dir_current"] == "/") {
$parent = "/";
} else {
$path_parts = pathinfo($_SESSION["monstaftp"][$this->serverID]["dir_current"]);
$parent = $path_parts['dirname'];
}
return $parent;
}
###############################################
# FORMAT FILE SIZES
###############################################
private function formatFileSize($size) {
global $lang_size_b;
global $lang_size_kb;
global $lang_size_mb;
global $lang_size_gb;
if ($size == "d" || $size == "l") {
$size="";
} else {
if ($size < 1024) {
$size = round($size,2).' '. $lang_size_b;
} elseif ($size < (1024*1024)) {
$size = round(($size/1024),0).' '.$lang_size_kb;
} elseif ($size < (1024*1024*1024)) {
$size = round((($size/1024)/1024),0).' '.$lang_size_mb;
} elseif ($size < (1024*1024*1024*1024)) {
$size = round(((($size/1024)/1024)/1024),0).' '.$lang_size_gb;
}
}
return $size;
}
###############################################
# DISPLAY ERRORS
###############################################
public function displayErrors() {
global $lang_title_errors;
$sizeAr = sizeof($_SESSION["monstaftp"][$this->serverID]["errors"]);
$return = '';
if ($sizeAr > 0) {
$width = ($this->getMaxStrLen($_SESSION["monstaftp"][$this->serverID]["errors"]) * 10) + 30;
$height = sizeof($_SESSION["monstaftp"][$this->serverID]["errors"]) * 25;
$title = $lang_title_errors;
// Display pop-up
$return .= $this->displayPopupOpen(1,$width,$height,1,$title);
$errors = array_reverse($_SESSION["monstaftp"][$this->serverID]["errors"]);
foreach($errors AS $error) {
$return .= $error."
";
}
$vars = "&ftpAction=openFolder&resetErrorArray=1";
$return .=$this->displayPopupClose(1,$vars,0);
}
$_SESSION["monstaftp"][$this->serverID]["errors"] = array();
return $return;
}
//##############################################
// DISPLAY POP-UP FRAME OPEN
//##############################################
private function displayPopupOpen($resize,$width,$height,$isError,$title) {
global $ui;
// Set default sizes of exceeded
if ($resize == 1) {
if ($width < 400)
$width = 400;
if ($height > 400)
$height = 400;
}
// Center window
if ($ui->id('windowWidth', 255, 'post') > 0)
$left = round(($ui->id('windowWidth', 255, 'post') - $width) / 2 - 15); // -15 for H padding
else
$left = 250;
if ($ui->id('windowHeight', 255, 'post') > 0)
$top = round(($ui->id('windowHeight', 255, 'post') - $height) / 2 - 50);
else
$top = 250;
$return = "";
$return .= "";
$return .= "
";
return $return;
}
public function divClose() {
return ' ';
}
###############################################
# DISPLAY IFRAME
###############################################
public function displayAjaxIframe() {
return '