00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 class eZAutoLinkOperator
00032 {
00033
00034
00035 function eZAutoLinkOperator( $name = 'autolink' )
00036 {
00037 $this->Operators = array( $name );
00038 }
00039
00040
00041
00042
00043 function &operatorList()
00044 {
00045 return $this->Operators;
00046 }
00047
00048
00049
00050
00051 function namedParameterList()
00052 {
00053 return array( 'max_chars' => array( 'type' => 'integer',
00054 'required' => false,
00055 'default' => null ) );
00056 }
00057
00058 function formatUri( $url, $max )
00059 {
00060 $text = $url;
00061 if (strlen($text) > $max)
00062 {
00063 $text = substr($text, 0, ($max / 2) - 3). '...'. substr($text, strlen($text) - ($max / 2));
00064 }
00065 return "<a href=\"$url\" title=\"$url\">$text</a>";
00066 }
00067
00068
00069
00070
00071 function addURILinks( $text, $max, $methods = 'http|https|ftp' )
00072 {
00073 return preg_replace(
00074 "!($methods):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#;*\(\)\!]*[\w\-\@?^=%&\/~\+#;*\(\)\!])?!e",
00075 'eZAutoLinkOperator::formatUri("$0", '. $max. ')',
00076 $text
00077 );
00078 }
00079
00080
00081
00082
00083
00084 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
00085 {
00086 $ini =& $tpl->ini();
00087 $max = $ini->variable( 'AutoLinkOperator', 'MaxCharacters' );
00088 if ( $namedParameters['max_chars'] !== null )
00089 {
00090 $max = $namedParameters['max_chars'];
00091 }
00092
00093 $methods = $ini->variable( 'AutoLinkOperator', 'Methods' );
00094 $methodText = implode( '|', $methods );
00095
00096
00097 $operatorValue = preg_replace( "#(([a-zA-Z0-9_-]+\\.)*[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+\\.)*[a-zA-Z0-9_-]+)#", "<a href='mailto:\\1'>\\1</a>", $operatorValue );
00098
00099
00100 $operatorValue = eZAutoLinkOperator::addURILinks($operatorValue, $max, $methodText);
00101 }
00102
00103
00104 var $Operators;
00105 };
00106
00107 ?>