Returns url for filename.

@param string $fileName The filename
@param string $content The content
@param string $urlBasePath The url base path

@return string The url
438914
public function createCacheBustedUrl(string $fileName, string $content, string $urlBasePath): string
    {
        $cacheFile = $this->createPublicCacheFile($fileName, $content);

        return $urlBasePath . pathinfo($cacheFile, PATHINFO_BASENAME);
    }
1298040
def getUrlFromFilename(self, filename):
        """"""
        components = util.splitpath(util.getRelativePath(self.basepath, filename))
        url = '/'.join([url_quote(component, '') for component in components])
        return self.baseurl + url
279699
public function getUrlPageName()
    {
        if (static::$urlPageName !== null) {
            return static::$urlPageName;
        }

        /*
         * Cache
         */
        $key = 'urlMaker'.$this->urlComponentName.crc32(get_class($this));

        $cached = Cache::get($key, false);
        if ($cached !== false && ($cached = @unserialize($cached)) !== false) {
            $filePath = array_get($cached, 'path');
            $mtime = array_get($cached, 'mtime');
            if (!File::isFile($filePath) || ($mtime != File::lastModified($filePath))) {
                $cached = false;
            }
        }

        if ($cached !== false) {
            return static::$urlPageName = array_get($cached, 'fileName');
        }

        /*
         * Fallback
         */
        $page = null;
        $useProperty = property_exists($this, 'urlComponentProperty');

        if ($useProperty) {
            $page = Page::whereComponent($this->urlComponentName, $this->urlComponentProperty, '1')->first();
        }

        if (!$useProperty || !$page) {
            $page = Page::withComponent($this->urlComponentName)->first();
        }

        if (!$page) {
            throw new ApplicationException(sprintf(
                'Unable to a find a primary component "%s" for generating a URL in %s.',
                $this->urlComponentName,
                get_class($this)
            ));
        }

        $baseFileName = $page->getBaseFileName();
        $filePath = $page->getFilePath();

        $cached = [
            'path'     => $filePath,
            'fileName' => $baseFileName,
            'mtime'    => @File::lastModified($filePath)
        ];

        Cache::put($key, serialize($cached), Config::get('cms.parsedPageCacheTTL', 1440));

        return static::$urlPageName = $baseFileName;
    }
493099
protected function getDocument( $content, $url )
	{
		$doc = new DOMDocument();
		ob_start();
		if( !@$doc->loadHTML( $content ) )
		{
			$content	= ob_get_clean();
			if( $content )
				$this->errors[$url]	= $content;
			throw new RuntimeException( 'Error reading HTML.' );
		}
		ob_end_clean();
		return $doc;
	}
984106
public static function getUrlPathFromFilePath($filePath, $relativeToRootUrl = false) {
		$dir = $filePath;
		$rootPath = ROOT_PATH;
		
		if (strpos($dir, ROOT_PATH) === 0) {
			$dirUrl = ROOT_URL.substr(ROOT_PATH, strlen(__DIR__)+1);
		} else {
			// The directory URL is below the ROOT_URL. Let's try to find it (not 100% success rate)
			$rootPaths = explode(DIRECTORY_SEPARATOR, trim($rootPath, DIRECTORY_SEPARATOR));
			$thisDirs = explode(DIRECTORY_SEPARATOR, trim($dir, DIRECTORY_SEPARATOR));
		
			for ($i=0; $i<count($rootPaths); $i++) {
				if ($rootPaths[$i] != $thisDirs[$i]) {
					break;
				}
			}
		
			$nbSkip = count($rootPaths) - $i;
			$urls = explode('/', trim(ROOT_URL, '/'));
		
			if ($nbSkip > count($urls)) {
				throw new Exception('The directory "'.$dir.'" is almost certainly out of reach from the web.');
			}
		
			$dirUrls = array();
			for ($j=0; $j < count($urls)- $nbSkip; $j++) {
				$dirUrls[] = $urls[$j];
			}
			for ($k = $i; $k<count($thisDirs); $k++) {
				$dirUrls[] = $thisDirs[$k];
			}
			$dirUrl = '/'.implode('/', $dirUrls);
			
			if ($relativeToRootUrl) {
				$dirUrl = ltrim(str_repeat('/..', count($urls)).$dirUrl, '/');
			}
		}
		return $dirUrl;
	}
1196623
public static function absolute_url($path, $base_url)
    {
        // check if path is an absolute URL
        if (preg_match('/^[fhtps]+:\/\//', $path)) {
            return $path;
        }

        // check if path is a content-id scheme
        if (strpos($path, 'cid:') === 0) {
            return $path;
        }

        $host_url = $base_url;
        $abs_path = $path;

        // cut base_url to the last directory
        if (strrpos($base_url, '/') > 7) {
            $host_url = substr($base_url, 0, strpos($base_url, '/', 7));
            $base_url = substr($base_url, 0, strrpos($base_url, '/'));
        }

        // $path is absolute
        if ($path[0] == '/') {
            $abs_path = $host_url.$path;
        }
        else {
            // strip './' because its the same as ''
            $path = preg_replace('/^\.\//', '', $path);

            if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) {
                $cnt = count($matches);
                while ($cnt--) {
                    if ($pos = strrpos($base_url, '/')) {
                        $base_url = substr($base_url, 0, $pos);
                    }
                    $path = substr($path, 3);
                }
            }

            $abs_path = $base_url.'/'.$path;
        }

        return $abs_path;
    }
990388
static public function file($content, $filename = '')
    {
        if (isset(Loader::$callback['CacheFile'])) {
            return call_user_func_array(Loader::$callback['CacheFile'], func_get_args());
        }
        empty($filename) && $filename = md5($content) . '.' . self::getFileExt($content);
        if (self::check() && file_put_contents(self::$cachepath . $filename, $content)) {
            return self::$cachepath . $filename;
        }
        return false;
    }
942417
def filename_from_url(url, path=None):
    
    r = requests.get(url, stream=True)
    if 'Content-Disposition' in r.headers:
        filename = re.findall(r'filename=([^;]+)',
                              r.headers['Content-Disposition'])[0].strip('"\"')
    else:
        filename = os.path.basename(urllib.parse.urlparse(url).path)
    return filename
588935
private function getAlternate($url, $webspaceKey, $locale, $default = false)
    {
        $url = $this->contentPath->getContentPath($url, $webspaceKey, $locale);

        return sprintf(
            '<link rel="alternate" href="%s" hreflang="%s" />',
            $url,
            !$default ? str_replace('_', '-', $locale) : 'x-default'
        );
    }
491385
public function getUrl(string $filename): GetUrlCommand
    {
        /** @var GetUrlCommand $command */
        $command = $this->builder->build(GetUrlCommand::class);
        $command->byFilename($filename);

        return $command;
    }
1282927
@Pure
	public static URL join(URL urlBase, String... elements) {
		if (urlBase == null) {
			return null;
		}
		final StringBuilder buf = new StringBuilder(decodeHTMLEntities(urlBase.getPath().replaceFirst(
				Pattern.quote(URL_PATH_SEPARATOR) + "+$", "")));  //$NON-NLS-1$//$NON-NLS-2$
		boolean empty;
		for (final String elt : elements) {
			empty = elt == null || elt.length() == 0;
			if (!empty) {
				assert elt != null;
				if (!elt.startsWith(File.separator)
						&& (buf.length() == 0
						|| buf.charAt(buf.length() - 1) != URL_PATH_SEPARATOR_CHAR)) {
					buf.append(URL_PATH_SEPARATOR_CHAR);
				}
				buf.append(elt);
			}
		}
		try {
			if (isJarURL(urlBase)) {
				return new URL(
						urlBase.getProtocol(),
						urlBase.getHost(),
						urlBase.getPort(),
						buf.toString());
			}
			return new URI(
					urlBase.getProtocol(),
					urlBase.getUserInfo(),
					urlBase.getHost(),
					urlBase.getPort(),
					buf.toString(),
					decodeHTMLEntities(urlBase.getQuery()),
					urlBase.getRef()).toURL();
		} catch (Throwable exception) {
			//
		}
		try {
			return new URL(
					urlBase.getProtocol(),
					urlBase.getHost(),
					buf.toString());
		} catch (Throwable exception) {
			return null;
		}
	}
1067660
@Pure
	@SuppressWarnings("checkstyle:npathcomplexity")
	public static URL dirname(URL filename) {
		if (filename == null) {
			return null;
		}

		URL prefix = null;
		String path;
		if (isJarURL(filename)) {
			prefix = getJarURL(filename);
			path = fromFileStandardToURLStandard(getJarFile(filename));
		} else {
			path = filename.getPath();
		}

		if ("".equals(path)) { //$NON-NLS-1$
			return null;
		}

		int idx = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
		if (idx == path.length() - 1) {
			idx = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR, path.length() - 2);
		}

		if (idx < 0) {
			if (URISchemeType.getSchemeType(filename).isFileBasedScheme()) {
				path = CURRENT_DIRECTORY;
			} else {
				path = URL_PATH_SEPARATOR;
			}
		} else {
			path = path.substring(0, idx + 1);
		}

		try {
			if (prefix != null) {
				return toJarURL(prefix, path);
			}
			return new URI(filename.getProtocol(),
					filename.getUserInfo(),
					filename.getHost(),
					filename.getPort(),
					decodeHTMLEntities(path),
					null,
					null).toURL();
		} catch (Throwable exception) {
			//
		}

		try {
			return new URL(
					filename.getProtocol(),
					filename.getHost(),
					path);
		} catch (Throwable exception) {
			//
		}
		return null;
	}
1208475
@Pure
	public static URL findLibraryURL(String libName) {
		return findLibraryURL(null, libName, null, null);
	}
603997
public static function getClassFullNameFromFile($filePathName, $backSlash = false) {
		$phpCode = \file_get_contents ( $filePathName );
		$ns = self::getClassNamespaceFromPhpCode ( $phpCode );
		if ($backSlash && UString::isNotNull ( $ns )) {
			$ns = "\\" . $ns;
		}
		return $ns . '\\' . self::getClassNameFromPhpCode ( $phpCode );
	}
632408
@Pure
	public static URL join(URL urlBase, File... elements) {
		if (urlBase == null) {
			return null;
		}
		final StringBuilder buf = new StringBuilder(urlBase.getPath());
		for (final File elt : elements) {
			if (!elt.isAbsolute() && (buf.length() == 0 || buf.charAt(buf.length() - 1) != URL_PATH_SEPARATOR_CHAR)) {
				buf.append(URL_PATH_SEPARATOR_CHAR);
			}
			buf.append(fromFileStandardToURLStandard(elt));
		}
		try {
			if (isJarURL(urlBase)) {
				return new URL(
						urlBase.getProtocol(),
						urlBase.getHost(),
						urlBase.getPort(),
						buf.toString());
			}
			return new URI(
					urlBase.getProtocol(),
					urlBase.getUserInfo(),
					urlBase.getHost(),
					urlBase.getPort(),
					decodeHTMLEntities(buf.toString()),
					decodeHTMLEntities(urlBase.getQuery()),
					urlBase.getRef()).toURL();
		} catch (Throwable exception) {
			//
		}
		try {
			return new URL(
					urlBase.getProtocol(),
					urlBase.getHost(),
					buf.toString());
		} catch (Throwable exception) {
			return null;
		}
	}
401484
public function getRelPath($content)
    {
        if (! $content instanceof File && ! $content instanceof Directory) {
            throw new \common_Exception('Content for ' . __FUNCTION__ . ' has to be a file or directory object. ' .
                is_object($content) ? get_class($content) : gettype($content) . ' given.');
        }

        return str_replace($this->getPrefix(), '', $content->getPrefix());
    }
1017881
public static function parse(string $urlPath): UrlPathInterface
    {
        if (!self::myParse(
            '/',
            $urlPath,
            function ($p, $d, &$e) {
                return self::myPartValidator($p, $d, $e);
            },
            function ($s) {
                return rawurldecode($s);
            },
            $isAbsolute,
            $aboveBaseLevel,
            $directoryParts,
            $filename,
            $error)
        ) {
            throw new UrlPathInvalidArgumentException($error = 'Url path "' . $urlPath . '" is invalid: ' . $error);
        }

        return new self($isAbsolute, $aboveBaseLevel, $directoryParts, $filename);
    }