diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-11-28 23:25:07 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-11-28 23:25:07 -0800 |
commit | f3981bbaa9c9e72d147e164a3decea411b6dd54c (patch) | |
tree | 137e3d802685508bd44908d8cfa650a298d82a5f /modules/gallery/helpers/theme.php | |
parent | b677778253cdea89e19befbf04441a741010bfc2 (diff) |
Rework the theme loading code to allow themes to be treated as Gallery
modules, and have an admin subdirectory that is treated like a Kohana
module (as distinct from a Gallery module).
The main advantage of creating the separate admin subdirectory is that
we will not load an admin theme and a site theme at the same time.
We'll only load a few specialized bits of the site theme while the
admin theme is active.
Concrete examples. A site theme named "xxx":
- will receive events at themes/xxx/helpers/xxx_event.php
- will have working controllers at themes/xxx/controllers/xxx.php
If theme xxx has an admin subdir, then in admin mode it:
- will receive events at themes/xxx/admin/helpers/xxx_event.php
- will have working controllers at themes/xxx/admin/controllers/xxx.php
Diffstat (limited to 'modules/gallery/helpers/theme.php')
-rw-r--r-- | modules/gallery/helpers/theme.php | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 19737c0e..75b48bcc 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -24,7 +24,8 @@ * Note: by design, this class does not do any permission checking. */ class theme_Core { - public static $active_theme; + public static $admin_theme_name; + public static $site_theme_name; public static $is_admin; /** @@ -38,22 +39,32 @@ class theme_Core { $path = "/" . $input->get("kohana_uri"); } + $modules = Kohana::config("core.modules"); self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); - $setting_name = self::$is_admin ? "active_admin_theme" : "active_site_theme"; - if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) { - $theme_name = module::get_var("gallery", $setting_name); + self::$site_theme_name = module::get_var("gallery", "active_site_theme"); + if (self::$is_admin) { + // Load the admin theme + self::$admin_theme_name = module::get_var("gallery", "active_admin_theme"); + array_unshift($modules, THEMEPATH . self::$admin_theme_name); - if (!file_exists(THEMEPATH . $theme_name)) { - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); - $theme_name = self::$is_admin ? "admin_wind" : "wind"; - module::set_var("gallery", $setting_name, $theme_name); + // If the site theme has an admin subdir, load that as a module so that + // themes can provide their own code. + if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) { + array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin"); + } + } else { + // Admins can override the site theme, temporarily. This lets us preview themes. + if (identity::active_user()->admin && $override = $input->get("theme")) { + if (file_exists(THEMEPATH . $override)) { + self::$site_theme_name = $override; + } else { + Kohana::log("error", "Missing override theme: '$override'"); + } } + array_unshift($modules, THEMEPATH . self::$site_theme_name); } - $modules = Kohana::config("core.modules"); - array_unshift($modules, THEMEPATH . $theme_name); - Kohana::config_set("core.modules", $modules); - self::$active_theme = $theme_name; + Kohana::config_set("core.modules", $modules); } static function get_edit_form_admin() { |