*/ /** * patTemplate modifier Clicktext * * Make standard text "clickable" * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Clicktext extends patTemplate_Modifier { /** * modify the value * * @access public * @param string value * @return string modified value */ public function modify( $value, $params = array() ) { // convert www.xxx to http://www.xxx $value = preg_replace( '|(\s+)(www\.)|', '${1}http://www.', $value ); // replace http and ftp URLS $regex = '/(https?|ftp):\\/\\/((?:[a-z0-9@:.-]|%[0-9A-F]{2}){3,})(?::(\\d+))?((?:\\/(?:[a-z0-9-._~!$&\'*+,;=:@]|%[0-9A-F]{2})*)*)(?:\\?((?:[a-z0-9-._~!$&\'*+,;=:\\/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&\'*+,;=:\\/?@]|%[0-9A-F]{2})*))?/i'; $value = preg_replace_callback($regex, array($this, 'replaceUrlString'), $value); // $value = preg_replace( '_(ftp|http(s?))://(([\w\d]+)\.([\w\d]+)[/\d\w\.\?\&\=]+)_', '${1}://${3}', $value ); // convert email to link //$value = preg_replace( '|([\d\w\.-\_]+)@([\d\.-\w]+)|', '${1}@${2}', $value, -1 ); return $value; } /** * callback for regex to create links * * Create links with title and href target="_blank" * * @param array $match * @return string */ protected function replaceUrlString($match) { // convert URL to node $href = $match[1] . '://' . $match[2] . $match[4]; if (isset($match[5])) { $href .= '?' . $match[5]; } $title = urldecode($href); return sprintf( '%s', $href, $title, $title); } } ?>