|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * af_newspapers/init.php |
| 4 | + * Plugin for TT-RSS 1.7.9 |
| 5 | + * |
| 6 | + * Retrieves full article text for feeds from Movable Type Enterprise sites (commonly |
| 7 | + * used by newspapers). |
| 8 | + * |
| 9 | + * CHANGELOG: |
| 10 | + * Version 1.2 by craywolf 2013-04-19 @ 14:00 GMT |
| 11 | + * - Added api_version() call |
| 12 | + * - Removed cruft |
| 13 | + * Version 1.1 by craywolf 2013-04-17 @ 15:22 GMT |
| 14 | + * - Added fix for removal of $this->link in 1.7.9 |
| 15 | + * - Added "more info" link to about() |
| 16 | + * Version 1.0 by craywolf 2013-03-26 @ 16:17 GMT |
| 17 | + * - Initial release |
| 18 | + */ |
| 19 | +class Af_newspapers extends Plugin { |
| 20 | + private $host; |
| 21 | + |
| 22 | + function about() { |
| 23 | + return array(1.2, |
| 24 | + "Turn newspaper feeds using Movable Type Enterprise (index.ssf in story link) into full-story feeds", |
| 25 | + "craywolf", |
| 26 | + "", |
| 27 | + "http://tt-rss.org/forum/viewtopic.php?f=22&t=1539"); |
| 28 | + } |
| 29 | + |
| 30 | + function api_version() { |
| 31 | + return 2; |
| 32 | + } |
| 33 | + |
| 34 | + function init($host) { |
| 35 | + $this->host = $host; |
| 36 | + |
| 37 | + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
| 38 | + } |
| 39 | + |
| 40 | + function hook_article_filter($article) { |
| 41 | + $owner_uid = $article["owner_uid"]; |
| 42 | + |
| 43 | + if (strpos($article["link"], "/index.ssf/") !== FALSE) { |
| 44 | + if (strpos($article["plugin_data"], "newspapers-full,$owner_uid:") === FALSE) { |
| 45 | + |
| 46 | + $doc = new DOMDocument(); |
| 47 | + @$doc->loadHTML(fetch_file_contents($article["link"])); |
| 48 | + |
| 49 | + $basenode = false; |
| 50 | + |
| 51 | + if ($doc) { |
| 52 | + $xpath = new DOMXPath($doc); |
| 53 | + |
| 54 | + $entries = $xpath->query('(//div[@class="entry-content"])'); |
| 55 | + foreach ($entries as $entry) { |
| 56 | + $basenode = $entry; |
| 57 | + } |
| 58 | + |
| 59 | + if ($basenode) { |
| 60 | + $article["content"] = $doc->saveXML($basenode); //, LIBXML_NOEMPTYTAG); |
| 61 | + $article["plugin_data"] = "newspapers-full,$owner_uid:" . $article["plugin_data"]; |
| 62 | + } |
| 63 | + } |
| 64 | + } else if (isset($article["stored"]["content"])) { |
| 65 | + $article["content"] = $article["stored"]["content"]; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return $article; |
| 70 | + } |
| 71 | +} |
| 72 | +?> |
0 commit comments