I have a fully modified version of CI packaged in the default 1.5.3 structure which allows for a configured set of global resources. (SEE FOLLOWING POST)
The only resource loading I DID NOT TOUCH are those found in system/libraries/Router.php as I believe it is best for that library to look in the local application directory for its routes.config, and controllers should always be loaded from the local application dir.
CHANGES:
application/config/config.php
*added after section where subclass_prefix is set
/*
|---------------------------------------------------------------
| CI Search Paths
|---------------------------------------------------------------
|
| If you want this application to share globally accessible directories
| of configurations, helpers, libraries, etc. with other applications
| you can tell CI where to look for these items. This setting is an array and
| can have as many entries as you want. Know, though, that the more you have
| the longer it will take to load a file that is actually in the system directory.
|
| By default, the CI loader looks in the local application directory for
| these sorts of files, and if nothing exists it looks in the core
| system directory. Adding enteries here adds intermediate places to look
| for code files. CI will now look in the local application directory, then
| in any directory you configure here (in order from first listed to last
| if more than one), then finally the core system directory.
|
| For example, if you were loading a library via $this->load->library('validation')
| the loader would first look for the validation library file in
| application/libraries/, then in the libraries/ directory under any configured
| 'ci_search_paths' directory, then in system/libraries/.
|
| FORMATTING
| *This path can be
| Relative (to the front controller which THIS config file configures)
| or Absolute
| *NO TRAILING SLASHES
|
*/
$config['ci_search_paths'] = Array(
);
system/codeigniter/Common.php
*added 2 functions to the bottom of the file
/**
* Set Search Paths
*
* Build an array of absolute paths where the first entry is the local
* application directory (APPPATH), the next entries are validated entries
* from the 'ci_search_paths' entry in main config, and the last entry is
* the system directory (BASEPATH)
*
* @access public
* @return array
*/
function set_search_paths()
{
$search_paths = array(APPPATH);
$configed_paths = config_item('ci_search_paths');
if ( is_array($configed_paths) && count($configed_paths)>0 )
{
foreach($configed_paths as $path)
{
$path =
substr($path,0,1)=='/'?
$path:
SELF.$path;
if ( ($path=realpath($path))!==FALSE && is_dir($path) )
{
$search_paths[] = $path.'/';
}
}
}
$search_paths[] = BASEPATH;
return $search_paths;
}
/**
* Find Resource
*
* Takes a filename, resource subdirectory (libraries, helpers, plugins, etc),
* and optional list of paths to exclude in the search and returns absolute
* path to first matching filename in search path hierarchy or BOOL FALSE if
* not found
*
* @access public
* @param string
* @param string
* @param array
* @return mixed
*/
function ci_find_resource($resource_file,$resource_subdir,$exclude_in_search=array())
{
global $SPATHS;
$returnVal = false;
foreach ( $SPATHS as $spath )
{
if ( (is_array($exclude_in_search) && !in_array($spath,$exclude_in_search)) && is_file($spath.$resource_subdir.'/'.$resource_file) )
{
$returnVal = $spath.$resource_subdir.'/'.$resource_file;
break;
}
}
return $returnVal;
}
*modified function &load_class() to use new global function ci_find_resource()
system/codeigniter/CodeIgniter.php
*added after the section that require() Common.php:
/*
* ------------------------------------------------------
* Get the list of search paths for resource loading
* ------------------------------------------------------
*/
$SPATHS = set_search_paths();
system/codeigniter/libraries/Loader.php
*modified methods to use new global function ci_find_resource()
>> _ci_load_class()
>> model()
>> helper()
>> plugin()
>> script()
>> _ci_load()—this effected methods file() and view()
>> _ci_init_class()
>> _ci_autoloader()
*Removed initial setting of property $_ci_view_path from the constructer as it is not needed unless explicitly set by scaffolding or the like
system/libraries/Language.php
*modified method load() to use new global function ci_find_resource()
system/libraries/Config.php
*modified method load() to use new global function ci_find_resource()
system/libraries/User_agent.php
*modified method _load_agent_file() to use new global function ci_find_resource()
system/database/DB.php
*modified method &DB() to use new global function ci_find_resource()
system/libraries/Exceptions.php
*modified methods to use new global function ci_find_resource()
>> show_error()
>> show_php_error()
system/libraries/Upload.php
*modified method mimes_types() to use new global function ci_find_resource()
system/libraries/Hooks.php
*modified methods to use new global function ci_find_resource()
>> _initialize()
>> _run_hook()
system/helpers/smiley_helper.php
*modified method _get_smiley_array() to use new global function ci_find_resource()
system/helpers/download_helper.php
*modified method force_download() to use new global function ci_find_resource()