Return the target of a symbolic link

@param string $link
@return mixed
@access public
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);
    }
1010178
public function findURL($url)
    {
        $nb_site_target = $this->getItem($url, self::INDEX_URL_STATIC);
        if ($nb_site_target === null) {
            //$nb_site_target = $this->findByRegExpr(self::INDEX_URL_REGEXP, $url);
        }

        return $nb_site_target;
    }
763611
public function symlink($target, $link)
    {
        if (!file_exists($target)) {
            throw new \InvalidArgumentException('Target not found: ' . $target);
        }
        if ($this->relative) {
            $target = $this->makePathRelative($target, dirname($link));
        }
        $this->fs->symlink($target, $link, $this->copyOnWindows);
    }
205657
public static function read(string $link = ''): string
    {
        $link = static::normalizePath($link);
        if (static::exists($link)) {
            return @\readlink($link);
        }
        return '';
    }
980865
public function processSymlink(Symlink $symlink): bool
    {
        if ($symlink->isForceCreate() && $this->isToUnlink($symlink->getLink())) {
            try {
                if (\is_dir($symlink->getLink())) {
                    $result = $this->filesystem->removeDirectory($symlink->getLink());
                } else {
                    $result = $this->filesystem->remove($symlink->getLink());
                }
                if (!$result) {
                    throw new RuntimeException('Unknown error');
                }
            } catch (\Exception $exception) {
                throw new RuntimeException(sprintf(
                    'Cant unlink %s: %s',
                    $symlink->getLink(),
                    $exception->getMessage()
                ));
            }
        }

        if ($this->isToUnlink($symlink->getLink())) {
            throw new LinkDirectoryError('Link ' . $symlink->getLink() . ' already exists');
        }

        if ($symlink->isAbsolutePath()) {
            return @symlink($symlink->getTarget(), $symlink->getLink());
        }
        return $this->filesystem->relativeSymlink($symlink->getTarget(), $symlink->getLink());
    }
1332497
protected function parseLinkHeader( $link ) {
		$parts = explode( ';', $link );
		$attrs = [
			'href' => trim( array_shift( $parts ), '<>' ),
		];
		foreach ( $parts as $part ) {
			if ( ! strpos( $part, '=' ) ) {
				continue;
			}
			list( $key, $value ) = explode( '=', $part, 2 );
			$key = trim( $key );
			$value = trim( $value, '" ' );
			$attrs[ $key ] = $value;
		}
		return $attrs;
	}
406897
public function assertSeeLink($link)
    {
        if ($this->resolver->prefix) {
            $message = "Did not see expected link [{$link}] within [{$this->resolver->prefix}].";
        } else {
            $message = "Did not see expected link [{$link}].";
        }

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

        return $this;
    }
142154
function link($target, $link)
    {
        $this->files->ensureDirExists(
            $linkPath = $this->sitesPath(), user()
        );

        $this->config->prependPath($linkPath);

        $this->files->symlinkAsUser($target, $linkPath.'/'.$link);

        return $linkPath.'/'.$link;
    }
1232104
public static function label($link) {
        if(isset($link['label']) && !empty(trim($link['label']))) {
            return trim($link['label']);
        }
        elseif(isset($link['title']) && !empty(trim($link['title']))) {
            return trim($link['title']);
        }
        return false;
    }
414094
public static function user_trailingslashit( $link ) {
		$link_parts = parse_url($link);

		if ( !$link_parts ) {
			return $link;
		}

		if ( isset($link_parts['path']) && $link_parts['path'] != '/' ) {
			$new_path = user_trailingslashit($link_parts['path']);

			if ( $new_path != $link_parts['path'] ) {
				$link = str_replace($link_parts['path'], $new_path, $link);
			}
		}
		return $link;
	}
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;
	}
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;
    }
184460
public static function parseParameters($link)
    {
        $pos = strpos($link, '?');
        if ($pos !== null) {
            $link = substr($link, $pos + 1);
        }

        $params = [];
        parse_str($link, $params);

        return $params;
    }
1341129
public function setLink($link)
    {
        if (!is_null($link) && substr($link, 0, 17) === 'http://www.tvrage') {
            $link = str_replace('www.tvrage', 'tvrage', $link);
        }
        $this->link = $link;
        return $this;
    }
1057249
public function asLink($href=NULL,$target=NULL) {
		if (isset($href)) {
			$_target="";
			if(isset($target))
				$_target="target='{$target}'";
			$this->wrap("<a href='" . $href . "' {$_target}>", "</a>");
		}
		return $this->addToProperty("class", "link");
	}
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);
        }
    }
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;
    }