function concatTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $function = $operatorName; if (count($parameters) < 1) { return false; } if (count($parameters) == 1 and eZTemplateNodeTool::isConstantElement($parameters[0])) { return array(eZTemplateNodeTool::createConstantElement(eZTemplateNodeTool::elementConstantValue($parameters[0]))); } $newElements = array(); $counter = 1; $code = "%output% = ( "; foreach ($parameters as $parameter) { $values[] = $parameter; if ($counter > 1) { $code .= ' . '; } $code .= "%{$counter}%"; $counter++; } $code .= " );\n"; $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values); return $newElements; }
function logicalComparisonTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters ) { $values = array(); $function = $operatorName; $minParameterCount = $maxParameterCount = 2; switch ( $operatorName ) { case 'lt': $operator = '<'; break; case 'le': $operator = '<='; break; case 'gt': $operator = '>'; break; case 'ge': $operator = '>='; break; case 'eq': $operator = '=='; break; case 'ne': $operator = '!='; break; case 'and': $operator = 'and'; $maxParameterCount = false; break; case 'or': $operator = 'or'; $maxParameterCount = false; break; } if ( ( count( $parameters ) < 2 ) || ( $maxParameterCount && ( count( $parameters ) > $maxParameterCount ) ) ) { return false; } $newElements = array(); if ( $operatorName == 'or' ) { $staticResult = false; $staticValue = null; $dynamicParameters = array(); $addDynamic = false; $lastValue = null; foreach ( $parameters as $parameter ) { if ( $addDynamic ) { $dynamicParameters[] = $parameter; continue; } if ( eZTemplateNodeTool::isConstantElement( $parameter ) ) { $parameterValue = eZTemplateNodeTool::elementConstantValue( $parameter ); if ( $staticValue === null ) { $staticValue = $parameterValue; } else { $staticValue = ( $staticValue or $parameterValue ); } $lastValue = $parameterValue; if ( $parameterValue ) { $staticResult = true; break; } continue; } $addDynamic = true; $dynamicParameters[] = $parameter; $staticValue = null; } if ( count( $dynamicParameters ) == 0 ) { if ( !$staticResult ) $lastValue = false; $newElements[] = eZTemplateNodeTool::createConstantElement( $lastValue ); return $newElements; } $code = ''; $counter = 0; foreach ( $dynamicParameters as $parameter ) { if ( $counter++ ) { $code .= "else "; } $code .= ( "if ( %$counter% )\n" . " %output% = %$counter%;\n" ); $values[] = $parameter; } $code .= ( "else\n" . " %output% = false;\n" ); } else if ( $operatorName == 'and' ) { $staticResult = false; $staticValue = null; $dynamicParameters = array(); $addDynamic = false; $lastValue = null; foreach ( $parameters as $parameter ) { if ( $addDynamic ) { $dynamicParameters[] = $parameter; continue; } if ( eZTemplateNodeTool::isConstantElement( $parameter ) ) { $parameterValue = eZTemplateNodeTool::elementConstantValue( $parameter ); if ( $staticValue === null ) { $staticValue = $parameterValue; } else { $staticValue = ( $staticValue and $parameterValue ); } $lastValue = $parameterValue; if ( !$parameterValue ) { $lastValue = false; $staticResult = true; break; } continue; } $addDynamic = true; $dynamicParameters[] = $parameter; $staticValue = null; } if ( count( $dynamicParameters ) == 0 ) { $newElements[] = eZTemplateNodeTool::createConstantElement( $lastValue ); return $newElements; } $code = ''; $counter = 0; foreach ( $dynamicParameters as $parameter ) { if ( $counter++ ) { $code .= "else "; } $code .= ( "if ( !%$counter% )\n" . " %output% = false;\n" ); $values[] = $parameter; } $code .= ( "else\n" . " %output% = %$counter%;\n" ); } else { $code = '%output% = ('; $counter = 0; $allStatic = true; foreach ( $parameters as $parameter ) { if ( !eZTemplateNodeTool::isConstantElement( $parameter ) ) $allStatic = false; } if ( $allStatic ) { switch ( $operatorName ) { case 'lt': { $evalStatus = ( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) < eZTemplateNodeTool::elementConstantValue( $parameters[1] ) ); } break; case 'le': { $evalStatus = ( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) <= eZTemplateNodeTool::elementConstantValue( $parameters[1] ) ); } break; case 'gt': { $evalStatus = ( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) > eZTemplateNodeTool::elementConstantValue( $parameters[1] ) ); } break; case 'ge': { $evalStatus = ( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) >= eZTemplateNodeTool::elementConstantValue( $parameters[1] ) ); } break; case 'eq': { $staticParameters = array(); foreach ( $parameters as $parameter ) { $staticParameters[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameter ), 0, 0, false ); } eval( '$evalStatus = ( ' . implode( ' == ', $staticParameters ) . ' );' ); } break; case 'ne': { $staticParameters = array(); foreach ( $parameters as $parameter ) { $staticParameters[] = eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameter ), 0, 0, false ); } eval( '$evalStatus = ( ' . implode( ' != ', $staticParameters ) . ' );' ); } break; break; } $newElements[] = eZTemplateNodeTool::createBooleanElement( $evalStatus ); return $newElements; } foreach ( $parameters as $parameter ) { if ( !eZTemplateNodeTool::isConstantElement( $parameter ) ) $allStatic = false; if ( $counter++ ) { $code .= " $operator"; } $code .= " ( %$counter% )"; $values[] = $parameter; } $code .= " );\n"; } $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values ); return $newElements; }
function customMapTransformation($operatorName, $node, $tpl, $resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $newElements = array(); $mapEntry = $this->customMap[$operatorName]; $paramCount = count($parameters); $strlenFunc = 'strlen'; $substrFunc = 'substr'; $code = "\$strlenFunc = 'strlen'; \$substrFunc = 'substr';\n"; if (function_exists('mb_strlen')) { $strlenFunc = 'mb_strlen'; $substrFunc = 'mb_substr'; $code = "\$strlenFunc = 'mb_strlen'; \$substrFunc = 'mb_substr';\n"; } if ($paramCount < 1) { return false; } $allStatic = true; $staticValues = array(); $replaceMap = array('$result'); $replacementMap = array('%output%'); for ($i = 0; $i < $paramCount; $i++) { if (eZTemplateNodeTool::isConstantElement($parameters[$i])) { $staticValues[$i] = eZTemplateNodeTool::elementConstantValue($parameters[$i]); } else { $allStatic = false; } } if ($allStatic) { $result = false; if (isset($mapEntry['code' . $paramCount])) { eval($mapEntry['code' . $paramCount]); } else { eval($mapEntry['code']); } return array(eZTemplateNodeTool::createConstantElement($result)); } else { $replaceMap = array('$result', '$paramCount'); $replacementMap = array('%output%', $paramCount); for ($i = 0; $i < $paramCount; $i++) { $values[] = $parameters[$i]; $replaceMap[] = "\$staticValues[{$i}]"; $replacementMap[] = '%' . ($i + 1) . '%'; } if (isset($mapEntry['code' . $paramCount])) { $code .= str_replace($replaceMap, $replacementMap, $mapEntry['code' . $paramCount]) . "\n"; } else { $code .= str_replace($replaceMap, $replacementMap, $mapEntry['code']) . "\n"; } } $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values); return $newElements; }
function extractTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $offset = 0; $length = false; $values = array(); $code = ''; if ($operatorName == $this->ExtractName) { if (eZTemplateNodeTool::isConstantElement($parameters[1])) { $offset = eZTemplateNodeTool::elementConstantValue($parameters[1]); $code .= (string) $offset; } else { $values[] = $parameters[1]; $code .= '%' . count($values) . '%'; } } else { if ($operatorName == $this->ExtractRightName) { if (eZTemplateNodeTool::isConstantElement($parameters[1])) { $offset = -1 * eZTemplateNodeTool::elementConstantValue($parameters[1]); $code .= (string) $offset; } else { $values[] = $parameters[1]; $code .= '-1 * %' . count($values) . '%'; } } else { $code .= '0'; } } if ($operatorName == $this->ExtractName) { if (isset($parameters[2]) and eZTemplateNodeTool::isConstantElement($parameters[2])) { $length = eZTemplateNodeTool::elementConstantValue($parameters[2]); $code .= ', ' . (string) $length; } else { if (isset($parameters[2])) { $values[] = $parameters[2]; $code .= ', ' . '%' . count($values) . '%'; } } } else { if ($operatorName == $this->ExtractLeftName) { if (eZTemplateNodeTool::isConstantElement($parameters[1])) { $length = eZTemplateNodeTool::elementConstantValue($parameters[1]); $code .= ', ' . (string) $length; } else { $values[] = $parameters[1]; $code .= ', ' . '%' . count($values) . '%'; } } } if (eZTemplateNodeTool::isConstantElement($parameters[0])) { if (count($values) == 0) { $input = eZTemplateNodeTool::elementConstantValue($parameters[0]); if ($operatorName == $this->ExtractRightName or !$length) { if (is_string($input)) { $output = substr($input, $offset); } else { $output = array_slice($input, $offset); } } else { if (is_string($input)) { $output = substr($input, $offset, $length); } else { $output = array_slice($input, $offset, $length); } } return array(eZTemplateNodeTool::createConstantElement($output)); } else { $code = '%output% = array_slice( ' . eZPHPCreator::variableText(eZTemplateNodeTool::elementConstantValue($parameters[0]), 0, 0, false) . ', ' . $code . ' );'; } } else { $values[] = $parameters[0]; $code = "if ( is_string( %" . count($values) . "% ) )\n" . " %output% = substr( %" . count($values) . "%, " . $code . " );\n" . "else\n" . " %output% = array_slice( %" . count($values) . "%, " . $code . " );"; } return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); }