function _update_178_url_fix in Drupal 5
Same name and namespace in other branches
- 4 database/updates.inc \_update_178_url_fix()
2 calls to _update_178_url_fix()
- system_update_178 in modules/
system/ system.install - Update base paths for relative URLs in node and comment content.
- system_update_179 in modules/
system/ system.install - Update base paths for relative URLs in custom blocks, profiles and various variables.
File
- modules/
system/ system.install, line 2797
Code
function _update_178_url_fix($text) {
// Key is the attribute to replace.
$urlpatterns['href'] = "/<a[^>]+href=\"([^\"]+)/i";
$urlpatterns['src'] = "/<img[^>]+src=\"([^\"]+)/i";
$old = $text;
foreach ($urlpatterns as $type => $pattern) {
if (preg_match_all($pattern, $text, $matches)) {
foreach ($matches[1] as $url) {
if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') {
$text = preg_replace('|' . $type . '\\s*=\\s*"' . preg_quote($url) . '\\s*"|', $type . '="' . base_path() . $url . '"', $text);
}
}
}
}
return $text != $old ? $text : FALSE;
}