summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-04-02 19:10:17 +0300
committerAndrew Dolgov <[email protected]>2023-04-02 19:10:17 +0300
commitc16489c50c6bfb399c2a8dd3ead74cc936164b90 (patch)
tree85d576d33370bcb2e7218631d490c295b0aa6592
parent6ff6984d04d41913123cbf687c62e782283682f8 (diff)
parent18e201aa31bcb43db0def3b940404f84b8304f8d (diff)
Merge branch 'master' of gitlab.tt-rss.org:tt-rss/plugins/ttrss-prefs-effective-config
-rw-r--r--README.md2
-rw-r--r--init.php230
2 files changed, 122 insertions, 110 deletions
diff --git a/README.md b/README.md
index 402ce2b..6bee511 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,6 @@ a bit easier to see what the live configuration is and how each value was determ
### Git
1. Clone the repo to **prefs_effective_config** in your tt-rss **plugins.local** directory:
- `git clone https://git.tt-rss.org/fox/ttrss-prefs-effective-config prefs_effective_config`
+ `git clone https://dev.tt-rss.org/tt-rss/ttrss-prefs-effective-config.git prefs_effective_config`
2. Enable the plugin @ Preferences → Plugins
diff --git a/init.php b/init.php
index 97882cf..008fe1c 100644
--- a/init.php
+++ b/init.php
@@ -1,55 +1,64 @@
<?php
-class Prefs_Effective_Config extends Plugin {
- private const CONFIG_KEYS_TO_MASK = ['DB_PASS'];
- private const PARAM_TYPE_TO_NAME = [
- Config::T_BOOL => 'boolean',
- Config::T_STRING => 'string',
- Config::T_INT => 'integer',
- ];
-
- /** @return array<null|float|string|bool> */
- function about() {
- return [
- null, // version
- 'Shows your effective tt-rss config @ Preferences --> System', // description
- 'wn', // author
- false, // is system
- 'https://dev.tt-rss.org/fox/ttrss-prefs-effective-config', // more info URL
- ];
- }
-
- /** @return int */
- function api_version() {
- return 2;
- }
-
- /**
- * @param PluginHost $host
- *
- * @return void
- * */
- function init($host) {
- $host->add_hook($host::HOOK_PREFS_TAB, $this);
- }
-
- /**
- * @param string $tab
- * @return void
- */
- function hook_prefs_tab($tab) {
- if ($tab != 'prefSystem' || !self::is_admin()) {
- return;
- }
+class Prefs_Effective_Config extends Plugin
+{
+ private const CONFIG_KEYS_TO_MASK = ['DB_PASS'];
+ private const PARAM_TYPE_TO_NAME = [
+ Config::T_BOOL => 'boolean',
+ Config::T_STRING => 'string',
+ Config::T_INT => 'integer',
+ ];
+
+ /** @return array<null|float|string|bool> */
+ function about()
+ {
+ return [
+ null, // version
+ 'Shows your effective tt-rss config @ Preferences --> System', // description
+ 'wn', // author
+ false, // is system
+ 'https://dev.tt-rss.org/fox/ttrss-prefs-effective-config', // more info URL
+ ];
+ }
+
+ /** @return int */
+ function api_version()
+ {
+ return 2;
+ }
+
+ /**
+ * @param PluginHost $host
+ *
+ * @return void
+ * */
+ function init($host)
+ {
+ $host->add_hook($host::HOOK_PREFS_TAB, $this);
+ }
+
+ /**
+ * @param string $tab
+ * @return void
+ */
+ function hook_prefs_tab($tab)
+ {
+ if ($tab != 'prefSystem' || !self::is_admin()) {
+ return;
+ }
?>
- <div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">subject</i> <?= __('Effective Config') ?>'>
- <script type='dojo/method' event='onSelected' args='evt'>
- if (!this.domNode.querySelector('.loading')) {
- return;
- }
-
- window.setTimeout(() => {
- xhr.json('backend.php', {op: 'pluginhandler', plugin: 'prefs_effective_config', method: 'get_effective_config'}, (reply) => {
- this.attr('content', `
+ <div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">subject</i> <?= __('Effective Config') ?>'>
+ <script type='dojo/method' event='onSelected' args='evt'>
+ if (!this.domNode.querySelector('.loading')) {
+ return;
+ }
+
+ window.setTimeout(() => {
+ xhr.json('backend.php', {
+ op: 'pluginhandler',
+ plugin: 'prefs_effective_config',
+ method: 'get_effective_config'
+ }, (reply) => {
+ this.attr('content', `
<style type='text/css'>
#config-items-list { text-align: left; border-spacing: 0; }
@@ -68,7 +77,7 @@ class Prefs_Effective_Config extends Plugin {
<p>
${__('Configuration item descriptions may be found in %s.')
.replace('%s',
- '<a target="_blank" rel="noreferrer noopener" href="https://git.tt-rss.org/fox/tt-rss.git/tree/classes/config.php">classes/config.php</a>')
+ '<a target="_blank" rel="noreferrer noopener" href="https://dev.tt-rss.org/tt-rss/tt-rss/src/branch/master/classes/config.php">classes/config.php</a>')
}
</p>
@@ -103,63 +112,66 @@ class Prefs_Effective_Config extends Plugin {
</tbody>
</table>
`);
- });
- }, 200);
- </script>
- <span class='loading'><?= __('Loading, please wait...') ?></span>
- </div>
+ });
+ }, 200);
+ </script>
+ <span class='loading'><?= __('Loading, please wait...') ?></span>
+ </div>
<?php
- }
-
- function get_effective_config(): void {
- if (!self::is_admin()) {
- print Errors::to_json(Errors::E_UNAUTHORIZED);
- return;
- }
-
- $cfg_instance = new Config();
- $cfg_rc = new ReflectionClass($cfg_instance);
-
- $envvar_prefix = $cfg_rc->getConstant('_ENVVAR_PREFIX');
- $defaults = $cfg_rc->getConstant('_DEFAULTS');
-
- $params_rc = $cfg_rc->getProperty('params');
- $params_rc->setAccessible(true);
-
- $params = [];
-
- foreach ($params_rc->getValue($cfg_instance) as $p => $v) {
- list ($pval, $ptype) = $v;
- $env_val = getenv($envvar_prefix . $p);
- list ($defval, $deftype) = $defaults[$cfg_rc->getConstant($p)];
- $should_redact = in_array($p, self::CONFIG_KEYS_TO_MASK);
-
- $params[] = [
- 'name' => $p,
- 'should_redact' => $should_redact,
- 'effective_val' => $should_redact ? 'redacted' : strval(self::maybe_bool_to_str($pval)),
- 'env_val' => $env_val ? ($should_redact ? 'redacted' : $env_val) : '',
- 'default_val' => strval($defval),
- 'type_hint' => self::PARAM_TYPE_TO_NAME[$ptype],
- ];
- }
-
- print json_encode([
- 'envvar_prefix' => $envvar_prefix,
- 'params' => $params,
- ]);
- }
-
- private static function is_admin(): bool {
- return ($_SESSION['access_level'] ?? UserHelper::ACCESS_LEVEL_DISABLED) >= UserHelper::ACCESS_LEVEL_ADMIN;
- }
-
- /**
- * @param bool|int|string $val
- *
- * @return int|string
- */
- private static function maybe_bool_to_str($val) {
- return $val === true ? 'true' : ($val === false ? 'false' : $val);
- }
+ }
+
+ function get_effective_config(): void
+ {
+ if (!self::is_admin()) {
+ print Errors::to_json(Errors::E_UNAUTHORIZED);
+ return;
+ }
+
+ $cfg_instance = new Config();
+ $cfg_rc = new ReflectionClass($cfg_instance);
+
+ $envvar_prefix = $cfg_rc->getConstant('_ENVVAR_PREFIX');
+ $defaults = $cfg_rc->getConstant('_DEFAULTS');
+
+ $params_rc = $cfg_rc->getProperty('params');
+ $params_rc->setAccessible(true);
+
+ $params = [];
+
+ foreach ($params_rc->getValue($cfg_instance) as $p => $v) {
+ list($pval, $ptype) = $v;
+ $env_val = getenv($envvar_prefix . $p);
+ list($defval, $deftype) = $defaults[$cfg_rc->getConstant($p)];
+ $should_redact = in_array($p, self::CONFIG_KEYS_TO_MASK);
+
+ $params[] = [
+ 'name' => $p,
+ 'should_redact' => $should_redact,
+ 'effective_val' => $should_redact ? 'redacted' : strval(self::maybe_bool_to_str($pval)),
+ 'env_val' => $env_val ? ($should_redact ? 'redacted' : $env_val) : '',
+ 'default_val' => strval($defval),
+ 'type_hint' => self::PARAM_TYPE_TO_NAME[$ptype],
+ ];
+ }
+
+ print json_encode([
+ 'envvar_prefix' => $envvar_prefix,
+ 'params' => $params,
+ ]);
+ }
+
+ private static function is_admin(): bool
+ {
+ return ($_SESSION['access_level'] ?? UserHelper::ACCESS_LEVEL_DISABLED) >= UserHelper::ACCESS_LEVEL_ADMIN;
+ }
+
+ /**
+ * @param bool|int|string $val
+ *
+ * @return int|string
+ */
+ private static function maybe_bool_to_str($val)
+ {
+ return $val === true ? 'true' : ($val === false ? 'false' : $val);
+ }
}