Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatetextoperator.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateTextOperator
18 {
19 public function __construct()
20 {
21 $this->Operators= array( 'concat', 'indent' );
22
23 foreach ( $this->Operators as $operator )
24 {
25 $name = $operator . 'Name';
26 $name[0] = $name[0] & "\xdf";
27 $this->$name = $operator;
28 }
29 }
30
34 function operatorList()
35 {
36 return $this->Operators;
37 }
38
39 function operatorTemplateHints()
40 {
41 return array( $this->ConcatName => array( 'input' => true,
42 'output' => true,
43 'parameters' => true,
44 'element-transformation' => true,
45 'transform-parameters' => true,
46 'input-as-parameter' => true,
47 'element-transformation-func' => 'concatTransformation'),
48 $this->IndentName => array( 'input' => true,
49 'output' => true,
50 'parameters' => 3,
51 'element-transformation' => true,
52 'transform-parameters' => true,
53 'input-as-parameter' => true,
54 'element-transformation-func' => 'indentTransformation') ) ;
55 }
56
60 function namedParameterPerOperator()
61 {
62 return true;
63 }
64
68 function namedParameterList()
69 {
70 return array( $this->IndentName => array( 'indent_count' => array( 'type' => 'integer',
71 'required' => true,
72 'default' => false ),
73 'indent_type' => array( 'type' => 'identifier',
74 'required' => false,
75 'default' => 'space' ),
76 'indent_filler' => array( 'type' => 'string',
77 'required' => false,
78 'default' => false ) ) );
79 }
80
81 function indentTransformation( $operatorName, &$node, $tpl, &$resourceData,
82 $element, $lastElement, $elementList, $elementTree, &$parameters )
83 {
84 $values = array();
85 $count = $type = $filler = false;
86 $paramCount = count( $parameters );
87
88 if ( $paramCount == 4 )
89 {
90 if ( eZTemplateNodeTool::isConstantElement( $parameters[3] ) )
91 {
92 $filler = eZTemplateNodeTool::elementConstantValue( $parameters[3] );
93 }
94 }
95 if ( $paramCount >= 3 )
96 {
97 if ( eZTemplateNodeTool::isConstantElement( $parameters[2] ) )
98 {
99 $type = eZTemplateNodeTool::elementConstantValue( $parameters[2] );
100 if ( $type == 'space' )
101 {
102 $filler = ' ';
103 }
104 else if ( $type == 'tab' )
105 {
106 $filler = "\t";
107 }
108 else if ( $type != 'custom' )
109 {
110 $filler = ' ';
111 }
112 }
113 }
114 if ( $paramCount >= 2 )
115 {
116 if ( eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
117 {
118 $count = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
119 }
120 if ( $paramCount < 3 )
121 {
122 $type = 'space';
123 $filler = ' ';
124 }
125 }
126 $newElements = array();
127
128 if ( $count and $type and $filler )
129 {
130 $tmpCount = 0;
131 $values[] = $parameters[0];
132 if ( $count < 0 )
133 {
134 //$code = ( $tpl->error( "indent", "Count parameter can not be negative" );
135 $code = ( "\$tpl->error( \"indent\", \"Count parameter can not be negative, string won't be indented\" );\n" .
136 "%output% = %1%;\n" );
137 }
138 else
139 {
140 $indentation = str_repeat( $filler, $count );
141 $code = ( "%output% = '$indentation' . str_replace( '\n', '\n$indentation', %1% );\n" );
142 }
143 }
144 else if ( $filler and $type )
145 {
146 $tmpCount = 1;
147 $values[] = $parameters[0];
148 $values[] = $parameters[1];
149 $code = ( "if ( %2% < 0 )\n{" .
150 "\$tpl->error( \"indent\", \"Count parameter can not be negative, string won't be indented\" );\n" .
151 "%output% = %1%;\n" .
152 "}else{\n" .
153 "%tmp1% = str_repeat( '$filler', %2% );\n" .
154 "%output% = %tmp1% . str_replace( '\n', '\n' . %tmp1%, %1% );\n" .
155 "}\n");
156 }
157 else
158 {
159 $tmpCount = 2;
160 $code = ( "if ( %2% < 0 ){\n" .
161 "\$tpl->error( \"indent\", \"Count parameter can not be negative, string won't be indented\" );\n" .
162 "%output% = %1%;\n" .
163 "}else{" .
164 "if ( %3% == 'tab' )\n{\n\t%tmp1% = \"\\t\";\n}\nelse " .
165 "if ( %3% == 'space' )\n{\n\t%tmp1% = ' ';\n}\nelse\n" );
166 if ( count ( $parameters ) == 4 )
167 {
168 $code .= "{\n\t%tmp1% = %4%;\n}\n";
169 }
170 else
171 {
172 $code.= "{\n\t%tmp1% = ' ';\n}\n";
173 }
174 $code .= ( "%tmp2% = str_repeat( %tmp1%, %2% );\n" .
175 "%output% = %tmp2% . str_replace( '\n', '\n' . %tmp2%, %1% );\n" );
176 $code .= "}\n";
177 foreach ( $parameters as $parameter )
178 {
179 $values[] = $parameter;
180 }
181 }
182
183 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, 'false', $tmpCount );
184 return $newElements;
185 }
186
187 function concatTransformation( $operatorName, &$node, $tpl, &$resourceData,
188 $element, $lastElement, $elementList, $elementTree, &$parameters )
189 {
190 $values = array();
191 $function = $operatorName;
192
193 if ( ( count( $parameters ) < 1 ) )
194 {
195 return false;
196 }
197 if ( ( count( $parameters ) == 1 ) and
198 eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
199 {
200 return array( eZTemplateNodeTool::createConstantElement( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) ) );
201 }
202 $newElements = array();
203
204 $counter = 1;
205 $code = "%output% = ( ";
206 foreach ( $parameters as $parameter )
207 {
208 $values[] = $parameter;
209 if ( $counter > 1 )
210 {
211 $code .= ' . ';
212 }
213 $code .= "%$counter%";
214 $counter++;
215 }
216 $code .= " );\n";
217
218 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
219 return $newElements;
220 }
221
225 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters,
226 $placement )
227 {
228 switch ( $operatorName )
229 {
230 case $this->ConcatName:
231 {
232 $operands = array();
233 if ( $operatorValue !== null )
234 $operands[] = $operatorValue;
235 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
236 {
237 $operand = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
238 if ( !is_object( $operand ) )
239 $operands[] = $operand;
240 }
241 $operatorValue = implode( '', $operands );
242 } break;
243 case $this->IndentName:
244 {
245 if( $namedParameters['indent_count'] < 0 )
246 {
247 eZDebug::writeError( 'The value of the "count" argument is negative, indent() will not be called' );
248 break;
249 }
250
251 $indentCount = $namedParameters['indent_count'];
252 $indentType = $namedParameters['indent_type'];
253 $filler = false;
254 switch ( $indentType )
255 {
256 case 'space':
257 default:
258 {
259 $filler = ' ';
260 } break;
261 case 'tab':
262 {
263 $filler = "\t";
264 } break;
265 case 'custom':
266 {
267 $filler = $namedParameters['indent_filler'];
268 } break;
269 }
270 $fillText = str_repeat( $filler, $indentCount );
271 $operatorValue = $fillText . str_replace( "\n", "\n" . $fillText, $operatorValue );
272 } break;
273 }
274 }
275
277 public $ConcatName;
278 public $Operators;
279 public $IndentName;
280 }
281
282 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\createConstantElement
static createConstantElement( $constant, $variablePlacement=false)
Definition: eztemplatenodetool.php:61
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZTemplateTextOperator
The class eZTemplateTextOperator does.
Definition: eztemplatetextoperator.php:18
eZTemplateTextOperator\concatTransformation
concatTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatetextoperator.php:187
eZTemplateTextOperator\__construct
__construct()
Definition: eztemplatetextoperator.php:19
eZTemplateTextOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatetextoperator.php:39
eZTemplateTextOperator\namedParameterList
namedParameterList()
Definition: eztemplatetextoperator.php:68
eZTemplateTextOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatetextoperator.php:60
eZTemplateTextOperator\indentTransformation
indentTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatetextoperator.php:81
eZTemplateTextOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztemplatetextoperator.php:225
eZTemplateTextOperator\$Operators
$Operators
Definition: eztemplatetextoperator.php:278
eZTemplateTextOperator\operatorList
operatorList()
Definition: eztemplatetextoperator.php:34
eZTemplateTextOperator\$ConcatName
$ConcatName
Definition: eztemplatetextoperator.php:277
eZTemplateTextOperator\$IndentName
$IndentName
Definition: eztemplatetextoperator.php:279
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.