diff options
author | Nathan Kinkade <nkinkade@nkinka.de> | 2010-08-19 23:29:35 +0000 |
---|---|---|
committer | Nathan Kinkade <nkinkade@nkinka.de> | 2010-08-19 23:29:35 +0000 |
commit | 45b6d344b4a5431e7cf11fde5808c63bf7553676 (patch) | |
tree | 33a5bd2ee0124553c4d35f4152e607296479a551 /modules/rest/helpers/rest.php | |
parent | d1475ec40ebda6404baab45b5b2482c651e657f9 (diff) | |
parent | 21a0f832b66eaba902b09e2a88ece52c76e4a0c3 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/rest/helpers/rest.php')
-rw-r--r-- | modules/rest/helpers/rest.php | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index 644779da..d5ed0452 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -24,8 +24,28 @@ class rest_Core { Session::instance()->abort_save(); header("X-Gallery-API-Version: " . rest::API_VERSION); - if (Input::instance()->get("output") == "html") { - header("Content-type: text/html"); + switch (Input::instance()->get("output", "json")) { + case "json": + json::reply($data); + break; + + case "jsonp": + if (!($callback = Input::instance()->get("callback", ""))) { + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("callback" => "missing"))); + } + + if (preg_match('/^[$A-Za-z_][0-9A-Za-z_]*$/', $callback) == 1) { + header("Content-type: application/javascript; charset=UTF-8"); + print "$callback(" . json_encode($data) . ")"; + } else { + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("callback" => "invalid"))); + } + break; + + case "html": + header("Content-type: text/html; charset=UTF-8"); if ($data) { $html = preg_replace( "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'<a href=\"\\1\" >\\1</a>'", @@ -34,8 +54,10 @@ class rest_Core { $html = t("Empty response"); } print "<pre>$html</pre>"; - } else { - json::reply($data); + break; + + default: + throw new Rest_Exception("Bad Request", 400); } } @@ -65,6 +87,16 @@ class rest_Core { identity::set_active_user($user); } + static function reset_access_key() { + $key = ORM::factory("user_access_key") + ->where("user_id", "=", identity::active_user()->id) + ->find(); + if ($key->loaded()) { + $key->delete(); + } + return rest::access_key(); + } + static function access_key() { $key = ORM::factory("user_access_key") ->where("user_id", "=", identity::active_user()->id) |