]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_readability/init.php
2 class Af_Readability
extends Plugin
{
8 "Try to inline article content using Readability",
20 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
21 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
22 $host->add_hook($host::HOOK_PREFS_EDIT_FEED
, $this);
23 $host->add_hook($host::HOOK_PREFS_SAVE_FEED
, $this);
26 function hook_prefs_tab($args) {
27 if ($args != "prefFeeds") return;
29 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('af_readability settings')."\">";
31 print_notice("Enable the plugin for specific feeds in the feed editor.");
33 $enabled_feeds = $this->host
->get($this, "enabled_feeds");
34 if (!array($enabled_feeds)) $enabled_feeds = array();
36 $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds);
37 $this->host
->set($this, "enabled_feeds", $enabled_feeds);
39 if (count($enabled_feeds) > 0) {
40 print "<h3>" . __("Currently enabled for (click to edit):") . "</h3>";
42 print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
43 foreach ($enabled_feeds as $f) {
45 "<img src='images/pub_set.png'
46 style='vertical-align : middle'> <a href='#'
47 onclick='editFeed($f)'>".
48 getFeedTitle($f) . "</a></li>";
56 function hook_prefs_edit_feed($feed_id) {
57 print "<div class=\"dlgSec\">".__("Readability")."</div>";
58 print "<div class=\"dlgSecCont\">";
60 $enabled_feeds = $this->host
->get($this, "enabled_feeds");
61 if (!array($enabled_feeds)) $enabled_feeds = array();
63 $key = array_search($feed_id, $enabled_feeds);
64 $checked = $key !== FALSE ?
"checked" : "";
66 print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"af_readability_enabled\"
67 name=\"af_readability_enabled\"
68 $checked> <label for=\"af_readability_enabled\">".__('Inline article content')."</label>";
73 function hook_prefs_save_feed($feed_id) {
74 $enabled_feeds = $this->host
->get($this, "enabled_feeds");
75 if (!is_array($enabled_feeds)) $enabled_feeds = array();
77 $enable = checkbox_to_sql_bool($_POST["af_readability_enabled"]) == 'true';
78 $key = array_search($feed_id, $enabled_feeds);
82 array_push($enabled_feeds, $feed_id);
86 unset($enabled_feeds[$key]);
90 $this->host
->set($this, "enabled_feeds", $enabled_feeds);
93 function hook_article_filter($article) {
95 $enabled_feeds = $this->host
->get($this, "enabled_feeds");
96 $key = array_search($article["feed"]["id"], $enabled_feeds);
97 if ($key === FALSE) return $article;
99 if (!class_exists("Readability")) require_once(__DIR__
. "/classes/Readability.php");
101 $tmp = fetch_file_contents($article["link"]);
104 $r = new Readability($tmp, $article["link"]);
108 $tmpxpath = new DOMXPath($r->dom
);
110 $entries = $tmpxpath->query('(//a[@href]|//img[@src])');
112 foreach ($entries as $entry) {
113 if ($entry->hasAttribute("href")) {
114 $entry->setAttribute("href",
115 rewrite_relative_url($article["link"], $entry->getAttribute("href")));
119 if ($entry->hasAttribute("src")) {
120 $entry->setAttribute("src",
121 rewrite_relative_url($article["link"], $entry->getAttribute("src")));
127 $article["content"] = $r->articleContent
->innerHTML
;
135 function api_version() {
139 private function filter_unknown_feeds($enabled_feeds) {
142 foreach ($enabled_feeds as $feed) {
144 $result = db_query("SELECT id FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
146 if (db_num_rows($result) != 0) {
147 array_push($tmp, $feed);