File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments