PHP Класс Twitter_Autolink, twitter-text-php

Parses tweets and generates HTML anchor tags around URLs, usernames, username/list pairs and hashtags. Originally written by {@link http://github.com/mikenz Mike Cochrane}, this is based on code by {@link http://github.com/mzsanford Matt Sanford} and heavily modified by {@link http://github.com/ngnpope Nick Pope}.
Автор: Mike Cochrane ([email protected])
Автор: Nick Pope ([email protected])
Наследование: extends Twitter_Regex
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$class_cash string CSS class for auto-linked cashtag URLs.
$class_hash string CSS class for auto-linked hashtag URLs.
$class_list string CSS class for auto-linked list URLs.
$class_url string CSS class for auto-linked URLs.
$class_user string CSS class for auto-linked username URLs.
$external boolean Often this is used to be matched on in JavaScript for dynamically adding the 'target' attribute which is deprecated in HTML 4.01. In HTML 5 it has been undeprecated and thus the 'target' attribute can be used. If this is set to false then the 'target' attribute will be output.
$nofollow boolean Whether to include the value 'nofollow' in the 'rel' attribute.
$target string Support for the 'target' attribute was deprecated in HTML 4.01 but has since been reinstated in HTML 5. To output the 'target' attribute you must disable the adding of the string 'external' to the 'rel' attribute.
$url_base_cash string URL base for cashtag links (the hashtag without the $ will be appended).
$url_base_hash string URL base for hashtag links (the hashtag without the # will be appended).
$url_base_list string URL base for list links (the username/list without the @ will be appended).
$url_base_user string URL base for username links (the username without the @ will be appended).

Открытые методы

Метод Описание
__construct ( string $tweet, boolean $escape = true, boolean $full_encode = false ) Reads in a tweet to be parsed and converted to contain links.
addLinks ( ) : string Adds links to all elements in the tweet.
addLinksToCashtags ( ) : string Adds links to cashtag elements in the tweet.
addLinksToHashtags ( ) : string Adds links to hashtag elements in the tweet.
addLinksToURLs ( ) : string Adds links to URL elements in the tweet.
addLinksToUsernamesAndLists ( ) : string Adds links to username/list elements in the tweet.
create ( string $tweet, boolean $full_encode = false ) : Twitter_Autolink Provides fluent method chaining.
getCashtagClass ( ) : string CSS class for auto-linked cashtag URLs.
getExternal ( ) : boolean Whether to include the value 'external' in the 'rel' attribute.
getHashtagClass ( ) : string CSS class for auto-linked hashtag URLs.
getListClass ( ) : string CSS class for auto-linked username/list URLs.
getNoFollow ( ) : boolean Whether to include the value 'nofollow' in the 'rel' attribute.
getTarget ( ) : string The scope to open the link in.
getURLClass ( ) : string CSS class for auto-linked URLs.
getUsernameClass ( ) : string CSS class for auto-linked username URLs.
setCashtagClass ( string $v ) : Twitter_Autolink CSS class for auto-linked cashtag URLs.
setExternal ( boolean $v ) : Twitter_Autolink Whether to include the value 'external' in the 'rel' attribute.
setHashtagClass ( string $v ) : Twitter_Autolink CSS class for auto-linked hashtag URLs.
setListClass ( string $v ) : Twitter_Autolink CSS class for auto-linked username/list URLs.
setNoFollow ( boolean $v ) : Twitter_Autolink Whether to include the value 'nofollow' in the 'rel' attribute.
setTarget ( string $v ) : Twitter_Autolink The scope to open the link in.
setURLClass ( string $v ) : Twitter_Autolink CSS class for auto-linked URLs.
setUsernameClass ( string $v ) : Twitter_Autolink CSS class for auto-linked username URLs.

Защищенные методы

Метод Описание
_addLinksToCashtags ( array $matches ) : string Callback used by the method that adds links to cashtags.
_addLinksToHashtags ( array $matches ) : string Callback used by the method that adds links to hashtags.
_addLinksToURLs ( array $matches ) : string Callback used by the method that adds links to URLs.
_addLinksToUsernamesAndLists ( array $matches ) : string Callback used by the method that adds links to username/list pairs.
wrap ( string $url, string $class, string $element ) : string Wraps a tweet element in an HTML anchor tag using the provided URL.
wrapHash ( string $url, string $class, string $element ) : string Wraps a tweet element in an HTML anchor tag using the provided URL.

Описание методов

__construct() публичный Метод

As the intent is to produce links and output the modified tweet to the user, we take this opportunity to ensure that we escape user input.
См. также: htmlspecialchars()
public __construct ( string $tweet, boolean $escape = true, boolean $full_encode = false )
$tweet string The tweet to be converted.
$escape boolean Whether to escape the tweet (default: true).
$full_encode boolean Whether to encode all special characters.

_addLinksToCashtags() защищенный Метод

Callback used by the method that adds links to cashtags.
См. также: addLinksToCashtags()
protected _addLinksToCashtags ( array $matches ) : string
$matches array The regular expression matches.
Результат string The link-wrapped cashtag.

_addLinksToHashtags() защищенный Метод

Callback used by the method that adds links to hashtags.
См. также: addLinksToHashtags()
protected _addLinksToHashtags ( array $matches ) : string
$matches array The regular expression matches.
Результат string The link-wrapped hashtag.

_addLinksToURLs() защищенный Метод

Callback used by the method that adds links to URLs.
См. также: addLinksToURLs()
protected _addLinksToURLs ( array $matches ) : string
$matches array The regular expression matches.
Результат string The link-wrapped URL.

_addLinksToUsernamesAndLists() защищенный Метод

Callback used by the method that adds links to username/list pairs.
См. также: addLinksToUsernamesAndLists()
protected _addLinksToUsernamesAndLists ( array $matches ) : string
$matches array The regular expression matches.
Результат string The link-wrapped username/list pair.

addLinksToCashtags() публичный Метод

Adds links to cashtag elements in the tweet.
public addLinksToCashtags ( ) : string
Результат string The modified tweet.

addLinksToHashtags() публичный Метод

Adds links to hashtag elements in the tweet.
public addLinksToHashtags ( ) : string
Результат string The modified tweet.

addLinksToURLs() публичный Метод

Adds links to URL elements in the tweet.
public addLinksToURLs ( ) : string
Результат string The modified tweet.

addLinksToUsernamesAndLists() публичный Метод

Adds links to username/list elements in the tweet.
public addLinksToUsernamesAndLists ( ) : string
Результат string The modified tweet.

create() публичный статический Метод

Provides fluent method chaining.
См. также: __construct()
public static create ( string $tweet, boolean $full_encode = false ) : Twitter_Autolink
$tweet string The tweet to be converted.
$full_encode boolean Whether to encode all special characters.
Результат Twitter_Autolink

getCashtagClass() публичный Метод

CSS class for auto-linked cashtag URLs.
public getCashtagClass ( ) : string
Результат string CSS class for cashtag links.

getExternal() публичный Метод

Often this is used to be matched on in JavaScript for dynamically adding the 'target' attribute which is deprecated in HTML 4.01. In HTML 5 it has been undeprecated and thus the 'target' attribute can be used. If this is set to false then the 'target' attribute will be output.
public getExternal ( ) : boolean
Результат boolean Whether to add 'external' to the 'rel' attribute.

getHashtagClass() публичный Метод

CSS class for auto-linked hashtag URLs.
public getHashtagClass ( ) : string
Результат string CSS class for hashtag links.

getListClass() публичный Метод

CSS class for auto-linked username/list URLs.
public getListClass ( ) : string
Результат string CSS class for username/list links.

getNoFollow() публичный Метод

Whether to include the value 'nofollow' in the 'rel' attribute.
public getNoFollow ( ) : boolean
Результат boolean Whether to add 'nofollow' to the 'rel' attribute.

getTarget() публичный Метод

Support for the 'target' attribute was deprecated in HTML 4.01 but has since been reinstated in HTML 5. To output the 'target' attribute you must disable the adding of the string 'external' to the 'rel' attribute.
public getTarget ( ) : string
Результат string The value to add to the 'target' attribute.

getURLClass() публичный Метод

CSS class for auto-linked URLs.
public getURLClass ( ) : string
Результат string CSS class for URL links.

getUsernameClass() публичный Метод

CSS class for auto-linked username URLs.
public getUsernameClass ( ) : string
Результат string CSS class for username links.

setCashtagClass() публичный Метод

CSS class for auto-linked cashtag URLs.
public setCashtagClass ( string $v ) : Twitter_Autolink
$v string CSS class for cashtag links.
Результат Twitter_Autolink Fluid method chaining.

setExternal() публичный Метод

Often this is used to be matched on in JavaScript for dynamically adding the 'target' attribute which is deprecated in HTML 4.01. In HTML 5 it has been undeprecated and thus the 'target' attribute can be used. If this is set to false then the 'target' attribute will be output.
public setExternal ( boolean $v ) : Twitter_Autolink
$v boolean The value to add to the 'target' attribute.
Результат Twitter_Autolink Fluid method chaining.

setHashtagClass() публичный Метод

CSS class for auto-linked hashtag URLs.
public setHashtagClass ( string $v ) : Twitter_Autolink
$v string CSS class for hashtag links.
Результат Twitter_Autolink Fluid method chaining.

setListClass() публичный Метод

CSS class for auto-linked username/list URLs.
public setListClass ( string $v ) : Twitter_Autolink
$v string CSS class for username/list links.
Результат Twitter_Autolink Fluid method chaining.

setNoFollow() публичный Метод

Whether to include the value 'nofollow' in the 'rel' attribute.
public setNoFollow ( boolean $v ) : Twitter_Autolink
$v boolean The value to add to the 'target' attribute.
Результат Twitter_Autolink Fluid method chaining.

setTarget() публичный Метод

Support for the 'target' attribute was deprecated in HTML 4.01 but has since been reinstated in HTML 5. To output the 'target' attribute you must disable the adding of the string 'external' to the 'rel' attribute.
public setTarget ( string $v ) : Twitter_Autolink
$v string The value to add to the 'target' attribute.
Результат Twitter_Autolink Fluid method chaining.

setURLClass() публичный Метод

CSS class for auto-linked URLs.
public setURLClass ( string $v ) : Twitter_Autolink
$v string CSS class for URL links.
Результат Twitter_Autolink Fluid method chaining.

setUsernameClass() публичный Метод

CSS class for auto-linked username URLs.
public setUsernameClass ( string $v ) : Twitter_Autolink
$v string CSS class for username links.
Результат Twitter_Autolink Fluid method chaining.

wrap() защищенный Метод

This is a helper function to perform the generation of the link.
protected wrap ( string $url, string $class, string $element ) : string
$url string The URL to use as the href.
$class string The CSS class(es) to apply (space separated).
$element string The tweet element to wrap.
Результат string The tweet element with a link applied.

wrapHash() защищенный Метод

This is a helper function to perform the generation of the hashtag link.
protected wrapHash ( string $url, string $class, string $element ) : string
$url string The URL to use as the href.
$class string The CSS class(es) to apply (space separated).
$element string The tweet element to wrap.
Результат string The tweet element with a link applied.

Описание свойств

$class_cash защищенное свойство

CSS class for auto-linked cashtag URLs.
protected string $class_cash
Результат string

$class_hash защищенное свойство

CSS class for auto-linked hashtag URLs.
protected string $class_hash
Результат string

$class_list защищенное свойство

CSS class for auto-linked list URLs.
protected string $class_list
Результат string

$class_url защищенное свойство

CSS class for auto-linked URLs.
protected string $class_url
Результат string

$class_user защищенное свойство

CSS class for auto-linked username URLs.
protected string $class_user
Результат string

$external защищенное свойство

Often this is used to be matched on in JavaScript for dynamically adding the 'target' attribute which is deprecated in HTML 4.01. In HTML 5 it has been undeprecated and thus the 'target' attribute can be used. If this is set to false then the 'target' attribute will be output.
protected bool $external
Результат boolean

$nofollow защищенное свойство

Whether to include the value 'nofollow' in the 'rel' attribute.
protected bool $nofollow
Результат boolean

$target защищенное свойство

Support for the 'target' attribute was deprecated in HTML 4.01 but has since been reinstated in HTML 5. To output the 'target' attribute you must disable the adding of the string 'external' to the 'rel' attribute.
protected string $target
Результат string

$url_base_cash защищенное свойство

URL base for cashtag links (the hashtag without the $ will be appended).
protected string $url_base_cash
Результат string

$url_base_hash защищенное свойство

URL base for hashtag links (the hashtag without the # will be appended).
protected string $url_base_hash
Результат string

$url_base_list защищенное свойство

URL base for list links (the username/list without the @ will be appended).
protected string $url_base_list
Результат string

$url_base_user защищенное свойство

URL base for username links (the username without the @ will be appended).
protected string $url_base_user
Результат string