Conditions | 9 |
Paths | 13 |
Total Lines | 36 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function convert(ElementFinder $finder, string $affectedUrl = '') { |
||
20 | |||
21 | $affected = new Uri($affectedUrl); |
||
22 | |||
23 | $srcElements = $finder->element('//*[@src] | //*[@href] | //form[@action]'); |
||
24 | $baseUrl = $finder->value('//base/@href')->getFirst(); |
||
25 | |||
26 | foreach ($srcElements as $element) { |
||
27 | $attributeName = 'href'; |
||
28 | |||
29 | if ($element->hasAttribute('action') === true and $element->tagName === 'form') { |
||
30 | $attributeName = 'action'; |
||
31 | } else if ($element->hasAttribute('src') === true) { |
||
32 | $attributeName = 'src'; |
||
33 | } |
||
34 | |||
35 | $relative = $element->getAttribute($attributeName); |
||
36 | |||
37 | # don`t change javascript in href |
||
38 | if (preg_match('!^\s*javascript\s*:\s*!', $relative)) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | if (parse_url($relative) === false) { |
||
43 | continue; |
||
44 | } |
||
45 | |||
46 | if ($baseUrl !== null and !preg_match('!^(/|http)!i', $relative)) { |
||
47 | $relative = UriResolver::resolve(new Uri($baseUrl), new Uri($relative)); |
||
48 | } |
||
49 | |||
50 | $url = UriResolver::resolve($affected, new Uri($relative)); |
||
51 | $element->setAttribute($attributeName, (string) $url); |
||
52 | } |
||
53 | |||
54 | } |
||
55 | |||
56 | } |