From 26b0603538eb447ab6832d9233e22ba7cf291b45 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 30 Oct 2010 20:43:14 +0000 Subject: organized functions in elgglib by purpose - more or less git-svn-id: http://code.elgg.org/elgg/trunk@7137 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 831 ++++++++++++++++++++++++------------------------- 1 file changed, 414 insertions(+), 417 deletions(-) diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index ff7886561..1b078fde7 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -99,47 +99,6 @@ function forward($location = "") { return false; } -/** - * Returns the current page's complete URL. - * - * The current URL is assembled using the network's wwwroot and the request URI - * in $_SERVER as populated by the web server. This function will include - * any schemes, usernames and passwords, and ports. - * - * @return string The current page URL. - */ -function current_page_url() { - global $CONFIG; - - $url = parse_url($CONFIG->wwwroot); - - $page = $url['scheme'] . "://"; - - // user/pass - if ((isset($url['user'])) && ($url['user'])) { - $page .= $url['user']; - } - if ((isset($url['pass'])) && ($url['pass'])) { - $page .= ":" . $url['pass']; - } - if ((isset($url['user']) && $url['user']) || - (isset($url['pass']) && $url['pass'])) { - $page .= "@"; - } - - $page .= $url['host']; - - if ((isset($url['port'])) && ($url['port'])) { - $page .= ":" . $url['port']; - } - - $page = trim($page, "/"); - - $page .= $_SERVER['REQUEST_URI']; - - return $page; -} - /** * Returns the HTML for "likes" and "like this" on entities. * @@ -1301,100 +1260,44 @@ function callpath_gatekeeper($path, $include_subdirs = true, $strict_mode = fals } /** - * Return the state of a php.ini setting. - * - * Normalizes the setting to bool. + * Returns the current page's complete URL. * - * @param string $ini_get_arg The INI setting + * The current URL is assembled using the network's wwwroot and the request URI + * in $_SERVER as populated by the web server. This function will include + * any schemes, usernames and passwords, and ports. * - * @return true|false Depending on whether it's on or off + * @return string The current page URL. */ -function ini_get_bool($ini_get_arg) { - $temp = ini_get($ini_get_arg); +function current_page_url() { + global $CONFIG; - if ($temp == '1' or strtolower($temp) == 'on') { - return true; - } - return false; -} + $url = parse_url($CONFIG->wwwroot); -/** - * Returns a PHP INI setting in bytes. - * - * @tip Use this for arithmetic when determining if a file can be uploaded. - * - * @param str $setting The php.ini setting - * - * @return int - * @since 1.7.0 - * @link http://www.php.net/manual/en/function.ini-get.php - */ -function elgg_get_ini_setting_in_bytes($setting) { - // retrieve INI setting - $val = ini_get($setting); + $page = $url['scheme'] . "://"; - // convert INI setting when shorthand notation is used - $last = strtolower($val[strlen($val) - 1]); - switch($last) { - case 'g': - $val *= 1024; - case 'm': - $val *= 1024; - case 'k': - $val *= 1024; + // user/pass + if ((isset($url['user'])) && ($url['user'])) { + $page .= $url['user']; } - - // return byte value - return $val; -} - -/** - * Returns true is string is not empty, false, or null. - * - * Function to be used in array_filter which returns true if $string is not null. - * - * @param string $string The string to test - * - * @return bool - * @todo This is used once in metadata.php. Use a lambda function instead. - */ -function is_not_null($string) { - if (($string === '') || ($string === false) || ($string === null)) { - return false; + if ((isset($url['pass'])) && ($url['pass'])) { + $page .= ":" . $url['pass']; + } + if ((isset($url['user']) && $url['user']) || + (isset($url['pass']) && $url['pass'])) { + $page .= "@"; } - return true; -} - + $page .= $url['host']; -/** - * Normalise the singular keys in an options array to plural keys. - * - * Used in elgg_get_entities*() functions to support shortcutting plural - * names by singular names. - * - * @param array $options The options array. $options['keys'] = 'values'; - * @param array $singulars A list of sinular words to pluralize by adding 's'. - * - * @return array - * @since 1.7.0 - */ -function elgg_normalise_plural_options_array($options, $singulars) { - foreach ($singulars as $singular) { - $plural = $singular . 's'; + if ((isset($url['port'])) && ($url['port'])) { + $page .= ":" . $url['port']; + } - if (array_key_exists($singular, $options)) { - if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { - $options[$plural] = $options[$singular]; - } else { - $options[$plural] = array($options[$singular]); - } - } + $page = trim($page, "/"); - unset($options[$singular]); - } + $page .= $_SERVER['REQUEST_URI']; - return $options; + return $page; } /** @@ -1420,30 +1323,6 @@ function full_url() { str_replace($quotes, $encoded, $_SERVER['REQUEST_URI']); } -/** - * Does nothing. - * - * @deprecated 1.7 - * @return 0 - */ -function test_ip() { - elgg_deprecated_notice('test_ip() was removed because of licensing issues.', 1.7); - - return 0; -} - -/** - * Does nothing. - * - * @return bool - * @deprecated 1.7 - */ -function is_ip_in_array() { - elgg_deprecated_notice('is_ip_in_array() was removed because of licensing issues.', 1.7); - - return false; -} - /** * Builds a URL from the a parts array like one returned by {@link parse_url()}. * @@ -1529,7 +1408,6 @@ function elgg_validate_action_url($url) { return elgg_add_action_tokens_to_url($url); } - /** * Removes an element from a URL's query string. * @@ -1589,79 +1467,177 @@ function elgg_http_add_url_query_elements($url, array $elements) { } /** - * Load all the REQUEST variables into the sticky form cache + * Test if two URLs are functionally identical. * - * Call this from an action when you want all your submitted variables - * available if the submission fails validation and is sent back to the form + * @tip If $ignore_params is used, neither the name nor its value will be considered when comparing. * - * @param string $form_name Name of the sticky form + * @tip The order of GET params doesn't matter. * - * @return void - * @link http://docs.elgg.org/Tutorials/UI/StickyForms + * @param string $url1 First URL + * @param string $url2 Second URL + * @param array $ignore_params GET params to ignore in the comparison + * + * @return BOOL + * @since 1.8 */ -function elgg_make_sticky_form($form_name) { +function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset', 'limit')) { global $CONFIG; - $CONFIG->active_sticky_form = $form_name; - elgg_clear_sticky_form($form_name); + // if the server portion is missing but it starts with / then add the url in. + if (elgg_substr($url1, 0, 1) == '/') { + $url1 = $CONFIG->url . ltrim($url1, '/'); + } - if (!isset($_SESSION['sticky_forms'])) { - $_SESSION['sticky_forms'] = array(); + if (elgg_substr($url1, 0, 1) == '/') { + $url2 = $CONFIG->url . ltrim($url2, '/'); } - $_SESSION['sticky_forms'][$form_name] = array(); - foreach ($_REQUEST as $key => $var) { - // will go through XSS filtering on the get function - $_SESSION['sticky_forms'][$form_name][$key] = $var; + // @todo - should probably do something with relative URLs + + if ($url1 == $url2) { + return TRUE; } -} -/** - * Clear the sticky form cache - * - * Call this if validation is successful in the action handler or - * when they sticky values have been used to repopulate the form - * after a validation error. - * - * @param string $form_name Form namespace - * - * @return void - * @link http://docs.elgg.org/Tutorials/UI/StickyForms - */ -function elgg_clear_sticky_form($form_name) { - unset($_SESSION['sticky_forms'][$form_name]); -} + $url1_info = parse_url($url1); + $url2_info = parse_url($url2); -/** - * Has this form been made sticky? - * - * @param string $form_name Form namespace - * - * @return boolean - * @link http://docs.elgg.org/Tutorials/UI/StickyForms - */ -function elgg_is_sticky_form($form_name) { - return isset($_SESSION['sticky_forms'][$form_name]); -} + $url1_info['path'] = trim($url1_info['path'], '/'); + $url2_info['path'] = trim($url2_info['path'], '/'); -/** - * Get a specific sticky variable - * - * @param string $form_name The name of the form - * @param string $variable The name of the variable - * @param mixed $default Default value if the variable does not exist in sticky cache - * @param boolean $filter_result Filter for bad input if true - * - * @return mixed - * - * @todo should this filter the default value? - * @link http://docs.elgg.org/Tutorials/UI/StickyForms - */ -function elgg_get_sticky_value($form_name, $variable = '', $default = NULL, $filter_result = true) { - if (isset($_SESSION['sticky_forms'][$form_name][$variable])) { - $value = $_SESSION['sticky_forms'][$form_name][$variable]; - if ($filter_result) { - // XSS filter result + // compare basic bits + $parts = array('scheme', 'host', 'path'); + + foreach ($parts as $part) { + if ((isset($url1_info[$part]) && isset($url2_info[$part])) + && $url1_info[$part] != $url2_info[$part]) { + return FALSE; + } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { + return FALSE; + } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { + return FALSE; + } + } + + // quick compare of get params + if (isset($url1_info['query']) && isset($url2_info['query']) + && $url1_info['query'] == $url2_info['query']) { + return TRUE; + } + + // compare get params that might be out of order + $url1_params = array(); + $url2_params = array(); + + if (isset($url1_info['query'])) { + if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { + $url1_params = elgg_parse_str($url1_info['query']); + } + } + + if (isset($url2_info['query'])) { + if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { + $url2_params = elgg_parse_str($url2_info['query']); + } + } + + // drop ignored params + foreach ($ignore_params as $param) { + if (isset($url1_params[$param])) { + unset($url1_params[$param]); + } + if (isset($url2_params[$param])) { + unset($url2_params[$param]); + } + } + + // array_diff_assoc only returns the items in arr1 that aren't in arrN + // but not the items that ARE in arrN but NOT in arr1 + // if arr1 is an empty array, this function will return 0 no matter what. + // since we only care if they're different and not how different, + // add the results together to get a non-zero (ie, different) result + $diff_count = count(array_diff_assoc($url1_params, $url2_params)); + $diff_count += count(array_diff_assoc($url2_params, $url1_params)); + if ($diff_count > 0) { + return FALSE; + } + + return TRUE; +} + +/** + * Load all the REQUEST variables into the sticky form cache + * + * Call this from an action when you want all your submitted variables + * available if the submission fails validation and is sent back to the form + * + * @param string $form_name Name of the sticky form + * + * @return void + * @link http://docs.elgg.org/Tutorials/UI/StickyForms + */ +function elgg_make_sticky_form($form_name) { + global $CONFIG; + + $CONFIG->active_sticky_form = $form_name; + elgg_clear_sticky_form($form_name); + + if (!isset($_SESSION['sticky_forms'])) { + $_SESSION['sticky_forms'] = array(); + } + $_SESSION['sticky_forms'][$form_name] = array(); + + foreach ($_REQUEST as $key => $var) { + // will go through XSS filtering on the get function + $_SESSION['sticky_forms'][$form_name][$key] = $var; + } +} + +/** + * Clear the sticky form cache + * + * Call this if validation is successful in the action handler or + * when they sticky values have been used to repopulate the form + * after a validation error. + * + * @param string $form_name Form namespace + * + * @return void + * @link http://docs.elgg.org/Tutorials/UI/StickyForms + */ +function elgg_clear_sticky_form($form_name) { + unset($_SESSION['sticky_forms'][$form_name]); +} + +/** + * Has this form been made sticky? + * + * @param string $form_name Form namespace + * + * @return boolean + * @link http://docs.elgg.org/Tutorials/UI/StickyForms + */ +function elgg_is_sticky_form($form_name) { + return isset($_SESSION['sticky_forms'][$form_name]); +} + +/** + * Get a specific sticky variable + * + * @param string $form_name The name of the form + * @param string $variable The name of the variable + * @param mixed $default Default value if the variable does not exist in sticky cache + * @param boolean $filter_result Filter for bad input if true + * + * @return mixed + * + * @todo should this filter the default value? + * @link http://docs.elgg.org/Tutorials/UI/StickyForms + */ +function elgg_get_sticky_value($form_name, $variable = '', $default = NULL, $filter_result = true) { + if (isset($_SESSION['sticky_forms'][$form_name][$variable])) { + $value = $_SESSION['sticky_forms'][$form_name][$variable]; + if ($filter_result) { + // XSS filter result $value = filter_tags($value); } return $value; @@ -1697,21 +1673,216 @@ function elgg_get_active_sticky_form() { return FALSE; } - return (elgg_is_sticky_form($form_name)) ? $form_name : FALSE; + return (elgg_is_sticky_form($form_name)) ? $form_name : FALSE; +} + +/** + * Sets the active sticky form. + * + * @param string $form_name The name of the form + * + * @return void + * @link http://docs.elgg.org/Tutorials/UI/StickyForms + */ +function elgg_set_active_sticky_form($form_name) { + global $CONFIG; + + $CONFIG->active_sticky_form = $form_name; +} + +/** + * Checks for $array[$key] and returns its value if it exists, else + * returns $default. + * + * Shorthand for $value = (isset($array['key'])) ? $array['key'] : 'default'; + * + * @param string $key The key to check. + * @param array $array The array to check against. + * @param mixed $default Default value to return if nothing is found. + * + * @return void + * @since 1.8 + */ +function elgg_get_array_value($key, array $array, $default = NULL) { + return (isset($array[$key])) ? $array[$key] : $default; +} + +/** + * Sorts a 3d array by specific element. + * + * @warning Will re-index numeric indexes. + * + * @note This operates the same as the built-in sort functions. + * It sorts the array and returns a bool for success. + * + * Do this: elgg_sort_3d_array_by_value($my_array); + * Not this: $my_array = elgg_sort_3d_array_by_value($my_array); + * + * @param array &$array Array to sort + * @param string $element Element to sort by + * @param int $sort_order PHP sort order + * {@see http://us2.php.net/array_multisort} + * @param int $sort_type PHP sort type + * {@see http://us2.php.net/sort} + * + * @return bool + */ +function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, +$sort_type = SORT_LOCALE_STRING) { + + $sort = array(); + + foreach ($array as $k => $v) { + if (isset($v[$element])) { + $sort[] = strtolower($v[$element]); + } else { + $sort[] = NULL; + } + }; + + return array_multisort($sort, $sort_order, $sort_type, $array); +} + +/** + * Return the state of a php.ini setting. + * + * Normalizes the setting to bool. + * + * @param string $ini_get_arg The INI setting + * + * @return true|false Depending on whether it's on or off + */ +function ini_get_bool($ini_get_arg) { + $temp = ini_get($ini_get_arg); + + if ($temp == '1' or strtolower($temp) == 'on') { + return true; + } + return false; +} + +/** + * Returns a PHP INI setting in bytes. + * + * @tip Use this for arithmetic when determining if a file can be uploaded. + * + * @param str $setting The php.ini setting + * + * @return int + * @since 1.7.0 + * @link http://www.php.net/manual/en/function.ini-get.php + */ +function elgg_get_ini_setting_in_bytes($setting) { + // retrieve INI setting + $val = ini_get($setting); + + // convert INI setting when shorthand notation is used + $last = strtolower($val[strlen($val) - 1]); + switch($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + // return byte value + return $val; +} + +/** + * Returns true is string is not empty, false, or null. + * + * Function to be used in array_filter which returns true if $string is not null. + * + * @param string $string The string to test + * + * @return bool + * @todo This is used once in metadata.php. Use a lambda function instead. + */ +function is_not_null($string) { + if (($string === '') || ($string === false) || ($string === null)) { + return false; + } + + return true; +} + +/** + * Normalise the singular keys in an options array to plural keys. + * + * Used in elgg_get_entities*() functions to support shortcutting plural + * names by singular names. + * + * @param array $options The options array. $options['keys'] = 'values'; + * @param array $singulars A list of sinular words to pluralize by adding 's'. + * + * @return array + * @since 1.7.0 + */ +function elgg_normalise_plural_options_array($options, $singulars) { + foreach ($singulars as $singular) { + $plural = $singular . 's'; + + if (array_key_exists($singular, $options)) { + if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { + $options[$plural] = $options[$singular]; + } else { + $options[$plural] = array($options[$singular]); + } + } + + unset($options[$singular]); + } + + return $options; +} + +/** + * Does nothing. + * + * @deprecated 1.7 + * @return 0 + */ +function test_ip() { + elgg_deprecated_notice('test_ip() was removed because of licensing issues.', 1.7); + + return 0; +} + +/** + * Does nothing. + * + * @return bool + * @deprecated 1.7 + */ +function is_ip_in_array() { + elgg_deprecated_notice('is_ip_in_array() was removed because of licensing issues.', 1.7); + + return false; } /** - * Sets the active sticky form. + * Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped. * - * @param string $form_name The name of the form + * @tip Register for the shutdown:system event to perform functions at the end of page loads. + * + * @warning Using this event to perform long-running functions is not very + * useful. Servers will hold pages until processing is done before sending + * them out to the browser. * * @return void - * @link http://docs.elgg.org/Tutorials/UI/StickyForms + * @see register_shutdown_hook() */ -function elgg_set_active_sticky_form($form_name) { - global $CONFIG; +function _elgg_shutdown_hook() { + global $START_MICROTIME; - $CONFIG->active_sticky_form = $form_name; + trigger_elgg_event('shutdown', 'system'); + + $time = (float)(microtime(TRUE) - $START_MICROTIME); + // demoted to NOTICE from DEBUG so javascript is not corrupted + elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE'); } /** @@ -1742,25 +1913,41 @@ function js_page_handler($page) { } /** - * Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped. + * Intercepts the index page when Walled Garden mode is enabled. * - * @tip Register for the shutdown:system event to perform functions at the end of page loads. + * @link http://docs.elgg.org/Tutorials/WalledGarden + * @elgg_plugin_hook index system + * @return void + */ +function elgg_walled_garden_index() { + $login = elgg_view('account/forms/login_walled_garden'); + + page_draw('', $login, 'page_shells/walled_garden'); + + // @hack Index must exit to keep plugins from continuing to extend + exit; +} + +/** + * Checks the status of the Walled Garden and forwards to a login page + * if required. * - * @warning Using this event to perform long-running functions is not very - * useful. Servers will hold pages until processing is done before sending - * them out to the browser. + * If the site is in Walled Garden mode, all page except those registered as + * plugin pages by {@elgg_hook public_pages walled_garden} will redirect to + * a login page. * + * @since 1.8 + * @elgg_event_handler init system + * @link http://docs.elgg.org/Tutorials/WalledGarden * @return void - * @see register_shutdown_hook() */ -function _elgg_shutdown_hook() { - global $START_MICROTIME; - - trigger_elgg_event('shutdown', 'system'); +function elgg_walled_garden() { + global $CONFIG; - $time = (float)(microtime(TRUE) - $START_MICROTIME); - // demoted to NOTICE from DEBUG so javascript is not corrupted - elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE'); + // check for external page view + if (isset($CONFIG->site) && $CONFIG->site instanceof ElggSite) { + $CONFIG->site->checkWalledGarden(); + } } /** @@ -1796,22 +1983,6 @@ function elgg_init() { } } -/** - * Intercepts the index page when Walled Garden mode is enabled. - * - * @link http://docs.elgg.org/Tutorials/WalledGarden - * @elgg_plugin_hook index system - * @return void - */ -function elgg_walled_garden_index() { - $login = elgg_view('account/forms/login_walled_garden'); - - page_draw('', $login, 'page_shells/walled_garden'); - - // @hack Index must exit to keep plugins from continuing to extend - exit; -} - /** * Adds unit tests for the general API. * @@ -1831,180 +2002,6 @@ function elgg_api_test($hook, $type, $value, $params) { return $value; } -/** - * Test if two URLs are functionally identical. - * - * @tip If $ignore_params is used, neither the name nor its value will be considered when comparing. - * - * @tip The order of GET params doesn't matter. - * - * @param string $url1 First URL - * @param string $url2 Second URL - * @param array $ignore_params GET params to ignore in the comparison - * - * @return BOOL - * @since 1.8 - */ -function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset', 'limit')) { - global $CONFIG; - - // if the server portion is missing but it starts with / then add the url in. - if (elgg_substr($url1, 0, 1) == '/') { - $url1 = $CONFIG->url . ltrim($url1, '/'); - } - - if (elgg_substr($url1, 0, 1) == '/') { - $url2 = $CONFIG->url . ltrim($url2, '/'); - } - - // @todo - should probably do something with relative URLs - - if ($url1 == $url2) { - return TRUE; - } - - $url1_info = parse_url($url1); - $url2_info = parse_url($url2); - - $url1_info['path'] = trim($url1_info['path'], '/'); - $url2_info['path'] = trim($url2_info['path'], '/'); - - // compare basic bits - $parts = array('scheme', 'host', 'path'); - - foreach ($parts as $part) { - if ((isset($url1_info[$part]) && isset($url2_info[$part])) - && $url1_info[$part] != $url2_info[$part]) { - return FALSE; - } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { - return FALSE; - } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { - return FALSE; - } - } - - // quick compare of get params - if (isset($url1_info['query']) && isset($url2_info['query']) - && $url1_info['query'] == $url2_info['query']) { - return TRUE; - } - - // compare get params that might be out of order - $url1_params = array(); - $url2_params = array(); - - if (isset($url1_info['query'])) { - if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { - $url1_params = elgg_parse_str($url1_info['query']); - } - } - - if (isset($url2_info['query'])) { - if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { - $url2_params = elgg_parse_str($url2_info['query']); - } - } - - // drop ignored params - foreach ($ignore_params as $param) { - if (isset($url1_params[$param])) { - unset($url1_params[$param]); - } - if (isset($url2_params[$param])) { - unset($url2_params[$param]); - } - } - - // array_diff_assoc only returns the items in arr1 that aren't in arrN - // but not the items that ARE in arrN but NOT in arr1 - // if arr1 is an empty array, this function will return 0 no matter what. - // since we only care if they're different and not how different, - // add the results together to get a non-zero (ie, different) result - $diff_count = count(array_diff_assoc($url1_params, $url2_params)); - $diff_count += count(array_diff_assoc($url2_params, $url1_params)); - if ($diff_count > 0) { - return FALSE; - } - - return TRUE; -} - -/** - * Checks the status of the Walled Garden and forwards to a login page - * if required. - * - * If the site is in Walled Garden mode, all page except those registered as - * plugin pages by {@elgg_hook public_pages walled_garden} will redirect to - * a login page. - * - * @since 1.8 - * @elgg_event_handler init system - * @link http://docs.elgg.org/Tutorials/WalledGarden - * @return void - */ -function elgg_walled_garden() { - global $CONFIG; - - // check for external page view - if (isset($CONFIG->site) && $CONFIG->site instanceof ElggSite) { - $CONFIG->site->checkWalledGarden(); - } -} - -/** - * Checks for $array[$key] and returns its value if it exists, else - * returns $default. - * - * Shorthand for $value = (isset($array['key'])) ? $array['key'] : 'default'; - * - * @param string $key The key to check. - * @param array $array The array to check against. - * @param mixed $default Default value to return if nothing is found. - * - * @return void - * @since 1.8 - */ -function elgg_get_array_value($key, array $array, $default = NULL) { - return (isset($array[$key])) ? $array[$key] : $default; -} - -/** - * Sorts a 3d array by specific element. - * - * @warning Will re-index numeric indexes. - * - * @note This operates the same as the built-in sort functions. - * It sorts the array and returns a bool for success. - * - * Do this: elgg_sort_3d_array_by_value($my_array); - * Not this: $my_array = elgg_sort_3d_array_by_value($my_array); - * - * @param array &$array Array to sort - * @param string $element Element to sort by - * @param int $sort_order PHP sort order - * {@see http://us2.php.net/array_multisort} - * @param int $sort_type PHP sort type - * {@see http://us2.php.net/sort} - * - * @return bool - */ -function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, -$sort_type = SORT_LOCALE_STRING) { - - $sort = array(); - - foreach ($array as $k => $v) { - if (isset($v[$element])) { - $sort[] = strtolower($v[$element]); - } else { - $sort[] = NULL; - } - }; - - return array_multisort($sort, $sort_order, $sort_type, $array); -} - - /**#@+ * Controlls access levels on ElggEntity entities, metadata, and annotations. * -- cgit v1.2.3