function conf_path
conf_path($require_settings = TRUE, $reset = FALSE)
Returns the appropriate configuration directory.
Returns the configuration path based on the site's hostname, port, and pathname. See default.settings.php for examples on how the URL is converted to a directory.
Parameters
bool $require_settings: Only configuration directories with an existing settings.php file will be recognized. Defaults to TRUE. During initial installation, this is set to FALSE so that Drupal can detect a matching directory, then create a new settings.php file in it.
bool $reset: Force a full search for matching directories even if one had been found previously. Defaults to FALSE.
Return value
The path of the matching directory.
See also
File
- includes/bootstrap.inc, line 549
- Functions that need to be loaded on every Drupal request.
Code
function conf_path($require_settings = TRUE, $reset = FALSE) { $conf = &drupal_static(__FUNCTION__, ''); if ($conf && !$reset) { return $conf; } $confdir = 'sites'; $sites = array(); if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) { // This will overwrite $sites with the desired mappings. include (DRUPAL_ROOT . '/' . $confdir . '/sites.php'); } $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']); $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.'))))); 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 (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) { $dir = $sites[$dir]; } if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) { $conf = "$confdir/$dir"; return $conf; } } } $conf = "$confdir/default"; return $conf; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/conf_path/7.x