From c3a4cf3f882c06ba04ed30b82648fa38d96c1c77 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Fri, 29 Oct 2010 12:39:44 +0800 Subject: [PATCH] Added REST support. --- .../itemchecksum/controllers/itemchecksum.php | 2 +- .../helpers/item_itemchecksums_rest.php | 42 ++++++++++++++ .../helpers/itemchecksum_md5_rest.php | 55 +++++++++++++++++++ .../helpers/itemchecksum_rest.php | 41 ++++++++++++++ .../helpers/itemchecksum_sha1_rest.php | 55 +++++++++++++++++++ .../itemchecksum/controllers/itemchecksum.php | 2 +- .../helpers/item_itemchecksums_rest.php | 42 ++++++++++++++ .../helpers/itemchecksum_md5_rest.php | 55 +++++++++++++++++++ .../helpers/itemchecksum_rest.php | 41 ++++++++++++++ .../helpers/itemchecksum_sha1_rest.php | 55 +++++++++++++++++++ 10 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 3.0/modules/itemchecksum/helpers/item_itemchecksums_rest.php create mode 100644 3.0/modules/itemchecksum/helpers/itemchecksum_md5_rest.php create mode 100644 3.0/modules/itemchecksum/helpers/itemchecksum_rest.php create mode 100644 3.0/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php create mode 100644 3.1/modules/itemchecksum/helpers/item_itemchecksums_rest.php create mode 100644 3.1/modules/itemchecksum/helpers/itemchecksum_md5_rest.php create mode 100644 3.1/modules/itemchecksum/helpers/itemchecksum_rest.php create mode 100644 3.1/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php diff --git a/3.0/modules/itemchecksum/controllers/itemchecksum.php b/3.0/modules/itemchecksum/controllers/itemchecksum.php index 01cbfc4f..7123350d 100644 --- a/3.0/modules/itemchecksum/controllers/itemchecksum.php +++ b/3.0/modules/itemchecksum/controllers/itemchecksum.php @@ -86,4 +86,4 @@ class itemchecksum_Controller extends Controller { print "0"; } } -} \ No newline at end of file +} diff --git a/3.0/modules/itemchecksum/helpers/item_itemchecksums_rest.php b/3.0/modules/itemchecksum/helpers/item_itemchecksums_rest.php new file mode 100644 index 00000000..3f109f66 --- /dev/null +++ b/3.0/modules/itemchecksum/helpers/item_itemchecksums_rest.php @@ -0,0 +1,42 @@ +url); + access::required("view", $item); + + $checksums = array(rest::url("itemchecksum_md5", $item), rest::url("itemchecksum_sha1", $item)); + return array( + "url" => $request->url, + "members" => $checksums); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/item_checksums/{$item->id}"); + } +} diff --git a/3.0/modules/itemchecksum/helpers/itemchecksum_md5_rest.php b/3.0/modules/itemchecksum/helpers/itemchecksum_md5_rest.php new file mode 100644 index 00000000..4cd6dfa9 --- /dev/null +++ b/3.0/modules/itemchecksum/helpers/itemchecksum_md5_rest.php @@ -0,0 +1,55 @@ +url); + access::required("view", $item); + $checksum = "0"; + // If the KeepOriginal module is active, check for/use the + // original image instead of the gallery edited version. + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); + if ($item->is_photo() && file_exists($original_image)) { + $checksum = md5_file($original_image); + } else { + $checksum = md5_file($item->file_path()); + } + } else { + $checksum = md5_file($item->file_path()); + } + $data = array("checksum" => $checksum); + + return array( + "url" => $request->url, + "entity" => $data); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum_md5/{$item->id}"); + } +} diff --git a/3.0/modules/itemchecksum/helpers/itemchecksum_rest.php b/3.0/modules/itemchecksum/helpers/itemchecksum_rest.php new file mode 100644 index 00000000..a1404eaa --- /dev/null +++ b/3.0/modules/itemchecksum/helpers/itemchecksum_rest.php @@ -0,0 +1,41 @@ + array( + "url" => rest::url("item_itemchecksums", $resource))); + } + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum/{$item->id}"); + } +} diff --git a/3.0/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php b/3.0/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php new file mode 100644 index 00000000..9bb5f118 --- /dev/null +++ b/3.0/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php @@ -0,0 +1,55 @@ +url); + access::required("view", $item); + $checksum = "0"; + // If the KeepOriginal module is active, check for/use the + // original image instead of the gallery edited version. + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); + if ($item->is_photo() && file_exists($original_image)) { + $checksum = sha1_file($original_image); + } else { + $checksum = sha1_file($item->file_path()); + } + } else { + $checksum = sha1_file($item->file_path()); + } + $data = array("checksum" => $checksum); + + return array( + "url" => $request->url, + "entity" => $data); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum_sha1/{$item->id}"); + } +} diff --git a/3.1/modules/itemchecksum/controllers/itemchecksum.php b/3.1/modules/itemchecksum/controllers/itemchecksum.php index 01cbfc4f..7123350d 100644 --- a/3.1/modules/itemchecksum/controllers/itemchecksum.php +++ b/3.1/modules/itemchecksum/controllers/itemchecksum.php @@ -86,4 +86,4 @@ class itemchecksum_Controller extends Controller { print "0"; } } -} \ No newline at end of file +} diff --git a/3.1/modules/itemchecksum/helpers/item_itemchecksums_rest.php b/3.1/modules/itemchecksum/helpers/item_itemchecksums_rest.php new file mode 100644 index 00000000..3f109f66 --- /dev/null +++ b/3.1/modules/itemchecksum/helpers/item_itemchecksums_rest.php @@ -0,0 +1,42 @@ +url); + access::required("view", $item); + + $checksums = array(rest::url("itemchecksum_md5", $item), rest::url("itemchecksum_sha1", $item)); + return array( + "url" => $request->url, + "members" => $checksums); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/item_checksums/{$item->id}"); + } +} diff --git a/3.1/modules/itemchecksum/helpers/itemchecksum_md5_rest.php b/3.1/modules/itemchecksum/helpers/itemchecksum_md5_rest.php new file mode 100644 index 00000000..4cd6dfa9 --- /dev/null +++ b/3.1/modules/itemchecksum/helpers/itemchecksum_md5_rest.php @@ -0,0 +1,55 @@ +url); + access::required("view", $item); + $checksum = "0"; + // If the KeepOriginal module is active, check for/use the + // original image instead of the gallery edited version. + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); + if ($item->is_photo() && file_exists($original_image)) { + $checksum = md5_file($original_image); + } else { + $checksum = md5_file($item->file_path()); + } + } else { + $checksum = md5_file($item->file_path()); + } + $data = array("checksum" => $checksum); + + return array( + "url" => $request->url, + "entity" => $data); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum_md5/{$item->id}"); + } +} diff --git a/3.1/modules/itemchecksum/helpers/itemchecksum_rest.php b/3.1/modules/itemchecksum/helpers/itemchecksum_rest.php new file mode 100644 index 00000000..a1404eaa --- /dev/null +++ b/3.1/modules/itemchecksum/helpers/itemchecksum_rest.php @@ -0,0 +1,41 @@ + array( + "url" => rest::url("item_itemchecksums", $resource))); + } + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum/{$item->id}"); + } +} diff --git a/3.1/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php b/3.1/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php new file mode 100644 index 00000000..9bb5f118 --- /dev/null +++ b/3.1/modules/itemchecksum/helpers/itemchecksum_sha1_rest.php @@ -0,0 +1,55 @@ +url); + access::required("view", $item); + $checksum = "0"; + // If the KeepOriginal module is active, check for/use the + // original image instead of the gallery edited version. + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); + if ($item->is_photo() && file_exists($original_image)) { + $checksum = sha1_file($original_image); + } else { + $checksum = sha1_file($item->file_path()); + } + } else { + $checksum = sha1_file($item->file_path()); + } + $data = array("checksum" => $checksum); + + return array( + "url" => $request->url, + "entity" => $data); + } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + static function url($item) { + return url::abs_site("rest/itemchecksum_sha1/{$item->id}"); + } +}