_update_178_url_fix

5 system.install _update_178_url_fix($text)

2 calls to _update_178_url_fix()

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;
}
Login or register to post comments