diff options
author | Andrew Dolgov <[email protected]> | 2021-01-15 08:37:52 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-01-15 08:37:52 +0300 |
commit | fa7791a69bdc05d92f1e22a78e05ad9a9871ebd2 (patch) | |
tree | ff17898fdfcd79be92a69b3f47c6cd30b5ab9b8b /init.php |
initial
Diffstat (limited to 'init.php')
-rw-r--r-- | init.php | 120 |
1 files changed, 120 insertions, 0 deletions
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; + } + +} |