/*
* TURDLE is "The Ultimate Recursive Directory Lister, Enhanced"
* it's not called ÑORDO because that doesn't make an nice acronym.
*
* It lists the content of the defined directory and creates
* links to it's content.
* It does not show files starting with ".".
* It does not show itself.
* It does not validate as HTML 4.01 Strict!
* It peruses the word "it" in it's header
*
* Copyright 2010 Lucas Vieites Fariña (except when noted otherwise,
* for example some of the functions used)
* It is licensed under the GNU/GPL or later, see below:
*/
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
// And now, for something completely different...
// CONFIGURATION SECTION
$base_dir = dirname(__FILE__); // Filesystem path to base directory
$language = "en"; // Interface language (see I18N section for available languages)
$dcol1 = "#AAC0D1"; // dir list even row color
$dcol2 = "#D2E2ED"; // dir list odd row color
$fcol1 = "#D9E6F0"; // file list even row color
$fcol2 = "#FFFFFF"; // file list odd row color
// If one of the files present in the $default_pages array is present
// in the current directory, load it instead ot the directory listing
$show_default_page = 1; // 1 = show default, 0 = show listing
$default_pages = array(
"index.html",
"index.htm",
"index.php",
"default.html",
"default.htm",
"default.php",
"home.html",
"home.htm",
"home.php"
);
// END CONFIGURATION SECTION
// I18N - Internationalisation
$strings = array(
"DIRECTORY_LISTING" => "Directory listing for:",
"YOU_ARE_HERE" => "You are here:",
"HOME" => "Home",
"BACK" => "Back",
"NOT_ALLOWED" => "You are not allowed to go here:"
);
switch ($language) {
case 'es';
$strings = array(
"DIRECTORY_LISTING" => "Listado del directorio:",
"YOU_ARE_HERE" => "Estás aquí:",
"HOME" => "Inicio",
"BACK" => "Atrás",
"NOT_ALLOWED" => "No tiene permiso para ir aquí:"
);
break;
case 'fr';
$strings = array(
"DIRECTORY_LISTING" => "Listage du répertoire:",
"YOU_ARE_HERE" => "Vous êtes ici:",
"HOME" => "Accueil",
"BACK" => "Retour",
"NOT_ALLOWED" => "Vous n'avez pas les droits d'accès à:"
);
break;
default :
// default language is english
break;
}
// END I18N
// FUNCTIONS
/**
* Return human readable sizes
*
* @author Aidan Lister
* @version 1.1.0
* @link http://aidanlister.com/repos/v/function.size_readable.php
* @param int $size Size
* @param int $unit The maximum unit
* @param int $retstring The return string format
* @param int $si Whether to use SI prefixes
*/
function size_readable($size, $unit = null, $retstring = null, $si = true) {
// Units
if ($si === true) {
$sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$mod = 1000;
} else {
$sizes = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
$mod = 1024;
}
$ii = count($sizes) - 1;
// Max unit
$unit = array_search((string) $unit, $sizes);
if ($unit === null || $unit === false) {
$unit = $ii;
}
// Return string
if ($retstring === null) {
$retstring = '%01.2f %s';
}
// Loop
$i = 0;
while ($unit != $i && $size >= 1024 && $i < $ii) {
$size /= $mod;
$i++;
}
return sprintf($retstring, $size, $sizes[$i]);
}
function print_navigation($dir) {
global $base_dir, $strings;
// Show breadcrumb
print($strings["YOU_ARE_HERE"] . " ");
$this_dir = str_replace($base_dir, ".", $dir);
$folders = explode("/", $this_dir);
foreach ($folders as $folder) {
$linkstring .= $folder."/";
if ($folder == ".") $folder = $strings["HOME"]; // Replace dot with name
print(''.$folder.' / ');
}
print('');
// Show Back link
print('< '.$strings["BACK"].'');
}
// END FUNCTIONS
if (!isset($_GET['d'])) {
$the_dir = $base_dir;
$is_subdir = 0;
} else {
$the_dir = realpath("./".$_GET['d']);
$is_subdir = 1;
}
//echo "#$the_dir# => #".realpath($the_dir)."# ";
// Check if the_dir is a subdirectory of base_dir
if (strlen($the_dir >= $base_dir) && substr($the_dir, 0, strlen($base_dir)) == $base_dir) {
// it's OK
} else {
//echo "WRONG_DIR ";
$wrong_dir = $the_dir;
// Fallback to base dir
$the_dir = $base_dir;
$is_subdir = 0;
}
// Open the directory
if ($handle = opendir($the_dir)) {
$directories = array();
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".."
&& substr($file, 0, 1) != "."
&& $file != basename($_SERVER["PHP_SELF"])) {
// Put directories and files each in their own array
if (is_dir($the_dir."/".$file)) {
$directories[] = $file;
} else {
$files[] = $file;
}
}
}
closedir($handle);
}
// Sort the arrays by natural alphabetic order
natcasesort($directories);
natcasesort($files);
// Print the list
?>
');
if ($is_subdir) {
print_navigation($the_dir);
}
?>
Listed for you by "The Ultimate Recursive Directory Lister, Enhanced" (TURDLE) version 0.1 - by Lucas 'Basurero' Vieites