Skip to content

Commit 0be6d24

Browse files
committed
fixed #22
1 parent 3365a9e commit 0be6d24

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Embed/Providers/Html.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public function __construct(Request $request)
105105
}
106106
}
107107

108-
//img tags
109108
//Search the main element:
110109
$content = $html->getElementsByTagName('main'); //<main> element
111110

@@ -137,10 +136,30 @@ public function __construct(Request $request)
137136
$src = new Url($img->getAttribute('src'));
138137

139138
//Check whether the image is in the same domain
139+
if ($src->getDomain() && $src->getDomain() !== $domain) {
140+
continue;
141+
}
142+
143+
//Check whether the image is inside an external link
144+
$parent = $img->parentNode;
145+
146+
while ($parent && isset($parent->tagName)) {
147+
if ($parent->tagName === 'a') {
148+
if ($parent->hasAttribute('href')) {
149+
$href = new Url($parent->getAttribute('href'));
150+
151+
if ($href->getDomain() && $src->getDomain() !== $domain) {
152+
continue 2;
153+
}
154+
}
155+
156+
break;
157+
}
140158

141-
if (!$src->getDomain() || $src->getDomain() === $domain) {
142-
$images[] = $src->getUrl();
159+
$parent = $parent->parentNode;
143160
}
161+
162+
$images[] = $src->getUrl();
144163
}
145164
}
146165

0 commit comments

Comments
 (0)