From 7ddd9521b3f3a397da3b0a6b56238d31414eb4be Mon Sep 17 00:00:00 2001 From: brettp Date: Thu, 28 Oct 2010 19:17:36 +0000 Subject: Standardized code in all of core, not including language files, tests, or core mods. git-svn-id: http://code.elgg.org/elgg/trunk@7124 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 552 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 376 insertions(+), 176 deletions(-) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 81be96752..4d51e6d7d 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2,17 +2,24 @@ /** * Bootstrapping and helper procedural code available for use in Elgg core and plugins. * - * * @package Elgg.Core * @todo These functions can't be subpackaged because they cover a wide mix of - * puposes and subsystems. Many of them should be moved to more relevant files. + * purposes and subsystems. Many of them should be moved to more relevant files. */ // prep core classes to be autoloadable -spl_autoload_register('__elgg_autoload'); +spl_autoload_register('_elgg_autoload'); elgg_register_classes(dirname(dirname(__FILE__)) . '/classes'); -function __elgg_autoload($class) { +/** + * Autoload classes + * + * @param string $class The name of the class + * + * @return void + * @throws Exception + */ +function _elgg_autoload($class) { global $CONFIG; if (!include($CONFIG->classes[$class])) { @@ -20,6 +27,14 @@ function __elgg_autoload($class) { } } +/** + * Register all files found in $dir as classes + * Need to be named MyClass.php + * + * @param string $dir The dir to look in + * + * @return void + */ function elgg_register_classes($dir) { $classes = elgg_get_file_list($dir, array(), array(), array('.php')); @@ -28,6 +43,14 @@ function elgg_register_classes($dir) { } } +/** + * Register a classname to a file. + * + * @param string $class The name of the class + * @param string $location The location of the file + * + * @return void + */ function elgg_register_class($class, $location) { global $CONFIG; @@ -41,9 +64,11 @@ function elgg_register_class($class, $location) { /** * Forward to $location. * - * Sends a 'Location: $location' header and exists. If headers have already been sent, returns FALSE. + * Sends a 'Location: $location' header and exists. If headers have + * already been sent, returns FALSE. * * @param string $location URL to forward to browser to. Can be path relative to the network's URL. + * * @return False False if headers have been sent. Terminates execution if forwarding. */ function forward($location = "") { @@ -95,11 +120,11 @@ function current_page_url() { $page .= $url['user']; } if ((isset($url['pass'])) && ($url['pass'])) { - $page .= ":".$url['pass']; + $page .= ":" . $url['pass']; } if ((isset($url['user']) && $url['user']) || (isset($url['pass']) && $url['pass'])) { - $page .="@"; + $page .= "@"; } $page .= $url['host']; @@ -154,6 +179,7 @@ function elgg_filepath_cache_reset() { * 'view_paths'. * * @param mixed $data The data + * * @return bool On success */ function elgg_filepath_cache_save($data) { @@ -170,7 +196,8 @@ function elgg_filepath_cache_save($data) { /** * Returns the contents of the views file paths cache from disk. * - * @return mixed Null if simplecache isn't enabled, the contents of the views file paths cache if it is. + * @return mixed Null if simplecache isn't enabled, the contents of the + * views file paths cache if it is. */ function elgg_filepath_cache_load() { global $CONFIG; @@ -224,6 +251,14 @@ function elgg_disable_filepath_cache() { * * @see elgg_add_submenu_item() * @deprecated 1.8 + * + * @param string $label The label + * @param string $link The link + * @param string $group The group to store item in + * @param boolean $onclick Add a confirmation when clicked? + * @param boolean $selected Is menu item selected + * + * @return bool */ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $selected = NULL) { elgg_deprecated_notice('add_submenu_item was deprecated by elgg_add_submenu_item', 1.8); @@ -239,7 +274,7 @@ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $ } if ($onclick) { - $js = "onclick=\"javascript:return confirm('". elgg_echo('deleteconfirm') . "')\""; + $js = "onclick=\"javascript:return confirm('" . elgg_echo('deleteconfirm') . "')\""; $item['vars'] = array('js' => $js); } // submenu items were added in the page setup hook usually by checking @@ -258,7 +293,7 @@ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $ /** * Add an entry to the submenu. * - * @param array $item The item as: + * @param array $item The item as: * * array( * 'title' => 'Text to display', @@ -270,8 +305,10 @@ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $ * ) * * - * @param string $context Context in which to display this menu item. 'all' will make it show up all the time. Use sparingly. - * @param string $group Group for the item. Each submenu group has its own