Refactored and lots of modification. See README.md.

This commit is contained in:
Lars Jung 2012-04-16 12:53:54 +02:00
parent 859a680e19
commit 71ed41fa69
85 changed files with 3191 additions and 2969 deletions

View file

@ -1,17 +1,10 @@
<?php
function safe_dirname($path, $endWithSlash = false) {
require_once(str_replace("\\", "/", __DIR__) . "/inc/H5ai.php");
$path = str_replace("\\", "/", dirname($path));
return preg_match("#^(\w:)?/$#", $path) ? $path : (preg_replace('#/$#', '', $path) . ($endWithSlash ? "/" : ""));
}
define("H5AI_ABS_PATH", safe_dirname(safe_dirname(__FILE__)));
function require_h5ai($lib) {
require_once(H5AI_ABS_PATH . $lib);
}
$h5ai = new H5ai();
$options = $h5ai->getOptions();
function fail($code, $msg, $cond = true) {
@ -31,11 +24,6 @@ function checkKeys($keys) {
}
require_h5ai("/php/inc/H5ai.php");
$h5ai = new H5ai();
$options = $h5ai->getOptions();
list($action) = checkKeys(array("action"));
@ -64,11 +52,11 @@ if ($action === "httpcodes") {
else if ($action === "thumb") {
fail(0, "thumbs are disabled", !$options["showThumbs"]);
fail(0, "thumbs are disabled", !$options["thumbnails"]["enabled"]);
list($srcAbsHref, $width, $height, $mode) = checkKeys(array("href", "width", "height", "mode"));
require_h5ai("/php/inc/Thumbnail.php");
require_h5ai("/php/inc/Image.php");
H5ai::req_once("/php/inc/Thumbnail.php");
H5ai::req_once("/php/inc/Image.php");
$srcAbsPath = $h5ai->getRootAbsPath() . rawurldecode($srcAbsHref);
@ -90,28 +78,42 @@ else if ($action === "thumb") {
}
else if ($action === "tree") {
else if ($action === "thumbsrc") {
list($href) = checkKeys(array("href"));
if (!$options["thumbnails"]["enabled"]) {
echo json_encode(array("code" => 1, "absHref" => null));
exit;
}
require_h5ai("/php/inc/Tree.php");
list($srcAbsHref, $width, $height, $mode) = checkKeys(array("href", "width", "height", "mode"));
$absHref = trim($href);
$absPath = $h5ai->getAbsPath($absHref);
H5ai::req_once("/php/inc/Thumbnail.php");
H5ai::req_once("/php/inc/Image.php");
$tree = new TreeEntry($h5ai, $absPath, $absHref);
$tree->loadContent();
$srcAbsPath = $h5ai->getRootAbsPath() . rawurldecode($srcAbsHref);
echo $tree->contentToHtml();
if (!Thumbnail::isUsable()) {
echo json_encode(array("code" => 2, "absHref" => null));
exit;
}
$thumbnail = new Thumbnail($h5ai, $srcAbsHref, $mode, $width, $height);
$thumbnail->create(1);
if (!file_exists($thumbnail->getPath())) {
echo json_encode(array("code" => 3, "absHref" => null));
exit;
}
echo json_encode(array("code" => 0, "absHref" => $thumbnail->getHref()));
}
else if ($action === "zip") {
fail(0, "zipped download is disabled", !$options["zippedDownload"]);
fail(0, "zipped download is disabled", !$options["zipped-download"]["enabled"]);
list($hrefs) = checkKeys(array("hrefs"));
require_h5ai("/php/inc/ZipIt.php");
H5ai::req_once("/php/inc/ZipIt.php");
$zipit = new ZipIt($h5ai);
@ -147,8 +149,10 @@ else if ($action === "checks") {
$response = array(
'php' => $h5ai->checks["php"],
'zips' => $h5ai->checks["php"] && $h5ai->checks["zip"],
'thumbs' => $h5ai->checks["php"] && $h5ai->checks["gd"]
'cache' => $h5ai->checks["php"] && $h5ai->checks["cache"],
'thumbs' => $h5ai->checks["php"] && $h5ai->checks["cache"] && $h5ai->checks["gd"],
'temp' => $h5ai->checks["php"] && $h5ai->checks["temp"],
'zips' => $h5ai->checks["php"] && $h5ai->checks["temp"] && $h5ai->checks["zip"]
);
echo json_encode($response);
}

View file

@ -1,55 +0,0 @@
<?php
class Crumb {
private $h5ai, $parts;
public function __construct($h5ai) {
$this->h5ai = $h5ai;
$this->parts = array();
$href = $h5ai->getAbsHref();
while ($href !== "/") {
$this->parts[] = $href;
$href = safe_dirname($href, true);
}
$this->parts[] = "/";
$this->parts = array_reverse($this->parts);
}
public function toHtml() {
$html = "";
$idx = 0;
foreach($this->parts as $href) {
$idx++;
$classes = "crumb folder" . ($idx === 1 ? " domain" : "") . ($idx === count($this->parts) ? " current" : "");
$image = $this->h5ai->image($idx === 1 ? "home" : "crumb");
$label = $this->h5ai->getLabel($href);
$hint = "";
$code = $this->h5ai->getHttpCode($href);
$classes .= " checkedHttpCode";
if ($code !== "h5ai") {
if ($code === 200) {
$hint = "<img class='hint' src='" . $this->h5ai->image("page") . "' alt='page' />";
} else {
$hint = "<span class='hint'>(" . $code . ")</span>";
}
}
$html .= "<li class='$classes'>\n";
$html .= "\t<a href='$href'>\n";
$html .= "\t\t<img src='$image' alt='>' /><span>" . $label . "</span>" . $hint . "\n";
$html .= "\t</a>\n";
$html .= "</li>\n";
}
return $html;
}
}
?>

View file

@ -1,35 +0,0 @@
<?php
class Customize {
private $customHeader, $customFooter;
public function __construct($h5ai) {
$absPath = $h5ai->getAbsPath();
$options = $h5ai->getOptions();
$this->customHeader = $options["customHeader"] ? $absPath . "/" . $options["customHeader"] : false;
$this->customFooter = $options["customFooter"] ? $absPath . "/" . $options["customFooter"] : false;
}
public function getHeader() {
return $this->getContent($this->customHeader, "header");
}
public function getFooter() {
return $this->getContent($this->customFooter, "footer");
}
private function getContent($file, $tag) {
return (is_string($file) && file_exists($file)) ? ("<$tag>" . file_get_contents($file) . "</$tag>") : "";
}
}
?>

105
src/_h5ai/php/inc/Entry.php Normal file
View file

@ -0,0 +1,105 @@
<?php
class Entry {
private static $cache = array();
public static function getCache() {
return Entry::$cache;
}
public static function get($h5ai, $absPath, $absHref) {
if (array_key_exists($absHref, Entry::$cache)) {
return Entry::$cache[$absHref];
}
return new Entry($h5ai, $absPath, $absHref);
}
public static function sort() {
uasort(Entry::$cache, function ($entry1, $entry2) {
return strcasecmp($entry1->absHref, $entry2->absHref);
});
}
public $h5ai, $absPath, $absHref, $date, $size, $isFolder, $parent;
private function __construct($h5ai, $absPath, $absHref) {
$this->h5ai = $h5ai;
$this->absPath = H5ai::normalize_path($absPath);
$this->isFolder = is_dir($this->absPath);
$this->absHref = H5ai::normalize_path($absHref, $this->isFolder);
$this->date = filemtime($this->absPath);
if ($this->isFolder) {
$this->size = null;
} else {
$this->size = filesize($this->absPath);
}
$this->parent = null;
if ($this->absHref !== "/") {
$this->parent = Entry::get($this->h5ai, H5ai::normalize_path(dirname($this->absPath)), H5ai::normalize_path(dirname($this->absHref), true));
}
Entry::$cache[$this->absHref] = $this;
}
public function toJsonObject($withStatus) {
$obj = array(
"absHref" => $this->absHref,
"time" => ($this->date * 1000),
"size" => $this->size
);
if ($withStatus && $this->isFolder) {
$obj["status"] = $this->h5ai->getHttpCode($this->absHref);
}
return $obj;
}
public function getParent() {
return $this->parent;
}
public function getContent() {
$content = array();
if ($this->h5ai->getHttpCode($this->absHref) !== "h5ai") {
return $content;
}
$files = $this->h5ai->readDir($this->absPath);
foreach ($files as $file) {
$entry = Entry::get($this->h5ai, $this->absPath . "/" . $file, $this->absHref . rawurlencode($file));
$content[$entry->absPath] = $entry;
}
return $content;
}
}
?>

View file

@ -1,152 +0,0 @@
<?php
require_h5ai("/php/inc/Thumbnail.php");
class Entry {
private $h5ai, $label, $absPath, $absHref, $date, $isFolder, $type, $size;
public function __construct($h5ai, $absPath, $absHref, $type = null, $label = null) {
$this->h5ai = $h5ai;
$this->label = $label !== null ? $label : $this->h5ai->getLabel($absHref);
$this->absPath = $this->h5ai->normalizePath($absPath, false);
$this->isFolder = is_dir($this->absPath);
$this->absHref = $this->h5ai->normalizePath($absHref, $this->isFolder);
$this->date = filemtime($this->absPath);
if ($this->isFolder) {
$this->type = $type !== null ? $type : "folder";
$this->size = "";
} else {
$this->type = $type !== null ? $type : $this->h5ai->getType($this->absPath);
$this->size = filesize($this->absPath);
}
}
public function isFolder() {
return $this->isFolder;
}
public function toHtml() {
$classes = "entry " . ($this->isFolder ? "folder " : "file ") . $this->type;
$imgClass = "";
$img = $this->type;
$smallImg = $this->h5ai->icon($this->type);
$bigImg = $this->h5ai->icon($this->type, true);
$hint = "";
if ($this->isFolder && $this->type !== "folder-parent") {
$code = $this->h5ai->getHttpCode($this->absHref);
$classes .= " checkedHttpCode";
if ($code !== "h5ai") {
if ($code === 200) {
$img = "folder-page";
$smallImg = $this->h5ai->icon("folder-page");
$bigImg = $this->h5ai->icon("folder-page", true);
} else {
$classes .= " error";
$hint = "<span class='hint'> " . $code . " </span>";
}
}
}
if ($this->h5ai->showThumbs() && in_array($this->type, $this->h5ai->getThumbTypes())) {
$imgClass = " class='thumb' ";
$thumbnail = new Thumbnail($this->h5ai, $this->absHref, "square", 16, 16);
$thumbnail->create();
$smallImg = file_exists($thumbnail->getPath()) ? $thumbnail->getHref() : $thumbnail->getLiveHref();
$thumbnail = new Thumbnail($this->h5ai,$this->absHref, "rational", 96, 46);
$thumbnail->create();
$bigImg = file_exists($thumbnail->getPath()) ? $thumbnail->getHref() : $thumbnail->getLiveHref();
}
$html = "\t<li class='" . $classes . "'>\n";
$html .= "\t\t<a href='" . $this->absHref . "'>\n";
$html .= "\t\t\t<span class='icon small'><img " . $imgClass . " src='" . $smallImg . "' alt='" . $img . "' /></span>\n";
$html .= "\t\t\t<span class='icon big'><img " . $imgClass . " src='" . $bigImg . "' alt='" . $img . "' /></span>\n";
$html .= "\t\t\t<span class='label'>" . $this->label . $hint . "</span>\n";
$html .= "\t\t\t<span class='date' data-time='" . $this->date . "000'></span>\n";
$html .= "\t\t\t<span class='size' data-bytes='" . $this->size . "'>" . $this->size . "</span>\n";
$html .= "\t\t</a>\n";
$html .= "\t</li>\n";
return $html;
}
}
class Extended {
private $h5ai, $parent, $content;
public function __construct($h5ai) {
$this->h5ai = $h5ai;
$this->parent = null;
$this->content = array();
$this->loadContent();
}
private function loadContent() {
if ($this->h5ai->getAbsHref() !== "/") {
$options = $this->h5ai->getOptions();
$parentPath = safe_dirname($this->h5ai->getAbsPath());
$parentHref = safe_dirname($this->h5ai->getAbsHref(), true);
$label = $options["setParentFolderLabels"] === true ? $this->h5ai->getLabel($parentHref) : "<span class='l10n-parentDirectory'>Parent Directory</span>";
$this->parent = new Entry($this->h5ai, $parentPath, $parentHref, "folder-parent", $label);
}
$this->content = array();
$files = $this->h5ai->readDir($this->h5ai->getAbsPath());
foreach ($files as $file) {
$absPath = $this->h5ai->getAbsPath() . "/" . $file;
$absHref = $this->h5ai->getAbsHref() . rawurlencode($file);
$this->content[$absPath] = new Entry($this->h5ai, $absPath, $absHref);
}
}
public function toHtml() {
$html = "<section id='extended' class='" . $this->h5ai->getView() . "-view clearfix'>\n";
$html .= "<ul>\n";
$html .= $this->generateHeaders();
if ($this->parent !== null) {
$html .= $this->parent->toHtml();
}
foreach($this->content as $entry) {
$html .= $entry->toHtml();
}
$html .= "</ul>\n";
if (count($this->content) === 0) {
$html .= "<div class='empty l10n-empty'>empty</div>";
}
$html .= "<div class='no-match l10n-noMatch'>no match</div>";
$html .="</section>";
return $html;
}
private function generateHeaders() {
$html = "\t<li class='header'>\n";
$html .= "\t\t<a class='icon'></a>\n";
$html .= "\t\t<a class='label' href='#'><span class='l10n-name'>Name</span></a>\n";
$html .= "\t\t<a class='date' href='#'><span class='l10n-lastModified'>Last modified</span></a>\n";
$html .= "\t\t<a class='size' href='#'><span class='l10n-size'>Size</span></a>\n";
$html .= "\t</li>\n";
return $html;
}
}
?>

View file

@ -1,58 +1,43 @@
<?php
require_h5ai("/config.php");
require_h5ai("/php/inc/Cache.php");
define("H5AI_ABS_PATH", H5ai::normalize_path(dirname(dirname(dirname(__FILE__)))));
H5ai::req_once("/config.php");
H5ai::req_once("/php/inc/Cache.php");
H5ai::req_once("/php/inc/Entry.php");
class H5ai {
private static $VIEWMODES = array("details", "icons");
private $h5aiAbsPath,
$rootAbsPath, $ignore, $ignoreRE,
$config, $options, $types, $langs,
$cache,
$rootAbsHref, $h5aiAbsHref, $domain,
$absHref, $absPath,
$view;
public static final function normalize_path($path, $endWithSlash = false) {
public function __construct() {
$this->checks = array(
"php" => version_compare(PHP_VERSION, "5.2.0") >= 0,
"zip" => class_exists("ZipArchive"),
"gd" => GD_VERSION != "GD_VERSION"
);
$this->h5aiAbsPath = H5AI_ABS_PATH;
global $H5AI_CONFIG;
$this->rootAbsPath = $H5AI_CONFIG["ROOT_ABS_PATH"];
$this->ignore = $H5AI_CONFIG["IGNORE"];
$this->ignoreRE = $H5AI_CONFIG["IGNORE_PATTERNS"];
$this->config = $this->loadConfig($this->h5aiAbsPath . "/config.js");
$this->options = $this->config["options"];
$this->types = $this->config["types"];
$this->langs = $this->config["langs"];
$this->cache = new Cache($this->h5aiAbsPath . "/cache");
$this->rootAbsHref = $this->options["rootAbsHref"];
$this->h5aiAbsHref = $this->options["h5aiAbsHref"];
$this->domain = getenv("HTTP_HOST");
$this->absHref = $this->normalizePath(preg_replace('/\\?.*/', '', getenv("REQUEST_URI")), true);
$this->absPath = $this->getAbsPath($this->absHref);
$this->view = $this->options["viewmodes"][0];
if (!in_array($this->view, H5ai::$VIEWMODES)) {
$this->view = H5ai::$VIEWMODES[0];
}
$path = str_replace("\\", "/", $path);
return preg_match("#^(\w:)?/$#", $path) ? $path : (preg_replace('#/$#', '', $path) . ($endWithSlash ? "/" : ""));
}
private function loadConfig($file) {
public static final function req_once($lib) {
require_once(H5AI_ABS_PATH . $lib);
}
public static final function starts_with($sequence, $start) {
return strcasecmp(substr($sequence, 0, strlen($start)), $start) === 0;
}
public static final function ends_with($sequence, $end) {
return strcasecmp(substr($sequence, -strlen($end)), $end) === 0;
}
private static final function load_config($file) {
$str = file_exists($file) ? file_get_contents($file) : "";
@ -66,9 +51,43 @@ class H5ai {
}
public function getH5aiAbsPath() {
return $this->h5aiAbsPath;
private $h5aiAbsPath,
$rootAbsPath, $ignore, $ignoreRE,
$config, $options,
$cache,
$rootAbsHref, $h5aiAbsHref,
$absHref, $absPath;
public function __construct() {
$this->h5aiAbsPath = H5ai::normalize_path(H5AI_ABS_PATH);
global $H5AI_CONFIG;
$this->rootAbsPath = H5ai::normalize_path($H5AI_CONFIG["ROOT_ABS_PATH"]);
$this->ignore = $H5AI_CONFIG["IGNORE"];
$this->ignoreRE = $H5AI_CONFIG["IGNORE_PATTERNS"];
$this->config = H5ai::load_config($this->h5aiAbsPath . "/config.js");
$this->options = $this->config["options"];
$this->rootAbsHref = H5ai::normalize_path($this->options["rootAbsHref"], true);
$this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true);
$this->absHref = H5ai::normalize_path(preg_replace('/\\?.*/', '', getenv("REQUEST_URI")), true);
$this->absPath = $this->getAbsPath($this->absHref);
$this->cache = new Cache($this->h5aiAbsPath . "/cache");
$this->checks = array(
"php" => version_compare(PHP_VERSION, "5.2.0") >= 0,
"zip" => class_exists("ZipArchive"),
"gd" => GD_VERSION != "GD_VERSION",
"cache" => is_writable($this->h5aiAbsPath . "/cache"),
"temp" => is_writable(sys_get_temp_dir())
);
}
@ -78,6 +97,12 @@ class H5ai {
}
public function getH5aiAbsPath() {
return $this->h5aiAbsPath;
}
public function getRootAbsHref() {
return $this->rootAbsHref;
@ -90,54 +115,18 @@ class H5ai {
}
public function getDomain() {
return $this->domain;
}
public function getView() {
return $this->view;
}
public function api() {
return $this->h5aiAbsHref . "php/api.php";
}
public function image($id) {
return $this->h5aiAbsHref . "images/" . $id . ".png";
}
public function icon($id, $big = false) {
return $this->h5aiAbsHref . "icons/" . ($big ? "48x48" : "16x16") . "/" . $id . ".png";
}
public function getOptions() {
return $this->options;
}
public function getLangs() {
return $this->langs;
}
public function normalizePath($path, $endWithSlash) {
return preg_match("#^(\w:)?/$#", $path) ? $path : (preg_replace('#/$#', '', $path) . ($endWithSlash ? "/" : ""));
}
public function getAbsHref($absPath = null, $endWithSlash = true) {
if ($absPath === null) {
@ -152,7 +141,7 @@ class H5ai {
$encodedParts[] = rawurlencode($part);
}
return $this->normalizePath($this->rootAbsHref . implode("/", $encodedParts), $endWithSlash);
return H5ai::normalize_path($this->rootAbsHref . implode("/", $encodedParts), $endWithSlash);
}
@ -164,51 +153,14 @@ class H5ai {
$absHref = substr($absHref, strlen($this->rootAbsHref));
return $this->normalizePath($this->rootAbsPath . "/" . rawurldecode($absHref), false);
}
public function showThumbs() {
return $this->options["showThumbs"] === true;
}
public function getThumbTypes() {
return $this->options["thumbTypes"];
}
public function getTitle() {
$title = $this->domain . rawurldecode($this->absHref);
$title = preg_replace("/\/$/", "", $title);
$title = preg_replace("/\//", " > ", $title);
if ($this->absHref !== "/") {
$title = basename($this->absPath) . " - " . $title;
}
return $title;
}
public function getType($absPath) {
foreach($this->types as $type => $exts) {
foreach($exts as $ext) {
if ($this->endsWith($absPath, $ext)) {
return $type;
}
}
}
return "unknown";
return H5ai::normalize_path($this->rootAbsPath . "/" . rawurldecode($absHref));
}
public function ignoreThisFile($file) {
// always ignore
if ($file === "." || $file === ".." || $this->startsWith($file, '.ht')) {
if ($file === "." || $file === ".." || H5ai::starts_with($file, '.ht')) {
return true;
}
@ -242,24 +194,6 @@ class H5ai {
}
public function getLabel($absHref) {
return $absHref === "/" ? $this->domain : rawurldecode(basename($absHref));
}
public function startsWith($sequence, $start) {
return strcasecmp(substr($sequence, 0, strlen($start)), $start) === 0;
}
public function endsWith($sequence, $end) {
return strcasecmp(substr($sequence, -strlen($end)), $end) === 0;
}
public function getHttpCode($absHref) {
//return $this->cachedHttpCode($absHref);
@ -271,12 +205,7 @@ class H5ai {
$cached = $this->cache->get($absHref);
if ($cached === false) {
$folderStatus = $this->options["folderStatus"];
if (array_key_exists($absHref, $folderStatus)) {
$code = $folderStatus[$absHref];
} else {
$code = $this->fetchHttpCode($absHref);
}
$code = $this->fetchHttpCode($absHref);
$cached = array("href" => $absHref, "code" => $code);
$this->cache->set($absHref, $cached);
}
@ -286,6 +215,17 @@ class H5ai {
public function fetchHttpCode($absHref) {
if (!is_dir($this->getAbsPath($absHref))) {
return null;
}
if ($this->options["folderstatus"]["enabled"]) {
$folders = $this->options["folderstatus"]["folders"];
if (array_key_exists($absHref, $folders)) {
return $folders[$absHref];
}
}
$contentType = "Content-Type:";
$h5aiContentType = "Content-Type: text/html;h5ai=";
$host = getenv("HTTP_HOST");
@ -307,16 +247,53 @@ class H5ai {
$content = fgets($socket);
$code = intval(trim(substr($content, 9, 4)));
if ($code === 200) {
while (! $this->startsWith($content, $contentType)) {
while (! H5ai::starts_with($content, $contentType)) {
$content = fgets($socket);
}
if ($this->startsWith($content, $h5aiContentType)) {
if (H5ai::starts_with($content, $h5aiContentType)) {
$code = "h5ai";
}
}
fclose($socket);
return $code;
}
private function fileExists($file) {
return is_string($file) && file_exists($file);
}
public function getGenericJson() {
$header = $this->options["custom"]["header"];
$footer = $this->options["custom"]["footer"];
$header = $this->fileExists($header ? $this->absPath . "/" . $header : null) ? $header : null;
$footer = $this->fileExists($footer ? $this->absPath . "/" . $footer : null) ? $footer : null;
// collect and sort entries
$folder = Entry::get($this, $this->absPath, $this->absHref);
while ($folder !== null) {
$folder->getContent();
$folder = $folder->getParent();
}
Entry::sort();
$entries = array();
foreach(Entry::getCache() as $entry) {
$entries[] = $entry->toJsonObject(true);
}
$json = array(
"entries" => $entries,
"customHeader" => $header,
"customFooter" => $footer
);
return json_encode($json) . "\n";
}
}
?>

View file

@ -51,7 +51,15 @@ class Image {
$this->sourceFile = $filename;
list($this->width, $this->height, $this->type) = getimagesize($this->sourceFile);
list($this->width, $this->height, $this->type) = @getimagesize($this->sourceFile);
if (!$this->width || !$this->height) {
$this->sourceFile = null;
$this->width = null;
$this->height = null;
$this->type = null;
return;
}
$this->source = imagecreatefromstring(file_get_contents($this->sourceFile));
}
@ -99,6 +107,10 @@ class Image {
private function magic($destX, $destY, $srcX, $srcY, $destWidth, $destHeight, $srcWidth, $srcHeight, $canWidth = null, $canHeight = null, $color = null) {
if (is_null($this->source)) {
return;
}
if (!is_null($canWidth) && !is_null($canHeight)) {
$this->dest = imagecreatetruecolor($canWidth, $canHeight);
} else {
@ -134,6 +146,10 @@ class Image {
public function squareThumb($width) {
if (is_null($this->source)) {
return;
}
$a = min($this->width, $this->height);
$x = intval(($this->width - $a) / 2);
$y = intval(($this->height - $a) / 2);
@ -144,6 +160,10 @@ class Image {
public function rationalThumb($width, $height) {
if (is_null($this->source)) {
return;
}
$r = 1.0 * $this->width / $this->height;
$h = $height;
@ -164,6 +184,10 @@ class Image {
public function centerThumb($width, $height, $color = null) {
if (is_null($this->source)) {
return;
}
$r = 1.0 * $this->width / $this->height;
$h = $height;
@ -187,6 +211,10 @@ class Image {
public function freeThumb($width, $height) {
if (is_null($this->source)) {
return;
}
$w = intval($width);
$h = intval($height);

View file

@ -1,6 +1,6 @@
<?php
require_h5ai("/php/inc/Image.php");
H5ai::req_once("/php/inc/Image.php");
class Thumbnail {

View file

@ -1,158 +0,0 @@
<?php
class TreeEntry {
private $h5ai, $label, $absPath, $absHref, $isFolder, $type, $content;
public function __construct($h5ai, $absPath, $absHref, $type = null) {
$this->h5ai = $h5ai;
$this->label = $this->h5ai->getLabel($absHref);
$this->absPath = $this->h5ai->normalizePath($absPath, false);
$this->isFolder = is_dir($this->absPath);
$this->absHref = $this->h5ai->normalizePath($absHref, $this->isFolder);
$this->type = $type !== null ? $type : ($this->isFolder ? "folder" : $this->h5ai->getType($this->absPath));
$this->content = null;
}
public function loadContent() {
$this->content = array();
if ($this->h5ai->getHttpCode($this->absHref) !== "h5ai") {
return;
}
$files = $this->h5ai->readDir($this->absPath);
foreach ($files as $file) {
$tree = new TreeEntry($this->h5ai, $this->absPath . "/" . $file, $this->absHref . rawurlencode($file));
if ($tree->isFolder) {
$this->content[$tree->absPath] = $tree;
}
}
$this->sort();
}
public function cmpTrees($t1, $t2) {
if ($t1->isFolder && !$t2->isFolder) {
return -1;
}
if (!$t1->isFolder && $t2->isFolder) {
return 1;
}
return strcasecmp($t1->absPath, $t2->absPath);
}
public function sort() {
if ($this->content !== null) {
uasort($this->content, array($this, "cmpTrees"));
}
}
public function toHtml() {
$classes = "entry " . $this->type . ($this->absHref === $this->h5ai->getAbsHref() ? " current" : "");
$icon = $this->type;
if ($this->absHref === "/") {
$icon = "folder-home";
}
$hint = "";
$code = "h5ai";
if ($this->isFolder) {
$code = $this->h5ai->getHttpCode($this->absHref);
$classes .= " checkedHttpCode";
if ($code !== "h5ai") {
if ($code === 200) {
$icon = "folder-page";
$hint = "<span class='hint'><img src='" . $this->h5ai->image("page") . "' alt='page' /></span>";
} else {
$classes .= " error";
$hint = "<span class='hint'> " . $code . " </span>";
}
}
}
$html = "<div class='" . $classes ."'>\n";
if ($this->content !== null && count($this->content) === 0 || $code !== "h5ai") {
$html .= "<span class='blank'></span>\n";
} else {
$indicatorState = $this->content === null ? " unknown" : " open";
$html .= "<span class='indicator" . $indicatorState . "'><img src='" . $this->h5ai->image("tree") . "' alt='>' /></span>\n";
}
$html .= "<a href='" . $this->absHref . "'>\n";
$html .= "<span class='icon'><img src='" . $this->h5ai->icon($icon) . "' alt='" . $icon . "' /></span>";
$html .= "<span class='label'>" . $this->label . "</span>" . $hint . "\n";
$html .= "</a>\n";
$html .= $this->contentToHtml();
$html .= "</div>\n";
return $html;
}
public function contentToHtml() {
$html = "<ul class='content'>\n";
if ($this->content !== null) {
foreach($this->content as $tree) {
$html .= "<li>" . $tree->toHtml() . "</li>";
}
}
$html .= "</ul>\n";
return $html;
}
public function getRoot() {
if ($this->absHref === "/") {
return $this;
};
$tree = new TreeEntry($this->h5ai, safe_dirname($this->absPath), safe_dirname($this->absHref, true));
$tree->loadContent();
$tree->content[$this->absPath] = $this;
return $tree->getRoot();
}
}
class Tree {
private $h5ai;
public function __construct($h5ai) {
$this->h5ai = $h5ai;
}
public function toHtml() {
$options = $this->h5ai->getOptions();
if ($options["showTree"] === false) {
return "";
}
$tree = new TreeEntry($this->h5ai, $this->h5ai->getAbsPath(), $this->h5ai->getAbsHref());
$tree->loadContent();
$root = $tree->getRoot();
return "<section id='tree'>\n" . $root->toHtml() . "</section>\n";
}
}
?>

View file

@ -28,7 +28,7 @@ class ZipIt {
$zip->addEmptyDir("/");
foreach ($hrefs as $href) {
$d = safe_dirname($href, true);
$d = H5ai::normalize_path(dirname($href, true));
$n = basename($href);
$code = $this->h5ai->getHttpCode($d);
if ($code == 401) {
@ -82,7 +82,7 @@ class ZipIt {
}
}
}
return code;
return $code;
}
}

View file

@ -1,28 +0,0 @@
<?php
function safe_dirname($path, $endWithSlash = false) {
$path = str_replace("\\", "/", dirname($path));
return preg_match("#^(\w:)?/$#", $path) ? $path : (preg_replace('#/$#', '', $path) . ($endWithSlash ? "/" : ""));
}
define("H5AI_ABS_PATH", safe_dirname(safe_dirname(__FILE__)));
function require_h5ai($lib) {
require_once(H5AI_ABS_PATH . $lib);
}
require_h5ai("/php/inc/H5ai.php");
require_h5ai("/php/inc/Crumb.php");
require_h5ai("/php/inc/Customize.php");
require_h5ai("/php/inc/Extended.php");
require_h5ai("/php/inc/Tree.php");
$h5ai = new H5ai();
$crumb = new Crumb($h5ai);
$customize = new Customize($h5ai);
$extended = new Extended($h5ai);
$tree = new Tree($h5ai);
?>