Some images (such as background images) are defined in
stylesheets and are not filtered out. Here is the new
filter function that fixes this problem:
function modify_urls()
{
preg_match_all("#\s(href|src|action|codebase|url)
=([\"\'])?(.*?)([\"\'])?([\s\>])#i", $this->response_body,
$matches, PREG_SET_ORDER);
foreach ($matches as $match)
{
$uri = trim($match[3]);
$fragment = ($hash_pos = strpos($uri, '#') !==
false) ? '#' . substr($uri, $hash_pos) : '';
if (!preg_match('#^[\w+.-]+://#i', $uri))
{
switch (substr($uri, 0, 1))
{
case '/':
$uri = $this->url_segments
['scheme'] . '://' . $this->url_segments['host'] . $uri;
break;
case '?':
$uri = $this->url_segments
['base'] . '/' . $this->url_segments['file'] . $uri;
break;
case '#':
continue 2;
break;
case 'm':
if (substr($uri, 0, 7) == 'mailto:')
{
continue 2;
}
default:
$uri = $this->url_segments
['base'] . '/' . $uri;
break;
}
}
$uri = $this->encode_url($uri);
$replace = ' ' . $match[1] . '=' . $match[2] .
$this->script_url . '?url=' . $uri . $fragment . $match[4] .
$match[5];
$this->response_body = str_replace($match[0],
$replace, $this->response_body);
}
preg_match_all("#(url[(])(.*?)([)])#i", $this-
>response_body, $matches, PREG_SET_ORDER);
foreach ($matches as $match)
{
$uri = trim($match[2]);
$fragment = ($hash_pos = strpos($uri, '#') !==
false) ? '#' . substr($uri, $hash_pos) : '';
if (!preg_match('#^[\w+.-]+://#i', $uri))
{
switch (substr($uri, 0, 1))
{
case '/':
$uri = $this->url_segments
['scheme'] . '://' . $this->url_segments['host'] . $uri;
break;
case '?':
$uri = $this->url_segments
['base'] . '/' . $this->url_segments['file'] . $uri;
break;
case '#':
continue 2;
break;
case 'm':
if (substr($uri, 0, 7) == 'mailto:')
{
continue 2;
}
default:
$uri = $this->url_segments
['base'] . '/' . $uri;
break;
}
}
$uri = $this->encode_url($uri);
$replace = $match[1] . $this->script_url . '?
url=' . $uri . $fragment . $match[3];
$this->response_body = str_replace($match[0],
$replace, $this->response_body);
}
}