function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $newNodes = array(); if ($functionName == $this->LName) { $newNodes = array(eZTemplateNodeTool::createTextNode($tpl->leftDelimiter())); } else { $newNodes = array(eZTemplateNodeTool::createTextNode($tpl->rightDelimiter())); } return $newNodes; }
function templateNodeTransformation($functionName, &$node, $tpl, &$resourceData, $parameters, $namespaceValue) { if ($this->Name != 'file') { return false; } $file = $resourceData['template-name']; if (!file_exists($file)) { return false; } $newNodes = array(); $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode($resourceData['resource'], $file, $file, eZTemplate::RESOURCE_FETCH, false, $node[4], array(), $namespaceValue); return $newNodes; }
function nl2brTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $function = $operatorName; if (count($parameters) != 1) { return false; } $newElements = array(); $values[] = $parameters[0]; $code = "%output% = nl2br( %1% );\n"; $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values); return $newElements; }
function phpOperatorTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $values = array(); $function = $operatorName; if (!isset($parameters[0])) { return false; } $newElements = array(); $phpname = $this->PHPNames[$operatorName]; $values[] = $parameters[0]; $code = "%output% = {$phpname}( %1% );\n"; $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values); return $newElements; }
function preferencesTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (count($parameters[0]) == 0) { return false; } $values = array(); if (eZTemplateNodeTool::isConstantElement($parameters[0])) { $name = eZTemplateNodeTool::elementConstantValue($parameters[0]); $nameText = eZPHPCreator::variableText($name, 0, 0, false); } else { $nameText = '%1%'; $values[] = $parameters[0]; } return array(eZTemplateNodeTool::createCodePieceElement("%output% = eZPreferences::value( {$nameText} );\n", $values)); }
function templateNodeTransformation($functionName, &$node, $tpl, &$parameters, $privateData) { // {while <condition> [sequence <sequence_array> as $<sequence_var>]} $tpl->WhileCounter++; $newNodes = array(); $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $uniqid = md5($nodePlacement[2]) . "_" . $tpl->WhileCounter; $loop = new eZTemplateCompiledLoop(eZTemplateWhileFunction::FUNCTION_NAME, $newNodes, $parameters, $nodePlacement, $uniqid, $node, $tpl, $privateData); $loop->initVars(); // loop header $newNodes[] = eZTemplateNodeTool::createCodePieceNode("while ( 1 ) // while\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['condition'], $nodePlacement, array('treat-value-as-non-object' => true), "while_cond"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( ! \$while_cond ) break;\n"); $loop->processBody(); // loop footer $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("} // end of while\n"); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('while_cond'); $loop->cleanup(); return $newNodes; }
function hashTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (count($parameters) != 1) { return false; } $code = ''; $function = ''; $newElements = array(); $values = array($parameters[0]); switch ($operatorName) { case 'crc32': $function = "eZSys::ezcrc32"; break; case 'rot13': $function = 'str_rot13'; break; default: $function = $operatorName; break; } $code .= "%output% = {$function}( %1% );\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) { $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 templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName == $this->TimingPointName) { $id = false; if (isset($parameters['id'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['id'])) { return false; } $id = eZTemplateNodeTool::elementConstantValue($parameters['id']); } $newNodes = array(); $startDescription = "debug-timing-point START: {$id}"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::addTimingPoint( " . var_export($startDescription, true) . " );"); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes = array_merge($newNodes, $children); $endDescription = "debug-timing-point END: {$id}"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::addTimingPoint( " . var_export($endDescription, true) . " );"); return $newNodes; } else { if ($functionName == $this->AccumulatorName) { $id = false; if (isset($parameters['id'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['id'])) { return false; } $id = eZTemplateNodeTool::elementConstantValue($parameters['id']); } $name = false; if (isset($parameters['name'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['name'])) { return false; } $name = eZTemplateNodeTool::elementConstantValue($parameters['name']); } // Assign a name (as $functionName) which will be used in the debug output. $name = ($name === false and $id === false) ? $functionName : $name; // To uniquely identify this accumulator. $id = $id === false ? uniqID($functionName . '_') : $id; $newNodes = array(); if ($name) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::accumulatorStart( " . var_export($id, true) . ", 'Debug-Accumulator', " . var_export($name, true) . " );"); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::accumulatorStart( " . var_export($id, true) . ", 'Debug-Accumulator' );"); } $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::accumulatorStop( " . var_export($id, true) . " );"); return $newNodes; } else { if ($functionName == $this->LogName) { $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $newNodes = array(); $varIsSet = $msgIsSet = false; if (isset($parameters['var'])) { $varIsSet = true; $var = $parameters['var']; } if (isset($parameters['msg'])) { $msgIsSet = true; $msg = $parameters['msg']; } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// debug-log starts\n"); if ($varIsSet) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $var, $nodePlacement, array('treat-value-as-non-object' => true), 'debug_log_var'); } if ($msgIsSet) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $msg, $nodePlacement, array('treat-value-as-non-object' => true), 'debug_log_msg'); } if ($varIsSet && $msgIsSet) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::writeDebug( \$debug_log_var, \$debug_log_msg );\n"); } elseif ($msgIsSet) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::writeDebug( \$debug_log_msg );\n"); } elseif ($varIsSet) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("eZDebug::writeDebug( \$debug_log_var );\n"); } if ($varIsSet) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("unset( \$debug_log_var );"); } if ($msgIsSet) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("unset( \$debug_log_msg );"); } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// debug-log ends\n"); return $newNodes; } else { if ($functionName == $this->TraceName) { $id = false; if (isset($parameters['id'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['id'])) { return false; } $id = eZTemplateNodeTool::elementConstantValue($parameters['id']); } if (!$id) { $id = 'template-debug'; } $newNodes = array(); $code = "if ( extension_loaded( 'xdebug' ) )\n" . "{\n" . "if ( file_exists( " . var_export($id . '.xt', true) . " ) )\n" . "{\n" . "\$fd = fopen( " . var_export($id . '.xt', true) . ", 'w' ); fclose( \$fd ); unset( \$fd );\n" . "}\n" . "xdebug_start_trace( " . var_export($id, true) . " );\n" . "}\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes = array_merge($newNodes, $children); $code = "if ( extension_loaded( 'xdebug' ) )\n" . "xdebug_stop_trace();\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); return $newNodes; } } } } return false; }
function operatorTransform($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (!eZTemplateNodeTool::isConstantElement($parameters[1]) || count($parameters) > 2 && !eZTemplateNodeTool::isConstantElement($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::isConstantElement($parameters[3])) { return false; } if (count($parameters) > 4 and !eZTemplateNodeTool::isConstantElement($parameters[4])) { return false; } if (count($parameters) > 5 and !eZTemplateNodeTool::isConstantElement($parameters[5])) { return false; } $locale = eZLocale::instance(); $decimalCount = $locale->decimalCount(); $decimalSymbol = $locale->decimalSymbol(); $decimalThousandsSeparator = $locale->thousandsSeparator(); if (count($parameters) > 2) { $prefix = eZTemplateNodeTool::elementConstantValue($parameters[2]); } else { $prefix = 'auto'; } if (count($parameters) > 3) { $decimalCount = eZTemplateNodeTool::elementConstantValue($parameters[3]); } elseif ($prefix == 'none') { $decimalCount = 0; } if (count($parameters) > 4) { $decimalSymbol = eZTemplateNodeTool::elementConstantValue($parameters[4]); } if (count($parameters) > 5) { $decimalThousandsSeparator = eZTemplateNodeTool::elementConstantValue($parameters[5]); } $decimalSymbolText = eZPHPCreator::variableText($decimalSymbol, 0, 0, false); $decimalThousandsSeparatorText = eZPHPCreator::variableText($decimalThousandsSeparator, 0, 0, false); $unit = eZTemplateNodeTool::elementConstantValue($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::isConstantElement($parameters[0])) { $output = eZTemplateNodeTool::elementConstantValue($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 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::isConstantElement($parameters['scope'])) { return false; } $scopeText = eZTemplateNodeTool::elementConstantValue($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::isConstantElement($parameters['name'])) { return false; } $name = eZTemplateNodeTool::elementConstantValue($parameters['name']); } $variableName = eZTemplateNodeTool::elementConstantValue($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) { $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::isConstantElement($parameters['expiry'])) { $expiryValue = eZTemplateNodeTool::elementConstantValue($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::elementConstantValue($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::isConstantElement($subtreeExpiryData)) { $hasKeys = true; } else { $subtreeValue = eZTemplateNodeTool::elementConstantValue($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 = "\$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 = ""; $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 templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { /* {foreach <array> as [$keyVar =>] $itemVar [sequence <array> as $sequenceVar] [offset <offset>] [max <max>] [reverse] } */ $tpl->ForeachCounter++; $newNodes = array(); $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $uniqid = md5($nodePlacement[2]) . "_" . $tpl->ForeachCounter; $loop = new eZTemplateCompiledLoop(eZTemplateForeachFunction::FUNCTION_NAME, $newNodes, $parameters, $nodePlacement, $uniqid, $node, $tpl, $privateData); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach begins"); $loop->initVars(); $array = "fe_array_{$uniqid}"; $arrayKeys = "fe_array_keys_{$uniqid}"; $nItems = "fe_n_items_{$uniqid}"; $nItemsProcessed = "fe_n_items_processed_{$uniqid}"; $i = "fe_i_{$uniqid}"; $key = "fe_key_{$uniqid}"; $val = "fe_val_{$uniqid}"; $offset = "fe_offset_{$uniqid}"; $max = "fe_max_{$uniqid}"; $reverse = "fe_reverse_{$uniqid}"; $firstVal = "fe_first_val_{$uniqid}"; $lastVal = "fe_last_val_{$uniqid}"; $variableStack = "fe_variable_stack_{$uniqid}"; $namesArray = array($array, $arrayKeys, $nItems, $nItemsProcessed, $i, $key, $val, $offset, $max, $reverse, $firstVal, $lastVal); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \${$variableStack} ) ) \${$variableStack} = array();"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$" . $variableStack . "[] = compact( '" . implode("', '", $namesArray) . "' );"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['array'], $nodePlacement, array('text-result' => false), $array); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$arrayKeys} = is_array( \${$array} ) ? array_keys( \${$array} ) : array();"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItems} = count( \${$arrayKeys} );"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItemsProcessed} = 0;"); // process offset, max and reverse parameters if (isset($parameters['offset'])) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['offset'], $nodePlacement, array('text-result' => false), $offset); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$offset} = 0;"); } if (isset($parameters['max'])) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], $nodePlacement, array('text-result' => false), $max); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$max} = \${$nItems} - \${$offset};"); } if (isset($parameters['reverse'])) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['reverse'], $nodePlacement, array('text-result' => false), $reverse); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$reverse} = false;"); } // fix definitely incorrect offset $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$offset} < 0 || \${$offset} >= \${$nItems} )\n{\n" . " \${$offset} = ( \${$offset} < 0 ) ? 0 : \${$nItems};\n" . " if ( \${$nItems} || \${$offset} < 0 )\n {\n" . " eZDebug::writeWarning(\"Invalid 'offset' parameter specified: '\${$offset}'. Array count: \${$nItems}\"); \n}\n}"); // fix definitely incorrect max $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$max} < 0 || \${$offset} + \${$max} > \${$nItems} )\n{\n" . " if ( \${$max} < 0 )\n eZDebug::writeWarning(\"Invalid 'max' parameter specified: \${$max}\");\n" . " \${$max} = \${$nItems} - \${$offset};\n}"); // initialize first and last indexes to iterate between them $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \${$reverse} )\n" . "{\n" . " \${$firstVal} = \${$nItems} - 1 - \${$offset};\n" . " \${$lastVal} = 0;\n" . "}\n" . "else\n" . "{\n" . " \${$firstVal} = \${$offset};\n" . " \${$lastVal} = \${$nItems} - 1;\n" . "}"); // generate loop header $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("for ( \${$i} = \${$firstVal}; " . "\${$nItemsProcessed} < \${$max} && ( \${$reverse} ? \${$i} >= \${$lastVal} : \${$i} <= \${$lastVal} ); " . "\${$reverse} ? \${$i}-- : \${$i}++ )\n" . "{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$key} = \${$arrayKeys}[\${$i}];"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$val} = \${$array}[\${$key}];"); // export $itemVar $newNodes[] = eZTemplateNodeTool::createVariableNode(false, "{$val}", $nodePlacement, array(), $parameters['item_var'][0][1], false, true, true); // export $keyVar (if specified) if (isset($parameters['key_var'])) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, "{$key}", $nodePlacement, array(), $parameters['key_var'][0][1], false, true, true); } $loop->processBody(); // generate loop footer $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\${$nItemsProcessed}++;"); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("} // foreach"); $loop->cleanup(); // unset the loop variables $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( count( \${$variableStack} ) ) extract( array_pop( \${$variableStack} ) );\n"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("else\n{\n"); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($array); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($arrayKeys); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($nItems); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($nItemsProcessed); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($i); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($key); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($val); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($offset); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($max); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($reverse); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($firstVal); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($lastVal); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode($variableStack); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// foreach ends"); 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::isConstantElement($parameters[0])) { return array(eZTemplateNodeTool::createConstantElement(eZTemplateNodeTool::elementConstantValue($parameters[0]))); } $newElements = array(); $counter = 1; $code = "%output% = ( "; foreach ($parameters as $parameter) { $values[] = $parameter; if ($counter > 1) { $code .= ' . '; } $code .= "%{$counter}%"; $counter++; } $code .= " );\n"; $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values); return $newElements; }
function 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::isConstantElement($uriData)) { return false; } $namespaceValue = false; $namespaceName = '$currentNamespace'; if (isset($parameters['name'])) { $nameData = $parameters['name']; if (!eZTemplateNodeTool::isConstantElement($nameData)) { return false; } $namespaceValue = eZTemplateNodeTool::elementConstantValue($nameData); $namespaceName = '$namespace'; } $uriString = eZTemplateNodeTool::elementConstantValue($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; }
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::isConstantElement($nameData)) { return false; } $namespaceValue = eZTemplateNodeTool::elementConstantValue($nameData); } if (isset($parameters['var'])) { $varData = $parameters['var']; if (!eZTemplateNodeTool::isConstantElement($varData)) { return false; } $varName = eZTemplateNodeTool::elementConstantValue($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 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::elementConstantValue($viewData); } else { $viewMode = "full"; } $params = $parameters; $namespaceValue = false; if (isset($parameters["name"])) { $nameData = $parameters["name"]; if (!eZTemplateNodeTool::isConstantElement($nameData)) { return false; } $nameValue = eZTemplateNodeTool::elementConstantValue($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 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::isConstantElement( $parameters['-scope'] ) ) return false; $scopeText = eZTemplateNodeTool::elementConstantValue( $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::isConstantElement( $parameters['-name'] ) ) { return false; } $namespaceValue = eZTemplateNodeTool::elementConstantValue( $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 templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $tpl->ElseifCounter++; $newNodes = array(); $nodesToPrepend = array(); $nodesToAppend = array(); $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $uniqid = md5($nodePlacement[2]) . "_" . $tpl->ElseifCounter; $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// if begins"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['condition'], $nodePlacement, array('treat-value-as-non-object' => true), 'if_cond'); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$if_cond )\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); if (is_array($children)) { foreach (array_keys($children) as $childKey) { $child =& $children[$childKey]; if ($child[0] == eZTemplate::NODE_FUNCTION) { $childFunctionName =& $child[2]; $childChildren = eZTemplateNodeTool::extractFunctionNodeChildren($child); $childFunctionArgs =& $child[3]; if ($childFunctionName == 'elseif') { $compiledElseifCondition = eZTemplateCompiler::processElementTransformationList($tpl, $child, $childFunctionArgs['condition'], $privateData); $nodesToPrepend[] = eZTemplateNodeTool::createVariableNode(false, $compiledElseifCondition, $nodePlacement, array('text-result' => true), "elseif_cond_{$uniqid}"); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelseif ( \$elseif_cond_{$uniqid} )\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); $nodesToAppend[] = eZTemplateNodeTool::createVariableUnsetNode("elseif_cond_{$uniqid}"); // increment unique elseif counter $uniqid = md5($nodePlacement[2]) . "_" . ++$tpl->ElseifCounter; } elseif ($childFunctionName == 'else') { $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelse\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); } elseif ($childFunctionName == 'break') { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("break;\n"); } elseif ($childFunctionName == 'continue') { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("continue;\n"); } elseif ($childFunctionName == 'skip') { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$skipDelimiter = true;\ncontinue;\n"); } // let other functions (ones not listed in the conditions above) be transformed if (in_array($childFunctionName, array('elseif', 'else', 'break', 'continue', 'skip'))) { continue; } } $newNodes[] = $child; } } $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("unset( \$if_cond );"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// if ends\n"); $newNodes = array_merge($nodesToPrepend, $newNodes, $nodesToAppend); return $newNodes; }
function templateNodeTransformation($functionName, &$node, $tpl, &$parameters, $privateData) { $undef = $functionName == 'undef'; $newNodes = array(); if (!$parameters) { if (!$undef) { // prevent execution of the function in processed mode return array(eZTemplateNodeTool::createCodePieceNode("// an error occured in {$functionName}")); } // {undef} called w/o arguments => destroy all local variables $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// undef all"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$tpl->unsetLocalVariables();"); return $newNodes; } $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); foreach (array_keys($parameters) as $parameterName) { $parameterData = $parameters[$parameterName]; if ($undef) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// undef \${$parameterName}"); // generates "$tpl->unsetLocalVariable();" $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue = false, $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL, $parameterName), array('remember_set' => false, 'local-variable' => true)); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("// def \${$parameterName}"); // generates "$tpl->setLocalVariable();" $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, $nodePlacement, array('local-variable' => true), array($namespaceValue = false, $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL, $parameterName), $onlyExisting = false, $overwrite = true, false, $rememberSet = false); } } 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 resourceAcquisitionTransformation( $functionName, &$node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, $acquisitionSpacing, &$resourceData ) { $startRoot = '/' . $templateRoot . $viewDir; $viewFileMatchName = '/' . $templateRoot . '/' . $viewValue . '.tpl'; $startRootLength = strlen( $startRoot ); $matchList = array(); $viewFileMatch = null; foreach ( $matchFileArray as $matchFile ) { if ( !isset( $matchFile['template'] ) ) continue; $path = $matchFile['template']; if ( substr( $path, 0, $startRootLength ) == $startRoot and $path[$startRootLength] == '/' ) { $matchFile['match_part'] = substr( $path, $startRootLength + 1 ); $matchList[] = $matchFile; } if ( $path == $viewFileMatchName ) $viewFileMatch = $matchFile; } $designKeysName = 'dKeys'; $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" . "{\n" . " \$resH = \$tpl->resourceHandler( 'design' );\n" . " \$$designKeysName = \$resH->keys();\n" . "}", array( 'spacing' => $acquisitionSpacing ) ); if ( isset( $rule["attribute_keys"] ) ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$" . $designKeysName . "Stack ) )\n" . "{\n" . " \$" . $designKeysName . "Stack = array();\n" . "}\n" . "\$" . $designKeysName . "Stack[] = \$$designKeysName;", array( 'spacing' => $acquisitionSpacing ) ); foreach ( $rule["attribute_keys"] as $designKey => $attributeKeyArray ) { $attributeAccessData = array(); $attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE ); foreach ( $attributeKeyArray as $attributeKey ) { $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeKey ); } $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false, array( 'spacing' => 0 ), 'dKey' ); $designKeyText = eZPHPCreator::variableText( $designKey, 0, 0, false ); $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $designKeysName . "[$designKeyText] = \$dKey;", array( 'spacing' => $acquisitionSpacing ) ); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'dKey' ); } } $attributeAccess = $rule["attribute_access"]; $hasAttributeAccess = false; if ( is_array( $attributeAccess ) ) { $hasAttributeAccess = count( $attributeAccess ) > 0; $attributeAccessCount = 0; foreach ( $attributeAccess as $attributeAccessEntries ) { $attributeAccessData = $inputData; $spacing = $acquisitionSpacing; if ( $attributeAccessCount > 1 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " if ( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $spacing += 4; } else if ( $attributeAccessCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $spacing += 4; } foreach ( $attributeAccessEntries as $attributeAccessName ) { // $attributeAccessData[] = eZTemplateNodeTool::createCodePieceNode( "" . ( $resourceData['use-comments'] ? ( "/*TC:" . __LINE__ . "*/" ) : "" ) . "" ); $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeAccessName ); } $accessNodes = array(); $accessNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false, array( 'spacing' => $spacing ), 'attributeAccess' ); $acquisitionNodes = array(); $templateCounter = 0; $hasAcquisitionNodes = false; $matchLookupArray = array(); foreach ( $matchList as $matchItem ) { $tmpAcquisitionNodes = array(); $matchPart = $matchItem['match_part']; if ( preg_match( "/^(.+)\.tpl$/", $matchPart, $matches ) ) $matchPart = $matches[1]; $code = "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$attributeAccess == '$matchPart' )\n{\n"; if ( $templateCounter > 0 ) $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "" . $code; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $spacing ) ); $defaultMatchSpacing = $spacing; $useArrayLookup = false; $addFileResource = true; if ( isset( $matchItem['custom_match'] ) ) { $customSpacing = $spacing + 4; $defaultMatchSpacing = $spacing + 4; $matchCount = 0; foreach ( $matchItem['custom_match'] as $customMatch ) { $matchConditionCount = count( $customMatch['conditions'] ); $code = ''; if ( $matchCount > 0 ) { $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . ""; } if ( $matchConditionCount > 0 ) { if ( $matchCount > 0 ) $code .= " "; $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( "; } $ifLength = strlen( $code ); $conditionCount = 0; if ( isset( $customMatch['conditions'] ) ) { foreach ( $customMatch['conditions'] as $conditionName => $conditionValue ) { if ( $conditionCount > 0 ) $code .= " and\n" . str_repeat( ' ', $ifLength ); $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 ); $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 ); $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and "; if ( $conditionNameText == '"url_alias"' ) { $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )"; } else { $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " . "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " . "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )"; } ++$conditionCount; } } if ( $matchConditionCount > 0 ) { $code .= " )\n"; } if ( $matchConditionCount > 0 or $matchCount > 0 ) { $code .= "{"; } $matchFile = $customMatch['match_file']; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $customSpacing ) ); $hasAcquisitionNodes = true; // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchFile ) ) return false; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $customSpacing + 4 ), $rule['namespace'] ); if ( $matchConditionCount > 0 or $matchCount > 0 ) { $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) ); } ++$matchCount; if ( $matchConditionCount == 0 ) { $addFileResource = false; break; } } if ( $addFileResource ) $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " \n{", array( 'spacing' => $customSpacing ) ); } else { $matchFile = $matchItem['base_dir'] . $matchItem['template']; $matchLookupArray[$matchPart] = $matchFile; $useArrayLookup = true; } if ( !$useArrayLookup ) { if ( $addFileResource ) { $matchFile = $matchItem['base_dir'] . $matchItem['template']; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $defaultMatchSpacing + 4 ), $rule['namespace'] ); $hasAcquisitionNodes = true; if ( isset( $matchItem['custom_match'] ) ) $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) ); } ++$templateCounter; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) ); $acquisitionNodes = array_merge( $acquisitionNodes, $tmpAcquisitionNodes ); } } if ( count( $matchLookupArray ) > 0 ) { $newNodes = array_merge( $newNodes, $accessNodes ); $accessNodes = array(); // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchLookupArray ) ) return false; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchLookupArray, false, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $spacing ), $rule['namespace'], 'attributeAccess' ); if ( $hasAcquisitionNodes ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $spacing ) ); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); } } if ( $hasAcquisitionNodes ) { $newNodes = array_merge( $newNodes, $accessNodes, $acquisitionNodes ); if ( $attributeAccessCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); } ++$attributeAccessCount; } else if ( count( $matchLookupArray ) == 0 ) { $newNodes[] = eZTemplateNodeTool::createErrorNode( "Failed to load template", $functionName, eZTemplateNodeTool::extractFunctionNodePlacement( $node ), array( 'spacing' => $acquisitionSpacing ) ); } if ( count( $matchLookupArray ) > 0 and $hasAcquisitionNodes ) { $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) ); } } } if ( $viewFileMatch !== null ) { $mainSpacing = 0; if ( $hasAttributeAccess ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $mainSpacing = 4; } $templateCounter = 0; $addFileResource = true; if ( isset( $viewFileMatch['custom_match'] ) ) { $spacing = $mainSpacing + 4; $matchCount = 0; foreach ( $viewFileMatch['custom_match'] as $customMatch ) { $matchConditionCount = count( $customMatch['conditions'] ); $code = ''; if ( $matchCount > 0 ) { $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . ""; } if ( $matchConditionCount > 0 ) { if ( $matchCount > 0 ) $code .= " "; $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( "; $ifLength = strlen( $code ); $conditionCount = 0; if ( is_array( $customMatch['conditions'] ) ) { foreach ( $customMatch['conditions'] as $conditionName => $conditionValue ) { if ( $conditionCount > 0 ) $code .= " and\n" . str_repeat( ' ', $ifLength ); $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 ); $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 ); $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and "; if ( $conditionNameText == '"url_alias"' ) { $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )"; } else { $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " . "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " . "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )"; } ++$conditionCount; } } $code .= " )\n"; } if ( $matchConditionCount > 0 or $matchCount > 0 ) { $code .= "{"; } $matchFile = $customMatch['match_file']; $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $acquisitionSpacing ) ); // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchFile ) ) return false; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $spacing ), $rule['namespace'] ); if ( $matchConditionCount > 0 or $matchCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); } ++$matchCount; if ( $matchConditionCount == 0 ) { if ( $matchCount > 0 ) $addFileResource = false; break; } } if ( $addFileResource ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $acquisitionSpacing ) ); } if ( $addFileResource ) { $file = $viewFileMatch['base_dir'] . $viewFileMatch['template']; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $file, $file, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $mainSpacing ), $rule['namespace'] ); } if ( isset( $viewFileMatch['custom_match'] ) and $addFileResource ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); if ( $hasAttributeAccess ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}\n", array( 'spacing' => $acquisitionSpacing ) ); } if ( isset( $rule["attribute_keys"] ) ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$designKeysName = array_pop( \$" . $designKeysName . "Stack );", array( 'spacing' => $acquisitionSpacing ) ); } return $newNodes; }
function isTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters ) { $values = array(); $values[] = $parameters[0]; $code = '%output% = '; switch( $operatorName ) { case $this->IsArrayName: { $code .= 'is_array( %1% );'; } break; case $this->IsBooleanName: { $code .= '( %1% === true || %1% === false );'; } break; case $this->IsIntegerName: { $code .= 'is_int( %1% );'; } break; case $this->IsFloatName: { $code .= 'is_float( %1% );'; } break; case $this->IsNumericName: { $code .= 'is_numeric( %1% );'; } break; case $this->IsStringName: { $code .= 'is_string( %1% );'; } break; case $this->IsObjectName: { $code .= 'is_object( %1% );'; } break; case $this->IsClassName: { $code .= '( strtolower( get_class( %1% ) ) == strtolower( %2% ) );'; $values[] = $parameters[1]; } break; case $this->IsNullName: { $code .= '(%1% === null);'; } break; case $this->IsSetName: { $code .= 'isset( %1% );'; } break; case $this->IsUnsetName: { $code .= '!isset( %1% );'; } break; case $this->GetTypeName: { return false; } break; case $this->GetClassName: { $code .= 'strtolower( get_class( %1% ) );'; } break; } 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::isConstantElement( $parameters[0] ) || !eZTemplateNodeTool::isConstantElement( $parameters[1] ) ) { return false; } $moduleName = eZTemplateNodeTool::elementConstantValue( $parameters[0] ); $functionName = eZTemplateNodeTool::elementConstantValue( $parameters[1] ); $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $moduleName ); if ( !$moduleFunctionInfo->isValid() ) { eZDebug::writeError( "Cannot execute module '$moduleName', no module found", __METHOD__ ); return array(); } $fetchParameters = array(); if ( isset( $parameters[2] ) ) $fetchParameters = $parameters[2]; } else if ( $operatorName == $this->FetchAlias ) { if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) ) { return false; } $aliasFunctionName = eZTemplateNodeTool::elementConstantValue( $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", __METHOD__ ); 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::isConstantElement( $fetchParameters ) ) { $staticParameters = eZTemplateNodeTool::elementConstantValue( $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::isConstantElement( $dynamicParameters[$parameterName] ) ) { $parametersCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $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 ) ); }
static function deflateFunctionNode(&$node, $preHook, $postHook) { $newNodes = array(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); eZTemplateNodeTool::removeFunctionNodeChildren($node); $preNode = $node; $preHookParameters = array(); if (isset($preHook['parameters'])) { $preHookParameters = $preHook['parameters']; } $preHookFunction = false; if (isset($preHook['function'])) { $preHookFunction = $preHook['function']; } eZTemplateNodeTool::createFunctionNodeHook($preNode, $preHook['name'], $preHookParameters, $preHookFunction); if (isset($preHook['use-parameters']) and !$preHook['use-parameters']) { eZTemplateNodeTool::removeFunctionNodeParameters($preNode); } $newNodes[] = $preNode; $newNodes = array_merge($newNodes, $children); $postNode = $node; $postHookParameters = array(); if (isset($postHook['parameters'])) { $postHookParameters = $postHook['parameters']; } $postHookFunction = false; if (isset($postHook['function'])) { $postHookFunction = $postHook['function']; } eZTemplateNodeTool::createFunctionNodeHook($postNode, $postHook['name'], $postHookParameters, $postHookFunction); if (isset($postHook['use-parameters']) and !$postHook['use-parameters']) { eZTemplateNodeTool::removeFunctionNodeParameters($postNode); } $newNodes[] = $postNode; return $newNodes; }
function templateNodeTransformation($functionName, &$node, $tpl, &$resourceData, $parameters, $namespaceValue) { if ($this->Name != 'design' and $this->Name != 'standard') { return false; } $file = $resourceData['template-name']; $matchFileArray = eZTemplateDesignResource::overrideArray($this->OverrideSiteAccess); $matchList = array(); foreach ($matchFileArray as $matchFile) { if (!isset($matchFile['template'])) { continue; } if ($matchFile['template'] == '/' . $file) { $matchList[] = $matchFile; } } $resourceName = $resourceData['resource']; $resourceNameText = eZPHPCreator::variableText($resourceName); $designKeysName = 'dKeys'; if ($resourceName == 'standard') { $designKeysName = 'rKeys'; } $newNodes = array(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if " . ($resourceData['use-comments'] ? "/*TDR:" . __LINE__ . "*/" : "") . "( !isset( \${$designKeysName} ) )\n" . "{\n" . " \$resH = \$tpl->resourceHandler( {$resourceNameText} );\n" . " \${$designKeysName} = \$resH->keys();" . "\n" . "}\n"); foreach ($matchList as $match) { $basedir = $match['base_dir']; $template = $match['template']; $file = $basedir . $template; $spacing = 0; $addFileResource = true; if (isset($match['custom_match'])) { $spacing = 4; $customMatchList = $match['custom_match']; $matchCount = 0; foreach ($customMatchList as $customMatch) { $matchConditionCount = count($customMatch['conditions']); $code = ''; if ($matchCount > 0) { $code = "else " . ($resourceData['use-comments'] ? "/*TDR:" . __LINE__ . "*/" : "") . ""; } if ($matchConditionCount > 0) { if ($matchCount > 0) { $code .= " "; } $code .= "if " . ($resourceData['use-comments'] ? "/*TDR:" . __LINE__ . "*/" : "") . "( "; } $ifLength = strlen($code); $conditionCount = 0; if (is_array($customMatch['conditions'])) { foreach ($customMatch['conditions'] as $conditionName => $conditionValue) { if ($conditionCount > 0) { $code .= " and\n" . str_repeat(' ', $ifLength); } $conditionNameText = eZPHPCreator::variableText($conditionName, 0); $conditionValueText = eZPHPCreator::variableText($conditionValue, 0); $code .= "isset( \$" . $designKeysName . "[{$conditionNameText}] ) and "; if ($conditionName == 'url_alias') { $code .= "(strpos( \$" . $designKeysName . "[{$conditionNameText}], {$conditionValueText} ) === 0 )"; } else { $code .= "( is_array( \$" . $designKeysName . "[{$conditionNameText}] ) ? " . "in_array( {$conditionValueText}, \$" . $designKeysName . "[{$conditionNameText}] ) : " . "\$" . $designKeysName . "[{$conditionNameText}] == {$conditionValueText} )"; } ++$conditionCount; } } if ($matchConditionCount > 0) { $code .= " )\n"; } if ($matchConditionCount > 0 or $matchCount > 0) { $code .= "{"; } $matchFile = $customMatch['match_file']; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode('', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array('spacing' => $spacing), $namespaceValue); if ($matchConditionCount > 0 or $matchCount > 0) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); } ++$matchCount; if ($matchConditionCount == 0) { $addFileResource = false; break; } } if ($addFileResource) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("else" . ($resourceData['use-comments'] ? "/*TDR:" . __LINE__ . "*/" : "") . "\n{"); } } if ($addFileResource) { $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode('', $file, $file, eZTemplate::RESOURCE_FETCH, false, $node[4], array('spacing' => $spacing), $namespaceValue); } if (isset($match['custom_match']) and $addFileResource) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); } } return $newNodes; }
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::elementConstantValue($parameters[0]); $numParameters = count($parameters); $context = $numParameters > 1 ? eZTemplateNodeTool::elementConstantValue($parameters[1]) : null; $comment = $numParameters > 2 ? eZTemplateNodeTool::elementConstantValue($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 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 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::isConstantElement($parameters[$i])) { $staticValues[$i] = eZTemplateNodeTool::elementConstantValue($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}' ), htmlspecialchars( %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; }