Generate a hyperlink with parameters and anchor and a subsection such as a subpage
Inspired by (c) Panther <http://www.pantherforum.org/>

@param $link
@param $sublink
@param $subarg
@param null $args
@return mixed|string
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;
    }
62719
public static function getLinkData( $link )
    {
        $root = str_replace('\\', '/', TL_ROOT) . '/';
        $sym = substr( str_replace('\\', '/', $link), strlen($root) );
        $target = str_replace('\\', '/', readlink( $link ) );
        
        if( substr($target, 0, strlen($root)) === $root ) {         // absolute path
            $target = substr($target, strlen($root));
            $depth = count(explode('/', $sym)) - 1;
        }
        else {                                                      // relative path
            $depth = 0;
            while( substr($target, 0, 3) === '../' ) {
                $target = substr($target, 3);
                $depth++;
            }
        }

        return array( 'link'=>$sym, 'target'=>trim($target, '/'), 'depth'=>$depth );        
    }
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;
    }
470483
public function url( array $args = [] ) {
		$url = get_permalink( $this->ID );
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;

	}
1316213
function regenerateLink(base, link) {
  const parsedBase = (0, _url.parse)(base);
  const parsedLink = link.split("/");
  let parts = [];
  let port = "";

  if (!link.startsWith("/")) {
    parts = parsedBase.pathname.split("/");
    parts.pop();
  }

  for (const part of parsedLink) {
    // Current directory:
    if (part === ".") {
      continue;
    } // Parent directory:


    if (part === "..") {
      // Accessing non-existing parent directories:
      if (!parts.pop() || parts.length === 0) {
        return null;
      }
    } else {
      parts.push(part);
    }
  }

  if (parsedBase.port) {
    port = ":" + parsedBase.port;
  } // eslint-disable-next-line max-len


  return `${parsedBase.protocol}//${parsedBase.hostname}${port}${parts.join("/")}`;
}
1211752
protected function generateStandardUrl(array $urlParameters = array(), $absolute = false)
    {
        $urlParameters = $this->addRequestVariablesToUrlParameters($urlParameters);

        $anchor = '';
        if ($this->hasAnchor())
        {
            $anchor = '#'.$this->getAnchor();
        }

        return $this->getRouter()->generate($this->getRouteName(), $urlParameters, $absolute) . $anchor;
    }
1149874
public static function getValues($name, array $args, $default = null, $link = ',') {
		$names = explode($link, $name);
        if (strpos($name, $link) === false ) {
            list($newKey, $arg, $oldKey) = self::_getValueByKeyWithDefault($name, $args, $default);
            if ($newKey == $oldKey) {
                return $arg;
            }
            return array(
                $newKey => $arg
            );
        }
		$returnValue = array();
		foreach ($names as $value) {
			list($newKey, $arg) = self::_getValueByKeyWithDefault($value, $args, $default);
            $returnValue[$newKey] = $arg;
		}
		return $returnValue;
	}
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;
    }
374585
def parse_links(args_link):
    
    links = []
    if (args_link is not None):
        for link_str in args_link:
            try:
                links.append(parse_link(link_str))
            except ClientFatalError as e:
                raise ClientFatalError(
                    "Bad --link option '%s' (%s)" %
                    (link_str, str(e)))
    return(links)
62888
function symlinkAsUser($target, $link)
    {
        if ($this->exists($link)) {
            $this->unlink($link);
        }

        CommandLineFacade::runAsUser('ln -s '.escapeshellarg($target).' '.escapeshellarg($link));
    }
1081766
public static function delegate($flag, $submodule, $arguments) {
		$options = Application::get($flag . '.' . $submodule . '.options');
		if (!empty($options)) {
			// todo: maybe add to first array instead to first element in arguments
			$arguments[0] = array_merge_hard($options, $arguments[0]);
		}
		// we need to determine whether we need to use additional submodule
		if (Application::get($flag . '.' . $submodule . '.submodule') && empty($arguments[0]['flag_call_previous_parent'])) {
			return call_user_func_array([self::submodule($flag . '.' . $submodule . '.submodule'), $submodule], $arguments);
		} else {
			return call_user_func_array([self::submodule($flag . '.submodule'), $submodule], $arguments);
		}
	}
1214958
public function setAboutLink($link)
    {
        if (false === filter_var($link, FILTER_VALIDATE_URL)) {
            throw new \InvalidArgumentException(sprintf('Provided link %s is not a valid resource', $link));
        }

        $this->links['about']['href'] = (string) $link;
    }
542540
function build($url,$args=[]) {
		$args+=$this->hive['PARAMS'];
		if (is_array($url))
			foreach ($url as &$var) {
				$var=$this->build($var,$args);
				unset($var);
			}
		else {
			$i=0;
			$url=preg_replace_callback('/@(\w+)|(\*)/',
				function($match) use(&$i,$args) {
					if (isset($match[1]) &&
						array_key_exists($match[1],$args))
						return $args[$match[1]];
					if (isset($match[2]) &&
						array_key_exists($match[2],$args)) {
						if (!is_array($args[$match[2]]))
							return $args[$match[2]];
						$i++;
						return $args[$match[2]][$i-1];
					}
					return $match[0];
				},$url);
		}
		return $url;
	}
1200672
protected function parseSupraLinkStart(LinkReferencedElement $link)
	{
		$tag = new HtmlTagStart('a');

		$title = ReferencedElementUtils::getLinkReferencedElementTitle(
				$link,
				$this->container->getDoctrine()->getManager(),
				$this->container->getLocaleManager()->getCurrentLocale()
		);

		// @TODO: what if we failed to obtain the URL?
		$url = ReferencedElementUtils::getLinkReferencedElementUrl(
				$link,
				$this->container->getDoctrine()->getManager(),
				$this->container->getLocaleManager()->getCurrentLocale()
		);

		$tag->setAttribute('title', $title)
				->setAttribute('href', $url)
				->setAttribute('class', $link->getClassName())
		;

		$target = $link->getTarget();
		if (! empty($target)) {
			$tag->setAttribute('target', $target);
		}

		switch ($link->getResource()) {
			case LinkReferencedElement::RESOURCE_FILE:
				$tag->setAttribute('target', '_blank');
				break;
		}

		return $tag;
	}
109135
def _subArgsInRoute(self, entry, args):
        

        route = entry['route']

        for arg, val in six.iteritems(args):
            toReplace = "<%s>" % arg
            if toReplace not in route:
                raise exceptions.TaskclusterFailure(
                    'Arg %s not found in route for %s' % (arg, entry['name']))
            val = urllib.parse.quote(str(val).encode("utf-8"), '')
            route = route.replace("<%s>" % arg, val)

        return route.lstrip('/')
347304
public static function getUrlFromCode($code, $addedArgs = array(), $anchor = null)
  {
    self::initialize();

    $code = self::clearQueryArg($code);

    if ($code == '_root') {
      return WebApp::url();
    }

    if (StringTools::right($code, 1) != '/') {
      $code .= '/';
    }

    $args = array('q' => $code);
    $args = array_merge($args, $addedArgs);
    return Url::getUrl(null, $args, true, $anchor);
  }
251952
protected function __linkPage($arguments)
	{
		if(isset($arguments[1]))
		{
			$this->limit($this->calcLimitStart($arguments[0], $arguments[1]),$arguments[1]);
		}
	}