af_redditimgur: gifv: fix iframe not being wide enough, fix indenting

master
Andrew Dolgov 10 years ago
parent c68013b132
commit 299aeb3094

@ -31,52 +31,53 @@ class Af_RedditImgur extends Plugin {
if (preg_match("/\.(gifv)$/i", $entry->getAttribute("href"))) { if (preg_match("/\.(gifv)$/i", $entry->getAttribute("href"))) {
$gifv_meta = fetch_file_contents($entry->getAttribute("href"), $gifv_meta = fetch_file_contents($entry->getAttribute("href"),
false, false, false, false, 10); false, false, false, false, 10);
if ($gifv_meta) { if ($gifv_meta) {
$adoc = new DOMDocument(); $adoc = new DOMDocument();
@$adoc->loadHTML($gifv_meta); @$adoc->loadHTML($gifv_meta);
if ($adoc) { if ($adoc) {
$axpath = new DOMXPath($adoc); $axpath = new DOMXPath($adoc);
$aentries = $axpath->query('(//meta)'); $aentries = $axpath->query('(//meta)');
$width = false; $width = false;
$height = false; $height = false;
foreach ($aentries as $aentry) { foreach ($aentries as $aentry) {
if (strpos($aentry->getAttribute("property"), "og:image:width") !== FALSE) { if (strpos($aentry->getAttribute("property"), "og:image:width") !== FALSE) {
$width = $aentry->getAttribute("content"); $width = $aentry->getAttribute("content");
} }
if (strpos($aentry->getAttribute("property"), "og:image:height") !== FALSE) {
$height = $aentry->getAttribute("content"); if (strpos($aentry->getAttribute("property"), "og:image:height") !== FALSE) {
} $height = $aentry->getAttribute("content");
} }
} }
} }
}
if ($width && $height) {
if ($width && $height) {
$iframe = $doc->createElement('iframe');
$iframe->setAttribute("src", str_replace("http:", "", $entry->getAttribute("href"))); $iframe = $doc->createElement('iframe');
$iframe->setAttribute("frameborder", "0"); $iframe->setAttribute("src", str_replace("http:", "", $entry->getAttribute("href")));
$iframe->setAttribute("width", $width); $iframe->setAttribute("frameborder", "0");
$iframe->setAttribute("height", $height); $iframe->setAttribute("width", $width + 64);
$iframe->setAttribute("height", $height + 64);
$br = $doc->createElement('br');
$entry->parentNode->insertBefore($iframe, $entry); $br = $doc->createElement('br');
$entry->parentNode->insertBefore($br, $entry); $entry->parentNode->insertBefore($iframe, $entry);
$entry->parentNode->insertBefore($br, $entry);
// add empty img tag to disable display of attachment
$img = $doc->createElement('img'); // add empty img tag to disable display of attachment
$img->setAttribute("src", "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); $img = $doc->createElement('img');
$img->setAttribute("width", "0"); $img->setAttribute("src", "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D");
$img->setAttribute("height", "0"); $img->setAttribute("width", "0");
$entry->parentNode->insertBefore($img, $entry); $img->setAttribute("height", "0");
$found = true; $entry->parentNode->insertBefore($img, $entry);
} $found = true;
} }
}
if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9])?$/i", $entry->getAttribute("href"))) { if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9])?$/i", $entry->getAttribute("href"))) {

Loading…
Cancel
Save