af_redditimgur: fix youtube regexp, try to inline images again if parsed

using readability
This commit is contained in:
Andrew Dolgov 2015-07-07 08:44:31 +03:00
parent 99bb8b3bbb
commit 6322fc6870
1 changed files with 201 additions and 210 deletions

View File

@ -69,14 +69,8 @@ class Af_RedditImgur extends Plugin {
echo __("Configuration saved");
}
function hook_article_filter($article) {
private function inline_stuff($article, &$doc, $xpath) {
if (strpos($article["link"], "reddit.com/r/") !== FALSE) {
$doc = new DOMDocument();
@$doc->loadHTML($article["content"]);
if ($doc) {
$xpath = new DOMXPath($doc);
$entries = $xpath->query('(//a[@href]|//img[@src])');
$found = false;
@ -113,26 +107,6 @@ class Af_RedditImgur extends Plugin {
if (preg_match("/\.(gifv)$/i", $entry->getAttribute("href"))) {
/*$video = $doc->createElement('video');
$video->setAttribute("autoplay", "1");
$video->setAttribute("loop", "1");
$source = $doc->createElement('source');
$source->setAttribute("src", str_replace(".gifv", ".mp4", $entry->getAttribute("href")));
$source->setAttribute("type", "video/mp4");
$video->appendChild($source);
$br = $doc->createElement('br');
$entry->parentNode->insertBefore($video, $entry);
$entry->parentNode->insertBefore($br, $entry);
$img = $doc->createElement('img');
$img->setAttribute("src",
"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D");
$entry->parentNode->insertBefore($img, $entry);*/
$source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href"));
$this->handle_as_video($doc, $entry, $source_stream);
@ -141,7 +115,7 @@ class Af_RedditImgur extends Plugin {
$matches = array();
if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) ||
preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry->getAttribute("href"), $matches) ||
preg_match("/\/\/www\.youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) ||
preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) {
$vid_id = $matches[1];
@ -254,6 +228,18 @@ class Af_RedditImgur extends Plugin {
}
}
return $found;
}
function hook_article_filter($article) {
if (strpos($article["link"], "reddit.com/r/") !== FALSE) {
$doc = new DOMDocument();
@$doc->loadHTML($article["content"]);
$xpath = new DOMXPath($doc);
$found = $this->inline_stuff($article, $doc, $xpath);
if (!$found && $this->host->get($this, "enable_readability") && mb_strlen(strip_tags($article["content"])) <= 150) {
if (!class_exists("Readability")) require_once(__DIR__ . "/classes/Readability.php");
@ -289,6 +275,12 @@ class Af_RedditImgur extends Plugin {
}
$article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"];
$doc = new DOMDocument();
@$doc->loadHTML($article["content"]);
$xpath = new DOMXPath($doc);
$found = $this->inline_stuff($article, $doc, $xpath);
}
}
@ -302,7 +294,6 @@ class Af_RedditImgur extends Plugin {
$article["content"] = $doc->saveXML($node);
}
}
}
return $article;
}