Given the complexity of queryFeedHeadlines
it looks like it’ll have to be a trade-off between allowing for the built-in UI filters to apply and allowing for queries against multiple feeds at once; making a version of queryFeedHeadlines
that supports multiple feeds seems like it would be massively error prone.
Using a query like the one used in testFilterDo
would be handy but if I understand correctly direct database queries are not exposed to plugins so that would mean a core change would be needed to provide a plugin helper.
Finally, I was only able to find 2 alternatives to creating the filter object: provide a feed and query all filters for that feed (conflicting filters will cause problems so that’s not viable outside of a hacky demo) or collect the parameters from the again similar to how testFilterDo
uses the form data to construct a filter on the fly.
I hacked on the vfeed example as an experiment; using the anonymous class to wrap fetch()
is a bit brittle, does anyone know a better way to filter on a result cursor?
Also apologies if I used any PHP anti-patterns; I can count on one hand the number of times I’ve had to touch PHP code.
<?php
class VF_Filters extends Plugin {
private $host;
private $dummy_id;
function about() {
return array(0.1,
"Filter vfeed plugin",
"Tyler Szabo");
}
function init($host) {
$this->host = $host;
$this->dummy_id = $host->add_feed(-1, 'Dummy feed', 'images/pub_set.svg', $this);
}
function get_unread($feed_id) {
return null;
}
function get_headlines($feed_id, $options) {
$feed = 3; # HACKHACK hardcoded for local testing - need to get this from user
$owner_uid = $this->host->get_owner_uid();
$filters = RSSUtils::load_filters($feed, $owner_uid); # HACKHACK - should get the filter from the user
$params = array(
"feed" => $feed,
"limit" => $options["limit"],
"view_mode" => $options['view_mode'],
"search" => $options['search'],
"override_order" => $options['override_order'],
"offset" => $options["offset"],
"filter" => $options["filter"],
"since_id" => $options["since_id"],
"include_children" => $options["include_children"]
);
$qfh_ret = Feeds::queryFeedHeadlines($params);
$qfh_ret[0] = new class($qfh_ret[0], $filters) {
private $res;
private $filters;
public function __construct($res, $filters) {
$this->res = $res;
$this->filters = $filters;
}
public function fetch() {
while ($article = $this->res->fetch()) {
$filter_actions = RSSUtils::get_article_filters($this->filters, $article['title'], $article['content'], $article['link'], $article['author'], explode(",", $article['tag_cache']));
if (count($filter_actions) > 0) {
return $article;
}
}
return $article;
}
};
$qfh_ret[1] = __("Filtered: " . $qfh_ret[1]);
return $qfh_ret; #array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override);
}
function api_version() {
return 2;
}
}
?>