From 22fe9b54d2150e543338dbc7541f134c0a7c61f6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 13:32:09 +0300 Subject: [PATCH] feed editor: use client dialog --- classes/api.php | 2 +- classes/pref/feeds.php | 310 +---------------------------- js/CommonDialogs.js | 435 ++++++++++++++++++----------------------- 3 files changed, 196 insertions(+), 551 deletions(-) diff --git a/classes/api.php b/classes/api.php index 8c32967a2..03eea1927 100755 --- a/classes/api.php +++ b/classes/api.php @@ -843,7 +843,7 @@ class API extends Handler { $_REQUEST['force_show_empty'] = $include_empty; $this->_wrap(self::STATUS_OK, - array("categories" => $pf->makefeedtree())); + array("categories" => $pf->_makefeedtree())); } // only works for labels or uncategorized for the time being diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 2c275349b..cf9e7c95e 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1,7 +1,7 @@ makefeedtree()); + print json_encode($this->_makefeedtree()); } - function makefeedtree() { + function _makefeedtree() { if (clean($_REQUEST['mode'] ?? 0) != 2) $search = $_SESSION["prefs_feed_search"] ?? ""; @@ -500,7 +496,7 @@ class Pref_Feeds extends Handler_Protected { WHERE id = ?"); $sth->execute([$feed_id]); - $rc = 0; + $rc = Feeds::_get_icon($feed_id); } } } else { @@ -573,298 +569,6 @@ class Pref_Feeds extends Handler_Protected { } else { print json_encode(["error" => "FEED_NOT_FOUND"]); } - - return; - - if ($row = $sth->fetch()) { - print '
-
'; - - $title = htmlspecialchars($row["title"]); - - print \Controls\hidden_tag("id", "$feed_id"); - print \Controls\hidden_tag("op", "pref-feeds"); - print \Controls\hidden_tag("method", "editSave"); - - print "
".__("Feed")."
"; - print "
"; - - /* Title */ - - print "
"; - - print ""; - - print "
"; - - /* Feed URL */ - - $feed_url = htmlspecialchars($row["feed_url"]); - - print "
"; - - print " "; - print ""; - - if (!empty($row["last_error"])) { - print " error"; - } - - print "
"; - - /* Category */ - - if (get_pref('ENABLE_FEED_CATS')) { - print "
"; - - print " "; - - print \Controls\select_feeds_cats("cat_id", $row["cat_id"]); - - print "
"; - } - - /* Site URL */ - - $site_url = htmlspecialchars($row["site_url"]); - - print "
"; - - print " "; - print ""; - - print "
"; - - /* FTS Stemming Language */ - - if (DB_TYPE == "pgsql") { - $feed_language = $row["feed_language"]; - - if (!$feed_language) - $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); - - print "
"; - - print " "; - print \Controls\select_tag("feed_language", $feed_language, $this::get_ts_languages()); - - print "
"; - } - - print "
"; - - print "
".__("Update")."
"; - print "
"; - - /* Update Interval */ - - $update_interval = $row["update_interval"]; - - print "
"; - - print " "; - - $local_update_intervals = $update_intervals; - $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); - - print \Controls\select_hash("update_interval", $update_interval, $local_update_intervals); - - print "
"; - - /* Purge intl */ - - $purge_interval = $row["purge_interval"]; - - print "
"; - - print " "; - - if (FORCE_ARTICLE_PURGE == 0) { - $local_purge_intervals = $purge_intervals; - $default_purge_interval = get_pref("PURGE_OLD_DAYS"); - - if ($default_purge_interval > 0) - $local_purge_intervals[0] .= " " . T_nsprintf('(%d day)', '(%d days)', $default_purge_interval, $default_purge_interval); - else - $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); - - } else { - $purge_interval = FORCE_ARTICLE_PURGE; - $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 "
"; - - print "
"; - - $auth_login = htmlspecialchars($row["auth_login"]); - $auth_pass = htmlspecialchars($row["auth_pass"]); - - $auth_enabled = $auth_login !== '' || $auth_pass !== ''; - - $auth_style = $auth_enabled ? '' : 'display: none'; - print "
"; - print "
".__("Authentication")."
"; - print "
"; - - print "
"; - - print ""; - - print "
"; - - print ""; - - print "
"; - - print "
"; - - $auth_checked = $auth_enabled ? 'checked' : ''; - print ""; - - print '
'; - - print "
"; - - $include_in_digest = $row["include_in_digest"]; - - if ($include_in_digest) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $always_display_enclosures = $row["always_display_enclosures"]; - - if ($always_display_enclosures) { - $checked = "checked"; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $hide_images = $row["hide_images"]; - - if ($hide_images) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $cache_images = $row["cache_images"]; - - if ($cache_images) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $mark_unread_on_update = $row["mark_unread_on_update"]; - - if ($mark_unread_on_update) { - $checked = "checked"; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - print '
'; - - /* Icon */ - - print ""; - - print "
- - - - - - - -
"; - - print ""; - - print '
'; - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id); - - print "
"; - - $title = htmlspecialchars($title, ENT_QUOTES); - - print ""; - } } function editfeeds() { @@ -1036,7 +740,7 @@ class Pref_Feeds extends Handler_Protected { return $this->editsaveops(false); } - function editsaveops($batch) { + private function editsaveops($batch) { $feed_title = clean($_POST["title"]); $feed_url = clean($_POST["feed_url"]); @@ -1064,10 +768,6 @@ class Pref_Feeds extends Handler_Protected { $feed_language = clean($_POST["feed_language"]); if (!$batch) { - if (clean($_POST["need_auth"] ?? "") !== 'on') { - $auth_login = ''; - $auth_pass = ''; - } /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); $sth->execute([$feed_id]); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 5477e9ecd..704e797d3 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -11,72 +11,6 @@ const CommonDialogs = { const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); }, - removeFeedIcon: function(id) { - if (confirm(__("Remove stored feed icon?"))) { - Notify.progress("Removing feed icon...", true); - - const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; - - xhr.post("backend.php", query, () => { - Notify.info("Feed icon removed."); - - if (App.isPrefs()) - dijit.byId("feedTree").reload(); - else - Feeds.reload(); - - const icon = App.findAll(".feed-editor-icon")[0]; - - if (icon) - icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime()); - - }); - } - - return false; - }, - uploadFeedIcon: function() { - const file = App.byId("icon_file"); - - if (file.value.length == 0) { - alert(__("Please select an image file to upload.")); - } else if (confirm(__("Upload new icon for this feed?"))) { - Notify.progress("Uploading, please wait...", true); - - const xhr = new XMLHttpRequest(); - - xhr.open( 'POST', 'backend.php', true ); - xhr.onload = function () { - switch (parseInt(this.responseText)) { - case 0: - { - Notify.info("Upload complete."); - - if (App.isPrefs()) - dijit.byId("feedTree").reload(); - else - Feeds.reload(); - - const icon = App.findAll(".feed-editor-icon")[0]; - - if (icon) - icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime()); - - } - break; - case 1: - Notify.error("Upload failed: icon is too big."); - break; - case 2: - Notify.error("Upload failed."); - break; - } - }; - xhr.send(new FormData(App.byId("feed_icon_upload_form"))); - } - - return false; - }, subscribeToFeed: function() { xhr.json("backend.php", {op: "feeds", method: "subscribeToFeed"}, @@ -407,6 +341,86 @@ const CommonDialogs = { CommonDialogs.unsubscribeFeed(feed_id); } }, + uploadIcon: function(input) { + if (input.files.length != 0) { + const icon_file = input.files[0]; + + if (icon_file.type.indexOf("image/") == -1) { + alert(__("Please select an image file.")); + return; + } + + const fd = new FormData(); + fd.append('icon_file', icon_file) + fd.append('feed_id', feed_id); + fd.append('op', 'pref-feeds'); + fd.append('method', 'uploadIcon'); + fd.append('csrf_token', App.getInitParam("csrf_token")); + + const xhr = new XMLHttpRequest(); + + xhr.open( 'POST', 'backend.php', true ); + xhr.onload = function () { + console.log(this.responseText); + + // TODO: make a notice box within panel content + switch (parseInt(this.responseText)) { + case 1: + Notify.error("Upload failed: icon is too big."); + break; + case 2: + Notify.error("Upload failed."); + break; + default: + { + Notify.info("Upload complete."); + + if (App.isPrefs()) + dijit.byId("feedTree").reload(); + else + Feeds.reload(); + + const icon = dialog.domNode.querySelector(".feedIcon"); + + if (icon) { + icon.src = this.responseText; + icon.show(); + } + + input.value = ""; + } + } + }; + + xhr.send(fd); + + } + }, + removeIcon: function(id) { + if (confirm(__("Remove stored feed icon?"))) { + Notify.progress("Removing feed icon...", true); + + const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; + + xhr.post("backend.php", query, () => { + Notify.info("Feed icon removed."); + + if (App.isPrefs()) + dijit.byId("feedTree").reload(); + else + Feeds.reload(); + + const icon = dialog.domNode.querySelector(".feedIcon"); + + if (icon) { + icon.src = ""; + icon.hide(); + } + }); + } + + return false; + }, execute: function () { if (this.validate()) { Notify.progress("Saving data...", true); @@ -437,205 +451,136 @@ const CommonDialogs = { // for unsub prompt dialog.feed_title = feed.title; + // options tab + const options = { + include_in_digest: [ feed.include_in_digest, __('Include in e-mail digest') ], + always_display_enclosures: [ feed.always_display_enclosures, __('Always display image attachments') ], + hide_images: [ feed.hide_images, __('Do not embed media') ], + cache_images: [ feed.cache_images, __('Cache media') ], + mark_unread_on_update: [ feed.mark_unread_on_update, __('Mark updated articles as unread') ] + }; + dialog.attr('content', ` -
-
+
+
+
- ${App.FormFields.hidden_tag("id", feed_id)} - ${App.FormFields.hidden_tag("op", "pref-feeds")} - ${App.FormFields.hidden_tag("method", "editSave")} + ${App.FormFields.hidden_tag("id", feed_id)} + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("method", "editSave")} -
-
- -
+
+
+ +
-
- - +
+ + - ${feed.last_error ? - `error + ${feed.last_error ? + `error + ` : ""} +
+ + ${reply.cats.enabled ? + ` +
+ + ${reply.cats.select} +
` : ""} -
- ${reply.cats.enabled ? - `
- - ${reply.cats.select} + +
- ` : ""} -
- - -
+ ${reply.lang.enabled ? + ` +
+ + ${App.FormFields.select_tag("feed_language", + feed.feed_language ? feed.feed_language : reply.lang.default, + reply.lang.all)} +
+ ` : ""} + +
- ${reply.lang.enabled ? - `
- - ${App.FormFields.select_tag("feed_language", feed.feed_language, reply.lang.all)} + + ${App.FormFields.select_hash("update_interval", feed.update_interval, reply.intervals.update)}
- ` : ""} +
+ -
+ ${App.FormFields.select_hash("purge_interval", + feed.purge_interval, + reply.intervals.purge, + reply.force_purge ? {disabled: 1} : {})} -
- - ${App.FormFields.select_hash("update_interval", feed.update_interval, reply.intervals.update)} -
-
- +
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+
+ ${Object.keys(options).map((name) => + ` +
+ +
+ `).join("")} +
+
+
+
- ${App.FormFields.select_hash("purge_interval", - feed.purge_interval, - reply.intervals.purge, - reply.force_purge ? {disabled: 1} : {})} - - - -
-
-
-
- - -
-
- - -
-
-
-
- -
- - $include_in_digest = $row["include_in_digest"]; - - if ($include_in_digest) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $always_display_enclosures = $row["always_display_enclosures"]; - - if ($always_display_enclosures) { - $checked = "checked - } else { - $checked = " - } - -
- - - -
- - $hide_images = $row["hide_images"]; - - if ($hide_images) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $cache_images = $row["cache_images"]; - - if ($cache_images) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $mark_unread_on_update = $row["mark_unread_on_update"]; - - if ($mark_unread_on_update) { - $checked = "checked - } else { - $checked = " - } - -
- - - -
- -
- -
- - - - -
+
+ ${reply.plugin_data} +
- -
- ${reply.plugin_data} -
- -
- -
- ${App.FormFields.button_tag(__("Unsubscribe"), "", {class: "pull-left alt-danger", onclick: "App.dialogOf(this).unsubscribe()"})} - ${App.FormFields.submit_tag(__("Save"), {onclick: "return App.dialogOf(this).execute()"})} - ${App.FormFields.cancel_dialog_tag(__("Cancel"))} -
+ + `); }) });