You are here

function _feeds_tamper_absolute_url in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 plugins/absolute_url.inc \_feeds_tamper_absolute_url()
1 call to _feeds_tamper_absolute_url()
feeds_tamper_absolute_url_callback in plugins/absolute_url.inc

File

plugins/absolute_url.inc, line 63

Code

function _feeds_tamper_absolute_url($r_url, &$urls, $b) {
  if (!strlen($r_url)) {
    return;
  }
  $r = parse_url($r_url);
  if ($r === FALSE) {
    return;
  }
  if (!empty($r['scheme']) || !empty($r['host'])) {
    return;
  }
  $r['scheme'] = $b['scheme'];
  unset($r['port']);
  unset($r['user']);
  unset($r['pass']);

  // Copy base authority.
  $r['host'] = $b['host'];
  if (isset($b['port'])) {
    $r['port'] = $b['port'];
  }
  if (isset($b['user'])) {
    $r['user'] = $b['user'];
  }
  if (isset($b['pass'])) {
    $r['pass'] = $b['pass'];
  }

  // If relative URL has no path, use base path.
  if (empty($r['path'])) {
    if (!empty($b['path'])) {
      $r['path'] = $b['path'];
    }
    if (!isset($r['query']) && isset($b['query'])) {
      $r['query'] = $b['query'];
    }
    $urls[$r_url] = _feeds_tamper_join_url($r);
    return;
  }

  // If relative URL path doesn't start with /, merge with base path.
  if (strpos($r['path'], '/') !== 0) {
    if (empty($b['path'])) {
      $b['path'] = '';
    }
    $r['path'] = $b['path'] . '/' . $r['path'];
  }
  $urls[$r_url] = _feeds_tamper_join_url($r);
}