PHP Class Phergie_Plugin_Url, phergie

Has an utility method accessible via $this->getPlugin('Url')->getTitle('http://foo..').
Author: Phergie Development Team ([email protected])
Inheritance: extends Phergie_Plugin_Abstract
Datei anzeigen Open project: phergie/phergie

Protected Properties

Property Type Description
$cache Phergie_Plugin_Cache Cache object to store cached URLs to prevent spamming, especially with more than one bot on the same channel.
$errorMessage
$errorStatus boolean Flag that is set to true by the custom error handler if an HTTP error code has been received
$expire integer Setting it to 0 or below disables the cache expiration
$limit integer Setting it to 0 or below disables the cache limit
$renderers Array of renderers
$shortener Shortener object
$sslFallback boolean Flag that determines if the plugin will fall back to using an HTTP stream when a URL using SSL is detected and OpenSSL support isn't available in the PHP installation in use

Public Methods

Method Description
findUrls ( string $message ) : array Detect URLs in a given string.
getTitle ( string $url ) : string Returns the title of the given page
onAction ( ) : void Checks an incoming message for the presence of a URL and, if one is found, responds with its title if it is an HTML document and the shortened equivalent of its original URL if it meets length requirements.
onLoad ( ) : void Checks for dependencies.
onPrivmsg ( ) : void Checks an incoming message for the presence of a URL and, if one is found, responds with its title if it is an HTML document and the shortened equivalent of its original URL if it meets length requirements.
preDispatch ( ) : void Processes events before they are dispatched and tries to shorten any urls in the text
registerRenderer ( object $obj ) : void Add a renderer to the stack

Protected Methods

Method Description
checkUrlCache ( string $url, string $shortenedUrl ) : boolean Checks a given URL (+shortened) against the cache to verify if they were previously posted on the channel.
checkValidIP ( string $ip ) : boolean Checks the given string to see if its a valid IP4 address
debug ( string $msg ) : void Output a debug message
decode ( string $str, integer $trim = null ) : string Transliterates a UTF-8 string into corresponding ASCII characters and truncates and appends an ellipsis to the string if it exceeds a given length.
getUrlChecksum ( string $url ) : string Takes a url, parses and cleans the URL without of all the junk and then return the hex checksum of the url.
glueUrl ( string $uri, string $base = false ) : string Parses a given URI and then glues it back together in the proper format.
handleMsg ( ) : void Handles message events and responds with url titles.
parseUrl ( string $url ) : array Parses a given URI and procceses the output to remove redundant or missing values.
updateUrlCache ( string $url, string $shortenedUrl ) : boolean Updates the cache and adds the given URL (+shortened) to the cache. It also handles cleaning the cache of old entries as well.

Method Details

checkUrlCache() protected method

Checks a given URL (+shortened) against the cache to verify if they were previously posted on the channel.
protected checkUrlCache ( string $url, string $shortenedUrl ) : boolean
$url string The URL to check against
$shortenedUrl string The shortened URL to check against
return boolean

checkValidIP() protected method

Checks the given string to see if its a valid IP4 address
protected checkValidIP ( string $ip ) : boolean
$ip string the ip to validate
return boolean

debug() protected method

Output a debug message
protected debug ( string $msg ) : void
$msg string the message to output
return void

decode() protected method

Transliterates a UTF-8 string into corresponding ASCII characters and truncates and appends an ellipsis to the string if it exceeds a given length.
protected decode ( string $str, integer $trim = null ) : string
$str string String to decode
$trim integer Maximum string length, optional
return string

findUrls() public method

Detect URLs in a given string.
public findUrls ( string $message ) : array
$message string the string to detect urls in
return array the array of urls found

getTitle() public method

Returns the title of the given page
public getTitle ( string $url ) : string
$url string url to the page
return string title

getUrlChecksum() protected method

Takes a url, parses and cleans the URL without of all the junk and then return the hex checksum of the url.
protected getUrlChecksum ( string $url ) : string
$url string url to checksum
return string the hex checksum of the cleaned url

glueUrl() protected method

If base is set, then it chops off the scheme, user and pass and fragment information to return a more unique base URI.
protected glueUrl ( string $uri, string $base = false ) : string
$uri string uri to rebuild
$base string set to true to only return the base components
return string the rebuilt uri

handleMsg() protected method

Handles message events and responds with url titles.
protected handleMsg ( ) : void
return void

onAction() public method

Checks an incoming message for the presence of a URL and, if one is found, responds with its title if it is an HTML document and the shortened equivalent of its original URL if it meets length requirements.
public onAction ( ) : void
return void

onLoad() public method

Checks for dependencies.
public onLoad ( ) : void
return void

onPrivmsg() public method

Checks an incoming message for the presence of a URL and, if one is found, responds with its title if it is an HTML document and the shortened equivalent of its original URL if it meets length requirements.
public onPrivmsg ( ) : void
return void

parseUrl() protected method

Parses a given URI and procceses the output to remove redundant or missing values.
protected parseUrl ( string $url ) : array
$url string the url to parse
return array the url components

preDispatch() public method

Processes events before they are dispatched and tries to shorten any urls in the text
public preDispatch ( ) : void
return void

registerRenderer() public method

Add a renderer to the stack
public registerRenderer ( object $obj ) : void
$obj object the renderer to add
return void

updateUrlCache() protected method

Updates the cache and adds the given URL (+shortened) to the cache. It also handles cleaning the cache of old entries as well.
protected updateUrlCache ( string $url, string $shortenedUrl ) : boolean
$url string The URL to add to the cache
$shortenedUrl string The shortened to add to the cache
return boolean

Property Details

$cache protected_oe property

Cache object to store cached URLs to prevent spamming, especially with more than one bot on the same channel.
protected Phergie_Plugin_Cache $cache
return Phergie_Plugin_Cache

$errorMessage protected_oe property

protected $errorMessage

$errorStatus protected_oe property

Flag that is set to true by the custom error handler if an HTTP error code has been received
protected bool $errorStatus
return boolean

$expire protected_oe property

Setting it to 0 or below disables the cache expiration
protected int $expire
return integer

$limit protected_oe property

Setting it to 0 or below disables the cache limit
protected int $limit
return integer

$renderers protected_oe property

Array of renderers
protected $renderers

$shortener protected_oe property

Shortener object
protected $shortener

$sslFallback protected_oe property

Flag that determines if the plugin will fall back to using an HTTP stream when a URL using SSL is detected and OpenSSL support isn't available in the PHP installation in use
protected bool $sslFallback
return boolean