function absolutize_url($relative, $base) { $relative = trim($relative); $base = trim($base); if (!empty($relative)) { $relative = SimplePie_Misc::parse_url($relative, false); $relative = array('scheme' => $relative[2], 'authority' => $relative[3], 'path' => $relative[5], 'query' => $relative[7], 'fragment' => $relative[9]); if (!empty($relative['scheme'])) { $target = $relative; } else { if (!empty($base)) { $base = SimplePie_Misc::parse_url($base, false); $base = array('scheme' => $base[2], 'authority' => $base[3], 'path' => $base[5], 'query' => $base[7], 'fragment' => $base[9]); $target['scheme'] = $base['scheme']; if (!empty($relative['authority'])) { $target = array_merge($relative, $target); } else { $target['authority'] = $base['authority']; if (!empty($relative['path'])) { if (strpos($relative['path'], '/') === 0) { $target['path'] = $relative['path']; } else { if (!empty($base['path'])) { $target['path'] = dirname("{$base['path']}.") . '/' . $relative['path']; } else { $target['path'] = '/' . $relative['path']; } } if (!empty($relative['query'])) { $target['query'] = $relative['query']; } $input = $target['path']; $target['path'] = ''; while (!empty($input)) { if (strpos($input, '../') === 0) { $input = substr($input, 3); } else { if (strpos($input, './') === 0) { $input = substr($input, 2); } else { if (strpos($input, '/./') === 0) { $input = substr_replace($input, '/', 0, 3); } else { if (strpos($input, '/.') === 0 && SimplePie_Misc::strendpos($input, '/.') === 0) { $input = substr_replace($input, '/', -2); } else { if (strpos($input, '/../') === 0) { $input = substr_replace($input, '/', 0, 4); $target['path'] = preg_replace('/(\\/)?([^\\/]+)$/msiU', '', $target['path']); } else { if (strpos($input, '/..') === 0 && SimplePie_Misc::strendpos($input, '/..') === 0) { $input = substr_replace($input, '/', 0, 3); $target['path'] = preg_replace('/(\\/)?([^\\/]+)$/msiU', '', $target['path']); } else { if ($input == '.' || $input == '..') { $input = ''; } else { if (preg_match('/^(.+)(\\/|$)/msiU', $input, $match)) { $target['path'] .= $match[1]; $input = substr_replace($input, '', 0, strlen($match[1])); } } } } } } } } } } else { if (!empty($base['path'])) { $target['path'] = $base['path']; } else { $target['path'] = '/'; } if (!empty($relative['query'])) { $target['query'] = $relative['query']; } else { if (!empty($base['query'])) { $target['query'] = $base['query']; } } } } if (!empty($relative['fragment'])) { $target['fragment'] = $relative['fragment']; } } else { return false; } } $return = ''; if (!empty($target['scheme'])) { $return .= "{$target['scheme']}:"; } if (!empty($target['authority'])) { $return .= $target['authority']; } if (!empty($target['path'])) { $return .= $target['path']; } if (!empty($target['query'])) { $return .= "?{$target['query']}"; } if (!empty($target['fragment'])) { $return .= "#{$target['fragment']}"; } } else { $return = $base; } return $return; }