? filter_absolute_urls.patch ? sites/default/settings.php Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.687 diff -u -F^f -r1.687 common.inc --- includes/common.inc 15 Sep 2007 07:33:46 -0000 1.687 +++ includes/common.inc 19 Sep 2007 19:18:36 -0000 @@ -850,6 +850,30 @@ function check_url($uri) { } /** + * Convert relative URLs in a block of HTML to absolute URLs. + * + * @param $url + * A possibly relative URL. + * @param $absolute_url + * Any absolute URL to this Drupal website. + */ +function filter_absolute_urls($url, $absolute_url) { + $absolute_url_root = (preg_match('%(.*://.*?)/%', $absolute_url, $matches) > 0) ? $matches[1] : $absolute_url; + + // Relative URLs. + $src = '%( href| src)="(?!\w+://)([^/][^"]*)"%'; + $dst = '$1="'. $absolute_url .'/$2"'; + $url = preg_replace($src, $dst, $url); + + // URLs that are relative to the root. + $src = '%( href| src)="(?!\w+://)/?([^"]*)"%'; + $dst = '$1="'. trim($absolute_url_root, '/') .'/$2"'; + $url = preg_replace($src, $dst, $url); + + return $url; +} + +/** * @defgroup format Formatting * @{ * Functions to format numbers, strings, dates, etc. @@ -889,7 +913,7 @@ function format_rss_item($title, $link, $output = "\n"; $output .= ' '. check_plain($title) ."\n"; $output .= ' '. check_url($link) ."\n"; - $output .= ' '. check_plain($description) ."\n"; + $output .= ' '. check_plain(filter_absolute_urls($description, $link)) ."\n"; $output .= format_xml_elements($args); $output .= "\n";