Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:gallery/gallery3 into bharat_dev
Browse files Browse the repository at this point in the history
Conflicts:
	modules/gallery/helpers/theme.php
	modules/gallery/libraries/Admin_View.php
	modules/gallery/libraries/Theme_View.php
  • Loading branch information
bharat committed Nov 29, 2009
2 parents 96b00d6 + 3d4672b commit 3f63e1c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
15 changes: 15 additions & 0 deletions modules/gallery/helpers/module.php
Expand Up @@ -338,6 +338,21 @@ static function event($name, &$data=null) {
call_user_func_array(array($class, $function), $args);
}
}

// Give the admin theme a chance to respond, if we're in admin mode.
if (theme::$is_admin) {
$class = theme::$admin_theme_name . "_event";
if (method_exists($class, $function)) {
call_user_func_array(array($class, $function), $args);
}
}

// Give the site theme a chance to respond as well. It gets a chance even in admin mode, as
// long as the theme has an admin subdir.
$class = theme::$site_theme_name . "_event";
if (method_exists($class, $function)) {
call_user_func_array(array($class, $function), $args);
}
}

/**
Expand Down
38 changes: 30 additions & 8 deletions modules/gallery/helpers/theme.php
Expand Up @@ -24,6 +24,10 @@
* Note: by design, this class does not do any permission checking.
*/
class theme_Core {
public static $admin_theme_name;
public static $site_theme_name;
public static $is_admin;

/**
* 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 +39,33 @@ static function load_themes() {
$path = "/" . $input->get("kohana_uri");
}

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");
$config = Kohana_Config::instance();
$modules = $config->get("core.modules");
self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
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 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::add("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::instance()->set("core.modules", $modules);

$config->set("core.modules", $modules);
}

static function get_edit_form_admin() {
Expand Down
6 changes: 0 additions & 6 deletions modules/gallery/libraries/Admin_View.php
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::add("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
13 changes: 7 additions & 6 deletions modules/gallery/libraries/Theme_View.php
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::add("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 Expand Up @@ -271,6 +265,13 @@ public function __call($function, $args) {
}
}

$helper_class = theme::$site_theme_name . "_theme";
if (method_exists($helper_class, $function)) {
$blocks[] = call_user_func_array(
array($helper_class, $function),
array_merge(array($this), $args));
}

if ($function == "head") {
array_unshift($blocks, $this->combine_files($this->css, "css"));
array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
Expand Down

0 comments on commit 3f63e1c

Please sign in to comment.