diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-04 09:45:17 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-04 10:12:21 -0700 |
commit | aa0529d557ed0609bf7e5b23a5cf2437f7998c4b (patch) | |
tree | 028337388818b1a1ef0de24c9ee7d62162206e05 | |
parent | 60c15e41b37fbe6b2adc7789b21b7e5acea3e949 (diff) |
Create a gallery::plugin_path which returns the appropriate path to the module or theme. This checks for the existence of an application/modules or application/themes first.
-rw-r--r-- | modules/gallery/controllers/admin_themes.php | 31 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 13 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 34 | ||||
-rw-r--r-- | modules/gallery/helpers/theme.php | 7 |
5 files changed, 55 insertions, 34 deletions
diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 24f91aba..722cfb45 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -29,17 +29,20 @@ class Admin_Themes_Controller extends Admin_Controller { private function _get_themes() { $themes = array(); - foreach (scandir(THEMEPATH) as $theme_name) { - if ($theme_name[0] == ".") { - continue; - } - - $file = THEMEPATH . "$theme_name/theme.info"; - $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $theme_info->description = t($theme_info->description); - $theme_info->name = t($theme_info->name); + foreach (array(APPPATH . "themes/", THEMEPATH) as $themepath) { + foreach (scandir($themepath) as $theme_name) { + if ($theme_name[0] == ".") { + continue; + } + $file = $themepath . "$theme_name/theme.info"; + if (file_exists($file)) { + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $theme_info->description = t($theme_info->description); + $theme_info->name = t($theme_info->name); - $themes[$theme_name] = $theme_info; + $themes[$theme_name] = $theme_info; + } + } } return $themes; } @@ -47,8 +50,8 @@ class Admin_Themes_Controller extends Admin_Controller { public function preview($type, $theme_name) { $view = new View("admin_themes_preview.html"); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $view->info = new ArrayObject( - parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); + $view->info = new ArrayObject(parse_ini_file( + gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); $view->theme_name = $theme_name; $view->type = $type; if ($type == "admin") { @@ -63,8 +66,8 @@ class Admin_Themes_Controller extends Admin_Controller { access::verify_csrf(); $theme_name = preg_replace("/[^\w]/", "", $theme_name); - $info = new ArrayObject( - parse_ini_file(THEMEPATH . "$theme_name/theme.info"), ArrayObject::ARRAY_AS_PROPS); + $info = new ArrayObject(parse_ini_file( + gallery::plugin_path("$theme_name/theme.info", "theme")), ArrayObject::ARRAY_AS_PROPS); if ($type == "admin" && $info->admin) { module::set_var("gallery", "active_admin_theme", $theme_name); diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 37a08d08..6d387d76 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -110,4 +110,17 @@ class gallery_Core { return $file_name; } + /** + * Return a full path to the theme or module file. It checks the APPPATH/(themes|modules) first + * then the THEMEPATH | MODPATH + * @param $file the file or directory + * @param $type ("module" | "theme" optional: defaults to "module") + * @return string + */ + static function plugin_path($file, $type="module") { + if (!file_exists($ofile = APPPATH . "{$type}s/$file")) { + $ofile = $type == "module" ? MODPATH . $file : THEMEPATH . $file; + } + return $ofile; + } }
\ No newline at end of file diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index b1ea1f19..e834a62c 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -245,8 +245,8 @@ class gallery_installer { // Instantiate default themes (site and admin) foreach (array("wind", "admin_wind") as $theme_name) { - $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), - ArrayObject::ARRAY_AS_PROPS); + $file = gallery::plugin_path("$theme_name/theme.info", "theme"); + $theme_info = new ArrayObject(parse_ini_file($file, ArrayObject::ARRAY_AS_PROPS); $theme = ORM::factory("theme"); $theme->name = $theme_name; $theme->version = $theme_info->version; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..99c52cab 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -77,15 +77,23 @@ class module_Core { static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (glob(MODPATH . "*/module.info") as $file) { - $module_name = basename(dirname($file)); - $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); - $m =& $modules->$module_name; - $m->installed = self::is_installed($module_name); - $m->active = self::is_active($module_name); - $m->code_version = $m->version; - $m->version = self::get_version($module_name); - $m->locked = false; + foreach (array(APPPATH . "modules/", MODPATH) as $modpath) { + foreach (scandir($modpath) as $module_name) { + if ($module_name[0] == ".") { + continue; + } + $file = "{$modpath}$module_name/module.info"; + if (file_exists($file)) { + $modules->$module_name = + new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $m =& $modules->$module_name; + $m->installed = self::is_installed($module_name); + $m->active = self::is_active($module_name); + $m->code_version = $m->version; + $m->version = self::get_version($module_name); + $m->locked = false; + } + } } // Lock certain modules @@ -113,7 +121,7 @@ class module_Core { */ static function install($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -140,7 +148,7 @@ class module_Core { */ static function upgrade($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $version_before = module::get_version($module_name); @@ -179,7 +187,7 @@ class module_Core { */ static function activate($module_name) { $kohana_modules = Kohana::config("core.modules"); - array_unshift($kohana_modules, MODPATH . $module_name); + array_unshift($kohana_modules, gallery::plugin_path($module_name)); Kohana::config_set("core.modules", $kohana_modules); $installer_class = "{$module_name}_installer"; @@ -271,7 +279,7 @@ class module_Core { $gallery = $module; } else { self::$active[] = $module; - $kohana_modules[] = MODPATH . $module->name; + $kohana_modules[] = gallery::plugin_path($module->name); } } self::$active[] = $gallery; // put gallery last in the module list to match core.modules diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index fb8f7ca7..3ba11aa2 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -30,11 +30,8 @@ class theme_Core { */ static function load_themes() { $modules = Kohana::config("core.modules"); - if (Router::$controller == "admin") { - array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_admin_theme")); - } else { - array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_site_theme")); - } + array_unshift($modules, gallery::plugin_path(module::get_var("gallery", + (Router::$controller == "admin") ? "active_admin_theme" : "active_site_theme"), "theme")); Kohana::config_set("core.modules", $modules); } |