1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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;
}
}
|