From a2e688fcb2d463a5db700ebd013c783e3a8f4971 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 22:17:13 +0300 Subject: render headline-specific toolbar on the client --- plugins/mail/init.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'plugins/mail/init.php') diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 40d147fc9..829620ebc 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -15,12 +15,17 @@ class Mail extends Plugin { $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); $host->add_hook($host::HOOK_PREFS_TAB, $this); + $host->add_hook($host::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, $this); } function get_js() { return file_get_contents(dirname(__FILE__) . "/mail.js"); } + function hook_headline_toolbar_select_menu_item($feed_id, $is_cat) { + return "
".__('Forward by email')."
"; + } + function save() { $addresslist = $_POST["addresslist"]; @@ -32,7 +37,7 @@ class Mail extends Plugin { function hook_prefs_tab($args) { if ($args != "prefPrefs") return; - print "
mail ".__('Mail plugin')."\">"; print "

" . __("You can set predefined email addressed here (comma-separated list):") . "

"; -- cgit v1.2.3-54-g00ecf From 26d6b84a572b5cbd99acffc5ae727ea6d1be543a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov 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 'plugins/mail/init.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 1f43d7916cda16e9680b9087bda1f52934e8f25b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 14:32:06 +0300 Subject: replace print_hidden with hidden_tag --- classes/pref/feeds.php | 12 ++++++------ classes/pref/filters.php | 10 +++++----- plugins/af_proxy_http/init.php | 6 +++--- plugins/af_psql_trgm/init.php | 6 +++--- plugins/af_readability/init.php | 6 +++--- plugins/af_redditimgur/init.php | 6 +++--- plugins/mail/init.php | 16 ++++++++-------- plugins/note/init.php | 8 ++++---- plugins/nsfw/init.php | 6 +++--- 9 files changed, 38 insertions(+), 38 deletions(-) (limited to 'plugins/mail/init.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index d97081293..d087d026d 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -524,9 +524,9 @@ class Pref_Feeds extends Handler_Protected { $title = htmlspecialchars($row["title"]); - print_hidden("id", "$feed_id"); - print_hidden("op", "pref-feeds"); - print_hidden("method", "editSave"); + print \Controls\hidden_tag("id", "$feed_id"); + print \Controls\hidden_tag("op", "pref-feeds"); + print \Controls\hidden_tag("method", "editSave"); print "
".__("Feed")."
"; print "
"; @@ -821,9 +821,9 @@ class Pref_Feeds extends Handler_Protected { print "

"; - print_hidden("ids", "$feed_ids"); - print_hidden("op", "pref-feeds"); - print_hidden("method", "batchEditSave"); + print \Controls\hidden_tag("ids", "$feed_ids"); + print \Controls\hidden_tag("op", "pref-feeds"); + print \Controls\hidden_tag("method", "batchEditSave"); print "

".__("Feed")."
"; print "
"; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 23275a1d6..9b740753a 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -327,16 +327,16 @@ class Pref_Filters extends Handler_Protected { print ""; - print_hidden("op", "pref-filters"); + print \Controls\hidden_tag("op", "pref-filters"); if ($filter_id) { - print_hidden("id", "$filter_id"); - print_hidden("method", "editSave"); + print \Controls\hidden_tag("id", "$filter_id"); + print \Controls\hidden_tag("method", "editSave"); } else { - print_hidden("method", "add"); + print \Controls\hidden_tag("method", "add"); } - print_hidden("csrf_token", $_SESSION['csrf_token']); + print \Controls\hidden_tag("csrf_token", $_SESSION['csrf_token']); print "
".__("Caption")."
diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php index 3f26ca900..b82999281 100644 --- a/plugins/af_proxy_http/init.php +++ b/plugins/af_proxy_http/init.php @@ -218,9 +218,9 @@ class Af_Proxy_Http extends Plugin { } "; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "af_proxy_http"); + print \Controls\hidden_tag("op", "pluginhandler"); + print \Controls\hidden_tag("method", "save"); + print \Controls\hidden_tag("plugin", "af_proxy_http"); $proxy_all = $this->host->get($this, "proxy_all"); print_checkbox("proxy_all", $proxy_all); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 47ff98fc2..715e63927 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -157,9 +157,9 @@ class Af_Psql_Trgm extends Plugin { } "; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "af_psql_trgm"); + print \Controls\hidden_tag("op", "pluginhandler"); + print \Controls\hidden_tag("method", "save"); + print \Controls\hidden_tag("plugin", "af_psql_trgm"); print "

" . __("Global settings") . "

"; diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 4d21a831c..435864c21 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -87,9 +87,9 @@ class Af_Readability extends Plugin { } "; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "af_readability"); + print \Controls\hidden_tag("op", "pluginhandler"); + print \Controls\hidden_tag("method", "save"); + print \Controls\hidden_tag("plugin", "af_readability"); $enable_share_anything = $this->host->get($this, "enable_share_anything"); diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index b9a2db68d..b9891ea03 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -58,9 +58,9 @@ class Af_RedditImgur extends Plugin { } "; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "af_redditimgur"); + print \Controls\hidden_tag("op", "pluginhandler"); + print \Controls\hidden_tag("method", "save"); + print \Controls\hidden_tag("plugin", "af_redditimgur"); print "
"; print "
"; +
+ "; - - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("plugin", "mail"); - print \Controls\hidden_tag("method", "sendEmail"); $sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE id = ?"); @@ -107,9 +104,6 @@ class Mail extends Plugin { if (!$user_name) $user_name = $_SESSION['name']; - print \Controls\hidden_tag("from_email", "$user_email"); - print \Controls\hidden_tag("from_name", "$user_name"); - $tpl = new Templator(); $tpl->readTemplateFromFile("email_article_template.txt"); @@ -150,40 +144,58 @@ class Mail extends Plugin { $content = ""; $tpl->generateOutputToString($content); - print ""; - - print "
"; - $addresslist = explode(",", $this->host->get($this, "addresslist")); - print __('To:'); - - print ""; - - print \Controls\select_tag("destination", "", $addresslist, - ["style" => "width: 30em", "required" => 1, "dojoType" => "dijit.form.ComboBox"]); - - print "
"; - - print __('Subject:'); - - print ""; - - print ""; - - print "
"; - - print "
"; - - print ""; - - print ""; + ?> + +
+ + + + + + + + + + +
+
+ + "width: 380px", "required" => 1, "dojoType" => "dijit.form.ComboBox"]) ?> +
+
+ +
+
+ + +
+
+ + + +
+ + +
+ +
+ ".__('Forward by email').""; + return "
".__('Forward by email (mailto:)')."
"; } function get_js() { @@ -26,7 +26,7 @@ class MailTo extends Plugin { function hook_article_button($line) { return "mail_outline"; + title='".__('Forward by email (mailto:)')."'>mail_outline"; } function emailArticle() { @@ -42,7 +42,6 @@ class MailTo extends Plugin { //$tpl->setVariable('USER_EMAIL', $user_email, true); $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true); - $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND id IN ($ids_qmarks) AND owner_uid = ?"); @@ -70,25 +69,23 @@ class MailTo extends Plugin { $content = ""; $tpl->generateOutputToString($content); - $mailto_link = htmlspecialchars("mailto:?subject=".rawurlencode($subject). - "&body=".rawurlencode($content)); - - print __("Clicking the following link to invoke your mail client:"); - - print "
"; - print "". - __("Forward selected article(s) by email.").""; - print "
"; + $mailto_link = "mailto:?subject=".rawurlencode($subject)."&body=".rawurlencode($content); - print __("You should be able to edit the message before sending in your mail client."); + ?> - print "

"; +

+
+ + + +
+
- print ""; + - //return; + Date: Wed, 17 Feb 2021 21:44:21 +0300 Subject: * add (disabled) shortcut syntax for plugin methods * add controls shortcut for pluginhandler tags * add similar shortcut for frontend * allow plugins to selectively exclude their methods from CSRF checking --- backend.php | 11 +++++++++++ classes/plugin.php | 4 ++++ classes/pluginhandler.php | 2 +- classes/pluginhost.php | 13 ++++++++++++- include/controls.php | 12 +++++++++++- js/App.js | 3 +++ plugins/af_proxy_http/init.php | 4 +--- plugins/af_psql_trgm/init.php | 4 +--- plugins/af_readability/init.js | 2 +- plugins/af_readability/init.php | 6 ++---- plugins/af_redditimgur/init.php | 9 +++++---- plugins/mail/init.php | 12 ++++-------- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- plugins/note/init.php | 4 +--- plugins/note/note.js | 2 +- plugins/nsfw/init.php | 4 +--- plugins/share/share.js | 8 +++----- plugins/share/share_prefs.js | 2 +- 19 files changed, 65 insertions(+), 41 deletions(-) (limited to 'plugins/mail/init.php') diff --git a/backend.php b/backend.php index 9ecc22914..e64c6561f 100644 --- a/backend.php +++ b/backend.php @@ -88,6 +88,17 @@ 5 => __("Power User"), 10 => __("Administrator")); + // shortcut syntax for plugin methods (?op=plugin--pmethod&...params) + /* if (strpos($op, PluginHost::PUBLIC_METHOD_DELIMITER) !== false) { + list ($plugin, $pmethod) = explode(PluginHost::PUBLIC_METHOD_DELIMITER, $op, 2); + + // TODO: better implementation that won't modify $_REQUEST + $_REQUEST["plugin"] = $plugin; + $method = $pmethod; + $op = "pluginhandler"; + } */ + + // TODO: figure out if is this still needed $op = str_replace("-", "_", $op); $override = PluginHost::getInstance()->lookup_handler($op, $method); diff --git a/classes/plugin.php b/classes/plugin.php index 2416418cd..6c572467a 100644 --- a/classes/plugin.php +++ b/classes/plugin.php @@ -54,4 +54,8 @@ abstract class Plugin { return vsprintf($this->__($msgid), $args); } + + function csrf_ignore($method) { + return false; + } } diff --git a/classes/pluginhandler.php b/classes/pluginhandler.php index a0e60b4e6..608f80dcb 100644 --- a/classes/pluginhandler.php +++ b/classes/pluginhandler.php @@ -11,7 +11,7 @@ class PluginHandler extends Handler_Protected { if ($plugin) { if (method_exists($plugin, $method)) { - if (validate_csrf($csrf_token)) { + if (validate_csrf($csrf_token) || $plugin->csrf_ignore($method)) { $plugin->$method(); } else { user_error("Rejected ${plugin_name}->${method}(): invalid CSRF token.", E_USER_WARNING); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 097bf987c..065fa99c4 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -611,6 +611,17 @@ class PluginHost { $params)); } + // shortcut syntax (disabled for now) + /* function get_method_url(Plugin $sender, string $method, $params) { + return get_self_url_prefix() . "/backend.php?" . + http_build_query( + array_merge( + [ + "op" => strtolower(get_class($sender) . self::PUBLIC_METHOD_DELIMITER . $method), + ], + $params)); + } */ + // WARNING: endpoint in public.php, exposed to unauthenticated users function get_public_method_url(Plugin $sender, string $method, $params) { if ($sender->is_public_method($method)) { @@ -618,7 +629,7 @@ class PluginHost { http_build_query( array_merge( [ - "op" => strtolower(get_class($sender) . PluginHost::PUBLIC_METHOD_DELIMITER . $method), + "op" => strtolower(get_class($sender) . self::PUBLIC_METHOD_DELIMITER . $method), ], $params)); } else { diff --git a/include/controls.php b/include/controls.php index 4c60d94f3..d8506877b 100755 --- a/include/controls.php +++ b/include/controls.php @@ -11,6 +11,17 @@ return $rv; } + // shortcut syntax (disabled) + /* function pluginhandler_tags(\Plugin $plugin, string $method) { + return hidden_tag("op", strtolower(get_class($plugin) . \PluginHost::PUBLIC_METHOD_DELIMITER . $method)); + } */ + + function pluginhandler_tags(\Plugin $plugin, string $method) { + return hidden_tag("op", "pluginhandler") . + hidden_tag("plugin", strtolower(get_class($plugin))) . + hidden_tag("method", $method); + } + function button_tag(string $value, string $type, array $attributes = []) { return ""; } @@ -155,4 +166,3 @@ return $ret; } - diff --git a/js/App.js b/js/App.js index 9d8f6c275..aeca688b7 100644 --- a/js/App.js +++ b/js/App.js @@ -101,6 +101,9 @@ const App = { return dijit.getEnclosingWidget(elem.closest('.dijitDialog')); }, + getPhArgs(plugin, method, args = {}) { + return {...{op: "pluginhandler", plugin: plugin, method: method}, ...args}; + }, label_to_feed_id: function(label) { return this.LABEL_BASE_INDEX - 1 - Math.abs(label); }, diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php index 5804e450f..d6cee5fcd 100644 --- a/plugins/af_proxy_http/init.php +++ b/plugins/af_proxy_http/init.php @@ -229,9 +229,7 @@ class Af_Proxy_Http extends Plugin { } "; - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("method", "save"); - print \Controls\hidden_tag("plugin", "af_proxy_http"); + print \Controls\pluginhandler_tags($this, "save"); $proxy_all = sql_bool_to_bool($this->host->get($this, "proxy_all")); print \Controls\checkbox_tag("proxy_all", $proxy_all); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 1d83ce5e0..bfbbdf49c 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -157,9 +157,7 @@ class Af_Psql_Trgm extends Plugin { } "; - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("method", "save"); - print \Controls\hidden_tag("plugin", "af_psql_trgm"); + print \Controls\pluginhandler_tags($this, "save"); print "

" . __("Global settings") . "

"; diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js index 3155475cc..ff2d94e8b 100644 --- a/plugins/af_readability/init.js +++ b/plugins/af_readability/init.js @@ -16,7 +16,7 @@ Plugins.Af_Readability = { Notify.progress("Loading, please wait..."); - xhrJson("backend.php",{ op: "pluginhandler", plugin: "af_readability", method: "embed", param: id }, (reply) => { + xhrJson("backend.php", App.getPhArgs("af_readability", "embed", {id: id}), (reply) => { if (content && reply.content) { content.setAttribute(self.orig_attr_name, content.innerHTML); diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index aeef8cddc..43d064fc7 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -67,9 +67,7 @@ class Af_Readability extends Plugin {
- - - +
@@ -350,32 +346,28 @@ class Pref_Prefs extends Handler_Protected { - @@ -459,23 +451,20 @@ class Pref_Prefs extends Handler_Protected { - @@ -521,22 +510,20 @@ class Pref_Prefs extends Handler_Protected {
- @@ -806,26 +793,23 @@ class Pref_Prefs extends Handler_Protected { - @@ -956,20 +940,15 @@ class Pref_Prefs extends Handler_Protected { ?> diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 43d064fc7..a1f92815c 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -69,19 +69,15 @@ class Af_Readability extends Plugin { - +