Add links to text.

@param string $text    Text to linkify.
@param bool   $urls    Linkify URLs?
@param bool   $emails  Linkify email addresses?
@param array  $options Options.

@return string Linkified text.
484084
protected function linkify($text, $urls = true, $emails = true, array $options = array())
    {
        if (false === $urls && false === $emails) {
            // nothing to do...
            return $text;
        }

        $options = array_merge_recursive($this->options, $options);

        $attr = '';

        if (true === array_key_exists('attr', $options)) {
            foreach ($options['attr'] as $key => $value) {
                if (true === is_array($value)) {
                    $value = array_pop($value);
                }
                $attr .= sprintf(' %s="%s"', $key, $value);
            }
        }

        $options['attr'] = $attr;

        $ignoreTags = array('head', 'link', 'a', 'script', 'style', 'code', 'pre', 'select', 'textarea', 'button');

        $chunks = preg_split('/(<.+?>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE);

        $openTag = null;

        for ($i = 0; $i < count($chunks); $i++) {
            if ($i % 2 === 0) { // even numbers are text
                // Only process this chunk if there are no unclosed $ignoreTags
                if (null === $openTag) {
                    if (true === $urls) {
                        $chunks[$i] = $this->linkifyUrls($chunks[$i], $options);
                    }
                    if (true === $emails) {
                        $chunks[$i] = $this->linkifyEmails($chunks[$i], $options);
                    }
                }
            } else { // odd numbers are tags
                // Only process this tag if there are no unclosed $ignoreTags
                if (null === $openTag) {
                    // Check whether this tag is contained in $ignoreTags and is not self-closing
                    if (preg_match("`<(" . implode('|', $ignoreTags) . ").*(?<!/)>$`is", $chunks[$i], $matches)) {
                        $openTag = $matches[1];
                    }
                } else {
                    // Otherwise, check whether this is the closing tag for $openTag.
                    if (preg_match('`</\s*' . $openTag . '>`i', $chunks[$i], $matches)) {
                        $openTag = null;
                    }
                }
            }
        }

        $text = implode($chunks);

        return $text;
    }
364516
public static function a($text = '', $route = '', Array $params = [], $options = [])
    {
        $optionsHtml = '';
        array_walk($options, function ($value, $key) use (&$optionsHtml) {
            $optionsHtml .= $key . '="' . $value . '" ';
        });
        return '<a href="' . self::url($route, $params) . '" ' . $optionsHtml . ' >' . $text . '</a>';
    }
1228064
public static function _text($text, $values = array()) {
		_t($text, static::getDomain(), is_array($values) ? $values : array_slice(func_get_args(), 1));
	}
1272195
protected function _linkUrls($text, $htmlOptions)
    {
        $replace = [];
        foreach ($this->_placeholders as $hash => $content) {
            $link = $url = $content['content'];
            $envelope = $content['envelope'];
            if (!preg_match('#^[a-z]+\://#i', $url)) {
                $url = 'http://' . $url;
            }
            $replace[$hash] = $envelope[0] . $this->Html->link($link, $url, $htmlOptions) . $envelope[1];
        }

        return strtr($text, $replace);
    }
339119
public function lexerCustom($text, $options=array()){

        $data = array();
        
        $data['text'] = $text;

        $data = array_merge($data, $options);
        $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');

        return $this->request($this->lexerCustomUrl, $data);
    }
698842
public function url($email, array $options = []) {
		$options = $this->_cleanOptions($options + $this->_config);
		$ext = $options['ext'];
		$secure = $options['secure'];
		unset($options['ext'], $options['secure']);
		$protocol = $secure === true ? 'https' : 'http';

		$imageUrl = $this->_url[$protocol] . md5($email);
		if ($ext === true) {
			// If 'ext' option is supplied and true, append an extension to the generated image URL.
			// This helps systems that don't display images unless they have a specific image extension on the URL.
			$imageUrl .= '.jpg';
		}
		$imageUrl .= $this->_buildOptions($options);
		return $imageUrl;
	}
263843
protected function _parseUrls($text, array $paths)
    {
        $matches = array();
        $replaces = array();

        $finder = $this->getService('anahita:file.pathfinder')
                ->addSearchDirs(array_reverse($paths));
        $starting_path = $paths[0];

        if (preg_match_all('/url\((.*?)\)/', $text, $matches)) {
            foreach ($matches[1] as $match) {
                $match = str_replace(array('"', "'"), '', $match);

                if ($path = $finder->getPath($match)) {
                    $path = AnHelperFile::getTravelPath($starting_path, $path);
                    $path = str_replace(DS, '/', $path);
                    $replaces[$match] = $path;
                }
            }
        }

        $text = str_replace(array_keys($replaces), array_values($replaces), $text);

        return $text;
    }
1037191
public function transform( $text, $options = null )
    {
        if ( null !== $options )
        {
            $this->setOptions( $options );
        }

        $parser = $this->extraEnabled
                ? new MarkdownExtraParser
                : new MarkdownParser;
        $parsed = $parser->transformMarkdown( $text );

        if ( ! empty( $this->linkTarget ) )
        {
            $parsed = preg_replace(
                '#<(a|form)((\s[^>]*)?)>(.*?)</\\1>#',
                '<$1 target="' . htmlspecialchars( $this->linkTarget ) . '"$2>$4</$1>',
                $parsed
            );
        }

        if ( $this->stripScripts )
        {
            $parsed = preg_replace(
                '#<script(\s[^>]*)?>.*?</script>#',
                '',
                $parsed
            );
        }

        return $parsed;
    }
1001733
public function seeLink($text, $url = null, $negate = false)
    {
        return $this->assertInPage(new HasLink($text, $url), $negate);
    }
349000
public function linkTag($text, &$data, &$root)
    {
        parent::linkPlainTag($text, $data, $root);
        $this->_name = '@link';
    }
1338929
public static function urlize($text)
    {
        $text = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $text);
        $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $text);
        $text = preg_replace("/@(\w+)/", "<a href=\"http://twitter.com/\\1\">@\\1</a>", $text);
        $text = preg_replace("/([^&]|^)#(\w+)/", "\\1<a href=\"http://twitter.com/search/\\2\">#\\2</a>", $text);

        return $text;
    }
765314
protected function doAutoLinks($text)
    {
        if(!$this->features['auto_mailto'])
        {
            return preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
            array(&$this, '_doAutoLinks_url_callback'), $text);
        }

        return parent::doAutoLinks($text);
    }
52522
public function link(string $route, $options, string $text = null): self
    {
        $this->render(function ($datum) use ($route, $options, $text) {
            $attributes = [];
            $options = Arr::wrap($options);

            foreach ($options as $option) {
                if (method_exists($datum, 'getContent')) {
                    $attributes[] = $datum->getContent($option);
                    continue;
                }

                $attributes[] = $datum->getAttribute($option);
            }

            if (! is_null($text)) {
                $text = $datum->getContent($text);
                $text = $text ?? '—';
            }

            return view('platform::partials.td.link', [
                'route'      => $route,
                'attributes' => $attributes,
                'text'       => $text,
            ]);
        });

        return $this;
    }
33816
public function action($action, string $text, $parameters = [], bool $absolute = true)
    {
        return $this->add(Link::toAction($action, $text, $parameters, $absolute));
    }
160209
public function label($text, $options = [])
    {
        if (is_string($options)) {
            $options = ['type' => $options];
        }

        $options += [
            'tag' => 'span',
            'type' => 'default',
        ];

        $classes = ['label', 'label-' . $options['type']];
        $tag = $options['tag'];
        unset($options['tag'], $options['type']);

        return $this->tag($tag, $text, $this->injectClasses($classes, $options));
    }
462618
public function addPills($text, $href = '', $active = false)
    {
        $this->pills[$text] = ['href' => $href, 'active' => $active];

        return $this;
    }
110516
protected function linkifyMail($text, array &$links, $attr)
    {
        $regexp = '~([^\s<>]+?@[^\s<>]+?\.[^\s<>]+)(?<![\.,:;\?!\'"\|])~';
        
        return preg_replace_callback($regexp, function ($match) use (&$links, $attr) {
            return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>')
                . '>';
        }, $text);
    }