|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZTemplateArrayOperator class 00004 // 00005 // Created on: <05-Mar-2002 12:52:10 amos> 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 /*! 00032 \class eZTemplateArrayOperator eztemplatearrayoperator.php 00033 \ingroup eZTemplateOperators 00034 \brief Dynamic creation of arrays using operator "array" 00035 00036 Creates an operator which can create arrays dynamically by 00037 adding all operator parameters as array elements. 00038 00039 \code 00040 // Example template code 00041 {array(1,"test")} 00042 {array(array(1,2),3)} 00043 \endcode 00044 00045 */ 00046 00047 //include_once( "lib/eztemplate/classes/eztemplate.php" ); 00048 00049 class eZTemplateArrayOperator 00050 { 00051 /*! 00052 Initializes the array operator with the operator name $name. 00053 */ 00054 function eZTemplateArrayOperator( $arrayName = 'array', 00055 $hashName = 'hash', 00056 $arrayPrependName = 'array_prepend', // DEPRECATED/OBSOLETE 00057 $prependName = 'prepend', // New, replaces array_prepend. 00058 $arrayAppendName = 'array_append', // DEPRECATED/OBSOLETE 00059 $appendName = 'append', // New, replaces array_append. 00060 $arrayMergeName = 'array_merge', // DEPRECATED/OBSOLETE 00061 $mergeName = 'merge', // New, replaces array_merge. 00062 $containsName = 'contains', 00063 $compareName = 'compare', 00064 $extractName = 'extract', 00065 $extractLeftName = 'extract_left', 00066 $extractRightName = 'extract_right', 00067 $beginsWithName = 'begins_with', 00068 $endsWithName = 'ends_with', 00069 $implodeName = 'implode', 00070 $explodeName = 'explode', 00071 $repeatName = 'repeat', 00072 $reverseName = 'reverse', 00073 $insertName = 'insert', 00074 $removeName = 'remove', 00075 $replaceName = 'replace', 00076 $uniqueName = 'unique', 00077 $arraySumName = 'array_sum' ) 00078 { 00079 $this->ArrayName = $arrayName; 00080 $this->HashName = $hashName; 00081 $this->ArrayPrependName = $arrayPrependName; // DEPRECATED/OBSOLETE 00082 $this->PrependName = $prependName; // New, replaces ArrayPrependName. 00083 $this->ArrayAppendName = $arrayAppendName; // DEPRECATED/OBSOLETE 00084 $this->AppendName = $appendName; // New, replaces ArrayAppendName. 00085 $this->ArrayMergeName = $arrayMergeName; // DEPRECATED/OBSOLETE 00086 $this->MergeName = $mergeName; // New, replaces ArrayMergeName. 00087 $this->ContainsName = $containsName; 00088 $this->CompareName = $compareName; 00089 $this->ExtractName = $extractName; 00090 $this->ExtractLeftName = $extractLeftName; 00091 $this->ExtractRightName = $extractRightName; 00092 $this->BeginsWithName = $beginsWithName; 00093 $this->EndsWithName = $endsWithName; 00094 $this->ImplodeName = $implodeName; 00095 $this->ExplodeName = $explodeName; 00096 $this->RepeatName = $repeatName; 00097 $this->ReverseName = $reverseName; 00098 $this->InsertName = $insertName; 00099 $this->RemoveName = $removeName; 00100 $this->ReplaceName = $replaceName; 00101 $this->UniqueName = $uniqueName; 00102 $this->ArraySumName = $arraySumName; 00103 00104 $this->Operators = array( $arrayName, 00105 $hashName, 00106 $arrayPrependName, // DEPRECATED/OBSOLETE 00107 $prependName, // New, replaces arrayPrependName. 00108 $arrayAppendName, // DEPRECATED/OBSOLETE 00109 $appendName, // New, replaces arrayAppendName. 00110 $arrayMergeName, // DEPRECATED/OBSOLETE 00111 $mergeName, // New, replaces arrayMergeName. 00112 $containsName, 00113 $compareName, 00114 $extractName, 00115 $extractLeftName, 00116 $extractRightName, 00117 $beginsWithName, 00118 $endsWithName, 00119 $implodeName, 00120 $explodeName, 00121 $repeatName, 00122 $reverseName, 00123 $insertName, 00124 $removeName, 00125 $replaceName, 00126 $uniqueName, 00127 $arraySumName ); 00128 } 00129 00130 /*! 00131 Returns the operators in this class. 00132 */ 00133 function operatorList() 00134 { 00135 return $this->Operators; 00136 } 00137 00138 function operatorTemplateHints() 00139 { 00140 return array( $this->ArrayName => array( 'input' => true, 00141 'output' => true, 00142 'parameters' => true, 00143 'element-transformation' => true, 00144 'transform-parameters' => true, 00145 'element-transformation-func' => 'arrayTrans' ), 00146 $this->HashName => array( 'input' => true, 00147 'output' => true, 00148 'parameters' => true, 00149 'element-transformation' => true, 00150 'transform-parameters' => true, 00151 'element-transformation-func' => 'arrayTrans'), 00152 $this->ArrayPrependName => array( 'input' => true, 00153 'output' => true, 00154 'parameters' => true, 00155 'element-transformation' => true, 00156 'transform-parameters' => true, 00157 'input-as-parameter' => 'always', 00158 'element-transformation-func' => 'mergeTrans' ), 00159 $this->PrependName => array( 'input' => true, 00160 'output' => true, 00161 'parameters' => true, 00162 'element-transformation' => true, 00163 'transform-parameters' => true, 00164 'input-as-parameter' => 'always', 00165 'element-transformation-func' => 'mergeTrans' ), 00166 $this->ArrayAppendName => array( 'input' => true, 00167 'output' => true, 00168 'parameters' => true, 00169 'element-transformation' => true, 00170 'transform-parameters' => true, 00171 'input-as-parameter' => 'always', 00172 'element-transformation-func' => 'mergeTrans' ), 00173 $this->AppendName => array( 'input' => true, 00174 'output' => true, 00175 'parameters' => true, 00176 'element-transformation' => true, 00177 'transform-parameters' => true, 00178 'input-as-parameter' => 'always', 00179 'element-transformation-func' => 'mergeTrans' ), 00180 $this->ArrayMergeName => array( 'input' => true, 00181 'output' => true, 00182 'parameters' => true, 00183 'element-transformation' => true, 00184 'transform-parameters' => true, 00185 'input-as-parameter' => 'always', 00186 'element-transformation-func' => 'mergeTrans' ), 00187 $this->MergeName => array( 'input' => true, 00188 'output' => true, 00189 'parameters' => true, 00190 'element-transformation' => true, 00191 'transform-parameters' => true, 00192 'input-as-parameter' => 'always', 00193 'element-transformation-func' => 'mergeTrans' ), 00194 $this->ContainsName => array( 'input' => true, 00195 'output' => true, 00196 'parameters' => 1, 00197 'element-transformation' => true, 00198 'transform-parameters' => true, 00199 'input-as-parameter' => 'always', 00200 'element-transformation-func' => 'arrayTrans'), 00201 $this->CompareName => array( 'input' => true, 00202 'output' => true, 00203 'parameters' => 1, 00204 'element-transformation' => true, 00205 'transform-parameters' => true, 00206 'input-as-parameter' => 'always', 00207 'element-transformation-func' => 'arrayTrans'), 00208 $this->ExtractName => array( 'input' => true, 00209 'output' => true, 00210 'parameters' => 2, 00211 'element-transformation' => true, 00212 'transform-parameters' => true, 00213 'input-as-parameter' => 'always', 00214 'element-transformation-func' => 'extractTrans'), 00215 $this->ExtractLeftName => array( 'input' => true, 00216 'output' => true, 00217 'parameters' => 1, 00218 'element-transformation' => true, 00219 'transform-parameters' => true, 00220 'input-as-parameter' => 'always', 00221 'element-transformation-func' => 'extractTrans'), 00222 $this->ExtractRightName => array( 'input' => true, 00223 'output' => true, 00224 'parameters' => 1, 00225 'element-transformation' => true, 00226 'transform-parameters' => true, 00227 'input-as-parameter' => 'always', 00228 'element-transformation-func' => 'extractTrans'), 00229 $this->BeginsWithName => array( 'input' => true, 00230 'output' => true, 00231 'parameters' => true, 00232 'element-transformation' => true, 00233 'transform-parameters' => true, 00234 'input-as-parameter' => 'always', 00235 'element-transformation-func' => 'compareTrans'), 00236 $this->EndsWithName => array( 'input' => true, 00237 'output' => true, 00238 'parameters' => true, 00239 'element-transformation' => true, 00240 'transform-parameters' => true, 00241 'input-as-parameter' => 'always', 00242 'element-transformation-func' => 'compareTrans'), 00243 $this->ImplodeName => array( 'input' => true, 00244 'output' => true, 00245 'parameters' => 1, 00246 'element-transformation' => true, 00247 'transform-parameters' => true, 00248 'input-as-parameter' => 'always', 00249 'element-transformation-func' => 'arrayTrans'), 00250 $this->ExplodeName => array( 'input' => true, 00251 'output' => true, 00252 'parameters' => 1, 00253 'element-transformation' => true, 00254 'transform-parameters' => true, 00255 'input-as-parameter' => 'always', 00256 'element-transformation-func' => 'arrayTrans'), 00257 $this->RepeatName => array( 'input' => true, 00258 'output' => true, 00259 'parameters' => 1, 00260 'element-transformation' => true, 00261 'transform-parameters' => true, 00262 'input-as-parameter' => 'always', 00263 'element-transformation-func' => 'arrayTrans'), 00264 $this->ReverseName => array( 'input' => true, 00265 'output' => true, 00266 'parameters' => false, 00267 'element-transformation' => true, 00268 'transform-parameters' => true, 00269 'input-as-parameter' => 'always', 00270 'element-transformation-func' => 'arrayTrans' ), 00271 $this->InsertName => array( 'input' => true, 00272 'output' => true, 00273 'parameters' => true, 00274 'element-transformation' => true, 00275 'transform-parameters' => true, 00276 'input-as-parameter' => 'always', 00277 'element-transformation-func' => 'arrayTrans' ), 00278 $this->RemoveName => array( 'input' => true, 00279 'output' => true, 00280 'parameters' => 2, 00281 'element-transformation' => true, 00282 'transform-parameters' => true, 00283 'input-as-parameter' => 'always', 00284 'element-transformation-func' => 'arrayTrans'), 00285 $this->ReplaceName => array( 'input' => true, 00286 'output' => true, 00287 'parameters' => true ), 00288 $this->UniqueName => array( 'input' => true, 00289 'output' => true, 00290 'parameters' => false, 00291 'element-transformation' => true, 00292 'transform-parameters' => true, 00293 'input-as-parameter' => 'always', 00294 'element-transformation-func' => 'arrayTrans'), 00295 $this->ArraySumName => array( 'input' => true, 00296 'output' => true, 00297 'parameters' => false, 00298 'element-transformation' => true, 00299 'transform-parameters' => true, 00300 'input-as-parameter' => 'always', 00301 'element-transformation-func' => 'arrayTrans' ) ); 00302 } 00303 00304 /*! 00305 \reimp 00306 */ 00307 function arrayTrans( $operatorName, &$node, $tpl, &$resourceData, 00308 $element, $lastElement, $elementList, $elementTree, &$parameters ) 00309 { 00310 switch( $operatorName ) 00311 { 00312 case $this->ArrayName: 00313 { 00314 $code = ''; 00315 $paramCount = 0; 00316 $values = array(); 00317 $staticArray = array(); 00318 for ( $i = 0; $i < count( $parameters ); ++$i ) 00319 { 00320 if ( $i != 0 ) 00321 { 00322 $code .= ', '; 00323 } 00324 else 00325 { 00326 $code .= '%output% = array( '; 00327 } 00328 00329 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 00330 { 00331 $values[] = $parameters[$i]; 00332 ++$paramCount; 00333 $code .= '%' . $paramCount . '%'; 00334 } 00335 else 00336 { 00337 if ( $paramCount == 0 ) 00338 { 00339 $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 00340 } 00341 00342 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 00343 } 00344 } 00345 00346 if ( $paramCount == 0 ) 00347 { 00348 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) ); 00349 } 00350 00351 $code .= ' );'; 00352 00353 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00354 } break; 00355 00356 case $this->HashName: 00357 { 00358 $code = ''; 00359 $paramCount = 0; 00360 $values = array(); 00361 $staticArray = array(); 00362 $staticKeys = true; 00363 $keys = array(); 00364 $vals = array(); 00365 $hashCount = (int)( count( $parameters ) / 2 ); 00366 for ( $i = 0; $i < $hashCount; ++$i ) 00367 { 00368 if ( $i != 0 ) 00369 { 00370 $code .= ', '; 00371 } 00372 else 00373 { 00374 $code .= '%output% = array( '; 00375 } 00376 00377 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i*2] ) ) 00378 { 00379 $staticKeys = false; 00380 $values[] = $parameters[$i*2]; 00381 ++$paramCount; 00382 $code .= '%' . $paramCount . '%'; 00383 } 00384 else 00385 { 00386 $keys[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ); 00387 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ), 0, 0, false ); 00388 } 00389 00390 $code .= ' => '; 00391 00392 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i*2+1] ) ) 00393 { 00394 $values[] = $parameters[$i*2 + 1]; 00395 ++$paramCount; 00396 $code .= '%' . $paramCount . '%'; 00397 } 00398 else 00399 { 00400 if ( $paramCount == 0 ) 00401 { 00402 $staticArray[ eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ) ] = eZTemplateNodeTool::elementStaticValue( $parameters[$i*2+1] ); 00403 } 00404 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i*2+1] ), 0, 0, false ); 00405 } 00406 00407 if ( $staticKeys ) 00408 { 00409 $vals[$keys[count( $keys ) - 1]] = $parameters[$i*2 + 1]; 00410 } 00411 } 00412 00413 if ( $paramCount == 0 ) 00414 { 00415 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) ); 00416 } 00417 00418 if ( $staticKeys ) 00419 { 00420 return array( eZTemplateNodeTool::createDynamicArrayElement( $keys, $vals ) ); 00421 } 00422 00423 $code .= ' );'; 00424 00425 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00426 } break; 00427 00428 case $this->ContainsName: 00429 { 00430 $values = array(); 00431 $inParam = null; 00432 $isString = false; 00433 $isArray = false; 00434 00435 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00436 { 00437 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 00438 if ( is_string( $inParam ) ) 00439 { 00440 $isString = true; 00441 } 00442 else if( is_array( $inParam ) ) 00443 { 00444 $isArray = true; 00445 } 00446 00447 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 00448 } 00449 else 00450 { 00451 $values[] = $parameters[0]; 00452 $inParamCode = '%' . count( $values ) . '%'; 00453 } 00454 00455 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00456 { 00457 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 00458 if ( count( $values ) == 0 ) 00459 { 00460 if ( $isString ) 00461 { 00462 $result = ( strpos( $inParam, $matchParam ) !== false ); 00463 } 00464 else if( $isArray ) 00465 { 00466 $result = in_array( $matchParam, $inParam ); 00467 } 00468 00469 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 00470 } 00471 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 00472 } 00473 else 00474 { 00475 $values[] = $parameters[1]; 00476 $matchParamCode = '%' . count( $values ) . '%'; 00477 } 00478 00479 if ( $isString ) 00480 { 00481 $code = '%output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );'; 00482 } 00483 else if ( $isArray ) 00484 { 00485 $code = '%output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );'; 00486 } 00487 else 00488 { 00489 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" . 00490 '{' . "\n" . 00491 ' %output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );' . "\n" . 00492 '}' . "\n" . 00493 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" . 00494 '{' . "\n" . 00495 ' %output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );' . "\n" . 00496 '}' . "\n" . 00497 'else' ."\n" . 00498 '{' . "\n" . 00499 '%output% = false;' . "\n" . 00500 '}'; 00501 } 00502 00503 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00504 } break; 00505 00506 case $this->CompareName: 00507 { 00508 $inParam = null; 00509 $isString = false; 00510 $isArray = false; 00511 $values = array(); 00512 00513 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00514 { 00515 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 00516 if ( is_string( $inParam ) ) 00517 { 00518 $isString = true; 00519 } 00520 else if( is_array( $inParam ) ) 00521 { 00522 $isArray = true; 00523 } 00524 00525 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 00526 } 00527 else 00528 { 00529 $values[] = $parameters[0]; 00530 $inParamCode = '%' . count( $values ) . '%'; 00531 } 00532 00533 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00534 { 00535 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 00536 if ( count( $values ) == 0 ) 00537 { 00538 if ( $isString ) 00539 { 00540 $result = strcmp( $inParam, $matchParam ) === 0; 00541 } 00542 else if( $isArray ) 00543 { 00544 $result = ( count( array_diff( $matchParam, $inParam ) ) == 0 and 00545 count( array_diff( $inParam, $matchParam ) ) == 0 ); 00546 } 00547 00548 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 00549 } 00550 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 00551 } 00552 else 00553 { 00554 $values[] = $parameters[1]; 00555 $matchParamCode = '%' . count( $values ) . '%'; 00556 } 00557 00558 if ( $isString ) 00559 { 00560 $code = '%output% = strcmp( ' . $inParamCode . ', ' . $matchParamCode . ' ) === 0;'; 00561 } 00562 else if ( $isArray ) 00563 { 00564 $code = '%output% = ( ( count( array_diff( ' . $inParamCode . ', ' . $matchParamCode . " ) ) == 0 ) and\n" . 00565 ' ( count( array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) ) == 0 ) );'; 00566 } 00567 else 00568 { 00569 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" . 00570 '{' . "\n" . 00571 ' %output% = strcmp( ' . $inParamCode . ', ' . $matchParamCode . ') === 0;' . "\n" . 00572 '}' . "\n" . 00573 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" . 00574 '{' . "\n" . 00575 ' %output% = ( ( count( array_diff( ' . $inParamCode . ', ' . $matchParamCode . " ) ) == 0 ) and\n" . 00576 '( count( array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) ) == 0 ) );' . "\n" . 00577 '}'; 00578 } 00579 00580 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00581 } break; 00582 00583 case $this->ImplodeName: 00584 { 00585 $values = array(); 00586 if ( !eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00587 { 00588 $values[] = $parameters[1]; 00589 $code = '%1%, '; 00590 } 00591 else 00592 { 00593 $code = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[1] ), 0, 0, false ) . ', '; 00594 } 00595 00596 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00597 { 00598 if ( count( $values ) == 0 ) 00599 { 00600 return array( eZTemplateNodeTool::createStringElement( implode( eZTemplateNodeTool::elementStaticValue( $parameters[1] ), 00601 eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 00602 } 00603 else 00604 { 00605 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 00606 } 00607 } 00608 else 00609 { 00610 $values[] = $parameters[0]; 00611 $code .= '%' . count( $values ) . '%'; 00612 } 00613 00614 $code = '%output% = implode( ' . $code . ' );'; 00615 00616 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00617 } break; 00618 00619 case $this->UniqueName: 00620 { 00621 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00622 { 00623 return array( eZTemplateNodeTool::createArrayElement( array_unique( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 00624 } 00625 00626 $values = array( $parameters[0] ); 00627 $code = '%output% = array_unique( %1% );'; 00628 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00629 } break; 00630 00631 case $this->ExplodeName: 00632 { 00633 $values = array(); 00634 $inParam = null; 00635 $isString = false; 00636 $isArray = false; 00637 00638 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00639 { 00640 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 00641 if ( is_string( $inParam ) ) 00642 { 00643 $isString = true; 00644 } 00645 else if( is_array( $inParam ) ) 00646 { 00647 $isArray = true; 00648 } 00649 00650 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 00651 } 00652 else 00653 { 00654 $values[] = $parameters[0]; 00655 $inParamCode = '%' . count( $values ) . '%'; 00656 } 00657 00658 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00659 { 00660 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 00661 if ( count( $values ) == 0 ) 00662 { 00663 if ( $isString ) 00664 { 00665 $result = explode( $matchParam, $inParam ); 00666 } 00667 else if( $isArray ) 00668 { 00669 $result = array( array_slice( $inParam, 0, $matchParam ), array_slice( $inParam, $matchParam ) ); 00670 } 00671 00672 return array( eZTemplateNodeTool::createArrayElement( $result ) ); 00673 } 00674 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 00675 } 00676 else 00677 { 00678 $values[] = $parameters[1]; 00679 $matchParamCode = '%' . count( $values ) . '%'; 00680 } 00681 00682 if ( $isString ) 00683 { 00684 $code = '%output% = explode( ' . $matchParamCode . ', ' . $inParamCode . ' );'; 00685 } 00686 else if ( $isArray ) 00687 { 00688 $code = '%output% = array( array_slice( ' . $inParamCode . ', 0,' . $matchParamCode . ' ), array_slice( ' . $inParamCode . ', ' . $matchParamCode .' ) );'; 00689 } 00690 else 00691 { 00692 $code = "if ( is_string( $inParamCode ) )\n" . 00693 "{\n" . 00694 "\t%output% = explode( $matchParamCode, $inParamCode );\n" . 00695 "}\n" . 00696 "else if ( is_array( $inParamCode ) )\n" . 00697 "{\n" . 00698 "\t%output% = array( array_slice( $inParamCode, 0, $matchParamCode ), array_slice( $inParamCode, $matchParamCode ) );\n" . 00699 "}\n" . 00700 "else\n" . 00701 "{\n" . 00702 "\t%output% = null;\n" . 00703 "}\n"; 00704 } 00705 00706 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00707 } break; 00708 00709 case $this->RemoveName: 00710 { 00711 $values = array(); 00712 $isArray = false; 00713 $isString = false; 00714 00715 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00716 { 00717 $inputArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 00718 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false ); 00719 $isString = is_string( $inputArray ); 00720 $isArray = is_array( $inputArray ); 00721 } 00722 else 00723 { 00724 $values[] = $parameters[0]; 00725 $inputArrayCode = '%' . count( $values ) . '%'; 00726 } 00727 00728 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00729 { 00730 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 00731 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false ); 00732 } 00733 else 00734 { 00735 $values[] = $parameters[1]; 00736 $offsetCode = '%' . count( $values ) . '%'; 00737 } 00738 00739 $length = false; 00740 $lengthCode = ''; 00741 if ( count( $parameters ) > 2 ) 00742 { 00743 if ( eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 00744 { 00745 $length = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 00746 $lengthCode = eZPHPCreator::variableText( $length, 0, 0, false ); 00747 } 00748 else 00749 { 00750 $values[] = $parameters[2]; 00751 $lengthCode = '%' . count( $values ) . '%'; 00752 } 00753 } 00754 00755 if ( count( $values ) == 0 ) 00756 { 00757 if ( $isString ) 00758 { 00759 return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, $offset, $length ) ) ); 00760 } 00761 else if ( $isArray ) 00762 { 00763 if ( $length === false ) 00764 $length = 1; 00765 00766 $array_one = array_slice( $inputArray, 0, $offset ); 00767 $array_two = array_slice( $inputArray, $offset + $length ); 00768 00769 return array ( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_two ) ) ); 00770 } 00771 } 00772 00773 if ( $isString ) 00774 { 00775 $code = '%output% = substr( ' . $inputArrayCode . ', ' . $offsetCode; 00776 if ( $lengthCode ) 00777 $code .= ', ' . $lengthCode; 00778 $code .= ' );'; 00779 } 00780 else if ( $isArray ) 00781 { 00782 $code = '%output% = array_merge( array_slice( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ), array_slice( ' . $inputArrayCode . ', ' . $offsetCode; 00783 if ( $lengthCode ) 00784 $code .= ' + ' . $lengthCode; 00785 $code .= ' ) );'; 00786 } 00787 else 00788 { 00789 $code = ( '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 00790 'if ( is_string( %tmp1% ) )' . "\n" . 00791 '{' . "\n" . 00792 ' %output% = ( substr( %tmp1%, 0, ' . $offsetCode . ' )' ); 00793 00794 $lengthCode = !$lengthCode ? 1 : $lengthCode; 00795 00796 if ( $lengthCode ) 00797 { 00798 $code .= ' . substr( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )'; 00799 } 00800 $code .= ( ' );' . "\n" . 00801 '}' . "\n" . 00802 'else if ( is_array( %tmp1% ) )' . "\n" . 00803 '{' . "\n" . 00804 ' %output% = array_merge( array_slice( %tmp1%, 0, ' . $offsetCode . ' )' ); 00805 if ( $lengthCode ) 00806 { 00807 $code .= ', array_slice( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )'; 00808 } 00809 $code .= ( ' );' . "\n" . 00810 '}' ); 00811 } 00812 00813 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) ); 00814 } break; 00815 00816 case $this->InsertName: 00817 { 00818 $values = array(); 00819 $isArray = false; 00820 $isString = false; 00821 00822 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00823 { 00824 $inputArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 00825 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false ); 00826 $isString = is_string( $inputArray ); 00827 $isArray = is_array( $inputArray ); 00828 } 00829 else 00830 { 00831 $values[] = $parameters[0]; 00832 $inputArrayCode = '%' . count( $values ) . '%'; 00833 } 00834 00835 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 00836 { 00837 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 00838 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false ); 00839 } 00840 else 00841 { 00842 $values[] = $parameters[1]; 00843 $offsetCode = '%' . count( $values ) . '%'; 00844 } 00845 00846 if ( count( $parameters ) > 2 ) 00847 { 00848 if ( eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 00849 { 00850 $insertText = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 00851 } 00852 } 00853 00854 $insertElemCode = array(); 00855 00856 for( $i = 2; $i < count( $parameters ); ++$i ) 00857 { 00858 if ( eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 00859 { 00860 $insertElemCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 00861 } 00862 else 00863 { 00864 $values[] = $parameters[$i]; 00865 $insertElemCode[] = '%' . count( $values ) . '%'; 00866 } 00867 } 00868 00869 if ( count( $values ) == 0 ) 00870 { 00871 if ( $isString ) 00872 { 00873 return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, 0, $offset ) . $insertText . substr( $inputArray, $offset ) ) ); 00874 } 00875 else if ( $isArray ) 00876 { 00877 $array_one = array_slice( $inputArray, 0, $offset ); 00878 $array_two = array_slice( $inputArray, $offset ); 00879 00880 $array_to_insert = array(); 00881 for ( $i = 2; $i < count( $parameters ); ++$i ) 00882 { 00883 $array_to_insert[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 00884 } 00885 00886 return array( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_to_insert, $array_two ) ) ); 00887 } 00888 } 00889 00890 $tmpCount = 0; 00891 if ( $isString ) 00892 { 00893 $code = '%output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );'; 00894 } 00895 else if ( $isArray ) 00896 { 00897 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 00898 '%tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" . 00899 '%tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" . 00900 '%tmp4% = array( '; 00901 for( $i = 0; $i < count( $insertElemCode ); ++$i ) 00902 { 00903 if ( $i != 0 ) 00904 { 00905 $code .= ", "; 00906 } 00907 $code .= $insertElemCode[$i]; 00908 } 00909 $code .= ' );' . "\n" . 00910 '%output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n"; 00911 $tmpCount = 4; 00912 } 00913 else 00914 { 00915 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 00916 'if ( is_string( %tmp1% ) )' . "\n" . 00917 '{' . "\n" . 00918 ' %output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );' . "\n" . 00919 '}' . "\n" . 00920 'else if ( is_array( %tmp1% ) )' . "\n" . 00921 '{' . "\n" . 00922 ' %tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" . 00923 ' %tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" . 00924 ' %tmp4% = array( '; 00925 for( $i = 0; $i < count( $insertElemCode ); ++$i ) 00926 { 00927 if ( $i != 0 ) 00928 { 00929 $code .= ", "; 00930 } 00931 $code .= $insertElemCode[$i]; 00932 } 00933 $code .= ' );' . "\n" . 00934 ' %output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n" . 00935 '}' . "\n"; 00936 $tmpCount = 4; 00937 } 00938 00939 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 00940 } break; 00941 00942 case $this->ReverseName: 00943 { 00944 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00945 { 00946 if ( is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) 00947 { 00948 return array( eZTemplateNodeTool::createStringElement( strrev( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 00949 } 00950 else if ( is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) 00951 { 00952 return array( eZTemplateNodeTool::createArrayElement( array_reverse( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 00953 } 00954 } 00955 00956 $values = array( $parameters[0] ); 00957 $code = 'if ( is_string( %1% ) )' . "\n" . 00958 '{' . "\n". 00959 ' %output% = strrev( %1% );' . "\n" . 00960 '}' . "\n" . 00961 'else if( is_array( %1% ) )' . "\n" . 00962 '{' . "\n" . 00963 ' %output% = array_reverse( %1% );' . "\n" . 00964 '}' . "\n"; 00965 00966 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00967 } break; 00968 00969 case $this->ArraySumName: 00970 { 00971 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00972 { 00973 return array( eZTemplateNodeTool::createNumericElement( array_sum( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 00974 } 00975 00976 $values = array( $parameters[0] ); 00977 $code = '%output% = array_sum( %1% );'; 00978 00979 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 00980 } break; 00981 00982 case $this->RepeatName: 00983 { 00984 $values = array(); 00985 $isString = false; 00986 $isArray = false; 00987 00988 if ( !eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 00989 { 00990 $values[] = $parameters[0]; 00991 $arrayCode = '%' . count( $values ) . '%'; 00992 } 00993 else 00994 { 00995 $arrayCode = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 00996 $isString = is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 00997 $isArray = is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 00998 } 00999 01000 if ( !eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 01001 { 01002 $values[] = $parameters[1]; 01003 $countCode = '%' . count( $values ) . '%'; 01004 } 01005 else 01006 { 01007 $count = (int)eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 01008 01009 if ( count( $values ) == 0 ) 01010 { 01011 if ( $isString ) 01012 { 01013 $retText = ''; 01014 $origText = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01015 for ( $i = 0; $i < $count; $i++) 01016 { 01017 $retText .= $origText; 01018 } 01019 01020 return array( eZTemplateNodeTool::createStringElement( $retText ) ); 01021 } 01022 else if ( $isArray ) 01023 { 01024 $retArray = array(); 01025 $origArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01026 for ( $i = 0; $i < $count; $i++) 01027 { 01028 $retArray = array_merge( $retArray, $origArray ); 01029 } 01030 01031 return array( eZTemplateNodeTool::createArrayElement( $retArray ) ); 01032 } 01033 } 01034 01035 $countCode = (string)$count; 01036 } 01037 01038 $code = '%tmp2% = ' . $arrayCode . ';' . "\n" . 01039 'if ( is_string( %tmp2% ) )' . "\n" . 01040 ' %output% = \'\';' . "\n" . 01041 'else if ( is_array( %tmp2% ) )' . "\n" . 01042 ' %output% = array();' . "\n" . 01043 'for( %tmp1% = 0; %tmp1% < ' . $countCode . '; ++%tmp1% )' . "\n" . 01044 '{' . "\n" . 01045 ' if ( is_string( %tmp2% ) )' . "\n" . 01046 ' %output% .= %tmp2%;' . "\n" . 01047 ' else if ( is_array( %tmp2% ) )' . "\n" . 01048 ' %output% = array_merge( %output%, %tmp2% );' . "\n" . 01049 '}' . "\n"; 01050 01051 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 2 ) ); 01052 } break; 01053 } 01054 } 01055 01056 /*! 01057 \reimp 01058 */ 01059 function compareTrans( $operatorName, &$node, $tpl, &$resourceData, 01060 $element, $lastElement, $elementList, $elementTree, &$parameters ) 01061 { 01062 $isArray = false; 01063 $isString = false; 01064 $inParam = null; 01065 $inParamCode = ''; 01066 $compareParams = array(); 01067 $compareParamsCode = array(); 01068 $offset = 0; 01069 $values = array(); 01070 $tmpCount = 0; 01071 01072 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 01073 { 01074 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01075 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 01076 $isString = is_string( $inParam ); 01077 $isArray = is_array( $inParam ); 01078 } 01079 else 01080 { 01081 $values[] = $parameters[0]; 01082 $inParamCode = '%' . count( $values ) . '%'; 01083 } 01084 01085 for( $i = 1; $i < count( $parameters ); $i++ ) 01086 { 01087 if ( eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 01088 { 01089 $compareParams[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 01090 $compareParamsCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 01091 } 01092 else 01093 { 01094 $values[] = $parameters[$i]; 01095 $compareParamsCode[] = '%' . count( $values ) . '%'; 01096 } 01097 } 01098 01099 switch( $operatorName ) 01100 { 01101 case $this->EndsWithName: 01102 { 01103 if ( count( $values ) == 0 ) 01104 { 01105 if ( $isString ) 01106 { 01107 $result = ( strrpos( $inParam, $compareParams[0] ) === ( strlen( $inParam ) - strlen ( $compareParams[0] ) ) ); 01108 } 01109 else if ( $isArray ) 01110 { 01111 $length = count( $inParam ); 01112 $params = count( $compareParams ); 01113 $start = $length - $params; 01114 01115 $result = true; 01116 for ( $i = 0; $i < $params; ++$i ) 01117 { 01118 if ( $inParam[$start + $i] != $compareParams[$i] ) 01119 { 01120 $result = false; 01121 break; 01122 } 01123 } 01124 } 01125 01126 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 01127 } 01128 01129 if ( $isString ) 01130 { 01131 $code = '%output% = ( strrpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === ( strlen( ' . $inParamCode . ' ) - strlen( ' . $compareParamsCode[0] . ' ) ) );'; 01132 } 01133 else if ( $isArray ) 01134 { 01135 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" . 01136 '%tmp1% = count( %tmp4% );' . "\n" . 01137 '%tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" . 01138 '%tmp3% = %tmp1% - %tmp2%;' . "\n" . 01139 '%output% = true;' . "\n"; 01140 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 01141 { 01142 if( $i != 0 ) 01143 $code .= 'else '; 01144 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 01145 ' %output% = false;' . "\n"; 01146 } 01147 01148 $tmpCount = 4; 01149 } 01150 else 01151 { 01152 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" . 01153 'if ( is_string( %tmp4% ) )' . "\n" . 01154 '{' . "\n" . 01155 ' %output% = ( strrpos( %tmp4%, ' . $compareParamsCode[0] . ' ) === ( strlen( %tmp4% ) - strlen( ' . $compareParamsCode[0] . ' ) ) );' . "\n" . 01156 '}' . "\n" . 01157 'else if( is_array( %tmp4% ) )' . "\n" . 01158 '{' . "\n" . 01159 ' %tmp1% = count( %tmp4% );' . "\n" . 01160 ' %tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" . 01161 ' %tmp3% = %tmp1% - %tmp2%;' . "\n" . 01162 ' %output% = true;' . "\n"; 01163 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 01164 { 01165 if( $i != 0 ) 01166 $code .= ' else '; 01167 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 01168 ' %output% = false;' . "\n"; 01169 } 01170 $code .= '}'; 01171 01172 $tmpCount = 4; 01173 } 01174 01175 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 01176 } break; 01177 01178 case $this->BeginsWithName: 01179 { 01180 if ( count( $values ) == 0 ) 01181 { 01182 if ( $isString ) 01183 { 01184 $result = ( strpos ( $inParam, $compareParams[0] ) === 0 ); 01185 } 01186 else if ( $isArray ) 01187 { 01188 $result = true; 01189 for ( $i = 0; $i < count( $compareParams ); ++$i ) 01190 { 01191 if ( $inParam[$i] != $compareParams[$i] ) 01192 { 01193 $result = false; 01194 break; 01195 } 01196 } 01197 } 01198 01199 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 01200 } 01201 01202 if ( $isString ) 01203 { 01204 $code = '%output% = ( ' . $compareParamsCode[0] . ' && strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === 0 );'; 01205 } 01206 else if ( $isArray ) 01207 { 01208 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" . 01209 '%output% = true;' . "\n"; 01210 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 01211 { 01212 if( $i != 0 ) 01213 $code .= 'else '; 01214 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 01215 ' %output% = false;' . "\n"; 01216 } 01217 01218 $tmpCount = 1; 01219 } 01220 else 01221 { 01222 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" . 01223 'if ( is_string( %tmp1% ) )' . "\n" . 01224 '{' . "\n" . 01225 " if ( {$compareParamsCode[0]} == '' )\n" . 01226 " %output% = false;\n" . 01227 " else\n" . 01228 ' %output% = ( strpos( %tmp1%, ' . $compareParamsCode[0] . ' ) === 0 );' . "\n" . 01229 '}' . "\n" . 01230 'else if( is_array( %tmp1% ) )' . "\n" . 01231 '{' . "\n" . 01232 ' %output% = true;' . "\n"; 01233 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 01234 { 01235 if( $i != 0 ) 01236 $code .= ' else '; 01237 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 01238 ' %output% = false;' . "\n"; 01239 } 01240 $code .= '}'; 01241 01242 $tmpCount = 1; 01243 } 01244 01245 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 01246 } break; 01247 } 01248 } 01249 01250 /*! 01251 \reimp 01252 */ 01253 function extractTrans( $operatorName, &$node, $tpl, &$resourceData, 01254 $element, $lastElement, $elementList, $elementTree, &$parameters ) 01255 { 01256 $offset = 0; 01257 $length = false; 01258 $values = array(); 01259 $code = ''; 01260 if ( $operatorName == $this->ExtractName ) 01261 { 01262 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 01263 { 01264 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 01265 $code .= (string)$offset; 01266 } 01267 else 01268 { 01269 $values[] = $parameters[1]; 01270 $code .= '%' . count ( $values ) . '%'; 01271 } 01272 } 01273 else if ( $operatorName == $this->ExtractRightName ) 01274 { 01275 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 01276 { 01277 $offset = -1 * eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 01278 $code .= (string)$offset; 01279 } 01280 else 01281 { 01282 $values[] = $parameters[1]; 01283 $code .= '-1 * %' . count ( $values ) . '%'; 01284 } 01285 } 01286 else 01287 { 01288 $code .= '0'; 01289 } 01290 01291 if ( $operatorName == $this->ExtractName ) 01292 { 01293 if ( isset( $parameters[2] ) and eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 01294 { 01295 $length = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 01296 $code .= ', ' . (string)$length; 01297 } 01298 else if ( isset( $parameters[2] ) ) 01299 { 01300 $values[] = $parameters[2]; 01301 $code .= ', ' . '%' . count ( $values ) . '%'; 01302 } 01303 } 01304 else if ( $operatorName == $this->ExtractLeftName ) 01305 { 01306 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 01307 { 01308 $length = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 01309 $code .= ', ' . (string)$length; 01310 } 01311 else 01312 { 01313 $values[] = $parameters[1]; 01314 $code .= ', ' . '%' . count ( $values ) . '%'; 01315 } 01316 } 01317 01318 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 01319 { 01320 if ( count( $values ) == 0 ) 01321 { 01322 $input = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01323 if ( $operatorName == $this->ExtractRightName or !$length ) 01324 { 01325 if ( is_string( $input ) ) 01326 $output = substr( $input, $offset ); 01327 else 01328 $output = array_slice( $input, $offset ); 01329 } 01330 else 01331 { 01332 if ( is_string( $input ) ) 01333 $output = substr( $input, $offset, $length ); 01334 else 01335 $output = array_slice( $input, $offset, $length ); 01336 } 01337 return array( eZTemplateNodeTool::createStaticElement( $output ) ); 01338 } 01339 else 01340 { 01341 $code = '%output% = array_slice( ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ) . ', ' . $code . ' );'; 01342 } 01343 } 01344 else 01345 { 01346 $values[] = $parameters[0]; 01347 $code = ( "if ( is_string( %" . count( $values ) . "% ) )\n" . 01348 " %output% = substr( %" . count( $values ) . "%, " . $code . " );\n" . 01349 "else\n" . 01350 " %output% = array_slice( %" . count( $values ) . "%, " . $code . " );" ); 01351 } 01352 01353 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 01354 } 01355 01356 /*! 01357 \reimp 01358 */ 01359 function mergeTrans( $operatorName, &$node, $tpl, &$resourceData, 01360 $element, $lastElement, $elementList, $elementTree, &$parameters ) 01361 { 01362 $code = ''; 01363 $stringCode = ''; 01364 01365 $paramCount = 0; 01366 $values = array(); 01367 $staticArray = array(); 01368 for ( $i = 1; $i < count( $parameters ); ++$i ) 01369 { 01370 if ( $i != 1 ) 01371 { 01372 $code .= ', '; 01373 $stringCode .= ', '; 01374 } 01375 01376 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 01377 { 01378 $values[] = $parameters[$i]; 01379 ++$paramCount; 01380 if ( $operatorName == $this->MergeName or 01381 $operatorName == $this->ArrayMergeName ) 01382 $code .= '%' . $paramCount . '%'; 01383 else 01384 $code .= 'array( %' . $paramCount . '% )'; 01385 $stringCode .= '%' . $paramCount . '%'; 01386 } 01387 else 01388 { 01389 if ( $paramCount == 0 ) 01390 { 01391 $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 01392 } 01393 if ( $operatorName == $this->MergeName or 01394 $operatorName == $this->ArrayMergeName ) 01395 $code .= '' . eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ) . ''; 01396 else 01397 { 01398 $tmp_check = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 01399 // hiding "%1%", "%output%" etc. in static input string to avoid replacing it on "$var" inside compiler. 01400 $tmp_check = str_replace( "%", '"."%"."', $tmp_check ); 01401 $code .= 'array( ' . $tmp_check . ' )'; 01402 } 01403 $stringCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 01404 } 01405 } 01406 01407 $isString = false; 01408 $isArray = false; 01409 $code2 = false; 01410 if ( $parameters[0] ) 01411 { 01412 if ( !eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 01413 { 01414 $values[] = $parameters[0]; 01415 ++$paramCount; 01416 $code2 = '%' . $paramCount . '%'; 01417 } 01418 else 01419 { 01420 $isString = is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 01421 $isArray = is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 01422 if ( $paramCount == 0 ) 01423 { 01424 // $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01425 } 01426 else 01427 { 01428 $code2 = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 01429 } 01430 } 01431 } 01432 01433 if ( $paramCount == 0 ) 01434 { 01435 if ( $operatorName == $this->AppendName or 01436 $operatorName == $this->ArrayAppendName or 01437 $operatorName == $this->MergeName or 01438 $operatorName == $this->ArrayMergeName ) 01439 { 01440 if ( $isString ) 01441 { 01442 $str = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01443 for( $i = 0; $i < count( $staticArray ); ++$i ) 01444 { 01445 $str .= $staticArray[$i]; 01446 } 01447 01448 return array( eZTemplateNodeTool::createStringElement( $str ) ); 01449 } 01450 else if ( $isArray ) 01451 { 01452 $returnArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 01453 for( $i = 0; $i < count( $staticArray ); ++$i ) 01454 { 01455 $returnArray = array_merge( $returnArray, $staticArray[$i] ); 01456 } 01457 return array( eZTemplateNodeTool::createArrayElement( $returnArray ) ); 01458 } 01459 } 01460 else if ( $operatorName == $this->PrependName or 01461 $operatorName == $this->ArrayPrependName ) 01462 { 01463 if ( $isString ) 01464 { 01465 return array( eZTemplateNodeTool::createStringElement( eZTemplateNodeTool::elementStaticValue( $parameters[1] ) . eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ); 01466 } 01467 else if ( $isArray ) 01468 { 01469 return array( eZTemplateNodeTool::createArrayElement( array_merge( $staticArray, eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 01470 } 01471 } 01472 } 01473 01474 if ( $code2 ) 01475 { 01476 if ( $operatorName == $this->AppendName ) 01477 { 01478 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" . 01479 ' %output% = ' . $code2 . ' . implode( \'\', array( ' . $stringCode . ' ) );' . "\n" . 01480 'else if( is_array( ' . $code2 . ' ) )' . "\n" . 01481 ' %output% = array_merge( ' . $code2 . ', ' . $code . ' );' ); 01482 } 01483 else if ( $operatorName == $this->ArrayAppendName ) 01484 { 01485 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 01486 } 01487 else if ( $operatorName == $this->MergeName ) 01488 { 01489 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 01490 } 01491 else if ( $operatorName == $this->ArrayMergeName ) 01492 { 01493 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 01494 } 01495 else if ( $operatorName == $this->PrependName ) 01496 { 01497 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" . 01498 ' %output% = implode( \'\', array( ' . $stringCode . ' ) ) . ' . $code2 . ';' . "\n" . 01499 'else if( is_array( ' . $code2 . ' ) )' . "\n" . 01500 ' %output% = array_merge( ' . $code . ', ' . $code2 . ' );' ); 01501 } 01502 else if ( $operatorName == $this->ArrayPrependName ) 01503 { 01504 $code = '%output% = array_merge( ' . $code . ', ' . $code2 . ' );'; 01505 } 01506 } 01507 else 01508 { 01509 if ( $operatorName == $this->MergeName ) 01510 { 01511 $code = '%output% = array_merge( ' . $code . ' );'; 01512 } 01513 else 01514 { 01515 $code = '%output% = array(' . $code . ');'; 01516 } 01517 } 01518 01519 return array( eZTemplateNodeTool::createCodePieceElement( $code . "\n", $values ) ); 01520 } 01521 01522 /*! 01523 \return true to tell the template engine that the parameter list exists per operator type. 01524 */ 01525 function namedParameterPerOperator() 01526 { 01527 return true; 01528 } 01529 /*! 01530 See eZTemplateOperator::namedParameterList() 01531 */ 01532 function namedParameterList() 01533 { 01534 return array( $this->RemoveName => array( 'offset' => array( "type" => "integer", 01535 "required" => true, 01536 "default" => false ), 01537 'length' => array( "type" => "integer", 01538 "required" => false, 01539 "default" => 1 ) ), 01540 $this->RepeatName => array( 'repeat_times' => array( "type" => "integer", 01541 "required" => false, 01542 "default" => 1 ) ), 01543 $this->InsertName => array( 'insert_position' => array( "type" => "integer", 01544 "required" => true, 01545 "default" => false ), 01546 'insert_string' => array( "type" => "string", 01547 "required" => true, 01548 "default" => false ) ), 01549 $this->ExplodeName => array( 'explode_first' => array( "type" => "mixed", 01550 "required" => true, 01551 "default" => false ) ), 01552 $this->ExtractName => array( 'extract_start' => array( "type" => "integer", 01553 "required" => true, 01554 "default" => false ), 01555 'extract_length' => array( "type" => "integer", 01556 "required" => false, 01557 "default" => false ) ), 01558 $this->ExtractLeftName => array( 'length' => array( "type" => "integer", 01559 "required" => true, 01560 "default" => false ) ), 01561 $this->ExtractRightName => array( 'length' => array( "type" => "integer", 01562 "required" => true, 01563 "default" => false ) ), 01564 $this->ReplaceName => array( 'offset' => array( "type" => "integer", 01565 "required" => true, 01566 "default" => false), 01567 'length' => array( "type" => "integer", 01568 "required" => false, 01569 "default" => false) ), 01570 $this->PrependName => array( 'prepend_string' => array( "type" => "string", 01571 "required" => false, 01572 "default" => false ) ), 01573 $this->ContainsName => array( 'match' => array( "type" => "string", 01574 "required" => true, 01575 "default" => false ) ), 01576 $this->BeginsWithName => array( 'match' => array( "type" => "string", 01577 "required" => true, 01578 "default" => false ) ), 01579 $this->EndsWithName => array( 'match' => array( "type" => "string", 01580 "required" => true, 01581 "default" => false ) ), 01582 $this->ImplodeName => array( 'separator' => array( "type" => "string", 01583 "required" => true, 01584 "default" => false) ), 01585 $this->CompareName => array( 'compare' => array( "type" => "mixed", 01586 "required" => true, 01587 "default" => false ) ) ); 01588 } 01589 01590 function modify( $tpl, $operatorName, $operatorParameters, 01591 $rootNamespace, $currentNamespace, &$operatorValue, 01592 $namedParameters, $placement ) 01593 { 01594 switch( $operatorName ) 01595 { 01596 case $this->ArrayName: 01597 { 01598 $operatorValue = array(); 01599 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 01600 { 01601 $operatorValue[] = $tpl->elementValue( $operatorParameters[$i], 01602 $rootNamespace, 01603 $currentNamespace, 01604 $placement ); 01605 } 01606 return; 01607 }break; 01608 01609 case $this->HashName: 01610 { 01611 $operatorValue = array(); 01612 $hashCount = (int)( count( $operatorParameters ) / 2 ); 01613 for ( $i = 0; $i < $hashCount; ++$i ) 01614 { 01615 $hashName = $tpl->elementValue( $operatorParameters[$i*2], 01616 $rootNamespace, 01617 $currentNamespace, 01618 $placement ); 01619 if ( is_string( $hashName ) or 01620 is_numeric( $hashName ) ) 01621 $operatorValue[$hashName] = $tpl->elementValue( $operatorParameters[($i*2)+1], 01622 $rootNamespace, 01623 $currentNamespace, 01624 $placement ); 01625 else 01626 $tpl->error( $operatorName, 01627 "Unknown hash key type '" . gettype( $hashName ) . "', skipping", 01628 $placement ); 01629 } 01630 return; 01631 } 01632 break; 01633 01634 case $this->ArraySumName: 01635 { 01636 if ( is_array( $operatorValue ) ) 01637 { 01638 $operatorValue = array_sum( $operatorValue ); 01639 } 01640 else 01641 { 01642 $tpl->error( $operatorName, 01643 "Unknown input type, can only work with arrays '" . gettype( $operatorValue ) . "'", 01644 $placement ); 01645 } 01646 return; 01647 } 01648 break; 01649 } 01650 01651 $isArray = false; 01652 if ( isset( $operatorParameters[0] ) and 01653 is_array( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ) ) ) 01654 $isArray = true; 01655 01656 if ( is_array( $operatorValue ) ) 01657 $isArray = true; 01658 01659 if ( $isArray ) 01660 { 01661 switch( $operatorName ) 01662 { 01663 // Append or prepend an array (or single elements) to the target array: 01664 case $this->ArrayPrependName: 01665 case $this->ArrayAppendName: 01666 case $this->PrependName: 01667 case $this->AppendName: 01668 { 01669 $i = 0; 01670 if ( is_array( $operatorValue ) ) 01671 { 01672 if ( count( $operatorParameters ) < 1 ) 01673 { 01674 $tpl->error( $operatorName, 01675 "Requires at least one item!", 01676 $placement ); 01677 return; 01678 } 01679 $mainArray = $operatorValue; 01680 } 01681 else 01682 { 01683 if ( count( $operatorParameters ) < 2 ) 01684 { 01685 $tpl->error( $operatorName, 01686 "Requires an array (and at least one item)!", 01687 $placement ); 01688 return; 01689 } 01690 $mainArray = $tpl->elementValue( $operatorParameters[$i++], 01691 $rootNamespace, 01692 $currentNamespace, 01693 $placement ); 01694 } 01695 $tmpArray = array(); 01696 for ( ; $i < count( $operatorParameters ); ++$i ) 01697 { 01698 $tmpArray[] = $tpl->elementValue( $operatorParameters[$i], 01699 $rootNamespace, 01700 $currentNamespace, 01701 $placement ); 01702 } 01703 if ( $operatorName == $this->ArrayPrependName or $operatorName == $this->PrependName ) 01704 $operatorValue = array_merge( $tmpArray, $mainArray ); 01705 else 01706 $operatorValue = array_merge( $mainArray, $tmpArray ); 01707 01708 } 01709 break; 01710 01711 // Merge two arrays: 01712 case $this->ArrayMergeName: 01713 case $this->MergeName: 01714 { 01715 $tmpArray = array(); 01716 if ( $operatorValue === null ) { 01717 $tmpArray[] = array(); // set to empty array in case of 01718 } else { 01719 $tmpArray[] = $operatorValue; 01720 } 01721 01722 if ( count( $operatorParameters ) < 1 ) 01723 { 01724 $tpl->error( $operatorName, "Requires an array (and at least one item!)", 01725 $placement ); 01726 return; 01727 } 01728 01729 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 01730 { 01731 $tmpVal = $tpl->elementValue( $operatorParameters[$i], 01732 $rootNamespace, 01733 $currentNamespace, 01734 $placement ); 01735 if ( $tmpVal !== null ) 01736 { 01737 $tmpArray[] = $tmpVal; 01738 } 01739 } 01740 $operatorValue = call_user_func_array( 'array_merge', $tmpArray ); 01741 }break; 01742 01743 // Check if the array contains a specified element: 01744 case $this->ContainsName: 01745 { 01746 if ( count( $operatorParameters ) < 1 ) 01747 { 01748 $tpl->error( $operatorName, "Missing matching value!", 01749 $placement ); 01750 return; 01751 } 01752 $matchValue = $tpl->elementValue( $operatorParameters[0], 01753 $rootNamespace, 01754 $currentNamespace, 01755 $placement ); 01756 01757 $operatorValue = in_array( $matchValue, $operatorValue ); 01758 } 01759 break; 01760 01761 // Compare two arrays: 01762 case $this->CompareName: 01763 { 01764 $operatorValue = ( count( array_diff( $operatorValue, $namedParameters['compare'] ) ) == 0 and 01765 count( array_diff( $namedParameters['compare'], $operatorValue ) ) == 0 ); 01766 } 01767 break; 01768 01769 // Extract a portion of the array: 01770 case $this->ExtractName: 01771 { 01772 if ( $namedParameters['extract_length'] === false ) 01773 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'] ); 01774 else 01775 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] ); 01776 } 01777 break; 01778 01779 // Extract a portion from the start of the array: 01780 case $this->ExtractLeftName: 01781 { 01782 $operatorValue = array_slice( $operatorValue, 0, $namedParameters['length'] ); 01783 }break; 01784 01785 // Extract a portion from the end of the array: 01786 case $this->ExtractRightName: 01787 { 01788 $index = count( $operatorValue ) - $namedParameters['length']; 01789 $operatorValue = array_slice( $operatorValue, $index ); 01790 }break; 01791 01792 // Check if the array begins with a given sequence: 01793 case $this->BeginsWithName: 01794 { 01795 for ( $i = 0; $i < count( $operatorParameters ); $i++ ) 01796 { 01797 $test = $tpl->elementValue( $operatorParameters[$i], 01798 $rootNamespace, 01799 $currentNamespace, 01800 $placement ); 01801 01802 if ( $operatorValue[$i] != $test ) 01803 { 01804 $operatorValue = false; 01805 return; 01806 } 01807 } 01808 01809 $operatorValue = true; 01810 }break; 01811 01812 // Check if the array ends with a given sequence: 01813 case $this->EndsWithName: 01814 { 01815 $length = count( $operatorValue ); 01816 $params = count( $operatorParameters ); 01817 01818 $start = $length - $params; 01819 01820 for ( $i = 0; $i < $params; $i++ ) 01821 { 01822 $test = $tpl->elementValue( $operatorParameters[$i], 01823 $rootNamespace, 01824 $currentNamespace, 01825 $placement ); 01826 01827 if ( $operatorValue[$start+$i] != $test ) 01828 { 01829 $operatorValue = false; 01830 return; 01831 } 01832 } 01833 $operatorValue = true; 01834 }break; 01835 01836 // Create a string containing the array elements with the separator string between elements. 01837 case $this->ImplodeName: 01838 { 01839 $operatorValue = implode( $operatorValue, $namedParameters['separator'] ); 01840 }break; 01841 01842 // Explode the array by making smaller arrays of it: 01843 case $this->ExplodeName: 01844 { 01845 $array_one = array(); 01846 $array_two = array(); 01847 01848 $array_one = array_slice( $operatorValue, 0, $namedParameters['explode_first'] ); 01849 $array_two = array_slice( $operatorValue, $namedParameters['explode_first'] ); 01850 01851 $operatorValue = array( $array_one, $array_two ); 01852 }break; 01853 01854 // Repeat the contents of an array a specified number of times: 01855 case $this->RepeatName: 01856 { 01857 $arrayElement = $operatorValue; 01858 $count = $namedParameters['repeat_times']; 01859 $operatorValue = array(); 01860 for ( $i = 0; $i < $count; $i++) 01861 { 01862 $operatorValue = array_merge( $operatorValue, $arrayElement ); 01863 } 01864 }break; 01865 01866 // Reverse the contents of the array: 01867 case $this->ReverseName: 01868 { 01869 $operatorValue = array_reverse( $operatorValue ); 01870 }break; 01871 01872 // Insert an array (or element) into a position in the target array: 01873 case $this->InsertName: 01874 { 01875 $array_one = array_slice( $operatorValue, 0, $namedParameters['insert_position'] ); 01876 $array_two = array_slice( $operatorValue, $namedParameters['insert_position'] ); 01877 01878 01879 $array_to_insert = array(); 01880 for ( $i = 1; $i < count( $operatorParameters ); ++$i ) 01881 { 01882 $array_to_insert[] = $tpl->elementValue( $operatorParameters[$i], 01883 $rootNamespace, 01884 $currentNamespace, 01885 $placement ); 01886 } 01887 01888 $operatorValue = array_merge( $array_one, $array_to_insert, $array_two ); 01889 }break; 01890 01891 // Remove a specified element (or portion) from the target array: 01892 case $this->RemoveName: 01893 { 01894 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] ); 01895 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 01896 01897 $operatorValue = array_merge( $array_one, $array_two ); 01898 }break; 01899 01900 // Replace a portion of the array: 01901 case $this->ReplaceName: 01902 { 01903 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] ); 01904 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 01905 $array_mid = array(); 01906 01907 for ( $i = 2; $i < count( $operatorParameters ); ++ $i ) 01908 { 01909 $array_mid[] = $tpl->elementValue( $operatorParameters[$i], 01910 $rootNamespace, 01911 $currentNamespace, 01912 $placement ); 01913 } 01914 01915 $operatorValue = array_merge( $array_one, $array_mid, $array_two ); 01916 } break; 01917 01918 // Removes duplicate values from array: 01919 case $this->UniqueName: 01920 { 01921 $operatorValue = array_unique( $operatorValue ); 01922 }break; 01923 01924 // Default case: 01925 default: 01926 { 01927 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement ); 01928 } 01929 break; 01930 } 01931 } 01932 else if ( is_string( $operatorValue ) ) 01933 { 01934 switch( $operatorName ) 01935 { 01936 // Not implemented. 01937 case $this->ArrayName: 01938 { 01939 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 01940 }break; 01941 01942 // Not implemented. 01943 case $this->HashName: 01944 { 01945 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 01946 } 01947 break; 01948 01949 // Add a string at the beginning of the input/target string: 01950 case $this->PrependName: 01951 { 01952 $operatorValue = $namedParameters['prepend_string'].$operatorValue; 01953 }break; 01954 01955 // Add a string at the end of the input/target string: 01956 case $this->AppendName: 01957 { 01958 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 01959 { 01960 $operatorValue .= $tpl->elementValue( $operatorParameters[$i], 01961 $rootNamespace, 01962 $currentNamespace, 01963 $placement ); 01964 } 01965 01966 }break; 01967 01968 // Not implemented. 01969 case $this->MergeName: 01970 { 01971 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 01972 }break; 01973 01974 // Check if the string contains a specified sequence of chars/string. 01975 case $this->ContainsName: 01976 { 01977 $operatorValue = ( strpos( $operatorValue, $namedParameters['match'] ) !== false ); 01978 } 01979 break; 01980 01981 // Compare two strings: 01982 case $this->CompareName: 01983 { 01984 if ( strcmp( $operatorValue, $namedParameters['compare'] ) === 0 ) 01985 { 01986 $operatorValue = true; 01987 } 01988 else 01989 { 01990 $operatorValue = false; 01991 } 01992 } 01993 break; 01994 01995 // Extract a portion from/of a string: 01996 case $this->ExtractName: 01997 { 01998 if ( $namedParameters['extract_length'] === false ) 01999 $operatorValue = substr( $operatorValue, $namedParameters['extract_start'] ); 02000 else 02001 $operatorValue = substr( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] ); 02002 } 02003 break; 02004 02005 // Extract string/portion from the start of the string. 02006 case $this->ExtractLeftName: 02007 { 02008 $operatorValue = substr( $operatorValue, 0, $namedParameters['length'] ); 02009 }break; 02010 02011 // Extract string/portion from the end of the string. 02012 case $this->ExtractRightName: 02013 { 02014 $offset = strlen( $operatorValue ) - $namedParameters['length']; 02015 $operatorValue = substr( $operatorValue, $offset ); 02016 }break; 02017 02018 // Check if string begins with specified sequence: 02019 case $this->BeginsWithName: 02020 { 02021 if ( strpos( $operatorValue, $namedParameters['match'] ) === 0 ) 02022 { 02023 $operatorValue = true; 02024 } 02025 else 02026 { 02027 $operatorValue = false; 02028 } 02029 }break; 02030 02031 // Check if string ends with specified sequence: 02032 case $this->EndsWithName: 02033 { 02034 if ( strrpos( $operatorValue, $namedParameters['match'] ) === ( strlen( $operatorValue ) - strlen ($namedParameters['match'] ) ) ) 02035 { 02036 $operatorValue = true; 02037 } 02038 else 02039 { 02040 $operatorValue = false; 02041 } 02042 }break; 02043 02044 // Only works with arrays. 02045 case $this->ImplodeName: 02046 { 02047 $tpl->warning( $operatorName, "$operatorName only works with arrays", $placement ); 02048 }break; 02049 02050 // Explode string (split a string by string). 02051 case $this->ExplodeName: 02052 { 02053 $operatorValue = explode( $namedParameters['explode_first'], $operatorValue ); 02054 }break; 02055 02056 // Repeat string n times: 02057 case $this->RepeatName: 02058 { 02059 $operatorValue = str_repeat( $operatorValue, $namedParameters['repeat_times'] ); 02060 }break; 02061 02062 // Reverse contents of string: 02063 case $this->ReverseName: 02064 { 02065 $operatorValue = strrev( $operatorValue ); 02066 }break; 02067 02068 // Insert a given string at a specified position: 02069 case $this->InsertName: 02070 { 02071 $first = substr( $operatorValue, 0, $namedParameters['insert_position'] ); 02072 $second = substr( $operatorValue, $namedParameters['insert_position'] ); 02073 $operatorValue = $first . $namedParameters['insert_string'] . $second; 02074 }break; 02075 02076 // Remove a portion from a string: 02077 case $this->RemoveName: 02078 { 02079 $first = substr( $operatorValue, 0, $namedParameters['offset'] ); 02080 $second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 02081 $operatorValue = $first . $second; 02082 }break; 02083 02084 // Replace a portion of a string: 02085 case $this->ReplaceName: 02086 { 02087 $first = substr( $operatorValue, 0, $namedParameters['offset'] ); 02088 $second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 02089 $mid = ''; 02090 02091 for ( $i = 2; $i < count( $operatorParameters ); ++ $i ) 02092 { 02093 $mid .= $tpl->elementValue( $operatorParameters[$i], 02094 $rootNamespace, 02095 $currentNamespace, 02096 $placement ); 02097 } 02098 02099 $operatorValue = $first . $mid . $second; 02100 }break; 02101 02102 // Not implemented. 02103 case $this->UniqueName: 02104 { 02105 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 02106 }break; 02107 02108 // Default case: 02109 default: 02110 { 02111 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement ); 02112 } 02113 break; 02114 } 02115 } 02116 // ..or something else? -> We're building the array: 02117 else 02118 { 02119 $operatorValue = array(); 02120 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 02121 { 02122 $operatorValue[] = $tpl->elementValue( $operatorParameters[$i], 02123 $rootNamespace, 02124 $currentNamespace, 02125 $placement ); 02126 } 02127 } 02128 } 02129 02130 /// \privatesection 02131 public $Operators; 02132 public $ArrayName; 02133 public $HashName; 02134 } 02135 02136 ?>