X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FConfig.php;h=c71ef68cd9ade1d07eeb6ebaf5a60338f8336339;hb=6fc14d530369740d27d6bd641369d4f5f5f04080;hp=ec799d7f75cda61bfe33bf4e3d228b5e4952cf85;hpb=38bedfbbcdd2a40e9f04f5753e0fd6f4fd513c21;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Config.php b/application/Config.php old mode 100755 new mode 100644 index ec799d7f..c71ef68c --- a/application/Config.php +++ b/application/Config.php @@ -1,129 +1,134 @@ - $value) { - $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($config['config'][$key], true).';'. PHP_EOL; - } - $configStr .= '?>'; - - if (!file_put_contents($config['config']['CONFIG_FILE'], $configStr) - || strcmp(file_get_contents($config['config']['CONFIG_FILE']), $configStr) != 0 - ) { - throw new Exception( - 'Shaarli could not create the config file. - Please make sure Shaarli has the right to write in the folder is it installed in.' - ); - } -} - -/** - * Milestone 0.9 - shaarli/Shaarli#41: options.php is not supported anymore. - * ==> if user is loggedIn, merge its content with config.php, then delete options.php. - * - * @param array $config contains all configuration fields. - * @param bool $isLoggedIn true if user is logged in. - * - * @return void - */ -function mergeDeprecatedConfig($config, $isLoggedIn) -{ - $config_file = $config['config']['CONFIG_FILE']; - - if (is_file($config['config']['DATADIR'].'/options.php') && $isLoggedIn) { - include $config['config']['DATADIR'].'/options.php'; - - // Load GLOBALS into config - foreach ($GLOBALS as $key => $value) { - $config[$key] = $value; - } - $config['config']['CONFIG_FILE'] = $config_file; - writeConfig($config, $isLoggedIn); - - unlink($config['config']['DATADIR'].'/options.php'); - } -} - -/** - * Exception used if a mandatory field is missing in given configuration. - */ -class MissingFieldConfigException extends Exception -{ - public $field; - - /** - * Construct exception. - * - * @param string $field field name missing. - */ - public function __construct($field) - { - $this->field = $field; - $this->message = 'Configuration value is required for '. $this->field; - } -} - -/** - * Exception used if an unauthorized attempt to edit configuration has been made. - */ -class UnauthorizedConfigException extends Exception -{ - /** - * Construct exception. - */ - public function __construct() - { - $this->message = 'You are not authorized to alter config.'; - } -} + $value) { + $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($config['config'][$key], true).';'. PHP_EOL; + } + + if (isset($config['plugins'])) { + foreach ($config['plugins'] as $key => $value) { + $configStr .= '$GLOBALS[\'plugins\'][\''. $key .'\'] = '.var_export($config['plugins'][$key], true).';'. PHP_EOL; + } + } + + if (!file_put_contents($config['config']['CONFIG_FILE'], $configStr) + || strcmp(file_get_contents($config['config']['CONFIG_FILE']), $configStr) != 0 + ) { + throw new Exception( + 'Shaarli could not create the config file. + Please make sure Shaarli has the right to write in the folder is it installed in.' + ); + } +} + +/** + * Milestone 0.9 - shaarli/Shaarli#41: options.php is not supported anymore. + * ==> if user is loggedIn, merge its content with config.php, then delete options.php. + * + * @param array $config contains all configuration fields. + * @param bool $isLoggedIn true if user is logged in. + * + * @return void + */ +function mergeDeprecatedConfig($config, $isLoggedIn) +{ + $config_file = $config['config']['CONFIG_FILE']; + + if (is_file($config['config']['DATADIR'].'/options.php') && $isLoggedIn) { + include $config['config']['DATADIR'].'/options.php'; + + // Load GLOBALS into config + foreach ($GLOBALS as $key => $value) { + $config[$key] = $value; + } + $config['config']['CONFIG_FILE'] = $config_file; + writeConfig($config, $isLoggedIn); + + unlink($config['config']['DATADIR'].'/options.php'); + } +} + +/** + * Exception used if a mandatory field is missing in given configuration. + */ +class MissingFieldConfigException extends Exception +{ + public $field; + + /** + * Construct exception. + * + * @param string $field field name missing. + */ + public function __construct($field) + { + $this->field = $field; + $this->message = 'Configuration value is required for '. $this->field; + } +} + +/** + * Exception used if an unauthorized attempt to edit configuration has been made. + */ +class UnauthorizedConfigException extends Exception +{ + /** + * Construct exception. + */ + public function __construct() + { + $this->message = 'You are not authorized to alter config.'; + } +}