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