function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName != $this->BlockName) { return false; } $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node); if (!isset($parameters['name'])) { return false; } $namespaceValue = false; $newNodes = array(); if (isset($parameters["name"])) { $menuIni = eZINI::instance("menu.ini"); $nameData = $parameters["name"]; if (!eZTemplateNodeTool::isStaticElement($nameData)) { return false; } $menuName = eZTemplateNodeTool::elementStaticValue($nameData); if ($menuIni->hasVariable('SelectedMenu', $menuName)) { $menuTemplate = $menuIni->variable("SelectedMenu", $menuName); if ($menuTemplate != null) { $uriString = "design:menu/{$menuTemplate}.tpl"; $resourceName = ""; $templateName = ""; $resource = $tpl->resourceFor($uriString, $resourceName, $templateName); $resourceData = $tpl->resourceData($resource, $uriString, $resourceName, $templateName); $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled(); $includeNodes = $resource->templateNodeTransformation($functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue); if ($includeNodes === false) { return false; } $variableList = array(); foreach (array_keys($parameters) as $parameterName) { if ($parameterName == 'name') { continue; } $parameterData =& $parameters[$parameterName]; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName)); $variableList[] = $parameterName; } $newNodes = array_merge($newNodes, $includeNodes); foreach ($variableList as $variableName) { $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName)); } } else { // to do: not use this function to generate empty code. $newNodes[] = eZTemplateNodeTool::createCodePieceNode(""); } } else { // to do: not use this function to generate empty code. $newNodes[] = eZTemplateNodeTool::createCodePieceNode(""); } } return $newNodes; }
function preferencesTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (count($parameters[0]) == 0) { return false; } $values = array(); if (eZTemplateNodeTool::isStaticElement($parameters[0])) { $name = eZTemplateNodeTool::elementStaticValue($parameters[0]); $nameText = eZPHPCreator::variableText($name, 0, 0, false); } else { $nameText = '%1%'; $values[] = $parameters[0]; } return array(eZTemplateNodeTool::createCodePieceElement("//include_once( 'kernel/classes/ezpreferences.php' );\n" . "%output% = eZPreferences::value( {$nameText} );\n", $values)); }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { switch ($functionName) { case $this->SetName: case $this->DefaultName: case $this->LetName: $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; if (isset($parameters['-scope'])) { if (!eZTemplateNodeTool::isStaticElement($parameters['-scope'])) { return false; } $scopeText = eZTemplateNodeTool::elementStaticValue($parameters['-scope']); if ($scopeText == 'relative') { $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; } else { if ($scopeText == 'root') { $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL; } else { if ($scopeText == 'global') { $scope = eZTemplate::NAMESPACE_SCOPE_GLOBAL; } } } } $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node); $namespaceValue = false; if (isset($parameters['-name'])) { if (!eZTemplateNodeTool::isStaticElement($parameters['-name'])) { return false; } $namespaceValue = eZTemplateNodeTool::elementStaticValue($parameters['-name']); } $variableList = array(); $setVarNodes = array(); foreach (array_keys($parameters) as $parameterName) { if ($parameterName == '-name' or $parameterName == '-scope') { continue; } $parameterData =& $parameters[$parameterName]; $setVarNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), array($namespaceValue, $scope, $parameterName), $functionName == $this->SetName, $functionName != $this->DefaultName, false, $functionName == $this->DefaultName); if ($functionName == $this->LetName or $functionName == $this->DefaultName) { $variableList[] = $parameterName; } } if (($functionName == $this->LetName or $functionName == $this->DefaultName) and $namespaceValue) { $setVarNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($namespaceValue); } if ($functionName == $this->LetName or $functionName == $this->DefaultName) { $childNodes = eZTemplateNodeTool::extractFunctionNodeChildren($node); if (!is_array($childNodes)) { $childNodes = array(); } } else { $childNodes = array(); } $unsetVarNodes = array(); if (($functionName == $this->LetName or $functionName == $this->DefaultName) and $namespaceValue) { $unsetVarNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } if ($functionName == $this->LetName or $functionName == $this->DefaultName) { foreach ($variableList as $parameterName) { $unsetVarNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName), array('remember_set' => $functionName == $this->DefaultName)); } } return array_merge($setVarNodes, $childNodes, $unsetVarNodes); break; } }
function dateTimeTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $newElements = array(); $paramCount = count($parameters); if ($paramCount < 2) { return false; } if (!eZTemplateNodeTool::isStaticElement($parameters[1])) { return false; } else { $class = eZTemplateNodeTool::elementStaticValue($parameters[1]); } if ($class == 'custom' && $paramCount != 3) { return false; } $newElements[] = eZTemplateNodeTool::createCodePieceElement('//include_once("lib/ezlocale/classes/ezlocale.php");' . "\n"); $newElements[] = eZTemplateNodeTool::createCodePieceElement('$locale = eZLocale::instance();' . "\n"); if ($class == 'custom') { $values[] = $parameters[0]; $values[] = $parameters[2]; $newElements[] = eZTemplateNodeTool::createCodePieceElement("%output% = \$locale->formatDateTimeType( %2%, %1% );\n", $values); return $newElements; } else { $dtINI = eZINI::instance('datetime.ini'); $formats = $dtINI->variable('ClassSettings', 'Formats'); if (array_key_exists($class, $formats)) { $classFormat = addcslashes($formats[$class], "'"); $values[] = $parameters[0]; $newElements[] = eZTemplateNodeTool::createCodePieceElement("%output% = \$locale->formatDateTimeType( '{$classFormat}', %1% );\n", $values); return $newElements; } } return false; }
function chooseTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $function = $operatorName; if (count($parameters) < 2) { return false; } $tmpValues = false; $newElements = array(); if (eZTemplateNodeTool::isStaticElement($parameters[0])) { $selected = eZTemplateNodeTool::elementStaticValue($parameters[0]); if ($selected < 0 or $selected > count($parameters) - 1) { return false; } return $parameters[$selected + 1]; } else { $values[] = $parameters[0]; $array = $parameters; unset($array[0]); $count = count($parameters) - 1; $operatorNameText = eZPHPCreator::variableText($operatorName); if (count($parameters) == 2 + 1) { $code = "%output% = %1% ? %3% : %2%;\n"; $values[] = $parameters[1]; $values[] = $parameters[2]; } else { $code = "if ( %1% < 0 and\n" . " %1% >= {$count} )\n" . "{\n" . " \$tpl->error( {$operatorNameText}, \"Index \" . %1% . \" out of range\" );\n" . " %output% = false;\n" . "}\n"; $code .= "else switch ( %1% )\n{\n"; $valueNumber = 2; for ($i = 0; $i < $count; ++$i) { $parameterNumber = $i + 1; $code .= " case {$i}:"; if (eZTemplateNodeTool::isStaticElement($parameters[$parameterNumber])) { $value = eZTemplateNodeTool::elementStaticValue($parameters[$parameterNumber]); $valueText = eZPHPCreator::variableText($value, 0, 0, false); $code .= " %output% = {$valueText}; break;\n"; } else { $code .= "\n {\n"; $code .= "%code{$valueNumber}%\n"; $code .= "%output% = %{$valueNumber}%;\n"; $code .= " } break;\n"; $values[] = $parameters[$parameterNumber]; ++$valueNumber; } } $code .= "}\n"; } } $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values, eZTemplateNodeTool::extractVariableNodePlacement($node), false); return $newElements; }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName != $this->IncludeName) { return false; } $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node); if (!isset($parameters['uri'])) { return false; } $uriData = $parameters['uri']; if (!eZTemplateNodeTool::isStaticElement($uriData)) { return false; } $namespaceValue = false; $namespaceName = '$currentNamespace'; if (isset($parameters['name'])) { $nameData = $parameters['name']; if (!eZTemplateNodeTool::isStaticElement($nameData)) { return false; } $namespaceValue = eZTemplateNodeTool::elementStaticValue($nameData); $namespaceName = '$namespace'; } $uriString = eZTemplateNodeTool::elementStaticValue($uriData); $resourceName = ""; $templateName = ""; $resource = $tpl->resourceFor($uriString, $resourceName, $templateName); $resourceData = $tpl->resourceData($resource, $uriString, $resourceName, $templateName); $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled(); $includeNodes = $resource->templateNodeTransformation($functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue); if ($includeNodes === false) { return false; } $newNodes = array(); $variableList = array(); $uniqID = md5(uniqid('inc')); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$oldRestoreIncludeArray" . "_{$uniqID} = isset( \$restoreIncludeArray ) ? \$restoreIncludeArray : array();\n" . "\$restoreIncludeArray = array();\n"); foreach (array_keys($parameters) as $parameterName) { if ($parameterName == 'uri' or $parameterName == 'name') { continue; } $parameterData =& $parameters[$parameterName]; $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( isset( {$namespaceName} ) and isset( \$vars[{$namespaceName}]['{$parameterName}'] ) )\n" . " \$restoreIncludeArray[] = array( {$namespaceName}, '{$parameterName}', \$vars[{$namespaceName}]['{$parameterName}'] );\n" . "elseif ( !isset( \$vars[( isset( {$namespaceName} ) ? {$namespaceName} : '' )]['{$parameterName}'] ) ) \n" . " \$restoreIncludeArray[] = array( ( isset( {$namespaceName} ) ? {$namespaceName} : '' ), '{$parameterName}', 'unset' );\n"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName)); $variableList[] = $parameterName; } $newNodes = array_merge($newNodes, $includeNodes); // Restore previous variables, before including $newNodes[] = eZTemplateNodeTool::createCodePieceNode("foreach ( \$restoreIncludeArray as \$element )\n" . "{\n" . " if ( \$element[2] === 'unset' )\n" . " {\n" . " unset( \$vars[\$element[0]][\$element[1]] );\n" . " continue;\n" . " }\n" . " \$vars[\$element[0]][\$element[1]] = \$element[2];\n" . "}\n" . "\$restoreIncludeArray = \$oldRestoreIncludeArray" . "_{$uniqID};\n"); return $newNodes; }
static function generateVariableDataCode($php, $tpl, $variableData, &$knownTypes, $dataInspection, &$persistence, $parameters, &$resourceData) { $staticTypeMap = array(eZTemplate::TYPE_STRING => 'string', eZTemplate::TYPE_NUMERIC => 'numeric', eZTemplate::TYPE_IDENTIFIER => 'string', eZTemplate::TYPE_ARRAY => 'array', eZTemplate::TYPE_BOOLEAN => 'boolean'); $variableAssignmentName = $parameters['variable']; $variableAssignmentCounter = $parameters['counter']; $spacing = 0; $optimizeNode = false; if (isset($parameters['spacing'])) { $spacing = $parameters['spacing']; } if ($variableAssignmentCounter > 0) { $variableAssignmentName .= $variableAssignmentCounter; } // We need to unset the assignment variable before any elements are processed // This ensures that we don't work on existing variables $php->addCodePiece("unset( \${$variableAssignmentName} );\n", array('spacing' => $spacing)); if (is_array($variableData)) { foreach ($variableData as $index => $variableDataItem) { $variableDataType = $variableDataItem[0]; if ($variableDataType == eZTemplate::TYPE_STRING or $variableDataType == eZTemplate::TYPE_NUMERIC or $variableDataType == eZTemplate::TYPE_IDENTIFIER or $variableDataType == eZTemplate::TYPE_ARRAY or $variableDataType == eZTemplate::TYPE_BOOLEAN) { $knownTypes = array_unique(array_merge($knownTypes, array($staticTypeMap[$variableDataType]))); $dataValue = $variableDataItem[1]; $dataText = $php->thisVariableText($dataValue, 0, 0, false); $php->addCodePiece("\${$variableAssignmentName} = {$dataText};\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_NODE) { $optimizeNode = true; if (!isset($resourceData['node-object-cached'])) { $tpl->error("eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : ""), "Attribute node-object-cached of variable \$resourceData was not found but variable node eZTemplate::TYPE_OPTIMIZED_NODE is still present. This should not happen"); } $php->addCodePiece("\${$variableAssignmentName} = \$nod_{$resourceData['uniqid']};\n"); // If optimized node is not set, use unoptimized code. $php->addCodePiece("if ( !\${$variableAssignmentName} )\n{\n"); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ARRAY_LOOKUP) { $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; // This code is used a lot so we create a variable for it $phpVar = "\${$variableAssignmentName}"; $indexName = "'{$variableDataItem[1][0][1]}'"; // Add sanity checking $code .= "if ( !isset( {$phpVar}[{$indexName}] ) )\n" . "{\n" . " \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar}" . "[{$indexName}] does not exist, cannot fetch the value.\" );\n" . " {$phpVar} = null;\n" . "}\n" . "else\n "; // Add the actual code $code .= "{$phpVar} = {$phpVar}[{$indexName}];\n"; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP) { $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; $code .= <<<END if ( !is_object( \${$variableAssignmentName} ) ) { \${$variableAssignmentName} = null; } else if ( \${$variableAssignmentName}->hasAttribute( "{$variableDataItem[1][0][1]}" ) ) { \${$variableAssignmentName} = \${$variableAssignmentName}->attribute( "{$variableDataItem[1][0][1]}" ); } END; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_CONTENT_CALL) { // Line number comment $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; // This code is used a lot so we create a variable for it $phpVar = "\${$variableAssignmentName}"; // Add sanity checking $code .= "if ( !is_object( {$phpVar} ) )\n" . "{\n" . " \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar} is not an object, cannot fetch content()\" );\n" . " {$phpVar} = null;\n" . "}\n" . "else\n" . "{\n"; // Add the actual code $code .= " {$phpVar}Tmp = {$phpVar}->content();\n" . " unset( {$phpVar} );\n" . " {$phpVar} = {$phpVar}Tmp;\n" . " unset( {$phpVar}Tmp );\n}\n"; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_PHP_VARIABLE) { $knownTypes = array(); $phpVariableName = $variableDataItem[1]; $php->addCodePiece("\${$variableAssignmentName} = \${$phpVariableName};\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_VARIABLE) { $knownTypes = array(); $namespace = $variableDataItem[1][0]; $namespaceScope = $variableDataItem[1][1]; $variableName = $variableDataItem[1][2]; $namespaceText = eZTemplateCompiler::generateMergeNamespaceCode($php, $tpl, $namespace, $namespaceScope, array('spacing' => $spacing), true); if (!is_string($namespaceText)) { $namespaceText = "\$namespace"; } $variableNameText = $php->thisVariableText($variableName, 0, 0, false); $code = "unset( \${$variableAssignmentName} );\n"; $code .= "\${$variableAssignmentName} = ( array_key_exists( {$namespaceText}, \$vars ) and array_key_exists( {$variableNameText}, \$vars[{$namespaceText}] ) ) ? \$vars[{$namespaceText}][{$variableNameText}] : null;\n"; $php->addCodePiece($code, array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_ATTRIBUTE) { $knownTypes = array(); $newParameters = $parameters; $newParameters['counter'] += 1; $tmpVariableAssignmentName = $newParameters['variable']; $tmpVariableAssignmentCounter = $newParameters['counter']; if ($tmpVariableAssignmentCounter > 0) { $tmpVariableAssignmentName .= $tmpVariableAssignmentCounter; } if (eZTemplateNodeTool::isStaticElement($variableDataItem[1])) { $attributeStaticValue = eZTemplateNodeTool::elementStaticValue($variableDataItem[1]); $attributeText = $php->thisVariableText($attributeStaticValue, 0, 0, false); } else { $newParameters['counter'] += 1; $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $variableDataItem[1], $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $attributeText = "\${$newVariableAssignmentName}"; } $php->addCodePiece("\${$tmpVariableAssignmentName} = compiledFetchAttribute( \${$variableAssignmentName}, {$attributeText} );\n" . "unset( \${$variableAssignmentName} );\n" . "\${$variableAssignmentName} = \${$tmpVariableAssignmentName};\n", array('spacing' => $spacing)); // End if optimized node object is null/false. See also eZTemplateOptimizer::optimizeVariable() if ($optimizeNode && $index == 3) { $php->addCodePiece("}\n"); } } else { if ($variableDataType == eZTemplate::TYPE_OPERATOR) { $knownTypes = array(); $operatorParameters = $variableDataItem[1]; $operatorName = $operatorParameters[0]; $operatorParameters = array_splice($operatorParameters, 1); $operatorNameText = $php->thisVariableText($operatorName, 0, 0, false); $operatorParametersText = $php->thisVariableText($operatorParameters, 23, 0, false); $operatorHint = eZTemplateCompiler::operatorHint($tpl, $operatorName); if (isset($operatorHint['output']) and $operatorHint['output']) { if (isset($operatorHint['output-type'])) { $knownType = $operatorHint['output-type']; if (is_array($knownType)) { $knownTypes = array_merge($knownTypes, $knownType); } else { $knownTypes[] = $knownType; } $knownTypes = array_unique($knownTypes); } else { $knownTypes[] = 'static'; } } $php->addCodePiece("if (! isset( \${$variableAssignmentName} ) ) \${$variableAssignmentName} = NULL;\n", array('spacing' => $spacing)); $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$variableAssignmentName} ) and method_exists( \${$variableAssignmentName}, 'templateValue' ) )\n" . " \${$variableAssignmentName} = \${$variableAssignmentName}" . "->templateValue();\n"); $php->addCodePiece("\$" . $variableAssignmentName . "Data = array( 'value' => \${$variableAssignmentName} );\n\$tpl->processOperator( {$operatorNameText},\n {$operatorParametersText},\n \$rootNamespace, \$currentNamespace, \$" . $variableAssignmentName . "Data, false, false );\n\${$variableAssignmentName} = \$" . $variableAssignmentName . "Data['value'];\nunset( \$" . $variableAssignmentName . "Data );\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_VOID) { } else { if ($variableDataType == eZTemplate::TYPE_DYNAMIC_ARRAY) { $knownTypes = array_unique(array_merge($knownTypes, array('array'))); $code = '%output% = array( '; $matchMap = array('%input%', '%output%'); $replaceMap = array('$' . $variableAssignmentName, '$' . $variableAssignmentName); $unsetList = array(); $counter = 1; $paramCount = 0; $values = $variableDataItem[2]; $newParameters = $parameters; foreach ($values as $key => $value) { if ($paramCount != 0) { $code .= ', '; } ++$paramCount; $code .= '\'' . $key . '\' => '; if (eZTemplateNodeTool::isStaticElement($value)) { $code .= eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($value), 0, 0, false); continue; } $code .= '%' . $counter . '%'; $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $matchMap[] = '%' . $counter . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); ++$counter; } $code .= ' );'; $code = str_replace($matchMap, $replaceMap, $code); $php->addCodePiece($code, array('spacing' => $spacing)); $php->addVariableUnsetList($unsetList, array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_INTERNAL_CODE_PIECE) { $code = $variableDataItem[1]; $values = false; $matchMap = array('%input%', '%output%'); $replaceMap = array('$' . $variableAssignmentName, '$' . $variableAssignmentName); $unsetList = array(); $counter = 1; if (isset($variableDataItem[3]) && is_array($variableDataItem[3])) { $newParameters = $parameters; $values = $variableDataItem[3]; foreach ($values as $value) { $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } if (eZTemplateNodeTool::isStaticElement($value)) { $staticValue = eZTemplateNodeTool::elementStaticValue($value); $staticValueText = $php->thisVariableText($staticValue, 0, 0, false); if (preg_match("/%code{$counter}%/", $code)) { $matchMap[] = '%code' . $counter . '%'; $replaceMap[] = ''; } $matchMap[] = '%' . $counter . '%'; $replaceMap[] = $staticValueText; } else { $matchMap[] = '%' . $counter . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; if (preg_match("/%code{$counter}%/", $code)) { $tmpPHP = new eZPHPCreator('', '', eZTemplateCompiler::TemplatePrefix()); $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($tmpPHP, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); $newCode = $tmpPHP->fetch(false); if (count($tmpKnownTypes) == 0 or in_array('objectproxy', $tmpKnownTypes)) { $newCode .= "while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$newVariableAssignmentName} ) and method_exists( \${$newVariableAssignmentName}, 'templateValue' ) )\n" . " \${$newVariableAssignmentName} = \${$newVariableAssignmentName}" . "->templateValue();\n"; } $matchMap[] = '%code' . $counter . '%'; $replaceMap[] = $newCode; } else { $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); if (!$parameters['treat-value-as-non-object'] and (count($tmpKnownTypes) == 0 or in_array('objectproxy', $tmpKnownTypes))) { $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$newVariableAssignmentName} ) and method_exists( \${$newVariableAssignmentName}, 'templateValue' ) )\n" . " \${$newVariableAssignmentName} = \${$newVariableAssignmentName}" . "->templateValue();\n", array('spacing' => $spacing)); } } } ++$counter; } } if (isset($variableDataItem[4]) && $variableDataItem[4] !== false) { $values = $variableDataItem[4]; for ($i = 0; $i < $values; $i++) { $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $matchMap[] = '%tmp' . ($i + 1) . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; } } if (isset($variableDataItem[5]) and $variableDataItem[5]) { if (is_array($variableDataItem[5])) { $knownTypes = array_unique(array_merge($knownTypes, $variableDataItem[5])); } else { if (is_string($variableDataItem[5])) { $knownTypes = array_unique(array_merge($knownTypes, array($variableDataItem[5]))); } else { $knownTypes = array_unique(array_merge($knownTypes, array('static'))); } } } $code = str_replace($matchMap, $replaceMap, $code); $php->addCodePiece($code, array('spacing' => $spacing)); $php->addVariableUnsetList($unsetList, array('spacing' => $spacing)); } } } } } } } } } } } } } } // After the entire expression line is done we try to extract the actual value if proxies are used $php->addCodePiece("if (! isset( \${$variableAssignmentName} ) ) \${$variableAssignmentName} = NULL;\n"); $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$variableAssignmentName} ) and method_exists( \${$variableAssignmentName}, 'templateValue' ) )\n" . " \${$variableAssignmentName} = \${$variableAssignmentName}" . "->templateValue();\n"); }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $newNodes = array(); $namespaceValue = false; $varName = 'match'; if (!isset($parameters['name'])) { return false; } if (!eZTemplateNodeTool::isStaticElement($parameters['name'])) { return false; } $nameData = $parameters['name']; $nameValue = eZTemplateNodeTool::elementStaticValue($nameData); $nameSpaceNode = eZTemplateNodeTool::createCodePieceNode("\$namespace = \$rootNamespace;\nif ( \$namespace == '' )\n \$namespace = \"{$nameValue}\";\nelse\n \$namespace .= ':{$nameValue}';\n"); if (isset($parameters['loop'])) { $loopData = $parameters['loop']; if (!eZTemplateNodeTool::isStaticElement($loopData)) { return false; } $loopValue = eZTemplateNodeTool::elementStaticValue($loopData); $newNodes = $this->templateNodeSequenceCreate($node, $tpl, $parameters, $nameValue, $loopValue); } else { $newNodes = $this->templateNodeSequenceIterate($node, $tpl, $parameters, $nameValue); } $retNodes = array_merge(array($nameSpaceNode), $newNodes); return $retNodes; }
function i18nTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { // i18n( $input, $context, $comment, $arguments ) // Check if if the three first parameters are constants, if not we cannot compile it foreach (array_slice($parameters, 0, 3) as $parameter) { if ($parameter !== null && !eZTemplateNodeTool::isConstantElement($parameter)) { return false; } } $value = eZTemplateNodeTool::elementStaticValue($parameters[0]); $numParameters = count($parameters); $context = $numParameters > 1 ? eZTemplateNodeTool::elementStaticValue($parameters[1]) : null; $comment = $numParameters > 2 ? eZTemplateNodeTool::elementStaticValue($parameters[2]) : null; if ($numParameters < 4) { return array(eZTemplateNodeTool::createStringElement(ezpI18n::tr($context, $value, $comment, null))); } $values = array(); $ini = eZINI::instance(); if ($ini->variable('RegionalSettings', 'TextTranslation') != 'disabled') { $language = eZLocale::instance()->localeFullCode(); if ($language != "eng-GB") { $file = 'translation.ts'; $ini = eZINI::instance(); $useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled'; eZTSTranslator::initialize($context, $language, $file, $useCache); $man = eZTranslatorManager::instance(); $newValue = $man->translate($context, $value, $comment); if ($newValue) { $value = $newValue; } } } $values[] = array(eZTemplateNodeTool::createStringElement($value)); $values[] = $parameters[3]; $code = '%tmp1% = array();' . "\n" . 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" . '{' . "\n" . ' if ( is_int( %tmp2% ) )' . "\n" . ' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" . ' else' . "\n" . ' %tmp1%[%tmp2%] = %tmp3%;' . "\n" . '}' . "\n" . '%output% = strtr( %1%, %tmp1% );' . "\n"; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); }
function washTransformation($operatorName, $node, $tpl, $resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $tmpVarCount = 0; $newElements = array(); $paramCount = count($parameters); if ($paramCount > 2) { return false; } $allStatic = true; $staticValues = array(); for ($i = 0; $i < $paramCount; $i++) { if (eZTemplateNodeTool::isStaticElement($parameters[$i])) { $staticValues[$i] = eZTemplateNodeTool::elementStaticValue($parameters[$i]); } else { $allStatic = false; } } /* Do optimalizations for 'xhtml' case */ if ($allStatic) { if ($paramCount == 1) { $type = 'xhtml'; } else { $type = $staticValues[1]; } $code = "%output% = '" . addcslashes($this->wash($staticValues[0], $tpl, $type), "'\\") . "' ;\n"; } else { if ($paramCount == 1 || $paramCount == 2 && isset($staticValues[1]) && $staticValues[1] == 'xhtml') { $values[] = $parameters[0]; $code = "%output% = htmlspecialchars( %1% );\n"; } else { if ($paramCount == 2 && isset($staticValues[1]) && $staticValues[1] == 'pdf') { $values[] = $parameters[0]; $tmpVarCount = 1; $code = '%tmp1% = str_replace( array( " ", "\\r\\n", "\\t" ), array( "<C:callSpace>", "<C:callNewLine>", "<C:callTab>" ), %1% );' . "\n"; $code .= '%output% = str_replace( "\\n", "<C:callNewLine>", %tmp1% );' . "\n"; } else { if ($paramCount == 2 && isset($staticValues[1]) && $staticValues[1] == 'email') { $ini = $tpl->ini(); $dotText = addcslashes($ini->variable('WashSettings', 'EmailDotText'), "'"); $atText = addcslashes($ini->variable('WashSettings', 'EmailAtText'), "'"); $values[] = $parameters[0]; $code = "%output% = str_replace( array( '.', '@' ), array( '{$dotText}', '{$atText}' ), %1% );\n"; } else { if ($paramCount == 2 && isset($staticValues[1]) && $staticValues[1] == 'javascript') { $values[] = $parameters[0]; $code = '%output% = str_replace( array( "\\\\", "\\"", "\'" ), array( "\\\\\\\\", "\\\\042", "\\\\047" ) , %1% ); '; } else { return false; } } } } } $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values, false, $tmpVarCount); return $newElements; }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if (!isset($this->Rules[$functionName])) { return false; } $rule = $this->Rules[$functionName]; $resourceData = $privateData['resource-data']; $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node); $inputName = $rule['input_name']; if (!isset($parameters[$inputName])) { return false; } $inputData = $parameters[$inputName]; $outputName = $rule['output_name']; $newNodes = array(); $viewDir = ''; $renderMode = false; if (isset($rule["render_mode"])) { $renderMode = $rule["render_mode"]; } if (isset($parameters['render-mode'])) { $renderData = $parameters['render-mode']; if (!eZTemplateNodeTool::isStaticElement($renderData)) { return false; } $renderMode = eZTemplateNodeTool::elementStaticValue($renderData); } if ($renderMode) { $view_dir .= "/render-{$renderMode}"; } $viewValue = false; $viewName = false; if ($rule['use_views']) { $optionalViews = isset($rule['optional_views']) ? $rule['optional_views'] : false; $viewName = $rule['use_views']; if (isset($parameters[$viewName])) { $viewData = $parameters[$viewName]; if (!eZTemplateNodeTool::isStaticElement($viewData)) { return false; } $viewValue = eZTemplateNodeTool::elementStaticValue($viewData); $viewDir .= '/' . $viewValue; } else { if (!$optionalViews) { return false; } } } $namespaceValue = false; if (isset($rule['namespace'])) { $namespaceValue = $rule['namespace']; } $variableList = array(); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $inputData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $outputName)); $variableList[] = $outputName; foreach (array_keys($parameters) as $parameterName) { if ($parameterName == $inputName or $parameterName == $outputName or $parameterName == $viewName) { continue; } $parameterData = $parameters[$parameterName]; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName)); $variableList[] = $parameterName; } $templateRoot = $rule["template_root"]; $matchFileArray = eZTemplateDesignResource::overrideArray(); if (is_string($templateRoot)) { $resourceNodes = $this->resourceAcquisitionTransformation($functionName, $node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, 0, $resourceData); // If the transformation failed we return false to invoke interpreted mode if ($resourceNodes === false) { return false; } $newNodes = array_merge($newNodes, $resourceNodes); } else { if (isset($templateRoot['type']) and $templateRoot['type'] == 'multi_match' and isset($templateRoot['attributes']) and isset($templateRoot['matches'])) { $rootAttributes = $templateRoot['attributes']; $attributeAccessData = array(); $attributeAccessData[] = eZTemplateNodeTool::createVariableElement($outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE); foreach ($rootAttributes as $rootAttributeName) { $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement($rootAttributeName); } $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $attributeAccessData, false, array('spacing' => 0), 'templateRootMatch'); $rootMatches = $templateRoot['matches']; $rootMatchCounter = 0; foreach ($rootMatches as $rootMatch) { $rootMatchValue = $rootMatch[0]; $templateRoot = $rootMatch[1]; $resourceNodes = $this->resourceAcquisitionTransformation($functionName, $node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, 4, $resourceData); // If this transformation failed we continue to the next root match if ($resourceNodes === false) { continue; } $rootMatchValueText = eZPHPCreator::variableText($rootMatchValue, 0, 0, false); $code = ''; if ($rootMatchCounter > 0) { $code .= "else " . ($resourceData['use-comments'] ? "/*OF:" . __LINE__ . "*/" : "") . ""; } $code .= "if " . ($resourceData['use-comments'] ? "/*OF:" . __LINE__ . "*/" : "") . "( \$templateRootMatch == {$rootMatchValueText} )\n{"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $newNodes = array_merge($newNodes, $resourceNodes); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); ++$rootMatchCounter; } // If the transformation failed we invoke interpreted mode if ($rootMatchCounter == 0) { return false; } $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('templateRootMatch'); } } foreach ($variableList as $variableName) { $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName)); } return $newNodes; }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName == $this->BlockName or $functionName == $this->AppendBlockName) { if (!isset($parameters['variable'])) { return false; } $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; if (isset($parameters['scope'])) { if (!eZTemplateNodeTool::isStaticElement($parameters['scope'])) { return false; } $scopeText = eZTemplateNodeTool::elementStaticValue($parameters['scope']); if ($scopeText == 'relative') { $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; } else { if ($scopeText == 'root') { $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL; } else { if ($scopeText == 'global') { $scope = eZTemplate::NAMESPACE_SCOPE_GLOBAL; } } } } $name = ''; if (isset($parameters['name'])) { if (!eZTemplateNodeTool::isStaticElement($parameters['name'])) { return false; } $name = eZTemplateNodeTool::elementStaticValue($parameters['name']); } $variableName = eZTemplateNodeTool::elementStaticValue($parameters['variable']); $newNodes = array(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode(); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('blockText'); if ($functionName == $this->AppendBlockName) { $data = array(eZTemplateNodeTool::createVariableElement($variableName, $name, $scope)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $data, false, array(), 'blockData'); // This block checks whether the append-block variable is an array or not. // TODO: This is a temporary solution and should also check whether the template variable exists. // This new solution requires probably writing the createVariableElement and createVariableNode your self. $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_null ( \$blockData ) ) \$blockData = array();"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array ( \$blockData ) ) \$blockData[] = \$blockText;"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("else eZDebug::writeError( \"Variable '{$variableName}' is already in use.\" );"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockData', false, array(), array($name, $scope, $variableName), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockData'); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockText', false, array(), array($name, $scope, $variableName), false, true, true); } $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockText'); $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode(); return $newNodes; } else { if ($functionName == $this->OnceName) { $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $key = $this->placementKey($functionPlacement); $newNodes = array(); if ($key !== false) { $keyText = eZPHPCreator::variableText($key, 0, 0, false); $placementText = eZPHPCreator::variableText($functionPlacement, 0, 0, false); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] ) )\n" . "{\n" . " \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] = {$placementText};"); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); } return $newNodes; } } return false; }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $newNodes = array(); $namespaceValue = false; $varName = 'match'; if (!isset($parameters['match'])) { return false; } if (isset($parameters['name'])) { $nameData = $parameters['name']; if (!eZTemplateNodeTool::isStaticElement($nameData)) { return false; } $namespaceValue = eZTemplateNodeTool::elementStaticValue($nameData); } if (isset($parameters['var'])) { $varData = $parameters['var']; if (!eZTemplateNodeTool::isStaticElement($varData)) { return false; } $varName = eZTemplateNodeTool::elementStaticValue($varData); } $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['match'], false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['match'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array('variable-name' => 'match', 'text-result' => true), 'match'); // 'text-result' => false ) ); if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $tmpNodes = array(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $caseNodes = array(); $caseCounter = 1; if (is_array($children)) { foreach ($children as $child) { $childType = $child[0]; if ($childType == eZTemplate::NODE_FUNCTION) { if ($this->templateNodeCaseTransformation($tpl, $tmpNodes, $caseNodes, $caseCounter, $child, $privateData) === false) { return false; } } } } $newNodes = array_merge($newNodes, $tmpNodes); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("switch ( \$match )\n{"); $newNodes = array_merge($newNodes, $caseNodes); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('match'); if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'match')); return $newNodes; }
function condTransform($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { switch ($operatorName) { case $this->CondName: $paramCount = count($parameters); $clauseCount = floor($paramCount / 2); $hasDefaultClause = $paramCount % 2 != 0; if ($paramCount == 1) { return $parameters[0]; } $values = array(); $code = ''; $spacing = 0; $spacingCode = ''; for ($i = 0; $i < $clauseCount; ++$i) { $prevSpacingCode = $spacingCode; $spacingCode = str_repeat(" ", $spacing * 4); if ($i > 0) { $code .= $prevSpacingCode . "else\n" . $prevSpacingCode . "{\n"; } $values[] = $parameters[$i * 2]; if ($i > 0) { $code .= $spacingCode . "%code" . count($values) . "%\n"; } $code .= $spacingCode . 'if ( %' . count($values) . "% )\n" . $spacingCode . "{\n"; if (!eZTemplateNodeTool::isStaticElement($parameters[$i * 2 + 1])) { $values[] = $parameters[$i * 2 + 1]; $code .= $spacingCode . " %code" . count($values) . "%\n" . $spacingCode . " %output% = %" . count($values) . "%;\n"; } else { $code .= $spacingCode . ' %output% = ' . eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i * 2 + 1]), 0, 0, false) . ';' . "\n"; } $code .= $spacingCode . "}\n"; ++$spacing; } $bracketCount = $clauseCount - 1; if ($hasDefaultClause) { ++$bracketCount; $values[] = $parameters[$paramCount - 1]; if ($clauseCount > 0) { $code .= $spacingCode . "else\n" . $spacingCode . "{\n" . $spacingCode . " %code" . count($values) . "%\n "; } $code .= $spacingCode . '%output% = %' . count($values) . "%;\n"; } for ($clauseIndex = 0; $clauseIndex < $bracketCount; ++$clauseIndex) { $spacingCode = str_repeat(" ", ($bracketCount - $clauseIndex - 1) * 4); $code .= $spacingCode . "}\n"; } return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); break; case $this->FirstSetName: $values = array(); $code = ''; $spacing = 0; $spacingCode = ''; $nestCount = 0; for ($i = 0; $i < count($parameters); ++$i) { if ($i != 0) { $code .= "{$spacingCode}}\n" . $spacingCode . "else\n{$spacingCode}{\n"; } $spacingCode = str_repeat(' ', $spacing * 4); ++$spacing; if (eZTemplateNodeTool::isStaticElement($parameters[$i])) { $code .= "{$spacingCode}%output% = " . eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false) . ";\n"; break; } ++$nestCount; $values[] = $parameters[$i]; $code .= $spacingCode . "%code" . count($values) . "%\n" . $spacingCode . 'if ( isset( %' . count($values) . "% ) )\n" . $spacingCode . "{\n" . $spacingCode . " %output% = %" . count($values) . '%;' . "\n"; } for ($i = 0; $i < $nestCount; ++$i) { $spacing = $nestCount - $i - 1; $spacingCode = str_repeat(' ', $spacing * 4); $code .= $spacingCode . "}\n"; } return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); break; } }
function operatorTransform($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (!eZTemplateNodeTool::isStaticElement($parameters[1]) || count($parameters) > 2 && !eZTemplateNodeTool::isStaticElement($parameters[2])) { return false; } // We do not support non-static values for decimal_count, decimal_symbol and thousands_separator if (count($parameters) > 3 and !eZTemplateNodeTool::isStaticElement($parameters[3])) { return false; } if (count($parameters) > 4 and !eZTemplateNodeTool::isStaticElement($parameters[4])) { return false; } if (count($parameters) > 5 and !eZTemplateNodeTool::isStaticElement($parameters[5])) { return false; } $locale = eZLocale::instance(); $decimalCount = $locale->decimalCount(); $decimalSymbol = $locale->decimalSymbol(); $decimalThousandsSeparator = $locale->thousandsSeparator(); if (count($parameters) > 2) { $prefix = eZTemplateNodeTool::elementStaticValue($parameters[2]); } else { $prefix = 'auto'; } if (count($parameters) > 3) { $decimalCount = eZTemplateNodeTool::elementStaticValue($parameters[3]); } elseif ($prefix == 'none') { $decimalCount = 0; } if (count($parameters) > 4) { $decimalSymbol = eZTemplateNodeTool::elementStaticValue($parameters[4]); } if (count($parameters) > 5) { $decimalThousandsSeparator = eZTemplateNodeTool::elementStaticValue($parameters[5]); } $decimalSymbolText = eZPHPCreator::variableText($decimalSymbol, 0, 0, false); $decimalThousandsSeparatorText = eZPHPCreator::variableText($decimalThousandsSeparator, 0, 0, false); $unit = eZTemplateNodeTool::elementStaticValue($parameters[1]); $ini = eZINI::instance(); if ($prefix == "auto") { $prefixes = $ini->variableArray("UnitSettings", "BinaryUnits"); if (in_array($unit, $prefixes)) { $prefix = "binary"; } else { $prefix = "decimal"; } } $unit_ini = eZINI::instance("units.ini"); $use_si = $ini->variable("UnitSettings", "UseSIUnits") == "true"; $fake = $use_si ? "" : "Fake"; if ($unit_ini->hasVariable("Base", $unit)) { $base = $unit_ini->variable("Base", $unit); } $hasInput = false; $output = false; if (eZTemplateNodeTool::isStaticElement($parameters[0])) { $output = eZTemplateNodeTool::elementStaticValue($parameters[0]); $hasInput = true; } $prefix_var = ""; if ($prefix == "decimal") { $prefixes = $unit_ini->group("DecimalPrefixes"); $prefix_group = $unit_ini->group("DecimalPrefixes"); $prefixes = array(); foreach ($prefix_group as $prefix_item) { $prefixes[] = explode(";", $prefix_item); } usort($prefixes, "eZTemplateUnitCompareFactor"); $prefix_var = ""; if ($hasInput) { if ($output >= 0 and $output < 10) { $prefix_var = ''; } else { foreach ($prefixes as $prefix) { $val = pow(10, (int) $prefix[0]); if ($val <= $output) { $prefix_var = $prefix[1]; $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); break; } } } } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createArrayElement($prefixes)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = 'if ( %1% >= 0 and %1% < 10 )' . "\n" . '{' . "\n" . ' %tmp3% = \'\';' . "\n" . '}' . "\n" . 'else' . "\n" . '{' . "\n" . ' %tmp3% = "";' . "\n" . ' foreach ( %2% as %tmp1% )' . "\n" . ' {' . "\n" . ' %tmp2% = pow( 10, (int)%tmp1%[0] );' . "\n" . ' if ( %tmp2% <= %1% )' . "\n" . ' {' . "\n" . ' %tmp3% = %tmp1%[1];' . "\n" . ' %1% = number_format( %1% / %tmp2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' );' . "\n" . ' break;' . "\n" . ' }' . "\n" . ' }' . "\n" . '}' . "\n" . '%output% = %1% . \' \' . %tmp3% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); } } else { if ($prefix == "binary") { $prefix_group = $unit_ini->group($fake . "BinaryPrefixes"); $prefixes = array(); foreach ($prefix_group as $prefix_item) { $prefixes[] = explode(";", $prefix_item); } usort($prefixes, "eZTemplateUnitCompareFactor"); $prefix_var = ""; if ($hasInput) { if ($output >= 0 and $output < 10) { $prefix_var = ''; } foreach ($prefixes as $prefix) { $val = pow(2, (int) $prefix[0]); if ($val <= $output) { $prefix_var = $prefix[1]; $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); break; } } } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createArrayElement($prefixes)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = 'if ( %1% >= 0 and %1% < 10 )' . "\n" . '{' . "\n" . ' %tmp3% = \'\';' . "\n" . '}' . "\n" . 'else' . "\n" . '{' . "\n" . ' %tmp3% = "";' . "\n" . ' foreach ( %2% as %tmp1% )' . "\n" . ' {' . "\n" . ' %tmp2% = pow( 2, (int)%tmp1%[0] );' . "\n" . ' if ( %tmp2% <= %1% )' . "\n" . ' {' . "\n" . ' %tmp3% = %tmp1%[1];' . "\n" . ' %1% = number_format( %1% / %tmp2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' );' . "\n" . ' break;' . "\n" . ' }' . "\n" . ' }' . "\n" . '}' . "\n" . '%output% = %1% . \' \' . %tmp3% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); } } else { if ($unit_ini->hasVariable("BinaryPrefixes", $prefix)) { $prefix_base = 2; $prefix_var = $unit_ini->variableArray("BinaryPrefixes", $prefix); } else { if ($unit_ini->hasVariable("DecimalPrefixes", $prefix)) { $prefix_base = 10; $prefix_var = $unit_ini->variableArray("DecimalPrefixes", $prefix); } else { if ($prefix == "none") { $prefix_var = ''; if ($hasInput) { $output = number_format($output, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createStringElement('')); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = number_format( %1%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' ) . \' \' . %2% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); } } } } if (is_array($prefix_var)) { if ($hasInput) { $val = pow($prefix_base, (int) $prefix_var[0]); $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); $prefix_var = $prefix_var[1]; } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createNumericElement(pow($prefix_base, (int) $prefix_var[0]))); $values[] = array(eZTemplateNodeTool::createStringElement($prefix_var[1])); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = number_format( %1% / %2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' ) . \' \' . %3% . %4%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); } } } } if ($hasInput) { return array(eZTemplateNodeTool::createStringElement($output . ' ' . $prefix_var . $base)); } $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createStringElement($prefix_var)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = %1% . \' \' . %2% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); }
function fetchTransform($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $parameterTranslation = false; $constParameters = array(); if ($operatorName == $this->Fetch) { if (!eZTemplateNodeTool::isStaticElement($parameters[0]) || !eZTemplateNodeTool::isStaticElement($parameters[1])) { return false; } $moduleName = eZTemplateNodeTool::elementStaticValue($parameters[0]); $functionName = eZTemplateNodeTool::elementStaticValue($parameters[1]); $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo($moduleName); if (!$moduleFunctionInfo->isValid()) { eZDebug::writeError("Cannot execute module '{$moduleName}', no module found", 'eZFunctionHandler::execute'); return array(); } $fetchParameters = array(); if (isset($parameters[2])) { $fetchParameters = $parameters[2]; } } else { if ($operatorName == $this->FetchAlias) { if (!eZTemplateNodeTool::isStaticElement($parameters[0])) { return false; } $aliasFunctionName = eZTemplateNodeTool::elementStaticValue($parameters[0]); $aliasSettings = eZINI::instance('fetchalias.ini'); if ($aliasSettings->hasSection($aliasFunctionName)) { $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo($aliasSettings->variable($aliasFunctionName, 'Module')); if (!$moduleFunctionInfo->isValid()) { eZDebug::writeError("Cannot execute function '{$aliasFunctionName}' in module '{$moduleName}', no valid data", 'eZFunctionHandler::executeAlias'); return array(); } $functionName = $aliasSettings->variable($aliasFunctionName, 'FunctionName'); $functionArray = array(); if ($aliasSettings->hasVariable($aliasFunctionName, 'Parameter')) { $parameterTranslation = $aliasSettings->variable($aliasFunctionName, 'Parameter'); } if ($aliasSettings->hasVariable($aliasFunctionName, 'Constant')) { $constantParameterArray = $aliasSettings->variable($aliasFunctionName, 'Constant'); if (is_array($constantParameterArray)) { foreach (array_keys($constantParameterArray) as $constKey) { if ($moduleFunctionInfo->isParameterArray($functionName, $constKey)) { $constParameters[$constKey] = explode(';', $constantParameterArray[$constKey]); } else { $constParameters[$constKey] = $constantParameterArray[$constKey]; } } } } } else { $placement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $tpl->warning('fetch_alias', "Fetch alias '{$aliasFunctionName}' is not defined in fetchalias.ini", $placement); return array(); } $fetchParameters = array(); if (isset($parameters[1])) { $fetchParameters = $parameters[1]; } } else { return false; } } $functionDefinition = $moduleFunctionInfo->preExecute($functionName); if ($functionDefinition === false) { return false; } $isDynamic = false; $isVariable = false; if (eZTemplateNodeTool::isStaticElement($fetchParameters)) { $staticParameters = eZTemplateNodeTool::elementStaticValue($fetchParameters); $functionKeys = array_keys($staticParameters); } else { if (eZTemplateNodeTool::isDynamicArrayElement($fetchParameters)) { $isDynamic = true; $dynamicParameters = eZTemplateNodeTool::elementDynamicArray($fetchParameters); $functionKeys = eZTemplateNodeTool::elementDynamicArrayKeys($fetchParameters); } else { if (eZTemplateNodeTool::isVariableElement($fetchParameters) or eZTemplateNodeTool::isInternalCodePiece($fetchParameters)) { $isVariable = true; } else { $functionKeys = array(); } } } $paramCount = 0; $values = array(); if ($isVariable) { $values[] = $fetchParameters; $parametersCode = 'array( '; foreach ($functionDefinition['parameters'] as $parameterDefinition) { if ($paramCount != 0) { $parametersCode .= ',' . "\n"; } ++$paramCount; $parameterName = $parameterDefinition['name']; if ($parameterTranslation) { if (in_array($parameterName, array_keys($parameterTranslation))) { $parameterName = $parameterTranslation[$parameterName]; } } $defaultValue = 'null'; if (!$parameterDefinition['required']) { $defaultValue = eZPHPCreator::variableText($parameterDefinition['default'], 0, 0, false); } $parametersSelection = '%1%[\'' . $parameterName . '\']'; $parametersCode .= '( isset( ' . $parametersSelection . ' ) ? ' . $parametersSelection . " : {$defaultValue} )"; } $parametersCode .= ' )'; } else { $parametersCode = 'array( '; if (count($functionDefinition['parameters'])) { foreach ($functionDefinition['parameters'] as $parameterDefinition) { if ($paramCount != 0) { $parametersCode .= ',' . "\n"; } ++$paramCount; $parameterName = $parameterDefinition['name']; if ($parameterTranslation) { if (in_array($parameterName, array_keys($parameterTranslation))) { $parameterName = $parameterTranslation[$parameterName]; } } $parametersCode .= ' \'' . $parameterName . '\' => '; if (in_array($parameterName, $functionKeys)) { if ($isDynamic) { if (eZTemplateNodeTool::isStaticElement($dynamicParameters[$parameterName])) { $parametersCode .= eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($dynamicParameters[$parameterName]), 0, 0, false); } else { $values[] = $dynamicParameters[$parameterName]; $parametersCode .= '%' . count($values) . '%'; } } else { $parametersCode .= eZPHPCreator::variableText($staticParameters[$parameterName], 0, 0, false); } } else { if ($constParameters && isset($constParameters[$parameterName])) { $parametersCode .= eZPHPCreator::variableText($constParameters[$parameterName], 0, 0, false); } else { if ($parameterDefinition['required']) { return false; } else { if (isset($parameterDefinition['default'])) { $parametersCode .= eZPHPCreator::variableText($parameterDefinition['default'], 0, 0, false); } else { $parametersCode .= 'null'; } } } } } } $parametersCode .= ' )'; } $code = '%output% = call_user_func_array( array( new ' . $functionDefinition['call_method']['class'] . '(), \'' . $functionDefinition['call_method']['method'] . '\' ),' . "\n" . ' ' . $parametersCode . ' );'; $code .= "\n"; $code .= '%output% = isset( %output%[\'result\'] ) ? %output%[\'result\'] : null;' . "\n"; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $ini = eZINI::instance(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); if ($ini->variable('TemplateSettings', 'TemplateCache') != 'enabled') { return $children; } $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $placementKeyString = eZTemplateCacheBlock::placementString($functionPlacement); $newNodes = array(); $ignoreContentExpiry = false; if (isset($parameters['expiry'])) { if (eZTemplateNodeTool::isStaticElement($parameters['expiry'])) { $expiryValue = eZTemplateNodeTool::elementStaticValue($parameters['expiry']); $ttlCode = $expiryValue > 0 ? eZPHPCreator::variableText($expiryValue, 0, 0, false) : 'null'; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['expiry'], false, array(), 'localExpiry'); $ttlCode = "( \$localExpiry > 0 ? \$localExpiry : null )"; } } else { $ttlCode = eZPHPCreator::variableText(self::DEFAULT_TTL, 0, 0, false); } if (isset($parameters['ignore_content_expiry'])) { $ignoreContentExpiry = eZTemplateNodeTool::elementStaticValue($parameters['ignore_content_expiry']); } $keysData = false; $hasKeys = false; $subtreeExpiryData = null; $subtreeValue = null; if (isset($parameters['keys'])) { $keysData = $parameters['keys']; $hasKeys = true; } if (isset($parameters['subtree_expiry'])) { $subtreeExpiryData = $parameters['subtree_expiry']; if (!eZTemplateNodeTool::isStaticElement($subtreeExpiryData)) { $hasKeys = true; } else { $subtreeValue = eZTemplateNodeTool::elementStaticValue($subtreeExpiryData); } $ignoreContentExpiry = true; } $accessName = false; if (isset($GLOBALS['eZCurrentAccess']['name'])) { $accessName = $GLOBALS['eZCurrentAccess']['name']; } if ($hasKeys) { $placementKeyStringText = eZPHPCreator::variableText($placementKeyString, 0, 0, false); $accessNameText = eZPHPCreator::variableText($accessName, 0, 0, false); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $keysData, false, array(), 'cacheKeys'); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $subtreeExpiryData, false, array(), 'subtreeExpiry'); $code = "//include_once( 'lib/eztemplate/classes/eztemplatecacheblock.php' );\n" . "\$cacheKeys = array( \$cacheKeys, {$placementKeyStringText}, {$accessNameText} );\n"; $cachePathText = "\$cachePath"; } else { $nodeID = $subtreeValue ? eZTemplateCacheBlock::decodeNodeID($subtreeValue) : false; $cachePath = eZTemplateCacheBlock::cachePath(eZTemplateCacheBlock::keyString(array($placementKeyString, $accessName)), $nodeID); $code = "//include_once( 'lib/eztemplate/classes/eztemplatecacheblock.php' );\n"; $cachePathText = eZPHPCreator::variableText($cachePath, 0, 0, false); } $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = ''; $codePlacementHash = md5($placementKeyString); if ($hasKeys) { $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n eZTemplateCacheBlock::retrieve( \$cacheKeys, \$subtreeExpiry, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n"; } else { $nodeIDText = var_export($nodeID, true); $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n eZTemplateCacheBlock::handle( {$cachePathText}, {$nodeIDText}, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n"; } $code .= "if ( !( \$contentData instanceof eZClusterFileFailure ) )\n" . "{\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 0)); $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('contentData', array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" unset( \$contentData );\n" . "}\n" . "else\n" . "{\n" . " unset( \$contentData );"); $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode(array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('cachedText', array('spacing' => 4)); $code = "\$cacheHandler_{$codePlacementHash}->storeCache( array( 'scope' => 'template-block', 'binarydata' => \$cachedText ) );\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode(array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('cachedText', array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" unset( \$cachedText, \$cacheHandler_{$codePlacementHash} );\n}\n"); return $newNodes; }
function romanTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); if (count($parameters) != 1) { return false; } $newElements = array(); if (eZTemplateNodeTool::isStaticElement($parameters[0])) { $staticResult = $this->buildRoman(eZTemplateNodeTool::elementStaticValue($parameters[0])); return array(eZTemplateNodeTool::createNumericElement($staticResult)); } else { return false; } }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName != $this->BlockName) { return false; } $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node); if (!isset($parameters['name'])) { return false; } // Read ini file $toolbarIni = eZINI::instance("toolbar.ini"); if (isset($parameters["view"])) { $viewData = $parameters["view"]; $viewMode = eZTemplateNodeTool::elementStaticValue($viewData); } else { $viewMode = "full"; } $params = $parameters; $namespaceValue = false; if (isset($parameters["name"])) { $nameData = $parameters["name"]; if (!eZTemplateNodeTool::isStaticElement($nameData)) { return false; } $nameValue = eZTemplateNodeTool::elementStaticValue($nameData); $toolbarPosition = $nameValue; $toolbarName = "Toolbar_" . $toolbarPosition; $toolArray = $toolbarIni->variable($toolbarName, 'Tool'); if (!is_array($toolArray)) { $toolArray = array(); } $newNodes = array(); foreach (array_keys($toolArray) as $toolKey) { $tool = $toolArray[$toolKey]; $placement = $toolKey + 1; $uriString = "design:toolbar/{$viewMode}/{$tool}.tpl"; $placementValue = ""; $firstValue = false; $lastValue = false; if ($placement == 1) { if ($placement == count($toolArray)) { $firstValue = true; $lastValue = true; $placementValue = "last"; } else { $firstValue = true; $placementValue = "first"; } } else { if ($placement == count($toolArray)) { $lastValue = true; $placementValue = "last"; } } $resourceName = ""; $templateName = ""; $resource = $tpl->resourceFor($uriString, $resourceName, $templateName); $resourceData = $tpl->resourceData($resource, $uriString, $resourceName, $templateName); $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled(); $includeNodes = $resource->templateNodeTransformation($functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue); if ($includeNodes === false) { return false; } $uniqID = md5(uniqid('inc')); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$oldRestoreIncludeArray" . "_{$uniqID} = isset( \$restoreIncludeArray ) ? \$restoreIncludeArray : array();\n" . "\$restoreIncludeArray = array();\n"); $variableList = array(); foreach (array_keys($parameters) as $parameterName) { if ($parameterName == 'name' or $parameterName == 'view') { continue; } $parameterData =& $parameters[$parameterName]; $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( isset( \$vars['']['{$parameterName}'] ) )\n" . " \$restoreIncludeArray[] = array( '', '{$parameterName}', \$vars['']['{$parameterName}'] );\n" . "elseif ( !isset( \$vars['']['{$parameterName}'] ) ) \n" . " \$restoreIncludeArray[] = array( '', '{$parameterName}', 'unset' );\n"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName)); $variableList[] = $parameterName; } $actionParameters = array(); if ($toolbarIni->hasGroup("Tool_" . $tool)) { $actionParameters = $toolbarIni->group("Tool_" . $tool); } if ($toolbarIni->hasGroup("Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement)) { $actionParameters = array_merge($actionParameters, $toolbarIni->group("Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement)); } foreach (array_keys($actionParameters) as $key) { $itemValue = $actionParameters[$key]; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $itemValue, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $key)); $variableList[] = $key; } // Add parameter tool_id and offset $toolIDValue = "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $toolIDValue, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "tool_id")); $variableList[] = "tool_id"; $toolOffset = $placement; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $toolOffset, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "offset")); $variableList[] = "offset"; // Add parameter first, last and placement $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $firstValue, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "first")); $variableList[] = "first"; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $lastValue, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "last")); $variableList[] = "last"; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $placementValue, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "placement")); $variableList[] = "placement"; $newNodes = array_merge($newNodes, $includeNodes); // Restore previous variables, before including $newNodes[] = eZTemplateNodeTool::createCodePieceNode("foreach ( \$restoreIncludeArray as \$element )\n" . "{\n" . " if ( \$element[2] === 'unset' )\n" . " {\n" . " unset( \$vars[\$element[0]][\$element[1]] );\n" . " continue;\n" . " }\n" . " \$vars[\$element[0]][\$element[1]] = \$element[2];\n" . "}\n" . "\$restoreIncludeArray = \$oldRestoreIncludeArray" . "_{$uniqID};\n"); } } return $newNodes; }
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::isStaticElement($parameters[0])) { return array(eZTemplateNodeTool::createStaticElement(eZTemplateNodeTool::elementStaticValue($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 applyQuotes($text, &$parameter, $onlyQuote = false) { $quote = "\""; if ($parameter != null) { $val = eZTemplateNodeTool::elementStaticValue($parameter); if ($val == 'single') { $quote = "'"; } else { if ($val == 'no') { $quote = false; } } } if ($onlyQuote) { return $quote; } $http = eZHTTPTool::instance(); if (isset($http->UseFullUrl) and $http->UseFullUrl and strncasecmp($text, '/', 1) === 0) { $text = $http->createRedirectUrl($text, array('pre_url' => false)); } if ($quote !== false) { return $quote . $text . $quote; } return $text; }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $useLastValue = false; if (isset($parameters['last-value']) and !eZTemplateNodeTool::isStaticElement($parameters['last-value'])) { return false; } if (isset($parameters['name']) and !eZTemplateNodeTool::isStaticElement($parameters['name'])) { return false; } if (isset($parameters['var']) and !eZTemplateNodeTool::isStaticElement($parameters['var'])) { return false; } if (isset($parameters['reverse']) and !eZTemplateNodeTool::isStaticElement($parameters['reverse'])) { return false; } $varName = false; if (isset($parameters['var'])) { $varName = eZTemplateNodeTool::elementStaticValue($parameters['var']); } if (isset($parameters['last-value'])) { $useLastValue = (bool) eZTemplateNodeTool::elementStaticValue($parameters['last-value']); } if (!$varName) { $useLastValue = false; } $reverseLoop = false; if (isset($parameters['reverse'])) { $reverseLoop = eZTemplateNodeTool::elementStaticValue($parameters['reverse']); } $useLoop = isset($parameters['loop']); $allowLoop = true; $newNodes = array(); $maxText = "false"; $useMax = false; $maxPopText = false; if (isset($parameters['max'])) { if (eZTemplateNodeTool::isStaticElement($parameters['max'])) { $maxValue = eZTemplateNodeTool::elementStaticValue($parameters['max']); if ($maxValue > 0) { $maxText = eZPHPCreator::variableText($maxValue); $useMax = true; } else { return array(eZTemplateNodeTool::createTextNode('')); } } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'max'); $maxText = "\$max"; $maxPopText = ", \$max"; $useMax = true; } } // Controls whether the 'if' statement with brackets is added $useShow = false; // Controls whether main nodes are handled, also controls delimiter and filters $useMain = true; // Controls wether else nodes are handled $useElse = false; $spacing = 0; if (isset($parameters['show'])) { if (eZTemplateNodeTool::isStaticElement($parameters['show'])) { $showValue = eZTemplateNodeTool::elementStaticValue($parameters['show']); if ($showValue) { $useMain = true; $useElse = false; $useShow = false; } else { $useMain = false; $useElse = true; $useShow = false; } $newNodes[] = eZTemplateNodeTool::createTextNode(''); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['show'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'show'); $spacing = 4; $useElse = true; $useShow = true; } } $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); if ($useShow) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$show )\n{\n"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show'); } if (isset($parameters['name']) and !$useLoop) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $mainNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'before', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else')), 'filter' => array(array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('delimiter', 'section-exclude', 'section-include'))))))); $delimiterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'delimiter'))))); $filterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('section-exclude', 'section-include')))))); $delimiterNode = false; if (count($delimiterNodes) > 0) { $delimiterNode = $delimiterNodes[0]; } if ($useMain) { // Avoid transformation if the nodes will not be used, saves time $mainNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $mainNodes, $privateData); } if ($useLoop and $useMain) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['loop'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'loopItem'); $hasSequence = false; if (isset($parameters['sequence'])) { $sequenceParameter = $parameters['sequence']; $hasSequence = true; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $sequenceParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'sequence'); } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $code = "if ( !isset( \$sectionStack ) )\n" . " \$sectionStack = array();\n"; $variableValuePushText = ''; $variableValuePopText = ''; if ($varName) { $code .= "//include_once( 'lib/eztemplate/classes/eztemplatesectioniterator.php' );\n" . "\$variableValue = new eZTemplateSectionIterator();\n" . "\$lastVariableValue = false;\n"; $variableValuePushText = "&\$variableValue, "; $variableValuePopText = "\$variableValue, "; } $code .= "\$index = 0;\n" . "\$currentIndex = 1;\n"; $arrayCode = ''; $numericCode = ''; $stringCode = ''; $offsetText = '0'; if (isset($parameters['offset'])) { $offsetParameter = $parameters['offset']; if (eZTemplateNodeTool::isStaticElement($offsetParameter)) { $iterationValue = (int) eZTemplateNodeTool::elementStaticValue($offsetParameter); if ($iterationValue > 0) { $arrayCode = " \$loopKeys = array_splice( \$loopKeys, {$iterationValue} );\n"; } $offsetText = $iterationValue; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $offsetParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'offset'); $arrayCode = " if ( \$offset > 0 )\n" . " \$loopKeys = array_splice( \$loopKeys, \$offset );\n"; $offsetText = "\$offset"; } } // Initialization for array $code .= "if ( is_array( \$loopItem ) )\n{\n" . " \$loopKeys = array_keys( \$loopItem );\n"; if ($reverseLoop) { $code .= " \$loopKeys = array_reverse( \$loopKeys );\n"; } $code .= $arrayCode; $code .= " \$loopCount = count( \$loopKeys );\n"; $code .= "}\n"; // Initialization for numeric $code .= "else if ( is_numeric( \$loopItem ) )\n{\n" . " \$loopKeys = false;\n" . $numericCode . " if ( \$loopItem < 0 )\n" . " \$loopCountValue = -\$loopItem;\n" . " else\n" . " \$loopCountValue = \$loopItem;\n" . " \$loopCount = \$loopCountValue - {$offsetText};\n" . "}\n"; // Initialization for string $code .= "else if ( is_string( \$loopItem ) )\n{\n" . " \$loopKeys = false;\n" . $stringCode . " \$loopCount = strlen( \$loopItem ) - {$offsetText};\n" . "}\n"; // Fallback for no item $code .= "else\n{\n" . " \$loopKeys = false;\n" . " \$loopCount = 0;\n" . "}"; // Initialization end $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = "while ( \$index < \$loopCount )\n" . "{\n"; if ($useMax) { $code .= " if ( \$currentIndex > {$maxText} )\n" . " break;\n" . " unset( \$item );\n"; } // Iterator check for array $code .= " if ( is_array( \$loopItem ) )\n" . " {\n" . " \$loopKey = \$loopKeys[\$index];\n" . " unset( \$item );\n" . " \$item = \$loopItem[\$loopKey];\n" . " }\n"; // Iterator check for numeric $code .= " else if ( is_numeric( \$loopItem ) )\n" . " {\n" . " unset( \$item );\n"; if ($reverseLoop) { $code .= " \$item = \$loopCountValue - \$index - {$offsetText};\n"; } else { $code .= " \$item = \$index + {$offsetText} + 1;\n"; } $code .= " if ( \$loopItem < 0 )\n" . " \$item = -\$item;\n"; if ($reverseLoop) { $code .= " \$loopKey = \$loopCountValue - \$index - {$offsetText} - 1;\n"; } else { $code .= " \$loopKey = \$index + {$offsetText};\n"; } $code .= " }\n"; // Iterator check for string $code .= " else if ( is_string( \$loopItem ) )\n" . " {\n" . " unset( \$item );\n"; if ($reverseLoop) { $code .= " \$loopKey = \$loopCount - \$index - {$offsetText} + 1;\n"; } else { $code .= " \$loopKey = \$index + {$offsetText};\n"; } $code .= " \$item = \$loopItem[\$loopKey];\n" . " }\n"; // Iterator check end $code .= " unset( \$last );\n" . " \$last = false;\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = ''; if ($useLastValue) { $code .= " if ( \$currentIndex > 1 )\n" . " {\n" . " \$last = \$lastVariableValue;\n" . " \$variableValue = new eZTemplateSectionIterator();\n" . " }\n"; } if ($varName) { $code .= " \$variableValue->setIteratorValues( \$item, \$loopKey, \$currentIndex - 1, \$currentIndex, false, \$last );"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'loopKey', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'key'), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'item', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'item'), false, true, true); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$currentIndexInc = \$currentIndex - 1;\n"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndexInc', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'index'), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndex', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'number'), false, true, true); } $mainSpacing = 0; $hasFilter = false; if (count($filterNodes) > 0) { $newFilterNodes = array(); $matchValue = true; $hasDynamicFilter = false; foreach ($filterNodes as $filterNode) { $filterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($filterNode); if (!isset($filterParameters['match'])) { continue; } $hasFilter = true; $filterParameterMatch = $filterParameters['match']; $filterParameterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $filterNode, $filterParameterMatch, $privateData); if (eZTemplateNodeTool::isStaticElement($filterParameterMatch)) { $matchValue = eZTemplateNodeTool::elementStaticValue($filterParameterMatch); if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') { if ($matchValue) { $matchValue = false; } } else { if ($matchValue) { $matchValue = true; } } $newFilterNodes = array(); $hasDynamicFilter = false; } else { $newFilterNodes[] = eZTemplateNodeTool::createVariableNode(false, $filterParameterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'tmpMatchValue'); if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') { $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n \$matchValue = false;", array('spacing' => 4)); } else { $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n \$matchValue = true;", array('spacing' => 4)); } $hasDynamicFilter = true; } } if ($hasFilter) { $mainSpacing += 4; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $matchValue, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'matchValue'); if ($hasDynamicFilter) { $newNodes = array_merge($newNodes, $newFilterNodes); } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$matchValue )\n{\n", array('spacing' => 4)); } } $sequencePopText = ''; if ($hasSequence) { $sequencePopText = ", \$sequence"; if ($varName) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . " \$sequenceValue = array_shift( \$sequence );\n" . " \$variableValue->setSequence( \$sequenceValue );\n" . " \$sequence[] = \$sequenceValue;\n" . " unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . " \$sequenceValue = array_shift( \$sequence );\n", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'sequenceValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => $mainSpacing + 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'sequence'), false, true, true); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" \$sequence[] = \$sequenceValue;\n" . " unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4)); } } $code = "\$sectionStack[] = array( " . $variableValuePushText . "&\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " );\n" . "unset( \$loopItem, \$loopKeys );\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($mainSpacing + 4); if ($delimiterNode) { $delimiterChildren = eZTemplateNodeTool::extractFunctionNodeChildren($delimiterNode); $delimiterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($delimiterNode); $delimiterChildren = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $delimiterChildren, $privateData); $delimiterModulo = false; $matchCode = false; $useModulo = true; if (isset($delimiterParameters['match'])) { $delimiterMatch = $delimiterParameters['match']; $delimiterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterNode, $delimiterMatch, $privateData); if (eZTemplateNodeTool::isStaticElement($delimiterMatch)) { $moduloValue = eZTemplateNodeTool::elementStaticValue($delimiterMatch); $useModulo = false; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'matchValue'); $matchCode = " and \$matchValue"; } } else { if (isset($delimiterParameters['modulo'])) { $delimiterModulo = $delimiterParameters['modulo']; $delimiterModulo = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterModulo, $delimiterModulo, $privateData); if (eZTemplateNodeTool::isStaticElement($delimiterModulo)) { $moduloValue = (int) eZTemplateNodeTool::elementStaticValue($delimiterModulo); $matchCode = " and ( ( \$currentIndex - 1 ) % {$moduloValue} ) == 0"; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterModulo, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'moduloValue'); $matchCode = " and ( ( \$currentIndex - 1 ) % \$moduloValue ) == 0"; } } } if ($useModulo) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$currentIndex > 1{$matchCode} )\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $delimiterChildren); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n"); } } $newNodes = array_merge($newNodes, $mainNodes); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($mainSpacing + 4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("list( " . $variableValuePopText . "\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " ) = array_pop( \$sectionStack );", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$currentIndex;\n", array('spacing' => $mainSpacing + 4)); if ($varName) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$lastVariableValue = \$variableValue;", array('spacing' => $mainSpacing + 4)); } if ($hasFilter) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" }"); $mainSpacing -= 4; } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$index;\n", array('spacing' => $mainSpacing + 4)); $code = "}\n" . "unset( \$loopKeys, \$loopCount, \$index, \$last, \$loopIndex, \$loopItem"; if ($hasSequence) { $code .= ", \$sequence"; } $code .= " );"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); } else { if ($useMain) { $newNodes = array_merge($newNodes, $mainNodes); } } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } if ($useShow) { $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing); } if ($useElse) { $elseNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'after', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else'))))); $elseNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $elseNodes, $privateData); if (count($elseNodes) > 0) { if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelse\n{\n"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show'); } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $newNodes = array_merge($newNodes, $elseNodes); if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing); } } if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n"); } } return $newNodes; }
function mergeTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $code = ''; $stringCode = ''; $paramCount = 0; $values = array(); $staticArray = array(); for ($i = 1; $i < count($parameters); ++$i) { if ($i != 1) { $code .= ', '; $stringCode .= ', '; } if (!eZTemplateNodeTool::isStaticElement($parameters[$i])) { $values[] = $parameters[$i]; ++$paramCount; if ($operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { $code .= '%' . $paramCount . '%'; } else { $code .= 'array( %' . $paramCount . '% )'; } $stringCode .= '%' . $paramCount . '%'; } else { if ($paramCount == 0) { $staticArray[] = eZTemplateNodeTool::elementStaticValue($parameters[$i]); } if ($operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { $code .= '' . eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false) . ''; } else { $tmp_check = eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false); // hiding "%1%", "%output%" etc. in static input string to avoid replacing it on "$var" inside compiler. $tmp_check = str_replace("%", '"."%"."', $tmp_check); $code .= 'array( ' . $tmp_check . ' )'; } $stringCode .= eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false); } } $isString = false; $isArray = false; $code2 = false; if ($parameters[0]) { if (!eZTemplateNodeTool::isStaticElement($parameters[0])) { $values[] = $parameters[0]; ++$paramCount; $code2 = '%' . $paramCount . '%'; } else { $isString = is_string(eZTemplateNodeTool::elementStaticValue($parameters[0])); $isArray = is_array(eZTemplateNodeTool::elementStaticValue($parameters[0])); if ($paramCount == 0) { // $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); } else { $code2 = eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[0]), 0, 0, false); } } } if ($paramCount == 0) { if ($operatorName == $this->AppendName or $operatorName == $this->ArrayAppendName or $operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { if ($isString) { $str = eZTemplateNodeTool::elementStaticValue($parameters[0]); for ($i = 0; $i < count($staticArray); ++$i) { $str .= $staticArray[$i]; } return array(eZTemplateNodeTool::createStringElement($str)); } else { if ($isArray) { $returnArray = eZTemplateNodeTool::elementStaticValue($parameters[0]); for ($i = 0; $i < count($staticArray); ++$i) { $returnArray = array_merge($returnArray, $staticArray[$i]); } return array(eZTemplateNodeTool::createArrayElement($returnArray)); } } } else { if ($operatorName == $this->PrependName or $operatorName == $this->ArrayPrependName) { if ($isString) { return array(eZTemplateNodeTool::createStringElement(eZTemplateNodeTool::elementStaticValue($parameters[1]) . eZTemplateNodeTool::elementStaticValue($parameters[0]))); } else { if ($isArray) { return array(eZTemplateNodeTool::createArrayElement(array_merge($staticArray, eZTemplateNodeTool::elementStaticValue($parameters[0])))); } } } } } if ($code2) { if ($operatorName == $this->AppendName) { $code = 'if ( is_string( ' . $code2 . ' ) )' . "\n" . ' %output% = ' . $code2 . ' . implode( \'\', array( ' . $stringCode . ' ) );' . "\n" . 'else if( is_array( ' . $code2 . ' ) )' . "\n" . ' %output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->ArrayAppendName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->MergeName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->ArrayMergeName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->PrependName) { $code = 'if ( is_string( ' . $code2 . ' ) )' . "\n" . ' %output% = implode( \'\', array( ' . $stringCode . ' ) ) . ' . $code2 . ';' . "\n" . 'else if( is_array( ' . $code2 . ' ) )' . "\n" . ' %output% = array_merge( ' . $code . ', ' . $code2 . ' );'; } else { if ($operatorName == $this->ArrayPrependName) { $code = '%output% = array_merge( ' . $code . ', ' . $code2 . ' );'; } } } } } } } else { if ($operatorName == $this->MergeName) { $code = '%output% = array_merge( ' . $code . ' );'; } else { $code = '%output% = array(' . $code . ');'; } } return array(eZTemplateNodeTool::createCodePieceElement($code . "\n", $values)); }
function processChildren() { // process the loop body $children = eZTemplateNodeTool::extractFunctionNodeChildren($this->Node); $transformedChildren = eZTemplateCompiler::processNodeTransformationNodes($this->Tpl, $this->Node, $children, $this->PrivateData); $childrenNodes = array(); $delimiter = null; if (is_array($transformedChildren)) { foreach ($transformedChildren as $child) { if ($child[0] == eZTemplate::NODE_FUNCTION) { $childFunctionName = $child[2]; if ($childFunctionName == 'delimiter') { // save delimiter for it to be processed below $delimiter = $child; continue; } elseif ($childFunctionName == 'break') { $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode("break;\n"); continue; } elseif ($childFunctionName == 'continue') { $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode("continue;\n"); continue; } elseif ($childFunctionName == 'skip') { $childrenNodes[] = eZTemplateNodeTool::createCodePieceNode("\$skipDelimiter = true;\ncontinue;\n"); continue; } } $childrenNodes[] = $child; } } if ($delimiter) { $delimiterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'delimiter'))))); $delimiterNode = false; if (count($delimiterNodes) > 0) { $delimiterNode = $delimiterNodes[0]; } $delimiterChildren = eZTemplateNodeTool::extractFunctionNodeChildren($delimiterNode); $delimiterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($delimiterNode); $checkModulo = array(); $checkModuloEnd = array(); $delemiterModuloValue = array(); if (isset($delimiterParameters['modulo'])) { switch ($this->Name) { case 'foreach': $delimiterModulo = $delimiterParameters['modulo']; $delimiterModulo = eZTemplateCompiler::processElementTransformationList($this->Tpl, $delimiterModulo, $delimiterModulo, $this->PrivateData); // Get unique index $currentIndex = "\$fe_i_{$this->UniqID}"; if (eZTemplateNodeTool::isStaticElement($delimiterModulo)) { $moduloValue = (int) eZTemplateNodeTool::elementStaticValue($delimiterModulo); $matchCode = "( ( {$currentIndex} ) % {$moduloValue} ) == 0"; } else { $delemiterModuloValue[] = eZTemplateNodeTool::createVariableNode(false, $delimiterModulo, eZTemplateNodeTool::extractFunctionNodePlacement($this->Node), array('spacing' => 0), 'moduloValue'); $matchCode = "( ( {$currentIndex} ) % \$moduloValue ) == 0"; } $checkModulo[] = eZTemplateNodeTool::createCodePieceNode("if ( {$matchCode} ) // Check modulo\n{"); $checkModulo[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $checkModuloEnd[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $checkModuloEnd[] = eZTemplateNodeTool::createCodePieceNode("}\n"); } } $delimiterNodes = array(); $delimiterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$skipDelimiter )\n" . " \$skipDelimiter = false;\n" . "else\n" . "{ // delimiter begins"); $delimiterNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); if (is_array($delimiter[1])) { // If modulo is specified $delimiterNodes = array_merge($delimiterNodes, $checkModulo); foreach ($delimiter[1] as $delimiterChild) { $delimiterNodes[] = $delimiterChild; } // Set end of checking for modulo $delimiterNodes = array_merge($delimiterNodes, $checkModuloEnd); } $delimiterNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $delimiterNodes[] = eZTemplateNodeTool::createCodePieceNode("} // delimiter ends\n"); // we place its code right before other loop children, // if delemiter and modulo are specified and value of modulo is not static // $delemiterModuloValue is initialization of variable // we should place initialization of moduloValue before checking for delimiter $childrenNodes = array_merge($delemiterModuloValue, $delimiterNodes, $childrenNodes); } $this->NewNodes = array_merge($this->NewNodes, $childrenNodes); }