mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 20:14:37 -04:00
Refactor API.
This commit is contained in:
parent
0f1ca4e85b
commit
e31028f5a9
7 changed files with 32 additions and 23 deletions
|
@ -84,7 +84,7 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/event', 'core/settings
|
||||||
|
|
||||||
function load(callback) {
|
function load(callback) {
|
||||||
|
|
||||||
modulejs.require('core/server').request({action: 'get', items: true, itemsHref: absHref, itemsWhat: 1}, function (json) {
|
modulejs.require('core/server').request({action: 'get', items: {href: absHref, what: 1}}, function (json) {
|
||||||
|
|
||||||
var Item = modulejs.require('model/item');
|
var Item = modulejs.require('model/item');
|
||||||
var item = Item.get(absHref);
|
var item = Item.get(absHref);
|
||||||
|
|
|
@ -10,7 +10,7 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/event', 'core/server',
|
||||||
|
|
||||||
function onLocationChanged(item) {
|
function onLocationChanged(item) {
|
||||||
|
|
||||||
server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) {
|
server.request({action: 'get', custom: item.absHref}, function (response) {
|
||||||
|
|
||||||
var hasHeader;
|
var hasHeader;
|
||||||
var hasFooter;
|
var hasFooter;
|
||||||
|
|
|
@ -67,7 +67,7 @@ modulejs.define('ext/l10n', ['_', '$', 'core/event', 'core/format', 'core/langs'
|
||||||
callback(loaded[isoCode]);
|
callback(loaded[isoCode]);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
server.request({action: 'get', l10n: true, l10nCodes: isoCode}, function (response) {
|
server.request({action: 'get', l10n: [isoCode]}, function (response) {
|
||||||
|
|
||||||
var json = response.l10n && response.l10n[isoCode] ? response.l10n[isoCode] : {};
|
var json = response.l10n && response.l10n[isoCode] ? response.l10n[isoCode] : {};
|
||||||
loaded[isoCode] = _.extend({}, defaultTranslations, json, {isoCode: isoCode});
|
loaded[isoCode] = _.extend({}, defaultTranslations, json, {isoCode: isoCode});
|
||||||
|
|
|
@ -107,7 +107,7 @@ modulejs.define('model/item', ['_', 'core/event', 'core/location', 'core/server'
|
||||||
if (self.isContentFetched) {
|
if (self.isContentFetched) {
|
||||||
callback(self);
|
callback(self);
|
||||||
} else {
|
} else {
|
||||||
server.request({action: 'get', items: true, itemsHref: self.absHref, itemsWhat: 1}, function (response) {
|
server.request({action: 'get', items: {href: self.absHref, what: 1}}, function (response) {
|
||||||
|
|
||||||
if (response.items) {
|
if (response.items) {
|
||||||
_.each(response.items, function (jsonItem) {
|
_.each(response.items, function (jsonItem) {
|
||||||
|
|
|
@ -49,23 +49,24 @@ class Api {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util::get_boolean_request_param("l10n", false)) {
|
if (Util::get_request_param("l10n", false)) {
|
||||||
|
|
||||||
$iso_codes = Util::get_request_param("l10nCodes");
|
$iso_codes = Util::get_request_param("l10n");
|
||||||
$iso_codes = array_filter(explode(":", $iso_codes));
|
$iso_codes = array_filter($iso_codes);
|
||||||
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util::get_boolean_request_param("custom", false)) {
|
if (Util::get_request_param("custom", false)) {
|
||||||
|
|
||||||
$href = Util::get_request_param("customHref");
|
$href = Util::get_request_param("custom");
|
||||||
$response["custom"] = $this->app->get_customizations($href);
|
$response["custom"] = $this->app->get_customizations($href);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util::get_boolean_request_param("items", false)) {
|
if (Util::get_request_param("items", false)) {
|
||||||
|
|
||||||
$href = Util::get_request_param("itemsHref");
|
$items = Util::get_request_param("items");
|
||||||
$what = Util::get_request_param("itemsWhat");
|
$href = $items["href"];
|
||||||
|
$what = $items["what"];
|
||||||
$what = is_numeric($what) ? intval($what, 10) : 1;
|
$what = is_numeric($what) ? intval($what, 10) : 1;
|
||||||
$response["items"] = $this->app->get_items($href, $what);
|
$response["items"] = $this->app->get_items($href, $what);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,18 +22,9 @@ class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function get_option($keypath, $default) {
|
public function get_option($keypath = "", $default = null) {
|
||||||
|
|
||||||
$value = $this->options;
|
return Util::array_query($this->options, $keypath, $default);
|
||||||
$keys = array_filter(explode(".", $keypath));
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
if (array_key_exists($key, $value)) {
|
|
||||||
$value = $value[$key];
|
|
||||||
} else {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,25 @@ class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function array_query($array, $keypath = "", $default = null) {
|
||||||
|
|
||||||
|
$value = $array;
|
||||||
|
|
||||||
|
$keys = array_filter(explode(".", $keypath));
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (!is_array($value) || !array_key_exists($key, $value)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
$value = $value[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function is_post_request() {
|
public static function is_post_request() {
|
||||||
|
|
||||||
|
// Logger::log("POSTED", $_POST);
|
||||||
return (strtolower($_SERVER["REQUEST_METHOD"]) === "post");
|
return (strtolower($_SERVER["REQUEST_METHOD"]) === "post");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue