Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID.

@param array      $arguments
@param string     $content
@param ShortcodeParser $parser
@return string
328779
public static function link_shortcode_handler($arguments, $content = null, $parser = null)
    {
        if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
            return null;
        }

        /** @var SiteTree $page */
        if (!($page = DataObject::get_by_id(self::class, $arguments['id']))         // Get the current page by ID.
            && !($page = Versioned::get_latest_version(self::class, $arguments['id'])) // Attempt link to old version.
        ) {
            return null; // There were no suitable matches at all.
        }

        /** @var SiteTree $page */
        $link = Convert::raw2att($page->Link());

        if ($content) {
            return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content));
        } else {
            return $link;
        }
    }
251952
protected function __linkPage($arguments)
	{
		if(isset($arguments[1]))
		{
			$this->limit($this->calcLimitStart($arguments[0], $arguments[1]),$arguments[1]);
		}
	}
11198
public function url($text, $url, $parameters = [], $secure = null)
    {
        return $this->addElement('a')->text($text)
            ->href(url($url, $parameters, $secure));
    }
638041
protected function removeAttributionLink( $content ) {
		$html5 = new HtmlParser();
		$dom = $html5->loadHTML( $content );

		$urls = $dom->getElementsByTagName( 'a' );
		foreach ( $urls as $url ) {
			/** @var \DOMElement $url */
			// Is this the the attributionUrl?
			if ( $url->getAttribute( 'rel' ) === 'cc:attributionURL' ) {
				$url->parentNode->replaceChild(
					$dom->createTextNode( $url->nodeValue ),
					$url
				);
			}
		}

		$content = $html5->saveHTML( $dom );

		return $content;
	}
1148560
protected function _query($content, $args = array())
    {
        if (!extension_loaded('curl')) {
            throw new \Exception('Missing the `curl` extension.');
        }

        $args = array_merge($this->_defaults, $args);
        if (!empty($this->_settings['level'])) {
            $args['compilation_level'] = $this->_settings['level'];
        }

        foreach ($this->_settings as $key => $val) {
            if (in_array($key, $this->_params)) {
                $args[$key] = $val;
            }
        }

        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => 'https://closure-compiler.appspot.com/compile',
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => 'js_code=' . urlencode($content) . '&' . http_build_query($args),
            CURLOPT_RETURNTRANSFER =>  1,
            CURLOPT_HEADER => 0,
            CURLOPT_FOLLOWLOCATION => 0
        ));

        $output = curl_exec($ch);

        if (false === $output) {
            throw new \Exception('Curl error: ' . curl_error($ch));
        }

        curl_close($ch);
        return $output;
    }
790170
private function getFullContent(string $content, array $params = [])
    {
        return str_replace(array_map(function ($key) {
            return '${' . $key . '}';
        }, array_keys($params)), array_values($params), $content);
    }
321500
public function tagUrl($tag, $content)
    {
        $url    = isset($tag['link']) ? $tag['link'] : '';
        $vars   = isset($tag['vars']) ? $tag['vars'] : '';
        $suffix = isset($tag['suffix']) ? $tag['suffix'] : 'true';
        $domain = isset($tag['domain']) ? $tag['domain'] : 'false';

        return '<?php echo url("' . $url . '","' . $vars . '",' . $suffix . ',' . $domain . ');?>';
    }
346229
private ResourceReference parseInterWikiLinks(StringBuilder content)
    {
        ResourceReference result = null;
        String interWikiAlias = parseElementAfterString(content, SEPARATOR_INTERWIKI);
        if (interWikiAlias != null) {
            InterWikiResourceReference link = new InterWikiResourceReference(removeEscapes(content.toString()));
            link.setInterWikiAlias(removeEscapes(interWikiAlias));
            result = link;
        }
        return result;
    }
128829
public function beforeParse($content) {
        $parser = $this->getParser();

        // To make sure we won't parse links inside [url] or [img] tags, we'll first replace all urls/imgs with uniqids
        // and keep them in this array, and restore them at the end, after parsing
        $ignoredStrings = array();

        // The tags we won't touch
        // For example, neither [url="http://www.example.com"] nor [img]http://www.example.com[/img] will be replaced.
        $ignoredTags = array('url', 'link', 'img', 'image');

        $i = 0;
        foreach ($ignoredTags as $tag) {
            if (preg_match_all(sprintf('/\[%s[\s=\]].*?\[\/%s\]/is', $tag, $tag), $content, $matches, PREG_SET_ORDER)) {
                $matches = array_unique(array_map(function($x) { return $x[0]; }, $matches));

                foreach ($matches as $val) {
                    $uniqid = uniqid($i++);

                    $ignoredStrings[$uniqid] = $val;
                    $content = str_replace($val, $uniqid, $content);
                }
            }
        }

        if ($parser->hasFilter('Url')) {
            $protocols = $parser->getFilter('Url')->getConfig('protocols');
            $chars = preg_quote('-_=+|\;:&?/[]%,.~!@#$*(){}"\'', '/');

            $pattern = implode('', array(
                '((' . implode('|', $protocols) . ')s?:\/\/([\w\.\+]+:[\w\.\+]+@)?|www\.)', // protocol & login or www. (without http(s))
                '([\w\-\.]{5,255}+)', // domain, tld
                '(:[0-9]{0,6}+)?', // port
                '(\/[a-z0-9' . $chars . ']+)?', // path
                '(\/?\?[a-z0-9' . $chars . ']+)?', // query
                '(#[a-z0-9' . $chars . ']+)?' // fragment
            ));

            $content = preg_replace_callback('/(' . $pattern . ')/i', array($this, '_urlCallback'), $content);
        }

        // Based on W3C HTML5 spec: https://www.w3.org/TR/html5/forms.html#valid-e-mail-address
        if ($parser->hasFilter('Email')) {
            $pattern = '(:\/\/[\w\.\+]+:)?([a-z0-9.!#$%&\'*+\/=?^_`{|}~\-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*)';

            $content = preg_replace_callback('/' . $pattern . '/i', array($this, '_emailCallback'), $content);
        }

        // We restore the tags we ommited
        foreach ($ignoredStrings as $key => $val) {
            $content = str_replace($key, $val, $content);
        }

        return $content;
    }
193678
protected function _get_favicon( $content ) {
		preg_match( '/<link +?rel=["\']shortcut icon["\'][^\/>]*? href=["\']([^"\']+?)["\'][^\/>]*?\/?>/si', $content, $reg );
		if ( empty( $reg[1] ) ) {
			preg_match( '/<link +?rel=["\']icon["\'][^\/>]*? href=["\']([^"\']+?)["\'][^\/>]*?\/?>/si', $content, $reg );
		}

		if ( empty( $reg[1] ) ) {
			return;
		}

		$favicon = $reg[1];
		$favicon = $this->_relative_path_to_url( $favicon, $content );

		if ( is_ssl() ) {
			$favicon = preg_replace( '|^http:|', 'https:', $favicon );
		}

		$requester = new Requester( $favicon );
		$response  = $requester->request( $favicon );
		if ( is_wp_error( $response ) ) {
			return;
		}

		$status_code = $requester->get_status_code();
		if ( 200 != $status_code && 304 != $status_code ) {
			return;
		}

		return $favicon;
	}
808440
public function injectTemplateContent($content, $params)
    {
        return str_replace(
            array(
                '%__ERROR_TYPE__%',
                '%__ERROR_REFERENCE__%',
                '%__ERROR_MESSAGE__%',
                '%__ERROR_FILE__%',
                '%__ERROR_LINE__%'
            ),
            array_map('addslashes',array(
                $params['type'],
                $params['reference'],
                $params['message'],
                $params['file'],
                $params['line']
            )),
            $content
        );
    }
1255107
protected static function videoEmbed($arguments, $content)
    {
        // Ensure outer div has given width (but leave height auto)
        if (!empty($arguments['width'])) {
            $arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;';
        }

        // Convert caption to <p>
        if (!empty($arguments['caption'])) {
            $xmlCaption = Convert::raw2xml($arguments['caption']);
            $content .= "\n<p class=\"caption\">{$xmlCaption}</p>";
        }
        unset($arguments['width']);
        unset($arguments['height']);
        unset($arguments['url']);
        unset($arguments['caption']);
        return HTML::createTag('div', $arguments, $content);
    }
650669
static function ContentTreeUrl(Content $content)
    {
        $args = array();
        $pageContent = $content->GetPageContent();
        if ($pageContent)
        {
            $args['page'] = $pageContent->GetPage()->GetID();
            $args['area'] = $pageContent->GetArea()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\PageContentTree, $args);
        }
        $layoutContent = $content->GetLayoutContent();
        if ($layoutContent)
        {
            $args['area'] = $layoutContent->GetArea()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\LayoutContentTree, $args);
        }
        $containerContent = $content->GetContainerContent();
        if($containerContent)
        {
            $args['container'] = $containerContent->GetContainer()->GetID();
            return self::ModuleUrl(new \Phine\Bundles\Core\Modules\Backend\ContainerContentTree, $args);
        }
    }
756682
public static function doParse($src, $src_links, $options)
    {
        $parser = new Parser($options);
        return $parser->parse($src, $src_links);
    }
1226201
public function findAllShortcodeIds( $content ) {
		$ids = [];
		$matches = [];
		$regex = get_shortcode_regex( [ self::SHORTCODE ] );
		if ( preg_match_all( '/' . $regex . '/s', $content, $matches, PREG_SET_ORDER ) ) {
			foreach ( $matches as $shortcode ) {
				$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
				if ( is_array( $shortcode_attrs ) && isset( $shortcode_attrs['id'] ) ) {
					// Remove quotes, return just the integer
					$my_id = $shortcode_attrs['id'];
					$my_id = trim( $my_id, "'" );
					$my_id = trim( $my_id, '"' );
					$my_id = str_replace( '&quot;', '', $my_id );
					$ids[] = (int) $my_id;
				}
			}
		}
		return $ids;
	}
125141
public static function link(
        string $content = null, 
        array $attributes = []
    ) : string
    {
        return self::tag("link", $content, $attributes);
    }
884737
public function link($content, $url = '', $attributes = array())
    {
        $attributes['href'] = $url;

        return $this->tag('a', $content, $attributes);
    }