コード例 #1
0
ファイル: api.php プロジェクト: nvdnkpr/h5ai
    H5ai::req_once("/php/inc/Thumb.php");
    if (!Thumb::is_supported()) {
        json_fail(2, "thumbnails not supported");
    }
    list($type, $srcAbsHref, $mode, $width, $height) = check_keys(array("type", "href", "mode", "width", "height"));
    $thumb = new Thumb($h5ai);
    $thumbHref = $thumb->thumb($type, $srcAbsHref, $mode, $width, $height);
    if ($thumbHref === null) {
        json_fail(3, "thumbnail creation failed");
    }
    json_exit(array("absHref" => $thumbHref));
} else {
    if ($action === "archive") {
        json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
        list($execution, $format, $hrefs) = check_keys(array("execution", "format", "hrefs"));
        H5ai::req_once("/php/inc/Archive.php");
        $archive = new Archive($h5ai);
        $hrefs = explode(":", trim($hrefs));
        $target = $archive->create($execution, $format, $hrefs);
        if (!is_string($target)) {
            json_fail($target, "package creation failed");
        }
        json_exit(array("id" => basename($target), "size" => filesize($target)));
    } else {
        if ($action === "getarchive") {
            json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
            list($id, $as) = check_keys(array("id", "as"));
            json_fail(2, "file not found", !preg_match("/^h5ai-selection-/", $id));
            $target = H5ai::normalize_path(sys_get_temp_dir(), true) . $id;
            json_fail(3, "file not found", !file_exists($target));
            header("Content-Type: application/octet-stream");
コード例 #2
0
ファイル: H5ai.php プロジェクト: rsertelon/h5ai
<?php

define("H5AI_ABS_PATH", H5ai::normalize_path(dirname(dirname(dirname(__FILE__)))));
H5ai::req_once("/config.php");
H5ai::req_once("/php/inc/Entry.php");
class H5ai
{
    public static final function normalize_path($path, $endWithSlash = false)
    {
        $path = str_replace("\\", "/", $path);
        return preg_match("#^(\\w:)?/\$#", $path) ? $path : preg_replace('#/$#', '', $path) . ($endWithSlash ? "/" : "");
    }
    public static final function req_once($lib)
    {
        require_once H5AI_ABS_PATH . $lib;
    }
    private static final function load_config($file)
    {
        $str = file_exists($file) ? file_get_contents($file) : "";
        // remove comments and change expression to pure json
        $str = preg_replace("/\\/\\*.*?\\*\\//s", "", $str);
        $str = preg_replace("/^.*H5AI_CONFIG\\s*=\\s*/s", "", $str);
        $str = preg_replace("/;.*/s", "", $str);
        $config = json_decode($str, true);
        return $config;
    }
    private static $H5AI_CONTENT_TYPE = "Content-Type: text/html;h5ai=";
    private $requested_from, $h5aiAbsPath, $rootAbsPath, $ignore_names, $ignore_patterns, $index_files, $config, $options, $rootAbsHref, $h5aiAbsHref, $absHref, $absPath;
    public function __construct($requested_from)
    {
        $this->requested_from = H5ai::normalize_path($requested_from);