Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 6866 lines (6241 sloc) 219.951 kb
<?php
/*
Author : David Wan
Contact : inventordavid AT yahoo.com
david AT simpledirectorylisting.net
Application Name : Simple Directory Listing
Version : 2.1 beta
Last Modified : 2008-08-02
License : GNU GENERAL PUBLIC LICENSE Version 3
Web Site : http://simpledirectorylisting.net/
http://sourceforge.net/projects/simpledirectory/
Copyright. All rights reserved.
*/
?>
<?php
//------------------------------------------------------------------------------
// CONFIG
//------------------------------------------------------------------------------
// added in 2.1;
// Service can be shuted down by setting it to false.(true or false)
define("SYSTEM_ON" , true);
// added in 2.0;
// Admin mode can be shuted down by setting it to false.(true or false)
define("ADMIN_MODE_ON" , true);
// added in 2.0;
// To allow access to public, set it to false.(true or false)
define("ADMIN_MODE_NEEDS_LOGIN" , true);
// added in 2.0;
// Login Name(a string)
define("ADMIN_MODE_LOGIN_NAME" , "admin");
// added in 2.0;
// Password encoded in sha1 format(a string) or raw password
define("ADMIN_MODE_PASSWORD" , "password");
// added in 2.0; removed in 2.1, see PASSWORD_FORMAT;
// "RAW", "SHA1"
//define("ADMIN_MODE_PASSWORD_FORMAT" , "RAW");
// added in 2.0;
// "CUSTOM_ROOT", "CURRENT_WORKING_DIR", "DOCUMENT_ROOT" or "SERVER_ROOT"
define("ADMIN_MODE_VIRTUAL_ROOT" , "DOCUMENT_ROOT");
// added in 2.0;
// An absolute path or null(a string or null)
define("ADMIN_MODE_CUSTOM_VIRTUAL_ROOT" , null);
// added in 2.0;
// A relative path or null(a string or null)
define("ADMIN_MODE_PERMITTED_DIR" , null);
// added in 2.1;
// User mode can be shuted down by setting it to false.(true or false)
define("USER_MODE_ON" , true);
// added in 2.1;
// To allow access to public, set it to false.(true or false)
define("USER_MODE_NEEDS_LOGIN" , false);
// added in 2.1;
// Login Name(a string)
define("USER_MODE_LOGIN_NAME" , "user");
// added in 2.1;
// Password encoded in sha1 format(a string) or raw password
define("USER_MODE_PASSWORD" , "password");
// added in 2.1;
// "CUSTOM_ROOT", "CURRENT_WORKING_DIR", "DOCUMENT_ROOT" or "SERVER_ROOT"
define("USER_MODE_VIRTUAL_ROOT" , "DOCUMENT_ROOT");
// added in 2.1;
// An absolute path or null(a string or null)
define("USER_MODE_CUSTOM_VIRTUAL_ROOT" , null);
// added in 2.1;
// A relative path or null(a string or null)
define("USER_MODE_PERMITTED_DIR" , null);
// added in 2.0;
// Font size in pixel(a number)
define("FONT_SIZE" , 15);
// added in 2.0;
// Enable/Disable Icon(true or false)
define("ICON_ON" , true);
// added in 2.0;
// Enable/Disable Image(true or false)
define("IMAGE_PASSTHRU_ON" , true);
// added in 2.0;
// "AUTO", "PASSTHRU_ONLY", "URL_ONLY"
define("IMAGE_LOAD_TYPE" , "AUTO");
// added in 2.0;
// Language class(the name of a locale class)
define("LOCALE_CLASS" , "LocaleEnglishUS");
// added in 2.0;
// For OS that doesn't use utf-8 as internal encoding method(a string)
define("OS_ENCODING" , null);
// added in 2.1;
// "RAW", "SHA1"
define("PASSWORD_FORMAT" , "RAW");
// added in 2.0;
// Enable/Disable RSS(true or false)
define("RSS_ON" , true);
// added in 2.0;
// Enable/Disable SFS(true or false)
define("SFS_ON" , true);
// added in 2.0;
// Theme class(the name of a theme class)
define("THEME_CLASS" , "ThemeApache");
// added in 2.0;
// Enable/Disable thumbnail view(true or false)
define("THUMBNAIL_ON" , true);
// added in 2.0;
// Pixel width in pixel(a number)
define("THUMBNAIL_SIZE" , 120);
// added in 2.0;
// Name of your web site(a string)
define("META_WEB_SITE_NAME" , "My Web Site");
//------------------------------------------------------------------------------
// ADVANCED CONFIG
//------------------------------------------------------------------------------
// added in 2.0;
// Enable/Disable 'remember me'(true or false)
define("SAVE_LOGIN_ON" , false);
// added in 2.0;
// Dependent on SAVE_LOGIN_ON(in minute)
define("SESSION_CACHE_EXPIRE" , 1440);
// added in 2.0;
// php ini(string)
define("SESSION_SAVE_PATH" , null);
// added in 2.0;
// php ini(in secons)
define("SESSION_GC_MAXLIFETIME" , null);
// added in 2.1;
// The size(no. of chars) of an incorrect XML response.(an integer)
define("DEBUG_XML_RESPONSE_LENGTH" , 200);
// added in 2.1;
// Sets which PHP errors are reported. (null for using the value in php.ini)
define("DEBUG_ERROR_REPORTING_LEVEL" , E_ALL ^ E_NOTICE);
// added in 2.1;
// Enable/disable FTP Layer for admin/readonly mode
define("FTP_LAYER_ON" , false);
// added in 2.1;
// The FTP server address
define("FTP_LAYER_HOST" , "localhost");
// added in 2.1;
// The FTP PORT
define("FTP_LAYER_PORT" , 21);
// added in 2.1;
// The username of the FTP account
// SECURITY WARNING: Do no use the FTP account of "root" on your server
// SECURITY WARNING: Do not use FTP layer for production use
define("FTP_LAYER_USERNAME" , "username");
// added in 2.1;
// The password of the FTP account
// SECURITY WARNING: Do no use the FTP account of "root" on your server
// SECURITY WARNING: Do not use FTP layer for production use
define("FTP_LAYER_PASSWORD" , "password");
// added in 2.1;
// Enable/diable secure SSL-FTP connection
define("FTP_LAYER_SSL_ON" , false);
// added in 2.1;
// The absolute path of the home of the FTP account.
define("FTP_LAYER_PATH_ON_SERVER" , "/home/username/");
// set true to disable ajax loading, so that it is easy for bookmarking
define("DIRECTORY_LINK_ON" , true);
?>
<?php
//------------------------------------------------------------------------------
// Class name : Browser
//------------------------------------------------------------------------------
class Browser {
var $cwd;
var $cwdRelPath; // for non-js
var $fileManager;
var $moduleManager;
var $view;
function getFilesViewList($files, $isJavascript) {
$html = null;
if (count($files) === 0) {
$html .= "<center>" . text("NO FILES") . "</center>";
} else {
$html .= "<table class='browserFilesViewList' id='browserFiles'><tbody>";
foreach ($files as $fileIndex => $file) {
if ($file->absPath !== $_SERVER['SCRIPT_FILENAME']) {
$html .= "<tr class='fileViewList' id='$fileIndex'>";
$html .= "<td class='systemAttribute'><div id='systemFilename_$fileIndex'>{$file->basename}</div></td>";
$html .= "<td class='systemAttribute'><div id='systemRelPath_$fileIndex'>{$file->relPath}</div></td>";
$html .= "<td class='systemAttribute'><div id='systemUrl_$fileIndex'>{$file->url}</div></td>";
$html .= "<td class='systemAttribute'><div id='systemIsDir_$fileIndex'>{$file->isDir}</div></td>";
foreach ($this->moduleManager->attributes as $attribute) {
$html .= "<td>" . $attribute->getHtml($file, $fileIndex, $this->view, $isJavascript) . "</td>";
}
$html .= "<td class='browserCellFiller'></td>";
$html .= "</tr>";
}
}
$html .= "</tbody></table>";
}
return $html;
}
function getFilesViewThumbnail($files, $isJavascript) {
$html = null;
if (count($files) === 0) {
$html .= "<center>" . text("NO FILES") . "</center>";
} else {
$html .= "<div class='browserFilesViewThumbnail' id='browserFiles'>";
foreach ($files as $fileIndex=>$file) {
if ($file->absPath !== $_SERVER['SCRIPT_FILENAME']) {
$html .= "<div class='fileViewThumbnail' id='$fileIndex'>";
$html .= "<div class='thumbnailItemContainer'>";
$html .= "<div class='systemAttribute' id='systemFilename_$fileIndex'>{$file->basename}</div>";
$html .= "<div class='systemAttribute' id='systemRelPath_$fileIndex'>{$file->relPath}</div>";
$html .= "<div class='systemAttribute' id='systemUrl_$fileIndex'>{$file->url}</div>";
$html .= "<div class='systemAttribute' id='systemIsDir_$fileIndex'>{$file->isDir}</div>";
if ($file->isDir) {
$html .= "<div class='thumbnailItemImageContainer' title='$file->basename'>" .
"<a href='?cwdRelPath={$file->relPath}&view=$this->view' onclick='Sdl.browser.onClickThumbnailRedirect(event, \"$file->relPath\"); return false;'>" .
"<img alt='<" . text("DIR") . ">' class='thumbnailItemImageDir' onload='Sdl.Image.position(this);' src='?print=icon&icon=dir'> </a></div>";
} else {
$ext = strtolower($file->extension);
if ($ext === "gif" || $ext === "jpg" || $ext === "jpeg" || $ext === "png" || $ext === "wbmp") {
If (IMAGE_LOAD_TYPE === "AUTO") {
if ($file->url) {$href = "url";}
else {$href = "passthru";}
} else if (IMAGE_LOAD_TYPE === "PASSTHRU_ONLY") {
$href = "passthru";
} else { // URL_ONLY
if ($file->url) {$href = "url";}
else {$href = "";}
}
$img = "<img alt='<" . text("IMG") . ">' onload='Sdl.Image.position(this);' src='?print=thumbnail&relPath=$file->relPath'>";
} else {
If (IMAGE_LOAD_TYPE === "AUTO") {
if ($file->url) {$href = "url";}
else {$href = "passthru";}
} else if (IMAGE_LOAD_TYPE === "PASSTHRU_ONLY") {
$href = "passthru";
} else { // URL_ONLY
if ($file->url) {$href = "url";}
else {$href .= "";}
}
$img = "<img alt='<" . text("UNKNOWN") . ">' class='thumbnailItemImageUnknown' onload='Sdl.Image.position(this);' src='?print=icon&icon=unknown'>";
}
if ($href === "passthru") {
if (IMAGE_PASSTHRU_ON) {$href = "href='?print=image&relPath=$file->relPath' onclick='Sdl.image.onClickShowByRelPath(event, \"$file->relPath\"); return false;'";}
else {$href = "";}
} else if ($href === "url") {
$href = "href='$file->url' onclick='Sdl.image.onClickShowByUrl(event, \"$file->url\"); return false;'";
}
$html .= "<div class='thumbnailItemImageContainer' title='$file->basename'><a $href>$img </a></div>";
}
foreach ($this->moduleManager->attributes as $attribute) {
$html .= "<div>" . $attribute->getHtml($file, $fileIndex, $this->view, $isJavascript) . "</div>";
}
$html .= "</div>";
$html .= "</div>";
}
}
$html .= "</div>";
// For IE6
// For Opera 9.21. Functions would flow through thumbnail view otherwise.
$html .= "<div style='clear:both'></div>";
}
return $html;
}
function getFunctions() {
$html = null;
if (count($this->moduleManager->functions) > 0) {
foreach ($this->moduleManager->functions as $function) {
//$function->fileManager = $this->fileManager;
//$function->moduleManager = $this->moduleManager;
$html .= "<div class='function'>" . $function->getHtml($this->cwdRelPath, $this->view) . "</div>";
}
}
// For IE6
// For Opera 9.21 though this part hasn't shown any problem yet.
$html .= "<div style='clear:both'></div>";
return $html;
}
function getHeader() {
$html = null;
$html .= "<table id='browserHeaders'><tbody><tr>";
$html .= "<td class='systemAttribute'><div>systemFilename</div></td>";
$html .= "<td class='systemAttribute'><div>systemRelPath</div></td>";
$html .= "<td class='systemAttribute'><div>systemUrl</div></td>";
$html .= "<td class='systemAttribute'><div>systemIsDir</div></td>";
foreach ($this->moduleManager->attributes as $attribute) {
$html .= "<td>" . $attribute->getHeader() . "</td>";
}
$html .= "<td class='browserCellFiller'><div class='browserScrollBarFiller'></div></td>";
$html .= "</tr></tbody></table>";
return $html;
}
function getHtml() {
if (isset($_GET["cwdRelPath"])) {$this->cwdRelPath = $_GET["cwdRelPath"];}
else {$this->cwdRelPath = $this->user->permittedDirRelPath;}
if ($_GET["view"] === "list" || $_GET["view"] === "thumbnail") {$this->view = $_GET["view"];}
else {$this->view = "list";}
$functions = $this->getFunctions();
$header = $this->getHeader();
$systemFiles = $this->getSystemFiles();
$files = $this->getDirListing();
if (!$functions) {$separator2Display = "display:none;";}
$html = null;
$html .=
"
<div id='browserContainer'>
<div id='browser'>
<div id='browserDirListingContainer'>
<div id='browserDirListing'>
<div id='browserHeadersContainer'>
$header
<div id='browserHeadersMovableBar'></div>
</div>
<div id='broswerSeparator1Container'>
<div id='broswerSeparator1'><hr/></div>
<div id='broswerSeparator1MovableBar'></div>
</div>
<div id='browserSystemFilesContainer'>
$systemFiles
<div id='browserSystemFilesMovableBar'></div>
</div>
<div id='browserFilesContainer'>
<div id='browserFilesDiv'><noscript>$files</noscript></div>
<div id='browserFilesMovableBar'></div>
</div>
</div>
<div id='browserDirListingMovableBar'></div>
</div>
<div id='broswerSeparator2Container'>
<div id='broswerSeparator2' style='$separator2Display'><hr/></div>
<div id='broswerSeparator2MovableBar'></div>
</div>
<div id='browserFunctionsContainer'>
<div id='browserFunctions'>$functions</div>
<div id='browserFunctionsMovableBar'></div>
</div>
<div id='broswerSeparator3Container'>
<div id='broswerSeparator3'><hr/></div>
<div id='broswerSeparator3MovableBar'></div>
</div>
</div>
<div id='browserMovableBar'></div>
</div>
";
return $html;
}
function getSystemFiles() {
$parentCwdRelPath = dirname($this->cwdRelPath);
if ($parentCwdRelPath === ".") $parentCwdRelPath = "";
$html = null;
$html .= "<table id='browserSystemFiles'><tbody>";
$html .= "<tr id='..' file >";
$html .= "<td class='systemAttribute'><div id='systemFilename_..'></div></td>";
$html .= "<td class='systemAttribute'><div id='systemRelPath_..'></div></td>";
$html .= "<td class='systemAttribute'><div id='systemUrl_..'></div></td>";
$html .= "<td class='systemAttribute'><div id='systemIsDir_..'></div></td>";
foreach ($this->moduleManager->attributes as $attribute) {
$html .= "<td>" . $attribute->getHtmlParentDirectory($parentCwdRelPath, $this->view) . "</td>";
}
$html .= "<td class='browserCellFiller'></td>";
$html .= "</tr></tbody></table>";
return $html;
}
// for noscript
// set cwdRelPath to permittedDir if it is not set
function getDirListing() {
$this->cwd = $this->fileManager->getFileByRelPath($this->cwdRelPath);
if ($this->cwd) {
if ($this->cwd->isDir) {
if ($this->cwd->isPermitted) {
$files = $this->fileManager->getFilesByDir($this->cwd->absPath);
$html = null;
if ($this->view === "list") {
$html .= $this->getFilesViewList($files, false);
} else if ($this->view === "thumbnail") {
if (THUMBNAIL_ON) {$html .= $this->getFilesViewThumbnail($files, false);}
else {$html .= "<center>" . text("THUMBNAIL VIEW IS DISABLED.") . "</center>";}
}
} else {
$html .= "<center>" . text("ACCESS DENIED") . "</center>";
}
} else {
$html .= "<center>" . text("ACCESS DENIED") . "</center>";
}
} else {
$html .= "<center>" . text("ACCESS DENIED") . "</center>";
}
return $html;
}
// show error if $_GET["cwdRelPath"] is not set
function printDirListing($cwdRelPath) {
$xml = new Xml();
if (isset($cwdRelPath)) {
$this->cwd = $this->fileManager->getFileByRelPath($cwdRelPath);
if ($this->cwd) {
if ($this->cwd->isDir) {
if ($this->cwd->isPermitted) {
$files = $this->fileManager->getFilesByDir($this->cwd->absPath);
if ($_GET["view"] === "list" || $_GET["view"] === "thumbnail") {$this->view = $_GET["view"];}
else {$this->view = "list";}
$html = null;
if ($this->view === "list") {
$html .= $this->getFilesViewList($files, true);
$xml->setStatusSuccess();
$xml->setContent($html);
} else if ($this->view === "thumbnail") {
//if (THUMBNAIL_ON) {
if (true) {
$html .= $this->getFilesViewThumbnail($files, true);
$xml->setStatusSuccess();
$xml->setContent($html);
} else {
$xml->setError(text("THUMBNAIL VIEW IS DISABLED."));
}
}
} else {
$xml->setError(text("ACCESS DENIED"));
}
} else {
$xml->setError(text("ACCESS DENIED")); //Do not output relevant information.
}
} else {
$xml->setError(text("ACCESS DENIED")); //Do not output relevant information.
}
} else {
$xml->setError(text("ACCESS DENIED"));
}
$xml->dump();
}
function printFiles() {
echo $this->getFiles();
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : File
//------------------------------------------------------------------------------
class File {
//
var $absPath;
var $basename;
var $dirAbsPath; // Only for regular files
var $dirRelPath; // Only for regular files
var $extension; // Only for regular files
var $filename; // Only for regular files
var $isDir;
var $isPermitted;
var $isWithinDocumentRoot;
var $relPath;
var $uri;
var $url;
// Encoded in OS encoding method
var $absPathEn;
var $basenameEn;
var $dirAbsPathEn; // Only for regular files
var $dirRelPathEn; // Only for regular files
var $extensionEn; // Only for regular files
var $filenameEn; // Only for regular files
var $relPathEn;
var $uriEn;
var $urlEn;
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : FileManager
//------------------------------------------------------------------------------
// added in 2.0
class FileManager {
var $user;
function absPathToRelPath($absPath) {
$len = strlen($this->user->virtualRootAbsPath);
if ($len === strlen($absPath)) return "";
else return substr($absPath, $len);
}
function addEndingSlash($absDir) {
if (strlen($absDir) === 0) return "";
else {
$lastchar = substr($absDir, -1);
if ($lastchar !== "/" && $lastchar !== "\\") $absDir .= "/";
return $absDir;
}
}
function changeSlashes($absPath) {
return str_replace("\\", "/", $absPath);
}
function getDir($absPath) {
$dirAbsPath = dirname($absPath);
$dirAbsPath = FileManager::changeSlashes($dirAbsPath);
return FileManager::addEndingSlash($dirAbsPath);
}
// A file at $absPath must exist.
function getFile($absPath) {
$absPath = realpath($absPath); // to strip ending / if it exists
$absPath = $this->changeSlashes($absPath);
$file = new File;
$file->isDir = is_dir($absPath);
$path_parts = pathinfo($absPath);
$file->basename = $path_parts["basename"];
if (is_dir($absPath)) {
$file->absPath = $this->addEndingSlash($absPath);
$file->relPath = $this->absPathToRelPath($file->absPath);
} else {
$file->absPath = $absPath;
$file->relPath = $this->absPathToRelPath($absPath);
$file->filename = $path_parts["filename"];
$file->extension = $path_parts["extension"];
}
$file->dirAbsPath = $this->getDir($file->absPath);
$file->dirRelPath = $this->absPathToRelPath($file->dirAbsPath);
$file->uri = $this->getUri($file->absPath);
$file->url = $this->getUrl($file->absPath);
$file->isWithinDocumentRoot = $this->isWithinDocumentRoot($file->absPath);
$file->isPermitted = $this->isPermitted($file->absPath);
$file->absPathEn = Text::convertEncodingToUtf8($file->absPath);
$file->basenameEn = Text::convertEncodingToUtf8($file->basename);
$file->dirAbsPathEn = Text::convertEncodingToUtf8($file->dirAbsPath);
$file->dirRelPathEn = Text::convertEncodingToUtf8($file->dirRelPath);
$file->extensionEn = Text::convertEncodingToUtf8($file->extension);
$file->filenameEn = Text::convertEncodingToUtf8($file->filename);
$file->relPathEn = Text::convertEncodingToUtf8($file->relPath);
$file->uriEn = Text::convertEncodingToUtf8($file->uri);
$file->urlEn = Text::convertEncodingToUtf8($file->url);
return $file;
}
function getFileByRelPath($relPath) {
$absPath = $this->relPathToAbsPath($relPath);
if ($absPath) return $this->getFile($absPath);
else return false;
}
function getFilesByDir($cwdAbsPath) {
$files = array();
$dirHandle = opendir($cwdAbsPath);
# When there is no permission to browse the directory
if ($dirHandle === false) {
return false;
# When there is permission to browse the directory
} else {
while($basename = readdir($dirHandle)) {
if (!($basename === "." || $basename === "..")) $files[] = $this->getFile($cwdAbsPath . $basename);
}
}
closedir($dirHandle);
usort($files, array("FileManager", "sortFilesCmp"));
return $files;
}
function getParentDir($dirAbsPath) {
$parentDirAbsPath = dirname($dirAbsPath);
$parentDirAbsPath = FileManager::changeSlashes($parentDirAbsPath);
return FileManager::addEndingSlash($parentDirAbsPath);
}
function getUri($absPath) {
if (FileManager::isWithinDocumentRoot($absPath)) {
// Some OS's add an ending slash to paths of directories
$docRoot = FileManager::addEndingSlash(FileManager::changeSlashes($_SERVER['DOCUMENT_ROOT']));
if (strlen($absPath) === strlen($docRoot)) return "";
else return substr($absPath, strlen($docRoot));
}
return false;
}
// edited in 2.1
function getUrl($absPath) {
$uri = FileManager::getUri($absPath);
if ($_SERVER["SERVER_PORT"] !== "80") $port = ":" . $_SERVER["SERVER_PORT"];
else $port = null;
if ($_SERVER["HTTPS"]) $protocal = "https";
else $protocal = "http";
if ($uri !== false) return $protocal . "://" . $_SERVER["SERVER_NAME"] . $port . "/" . $uri;
return false;
}
function isPermitted($absPath) {
if (strpos($absPath, $this->user->permittedDirAbsPath) === 0) return true;
return false;
}
function isRelPathExist($relPath) {
$absPath = realpath($this->user->virtualRootAbsPath . $relPath);
str_replace("\\", "/", $absPath);
return (file_exists($absPath));
}
function isWithinDocumentRoot($absPath) {
// Some OS's add an ending slash to paths of directories
$docRoot = FileManager::addEndingSlash(FileManager::changeSlashes($_SERVER['DOCUMENT_ROOT']));
if (strpos($absPath, $docRoot) === 0) return true;
else return false;
}
function relPathToAbsPath($relPath) {
$absPath = realpath($this->user->virtualRootAbsPath . $relPath);
$absPath = FileManager::changeSlashes($absPath);
if ($absPath) {
if (is_dir($absPath)) return FileManager::addEndingSlash($absPath);
else return $absPath;
} else {
return false;
}
}
function relPathsToAbsPaths($relPaths) {
$absPaths = array();
foreach ($relPaths as $relPath) {
$absPath = $this->relPathToAbsPath($relPath);
$absPaths[$relPath] = $absPath;
}
return $absPaths;
}
// 2007-12-26
function removeBeginningSlash($relPath) {
return ltrim($relPath, "/\\");
}
function removeDoubleDots($absPath) {
return str_replace("..", "", $absPath);
}
function sortFiles($files) {
usort($files, array("FileManager", "sortFilesCmp"));
}
function sortFilesCmp($file1, $file2) {
$basename1 = strtolower($file1->basename);
$basename2 = strtolower($file2->basename);
//$basename1 = $file1->basename;
//$basename2 = $file2->basename;
if ($basename1 == $basename2) return 0;
return ($basename1 < $basename2) ? -1 : 1;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Ftp
//------------------------------------------------------------------------------
// added in 2.1
class Ftp {
var $connId = null;
var $password = FTP_LAYER_PASSWORD;
var $path = FTP_LAYER_PATH_ON_SERVER;
var $port = FTP_LAYER_PORT;
var $server = FTP_LAYER_HOST;
var $ssl = FTP_LAYER_SSL_ON;
var $timeout = 60;
var $username = FTP_LAYER_USERNAME;
function Ftp() {
$this->path = FileManager::changeSlashes($this->path);
$this->path = FileManager::addEndingSlash($this->path);
}
function absPathToFtpAbsPath($absPath) {
if ($this->isWithinFtpRoot($absPath)) {
$len = strlen($this->path);
if ($len === strlen($absPath)) return "/";
else return "/" . substr($absPath, $len);
} else {
return false;
}
}
function chdir($absPath) {
$this->connect();
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
return ftp_chdir($this->getConnId(), $ftpAbsPath);
}
}
// PHP 5 or above only
function chmod($absPath, $mode) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
if (!function_exists("ftp_chmod")) {
return -1;
}
// ftp_chmod may not work on Windows. PHP 5 shows warning on Windows.
return ftp_chmod($this->getConnId(), $mode, $ftpAbsPath);
}
return false;
}
function connect() {
if (!$this->connId) {
// set up basic connection
if ($this->ssl) {
$this->connId = @ftp_ssl_connect($this->server, $this->port, $this->timeout);
} else {
$this->connId = @ftp_connect($this->server, $this->port, $this->timeout);
}
if (!$this->connId) die("Cannot connect to FTP server");
// login with username and password
$loginResult = @ftp_login($this->connId, $this->username, $this->password);
if (!$loginResult) die("Cannot login to FTP server");
}
return true;
}
function copy($srcAbsPath, $desAbsPath) {
$ftpSrcAbsPath = $this->absPathToFtpAbsPath($srcAbsPath);
$ftpDesAbsPath = $this->absPathToFtpAbsPath($desAbsPath);
if ($ftpSrcAbsPath !== false && $ftpDesAbsPath !== false) {
$result = false;
$temp = tmpfile();
if (ftp_fget($this->getConnId(), $temp, $ftpSrcAbsPath, FTP_BINARY, 0)) {
//fseek($temp, 0); // Content to be uploaded will be content after the pointer
$result = ftp_fput($this->getConnId(), $ftpDesAbsPath, $temp, FTP_BINARY);
}
fclose($temp);
return $result;
}
return false;
}
function delete($absPath) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
return ftp_delete($this->getConnId(), $ftpAbsPath);
}
return false;
}
function getConnId() {
$this->connect();
return $this->connId;
}
function isWithinFtpRoot($absPath) {
if (strpos($absPath, $this->path) === 0) return true;
else return false;
}
function mkdir($absPath) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
return ftp_mkdir($this->getConnId(), $ftpAbsPath);
}
return false;
}
function moveUploadedFile($tmpAbsPath, $desAbsPath) {
$ftpDesAbsPath = $this->absPathToFtpAbsPath($desAbsPath);
if ($ftpDesAbsPath !== false) {
if (is_uploaded_file($tmpAbsPath)) { // to prevent file upload attack
return ftp_put($this->getConnId(), $ftpDesAbsPath, $tmpAbsPath, FTP_BINARY);
}
}
return false;
}
function putWithContent($absPath, $content) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
$temp = tmpfile();
if (fwrite($temp, $content) === false) return false;
fseek($temp, 0); // Content to be uploaded will be content after the pointer
$result = ftp_fput($this->getConnId(), $ftpAbsPath, $temp, FTP_BINARY);
fclose($temp);
return $result;
}
return false;
}
function rename($oldAbsPath, $newAbsPath) {
$this->connect();
$oldFtpAbsPath = $this->absPathToFtpAbsPath($oldAbsPath);
$newFtpAbsPath = $this->absPathToFtpAbsPath($newAbsPath);
if (($oldFtpAbsPath !== false) && ($newFtpAbsPath !== false)) {
return ftp_rename($this->getConnId(), $oldFtpAbsPath, $newFtpAbsPath);
}
return false;
}
function rmdir($absPath) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
return ftp_rmdir($this->getConnId(), $ftpAbsPath);
}
return false;
}
function touch($absPath) {
$ftpAbsPath = $this->absPathToFtpAbsPath($absPath);
if ($ftpAbsPath !== false) {
$temp = tmpfile();
$result = ftp_fput($this->getConnId(), $ftpAbsPath, $temp, FTP_BINARY);
fclose($temp);
return $result;
}
return false;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Image
//------------------------------------------------------------------------------
class Image {
var $file;
var $height;
var $image;
var $type;
var $width;
function printImage($file) {
if ($this->setImageByFile($file)) {
$this->dump();
} else {
return false;
}
}
function printThumbnail($file) {
if ($this->setImageByFile($file)) {
$this->resize(THUMBNAIL_SIZE);
$this->dump();
} else {
return false;
}
}
function setImageByFile($file) {
$this->file = $file;
$size = getimagesize($this->file->absPath);
$this->width = $size[0];
$this->height = $size[1];
$this->type = $size[2];
if ($this->type === IMAGETYPE_JPEG) {
$this->image = imagecreatefromjpeg($this->file->absPath);
} else if ($this->type === IMAGETYPE_GIF) {
$this->image = imagecreatefromgif($this->file->absPath);
} else if ($this->type === IMAGETYPE_PNG) {
$this->image = imagecreatefrompng($this->file->absPath);
} else if ($this->type === IMAGETYPE_WBMP) {
$this->image = imagecreatefromwbmp($this->file->absPath);
} else {
return false;
}
return true;
}
function resize($newSize) {
$containerRatio = 1; // square
if ($this->height > $newSize || $this->width > $newSize) {
$ratio = $this->height / $this->width;
if ($ratio > $containerRatio) {
$newWidth = $newSize / $ratio;
$newHeight = $newSize;
} else {
$newWidth = $newSize;
$newHeight = $newSize * $ratio;
}
$newImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height);
$this->image = $newImage;
}
}
function dump() {
header("Cache-Control: public");
header("Content-type: " . image_type_to_mime_type($this->type));
header('Content-Disposition: attachment; filename="'.$this->file->basename.'"');
header("Content-Transfer-Encoding: binary\n");
if ($this->type === IMAGETYPE_JPEG) {
imagejpeg($this->image);
} else if ($this->type === IMAGETYPE_GIF) {
imagegif($this->image);
} else if ($this->type === IMAGETYPE_PNG) {
imagepng($this->image);
} else if ($this->type === IMAGETYPE_WBMP) {
imagewbmp($this->image);
}
exit(0);
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Javascript
//------------------------------------------------------------------------------
class Javascript {
function getJavascrtipt() {
$javascript = null;
$javascript .=
"
var Sdl = {};
//------------------------------------------------------------------------------
Sdl.Ajax = function() {}
Sdl.Ajax.ajaxGet = function(fn, targetLink) {
var xhr;
xhr = Sdl.Ajax.initializeAjax();
if (xhr) {
//xhr.onerror = Sdl.Ajax.onError; //IE6 doesn't support it.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {fn(xhr)};
}
xhr.open('GET', targetLink, true);
xhr.send(null);
return xhr;
} else {
return false;
}
}
Sdl.Ajax.ajaxPost = function(fn, targetLink, param) {
var xhr
xhr = Sdl.Ajax.initializeAjax();
if (xhr) {
//xhr.onerror = Sdl.Ajax.onError; //IE6 doesn't support it.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {fn(xhr)};
}
xhr.open('POST', targetLink, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Content-length', param.length);
xhr.setRequestHeader('Connection', 'close');
xhr.send(param);
return xhr;
} else {
return false;
}
}
Sdl.Ajax.initializeAjax = function() {
var xhr;
try {
xhr = new XMLHttpRequest(); // FF & IE7
} catch (e) {
try {
xhr = new ActiveXObject('MSXML2.XMLHTTP.3.0');
} catch(e) {
try {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
alert('" . text("JAVASCRIPT ERROR") . "');
return false;
}
}
}
return xhr;
}
Sdl.Ajax.onError = function() {
alert('" . text("JAVASCRIPT ERROR") . "');
}
//------------------------------------------------------------------------------
Sdl.Browser = function() {
var this_clone = this;
this.cacheLocation = null;
this.caches = [];
this.cwd = new Sdl.File();
this.cwdLoading = new Sdl.File();
this.onLoadListeners = [];
this.permittedDir = new Sdl.File(); //For reference only. It's not used for permission checking.
this.status = {};
this.status.success = false;
this.view = null;
this.ajaxActionLoadDirListingPass = function(xhr) {
this_clone.ajaxActionLoadDirListing(xhr);
}
Sdl.Event.addWindowOnLoadListener(function() {this_clone.windowOnLoadListener();});
}
Sdl.Browser.prototype = {
addOnLoadListener : function(fn) {
this.onLoadListeners.push(fn);
},
ajaxActionLoadDirListing : function(xhr) {
var div, container, dirListing, response;
response = Sdl.Xml.digestResponseXml(xhr);
if (Sdl.Xml.validateResponseAndWarn(response)) {
this.cwd = new Sdl.Object.cloneObject(this.cwdLoading);
div = document.getElementById('browserFilesDiv');
if(response.status.success) {
div.innerHTML = response.content;
this.status.success = true;
} else {
this.status.success = false;
div.innerHTML = '<center>' + response.error + '</center>';
}
var cache = {};
cache.cwd = new Sdl.Object.cloneObject(this.cwd);
cache.innerHTML = div.innerHTML;
cache.view = this.view;
cache.status = new Sdl.Object.cloneObject(this.status);
this.cacheAdd(cache);
this.onLoad();
}
},
cacheAdd : function(cache) {
if (this.cacheLocation != null) {
if (this.caches[this.cacheLocation].cwd.relPath == cache.cwd.relPath) {
this.caches.splice(this.cacheLocation, 1, cache);
} else {
this.caches.splice(this.cacheLocation + 1);
this.cacheLocation++;
this.caches.push(cache);
}
} else {
this.cacheLocation = 0;
this.caches.push(cache);
}
},
cacheBackward : function() {
if (this.cacheLocation != null) {
if (this.caches[this.cacheLocation - 1]) {
this.cacheLoad(this.caches[this.cacheLocation - 1]);
this.cacheLocation--;
}
}
},
cacheForward : function() {
if (this.cacheLocation != null) {
if (this.caches[this.cacheLocation + 1]) {
this.cacheLoad(this.caches[this.cacheLocation + 1]);
this.cacheLocation++;
}
}
},
cacheLoad : function(cache) {
var div;
this.cwd = new Sdl.Object.cloneObject(cache.cwd);
div = document.getElementById('browserFilesDiv');
div.innerHTML = cache.innerHTML;
this.view = cache.view;
this.status = new Sdl.Object.cloneObject(cache.status);
this.onLoad();
},
getAllFiles : function() {
var files = [];
this.traverseAllFiles(function(row) {
var file = {};
file.id = row.id;
file.relPath = document.getElementById('systemRelPath_' + row.id).innerHTML.
file.filename = document.getElementById('systeFilename_' + row.id).innerHTML.
files.push(file);
});
return files;
},
getParentDir : function(path) {
var i, parentDir;
i = path.lastIndexOf('/', path.length - 2);
if (i>=0) {parentDir = path.substring(0, i+1);}
else {parentDir = '';}
return parentDir;
},
loadDirListing : function(cwdRelPath, view) {
if (view == 'list') {this.view = 'list';}
else if (view == 'thumbnail') {this.view = 'thumbnail';}
this.cwdLoading.relPath = cwdRelPath;
this.cwdLoading.parentDir = this.getParentDir(cwdRelPath);
Sdl.Ajax.ajaxGet(this.ajaxActionLoadDirListingPass, '?print=dirListing&cwdRelPath=' + encodeURIComponent(this.cwdLoading.relPath) + '&view=' + this.view);
},
loadDirListingParentDir : function() {
this.loadDirListing(this.cwd.parentDir);
},
onClickThumbnailRedirect : function(e, cwdRelPath) {
Sdl.Event.stopPropagation(e);
this.loadDirListing(cwdRelPath);
},
onLoad : function() {
var headers, len;
document.title = '/' + this.cwd.relPath + ' - Simple Directory Listing';
headers = document.getElementById('browserHeaders');
for (var i = 0 ; i < headers.rows[0].cells.length ; i++) {
if (this.view == 'thumbnail') {
headers.rows[0].cells[i].childNodes[0].style.display = 'inline';
} else if (this.view == 'list') {
headers.rows[0].cells[i].childNodes[0].style.display = 'block';
}
}
// It is replaced by Sdl.Image.position as an onload listener for thumbnails
/*
// For IE6. I don't know how to vertically align img with CSS only in IE6.
if (Sdl.System.isIe6() && this.view == 'thumbnail') {
this.traverseAllFiles(function(file) {
var imgs, marginTop;
imgs = file.getElementsByTagName('img');
marginTop = ((" . THUMBNAIL_SIZE . " - imgs[0].offsetHeight ) / 2);
imgs[0].style.marginTop = marginTop >= 0 ? marginTop + 'px' : '0px';
});
}
*/
len = this.onLoadListeners.length;
for (var i = 0 ; i < len ; i++) {
this.onLoadListeners[i]();
}
},
redirectPermittedDir : function() {
this.loadDirListing(this.permittedDir.relPath);
},
reloadDirListing : function() {
this.loadDirListing(this.cwd.relPath);
},
removeOnLoadListener : function(fn) {
var len;
len = this.onLoadListeners.length;
for (var i = 0 ; i < len ; i++) {
if (this.onLoadListeners[i] == fn) {
this.onLoadListeners.splice(i,1);
return;
}
}
},
setView : function(view) {
if (view == 'list' && this.view != 'list') {this.loadDirListing(this.cwd.relPath, 'list');}
else if (view == 'thumbnail' && this.view != 'thumbnail') {this.loadDirListing(this.cwd.relPath, 'thumbnail');}
},
traverseAllFiles : function(fn) {
var b, elts, len;
b = document.getElementById('browserFiles');
if (b) {
if (b.tagName == 'TABLE') {
elts = b.rows;
} else {
elts = [];
for (var i=0 ; i<b.childNodes.length ; i++) {
if (b.childNodes[i].nodeType == 1 && b.childNodes[i].tagName == 'DIV') {elts.push(b.childNodes[i]);}
}
}
len = elts.length;
for (var i = 0 ; i < len ; i++) {
fn(elts[i]);
}
}
},
traverseAllFilesOnAttribute : function(fn, idTag) {
this.traverseAllFiles(function(elt) {
var a;
a = document.getElementById(idTag + '_' + elt.id);
fn(a, elt);
});
},
windowOnLoadListener : function() {
document.getElementById('browserFilesDiv').innerHTML = '<center>" . text("LOADING") . "</center>';
this.cwd.relPath = Sdl.Text.decodeHtmlEntity(this.cwd.relPath);
this.permittedDir.relPath = Sdl.Text.decodeHtmlEntity(this.permittedDir.relPath);
this.view = Sdl.Text.decodeHtmlEntity(this.view);
this.loadDirListing(this.cwd.relPath, this.view);
}
}
//------------------------------------------------------------------------------
Sdl.Button = function() {}
Sdl.Button.decorateById = function(id) {
Sdl.Button.decorateByRef(document.getElementById(id));
}
Sdl.Button.decorateByRef = function(elt) {
Sdl.Object.modifyClassName(elt, 'functionButton', null);
elt.onmouseout = function() {Sdl.Object.modifyClassName(this, null, 'functionButtonMouseOver');}
elt.onmouseover = function() {Sdl.Object.modifyClassName(this, 'functionButtonMouseOver', null);}
}
//------------------------------------------------------------------------------
Sdl.CoverBody = function() {
Sdl.CoverBody.cover = null;
Sdl.CoverBody.isCovered = false;
Sdl.CoverBody.isTextShown = false;
Sdl.CoverBody.text = null;
}
Sdl.CoverBody.hideCoverBody = function() {
if (Sdl.CoverBody.isCovered) {
document.body.removeChild(Sdl.CoverBody.cover);
Sdl.CoverBody.isCovered = false;
}
}
Sdl.CoverBody.hideText = function() {
if (Sdl.CoverBody.isTextShown) {
document.body.removeChild(Sdl.CoverBody.text);
Sdl.CoverBody.isTextShown = false;
}
}
Sdl.CoverBody.modifyText = function(text) {
if (Sdl.CoverBody.isTextShown) {
var clientWidth;
clientWidth = document.documentElement.clientWidth;
Sdl.CoverBody.text.style.visibility = 'hidden';
Sdl.CoverBody.text.innerHTML = text;
Sdl.CoverBody.text.style.left = ((clientWidth - Sdl.CoverBody.text.offsetWidth) / 2) + 'px';
Sdl.CoverBody.text.style.visibility = 'visible';
}
}
Sdl.CoverBody.resizeCoverBody = function() {
if (Sdl.CoverBody.isCovered) {
var clientHeight, clientWidth, newHeight, newWidth, pageHeight, pageWidth;
clientWidth = document.documentElement.clientWidth;
clientHeight = document.documentElement.clientHeight;
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
newHeight = clientHeight > pageHeight ? clientHeight : pageHeight;
newWidth = clientWidth > pageWidth ? clientWidth : pageWidth;
Sdl.CoverBody.cover.style.height = newHeight + 'px';
Sdl.CoverBody.cover.style.width = newWidth + 'px';
}
}
Sdl.CoverBody.resizeText = function() {
if (Sdl.CoverBody.isTextShown) {
var clientWidth;
clientWidth = document.documentElement.clientWidth;
Sdl.CoverBody.text.style.left = ((clientWidth - Sdl.CoverBody.text.offsetWidth) / 2) + 'px';
}
}
// For IE. IE6 doesn't support position:fixed.
Sdl.CoverBody.positionText = function() {
if (Sdl.CoverBody.isTextShown) {
Sdl.CoverBody.text.style.position = 'absolute';
Sdl.CoverBody.text.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - Sdl.CoverBody.text.clientHeight) / 2) + 'px';
}
}
Sdl.CoverBody.showCoverBody = function() {
if (!Sdl.CoverBody.isCovered) {
var newHeight, newWidth, clientHeight, clientWidth, pageHeight, pageWidth;
clientWidth = document.documentElement.clientWidth;
clientHeight = document.documentElement.clientHeight;
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
newHeight = clientHeight > pageHeight ? clientHeight : pageHeight;
newWidth = clientWidth > pageWidth ? clientWidth : pageWidth;
Sdl.CoverBody.cover = document.createElement('div');
Sdl.CoverBody.cover.className = 'coverBody';
Sdl.CoverBody.cover.style.height = newHeight + 'px';
Sdl.CoverBody.cover.style.width = newWidth + 'px';
document.body.appendChild(Sdl.CoverBody.cover);
Sdl.CoverBody.isCovered = true;
}
}
Sdl.CoverBody.showText = function(text) {
if (!Sdl.CoverBody.isTextShown) {
var clientWidth;
clientWidth = document.documentElement.clientWidth;
Sdl.CoverBody.text = document.createElement('div');
Sdl.CoverBody.text.className = 'coverBodyText';
Sdl.CoverBody.text.innerHTML = text;
document.body.appendChild(Sdl.CoverBody.text);
Sdl.CoverBody.text.style.left = ((clientWidth - Sdl.CoverBody.text.offsetWidth) / 2) + 'px';
Sdl.CoverBody.isTextShown = true;
}
}
//------------------------------------------------------------------------------
Sdl.Css = function() {}
Sdl.Css.changeAttribute = function(className, attribute, value) {
for (var i = 0; i < document.styleSheets.length; i++){
for (var j = 0; j < document.styleSheets[i]['cssRules'].length; j++) {
if (document.styleSheets[i]['cssRules'][j].selectorText == className) {
document.styleSheets[i]['cssRules'][j].style[attribute] = value;
}
}
}
}
//------------------------------------------------------------------------------
Sdl.Event = function() {}
Sdl.Event.addEventListener = function(target, event, fn) {
if (target.addEventListener) {target.addEventListener(event, fn, false);}
else if (target.attachEvent) {target.attachEvent('on' + event, fn);}
}
Sdl.Event.addWindowOnLoadListener = function(fn) {
Sdl.Event.addEventListener(window,'load',fn);
}
Sdl.Event.disableSelection = function(elt) {
elt.onselectstart = function() {return false;};
elt.style.MozUserSelect = 'none';
}
Sdl.Event.removeEventListener = function(target, event, fn) {
if (target.removeEventListener) {target.removeEventListener(event, fn, false);}
else if (target.detachEvent) {target.detachEvent('on' + event, fn);}
}
Sdl.Event.stopPropagation = function(e) {
if (e.stopPropagation) {e.stopPropagation();}
else {e.cancelBubble = true;}
}
//------------------------------------------------------------------------------
Sdl.File = function() {
this.filename = null;
this.id = null;
this.isDir = null;
this.relPath = null;
}
//------------------------------------------------------------------------------
Sdl.FileContainer = function() {
var this_clone = this;
this.fileContainer = null;
this.files = [];
this.select = null;
this.acceptedFileType = 1; //1=files/dirs, 2=files only, 3=dirs only
this.onClickAddPass = function() {
this_clone.onClickAdd();
}
this.onClickRemovePass = function() {
this_clone.onClickRemove();
}
this.onClickResetPass = function() {
this_clone.onClickReset();
}
}
Sdl.FileContainer.prototype = {
addFile : function(file) {
if(!this.isFileExist(file)) {
if(this.acceptedFileType == 2 && file.isDir) {
alert('Cannot add directory. ' + file.relPath + ' is a directory.');
return;
}
if(this.acceptedFileType == 3 && !file.isDir) {
alert('Directory only. ' + file.relPath + ' is not a directory.');
return;
}
this.files.push(file);
this.addOption(this.select, file.relPath);
this.updateNumber();
}
},
addFiles : function(files) {
var len;
len = files.length;
for(var i = 0 ; i < len ; i++) {
this.addFile(files[i]);
}
},
addOption : function(select, text) {
var o;
o = document.createElement('option');
o.text = text;
try {select.add(o, null);}
catch (ex) {select.add(o);}
return o;
},
isFileExist : function(file) {
var exist, len;
len = this.files.length;
exist = false;
for(var i = 0 ; i < len ; i++) {
if(file.relPath == this.files[i].relPath) {
exist = true;
break;
}
}
return exist;
},
onClickAdd : function() {
var selectedFiles;
selectedFiles = Sdl.ModuleSelector.main.getSelectedFilesAndWarn();
if (selectedFiles && selectedFiles.length > 0) {this.addFiles(selectedFiles);}
},
onClickRemove : function() {
var index;
index = this.select.selectedIndex;
if(index>0) {this.removeFile(index);}
},
onClickReset : function() {
var len;
len = this.select.length;
for (var i = len - 1 ; i > 0 ; i--) {
this.removeFile(i);
}
},
removeFile : function(index) {
this.select.remove(index);
this.files.splice(index-1, 1);
if (index < this.select.length) {this.select.selectedIndex = index;}
else {this.select.selectedIndex = index - 1;}
this.updateNumber();
},
setFileContainer : function(fc) {
this.fileContainer = fc;
this.add = document.createElement('input');
//this.add.value = '" . text("ADD") . "';
this.add.type = 'button';
this.add.onclick = this.onClickAddPass;
this.remove = document.createElement('input');
//this.remove.value = '" . text("REMOVE") . "';
this.remove.type = 'button';
this.remove.onclick = this.onClickRemovePass;
this.reset = document.createElement('input');
//this.reset.value = '" . text("RESET") . "';
this.reset.type = 'button';
this.reset.onclick = this.onClickResetPass;
this.select = document.createElement('select');
this.select.style.width = '6em'; // Safari 3 beta occupies a longer select box.
// IE6 doesn't expand items when a select box is clicked.
if (Sdl.System.isIe6()) {
this.select.style.width = '30em';
}
this.addOption(this.select, '0 " . text("FILES") . "');
this.fileContainer.appendChild(this.select);
this.fileContainer.appendChild(this.add);
this.fileContainer.appendChild(this.remove);
this.fileContainer.appendChild(this.reset);
// For Opera 9.21. It can't set values to input buttons before they are added to DOM.
this.add.value = '" . text("ADD") . "';
this.remove.value = '" . text("REMOVE") . "';
this.reset.value = '" . text("RESET") . "';
},
updateNumber : function() {
this.select.options[0].text = this.files.length + ' " . text("FILES") . "';
}
}
//------------------------------------------------------------------------------
Sdl.Image = function() {
var this_clone = this;
this.img = null;
this.intervalId = null;
this.originalHeight = null;
this.originalWidth = null;
this.success = false;
this.checkCompletePass = function() {
this_clone.checkComplete();
}
this.onClickShowPass = function(e, relPath) {
this_clone.onClickShow(e, relPath);
}
this.onErrorPass = function() {
this_clone.onError();
}
this.onLoadPass = function() {
this_clone.onLoad();
}
}
Sdl.Image.prototype = {
// For Opera 9.21. zero byte image does not go to onerror
// It isn't used.
checkComplete : function() {
if (this.img.complete) {
if (!this.success) {Sdl.CoverBody.modifyText('". text("INVALID IMAGE FORMAT") ."');}
window.clearInterval(this.intervalId);
}
},
onClickShowByRelPath : function(e, relPath) {
this.showByRelPath(relPath);
Sdl.Event.stopPropagation(e);
},
onClickShowByUrl : function(e, url) {
this.showByUrl(url);
Sdl.Event.stopPropagation(e);
},
onError : function() {
Sdl.CoverBody.modifyText('Invalid image format.');
//window.clearInterval(this.intervalId);
},
onLoad : function() {
this.success = true;
this.originalHeight = this.img.offsetHeight;
this.originalWidth = this.img.offsetWidth;
this.resize();
Sdl.CoverBody.hideText();
this.img.style.visibility = 'visible';
},
// For IE. IE6 doesn't support position:fixed.
position : function() {
this.img.style.position = 'absolute';
this.img.style.top = document.documentElement.scrollTop + 'px';
},
resize : function() {
if (this.success) {
var imgHeight, imgWidth, newHeight, newWidth, screenHeight, screenWidth;
screenHeight = document.documentElement.clientHeight < document.body.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
screenWidth = document.documentElement.clientWidth < document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
imgHeight = this.originalHeight;
imgWidth = this.originalWidth;
if (imgHeight > screenHeight || imgWidth > screenWidth) {
var imgRatio, screenRatio;
imgRatio = imgHeight / imgWidth;
screenRatio = screenHeight / screenWidth;
if (imgRatio > screenRatio) {
newHeight = screenHeight;
newWidth = newHeight / imgRatio;
} else {
newWidth = screenWidth;
newHeight = newWidth * imgRatio;
}
} else {
newHeight = imgHeight;
newWidth = imgWidth;
}
this.img.style.height = newHeight + 'px';
this.img.style.width = newWidth + 'px';
}
},
show : function(url) {
var width1, height1;
width1 = document.documentElement.clientWidth;
height1 = document.documentElement.clientHeight;
this.success = false;
this.img = document.createElement('img');
this.img.style.visibility = 'hidden';
this.img.className = 'image';
this.img.onload = this.onLoadPass;
this.img.onerror = this.onErrorPass;
document.body.appendChild(this.img);
Sdl.CoverBody.showCoverBody();
Sdl.CoverBody.showText('Loading');
if (Sdl.System.isIe6()) {
this.position(); // For IE. IE6 doesn't support position:fixed.
Sdl.CoverBody.positionText(); // For IE. IE6 doesn't support position:fixed.
Sdl.CoverBody.resizeText(); // For IE. IE6 doesn't support position:fixed.
}
this.img.src = url;
//this.intervalId = window.setInterval(this.checkCompletePass, 500);
var this_clone_tmp = this;
window.onresize = function() {
this_clone_tmp.resize();
if (Sdl.System.isIe6()) {
this_clone_tmp.position(); // For IE. IE6 doesn't support position:fixed.
Sdl.CoverBody.positionText(); // For IE. IE6 doesn't support position:fixed.
}
Sdl.CoverBody.resizeCoverBody();
Sdl.CoverBody.resizeText();
}
if (Sdl.System.isIe6()) {
window.onscroll = function() {
this_clone_tmp.position(); // For IE. IE6 doesn't support position:fixed.
Sdl.CoverBody.positionText(); // For IE. IE6 doesn't support position:fixed.
}
}
document.onmousedown = function() {
//window.clearInterval(this_clone_tmp.intervalId);
document.body.removeChild(this_clone_tmp.img);
document.onmousedown = null;
window.onresize = null;
if (Sdl.System.isIe6()) {
window.onscroll = null; // For IE. IE6 doesn't support position:fixed.
}
Sdl.CoverBody.hideCoverBody();
Sdl.CoverBody.hideText();
this_clone_tmp.img = null;
return false;
}
},
showByRelPath : function(relPath) {
this.show('?print=image&relPath=' + relPath);
},
showByUrl : function(url) {
this.show(url);
}
}
// For IE6. I don't know how to vertically align img with CSS only in IE6.
Sdl.Image.position = function(img) {
if (Sdl.System.isIe6()) {
var marginTop;
marginTop = ((" . THUMBNAIL_SIZE . " - img.offsetHeight ) / 2);
img.style.marginTop = marginTop >= 0 ? marginTop + 'px' : '0px';
}
}
//------------------------------------------------------------------------------
Sdl.Layout = function() {
var this_clone = this;
Sdl.Event.addWindowOnLoadListener(function() {this_clone.windowOnLoadListener();});
}
Sdl.Layout.prototype = {
windowOnLoadListener : function() {
document.getElementById('font').style.display = 'inline';
}
}
Sdl.Layout.changeFontSize = function(num) {
var fontSize;
fontSize = document.body.style.fontSize;
if (fontSize) {document.body.style.fontSize = parseInt(fontSize.substring(0, fontSize.length - 2)) + num + 'px';}
else {document.body.style.fontSize = " . FONT_SIZE . " + num + 'px';}
}
Sdl.Layout.increaseFontSize = function() {
Sdl.Layout.changeFontSize(1);
}
Sdl.Layout.decreaseFontSize = function() {
Sdl.Layout.changeFontSize(-1);
}
//------------------------------------------------------------------------------
Sdl.MovableBar = function() {
var this_clone = this;
this.div = null;
this.isCovered = false;
this.isDefaultLocked = null;
this.lock = null;
this.unlockType = 'auto';
this.movableBar = null;
this.moveTarget = null;
this.onClickLock = function(e) {
e = e || event;
if (this_clone.lock.checked) {
this_clone.moveTarget.style.height = this_clone.moveTarget.offsetHeight + 'px';
} else {
if (this_clone.unlockType == 'scrollHeight') {this_clone.moveTarget.style.height = this_clone.moveTarget.scrollHeight + 'px';}
else {this_clone.moveTarget.style.height = 'auto';}
}
Sdl.Event.stopPropagation(e);
}
this.onMouseDown = function(e) {
var oldY, oldHeight;
e = e || event;
oldY = e.pageY ? e.pageY : e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
oldHeight = this_clone.moveTarget.offsetHeight;
this_clone.movableBar.onmouseout = null;
this_clone.movableBar.onmouseover = null;
document.onselectstart = function(e) {return false;}
document.onmousedown = function(e) {return false;}
//document.body.style.MozUserSelect = 'none';
document.onmousemove = function(e) {
var lock, newY, newHeight, diff;
this_clone.lock.checked = true;
e = e || event;
newY = e.pageY ? e.pageY : e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
diff = newY - oldY;
newHeight = oldHeight + diff;
if (newHeight >= 0 ) {
this_clone.moveTargetHeight = newHeight;
this_clone.moveTarget.style.height = newHeight + 'px';
}
};
document.onmouseup = function(e) {
document.body.onselectstart = null;
document.onmousemove = null;
document.onmousedown = null;
this_clone.movableBar.onmouseout = this_clone.onMouseOut;
this_clone.movableBar.onmouseover = this_clone.onMouseOver;
this_clone.onMouseOut(e);
};
}
this.onMouseOut = function() {
Sdl.Object.modifyClassName(this_clone.movableBar, null, 'movableBarMouseOver')
}
this.onMouseOver = function() {
Sdl.Object.modifyClassName(this_clone.movableBar, 'movableBarMouseOver', null)
}
}
Sdl.MovableBar.prototype = {
setMoveTarget : function(t) {
//It would make body have no x-scroll
//t.style.overflowY = 'auto';
this.moveTarget = t;
// IE6 retrieved incorrect .offsetHeight if there is no border in this case.
if (Sdl.System.isIe6()) {
Sdl.Object.modifyClassName(this.moveTarget, 'moveTargetIe6', null);
}
},
setup : function() {
var content, locked, sign;
this.movableBar = document.createElement('div');
Sdl.Object.modifyClassName(this.movableBar, 'movableBar', null)
this.movableBar.onmouseover = this.onMouseOver;
this.movableBar.onmouseout = this.onMouseOut;
this.movableBar.onmousedown = this.onMouseDown;
sign = document.createElement('div');
sign.innerHTML = '------';
sign.className = 'movableBarSign';
content = document.createElement('div');
content.className = 'movableBarContent';
this.lock = document.createElement('input');
this.lock.style.cursor = 'default';
this.lock.type = 'checkbox';
this.lock.onclick = this.onClickLock;
this.lock.tabIndex = -1;
locked = document.createTextNode('Locked');
content.appendChild(this.lock);
content.appendChild(locked);
this.movableBar.appendChild(sign);
this.movableBar.appendChild(content);
// Properties/status change must be done after elements are added to DOM
this.lock.checked = this.isDefaultLocked;
}
}
//------------------------------------------------------------------------------
Sdl.Object = function() {}
Sdl.Object.cloneObject = function(obj) {
for (i in obj) {
if (typeof obj[i] == 'object') {this[i] = new Sdl.Object.cloneObject(obj[i]);}
else {this[i] = obj[i];}
}
}
Sdl.Object.modifyClassName = function(elt, add, remove) {
var classNames, len, newClassName = '';
classNames = elt.className.split(' ');
len = classNames.length;
for (var i = 0 ; i < len ; i++) {
if (classNames[i] != remove && classNames[i] != add) {
newClassName += classNames[i] + ' ';
}
}
if (add) {
newClassName += add;
}
elt.className = newClassName;
//alert(elt.className);
}
//------------------------------------------------------------------------------
Sdl.Page = function() {
var this_clone = this;
this.content = null;
this.contentContainer = null;
this.movableBar = new Sdl.MovableBar();
this.resizableElement = null;
this.tabContent = null;
this.tab = null;
this.onClickTab = function() {
Sdl.pageManager.switchPage(this_clone);
}
this.onClickTabRemove = function(e) {
/* e.stopPropagation is for Safari 3 beta, after this page is removed, this clicking bubbles to
switching tab again. This doesn't happer in FF and IE since this page
should have been deleted from DOM. */
Sdl.Event.stopPropagation(e || event);
Sdl.pageManager.removePage(this_clone);
}
}
Sdl.Page.prototype = {
hideContent : function() {
this.contentContainer.style.display = 'none';
},
showContent : function() {
this.contentContainer.style.display = 'block';
},
focusTab : function() {
Sdl.Object.modifyClassName(this.tab, 'tabFocus', null);
},
blurTab : function() {
Sdl.Object.modifyClassName(this.tab, null, 'tabFocus');
}
}
//------------------------------------------------------------------------------
Sdl.PageManager = function() {
var this_clone = this;
this.currentPage = null;
this.pages = [];
Sdl.Event.addWindowOnLoadListener(function() {this_clone.windowOnLoadListener();});
}
Sdl.PageManager.prototype = {
addContent : function(page) {
var pages;
pages = document.getElementById('pages');
page.contentContainer = document.createElement('div');
page.contentContainer.style.display = 'none';
page.contentContainer.appendChild(page.content);
pages.appendChild(page.contentContainer);
},
addMovableBar : function(page) {
page.movableBar.setup();
page.contentContainer.appendChild(page.movableBar.movableBar);
},
addPage : function(page) {
this.pages.push(page);
this.addContent(page);
this.addTab(page);
this.addMovableBar(page);
this.switchPage(page);
this.showHideTabs();
},
addTab : function(page, removable) {
var tabContentContainer, tabs;
tabs = document.getElementById('tabs');
tabContentContainer = document.createElement('div');
page.tab = document.createElement('div');
Sdl.Object.modifyClassName(page.tab, 'tab', null);
page.tab.onclick = page.onClickTab;
tabContentContainer.style.cssFloat = 'left';
tabContentContainer.style.styleFloat = 'left';
tabContentContainer.appendChild(page.tabContent);
page.tab.appendChild(tabContentContainer);
if (removable != false) {
var remove, removeDiv;
removeDiv = document.createElement('div');
remove = document.createElement('img');
remove.src = '?print=icon&icon=cross';
remove.alt = '[x]';
remove.align = 'middle';
remove.style.verticalAlign = 'middle';
removeDiv.style.cssFloat = 'left';
removeDiv.style.styleFloat = 'left';
remove.onclick = page.onClickTabRemove;
removeDiv.appendChild(remove);
page.tab.appendChild(removeDiv);
}
tabs.appendChild(page.tab);
},
removePage : function(page) {
var pages, tabs;
tabs = document.getElementById('tabs');
pages = document.getElementById('pages');
tabs.removeChild(page.tab);
pages.removeChild(page.contentContainer);
var i = 0, len = this.pages.length;
for (i ; i < len ; i++) {
if (this.pages[i] == page) {
if (this.currentPage == page) {
if (this.pages[parseInt(i)+1]) {this.switchPage(this.pages[parseInt(i)+1]);}
else {this.switchPage(this.pages[parseInt(i)-1]);}
}
this.pages.splice(i, 1);
break;
}
}
this.showHideTabs();
},
removeTab : function(id) {
var tabs = document.getElementById('tabs');
for (var i in tabs.childNodes) {
if (tabs.childNodes[i].id == id) {
tabs.removeChild(tabs.childNodes[i]);
break;
}
}
for (var i in this.pages) {
if (this.tabs[i] == id) {
this.tabs.splice(i, 1);
break;
}
}
},
showHideTabs : function() {
if (this.pages.length > 1) {
document.getElementById('tabs').style.display = 'block';
document.getElementById('pages').className = 'pagesSideBoxTopExist';
} else {
var sideBoxTopHeight;
document.getElementById('tabs').style.display = 'none';
sideBoxTopHeight = document.getElementById('containerSideBoxTopContainerCell').offsetHeight;
if (sideBoxTopHeight > 0) {document.getElementById('pages').className = 'pagesSideBoxTopExist';}
else {document.getElementById('pages').className = 'pagesSideBoxTopNotExist';}
}
},
switchPage : function(page) {
if (this.currentPage) {
this.currentPage.hideContent();
this.currentPage.blurTab();
/*
for (var i in this.pages) {
this.pages[i].hideContent();
}
*/
}
page.showContent();
page.focusTab();
this.currentPage = page;
},
windowOnLoadListener : function() {
var page, tabContent;
this.showHideTabs();
page = new Sdl.Page();
page.contentContainer = document.getElementById('browserContainer');
tabContent = document.createElement('div');
tabContent.innerHTML = 'Browser';
page.tabContent = tabContent;
page.movableBar.moveTarget = document.getElementById('browserFilesContainer');
// IE6 retrieved incorrect .offsetHeight if there is no border in this case.
if (Sdl.System.isIe6()) {
Sdl.Object.modifyClassName(page.movableBar.moveTarget, 'moveTargetIe6', null);
}
this.addTab(page, false);
this.pages.push(page);
this.addMovableBar(page);
this.switchPage(page);
Sdl.browser.page = page;
this.showHideTabs();
}
}
//------------------------------------------------------------------------------
Sdl.Rss = function() {
var this_clone = this;
Sdl.browser.addOnLoadListener(function() {this_clone.browserOnLoadListener();});
}
Sdl.Rss.prototype = {
browserOnLoadListener : function() {
var rss;
rss = document.getElementById('rss');
if (Sdl.browser.status.success && Sdl.browser.cwd) {rss.href = '?print=rss&cwdRelPath=' + Sdl.browser.cwd.relPath;}
else {rss.removeAttribute('href');}
}
}
//------------------------------------------------------------------------------
Sdl.Main = function() {
Sdl.browser = new Sdl.Browser(); // Must be on top
Sdl.image = new Sdl.Image();
Sdl.layout = new Sdl.Layout();
Sdl.movableBar = new Sdl.MovableBar();
Sdl.pageManager = new Sdl.PageManager();
Sdl.rss = new Sdl.Rss();
Sdl.sfs = new Sdl.Sfs();
Sdl.sort = new Sdl.Sort();
Sdl.sortManager = new Sdl.SortManager();
}
//------------------------------------------------------------------------------
Sdl.Sfs = function() {
var this_clone = this;
Sdl.browser.addOnLoadListener(function() {this_clone.browserOnLoadListener();});
}
Sdl.Sfs.prototype = {
browserOnLoadListener : function() {
var sfs;
sfs = document.getElementById('sfs');
if (Sdl.browser.status.success && Sdl.browser.cwd) {sfs.href = '?print=sfs&cwdRelPath=' + Sdl.browser.cwd.relPath;}
else {sfs.removeAttribute('href');}
}
}
//------------------------------------------------------------------------------
Sdl.Sort = function() {
var this_clone = this;
this.pos = null;
this.sortSign = null;
this.sortOnClick = function() {
this_clone.order = -this_clone.order;
this_clone.sort();
Sdl.sortManager.sort = this_clone;
}
this.sortLiteral = function(a, b) {
if (a.sortValue.toLowerCase() > b.sortValue.toLowerCase()) {return this_clone.order;}
//if (a.sortValue > b.sortValue) {return this_clone.order;}
else {return -this_clone.order;}
}
this.sortNumeric = function(a, b) {
if (parseInt(a.sortValue, 10) > parseInt(b.sortValue, 10)) {return this_clone.order;}
else {return -this_clone.order;}
}
}
Sdl.Sort.prototype = {
setDefaultOrder : function(order) {
this.order = order;
},
setSortButton : function(button) {
Sdl.Object.modifyClassName(button, 'sortHeader', null);
button.onclick = this.sortOnClick;
button.onmouseover = function() {Sdl.Object.modifyClassName(this, 'sortHeaderMouseOver', null);}
button.onmouseout = function() {Sdl.Object.modifyClassName(this, null, 'sortHeaderMouseOver');}
},
sort : function() {
var files = [], refs = [];
Sdl.browser.traverseAllFilesOnAttribute(function(a, file) {
var arr = {};
arr.sortValue = a.innerHTML;
arr.clone = file.cloneNode(true);
arr.file = file;
files.push(arr);
refs.push(file);
}, this.attribute);
if (files.length > 0) {
var len, parentNode;
if (this.type == 'literal') {files.sort(this.sortLiteral);}
else if (this.type == 'numeric'){files.sort(this.sortNumeric);}
parentNode = refs[0].parentNode;
len = refs.length;
for (var i = 0 ; i < len ; i++) {
parentNode.appendChild(files[i].file);
}
}
}
}
Sdl.SortManager = function() {
var this_clone = this;
this.defaultSort = null;
Sdl.browser.addOnLoadListener(function() {this_clone.browserOnLoadListener();});
}
Sdl.SortManager.prototype = {
browserOnLoadListener : function() {
if (Sdl.browser.status.success) {
if (this.defaultSort != null) {
this.defaultSort.sort();
}
}
}
}
//------------------------------------------------------------------------------
Sdl.System = {};
Sdl.System.isIe6 = function() {
if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {return true;}
}
Sdl.System.isOpera = function() {
if (navigator.userAgent.toLowerCase().indexOf('opera') != -1) {return true;}
}
Sdl.System.isFf1 = function() {
if (navigator.userAgent.toLowerCase().indexOf('gecko') != -1 && navigator.userAgent.toLowerCase().indexOf('rv:1.7') != -1) {return true;}
}
//------------------------------------------------------------------------------
Sdl.Text = function() {}
Sdl.Text.decodeHtmlEntity = function(text) {
text = text.replace('&amp;', '&');
text = text.replace('&lt;', '<');
text = text.replace('&gt;', '>');
return text;
}
Sdl.Text.encodeHtmlEntity = function(text) {
text = text.replace('&', '&amp;');
text = text.replace('<', '&lt;');
text = text.replace('>', '&gt;');
return text;
}
//------------------------------------------------------------------------------
Sdl.Xml = function() {}
Sdl.Xml.digestResponseXml = function(xhr) {
var container, nodes, response = {};
if (!xhr) {
response.valid = false;
response.debug = '" . text("ERROR") . " : Sdl.Ajax';
return response;
}
if (xhr.responseXML == null) {
response.valid = false;
response.debug = xhr.responseText.substr(0, " . DEBUG_XML_RESPONSE_LENGTH . ");
return response;
}
container = xhr.responseXML.documentElement;
if (!container || container.tagName != 'container') {
response.valid = false;
response.debug = xhr.responseText.substr(0, " . DEBUG_XML_RESPONSE_LENGTH . ");
return response;
}
response.valid = true;
response.status = {};
nodes = container.getElementsByTagName('error')[0].childNodes;
response.error = nodes[0] ? nodes[0].nodeValue : null;
nodes = container.getElementsByTagName('status')[0].childNodes;
response.status.text = nodes[0] ? nodes[0].nodeValue : null;
nodes = container.getElementsByTagName('content')[0].childNodes;
if (nodes[0]) {
response.contentNodes = nodes;
response.content = '';
for (var i = 0 ; i < nodes.length ; i++) {
response.content += nodes[i].nodeValue;
}
} else {
response.content = null;
}
nodes = container.getElementsByTagName('debug')[0].childNodes;
response.debug = nodes[0] ? nodes[0].nodeValue : null;
nodes = container.getElementsByTagName('message')[0].childNodes;
response.message = nodes[0] ? nodes[0].nodeValue : null;
nodes = container.getElementsByTagName('warning')[0].childNodes;
response.warning = nodes[0] ? nodes[0].nodeValue : null;
if (response.status.text != null) {
if (response.status.text == 'success') {
response.status.success = true;
} else if (response.status.text == 'error') {
response.status.success = false;
} else {
response.status.success = null;
}
} else {
response.status.success = null;
}
return response;
}
Sdl.Xml.validateResponseAndWarn = function(response) {
if (response.valid) {
return true;
} else {
alert('" . text("ERROR") . " : " . text("INCORRECT XML RESPONSE") . ".\\n" . text("DEBUG") . " : \\n' + response.debug);
return false;
}
}
Sdl.Xml.alertResponse = function(response) {
if (response.status.success != null) {
if (response.status.success == true) {
if(response.message) {alert(response.message);}
if(response.warning) {alert('" . text("WARNING") . " : ' + response.warning);}
} else if (response.status.success == false){
alert('" . text("ERROR") . " : ' + response.error);
}
} else {
alert('" . text("ERROR") . " : " . text("UNKNOWN RESPONSE STATUS") . "');
}
}
//------------------------------------------------------------------------------
Sdl.main = new Sdl.Main();
";
return $javascript;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Layout
//------------------------------------------------------------------------------
class Layout {
var $cwdRelPath;
var $footer;
var $logout;
var $pageBrowser;
var $permittedDirRelPath;
var $sideBoxBottom;
var $sideBoxLeft;
var $sideBoxRight;
var $sideBoxTop;
var $view;
function getHtml() {
$this->cwdRelPath = addslashes($this->cwdRelPath);
if (!$this->sideBoxBottom) {$sideBoxBottomDisplay = "display:none;";}
if (!$this->sideBoxLeft) {$sideBoxLeftDisplay = "display:none;";}
if (!$this->sideBoxRight) {$sideBoxRightDisplay = "display:none;";}
if (!$this->sideBoxTop) {
$sideBoxTopDisplay = "display:none;";
$pagesClass = "pagesSideBoxTopNotExist";
} else {
$pagesClass = "pagesSideBoxTopExist";
}
$html = null;
$html .=
"
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<link rel='stylesheet' type='text/css' href='?print=css' />
<meta name='keywords' content='simple, directory, listing, $this->title'></meta>
<script type='text/javascript' src='?print=javascript'></script>
<script type='text/javascript'>
Sdl.browser.cwd.relPath = '$this->cwdRelPath';
Sdl.browser.view = '$this->view';
Sdl.browser.permittedDir.relPath = '$this->permittedDirRelPath';
</script>
<title>$this->title</title>
</head>
<body>
<div id='body'>
<div id='containerContainer'>
<table id='container'>
<tbody>
<tr>
<td class='containerCell' id='containerSideBoxLeftContainerCell' rowspan='3' style='{$sideBoxLeftDisplay}'>
<div id='containerSideBoxLeftContainer'>
<div id='containerSideBoxLeft'>$this->sideBoxLeft</div>
<div id='containerSideBoxLeftMovableBar'></div>
</div>
</td>
<td height='1px' class='containerCell' id='containerSideBoxTopContainerCell' colspan='2' style='{$sideBoxTopDisplay}'>
<div id='containerSideBoxTopContainer'>
<div id='containerSideBoxTop'>$this->sideBoxTop</div>
<div id='containerSideBoxTopMovableBar'></div>
</div>
</td>
</tr>
<tr>
<td class='containerCell' id='containerCentralContainerCell'>
<div id='containerCentralContainer'>
<div id='containerCentral'>
<div id='tabsContainer'>
<div id='tabs'></div>
<div id='tabsMovableBar'></div>
</div>
<div id='pagesContainer'>
<div id='pages' class='$pagesClass'>$this->pageBrowser</div>
<div id='pagesMovableBar'></div>
</div>
</div>
<div id='containerCentralMovableBar'></div>
</div>
</td>
<td class='containerCell' id='containerSideBoxRightContainerCell' style='{$sideBoxRightDisplay}'>
<div id='containerSideBoxRightContainer'>
<div id='containerSideBoxRight'>$this->sideBoxRight</div>
<div id='containerSideBoxRightMovableBar'></div>
</div>
</td>
<tr>
<td height='1px' class='containerCell' id='containerSideBoxBottomContainerCell' colspan='2' style='{$sideBoxBottomDisplay}'>
<div id='containerSideBoxBottomContainer'>
<div id='containerSideBoxBottom'>$this->sideBoxBottom</div>
<div id='containerSideBoxBottomMovableBar'></div>
</div>
</td>
</tr>
</tbody>
</table>
<div id='containerMovableBar'></div>
</div>
$this->footer
</div>
</body>
</html>
";
return $html;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Locale
//------------------------------------------------------------------------------
class Locale {
var $text;
function text($str, $replace=null, $firstCap=false) {
$str = $this->text[$str];
if (isset($replace)) {
foreach ($replace as $key => $value) {
$str = str_replace($key, $value, $str);
}
}
if ($firstCap) {
$str = strtoupper(substr($str, 0, 1)) . substr($str, 1);
}
return $str;
}
function setLocale() {
$localeClass = LOCALE_CLASS;
$locale = new $localeClass;
$this->text = $locale->text;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : System
//------------------------------------------------------------------------------
// added in 2.1
class System {
var $fileManager = null;
var $ftpLayerOn = false;
// added in 2.1
function sysChmod($absPath, $mode) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->chmod($absPath, $mode);
} else {
return chmod($absPath, $mode);
}
}
// added in 2.1
function sysCopy($srcAbsPath, $desAbsPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->copy($srcAbsPath, $desAbsPath);
} else {
return copy($srcAbsPath, $desAbsPath);
}
}
// added in 2.1
function sysMkdir($absPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->mkdir($absPath);
} else {
return mkdir($absPath);
}
}
// added in 2.1
function sysMoveUploadedFile($tmpAbsPath, $desAbsPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->moveUploadedFile($tmpAbsPath, $desAbsPath);
} else {
return move_uploaded_file($tmpAbsPath, $desAbsPath);
}
}
// added in 2.1
function sysRename($oldAbsPath, $newAbsPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->rename($oldAbsPath, $newAbsPath);
} else {
return rename($oldAbsPath, $newAbsPath);
}
}
// added in 2.1
function sysRmdir($absPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->rmdir($absPath);
} else {
return rmdir($absPath);
}
}
// added in 2.1
function sysTouch($absPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->touch($absPath);
} else {
return touch($absPath);
}
}
// added in 2.1
function sysUnlink($absPath) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->delete($absPath);
} else {
return unlink($absPath);
}
}
function sysWrite($absPath, $content) {
$ftp = $this->fileManager->user->ftp;
if ($this->ftpLayerOn && $ftp) {
return $ftp->putWithContent($absPath, $content);
} else {
return $this->write($absPath, $content);
}
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Module
//------------------------------------------------------------------------------
class Module extends System{
var $enabled = true;
var $disabledIfNotRequired = false;
// removed in 2.1
//var $fileManager;
var $locale;
var $localeClass;
var $moduleManager;
var $requiredModules = array();
var $text;
// added in 2.1
var $enabledAdminMode = true;
var $enabledUserMode = true;
function Module() {
if ($this->localeClass) {$this->locale = new $this->localeClass;}
}
function getCss() {}
function getHtml($fileIndex) {}
function getHtmlParentDirectory($file, $view) {}
function getIcon() {
return $this->icons[$_GET["moduleParams"]["icon"]];
}
function getJavascript() {}
function getRss($file) {}
function text($str, $replace = null, $firstCap = false) {
return $this->locale->text($str, $replace, $firstCap);
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : ModuleManager
//------------------------------------------------------------------------------
class ModuleManager {
var $modules = array();
var $attributes = array();
var $functions = array();
//var $sideBoxes = array();
var $sideBoxesBottom = array();
var $sideBoxesLeft = array();
var $sideBoxesRight = array();
var $sideBoxesTop = array();
var $services = array();
// edited in 2.1;
function ModuleManager($user) {
$classes = get_declared_classes();
foreach ($classes as $class) {
$class = strtolower($class);
if (strpos($class, "module") === 0 && strlen($class) > 6) {
// PHP 4 returns lowercase while PHP 5 returns the original one
//if (get_parent_class($class) === "module") {
if (strtolower(get_parent_class($class)) === "module") {
$module = new $class;
if ($module->requiredModules) {
foreach ($module->requiredModules as $requiredModule) {
$requiredModule = strtolower($requiredModule);
if (!class_exists($requiredModule)) {
die(text("MODULE ERROR") . " : $class " . text("REQUIRES") . " $requiredModule");
}
}
}
if ($module->enabled) {
// "b8ff02892916ff59f7fbd4e617fccd01f6bca576" === sha1("Module")
if (($user->mode == "admin" && $module->enabledAdminMode) || ($user->mode == "user" && $module->enabledUserMode)) {
$this->modules[] = $module;
}
/*
if ($module->isAttribute === true) {
$this->attributes[] = $module;
} else if($module->isFunction === true) {
$this->functions[] = $module;
} else if($module->isSideBox === true) {
//$this->sideBoxes[] = $module;
if ($module->isSideBoxPositionBottom) $this->sideBoxesBottom[] = $module;
if ($module->isSideBoxPositionLeft) $this->sideBoxesLeft[] = $module;
if ($module->isSideBoxPositionRight) $this->sideBoxesRight[] = $module;
if ($module->isSideBoxPositionTop) $this->sideBoxesTop[] = $module;
} else {
$this->services[] = $module;
}
*/
}
}
}
}
$requiredModules = array();
foreach ($this->modules as $module) {
foreach ($module->requiredModules as $requiredModule) {
$requiredModule = strtolower($requiredModule);
if(!$this->isModuleExist($requiredModule)) {
die(text("MODULE ERROR") . " : " . get_class($module) . " " . text("REQUIRES") . " $requiredModule");
}
$requiredModules[] = $requiredModule; // Store the list of required modules for next part
}
}
// Remove modules which are necessary only when required by others
foreach ($this->modules as $key => $module) {
if ($module->disabledIfNotRequired) {
if (!in_array(strtolower($module->moduleName), $requiredModules)) {
array_splice($this->modules, $key, 1);
}
}
}
foreach ($this->modules as $module) {
if ($module->isAttribute === true) {
$this->attributes[] = $module;
} else if($module->isFunction === true) {
$this->functions[] = $module;
} else if($module->isSideBox === true) {
//$this->sideBoxes[] = $module;
if ($module->isSideBoxPositionBottom) $this->sideBoxesBottom[] = $module;
if ($module->isSideBoxPositionLeft) $this->sideBoxesLeft[] = $module;
if ($module->isSideBoxPositionRight) $this->sideBoxesRight[] = $module;
if ($module->isSideBoxPositionTop) $this->sideBoxesTop[] = $module;
} else {
$this->services[] = $module;
}
}
$this->sortModules();
}
function getSideBoxes($pos, $cwdRelPath, $view) {
$html = null;
foreach ($this->{sideBoxes . $pos} as $sideBox) {
$html .= $sideBox->getHtml($cwdRelPath, $view);
}
return $html;
}
function isModuleExist($moduleName) {
foreach ($this->modules as $module) {
if (strcasecmp(get_class($module), $moduleName) == 0) {
return $module;
}
}
return false;
}
function setManagersToModules($fileManager, $user) {
foreach ($this->modules as $key=>$module) {
$this->modules[$key]->fileManager = $fileManager;
$this->modules[$key]->moduleManager = $this;
$this->modules[$key]->user = $user;
}
foreach ($this->functions as $key=>$function) {
$this->functions[$key]->fileManager = $fileManager;
$this->functions[$key]->moduleManager = $this;
$this->functions[$key]->user = $user;
}
foreach ($this->attributes as $key=>$attribute) {
$this->attributes[$key]->fileManager = $fileManager;
$this->attributes[$key]->moduleManager = $this;
$this->attributes[$key]->user = $user;
}
foreach ($this->sideBoxesBottom as $key=>$sideBox) {
$this->sideBoxesBottom[$key]->fileManager = $fileManager;
$this->sideBoxesBottom[$key]->moduleManager = $this;
$this->sideBoxesBottom[$key]->user = $user;
}
foreach ($this->sideBoxesLeft as $key=>$sideBox) {
$this->sideBoxesLeft[$key]->fileManager = $fileManager;
$this->sideBoxesLeft[$key]->moduleManager = $this;
$this->sideBoxesLeft[$key]->user = $user;
}
foreach ($this->sideBoxesRight as $key=>$sideBox) {
$this->sideBoxesRight[$key]->fileManager = $fileManager;
$this->sideBoxesRight[$key]->moduleManager = $this;
$this->sideBoxesRight[$key]->user = $user;
}
foreach ($this->sideBoxesTop as $key=>$sideBox) {
$this->sideBoxesTop[$key]->fileManager = $fileManager;
$this->sideBoxesTop[$key]->moduleManager = $this;
$this->sideBoxesTop[$key]->user = $user;
}
}
function sortModules() {
usort($this->attributes, array("ModuleManager", "sortModulesCmp"));
usort($this->functions, array("ModuleManager", "sortModulesCmp"));
//usort($this->sideBoxes, array("ModuleManager", "sortModulesCmp"));
usort($this->sideBoxesBottom, array("ModuleManager", "sortModulesCmp"));
usort($this->sideBoxesLeft, array("ModuleManager", "sortModulesCmp"));
usort($this->sideBoxesRight, array("ModuleManager", "sortModulesCmp"));
usort($this->sideBoxesTop, array("ModuleManager", "sortModulesCmp"));
}
function sortModulesCmp($module1, $module2) {
if ($module1->position == $module2->position) {return 0;}
return ($module1->position < $module2->position) ? -1 : 1;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Param
//------------------------------------------------------------------------------
class Param {
function filter(&$param) {
if (is_array($param)) {
array_map(array("Param", "filter"), &$param);
} else {
if (get_magic_quotes_gpc()) {$param = stripslashes($param);}
$param = Text::convertEncodingFromUtf8($param);
}
}
}
?>
<?php
class Rss {
var $fileManager;
var $moduleManager;
function printRss($cwdRelPath) {
$content = array();
$content["description"] = "(RSS generated by Simple Directory Listing - http://simpledirectorylisting.net)";
if (RSS_ON) {
if (isset($cwdRelPath)) {
$cwd = $this->fileManager->getFileByRelPath($cwdRelPath);
if ($cwd) {
if ($cwd->isDir) {
if ($cwd->isPermitted) {
$files = $this->fileManager->getFilesByDir($cwd->absPath);
$content["title"] = text("INDEX OF") . " /$cwd->relPath";
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}?cwdRelPath=$cwd->relPath";
$content["items"] = array();
if (count($files) > 0) {
foreach ($files as $fileIndex=>$file) {
$description = null;
foreach ($this->moduleManager->attributes as $attribute) {
$description .= $attribute->getRss($file, $fileIndex);
}
$item = array();
$item["description"] = $description;
$item["link"] = $file->url;
$item["title"] = $file->basename;
$content["items"][] = $item;
}
}
} else {
$content["title"] = text("ACCESS DENIED");
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}";
}
} else {
$content["title"] = text("ACCESS DENIED");
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}";
}
} else {
$content["title"] = text("ACCESS DENIED");
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}";
}
} else {
$content["title"] = text("ACCESS DENIED");
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}";
}
} else {
$content["title"] = text("RSS IS DISABLED.");
$content["link"] = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}";
}
$this->dumb($content);
}
function dumb($content) {
$xml = null;
$content["title"] = Text::convertEncodingToUtf8($content["title"]);
$content["link"] = Text::convertEncodingToUtf8($content["link"]);
$content["description"] = Text::convertEncodingToUtf8($content["description"]);
$xml .=
"<?xml version='1.0' encoding='utf-8'?>" .
"<rss version='2.0'>" .
"<channel>" .
"<title>" . htmlentities($content["title"], null, "utf-8") . "</title>" .
"<link>" . htmlentities($content["link"], null, "utf-8") . "</link>" .
"<description>" . htmlentities($content["description"], null, "utf-8") . "</description>" .
"<generator>Simple Directory Listing</generator>";
if ($content["items"]) {
foreach ($content["items"] as $item) {
$item["title"] = Text::convertEncodingToUtf8($item["title"]);
$item["link"] = Text::convertEncodingToUtf8($item["link"]);
$item["description"] = Text::convertEncodingToUtf8($item["description"]);
$xml .=
"<item>" .
"<title>" . htmlentities($item["title"], null, "utf-8") . "</title>" .
"<link>" . htmlentities($item["link"], null, "utf-8") . "</link>" .
"<description>" . htmlentities($item["description"], null, "utf-8") . "</description>" .
"</item>";
}
}
$xml .=
"</channel>" .
"</rss>";
header("content-type: text/xml");
echo $xml;
}
}
?>
<?php
class Sfs {
var $fileManager;
function printSfs($cwdRelPath) {
$content = array();
if (SFS_ON) {
if (isset($cwdRelPath)) {
$cwd = $this->fileManager->getFileByRelPath($cwdRelPath);
if ($cwd) {
if ($cwd->isDir) {
if($cwd->url != false) {
if ($cwd->isPermitted) {
$files = $this->fileManager->getFilesByDir($cwd->absPath);
$content["description"] = "(SFS generated by Simple Directory Listing - http://simpledirectorylisting.net)";
$content["cwd"] = array();
$content["cwd"]["path"] = $cwd->relPath;
$content["cwd"]["link"] = $cwd->url;
$content["cwd"]["mtime"] = filemtime($cwd->absPath);
$content["files"] = array();
if (count($files) > 0) {
foreach ($files as $fileIndex=>$file) {
$item = array();
$item["name"] = $file->basename;
$item["mtime"] = filemtime($file->absPath);
if ($file->isDir) {
$item["type"] = "dir";
$item["size"] = "";
} else {
$item["type"] = "file";
$item["size"] = filesize($file->absPath);
}
$content["files"][] = $item;
}
}
} else {
$content["description"] = text("ACCESS DENIED");
}
} else {
$content["description"] = text("ACCESS DENIED");
}
} else {
$content["description"] = text("ACCESS DENIED");
}
} else {
$content["description"] = text("ACCESS DENIED");
}
} else {
$content["description"] = text("ACCESS DENIED");
}
} else {
$content["description"] = text("ACCESS DENIED");
}
$this->dumb($content);
}
function dumb($content) {
$xml = null;
$content["description"] = Text::convertEncodingToUtf8($content["description"]);
$xml .=
"<?xml version='1.0' encoding='utf-8'?>" .
"<sfs version='1.0'>" .
"<description>{$content["description"]}</description>";
if ($content["cwd"]) {
$content["cwd"]["path"] = Text::convertEncodingToUtf8($content["cwd"]["path"]);
$content["cwd"]["link"] = Text::convertEncodingToUtf8($content["cwd"]["link"]);
$xml .=
"<cwd>" .
"<path>" . htmlentities($content["cwd"]["path"], null, "utf-8") . "</path>" .
"<link>" . htmlentities($content["cwd"]["link"], null, "utf-8") . "</link>" .
"<mtime>{$content["cwd"]["mtime"]}</mtime>" .
"</cwd>";
}
if ($content["files"]) {
foreach ($content["files"] as $file) {
$file["name"] = Text::convertEncodingToUtf8($file["name"]);
$file["link"] = Text::convertEncodingToUtf8($file["link"]);
$xml .=
"<file>" .
"<name>" . htmlentities($file["name"], null, "utf-8") . "</name>" .
"<mtime>{$file["mtime"]}</mtime>" .
"<size>{$file["size"]}</size>" .
"<type>{$file["type"]}</type>" .
"</file>";
}
}
$xml .=
"</sfs>";
header("content-type: text/xml");
echo $xml;
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : SimpleDirectoryListing
//------------------------------------------------------------------------------
class SimpleDirectoryListing {
var $fileManager;
var $moduleManager;
var $user;
// edited in 2.1;
function SimpleDirectoryListing() {
$this->validateConfig();
// edited in 2.1;
if (!SYSTEM_ON || (!ADMIN_MODE_ON && !USER_MODE_ON)){
if (!(isset($_GET["print"]) || isset($_GET["action"]))) {
echo text("SYSTEM HAS BEEN SHUTTED DOWN");
}
exit(0);
}
#-----------------------------------------------------------------------
# Service is available
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Anonymous visitor
#-----------------------------------------------------------------------
Param::filter($_GET);
Param::filter($_POST);
UserManager::proceedLoginLogout();
$this->user = UserManager::checkPermissionAndGetUser();
if (!$this->user) {
if (!(isset($_GET["print"]) || isset($_GET["action"]))) {UserManager::printLogin();}
if (isset($_GET["action"]) || $_GET["print"] === "dirListing") {echo text("PLEASE LOGIN");};
exit(0);
}
#-----------------------------------------------------------------------
# Have rights to access
#-----------------------------------------------------------------------
// added in 2.1;
if (($_GET["system"] === "loginPage") && !$_SESSION["loggedIn"]) {
UserManager::printLogin();
exit(0);
}
$this->moduleManager = new moduleManager($this->user);
// The output is static data
if (($_GET["print"] === "css")) {
$this->printCss();
exit(0);
}
// The output is static data
if (($_GET["print"] === "icon")) {
$this->printIcon();
exit(0);
}
// The output is static data
if (($_GET["print"] === "javascript")) {
$this->printJavascript();
exit(0);
}
#-----------------------------------------------------------------------
# Needs to have the $_GET['relCwd']
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Printing of sections and modules
# Execution of actions
#-----------------------------------------------------------------------
$this->fileManager = New fileManager();
$this->fileManager->user = $this->user;
$this->moduleManager->setManagersToModules($this->fileManager, $this->user);
// The output is static data
if (($_GET["print"] === "image")) {
$this->printImage();
exit(0);
}
// The output is static data
if (($_GET["print"] === "thumbnail")) {
$this->printThumbnail();
exit(0);
}
// The output is dynamic
if ($_GET["print"] === "dirListing") {
$this->printDirListing();
exit(0);
}
// The output is dynamic
if ($_GET["print"] === "rss") {
$this->printRss();
exit(0);
}
// The output is dynamic
if ($_GET["print"] === "sfs") {
$this->printSfs();
exit(0);
}
// The output is dynamic
if ($_GET["action"] === "module") {
$this->actionModule();
exit(0);
}
$this->printHtml();
exit(0);
}
function actionModule() {
$module = $this->moduleManager->isModuleExist($_GET["module"]);
if ($module) {
//$module->fileManager = $this->fileManager;
//$module->moduleManager = $this->moduleManager;
//$module->user = $this->user;
$module->action();
}
exit(0);
}
// edited in 2.1;
function getFooter() {
if (isset($_GET["cwdRelPath"])) {$rss = $sfs = $_GET["cwdRelPath"];}
else {$rss = $sfs = $this->user->permittedDirRelPath;}
if ($_SESSION["loggedIn"] === true) {
$logout = " <a href='?system=logout'>" . text("LOGOUT") . "</a>";
} else {
// shows login only if one of the modes needs login
if ((ADMIN_MODE_ON && ADMIN_MODE_NEEDS_LOGIN) || (USER_MODE_ON && USER_MODE_NEEDS_LOGIN)) {
$login = " <a href='?system=loginPage'>" . text("LOGIN") . "</a>";
}
}
$footer = null;
$footer .= "<div id='footer'>";
$footer .= "<div style='float:left'>";
$footer .= "<span id='poweredBy'><i><b>powered by <a href='http://simpledirectorylisting.net'>SimpleDirectoryListing</a></b></i></span>";
$footer .= " <a href='?print=rss&cwdRelPath=$rss' id='rss' target='_blank'>RSS</a>";
$footer .= " <a href='?print=sfs&cwdRelPath=$sfs' id='sfs' target='_blank'>SFS</a>";
$footer .= $login . $logout;
$footer .= " Mode:" . $this->user->mode;
$footer .= " <span id='font' style='cursor:pointer; display:none'>Font size: <span onclick='Sdl.Layout.increaseFontSize();'>[+]</span> <span onclick='Sdl.Layout.decreaseFontSize();'>[-]</span></span>";
$footer .= "</div>";
$footer .= "<div style='float:right'>" . META_WEB_SITE_NAME . "</div>";
$footer .= "</div>";
return $footer;
}
function getTheme() {
if (get_parent_class($_GET["theme"]) === "theme") {
$_SESSION["theme"] = $_GET["theme"];
$theme = new $_GET["theme"];
} else if (get_parent_class($_SESSION["theme"]) === "theme") {
$theme = new $_SESSION["theme"];
} else {
$themeName = THEME_CLASS;
$theme = new $themeName;
}
return $theme;
}
function printCss() {
header("Cache-Control: public");
header("content-type: text/css");
$theme = $this->getTheme();
$css = null;
$css .= $theme->getCss();
foreach ($this->moduleManager->modules as $module) {
$css .= $module->getCss();
}
echo $css;
exit(0);
}
// Output in XML format
function printDirListing() {
$browser = new Browser;
$browser->fileManager = $this->fileManager;
$browser->moduleManager = $this->moduleManager;
$browser->printDirListing($_GET["cwdRelPath"]);
exit(0);
}
function printHtml() {
$layout = new Layout;
$browser = new Browser;
if (isset($_GET["cwdRelPath"])) {$cwdRelPath = $_GET["cwdRelPath"];}
else {$cwdRelPath = $this->user->permittedDirRelPath;}
if ($_GET["view"] === "list" || $_GET["view"] === "thumbnail") {$view = $_GET["view"];}
else { $view = "list";}
$browser->fileManager = $this->fileManager;
$browser->moduleManager = $this->moduleManager;
$layout->pageBrowser = $browser->getHtml();
$layout->sideBoxBottom = $browser->moduleManager->getSideBoxes("Bottom", $cwdRelPath, $view);
$layout->sideBoxLeft = $browser->moduleManager->getSideBoxes("Left", $cwdRelPath, $view);
$layout->sideBoxRight = $browser->moduleManager->getSideBoxes("Right", $cwdRelPath, $view);
$layout->sideBoxTop = $browser->moduleManager->getSideBoxes("Top", $cwdRelPath, $view);
$layout->permittedDirRelPath = Text::htmlentitiesUtf8($this->user->permittedDirRelPath);
$layout->cwdRelPath = Text::htmlentitiesUtf8($cwdRelPath);
$layout->view = $view;
$layout->title = Text::htmlentitiesUtf8("/$cwdRelPath") . " - Simple Directory Listing";
$layout->footer = $this->getFooter();
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/html; charset=utf-8");
$html = null;
$html .= $layout->getHtml();
echo Text::convertEncodingToUtf8($html);
}
function printIcon() {
if (ICON_ON) {
if (isset($_GET["module"])) {
if ($this->moduleManager->isModuleExist($_GET["module"])) {
header("Cache-Control: public");
$module = new $_GET["module"];
$icon = base64_decode($module->getIcon());
}
} else {
$theme = $this->getTheme();
$icon = base64_decode($theme->icons[$_GET["icon"]]);
}
//header('Content-type: image/gif');
header('Content-length: '.strlen($icon));
echo $icon;
}
exit(0);
}
function printImage() {
if (IMAGE_PASSTHRU_ON) {
$file = $this->fileManager->getFileByRelPath($_GET["relPath"]);
if ($file) {
if ($file->isPermitted) {
$image = new Image();
$image->printImage($file);
}
}
}
exit(0);
}
function printJavascript() {
$javascriptObj = new Javascript;
$javascript = $javascriptObj->getJavascrtipt();
foreach ($this->moduleManager->modules as $module) {
$javascript .= $module->getJavascript();
}
header("Cache-Control: public");
header("content-type: text/javascript");
echo $javascript;
}
function printRss() {
$rss = new Rss;
$rss->fileManager = $this->fileManager;
$rss->moduleManager = $this->moduleManager;
$rss->printRss($_GET["cwdRelPath"]);
exit(0);
}
function printSfs() {
$sfs = new Sfs;
$sfs->fileManager = $this->fileManager;
//$rss->moduleManager = $this->moduleManager;
$sfs->printSfs($_GET["cwdRelPath"]);
exit(0);
}
function printThumbnail() {
if (THUMBNAIL_ON) {
$file = $this->fileManager->getFileByRelPath($_GET["relPath"]);
if ($file) {
if ($file->isPermitted) {
$image = new Image();
$image->printThumbnail($file);
}
}
}
exit(0);
}
function validateConfig() {}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Text
//------------------------------------------------------------------------------
class Text {
var $text;
function convertEncodingToUtf8($str) {
if(OS_ENCODING != null) {
if (mb_detect_encoding($str, OS_ENCODING . ",utf-8")) {
return mb_convert_encoding($str, "utf-8", OS_ENCODING . ",utf-8");
}
}
return $str;
}
function convertEncodingFromUtf8($str) {
if(OS_ENCODING != null) {
if (mb_detect_encoding($str, OS_ENCODING . ",utf-8")) {
return mb_convert_encoding($str, OS_ENCODING, OS_ENCODING . ",utf-8");
}
}
return $str;
}
function htmlentitiesUtf8($str) {
return htmlentities(Text::convertEncodingToUtf8($str), null, "utf-8");
}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : Theme
//------------------------------------------------------------------------------
class Theme {
var $icons = array();
function getCss() {}
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : User
//------------------------------------------------------------------------------
class User {
var $ftp = null;
var $mode = false;
var $virtualRootAbsPath = null;
var $permittedDirAbsPath = null;
var $permittedDirRelPath = null;
}
?>
<?php
//------------------------------------------------------------------------------
// Class name : UserManager
//------------------------------------------------------------------------------
class UserManager {
var $user;
// edited in 2.1;
// It checks session and config
function getMode() {
if (ADMIN_MODE_ON) {
if (ADMIN_MODE_NEEDS_LOGIN) {
if ($_SESSION["mode"] === "admin") {return "admin";}
} else {
return "admin";
}
}
if (USER_MODE_ON) {
if (USER_MODE_NEEDS_LOGIN) {
if ($_SESSION["mode"] === "user") {return "user";}
} else {
return "user";
}
}
return false;
}
// edited in 2.1;
// It returns a user
function checkPermissionAndGetUser() {
$user = new User;
$user->mode = UserManager::getMode();
if ($user->mode === "admin") {
//$user->virtualRootAbsPath = ADMIN_MODE_VIRTUAL_ROOT;
$configVirtualRoot = ADMIN_MODE_VIRTUAL_ROOT;
$configCustomVirtualRoot = ADMIN_MODE_CUSTOM_VIRTUAL_ROOT;
$configPermittedDir = ADMIN_MODE_PERMITTED_DIR;
} elseif ($user->mode === "user") {
$configVirtualRoot = USER_MODE_VIRTUAL_ROOT;
$configCustomVirtualRoot = USER_MODE_CUSTOM_VIRTUAL_ROOT;
$configPermittedDir = USER_MODE_PERMITTED_DIR;
}
else {return false;}
$user->virtualRootAbsPath = $configVirtualRoot;
// Some OS's add an ending slash to paths of directories
if ($user->virtualRootAbsPath === "CURRENT_WORKING_DIR") {$user->virtualRootAbsPath = dirname($_SERVER['SCRIPT_FILENAME']);}
elseif ($user->virtualRootAbsPath === "DOCUMENT_ROOT") {$user->virtualRootAbsPath = $_SERVER['DOCUMENT_ROOT'];}
elseif ($user->virtualRootAbsPath === "SERVER_ROOT") {$user->virtualRootAbsPath = substr($_SERVER['DOCUMENT_ROOT'], 0, strpos($_SERVER['DOCUMENT_ROOT'], "/")+ 1);}
elseif ($user->virtualRootAbsPath === "CUSTOM_ROOT") {$user->virtualRootAbsPath = $configCustomVirtualRoot;}
// virtual root does not need to have relPath because it is null.
$user-><