From b647aa0f74e66548d6d69fc4585b89220ce60043 Mon Sep 17 00:00:00 2001 From: Felix Rabinovich Date: Fri, 9 Jan 2009 23:31:46 +0000 Subject: Theme Administration v. 2. Doesn't distinguish between regular and admin themes yet --- core/controllers/admin_themes.php | 19 ++++++++++++-- core/helpers/core_installer.php | 18 +++++++++++++ core/helpers/module.php | 14 ---------- core/helpers/theme.php | 55 +++++++++++++++++++++++++++++++++++++++ core/hooks/load_modules.php | 2 +- core/hooks/load_themes.php | 21 +++++++++++++++ core/models/theme.php | 21 +++++++++++++++ core/views/admin_themes.html.php | 31 +++++++++++++++------- 8 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 core/helpers/theme.php create mode 100644 core/hooks/load_themes.php create mode 100644 core/models/theme.php (limited to 'core') diff --git a/core/controllers/admin_themes.php b/core/controllers/admin_themes.php index 6641221f..8943f588 100644 --- a/core/controllers/admin_themes.php +++ b/core/controllers/admin_themes.php @@ -21,12 +21,27 @@ class Admin_Themes_Controller extends Admin_Controller { public function index() { $view = new Admin_View("admin.html"); $view->content = new View("admin_themes.html"); - $themes = scandir(THEMEPATH); - $view->content->themes = array_diff($themes, array(".", "..", ".svn")); + $themeDir = scandir(THEMEPATH); + $themes = array(); + foreach ($themeDir as $theme_name) { + if (substr($theme_name, 0, 1) == ".") continue; + $file = THEMEPATH . $theme_name . "/theme.info"; + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $details = theme::get_edit_form_admin($theme_info); + $theme_info['details'] = $details; + $themes[$theme_name] = $theme_info; + } + $view->content->themes = $themes; $view->content->active = module::get_var("core", "active_theme"); print $view; } + public function edit($theme_name) { + $file = THEMEPATH . $theme_name . "/theme.info"; + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + print theme::get_edit_form_admin($theme_info); + } + public function save() { access::verify_csrf(); $theme = $this->input->post("theme"); diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index 043af641..115aca20 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -112,6 +112,14 @@ class core_installer { UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE `themes` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) default NULL, + `version` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE `permissions` ( `id` int(9) NOT NULL auto_increment, `name` varchar(64) default NULL, @@ -216,6 +224,15 @@ class core_installer { "missing_graphics_toolkit"); } + // Instantiate default themes (regular and admin) + foreach (array("default", "admin_default") as $theme_name) { + $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), + ArrayObject::ARRAY_AS_PROPS); + $theme = ORM::factory("theme"); + $theme->name = $theme_name; + $theme->version = $theme_info->version; + $theme->save(); + } module::set_version("core", 1); } } @@ -229,6 +246,7 @@ class core_installer { $db->query("DROP TABLE IF EXISTS `logs`;"); $db->query("DROP TABLE IF EXISTS `messages`;"); $db->query("DROP TABLE IF EXISTS `modules`;"); + $db->query("DROP TABLE IF EXISTS `themes`;"); $db->query("DROP TABLE IF EXISTS `translations_incoming`;"); $db->query("DROP TABLE IF EXISTS `permissions`;"); $db->query("DROP TABLE IF EXISTS `sessions`;"); diff --git a/core/helpers/module.php b/core/helpers/module.php index 5568ee7a..0c800786 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -183,20 +183,6 @@ class module_Core { } public static function dummy_error_handler() { } - /** - * Load the active theme. This is called at bootstrap time. We will only ever have one theme - * active for any given request. - */ - public static function load_themes() { - $modules = Kohana::config('core.modules'); - if (Router::$controller == "admin") { - array_unshift($modules, THEMEPATH . 'admin_default'); - } else { - array_unshift($modules, THEMEPATH . 'default'); - } - Kohana::config_set('core.modules', $modules); - } - /** * Run a specific event on all active modules. * @param string $name the event name diff --git a/core/helpers/theme.php b/core/helpers/theme.php new file mode 100644 index 00000000..62433898 --- /dev/null +++ b/core/helpers/theme.php @@ -0,0 +1,55 @@ +name", "Theme Parameters", "GET"); +// array("id" => "gThemeDetails")); + $group = $form->group("edit_theme")->label($theme->description); + $group->input("name")->label(t("Name"))->id("gName")->value($theme->name); + $group->submit(t("Modify Theme")); + return $form; + } + + public static function get_edit_form_content($theme_name) { + $file = THEMEPATH . $theme_name . "/theme.info"; + $theme_info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + } +} + diff --git a/core/hooks/load_modules.php b/core/hooks/load_modules.php index 887582f7..1c281cdf 100644 --- a/core/hooks/load_modules.php +++ b/core/hooks/load_modules.php @@ -19,4 +19,4 @@ */ Event::add("system.ready", array("module", "load_modules")); -Event::add("system.post_routing", array("module", "load_themes")); + diff --git a/core/hooks/load_themes.php b/core/hooks/load_themes.php new file mode 100644 index 00000000..e5fc12b6 --- /dev/null +++ b/core/hooks/load_themes.php @@ -0,0 +1,21 @@ +

-

- -

-
"> + "> - - checked="checked" - /> - + + $theme): ?> + + +
+
+ + " alt="name ?>" /> +
+ description ?>
+ + name ?> +
+ + " alt="name ?>" /> +
+ description ?>
+ name ?> +
"/>
+
+
-- cgit v1.2.3