classes[$class])) { throw new Exception("Failed to autoload $class"); } } 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); } } 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; } /** * Returns an ElggCache object suitable for caching view * file load paths to disk under $CONFIG->dataroot. * * @todo Can this be done in a cleaner way? * @todo Swap to memcache etc? * * @return ElggFileCache A cache object suitable for caching file load paths. */ function elgg_get_filepath_cache() { global $CONFIG; /** * A default filestore cache using the dataroot. */ static $FILE_PATH_CACHE; if (!$FILE_PATH_CACHE) { $FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot); } return $FILE_PATH_CACHE; } /** * Deletes the view file paths cache from disk. * * @return bool On success */ function elgg_filepath_cache_reset() { $cache = elgg_get_filepath_cache(); return $cache->delete('view_paths'); } /** * Saves $data to the views file paths disk cache as * 'view_paths'. * * @param mixed $data The data * @return bool On success */ function elgg_filepath_cache_save($data) { global $CONFIG; if ($CONFIG->viewpath_cache_enabled) { $cache = elgg_get_filepath_cache(); return $cache->save('view_paths', $data); } return false; } /** * 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. */ function elgg_filepath_cache_load() { global $CONFIG; if ($CONFIG->viewpath_cache_enabled) { $cache = elgg_get_filepath_cache(); $cached_view_paths = $cache->load('view_paths'); if ($cached_view_paths) { return $cached_view_paths; } } return NULL; } /** * Enables the views file paths disk cache. * * Uses the 'viewpath_cache_enabled' datalist with a boolean value. * Resets the views paths cache. * * @return null */ function elgg_enable_filepath_cache() { global $CONFIG; datalist_set('viewpath_cache_enabled', 1); $CONFIG->viewpath_cache_enabled = 1; elgg_filepath_cache_reset(); } /** * Disables the views file paths disk cache. * * Uses the 'viewpath_cache_enabled' datalist with a boolean value. * Resets the views paths cache. * * @return null */ function elgg_disable_filepath_cache() { global $CONFIG; datalist_set('viewpath_cache_enabled', 0); $CONFIG->viewpath_cache_enabled = 0; elgg_filepath_cache_reset(); } /** * Deprecated by elgg_add_submenu_item() * * @see elgg_add_submenu_item() * @deprecated 1.8 */ 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