summaryrefslogtreecommitdiff
path: root/modules/gallery/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r--modules/gallery/controllers/albums.php91
-rw-r--r--modules/gallery/controllers/items.php12
-rw-r--r--modules/gallery/controllers/movies.php16
-rw-r--r--modules/gallery/controllers/photos.php17
-rw-r--r--modules/gallery/controllers/rest.php183
5 files changed, 24 insertions, 295 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index cc63d43f..19140891 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -18,10 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Albums_Controller extends Items_Controller {
-
- /**
- * @see REST_Controller::_show($resource)
- */
public function _show($album) {
$page_size = module::get_var("gallery", "page_size", 9);
if (!access::can("view", $album)) {
@@ -83,27 +79,9 @@ class Albums_Controller extends Items_Controller {
print $template;
}
- /**
- * @see REST_Controller::_create($resource)
- */
- public function _create($album) {
+ public function create($parent_id) {
access::verify_csrf();
- access::required("view", $album);
- access::required("add", $album);
-
- switch ($this->input->post("type")) {
- case "album":
- return $this->_create_album($album);
-
- case "photo":
- return $this->_create_photo($album);
-
- default:
- access::forbidden();
- }
- }
-
- private function _create_album($album) {
+ $album = ORM::factory("item", $parent_id);
access::required("view", $album);
access::required("add", $album);
@@ -124,8 +102,7 @@ class Albums_Controller extends Items_Controller {
print json_encode(
array("result" => "success",
- "location" => $new_album->url(),
- "resource" => $new_album->url()));
+ "location" => $new_album->url()));
} else {
print json_encode(
array(
@@ -134,43 +111,9 @@ class Albums_Controller extends Items_Controller {
}
}
- private function _create_photo($album) {
- access::required("view", $album);
- access::required("add", $album);
-
- // If we set the content type as JSON, it triggers saving the result as
- // a document in the browser (well, in Chrome at least).
- // @todo figure out why and fix this.
- $form = photo::get_add_form($album);
- if ($form->validate()) {
- $photo = photo::create(
- $album,
- $this->input->post("file"),
- $_FILES["file"]["name"],
- $this->input->post("title", $this->input->post("name")),
- $this->input->post("description"),
- identity::active_user()->id);
-
- log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo"));
- message::success(t("Added photo %photo_title",
- array("photo_title" => html::purify($photo->title))));
-
- print json_encode(
- array("result" => "success",
- "resource" => $photo->url(),
- "location" => $photo->url()));
- } else {
- print json_encode(
- array("result" => "error",
- "form" => $form->__toString()));
- }
- }
-
- /**
- * @see REST_Controller::_update($resource)
- */
- public function _update($album) {
+ public function update($album_id) {
access::verify_csrf();
+ $album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("edit", $album);
@@ -230,32 +173,16 @@ class Albums_Controller extends Items_Controller {
}
}
- /**
- * @see REST_Controller::_form_add($parameters)
- */
- public function _form_add($album_id) {
+ public function form_add($album_id) {
$album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("add", $album);
- switch ($this->input->get("type")) {
- case "album":
- print album::get_add_form($album);
- break;
-
- case "photo":
- print photo::get_add_form($album);
- break;
-
- default:
- kohana::show_404();
- }
+ print album::get_add_form($album);
}
- /**
- * @see REST_Controller::_form_add($parameters)
- */
- public function _form_edit($album) {
+ public function form_edit($album_id) {
+ $album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("edit", $album);
diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php
index 7f60f2b7..ec3681a3 100644
--- a/modules/gallery/controllers/items.php
+++ b/modules/gallery/controllers/items.php
@@ -17,14 +17,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Items_Controller extends REST_Controller {
- protected $resource_type = "item";
-
- public function _show($item) {
+class Items_Controller extends Controller {
+ public function __call($function, $args) {
+ $item = ORM::factory("item", (int)$function);
+ if (!$item->loaded) {
+ return Kohana::show_404();
+ }
// Redirect to the more specific resource type, since it will render
// differently. We could also just delegate here, but it feels more appropriate
// to have a single canonical resource mapping.
access::required("view", $item);
- return url::redirect($item->abs_url());
+ return $this->_show($item);
}
}
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 2e2e837c..3d5eac32 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -18,10 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Movies_Controller extends Items_Controller {
-
- /**
- * @see REST_Controller::_show($resource)
- */
public function _show($movie) {
access::required("view", $movie);
@@ -53,11 +49,9 @@ class Movies_Controller extends Items_Controller {
print $template;
}
- /**
- * @see REST_Controller::_update($resource)
- */
- public function _update($movie) {
+ public function update($movie_id) {
access::verify_csrf();
+ $movie = ORM::factory("item", $movie_id);
access::required("view", $movie);
access::required("edit", $movie);
@@ -120,10 +114,8 @@ class Movies_Controller extends Items_Controller {
}
}
- /**
- * @see REST_Controller::_form_edit($resource)
- */
- public function _form_edit($movie) {
+ public function form_edit($movie_id) {
+ $movie = ORM::factory("item", $movie_id);
access::required("view", $movie);
access::required("edit", $movie);
print movie::get_edit_form($movie);
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 0c2ff6ee..f052eccd 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -18,10 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Photos_Controller extends Items_Controller {
-
- /**
- * @see REST_Controller::_show($resource)
- */
public function _show($photo) {
access::required("view", $photo);
@@ -53,12 +49,9 @@ class Photos_Controller extends Items_Controller {
print $template;
}
-
- /**
- * @see REST_Controller::_update($resource)
- */
- public function _update($photo) {
+ public function update($photo_id) {
access::verify_csrf();
+ $photo = ORM::factory("item", $photo_id);
access::required("view", $photo);
access::required("edit", $photo);
@@ -125,10 +118,8 @@ class Photos_Controller extends Items_Controller {
}
}
- /**
- * @see REST_Controller::_form_edit($resource)
- */
- public function _form_edit($photo) {
+ public function form_edit($photo_id) {
+ $photo = ORM::factory("item", $photo_id);
access::required("view", $photo);
access::required("edit", $photo);
diff --git a/modules/gallery/controllers/rest.php b/modules/gallery/controllers/rest.php
deleted file mode 100644
index 087f2c29..00000000
--- a/modules/gallery/controllers/rest.php
+++ /dev/null
@@ -1,183 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/**
- * This abstract controller makes it easy to create a RESTful controller. To use it, create a
- * subclass which defines the resource type and implements get/post/put/delete methods, like this:
- *
- * class Comment_Controller extends REST_Controller {
- * protected $resource_type = "comment"; // this tells REST which model to use
- *
- * public function _index() {
- * // Handle GET request to /controller
- * }
- *
- * public function _show(ORM $comment) {
- * // Handle GET request to /comments/{comment_id}
- * }
- *
- * public function _update(ORM $comment) {
- * // Handle PUT request to /comments/{comment_id}
- * }
- *
- * public function _create(ORM $comment) {
- * // Handle POST request to /comments
- * }
- *
- * public function _delete(ORM $comment) {
- * // Handle DELETE request to /comments/{comments_id}
- * }
- *
- * public function _form_add($parameters) {
- * // Handle GET request to /form/add/comments
- * // Show a form for creating a new comment
- * }
- *
- * public function _form_edit(ORM $comment) {
- * // Handle GET request to /form/edit/comments
- * // Show a form for editing an existing comment
- * }
- *
- * A request to http://example.com/gallery3/comments/3 will result in a call to
- * REST_Controller::__call(3) which will load up the comment associated with id 3. If there's
- * no such comment, it returns a 404. Otherwise, it will then delegate to
- * Comment_Controller::get() with the ORM instance as an argument.
- */
-class REST_Controller extends Controller {
- protected $resource_type = null;
-
- public function __construct() {
- if ($this->resource_type == null) {
- throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE");
- }
- parent::__construct();
- }
-
- /**
- * Handle dispatching for all REST controllers.
- */
- public function __call($function, $args) {
- // If no parameter was provided after the controller name (eg "/albums") then $function will
- // be set to "index". Otherwise, $function is the first parameter, and $args are all
- // subsequent parameters.
- $request_method = rest::request_method();
- if ($function == "index" && $request_method == "get") {
- return $this->_index();
- }
-
- $resource = ORM::factory($this->resource_type, (int)$function);
- if (!$resource->loaded() && $request_method != "post") {
- return Kohana::show_404();
- }
-
- switch ($request_method) {
- case "get":
- return $this->_show($resource);
-
- case "put":
- access::verify_csrf();
- return $this->_update($resource);
-
- case "delete":
- access::verify_csrf();
- return $this->_delete($resource);
-
- case "post":
- access::verify_csrf();
- return $this->_create($resource);
- }
- }
-
- /* We're editing an existing item, load it from the database. */
- public function form_edit($resource_id) {
- if ($this->resource_type == null) {
- throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE");
- }
-
- $resource = ORM::factory($this->resource_type, $resource_id);
- if (!$resource->loaded()) {
- return Kohana::show_404();
- }
-
- // Security checks must be performed in _form_edit
- return $this->_form_edit($resource);
- }
-
- /* We're adding a new item, pass along any additional parameters. */
- public function form_add($parameters) {
- // Security checks must be performed in _form_add
- return $this->_form_add($parameters);
- }
-
- /**
- * Perform a GET request on the controller root
- * (e.g. http://www.example.com/gallery3/comments)
- */
- public function _index() {
- throw new Exception("@todo _create NOT IMPLEMENTED");
- }
-
- /**
- * Perform a POST request on this resource
- * @param ORM $resource the instance of this resource type
- */
- public function _create($resource) {
- throw new Exception("@todo _create NOT IMPLEMENTED");
- }
-
- /**
- * Perform a GET request on this resource
- * @param ORM $resource the instance of this resource type
- */
- public function _show($resource) {
- throw new Exception("@todo _show NOT IMPLEMENTED");
- }
-
- /**
- * Perform a PUT request on this resource
- * @param ORM $resource the instance of this resource type
- */
- public function _update($resource) {
- throw new Exception("@todo _update NOT IMPLEMENTED");
- }
-
- /**
- * Perform a DELETE request on this resource
- * @param ORM $resource the instance of this resource type
- */
- public function _delete($resource) {
- throw new Exception("@todo _delete NOT IMPLEMENTED");
- }
-
- /**
- * Present a form for adding a new resource
- * @param string part of the URI after the controller name
- */
- public function _form_add($parameter) {
- throw new Exception("@todo _form_add NOT IMPLEMENTED");
- }
-
- /**
- * Present a form for editing an existing resource
- * @param ORM $resource the resource container for instances of this resource type
- */
- public function _form_edit($resource) {
- throw new Exception("@todo _form_edit NOT IMPLEMENTED");
- }
-}