host = $host; $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); $host->add_hook($host::HOOK_PREFS_TAB, $this); $host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this); $host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this); $host->add_filter_action($this, "action_inline", __("Inline content")); } function hook_prefs_tab($args) { if ($args != "prefFeeds") return; print "
"; print_notice("Enable the plugin for specific feeds in the feed editor."); $enabled_feeds = $this->host->get($this, "enabled_feeds"); if (!array($enabled_feeds)) $enabled_feeds = array(); $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); $this->host->set($this, "enabled_feeds", $enabled_feeds); if (count($enabled_feeds) > 0) { print "

" . __("Currently enabled for (click to edit):") . "

"; print ""; } print "
"; } function hook_prefs_edit_feed($feed_id) { print "
".__("Readability")."
"; print "
"; $enabled_feeds = $this->host->get($this, "enabled_feeds"); if (!array($enabled_feeds)) $enabled_feeds = array(); $key = array_search($feed_id, $enabled_feeds); $checked = $key !== FALSE ? "checked" : ""; print "
 "; print "
"; } function hook_prefs_save_feed($feed_id) { $enabled_feeds = $this->host->get($this, "enabled_feeds"); if (!is_array($enabled_feeds)) $enabled_feeds = array(); $enable = checkbox_to_sql_bool($_POST["af_readability_enabled"]) == 'true'; $key = array_search($feed_id, $enabled_feeds); if ($enable) { if ($key === FALSE) { array_push($enabled_feeds, $feed_id); } } else { if ($key !== FALSE) { unset($enabled_feeds[$key]); } } $this->host->set($this, "enabled_feeds", $enabled_feeds); } function hook_article_filter_action($article, $action) { return $this->process_article($article); } function process_article($article) { if (!class_exists("Readability")) require_once(dirname(dirname(__DIR__)). "/lib/readability/Readability.php"); if (function_exists("curl_init")) { $ch = curl_init($article["link"]); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir")); curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); @$result = curl_exec($ch); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if (strpos($content_type, "text/html") === FALSE) return $article; } $tmp = fetch_file_contents($article["link"]); if ($tmp && mb_strlen($tmp) < 65535 * 4) { $tmpdoc = new DOMDocument("1.0", "UTF-8"); if (!$tmpdoc->loadHTML($tmp)) return $article; if (strtolower($tmpdoc->encoding) != 'utf-8') { $tmpxpath = new DOMXPath($tmpdoc); foreach ($tmpxpath->query("//meta") as $elem) { $elem->parentNode->removeChild($elem); } $tmp = $tmpdoc->saveHTML(); } $r = new Readability($tmp, $article["link"]); if ($r->init()) { $tmpxpath = new DOMXPath($r->dom); $entries = $tmpxpath->query('(//a[@href]|//img[@src])'); foreach ($entries as $entry) { if ($entry->hasAttribute("href")) { $entry->setAttribute("href", rewrite_relative_url($article["link"], $entry->getAttribute("href"))); } if ($entry->hasAttribute("src")) { $entry->setAttribute("src", rewrite_relative_url($article["link"], $entry->getAttribute("src"))); } } $article["content"] = $r->articleContent->innerHTML; } } return $article; } function hook_article_filter($article) { $enabled_feeds = $this->host->get($this, "enabled_feeds"); $key = array_search($article["feed"]["id"], $enabled_feeds); if ($key === FALSE) return $article; return $this->process_article($article); } function api_version() { return 2; } private function filter_unknown_feeds($enabled_feeds) { $tmp = array(); foreach ($enabled_feeds as $feed) { $result = db_query("SELECT id FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) != 0) { array_push($tmp, $feed); } } return $tmp; } } ?>