From 6af83e3881b3f38104027275913f7fc55251d020 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 12 Feb 2021 21:43:38 +0300 Subject: drop ENABLE_GZIP_OUTPUT; system prefs: load php info only if needed --- classes/pref/system.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/pref/system.php b/classes/pref/system.php index d91339698..a7512915a 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -25,6 +25,15 @@ class Pref_System extends Handler_Protected { $this->pdo->query("DELETE FROM ttrss_error_log"); } + function getphpinfo() { + ob_start(); + phpinfo(); + $info = ob_get_contents(); + ob_end_clean(); + + print preg_replace( '%^.*(.*).*$%ms','$1', $info); + } + private function log_viewer(int $page, int $severity) { $errno_values = []; @@ -167,14 +176,11 @@ class Pref_System extends Handler_Protected { print "
"; - ob_start(); - phpinfo(); - $info = ob_get_contents(); - ob_end_clean(); + print ""; - print "
"; - print preg_replace( '%^.*(.*).*$%ms','$1', $info); - print "
"; + print "
" . __("Loading, please wait...") . "
"; print "
"; # accordion pane -- cgit v1.2.3-54-g00ecf From aa63014073a42b123145db487276a8b6e366a510 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 13 Feb 2021 13:37:57 +0300 Subject: pref-labels index: use cleaner markup --- classes/pref/system.php | 56 +++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/pref/system.php b/classes/pref/system.php index a7512915a..763440d78 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -150,43 +150,35 @@ class Pref_System extends Handler_Protected { } print ""; + print ""; + print ""; } function index() { $severity = (int) ($_REQUEST["severity"] ?? E_USER_WARNING); $page = (int) ($_REQUEST["page"] ?? 0); - - print "
"; - print "
"; - - if (LOG_DESTINATION == "sql") { - - $this->log_viewer($page, $severity); - - } else { - print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); - } - - print "
"; # content pane - print "
"; # container - print ""; # accordion pane - - print "
"; - - print ""; - - print "
" . __("Loading, please wait...") . "
"; - - print "
"; # accordion pane - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem"); - - print ""; #container + ?> +
+
'> + log_viewer($page, $severity); + } else { + print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); + } + ?> +
+ +
'> + +
+
+ + run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem") ?> +
+ Date: Sat, 13 Feb 2021 13:50:53 +0300 Subject: prefs system: markup cleanup --- classes/pref/labels.php | 2 +- classes/pref/system.php | 164 ++++++++++++++++++++++++------------------------ 2 files changed, 84 insertions(+), 82 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/pref/labels.php b/classes/pref/labels.php index acaabb233..92acabd9e 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -139,7 +139,7 @@ class Pref_Labels extends Handler_Protected { $sth->execute([$caption, $old_caption, $_SESSION['uid']]); - print clean($_REQUEST["value"]); + print clean($_REQUEST["caption"]); } else { print $old_caption; } diff --git a/classes/pref/system.php b/classes/pref/system.php index 763440d78..994e024c7 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -31,7 +31,7 @@ class Pref_System extends Handler_Protected { $info = ob_get_contents(); ob_end_clean(); - print preg_replace( '%^.*(.*).*$%ms','$1', $info); + print preg_replace( '%^.*(.*).*$%ms','$1', (string)$info); } private function log_viewer(int $page, int $severity) { @@ -71,87 +71,89 @@ class Pref_System extends Handler_Protected { $total_pages = 0; } - print "
"; - - print "
"; - - print ""; - - $prev_page_disabled = $page <= 0 ? "disabled" : ""; - - print ""; - - print ""; - - $next_page_disabled = $page >= $total_pages ? "disabled" : ""; - - print ""; - - print ""; - - print "
"; - - print __("Severity:") . " "; - print_select_hash("severity", $severity, - [ - E_USER_ERROR => __("Errors"), - E_USER_WARNING => __("Warnings"), - E_USER_NOTICE => __("Everything") - ], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"'); - - print "
"; # pull-right - - print "
"; # toolbar - - print '
'; - - print ""; - - print " - - - - - - "; - - $sth = $this->pdo->prepare("SELECT - errno, errstr, filename, lineno, created_at, login, context - FROM - ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) - WHERE - $errno_filter_qpart - ORDER BY - ttrss_error_log.id DESC - LIMIT $limit OFFSET $offset"); - - $sth->execute($errno_values); - - while ($line = $sth->fetch()) { - print ""; - - foreach ($line as $k => $v) { - $line[$k] = htmlspecialchars($v); - } - - print ""; - print ""; - print ""; - print ""; - - print ""; - - print ""; - } + ?> +
+
+ + + + + + + + + + + +
+ + + __("Errors"), + E_USER_WARNING => __("Warnings"), + E_USER_NOTICE => __("Everything") + ], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"') ?> +
+
- print "
".__("Error")."".__("Filename")."".__("Message")."".__("User")."".__("Date")."
" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")" . $line["filename"] . ":" . $line["lineno"] . "" . $line["errstr"] . "\n" . $line["context"] . "" . - TimeHelper::make_local_datetime($line["created_at"], false) . "
"; - print "
"; - print "
"; +
+ + + + + + + + + + + + pdo->prepare("SELECT + errno, errstr, filename, lineno, created_at, login, context + FROM + ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) + WHERE + $errno_filter_qpart + ORDER BY + ttrss_error_log.id DESC + LIMIT $limit OFFSET $offset"); + + $sth->execute($errno_values); + + while ($line = $sth->fetch()) { + foreach ($line as $k => $v) { $line[$k] = htmlspecialchars($v); } + ?> + + + + + + + + +
+ + + +
+
+ + Date: Sat, 13 Feb 2021 16:07:52 +0300 Subject: minor fixes re: previous --- classes/pref/filters.php | 2 +- classes/pref/system.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index c80a10c64..c83299678 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -717,7 +717,7 @@ class Pref_Filters extends Handler_Protected {
+ value="">
diff --git a/classes/pref/system.php b/classes/pref/system.php index 994e024c7..72e15e4f3 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -146,7 +146,7 @@ class Pref_System extends Handler_Protected { - + -- cgit v1.2.3-54-g00ecf From 15fd23c374eb32c50733de1906065f552afbfbc4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 09:15:51 +0300 Subject: use shortcut echo syntax for php templates --- classes/feeds.php | 10 +++--- classes/handler/public.php | 44 +++++++++++------------ classes/pref/feeds.php | 74 +++++++++++++++++++------------------- classes/pref/filters.php | 20 +++++------ classes/pref/labels.php | 12 +++---- classes/pref/system.php | 42 +++++++++++----------- include/login_form.php | 34 +++++++++--------- index.php | 78 ++++++++++++++++++++--------------------- plugins/af_redditimgur/init.php | 4 +-- plugins/auth_internal/init.php | 18 +++++----- plugins/toggle_sidebar/init.php | 2 +- prefs.php | 28 +++++++-------- 12 files changed, 183 insertions(+), 183 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/feeds.php b/classes/feeds.php index 031a671ae..e6bd1459d 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -838,14 +838,14 @@ class Feeds extends Handler_Protected {
-

Feed Debugger: getFeedTitle($feed_id) ?>

+

Feed Debugger: getFeedTitle($feed_id) ?>

- + - +
- +
- +
diff --git a/classes/handler/public.php b/classes/handler/public.php index db8a924ad..481145606 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -519,7 +519,7 @@ class Handler_Public extends Handler { - <?php echo __("Share with Tiny Tiny RSS") ?> + <?= __("Share with Tiny Tiny RSS") ?>
- - + +
- - + +
- +
- +
- - - + + +
@@ -635,24 +635,24 @@ class Handler_Public extends Handler { -
+
- + " /> + required="1" value="" />
- + "/> + value=""/>

@@ -660,7 +660,7 @@ class Handler_Public extends Handler {
- +
@@ -781,7 +781,7 @@ class Handler_Public extends Handler { };
-

+

- +
- + Database Updater - +
-

+

diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 72a8344ad..6b5df0289 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1223,52 +1223,52 @@ class Pref_Feeds extends Handler_Protected {
+ value=""> +
- +
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
- +
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
-
+
- +
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
+ dojoType="dijit.MenuItem">
- - + +
" + autoExpand="" persist="true" model="feedModel" openOnClick="false"> @@ -1311,19 +1311,19 @@ class Pref_Feeds extends Handler_Protected { private function index_opml() { ?> -

+

-
+ + + + + diff --git a/classes/pref/labels.php b/classes/pref/labels.php index 22a2dddea..d182a0995 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -195,23 +195,23 @@ class Pref_Labels extends Handler_Protected {
- +
+ dojoType='dijit.MenuItem'>
+ dojoType='dijit.MenuItem'>
+ + + diff --git a/classes/pref/system.php b/classes/pref/system.php index 72e15e4f3..1adddf116 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -76,30 +76,30 @@ class Pref_System extends Handler_Protected {
- -
- + - - - - - + + + + + - + - - - + + + - + @@ -162,7 +162,7 @@ class Pref_System extends Handler_Protected { $page = (int) ($_REQUEST["page"] ?? 0); ?>
-
'> +
'> log_viewer($page, $severity); @@ -172,11 +172,11 @@ class Pref_System extends Handler_Protected { ?>
-
'> +
'> -
+
run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem") ?> diff --git a/include/login_form.php b/include/login_form.php index aec305b13..aa6a72260 100755 --- a/include/login_form.php +++ b/include/login_form.php @@ -92,29 +92,29 @@
-

+

-
- +
- + " /> + required="1" value="" />
- + "/> + value=""/>
- +
- +
@@ -143,11 +143,11 @@ +
- +
@@ -155,11 +155,11 @@ +
- +
0) { ?> @@ -167,7 +167,7 @@ @@ -177,7 +177,7 @@
- +
@@ -185,7 +185,7 @@
diff --git a/index.php b/index.php index fa23570ff..8bfca1af2 100644 --- a/index.php +++ b/index.php @@ -47,7 +47,7 @@ } ?> @@ -68,7 +68,7 @@ @@ -50,7 +50,7 @@ -
+ +
run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem") ?> diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index b09beb995..7a3d38d02 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -54,11 +54,7 @@ const Helpers = { }, }, System: { - getPHPInfo: function(widget) { - xhrPost("backend.php", {op: 'pref-system', method: 'getphpinfo'}, (transport) => { - widget.attr('content', transport.responseText); - }); - } + // }, EventLog: { log_page: 0, -- cgit v1.2.3-54-g00ecf From 0b7377238a556708035b0cd51a9e58693fb648f6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:50:46 +0300 Subject: add Handler_Administrative --- classes/handler/administrative.php | 11 +++++++++++ classes/pref/system.php | 13 +------------ classes/pref/users.php | 13 +------------ 3 files changed, 13 insertions(+), 24 deletions(-) create mode 100644 classes/handler/administrative.php (limited to 'classes/pref/system.php') diff --git a/classes/handler/administrative.php b/classes/handler/administrative.php new file mode 100644 index 000000000..52dfed8b7 --- /dev/null +++ b/classes/handler/administrative.php @@ -0,0 +1,11 @@ += 10) { + return true; + } + } + return false; + } +} diff --git a/classes/pref/system.php b/classes/pref/system.php index 14df6f8d1..2a97ec6f0 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -1,20 +1,9 @@ Date: Mon, 15 Feb 2021 16:07:22 +0300 Subject: prefs: unify naming --- classes/handler/public.php | 2 +- classes/pref/filters.php | 32 ++++++++++++++++---------------- classes/pref/prefs.php | 20 ++++++++++---------- classes/pref/system.php | 4 ++-- classes/pref/users.php | 8 ++++---- classes/rpc.php | 2 +- classes/userhelper.php | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/handler/public.php b/classes/handler/public.php index b11c8ba04..ea2a0c5ef 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -950,7 +950,7 @@ class Handler_Public extends Handler { WHERE id = ?"); $sth->execute([$id]); - Pref_Users::resetUserPassword($id, true); + Pref_Users::_reset_password($id, true); print "

"."Completed."."

"; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 62bcb8f59..95f0fcfc0 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -162,7 +162,7 @@ class Pref_Filters extends Handler_Protected { print json_encode($rv); } - private function getfilterrules_list($filter_id) { + private function _get_rules_list($filter_id) { $sth = $this->pdo->prepare("SELECT reg_exp, inverse, match_on, @@ -250,7 +250,7 @@ class Pref_Filters extends Handler_Protected { while ($line = $sth->fetch()) { - $name = $this->getFilterName($line["id"]); + $name = $this->_get_name($line["id"]); $match_ok = false; if ($filter_search) { @@ -292,7 +292,7 @@ class Pref_Filters extends Handler_Protected { $filter['checkbox'] = false; $filter['last_triggered'] = $line["last_triggered"] ? TimeHelper::make_local_datetime($line["last_triggered"], false) : null; $filter['enabled'] = sql_bool_to_bool($line["enabled"]); - $filter['rules'] = $this->getfilterrules_list($line['id']); + $filter['rules'] = $this->_get_rules_list($line['id']); if (!$filter_search || $match_ok) { array_push($folder['items'], $filter); @@ -391,7 +391,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars((string)json_encode($line)); print "
  • - ".$this->getRuleName($line)."". + ".$this->_get_rule_name($line)."". format_hidden("rule[]", $data)."
  • "; } } @@ -433,7 +433,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars((string)json_encode($line)); print "
  • - ".$this->getActionName($line)."". + ".$this->_get_action_name($line)."". format_hidden("action[]", $data)."
  • "; } } @@ -482,7 +482,7 @@ class Pref_Filters extends Handler_Protected { } } - private function getRuleName($rule) { + private function _get_rule_name($rule) { if (!$rule) $rule = json_decode(clean($_REQUEST["rule"]), true); $feeds = $rule["feed_id"]; @@ -523,10 +523,10 @@ class Pref_Filters extends Handler_Protected { } function printRuleName() { - print $this->getRuleName(json_decode(clean($_REQUEST["rule"]), true)); + print $this->_get_rule_name(json_decode(clean($_REQUEST["rule"]), true)); } - private function getActionName($action) { + private function _get_action_name($action) { $sth = $this->pdo->prepare("SELECT description FROM ttrss_filter_actions WHERE id = ?"); $sth->execute([(int)$action["action_id"]]); @@ -561,7 +561,7 @@ class Pref_Filters extends Handler_Protected { } function printActionName() { - print $this->getActionName(json_decode(clean($_REQUEST["action"]), true)); + print $this->_get_action_name(json_decode(clean($_REQUEST["action"]), true)); } function editSave() { @@ -581,7 +581,7 @@ class Pref_Filters extends Handler_Protected { $sth->execute([$enabled, $match_any_rule, $inverse, $title, $filter_id, $_SESSION['uid']]); - $this->saveRulesAndActions($filter_id); + $this->_save_rules_and_actions($filter_id); $this->pdo->commit(); } @@ -596,7 +596,7 @@ class Pref_Filters extends Handler_Protected { $sth->execute(array_merge($ids, [$_SESSION['uid']])); } - private function saveRulesAndActions($filter_id) + private function _save_rules_and_actions($filter_id) { $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?"); @@ -696,7 +696,7 @@ class Pref_Filters extends Handler_Protected { if ($row = $sth->fetch()) { $filter_id = $row['id']; - $this->saveRulesAndActions($filter_id); + $this->_save_rules_and_actions($filter_id); } $this->pdo->commit(); @@ -941,7 +941,7 @@ class Pref_Filters extends Handler_Protected { print ""; } - private function getFilterName($id) { + private function _get_name($id) { $sth = $this->pdo->prepare( "SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions @@ -970,7 +970,7 @@ class Pref_Filters extends Handler_Protected { $actions = ""; if ($line = $sth->fetch()) { - $actions = $this->getActionName($line); + $actions = $this->_get_action_name($line); $num_actions -= 1; } @@ -1012,12 +1012,12 @@ class Pref_Filters extends Handler_Protected { $this->pdo->commit(); - $this->optimizeFilter($base_id); + $this->_optimize($base_id); } } - private function optimizeFilter($id) { + private function _optimize($id) { $this->pdo->beginTransaction(); diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 6e4deb223..81b7767eb 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -268,7 +268,7 @@ class Pref_Prefs extends Handler_Protected { AND owner_uid = :uid"); $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); - $this->initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); + $this->_init_user_prefs($_SESSION["uid"], $_SESSION["profile"]); echo __("Your preferences are now set to default values."); } @@ -588,9 +588,9 @@ class Pref_Prefs extends Handler_Protected { if ($profile) { print_notice(__("Some preferences are only available in default profile.")); - $this->initialize_user_prefs($_SESSION["uid"], $profile); + $this->_init_user_prefs($_SESSION["uid"], $profile); } else { - $this->initialize_user_prefs($_SESSION["uid"]); + $this->_init_user_prefs($_SESSION["uid"]); } $prefs_available = []; @@ -621,7 +621,7 @@ class Pref_Prefs extends Handler_Protected { } $pref_name = $line["pref_name"]; - $short_desc = $this->getShortDesc($pref_name); + $short_desc = $this->_get_short_desc($pref_name); if (!$short_desc) continue; @@ -629,7 +629,7 @@ class Pref_Prefs extends Handler_Protected { $prefs_available[$pref_name] = [ 'type_name' => $line["type_name"], 'value' => $line['value'], - 'help_text' => $this->getHelpText($pref_name), + 'help_text' => $this->_get_help_text($pref_name), 'short_desc' => $short_desc ]; } @@ -1318,14 +1318,14 @@ class Pref_Prefs extends Handler_Protected { } - private function getShortDesc($pref_name) { + private function _get_short_desc($pref_name) { if (isset($this->pref_help[$pref_name][0])) { return $this->pref_help[$pref_name][0]; } return ""; } - private function getHelpText($pref_name) { + private function _get_help_text($pref_name) { if (isset($this->pref_help[$pref_name][1])) { return $this->pref_help[$pref_name][1]; } @@ -1380,7 +1380,7 @@ class Pref_Prefs extends Handler_Protected { encryptAppPassword($new_password); + $new_password_hash = $this->_encrypt_app_password($new_password); print_warning(T_sprintf("Generated password %s for %s. Please remember it for future reference.", $new_password, $title)); @@ -1413,7 +1413,7 @@ class Pref_Prefs extends Handler_Protected { $this->appPasswordList(); } - static function initialize_user_prefs($uid, $profile = false) { + static function _init_user_prefs($uid, $profile = false) { if (get_schema_version() < 63) $profile_qpart = ""; diff --git a/classes/pref/system.php b/classes/pref/system.php index 2a97ec6f0..f0a5f7b7f 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -23,7 +23,7 @@ class Pref_System extends Handler_Administrative { print preg_replace( '%^.*(.*).*$%ms','$1', (string)$info); } - private function log_viewer(int $page, int $severity) { + private function _log_viewer(int $page, int $severity) { $errno_values = []; switch ($severity) { @@ -154,7 +154,7 @@ class Pref_System extends Handler_Administrative {
    '> log_viewer($page, $severity); + $this->_log_viewer($page, $severity); } else { print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); } diff --git a/classes/pref/users.php b/classes/pref/users.php index bc125d0ce..d2dd06fd8 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -166,7 +166,7 @@ class Pref_Users extends Handler_Administrative { } } - static function resetUserPassword($uid, $format_output = false) { + static function _reset_password($uid, $format_output = false) { $pdo = Db::pdo(); @@ -199,7 +199,7 @@ class Pref_Users extends Handler_Administrative { function resetPass() { $uid = clean($_REQUEST["id"]); - self::resetUserPassword($uid); + self::_reset_password($uid); } function index() { @@ -220,7 +220,7 @@ class Pref_Users extends Handler_Administrative { $sort = "login"; } - $sort = $this->validate_field($sort, + $sort = $this->_validate_field($sort, ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); if ($sort != "login") $sort = "$sort DESC"; @@ -314,7 +314,7 @@ class Pref_Users extends Handler_Administrative { Date: Tue, 16 Feb 2021 14:23:00 +0300 Subject: add namespaced controls with unified naming; deprecated old-style control shortcuts --- classes/feeds.php | 22 ++- classes/handler/public.php | 4 +- classes/pref/feeds.php | 27 ++-- classes/pref/filters.php | 21 +-- classes/pref/prefs.php | 41 +++-- classes/pref/system.php | 4 +- include/controls.php | 383 +++++++++++--------------------------------- include/controls_compat.php | 312 ++++++++++++++++++++++++++++++++++++ include/functions.php | 1 + include/login_form.php | 2 +- plugins/mail/init.php | 2 +- 11 files changed, 470 insertions(+), 349 deletions(-) create mode 100644 include/controls_compat.php (limited to 'classes/pref/system.php') diff --git a/classes/feeds.php b/classes/feeds.php index f3ce1e48b..aa1f889e0 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -583,7 +583,7 @@ class Feeds extends Handler_Protected { function subscribeToFeed() { print json_encode([ - "cat_select" => format_feed_cat_select("cat", false, 'dojoType="fox.form.Select"') + "cat_select" => \Controls\select_feeds_cats("cat") ]); } @@ -607,8 +607,8 @@ class Feeds extends Handler_Protected { if (DB_TYPE == "pgsql") { print "
    "; print ""; - print_select("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), - "dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\""); + print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), + "title=\"".__('Used for word stemming')."\""); print "
    "; } @@ -668,6 +668,15 @@ class Feeds extends Handler_Protected { display : none; } + - - + +
    diff --git a/classes/pref/system.php b/classes/pref/system.php index f0a5f7b7f..d3b733364 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -90,12 +90,12 @@ class Pref_System extends Handler_Administrative {
    - __("Errors"), E_USER_WARNING => __("Warnings"), E_USER_NOTICE => __("Everything") - ], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"') ?> + ], 'onchange="Helpers.EventLog.refresh()"', "severity") ?>
    diff --git a/include/controls.php b/include/controls.php index f706931db..34a4af1f2 100755 --- a/include/controls.php +++ b/include/controls.php @@ -1,326 +1,133 @@ "; - foreach ($values as $v) { - if ($v == $default) - $sel = "selected=\"1\""; - else - $sel = ""; + $rv = ""; -} + $rv .= ""; + } -function print_select_hash($id, $default, $values, $attributes = "", $name = "") { - if (!$name) $name = $id; + $rv .= ""; - print ""; -} + $values = []; -function format_hidden($name, $value) { - return ""; -} + while ($row = $sth->fetch()) { + array_push($values, $row["caption"]); + } -function print_hidden($name, $value) { - print format_hidden($name, $value); -} + return select_tag($name, $value, $values, $attributes, $id); + } -function format_checkbox($id, $checked, $value = "", $attributes = "") { - $checked_str = $checked ? "checked" : ""; - $value_str = $value ? "value=\"$value\"" : ""; + function select_hash(string $name, $value, array $values, string $attributes = "", string $id = "") { + $dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; - return ""; -} + $rv = ""; - if ($v == $default) - $sel = "checked"; - else - $sel = ""; + return $rv; + } - if ($v == $true_is) { - $sel .= " value=\"1\""; - } else { - $sel .= " value=\"0\""; - } + function hidden_tag(string $name, string $value) { + return ""; + } - print " $v "; + function checkbox_tag(string $name, bool $checked, string $value = "", string $attributes = "", string $id = "") { + $is_checked = $checked ? "checked" : ""; + $value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : ""; - } -} + return ""; + } -function print_feed_multi_select($id, $default_ids = [], - $attributes = "", $include_all_feeds = true, - $root_id = null, $nest_level = 0) { + function select_feeds_cats(string $name, int $default_id = null, string $attributes = "", + bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = "") { - $pdo = Db::pdo(); + $ret = ""; - print_r(in_array("CAT:6",$default_ids)); + if (!$root_id) { + $ret .= ""; - if ($include_all_feeds) { - $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; - print ""; - } - } + $pdo = \Db::pdo(); - if (get_pref('ENABLE_FEED_CATS')) { + if (!$root_id) $root_id = null; - if (!$root_id) $root_id = null; + $sth = $pdo->prepare("SELECT id,title, + (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE + c2.parent_cat = ttrss_feed_categories.id) AS num_children + FROM ttrss_feed_categories + WHERE owner_uid = :uid AND + (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); + $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); - $sth = $pdo->prepare("SELECT id,title, - (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE - c2.parent_cat = ttrss_feed_categories.id) AS num_children - FROM ttrss_feed_categories - WHERE owner_uid = :uid AND - (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); + $found = 0; - $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); + while ($line = $sth->fetch()) { + ++$found; - while ($line = $sth->fetch()) { + if ($line["id"] == $default_id) { + $is_selected = "selected=\"1\""; + } else { + $is_selected = ""; + } - for ($i = 0; $i < $nest_level; $i++) - $line["title"] = " " . $line["title"]; + for ($i = 0; $i < $nest_level; $i++) + $line["title"] = " " . $line["title"]; - $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; + if ($line["title"]) + $ret .= sprintf("", + $line["id"], htmlspecialchars($line["title"])); - printf("", - $line["id"], htmlspecialchars($line["title"])); + if ($line["num_children"] > 0) + $ret .= select_feeds_cats($id, $default_id, $attributes, + $include_all_cats, $line["id"], $nest_level+1, $id); + } - if ($line["num_children"] > 0) - print_feed_multi_select($id, $default_ids, $attributes, - $include_all_feeds, $line["id"], $nest_level+1); + if (!$root_id) { + if ($include_all_cats) { + if ($found > 0) { + $ret .= ""; + } - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); + if ($default_id == 0) { + $is_selected = "selected=\"1\""; + } else { + $is_selected = ""; + } - $f_sth->execute([$line['id'], $_SESSION['uid']]); + $ret .= ""; + } + $ret .= ""; + } - while ($fline = $f_sth->fetch()) { - $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; + return $ret; + } - $fline["title"] = " " . $fline["title"]; - - for ($i = 0; $i < $nest_level; $i++) - $fline["title"] = " " . $fline["title"]; - - printf("", - $fline["id"], htmlspecialchars($fline["title"])); - } - } - - if (!$root_id) { - $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; - - printf("", - __("Uncategorized")); - - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); - $f_sth->execute([$_SESSION['uid']]); - - while ($fline = $f_sth->fetch()) { - $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; - - $fline["title"] = " " . $fline["title"]; - - for ($i = 0; $i < $nest_level; $i++) - $fline["title"] = " " . $fline["title"]; - - printf("", - $fline["id"], htmlspecialchars($fline["title"])); - } - } - - } else { - $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE owner_uid = ? ORDER BY title"); - $sth->execute([$_SESSION['uid']]); - - while ($line = $sth->fetch()) { - - $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; - - printf("", - $line["id"], htmlspecialchars($line["title"])); - } - } - - if (!$root_id) { - print ""; - } -} - -function print_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, - $root_id = null, $nest_level = 0) { - - print format_feed_cat_select($id, $default_id, $attributes, $include_all_cats, $root_id, $nest_level); -} - -function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, - $root_id = null, $nest_level = 0) { - - $ret = ""; - - if (!$root_id) { - $ret .= ""; - } - - return $ret; -} - -function stylesheet_tag($filename, $id = false) { - $timestamp = filemtime($filename); - - $id_part = $id ? "id=\"$id\"" : ""; - - return "\n"; -} - -function javascript_tag($filename) { - $query = ""; - - if (!(strpos($filename, "?") === false)) { - $query = substr($filename, strpos($filename, "?")+1); - $filename = substr($filename, 0, strpos($filename, "?")); - } - - $timestamp = filemtime($filename); - - if ($query) $timestamp .= "&$query"; - - return "\n"; -} - -function format_warning($msg, $id = "") { - return "
    $msg
    "; -} - -function format_notice($msg, $id = "") { - return "
    $msg
    "; -} - -function format_error($msg, $id = "") { - return "
    $msg
    "; -} - -function print_notice($msg) { - return print format_notice($msg); -} - -function print_warning($msg) { - return print format_warning($msg); -} - -function print_error($msg) { - return print format_error($msg); -} - -function print_label_select($name, $value, $attributes = "") { - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 - WHERE owner_uid = ? ORDER BY caption"); - $sth->execute([$_SESSION['uid']]); - - print ""; - - -} diff --git a/include/controls_compat.php b/include/controls_compat.php new file mode 100644 index 000000000..3d2779b08 --- /dev/null +++ b/include/controls_compat.php @@ -0,0 +1,312 @@ +"; + foreach ($values as $v) { + if ($v == $default) + $sel = "selected=\"1\""; + else + $sel = ""; + + $v = trim($v); + + print ""; + } + print ""; +} + +function print_select_hash($id, $default, $values, $attributes = "", $name = "") { + if (!$name) $name = $id; + + print ""; +} + +function format_hidden($name, $value) { + return ""; +} + +function print_hidden($name, $value) { + print format_hidden($name, $value); +} + +function format_checkbox($id, $checked, $value = "", $attributes = "") { + $checked_str = $checked ? "checked" : ""; + $value_str = $value ? "value=\"$value\"" : ""; + + return ""; +} + +function print_checkbox($id, $checked, $value = "", $attributes = "") { + print format_checkbox($id, $checked, $value, $attributes); +} + +function format_button($type, $value, $attributes = "") { + return ""; +} + +function print_button($type, $value, $attributes = "") { + print format_button($type, $value, $attributes); +} + +function print_feed_multi_select($id, $default_ids = [], + $attributes = "", $include_all_feeds = true, + $root_id = null, $nest_level = 0) { + + $pdo = Db::pdo(); + + print_r(in_array("CAT:6",$default_ids)); + + if (!$root_id) { + print ""; + } +} + +function print_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, + $root_id = null, $nest_level = 0) { + + print format_feed_cat_select($id, $default_id, $attributes, $include_all_cats, $root_id, $nest_level); +} + +function format_feed_cat_select($id, $default_id, $attributes, $include_all_cats = true, + $root_id = null, $nest_level = 0) { + + $ret = ""; + + if (!$root_id) { + $ret .= ""; + } + + return $ret; +} + +function stylesheet_tag($filename, $id = false) { + $timestamp = filemtime($filename); + + $id_part = $id ? "id=\"$id\"" : ""; + + return "\n"; +} + +function javascript_tag($filename) { + $query = ""; + + if (!(strpos($filename, "?") === false)) { + $query = substr($filename, strpos($filename, "?")+1); + $filename = substr($filename, 0, strpos($filename, "?")); + } + + $timestamp = filemtime($filename); + + if ($query) $timestamp .= "&$query"; + + return "\n"; +} + +function format_warning($msg, $id = "") { + return "
    $msg
    "; +} + +function format_notice($msg, $id = "") { + return "
    $msg
    "; +} + +function format_error($msg, $id = "") { + return "
    $msg
    "; +} + +function print_notice($msg) { + return print format_notice($msg); +} + +function print_warning($msg) { + return print format_warning($msg); +} + +function print_error($msg) { + return print format_error($msg); +} + +function print_label_select($name, $value, $attributes = "") { + + $pdo = Db::pdo(); + + $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 + WHERE owner_uid = ? ORDER BY caption"); + $sth->execute([$_SESSION['uid']]); + + print ""; + + +} diff --git a/include/functions.php b/include/functions.php index 4557c0411..174ef39f0 100644 --- a/include/functions.php +++ b/include/functions.php @@ -203,6 +203,7 @@ require_once 'db-prefs.php'; require_once 'controls.php'; + require_once 'controls_compat.php'; define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); ini_set('user_agent', SELF_USER_AGENT); diff --git a/include/login_form.php b/include/login_form.php index aa6a72260..798efa624 100755 --- a/include/login_form.php +++ b/include/login_form.php @@ -97,7 +97,7 @@
    - + diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 829620ebc..b1263ece5 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -160,7 +160,7 @@ class Mail extends Plugin { style=\"width : 30em;\" name=\"destination\" id=\"emailArticleDlg_destination\">"; */ - print_select("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); + print \Controls\select_tag("destination", "", $addresslist, 'style="width: 30em" dojoType="dijit.form.ComboBox"'); /* print "
    "; */ -- cgit v1.2.3-54-g00ecf From bdbbdbb0eddd125bec167da5f42bbd95c770151f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 16:59:21 +0300 Subject: rework controls to accept parameters as array --- classes/feeds.php | 2 +- classes/pref/feeds.php | 15 +++++++-------- classes/pref/filters.php | 8 ++++---- classes/pref/prefs.php | 4 ++-- classes/pref/system.php | 2 +- include/controls.php | 47 ++++++++++++++++++++++++++++++----------------- include/login_form.php | 3 ++- plugins/mail/init.php | 3 ++- 8 files changed, 49 insertions(+), 35 deletions(-) (limited to 'classes/pref/system.php') diff --git a/classes/feeds.php b/classes/feeds.php index 4e6fdbaf8..43c8bf584 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -608,7 +608,7 @@ class Feeds extends Handler_Protected { print "
    "; print ""; print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), - "title=\"".__('Used for word stemming')."\""); + ["title" => __('Used for word stemming')]); print "
    "; } diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 636f2d69b..ce2d321bd 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -644,8 +644,10 @@ class Pref_Feeds extends Handler_Protected { $local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ]; } - print \Controls\select_hash("purge_interval", $purge_interval, $local_purge_intervals, - ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); + print \Controls\select_hash("purge_interval", + $purge_interval, + $local_purge_intervals, + (FORCE_ARTICLE_PURGE == 0) ? [] : ["disabled" => 1]); print ""; @@ -815,8 +817,6 @@ class Pref_Feeds extends Handler_Protected { print_notice("Enable the options you wish to apply using checkboxes on the right:"); - print "

    "; - print \Controls\hidden_tag("ids", "$feed_ids"); print \Controls\hidden_tag("op", "pref-feeds"); print \Controls\hidden_tag("method", "batchEditSave"); @@ -846,8 +846,7 @@ class Pref_Feeds extends Handler_Protected { print "

    "; print " "; - print \Controls\select_tag("feed_language", "", $this::get_ts_languages(), - 'disabled="1"'); + print \Controls\select_tag("feed_language", "", $this::get_ts_languages(), ["disabled"=> 1]); $this->batch_edit_cbox("feed_language"); @@ -868,7 +867,7 @@ class Pref_Feeds extends Handler_Protected { $local_update_intervals = $update_intervals; $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); - print \Controls\select_hash("update_interval", "", $local_update_intervals, 'disabled="1"'); + print \Controls\select_hash("update_interval", "", $local_update_intervals, ["disabled" => 1]); $this->batch_edit_cbox("update_interval"); @@ -890,7 +889,7 @@ class Pref_Feeds extends Handler_Protected { else $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); - print \Controls\select_hash("purge_interval", "", $local_purge_intervals, 'disabled="1"'); + print \Controls\select_hash("purge_interval", "", $local_purge_intervals, ["disabled" => 1]); $this->batch_edit_cbox("purge_interval"); diff --git a/classes/pref/filters.php b/classes/pref/filters.php index caefb1ea7..e9c58cc3e 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -894,7 +894,7 @@ class Pref_Filters extends Handler_Protected { dojoType='fox.form.Select'");*/ print \Controls\select_labels("action_param_label", $action_param, - "style=\"$label_param_hidden\"", + ["style" => $label_param_hidden], "filterDlg_actionParamLabel"); $filter_actions = PluginHost::getInstance()->get_filter_actions(); @@ -909,16 +909,16 @@ class Pref_Filters extends Handler_Protected { } if (count($filter_action_hash) == 0) { - $filter_plugin_disabled = "disabled"; + $filter_plugin_disabled = ["disabled" => "1"]; $filter_action_hash["no-data"] = __("No actions available"); } else { - $filter_plugin_disabled = ""; + $filter_plugin_disabled = []; } print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash, - "style=\"$plugin_param_hidden\" $filter_plugin_disabled", + array_merge(["style" => $plugin_param_hidden], $filter_plugin_disabled), "filterDlg_actionParamPlugin"); print ""; diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index d8491995d..3bc8a9a9c 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -664,13 +664,13 @@ class Pref_Prefs extends Handler_Protected { if ($pref_name == "USER_LANGUAGE") { print \Controls\select_hash($pref_name, $value, get_translations(), - "style='width : 220px; margin : 0px'"); + ["style" => 'width : 220px; margin : 0px']); } else if ($pref_name == "USER_TIMEZONE") { $timezones = explode("\n", file_get_contents("lib/timezones.txt")); - print \Controls\select_tag($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); + print \Controls\select_tag($pref_name, $value, $timezones, ["dojoType" => "dijit.form.FilteringSelect"]); } else if ($pref_name == "BLACKLISTED_TAGS") { # TODO: other possible