diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-08-08 09:57:13 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-08-08 09:57:13 -0700 |
commit | b7700d1eec02caa794629adcc0555d7c9f0c1414 (patch) | |
tree | 43867e61df023022f1de54443eb940c49e52fdbd /modules/gallery/helpers/data_rest.php | |
parent | cc43c37a1c71c54d03979489ee7f1d5884a648af (diff) |
Require the size parameter. Optional params are confusing. And be
robust in the face of a missing data file (movies and albums lack
resize, albums lack full size, some albums don't have a thumb if they
have no contents, etc)
Diffstat (limited to 'modules/gallery/helpers/data_rest.php')
-rw-r--r-- | modules/gallery/helpers/data_rest.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/modules/gallery/helpers/data_rest.php b/modules/gallery/helpers/data_rest.php index e45a4645..48de2a3a 100644 --- a/modules/gallery/helpers/data_rest.php +++ b/modules/gallery/helpers/data_rest.php @@ -23,7 +23,11 @@ class data_rest_Core { access::required("view", $item); $p = $request->params; - switch (isset($p->size) ? $p->size : "full") { + if (!isset($p->size) || !in_array($p->size, array("thumb", "resize", "full"))) { + throw new Rest_Exception("Bad Request", 400, array("errors" => array("size" => "invalid"))); + } + + switch ($p->size) { case "thumb": $entity = array( "width" => $item->thumb_width, @@ -38,7 +42,6 @@ class data_rest_Core { "path" => $item->resize_path()); break; - default: case "full": $entity = array( "width" => $item->width, @@ -47,8 +50,13 @@ class data_rest_Core { break; } - $entity["size"] = filesize($entity["path"]); - $entity["contents"] = file_get_contents($entity["path"]); + if (file_exists($entity["path"]) && is_file($entity["path"])) { + $entity["size"] = filesize($entity["path"]); + $entity["contents"] = file_get_contents($entity["path"]); + } else { + $entity["size"] = null; + $entity["contents"] = null; + } unset($entity["path"]); $result = array( |