Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsimpletagsoperator.php
Go to the documentation of this file.
1 <?php
11 class eZSimpleTagsOperator
12 {
18 public function __construct( $name = 'simpletags' )
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( 'listname' => array( 'type' => 'string',
37 'required' => false,
38 'default' => false ) );
39 }
40
47 function initializeIncludes()
48 {
49 // If we have this global variable we shouldn't do any processing
50 if ( !empty( $GLOBALS['eZSimpleTagsInit'] ) )
51 return;
52
53 $GLOBALS['eZSimpleTagsInit'] = true;
54 $ini = eZINI::instance( 'template.ini' );
55 $extensions = $ini->variable( 'SimpleTagsOperator', 'Extensions' );
56 $pathList = eZExtension::expandedPathList( $extensions, 'simpletags' );
57 $includeList = $ini->variable( 'SimpleTagsOperator', 'IncludeList' );
58
59 foreach ( $includeList as $includeFile )
60 {
61 foreach ( $pathList as $path )
62 {
63 $file = $path . '/' . $includeFile;
64 if ( file_exists( $file ) )
65 {
66 include_once( $file );
67 }
68 }
69 }
70 }
71
72 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
73 {
74 $elements = preg_split( "#(</?[a-zA-Z0-9_-]+>)#",
75 $operatorValue,
76 false,
77 PREG_SPLIT_DELIM_CAPTURE );
78 $newElements = array();
79 $i = 0;
80 foreach ( $elements as $element )
81 {
82 if ( ( $i % 2 ) == 1 )
83 {
84 $tagText = $element;
85 if ( preg_match( "#<(/?)([a-zA-Z0-9_-]+)>#", $tagText, $matches ) )
86 {
87 $isEndTag = false;
88 if ( $matches[1] )
89 $isEndTag = true;
90 $tag = $matches[2];
91 $element = array( $tag, $isEndTag, $tagText );
92 }
93 }
94 $newElements[] = $element;
95 ++$i;
96 }
97
98 $tagListName = 'TagList';
99 if ( $namedParameters['listname'] )
100 $tagListName .= '_' . $namedParameters['listname'];
101
102 $this->initializeIncludes();
103
104 $tagMap = array();
105 $ini = eZINI::instance( 'template.ini' );
106 $tagList = $ini->variable( 'SimpleTagsOperator', $tagListName );
107 foreach ( $tagList as $tag => $tagItem )
108 {
109 $elements = explode( ';', $tagItem );
110 $pre = $elements[0];
111 $post = $elements[1];
112 $phpFunctions = array();
113 if ( isset( $elements[2] ) )
114 {
115 $phpFunctionList = explode( ',', $elements[2] );
116 $phpFunctions = array();
117 foreach ( $phpFunctionList as $phpFunction )
118 {
119 if ( function_exists( $phpFunction ) )
120 $phpFunctions[] = $phpFunction;
121 }
122 }
123 $tagMap[$tag] = array( 'pre' => $pre,
124 'post' => $post,
125 'phpfunctions' => $phpFunctions );
126 }
127
128 $textPHPFunctions = array( 'htmlspecialchars' );
129 $textPre = false;
130 $textPost = false;
131 if ( isset( $tagMap['text']['pre'] ) )
132 $textPre = $tagMap['text']['pre'];
133 if ( isset( $tagMap['text']['post'] ) )
134 $textPost = $tagMap['text']['post'];
135 if ( isset( $tagMap['text']['phpfunctions'] ) )
136 $textPHPFunctions = $tagMap['text']['phpfunctions'];
137 $textElements = array();
138 for ( $i = 0; $i < count( $newElements ); ++$i )
139 {
140 $element = $newElements[$i];
141 if ( is_string( $element ) )
142 {
143 $text = $element;
144 foreach ( $textPHPFunctions as $textPHPFunction )
145 {
146 $text = $textPHPFunction( $text );
147 }
148 $textElements[] = $textPre . $text . $textPost;
149 }
150 else if ( is_array( $element ) )
151 {
152 $tag = $element[0];
153 $isEndTag = $element[1];
154 $originalText = $element[2];
155 if ( isset( $tagMap[$tag] ) )
156 {
157 $tagOptions = $tagMap[$tag];
158 $phpFunctions = $tagOptions['phpfunctions'];
159 if ( !$isEndTag )
160 {
161 $tagElements = array();
162 for ( $j = $i + 1; $j < count( $newElements ); ++$j )
163 {
164 $tagElement = $newElements[$j];
165 if ( is_string( $tagElement ) )
166 {
167 $tagElements[] = $tagElement;
168 }
169 else if ( is_array( $tagElement ) )
170 {
171 if ( $tagElement[0] == $tag and
172 $tagElement[1] )
173 {
174 break;
175 }
176 $text = $tagElement[2];
177 $tagElements[] = $text;
178 }
179 }
180 $i = $j;
181 $textElements[] = $tagOptions['pre'];
182 $text = implode( '', $tagElements );
183 foreach ( $phpFunctions as $phpFunction )
184 {
185 $text = $phpFunction( $text );
186 }
187 $textElements[] = $text;
188 $textElements[] = $tagOptions['post'];
189 }
190 }
191 else
192 {
193 $text = $originalText;
194 foreach ( $textPHPFunctions as $textPHPFunction )
195 {
196 $text = $textPHPFunction( $text );
197 }
198 $textElements[] = $textPre . $text . $textPost;
199 }
200 }
201 }
202
203 $operatorValue = implode( '', $textElements );
204 }
205
207 public $Operators;
208 }
209
210 ?>
eZExtension\expandedPathList
static expandedPathList( $extensionList, $subdirectory=false)
Definition: ezextension.php:334
eZSimpleTagsOperator
Definition: ezsimpletagsoperator.php:12
eZSimpleTagsOperator\initializeIncludes
initializeIncludes()
Definition: ezsimpletagsoperator.php:47
eZSimpleTagsOperator\namedParameterList
namedParameterList()
Definition: ezsimpletagsoperator.php:34
eZSimpleTagsOperator\$Operators
$Operators
Definition: ezsimpletagsoperator.php:207
eZSimpleTagsOperator\__construct
__construct( $name='simpletags')
Definition: ezsimpletagsoperator.php:18
eZSimpleTagsOperator\operatorList
operatorList()
Definition: ezsimpletagsoperator.php:26
eZSimpleTagsOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezsimpletagsoperator.php:72
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.