summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-24 04:22:22 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-24 04:22:22 +0000
commitc7193f9b2ede6ed913d16a9a8047b6867b8afada (patch)
treecd7bf045bb8f6a971eda11de9b91b4c61d52f4f6
parentb2c9a59d1b80cfe651c740c2eabbc0862a7a867e (diff)
Normalize our Admin controllers so that functions always print out
their results, as opposed to having them return their view back upstream. This is a little more code in every controller, but it's much less magical and more consistent. Look up the active_theme and active_admin_theme inside the view itself, no need to do that in the controllers. This makes view initialization easier in the controllers.
-rw-r--r--core/controllers/admin.php11
-rw-r--r--core/controllers/admin_dashboard.php4
-rw-r--r--core/controllers/admin_modules.php7
-rw-r--r--core/controllers/albums.php3
-rw-r--r--core/controllers/photos.php5
-rw-r--r--core/libraries/Admin_View.php5
-rw-r--r--core/libraries/Theme_View.php5
-rw-r--r--modules/tag/controllers/tags.php3
-rw-r--r--modules/user/controllers/admin_users.php11
-rw-r--r--modules/watermark/controllers/admin_watermarks.php12
10 files changed, 31 insertions, 35 deletions
diff --git a/core/controllers/admin.php b/core/controllers/admin.php
index 6e44c54e..6f4ec47a 100644
--- a/core/controllers/admin.php
+++ b/core/controllers/admin.php
@@ -24,14 +24,9 @@ class Admin_Controller extends Controller {
if (!(user::active()->admin)) {
throw new Exception("@todo UNAUTHORIZED", 401);
}
- $this->theme = $theme;
parent::__construct();
}
- public function theme() {
- return $this->theme;
- }
-
public function __call($controller_name, $args) {
if (request::method() == "post") {
access::verify_csrf();
@@ -48,11 +43,7 @@ class Admin_Controller extends Controller {
$method = "index";
}
- $theme_name = module::get_var("core", "active_admin_theme", "admin_default");
- $this->template = $template = new Admin_View("admin.html", $theme_name);
- $template->content = call_user_func_array(
- array(new $controller_name($template), $method), $args);
- print $template;
+ call_user_func_array(array(new $controller_name, $method), $args);
}
}
diff --git a/core/controllers/admin_dashboard.php b/core/controllers/admin_dashboard.php
index 13ec5d82..bd295b84 100644
--- a/core/controllers/admin_dashboard.php
+++ b/core/controllers/admin_dashboard.php
@@ -19,7 +19,9 @@
*/
class Admin_Dashboard_Controller extends Admin_Controller {
public function index() {
- return $this->theme()->admin_dashboard_blocks();
+ $view = new Admin_View("admin.html");
+ $view->content = $view->admin_dashboard_blocks();
+ print $view;
}
}
diff --git a/core/controllers/admin_modules.php b/core/controllers/admin_modules.php
index ada7dcfd..152e49c3 100644
--- a/core/controllers/admin_modules.php
+++ b/core/controllers/admin_modules.php
@@ -19,9 +19,10 @@
*/
class Admin_Modules_Controller extends Admin_Controller {
public function index() {
- $view = new View("admin_modules.html");
- $view->available = module::available();
- return $view;
+ $view = new Admin_View("admin.html");
+ $view->content = new View("admin_modules.html");
+ $view->content->available = module::available();
+ print $view;
}
public function save() {
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index 8d2b5b77..08b61058 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -25,7 +25,6 @@ class Albums_Controller extends Items_Controller {
public function _show($album) {
access::required("view", $album);
- $theme_name = module::get_var("core", "active_theme", "default");
$page_size = module::get_var("core", "page_size", 9);
$page = $this->input->get("page", "1");
$children_count = $album->viewable()->children_count();
@@ -36,7 +35,7 @@ class Albums_Controller extends Items_Controller {
Kohana::show_404();
}
- $template = new Theme_View("page.html", "album", $theme_name);
+ $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));
diff --git a/core/controllers/photos.php b/core/controllers/photos.php
index 730cfd2c..4690bf58 100644
--- a/core/controllers/photos.php
+++ b/core/controllers/photos.php
@@ -25,10 +25,7 @@ class Photos_Controller extends Items_Controller {
public function _show($photo) {
access::required("view", $photo);
- $theme_name = module::get_var("core", "active_theme", "default");
-
- $template = new Theme_View("page.html", "photo", $theme_name);
-
+ $template = new Theme_View("page.html", "photo");
$template->set_global('item', $photo);
$template->set_global('children', array());
$template->set_global('children_count', $photo->children_count());
diff --git a/core/libraries/Admin_View.php b/core/libraries/Admin_View.php
index e9ff9791..3255f04d 100644
--- a/core/libraries/Admin_View.php
+++ b/core/libraries/Admin_View.php
@@ -28,9 +28,10 @@ class Admin_View_Core extends View {
* @param string $theme_name view name
* @return void
*/
- public function __construct($name, $theme_name="default") {
+ public function __construct($name) {
parent::__construct($name);
- $this->theme_name = $theme_name;
+
+ $this->theme_name = module::get_var("core", "active_admin_theme");
$this->set_global('theme', $this);
$this->set_global('user', user::active());
}
diff --git a/core/libraries/Theme_View.php b/core/libraries/Theme_View.php
index 030e564d..37507a70 100644
--- a/core/libraries/Theme_View.php
+++ b/core/libraries/Theme_View.php
@@ -29,9 +29,10 @@ class Theme_View_Core extends View {
* @param string $theme_name view name
* @return void
*/
- public function __construct($name, $page_type, $theme_name="default") {
+ public function __construct($name, $page_type) {
parent::__construct($name);
- $this->theme_name = $theme_name;
+
+ $this->theme_name = module::get_var("core", "active_theme");
$this->set_global('theme', $this);
$this->set_global('user', user::active());
$this->set_global("page_type", $page_type);
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 94890639..d87ab8e8 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -21,7 +21,6 @@ class Tags_Controller extends REST_Controller {
protected $resource_type = "tag";
public function _show($tag) {
- $theme_name = module::get_var("core", "active_theme", "default");
$page_size = module::get_var("core", "page_size", 9);
$page = $this->input->get("page", "1");
$children_count = $tag->items_count();
@@ -32,7 +31,7 @@ class Tags_Controller extends REST_Controller {
Kohana::show_404();
}
- $template = new Theme_View("page.html", "tag", $theme_name);
+ $template = new Theme_View("page.html", "tag");
$template->set_global('page_size', $page_size);
$template->set_global('tag', $tag);
$template->set_global('children', $tag->items($page_size, $offset));
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index 38e4e43a..ac328780 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -19,9 +19,10 @@
*/
class Admin_Users_Controller extends Controller {
public function index() {
- $view = new View("admin_users.html");
- $view->users = ORM::factory("user")->find_all();
- return $view;
+ $view = new Admin_View("admin.html");
+ $view->content = new View("admin_users.html");
+ $view->content->users = ORM::factory("user")->find_all();
+ print $view;
}
public function edit($id) {
@@ -40,6 +41,8 @@ class Admin_Users_Controller extends Controller {
url::redirect("admin/users/edit/$id");
}
- return $form;
+ $view = new Admin_View("admin.html");
+ $view->content = $form;
+ print $view;
}
}
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php
index 972e506e..469f14fe 100644
--- a/modules/watermark/controllers/admin_watermarks.php
+++ b/modules/watermark/controllers/admin_watermarks.php
@@ -41,17 +41,19 @@ class Admin_Watermarks_Controller extends Admin_Controller {
$watermark->height = $image_info[1];
$watermark->mime_type = $image_info["mime"];
$watermark->save();
+
message::add(_("Watermark saved"));
- url::redirect("admin/watermarks");
+ response::redirect("admin/watermarks");
}
}
@unlink($file);
}
- $view = new View("admin_watermarks.html");
- $view->watermarks = ORM::factory("watermark")->find_all();
- $view->form = watermark::get_watermark_form();
- return $view;
+ $view = new Admin_View("admin.html");
+ $view->content = new View("admin_watermarks.html");
+ $view->content->watermarks = ORM::factory("watermark")->find_all();
+ $view->content->form = watermark::get_watermark_form();
+ print $view;
}
public function get_form($user_id) {