当前位置: 首页>>代码示例>>PHP>>正文


PHP eZTemplateNodeTool::createCodePieceElement方法代码示例

本文整理汇总了PHP中eZTemplateNodeTool::createCodePieceElement方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTemplateNodeTool::createCodePieceElement方法的具体用法?PHP eZTemplateNodeTool::createCodePieceElement怎么用?PHP eZTemplateNodeTool::createCodePieceElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZTemplateNodeTool的用法示例。


在下文中一共展示了eZTemplateNodeTool::createCodePieceElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: nl2brTransformation

 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;
 }
开发者ID:nfrp,项目名称:ezpublish,代码行数:13,代码来源:eztemplatenl2broperator.php

示例2: phpOperatorTransformation

 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;
 }
开发者ID:legende91,项目名称:ez,代码行数:14,代码来源:eztemplatephpoperator.php

示例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));
 }
开发者ID:patrickallaert,项目名称:ezpublish-legacy-php7,代码行数:15,代码来源:ezkerneloperator.php

示例4: hashTransformation

 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;
 }
开发者ID:netbliss,项目名称:ezpublish,代码行数:24,代码来源:eztemplatedigestoperator.php

示例5: 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;
 }
开发者ID:nfrp,项目名称:ezpublish,代码行数:25,代码来源:eztemplatetextoperator.php

示例6: urlTransformation


//.........这里部分代码省略.........
            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;
    }
开发者ID:stevoland,项目名称:ez_patch,代码行数:101,代码来源:ezurloperator.php

示例7: 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) {
//.........这里部分代码省略.........
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:101,代码来源:eztemplateunitoperator.php

示例8: 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;
 }
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:58,代码来源:eztemplatestringoperator.php

示例9: 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));
 }
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:37,代码来源:ezi18noperator.php

示例10: randTransformation

    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;
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:26,代码来源:eztemplatearithmeticoperator.php

示例11: getTimeTransformation

    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;
    }
开发者ID:robinmuilwijk,项目名称:ezpublish,代码行数:37,代码来源:eztemplatelocaleoperator.php

示例12: chooseTransformation

    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;
    }
开发者ID:nottavi,项目名称:ezpublish,代码行数:75,代码来源:eztemplatelogicoperator.php

示例13: 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 )
//.........这里部分代码省略.........
开发者ID:nottavi,项目名称:ezpublish,代码行数:101,代码来源:eztemplatecontroloperator.php

示例14: fetchTransform


//.........这里部分代码省略.........

                $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 ) );
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:101,代码来源:eztemplateexecuteoperator.php

示例15: isTransform

    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 ) );
    }
开发者ID:nottavi,项目名称:ezpublish,代码行数:78,代码来源:eztemplatetypeoperator.php


注:本文中的eZTemplateNodeTool::createCodePieceElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。