本文整理汇总了PHP中eZTemplateNodeTool::elementConstantValue方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTemplateNodeTool::elementConstantValue方法的具体用法?PHP eZTemplateNodeTool::elementConstantValue怎么用?PHP eZTemplateNodeTool::elementConstantValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZTemplateNodeTool
的用法示例。
在下文中一共展示了eZTemplateNodeTool::elementConstantValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
if ($functionName != $this->BlockName) {
return false;
}
$parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node);
if (!isset($parameters['name'])) {
return false;
}
$namespaceValue = false;
$newNodes = array();
if (isset($parameters["name"])) {
$menuIni = eZINI::instance("menu.ini");
$nameData = $parameters["name"];
if (!eZTemplateNodeTool::isConstantElement($nameData)) {
return false;
}
$menuName = eZTemplateNodeTool::elementConstantValue($nameData);
if ($menuIni->hasVariable('SelectedMenu', $menuName)) {
$menuTemplate = $menuIni->variable("SelectedMenu", $menuName);
if ($menuTemplate != null) {
$uriString = "design:menu/{$menuTemplate}.tpl";
$resourceName = "";
$templateName = "";
$resource = $tpl->resourceFor($uriString, $resourceName, $templateName);
$resourceData = $tpl->resourceData($resource, $uriString, $resourceName, $templateName);
$resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
$includeNodes = $resource->templateNodeTransformation($functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue);
if ($includeNodes === false) {
return false;
}
$variableList = array();
foreach (array_keys($parameters) as $parameterName) {
if ($parameterName == 'name') {
continue;
}
$parameterData =& $parameters[$parameterName];
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameterData, false, array(), array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName));
$variableList[] = $parameterName;
}
$newNodes = array_merge($newNodes, $includeNodes);
foreach ($variableList as $variableName) {
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode(array($namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName));
}
} else {
// to do: not use this function to generate empty code.
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("");
}
} else {
// to do: not use this function to generate empty code.
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("");
}
}
return $newNodes;
}
示例2: templateNodeTransformation
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;
}
示例3: preferencesTransformation
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));
}
示例4: i18nTrans
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));
}
示例5: templateNodeTransformation
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;
}
示例6: templateNodeTransformation
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;
}
//.........这里部分代码省略.........
示例7: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
$newNodes = array();
$namespaceValue = false;
$varName = 'match';
if (!isset($parameters['name'])) {
return false;
}
if (!eZTemplateNodeTool::isConstantElement($parameters['name'])) {
return false;
}
$nameData = $parameters['name'];
$nameValue = eZTemplateNodeTool::elementConstantValue($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::isConstantElement($loopData)) {
return false;
}
$loopValue = eZTemplateNodeTool::elementConstantValue($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;
}
示例8: fetchTransform
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 ) )
{
//.........这里部分代码省略.........
示例9: concatTransformation
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;
}
示例10: operatorTransform
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) {
//.........这里部分代码省略.........
示例11: washTransformation
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;
}
示例12: templateNodeTransformation
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData)
{
$useLastValue = false;
if (isset($parameters['last-value']) and !eZTemplateNodeTool::isConstantElement($parameters['last-value'])) {
return false;
}
if (isset($parameters['name']) and !eZTemplateNodeTool::isConstantElement($parameters['name'])) {
return false;
}
if (isset($parameters['var']) and !eZTemplateNodeTool::isConstantElement($parameters['var'])) {
return false;
}
if (isset($parameters['reverse']) and !eZTemplateNodeTool::isConstantElement($parameters['reverse'])) {
return false;
}
$varName = false;
if (isset($parameters['var'])) {
$varName = eZTemplateNodeTool::elementConstantValue($parameters['var']);
}
if (isset($parameters['last-value'])) {
$useLastValue = (bool) eZTemplateNodeTool::elementConstantValue($parameters['last-value']);
}
if (!$varName) {
$useLastValue = false;
}
$reverseLoop = false;
if (isset($parameters['reverse'])) {
$reverseLoop = eZTemplateNodeTool::elementConstantValue($parameters['reverse']);
}
$useLoop = isset($parameters['loop']);
$allowLoop = true;
$newNodes = array();
$maxText = "false";
$useMax = false;
$maxPopText = false;
if (isset($parameters['max'])) {
if (eZTemplateNodeTool::isConstantElement($parameters['max'])) {
$maxValue = eZTemplateNodeTool::elementConstantValue($parameters['max']);
if ($maxValue > 0) {
$maxText = eZPHPCreator::variableText($maxValue);
$useMax = true;
} else {
return array(eZTemplateNodeTool::createTextNode(''));
}
} else {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'max');
$maxText = "\$max";
$maxPopText = ", \$max";
$useMax = true;
}
}
// Controls whether the 'if' statement with brackets is added
$useShow = false;
// Controls whether main nodes are handled, also controls delimiter and filters
$useMain = true;
// Controls wether else nodes are handled
$useElse = false;
$spacing = 0;
if (isset($parameters['show'])) {
if (eZTemplateNodeTool::isConstantElement($parameters['show'])) {
$showValue = eZTemplateNodeTool::elementConstantValue($parameters['show']);
if ($showValue) {
$useMain = true;
$useElse = false;
$useShow = false;
} else {
$useMain = false;
$useElse = true;
$useShow = false;
}
$newNodes[] = eZTemplateNodeTool::createTextNode('');
} else {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['show'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'show');
$spacing = 4;
$useElse = true;
$useShow = true;
}
}
$children = eZTemplateNodeTool::extractFunctionNodeChildren($node);
if ($useShow) {
$newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$show )\n{\n");
$newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing);
$newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show');
}
if (isset($parameters['name']) and !$useLoop) {
$newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']);
}
$mainNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'before', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else')), 'filter' => array(array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('delimiter', 'section-exclude', 'section-include')))))));
$delimiterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'delimiter')))));
$filterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('section-exclude', 'section-include'))))));
$delimiterNode = false;
if (count($delimiterNodes) > 0) {
$delimiterNode = $delimiterNodes[0];
}
if ($useMain) {
// Avoid transformation if the nodes will not be used, saves time
$mainNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $mainNodes, $privateData);
}
if ($useLoop and $useMain) {
$newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['loop'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'loopItem');
//.........这里部分代码省略.........
示例13: mergeTrans
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::isConstantElement($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::elementConstantValue($parameters[$i]);
}
if ($operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) {
$code .= '' . eZPHPCreator::variableText(eZTemplateNodeTool::elementConstantValue($parameters[$i]), 0, 0, false) . '';
} else {
$tmp_check = eZPHPCreator::variableText(eZTemplateNodeTool::elementConstantValue($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::elementConstantValue($parameters[$i]), 0, 0, false);
}
}
$isString = false;
$isArray = false;
$code2 = false;
if ($parameters[0]) {
if (!eZTemplateNodeTool::isConstantElement($parameters[0])) {
$values[] = $parameters[0];
++$paramCount;
$code2 = '%' . $paramCount . '%';
} else {
$isString = is_string(eZTemplateNodeTool::elementConstantValue($parameters[0]));
$isArray = is_array(eZTemplateNodeTool::elementConstantValue($parameters[0]));
if ($paramCount == 0) {
// $staticArray[] = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
} else {
$code2 = eZPHPCreator::variableText(eZTemplateNodeTool::elementConstantValue($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::elementConstantValue($parameters[0]);
for ($i = 0; $i < count($staticArray); ++$i) {
$str .= $staticArray[$i];
}
return array(eZTemplateNodeTool::createStringElement($str));
} else {
if ($isArray) {
$returnArray = eZTemplateNodeTool::elementConstantValue($parameters[0]);
for ($i = 0; $i < count($staticArray); ++$i) {
if (is_array($staticArray[$i])) {
$returnArray = array_merge($returnArray, $staticArray[$i]);
} else {
$returnArray[] = $staticArray[$i];
}
}
return array(eZTemplateNodeTool::createArrayElement($returnArray));
}
}
} else {
if ($operatorName == $this->PrependName or $operatorName == $this->ArrayPrependName) {
if ($isString) {
return array(eZTemplateNodeTool::createStringElement(eZTemplateNodeTool::elementConstantValue($parameters[1]) . eZTemplateNodeTool::elementConstantValue($parameters[0])));
} else {
if ($isArray) {
return array(eZTemplateNodeTool::createArrayElement(array_merge($staticArray, eZTemplateNodeTool::elementConstantValue($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 {
//.........这里部分代码省略.........
示例14: condTransform
function condTransform( $operatorName, &$node, $tpl, &$resourceData,
$element, $lastElement, $elementList, $elementTree, &$parameters )
{
switch( $operatorName )
{
case $this->CondName:
{
$paramCount = count( $parameters );
$clauseCount = floor( $paramCount / 2 );
$hasDefaultClause = ( $paramCount % 2 ) != 0;
if ( $paramCount == 1 )
{
return $parameters[0];
}
$values = array();
$code = '';
$spacing = 0;
$spacingCode = '';
for ( $i = 0; $i < $clauseCount; ++$i )
{
$prevSpacingCode = $spacingCode;
$spacingCode = str_repeat( " ", $spacing*4 );
if ( $i > 0 )
{
$code .= $prevSpacingCode . "else\n" . $prevSpacingCode . "{\n";
}
$values[] = $parameters[$i*2];
if ( $i > 0 )
{
$code .= $spacingCode . "%code" . count( $values ) . "%\n";
}
$code .= $spacingCode. 'if ( %' . count( $values ) . "% )\n" . $spacingCode . "{\n";
if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i*2 + 1] ) )
{
$values[] = $parameters[$i*2 + 1];
$code .= ( $spacingCode . " %code" . count( $values ) . "%\n" .
$spacingCode . " %output% = %" . count( $values ) . "%;\n" );
}
else
{
$code .= $spacingCode . ' %output% = ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i*2 + 1] ), 0, 0, false ) . ';' . "\n";
}
$code .= $spacingCode . "}\n";
++$spacing;
}
$bracketCount = $clauseCount - 1;
if ( $hasDefaultClause )
{
++$bracketCount;
$values[] = $parameters[$paramCount - 1];
if ( $clauseCount > 0 )
{
$code .= $spacingCode . "else\n" . $spacingCode . "{\n" . $spacingCode . " %code" . count( $values ) . "%\n ";
}
$code .= $spacingCode . '%output% = %' . count( $values ) . "%;\n";
}
for ( $clauseIndex = 0; $clauseIndex < $bracketCount; ++$clauseIndex )
{
$spacingCode = str_repeat( " ", ( $bracketCount - $clauseIndex - 1 ) *4 );
$code .= $spacingCode . "}\n";
}
return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
} break;
case $this->FirstSetName:
{
$values = array();
$code = '';
$spacing = 0;
$spacingCode = '';
$nestCount = 0;
for( $i = 0; $i < count( $parameters ); ++$i )
{
if ( $i != 0 )
{
$code .= "$spacingCode}\n" . $spacingCode . "else\n$spacingCode{\n";
}
$spacingCode = str_repeat( ' ', $spacing*4 );
++$spacing;
if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
{
$code .= "$spacingCode%output% = " . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false ) . ";\n";
break;
}
++$nestCount;
$values[] = $parameters[$i];
$code .= ( $spacingCode . "%code" . count( $values ) . "%\n" .
$spacingCode . 'if ( isset( %' . count( $values ) . "% ) )\n" .
$spacingCode . "{\n" .
$spacingCode . " %output% = %" . count( $values ) . '%;' . "\n" );
}
for ( $i = 0; $i < $nestCount; ++$i )
//.........这里部分代码省略.........
示例15: romanTransformation
function romanTransformation( $operatorName, &$node, $tpl, &$resourceData,
$element, $lastElement, $elementList, $elementTree, &$parameters )
{
$values = array();
if ( count( $parameters ) != 1 )
return false;
$newElements = array();
if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
{
$staticResult = $this->buildRoman( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
}
else
{
return false;
}
}