All pastes #943007 Raw Edit

Stuff

public php v1 · immutable
·published 2008-03-14 21:53 UTC
rendered paste body
function __autoload($class_name) {	static $files= null;	$success= false;	$class_file = strtolower($class_name) . '.php';	if( empty($files) ) {		$files = array();		$dirs= array( HABARI_PATH . '/system', HABARI_PATH . '/user' );		// For each directory, save the available files in the $files array.		foreach ($dirs as $dir) {			$glob = glob( $dir . '/classes/*.php' );			if ( $glob === false || empty( $glob ) ) continue;			$fnames = array_map(create_function('$a', 'return strtolower(basename($a));'), $glob);			$files = array_merge($files, array_combine($fnames, $glob));		}		// Load the Site class, a requirement to get files from a multisite directory.		if(isset($files['site.php'])) {			require_once $files['site.php'];		}		// Verify if this Habari instance is a multisite.		if ( ($site_user_dir = Site::get_dir('user')) != HABARI_PATH . '/user' ) {			// We are dealing with a site defined in /user/sites/x.y.z			// Add the available files in that directory in the $files array.			$glob = glob( $site_user_dir . '/classes/*.php' );			$fnames = array_map(create_function('$a', 'return strtolower(basename($a));'), $glob);			if ( $glob !== false && ! empty( $glob ) && ! empty( $fnames ) ) {				$files = array_merge($files, array_combine($fnames, $glob));			}		}	}	// Search in the available files for the undefined class file.	if(isset($files[$class_file])) {		require_once $files[$class_file];		// If the class has a static method named __static(), execute it now, on initial load.		if(class_exists($class_name, false) && method_exists($class_name, '__static') ) {			call_user_func(array($class_name, '__static'));		}		$success= true;	}	if ( ! $success ) {		die( 'Could not include class file ' . $class_file );	}}