diff --git a/lib/XRay/Formats/Format.php b/lib/XRay/Formats/Format.php
index 41ae28a..6cd7c5c 100644
--- a/lib/XRay/Formats/Format.php
+++ b/lib/XRay/Formats/Format.php
@@ -104,5 +104,36 @@ abstract class Format implements iFormat {
return trim(str_replace(['
','
'],"\n", $sanitized));
}
+ protected static function findLinksInDocument(&$xpath, $target) {
+ $found = [];
+ self::xPathFindNodeWithAttribute($xpath, 'a', 'href', function($u) use($target, &$found){
+ if($u == $target) {
+ $found[$u] = null;
+ }
+ });
+ self::xPathFindNodeWithAttribute($xpath, 'img', 'src', function($u) use($target, &$found){
+ if($u == $target) {
+ $found[$u] = null;
+ }
+ });
+ self::xPathFindNodeWithAttribute($xpath, 'video', 'src', function($u) use($target, &$found){
+ if($u == $target) {
+ $found[$u] = null;
+ }
+ });
+ self::xPathFindNodeWithAttribute($xpath, 'audio', 'src', function($u) use($target, &$found){
+ if($u == $target) {
+ $found[$u] = null;
+ }
+ });
+ return $found;
+ }
+
+ public static function xPathFindNodeWithAttribute($xpath, $node, $attr, $callback) {
+ foreach($xpath->query('//'.$node.'[@'.$attr.']') as $el) {
+ $v = $el->getAttribute($attr);
+ $callback($v);
+ }
+ }
}
diff --git a/lib/XRay/Formats/HTML.php b/lib/XRay/Formats/HTML.php
index 3f83893..9f9528b 100644
--- a/lib/XRay/Formats/HTML.php
+++ b/lib/XRay/Formats/HTML.php
@@ -47,26 +47,7 @@ class HTML extends Format {
$found = [];
if($target) {
- self::xPathFindNodeWithAttribute($xpath, 'a', 'href', function($u) use($target, &$found){
- if($u == $target) {
- $found[$u] = null;
- }
- });
- self::xPathFindNodeWithAttribute($xpath, 'img', 'src', function($u) use($target, &$found){
- if($u == $target) {
- $found[$u] = null;
- }
- });
- self::xPathFindNodeWithAttribute($xpath, 'video', 'src', function($u) use($target, &$found){
- if($u == $target) {
- $found[$u] = null;
- }
- });
- self::xPathFindNodeWithAttribute($xpath, 'audio', 'src', function($u) use($target, &$found){
- if($u == $target) {
- $found[$u] = null;
- }
- });
+ $found = self::findLinksInDocument($xpath, $target);
}
if(!$found) {
@@ -178,13 +159,6 @@ class HTML extends Format {
return mb_convert_encoding($input, 'HTML-ENTITIES', mb_detect_encoding($input));
}
- private static function xPathFindNodeWithAttribute($xpath, $node, $attr, $callback) {
- foreach($xpath->query('//'.$node.'[@'.$attr.']') as $el) {
- $v = $el->getAttribute($attr);
- $callback($v);
- }
- }
-
private static function xPathGetElementById($xpath, $id) {
$element = null;
foreach($xpath->query("//*[@id='$id']") as $el) {