function functionTemplateStatistics($functionName, &$node, $tpl, $resourceData, $namespace, &$stats)
 {
     $newNamespace = $namespace;
     $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node);
     if ($functionName == $this->SetName or $functionName == $this->LetName or $functionName == $this->DefaultName) {
         if (isset($parameters['-name'])) {
             $nameData = $parameters['-name'];
             $nameDataInspection = eZTemplateCompiler::inspectVariableData($tpl, $nameData, false, $resourceData);
             if ($nameDataInspection['is-constant'] and !$nameDataInspection['has-operators'] and !$nameDataInspection['has-attributes']) {
                 $parameterNamespace = $nameDataInspection['new-data'][0][1];
                 $newNamespace = $tpl->mergeNamespace($namespace, $parameterNamespace);
             }
         }
     }
     if ($functionName == $this->SetName) {
         foreach (array_keys($parameters) as $name) {
             if ($name == '-name') {
                 continue;
             }
             $parameter =& $parameters[$name];
             eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $name, array('is_modified' => true));
             eZTemplateCompiler::calculateVariableNodeStatistics($tpl, $parameter, false, $resourceData, $namespace, $stats);
         }
     } else {
         if ($functionName == $this->LetName) {
             foreach (array_keys($parameters) as $name) {
                 if ($name == '-name') {
                     continue;
                 }
                 $parameter =& $parameters[$name];
                 eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $name, array('is_created' => true, 'is_removed' => true));
                 eZTemplateCompiler::calculateVariableNodeStatistics($tpl, $parameter, false, $resourceData, $namespace, $stats);
             }
         } else {
             if ($functionName == $this->DefaultName) {
                 foreach (array_keys($parameters) as $name) {
                     if ($name == '-name') {
                         continue;
                     }
                     $parameter =& $parameters[$name];
                     eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $name, array());
                     eZTemplateCompiler::calculateVariableNodeStatistics($tpl, $parameter, false, $resourceData, $namespace, $stats);
                 }
             }
         }
     }
     if ($functionName == $this->LetName or $functionName == $this->DefaultName) {
         $functionChildren = eZTemplateNodeTool::extractFunctionNodeChildren($node);
         if (is_array($functionChildren)) {
             eZTemplateCompiler::calculateVariableStatisticsChildren($tpl, $functionChildren, $resourceData, $newNamespace, $stats);
         }
     }
 }
Ejemplo n.º 2
0
 static function calculateVariableStatisticsChildren($tpl, &$nodeChildren, &$resourceData, $namespace, &$stats)
 {
     foreach ($nodeChildren as $node) {
         if (!isset($node[0])) {
             continue;
         }
         $nodeType = $node[0];
         if ($nodeType == eZTemplate::NODE_ROOT) {
             $children = $node[1];
             if ($children) {
                 eZTemplateCompiler::calculateVariableStatisticsChildren($tpl, $children, $resourceData, $namespace, $stats);
             }
         } else {
             if ($nodeType == eZTemplate::NODE_TEXT) {
                 $text = $node[2];
                 $placement = $node[3];
             } else {
                 if ($nodeType == eZTemplate::NODE_VARIABLE) {
                     $variableData = $node[2];
                     $variablePlacement = $node[3];
                     $variableParameters = false;
                     eZTemplateCompiler::calculateVariableNodeStatistics($tpl, $variableData, $variablePlacement, $resourceData, $namespace, $stats);
                 } else {
                     if ($nodeType == eZTemplate::NODE_FUNCTION) {
                         $functionChildren = $node[1];
                         $functionName = $node[2];
                         $functionParameters = $node[3];
                         $functionPlacement = $node[4];
                         if (!isset($tpl->Functions[$functionName])) {
                             continue;
                         }
                         if (is_array($tpl->Functions[$functionName])) {
                             $tpl->loadAndRegisterOperators($tpl->Functions[$functionName]);
                         }
                         $functionObject =& $tpl->Functions[$functionName];
                         if (is_object($functionObject)) {
                             $hasTransformationSupport = false;
                             $transformChildren = true;
                             if (method_exists($functionObject, 'functionTemplateStatistics')) {
                                 $functionObject->functionTemplateStatistics($functionName, $node, $tpl, $resourceData, $namespace, $stats);
                             }
                         } else {
                             if ($resourceData['test-compile']) {
                                 $tpl->warning('', "Operator '{$operatorName}' is not registered.", $functionPlacement);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 function functionTemplateStatistics($functionName, &$node, $tpl, $resourceData, $namespace, &$stats)
 {
     if ($functionName != $this->Name) {
         return false;
     }
     $newNamespace = $namespace;
     $parameters = eZTemplateNodeTool::extractFunctionNodeParameters($node);
     if (isset($parameters['name'])) {
         $nameData = $parameters['name'];
         $nameDataInspection = eZTemplateCompiler::inspectVariableData($tpl, $nameData, false, $resourceData);
         if ($nameDataInspection['is-constant'] and !$nameDataInspection['has-operators'] and !$nameDataInspection['has-attributes']) {
             $parameterNamespace = $nameDataInspection['new-data'][0][1];
             $newNamespace = $tpl->mergeNamespace($namespace, $parameterNamespace);
         }
     }
     $parameterNames = array('loop', 'show', 'var', 'last-value', 'reverse', 'sequence', 'max', 'offset');
     foreach ($parameterNames as $parameterName) {
         if (isset($parameters[$parameterName])) {
             eZTemplateCompiler::calculateVariableNodeStatistics($tpl, $parameters[$parameterName], false, $resourceData, $namespace, $stats);
         }
     }
     if (!isset($parameters['var'])) {
         if (isset($parameters['loop'])) {
             $newVariables = array('key', 'item', 'index', 'number');
             foreach ($newVariables as $newVariableName) {
                 eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $newVariableName, array('is_created' => true, 'is_removed' => true));
             }
         }
         if (isset($parameters['sequence'])) {
             $newVariables = array('sequence');
             foreach ($newVariables as $newVariableName) {
                 eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $newVariableName, array('is_created' => true, 'is_removed' => true));
             }
         }
     } else {
         if (isset($parameters['loop'])) {
             $varDataInspection = eZTemplateCompiler::inspectVariableData($tpl, $parameters['var'], false, $resourceData);
             if ($varDataInspection['is-constant'] and !$varDataInspection['has-operators'] and !$varDataInspection['has-attributes']) {
                 $varName = $varDataInspection['new-data'][0][1];
                 eZTemplateCompiler::setVariableStatistics($stats, $newNamespace, $varName, array('is_created' => true, 'is_removed' => true));
             }
         }
     }
     $functionChildren = eZTemplateNodeTool::extractFunctionNodeChildren($node);
     if (is_array($functionChildren)) {
         eZTemplateCompiler::calculateVariableStatisticsChildren($tpl, $functionChildren, $resourceData, $newNamespace, $stats);
     }
 }