diff --git a/classes/db/queryparts/Query.class.php b/classes/db/queryparts/Query.class.php index 405f17f3d..46190f32a 100644 --- a/classes/db/queryparts/Query.class.php +++ b/classes/db/queryparts/Query.class.php @@ -560,7 +560,7 @@ class Query extends BaseObject { if(!$this->_orderByString) { - if(count($this->orderby) === 0) + if(countobj($this->orderby) === 0) { return ''; } @@ -587,7 +587,7 @@ class Query extends BaseObject function getLimitString() { $limit = ''; - if(count($this->limit) > 0) + if(countobj($this->limit) > 0) { $limit = ''; $limit .= $this->limit->toString(); @@ -611,7 +611,7 @@ class Query extends BaseObject $this->arguments = array(); // Join table arguments - if(count($this->tables) > 0) + if(countobj($this->tables) > 0) { foreach($this->tables as $table) { @@ -628,7 +628,7 @@ class Query extends BaseObject // Column arguments // The if is for delete statements, all others must have columns - if(count($this->columns) > 0) + if(countobj($this->columns) > 0) { foreach($this->columns as $column) { @@ -644,12 +644,12 @@ class Query extends BaseObject } // Condition arguments - if(count($this->conditions) > 0) + if(countobj($this->conditions) > 0) { foreach($this->conditions as $conditionGroup) { $args = $conditionGroup->getArguments(); - if(count($args) > 0) + if(countobj($args) > 0) { $this->arguments = array_merge($this->arguments, $args); } @@ -657,12 +657,12 @@ class Query extends BaseObject } // Navigation arguments - if(count($this->orderby) > 0) + if(countobj($this->orderby) > 0) { foreach($this->orderby as $order) { $args = $order->getArguments(); - if(count($args) > 0) + if(countobj($args) > 0) { $this->arguments = array_merge($this->arguments, $args); } diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index 182cd5e9d..473f5e4e7 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -858,7 +858,7 @@ class ModuleHandler extends Handler { Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']); } - if(count($_SESSION['INPUT_ERROR'])) + if(countobj($_SESSION['INPUT_ERROR'])) { Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']); } diff --git a/common/autoload.php b/common/autoload.php index f79821c39..02b04292c 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -41,6 +41,7 @@ if (function_exists('mb_regex_encoding')) require_once __DIR__ . '/constants.php'; require_once __DIR__ . '/functions.php'; require_once __DIR__ . '/legacy.php'; +require_once RX_BASEDIR . 'classes/object/Object.class.php'; /** * Load user configuration. @@ -98,8 +99,6 @@ $GLOBALS['RX_AUTOLOAD_FILE_MAP'] = array_change_key_case(array( 'Mobile' => 'classes/mobile/Mobile.class.php', 'ModuleHandler' => 'classes/module/ModuleHandler.class.php', 'ModuleObject' => 'classes/module/ModuleObject.class.php', - 'BaseObject' => 'classes/object/Object.class.php', - 'Object' => 'classes/object/Object.class.php', 'PageHandler' => 'classes/page/PageHandler.class.php', 'EmbedFilter' => 'classes/security/EmbedFilter.class.php', 'IpFilter' => 'classes/security/IpFilter.class.php', @@ -193,7 +192,7 @@ spl_autoload_register(function($class_name) /** * Also include the Composer autoloader. */ -require_once RX_BASEDIR . 'vendor/autoload.php'; +require_once RX_BASEDIR . 'vendor/autoload.php'; /** * Load system configuration. diff --git a/common/functions.php b/common/functions.php index 148c6b25f..078c280e5 100644 --- a/common/functions.php +++ b/common/functions.php @@ -517,6 +517,28 @@ function tobool($input) return (bool)$input; } +/** + * Counts members of an array or an object. + * + * @param mixed $array_or_object + * @return int + */ +function countobj($array_or_object) +{ + if (is_array($array_or_object)) + { + return count($array_or_object); + } + elseif (is_object($array_or_object)) + { + return count(get_object_vars($array_or_object)); + } + else + { + return @count($array_or_object); + } +} + /** * Checks if the given string contains valid UTF-8. * diff --git a/modules/module/module.model.php b/modules/module/module.model.php index 57fb56da5..849b89ba2 100644 --- a/modules/module/module.model.php +++ b/modules/module/module.model.php @@ -467,7 +467,7 @@ class moduleModel extends module foreach($target_module_info as $key => $val) { - if(!$extra_vars[$val->module_srl] || !count($extra_vars[$val->module_srl])) continue; + if(!$extra_vars[$val->module_srl] || !count(get_object_vars($extra_vars[$val->module_srl]))) continue; foreach($extra_vars[$val->module_srl] as $k => $v) { if($target_module_info[$key]->{$k}) continue; @@ -1828,10 +1828,9 @@ class moduleModel extends module $args = new stdClass(); $args->module_srl = implode(',', $get_module_srls); $output = executeQueryArray('module.getModuleExtraVars', $args); - if(!$output->toBool()) { - return; + return array(); } if(!$output->data) diff --git a/modules/widget/widget.controller.php b/modules/widget/widget.controller.php index c86f669ff..4bb253a4f 100644 --- a/modules/widget/widget.controller.php +++ b/modules/widget/widget.controller.php @@ -707,7 +707,7 @@ class widgetController extends widget $widgetstyle_extra_var = new stdClass(); $widgetstyle_extra_var_key = get_object_vars($widgetstyle_info); - if(count($widgetstyle_extra_var_key['extra_var'])) + if(countobj($widgetstyle_extra_var_key['extra_var'])) { foreach($widgetstyle_extra_var_key['extra_var'] as $key => $val) { diff --git a/tests/unit/functions/FunctionsTest.php b/tests/unit/functions/FunctionsTest.php index 53dff0391..d2ee628c0 100644 --- a/tests/unit/functions/FunctionsTest.php +++ b/tests/unit/functions/FunctionsTest.php @@ -149,6 +149,13 @@ class FunctionsTest extends \Codeception\TestCase\Test $this->assertFalse(tobool(array())); } + public function testCountObj() + { + $this->assertEquals(3, countobj(array('foo' => 1, 'bar' => 2, 'baz' => 3))); + $this->assertEquals(3, countobj((object)array('foo' => 1, 'bar' => 2, 'baz' => 3))); + $this->assertEquals(1, countobj('foobar')); + } + public function testUTF8Functions() { $this->assertTrue(utf8_check('Hello, world!'));