Skip to content

Instantly share code, notes, and snippets.

@pluser pluser/init.php
Created Sep 9, 2014

Embed
What would you like to do?
The plugin to retrieve full contents via Readability for Tiny Tiny RSS
<?php
class Af_Fullfeed extends Plugin {
private $host;
function about() {
return array(1.0,
"Readability makes us clean page.",
"pluser",
false);
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
}
function hook_article_filter($article) {
$url = "https://www.readability.com/api/content/v1/parser?token=+++++PLEASE_INSERT_YOUR_READABILITY_PARSER_TOKEN+++++&url=".urlencode($article["link"]);
stream_context_set_default(array("http"=>array("method"=>"HEAD")));
$headers = get_headers($url, 1);
stream_context_set_default(array("http"=>array("method"=>"GET")));
switch($headers["X-Article-Status"]) {
case "INVALID":
case "UNRETRIEVED":
case "PROVIDED_BY_USER":
break;
case "VALIDATED_BY_USERS":
case "FETCHED":
default:
$readability = file_get_contents($url);
if($readability !== false) {
$obj = json_decode($readability, true);
if($obj["error"] !== true) $article["content"] = $obj["content"];
}
break;
}
return $article;
}
function api_version() {
return 2;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.