]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/config/ConfigPhp.php
4 * Class ConfigPhp (ConfigIO implementation)
6 * Handle Shaarli's legacy PHP configuration file.
7 * Note: this is only designed to support the transition to JSON configuration.
9 class ConfigPhp
implements ConfigIO
12 * @var array List of config key without group.
14 public static $ROOT_KEYS = array(
22 'disablesessionprotection',
23 'privateLinkByDefault',
27 * Map legacy config keys with the new ones.
28 * If ConfigPhp is used, getting <newkey> will actually look for <legacykey>.
29 * The Updater will use this array to transform keys when switching to JSON.
31 * @var array current key => legacy key.
33 public static $LEGACY_KEYS_MAPPING = array(
34 'credentials.login' => 'login',
35 'credentials.hash' => 'hash',
36 'credentials.salt' => 'salt',
37 'resource.data_dir' => 'config.DATADIR',
38 'resource.config' => 'config.CONFIG_FILE',
39 'resource.datastore' => 'config.DATASTORE',
40 'resource.updates' => 'config.UPDATES_FILE',
41 'resource.log' => 'config.LOG_FILE',
42 'resource.update_check' => 'config.UPDATECHECK_FILENAME',
43 'resource.raintpl_tpl' => 'config.RAINTPL_TPL',
44 'resource.theme' => 'config.theme',
45 'resource.raintpl_tmp' => 'config.RAINTPL_TMP',
46 'resource.thumbnails_cache' => 'config.CACHEDIR',
47 'resource.page_cache' => 'config.PAGECACHE',
48 'resource.ban_file' => 'config.IPBANS_FILENAME',
49 'security.session_protection_disabled' => 'disablesessionprotection',
50 'security.ban_after' => 'config.BAN_AFTER',
51 'security.ban_duration' => 'config.BAN_DURATION',
52 'general.title' => 'title',
53 'general.timezone' => 'timezone',
54 'general.header_link' => 'titleLink',
55 'updates.check_updates' => 'config.ENABLE_UPDATECHECK',
56 'updates.check_updates_branch' => 'config.UPDATECHECK_BRANCH',
57 'updates.check_updates_interval' => 'config.UPDATECHECK_INTERVAL',
58 'privacy.default_private_links' => 'privateLinkByDefault',
59 'feed.rss_permalinks' => 'config.ENABLE_RSS_PERMALINKS',
60 'general.links_per_page' => 'config.LINKS_PER_PAGE',
61 'thumbnail.enable_thumbnails' => 'config.ENABLE_THUMBNAILS',
62 'thumbnail.enable_localcache' => 'config.ENABLE_LOCALCACHE',
63 'general.enabled_plugins' => 'config.ENABLED_PLUGINS',
64 'redirector.url' => 'redirector',
65 'redirector.encode_url' => 'config.REDIRECTOR_URLENCODE',
66 'feed.show_atom' => 'config.SHOW_ATOM',
67 'privacy.hide_public_links' => 'config.HIDE_PUBLIC_LINKS',
68 'privacy.hide_timestamps' => 'config.HIDE_TIMESTAMPS',
69 'security.open_shaarli' => 'config.OPEN_SHAARLI',
75 public function read($filepath)
77 if (! file_exists($filepath) || ! is_readable($filepath)) {
84 foreach (self
::$ROOT_KEYS as $key) {
85 $out[$key] = $GLOBALS[$key];
87 $out['config'] = $GLOBALS['config'];
88 $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array();
95 public function write($filepath, $conf)
97 $configStr = '<?php '. PHP_EOL
;
98 foreach (self
::$ROOT_KEYS as $key) {
99 if (isset($conf[$key])) {
100 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL
;
104 // Store all $conf['config']
105 foreach ($conf['config'] as $key => $value) {
106 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL
;
109 if (isset($conf['plugins'])) {
110 foreach ($conf['plugins'] as $key => $value) {
111 $configStr .= '$GLOBALS[\'plugins\'][\''. $key .'\'] = '.var_export($conf['plugins'][$key], true).';'. PHP_EOL
;
115 if (!file_put_contents($filepath, $configStr)
116 || strcmp(file_get_contents($filepath), $configStr) != 0
118 throw new IOException(
120 'Shaarli could not create the config file.
121 Please make sure Shaarli has the right to write in the folder is it installed in.'
129 public function getExtension()