Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezautolinkoperator.php
Go to the documentation of this file.
1 <?php
11 class eZAutoLinkOperator
12 {
18 public function __construct( $name = 'autolink' )
19 {
20 $this->Operators = array( $name );
21 }
22
26 function operatorList()
27 {
28 return $this->Operators;
29 }
30
34 function namedParameterList()
35 {
36 return array( 'max_chars' => array( 'type' => 'integer',
37 'required' => false,
38 'default' => null ) );
39 }
40
41 function formatUri( $url, $max )
42 {
43 $text = $url;
44 if (strlen($text) > $max)
45 {
46 $text = substr($text, 0, ($max / 2) - 3). '...'. substr($text, strlen($text) - ($max / 2));
47 }
48 return "<a href=\"$url\" title=\"$url\">$text</a>";
49 }
50
54 function addURILinks( $text, $max, $methods = 'http|https|ftp' )
55 {
56 return preg_replace_callback(
57 "`(?<!href=\"|href='|src=\"|src='|value=\"|value=')($methods):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#;*\‍(\‍)\!]*[\w\-\@?^=%&\/~\+#;*\‍(\‍)\!])?`",
58 function($matches) use ($max) { return eZAutoLinkOperator::formatUri( $matches[0], $max ); },
59 $text
60 );
61 }
62
63
64 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
65 {
66 $ini = $tpl->ini();
67 $max = $ini->variable( 'AutoLinkOperator', 'MaxCharacters' );
68 if ( $namedParameters['max_chars'] !== null )
69 {
70 $max = $namedParameters['max_chars'];
71 }
72
73 $methods = $ini->variable( 'AutoLinkOperator', 'Methods' );
74 $methodText = implode( '|', $methods );
75
76 // Replace mail
77 $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 );
78
79 // Replace http/ftp etc. links
80 $operatorValue = eZAutoLinkOperator::addURILinks($operatorValue, $max, $methodText);
81 }
82
84 public $Operators;
85 }
86
87 ?>
eZAutoLinkOperator
Definition: ezautolinkoperator.php:12
eZAutoLinkOperator\formatUri
formatUri( $url, $max)
Definition: ezautolinkoperator.php:41
eZAutoLinkOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezautolinkoperator.php:64
eZAutoLinkOperator\addURILinks
addURILinks( $text, $max, $methods='http|https|ftp')
Definition: ezautolinkoperator.php:54
eZAutoLinkOperator\namedParameterList
namedParameterList()
Definition: ezautolinkoperator.php:34
eZAutoLinkOperator\operatorList
operatorList()
Definition: ezautolinkoperator.php:26
eZAutoLinkOperator\__construct
__construct( $name='autolink')
Definition: ezautolinkoperator.php:18
eZAutoLinkOperator\$Operators
$Operators
Definition: ezautolinkoperator.php:84
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.