Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatestringoperator.php
Go to the documentation of this file.
1 <?php
20 class eZTemplateStringOperator
21 {
22 public function __construct()
23 {
24 $this->Operators = array( 'upcase', 'downcase',
25 'count_words', 'count_chars',
26 'trim', 'break', 'wrap', 'shorten', 'pad',
27 'upfirst', 'upword',
28 'simplify', 'wash',
29 'chr', 'ord');
30 foreach ( $this->Operators as $operator )
31 {
32 $name = $operator . 'Name';
33 $name[0] = $name[0] & "\xdf";
34 $this->$name = $operator;
35 }
36
37 $this->phpMap = array ('upcase' => 'mb_strtoupper,strtoupper',
38 'downcase' => 'mb_strtolower,strtolower',
39 'break' => 'nl2br',
40 'count_chars' => 'mb_strlen,strlen');
41
42 $this->customMap = array ( 'count_words' => array( 'return' => 'int',
43 'code' => '$result = preg_match_all( "#(\w+)#", $staticValues[0], $dummy );'
44 ),
45 'chr' => array( 'return' => 'string',
46 'code' => '$codec = eZTextCodec::instance( "unicode", false );' . "\n" .
47 '$result = $codec->convertString( $staticValues[0] );'
48 ),
49 'ord' => array( 'return' => 'string',
50 'code' => '$codec = eZTextCodec::instance( false, "unicode" );' . "\n" .
51 '$result = $codec->convertString( $staticValues[0] );'
52 ),
53 'pad' => array( 'return' => 'string',
54 'code' => '$result = $paramCount == 2 ? str_pad( $staticValues[0], $staticValues[1] ) : str_pad ( $staticValues[0], $staticValues[1], $staticValues[2] );',
55 'code2' => '$result = str_pad( $staticValues[0], $staticValues[1] );',
56 'code3' => '$result = str_pad( $staticValues[0], $staticValues[1], $staticValues[2] );',
57 ),
58 'trim' => array( 'return' => 'string',
59 'code' => '$result = $paramCount == 1 ? trim( $staticValues[0] ) : trim ( $staticValues[0], $staticValues[1] );',
60 'code1' => '$result = trim( $staticValues[0] );',
61 'code2' => '$result = trim( $staticValues[0], $staticValues[1] );',
62 ),
63 'wrap' => array( 'return' => 'string',
64 'code1' => '$result = wordwrap( $staticValues[0] );',
65 'code2' => '$result = wordwrap( $staticValues[0], $staticValues[1] );',
66 'code3' => '$result = wordwrap( $staticValues[0], $staticValues[1], $staticValues[2] );',
67 'code4' => '$result = wordwrap( $staticValues[0], $staticValues[1], $staticValues[2], $staticValues[3] );',
68 ),
69 'simplify' => array( 'return' => 'string',
70 'code' => 'if ( $paramCount == 1 )
71 {
72 $replacer = " ";
73 }
74 else
75 {
76 $replacer = $staticValues[1];
77 }
78 $result = preg_replace( "/".$replacer."{2,}/", $replacer, $staticValues[0] );',
79 'code1' => '$result = preg_replace( "/ {2,}/", " ", $staticValues[0] );',
80 'code2' => '$result = preg_replace( "/".$staticValues[1]."{2,}/", $staticValues[1], $staticValues[0] );',
81 ),
82 'shorten' => array( 'return' => 'string',
83 'code' => '$length = 80; $seq = "..."; $trimType = "right";
84 if ( $paramCount > 1 )
85 {
86 $length = $staticValues[1];
87 }
88 if ( $paramCount > 2 )
89 {
90 $seq = $staticValues[2];
91 }
92 if ( $paramCount > 3 )
93 {
94 $trimType = $staticValues[3];
95 }
96 if ( $trimType === "middle" )
97 {
98 $appendedStrLen = $strlenFunc( $seq );
99 if ( $length > $appendedStrLen && ( $strlenFunc( $staticValues[0] ) > $length ) )
100 {
101 $operatorValueLength = $strlenFunc( $staticValues[0] );
102 $chop = $length - $appendedStrLen;
103 $middlePos = (int)($chop / 2);
104 $leftPartLength = $middlePos;
105 $rightPartLength = $chop - $middlePos;
106 $result = trim( $substrFunc( $staticValues[0], 0, $leftPartLength ) . $seq . $substrFunc( $staticValues[0], $operatorValueLength - $rightPartLength, $rightPartLength ) );
107 }
108 else
109 {
110 $result = $staticValues[0];
111 }
112 }
113 else // default: trim_type === "right"
114 {
115 $maxLength = $length - $strlenFunc( $seq );
116 if ( ( $strlenFunc( $staticValues[0] ) > $length ) && $strlenFunc( $staticValues[0] ) > $maxLength )
117 {
118 $result = trim( $substrFunc( $staticValues[0], 0, $maxLength) ) . $seq;
119 }
120 else
121 {
122 $result = $staticValues[0];
123 }
124 }'
125 ),
126 'upfirst' => array( 'return' => 'string',
127 'code' => '$i18nIni = eZINI::instance( \'i18n.ini\' );
128 $hasMBString = ( $i18nIni->variable( \'CharacterSettings\', \'MBStringExtension\' ) == \'enabled\' and
129 function_exists( "mb_strtoupper" ) and
130 function_exists( "mb_substr" ) and
131 function_exists( "mb_strlen" ) );
132
133 if ( $hasMBString )
134 {
135 $encoding = eZTextCodec::internalCharset();
136 $firstLetter = mb_strtoupper( mb_substr( $staticValues[0], 0, 1, $encoding ), $encoding );
137 $remainingText = mb_substr( $staticValues[0], 1, mb_strlen( $staticValues[0], $encoding ), $encoding );
138 $result = $firstLetter . $remainingText;
139 }
140 else
141 {
142 $result = ucfirst( $staticValues[0] );
143 }'
144 ),
145 'upword' => array( 'return' => 'string',
146 'code' => ' $i18nIni = eZINI::instance( \'i18n.ini\' );
147 $hasMBString = ( $i18nIni->variable( \'CharacterSettings\', \'MBStringExtension\' ) == \'enabled\' and
148 function_exists( "mb_strtoupper" ) and
149 function_exists( "mb_substr" ) and
150 function_exists( "mb_strlen" ) );
151
152 if ( $hasMBString )
153 {
154 $encoding = eZTextCodec::internalCharset();
155 $words = explode( " ", $staticValues[0] );
156 $newString = array();
157 foreach ( $words as $word )
158 {
159 $firstLetter = mb_strtoupper( mb_substr( $word, 0, 1, $encoding ), $encoding );
160 $remainingText = mb_substr( $word, 1, mb_strlen( $word, $encoding ), $encoding );
161 $newString[] = $firstLetter . $remainingText;
162 }
163 $result = implode( " ", $newString );
164 unset( $newString, $words );
165 }
166 else
167 {
168 $result = ucwords( $staticValues[0] );
169 }'
170 )
171
172 );
173 }
174
178 function operatorList()
179 {
180 return $this->Operators;
181 }
182
183 function operatorTemplateHints()
184 {
185 $hints = array(
186 $this->BreakName => array( 'parameters' => false, 'element-transformation-func' => 'phpMapTransformation' ),
187 $this->Count_charsName => array( 'parameters' => false, 'element-transformation-func' => 'phpMapTransformation' ),
188 $this->DowncaseName => array( 'parameters' => false, 'element-transformation-func' => 'phpMapTransformation' ),
189 $this->UpcaseName => array( 'parameters' => false, 'element-transformation-func' => 'phpMapTransformation' ),
190 $this->UpfirstName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
191 $this->UpwordName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
192
193 $this->Count_wordsName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
194 $this->ChrName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
195 $this->OrdName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
196 $this->PadName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
197 $this->ShortenName => array( 'parameters' => 3 , 'element-transformation-func' => 'customMapTransformation' ),
198 $this->SimplifyName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
199 $this->TrimName => array( 'parameters' => 1 , 'element-transformation-func' => 'customMapTransformation' ),
200 $this->WrapName => array( 'parameters' => false, 'element-transformation-func' => 'customMapTransformation' ),
201
202 $this->WashName => array( 'parameters' => 1, 'element-transformation-func' => 'washTransformation' ),
203 );
204
205 foreach ( $this->Operators as $operator )
206 {
207 $hints[$operator]['input'] = true;
208 $hints[$operator]['output'] = true;
209 $hints[$operator]['element-transformation'] = true;
210 $hints[$operator]['transform-parameters'] = true;
211 if ( !isset( $hints[$operator]['input-as-parameter'] ) )
212 $hints[$operator]['input-as-parameter'] = 'always';
213 }
214 return $hints;
215 }
216
220 function namedParameterPerOperator()
221 {
222 return true;
223 }
224
228 function namedParameterList()
229 {
230 return array( $this->TrimName => array( 'chars_to_remove' => array( "type" => "string",
231 "required" => false,
232 "default" => false ) ),
233 $this->WrapName => array( 'wrap_at_position' => array( "type" => "integer",
234 "required" => false,
235 "default" => false ),
236 'break_sequence' => array( "type" => "string",
237 "required" => false,
238 "default" => false ),
239 'cut' => array( "type" => "boolean",
240 "required" => false,
241 "default" => false ) ),
242 $this->WashName => array( 'type' => array( "type" => "string",
243 "required" => false,
244 "default" => "xhtml" ) ),
245 $this->ShortenName => array( 'chars_to_keep' => array( "type" => "integer",
246 "required" => false,
247 "default" => 80 ),
248 'str_to_append' => array( "type" => "string",
249 "required" => false,
250 "default" => "..." ),
251 'trim_type' => array( "type" => "string",
252 "required" => false,
253 "default" => "right" ) ),
254 $this->PadName => array( 'desired_length' => array( "type" => "integer",
255 "required" => false,
256 "default" => 80 ),
257 'pad_sequence' => array( "type" => "string",
258 "required" => false,
259 "default" => " " ) ),
260 $this->SimplifyName => array ( 'char' => array( "type" => "string",
261 "required" => false,
262 "default" => false ) ) );
263 }
264
265 function phpMapTransformation( $operatorName, $node, $tpl, $resourceData,
266 $element, $lastElement, $elementList, $elementTree, &$parameters )
267 {
268 $values = array();
269 $phpFunctionList = explode( ',', $this->phpMap[$operatorName] );
270 foreach ( $phpFunctionList as $element )
271 {
272 if ( function_exists( $element ) )
273 {
274 $phpFunction = $element;
275 break;
276 }
277 }
278 $newElements = array();
279
280 if ( count ( $parameters ) != 1 )
281 {
282 return false;
283 }
284
285 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
286 {
287 $text = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
288 $text = $phpFunction( $text );
289 $text = str_replace( array( "'" ), array( "\\'" ), $text );
290 $code = "%output% = '" . $text . "' ;\n";
291 }
292 else
293 {
294 $values[] = $parameters[0];
295 $code = "%output% = $phpFunction( %1% );\n";
296 }
297
298 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
299 return $newElements;
300 }
301
302 function customMapTransformation( $operatorName, $node, $tpl, $resourceData,
303 $element, $lastElement, $elementList, $elementTree, &$parameters )
304 {
305 $values = array();
306 $newElements = array();
307 $mapEntry = $this->customMap[$operatorName];
308 $paramCount = count( $parameters );
309 $strlenFunc = 'strlen';
310 $substrFunc = 'substr';
311 $code = "\$strlenFunc = 'strlen'; \$substrFunc = 'substr';\n";
312 if ( function_exists( 'mb_strlen' ) )
313 {
314 $strlenFunc = 'mb_strlen';
315 $substrFunc = 'mb_substr';
316 $code = "\$strlenFunc = 'mb_strlen'; \$substrFunc = 'mb_substr';\n";
317 }
318
319 if ( $paramCount < 1 )
320 {
321 return false;
322 }
323
324 $allStatic = true;
325 $staticValues = array();
326 $replaceMap = array('$result');
327 $replacementMap = array('%output%');
328 for ($i = 0; $i < $paramCount; $i++)
329 {
330 if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
331 {
332 $staticValues[$i] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
333 }
334 else
335 {
336 $allStatic = false;
337 }
338 }
339
340 if ( $allStatic )
341 {
342 $result = false;
343 if ( isset( $mapEntry['code'. $paramCount] ) )
344 {
345 eval( $mapEntry['code' . $paramCount] );
346 }
347 else
348 {
349 eval( $mapEntry['code'] );
350 }
351 return array( eZTemplateNodeTool::createConstantElement( $result ) );
352 }
353 else
354 {
355 $replaceMap = array( '$result', '$paramCount' );
356 $replacementMap = array( '%output%', $paramCount );
357 for ( $i = 0; $i < $paramCount; $i++ )
358 {
359 $values[] = $parameters[$i];
360 $replaceMap[] = "\$staticValues[$i]";
361 $replacementMap[] = '%' . ( $i + 1 ) . '%';
362 }
363 if ( isset( $mapEntry['code'. $paramCount] ) )
364 {
365 $code .= str_replace( $replaceMap, $replacementMap, $mapEntry['code' . $paramCount] ) . "\n";
366 }
367 else
368 {
369 $code .= str_replace( $replaceMap, $replacementMap, $mapEntry['code'] ) . "\n";
370 }
371 }
372
373 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
374 return $newElements;
375 }
376
380 function wash( $operatorValue, $tpl, $type = 'xhtml' )
381 {
382 switch ( $type )
383 {
384 case "xhtml":
385 {
386 $operatorValue = htmlspecialchars( (string) $operatorValue );
387 } break;
388
389 case "email":
390 {
391 $ini = $tpl->ini();
392 $dotText = $ini->variable( 'WashSettings', 'EmailDotText' );
393 $atText = $ini->variable( 'WashSettings', 'EmailAtText' );
394 $operatorValue = str_replace(
395 array( '.', '@' ),
396 array( $dotText, $atText ),
397 htmlspecialchars( $operatorValue )
398 );
399 } break;
400
401 case 'pdf':
402 {
403 $operatorValue = str_replace( array( ' ', // use default callback functions in ezpdf library
404 "\r\n",
405 "\t" ),
406 array( '<C:callSpace>',
407 '<C:callNewLine>',
408 '<C:callTab>' ),
409 $operatorValue );
410 $operatorValue = str_replace( "\n", '<C:callNewLine>', $operatorValue );
411 } break;
412
413 case 'javascript':
414 {
415 $operatorValue = str_replace( array( "\\", "\"", "'"),
416 array( "\\\\", "\\042", "\\047" ) , $operatorValue );
417 } break;
418 }
419 return $operatorValue;
420 }
421
422 function washTransformation( $operatorName, $node, $tpl, $resourceData,
423 $element, $lastElement, $elementList, $elementTree, &$parameters )
424 {
425 $values = array();
426 $tmpVarCount = 0;
427 $newElements = array();
428 $paramCount = count( $parameters );
429
430 if ( $paramCount > 2 )
431 {
432 return false;
433 }
434
435 $allStatic = true;
436 $staticValues = array();
437 for ($i = 0; $i < $paramCount; $i++)
438 {
439 if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
440 {
441 $staticValues[$i] = eZTemplateNodeTool::elementConstantValue( $parameters[$i] );
442 }
443 else
444 {
445 $allStatic = false;
446 }
447 }
448
449 /* Do optimalizations for 'xhtml' case */
450 if ( $allStatic ) {
451 if ( $paramCount == 1 )
452 {
453 $type = 'xhtml';
454 }
455 else
456 {
457 $type = $staticValues[1];
458 }
459 $code = "%output% = '" . addcslashes( $this->wash( $staticValues[0], $tpl, $type ), "'\\" ) . "' ;\n";
460 }
461 /* XHTML: Type is static, input is not */
462 else if ( ( $paramCount == 1 ) || ( ( $paramCount == 2 ) && isset( $staticValues[1] ) && ( $staticValues[1] == 'xhtml' ) ) )
463 {
464 $values[] = $parameters[0];
465 $code = "%output% = htmlspecialchars( (string) %1% );\n";
466 }
467 /* PDF: Type is static, input is not static */
468 else if ( ( $paramCount == 2 ) && isset( $staticValues[1] ) && ( $staticValues[1] == 'pdf' ) )
469 {
470 $values[] = $parameters[0];
471 $tmpVarCount = 1;
472 $code = '%tmp1% = str_replace( array( " ", "\r\n", "\t" ), array( "<C:callSpace>", "<C:callNewLine>", "<C:callTab>" ), %1% );'. "\n";
473 $code .= '%output% = str_replace( "\n", "<C:callNewLine>", %tmp1% );'."\n";
474 }
475 /* MAIL: Type is static, input is not static */
476 else if ( ( $paramCount == 2 ) && isset( $staticValues[1] ) && ( $staticValues[1] == 'email' ) )
477 {
478 $ini = $tpl->ini();
479 $dotText = addcslashes( $ini->variable( 'WashSettings', 'EmailDotText' ), "'" );
480 $atText = addcslashes( $ini->variable( 'WashSettings', 'EmailAtText' ), "'" );
481
482 $values[] = $parameters[0];
483 $code = "%output% = str_replace( array( '.', '@' ), array( '$dotText', '$atText' ), htmlspecialchars( %1% ) );\n";
484 }
485 /* JAVASCRIPT: Type is static, input is not static */
486 else if ( ( $paramCount == 2 ) && isset( $staticValues[1] ) && ( $staticValues[1] == 'javascript' ) )
487 {
488 $values[] = $parameters[0];
489 $code = '%output% = str_replace( array( "\\\\", "\"", "\'" ),
490 array( "\\\\\\\\", "\\\\042", "\\\\047" ) , %1% ); ';
491
492
493
494 }
495 else /* No compiling for the rest cases */
496 {
497 return false;
498 }
499
500 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpVarCount );
501 return $newElements;
502 }
503
504 /*
505 The modify function takes care of the various operations.
506 */
507 function modify( $tpl,
508 $operatorName,
509 $operatorParameters,
510 $rootNamespace,
511 $currentNamespace,
512 &$operatorValue,
513 $namedParameters,
514 $placement )
515 {
516 switch ( $operatorName )
517 {
518 // Convert all alphabetical chars of operatorvalue to uppercase.
519 case $this->UpcaseName:
520 {
521 $funcName = function_exists( 'mb_strtoupper' ) ? 'mb_strtoupper' : 'strtoupper';
522 $operatorValue = $funcName( $operatorValue );
523 } break;
524
525 // Convert all alphabetical chars of operatorvalue to lowercase.
526 case $this->DowncaseName:
527 {
528 $funcName = function_exists( 'mb_strtolower' ) ? 'mb_strtolower' : 'strtolower';
529 $operatorValue = $funcName( $operatorValue );
530 } break;
531
532 // Count and return the number of words in operatorvalue.
533 case $this->Count_wordsName:
534 {
535 $operatorValue = preg_match_all( "#(\w+)#", $operatorValue, $dummy_match );
536 }break;
537
538 // Count and return the number of chars in operatorvalue.
539 case $this->Count_charsName:
540 {
541 $funcName = function_exists( 'mb_strlen' ) ? 'mb_strlen' : 'strlen';
542 $operatorValue = $funcName( (string) $operatorValue );
543 }break;
544
545 // Insert HTML line breaks before newlines.
546 case $this->BreakName:
547 {
548 $operatorValue = nl2br( $operatorValue );
549 }break;
550
551 // Wrap line (insert newlines).
552 case $this->WrapName:
553 {
554 $parameters = array( $operatorValue );
555 if ( $namedParameters['wrap_at_position'] )
556 {
557 $parameters[] = $namedParameters['wrap_at_position'];
558 if ( $namedParameters['break_sequence'] )
559 {
560 $parameters[] = $namedParameters['break_sequence'];
561 if ( $namedParameters['cut'] )
562 {
563 $parameters[] = $namedParameters['cut'];
564 }
565 }
566 }
567 $operatorValue = call_user_func_array( 'wordwrap', $parameters );
568 }break;
569
570 // Convert the first character to uppercase.
571 case $this->UpfirstName:
572 {
573 $i18nIni = eZINI::instance( 'i18n.ini' );
574 $hasMBString = ( $i18nIni->variable( 'CharacterSettings', 'MBStringExtension' ) == 'enabled' and
575 function_exists( "mb_strtoupper" ) and
576 function_exists( "mb_substr" ) and
577 function_exists( "mb_strlen" ) );
578
579 if ( $hasMBString )
580 {
581 $encoding = eZTextCodec::internalCharset();
582 $firstLetter = mb_strtoupper( mb_substr( $operatorValue, 0, 1, $encoding ), $encoding );
583 $remainingText = mb_substr( $operatorValue, 1, mb_strlen( $operatorValue, $encoding ), $encoding );
584 $operatorValue = $firstLetter . $remainingText;
585 }
586 else
587 {
588 $operatorValue = ucfirst( $operatorValue );
589 }
590
591 }break;
592
593 // Simplify / transform multiple consecutive characters into one.
594 case $this->SimplifyName:
595 {
596 $simplifyCharacter = $namedParameters['char'];
597 if ( $namedParameters['char'] === false )
598 {
599 $replace_this = "/ {2,}/";
600 $simplifyCharacter = ' ';
601 }
602 else
603 {
604 $replace_this = "/". $simplifyCharacter ."{2,}/";
605 }
606 $operatorValue = preg_replace( $replace_this, $simplifyCharacter, $operatorValue );
607 }break;
608 // Convert all first characters [in all words] to uppercase.
609 case $this->UpwordName:
610 {
611 $i18nIni = eZINI::instance( 'i18n.ini' );
612 $hasMBString = ( $i18nIni->variable( 'CharacterSettings', 'MBStringExtension' ) == 'enabled' and
613 function_exists( "mb_strtoupper" ) and
614 function_exists( "mb_substr" ) and
615 function_exists( "mb_strlen" ) );
616
617 if ( $hasMBString )
618 {
619 $encoding = eZTextCodec::internalCharset();
620 $words = explode( " ", $operatorValue );
621 $newString = array();
622 foreach ( $words as $word )
623 {
624 $firstLetter = mb_strtoupper( mb_substr( $word, 0, 1, $encoding ), $encoding );
625 $remainingText = mb_substr( $word, 1, mb_strlen( $word, $encoding ), $encoding );
626 $newString[]= $firstLetter . $remainingText;
627 }
628 $operatorValue = implode( " ", $newString );
629 unset( $newString, $words );
630 }
631 else
632 {
633 $operatorValue = ucwords( $operatorValue );
634 }
635 }break;
636
637 // Strip whitespace from the beginning and end of a string.
638 case $this->TrimName:
639 {
640 if ( $namedParameters['chars_to_remove'] === false )
641 $operatorValue = trim( (string) $operatorValue );
642 else
643 $operatorValue = trim( (string) $operatorValue, $namedParameters['chars_to_remove'] );
644 }break;
645
646 // Pad...
647 case $this->PadName:
648 {
649 if (strlen( $operatorValue ) < $namedParameters['desired_length'])
650 {
651 $operatorValue = str_pad( $operatorValue,
652 $namedParameters['desired_length'],
653 $namedParameters['pad_sequence'] );
654 }
655 }break;
656
657 // Shorten string [default or specified length, length=text+"..."] and add '...'
658 case $this->ShortenName:
659 {
660 $strlenFunc = function_exists( 'mb_strlen' ) ? 'mb_strlen' : 'strlen';
661 $substrFunc = function_exists( 'mb_substr' ) ? 'mb_substr' : 'substr';
662 if ( $strlenFunc( $operatorValue ) > $namedParameters['chars_to_keep'] )
663 {
664 $operatorLength = $strlenFunc( $operatorValue );
665
666 if ( $namedParameters['trim_type'] === 'middle' )
667 {
668 $appendedStrLen = $strlenFunc( $namedParameters['str_to_append'] );
669
670 if ( $namedParameters['chars_to_keep'] > $appendedStrLen )
671 {
672 $chop = $namedParameters['chars_to_keep'] - $appendedStrLen;
673
674 $middlePos = (int)($chop / 2);
675 $leftPartLength = $middlePos;
676 $rightPartLength = $chop - $middlePos;
677
678 $operatorValue = trim( $substrFunc( $operatorValue, 0, $leftPartLength ) . $namedParameters['str_to_append'] . $substrFunc( $operatorValue, $operatorLength - $rightPartLength, $rightPartLength ) );
679 }
680 else
681 {
682 $operatorValue = $namedParameters['str_to_append'];
683 }
684 }
685 else // default: trim_type === 'right'
686 {
687 $chop = $namedParameters['chars_to_keep'] - $strlenFunc( $namedParameters['str_to_append'] );
688 $operatorValue = $substrFunc( $operatorValue, 0, $chop );
689 $operatorValue = trim( $operatorValue );
690 if ( $operatorLength > $chop )
691 $operatorValue = $operatorValue.$namedParameters['str_to_append'];
692 }
693 }
694 }break;
695
696 // Wash (translate strings to non-spammable text):
697 case $this->WashName:
698 {
699 $type = $namedParameters['type'];
700 $operatorValue = $this->wash( $operatorValue, $tpl, $type );
701 }break;
702
703 // Ord (translate a unicode string to actual unicode id/numbers):
704 case $this->OrdName:
705 {
706 $codec = eZTextCodec::instance( false, 'unicode' );
707 $output = $codec->convertString( $operatorValue );
708 $operatorValue = $output;
709 }break;
710
711 // Chr (generate unicode characters based on input):
712 case $this->ChrName:
713 {
714 $codec = eZTextCodec::instance( 'unicode', false );
715 $output = $codec->convertString( $operatorValue );
716 $operatorValue = $output;
717 }break;
718
719 // Default case: something went wrong - unknown things...
720 default:
721 {
722 if ( !isset( $type ) )
723 $type = '';
724 $tpl->warning( $operatorName, "Unknown string type '$type'", $placement );
725 } break;
726 }
727 }
728
730 public $Operators;
731 public $UpcaseName;
732 public $DowncaseName;
733 public $Count_wordsName;
734 public $Count_charsName;
735 public $TrimName;
736 public $BreakName;
737 public $WrapName;
738 public $ShortenName;
739 public $PadName;
740 public $UpfirstName;
741 public $UpwordName;
742 public $SimplifyName;
743 public $WashName;
744 public $ChrName;
745 public $OrdName;
746 public $phpMap;
747 public $customMap;
748 }
749
750 ?>
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
eZTemplateStringOperator
Definition: eztemplatestringoperator.php:21
eZTemplateStringOperator\$ShortenName
$ShortenName
Definition: eztemplatestringoperator.php:738
eZTemplateStringOperator\$SimplifyName
$SimplifyName
Definition: eztemplatestringoperator.php:742
eZTemplateStringOperator\$customMap
$customMap
Definition: eztemplatestringoperator.php:747
eZTemplateStringOperator\namedParameterList
namedParameterList()
Definition: eztemplatestringoperator.php:228
eZTemplateStringOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztemplatestringoperator.php:507
eZTemplateStringOperator\$Count_wordsName
$Count_wordsName
Definition: eztemplatestringoperator.php:733
eZTemplateStringOperator\wash
wash( $operatorValue, $tpl, $type='xhtml')
Definition: eztemplatestringoperator.php:380
eZTemplateStringOperator\$WashName
$WashName
Definition: eztemplatestringoperator.php:743
eZTemplateStringOperator\$UpwordName
$UpwordName
Definition: eztemplatestringoperator.php:741
eZTemplateStringOperator\customMapTransformation
customMapTransformation( $operatorName, $node, $tpl, $resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatestringoperator.php:302
eZTemplateStringOperator\$DowncaseName
$DowncaseName
Definition: eztemplatestringoperator.php:732
eZTemplateStringOperator\$OrdName
$OrdName
Definition: eztemplatestringoperator.php:745
eZTemplateStringOperator\$ChrName
$ChrName
Definition: eztemplatestringoperator.php:744
eZTemplateStringOperator\$BreakName
$BreakName
Definition: eztemplatestringoperator.php:736
eZTemplateStringOperator\$UpcaseName
$UpcaseName
Definition: eztemplatestringoperator.php:731
eZTemplateStringOperator\__construct
__construct()
Definition: eztemplatestringoperator.php:22
eZTemplateStringOperator\$TrimName
$TrimName
Definition: eztemplatestringoperator.php:735
eZTemplateStringOperator\operatorList
operatorList()
Definition: eztemplatestringoperator.php:178
eZTemplateStringOperator\$Operators
$Operators
The array of operators, used for registering operators.
Definition: eztemplatestringoperator.php:730
eZTemplateStringOperator\$WrapName
$WrapName
Definition: eztemplatestringoperator.php:737
eZTemplateStringOperator\$PadName
$PadName
Definition: eztemplatestringoperator.php:739
eZTemplateStringOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatestringoperator.php:183
eZTemplateStringOperator\$phpMap
$phpMap
Definition: eztemplatestringoperator.php:746
eZTemplateStringOperator\$Count_charsName
$Count_charsName
Definition: eztemplatestringoperator.php:734
eZTemplateStringOperator\$UpfirstName
$UpfirstName
Definition: eztemplatestringoperator.php:740
eZTemplateStringOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatestringoperator.php:220
eZTemplateStringOperator\washTransformation
washTransformation( $operatorName, $node, $tpl, $resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatestringoperator.php:422
eZTemplateStringOperator\phpMapTransformation
phpMapTransformation( $operatorName, $node, $tpl, $resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatestringoperator.php:265
eZTextCodec\internalCharset
static internalCharset()
Definition: eztextcodec.php:546
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.