summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2016-07-26 09:49:40 +0300
committerAndrew Dolgov <[email protected]>2016-07-26 09:49:40 +0300
commit745e6fad85df121dc385767652be849f06b38247 (patch)
tree4ea186da64b992146b84d195af3ad2ae7b4ab555
parent966e4ac1d042773286652209b48446990f202f06 (diff)
add basic support for <video> elements
-rwxr-xr-xinit.php59
1 files changed, 37 insertions, 22 deletions
diff --git a/init.php b/init.php
index d41d187..8650e39 100755
--- a/init.php
+++ b/init.php
@@ -192,30 +192,45 @@ class Af_Zz_Img_Phash extends Plugin {
$this->host->set($this, "enabled_feeds", $enabled_feeds);
}
- private function rewrite_duplicate($doc, $img, $api_mode = false) {
- $src = $this->absolutize_url($img->getAttribute("src"));
+ private function rewrite_duplicate($doc, $elem, $api_mode = false) {
- $p = $doc->createElement('p');
+ if ($elem->hasAttribute("src")) {
+ $uri = $this->absolutize_url($elem->getAttribute("src"));
+ $check_uri = $uri;
+ } else if ($elem->hasAttribute("poster")) {
+ $check_uri = $this->absolutize_url($elem->getAttribute("poster"));
- $a = $doc->createElement("a");
- $a->setAttribute("href", $src);
- $a->setAttribute("target", "_blank");
- $a->appendChild(new DOMText(truncate_middle($src, 48, "...")));
+ $video_source = $elem->getElementsByTagName("source")->item(0);
- $p->appendChild($a);
+ if ($video_source) {
+ $uri = $video_source->getAttribute("src");
+ }
+ }
- if (!$api_mode) {
- $b = $doc->createElement("a");
- $b->setAttribute("href", "#");
- $b->setAttribute("onclick", "showPhashSimilar(this)");
- $b->setAttribute("data-check-url", $this->absolutize_url($src));
- $b->appendChild(new DOMText("(similar)"));
+ if ($check_uri && $uri) {
- $p->appendChild(new DOMText(" "));
- $p->appendChild($b);
- }
+ $p = $doc->createElement('p');
+
+ $a = $doc->createElement("a");
+ $a->setAttribute("href", $uri);
+ $a->setAttribute("target", "_blank");
+ $a->appendChild(new DOMText(truncate_middle($uri, 48, "...")));
+
+ $p->appendChild($a);
- $img->parentNode->replaceChild($p, $img);
+ if (!$api_mode) {
+ $b = $doc->createElement("a");
+ $b->setAttribute("href", "#");
+ $b->setAttribute("onclick", "showPhashSimilar(this)");
+ $b->setAttribute("data-check-url", $this->absolutize_url($check_uri));
+ $b->appendChild(new DOMText("(similar)"));
+
+ $p->appendChild(new DOMText(" "));
+ $p->appendChild($b);
+ }
+
+ $elem->parentNode->replaceChild($p, $elem);
+ }
}
function hook_article_filter($article) {
@@ -242,11 +257,11 @@ class Af_Zz_Img_Phash extends Plugin {
if (@$doc->loadHTML($article["content"])) {
$xpath = new DOMXPath($doc);
- $imgs = $xpath->query("//img[@src]");
+ $imgs = $xpath->query("//img[@src]|//video[@poster]");
foreach ($imgs as $img) {
- $src = $img->getAttribute("src");
+ $src = $img->tagName == "video" ? $img->getAttribute("poster") : $img->getAttribute("src");
$src = $this->absolutize_url(rewrite_relative_url($article["link"], $src));
$domain_found = $this->check_src_domain($src, $domains_list);
@@ -375,11 +390,11 @@ class Af_Zz_Img_Phash extends Plugin {
if (@$doc->loadHTML($article["content"])) {
$xpath = new DOMXPath($doc);
- $imgs = $xpath->query("//img[@src]");
+ $imgs = $xpath->query("//img[@src]|//video[@poster]");
foreach ($imgs as $img) {
- $src = $img->getAttribute("src");
+ $src = $img->tagName == "video" ? $img->getAttribute("poster") : $img->getAttribute("src");
$src = $this->absolutize_url(rewrite_relative_url($article["link"], $src, $api_mode));
$domain_found = $this->check_src_domain($src, $domains_list);