diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/admin_themes.php | 19 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 18 | ||||
-rw-r--r-- | core/helpers/module.php | 14 | ||||
-rw-r--r-- | core/helpers/theme.php | 55 | ||||
-rw-r--r-- | core/hooks/load_modules.php | 2 | ||||
-rw-r--r-- | core/hooks/load_themes.php | 21 | ||||
-rw-r--r-- | core/models/theme.php | 21 | ||||
-rw-r--r-- | core/views/admin_themes.html.php | 31 |
8 files changed, 155 insertions, 26 deletions
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 @@ -184,20 +184,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 * @param mixed $data data to pass to each event handler 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 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** + * This is the API for handling themes. + * + * Note: by design, this class does not do any permission checking. + */ +class theme_Core { + /** + * 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); + } + + public static function get_edit_form_admin($theme) { + $form = new Forge("admin/themes/edit/$theme->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 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +Event::add("system.post_routing", array("theme", "load_themes")); diff --git a/core/models/theme.php b/core/models/theme.php new file mode 100644 index 00000000..d76bcdaf --- /dev/null +++ b/core/models/theme.php @@ -0,0 +1,21 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Theme_Model extends ORM { +}
\ No newline at end of file diff --git a/core/views/admin_themes.html.php b/core/views/admin_themes.html.php index 1064ae5e..e6475b45 100644 --- a/core/views/admin_themes.html.php +++ b/core/views/admin_themes.html.php @@ -1,17 +1,30 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <div id="gThemes"> <h1><?= t("Theme Administration") ?></h1> - <p> - <?= t("These are the themes in your system") ?> - </p> - <form method="post" action="<?= url::site("admin/themes/save") ?>"> + <form method="post" id="gThemeAdmin" action="<?= url::site("admin/themes/save") ?>"> <?= access::csrf_form_field() ?> - <? foreach ($themes as $theme): ?> - <input type="radio" name="theme" value="<?= $theme ?>" - <? if ($theme == $active): ?> checked="checked" <? endif ?> - /> - <?= $theme ?> + <table><tbody><tr><td> + <?= t("Current theme") ?><br /> + <a href="#"> + <img src="<?= url::file("themes/{$active}/thumbnail.png") ?>" alt="<?= $themes[$active]->name ?>" /> + </a><br /> + <?= $themes[$active]->description ?><br /> + <input type="radio" name="themes" value="<?= $active ?>" checked="checked"> + <?= $themes[$active]->name ?> + </td> + <? foreach ($themes as $id => $theme): ?> + <? if ($id == $active) continue; ?> + <td> + <a href="#"> + <img src="<?= url::file("themes/{$id}/thumbnail.png") ?>" alt="<?= $theme->name ?>" /> + </a><br /> + <?= $theme->description ?><br /> + <input type="radio" name="themes" value="<?= $id ?>"> <?= $theme->name ?> + </td> <? endforeach ?> + </tr></tbody></table> <input type="submit" value="<?= t("Save") ?>"/> </form> + <div id="gThemeDetails"></div> + </div> |