Created
September 9, 2014 18:14
-
-
Save pluser/3039ffacfffa8c55e63d to your computer and use it in GitHub Desktop.
The plugin to retrieve full contents via Readability for Tiny Tiny RSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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