[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplateArrayOperator class 4 // 5 // Created on: <05-Mar-2002 12:52:10 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZTemplateArrayOperator eztemplatearrayoperator.php 31 \ingroup eZTemplateOperators 32 \brief Dynamic creation of arrays using operator "array" 33 34 Creates an operator which can create arrays dynamically by 35 adding all operator parameters as array elements. 36 37 \code 38 // Example template code 39 {array(1,"test")} 40 {array(array(1,2),3)} 41 \endcode 42 43 */ 44 45 include_once ( "lib/eztemplate/classes/eztemplate.php" ); 46 47 class eZTemplateArrayOperator 48 { 49 /*! 50 Initializes the array operator with the operator name $name. 51 */ 52 function eZTemplateArrayOperator( $arrayName = 'array', 53 $hashName = 'hash', 54 $arrayPrependName = 'array_prepend', // DEPRECATED/OBSOLETE 55 $prependName = 'prepend', // New, replaces array_prepend. 56 $arrayAppendName = 'array_append', // DEPRECATED/OBSOLETE 57 $appendName = 'append', // New, replaces array_append. 58 $arrayMergeName = 'array_merge', // DEPRECATED/OBSOLETE 59 $mergeName = 'merge', // New, replaces array_merge. 60 $containsName = 'contains', 61 $compareName = 'compare', 62 $extractName = 'extract', 63 $extractLeftName = 'extract_left', 64 $extractRightName = 'extract_right', 65 $beginsWithName = 'begins_with', 66 $endsWithName = 'ends_with', 67 $implodeName = 'implode', 68 $explodeName = 'explode', 69 $repeatName = 'repeat', 70 $reverseName = 'reverse', 71 $insertName = 'insert', 72 $removeName = 'remove', 73 $replaceName = 'replace', 74 $uniqueName = 'unique', 75 $arraySumName = 'array_sum' ) 76 { 77 $this->ArrayName = $arrayName; 78 $this->HashName = $hashName; 79 $this->ArrayPrependName = $arrayPrependName; // DEPRECATED/OBSOLETE 80 $this->PrependName = $prependName; // New, replaces ArrayPrependName. 81 $this->ArrayAppendName = $arrayAppendName; // DEPRECATED/OBSOLETE 82 $this->AppendName = $appendName; // New, replaces ArrayAppendName. 83 $this->ArrayMergeName = $arrayMergeName; // DEPRECATED/OBSOLETE 84 $this->MergeName = $mergeName; // New, replaces ArrayMergeName. 85 $this->ContainsName = $containsName; 86 $this->CompareName = $compareName; 87 $this->ExtractName = $extractName; 88 $this->ExtractLeftName = $extractLeftName; 89 $this->ExtractRightName = $extractRightName; 90 $this->BeginsWithName = $beginsWithName; 91 $this->EndsWithName = $endsWithName; 92 $this->ImplodeName = $implodeName; 93 $this->ExplodeName = $explodeName; 94 $this->RepeatName = $repeatName; 95 $this->ReverseName = $reverseName; 96 $this->InsertName = $insertName; 97 $this->RemoveName = $removeName; 98 $this->ReplaceName = $replaceName; 99 $this->UniqueName = $uniqueName; 100 $this->ArraySumName = $arraySumName; 101 102 $this->Operators = array( $arrayName, 103 $hashName, 104 $arrayPrependName, // DEPRECATED/OBSOLETE 105 $prependName, // New, replaces arrayPrependName. 106 $arrayAppendName, // DEPRECATED/OBSOLETE 107 $appendName, // New, replaces arrayAppendName. 108 $arrayMergeName, // DEPRECATED/OBSOLETE 109 $mergeName, // New, replaces arrayMergeName. 110 $containsName, 111 $compareName, 112 $extractName, 113 $extractLeftName, 114 $extractRightName, 115 $beginsWithName, 116 $endsWithName, 117 $implodeName, 118 $explodeName, 119 $repeatName, 120 $reverseName, 121 $insertName, 122 $removeName, 123 $replaceName, 124 $uniqueName, 125 $arraySumName ); 126 } 127 128 /*! 129 Returns the operators in this class. 130 */ 131 function &operatorList() 132 { 133 return $this->Operators; 134 } 135 136 function operatorTemplateHints() 137 { 138 return array( $this->ArrayName => array( 'input' => true, 139 'output' => true, 140 'parameters' => true, 141 'element-transformation' => true, 142 'transform-parameters' => true, 143 'element-transformation-func' => 'arrayTrans' ), 144 $this->HashName => array( 'input' => true, 145 'output' => true, 146 'parameters' => true, 147 'element-transformation' => true, 148 'transform-parameters' => true, 149 'element-transformation-func' => 'arrayTrans'), 150 $this->ArrayPrependName => array( 'input' => true, 151 'output' => true, 152 'parameters' => true, 153 'element-transformation' => true, 154 'transform-parameters' => true, 155 'input-as-parameter' => 'always', 156 'element-transformation-func' => 'mergeTrans' ), 157 $this->PrependName => array( 'input' => true, 158 'output' => true, 159 'parameters' => true, 160 'element-transformation' => true, 161 'transform-parameters' => true, 162 'input-as-parameter' => 'always', 163 'element-transformation-func' => 'mergeTrans' ), 164 $this->ArrayAppendName => array( 'input' => true, 165 'output' => true, 166 'parameters' => true, 167 'element-transformation' => true, 168 'transform-parameters' => true, 169 'input-as-parameter' => 'always', 170 'element-transformation-func' => 'mergeTrans' ), 171 $this->AppendName => array( 'input' => true, 172 'output' => true, 173 'parameters' => true, 174 'element-transformation' => true, 175 'transform-parameters' => true, 176 'input-as-parameter' => 'always', 177 'element-transformation-func' => 'mergeTrans' ), 178 $this->ArrayMergeName => array( 'input' => true, 179 'output' => true, 180 'parameters' => true, 181 'element-transformation' => true, 182 'transform-parameters' => true, 183 'input-as-parameter' => 'always', 184 'element-transformation-func' => 'mergeTrans' ), 185 $this->MergeName => array( 'input' => true, 186 'output' => true, 187 'parameters' => true, 188 'element-transformation' => true, 189 'transform-parameters' => true, 190 'input-as-parameter' => 'always', 191 'element-transformation-func' => 'mergeTrans' ), 192 $this->ContainsName => array( 'input' => true, 193 'output' => true, 194 'parameters' => 1, 195 'element-transformation' => true, 196 'transform-parameters' => true, 197 'input-as-parameter' => 'always', 198 'element-transformation-func' => 'arrayTrans'), 199 $this->CompareName => array( 'input' => true, 200 'output' => true, 201 'parameters' => 1, 202 'element-transformation' => true, 203 'transform-parameters' => true, 204 'input-as-parameter' => 'always', 205 'element-transformation-func' => 'arrayTrans'), 206 $this->ExtractName => array( 'input' => true, 207 'output' => true, 208 'parameters' => 2, 209 'element-transformation' => true, 210 'transform-parameters' => true, 211 'input-as-parameter' => 'always', 212 'element-transformation-func' => 'extractTrans'), 213 $this->ExtractLeftName => array( 'input' => true, 214 'output' => true, 215 'parameters' => 1, 216 'element-transformation' => true, 217 'transform-parameters' => true, 218 'input-as-parameter' => 'always', 219 'element-transformation-func' => 'extractTrans'), 220 $this->ExtractRightName => array( 'input' => true, 221 'output' => true, 222 'parameters' => 1, 223 'element-transformation' => true, 224 'transform-parameters' => true, 225 'input-as-parameter' => 'always', 226 'element-transformation-func' => 'extractTrans'), 227 $this->BeginsWithName => array( 'input' => true, 228 'output' => true, 229 'parameters' => true, 230 'element-transformation' => true, 231 'transform-parameters' => true, 232 'input-as-parameter' => 'always', 233 'element-transformation-func' => 'compareTrans'), 234 $this->EndsWithName => array( 'input' => true, 235 'output' => true, 236 'parameters' => true, 237 'element-transformation' => true, 238 'transform-parameters' => true, 239 'input-as-parameter' => 'always', 240 'element-transformation-func' => 'compareTrans'), 241 $this->ImplodeName => array( 'input' => true, 242 'output' => true, 243 'parameters' => 1, 244 'element-transformation' => true, 245 'transform-parameters' => true, 246 'input-as-parameter' => 'always', 247 'element-transformation-func' => 'arrayTrans'), 248 $this->ExplodeName => array( 'input' => true, 249 'output' => true, 250 'parameters' => 1, 251 'element-transformation' => true, 252 'transform-parameters' => true, 253 'input-as-parameter' => 'always', 254 'element-transformation-func' => 'arrayTrans'), 255 $this->RepeatName => array( 'input' => true, 256 'output' => true, 257 'parameters' => 1, 258 'element-transformation' => true, 259 'transform-parameters' => true, 260 'input-as-parameter' => 'always', 261 'element-transformation-func' => 'arrayTrans'), 262 $this->ReverseName => array( 'input' => true, 263 'output' => true, 264 'parameters' => false, 265 'element-transformation' => true, 266 'transform-parameters' => true, 267 'input-as-parameter' => 'always', 268 'element-transformation-func' => 'arrayTrans' ), 269 $this->InsertName => array( 'input' => true, 270 'output' => true, 271 'parameters' => true, 272 'element-transformation' => true, 273 'transform-parameters' => true, 274 'input-as-parameter' => 'always', 275 'element-transformation-func' => 'arrayTrans' ), 276 $this->RemoveName => array( 'input' => true, 277 'output' => true, 278 'parameters' => 2, 279 'element-transformation' => true, 280 'transform-parameters' => true, 281 'input-as-parameter' => 'always', 282 'element-transformation-func' => 'arrayTrans'), 283 $this->ReplaceName => array( 'input' => true, 284 'output' => true, 285 'parameters' => true ), 286 $this->UniqueName => array( 'input' => true, 287 'output' => true, 288 'parameters' => false, 289 'element-transformation' => true, 290 'transform-parameters' => true, 291 'input-as-parameter' => 'always', 292 'element-transformation-func' => 'arrayTrans'), 293 $this->ArraySumName => array( 'input' => true, 294 'output' => true, 295 'parameters' => false, 296 'element-transformation' => true, 297 'transform-parameters' => true, 298 'input-as-parameter' => 'always', 299 'element-transformation-func' => 'arrayTrans' ) ); 300 } 301 302 /*! 303 \reimp 304 */ 305 function arrayTrans( $operatorName, &$node, &$tpl, &$resourceData, 306 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 307 { 308 switch( $operatorName ) 309 { 310 case $this->ArrayName: 311 { 312 $code = ''; 313 $paramCount = 0; 314 $values = array(); 315 $staticArray = array(); 316 for ( $i = 0; $i < count( $parameters ); ++$i ) 317 { 318 if ( $i != 0 ) 319 { 320 $code .= ', '; 321 } 322 else 323 { 324 $code .= '%output% = array( '; 325 } 326 327 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 328 { 329 $values[] = $parameters[$i]; 330 ++$paramCount; 331 $code .= '%' . $paramCount . '%'; 332 } 333 else 334 { 335 if ( $paramCount == 0 ) 336 { 337 $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 338 } 339 340 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 341 } 342 } 343 344 if ( $paramCount == 0 ) 345 { 346 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) ); 347 } 348 349 $code .= ' );'; 350 351 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 352 } break; 353 354 case $this->HashName: 355 { 356 $code = ''; 357 $paramCount = 0; 358 $values = array(); 359 $staticArray = array(); 360 $staticKeys = true; 361 $keys = array(); 362 $vals = array(); 363 $hashCount = (int)( count( $parameters ) / 2 ); 364 for ( $i = 0; $i < $hashCount; ++$i ) 365 { 366 if ( $i != 0 ) 367 { 368 $code .= ', '; 369 } 370 else 371 { 372 $code .= '%output% = array( '; 373 } 374 375 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i*2] ) ) 376 { 377 $staticKeys = false; 378 $values[] = $parameters[$i*2]; 379 ++$paramCount; 380 $code .= '%' . $paramCount . '%'; 381 } 382 else 383 { 384 $keys[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ); 385 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ), 0, 0, false ); 386 } 387 388 $code .= ' => '; 389 390 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i*2+1] ) ) 391 { 392 $values[] = $parameters[$i*2 + 1]; 393 ++$paramCount; 394 $code .= '%' . $paramCount . '%'; 395 } 396 else 397 { 398 if ( $paramCount == 0 ) 399 { 400 $staticArray[ eZTemplateNodeTool::elementStaticValue( $parameters[$i*2] ) ] = eZTemplateNodeTool::elementStaticValue( $parameters[$i*2+1] ); 401 } 402 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i*2+1] ), 0, 0, false ); 403 } 404 405 if ( $staticKeys ) 406 { 407 $vals[$keys[count( $keys ) - 1]] = $parameters[$i*2 + 1]; 408 } 409 } 410 411 if ( $paramCount == 0 ) 412 { 413 return array( eZTemplateNodeTool::createArrayElement( $staticArray ) ); 414 } 415 416 if ( $staticKeys ) 417 { 418 return array( eZTemplateNodeTool::createDynamicArrayElement( $keys, $vals ) ); 419 } 420 421 $code .= ' );'; 422 423 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 424 } break; 425 426 case $this->ContainsName: 427 { 428 $values = array(); 429 $inParam = null; 430 $isString = false; 431 $isArray = false; 432 433 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 434 { 435 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 436 if ( is_string( $inParam ) ) 437 { 438 $isString = true; 439 } 440 else if( is_array( $inParam ) ) 441 { 442 $isArray = true; 443 } 444 445 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 446 } 447 else 448 { 449 $values[] = $parameters[0]; 450 $inParamCode = '%' . count( $values ) . '%'; 451 } 452 453 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 454 { 455 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 456 if ( count( $values ) == 0 ) 457 { 458 if ( $isString ) 459 { 460 $result = ( strpos( $inParam, $matchParam ) !== false ); 461 } 462 else if( $isArray ) 463 { 464 $result = in_array( $matchParam, $inParam ); 465 } 466 467 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 468 } 469 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 470 } 471 else 472 { 473 $values[] = $parameters[1]; 474 $matchParamCode = '%' . count( $values ) . '%'; 475 } 476 477 if ( $isString ) 478 { 479 $code = '%output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );'; 480 } 481 else if ( $isArray ) 482 { 483 $code = '%output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );'; 484 } 485 else 486 { 487 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" . 488 '{' . "\n" . 489 ' %output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );' . "\n" . 490 '}' . "\n" . 491 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" . 492 '{' . "\n" . 493 ' %output% = in_array( ' . $matchParamCode . ', ' . $inParamCode . ' );' . "\n" . 494 '}' . "\n" . 495 'else' ."\n" . 496 '{' . "\n" . 497 '%output% = false;' . "\n" . 498 '}'; 499 } 500 501 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 502 } break; 503 504 case $this->CompareName: 505 { 506 $inParam = null; 507 $isString = false; 508 $isArray = false; 509 $values = array(); 510 511 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 512 { 513 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 514 if ( is_string( $inParam ) ) 515 { 516 $isString = true; 517 } 518 else if( is_array( $inParam ) ) 519 { 520 $isArray = true; 521 } 522 523 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 524 } 525 else 526 { 527 $values[] = $parameters[0]; 528 $inParamCode = '%' . count( $values ) . '%'; 529 } 530 531 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 532 { 533 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 534 if ( count( $values ) == 0 ) 535 { 536 if ( $isString ) 537 { 538 $result = ( $inParam == $matchParam ); 539 } 540 else if( $isArray ) 541 { 542 $result = ( array_diff( $matchParam, $inParam ) == array_diff( $inParam, $matchParam ) ); 543 } 544 545 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 546 } 547 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 548 } 549 else 550 { 551 $values[] = $parameters[1]; 552 $matchParamCode = '%' . count( $values ) . '%'; 553 } 554 555 if ( $isString ) 556 { 557 $code = '%output% = ( ' . $inParamCode . ' == ' . $matchParamCode . ' );'; 558 } 559 else if ( $isArray ) 560 { 561 $code = '%output% = ( array_diff( ' . $inParamCode . ', ' . $matchParamCode . ' ) == array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) );'; 562 } 563 else 564 { 565 $code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" . 566 '{' . "\n" . 567 ' %output% = ( ' . $inParamCode . ' == ' . $matchParamCode . ' );' . "\n" . 568 '}' . "\n" . 569 'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" . 570 '{' . "\n" . 571 ' %output% = ( array_diff( ' . $inParamCode . ', ' . $matchParamCode . ' ) == array_diff( ' . $matchParamCode . ', ' . $inParamCode . ' ) );' . "\n" . 572 '}'; 573 } 574 575 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 576 } break; 577 578 case $this->ImplodeName: 579 { 580 $values = array(); 581 if ( !eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 582 { 583 $values[] = $parameters[1]; 584 $code = '%1%, '; 585 } 586 else 587 { 588 $code = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[1] ), 0, 0, false ) . ', '; 589 } 590 591 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 592 { 593 if ( count( $values ) == 0 ) 594 { 595 return array( eZTemplateNodeTool::createStringElement( implode( eZTemplateNodeTool::elementStaticValue( $parameters[1] ), 596 eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 597 } 598 else 599 { 600 $code .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 601 } 602 } 603 else 604 { 605 $values[] = $parameters[0]; 606 $code .= '%' . count( $values ) . '%'; 607 } 608 609 $code = '%output% = implode( ' . $code . ' );'; 610 611 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 612 } break; 613 614 case $this->UniqueName: 615 { 616 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 617 { 618 return array( eZTemplateNodeTool::createArrayElement( array_unique( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 619 } 620 621 $values = array( $parameters[0] ); 622 $code = '%output% = array_unique( %1% );'; 623 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 624 } break; 625 626 case $this->ExplodeName: 627 { 628 $values = array(); 629 $inParam = null; 630 $isString = false; 631 $isArray = false; 632 633 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 634 { 635 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 636 if ( is_string( $inParam ) ) 637 { 638 $isString = true; 639 } 640 else if( is_array( $inParam ) ) 641 { 642 $isArray = true; 643 } 644 645 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 646 } 647 else 648 { 649 $values[] = $parameters[0]; 650 $inParamCode = '%' . count( $values ) . '%'; 651 } 652 653 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 654 { 655 $matchParam = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 656 if ( count( $values ) == 0 ) 657 { 658 if ( $isString ) 659 { 660 $result = explode( $matchParam, $inParam ); 661 } 662 else if( $isArray ) 663 { 664 $result = array( array_slice( $inParam, 0, $matchParam ), array_slice( $inParam, $matchParam ) ); 665 } 666 667 return array( eZTemplateNodeTool::createArrayElement( $result ) ); 668 } 669 $matchParamCode = eZPHPCreator::variableText( $matchParam, 0, 0, false ); 670 } 671 else 672 { 673 $values[] = $parameters[1]; 674 $matchParamCode = '%' . count( $values ) . '%'; 675 } 676 677 if ( $isString ) 678 { 679 $code = '%output% = explode( ' . $matchParamCode . ', ' . $inParamCode . ' );'; 680 } 681 else if ( $isArray ) 682 { 683 $code = '%output% = array( array_slice( ' . $inParamCode . ', 0,' . $matchParamCode . ' ), array_slice( ' . $inParamCode . ', ' . $matchParamCode .' ) );'; 684 } 685 else 686 { 687 $code = "if ( is_string( $inParamCode ) )\n" . 688 "{\n" . 689 "\t%output% = explode( $matchParamCode, $inParamCode );\n" . 690 "}\n" . 691 "else if ( is_array( $inParamCode ) )\n" . 692 "{\n" . 693 "\t%output% = array( array_slice( $inParamCode, 0, $matchParamCode ), array_slice( $inParamCode, $matchParamCode ) );\n" . 694 "}\n" . 695 "else\n" . 696 "{\n" . 697 "\t%output% = null;\n" . 698 "}\n"; 699 } 700 701 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 702 } break; 703 704 case $this->RemoveName: 705 { 706 $values = array(); 707 $isArray = false; 708 $isString = false; 709 710 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 711 { 712 $inputArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 713 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false ); 714 $isString = is_string( $inputArray ); 715 $isArray = is_array( $inputArray ); 716 } 717 else 718 { 719 $values[] = $parameters[0]; 720 $inputArrayCode = '%' . count( $values ) . '%'; 721 } 722 723 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 724 { 725 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 726 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false ); 727 } 728 else 729 { 730 $values[] = $parameters[1]; 731 $offsetCode = '%' . count( $values ) . '%'; 732 } 733 734 $length = false; 735 $lengthCode = ''; 736 if ( count( $parameters ) > 2 ) 737 { 738 if ( eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 739 { 740 $length = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 741 $lengthCode = eZPHPCreator::variableText( $length, 0, 0, false ); 742 } 743 else 744 { 745 $values[] = $parameters[2]; 746 $lengthCode = '%' . count( $values ) . '%'; 747 } 748 } 749 750 if ( count( $values ) == 0 ) 751 { 752 if ( $isString ) 753 { 754 return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, $offset, $length ) ) ); 755 } 756 else if ( $isArray ) 757 { 758 if ( $length === false ) 759 $length = 1; 760 761 $array_one = array_slice( $inputArray, 0, $offset ); 762 $array_two = array_slice( $inputArray, $offset + $length ); 763 764 return array ( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_two ) ) ); 765 } 766 } 767 768 if ( $isString ) 769 { 770 $code = '%output% = substr( ' . $inputArrayCode . ', ' . $offsetCode; 771 if ( $lengthCode ) 772 $code .= ', ' . $lengthCode; 773 $code .= ' );'; 774 } 775 else if ( $isArray ) 776 { 777 $code = '%output% = array_merge( array_slice( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ), array_slice( ' . $inputArrayCode . ', ' . $offsetCode; 778 if ( $lengthCode ) 779 $code .= ' + ' . $lengthCode; 780 $code .= ' ) );'; 781 } 782 else 783 { 784 $code = ( '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 785 'if ( is_string( %tmp1% ) )' . "\n" . 786 '{' . "\n" . 787 ' %output% = ( substr( %tmp1%, 0, ' . $offsetCode . ' )' ); 788 789 $lengthCode = !$lengthCode ? 1 : $lengthCode; 790 791 if ( $lengthCode ) 792 { 793 $code .= ' . substr( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )'; 794 } 795 $code .= ( ' );' . "\n" . 796 '}' . "\n" . 797 'else if ( is_array( %tmp1% ) )' . "\n" . 798 '{' . "\n" . 799 ' %output% = array_merge( array_slice( %tmp1%, 0, ' . $offsetCode . ' )' ); 800 if ( $lengthCode ) 801 { 802 $code .= ', array_slice( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )'; 803 } 804 $code .= ( ' );' . "\n" . 805 '}' ); 806 } 807 808 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) ); 809 } break; 810 811 case $this->InsertName: 812 { 813 $values = array(); 814 $isArray = false; 815 $isString = false; 816 817 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 818 { 819 $inputArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 820 $inputArrayCode = eZPHPCreator::variableText( $inputArray, 0, 0, false ); 821 $isString = is_string( $inputArray ); 822 $isArray = is_array( $inputArray ); 823 } 824 else 825 { 826 $values[] = $parameters[0]; 827 $inputArrayCode = '%' . count( $values ) . '%'; 828 } 829 830 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 831 { 832 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 833 $offsetCode = eZPHPCreator::variableText( $offset, 0, 0, false ); 834 } 835 else 836 { 837 $values[] = $parameters[1]; 838 $offsetCode = '%' . count( $values ) . '%'; 839 } 840 841 if ( count( $parameters ) > 2 ) 842 { 843 if ( eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 844 { 845 $insertText = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 846 } 847 } 848 849 $insertElemCode = array(); 850 851 for( $i = 2; $i < count( $parameters ); ++$i ) 852 { 853 if ( eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 854 { 855 $insertElemCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 856 } 857 else 858 { 859 $values[] = $parameters[$i]; 860 $insertElemCode[] = '%' . count( $values ) . '%'; 861 } 862 } 863 864 if ( count( $values ) == 0 ) 865 { 866 if ( $isString ) 867 { 868 return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, 0, $offset ) . $insertText . substr( $inputArray, $offset ) ) ); 869 } 870 else if ( $isArray ) 871 { 872 $array_one = array_slice( $inputArray, 0, $offset ); 873 $array_two = array_slice( $inputArray, $offset ); 874 875 $array_to_insert = array(); 876 for ( $i = 2; $i < count( $parameters ); ++$i ) 877 { 878 $array_to_insert[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 879 } 880 881 return array( eZTemplateNodeTool::createArrayElement( array_merge( $array_one, $array_to_insert, $array_two ) ) ); 882 } 883 } 884 885 $tmpCount = 0; 886 if ( $isString ) 887 { 888 $code = '%output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );'; 889 } 890 else if ( $isArray ) 891 { 892 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 893 '%tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" . 894 '%tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" . 895 '%tmp4% = array( '; 896 for( $i = 0; $i < count( $insertElemCode ); ++$i ) 897 { 898 if ( $i != 0 ) 899 { 900 $code .= ", "; 901 } 902 $code .= $insertElemCode[$i]; 903 } 904 $code .= ' );' . "\n" . 905 '%output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n"; 906 $tmpCount = 4; 907 } 908 else 909 { 910 $code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" . 911 'if ( is_string( %tmp1% ) )' . "\n" . 912 '{' . "\n" . 913 ' %output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );' . "\n" . 914 '}' . "\n" . 915 'else if ( is_array( %tmp1% ) )' . "\n" . 916 '{' . "\n" . 917 ' %tmp2% = array_slice( %tmp1%, 0, ' . $offsetCode . ' );' . "\n" . 918 ' %tmp3% = array_slice( %tmp1%, ' . $offsetCode . ' );' . "\n" . 919 ' %tmp4% = array( '; 920 for( $i = 0; $i < count( $insertElemCode ); ++$i ) 921 { 922 if ( $i != 0 ) 923 { 924 $code .= ", "; 925 } 926 $code .= $insertElemCode[$i]; 927 } 928 $code .= ' );' . "\n" . 929 ' %output% = array_merge( %tmp2%, %tmp4%, %tmp3% );' . "\n" . 930 '}' . "\n"; 931 $tmpCount = 4; 932 } 933 934 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 935 } break; 936 937 case $this->ReverseName: 938 { 939 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 940 { 941 if ( is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) 942 { 943 return array( eZTemplateNodeTool::createStringElement( strrev( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 944 } 945 else if ( is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) 946 { 947 return array( eZTemplateNodeTool::createArrayElement( array_reverse( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 948 } 949 } 950 951 $values = array( $parameters[0] ); 952 $code = 'if ( is_string( %1% ) )' . "\n" . 953 '{' . "\n". 954 ' %output% = strrev( %1% );' . "\n" . 955 '}' . "\n" . 956 'else if( is_array( %1% ) )' . "\n" . 957 '{' . "\n" . 958 ' %output% = array_reverse( %1% );' . "\n" . 959 '}' . "\n"; 960 961 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 962 } break; 963 964 case $this->ArraySumName: 965 { 966 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 967 { 968 return array( eZTemplateNodeTool::createNumericElement( array_sum( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 969 } 970 971 $values = array( $parameters[0] ); 972 $code = '%output% = array_sum( %1% );'; 973 974 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 975 } break; 976 977 case $this->RepeatName: 978 { 979 $values = array(); 980 $isString = false; 981 $isArray = false; 982 983 if ( !eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 984 { 985 $values[] = $parameters[0]; 986 $arrayCode = '%' . count( $values ) . '%'; 987 } 988 else 989 { 990 $arrayCode = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 991 $isString = is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 992 $isArray = is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 993 } 994 995 if ( !eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 996 { 997 $values[] = $parameters[1]; 998 $countCode = '%' . count( $values ) . '%'; 999 } 1000 else 1001 { 1002 $count = (int)eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 1003 1004 if ( count( $values ) == 0 ) 1005 { 1006 if ( $isString ) 1007 { 1008 $retText = ''; 1009 $origText = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1010 for ( $i = 0; $i < $count; $i++) 1011 { 1012 $retText .= $origText; 1013 } 1014 1015 return array( eZTemplateNodeTool::createStringElement( $retText ) ); 1016 } 1017 else if ( $isArray ) 1018 { 1019 $retArray = array(); 1020 $origArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1021 for ( $i = 0; $i < $count; $i++) 1022 { 1023 $retArray = array_merge( $retArray, $origArray ); 1024 } 1025 1026 return array( eZTemplateNodeTool::createArrayElement( $retArray ) ); 1027 } 1028 } 1029 1030 $countCode = (string)$count; 1031 } 1032 1033 $code = '%tmp2% = ' . $arrayCode . ';' . "\n" . 1034 'if ( is_string( %tmp2% ) )' . "\n" . 1035 ' %output% = \'\';' . "\n" . 1036 'else if ( is_array( %tmp2% ) )' . "\n" . 1037 ' %output% = array();' . "\n" . 1038 'for( %tmp1% = 0; %tmp1% < ' . $countCode . '; ++%tmp1% )' . "\n" . 1039 '{' . "\n" . 1040 ' if ( is_string( %tmp2% ) )' . "\n" . 1041 ' %output% .= %tmp2%;' . "\n" . 1042 ' else if ( is_array( %tmp2% ) )' . "\n" . 1043 ' %output% = array_merge( %output%, %tmp2% );' . "\n" . 1044 '}' . "\n"; 1045 1046 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 2 ) ); 1047 } break; 1048 } 1049 } 1050 1051 /*! 1052 \reimp 1053 */ 1054 function compareTrans( $operatorName, &$node, &$tpl, &$resourceData, 1055 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 1056 { 1057 $isArray = false; 1058 $isString = false; 1059 $inParam = null; 1060 $inParamCode = ''; 1061 $compareParams = array(); 1062 $compareParamsCode = array(); 1063 $offset = 0; 1064 $values = array(); 1065 $tmpCount = 0; 1066 1067 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 1068 { 1069 $inParam = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1070 $inParamCode = eZPHPCreator::variableText( $inParam, 0, 0, false ); 1071 $isString = is_string( $inParam ); 1072 $isArray = is_array( $inParam ); 1073 } 1074 else 1075 { 1076 $values[] = $parameters[0]; 1077 $inParamCode = '%' . count( $values ) . '%'; 1078 } 1079 1080 for( $i = 1; $i < count( $parameters ); $i++ ) 1081 { 1082 if ( eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 1083 { 1084 $compareParams[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 1085 $compareParamsCode[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 1086 } 1087 else 1088 { 1089 $values[] = $parameters[$i]; 1090 $compareParamsCode[] = '%' . count( $values ) . '%'; 1091 } 1092 } 1093 1094 switch( $operatorName ) 1095 { 1096 case $this->EndsWithName: 1097 { 1098 if ( count( $values ) == 0 ) 1099 { 1100 if ( $isString ) 1101 { 1102 $result = ( strpos ( $inParam, $compareParams[0] ) === ( strlen( $inParam ) - strlen ( $compareParams[0] ) ) ); 1103 } 1104 else if ( $isArray ) 1105 { 1106 $length = count( $inParam ); 1107 $params = count( $compareParams ); 1108 $start = $length - $params; 1109 1110 $result = true; 1111 for ( $i = 0; $i < $params; ++$i ) 1112 { 1113 if ( $inParam[$start + $i] != $compareParams[$i] ) 1114 { 1115 $result = false; 1116 break; 1117 } 1118 } 1119 } 1120 1121 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 1122 } 1123 1124 if ( $isString ) 1125 { 1126 $code = '%output% = ( strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === ( strlen( ' . $inParamCode . ' ) - strlen( ' . $compareParamsCode[0] . ' ) ) );'; 1127 } 1128 else if ( $isArray ) 1129 { 1130 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" . 1131 '%tmp1% = count( %tmp4% );' . "\n" . 1132 '%tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" . 1133 '%tmp3% = %tmp1% - %tmp2%;' . "\n" . 1134 '%output% = true;' . "\n"; 1135 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 1136 { 1137 if( $i != 0 ) 1138 $code .= 'else '; 1139 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 1140 ' %output% = false;' . "\n"; 1141 } 1142 1143 $tmpCount = 4; 1144 } 1145 else 1146 { 1147 $code = '%tmp4% = ' . $inParamCode . ';' . "\n" . 1148 'if ( is_string( %tmp4% ) )' . "\n" . 1149 '{' . "\n" . 1150 ' %output% = ( strpos( %tmp4%, ' . $compareParamsCode[0] . ' ) === ( strlen( %tmp4% ) - strlen( ' . $compareParamsCode[0] . ' ) ) );' . "\n" . 1151 '}' . "\n" . 1152 'else if( is_array( %tmp4% ) )' . "\n" . 1153 '{' . "\n" . 1154 ' %tmp1% = count( %tmp4% );' . "\n" . 1155 ' %tmp2% = ' . count( $compareParamsCode ) . ';' . "\n" . 1156 ' %tmp3% = %tmp1% - %tmp2%;' . "\n" . 1157 ' %output% = true;' . "\n"; 1158 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 1159 { 1160 if( $i != 0 ) 1161 $code .= ' else '; 1162 $code .= 'if ( %tmp4%[%tmp3% + ' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 1163 ' %output% = false;' . "\n"; 1164 } 1165 $code .= '}'; 1166 1167 $tmpCount = 4; 1168 } 1169 1170 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 1171 } break; 1172 1173 case $this->BeginsWithName: 1174 { 1175 if ( count( $values ) == 0 ) 1176 { 1177 if ( $isString ) 1178 { 1179 $result = ( strpos ( $inParam, $compareParams[0] ) == 0 ); 1180 } 1181 else if ( $isArray ) 1182 { 1183 $result = true; 1184 for ( $i = 0; $i < count( $compareParams ); ++$i ) 1185 { 1186 if ( $inParam[$i] != $compareParams[$i] ) 1187 { 1188 $result = false; 1189 break; 1190 } 1191 } 1192 } 1193 1194 return array( eZTemplateNodeTool::createBooleanElement( $result ) ); 1195 } 1196 1197 if ( $isString ) 1198 { 1199 $code = '%output% = ( ' . $compareParamsCode[0] . ' && strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) == 0 );'; 1200 } 1201 else if ( $isArray ) 1202 { 1203 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" . 1204 '%output% = true;' . "\n"; 1205 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 1206 { 1207 if( $i != 0 ) 1208 $code .= 'else '; 1209 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 1210 ' %output% = false;' . "\n"; 1211 } 1212 1213 $tmpCount = 1; 1214 } 1215 else 1216 { 1217 $code = '%tmp1% = ' . $inParamCode . ';' . "\n" . 1218 'if ( is_string( %tmp1% ) )' . "\n" . 1219 '{' . "\n" . 1220 " if ( {$compareParamsCode[0]} == '' )\n" . 1221 " %output% = false;\n" . 1222 " else\n" . 1223 ' %output% = ( strpos( %tmp1%, ' . $compareParamsCode[0] . ' ) === 0 );' . "\n" . 1224 '}' . "\n" . 1225 'else if( is_array( %tmp1% ) )' . "\n" . 1226 '{' . "\n" . 1227 ' %output% = true;' . "\n"; 1228 for( $i = 0 ; $i < count( $compareParamsCode ); ++$i ) 1229 { 1230 if( $i != 0 ) 1231 $code .= ' else '; 1232 $code .= 'if ( %tmp1%[' . $i . '] != ' . $compareParamsCode[$i] . ')' . "\n" . 1233 ' %output% = false;' . "\n"; 1234 } 1235 $code .= '}'; 1236 1237 $tmpCount = 1; 1238 } 1239 1240 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount ) ); 1241 } break; 1242 } 1243 } 1244 1245 /*! 1246 \reimp 1247 */ 1248 function extractTrans( $operatorName, &$node, &$tpl, &$resourceData, 1249 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 1250 { 1251 $offset = 0; 1252 $length = false; 1253 $values = array(); 1254 $code = ''; 1255 if ( $operatorName == $this->ExtractName ) 1256 { 1257 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 1258 { 1259 $offset = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 1260 $code .= (string)$offset; 1261 } 1262 else 1263 { 1264 $values[] = $parameters[1]; 1265 $code .= '%' . count ( $values ) . '%'; 1266 } 1267 } 1268 else if ( $operatorName == $this->ExtractRightName ) 1269 { 1270 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 1271 { 1272 $offset = -1 * eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 1273 $code .= (string)$offset; 1274 } 1275 else 1276 { 1277 $values[] = $parameters[1]; 1278 $code .= '-1 * %' . count ( $values ) . '%'; 1279 } 1280 } 1281 else 1282 { 1283 $code .= '0'; 1284 } 1285 1286 if ( $operatorName == $this->ExtractName ) 1287 { 1288 if ( isset( $parameters[2] ) and eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 1289 { 1290 $length = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 1291 $code .= ', ' . (string)$length; 1292 } 1293 else if ( isset( $parameters[2] ) ) 1294 { 1295 $values[] = $parameters[2]; 1296 $code .= ', ' . '%' . count ( $values ) . '%'; 1297 } 1298 } 1299 else if ( $operatorName == $this->ExtractLeftName ) 1300 { 1301 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 1302 { 1303 $length = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 1304 $code .= ', ' . (string)$length; 1305 } 1306 else 1307 { 1308 $values[] = $parameters[1]; 1309 $code .= ', ' . '%' . count ( $values ) . '%'; 1310 } 1311 } 1312 1313 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 1314 { 1315 if ( count( $values ) == 0 ) 1316 { 1317 $input = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1318 if ( $operatorName == $this->ExtractRightName or !$length ) 1319 { 1320 if ( is_string( $input ) ) 1321 $output = substr( $input, $offset ); 1322 else 1323 $output = array_slice( $input, $offset ); 1324 } 1325 else 1326 { 1327 if ( is_string( $input ) ) 1328 $output = substr( $input, $offset, $length ); 1329 else 1330 $output = array_slice( $input, $offset, $length ); 1331 } 1332 return array( eZTemplateNodeTool::createStaticElement( $output ) ); 1333 } 1334 else 1335 { 1336 $code = '%output = array_slice( ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ) . ', ' . $code . ' );'; 1337 } 1338 } 1339 else 1340 { 1341 $values[] = $parameters[0]; 1342 $code = ( "if ( is_string( %" . count( $values ) . "% ) )\n" . 1343 " %output% = substr( %" . count( $values ) . "%, " . $code . " );\n" . 1344 "else\n" . 1345 " %output% = array_slice( %" . count( $values ) . "%, " . $code . " );" ); 1346 } 1347 1348 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 1349 } 1350 1351 /*! 1352 \reimp 1353 */ 1354 function mergeTrans( $operatorName, &$node, &$tpl, &$resourceData, 1355 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 1356 { 1357 $code = ''; 1358 $stringCode = ''; 1359 1360 $paramCount = 0; 1361 $values = array(); 1362 $staticArray = array(); 1363 for ( $i = 1; $i < count( $parameters ); ++$i ) 1364 { 1365 if ( $i != 1 ) 1366 { 1367 $code .= ', '; 1368 $stringCode .= ', '; 1369 } 1370 1371 if ( !eZTemplateNodeTool::isStaticElement( $parameters[$i] ) ) 1372 { 1373 $values[] = $parameters[$i]; 1374 ++$paramCount; 1375 if ( $operatorName == $this->MergeName or 1376 $operatorName == $this->ArrayMergeName ) 1377 $code .= '%' . $paramCount . '%'; 1378 else 1379 $code .= 'array( %' . $paramCount . '% )'; 1380 $stringCode .= '%' . $paramCount . '%'; 1381 } 1382 else 1383 { 1384 if ( $paramCount == 0 ) 1385 { 1386 $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[$i] ); 1387 } 1388 if ( $operatorName == $this->MergeName or 1389 $operatorName == $this->ArrayMergeName ) 1390 $code .= '' . eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ) . ''; 1391 else 1392 { 1393 $tmp_check = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 1394 // hiding "%1%", "%output%" etc. in static input string to avoid replacing it on "$var" inside compiler. 1395 $tmp_check = str_replace( "%", '"."%"."', $tmp_check ); 1396 $code .= 'array( ' . $tmp_check . ' )'; 1397 } 1398 $stringCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[$i] ), 0, 0, false ); 1399 } 1400 } 1401 1402 $isString = false; 1403 $isArray = false; 1404 $code2 = false; 1405 if ( $parameters[0] ) 1406 { 1407 if ( !eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 1408 { 1409 $values[] = $parameters[0]; 1410 ++$paramCount; 1411 $code2 = '%' . $paramCount . '%'; 1412 } 1413 else 1414 { 1415 $isString = is_string( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 1416 $isArray = is_array( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ); 1417 if ( $paramCount == 0 ) 1418 { 1419 // $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1420 } 1421 else 1422 { 1423 $code2 = eZPHPCreator::variableText( eZTemplateNodeTool::elementStaticValue( $parameters[0] ), 0, 0, false ); 1424 } 1425 } 1426 } 1427 1428 if ( $paramCount == 0 ) 1429 { 1430 if ( $operatorName == $this->AppendName or 1431 $operatorName == $this->ArrayAppendName or 1432 $operatorName == $this->MergeName or 1433 $operatorName == $this->ArrayMergeName ) 1434 { 1435 if ( $isString ) 1436 { 1437 $str = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1438 for( $i = 0; $i < count( $staticArray ); ++$i ) 1439 { 1440 $str .= $staticArray[$i]; 1441 } 1442 1443 return array( eZTemplateNodeTool::createStringElement( $str ) ); 1444 } 1445 else if ( $isArray ) 1446 { 1447 $returnArray = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); 1448 for( $i = 0; $i < count( $staticArray ); ++$i ) 1449 { 1450 $returnArray = array_merge( $returnArray, $staticArray[$i] ); 1451 } 1452 return array( eZTemplateNodeTool::createArrayElement( $returnArray ) ); 1453 } 1454 } 1455 else if ( $operatorName == $this->PrependName or 1456 $operatorName == $this->ArrayPrependName ) 1457 { 1458 if ( $isString ) 1459 { 1460 return array( eZTemplateNodeTool::createStringElement( eZTemplateNodeTool::elementStaticValue( $parameters[1] ) . eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ); 1461 } 1462 else if ( $isArray ) 1463 { 1464 return array( eZTemplateNodeTool::createArrayElement( array_merge( $staticArray, eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ) ); 1465 } 1466 } 1467 } 1468 1469 if ( $code2 ) 1470 { 1471 if ( $operatorName == $this->AppendName ) 1472 { 1473 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" . 1474 ' %output% = ' . $code2 . ' . implode( \'\', array( ' . $stringCode . ' ) );' . "\n" . 1475 'else if( is_array( ' . $code2 . ' ) )' . "\n" . 1476 ' %output% = array_merge( ' . $code2 . ', ' . $code . ' );' ); 1477 } 1478 else if ( $operatorName == $this->ArrayAppendName ) 1479 { 1480 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 1481 } 1482 else if ( $operatorName == $this->MergeName ) 1483 { 1484 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 1485 } 1486 else if ( $operatorName == $this->ArrayMergeName ) 1487 { 1488 $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; 1489 } 1490 else if ( $operatorName == $this->PrependName ) 1491 { 1492 $code = ( 'if ( is_string( ' . $code2 . ' ) )' . "\n" . 1493 ' %output% = implode( \'\', array( ' . $stringCode . ' ) ) . ' . $code2 . ';' . "\n" . 1494 'else if( is_array( ' . $code2 . ' ) )' . "\n" . 1495 ' %output% = array_merge( ' . $code . ', ' . $code2 . ' );' ); 1496 } 1497 else if ( $operatorName == $this->ArrayPrependName ) 1498 { 1499 $code = '%output% = array_merge( ' . $code . ', ' . $code2 . ' );'; 1500 } 1501 } 1502 else 1503 { 1504 if ( $operatorName == $this->MergeName ) 1505 { 1506 $code = '%output% = array_merge( ' . $code . ' );'; 1507 } 1508 else 1509 { 1510 $code = '%output% = array(' . $code . ');'; 1511 } 1512 } 1513 1514 return array( eZTemplateNodeTool::createCodePieceElement( $code . "\n", $values ) ); 1515 } 1516 1517 /*! 1518 \return true to tell the template engine that the parameter list exists per operator type. 1519 */ 1520 function namedParameterPerOperator() 1521 { 1522 return true; 1523 } 1524 /*! 1525 See eZTemplateOperator::namedParameterList() 1526 */ 1527 function namedParameterList() 1528 { 1529 return array( $this->RemoveName => array( 'offset' => array( "type" => "integer", 1530 "required" => true, 1531 "default" => false ), 1532 'length' => array( "type" => "integer", 1533 "required" => false, 1534 "default" => 1 ) ), 1535 $this->RepeatName => array( 'repeat_times' => array( "type" => "integer", 1536 "required" => false, 1537 "default" => 1 ) ), 1538 $this->InsertName => array( 'insert_position' => array( "type" => "integer", 1539 "required" => true, 1540 "default" => false ), 1541 'insert_string' => array( "type" => "string", 1542 "required" => true, 1543 "default" => false ) ), 1544 $this->ExplodeName => array( 'explode_first' => array( "type" => "mixed", 1545 "required" => true, 1546 "default" => false ) ), 1547 $this->ExtractName => array( 'extract_start' => array( "type" => "integer", 1548 "required" => true, 1549 "default" => false ), 1550 'extract_length' => array( "type" => "integer", 1551 "required" => false, 1552 "default" => false ) ), 1553 $this->ExtractLeftName => array( 'length' => array( "type" => "integer", 1554 "required" => true, 1555 "default" => false ) ), 1556 $this->ExtractRightName => array( 'length' => array( "type" => "integer", 1557 "required" => true, 1558 "default" => false ) ), 1559 $this->ReplaceName => array( 'offset' => array( "type" => "integer", 1560 "required" => true, 1561 "default" => false), 1562 'length' => array( "type" => "integer", 1563 "required" => false, 1564 "default" => false) ), 1565 $this->PrependName => array( 'prepend_string' => array( "type" => "string", 1566 "required" => false, 1567 "default" => false ) ), 1568 $this->ContainsName => array( 'match' => array( "type" => "string", 1569 "required" => true, 1570 "default" => false ) ), 1571 $this->BeginsWithName => array( 'match' => array( "type" => "string", 1572 "required" => true, 1573 "default" => false ) ), 1574 $this->EndsWithName => array( 'match' => array( "type" => "string", 1575 "required" => true, 1576 "default" => false ) ), 1577 $this->ImplodeName => array( 'separator' => array( "type" => "string", 1578 "required" => true, 1579 "default" => false) ), 1580 $this->CompareName => array( 'compare' => array( "type" => "mixed", 1581 "required" => true, 1582 "default" => false ) ) ); 1583 } 1584 1585 function modify( &$tpl, &$operatorName, &$operatorParameters, 1586 &$rootNamespace, &$currentNamespace, &$operatorValue, 1587 &$namedParameters, $placement ) 1588 { 1589 switch( $operatorName ) 1590 { 1591 case $this->ArrayName: 1592 { 1593 $operatorValue = array(); 1594 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 1595 { 1596 $operatorValue[] =& $tpl->elementValue( $operatorParameters[$i], 1597 $rootNamespace, 1598 $currentNamespace, 1599 $placement ); 1600 } 1601 return; 1602 }break; 1603 1604 case $this->HashName: 1605 { 1606 $operatorValue = array(); 1607 $hashCount = (int)( count( $operatorParameters ) / 2 ); 1608 for ( $i = 0; $i < $hashCount; ++$i ) 1609 { 1610 $hashName = $tpl->elementValue( $operatorParameters[$i*2], 1611 $rootNamespace, 1612 $currentNamespace, 1613 $placement ); 1614 if ( is_string( $hashName ) or 1615 is_numeric( $hashName ) ) 1616 $operatorValue[$hashName] =& $tpl->elementValue( $operatorParameters[($i*2)+1], 1617 $rootNamespace, 1618 $currentNamespace, 1619 $placement ); 1620 else 1621 $tpl->error( $operatorName, 1622 "Unknown hash key type '" . gettype( $hashName ) . "', skipping", 1623 $placement ); 1624 } 1625 return; 1626 } 1627 break; 1628 1629 case $this->ArraySumName: 1630 { 1631 if ( is_array( $operatorValue ) ) 1632 { 1633 $operatorValue = array_sum( $operatorValue ); 1634 } 1635 else 1636 { 1637 $tpl->error( $operatorName, 1638 "Unknown input type, can only work with arrays '" . gettype( $operatorValue ) . "'", 1639 $placement ); 1640 } 1641 return; 1642 } 1643 break; 1644 } 1645 1646 $isArray = false; 1647 if ( isset( $operatorParameters[0] ) and 1648 is_array( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ) ) ) 1649 $isArray = true; 1650 1651 if ( is_array( $operatorValue ) ) 1652 $isArray = true; 1653 1654 if ( $isArray ) 1655 { 1656 switch( $operatorName ) 1657 { 1658 // Append or prepend an array (or single elements) to the target array: 1659 case $this->ArrayPrependName: 1660 case $this->ArrayAppendName: 1661 case $this->PrependName: 1662 case $this->AppendName: 1663 { 1664 $i = 0; 1665 if ( is_array( $operatorValue ) ) 1666 { 1667 if ( count( $operatorParameters ) < 1 ) 1668 { 1669 $tpl->error( $operatorName, 1670 "Requires at least one item!", 1671 $placement ); 1672 return; 1673 } 1674 $mainArray = $operatorValue; 1675 } 1676 else 1677 { 1678 if ( count( $operatorParameters ) < 2 ) 1679 { 1680 $tpl->error( $operatorName, 1681 "Requires an array (and at least one item)!", 1682 $placement ); 1683 return; 1684 } 1685 $mainArray =& $tpl->elementValue( $operatorParameters[$i++], 1686 $rootNamespace, 1687 $currentNamespace, 1688 $placement ); 1689 } 1690 $tmpArray = array(); 1691 for ( ; $i < count( $operatorParameters ); ++$i ) 1692 { 1693 $tmpArray[] =& $tpl->elementValue( $operatorParameters[$i], 1694 $rootNamespace, 1695 $currentNamespace, 1696 $placement ); 1697 } 1698 if ( $operatorName == $this->ArrayPrependName or $operatorName == $this->PrependName ) 1699 $operatorValue = array_merge( $tmpArray, $mainArray ); 1700 else 1701 $operatorValue = array_merge( $mainArray, $tmpArray ); 1702 1703 } 1704 break; 1705 1706 // Merge two arrays: 1707 case $this->ArrayMergeName: 1708 case $this->MergeName: 1709 { 1710 $tmpArray = array(); 1711 $tmpArray[] = $operatorValue; 1712 1713 if ( count( $operatorParameters ) < 1 ) 1714 { 1715 $tpl->error( $operatorName, "Requires an array (and at least one item!)", 1716 $placement ); 1717 return; 1718 } 1719 1720 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 1721 { 1722 $tmpArray[] =& $tpl->elementValue( $operatorParameters[$i], 1723 $rootNamespace, 1724 $currentNamespace, 1725 $placement ); 1726 } 1727 $operatorValue = call_user_func_array( 'array_merge', $tmpArray ); 1728 }break; 1729 1730 // Check if the array contains a specified element: 1731 case $this->ContainsName: 1732 { 1733 if ( count( $operatorParameters ) < 1 ) 1734 { 1735 $tpl->error( $operatorName, "Missing matching value!", 1736 $placement ); 1737 return; 1738 } 1739 $matchValue =& $tpl->elementValue( $operatorParameters[0], 1740 $rootNamespace, 1741 $currentNamespace, 1742 $placement ); 1743 1744 $operatorValue = in_array( $matchValue, $operatorValue ); 1745 } 1746 break; 1747 1748 // Compare two arrays: 1749 case $this->CompareName: 1750 { 1751 if ( count( array_diff( $operatorValue, $namedParameters['compare'] ) ) != 0 or 1752 count( array_diff( $namedParameters['compare'], $operatorValue ) ) != 0 ) 1753 { 1754 $operatorValue = false; 1755 } 1756 else 1757 { 1758 $operatorValue = true; 1759 } 1760 } 1761 break; 1762 1763 // Extract a portion of the array: 1764 case $this->ExtractName: 1765 { 1766 if ( $namedParameters['extract_length'] === false ) 1767 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'] ); 1768 else 1769 $operatorValue = array_slice( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] ); 1770 } 1771 break; 1772 1773 // Extract a portion from the start of the array: 1774 case $this->ExtractLeftName: 1775 { 1776 $operatorValue = array_slice( $operatorValue, 0, $namedParameters['length'] ); 1777 }break; 1778 1779 // Extract a portion from the end of the array: 1780 case $this->ExtractRightName: 1781 { 1782 $index = count( $operatorValue ) - $namedParameters['length']; 1783 $operatorValue = array_slice( $operatorValue, $index ); 1784 }break; 1785 1786 // Check if the array begins with a given sequence: 1787 case $this->BeginsWithName: 1788 { 1789 for ( $i = 0; $i < count( $operatorParameters ); $i++ ) 1790 { 1791 $test = $tpl->elementValue( $operatorParameters[$i], 1792 $rootNamespace, 1793 $currentNamespace, 1794 $placement ); 1795 1796 if ( $operatorValue[$i] != $test ) 1797 { 1798 $operatorValue = false; 1799 return; 1800 } 1801 } 1802 1803 $operatorValue = true; 1804 }break; 1805 1806 // Check if the array ends with a given sequence: 1807 case $this->EndsWithName: 1808 { 1809 $length = count( $operatorValue ); 1810 $params = count( $operatorParameters ); 1811 1812 $start = $length - $params; 1813 1814 for ( $i = 0; $i < $params; $i++ ) 1815 { 1816 $test = $tpl->elementValue( $operatorParameters[$i], 1817 $rootNamespace, 1818 $currentNamespace, 1819 $placement ); 1820 1821 if ( $operatorValue[$start+$i] != $test ) 1822 { 1823 $operatorValue = false; 1824 return; 1825 } 1826 } 1827 $operatorValue = true; 1828 }break; 1829 1830 // Create a string containing the array elements with the separator string between elements. 1831 case $this->ImplodeName: 1832 { 1833 $operatorValue = implode( $operatorValue, $namedParameters['separator'] ); 1834 }break; 1835 1836 // Explode the array by making smaller arrays of it: 1837 case $this->ExplodeName: 1838 { 1839 $array_one = array(); 1840 $array_two = array(); 1841 1842 $array_one = array_slice( $operatorValue, 0, $namedParameters['explode_first'] ); 1843 $array_two = array_slice( $operatorValue, $namedParameters['explode_first'] ); 1844 1845 $operatorValue = array( $array_one, $array_two ); 1846 }break; 1847 1848 // Repeat the contents of an array a specified number of times: 1849 case $this->RepeatName: 1850 { 1851 $arrayElement = $operatorValue; 1852 $count = $namedParameters['repeat_times']; 1853 $operatorValue = array(); 1854 for ( $i = 0; $i < $count; $i++) 1855 { 1856 $operatorValue = array_merge( $operatorValue, $arrayElement ); 1857 } 1858 }break; 1859 1860 // Reverse the contents of the array: 1861 case $this->ReverseName: 1862 { 1863 $operatorValue = array_reverse( $operatorValue ); 1864 }break; 1865 1866 // Insert an array (or element) into a position in the target array: 1867 case $this->InsertName: 1868 { 1869 $array_one = array_slice( $operatorValue, 0, $namedParameters['insert_position'] ); 1870 $array_two = array_slice( $operatorValue, $namedParameters['insert_position'] ); 1871 1872 1873 $array_to_insert = array(); 1874 for ( $i = 1; $i < count( $operatorParameters ); ++$i ) 1875 { 1876 $array_to_insert[] =& $tpl->elementValue( $operatorParameters[$i], 1877 $rootNamespace, 1878 $currentNamespace, 1879 $placement ); 1880 } 1881 1882 $operatorValue = array_merge( $array_one, $array_to_insert, $array_two ); 1883 }break; 1884 1885 // Remove a specified element (or portion) from the target array: 1886 case $this->RemoveName: 1887 { 1888 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] ); 1889 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 1890 1891 $operatorValue = array_merge( $array_one, $array_two ); 1892 }break; 1893 1894 // Replace a portion of the array: 1895 case $this->ReplaceName: 1896 { 1897 $array_one = array_slice( $operatorValue, 0, $namedParameters['offset'] ); 1898 $array_two = array_slice( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 1899 $array_mid = array(); 1900 1901 for ( $i = 2; $i < count( $operatorParameters ); ++ $i ) 1902 { 1903 $array_mid[] =& $tpl->elementValue( $operatorParameters[$i], 1904 $rootNamespace, 1905 $currentNamespace, 1906 $placement ); 1907 } 1908 1909 $operatorValue = array_merge( $array_one, $array_mid, $array_two ); 1910 } break; 1911 1912 // Removes duplicate values from array: 1913 case $this->UniqueName: 1914 { 1915 $operatorValue = array_unique( $operatorValue ); 1916 }break; 1917 1918 // Default case: 1919 default: 1920 { 1921 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement ); 1922 } 1923 break; 1924 } 1925 } 1926 else if ( is_string( $operatorValue ) ) 1927 { 1928 switch( $operatorName ) 1929 { 1930 // Not implemented. 1931 case $this->ArrayName: 1932 { 1933 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 1934 }break; 1935 1936 // Not implemented. 1937 case $this->HashName: 1938 { 1939 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 1940 } 1941 break; 1942 1943 // Add a string at the beginning of the input/target string: 1944 case $this->PrependName: 1945 { 1946 $operatorValue = $namedParameters['prepend_string'].$operatorValue; 1947 }break; 1948 1949 // Add a string at the end of the input/target string: 1950 case $this->AppendName: 1951 { 1952 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 1953 { 1954 $operatorValue .= $tpl->elementValue( $operatorParameters[$i], 1955 $rootNamespace, 1956 $currentNamespace, 1957 $placement ); 1958 } 1959 1960 }break; 1961 1962 // Not implemented. 1963 case $this->MergeName: 1964 { 1965 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 1966 }break; 1967 1968 // Check if the string contains a specified sequence of chars/string. 1969 case $this->ContainsName: 1970 { 1971 $operatorValue = ( strpos( $operatorValue, $namedParameters['match'] ) !== false ); 1972 } 1973 break; 1974 1975 // Compare two strings: 1976 case $this->CompareName: 1977 { 1978 if ( $operatorValue == $namedParameters['compare'] ) 1979 { 1980 $operatorValue = true; 1981 } 1982 else 1983 { 1984 $operatorValue = false; 1985 } 1986 } 1987 break; 1988 1989 // Extract a portion from/of a string: 1990 case $this->ExtractName: 1991 { 1992 if ( $namedParameters['extract_length'] === false ) 1993 $operatorValue = substr( $operatorValue, $namedParameters['extract_start'] ); 1994 else 1995 $operatorValue = substr( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] ); 1996 } 1997 break; 1998 1999 // Extract string/portion from the start of the string. 2000 case $this->ExtractLeftName: 2001 { 2002 $operatorValue = substr( $operatorValue, 0, $namedParameters['length'] ); 2003 }break; 2004 2005 // Extract string/portion from the end of the string. 2006 case $this->ExtractRightName: 2007 { 2008 $offset = strlen( $operatorValue ) - $namedParameters['length']; 2009 $operatorValue = substr( $operatorValue, $offset ); 2010 }break; 2011 2012 // Check if string begins with specified sequence: 2013 case $this->BeginsWithName: 2014 { 2015 if ( strpos( $operatorValue, $namedParameters['match'] ) === 0 ) 2016 { 2017 $operatorValue = true; 2018 } 2019 else 2020 { 2021 $operatorValue = false; 2022 } 2023 }break; 2024 2025 // Check if string ends with specified sequence: 2026 case $this->EndsWithName: 2027 { 2028 if ( strpos( $operatorValue, $namedParameters['match'] ) === ( strlen( $operatorValue ) - strlen ($namedParameters['match'] ) ) ) 2029 { 2030 $operatorValue = true; 2031 } 2032 else 2033 { 2034 $operatorValue = false; 2035 } 2036 }break; 2037 2038 // Only works with arrays. 2039 case $this->ImplodeName: 2040 { 2041 $tpl->warning( $operatorName, "$operatorName only works with arrays", $placement ); 2042 }break; 2043 2044 // Explode string (split a string by string). 2045 case $this->ExplodeName: 2046 { 2047 $operatorValue = explode( $namedParameters['explode_first'], $operatorValue ); 2048 }break; 2049 2050 // Repeat string n times: 2051 case $this->RepeatName: 2052 { 2053 $operatorValue = str_repeat( $operatorValue, $namedParameters['repeat_times'] ); 2054 }break; 2055 2056 // Reverse contents of string: 2057 case $this->ReverseName: 2058 { 2059 $operatorValue = strrev( $operatorValue ); 2060 }break; 2061 2062 // Insert a given string at a specified position: 2063 case $this->InsertName: 2064 { 2065 $first = substr( $operatorValue, 0, $namedParameters['insert_position'] ); 2066 $second = substr( $operatorValue, $namedParameters['insert_position'] ); 2067 $operatorValue = $first . $namedParameters['insert_string'] . $second; 2068 }break; 2069 2070 // Remove a portion from a string: 2071 case $this->RemoveName: 2072 { 2073 $first = substr( $operatorValue, 0, $namedParameters['offset'] ); 2074 $second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 2075 $operatorValue = $first . $second; 2076 }break; 2077 2078 // Replace a portion of a string: 2079 case $this->ReplaceName: 2080 { 2081 $first = substr( $operatorValue, 0, $namedParameters['offset'] ); 2082 $second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] ); 2083 $mid = ''; 2084 2085 for ( $i = 2; $i < count( $operatorParameters ); ++ $i ) 2086 { 2087 $mid .= $tpl->elementValue( $operatorParameters[$i], 2088 $rootNamespace, 2089 $currentNamespace, 2090 $placement ); 2091 } 2092 2093 $operatorValue = $first . $mid . $second; 2094 }break; 2095 2096 // Not implemented. 2097 case $this->UniqueName: 2098 { 2099 $tpl->warning( $operatorName, "$operatorName works only with arrays.", $placement ); 2100 }break; 2101 2102 // Default case: 2103 default: 2104 { 2105 $tpl->warning( $operatorName, "Unknown operatorname: $operatorName", $placement ); 2106 } 2107 break; 2108 } 2109 } 2110 // ..or something else? -> We're building the array: 2111 else 2112 { 2113 $operatorValue = array(); 2114 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 2115 { 2116 $operatorValue[] =& $tpl->elementValue( $operatorParameters[$i], 2117 $rootNamespace, 2118 $currentNamespace, 2119 $placement ); 2120 } 2121 } 2122 } 2123 2124 /// \privatesection 2125 var $Operators; 2126 var $ArrayName; 2127 var $HashName; 2128 } 2129 2130 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |