Generate a Short Link by Long link
@param $longLink
@return Response
494812
public function genereteShortLink($longLink)
    {
        $this->client->setMethod('POST');
        $this->client->setUri('https://www.googleapis.com/urlshortener/v1/url');
        $data = array('longUrl' => $longLink);
        $this->client->setRawBody(json_encode($data));
        $contentJson = $this->client->send()->getContent();
        $responseArray = json_decode($contentJson, true);
        if (!empty($responseArray['error'])) {
            $response = new Response();
            return $response->setError($responseArray['error']['errors']);
        } else {
            $response = new Response();
            $response->setId($responseArray['id'])
                ->setKind($responseArray['kind'])
                ->setLongUrl($responseArray['longUrl']);
            return $response;
        }
    }
252314
protected function LinkWithSearch($link) {
        // Whitelist to avoid side effects
        $params=array(
                    'q'=>(array)$this->request->getVar('q'),
                    'tag'=>$this->request->getVar('tag'),
                    'creator'=>$this->request->getVar('creator'),
                    'ParentID'=>$this->request->getVar('ParentID')
                );
        
        $link=Controller::join_links(
                                    $link,
                                    (array_filter(array_values($params)) ? '?'.http_build_query($params):null)
                                );
        
        $this->extend('updateLinkWithSearch', $link);
        return $link;
    }
315065
public function link($target, $link)
    {
        if (! windows_os()) {
            return symlink($target, $link);
        }

        $mode = $this->isDirectory($target) ? 'J' : 'H';

        exec("mklink /{$mode} \"{$link}\" \"{$target}\"");
    }
1057247
private function generateLink()
    {
        $extras = ['fieldType' => $this->fieldType];

        if ($this->files) {
            $extras['files'] = (bool) $this->files;
        }

        if ($this->filesOnly) {
            $extras['filesOnly'] = (bool) $this->filesOnly;
        }

        if ($this->path) {
            $extras['path'] = (string) $this->path;
        }

        if ($this->extensions) {
            $extras['extensions'] = (string) $this->extensions;
        }

        return System::getContainer()->get('contao.picker.builder')->getUrl('file', $extras);
    }
309312
private function resolveQsen($link)
    {
        if (!$this->isFqsen($link)) {
            $typeCollection = new TypeCollection(array($link), $this->createDocBlockContext());

            // only a single element reference is allowed!
            $link = $typeCollection[0];
        }

        return $link;
    }
1036290
public function expand($url)
    {
        $link = new Link;
        $link->setShortUrl($url);
        $this->provider->expand($link);
        return $link->getLongUrl();
    }
773929
protected function getLink($link) {
		$page = new \Phile\Repository\Page();
		$linked_page = $page->findByPath($link);

		if ($linked_page) {
			// the user linked to an internal page
			return \Phile\Utility::getBaseUrl() . '/'. $linked_page->getUrl();
		}

		$file = ROOT_DIR . DIRECTORY_SEPARATOR . $link;
		if (file_exists($file)) {
			// the user linked to an internal file
			return \Phile\Utility::getBaseUrl() . '/' . $link;
		}

		// it's not an internal page, it's not an internal file -
		// let's see if it's (at least) a somewhat valid URL
		$url_parts = parse_url($link);

		if (is_array($url_parts)) {
			if (!array_key_exists("scheme", $url_parts)) {
				// it doesn't have a http:// or https:// or similar prefix.
				// This could mean the user provided something like: (link: cnn.com)
				// -> check if the first part of the link looks like a domain name
				$p = explode('/', $url_parts["path"]);
				$domain = $p[0];

				if ($this->isValidDomainName($domain)) {
					// the first part of the link looks like a valid domain name
					// -> just prepend 'http://' and continue
					return "http://$link";
				}
			}
		}

		// If we get to this point, we just return whatever the user typed.
		return $link;
	}
499817
public static function create($short, $long = null, $mode = GetOpt::NO_ARGUMENT)
    {
        return new static($short, $long, $mode);
    }
470235
final public function getLongName()
    {
        $name = ($this->module ? $this->module->getName() . '/' : '') . $this->getName();
        return $this->action ? $name . '/' . $this->getAction() : $name;
    }
1337000
public function shorten($url)
    {
        // make the API call through the extended client
        $response = $this->fetchUrl($this->url(), $this->parameters($url));

        // read the shorted url from the response object
        $shorter_url = $this->parse($response);

        return $shorter_url;
    }
700413
protected function prepareLink(string &$link = null): void
	{
		if ($link !== null) {
			if (Strings::endsWith($link, ':default')) {
				$link = substr($link, 0, -7);
			}
			$pos = strrpos($link, ':');
			if ($pos !== strlen($link)) {
				$link = substr($link, 0, $pos + 1);
			}
		}
	}
712272
public function shorten($url)
    {
        $link = new Link;
        $link->setLongUrl($url);
        $this->provider->shorten($link);
        return $link->getShortUrl();
    }
937170
public function setLink($link)
    {
        if (strlen($link) == 0) {
            throw new \InvalidArgumentException(sprintf('TextInput link should not be empty'));
        }

        if (!preg_match('@^https?://@', $link)) {
            throw new \InvalidArgumentException(sprintf('Invalid url: %s', $link));
        }

        $this->link = $link;

        return $this;
    }
397934
public function insertId($link = null)
    {
        is_null($link) && $link = $this->wlink;
        return $link->lastInsertId();
    }
1023688
public function url($long_url, $action = 'long2short')
    {
        if (!is_string($long_url)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr = [
            "action"   => $action,
            "long_url" => $long_url,
        ];

        $this->module = 'shorturl';

        $res = $this->_post('', $queryStr);

        return $res;
    }
474489
public function Link($short = false)
    {
        if ($this->getIsDefaultEntity()) {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                '/'
            );
        } else {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                $this->getKey(),
                '/'
            );
        }

        if ($short && $this->stable) {
            return $base;
        }

        return Controller::join_links(
            $base,
            $this->getVersion(),
            '/'
        );
    }
1293620
public function assertDontSeeLink($link)
    {
        if ($this->resolver->prefix) {
            $message = "Saw unexpected link [{$link}] within [{$this->resolver->prefix}].";
        } else {
            $message = "Saw unexpected link [{$link}].";
        }

        PHPUnit::assertFalse(
            $this->seeLink($link),
            $message
        );

        return $this;
    }