/** * A method to write the configuration file for plugin. Also creates "fake" * configuration files when required by multi-host installations. * * @static * @param array $aConfig The configuration array to save as a configuration file. * @param string $module The plugin module name (i.e. /plugins/module directory). * @param string $package An optional plugin package name (i.e. /plugins/module/package * directory). If not given, writes the module level * configuration file path. * @param string $name An optional plugin name (i.e. /plugins/module/package/plugin.plugin.php). * If not given, writes the package level configuration file, or * the module level configuration file, depending on the $package * parameter. * @return boolean True on success, false otherwise. */ function writePluginConfig($aConfig, $module, $package = null, $name = null) { $conf = $GLOBALS['_MAX']['CONF']; // Prepare the config file for writing, using the delivery engine // host as the hostname for the "real" config file $url = @parse_url('http://' . $conf['webpath']['delivery']); if (!isset($url['host'])) { return false; } $deliveryHost = $url['host']; $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $deliveryHost); if (!file_exists($configFileName)) { MAX_Plugin::copyDefaultConfig($module, $package, $name); } // Create a new config class, parse the config array, and write to disk $oConfig = new Config(); $oConfig->parseConfig($aConfig, 'phpArray'); $result = $oConfig->writeConfig($configFileName, 'inifile'); if ($result == false || PEAR::isError($result)) { return false; } // Check the other possible host names, and write out the fake // configuration files if different $url = @parse_url('http://' . $conf['webpath']['admin']); if (isset($url['host'])) { $adminHost = $url['host']; if ($adminHost != $deliveryHost) { // Create fake file for this host $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $adminHost); $aConfig = array('realConfig' => $deliveryHost); $oConfig = new Config(); $oConfig->parseConfig($aConfig, 'phpArray'); if (!$oConfig->writeConfig($configFileName, 'inifile')) { return false; } } } $url = @parse_url('http://' . $conf['webpath']['deliverySSL']); if (isset($url['host'])) { $deliverySslHost = $url['host']; if ($deliverySslHost != $deliveryHost) { // Create fake file for this host $configFileName = MAX_Plugin::getConfigFileName($module, $package, $name, false, $deliverySslHost); $aConfig = array('realConfig' => $deliveryHost); $oConfig = new Config(); $oConfig->parseConfig($aConfig, 'phpArray'); if (!$oConfig->writeConfig($configFileName, 'inifile')) { return false; } } } return true; }