From a481a684b6c0fcfbf624e91f7e4bb483d1e6a45a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 30 Dec 2008 04:14:57 +0000 Subject: Add a "Graphics Settings" page that lets admins choose which graphics toolkit we use. We only allow users to use one toolkit. The UI needs work! --- core/controllers/admin_graphics.php | 48 +++++++++++++++++++ core/helpers/core_installer.php | 25 +++++++++- core/helpers/core_menu.php | 9 ++-- core/helpers/graphics.php | 48 +++++++++++++++++++ core/libraries/Admin_View.php | 2 +- core/views/admin_graphics.html.php | 92 +++++++++++++++++++++++++++++++++++++ 6 files changed, 219 insertions(+), 5 deletions(-) create mode 100644 core/controllers/admin_graphics.php create mode 100644 core/views/admin_graphics.html.php (limited to 'core') diff --git a/core/controllers/admin_graphics.php b/core/controllers/admin_graphics.php new file mode 100644 index 00000000..e6e42672 --- /dev/null +++ b/core/controllers/admin_graphics.php @@ -0,0 +1,48 @@ +content = new View("admin_graphics.html"); + $view->content->tk = new ArrayObject(graphics::detect_toolkits(), ArrayObject::ARRAY_AS_PROPS); + $view->content->active = module::get_var("core", "graphics_toolkit"); + print $view; + } + + public function save() { + access::verify_csrf(); + $toolkit = $this->input->post("graphics_toolkit"); + if ($toolkit != module::get_var("core", "graphics_toolkit")) { + module::set_var("core", "graphics_toolkit", $toolkit); + + $toolkit_info = graphics::detect_toolkits(); + if ($toolkit == "graphicsmagick" || $toolkit == "imagemagick") { + module::set_var("core", "graphics_toolkit_path", $toolkit_info[$toolkit]); + } + + site_status::clear("missing_graphics_toolkit"); + message::success(_("Updated Graphics Toolkit")); + log::success("graphics", sprintf(_("Changed graphics toolkit to %s"), $toolkit)); + } + + url::redirect("admin/graphics"); + } +} + diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index d1904181..e720bfb3 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -185,6 +185,24 @@ class core_installer { array("width" => 640, "height" => 480, "master" => Image::AUTO), 100); + // Detect a graphics toolkit + $toolkits = graphics::detect_toolkits(); + foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) { + if ($toolkits[$tk]) { + module::set_var("core", "graphics_toolkit", $tk); + if ($tk != "gd") { + module::set_var("core", "graphics_toolkit_path", $toolkits[$tk]); + } + break; + } + } + if (!module::get_var("core", "graphics_toolkit")) { + site_status::warning( + sprintf(_("Graphics toolkit missing! Please %schoose a toolkit%s."), + "", ""), + "missing_graphics_toolkit"); + } + module::set_version("core", 1); } } @@ -193,9 +211,14 @@ class core_installer { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS `access_caches`;"); $db->query("DROP TABLE IF EXISTS `access_intents`;"); - $db->query("DROP TABLE IF EXISTS `permissions`;"); + $db->query("DROP TABLE IF EXISTS `graphics_rules`;"); $db->query("DROP TABLE IF EXISTS `items`;"); + $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 `permissions`;"); + $db->query("DROP TABLE IF EXISTS `sessions`;"); + $db->query("DROP TABLE IF EXISTS `tasks`;"); $db->query("DROP TABLE IF EXISTS `vars`;"); system("/bin/rm -rf " . VARPATH . "albums"); system("/bin/rm -rf " . VARPATH . "resizes"); diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index d6f7bc56..68d6c7d9 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -73,10 +73,13 @@ class core_menu_Core { ->id("dashboard") ->label(_("Dashboard")) ->url(url::site("admin"))) - ->append(Menu::factory("link") - ->id("general_settings") + ->append(Menu::factory("submenu") + ->id("general_settings_menu") ->label(_("General Settings")) - ->url("#")) + ->append(Menu::factory("link") + ->id("graphics_toolkits") + ->label(_("Graphics")) + ->url(url::site("admin/graphics")))) ->append(Menu::factory("link") ->id("modules") ->label(_("Modules")) diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index e64a9c6d..85f86863 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class graphics_Core { + private static $init; + /** * Add a new graphics rule. * @@ -126,6 +128,10 @@ class graphics_Core { * @param array $options */ public static function resize($input_file, $output_file, $options) { + if (!self::$init) { + self::init_toolkit(); + } + Image::factory($input_file) ->resize($options["width"], $options["height"], $options["master"]) ->save($output_file); @@ -141,6 +147,10 @@ class graphics_Core { * @param array $options */ public static function composite($input_file, $output_file, $options) { + if (!self::$init) { + self::init_toolkit(); + } + list ($width, $height) = getimagesize($input_file); list ($w_width, $w_height) = getimagesize($options["file"]); @@ -240,4 +250,42 @@ class graphics_Core { site_status::clear("graphics_dirty"); } } + + /** + * Detect which graphics toolkits are available on this system. Return an array of key value + * pairs where the key is one of gd, imagemagick, graphicsmagick and the value is information + * about that toolkit. For GD we return the version string, and for ImageMagick and + * GraphicsMagick we return the path to the directory containing the appropriate binaries. + */ + public static function detect_toolkits() { + $gd_info = gd_info(); + return array("gd" => $gd_info["GD Version"], + "imagemagick" => dirname(exec("which convert")), + "graphicsmagick" => dirname(exec("which gm"))); + } + + /** + * Choose which driver the Kohana Image library uses. + */ + public static function init_toolkit() { + switch(module::get_var("core", "graphics_toolkit")) { + case "gd": + Kohana::config_set("image.driver", "GD"); + break; + + case "imagemagick": + Kohana::config_set("image.driver", "ImageMagick"); + Kohana::config_set( + "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + break; + + case "graphicsmagick": + Kohana::config_set("image.driver", "GraphicsMagick"); + Kohana::config_set( + "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + break; + } + + self::$init = 1; + } } diff --git a/core/libraries/Admin_View.php b/core/libraries/Admin_View.php index 803b8942..332be596 100644 --- a/core/libraries/Admin_View.php +++ b/core/libraries/Admin_View.php @@ -62,7 +62,7 @@ class Admin_View_Core extends View { } /** - * Print out any site wide status information. This is for admins only. + * Print out any site wide status information. */ public function site_status() { return site_status::get(); diff --git a/core/views/admin_graphics.html.php b/core/views/admin_graphics.html.php new file mode 100644 index 00000000..9d1f49a8 --- /dev/null +++ b/core/views/admin_graphics.html.php @@ -0,0 +1,92 @@ + +
+

+

+ +

+ +
"> + +

+ + + + + + + + + + + + + + + +
+
+ gd): ?> disabled="disabled" + checked="checked" + > +
+
+

+

+ ", "") ?> +

+ gd): ?> +

+ gd) ?> +

+ +

+ +

+ +
+
+ imagemagick): ?> disabled="disabled" + checked="checked" + > +
+
+

+

+ ", "") ?> +

+ imagemagick): ?> +

+ imagemagick) ?> +

+ +

+ +

+ +
+
+ graphicsmagick): ?> disabled="disabled" + checked="checked" + > +
+
+

+

+ ", "") ?> +

+ graphicsmagick): ?> +

+ graphicsmagick) ?> +

+ +

+ +

+ +
+ "/> +
+
-- cgit v1.2.3