Switch to general API nearly done.

This commit is contained in:
Lars Jung 2012-10-10 16:05:50 +02:00
parent a60d5556af
commit d7f1c68366
13 changed files with 226 additions and 142 deletions

View file

@ -40,7 +40,7 @@ class Api {
if (array_key_exists("l10n", $_REQUEST)) {
list($iso_codes) = use_request_params("l10nCodes", "l10n");
$iso_codes = explode(",", $iso_codes);
$iso_codes = explode(":", $iso_codes);
$response["l10n"] = $this->app->get_l10n($iso_codes);
}
@ -58,14 +58,14 @@ class Api {
if (array_key_exists("custom", $_REQUEST)) {
list($abs_href) = use_request_params("customHref", "custom");
list($abs_href) = use_optional_request_params("customHref", "custom");
$response["custom"] = $this->app->get_customizations($abs_href);
}
if (array_key_exists("entries", $_REQUEST)) {
list($abs_href, $what) = use_request_params("entriesHref", "entriesWhat", "entries");
$what = intval($what, 10);
list($abs_href, $what) = use_optional_request_params("entriesHref", "entriesWhat", "entries");
$what = is_numeric($what) ? intval($what, 10) : 1;
$response["entries"] = $this->app->get_entries($abs_href, $what);
}

View file

@ -197,11 +197,11 @@ class App {
$html = "<table>";
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
if ($folder->get_parent($cache)) {
$html .= "<tr><td>UP</td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
$html .= "<tr><td><img src=\"" . $this->app_abs_href . "client/icons/16x16/folder-parent.png\"/></td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
}
foreach ($entries as $entry) {
$html .= "<tr>";
$html .= "<td>" . ($entry->is_folder ? "DIR" : "FILE") . "</td>";
$html .= "<td><img src=\"" . $this->app_abs_href . "client/icons/16x16/" . ($entry->is_folder ? "folder" : "default") . ".png\"/></td>";
$html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . "</a></td>";
$html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>";
$html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>";

View file

@ -23,7 +23,7 @@ $app = new App(APP_ABS_PATH, APP_ABS_HREF, ABS_HREF);
if (count($_REQUEST)) {
header("Content-type: application/json;h5ai={{pkg.version}}");
header("Content-type: application/json");
normalized_require_once("/server/php/inc/Api.php");
$api = new Api($app);
@ -33,8 +33,6 @@ if (count($_REQUEST)) {
} else {
header("Content-type: text/html;h5ai={{pkg.version}}");
$HREF = $app->get_app_abs_href();
$JSON = $app->get_generic_json();
$FALLBACK = $app->get_no_js_fallback();

View file

@ -30,6 +30,24 @@ function use_request_params($keys) {
return $values;
}
function use_optional_request_params($keys) {
if (!is_array($keys)) {
$keys = func_get_args();
}
$values = array();
foreach ($keys as $key) {
if (array_key_exists($key, $_REQUEST)) {
$values[] = $_REQUEST[$key];
unset($_REQUEST[$key]);
} else {
$values[] = null;
}
}
return $values;
}
function delete_tempfile($file) {
@unlink($file);