Turns internal links into proper absolute links, and/or adds 'http'
to external links that were specified without one.

@param $link
@return string
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;
	}
99787
public function setLink($link)
    {
        // (parse_url function returns false on malformed URLs)
        $result = parse_url($link);

        // Remove scheme from url (doesn't change relative URLs)
        $this->link = '//'.
                      (isset($result['user']) ? $result['user'] : '').
                      (isset($result['pass']) ? ':'.$result['pass'].'@' : '').
                      $result['host'].
                      (isset($result['port']) ? ':'.$result['port'] : '').
                      (isset($result['path']) ? $result['path'] : '').
                      (isset($result['query']) ? '?'.$result['query'] : '').
                      (isset($result['fragment']) ? '#'.$result['fragment']
                          : '');

        // Set post type and thumbnail according to url
        if (isset($result['host'])) {
            switch ($result['host']) {
                case 'www.car360app.com':
                case 'www.argus360.fr':
                    $this->type  = 'argus360';
                    $this->image = '//car360app.com/viewer/?spin='
                                   .$this->getHash($link)
                                   .'&res=640x360&angle=45';
                    break;
                case 'dai.ly':
                case 'www.dailymotion.com':
                    $this->type  = 'dailymotion';
                    $this->image = '//www.dailymotion.com/thumbnail/video/'
                                   .$this->getHash($link);
                    break;
                case 'giphy.com':
                    $this->type = 'giphy';
                    break;
                case 'gist.github.com':
                    $this->type = 'gist';
                    break;
                case 'twitter.com':
                    $this->type = 'tweet';
                    break;
                case 'www.youtube.com':
                case 'youtu.be':
                    $this->type  = 'youtube';
                    $this->image = '//i.ytimg.com/vi/'.$this->getHash($link)
                                   .'/maxresdefault.jpg';
//                                   .'/mqdefault.jpg';
//                                   .'/hqdefault.jpg';
                    break;
                case 'vimeo.com':
                    $this->type  = 'vimeo';
                    $xml         = unserialize(
                        file_get_contents(
                            'http://vimeo.com/api/v2/video/'.$this->getHash(
                                $link
                            ).'.php'
                        )
                    );
                    $this->image = $xml[0]['thumbnail_medium'];
                    break;
            }
        }

        return $this;
    }
1315108
public function getLink($link)
    {
        return isset($this->link[$link]) ? $this->link[$link] : null;
    }
309175
public static function link($target, $link)
  {
    if (! windows_os()) {
      return symlink($target, $link);
    }

    $mode = is_dir($target) ? 'J' : 'H';

    exec("mklink /{$mode} \"{$link}\" \"{$target}\"");
  }
298226
public function checkLink($url)
    {
        $url = trim($url);
        if (substr($url, 0, 7 ) == "http://") return $url;

        if (substr($url, 0, 8 ) == "https://") return $url;

        return "http://".$url;
    }
1132170
public static function get($link, $args = null)
    {
        $base_url = self::base();

        $gen_link = $link;
        if ($args == null) {
            $gen_link = $base_url.$link;
        } elseif (!is_array($args)) {
            $gen_link = $base_url.'/'.str_replace('$1', $args, $link);
        } else {
            for ($i = 0; isset($args[$i]); ++$i) {
                $gen_link = str_replace('$'.($i + 1), $args[$i], $gen_link);
            }
            $gen_link = $base_url.$gen_link;
        }

        return $gen_link;
    }
36980
private String getExternalLinkFile(String link) {

        String filename = link.substring(link.indexOf("://") + 3, link.length());
        filename = m_cmsObject.getRequestContext().getFileTranslator().translateResource(filename.replace('/', '-'));
        return filename;
    }
26551
protected function prepare($link)
    {
        $response = Client::request((string) $link);

        $response = str_replace('<strong> </strong>', ' ', $response);

        $this->crawler = new Crawler($response);
    }
338992
protected function composeListLink($link)
    {
        $query = $this->addIdToQuery();
        $query = $this->addPaginationToQuery($query);

        $link .= '?' . http_build_query($query);

        return $link;
    }
1068232
public function setLink($link)
    {
        if ($this->version == Feed::ATOM)
            $this->setAtomLink($link);
        else
            $this->setChannelElement('link', $link);

        return $this;
    }
43082
private function _parseMemcacheAddress($link)
    {
        $protoSeparator = strpos($link, '://');
        if ($protoSeparator !== false) {
            $link = substr($link, $protoSeparator + 3);
        }
        $server = $link;
        $serverOptions = [];
        $hookSeparator = strpos($link, '?');
        if ($hookSeparator !== false) {
            $server = substr($link, 0, $hookSeparator);
            parse_str(substr($link, $hookSeparator + 1), $serverOptions);
        }
        $server = explode(':', $server);
        $serverOptions['host'] = $server[0];
        $serverOptions['port'] = $server[1];
        return $serverOptions;
    }
150875
public static function getHref($link) {
        self::setURI($link['uri']);
        self::setAnchorPoint($link['fragment']);
        return self::getURI().self::getAnchorPoint();
    }
212643
public static function isRemoteLink($link)
    {
        $base = Grav::instance()['uri']->rootUrl(true);

        // Sanity check for local URLs with absolute URL's enabled
        if (Utils::startsWith($link, $base)) {
            return false;
        }

        return (0 === strpos($link, 'http://') || 0 === strpos($link, 'https://') || 0 === strpos($link, '//'));
    }
639174
protected function _parseLinks($links)
    {
        $links = array_map(function ($value) {
            $matches = [];
            preg_match('/\<(?P<link>.*)\>\; rel\=\"(?P<rel>.*)\"/', $value, $matches);

            return $matches;
        }, explode(', ', $links));

        return Hash::combine($links, '{n}.rel', '{n}.link');
    }
658396
public function hasLink($link) {
        $found = false;
        array_walk_recursive($this->navigation, function($value, $key) use (&$found, $link) {
            if ($value == $link && $key === 'uri') {
                $found = true;
            }
        });
        return $found;
    }
555309
function readlink($link)
    {
        if (!($this->bitmap & SSH2::MASK_LOGIN)) {
            return false;
        }

        $link = $this->_realpath($link);

        if (!$this->_send_sftp_packet(NET_SFTP_READLINK, pack('Na*', strlen($link), $link))) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_NAME:
                break;
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
            default:
                user_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS');
                return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Ncount', $this->_string_shift($response, 4)));
        // the file isn't a symlink
        if (!$count) {
            return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Nlength', $this->_string_shift($response, 4)));
        return $this->_string_shift($response, $length);
    }
1305344
protected function turnIntoNewWindowLink($link)
    {
        if ($link) {
            $link->setAttribute('target', 'pz2-linkTarget');
            $oldClass = $link->getAttribute('class');
            $newClass = trim($oldClass . ' pz2-newWindowLink');
            $link->setAttribute('class', $newClass);

            $newTitle = LocalizationUtility::translate('Erscheint in separatem Fenster.', 'Pazpar2');
            if ($link->hasAttribute('title')) {
                $oldTitle = $link->getAttribute('title');
                $newTitle = $oldTitle . ' (' . $newTitle . ')';
            }
            $link->setAttribute('title', $newTitle);
        }
    }