af_redditimgur: instead of generating potentially blacklisted iframes (i.e. huge black boxes),

save found youtube videos as post enclosures for af_youtube_... plugins to deal with later, if enabled
This commit is contained in:
Andrew Dolgov 2021-04-23 20:30:29 +03:00
parent 88a7130d79
commit e8f78181f1
1 changed files with 8 additions and 18 deletions

View File

@ -7,6 +7,7 @@ class Af_RedditImgur extends Plugin {
private $dump_json_data = false;
private $fallback_preview_urls = [];
private $default_max_score = 100;
private $generated_enclosures = [];
function about() {
return array(null,
@ -247,6 +248,8 @@ class Af_RedditImgur extends Plugin {
$link_flairs = [];
$apply_nsfw_tags = FeedItem_Common::normalize_categories($this->host->get_array($this, "apply_nsfw_tags", []));
$this->generated_enclosures = [];
// embed anchor element, before reddit <table> post layout
$anchor = $xpath->query('//body/*')->item(0);
@ -432,24 +435,11 @@ class Af_RedditImgur extends Plugin {
Debug::log("Handling as youtube: $vid_id", Debug::LOG_VERBOSE);
$iframe = $doc->createElement("iframe");
$iframe->setAttribute("class", "youtube-player");
$iframe->setAttribute("type", "text/html");
$iframe->setAttribute("width", "640");
$iframe->setAttribute("height", "385");
$iframe->setAttribute("src", "https://www.youtube.com/embed/$vid_id");
$iframe->setAttribute("allowfullscreen", "1");
$iframe->setAttribute("frameborder", "0");
/* normalize video URL for af_youtube_... plugins */
$video_url = "https://www.youtube.com/v/$vid_id";
//$br = $doc->createElement('br');
//$entry->parentNode->insertBefore($iframe, $entry);
//$entry->parentNode->insertBefore($br, $entry);
// reparent generated iframe because it doesn't scale well inside <td>
if ($anchor)
$anchor->parentNode->insertBefore($iframe, $anchor);
else
$entry->parentNode->insertBefore($iframe, $entry);
/* push generated video URL to enclosures so that youtube embed plugins would deal with it later (if enabled) */
$this->generated_enclosures[] = [$video_url, "text/html", null, null, '', ''];
$found = true;
}
@ -635,7 +625,7 @@ class Af_RedditImgur extends Plugin {
if ($node && $found) {
$article["content"] = $doc->saveHTML($node);
$article["enclosures"] = [];
$article["enclosures"] = $this->generated_enclosures;
} else if ($content_link) {
$article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath);
}