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 --- 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 +-- 11 files changed, 25 insertions(+), 69 deletions(-) delete mode 100644 modules/gallery/libraries/MY_Kohana.php (limited to 'modules/gallery') 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); -- cgit v1.2.3