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;
 }
示例#2
0
 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 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;
 }
示例#5
0
 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;
 }
示例#6
0
    function urlTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
    {
        $ini = eZINI::instance();
        $shareTemplates = $ini->hasVariable('TemplateSettings', 'ShareCompiledTemplates') ? $ini->variable('TemplateSettings', 'ShareCompiledTemplates') == 'enabled' : false;
        $useTmp = false;
        $newElements = array();
        $values = array();
        $paramCount = 0;
        $tmpCount = 0;
        switch ($operatorName) {
            case $this->URLName:
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                    $url = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                    $serverURL = isset($parameters[2]) ? eZTemplateNodeTool::elementStaticValue($parameters[2]) : 'relative';
                    eZURI::transformURI($url, false, $serverURL);
                    $url = $this->applyQuotes($url, $parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($url));
                } else {
                    if ($shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                        $url = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                        $values[] = array(eZTemplateNodeTool::createStringElement($url));
                        $values[] = isset($parameters[2]) ? $parameters[2] : array(eZTemplateNodeTool::createStringElement('relative'));
                        $code = <<<CODEPIECE

%tmp1% = %1%;
eZURI::transformURI( %tmp1%, false, %2% );

CODEPIECE;
                        $useTmp = true;
                        ++$tmpCount;
                    } else {
                        $values[] = $parameters[0];
                        $values[] = isset($parameters[2]) ? $parameters[2] : array(eZTemplateNodeTool::createStringElement('relative'));
                        $code = <<<CODEPIECE

//include_once( 'lib/ezutils/classes/ezuri.php' );
eZURI::transformURI( %1%, false, %2% );

CODEPIECE;
                    }
                }
                ++$paramCount;
                break;
            case $this->URLRootName:
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                    $url = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                    if (preg_match("#^[a-zA-Z0-9]+:#", $url) or substr($url, 0, 2) == '//') {
                        $url = '/';
                    } else {
                        if (strlen($url) > 0 and $url[0] != '/') {
                            $url = '/' . $url;
                        }
                    }
                    $serverURL = isset($parameters[2]) ? eZTemplateNodeTool::elementStaticValue($parameters[2]) : 'relative';
                    // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
                    eZURI::transformURI($url, true, $serverURL);
                    $url = $this->applyQuotes($url, $parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($url));
                } else {
                    if ($shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                        $url = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                        $values[] = array(eZTemplateNodeTool::createStringElement($url));
                        $values[] = isset($parameters[2]) ? $parameters[2] : array(eZTemplateNodeTool::createStringElement('relative'));
                        $code = '%tmp1% = %1%;';
                        $code .= 'if ( preg_match( "#^[a-zA-Z0-9]+:#", %tmp1% ) or' . "\n" . 'substr( %tmp1%, 0, 2 ) == \'//\' )' . "\n" . '  %tmp1% = \'/\';' . "\n" . 'else if ( strlen( %tmp1% ) > 0 and' . "\n" . '  %tmp1%[0] != \'/\' )' . "\n" . '%tmp1% = \'/\' . %tmp1%;' . "\n";
                        $code .= '//include_once( \'lib/ezutils/classes/ezuri.php\' );' . "\n" . 'eZURI::transformURI( %tmp1%, true, %2% );' . "\n";
                        $useTmp = true;
                        ++$tmpCount;
                    } else {
                        $values[] = $parameters[0];
                        $values[] = isset($parameters[2]) ? $parameters[2] : array(eZTemplateNodeTool::createStringElement('relative'));
                        $code = 'if ( preg_match( "#^[a-zA-Z0-9]+:#", %1% ) or' . "\n" . 'substr( %1%, 0, 2 ) == \'//\' )' . "\n" . '  %1% = \'/\';' . "\n" . 'else if ( strlen( %1% ) > 0 and' . "\n" . '  %1%[0] != \'/\' )' . "\n" . '%1% = \'/\' . %1%;' . "\n";
                        $code .= '//include_once( \'lib/ezutils/classes/ezuri.php\' );' . "\n" . 'eZURI::transformURI( %1%, true, %2% );' . "\n";
                    }
                }
                ++$paramCount;
                break;
            case $this->SysName:
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[1])) {
                    $sysAttribute = eZTemplateNodeTool::elementStaticValue($parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($this->Sys->attribute($sysAttribute)));
                }
                return false;
                break;
            case $this->DesignName:
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                    $path = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                    $path = $this->eZDesign($tpl, $path, $operatorName);
                    $path = $this->applyQuotes($path, $parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($path));
                } else {
                    if ($shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                        $path = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                        $values[] = array(eZTemplateNodeTool::createStringElement($path));
                        $code = '%tmp1% = %1%;' . "\n" . '%tmp1% = eZURLOperator::eZDesign( $tpl, %tmp1%, "' . $operatorName . '" );' . "\n";
                        $useTmp = true;
                        ++$tmpCount;
                    } else {
                        $values[] = $parameters[0];
                        $code = '%1% = eZURLOperator::eZDesign( $tpl, %1%, "' . $operatorName . '" );' . "\n";
                    }
                }
                ++$paramCount;
                break;
            case $this->ImageName:
                $skipSlash = count($parameters) > 2 ? eZTemplateNodeTool::elementStaticValue($parameters[2]) == true : false;
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                    $path = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                    $path = eZURLOperator::eZImage($tpl, $path, $operatorName, $skipSlash);
                    $path = $this->applyQuotes($path, $parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($path));
                } else {
                    if ($shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                        $path = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                        $values[] = array(eZTemplateNodeTool::createStringElement($path));
                        $values[] = array(eZTemplateNodeTool::createBooleanElement($skipSlash));
                        $code = '%tmp1% = %1%;' . "\n" . '%tmp1% = eZURLOperator::eZImage( $tpl, %tmp1%, "' . $operatorName . '", %2% );' . "\n";
                        $useTmp = true;
                        ++$tmpCount;
                    } else {
                        $values[] = $parameters[0];
                        $values[] = array(eZTemplateNodeTool::createBooleanElement($skipSlash));
                        $code = '%1% = eZURLOperator::eZImage( $tpl, %1%, "' . $operatorName . '", %2% );' . "\n";
                    }
                }
                ++$paramCount;
                break;
            case $this->ExtName:
                if (!$shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                    $origUrl = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                    $url = eZURL::urlByMD5(md5($origUrl));
                    if ($url == false) {
                        eZURL::registerURL($origUrl);
                    } else {
                        $origUrl = $url;
                    }
                    $origUrl = $this->applyQuotes($origUrl, $parameters[1]);
                    return array(eZTemplateNodeTool::createStringElement($origUrl));
                } else {
                    if ($shareTemplates && eZTemplateNodeTool::isStaticElement($parameters[0])) {
                        $origUrl = eZTemplateNodeTool::elementStaticValue($parameters[0]);
                        $values[] = array(eZTemplateNodeTool::createStringElement($origUrl));
                        $code .= '//include_once( \'kernel/classes/datatypes/ezurl/ezurl.php\' );' . "\n" . '%tmp1% = %1%; ' . "\n" . '%tmp2% = eZURL::urlByMD5( md5( %tmp1% ) );' . "\n" . 'if ( %tmp2% == false )' . "\n" . '  eZURL::registerURL( %tmp1% );' . "\n" . 'else' . "\n" . '  %tmp1% = %tmp2%;' . "\n";
                        ++$tmpCount;
                        $useTmp = true;
                    } else {
                        $values[] = $parameters[0];
                        $code .= '//include_once( \'kernel/classes/datatypes/ezurl/ezurl.php\' );' . "\n" . '%tmp1% = eZURL::urlByMD5( md5( %1% ) );' . "\n" . 'if ( %tmp1% == false )' . "\n" . '  eZURL::registerURL( %1% );' . "\n" . 'else' . "\n" . '  %1% = %tmp1%;' . "\n";
                    }
                }
                ++$tmpCount;
                ++$paramCount;
                break;
        }
        $http = eZHTTPTool::instance();
        if (isset($http->UseFullUrl) and $http->UseFullUrl) {
            ++$tmpCount;
            $code .= '//include_once( \'lib/ezutils/classes/ezhttptool.php\' );' . "\n" . '%tmp' . $tmpCount . '% = eZHTTPTool::instance();' . "\n" . 'if ( isset( %tmp' . $tmpCount . '%->UseFullUrl ) and %tmp' . $tmpCount . '%->UseFullUrl ' . "\n" . '                                                 and strncasecmp( %1%, \'/\' , 1 ) === 0 ) // do not prepend the site path if it\'s not a http url%' . "\n" . '{' . "\n" . ' %1% = %tmp' . $tmpCount . '%->createRedirectUrl( %1%, array( \'pre_url\' => false ) );' . "\n" . '}' . "\n";
        }
        if (count($parameters) > $paramCount) {
            if (eZTemplateNodeTool::isStaticElement($parameters[$paramCount])) {
                $quote = '"';
                $val = eZTemplateNodeTool::elementStaticValue($parameters[$paramCount]);
                ++$paramCount;
                if ($val == 'single') {
                    $quote = "'";
                } else {
                    if ($val == 'no') {
                        $quote = false;
                    }
                }
                if ($quote !== false) {
                    $values[] = array(eZTemplateNodeTool::createStringElement($quote));
                    if ($useTmp) {
                        $code .= '%tmp1% = %' . count($values) . '% . %tmp1% . %' . count($values) . '%;' . "\n";
                    } else {
                        $code .= '%1% = %' . count($values) . '% . %1% . %' . count($values) . '%;' . "\n";
                    }
                }
            } else {
                $values[] = $parameters[$paramCount];
                if ($useTmp) {
                    $code .= 'switch (%' . count($values) . '%)' . "\n" . '{' . "\n" . '    case \'single\':' . "\n" . '         %tmp1% = \'\\\'\' . %tmp1% . \'\\\'\' ;' . "\n" . '         break;' . "\n" . '    case \'no\':' . "\n" . '         break;' . "\n" . '     default:' . "\n" . '         %tmp1 = \'"\' . %tmp1% . \'"\' ;' . "\n" . '}' . "\n";
                } else {
                    $code .= 'switch (%' . count($values) . '%)' . "\n" . '{' . "\n" . '    case \'single\':' . "\n" . '         %1% = \'\\\'\' . %1% . \'\\\'\' ;' . "\n" . '         break;' . "\n" . '    case \'no\':' . "\n" . '         break;' . "\n" . '     default:' . "\n" . '         %1% = \'"\' . %1% . \'"\' ;' . "\n" . '}' . "\n";
                }
            }
        } else {
            $quote = '"';
            $values[] = array(eZTemplateNodeTool::createStringElement($quote));
            if ($useTmp) {
                $code .= '%tmp1% = %' . count($values) . '% . %tmp1% . %' . count($values) . '%;' . "\n";
            } else {
                $code .= '%1% = %' . count($values) . '% . %1% . %' . count($values) . '%;' . "\n";
            }
        }
        if ($useTmp) {
            $code .= '%output% = %tmp1%;' . "\n";
        } else {
            $code .= '%output% = %1%;' . "\n";
        }
        $newElements[] = eZTemplateNodeTool::createCodePieceElement($code, $values, false, $tmpCount);
        return $newElements;
    }
 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 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;
 }
示例#9
0
 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 randTransformation( $operatorName, &$node, $tpl, &$resourceData,
                                 $element, $lastElement, $elementList, $elementTree, &$parameters )
    {
        $paramCount = count( $parameters );
        if ( $paramCount != 0 ||
             $paramCount != 2 )
        {
            return false;
        }
        $values = array();
        $newElements = array();

        if ( $paramCount == 2 )
        {
            $code = "%output% = mt_rand( %1%, %2% );\n";
            $values[] = $parameters[0];
            $values[] = $parameters[1];
        }
        else
        {
            $code = "%output% = mt_rand();\n";
        }

        $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
        return $newElements;
    }
    function getTimeTransformation( $operatorName, &$node, $tpl, &$resourceData,
                                    $element, $lastElement, $elementList, $elementTree, &$parameters )
    {
        $newElements = array();
        $values = array();
        $paramCount = count( $parameters );

        if ( $paramCount == 1 )
        {
            $values[] = $parameters[0];
            $code = "%tmp1% = %1%;\n";
        }
        else if ( $paramCount == 0 )
        {
            $code = "%tmp1% = time();\n";
        }
        else
        {
            return false;
        }
        $newElements[] = eZTemplateNodeTool::createCodePieceElement(
            $code .
            "%tmp2% = getdate( %tmp1% );\n".
            "%tmp3% = date( 'W', %tmp1% );\n".
            "if ( %tmp2%['wday'] == 0 )\n{\n\t++%tmp3%;\n}\n".
            "%output% = array( 'seconds' => %tmp2%['seconds'],
              'minutes' => %tmp2%['minutes'],
              'hours' => %tmp2%['hours'],
              'day' => %tmp2%['mday'],
              'month' => %tmp2%['mon'],
              'year' => %tmp2%['year'],
              'weeknumber' => %tmp3%,
              'weekday' => %tmp2%['wday'],
              'yearday' => %tmp2%['yday'],
              'epoch' => %tmp2%[0] );\n", $values, false, 3);
        return $newElements;
    }
    function chooseTransformation( $operatorName, &$node, $tpl, &$resourceData,
                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
    {
        $values = array();
        $function = $operatorName;

        if ( ( count( $parameters ) < 2) )
        {
            return false;
        }

        $tmpValues = false;
        $newElements = array();
        if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
        {
            $selected = eZTemplateNodeTool::elementConstantValue( $parameters[0] );

            if ( $selected < 0 or $selected > ( count( $parameters ) - 1 ) )
            {
                return false;
            }

            return $parameters[$selected + 1];
        }
        else
        {
            $values[] = $parameters[0];
            $array = $parameters;
            unset( $array[0] );

            $count = count( $parameters ) - 1;
            $operatorNameText = eZPHPCreator::variableText( $operatorName );

            if ( count( $parameters ) == ( 2 + 1 ) )
            {
                $code = "%output% = %1% ? %3% : %2%;\n";
                $values[] = $parameters[1];
                $values[] = $parameters[2];
            }
            else
            {
                $code = ( "if ( %1% < 0 and\n" .
                          "     %1% >= $count )\n" .
                          "{\n" .
                          "    \$tpl->error( $operatorNameText, \"Index \" . %1% . \" out of range\" );\n" .
                          "     %output% = false;\n" .
                          "}\n" );
                $code .= "else switch ( %1% )\n{\n";
                $valueNumber = 2;
                for ( $i = 0; $i < $count; ++$i )
                {
                    $parameterNumber = $i + 1;
                    $code .= "    case $i:";
                    if ( eZTemplateNodeTool::isConstantElement( $parameters[$parameterNumber] ) )
                    {
                        $value = eZTemplateNodeTool::elementConstantValue( $parameters[$parameterNumber] );
                        $valueText = eZPHPCreator::variableText( $value, 0, 0, false );
                        $code .= " %output% = $valueText; break;\n";
                    }
                    else
                    {
                        $code .= "\n    {\n";
                        $code .= "%code$valueNumber%\n";
                        $code .= "%output% = %$valueNumber%;\n";
                        $code .= "    } break;\n";
                        $values[] = $parameters[$parameterNumber];
                        ++$valueNumber;
                    }
                }
                $code .= "}\n";
            }
        }
        $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, eZTemplateNodeTool::extractVariableNodePlacement( $node ), false );
        return $newElements;
    }
    function 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 )
                {
                    $spacing = $nestCount - $i - 1;
                    $spacingCode = str_repeat( ' ', $spacing*4 );
                    $code .= $spacingCode . "}\n";
                }

                return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
            } break;
        }
    }
    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 ) );
    }
    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 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 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;
            }
        }

        $ini = eZINI::instance();
        $dynamic = $ini->variable( 'RegionalSettings', 'DynamicTemplateMode' ) === 'enabled';

        if ( $dynamic )
        {
            $numParameters = count ( $parameters );
            $values = array();
            $values[] = ( $numParameters > 1 ) ? $parameters[1] : null;;
            $values[] = $parameters[0];
            $values[] = ( $numParameters > 2 ) ? $parameters[2] : null;
            $values[] = ( $numParameters > 3 ) ? $parameters[3] : null;
            $code = '%output% = ezpI18n::tr( %1%, %2%, %3%, %4% );' . "\n";
            return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
        }

        $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();

        if ( $ini->variable( 'RegionalSettings', 'TextTranslation' ) != 'disabled' )
        {
            $newValue = ezpI18n::tr( $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 ) );
    }