diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 42 | ||||
-rw-r--r-- | includes/common.inc | 94 | ||||
-rw-r--r-- | includes/conf.php | 68 | ||||
-rw-r--r-- | includes/file.inc | 54 | ||||
-rw-r--r-- | includes/module.inc | 78 |
5 files changed, 166 insertions, 170 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index b1da3b337..a0d783910 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -12,25 +12,41 @@ define('CACHE_TEMPORARY', -1); /** * Locate the appropriate configuration file. * - * Try finding a matching configuration file by stripping the website's - * URI from left to right. If no configuration file is found, return the - * default value, "conf". + * Try finding a matching configuration directory by stripping the + * website's hostname from left to right and pathname from right to + * left. If no configuration file is found, return a default value + * '$confdir/default'. Example for a ficticious site installed at + * http://www.drupal.org/test: + * + * 1. www.drupal.org.test + * 2. drupal.org.test + * 3. www.drupal.org + * 4. drupal.org + * 5. default */ function conf_init() { - $uri = $_SERVER['PHP_SELF']; + static $conf = ''; - $file = strtolower(strtr($_SERVER['HTTP_HOST'] . substr($uri, 0, strrpos($uri, '/')), '/:', '..')); + if ($conf) { + return $conf; + } - while (strlen($file) > 4) { - if (file_exists('includes/'. $file .'.php')) { - return $file; - } - else { - $file = substr($file, strpos($file, '.') + 1); + $uri = explode('/', $_SERVER['PHP_SELF']); + $server = explode('.', $_SERVER['HTTP_HOST']); + $confdir = 'sites'; + for ($i = count($uri) - 1; $i > 0; $i--) { + for ($j = count($server); $j > 0; $j--) { + $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i)); + if (file_exists("$confdir/$dir/settings.php")) { + $conf = "$confdir/$dir"; + return $conf; + } } } - return 'conf'; +print "$confdir/default/settings.php<br />"; + $conf = "$confdir/default"; + return $conf; } /** @@ -442,7 +458,7 @@ function drupal_get_messages() { unset($conf); $config = conf_init(); -include_once "includes/$config.php"; +include_once "$config/settings.php"; include_once 'includes/database.inc'; include_once 'includes/session.inc'; include_once 'includes/module.inc'; diff --git a/includes/common.inc b/includes/common.inc index d65ebe7a2..3da8bda85 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1836,6 +1836,100 @@ function drupal_eval($code) { return $output; } +/** + * Returns and optionally sets the filename for a system item (module, + * theme, etc.). The filename, whether provided, cached, or retrieved + * from the database, is only returned if the file exists. + * + * @param $type + * The type of the item (i.e. theme, theme_engine, module). + * @param $name + * The name of the item for which the filename is requested. + * @param $filename + * The filename of the item if it is to be set explicitly rather + * than by consulting the database. + * + * @return + * The filename of the requested item. + */ +function drupal_get_filename($type, $name, $filename = NULL) { + static $files = array(); + + if (!$files[$type]) { + $files[$type] = array(); + } + + if ($filename && file_exists($filename)) { + $files[$type][$name] = $filename; + } + elseif ($files[$type][$name]) { + // nothing + } + elseif (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file)) { + $files[$type][$name] = $file; + } + else { + $config = conf_init(); + $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s"); + $file = "$name.$type"; + + foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) { + if (file_exists($file)) { + $files[$type][$name] = $file; + break; + } + } + } + + return $files[$type][$name]; +} + +/** + * Returns the path to a system item (module, theme, etc.). + * + * @param $type + * The type of the item (i.e. theme, theme_engine, module). + * @param $name + * The name of the item for which the path is requested. + * + * @return + * The path to the requested item. + */ +function drupal_get_path($type, $name) { + return dirname(drupal_get_filename($type, $name)); +} + +/** + * Includes a file with the provided type and name. This prevents + * including a theme, engine, module, etc., more than once. + * + * @param $type + * The type of item to load (i.e. theme, theme_engine, module). + * @param $name + * The name of the item to load. + * + * @return + * TRUE if the item is loaded or has already been loaded. + */ +function drupal_load($type, $name) { + static $files = array(); + + if ($files[$type][$name]) { + return TRUE; + } + + $filename = drupal_get_filename($type, $name); + + if ($filename) { + include_once($filename); + $files[$type][$name] = TRUE; + + return TRUE; + } + + return FALSE; +} + include_once 'includes/theme.inc'; include_once 'includes/pager.inc'; include_once 'includes/menu.inc'; diff --git a/includes/conf.php b/includes/conf.php deleted file mode 100644 index 365d4fd68..000000000 --- a/includes/conf.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php -// $Id$ - -/** - * @file - * Drupal site-specific configuration file. - */ - -# -# Database settings: -# -# Note that the $db_url variable gets parsed using PHP's built-in -# URL parser (i.e. using the "parse_url()" function) so make sure -# not to confuse the parser. In practice, you should avoid using -# special characters that are not used in "normal" URLs either. -# That is, the use of ':', '/', '@', '?', '=' and '#', ''', '"', -# and so on is likely to confuse the parser; use alpha-numerical -# characters instead. -# -# To specify multiple connections to be used in your site (i.e. for -# complex custom modules) you can also specify an associative array -# of $db_url variables with the 'default' element used until otherwise -# requested. - -# $db_url = "mysql://user:password@hostname/database"; -# $db_url = "pgsql://user:password@hostname/database"; -$db_url = "mysql://drupal:drupal@localhost/drupal"; - -# If $db_prefix is specified all database table names will be -# prepended with this string. Be sure to use valid database -# characters only, usually alphanumeric and underscore. If no -# prefixes are desired, set to empty string "". -$db_prefix = ""; - -# -# Base URL: -# -# The URL of your website's main page. It is not allowed to have -# a trailing slash; Drupal will add it for you. -# -$base_url = "http://localhost"; - -# -# PHP settings: -# -# To see what PHP settings are known to work well, take a look at -# the .htaccesss file in Drupal's root directory. If you get -# unexpected warnings or errors, double-check your PHP settings. - -# If required, update PHP's include path to include your PEAR directory: -// ini_set("include_path", ".:/path/to/pear"); - -# -# Variable overrides: -# -# To override specific entries in the 'variable' table for this site, -# set them here. You usually don't need to use this feature. This is -# useful when used in a configuration file for a vhost or directory, -# rather than the default conf.php. Any configuration setting from the -# variable table can be given a new value. -# -# $conf = array( -# 'site_name' => 'My Drupal site', -# 'theme_default' => 'pushbutton', -# 'anonymous' => 'Visitor' -# ); - -?> diff --git a/includes/file.inc b/includes/file.inc index 0eda14c6c..7c467ad17 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -469,39 +469,59 @@ function file_download() { } /** - * Finds all files that match a given mask in a given directory. + * Finds all files that match a given mask in a given + * directory. * - * @param $dir Directory to scan - * @param $mask Regular expression to filter out files. Only filenames that - * match the mask will be returned. - * @param $nomask Array of filenames which should never be returned regardless - * if they match the $mask - * @param $callback Function to call for qualifying file. - * Set to 0 or false if you do not want callbacks. - * @param $recurse When true directory scan will recurse the entire tree starting at $dir - * @return Array of qualifying files + * @param $dir + * The base directory for the scan. + * @param $mask + * The regular expression of the files to find. + * @param $nomask + * An array of files/directories to ignore. + * @param $callback + * The callback function to call for each match. + * @param $recurse + * When TRUE, the directory scan will recurse the entire tree + * starting at the provided directory. + * @param $key + * The key to be used for the returned array of files. Possible + * values are "filename", for the path starting with $dir, + * "basename", for the basename of the file, and "name" for the name + * of the file without an extension. + * + * @return + * An associative array (keyed on the provided key) of objects with + * "path", "basename", and "name" members corresponding to the + * matching files. */ -function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = TRUE) { +function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = TRUE, $key = 'filename') { + $key = (in_array($key, array('filename', 'basename', 'name')) ? $key : 'filename'); $files = array(); + if (is_dir($dir) && $handle = opendir($dir)) { while ($file = readdir($handle)) { if (!in_array($file, $nomask)) { if (is_dir("$dir/$file") && $recurse) { - $files = array_merge($files, file_scan_directory("$dir/$file", $mask, $nomask, $callback)); + $files = array_merge($files, file_scan_directory("$dir/$file", $mask, $nomask, $callback, $recurse, $key)); } elseif (ereg($mask, $file)) { - $name = basename($file); - $files["$dir/$file"] = new stdClass(); - $files["$dir/$file"]->filename = "$dir/$file"; - $files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.')); + $filename = "$dir/$file"; + $basename = basename($file); + $name = substr($basename, 0, strrpos($basename, '.')); + $files[$$key] = new stdClass(); + $files[$$key]->filename = $filename; + $files[$$key]->basename = $basename; + $files[$$key]->name = $name; if ($callback) { - $callback("$dir/$file"); + $callback($filename); } } } } + closedir($handle); } + return $files; } diff --git a/includes/module.inc b/includes/module.inc index e4ac60dda..e5a68d7f1 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -61,8 +61,8 @@ function module_list($refresh = FALSE, $bootstrap = FALSE) { // variables, since throttle.module may not be loaded yet. $throttle = ($module->throttle && variable_get('throttle_level', 0) > 0); if (!$throttle) { + drupal_get_filename('module', $module->name, $module->filename); $list[$module->name] = $module->name; - module_set_filename($module->name, $module->filename); } } } @@ -72,85 +72,19 @@ function module_list($refresh = FALSE, $bootstrap = FALSE) { } /** - * Set the filename of a module, for future loading through module_load() - * - * @param $module - * Name of the module which to specify the filename of. - * @param $pa - * Filename of the module named $module. - * @return - * Filename of module, if no $path has been specified. - */ -function module_set_filename($module, $path = null) { - static $list; - - if ($path) { - $list[$module] = $path; - } - else { - return $list[$module] ? $list[$module] : "modules/$module.module"; - } -} - -/** - * Retrieve the filename of a module - * - * @param $module - * Name of the module which to retrieve the filename of. - * @return - * Filename of module. - */ -function module_get_filename($module) { - return module_set_filename($module); -} - -/** - * Retrieve the path of a module - * - * @param $module - * Name of the module which to retrieve the path of. - * @return - * Path of module. - */ -function module_get_path($module) { - return dirname(module_get_filename($module)); -} - -/** - * Load a module into Drupal, but check first whether a module by the same name - * has been loaded, and that the filename being included exists. - * @param $module - * The name of the module to be loaded. - * @return - * TRUE if the load was successful. - */ -function module_load($module) { - static $loaded = array(); - - if (!$loaded[$module]) { - $filename = module_get_filename($module); - if (file_exists($filename)) { - include_once($filename); - $loaded[$module] = $filename; - return true; - } - } - return false; -} - - -/** * Load all the modules that have been enabled in the system table. * * @return - * TRUE if all modules were loaded successfully + * TRUE if all modules were loaded successfully. */ function module_load_all() { $list = module_list(); - $status = true; + $status = TRUE; + foreach ($list as $module) { - $status &= module_load($module); + $status = (drupal_load('module', $module) && $status); } + return $status; } |