You are here

public static function UrlValidator::relativeToRoot in Mini site 8

Convert relative to root-level URL with parent prefix support.

6 calls to UrlValidator::relativeToRoot()
PageProcessor::processTagA in src/PageProcessor.php
Process <a> tag.
PageProcessor::processTagImg in src/PageProcessor.php
Process <img> tag.
PageProcessor::processTagLink in src/PageProcessor.php
Process <link> tag.
PageProcessor::processTagScript in src/PageProcessor.php
Process <script> tag.
PageProcessor::processTagStyle in src/PageProcessor.php
Process <style> tag.

... See full list

File

src/UrlValidator.php, line 75

Class

UrlValidator
Class UrlValidator.

Namespace

Drupal\minisite

Code

public static function relativeToRoot($url, $parent) {
  if (self::urlIsExternal($url)) {
    return $url;
  }
  if (!self::urlIsRelative($url)) {
    if (substr($url, 0, 2) == './') {
      $url = substr($url, 2);
    }
    elseif (substr($url, 0, 1) == '/') {
      $url = substr($url, 1);
    }
  }

  // We assume that all relative links are correctly pointing to the root
  // of the archive, so we are removing all of them and adding a relative
  // path.
  $url = str_replace('../', '', $url);
  $url = rtrim($parent, '/') . '/' . ltrim($url, '/');
  $url = LegacyWrapper::isValidUri($url) ? file_url_transform_relative(file_create_url($url)) : $url;

  // Decode URL encoded in file_create_url().
  $url = rawurldecode($url);
  $url = '/' . ltrim($url, '/');
  return $url;
}