You are here

function feeds_tamper_absolute_url_callback in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 plugins/absolute_url.inc \feeds_tamper_absolute_url_callback()
1 string reference to 'feeds_tamper_absolute_url_callback'
absolute_url.inc in plugins/absolute_url.inc

File

plugins/absolute_url.inc, line 26

Code

function feeds_tamper_absolute_url_callback($result, $item_key, $element_key, &$field, $settings, $source) {
  static $dom;
  $b = parse_url($result->link);
  if (!isset($dom)) {
    $dom = new DOMDocument();
  }
  $field = (string) $field;
  if (!$field) {
    return;
  }

  // Supress warnings for invalid HTML.
  $errors = libxml_use_internal_errors(TRUE);
  $entity_loader = libxml_disable_entity_loader(TRUE);
  $dom
    ->loadHTML($field);
  libxml_clear_errors();
  libxml_use_internal_errors($errors);
  libxml_disable_entity_loader($entity_loader);
  $urls = array();
  $tags = array(
    'a' => 'href',
    'img' => 'src',
    'iframe' => 'src',
    'script' => 'src',
    'object' => 'codebase',
    'link' => 'href',
    'applet' => 'code',
    'base' => 'href',
  );
  foreach ($tags as $tag => $attr) {
    foreach ($dom
      ->getElementsByTagName($tag) as $t) {
      $value = trim($t
        ->getAttribute($attr));
      _feeds_tamper_absolute_url($value, $urls, $b);
    }
  }
  $field = strtr($field, $urls);
}