Duplicate a file given it's URL

@param  string $url
@return string
517160
public function duplicate($url) {

		// Make the destination path
		$current_path = $this->helpers->path($url);
		$filename = basename($current_path);
		$dst_disk = $this->disks ? $this->disks->getFilesystem('dst') : $this->disk;
		$new_path = $this->storage->makeNestedAndUniquePath($filename, $dst_disk);

		// Copy, supporting alternative destination disks
		if ($this->disks) $this->disks->copy('src://'.$current_path, 'dst://'.$new_path);
		else $this->disk->copy($current_path, $new_path);

		// Return the Upchuck URL
		return $this->helpers->url($new_path);
	}
424505
private function generateUrl($url)
    {
        if ($this->packages) {
            return $this->packages->getUrl($url);
        }

        if ($this->coreAssetsHelper) {
            // To remove when compatibility with Symfony 2.7 is dropped
            return $this->coreAssetsHelper->getUrl($url);
        }

        return $url;
    }
1095489
public static function explode_url($url)
    {
        $protocol = "";
        $host = "";
        $path = "";
        $file = "";

        $arr = parse_url($url);
        if ( isset($arr["scheme"]) ) {
            $arr["scheme"] = mb_strtolower($arr["scheme"]);
        }

        // Exclude windows drive letters...
        if (isset($arr["scheme"]) && $arr["scheme"] !== "file" && strlen($arr["scheme"]) > 1) {
            $protocol = $arr["scheme"] . "://";

            if (isset($arr["user"])) {
                $host .= $arr["user"];

                if (isset($arr["pass"])) {
                    $host .= ":" . $arr["pass"];
                }

                $host .= "@";
            }

            if (isset($arr["host"])) {
                $host .= $arr["host"];
            }

            if (isset($arr["port"])) {
                $host .= ":" . $arr["port"];
            }

            if (isset($arr["path"]) && $arr["path"] !== "") {
                // Do we have a trailing slash?
                if ($arr["path"][mb_strlen($arr["path"]) - 1] === "/") {
                    $path = $arr["path"];
                    $file = "";
                } else {
                    $path = rtrim(dirname($arr["path"]), '/\\') . "/";
                    $file = basename($arr["path"]);
                }
            }

            if (isset($arr["query"])) {
                $file .= "?" . $arr["query"];
            }

            if (isset($arr["fragment"])) {
                $file .= "#" . $arr["fragment"];
            }

        } else {

            $i = mb_stripos($url, "file://");
            if ($i !== false) {
                $url = mb_substr($url, $i + 7);
            }

            $protocol = ""; // "file://"; ? why doesn't this work... It's because of
            // network filenames like //COMPU/SHARENAME

            $host = ""; // localhost, really
            $file = basename($url);

            $path = dirname($url);

            // Check that the path exists
            if ($path !== false) {
                $path .= '/';

            } else {
                // generate a url to access the file if no real path found.
                $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';

                $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : php_uname("n");

                if (substr($arr["path"], 0, 1) === '/') {
                    $path = dirname($arr["path"]);
                } else {
                    $path = '/' . rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/') . '/' . $arr["path"];
                }
            }
        }

        $ret = array($protocol, $host, $path, $file,
            "protocol" => $protocol,
            "host" => $host,
            "path" => $path,
            "file" => $file);
        return $ret;
    }
117939
public function getRequestUrl($url)
    {
        if ($this->getPerPage() && $this->getPage()) {
            return $url . $this->getRequestPageInfo();
        }

        return $url;
    }
485308
public static function OpenRemoteDocument($url)
	{
		// Expression Regular:
		// [1]: http or ftp
		// [2]: Server name
		// [4]: Full Path
		$pat = '/(http|ftp|https):\\/\\/((\\w|\\.)+)/i';
		$urlParts = preg_split($pat, $url, -1,PREG_SPLIT_DELIM_CAPTURE);

		$handle = fsockopen($urlParts[2], 80, $errno, $errstr, 30);
		if (!$handle)
		{
			throw new FileUtilException("Socket error: $errstr ($errno)");
		}
		else
		{
			$out = "GET " . $urlParts[4] . " HTTP/1.1\r\n";
			$out .= "Host: " . $urlParts[2] . "\r\n";
			$out .= "Connection: Close\r\n\r\n";

			fwrite($handle, $out);

			return $handle;
		}
	}
101119
protected function _getAssetFile($url) {
		$parts = explode('/', $url);
		if ($parts[0] === 'theme') {
			$themeName = $parts[1];
			unset($parts[0], $parts[1]);
			$fileFragment = implode(DS, $parts);
			$path = App::themePath($themeName) . 'webroot' . DS;
			return $path . $fileFragment;
		}

		$plugin = Inflector::camelize($parts[0]);
		if ($plugin && CakePlugin::loaded($plugin)) {
			unset($parts[0]);
			$fileFragment = implode(DS, $parts);
			$pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS;
			return $pluginWebroot . $fileFragment;
		}

		$webroot = APP . 'webroot' . DS;
		$fileFragment = implode(DS, $parts);
		if (file_exists($webroot . $parts[0])) {
			return $webroot . $fileFragment;
		}

		$router = Router::parse($url);
		if (strpos($router['controller'], '.') !== false || strpos($router['action'], '.') !== false) {
			return 'webroot' . DS . $fileFragment;
		}
	}
1147968
public function setUrl($url)
    {
        $this->url = $url;

        // Normalize URL if its relative (strictly speaking), or has leading slashes
        if (Director::is_relative_url($url) || preg_match('/^\//', $url)) {
            $this->url = preg_replace(array('/\/+/','/^\//', '/\/$/'), array('/','',''), $this->url);
        }
        if (preg_match('/^(.*)\.([A-Za-z][A-Za-z0-9]*)$/', $this->url, $matches)) {
            $this->url = $matches[1];
            $this->extension = $matches[2];
        }
        if ($this->url) {
            $this->dirParts = preg_split('|/+|', $this->url);
        } else {
            $this->dirParts = array();
        }

        return $this;
    }
704355
public function duplicate($hash, $suffix='copy') {
		if ($this->commandDisabled('duplicate')) {
			return $this->setError(elFinder::ERROR_COPY, '#'.$hash, elFinder::ERROR_PERM_DENIED);
		}
		
		if (($file = $this->file($hash)) == false) {
			return $this->setError(elFinder::ERROR_COPY, elFinder::ERROR_FILE_NOT_FOUND);
		}

		$path = $this->decode($hash);
		$dir  = $this->_dirname($path);

		return ($path = $this->copy($path, $dir, $this->uniqueName($dir, $this->_basename($path), ' '.$suffix.' '))) == false
			? false
			: $this->stat($path);
	}
1066982
protected function expandUrl($url)
    {
        // skip if no short url
        if (!ParserUtil::isShortUrl($url)) {
            return $url;
        }

        $header_location = get_headers($url, 1)['Location'];

        return $header_location ?: $url;
    }
1135267
public function getCuztomUrl($path = __FILE__, $url = [])
    {
        // Retun URL if defined
        if (defined('CUZTOM_URL')) {
            return CUZTOM_URL;
        }

        // Base vars
        $path = dirname($path);
        $path = str_replace('\\', '/', $path);
        $expath = explode('/', $path);
        $current = $expath[count($expath) - 1];

        // Push to path array
        array_push($url, $current);

        // Check for current
        if (preg_match('/content|app/', $current)) {
            $path = '';
            $directories = array_reverse($url);

            foreach ($directories as $dir) {
                if (! preg_match('/content|app/', $dir)) {
                    $path = $path.'/'.$dir;
                }
            }

            return apply_filters('cuztom_url', WP_CONTENT_URL.$path);
        } else {
            return $this->getCuztomUrl($path, $url);
        }
    }
250569
protected static function resolveUrl($url)
    {
        $url = trim($url);
        if (strlen($url)) {
            if (preg_match('%^https?\:\/\/%', $url)) {
                return $url;
            }
            $absScript = GeneralUtility::getFileAbsFileName($url);
            if (is_file($absScript)) {
                return substr($absScript, strlen(PATH_site));
            }
        }

        return null;
    }
623194
private function buildUrl($url)
    {
        if (!is_array($url)) {
            if (strpos($url, '://')) {
                return (string) $url;
            }
            return (string) $this->baseUrl->combine($url);
        } elseif (strpos($url[0], '://')) {
            return \GuzzleHttp\uri_template($url[0], $url[1]);
        }

        return (string) $this->baseUrl->combine(
            \GuzzleHttp\uri_template($url[0], $url[1])
        );
    }
741312
public static function getInstanceByRemote($url)
    {
        $validator = new UrlValidator();
        if ($validator->validate($url, $error)) {
            $url = str_replace("&amp;", "&", $url);
            $http = new Client();
            $response = $http->get($url)->send();
            if (!$response->isOk) {
                return null;
            } else {
                $baseName = basename($url);
                $tempPath = FileHelper::getTempFilePath($baseName);
                file_put_contents($tempPath, $response->content);
                return new static([
                    'isUploadedFile' => false,
                    'name' => $baseName,
                    'tempName' => $tempPath,
                    'type' => FileHelper::getMimeType($tempPath),
                    'size' => strlen($response->content),
                    'error' => UPLOAD_ERR_OK,
                ]);
            }
        } else {
            return null;
        }
    }
712272
public function shorten($url)
    {
        $link = new Link;
        $link->setLongUrl($url);
        $this->provider->shorten($link);
        return $link->getShortUrl();
    }
142174
private function parseUrl($url)
	{
		$newUrl = preg_replace($this->patterns, $this->replacements, $url);
		$newUrl = trim($newUrl, '\/?');
		$newUrl = trim($newUrl, '\/');

		return $newUrl;
	}
735140
private function urlGen($url)
    {
        if (empty($url) && empty($this->url)) {
            throw new \Exception("URL not set!", 1);
        }
        return empty($url) ? $this->url : $url;
    }
300209
public function setUrl($url)
    {
        if (strpos($url, '/') !== 0) {
            $url = '/' . $url;
        }
        $this->url = $url;
        return $this;
    }