From b2772f5a050351129a64b966b127e39cf76c80b5 Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Wed, 19 Nov 2008 00:12:25 +0000 Subject: * Renamed the album, item and photo controllers to albums, items and photos in order to follow the convention that controllers that refer to a collection of resources have plural names. * Added a bug workaround to routes.php --- core/config/routes.php | 5 ++ core/controllers/album.php | 45 -------------- core/controllers/albums.php | 45 ++++++++++++++ core/controllers/item.php | 140 -------------------------------------------- core/controllers/items.php | 140 ++++++++++++++++++++++++++++++++++++++++++++ core/controllers/photo.php | 40 ------------- core/controllers/photos.php | 40 +++++++++++++ core/views/welcome.html.php | 8 +-- 8 files changed, 234 insertions(+), 229 deletions(-) delete mode 100644 core/controllers/album.php create mode 100644 core/controllers/albums.php delete mode 100644 core/controllers/item.php create mode 100644 core/controllers/items.php delete mode 100644 core/controllers/photo.php create mode 100644 core/controllers/photos.php (limited to 'core') diff --git a/core/config/routes.php b/core/config/routes.php index 120e6900..4da97654 100644 --- a/core/config/routes.php +++ b/core/config/routes.php @@ -18,6 +18,11 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +// FIXME Temporary workaround to show the welcome page at /welcome. +// The problem is that we're routing all requests to /{controllername} to Rest_Controller, +// even requests to controllers that do not implement Rest_Controller. +$config['^welcome$'] = 'welcome'; + // REST configuration // Any resource requests (eg: album/1 or comment/3) get dispatched to the REST // dispatcher, and the abstract REST_Controller is not directly routable. diff --git a/core/controllers/album.php b/core/controllers/album.php deleted file mode 100644 index 82652d88..00000000 --- a/core/controllers/album.php +++ /dev/null @@ -1,45 +0,0 @@ -input->get("page", "1"); - $theme = new Theme($theme_name, $template); - - $template->set_global('page_size', $page_size); - $template->set_global('item', $item); - $template->set_global('children', $item->children($page_size, ($page-1) * $page_size)); - $template->set_global('parents', $item->parents()); - $template->set_global('theme', $theme); - $template->set_global('user', Session::instance()->get('user', null)); - $template->content = new View("album.html"); - - print $template; - } -} diff --git a/core/controllers/albums.php b/core/controllers/albums.php new file mode 100644 index 00000000..ead738d9 --- /dev/null +++ b/core/controllers/albums.php @@ -0,0 +1,45 @@ +input->get("page", "1"); + $theme = new Theme($theme_name, $template); + + $template->set_global('page_size', $page_size); + $template->set_global('item', $item); + $template->set_global('children', $item->children($page_size, ($page-1) * $page_size)); + $template->set_global('parents', $item->parents()); + $template->set_global('theme', $theme); + $template->set_global('user', Session::instance()->get('user', null)); + $template->content = new View("album.html"); + + print $template; + } +} diff --git a/core/controllers/item.php b/core/controllers/item.php deleted file mode 100644 index f5c5f9c9..00000000 --- a/core/controllers/item.php +++ /dev/null @@ -1,140 +0,0 @@ -type}/$item->id"); - } - - public function _update($item) { - // @todo Productionize this code - // 1) Add security checks - // 2) Support owner_ids properly - - $user = Session::instance()->get("user"); - $owner_id = $user ? $user->id : $item->owner_id; - - switch ($this->input->post("type")) { - case "album": - $album = album::create( - $item->id, - $this->input->post("name"), - $this->input->post("title", $this->input->post("name")), - $this->input->post("description"), - $owner_id); - url::redirect("album/{$album->id}"); - break; - - case "photo": - if (is_array($_FILES["file"]["name"])) { - for ($i = 0; $i < count($_FILES["file"]["name"]) - 1; $i++) { - if ($_FILES["file"]["error"][$i] == 0) { - $photo = photo::create( - $item->id, - $_FILES["file"]["tmp_name"][$i], - $_FILES["file"]["name"][$i], - $_FILES["file"]["name"][$i], - "", $owner_id); - } else { - throw new Exception("@todo ERROR_IN_UPLOAD_FILE"); - } - } - url::redirect("album/{$item->id}"); - } else { - $photo = photo::create( - $item->id, - $_FILES["file"]["tmp_name"], - $_FILES["file"]["name"], - $this->input->post("title", $this->input->post("name")), - $this->input->post("description"), - $owner_id); - url::redirect("{$new_item->type}/{$new_item->id}"); - } - break; - } - } - - public function _delete($item) { - // @todo Production this code - // 1) Add security checks - $parent = $item->parent(); - if ($parent->id) { - $item->delete(); - } - url::redirect("{$parent->type}/{$parent->id}"); - } - - public function _create($item) { - // @todo Productionize this - // 1) Figure out how to do the right validation here. Validate the form input and apply it to - // the model as appropriate. - // 2) Figure out how to dispatch according to the needs of the client. Ajax requests from - // jeditable will want the changed field back, and possibly the whole item in json. - // - // For now let's establish a simple protocol where the client passes in a __return parameter - // that specifies which field it wants back from the item. Later on we can expand that to - // include a data format, etc. - - // These fields are safe to change - $post = $this->input->post(); - foreach ($post as $key => $value) { - switch ($key) { - case "title": - case "description": - $item->$key = $value; - break; - } - } - - // @todo Support additional fields - // These fields require additional work if you change them - // parent_id, owner_id - - $item->save(); - if (array_key_exists("__return", $post)) { - print $item->{$post["__return"]}; - } - } -} diff --git a/core/controllers/items.php b/core/controllers/items.php new file mode 100644 index 00000000..6c202b30 --- /dev/null +++ b/core/controllers/items.php @@ -0,0 +1,140 @@ +type}s}/$item->id"); + } + + public function _update($item) { + // @todo Productionize this code + // 1) Add security checks + // 2) Support owner_ids properly + + $user = Session::instance()->get("user"); + $owner_id = $user ? $user->id : $item->owner_id; + + switch ($this->input->post("type")) { + case "album": + $album = album::create( + $item->id, + $this->input->post("name"), + $this->input->post("title", $this->input->post("name")), + $this->input->post("description"), + $owner_id); + url::redirect("album/{$album->id}"); + break; + + case "photo": + if (is_array($_FILES["file"]["name"])) { + for ($i = 0; $i < count($_FILES["file"]["name"]) - 1; $i++) { + if ($_FILES["file"]["error"][$i] == 0) { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"][$i], + $_FILES["file"]["name"][$i], + $_FILES["file"]["name"][$i], + "", $owner_id); + } else { + throw new Exception("@todo ERROR_IN_UPLOAD_FILE"); + } + } + url::redirect("album/{$item->id}"); + } else { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"], + $_FILES["file"]["name"], + $this->input->post("title", $this->input->post("name")), + $this->input->post("description"), + $owner_id); + url::redirect("{$new_item->type}s/{$new_item->id}"); + } + break; + } + } + + public function _delete($item) { + // @todo Production this code + // 1) Add security checks + $parent = $item->parent(); + if ($parent->id) { + $item->delete(); + } + url::redirect("{$parent->type}s/{$parent->id}"); + } + + public function _create($item) { + // @todo Productionize this + // 1) Figure out how to do the right validation here. Validate the form input and apply it to + // the model as appropriate. + // 2) Figure out how to dispatch according to the needs of the client. Ajax requests from + // jeditable will want the changed field back, and possibly the whole item in json. + // + // For now let's establish a simple protocol where the client passes in a __return parameter + // that specifies which field it wants back from the item. Later on we can expand that to + // include a data format, etc. + + // These fields are safe to change + $post = $this->input->post(); + foreach ($post as $key => $value) { + switch ($key) { + case "title": + case "description": + $item->$key = $value; + break; + } + } + + // @todo Support additional fields + // These fields require additional work if you change them + // parent_id, owner_id + + $item->save(); + if (array_key_exists("__return", $post)) { + print $item->{$post["__return"]}; + } + } +} diff --git a/core/controllers/photo.php b/core/controllers/photo.php deleted file mode 100644 index d6d37f98..00000000 --- a/core/controllers/photo.php +++ /dev/null @@ -1,40 +0,0 @@ -set_global('item', $item); - $template->set_global('children', $item->children()); - $template->set_global('parents', $item->parents()); - $template->set_global('theme', $theme); - $template->set_global('user', Session::instance()->get('user', null)); - $template->content = new View("photo.html"); - - print $template; - } -} diff --git a/core/controllers/photos.php b/core/controllers/photos.php new file mode 100644 index 00000000..a5b75b79 --- /dev/null +++ b/core/controllers/photos.php @@ -0,0 +1,40 @@ +set_global('item', $item); + $template->set_global('children', $item->children()); + $template->set_global('parents', $item->parents()); + $template->set_global('theme', $theme); + $template->set_global('user', Session::instance()->get('user', null)); + $template->content = new View("photo.html"); + + print $template; + } +} diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php index cc85475c..a015fc92 100644 --- a/core/views/welcome.html.php +++ b/core/views/welcome.html.php @@ -164,7 +164,7 @@

- + ( albums, photos)

@@ -183,7 +183,7 @@

Photos -
" enctype="multipart/form-data"> + " enctype="multipart/form-data"> @@ -192,7 +192,7 @@
Albums - "> + "> @@ -210,7 +210,7 @@
  • - id}", "Deepest photo") ?> + id}", "Deepest photo") ?> (level ?> levels deep)
  • -- cgit v1.2.3