[core] Add urljoin (#756)
Adds php-urljoin from https://github.com/fluffy-critter/php-urljoin to replace the custom implementation of 'defaultLinkTo'
This commit is contained in:
parent
9d0452d11b
commit
df58f5bbdb
3 changed files with 144 additions and 9 deletions
lib
11
lib/html.php
11
lib/html.php
|
@ -42,18 +42,11 @@ function backgroundToImg($htmlContent) {
|
|||
|
||||
function defaultLinkTo($content, $server){
|
||||
foreach($content->find('img') as $image) {
|
||||
if(strpos($image->src, 'http') === false
|
||||
&& strpos($image->src, '//') === false
|
||||
&& strpos($image->src, 'data:') === false)
|
||||
$image->src = $server . $image->src;
|
||||
$image->src = urljoin($server, $image->src);
|
||||
}
|
||||
|
||||
foreach($content->find('a') as $anchor) {
|
||||
if(strpos($anchor->href, 'http') === false
|
||||
&& strpos($anchor->href, '//') === false
|
||||
&& strpos($anchor->href, '#') !== 0
|
||||
&& strpos($anchor->href, '?') !== 0)
|
||||
$anchor->href = $server . $anchor->href;
|
||||
$anchor->href = urljoin($server, $anchor->href);
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue