|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZAutoLinkOperator class 00004 // 00005 // Created on: <07-Feb-2003 09:39:55 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 class eZAutoLinkOperator 00032 { 00033 /*! 00034 */ 00035 function eZAutoLinkOperator( $name = 'autolink' ) 00036 { 00037 $this->Operators = array( $name ); 00038 } 00039 00040 /*! 00041 Returns the operators in this class. 00042 */ 00043 function operatorList() 00044 { 00045 return $this->Operators; 00046 } 00047 00048 /*! 00049 See eZTemplateOperator::namedParameterList() 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 \static 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 \reimp 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 // Replace mail 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 // Replace http/ftp etc. links 00100 $operatorValue = eZAutoLinkOperator::addURILinks($operatorValue, $max, $methodText); 00101 } 00102 00103 /// \privatesection 00104 public $Operators; 00105 }; 00106 00107 ?>