@param $link

@return string
966804
protected function composeListLink($link)
    {
        $query = [];

        $query['PAGEN_1'] = $this->listPage;

        if (!empty($this->listQuery)) {
            $query['term'] = $this->listQuery;
        }

        $query = array_merge($query, $this->listParams);

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

        return $link;
    }
545643
private function processLink($text, $link) {
        $link = rtrim($link, '.');
        $pipe = explode('|', $text);

        if (mb_strlen($pipe[0]) !== mb_strlen($text)) {
            $pipe = explode('[', $pipe[0]);
            $linkText = $pipe[1];
            $search = '[' . $linkText . '|' . $link . ']';
            $replace = sprintf('<a href="%s">%s</a>', $link, $linkText);
        } else {
            $search = $link;
            $replace = sprintf('<a href="%s">%s</a>', $link, $link);
        }

        $this->writeRaw(str_replace($search, $replace, $text));

        return '';
    }
590078
public function download($link)
    {
        $url = str_replace('\/', '/', $link);
        $fileName = \tao_helpers_File::createTempDir() . basename($link);

        common_Logger::d('Downloading ' . $url);
        helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::NO_TIMEOUT);
        $fp = fopen($fileName, 'w+');
        $curlHandler = curl_init();
        curl_setopt($curlHandler, CURLOPT_URL, $url);
        curl_setopt($curlHandler, CURLOPT_FILE, $fp);
        curl_setopt($curlHandler, CURLOPT_TIMEOUT, 50);
        curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);

        //if there is an http auth on the local domain, it's mandatory to auth with curl
        if (USE_HTTP_AUTH) {

            $addAuth = false;
            $domains = array('localhost', '127.0.0.1', ROOT_URL);

            foreach ($domains as $domain) {
                if (preg_match("/" . preg_quote($domain, '/') . "/", $url)) {
                    $addAuth = true;
                }
            }

            if ($addAuth) {
                curl_setopt($curlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($curlHandler, CURLOPT_USERPWD, USE_HTTP_USER . ":" . USE_HTTP_PASS);
            }
        }

        curl_exec($curlHandler);
        $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
        $success = $httpCode == 200;
        curl_close($curlHandler);
        fclose($fp);
        helpers_TimeOutHelper::reset();

        return $fileName;
    }
379440
protected function processLinkHtml($link)
    {
        $_html  = !empty($link[0]) ? $link[0] : '';
        $_href  = !empty($link[1]) ? $link[1] : '';
        $_url   = !empty($link[2]) ? $link[2] : '';
        $_title = isset($link[3]) && strip_tags($link[3]) ? strip_tags($link[3]) : $_url;

        // --------------------------------------------------------------------------

        /**
         * Only process if there's at least the HTML tag and a detected URL
         * otherwise it's not worth it/possible to accurately replace the tag
         */

        if ($_html && $_url) {
            $_html = $this->processLinkGenerate($_html, $_url, $_title, true);
        }

        return $_html;
    }
1220022
public static function remove(string $link = ''): bool
    {
        $link = static::normalizePath($link);
        if (static::exists($link)) {
            return @\unlink($link);
        }
        return false;
    }
106572
public static function wiki_parser_link_callback($link, $options) {
        $l = urlencode($link);
        if(!empty($options['anchor'])) {
            $l .= "#".urlencode($options['anchor']);
        }
        return array('content' => $link, 'url' => "http://".$l);
    }
422011
protected function link($link, $anchor = "") {
        $link = trim($link);
        if (preg_match("/^(https?|s?ftp):\/\/.+$/i", $link)) {
            $link = trim($link, ",.?!");
            return array('content' => $link, 'url' => $link);
        } else {
            $callbackargs = $this->linkgeneratorcallbackargs;
            $callbackargs['anchor'] = $anchor;
            $link = call_user_func_array($this->linkgeneratorcallback, array($link, $callbackargs));

            if (isset($link['link_info'])) {
                $l = $link['link_info']['link'];
                unset($link['link_info']['link']);
                $this->returnvalues['link_count'][$l] = $link['link_info'];
            }
            return $link;
        }
    }
608113
protected function routeExists($link)
    {
        if ($this->option('api')) {
            return $this->apiRouteExists($link);
        }
        return $this->webRouteExists($link);
    }
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;
    }
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;
    }
867932
private String parseLink(final String link) {
		String[] tokens = link.substring(7, link.length() - 1).split("\\s");
		if (tokens.length == 1) {
			return tokens[0];
		}
		StringBuilder result = new StringBuilder();

		boolean parametersSeen = false;
		boolean inParameters = false;

		for (int index = 0; index < tokens.length; index++) {
			result.append(" ").append(tokens[index]);
			if (tokens[index].indexOf('(') != -1 && !parametersSeen) {
				inParameters = true;
			}
			if (index == 1 && !inParameters) {
				result = new StringBuilder(tokens[index]);
			}
			if (tokens[index].indexOf(')') != -1 && !parametersSeen) {
				parametersSeen = true;
				if (index != tokens.length - 1) {
					result = new StringBuilder();
				}

			}

		}

		return result.toString().trim();
	}
893107
protected function getPageNumber($link)
    {
        if ($link) {
            $url = str_replace(
                'rel="next"', '', preg_replace('/[<>;\ ]/', '', $link)
            );
            parse_str(parse_url($url, PHP_URL_QUERY), $output);

            return (int) $output['page'];
        }

        return null;
    }
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;
    }
514352
private static function getSublink($link, $sublink, $subarg, $args = null)
    {
        $base_url = self::base();

        if ($sublink == 'p$1' && $subarg == 1) {
            return self::get($link, $args);
        }

        $gen_link = $link;
        if (!is_array($args) && $args != null) {
            $gen_link = 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.'/'.str_replace(
        $gen_link = $base_url.str_replace(
            '#',
            str_replace('$1', str_replace('$1', $subarg, $sublink), '$1/'),
            $gen_link
        );

        return $gen_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;
    }
628145
public function version($link = null)
    {
        $cursor = $this->getMaster()->executeCommand(
            $this->getDbName(),
            new Command(['buildInfo' => 1])
        );

        $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
        $info = current($cursor->toArray());
        return $info['version'];
    }
1116779
public static function title($link) {
        if(isset($link['title']) || isset($link['label'])){
            return ' title="'.trim(isset($link['title']) && !empty(trim($link['title'])) ? $link['title'] : $link['label']).'"';
        }
        return false;
    }