classes[$class])) { throw new Exception("Failed to 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')); foreach ($classes as $class) { elgg_register_class(basename($class, '.php'), $class); } } /** * 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; if (!isset($CONFIG->classes)) { $CONFIG->classes = array(); } $CONFIG->classes[$class] = $location; } /** * Forward to $location. * * 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 = "") { global $CONFIG; if (!headers_sent()) { if ($location === REFERER) { $location = $_SERVER['HTTP_REFERER']; } if ((substr_count($location, 'http://') == 0) && (substr_count($location, 'https://') == 0)) { $location = $CONFIG->url . $location; } // return new forward location or false to stop the forward or empty string to exit $current_page = current_page_url(); $params = array('current_url' => $current_page, 'forward_url' => $location); $location = trigger_plugin_hook('forward', 'system', $params, $location); if ($location) { header("Location: {$location}"); exit; } else if ($location === '') { exit; } } 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; } /** * Deprecated by elgg_add_submenu_item() * * @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); $item = array( 'text' => $label, 'href' => $link, 'selected' => $selected ); if (!$group) { $group = 'default'; } if ($onclick) { $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 // the context. We'll pass in the current context here, which will // emulate that effect. // if context == 'main' (default) it probably means they always wanted // the menu item to show up everywhere. $context = get_context(); if ($context == 'main') { $context = 'all'; } return elgg_add_submenu_item($item, $context, $group); } /** * Add an entry to the submenu. * * @param array $item The item as: * * array( * 'title' => 'Text to display', * 'url' => 'URL of the link', * 'id' => 'entry_unique_id' //used by children items to identify parents * 'parent_id' => 'id_of_parent', * 'selected' => BOOL // Is this item selected? (If NULL or unset will attempt to guess) * 'vars' => array() // Array of vars to pass to the navigation/submenu_item view * ) * * * @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