Skip to content

Commit

Permalink
Move the theme fallback checking into theme::load_themes() so that
Browse files Browse the repository at this point in the history
we're calling it once per request.
  • Loading branch information
bharat committed Nov 28, 2009
1 parent ce183e5 commit 22149b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
17 changes: 13 additions & 4 deletions modules/gallery/helpers/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Note: by design, this class does not do any permission checking.
*/
class theme_Core {
public static $active_theme;

/**
* Load the active theme. This is called at bootstrap time. We will only ever have one theme
* active for any given request.
Expand All @@ -35,15 +37,22 @@ static function load_themes() {
$path = "/" . $input->get("kohana_uri");
}

$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
$setting_name = $is_admin ? "active_admin_theme" : "active_site_theme";
if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) {
$theme_name = module::get_var(
"gallery",
$path == "/admin" || !strncmp($path, "/admin/", 7) ?
"active_admin_theme" : "active_site_theme");
$theme_name = module::get_var("gallery", $setting_name);

if (!file_exists(THEMEPATH . $theme_name)) {
Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme.");
$theme_name = $is_admin ? "admin_wind" : "wind";
module::set_var("gallery", $setting_name, $theme_name);
}
}
$modules = Kohana::config("core.modules");
array_unshift($modules, THEMEPATH . $theme_name);
Kohana::config_set("core.modules", $modules);

self::$active_theme = $theme_name;
}

static function get_edit_form_admin() {
Expand Down
6 changes: 0 additions & 6 deletions modules/gallery/libraries/Admin_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class Admin_View_Core extends Gallery_View {
* @return void
*/
public function __construct($name) {
$theme_name = module::get_var("gallery", "active_admin_theme");
if (!file_exists(THEMEPATH . $theme_name)) {
module::set_var("gallery", "active_admin_theme", "admin_wind");
theme::load_themes();
Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme.");
}
parent::__construct($name);

$this->theme_name = module::get_var("gallery", "active_admin_theme");
Expand Down
6 changes: 0 additions & 6 deletions modules/gallery/libraries/Theme_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ class Theme_View_Core extends Gallery_View {
* @return void
*/
public function __construct($name, $page_type, $page_subtype) {
$theme_name = module::get_var("gallery", "active_site_theme");
if (!file_exists(THEMEPATH . $theme_name)) {
module::set_var("gallery", "active_site_theme", "wind");
theme::load_themes();
Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme.");
}
parent::__construct($name);

$this->theme_name = module::get_var("gallery", "active_site_theme");
Expand Down

0 comments on commit 22149b5

Please sign in to comment.