From 94aadf03dadbfa01ba1744df60c97b6f3094ae88 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Wed, 20 Feb 2013 17:30:27 +0100 Subject: #2008 - Add warnings if some active modules are obsolete. - added module::get_obsolete_modules_message function - put message on admin/dashboard - put message on admin/modules - put message on upgrader - updated unit test golden file xss_data --- modules/gallery/helpers/module.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index df258e87..d7429121 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -541,4 +541,34 @@ class module_Core { static function get_version($module_name) { return module::get($module_name)->version; } + + /** + * Check if obsolete modules are active and, if so, return a warning message. + * If none are found, return null. + */ + static function get_obsolete_modules_message() { + // This is the obsolete modules list. Any active module that's on the list + // with version number at or below the one given will be considered obsolete. + // It is hard-coded here, and may be updated with future releases of Gallery. + $obsolete_modules = array("videos" => 4, "noffmpeg" => 1, "videodimensions" => 1, + "digibug" => 2); + + $modules_found = array(); + foreach ($obsolete_modules as $module => $version) { + if (module::is_active($module) && (module::get_version($module) <= $version)) { + $modules_found[] = $module; + } + } + + if ($modules_found) { + // Need this to be on one super-long line or else the localization scanner may not work. + // (ref: http://sourceforge.net/apps/trac/gallery/ticket/1321) + return t("Recent upgrades to Gallery have made the following modules obsolete: %modules. We recommend that you deactivate the module(s). For more information, please see the documentation page.", + array("modules" => implode(", ", $modules_found), + "url_mod" => url::site("admin/modules"), + "url_doc" => "http://codex.galleryproject.org/Gallery3:User_guide:Obsolete_modules")); + } + + return null; + } } -- cgit v1.2.3 From 9b9f1a7b07daecf2251770e4f49838f22cb58a2a Mon Sep 17 00:00:00 2001 From: shadlaws Date: Sat, 2 Mar 2013 13:25:10 +0100 Subject: #2031 - Add class_exists() before method_exists() if class existence is unknown. - fixed all instances of this in core code - deleted previous Zend Guard Loader workaround in MY_Kohana.php - updated Bootstrap.php to reflect deleted MY_Kohana.php --- application/Bootstrap.php | 2 +- modules/gallery/controllers/admin.php | 2 +- modules/gallery/helpers/block_manager.php | 10 +++--- modules/gallery/helpers/module.php | 18 +++++------ modules/gallery/helpers/task.php | 2 +- modules/gallery/libraries/Admin_View.php | 2 +- modules/gallery/libraries/IdentityProvider.php | 3 +- modules/gallery/libraries/MY_Kohana.php | 45 -------------------------- modules/gallery/libraries/SafeString.php | 2 +- modules/gallery/libraries/Theme_View.php | 4 +-- modules/gallery/tests/Html_Helper_Test.php | 2 +- modules/gallery/tests/SafeString_Test.php | 4 +-- modules/rest/controllers/rest.php | 2 +- modules/rest/helpers/rest.php | 6 ++-- modules/rss/controllers/rss.php | 2 +- modules/rss/helpers/rss_block.php | 2 +- 16 files changed, 32 insertions(+), 76 deletions(-) delete mode 100644 modules/gallery/libraries/MY_Kohana.php (limited to 'modules/gallery/helpers/module.php') diff --git a/application/Bootstrap.php b/application/Bootstrap.php index a79ccba4..93353b47 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -35,7 +35,7 @@ require SYSPATH.'core/Event'.EXT; final class Event extends Event_Core {} require SYSPATH.'core/Kohana'.EXT; -require MODPATH.'gallery/libraries/MY_Kohana'.EXT; +final class Kohana extends Kohana_Core {} require SYSPATH.'core/Kohana_Exception'.EXT; require MODPATH.'gallery/libraries/MY_Kohana_Exception'.EXT; diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index c9d944cc..b35a9299 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -55,7 +55,7 @@ class Admin_Controller extends Controller { $method = "index"; } - if (!method_exists($controller_name, $method)) { + if (!class_exists($controller_name) || !method_exists($controller_name, $method)) { throw new Kohana_404_Exception(); } diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php index bd6ca1c8..a2279468 100644 --- a/modules/gallery/helpers/block_manager.php +++ b/modules/gallery/helpers/block_manager.php @@ -35,7 +35,7 @@ class block_manager_Core { static function activate_blocks($module_name) { $block_class = "{$module_name}_block"; - if (method_exists($block_class, "get_site_list")) { + if (class_exists($block_class) && method_exists($block_class, "get_site_list")) { $blocks = call_user_func(array($block_class, "get_site_list")); foreach (array_keys($blocks) as $block_id) { block_manager::add("site_sidebar", $module_name, $block_id); @@ -61,14 +61,14 @@ class block_manager_Core { static function deactivate_blocks($module_name) { $block_class = "{$module_name}_block"; - if (method_exists($block_class, "get_site_list")) { + if (class_exists($block_class) && method_exists($block_class, "get_site_list")) { $blocks = call_user_func(array($block_class, "get_site_list")); foreach (array_keys($blocks) as $block_id) { block_manager::remove_blocks_for_module("site_sidebar", $module_name); } } - if (method_exists($block_class, "get_admin_list")) { + if (class_exists($block_class) && method_exists($block_class, "get_admin_list")) { $blocks = call_user_func(array($block_class, "get_admin_list")); foreach (array("dashboard_sidebar", "dashboard_center") as $location) { block_manager::remove_blocks_for_module($location, $module_name); @@ -89,7 +89,7 @@ class block_manager_Core { foreach (module::active() as $module) { $class_name = "{$module->name}_block"; - if (method_exists($class_name, $function)) { + if (class_exists($class_name) && method_exists($class_name, $function)) { foreach (call_user_func(array($class_name, $function)) as $id => $title) { $blocks["{$module->name}:$id"] = $title; } @@ -102,7 +102,7 @@ class block_manager_Core { $active = block_manager::get_active($location); $result = ""; foreach ($active as $id => $desc) { - if (method_exists("$desc[0]_block", "get")) { + if (class_exists("$desc[0]_block") && method_exists("$desc[0]_block", "get")) { $block = call_user_func(array("$desc[0]_block", "get"), $desc[1], $theme); if (!empty($block)) { $block->id = $id; diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index d7429121..da201d20 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -141,7 +141,7 @@ class module_Core { $messages = array(); $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "can_activate")) { + if (class_exists($installer_class) && method_exists($installer_class, "can_activate")) { $messages = call_user_func(array($installer_class, "can_activate")); } @@ -173,7 +173,7 @@ class module_Core { module::_add_to_path($module_name); $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "install")) { + if (class_exists($installer_class) && method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); } module::set_version($module_name, module::available()->$module_name->code_version); @@ -226,7 +226,7 @@ class module_Core { $version_before = module::get_version($module_name); $installer_class = "{$module_name}_installer"; $available = module::available(); - if (method_exists($installer_class, "upgrade")) { + if (class_exists($installer_class) && method_exists($installer_class, "upgrade")) { call_user_func_array(array($installer_class, "upgrade"), array($version_before)); } else { if (isset($available->$module_name->code_version)) { @@ -261,7 +261,7 @@ class module_Core { module::_add_to_path($module_name); $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "activate")) { + if (class_exists($installer_class) && method_exists($installer_class, "activate")) { call_user_func_array(array($installer_class, "activate"), array()); } @@ -288,7 +288,7 @@ class module_Core { */ static function deactivate($module_name) { $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "deactivate")) { + if (class_exists($installer_class) && method_exists($installer_class, "deactivate")) { call_user_func_array(array($installer_class, "deactivate"), array()); } @@ -314,7 +314,7 @@ class module_Core { */ static function uninstall($module_name) { $installer_class = "{$module_name}_installer"; - if (method_exists($installer_class, "uninstall")) { + if (class_exists($installer_class) && method_exists($installer_class, "uninstall")) { call_user_func(array($installer_class, "uninstall")); } @@ -403,7 +403,7 @@ class module_Core { continue; } $class = "{$module->name}_event"; - if (method_exists($class, $function)) { + if (class_exists($class) && method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); } } @@ -411,7 +411,7 @@ class module_Core { // Give the admin theme a chance to respond, if we're in admin mode. if (theme::$is_admin) { $class = theme::$admin_theme_name . "_event"; - if (method_exists($class, $function)) { + if (class_exists($class) && method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); } } @@ -419,7 +419,7 @@ class module_Core { // Give the site theme a chance to respond as well. It gets a chance even in admin mode, as // long as the theme has an admin subdir. $class = theme::$site_theme_name . "_event"; - if (method_exists($class, $function)) { + if (class_exists($class) && method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); } } diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index 32fd9739..5638faf4 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -25,7 +25,7 @@ class task_Core { $tasks = array(); foreach (module::active() as $module) { $class_name = "{$module->name}_task"; - if (method_exists($class_name, "available_tasks")) { + if (class_exists($class_name) && method_exists($class_name, "available_tasks")) { foreach (call_user_func(array($class_name, "available_tasks")) as $task) { $tasks[$task->callback] = $task; } diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 83163868..62645d18 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -95,7 +95,7 @@ class Admin_View_Core extends Gallery_View { $blocks = array(); foreach (module::active() as $module) { $helper_class = "{$module->name}_theme"; - if (method_exists($helper_class, $function)) { + if (class_exists($helper_class) && method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( array($helper_class, $function), array_merge(array($this), $args)); diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index 23368a6a..525e1695 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -81,7 +81,8 @@ class IdentityProvider_Core { module::set_var("gallery", "identity_provider", $new_provider); - if (method_exists("{$new_provider}_installer", "initialize")) { + if (class_exists("{$new_provider}_installer") && + method_exists("{$new_provider}_installer", "initialize")) { call_user_func("{$new_provider}_installer::initialize"); } diff --git a/modules/gallery/libraries/MY_Kohana.php b/modules/gallery/libraries/MY_Kohana.php deleted file mode 100644 index d344c8ed..00000000 --- a/modules/gallery/libraries/MY_Kohana.php +++ /dev/null @@ -1,45 +0,0 @@ -= 3)) { - // Load a dummy class instead. - eval("class $class {}"); - } - - // Return the same result. - return $found; - } -} \ No newline at end of file diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php index 31e9d31b..179cbd41 100644 --- a/modules/gallery/libraries/SafeString.php +++ b/modules/gallery/libraries/SafeString.php @@ -153,7 +153,7 @@ class SafeString_Core { * Purify the string, removing any potentially malicious or unsafe HTML / JavaScript. */ private static function _purify_for_html($dirty_html) { - if (method_exists("purifier", "purify")) { + if (class_exists("purifier") && method_exists("purifier", "purify")) { return purifier::purify($dirty_html); } else { return self::_escape_for_html($dirty_html); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 986fc8a2..0a4c96e1 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -239,7 +239,7 @@ class Theme_View_Core extends Gallery_View { continue; } $helper_class = "{$module->name}_theme"; - if (method_exists($helper_class, $function)) { + if (class_exists($helper_class) && method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( array($helper_class, $function), array_merge(array($this), $args)); @@ -247,7 +247,7 @@ class Theme_View_Core extends Gallery_View { } $helper_class = theme::$site_theme_name . "_theme"; - if (method_exists($helper_class, $function)) { + if (class_exists($helper_class) && method_exists($helper_class, $function)) { $blocks[] = call_user_func_array( array($helper_class, $function), array_merge(array($this), $args)); diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php index 476faa5a..4643e6fd 100644 --- a/modules/gallery/tests/Html_Helper_Test.php +++ b/modules/gallery/tests/Html_Helper_Test.php @@ -27,7 +27,7 @@ class Html_Helper_Test extends Gallery_Unit_Test_Case { public function purify_test() { $safe_string = html::purify("hello

world

"); - $expected = method_exists("purifier", "purify") + $expected = (class_exists("purifier") && method_exists("purifier", "purify")) ? "hello

world

" : "hello <p >world</p>"; $this->assert_equal($expected, $safe_string->unescaped()); diff --git a/modules/gallery/tests/SafeString_Test.php b/modules/gallery/tests/SafeString_Test.php index 946410d4..dab7d7df 100644 --- a/modules/gallery/tests/SafeString_Test.php +++ b/modules/gallery/tests/SafeString_Test.php @@ -91,7 +91,7 @@ class SafeString_Test extends Gallery_Unit_Test_Case { public function purify_test() { $safe_string = SafeString::purify("hello

world

"); - $expected = method_exists("purifier", "purify") + $expected = (class_exists("purifier") && method_exists("purifier", "purify")) ? "hello

world

" : "hello <p >world</p>"; $this->assert_equal($expected, $safe_string); @@ -100,7 +100,7 @@ class SafeString_Test extends Gallery_Unit_Test_Case { public function purify_twice_test() { $safe_string = SafeString::purify("hello

world

"); $safe_string_2 = SafeString::purify($safe_string); - $expected = method_exists("purifier", "purify") + $expected = (class_exists("purifier") && method_exists("purifier", "purify")) ? "hello

world

" : "hello <p >world</p>"; $this->assert_equal($expected, $safe_string_2); diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 54ca6fe9..b3d59e0f 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -98,7 +98,7 @@ class Rest_Controller extends Controller { $handler_class = "{$function}_rest"; $handler_method = $request->method; - if (!method_exists($handler_class, $handler_method)) { + if (!class_exists($handler_class) || !method_exists($handler_class, $handler_method)) { throw new Rest_Exception("Bad Request", 400); } diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index 9b367feb..c6be1e1d 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -141,7 +141,7 @@ class rest_Core { } $class = "$components[1]_rest"; - if (!method_exists($class, "resolve")) { + if (!class_exists($class) || !method_exists($class, "resolve")) { throw new Kohana_404_Exception($url); } @@ -158,7 +158,7 @@ class rest_Core { $resource_type = array_shift($args); $class = "{$resource_type}_rest"; - if (!method_exists($class, "url")) { + if (!class_exists($class) || !method_exists($class, "url")) { throw new Rest_Exception("Bad Request", 400); } @@ -178,7 +178,7 @@ class rest_Core { foreach (module::active() as $module) { foreach (glob(MODPATH . "{$module->name}/helpers/*_rest.php") as $filename) { $class = str_replace(".php", "", basename($filename)); - if (method_exists($class, "relationships")) { + if (class_exists($class) && method_exists($class, "relationships")) { if ($tmp = call_user_func(array($class, "relationships"), $resource_type, $resource)) { $results = array_merge($results, $tmp); } diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index 12461325..571995b3 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -32,7 +32,7 @@ class Rss_Controller extends Controller { // Run the appropriate feed callback if (module::is_active($module_id)) { $class_name = "{$module_id}_rss"; - if (method_exists($class_name, "feed")) { + if (class_exists($class_name) && method_exists($class_name, "feed")) { $feed = call_user_func( array($class_name, "feed"), $feed_id, ($page - 1) * $page_size, $page_size, $id); diff --git a/modules/rss/helpers/rss_block.php b/modules/rss/helpers/rss_block.php index 74334e93..9a77b05d 100644 --- a/modules/rss/helpers/rss_block.php +++ b/modules/rss/helpers/rss_block.php @@ -29,7 +29,7 @@ class rss_block_Core { $feeds = array(); foreach (module::active() as $module) { $class_name = "{$module->name}_rss"; - if (method_exists($class_name, "available_feeds")) { + if (class_exists($class_name) && method_exists($class_name, "available_feeds")) { $feeds = array_merge($feeds, call_user_func(array($class_name, "available_feeds"), $theme->item(), $theme->tag())); } -- cgit v1.2.3 From 4b28478776071bf764545de767b70939484519aa Mon Sep 17 00:00:00 2001 From: shadlaws Date: Tue, 5 Mar 2013 16:54:41 +0100 Subject: #2040 - Deactivate modules that no longer exist. - added module::deactivate_missing_modules() - revised module::deactivate() to change log message if the module is missing - added call to new function in module::get_obsolete_modules_message() - added call to new function when loading admin/maintenance menu --- modules/gallery/controllers/admin_maintenance.php | 1 + modules/gallery/helpers/module.php | 24 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers/module.php') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 23df33ee..32f20784 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -55,6 +55,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { ->where("expiration", "<>", 0) ->where("expiration", "<=", time()) ->execute(); + module::deactivate_missing_modules(); } /** diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index da201d20..1b6c8d1a 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -303,8 +303,25 @@ class module_Core { block_manager::deactivate_blocks($module_name); - log::success( - "module", t("Deactivated module %module_name", array("module_name" => $module_name))); + if (module::info($module_name)) { + log::success( + "module", t("Deactivated module %module_name", array("module_name" => $module_name))); + } else { + log::success( + "module", t("Deactivated missing module %module_name", array("module_name" => $module_name))); + } + } + + /** + * Deactivate modules that are unavailable or missing, yet still active. + * This happens when a user deletes a module without deactivating it. + */ + static function deactivate_missing_modules() { + foreach (self::$modules as $module_name => $module) { + if (module::is_active($module_name) && !module::info($module_name)) { + module::deactivate($module_name); + } + } } /** @@ -553,6 +570,9 @@ class module_Core { $obsolete_modules = array("videos" => 4, "noffmpeg" => 1, "videodimensions" => 1, "digibug" => 2); + // Before we check the active modules, deactivate any that are missing. + module::deactivate_missing_modules(); + $modules_found = array(); foreach ($obsolete_modules as $module => $version) { if (module::is_active($module) && (module::get_version($module) <= $version)) { -- cgit v1.2.3