summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery/controllers/albums.php192
1 files changed, 96 insertions, 96 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 627ee052..5f62f798 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -17,102 +17,102 @@
* along with this program; if not, write to the Free Software
* 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)) {
- if ($album->id == 1) {
- $view = new Theme_View("page.html", "login");
- $view->page_title = t("Log in to Gallery");
- $view->content = user::get_login_form("login/auth_html");
- print $view;
- return;
- } else {
- access::forbidden();
- }
- }
-
- $show = $this->input->get("show");
-
- if ($show) {
- $index = $album->get_position($show);
- $page = ceil($index / $page_size);
- if ($page == 1) {
- url::redirect("albums/$album->id");
- } else {
- url::redirect("albums/$album->id?page=$page");
- }
- }
-
- $page = $this->input->get("page", "1");
- $children_count = $album->viewable()->children_count();
- $offset = ($page - 1) * $page_size;
- $max_pages = max(ceil($children_count / $page_size), 1);
-
- // Make sure that the page references a valid offset
- if ($page < 1) {
- url::redirect("albums/$album->id");
- } else if ($page > $max_pages) {
- url::redirect("albums/$album->id?page=$max_pages");
- }
-
- $template = new Theme_View("page.html", "album");
- $template->set_global("page_size", $page_size);
- $template->set_global("item", $album);
- $template->set_global("children", $album->viewable()->children($page_size, $offset));
- $template->set_global("children_count", $children_count);
- $template->set_global("parents", $album->parents());
- $template->content = new View("album.html");
-
- // We can't use math in ORM or the query builder, so do this by hand. It's important
- // that we do this with math, otherwise concurrent accesses will damage accuracy.
- Database::instance()->query(
- "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id");
-
- print $template;
- }
-
- /**
- * @see REST_Controller::_create($resource)
- */
- public function _create($album) {
- 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) {
- access::required("view", $album);
- access::required("add", $album);
-
- $form = album::get_add_form($album);
- if ($form->validate()) {
- $new_album = album::create(
- $album,
- $this->input->post("name"),
- $this->input->post("title", $this->input->post("name")),
- $this->input->post("description"),
- user::active()->id);
-
- log::success("content", "Created an album",
- html::anchor("albums/$new_album->id", "view album"));
- message::success(t("Created album %album_title",
- array("album_title" => html::purify($new_album->title))));
+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)) {
+ if ($album->id == 1) {
+ $view = new Theme_View("page.html", "login");
+ $view->page_title = t("Log in to Gallery");
+ $view->content = user::get_login_form("login/auth_html");
+ print $view;
+ return;
+ } else {
+ access::forbidden();
+ }
+ }
+
+ $show = $this->input->get("show");
+
+ if ($show) {
+ $index = $album->get_position($show);
+ $page = ceil($index / $page_size);
+ if ($page == 1) {
+ url::redirect("albums/$album->id");
+ } else {
+ url::redirect("albums/$album->id?page=$page");
+ }
+ }
+
+ $page = $this->input->get("page", "1");
+ $children_count = $album->viewable()->children_count();
+ $offset = ($page - 1) * $page_size;
+ $max_pages = max(ceil($children_count / $page_size), 1);
+
+ // Make sure that the page references a valid offset
+ if ($page < 1) {
+ url::redirect("albums/$album->id");
+ } else if ($page > $max_pages) {
+ url::redirect("albums/$album->id?page=$max_pages");
+ }
+
+ $template = new Theme_View("page.html", "album");
+ $template->set_global("page_size", $page_size);
+ $template->set_global("item", $album);
+ $template->set_global("children", $album->viewable()->children($page_size, $offset));
+ $template->set_global("children_count", $children_count);
+ $template->set_global("parents", $album->parents());
+ $template->content = new View("album.html");
+
+ // We can't use math in ORM or the query builder, so do this by hand. It's important
+ // that we do this with math, otherwise concurrent accesses will damage accuracy.
+ Database::instance()->query(
+ "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id");
+
+ print $template;
+ }
+
+ /**
+ * @see REST_Controller::_create($resource)
+ */
+ public function _create($album) {
+ 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) {
+ access::required("view", $album);
+ access::required("add", $album);
+
+ $form = album::get_add_form($album);
+ if ($form->validate()) {
+ $new_album = album::create(
+ $album,
+ $this->input->post("name"),
+ $this->input->post("title", $this->input->post("name")),
+ $this->input->post("description"),
+ user::active()->id);
+
+ log::success("content", "Created an album",
+ html::anchor("albums/$new_album->id", "view album"));
+ message::success(t("Created album %album_title",
+ array("album_title" => html::purify($new_album->title))));
print json_encode(
array("result" => "success",