diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/admin_theme_options.php | 52 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_themes.php | 21 | ||||
-rw-r--r-- | modules/gallery/controllers/albums.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 21 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 21 | ||||
-rw-r--r-- | modules/gallery/helpers/theme.php | 70 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 2 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 | ||||
-rw-r--r-- | modules/gallery/views/admin_theme_options.html.php | 2 |
9 files changed, 110 insertions, 83 deletions
diff --git a/modules/gallery/controllers/admin_theme_options.php b/modules/gallery/controllers/admin_theme_options.php index 27a67bdb..dc421ee1 100644 --- a/modules/gallery/controllers/admin_theme_options.php +++ b/modules/gallery/controllers/admin_theme_options.php @@ -21,48 +21,44 @@ class Admin_Theme_Options_Controller extends Admin_Controller { public function index() { $view = new Admin_View("admin.html"); $view->content = new View("admin_theme_options.html"); - $view->content->form = theme::get_edit_form_admin(); + + $theme_name = theme::$site; + $info = theme::get_info($theme_name); + + // Don't use the Kohana cascading file system because we don't want to mess up the admin theme + $theme_helper = THEMEPATH . "$theme_name/helpers/{$theme_name}.php"; + @require_once($theme_helper); + $view->content->form = call_user_func_array(array(theme::$site, "get_admin_form"), + array("admin/theme_options/save/")); + + $view->content->title = t("%name options", array("name" => $info->name)); + print $view; } public function save() { access::verify_csrf(); - $form = theme::get_edit_form_admin(); - if ($form->validate()) { - module::set_var("gallery", "page_size", $form->edit_theme->page_size->value); + // Don't use the Kohana cascading file system because we don't want to mess up the admin theme + $theme_name = theme::$site; + $theme_helper = THEMEPATH . "$theme_name/helpers/{$theme_name}.php"; + @require_once($theme_helper); - $thumb_size = $form->edit_theme->thumb_size->value; - $thumb_dirty = false; - if (module::get_var("gallery", "thumb_size") != $thumb_size) { - graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize"); - graphics::add_rule( - "gallery", "thumb", "gallery_graphics::resize", - array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), - 100); - module::set_var("gallery", "thumb_size", $thumb_size); - } + $info = theme::get_info($theme_name); - $resize_size = $form->edit_theme->resize_size->value; - $resize_dirty = false; - if (module::get_var("gallery", "resize_size") != $resize_size) { - graphics::remove_rule("gallery", "resize", "gallery_graphics::resize"); - graphics::add_rule( - "gallery", "resize", "gallery_graphics::resize", - array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), - 100); - module::set_var("gallery", "resize_size", $resize_size); - } + $form = call_user_func_array(array(theme::$site, "get_admin_form"), + array("admin/theme_options/save/")); + if ($form->validate()) { - module::set_var("gallery", "header_text", $form->edit_theme->header_text->value); - module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value); - module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value); + $view->content->form = call_user_func_array(array(theme::$site, "update_options"), + array($form)); - message::success(t("Updated theme details")); + message::success(t("Updated %name options", array("name" => $info->name))); url::redirect("admin/theme_options"); } else { $view = new Admin_View("admin.html"); $view->content = $form; + $view->content->title = t("%name options", array("name" => $info->name)); print $view; } } diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 24f91aba..23685c90 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -34,22 +34,15 @@ class Admin_Themes_Controller extends Admin_Controller { 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); - - $themes[$theme_name] = $theme_info; + $themes[$theme_name] = theme::get_info($theme_name); } return $themes; } 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->theme_name = $theme_name; + $view->info = theme::get_info($theme_name); + $view->theme_name = t($theme_name); $view->type = $type; if ($type == "admin") { $view->url = url::site("admin?theme=$theme_name"); @@ -62,18 +55,16 @@ class Admin_Themes_Controller extends Admin_Controller { public function choose($type, $theme_name) { 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 = theme::get_info($theme_name); if ($type == "admin" && $info->admin) { module::set_var("gallery", "active_admin_theme", $theme_name); message::success(t("Successfully changed your admin theme to <b>%theme_name</b>", - array("theme_name" => t($info->name)))); + array("theme_name" => $info->name))); } else if ($type == "site" && $info->site) { module::set_var("gallery", "active_site_theme", $theme_name); message::success(t("Successfully changed your Gallery theme to <b>%theme_name</b>", - array("theme_name" => t($info->name)))); + array("theme_name" => $info->name))); } url::redirect("admin/themes"); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e67df6f6..749fb520 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -23,7 +23,7 @@ class Albums_Controller extends Items_Controller { * @see REST_Controller::_show($resource) */ public function _show($album) { - $page_size = module::get_var("gallery", "page_size", 9); + $page_size = theme::get_var("page_size", 9); if (!access::can("view", $album)) { if ($album->id == 1) { $view = new Theme_View("page.html", "other", "login"); diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 3139951f..88f4a67b 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -245,11 +245,7 @@ class gallery_event_Core { ->id("themes") ->label(t("Theme choice")) ->url(url::site("admin/themes"))) - ->append(Menu::factory("link") - ->id("theme_options") - ->label(t("Theme options")) - ->url(url::site("admin/theme_options"))) - ->append(Menu::factory("link") + ->append(Menu::factory("link") ->id("sidebar") ->label(t("Manage sidebar")) ->url(url::site("admin/sidebar")))) @@ -260,6 +256,21 @@ class gallery_event_Core { ->id("maintenance") ->label(t("Maintenance")) ->url(url::site("admin/maintenance"))); + + $theme_name = theme::$site; + $theme_helper = THEMEPATH . "$theme_name/helpers/{$theme_name}.php"; + if (file_exists($theme_helper)) { + require_once($theme_helper); + + if (method_exists($theme_name, "get_admin_form")) { + $info = theme::get_info($theme_name); + $menu->get("appearance_menu") + ->add_after("themes", Menu::factory("link") + ->id("theme_options") + ->label(t("%name options", array("name" => $info->name))) + ->url(url::site("admin/theme_options"))); + } + } return $menu; } diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 57a5ee9f..4051c6e9 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -226,9 +226,9 @@ class gallery_installer { module::set_var("gallery", "active_site_theme", "wind"); module::set_var("gallery", "active_admin_theme", "admin_wind"); - module::set_var("gallery", "page_size", 9); - module::set_var("gallery", "thumb_size", 200); - module::set_var("gallery", "resize_size", 640); + module::set_var("wind", "page_size", 9); + module::set_var("wind", "thumb_size", 200); + module::set_var("wind", "resize_size", 640); module::set_var("gallery", "default_locale", "en_US"); module::set_var("gallery", "image_quality", 75); module::set_var("gallery", "image_sharpen", 15); @@ -265,10 +265,10 @@ class gallery_installer { module::set_var("gallery", "date_format", "Y-M-d"); module::set_var("gallery", "date_time_format", "Y-M-d H:i:s"); module::set_var("gallery", "time_format", "H:i:s"); - module::set_var("gallery", "show_credits", 1); + module::set_var("wind", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>"); - module::set_version("gallery", 19); + module::set_version("gallery", 20); } static function upgrade($version) { @@ -432,6 +432,17 @@ class gallery_installer { module::clear_var("gallery", "blocks_site.sidebar"); module::set_version("gallery", $version = 19); } + + // Move the theme related variables into the current theme + if ($version == 19) { + foreach (array("page_size", "thumb_size", "resize_size", "header_text", + "footer_text", "show_credits") as $var) { + $value = module::get_var("gallery", $var); + theme::set_var($var, $value); + module::clear_var("gallery", $var); + } + module::set_version("gallery", $version = 20); + } } static function uninstall() { diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 5a3a328a..c7b773d1 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -24,48 +24,66 @@ * Note: by design, this class does not do any permission checking. */ class theme_Core { + public static $site; + public static $admin; + /** * Load the active theme. This is called at bootstrap time. We will only ever have one theme * active for any given request. */ static function load_themes() { - $path = Input::instance()->server("PATH_INFO"); $input = Input::instance(); + $path = $input->server("PATH_INFO"); if (empty($path)) { $path = "/" . $input->get("kohana_uri"); } + self::$site = module::get_var("gallery", "active_site_theme"); + self::$admin = module::get_var("gallery", "active_admin_theme"); 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"); + $theme_name = $path == "/admin" || !strncmp($path, "/admin/", 7) ? self::$admin : self::$site; } $modules = Kohana::config("core.modules"); array_unshift($modules, THEMEPATH . $theme_name); Kohana::config_set("core.modules", $modules); } - static function get_edit_form_admin() { - $form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form")); - $group = $form->group("edit_theme"); - $group->input("page_size")->label(t("Items per page"))->id("g-page-size") - ->rules("required|valid_digit") - ->value(module::get_var("gallery", "page_size")); - $group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("g-thumb-size") - ->rules("required|valid_digit") - ->value(module::get_var("gallery", "thumb_size")); - $group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("g-resize-size") - ->rules("required|valid_digit") - ->value(module::get_var("gallery", "resize_size")); - $group->textarea("header_text")->label(t("Header text"))->id("g-header-text") - ->value(module::get_var("gallery", "header_text")); - $group->textarea("footer_text")->label(t("Footer text"))->id("g-footer-text") - ->value(module::get_var("gallery", "footer_text")); - $group->checkbox("show_credits")->label(t("Show site credits"))->id("g-footer-text") - ->checked(module::get_var("gallery", "show_credits")); - $group->submit("")->value(t("Save")); - return $form; + static function get_info($theme_name) { + $theme_name = preg_replace("/[^\w]/", "", $theme_name); + $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); + + return $theme_info; + } + + /** + * Get a variable from the active theme + * @param string $name + * @param string $default_value + * @return the value + */ + static function get_var($name, $default_value=null) { + return module::get_var(self::$site, $name, $default_value); } -} + /** + * Store a variable for active theme + * @param string $module_name + * @param string $name + * @param string $value + */ + static function set_var($name, $value) { + module::set_var(self::$site, $name, $value); + } + + /** + * Remove a variable for this module. + * @param string $module_name + * @param string $name + */ + static function clear_var($name) { + module::clear_var(self::$site, $name); + } +} diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index b1167d0e..87d8de56 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -65,7 +65,7 @@ class Theme_View_Core extends Gallery_View { public function thumb_proportion() { // @TODO change the 200 to a theme supplied value when and if we come up with an // API to allow the theme to set defaults. - return module::get_var("gallery", "thumb_size", 200) / 200; + return theme::get_var("thumb_size", 200) / 200; } public function item() { diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 2dc62ecd..ecce9118 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 19 +version = 20 diff --git a/modules/gallery/views/admin_theme_options.html.php b/modules/gallery/views/admin_theme_options.html.php index a4bf1c4e..9f28e055 100644 --- a/modules/gallery/views/admin_theme_options.html.php +++ b/modules/gallery/views/admin_theme_options.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <div class="g-block"> - <h1> <?= t("Theme Options") ?> </h1> + <h1> <?= t($title) ?> </h1> <div class="g-block-content"> <?= $form ?> |