Browse Source

af_readability: add article button to embed content of a specific article

Andrew Dolgov 5 months ago
parent
commit
71ff485fbf
3 changed files with 39 additions and 37 deletions
  1. 1 1
      js/Article.js
  2. 25 0
      plugins/af_readability/init.php
  3. 13 36
      plugins/note/note.js

+ 1 - 1
js/Article.js

@@ -194,7 +194,7 @@ define(["dojo/_base/declare"], function (declare) {
 					const comments = this.formatComments(hl);
 					const originally_from = this.formatOriginallyFrom(hl);
 
-					const article = `<div class="post post-${hl.id}">
+					const article = `<div class="post post-${hl.id}" data-article-id="${hl.id}">
 						<div class="header">
 							<div class="row">
 								<div class="title"><a target="_blank" rel="noopener noreferrer"

+ 25 - 0
plugins/af_readability/init.php

@@ -38,6 +38,7 @@ class Af_Readability extends Plugin {
 		$host->add_hook($host::HOOK_PREFS_TAB, $this);
 		$host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this);
 		$host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this);
+		$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
 
 		// Note: we have to install the hook even if disabled because init() is being run before plugin data has loaded
 		// so we can't check for our storage-set options here
@@ -46,6 +47,15 @@ class Af_Readability extends Plugin {
 		$host->add_filter_action($this, "action_inline", __("Inline content"));
 	}
 
+	function get_js() {
+		return file_get_contents(__DIR__ . "/init.js");
+	}
+
+	function hook_article_button($line) {
+		return "<i class='material-icons' onclick=\"Plugins.Af_Readability.embed(".$line["id"].")\"
+			style='cursor : pointer' title='".__('Get full article text')."'>description</i>";
+	}
+
 	function hook_prefs_tab($args) {
 		if ($args != "prefFeeds") return;
 
@@ -284,4 +294,19 @@ class Af_Readability extends Plugin {
 		return $tmp;
 	}
 
+	function embed() {
+		$article_id = (int) $_REQUEST["param"];
+
+		$sth = $this->pdo->prepare("SELECT link FROM ttrss_entries WHERE id = ?");
+		$sth->execute([$article_id]);
+
+		$ret = [];
+
+		if ($row = $sth->fetch()) {
+			$ret["content"] = $this->extract_content($row["link"]);
+		}
+
+		print json_encode($ret);
+	}
+
 }

+ 13 - 36
plugins/note/note.js

@@ -1,40 +1,17 @@
-Plugins.Note = {
-	edit: function(id) {
-		const query = "backend.php?op=pluginhandler&plugin=note&method=edit&param=" + encodeURIComponent(id);
+Plugins.Af_Readability = {
+	embed: function(id) {
+		Notify.progress("Loading, please wait...");
 
-		if (dijit.byId("editNoteDlg"))
-			dijit.byId("editNoteDlg").destroyRecursive();
+		xhrJson("backend.php",{ op: "pluginhandler", plugin: "af_readability", method: "embed", param: id }, (reply) => {
+			const content = $$(App.isCombinedMode() ? ".cdm[data-article-id=" + id + "] .content-inner" :
+				".post[data-article-id=" + id + "] .content")[0];
 
-		const dialog = new dijit.Dialog({
-			id: "editNoteDlg",
-			title: __("Edit article note"),
-			style: "width: 600px",
-			execute: function () {
-				if (this.validate()) {
-					Notify.progress("Saving article note...", true);
-
-					xhrJson("backend.php", this.attr('value'), (reply) => {
-						Notify.close();
-						dialog.hide();
-
-						if (reply) {
-							const elem = $("POSTNOTE-" + id);
-
-							if (elem) {
-								elem.innerHTML = reply.note;
-
-								if (reply.raw_length != 0)
-									Element.show(elem);
-								else
-									Element.hide(elem);
-							}
-						}
-					});
-				}
-			},
-			href: query,
+			if (content && reply.content) {
+				content.innerHTML = reply.content;
+				Notify.close();
+			} else {
+				Notify.error("Unable to fetch content for this article");
+			}
 		});
-
-		dialog.show();
 	}
-};
+};