You are here

function find_conf_path in Mail MIME 7.2

Same name and namespace in other branches
  1. 8.2 url_to_path.inc \find_conf_path()
  2. 6.2 url_to_path.inc \find_conf_path()
  3. 6 url_to_path.inc \find_conf_path()
  4. 7 url_to_path.inc \find_conf_path()

Find the appropriate configuration directory for a given host and path.

Parameters

$http_host: The hostname and optional port number, e.g. "www.example.com" or "www.example.com:8080".

$script_name: The part of the url following the hostname, including the leading slash.

Return value

The path of the matching configuration directory.

See also

conf_path()

1 call to find_conf_path()
url_to_path in ./url_to_path.inc
Returns the local relative path corresponding to a given URL, if possible.

File

./url_to_path.inc, line 24
Provide a url_to_path() function by refactoring and repurposing conf_path().

Code

function find_conf_path($http_host, $script_name, $require_settings = TRUE) {
  $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('/', $script_name);
  $server = explode('.', implode('.', array_reverse(explode(':', rtrim($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;
}