All pastes #342368 Raw Edit

Stuff

public php v1 · immutable
·published 2007-02-06 07:42 UTC
rendered paste body
<?php/** * RandomTales.net * A site where you can share, manage and edit your stories! * * @author		Dean Newman <webmaster@auscoder.com> * @copyright	Copyright 2007, Dean Newman */if ( ! defined('IN_SITE') ){	return;}/** * Module Management Class * * @package		framework * @subpackage	modules * @copyright	Copyright 2007, Dean Newman * @author		Afterlife(69) <webmaster@auscoder.com> */class modules{	var $modlist = array();	var $prefix = 'def';	var $automodule = 'index';	var $directory = '';	var $modulename;	var $module;	/**	 * @return modules	 */	function modules($module_name = '', $module_dir = '', $prefix = '', $automodule = '', $construct_now = true)	{		if ( $prefix )		{			$this->prefix = $prefix;		}				if ( $automodule )		{			$this->automodule = $automodule;		}		$this->modulename = ($module_name);		$this->scan_directory($module_dir);				if ( $construct_now )		{			$this->build($module_name);		}				return;	}		/**	 * @return array	 */	function scan_directory($module_dir = '')	{		$modules = array();			if ( ! is_dir(ROOT_PATH . 'modules/' . $module_dir) || !is_readable(ROOT_PATH . 'modules/' . $module_dir) )		{			trigger_error('Unable to locate module storage directory.');			exit;		}				$this->directory = (ROOT_PATH . 'modules/' . $module_dir);			//		// Scan for modules		//		$dir = @opendir($this->directory);		while ( $file = @readdir ( $dir ) )		{			// Make sure the file is not a dir, or self/top			if ( is_dir ( $file ) )			{				continue;			}					// Regex the filename			if ( ! preg_match ( '/' . preg_quote($this->prefix, '/') . '_(.*?)\.php/is', $file, $match ) )			{				continue;			}						// Add to modules array			$modules[] = ($this->prefix . '_' . $match[1]);		}		@closedir($dir);				$this->modlist = $modules;				return $modules;	}		/**	 * return object	 */	function build($module_name = '', $construct = true)	{		// Append the prefix		$this_module = ( $module_name ) ? $module_name : $this->modulename;		$this_module = ($this->prefix . '_' . $this_module);			// Check for the module, if not load default		if ( ! in_array($this_module, $this->modlist) )		{			$this_module = ($this->prefix . '_' . $this->automodule);		}				// Check again to make sure default is there, if not error		if ( ! in_array($this_module, $this->modlist) )		{			trigger_error('The default module could not be found');			exit;		}				// include the module if required		if ( ! class_exists ( $this_module ) )		{			include ($this->directory . '/' . $this_module . '.php');		}				// if needed, construct the module		$module = false;		if ( $construct )		{			$this->module = $module = new $this_module();		}		return $module;	}}/** * Module Information Reader * * This class will read module information files if they exist, otherwise it will try to load the class and detect a "prefix_module_info" class. * * @package		framework * @subpackage	modules * @copyright	Copyright 2007, Dean Newman * @author		Afterlife(69) <webmaster@auscoder.com> */class modules_info{	var $moduleclass;	var $directory;	var $modules;	var $modlist;	function modules_info(&$moduleclass, $directory = '', $do_not_construct = false)	{		if ( ! is_instanceof($moduleclass, 'modules') )		{			trigger_error('The class provided is not an instance of the module object.');			exit;		}				$this->moduleclass = $moduleclass;		$this->scan_directory($directory);		$this->get_module_info();	}		/**	 * @return array	 */	function scan_directory($module_dir = '')	{		if ( ! is_dir(ROOT_PATH . 'modules/' . $module_dir) || !is_readable(ROOT_PATH . 'modules/' . $module_dir) )		{			trigger_error('Unable to locate module storage directory.');			exit;		}				$this->directory = (ROOT_PATH . 'modules/' . $module_dir);			//		// Scan for modules		//		$dir = @opendir($this->directory);		$modules = array();		while ( $file = @readdir ( $dir ) )		{			// Make sure the file is not a dir, or self/top			if ( is_dir ( $file ) )			{				continue;			}					// Regex the filename			if ( ! preg_match ( '/' . preg_quote($this->moduleclass->prefix, '/') . '_(.*?)_info\.php/is', $file, $match ) )			{				continue;			}						if ( !in_array($this->moduleclass->prefix . '_' . $match[1], $this->moduleclass->modlist) )			{				continue;			}						// Add to modules array			$modules[] = ($this->moduleclass->prefix . '_' . $match[1] . '_info');		}		@closedir($dir);				$this->modlist = $modules;				return $modules;	}		/**	 * @return array An array of objects containing module information used to build the navigation lists, etc...	 */	function get_module_info()	{		$this->modules = array();		for ( $i = 0 ; $i < sizeof($this->moduleclass->modlist) ; $i++ )		{			$this_module = (substr($this->moduleclass->modlist[$i], strlen($this->moduleclass->prefix) + 1));			$this_module_info = ($this_module . '_info');			$this->modules[] = ($this->moduleclass->prefix . '_' . $this_module_info);						if ( class_exists($this->moduleclass->prefix . '_' . $this_module_info) )			{				continue;			}						if ( ! in_array($this->moduleclass->prefix . '_' . $this_module_info, $this->modlist) )			{				$this->moduleclass->build(substr($this->moduleclass->modlist[$i], strlen($this->moduleclass->prefix) + 1), false);			}						if ( !class_exists($this->moduleclass->prefix . '_' . $this_module_info) && file_exists("{$this->directory}/{$this->moduleclass->prefix}_{$this_module_info}.php") )			{				include ("{$this->directory}/{$this->moduleclass->prefix}_{$this_module_info}.php");			}			if ( ! class_exists($this->moduleclass->prefix . '_' . $this_module_info) )			{				array_pop($this->modules);			}					}				for ( $i = 0 ; $i < sizeof ( $this->modules ) ; $i++ )		{			$this->modules[$i] = new $this->modules[$i]();		}				return $this->modules;	}}?>