Exemplo n.º 1
0
/**
 * Support function -- load the main configuration options, overriding with
 * custom local settings if applicable.
 *
 * @return  array       The desired config.ini settings in array format.
 */
function readConfig()
{
    //Read default configuration file
    $configFile = '../../sites/default/conf/packaging_web_service.ini';
    $mainArray = parse_ini_file($configFile, true);
    global $servername;
    $serverUrl = $_SERVER['SERVER_NAME'];
    $server = $serverUrl;
    $serverParts = explode('.', $server);
    $servername = 'default';
    while (count($serverParts) > 0) {
        $tmpServername = join('.', $serverParts);
        $configFile = "../../sites/{$tmpServername}/conf/config.ini";
        if (file_exists($configFile)) {
            $serverArray = parse_ini_file($configFile, true);
            $mainArray = ini_merge($mainArray, $serverArray);
            $servername = $tmpServername;
        }
        array_shift($serverParts);
    }
    if ($mainArray == false) {
        echo "Unable to parse configuration file {$configFile}, please check syntax";
    }
    //If we are accessing the site via a subdomain, need to preserve the subdomain
    if (isset($_SERVER['HTTPS'])) {
        $mainArray['Site']['url'] = "https://" . $serverUrl;
    } else {
        $mainArray['Site']['url'] = "http://" . $serverUrl;
    }
    return $mainArray;
}
/**
 * Support function -- merge the contents of two arrays parsed from ini files.
 *
 * @param   array $config_ini  The base config array.
 * @param   array $custom_ini  Overrides to apply on top of the base array.
 * @return  array       The merged results.
 */
function ini_merge($config_ini, $custom_ini)
{
    foreach ($custom_ini as $k => $v) {
        if (is_array($v)) {
            $config_ini[$k] = ini_merge(isset($config_ini[$k]) ? $config_ini[$k] : array(), $custom_ini[$k]);
        } else {
            $config_ini[$k] = $v;
        }
    }
    return $config_ini;
}
Exemplo n.º 3
0
/**
 * Support function -- load the main configuration options, overriding with
 * custom local settings if applicable.
 *
 * @return  array       The desired config.ini settings in array format.
 */
function readConfig()
{
    //Read default configuration file
    $configFile = '../../sites/default/conf/config.ini';
    $mainArray = parse_ini_file($configFile, true);
    global $serverName;
    $serverUrl = $_SERVER['SERVER_NAME'];
    $server = $serverUrl;
    $serverParts = explode('.', $server);
    $serverName = 'default';
    while (count($serverParts) > 0) {
        $tmpServername = join('.', $serverParts);
        $configFile = "../../sites/{$tmpServername}/conf/config.ini";
        if (file_exists($configFile)) {
            $serverArray = parse_ini_file($configFile, true);
            $mainArray = ini_merge($mainArray, $serverArray);
            $serverName = $tmpServername;
            $passwordFile = "../../sites/{$tmpServername}/conf/config.pwd.ini";
            if (file_exists($passwordFile)) {
                $serverArray = parse_ini_file($passwordFile, true);
                $mainArray = ini_merge($mainArray, $serverArray);
            }
        }
        array_shift($serverParts);
    }
    // Sanity checking to make sure we loaded a good file
    // @codeCoverageIgnoreStart
    if ($serverName == 'default') {
        global $logger;
        if ($logger) {
            $logger->log('Did not find servername for server ' . $_SERVER['SERVER_NAME'], PEAR_LOG_ERR);
        }
        PEAR_Singleton::raiseError("Invalid configuration, could not find site for " . $_SERVER['SERVER_NAME']);
    }
    if ($mainArray == false) {
        echo "Unable to parse configuration file {$configFile}, please check syntax";
    }
    // @codeCoverageIgnoreEnd
    //If we are accessing the site via a subdomain, need to preserve the subdomain
    //Don't try to preserve SSL since the combination of proxy and SSL does not work nicely.
    //i.e. https://mesa.marmot.org is proxied to https://mesa.opac.marmot.org which does not have
    //a valid SSL cert
    $mainArray['Site']['url'] = "http://" . $serverUrl;
    return $mainArray;
}