summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-01-15 08:37:52 +0300
committerAndrew Dolgov <[email protected]>2021-01-15 08:37:52 +0300
commitfa7791a69bdc05d92f1e22a78e05ad9a9871ebd2 (patch)
treeff17898fdfcd79be92a69b3f47c6cd30b5ab9b8b
initial
-rw-r--r--README.md1
-rw-r--r--init.php120
2 files changed, 121 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ec12090
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+git checkout to ``(plugins.local)/vf_search``
diff --git a/init.php b/init.php
new file mode 100644
index 0000000..d457be7
--- /dev/null
+++ b/init.php
@@ -0,0 +1,120 @@
+<?php
+class VF_Search extends Plugin {
+
+ private $host;
+ private $feeds = [];
+
+ function about() {
+ return array(1.0,
+ "Show searches as feeds",
+ "fox",
+ false);
+ }
+
+ function init($host) {
+ $this->host = $host;
+
+ $searches = explode("\n", $this->host->get($this, "searches", ""));
+
+ foreach ($searches as $line) {
+ list ($caption, $query) = explode(",", $line, 2);
+
+ if ($caption && $query)
+ array_push($this->feeds,
+ [$host->add_feed(-1, $caption, 'search', $this), $query]
+ );
+ }
+
+ $host->add_hook($host::HOOK_PREFS_TAB, $this);
+ }
+
+ function get_unread($feed_id) {
+ return 0;
+ }
+
+ function get_total($feed_id) {
+ return 0;
+ }
+
+ function get_headlines($feed_id, $options) {
+ $search = array_reduce($this->feeds,
+ function ($carry, $feed) use ($feed_id) {
+ if ($feed_id == $feed[0])
+ return $feed[1];
+ else
+ return $carry;
+ }
+ );
+
+ $params = array(
+ "feed" => -4,
+ "limit" => $options["limit"],
+ "view_mode" => $this->get_unread(-1) > 0 ? "adaptive" : "all_articles",
+ "override_order" => $options['override_order'],
+ "offset" => $options["offset"],
+ "filter" => $options["filter"],
+ "since_id" => $options["since_id"],
+ "include_children" => $options["include_children"],
+ "search" => $search,
+ "override_vfeed" => "ttrss_feeds.title AS feed_title,"
+ );
+
+ $qfh_ret = Feeds::queryFeedHeadlines($params);
+ $qfh_ret[1] = "Search results: $search";
+
+ return $qfh_ret;
+ }
+
+ function hook_prefs_tab($args) {
+ if ($args != "prefFeeds") return;
+
+ $searches = $this->host->get($this, "searches", "");
+
+ print "<div dojoType='dijit.layout.AccordionPane'
+ title=\"<i class='material-icons'>search</i> Show searches as feeds (vf_search)\">";
+
+ print "<form dojoType='dijit.form.Form'>";
+
+ print "<script type='dojo/method' event='onSubmit' args='evt'>
+ evt.preventDefault();
+ if (this.validate()) {
+ console.log(dojo.objectToQuery(this.getValues()));
+ new Ajax.Request('backend.php', {
+ parameters: dojo.objectToQuery(this.getValues()),
+ onComplete: function(transport) {
+ Notify.info(transport.responseText);
+ }
+ });
+ }
+ </script>";
+
+ print_hidden("op", "pluginhandler");
+ print_hidden("method", "save");
+ print_hidden("plugin", "vf_search");
+
+ print_notice("One line per generated feed. Use the following format for each line: <b>feed title,search query</b>");
+
+ print "<fieldset>";
+ print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' name='searches'>$searches</textarea>";
+ print "</fieldset>";
+
+ print_button("submit", "Save", "class='alt-primary'");
+
+ print "</form>";
+
+ print "</div>";
+ }
+
+ function save() {
+ $searches = $_POST["searches"];
+
+ $this->host->set($this, "searches", $searches);
+
+ echo "Data saved";
+ }
+
+ function api_version() {
+ return 2;
+ }
+
+}