summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-11-18 14:37:49 -0800
committerTim Almdal <tnalmdal@shaw.ca>2009-11-18 14:37:49 -0800
commit1692ee130887a6ad1ba68aa34a96ad36161600f9 (patch)
tree2901fee570d5ee8aa6a0ada01c1d92980be11e03
parent372f589f66436c5b5bb8ed8a98532842c1e01a71 (diff)
Currently Admin_Theme_Options controller assumes that all the themes will provide the same values. This change corrects that assumption and moves the management of the theme options, including creating the form and updating the theme options into the theme.
-rw-r--r--modules/gallery/controllers/admin_theme_options.php52
-rw-r--r--modules/gallery/helpers/gallery_event.php21
-rw-r--r--modules/gallery/helpers/theme.php33
-rw-r--r--modules/gallery/views/admin_theme_options.html.php2
-rw-r--r--themes/wind/helpers/wind.php73
5 files changed, 120 insertions, 61 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/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/theme.php b/modules/gallery/helpers/theme.php
index 16ed104e..6e8943b3 100644
--- a/modules/gallery/helpers/theme.php
+++ b/modules/gallery/helpers/theme.php
@@ -24,6 +24,9 @@
* 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.
@@ -35,39 +38,16 @@ class theme_Core {
$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";
@@ -78,4 +58,3 @@ class theme_Core {
return $theme_info;
}
}
-
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 ?>
diff --git a/themes/wind/helpers/wind.php b/themes/wind/helpers/wind.php
new file mode 100644
index 00000000..deb778d2
--- /dev/null
+++ b/themes/wind/helpers/wind.php
@@ -0,0 +1,73 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 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 wind {
+ static function get_admin_form($action) {
+ $form = new Forge($action, "", null, array("id" =>"g-wind-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 update_options($form) {
+ module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);
+
+ $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);
+ }
+
+ $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);
+ }
+
+ 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);
+ }
+}