00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 class eZTemplateArithmeticOperator
00063 {
00064
00065
00066
00067 function eZTemplateArithmeticOperator()
00068 {
00069 $this->Operators = array( 'sum', 'sub', 'inc', 'dec',
00070 'div', 'mod', 'mul',
00071 'max', 'min',
00072 'abs', 'ceil', 'floor', 'round',
00073 'int', 'float',
00074 'count',
00075 'roman',
00076 'rand' );
00077 foreach ( $this->Operators as $operator )
00078 {
00079 $name = $operator . 'Name';
00080 $name[0] = $name[0] & "\xdf";
00081 $this->$name = $operator;
00082 }
00083 }
00084
00085
00086
00087
00088 function &operatorList()
00089 {
00090 return $this->Operators;
00091 }
00092
00093 function operatorTemplateHints()
00094 {
00095 return array( $this->SumName => array( 'input' => true,
00096 'output' => true,
00097 'parameters' => true,
00098 'element-transformation' => true,
00099 'transform-parameters' => true,
00100 'input-as-parameter' => true,
00101 'element-transformation-func' => 'basicTransformation'),
00102 $this->SubName => array( 'input' => true,
00103 'output' => true,
00104 'parameters' => true,
00105 'element-transformation' => true,
00106 'transform-parameters' => true,
00107 'input-as-parameter' => true,
00108 'element-transformation-func' => 'basicTransformation'),
00109 $this->MulName => array( 'input' => true,
00110 'output' => true,
00111 'parameters' => true,
00112 'element-transformation' => true,
00113 'transform-parameters' => true,
00114 'input-as-parameter' => true,
00115 'element-transformation-func' => 'basicTransformation'),
00116 $this->DivName => array( 'input' => true,
00117 'output' => true,
00118 'parameters' => true,
00119 'element-transformation' => true,
00120 'transform-parameters' => true,
00121 'input-as-parameter' => true,
00122 'element-transformation-func' => 'basicTransformation'),
00123
00124 $this->IncName => array( 'input' => true,
00125 'output' => true,
00126 'parameters' => 1,
00127 'element-transformation' => true,
00128 'transform-parameters' => true,
00129 'input-as-parameter' => true,
00130 'element-transformation-func' => 'decIncTransformation'),
00131 $this->DecName => array( 'input' => true,
00132 'output' => true,
00133 'parameters' => 1,
00134 'element-transformation' => true,
00135 'transform-parameters' => true,
00136 'input-as-parameter' => true,
00137 'element-transformation-func' => 'decIncTransformation'),
00138
00139 $this->ModName => array( 'input' => true,
00140 'output' => true,
00141 'parameters' => 2,
00142 'element-transformation' => true,
00143 'transform-parameters' => true,
00144 'input-as-parameter' => true,
00145 'element-transformation-func' => 'modTransformation'),
00146
00147 $this->MaxName => array( 'input' => true,
00148 'output' => true,
00149 'parameters' => true,
00150 'element-transformation' => true,
00151 'transform-parameters' => true,
00152 'input-as-parameter' => true,
00153 'element-transformation-func' => 'minMaxTransformation'),
00154 $this->MinName => array( 'input' => true,
00155 'output' => true,
00156 'parameters' => true,
00157 'element-transformation' => true,
00158 'transform-parameters' => true,
00159 'input-as-parameter' => true,
00160 'element-transformation-func' => 'minMaxTransformation'),
00161
00162 $this->AbsName => array( 'input' => true,
00163 'output' => true,
00164 'parameters' => 1,
00165 'element-transformation' => true,
00166 'transform-parameters' => true,
00167 'input-as-parameter' => true,
00168 'element-transformation-func' => 'roundTransformation'),
00169 $this->CeilName => array( 'input' => true,
00170 'output' => true,
00171 'parameters' => 1,
00172 'element-transformation' => true,
00173 'transform-parameters' => true,
00174 'input-as-parameter' => true,
00175 'element-transformation-func' => 'roundTransformation'),
00176 $this->FloorName => array( 'input' => true,
00177 'output' => true,
00178 'parameters' => 1,
00179 'element-transformation' => true,
00180 'transform-parameters' => true,
00181 'input-as-parameter' => true,
00182 'element-transformation-func' => 'roundTransformation'),
00183 $this->RoundName => array( 'input' => true,
00184 'output' => true,
00185 'parameters' => 1,
00186 'element-transformation' => true,
00187 'transform-parameters' => true,
00188 'input-as-parameter' => true,
00189 'element-transformation-func' => 'roundTransformation'),
00190
00191 $this->IntName => array( 'input' => true,
00192 'output' => true,
00193 'parameters' => 1,
00194 'element-transformation' => true,
00195 'transform-parameters' => true,
00196 'input-as-parameter' => true,
00197 'element-transformation-func' => 'castTransformation'),
00198 $this->FloatName => array( 'input' => true,
00199 'output' => true,
00200 'parameters' => 1,
00201 'element-transformation' => true,
00202 'transform-parameters' => true,
00203 'input-as-parameter' => true,
00204 'element-transformation-func' => 'castTransformation'),
00205
00206 $this->RomanName => array( 'input' => true,
00207 'output' => true,
00208 'parameters' => 1,
00209 'element-transformation' => true,
00210 'transform-parameters' => true,
00211 'input-as-parameter' => true,
00212 'element-transformation-func' => 'romanTransformation'),
00213
00214 $this->CountName => array( 'input' => true,
00215 'output' => true,
00216 'parameters' => 1 ),
00217
00218 $this->RandName => array( 'input' => true,
00219 'output' => true,
00220 'parameters' => true,
00221 'element-transformation' => true,
00222 'transform-parameters' => true,
00223 'input-as-parameter' => true,
00224 'element-transformation-func' => 'randTransformation') );
00225 }
00226
00227 function basicTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00228 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00229 {
00230 $values = array();
00231 $function = $operatorName;
00232 $divOperation = false;
00233 if ( $function == $this->SumName )
00234 {
00235 $operator = '+';
00236 }
00237 else if ( $function == $this->SubName )
00238 {
00239 $operator = '-';
00240 }
00241 else if ( $function == $this->MulName )
00242 {
00243 $operator = '*';
00244 }
00245 else
00246 {
00247 $divOperation = true;
00248 $operator = '/';
00249 }
00250
00251 if ( count( $parameters ) == 0 )
00252 return false;
00253 $newElements = array();
00254
00255
00256
00257 $notInitialised = true;
00258 $staticResult = 0;
00259 $isStaticFirst = false;
00260 $allNumeric = true;
00261 $newParameters = array();
00262 $endParameters = array();
00263 $parameterIndex = 0;
00264 foreach ( $parameters as $parameter )
00265 {
00266 if ( !eZTemplateNodeTool::isStaticElement( $parameter ) )
00267 {
00268 $allNumeric = false;
00269 $endParameters[] = $parameter;
00270 }
00271 else
00272 {
00273 $staticValue = eZTemplateNodeTool::elementStaticValue( $parameter );
00274 if ( $notInitialised )
00275 {
00276 $staticResult = $staticValue;
00277 if ( $parameterIndex == 0 )
00278 $isStaticFirst = true;
00279 $notInitialised = false;
00280 }
00281 else
00282 {
00283 if ( $function == 'sum' )
00284 {
00285 $staticResult += $staticValue;
00286 }
00287 else if ( $function == 'sub' )
00288 {
00289 if ( $isStaticFirst )
00290 $staticResult -= $staticValue;
00291 else
00292 $staticResult += $staticValue;
00293 }
00294 else if ( $function == 'mul' )
00295 {
00296 $staticResult *= $staticValue;
00297 }
00298 else
00299 {
00300 if ( $isStaticFirst )
00301 $staticResult /= $staticValue;
00302 else
00303 $staticResult *= $staticValue;
00304 }
00305 }
00306 $isPreviousStatic = true;
00307 }
00308 ++$parameterIndex;
00309 }
00310
00311 if ( $allNumeric )
00312 {
00313 $newElements[] = eZTemplateNodeTool::createNumericElement( $staticResult );
00314 return $newElements;
00315 }
00316 else
00317 {
00318 if ( !$notInitialised )
00319 {
00320 if ( $isStaticFirst )
00321 $newParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00322 else
00323 $endParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00324 }
00325 $newParameters = array_merge( $newParameters, $endParameters );
00326
00327 $code = '';
00328 if ( $divOperation )
00329 {
00330 $code .= '@';
00331 }
00332 $code .= '%output% =';
00333 $counter = 1;
00334 $index = 0;
00335
00336
00337 require_once( 'lib/compat.php' );
00338
00339 foreach ( $newParameters as $parameter )
00340 {
00341 if ( $index > 0 )
00342 {
00343 $code .= " $operator";
00344 }
00345 if ( eZTemplateNodeTool::isStaticElement( $parameter ) )
00346 {
00347 $staticValue = eZTemplateNodeTool::elementStaticValue( $parameter );
00348 if ( !is_numeric( $staticValue ) )
00349 $staticValue = (int)$staticValue;
00350 $code .= ezsprintf(" %F", $staticValue);
00351 }
00352 else
00353 {
00354 $code .= " %$counter%";
00355 $values[] = $parameter;
00356 ++$counter;
00357 }
00358 ++$index;
00359 }
00360 $code .= ";\n";
00361 }
00362 $knownType = 'integer';
00363 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, false, $knownType );
00364 return $newElements;
00365 }
00366
00367 function minMaxTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00368 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00369 {
00370 $values = array();
00371 $function = $operatorName;
00372
00373 if ( count( $parameters ) == 0 )
00374 return false;
00375 $newElements = array();
00376
00377
00378 $staticResult = array();
00379 $allNumeric = true;
00380 foreach ( $parameters as $parameter )
00381 {
00382 if ( !eZTemplateNodeTool::isStaticElement( $parameter ) )
00383 {
00384 $allNumeric = false;
00385 }
00386 else
00387 {
00388 $staticResult[] = eZTemplateNodeTool::elementStaticValue( $parameter );
00389 }
00390 }
00391
00392 if ( $allNumeric )
00393 {
00394 $staticResult = $function( $staticResult );
00395 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00396 }
00397 else
00398 {
00399 $code = "%output% = $function(";
00400 $counter = 1;
00401 foreach ( $parameters as $parameter )
00402 {
00403 if ( $counter > 1 )
00404 {
00405 $code .= ', ';
00406 }
00407 $code .= " %$counter%";
00408 $values[] = $parameter;
00409 ++$counter;
00410 }
00411 $code .= ");\n";
00412 }
00413 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00414 return $newElements;
00415 }
00416
00417 function modTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00418 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00419 {
00420 $values = array();
00421 if ( count( $parameters ) != 2 )
00422 return false;
00423 $newElements = array();
00424
00425 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) && eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00426 {
00427 $staticResult = eZTemplateNodeTool::elementStaticValue( $parameters[0] ) % eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00428 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00429 }
00430 else
00431 {
00432 $code = "%output% = %1% % %2%;\n";
00433 $values[] = $parameters[0];
00434 $values[] = $parameters[1];
00435 }
00436 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00437 return $newElements;
00438 }
00439
00440 function roundTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00441 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00442 {
00443 $values = array();
00444 $function = $operatorName;
00445
00446 if ( count( $parameters ) != 1 )
00447 return false;
00448 $newElements = array();
00449
00450 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00451 {
00452 $staticResult = $function( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) );
00453 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00454 }
00455 else
00456 {
00457 $code = "%output% = $function( %1% );\n";
00458 $values[] = $parameters[0];
00459 }
00460 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00461 return $newElements;
00462 }
00463
00464 function decIncTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00465 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00466 {
00467 $values = array();
00468 $function = $operatorName;
00469 $direction = $this->DecName == $function ? -1 : 1;
00470
00471 if ( count( $parameters ) < 1 )
00472 return false;
00473 $newElements = array();
00474
00475 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00476 {
00477 return array( eZTemplateNodeTool::createNumericElement( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) + $direction ) );
00478 }
00479 else
00480 {
00481 $code = "%output% = %1% + $direction;\n";
00482 $values[] = $parameters[0];
00483 }
00484 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00485 return $newElements;
00486 }
00487
00488 function castTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00489 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00490 {
00491 $values = array();
00492 if ( count( $parameters ) != 1 )
00493 return false;
00494 $newElements = array();
00495
00496 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00497 {
00498 $staticResult = ( $operatorName == $this->IntName ) ? (int) eZTemplateNodeTool::elementStaticValue( $parameters[0] ) : (float) eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00499 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00500 }
00501 else
00502 {
00503 $code = "%output% = ($operatorName)%1%;\n";
00504 $values[] = $parameters[0];
00505 }
00506 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00507 return $newElements;
00508 }
00509
00510 function randTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00511 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00512 {
00513 $paramCount = count( $parameters );
00514 if ( $paramCount != 0 ||
00515 $paramCount != 2 )
00516 {
00517 return false;
00518 }
00519 $values = array();
00520 $newElements = array();
00521
00522 if ( $paramCount == 2 )
00523 {
00524 $code = "%output% = mt_rand( %1%, %2% );\n";
00525 $values[] = $parameters[0];
00526 $values[] = $parameters[1];
00527 }
00528 else
00529 {
00530 $code = "%output% = mt_rand();\n";
00531 }
00532
00533 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00534 return $newElements;
00535 }
00536
00537 function romanTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00538 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00539 {
00540 $values = array();
00541 if ( count( $parameters ) != 1 )
00542 return false;
00543 $newElements = array();
00544
00545 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00546 {
00547 $staticResult = $this->buildRoman( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) );
00548 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00549 }
00550 else
00551 {
00552 return false;
00553 }
00554 }
00555
00556
00557
00558
00559 function namedParameterPerOperator()
00560 {
00561 return true;
00562 }
00563
00564
00565
00566
00567 function namedParameterList()
00568 {
00569 return array( $this->IncName => array( 'value' => array( 'type' => 'mixed',
00570 'required' => false,
00571 'default' => false ) ),
00572 $this->DecName => array( 'value' => array( 'type' => 'mixed',
00573 'required' => false,
00574 'default' => false ) ),
00575 $this->RomanName => array( 'value' => array( 'type' => 'mixed',
00576 'required' => false,
00577 'default' => false ) ) );
00578 }
00579
00580
00581
00582
00583
00584 function numericalValue( $mixedValue )
00585 {
00586 if ( is_array( $mixedValue ) )
00587 {
00588 return count( $mixedValue );
00589 }
00590 else if ( is_object( $mixedValue ) )
00591 {
00592 if ( method_exists( $mixedValue, 'attributes' ) )
00593 return count( $mixedValue->attributes() );
00594 else if ( method_exists( $mixedValue, 'numericalValue' ) )
00595 return $mixedValue->numericalValue();
00596 }
00597 else if ( is_numeric( $mixedValue ) )
00598 return $mixedValue;
00599 else
00600 return 0;
00601 }
00602
00603
00604
00605
00606 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters,
00607 $placement )
00608 {
00609 switch ( $operatorName )
00610 {
00611 case $this->RomanName:
00612 {
00613 if ( $namedParameters['value'] !== false )
00614 $value = $namedParameters['value'];
00615 else
00616 $value = $operatorValue;
00617
00618 $operatorValue = $this->buildRoman( $value );
00619 } break;
00620 case $this->CountName:
00621 {
00622 if ( count( $operatorParameters ) == 0 )
00623 $mixedValue =& $operatorValue;
00624 else
00625 $mixedValue =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00626 if ( count( $operatorParameters ) > 1 )
00627 $tpl->extraParameters( $operatorName, count( $operatorParameters ), 1 );
00628 if ( is_array( $mixedValue ) )
00629 $operatorValue = count( $mixedValue );
00630 else if ( is_object( $mixedValue ) and
00631 method_exists( $mixedValue, 'attributes' ) )
00632 $operatorValue = count( $mixedValue->attributes() );
00633 else if ( is_string( $mixedValue ) )
00634 $operatorValue = strlen( $mixedValue );
00635 else
00636 $operatorValue = 0;
00637 } break;
00638 case $this->SumName:
00639 {
00640 $value = 0;
00641 if ( $operatorValue !== null )
00642 $value = $operatorValue;
00643 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
00644 {
00645 $tmpValue =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00646 $value += $tmpValue;
00647 }
00648 $operatorValue = $value;
00649 } break;
00650 case $this->SubName:
00651 {
00652 $values = array();
00653 if ( $operatorValue !== null )
00654 $values[] = $operatorValue;
00655 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
00656 {
00657 $values[] = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00658 }
00659 $value = 0;
00660 if ( count( $values ) > 0 )
00661 {
00662 $value = $values[0];
00663 for ( $i = 1; $i < count( $values ); ++$i )
00664 {
00665 $value -= $values[$i];
00666 }
00667 }
00668 $operatorValue = $value;
00669 } break;
00670 case $this->IncName:
00671 case $this->DecName:
00672 {
00673 if ( $operatorValue !== null )
00674 $value = $operatorValue;
00675 else
00676 $value = $namedParameters['value'];
00677 if ( $operatorName == $this->DecName )
00678 --$value;
00679 else
00680 ++$value;
00681 $operatorValue = $value;
00682 } break;
00683 case $this->DivName:
00684 {
00685 if ( count( $operatorParameters ) < 1 )
00686 {
00687 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00688 return;
00689 }
00690 $i = 0;
00691 if ( $operatorValue !== null )
00692 $value = $operatorValue;
00693 else
00694 $value = $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
00695 for ( ; $i < count( $operatorParameters ); ++$i )
00696 {
00697 $tmpValue =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00698 @$value /= $tmpValue;
00699 }
00700 $operatorValue = $value;
00701 } break;
00702 case $this->ModName:
00703 {
00704 if ( count( $operatorParameters ) < 1 )
00705 {
00706 $tpl->warning( $operatorName, 'Missing dividend and divisor', $placement );
00707 return;
00708 }
00709 if ( count( $operatorParameters ) == 1 )
00710 {
00711 $dividend = $operatorValue;
00712 $divisor = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00713 }
00714 else
00715 {
00716 $dividend = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00717 $divisor = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement );
00718 }
00719 $operatorValue = $dividend % $divisor;
00720 } break;
00721 case $this->MulName:
00722 {
00723 if ( count( $operatorParameters ) < 1 )
00724 {
00725 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00726 return;
00727 }
00728 $i = 0;
00729 if ( $operatorValue !== null )
00730 $value = $operatorValue;
00731 else
00732 $value = $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
00733 for ( ; $i < count( $operatorParameters ); ++$i )
00734 {
00735 $tmpValue =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00736 $value *= $tmpValue;
00737 }
00738 $operatorValue = $value;
00739 } break;
00740 case $this->MaxName:
00741 {
00742 if ( count( $operatorParameters ) < 1 )
00743 {
00744 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00745 return;
00746 }
00747 $i = 0;
00748 if ( $operatorValue !== null )
00749 {
00750 $value = $operatorValue;
00751 }
00752 else
00753 {
00754 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00755 ++$i;
00756 }
00757 for ( ; $i < count( $operatorParameters ); ++$i )
00758 {
00759 $tmpValue =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00760 if ( $tmpValue > $value )
00761 $value = $tmpValue;
00762 }
00763 $operatorValue = $value;
00764 } break;
00765 case $this->MinName:
00766 {
00767 if ( count( $operatorParameters ) < 1 )
00768 {
00769 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00770 return;
00771 }
00772 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00773 for ( $i = 1; $i < count( $operatorParameters ); ++$i )
00774 {
00775 $tmpValue =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00776 if ( $tmpValue < $value )
00777 $value = $tmpValue;
00778 }
00779 $operatorValue = $value;
00780 } break;
00781 case $this->AbsName:
00782 case $this->CeilName:
00783 case $this->FloorName:
00784 case $this->RoundName:
00785 {
00786 if ( count( $operatorParameters ) < 1 )
00787 $value = $operatorValue;
00788 else
00789 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00790 switch ( $operatorName )
00791 {
00792 case $this->AbsName:
00793 {
00794 $operatorValue = abs( $value );
00795 } break;
00796 case $this->CeilName:
00797 {
00798 $operatorValue = ceil( $value );
00799 } break;
00800 case $this->FloorName:
00801 {
00802 $operatorValue = floor( $value );
00803 } break;
00804 case $this->RoundName:
00805 {
00806 $operatorValue = round( $value );
00807 } break;
00808 }
00809 } break;
00810 case $this->IntName:
00811 {
00812 if ( count( $operatorParameters ) > 0 )
00813 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00814 else
00815 $value = $operatorValue;
00816 $operatorValue = (int)$value;
00817 } break;
00818 case $this->FloatName:
00819 {
00820 if ( count( $operatorParameters ) > 0 )
00821 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00822 else
00823 $value = $operatorValue;
00824 $operatorValue = (float)$value;
00825 } break;
00826 case $this->RandName:
00827 {
00828 if ( count( $operatorParameters ) == 2 )
00829 {
00830 $operatorValue = mt_rand( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ),
00831 $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement ) );
00832 }
00833 else
00834 {
00835 $operatorValue = mt_rand();
00836 }
00837 } break;
00838 }
00839 }
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 function buildRoman( $value )
00852 {
00853 if ( $value >= 1000 )
00854 return 'M'.$this->buildRoman( $value - 1000 );
00855 if ( $value >= 500 )
00856 {
00857 if ( $value >= 900 )
00858 return 'CM'.$this->buildRoman( $value - 900 );
00859 else
00860 return 'D'.$this->buildRoman( $value - 500 );
00861 }
00862 if ( $value >= 100 )
00863 {
00864 if( $value >= 400 )
00865 return 'CD'.$this->buildRoman( $value - 400 );
00866 else
00867 return 'C'.$this->buildRoman( $value - 100 );
00868 }
00869 if ( $value >= 50 )
00870 {
00871 if( $value >= 90 )
00872 return 'XC'.$this->buildRoman( $value - 90 );
00873 else
00874 return 'L'.$this->buildRoman( $value - 50 );
00875 }
00876 if ( $value >= 10 )
00877 {
00878 if( $value >= 40 )
00879 return 'XL'.$this->buildRoman( $value - 40 );
00880 else
00881 return 'X'.$this->buildRoman( $value - 10 );
00882 }
00883 if ( $value >= 5 )
00884 {
00885 if( $value == 9 )
00886 return 'IX'.$this->buildRoman( $value - 9 );
00887 else
00888 return 'V'.$this->buildRoman( $value - 5 );
00889 }
00890 if ( $value >= 1 )
00891 {
00892 if( $value == 4 )
00893 return 'IV'.$this->buildRoman( $value - 4 );
00894 else
00895 return 'I'.$this->buildRoman( $value - 1 );
00896 }
00897 return '';
00898 }
00899
00900 var $Operators;
00901 var $SumName;
00902 var $SubName;
00903 var $IncName;
00904 var $DecName;
00905
00906 var $DivName;
00907 var $ModName;
00908 var $MulName;
00909
00910 var $MaxName;
00911 var $MinName;
00912
00913 var $AbsName;
00914 var $CeilName;
00915 var $FloorName;
00916 var $RoundName;
00917
00918 var $IntName;
00919 var $FloatName;
00920
00921 var $CountName;
00922
00923 var $RomanName;
00924
00925 var $RandName;
00926 }
00927
00928 ?>