Documentation

Autolinker
in package

Detects URLs in strings.

Table of Contents

Properties

$balanced_pairs  : array<string|int, mixed>
$domain_label_chars  : string
$no_autolink_tags  : array<string|int, mixed>
$schemes  : array<string|int, mixed>
$tags_to_fix  : array<string|int, mixed>
$email_regex  : string
$encoding  : string
$integrate_autolinker_fix_tags_done  : bool
$integrate_autolinker_schemes_done  : bool
$js_email_regex  : string
$js_tld_regex  : string
$js_url_regexes  : array<string|int, mixed>
$only_basic  : bool
$tld_regex  : string
$url_regex  : string
$instance  : self

Methods

__construct()  : mixed
Constructor.
createJavaScriptFile()  : void
Creates the JavaScript file used for autolinking in the editor.
detectEmails()  : array<string|int, mixed>
Detects email addresses in a string.
detectUrls()  : array<string|int, mixed>
Detects URLs in a string.
fixUrlsInBBC()  : string
Checks URLs inside BBCodes and fixes them if invalid.
getEmailRegex()  : string
Gets a PCRE regular expression to match email addresses.
getJavaScriptEmailRegex()  : string
Gets a JavaScript regular expression to match email addresses.
getJavaScriptTldRegex()  : string
Gets a JavaScript regular expression to match all known TLDs.
getJavaScriptUrlRegexes()  : array<string|int, mixed>
Gets a series of JavaScript regular expressions to match URLs.
getTldRegex()  : string
Gets a PCRE regular expression to match all known TLDs.
getUrlRegex()  : string
Gets a PCRE regular expression to match URLs.
load()  : object
Returns a reusable instance of this class.
makeLinks()  : string
Detects plain text URLs and email addresses and formats them as BBCode links.
setEmailRegex()  : void
Sets $this->email_regex.
setJavaScriptEmailRegex()  : void
Sets $this->js_email_regex.
setJavaScriptTldRegex()  : void
Sets $this->js_tld_regex.
setJavaScriptUrlRegexes()  : void
Sets $this->js_url_regexes.
setTldRegex()  : void
Sets $this->tld_regex.
setUrlRegex()  : void
Sets $this->url_regex.

Properties

$balanced_pairs

public static array<string|int, mixed> $balanced_pairs = [ // Brackets and parentheses '(' => ')', // '&#x28;' => '&#x29;', '[' => ']', // '&#x5B;' => '&#x5D;', '{' => '}', // '&#x7B;' => '&#x7D;', // Double quotation marks '"' => '"', // '&#x22;' => '&#x22;', '“' => '”', // '&#x201C;' => '&#x201D;', '„' => '”', // '&#x201E;' => '&#x201D;', '‟' => '”', // '&#x201F;' => '&#x201D;', '«' => '»', // '&#xAB;' => '&#xBB;', // Single quotation marks "'" => "'", // '&#x27;' => '&#x27;', '‘' => '’', // '&#x2018;' => '&#x2019;', '‚' => '’', // '&#x201A;' => '&#x2019;', '‛' => '’', // '&#x201B;' => '&#x2019;', '‹' => '›', ]

Brackets and quotation marks are problematic at the end of an IRI. E.g.: http://foo.com/baz(qux) vs. (http://foo.com/baz_qux) In the first case, the user probably intended the ) as part of the IRI, but not in the second case. To account for this, we test for balanced pairs within the IRI.

$domain_label_chars

public static string $domain_label_chars = '0-9A-Za-z\-' . '\x{A0}-\x{D7FF}' . '\x{F900}-\x{FDCF}' . '\x{FDF0}-\x{FFEF}' . '\x{10000}-\x{1FFFD}' . '\x{20000}-\x{2FFFD}' . '\x{30000}-\x{3FFFD}' . '\x{40000}-\x{4FFFD}' . '\x{50000}-\x{5FFFD}' . '\x{60000}-\x{6FFFD}' . '\x{70000}-\x{7FFFD}' . '\x{80000}-\x{8FFFD}' . '\x{90000}-\x{9FFFD}' . '\x{A0000}-\x{AFFFD}' . '\x{B0000}-\x{BFFFD}' . '\x{C0000}-\x{CFFFD}' . '\x{D0000}-\x{DFFFD}' . '\x{E1000}-\x{EFFFD}'

Regular expression character class to match all characters allowed to appear in a domain name.

public static array<string|int, mixed> $no_autolink_tags = ['url', 'iurl', 'email', 'img', 'html', 'attach', 'ftp', 'flash', 'member', 'code', 'php', 'nobbc', 'nolink']

BBCodes whose content should be skipped when autolinking URLs.

Mods can add to this list using the integrate_bbc_codes hook in Parsers\BBCodeParser::integrateBBC()

$schemes

public static array<string|int, mixed> $schemes = [ // Schemes whose URI definitions require a domain name in the // authority (or whatever the next part of the URI is). 'need_domain' => ['aaa', 'aaas', 'acap', 'acct', 'afp', 'cap', 'cid', 'coap', 'coap+tcp', 'coap+ws', 'coaps', 'coaps+tcp', 'coaps+ws', 'crid', 'cvs', 'dict', 'dns', 'feed', 'fish', 'ftp', 'git', 'go', 'gopher', 'h323', 'http', 'https', 'iax', 'icap', 'im', 'imap', 'ipp', 'ipps', 'irc', 'irc6', 'ircs', 'ldap', 'ldaps', 'mailto', 'mid', 'mupdate', 'nfs', 'nntp', 'pop', 'pres', 'reload', 'rsync', 'rtsp', 'sftp', 'sieve', 'sip', 'sips', 'smb', 'snmp', 'soap.beep', 'soap.beeps', 'ssh', 'svn', 'stun', 'stuns', 'telnet', 'tftp', 'tip', 'tn3270', 'turn', 'turns', 'tv', 'udp', 'vemmi', 'vnc', 'webcal', 'ws', 'wss', 'xmlrpc.beep', 'xmlrpc.beeps', 'xmpp', 'z39.50', 'z39.50r', 'z39.50s'], // Schemes that allow an empty authority ("://" followed by "/") 'empty_authority' => ['file', 'ni', 'nih'], // Schemes that do not use an authority but still have a reasonable // chance of working as clickable links. 'no_authority' => ['about', 'callto', 'geo', 'gg', 'leaptofrogans', 'magnet', 'mailto', 'maps', 'news', 'ni', 'nih', 'service', 'skype', 'sms', 'tel', 'tv'], // Schemes that should never be autolinked. 'forbidden' => ['javascript', 'data'], ]

URI schemes that require some sort of special handling.

Mods can add to this list using the integrate_autolinker_schemes hook in Autolinker::__construct().

$tags_to_fix

public static array<string|int, mixed> $tags_to_fix = ['url', 'iurl', 'img', 'ftp']

BBCodes in which to fix URL strings.

Mods can add to this list using the integrate_autolinker_fix_tags hook in Autolinker::fixUrlsInBBC().

$email_regex

protected string $email_regex

PCRE regular expression to match e-mail addresses.

$encoding

protected string $encoding = 'UTF-8'

The character encoding being used.

$integrate_autolinker_fix_tags_done

protected static bool $integrate_autolinker_fix_tags_done = false

Ensures we only call integrate_autolinker_fix_tags once.

$integrate_autolinker_schemes_done

protected static bool $integrate_autolinker_schemes_done = false

Ensures we only call integrate_autolinker_schemes once.

$js_email_regex

protected string $js_email_regex

JavaScript regular expression to match e-mail addresses.

$js_tld_regex

protected string $js_tld_regex

JavaScript regular expression to match top level domains.

$js_url_regexes

protected array<string|int, mixed> $js_url_regexes

JavaScript regular expressions to match URLs.

Due to limitations of JavaScript's regex engine, this has to be a series of different regexes rather than one regex like the PCRE version.

$only_basic

protected bool $only_basic = false

If true, will only link URLs with basic TLDs.

$tld_regex

protected string $tld_regex

PCRE regular expression to match top level domains.

$url_regex

protected string $url_regex

PCRE regular expression to match URLs.

$instance

private static self $instance

A reference to an existing, reusable instance of this class.

Methods

__construct()

Constructor.

public __construct([bool $only_basic = false ]) : mixed
Parameters
$only_basic : bool = false

If true, will only link URLs with basic TLDs.

createJavaScriptFile()

Creates the JavaScript file used for autolinking in the editor.

public static createJavaScriptFile([bool $force = false ]) : void
Parameters
$force : bool = false

Whether to overwrite an existing file. Default: false.

detectEmails()

Detects email addresses in a string.

public detectEmails(string $string[, bool $plaintext_only = false ]) : array<string|int, mixed>

Returns an array in which the keys are the start positions of any detected email addresses in the string, and the values are the email addresses themselves.

Parameters
$string : string

The string to examine.

$plaintext_only : bool = false
Return values
array<string|int, mixed>

Positional info about any detected email addresses.

detectUrls()

Detects URLs in a string.

public detectUrls(string $string[, bool $plaintext_only = false ]) : array<string|int, mixed>

Returns an array in which the keys are the start positions of any detected URLs in the string, and the values are the URLs themselves.

Parameters
$string : string

The string to examine.

$plaintext_only : bool = false
Return values
array<string|int, mixed>

Positional info about any detected URLs.

fixUrlsInBBC()

Checks URLs inside BBCodes and fixes them if invalid.

public fixUrlsInBBC(string $string) : string
Parameters
$string : string

The string containing the BBCodes.

Return values
string

The fixed string.

getEmailRegex()

Gets a PCRE regular expression to match email addresses.

public getEmailRegex() : string
Return values
string

Regular expression to match email addresses.

getJavaScriptEmailRegex()

Gets a JavaScript regular expression to match email addresses.

public getJavaScriptEmailRegex() : string
Return values
string

Regular expression to match email addresses.

getJavaScriptTldRegex()

Gets a JavaScript regular expression to match all known TLDs.

public getJavaScriptTldRegex() : string
Return values
string

Regular expression to match all known TLDs.

getJavaScriptUrlRegexes()

Gets a series of JavaScript regular expressions to match URLs.

public getJavaScriptUrlRegexes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Regular expressions to match URLs.

getTldRegex()

Gets a PCRE regular expression to match all known TLDs.

public getTldRegex() : string
Return values
string

Regular expression to match all known TLDs.

getUrlRegex()

Gets a PCRE regular expression to match URLs.

public getUrlRegex() : string
Return values
string

Regular expression to match URLs.

load()

Returns a reusable instance of this class.

public static load([bool $only_basic = false ]) : object
Parameters
$only_basic : bool = false

If true, will only link URLs with basic TLDs.

Return values
object

An instance of this class.

Detects plain text URLs and email addresses and formats them as BBCode links.

public makeLinks(string $string[, bool $link_emails = true ][, bool $link_urls = true ]) : string
Parameters
$string : string

The string to autolink.

$link_emails : bool = true

Whether to autolink email addresses. Default: true.

$link_urls : bool = true

Whether to autolink URLs. Default: true.

Return values
string

The string with linked URLs.

setEmailRegex()

Sets $this->email_regex.

protected setEmailRegex() : void

setJavaScriptEmailRegex()

Sets $this->js_email_regex.

protected setJavaScriptEmailRegex() : void

setJavaScriptTldRegex()

Sets $this->js_tld_regex.

protected setJavaScriptTldRegex() : void

setJavaScriptUrlRegexes()

Sets $this->js_url_regexes.

protected setJavaScriptUrlRegexes() : void

setTldRegex()

Sets $this->tld_regex.

protected setTldRegex() : void

setUrlRegex()

Sets $this->url_regex.

protected setUrlRegex() : void

        
On this page

Search results