custom.info
Convert relative urls to absolute urls in feeds
custom.module
<?php
/** taked from http://drupal.org/files/issues/drupal_force_absolute_urls_2.patch
* 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;
}
function absoluteurlfeeds_nodeapi(&$node, $op, $teaser, $page) {
switch($op) {
case 'rss item':
if ($node->type == 'story') {
$node->teaser = drupal_force_absolute_urls($node->teaser);
$node->body = drupal_force_absolute_urls($node->body);
return;
}
}
}
I know, It's not working.
So, can you help ?
Comments
Absolute URL's in Drupal Teasers
Check out http://drupal.org/project/pathologic. "...Pathologic can also solve the problem of missing images and broken links in your site’s RSS feeds...."