1 |
1626
|
darkviper
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* Convert full qualified, local URLs into relative URLs
|
4 |
|
|
* @param string $content
|
5 |
|
|
* @return string
|
6 |
|
|
*/
|
7 |
|
|
function doFilterRelUrl($content) {
|
8 |
|
|
$content = preg_replace_callback(
|
9 |
|
|
'/((?:href|src)\s*=\s*")([^\"]*?)(")/iU',
|
10 |
|
|
create_function('$matches',
|
11 |
|
|
'$retval = $matches[0]; '.
|
12 |
|
|
'$h = parse_url($matches[2], PHP_URL_HOST); '.
|
13 |
|
|
'if(isset($h) && $h != \'\') { '.
|
14 |
|
|
'if(stripos(WB_URL, $h) !== false) { '.
|
15 |
|
|
'$a = parse_url($matches[2]); '.
|
16 |
|
|
'$p = (isset($a[\'path\']) ? $a[\'path\'] : \'\'); '.
|
17 |
|
|
'$q = (isset($a[\'query\']) ? \'?\'.$a[\'query\'] : \'\'); '.
|
18 |
|
|
'$f = (isset($a[\'fragment\']) ? \'#\'.$a[\'fragment\'] : \'\'); '.
|
19 |
|
|
'$p .= ($q.$f); '.
|
20 |
|
|
'$retval = $matches[1]."/".(isset($p) ? ltrim(str_replace("//", "/", $p), "/") : "").$matches[3]; '.
|
21 |
|
|
'}} return $retval;'),
|
22 |
|
|
$content);
|
23 |
|
|
return $content;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
?>
|