diff options
| author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-17 13:00:16 +0000 | 
|---|---|---|
| committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-10-17 13:00:16 +0000 | 
| commit | 2819e203902392e229564e734194c5c8f8e26db5 (patch) | |
| tree | cd86658ee218d584d57e506177218337af11fc97 /engine/lib | |
| parent | a36a28ebfbc3f2662e95bd36a84ccf3fbc54fdaa (diff) | |
| download | elgg-2819e203902392e229564e734194c5c8f8e26db5.tar.gz elgg-2819e203902392e229564e734194c5c8f8e26db5.tar.bz2  | |
Fixes #2563 - setup autoload in elgglib.php so exceptions and other classes are available as soon as possible
git-svn-id: http://code.elgg.org/elgg/trunk@7091 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
| -rw-r--r-- | engine/lib/elgglib.php | 79 | ||||
| -rw-r--r-- | engine/lib/input.php | 23 | 
2 files changed, 53 insertions, 49 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 675c0143e..8ff0a24a5 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -8,6 +8,36 @@   * puposes and subsystems.  Many of them should be moved to more relevant files.   */ +// prep core classes to be autoloadable +spl_autoload_register('__elgg_autoload'); +elgg_register_classes(dirname(dirname(__FILE__)) . '/classes'); + +function __elgg_autoload($class) { +	global $CONFIG; + +	if (!include($CONFIG->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.   * @@ -584,6 +614,29 @@ function elgg_get_file_list($directory, $exceptions = array(), $list = array(),  }  /** + * Sanitise file paths ensuring that they begin and end with slashes etc. + * + * @param string $path The path + * @return string + */ +function sanitise_filepath($path, $append_slash = TRUE) { +	// Convert to correct UNIX paths +	$path = str_replace('\\', '/', $path); +	$path = str_replace('../', '/', $path); + +	// Sort trailing slash +	$path = trim($path); +	// rtrim defaults plus / +	$path = rtrim($path, " \n\t\0\x0B/"); + +	if ($append_slash) { +		$path = $path . '/'; +	} + +	return $path; +} + +/**   * Adds an entry in $CONFIG[$register_name][$subregister_name].   *   * This is only used for the site-wide menu.  See {@link add_menu()}. @@ -2200,32 +2253,6 @@ function js_page_handler($page) {  	}  } -function __elgg_autoload($class) { -	global $CONFIG; - -	if (!include($CONFIG->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; -} -  /**   * Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.   * diff --git a/engine/lib/input.php b/engine/lib/input.php index 324b0cec4..fe481b24b 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -84,29 +84,6 @@ function filter_tags($var) {  }  /** - * Sanitise file paths for input, ensuring that they begin and end with slashes etc. - * - * @param string $path The path - * @return string - */ -function sanitise_filepath($path, $append_slash = TRUE) { -	// Convert to correct UNIX paths -	$path = str_replace('\\', '/', $path); -	$path = str_replace('../', '/', $path); - -	// Sort trailing slash -	$path = trim($path); -	// rtrim defaults plus / -	$path = rtrim($path, " \n\t\0\x0B/"); - -	if ($append_slash) { -		$path = $path . '/'; -	} - -	return $path; -} - -/**   * Validates an email address.   *   * @param string $address Email address.  | 
