diff --git a/src/_h5ai/server/php/inc/Api.php b/src/_h5ai/server/php/inc/Api.php index 518a4702..fe063c64 100644 --- a/src/_h5ai/server/php/inc/Api.php +++ b/src/_h5ai/server/php/inc/Api.php @@ -3,6 +3,9 @@ class Api { + private $app; + + public function __construct($app) { $this->app = $app; @@ -19,50 +22,50 @@ class Api { $response = array(); - if (array_key_exists("options", $_REQUEST)) { + if (has_request_param("options")) { use_request_params("options"); $response["options"] = $this->app->get_options(); } - if (array_key_exists("types", $_REQUEST)) { + if (has_request_param("types")) { use_request_params("types"); $response["types"] = $this->app->get_types(); } - if (array_key_exists("langs", $_REQUEST)) { + if (has_request_param("langs")) { use_request_params("langs"); $response["langs"] = $this->app->get_l10n_list(); } - if (array_key_exists("l10n", $_REQUEST)) { + if (has_request_param("l10n")) { list($iso_codes) = use_request_params("l10nCodes", "l10n"); $iso_codes = explode(":", $iso_codes); $response["l10n"] = $this->app->get_l10n($iso_codes); } - if (array_key_exists("checks", $_REQUEST)) { + if (has_request_param("checks")) { use_request_params("checks"); $response["checks"] = $this->app->get_server_checks(); } - if (array_key_exists("server", $_REQUEST)) { + if (has_request_param("server")) { use_request_params("server"); $response["server"] = $this->app->get_server_details(); } - if (array_key_exists("custom", $_REQUEST)) { + if (has_request_param("custom")) { list($abs_href) = use_optional_request_params("customHref", "custom"); $response["custom"] = $this->app->get_customizations($abs_href); } - if (array_key_exists("items", $_REQUEST)) { + if (has_request_param("items")) { list($abs_href, $what) = use_optional_request_params("itemsHref", "itemsWhat", "items"); $what = is_numeric($what) ? intval($what, 10) : 1; @@ -83,7 +86,7 @@ class Api { json_fail(1, "thumbnails disabled"); } - normalized_require_once("/server/php/inc/Thumb.php"); + normalized_require_once("Thumb.php"); if (!Thumb::is_supported()) { json_fail(2, "thumbnails not supported"); } @@ -106,7 +109,7 @@ class Api { list($as, $type, $hrefs) = use_request_params(array("as", "type", "hrefs")); - normalized_require_once("/server/php/inc/Archive.php"); + normalized_require_once("Archive.php"); $archive = new Archive($this->app); $hrefs = explode("|:|", trim($hrefs)); diff --git a/src/_h5ai/server/php/inc/App.php b/src/_h5ai/server/php/inc/App.php index 63166f34..11b69732 100644 --- a/src/_h5ai/server/php/inc/App.php +++ b/src/_h5ai/server/php/inc/App.php @@ -27,6 +27,8 @@ class App { $server_version = $matches[2]; } + $app_abs_path = normalize_path(dirname(dirname(dirname(dirname(__FILE__))))); + $script_name = getenv("SCRIPT_NAME"); if ($server_name === "lighttpd") { $script_name = preg_replace("#^.*//#", "/", $script_name); @@ -36,7 +38,7 @@ class App { $url_parts = parse_url(getenv("REQUEST_URI")); $abs_href = $url_parts["path"]; - return new App($server_name, $server_version, APP_ABS_PATH, $app_abs_href, $abs_href); + return new App($server_name, $server_version, $app_abs_path, $app_abs_href, $abs_href); } @@ -57,6 +59,10 @@ class App { $this->abs_href = normalize_path($abs_href, true); $this->abs_path = $this->get_abs_path($this->abs_href); + // echo("
"); + // var_dump($this); + // exit(); + $this->options = load_commented_json($this->app_abs_path . "/conf/options.json"); } @@ -235,8 +241,6 @@ class App { public function get_fallback() { - date_default_timezone_set("UTC"); - $cache = array(); $folder = Item::get($this, $this->abs_path, $cache); $items = $folder->get_content($cache); @@ -327,10 +331,10 @@ class App { $results = array(); $results["path_index"] = $this->app_abs_href . "server/php/index.php"; + $results["path_cache_writable"] = @is_writable($this->get_cache_abs_path()); $results["php_version"] = PHP_VERSION; $results["php_version_supported"] = $this->is_supported_php; $results["php_exif"] = function_exists("exif_thumbnail"); - $results["path_cache_writable"] = @is_writable($this->get_cache_abs_path()); $gd = false; if (function_exists("gd_info")) { @@ -365,6 +369,7 @@ class App { return array( "backend" => "php", + "api" => true, "name" => $this->server_name, "version" => $this->server_version ); diff --git a/src/_h5ai/server/php/inc/Thumb.php b/src/_h5ai/server/php/inc/Thumb.php index 00dad454..f982cb7f 100644 --- a/src/_h5ai/server/php/inc/Thumb.php +++ b/src/_h5ai/server/php/inc/Thumb.php @@ -6,19 +6,16 @@ class Thumb { private static $AVCONV_CMD = "avconv -ss 0:01:00 -i [SOURCE] -an -vframes 1 [TARGET]"; private static $CONVERT_CMD = "convert -strip [SOURCE][0] [TARGET]"; private static $THUMB_CACHE = "thumbs"; + private static $CAPTURE_CACHE = "captures"; + public static final function is_supported() { - if (!function_exists("gd_info")) { - return false; - } - - $gdinfo = gd_info(); - return array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"]; + return Image::is_supported(); } - private $app; + private $app, $thumbs_path, $thumbs_href; public function __construct($app) { @@ -93,7 +90,7 @@ class Thumb { return null; } - $capture_abs_path = $this->app->get_cache_abs_path() . "/capture-" . sha1($source_abs_path) . ".jpg"; + $capture_abs_path = $this->thumbs_path . "/capture-" . sha1($source_abs_path) . ".jpg"; if (!file_exists($capture_abs_path) || filemtime($source_abs_path) >= filemtime($capture_abs_path)) { $cmd = str_replace("[SOURCE]", escapeshellarg($source_abs_path), $cmd); diff --git a/src/_h5ai/server/php/inc/main.php b/src/_h5ai/server/php/inc/main.php new file mode 100644 index 00000000..66badf85 --- /dev/null +++ b/src/_h5ai/server/php/inc/main.php @@ -0,0 +1,57 @@ +apply(); + +} else { + + header("Content-type: text/html;charset=utf-8"); + + global $HREF, $FALLBACK; + $HREF = $app->get_app_abs_href(); + $FALLBACK = $app->get_fallback(); + normalized_require_once("page.php"); +} + +?> \ No newline at end of file diff --git a/src/_h5ai/server/php/inc/util.php b/src/_h5ai/server/php/inc/util.php index e684bf5c..534fcdba 100644 --- a/src/_h5ai/server/php/inc/util.php +++ b/src/_h5ai/server/php/inc/util.php @@ -1,5 +1,11 @@ apply(); - -} else { - - header("Content-type: text/html;charset=utf-8"); - - $HREF = $app->get_app_abs_href(); - $FALLBACK = $app->get_fallback(); - - normalized_require_once("/server/php/inc/page.php"); -} +normalized_require_once("main.php"); ?> \ No newline at end of file