From 4988741e6250940b82d84f176324db6144e792f7 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Tue, 1 Feb 2022 16:40:56 +0300 Subject: [PATCH] + ability to see config params as json with #settings.json or ctrl+click on settings --- src/content/themes/default/style.css | 1 + src/includes/class.config.php | 16 ++++++++++++++-- src/includes/mytinytodo.js | 17 ++++++++++------- src/settings.php | 21 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/content/themes/default/style.css b/src/content/themes/default/style.css index 4ff9d7a..b08e4a9 100644 --- a/src/content/themes/default/style.css +++ b/src/content/themes/default/style.css @@ -486,6 +486,7 @@ li.mtt-item-hidden { display:none; } .mtt-settings-table .th { width:30%; font-weight: bold; } .mtt-settings-table .descr { font-size:0.8rem; font-weight:normal; color:#222; } .mtt-settings-table .in350 { min-width:350px; } +.mtt-settings-table textarea.in350 { height:400px; } .mtt-settings-table input { padding:3px; border:1px solid #ccc; border-radius:2px; } .mtt-settings-table select { padding:2px; border:1px solid #ccc; border-radius:2px; } .mtt-settings-table .form-bottom-buttons input { padding:4px; border:1px solid #ccc; border-radius:3px; background-color:#efefef; margin:2px; } diff --git a/src/includes/class.config.php b/src/includes/class.config.php index 84c2dfa..d12604e 100644 --- a/src/includes/class.config.php +++ b/src/includes/class.config.php @@ -122,7 +122,7 @@ class Config if (self::$noDatabase) { return; } - $j = self::requestDomain('config.json'); + $j = self::requestDefaultDomain(); foreach ($j as $key=>$val) { // Ignore params for database config if ( !isset(self::$dbparams[$key]) ) { @@ -202,7 +202,7 @@ class Config * @return array * @throws Exception */ - public static function requestDomain($key) + public static function requestDomain(string $key) { $db = DBConnection::instance(); $json = $db->sq("SELECT param_value FROM {$db->prefix}settings WHERE param_key = ?", array($key)); @@ -211,6 +211,18 @@ class Config return $j; } + + /** + * + * @return array + * @throws Exception + */ + public static function requestDefaultDomain() + { + return self::requestDomain('config.json'); + } + + /** * * @param string $key diff --git a/src/includes/mytinytodo.js b/src/includes/mytinytodo.js index 0af0037..1c48c9d 100644 --- a/src/includes/mytinytodo.js +++ b/src/includes/mytinytodo.js @@ -577,7 +577,7 @@ var mytinytodo = window.mytinytodo = _mtt = { // Settings $("#settings_btn").click(function(event){ - showSettings(); + showSettings( (event.metaKey || event.ctrlKey) ? 1 : 0 ); return false; }); @@ -653,7 +653,7 @@ var mytinytodo = window.mytinytodo = _mtt = { updateAccessStatus(); if (path.settings) { - showSettings(); + showSettings(path.settings == 'json' ? 1 : 0); } else if (path.search && path.list) { filter.search = path.search; @@ -893,6 +893,7 @@ var mytinytodo = window.mytinytodo = _mtt = { case "list": if(a[++i].match(/^-?\d+$/)) { p[s] = a[i]; } break; case "alltasks": p.list = '-1'; break; case "settings": p.settings = true; break; + case "settings.json": p.settings = 'json'; break; case "search": p.search = decodeURIComponent(a[++i]); break; } } @@ -925,8 +926,9 @@ var mytinytodo = window.mytinytodo = _mtt = { return _mtt.mttUrl + 'feed.php?list='+l.id; }, - urlForSettings: function() + urlForSettings: function(json = 0) { + if (json == 1) return '#settings.json'; return '#settings'; } @@ -2505,15 +2507,16 @@ function logout() Settings */ -function showSettings() +function showSettings(json = 0) { if (_mtt.pages.current && _mtt.pages.current.page == 'ajax' && _mtt.pages.current.pageClass == 'settings') { return false; } - $('#page_ajax').load(_mtt.mttUrl+'settings.php?ajax=yes', null, function(){ + var jsonParam = (json == 1) ? '&json=1' : ''; + $('#page_ajax').load(_mtt.mttUrl + 'settings.php?ajax=yes' + jsonParam, null, function(){ _mtt.pageSet('ajax','settings'); var newTitle = _mtt.lang.get('set_header') + ' - ' + _mtt.options.title; - updateHistoryState( { settings:1 }, _mtt.urlForSettings(), newTitle ); + updateHistoryState( { settings:1, settingsJson:json }, _mtt.urlForSettings(json), newTitle ); _mtt.doAction('settingsLoaded'); }) } @@ -2617,7 +2620,7 @@ function historyOnPopState(event) } else if (event.state.settings) { flag.dontChangeHistoryOnce = true; - showSettings(); + showSettings(event.state.settingsJson); } else { console.log("unexpected: nothing to pop"); diff --git a/src/settings.php b/src/settings.php index 1e94753..28e355c 100644 --- a/src/settings.php +++ b/src/settings.php @@ -13,10 +13,11 @@ $lang = Lang::instance(); if ( !is_logged() ) { die("Access denied!
Disable password protection or Log in."); } -check_token(); if(isset($_POST['save'])) { + check_token(); + $t = array(); $langs = getLangs(); Config::$params['lang']['options'] = array_keys($langs); @@ -134,6 +135,24 @@ header('Content-type:text/html; charset=utf-8');

+ +"; + $j = json_encode($j, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); +?> +
+
+
config.json
+
+
+
+ +