diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-11-24 22:44:01 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-11-24 22:44:01 +0000 |
commit | 5d759ccbb9764e4c0328ce7fc4a83df8b958cf85 (patch) | |
tree | 99a4f638669ab176c5714c87cb982c19dab04528 /includes/common.inc | |
parent | 062a8abdeae40ab03004f7c11dc21b7a13b57ca1 (diff) | |
download | brdo-5d759ccbb9764e4c0328ce7fc4a83df8b958cf85.tar.gz brdo-5d759ccbb9764e4c0328ce7fc4a83df8b958cf85.tar.bz2 |
- Patch #5942 by jhriggs and Adrian:
+ added support for multi-site configurations.
+ tidied up some old cruft and added code comments.
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 94 |
1 files changed, 94 insertions, 0 deletions
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'; |