You are here

function _update_178_url_fix in Drupal 4

Same name and namespace in other branches
  1. 5 modules/system/system.install \_update_178_url_fix()
2 calls to _update_178_url_fix()
system_update_178 in database/updates.inc
Update base paths for relative URLs in node and comment content.
system_update_179 in database/updates.inc
Update base paths for relative URLs in custom blocks, profiles and various variables.

File

database/updates.inc, line 1741

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;
}