=== modified file 'includes/common.inc' --- includes/common.inc 2007-09-12 09:47:23 +0000 +++ includes/common.inc 2007-10-11 15:01:42 +0000 @@ -895,6 +895,41 @@ return $output; } + /** + * Convert relative URLs in a block of HTML to absolute URLs. + * + * @param $html + * A chunk of HTML. + * @param $base_document + * Optional url to which the chunk of HTML is relative to. + * @return + * The same HTML with URL in <... href=""> and <... src=""> attributes + * changed to absolute. + */ +function drupal_force_absolute_urls($html, $base_document = NULL) { + if(!isset($base_document)) { + global $base_url; + $base_document = $base_url; + } + $base_document_root = (preg_match('%(\w+://.*?)/%', $base_document, $matches)>0) ? $matches[1] : trim($base_document, '/'); + $base_document = substr($base_document, 0, strrpos($base_document,'/')); + + $src = array( + '/(\<[^\>]*? href| src)="(?!\w+:\/\/)([^\/][^"]*)"/i', + '/(\<[^\>]*? href| src)="(?!\w+:\/\/)\/?([^"]*)"/i' + ); + $dst = array( + '$1="'. $base_document .'/$2"', + '$1="'. $base_document_root .'/$2"' + ); + $html = preg_replace($src, $dst, $html); + + return $html; +} + +/** + + /** * Format a single RSS item. * @@ -904,7 +939,7 @@ $output = "\n"; $output .= ' '. check_plain($title) ."\n"; $output .= ' '. check_url($link) ."\n"; - $output .= ' '. check_plain($description) ."\n"; + $output .= ' '. check_plain(drupal_force_absolute_urls($description, $link)) ."\n"; $output .= format_xml_elements($args); $output .= "\n";