Returns a shorter representation of the given URL. Similar to URL shortening services like bit.ly, etc.

@param string $url

@return string|null
496799
public function shorten ($url)
    {
        $shortened = null;
        
        $this->shortenAll([$url], function ($error, $short, $long) use (&$shortened) {
            $shortened = $short;
        });
        
        return $shortened;
    }
879394
public static function normalizeUrl($url)
        {
            if (substr($url, 0, 1) != '/') $url = '/' . $url;

            if (substr($url, -1) == '/') $url = substr($url, 0, -1);

            if (!strlen($url)) $url = '/';

            return $url;
        }
492912
public function shorten($url)
    {
        $short = $this->exists($url);

        if (false !== $short) {
            return $short;
        }

        return route('shortener.show', [
            'url' => $this->hashids->encode($this->save($url)),
        ]);
    }
88414
public static function wwwLess($url) {
		if (strpos($url, 'www.') === 0 && substr_count($url, '.') > 1) {
			$url = substr($url, 4);
		}
		return $url;
	}
439796
private function split($url)
    {
        $parts = parse_url($url) + array(
                'scheme' => 'http',
                'query' => '',
                'path' => '',
            );

        $parts['prefix'] = '';
        if (isset($parts['host'])) {
            $parts['prefix'] = sprintf('%s://%s', $parts['scheme'], $parts['host']);
        }

        return $parts;
    }
407020
public function queryString($url = null)
    {
        $query = '';

        if (!$url)
        {
            $url = $this->server('request_uri');
        }

        $position = mb_strpos($url, '?');

        if ($position !== false)
        {
            $query = mb_substr($url, $position + 1);
        }

        return $query;
    }
458164
public static function sanitizeUrl(string $url) : string
    {
        $url_no_protocol = $url;
        if (stristr($url, "https://")) {
            $tmp             = explode("https://", $url);
            $url_no_protocol = $tmp[1];
        } else {
            if (stristr($url, "http://")) {
                $tmp             = explode("http://", $url);
                $url_no_protocol = $tmp[1];
            }
        }

        if ($url_no_protocol == '') {
            return '';
        }

        return rtrim($url_no_protocol, '/');
    }
527210
public static function shortenUrl($inputUrl)
	{
		if(!self::checkInput($inputUrl)) { return false; }

		$encodedUrl = rawurlencode($inputUrl);
		$contextOptions = array(
			'ssl' => array(
				'verify_peer' => false,
				//'verify_peer' => true, // You could skip all of the trouble by changing this to false, but it's WAY uncool for security reasons.
				//'cafile' => require 'base/ssl/cacert.pem',
				//'CN_match' => 'is.gd', // Change this to your certificates Common Name (or just comment this line out if not needed)
				//'ciphers' => 'HIGH:!SSLv2:!SSLv3',
				//'disable_compression' => true,
			)
		);
		$context = stream_context_create($contextOptions);
		$shortenedUrl = file_get_contents(self::ISGD_BASIC . $encodedUrl, false, $context);

		return self::checkResult($shortenedUrl);
	}
87464
public function embedCodeFor(string $url)
    {
        if (!$parsedUrl = $this->embedder->parseUrl($url)) {
            return null;
        }

        return $parsedUrl->getEmbedCode();
    }
662180
public static function sanitizeUrl($url)
    {
        $url = trim($url);

        if (!$url) {
            return null;
        }

        if (!preg_match("/^https?:\/\//i", $url)) {
            $url = "http://" . $url;
        }

        return self::sanitizeString($url);
    }
1273389
protected function removeLastPart($url)
    {
        $shortenUrl = null;

        if ($url !== null && $url !== '') {
            // split on the / character
            $keywords = preg_split("/\//", $url);

            //if there are some words, we pop the last
            if (count($keywords) > 0) {
                array_pop($keywords);

                //rebuild the url
                $shortenUrl = implode('/', $keywords);
            }
        }

        return $shortenUrl;
    }
1253106
public function byURL($url) {
        $URL = \Convert::raw2sql($url);
        return $this->owner->filter('URLSegment', $URL)->first();
    }
456050
public function shortenUrl($url, $provider)
    {
        if (!empty($url) && !empty($provider)) {
            if ($provider == 'tinyurl') {
                $url_data = sprintf($this->_tinyUrlShortApiUrl, $url);
            } elseif ($provider == 'google') {
                $url_data = sprintf('%s/url', $this->_googleShortApiUrl);
            }

            switch ($provider) {
                case 'tinyurl':
                    $ch = curl_init($url_data);  
                    $timeout = 5;  
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
                    $result = curl_exec($ch);  
                    curl_close($ch);

                    return $result; 
                    break;

                case 'google':
                    $ch = curl_init($url_data);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    $requestData = array(
                        'longUrl' => $url
                    );

                    curl_setopt($ch, CURLOPT_POST, true);
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData));
                    $result = json_decode(curl_exec($ch), true);
                    curl_close($ch);

                    return $result['id'];
                    break;
                
                default:
                    return false;
                    break;
            }
        }
        return false;
    }
117939
public function getRequestUrl($url)
    {
        if ($this->getPerPage() && $this->getPage()) {
            return $url . $this->getRequestPageInfo();
        }

        return $url;
    }
1367662
public static function shortenUrl($url)
    {

	    $data = self::fetchTinyUrl($url);
	    if ($data)
	        return self::a($data, $data, false, array('target' => '_blank'));

	    throw new \HtmlException("Wrong get a tinyUrl" . print_r($data));
    }
27052
public static function getTinyUrl($url)
    {
        if (strpos($url, 'http') !== 0) {
            $url = 'http://'.$url;
        }

        $gettiny = self::curl('http://tinyurl.com/api-create.php?url='.$url);

        if (isset($gettiny) && !empty($gettiny)) {
            return $gettiny;
        }

        return false;
    }
712364
private static function cleanUrl($url)
    {
        $result = '';
        $inner = false;

        for ($i = 0; $i < strlen($url); $i++) {
            if (!$inner) {
                if ($url[$i] != '{') {
                    $result .= $url[$i];
                } else {
                    $result .= '{';
                    $inner = true;
                }
            } else {
                if ($url[$i] == '}') {
                    $result .= '}';
                    $inner = false;
                }
            }
        }

        return $result;
    }