eZ Publish  [4.0]
eztemplatenodetool.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTemplateNodeTool class
00004 //
00005 // Created on: <13-May-2003 14:12:01 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file eztemplatenodetool.php
00032 */
00033 
00034 /*!
00035   \class eZTemplateNodeTool eztemplatenodetool.php
00036   \ingroup eZTemplate
00037   \brief Various tool functions for working with template nodes
00038 
00039 */
00040 
00041 class eZTemplateNodeTool
00042 {
00043     /*!
00044      \static
00045      Removes the children from the function node \a $node.
00046     */
00047     static function removeFunctionNodeChildren( &$node )
00048     {
00049         $node[1] = false;
00050     }
00051 
00052     /*!
00053      \static
00054      Removes the parameters from the function node \a $node.
00055     */
00056     static function removeFunctionNodeParameters( &$node )
00057     {
00058         $node[3] = false;
00059     }
00060 
00061     /*!
00062      \static
00063      Removes the placement info from the function node \a $node.
00064     */
00065     static function removeFunctionNodePlacement( &$node )
00066     {
00067         $node[4] = false;
00068     }
00069 
00070     /*!
00071      \static
00072      Creates an element which represents nothing (void).
00073     */
00074     static function createVoidElement()
00075     {
00076         return array( eZTemplate::TYPE_VOID );
00077     }
00078 
00079     /*!
00080      \static
00081      Creates an element which represents the static value and returns it,
00082      the type of the variable determines the type of the element.
00083     */
00084     static function createConstantElement( $constant, $variablePlacement = false )
00085     {
00086         if ( is_array( $constant ) )
00087             return eZTemplateNodeTool::createArrayElement( $constant, $variablePlacement );
00088         else if ( is_string( $constant ) )
00089             return eZTemplateNodeTool::createStringElement( $constant, $variablePlacement );
00090         else if ( is_bool( $constant ) )
00091             return eZTemplateNodeTool::createBooleanElement( $constant, $variablePlacement );
00092         else if ( is_numeric( $constant ) )
00093             return eZTemplateNodeTool::createNumericElement( $constant, $variablePlacement );
00094         else
00095             return eZTemplateNodeTool::createVoidElement();
00096     }
00097 
00098     /*!
00099      \static
00100      \deprecated Use createConstantElement instead.
00101     */
00102     static function createStaticElement( $static, $variablePlacement = false )
00103     {
00104         if ( is_array( $static ) )
00105             return eZTemplateNodeTool::createArrayElement( $static, $variablePlacement );
00106         else if ( is_string( $static ) )
00107             return eZTemplateNodeTool::createStringElement( $static, $variablePlacement );
00108         else if ( is_bool( $static ) )
00109             return eZTemplateNodeTool::createBooleanElement( $static, $variablePlacement );
00110         else if ( is_numeric( $static ) )
00111             return eZTemplateNodeTool::createNumericElement( $static, $variablePlacement );
00112         else
00113             return eZTemplateNodeTool::createVoidElement();
00114     }
00115 
00116     /*!
00117      \static
00118      Creates an element which represents a string and returns it.
00119     */
00120     static function createStringElement( $string, $variablePlacement = false )
00121     {
00122         return array( eZTemplate::TYPE_STRING,
00123                       $string, $variablePlacement );
00124     }
00125 
00126     /*!
00127      \static
00128      Creates an element which represents a number (float or integer) and returns it.
00129     */
00130     static function createNumericElement( $number, $variablePlacement = false )
00131     {
00132         return array( eZTemplate::TYPE_NUMERIC,
00133                       $number, $variablePlacement );
00134     }
00135 
00136     /*!
00137      \static
00138      Creates an element which represents an identifier and returns it.
00139     */
00140     static function createIdentifierElement( $identifier, $variablePlacement = false )
00141     {
00142         return array( eZTemplate::TYPE_IDENTIFIER,
00143                       $identifier, $variablePlacement );
00144     }
00145 
00146     /*!
00147      \static
00148      Creates an element which represents an array and returns it.
00149 
00150      \param array key list, static.
00151      \param array values as php code.
00152      \param values.
00153     */
00154     static function createDynamicArrayElement( &$arrayKeys, &$arrayValues, $variablePlacement = false )
00155     {
00156         return array( eZTemplate::TYPE_DYNAMIC_ARRAY,
00157                       $arrayKeys, $arrayValues, $variablePlacement );
00158     }
00159 
00160     /*!
00161      \static
00162      Creates an element which represents an array and returns it.
00163     */
00164     static function createArrayElement( $array, $variablePlacement = false )
00165     {
00166         return array( eZTemplate::TYPE_ARRAY,
00167                       $array, $variablePlacement );
00168     }
00169 
00170     /*!
00171      \static
00172      Creates an element which represents a boolean and returns it.
00173     */
00174     static function createBooleanElement( $boolean, $variablePlacement = false )
00175     {
00176         if ( !is_bool( $boolean ) )
00177             $boolean = (bool)$boolean;
00178         return array( eZTemplate::TYPE_BOOLEAN,
00179                       $boolean, $variablePlacement );
00180     }
00181 
00182     /*!
00183      \static
00184      Creates an element which represents an array and returns it.
00185     */
00186     static function createPHPVariableElement( $variableName, $variablePlacement = false )
00187     {
00188         return array( eZTemplate::TYPE_PHP_VARIABLE,
00189                       $variableName, $variablePlacement );
00190     }
00191 
00192     /*!
00193      \static
00194      Creates an element which represents an variable lookup and returns it.
00195      \param $namespaceScope Type of variable lookup, can be one of:
00196                             - \b eZTemplate::NAMESPACE_SCOPE_GLOBAL, Look for variables at the very top of the namespace tree
00197                             - \b eZTemplate::NAMESPACE_SCOPE_LOCAL, Look for variables at the top of the current file being processed
00198                             - \b eZTemplate::NAMESPACE_SCOPE_RELATIVE, Look for variables from the current namespace
00199     */
00200     static function createVariableElement( $variableName, $namespaceName, $namespaceScope = eZTemplate::NAMESPACE_SCOPE_LOCAL, $variablePlacement = false )
00201     {
00202         return array( eZTemplate::TYPE_VARIABLE,
00203                       array( $namespaceName, $namespaceScope, $variableName ), $variablePlacement );
00204     }
00205 
00206     /*!
00207      \static
00208      Creates an element which does lookup on an attribute and returns it.
00209      \param $attributeValues Must be an array with elements that result in scalar value or string.
00210     */
00211     static function createAttributeLookupElement( $attributeValues = array(), $variablePlacement = false )
00212     {
00213         if ( is_numeric( $attributeValues ) )
00214             $attributeValues = array( eZTemplateNodeTool::createNumericElement( $attributeValues, $variablePlacement ) );
00215         else if ( !is_array( $attributeValues ) )
00216             $attributeValues = array( eZTemplateNodeTool::createStringElement( $attributeValues, $variablePlacement ) );
00217         return array( eZTemplate::TYPE_ATTRIBUTE,
00218                       $attributeValues, $variablePlacement );
00219     }
00220 
00221     /*!
00222      \static
00223      Creates an element which represents an operator and returns it.
00224      \param $name The name of the operator to run.
00225      \param $parameters An array with parameters, each parameter is an array of variable elements.
00226     */
00227     static function createOperatorElement( $name, $parameters = array(), $variablePlacement = false )
00228     {
00229         return array( eZTemplate::TYPE_ATTRIBUTE,
00230                       array_merge( array( $name ), $parameters ), $variablePlacement );
00231     }
00232 
00233     /*!
00234      \return The value of the constant element or \c null if the element is not constant.
00235      \note Make sure the element is checked with isConstantElement() before running this.
00236      \note Can also be used on PHP variable elements, it will then fetch the variable name.
00237     */
00238     static function elementConstantValue( $elements )
00239     {
00240         if ( eZTemplateNodeTool::isConstantElement( $elements ) or
00241              eZTemplateNodeTool::isPHPVariableElement( $elements ) )
00242             return $elements[0][1];
00243         return null;
00244     }
00245 
00246     /*!
00247      \static
00248      \deprecated Use elementConstantValue instead.
00249     */
00250     static function elementStaticValue( $elements )
00251     {
00252         if ( eZTemplateNodeTool::isConstantElement( $elements ) or
00253              eZTemplateNodeTool::isPHPVariableElement( $elements ) )
00254             return $elements[0][1];
00255         return null;
00256     }
00257 
00258     /*!
00259      \return the array keys of the Dynamic array
00260     */
00261     static function elementDynamicArrayKeys( $elements )
00262     {
00263         if ( !eZTemplateNodeTool::isDynamicArrayElement( $elements ) )
00264             return null;
00265         return $elements[0][1];
00266     }
00267 
00268     /*!
00269      \return assosiative array of parameters in Dynamic Array
00270     */
00271     static function elementDynamicArray( $elements )
00272     {
00273         if ( !eZTemplateNodeTool::isDynamicArrayElement( $elements ) )
00274             return null;
00275         return $elements[0][2];
00276     }
00277 
00278 
00279     /*!
00280      \return \c true if the element list \a $elements is considered to have a constant value.
00281              It is considered constant if the following is true:
00282              - The start value is either numeric, text, identifier, array or boolean
00283              - It has no operators
00284              - It has no attribute lookup
00285     */
00286     static function isConstantElement( $elements )
00287     {
00288         $constantElements = array( eZTemplate::TYPE_VOID,
00289                                    eZTemplate::TYPE_STRING, eZTemplate::TYPE_IDENTIFIER,
00290                                    eZTemplate::TYPE_NUMERIC, eZTemplate::TYPE_BOOLEAN, eZTemplate::TYPE_ARRAY );
00291 
00292         if ( count( $elements ) == 0 )
00293             return false;
00294         if ( count( $elements ) > 1 )
00295             return false;
00296 
00297         if ( in_array( $elements[0][0], $constantElements ) )
00298             return true;
00299         return false;
00300     }
00301 
00302     /*!
00303      \deprecated Use isConstantElement instead.
00304     */
00305     static function isStaticElement( $elements )
00306     {
00307         $staticElements = array( eZTemplate::TYPE_VOID,
00308                                  eZTemplate::TYPE_STRING, eZTemplate::TYPE_IDENTIFIER,
00309                                  eZTemplate::TYPE_NUMERIC, eZTemplate::TYPE_BOOLEAN, eZTemplate::TYPE_ARRAY );
00310 
00311         if ( count( $elements ) == 0 )
00312             return false;
00313         if ( count( $elements ) > 1 )
00314             return false;
00315 
00316         if ( in_array( $elements[0][0], $staticElements ) )
00317             return true;
00318         return false;
00319     }
00320 
00321     /*!
00322      \return \c true if the element list \a $elements is considered to be an internal code piece.
00323     */
00324     static function isInternalCodePiece( $elements )
00325     {
00326         if ( isset( $elements[0][0]) && ( $elements[0][0] == eZTemplate::TYPE_INTERNAL_CODE_PIECE ) )
00327             return true;
00328         return false;
00329     }
00330 
00331     /*!
00332      \return \c true if the element list \a $elements is considered to be a variable element.
00333     */
00334     static function isVariableElement( $elements )
00335     {
00336         if ( isset( $elements[0][0] ) && ( $elements[0][0] == eZTemplate::TYPE_VARIABLE ) )
00337             return true;
00338         return false;
00339     }
00340 
00341     /*!
00342      \return \c true if the element list \a $elements is considered to have a PHP variable element.
00343              The following must be true.
00344              - The start value is PHP variable
00345              - It has no operators
00346              - It has no attribute lookup
00347     */
00348     static function isPHPVariableElement( $elements )
00349     {
00350         if ( count( $elements ) == 0 )
00351             return false;
00352         if ( count( $elements ) > 1 )
00353             return false;
00354 
00355         if ( $elements[0][0] == eZTemplate::TYPE_PHP_VARIABLE )
00356             return true;
00357         return false;
00358     }
00359 
00360     /*!
00361      \return \c true if the element list \a $elements is considered to be numerical.
00362              It is considered constant if the following is true:
00363              - The start value is numeric (integer or float)
00364              - It has no operators
00365              - It has no attribute lookup
00366      \sa isConstantElement
00367      \note If you don't care about pure integers or floats use isConstantElement instead and just use the
00368            element value as numerical value.
00369     */
00370     static function isNumericElement( $elements )
00371     {
00372         $constantElements = array( eZTemplate::TYPE_NUMERIC );
00373 
00374         if ( count( $elements ) == 0 )
00375             return false;
00376 
00377         if ( in_array( $elements[0][0], $constantElements ) )
00378             return true;
00379         return false;
00380     }
00381 
00382     /*!
00383      \return \c true if the element list \a $elements is considered to be a string.
00384              It is considered constant if the following is true:
00385              - The start value is string or identifier
00386              - It has no operators
00387              - It has no attribute lookup
00388      \sa isConstantElement
00389      \note If you don't care about pure strings use isConstantElement instead and just use the
00390            element value as string value.
00391     */
00392     static function isStringElement( $elements )
00393     {
00394         $constantElements = array( eZTemplate::TYPE_STRING, eZTemplate::TYPE_IDENTIFIER );
00395 
00396         if ( count( $elements ) == 0 )
00397             return false;
00398 
00399         if ( in_array( $elements[0][0], $constantElements ) )
00400             return true;
00401         return false;
00402     }
00403 
00404     /*!
00405      \return \c true if the element list \a $elements is considered to be an identifier.
00406              It is considered constant if the following is true:
00407              - The start value is identifier
00408              - It has no operators
00409              - It has no attribute lookup
00410      \sa isConstantElement
00411      \note If you don't care about pure identifiers use isStringElement or isConstantElement instead.
00412     */
00413     static function isIdentifierElement( $elements )
00414     {
00415         $constantElements = array( eZTemplate::TYPE_IDENTIFIER );
00416 
00417         if ( count( $elements ) == 0 )
00418             return false;
00419 
00420         if ( in_array( $elements[0][0], $constantElements ) )
00421             return true;
00422         return false;
00423     }
00424 
00425     /*!
00426      \return \c true if the element list \a $elements is considered to be a boolean.
00427              It is considered constant if the following is true:
00428              - The start value is boolean
00429              - It has no operators
00430              - It has no attribute lookup
00431      \sa isConstantElement
00432      \note If you don't care about pure booleans use isConstantElement instead and just use the
00433            element value as boolean value.
00434     */
00435     static function isBooleanElement( $elements )
00436     {
00437         $constantElements = array( eZTemplate::TYPE_BOOLEAN );
00438 
00439         if ( count( $elements ) == 0 )
00440             return false;
00441 
00442         if ( in_array( $elements[0][0], $constantElements ) )
00443             return true;
00444         return false;
00445     }
00446 
00447     /*!
00448       \static
00449       Check if element id Dynamic Array
00450     */
00451     static function isDynamicArrayElement( $elements )
00452     {
00453         if ( count( $elements ) == 0 )
00454             return false;
00455 
00456         if ( $elements[0][0] == eZTemplate::TYPE_DYNAMIC_ARRAY )
00457             return true;
00458         return false;
00459     }
00460 
00461     /*!
00462      \return \c true if the element list \a $elements is considered to be an array.
00463              It is considered constant if the following is true:
00464              - The start value is array
00465              - It has no operators
00466              - It has no attribute lookup
00467      \sa isConstantElement
00468     */
00469     static function isArrayElement( $elements )
00470     {
00471         $constantElements = array( eZTemplate::TYPE_ARRAY );
00472 
00473         if ( count( $elements ) == 0 )
00474             return false;
00475 
00476         if ( in_array( $elements[0][0], $constantElements ) )
00477             return true;
00478         return false;
00479     }
00480 
00481     /*!
00482      \static
00483      Creates a new function node hook with name \a $hookName and optional parameters \a $hookParameters
00484      and function data \a $hookFunction and returns it.
00485     */
00486     static function createFunctionNodeHook( &$node, $hookName, $hookParameters = array(), $hookFunction = false )
00487     {
00488         $node[5] = array( 'name' => $hookName,
00489                           'parameters' => $hookParameters,
00490                           'function' => $hookFunction );
00491     }
00492 
00493     /*!
00494      \static
00495      Creates a new variable node and returns it.
00496     */
00497     static function createVariableNode( $originalNode = false, $variableData = false, $variablePlacement = false,
00498                                  $parameters = array(), $variableAssignmentName = false, $onlyExisting = false,
00499                                  $overWrite = true, $assignFromVariable = false, $rememberSet = false )
00500     {
00501         $node = array();
00502         if ( $originalNode )
00503             $node = $originalNode;
00504         else
00505         {
00506             $node[0] = eZTemplate::NODE_VARIABLE;
00507             $node[1] = $variableAssignmentName;
00508             if ( is_array( $variableData ) )
00509                 $node[2] = $variableData;
00510             else if ( $assignFromVariable )
00511                 $node[2] = array( array( eZTemplate::TYPE_PHP_VARIABLE,
00512                                          $variableData,
00513                                          false ) );
00514             else if ( is_bool( $variableData ) )
00515                 $node[2] = array( array( eZTemplate::TYPE_BOOLEAN,
00516                                          $variableData,
00517                                          false ) );
00518             else if ( is_string( $variableData ) )
00519                 $node[2] = array( array( eZTemplate::TYPE_STRING,
00520                                          $variableData,
00521                                          false ) );
00522             else if ( is_numeric( $variableData ) )
00523                 $node[2] = array( array( eZTemplate::TYPE_NUMERIC,
00524                                          $variableData,
00525                                          false ) );
00526             else
00527                 $node[2] = array( array( eZTemplate::TYPE_STRING,
00528                                          $variableData,
00529                                          false ) );
00530             $node[3] = $variablePlacement;
00531         }
00532         $node[4] = $parameters;
00533         $node[5] = $onlyExisting;
00534         $node[6] = $overWrite;
00535         $node[7] = $rememberSet;
00536         return $node;
00537     }
00538 
00539     static function createCodePieceElement( $codePiece, $values = false, $placement = false, $tmpValues = false, $knownTypes = true )
00540     {
00541         $element = array( eZTemplate::TYPE_INTERNAL_CODE_PIECE,
00542                           $codePiece,
00543                           $placement,
00544                           $values, $tmpValues, $knownTypes );
00545         return $element;
00546     }
00547 
00548     static function createTextNode( $text )
00549     {
00550         $node = array( eZTemplate::NODE_TEXT, false, $text, false );
00551         return $node;
00552     }
00553 
00554     static function createWarningNode( $text, $label, $placement = false, $parameters = array() )
00555     {
00556         $node = array( eZTemplate::NODE_INTERNAL_WARNING,
00557                        $text, $label,
00558                        $parameters, $placement );
00559         return $node;
00560     }
00561 
00562     static function createErrorNode( $text, $label, $placement = false, $parameters = array() )
00563     {
00564         $node = array( eZTemplate::NODE_INTERNAL_ERROR,
00565                        $text, $label,
00566                        $parameters, $placement );
00567         return $node;
00568     }
00569 
00570     static function createCodePieceNode( $codePiece, $parameters = array() )
00571     {
00572         $node = array( eZTemplate::NODE_INTERNAL_CODE_PIECE,
00573                        $codePiece,
00574                        $parameters );
00575         return $node;
00576     }
00577 
00578     static function createVariableUnsetNode( $variableName, $parameters = array() )
00579     {
00580         $node = array( eZTemplate::NODE_INTERNAL_VARIABLE_UNSET,
00581                        $variableName,
00582                        $parameters );
00583         return $node;
00584     }
00585 
00586     /*!
00587      Creates a new template node that will assign the content of the current output variable
00588      to the variable named \a $variableName.
00589 
00590      The assignment type is by default text concat (.) and can be changed using \a $assignmentType.
00591      \param $parameters An array with optional parameters, can contain the followin:
00592             - spacing - The number of spaces to added for each line this expression creates.
00593     */
00594     static function createWriteToOutputVariableNode( $variableName, $parameters = array(), $assignmentType = eZPHPCreator::VARIABLE_APPEND_TEXT )
00595     {
00596         $node = array( eZTemplate::NODE_INTERNAL_OUTPUT_ASSIGN,
00597                        $variableName,
00598                        $parameters,
00599                        $assignmentType );
00600         return $node;
00601     }
00602 
00603     /*!
00604      Creates a new template node that will assign the content of the current output variable
00605      to the variable named \a $variableName.
00606 
00607      The assignment type is by default variable assignment (=) and can be changed using \a $assignmentType.
00608      \param $parameters An array with optional parameters, can contain the followin:
00609             - spacing - The number of spaces to added for each line this expression creates.
00610     */
00611     static function createAssignFromOutputVariableNode( $variableName, $parameters = array(), $assignmentType = eZPHPCreator::VARIABLE_ASSIGNMENT )
00612     {
00613         $node = array( eZTemplate::NODE_INTERNAL_OUTPUT_READ,
00614                        $variableName,
00615                        $parameters,
00616                        $assignmentType );
00617         return $node;
00618     }
00619 
00620     static function createOutputVariableIncreaseNode( $parameters = array() )
00621     {
00622         $node = array( eZTemplate::NODE_INTERNAL_OUTPUT_INCREASE,
00623                        $parameters );
00624         return $node;
00625     }
00626 
00627     static function createOutputVariableDecreaseNode( $parameters = array() )
00628     {
00629         $node = array( eZTemplate::NODE_INTERNAL_OUTPUT_DECREASE,
00630                        $parameters );
00631         return $node;
00632     }
00633 
00634     static function createSpacingIncreaseNode( $spacing = 4, $parameters = array() )
00635     {
00636         $node = array( eZTemplate::NODE_INTERNAL_OUTPUT_SPACING_INCREASE,
00637                        $spacing, $parameters );
00638         return $node;
00639     }
00640 
00641     static function createSpacingDecreaseNode( $spacing = 4, $parameters = array() )
00642     {
00643         $node = array( eZTemplate::NODE_INTERNAL_SPACING_DECREASE,
00644                        $spacing, $parameters );
00645         return $node;
00646     }
00647 
00648     static function createNamespaceChangeNode( $variableData, $parameters = array() )
00649     {
00650         if ( is_string( $variableData ) )
00651             $variableData = array( eZTemplateNodeTool::createStringElement( $variableData ) );
00652         else if ( is_numeric( $variableData ) )
00653             $variableData = array( eZTemplateNodeTool::createNumericElement( $variableData ) );
00654         $node = array( eZTemplate::NODE_INTERNAL_NAMESPACE_CHANGE,
00655                        $variableData,
00656                        $parameters );
00657         return $node;
00658     }
00659 
00660     static function createNamespaceRestoreNode( $parameters = array() )
00661     {
00662         $node = array( eZTemplate::NODE_INTERNAL_NAMESPACE_RESTORE,
00663                        $parameters );
00664         return $node;
00665     }
00666 
00667     static function createResourceAcquisitionNode( $resourceName, $templateName, $fileName,
00668                                             $method, $extraParameters, $placement = false,
00669                                             $parameters = array(), $newRootNamespace = false, $resourceVariableName = false )
00670     {
00671         $node = array( eZTemplate::NODE_INTERNAL_RESOURCE_ACQUISITION,
00672                        $resourceName, $templateName, $fileName,
00673                        $method, $extraParameters, $placement );
00674         if ( count( $parameters ) > 0 )
00675             $node[] = $parameters;
00676         else
00677             $node[] = false;
00678         $node[] = $newRootNamespace;
00679         $node[] = $resourceVariableName;
00680         return $node;
00681     }
00682 
00683     static function extractNodes( $nodeList, $parameters = array() )
00684     {
00685         $match = false;
00686         if ( isset( $parameters['match'] ) )
00687             $match = $parameters['match'];
00688         $newNodes = array();
00689         $skipNode = false;
00690         if ( $match['type'] == 'after' )
00691             $skipNode = true;
00692 
00693         if ( !is_array( $nodeList ) )
00694         {
00695             return $newNodes;
00696         }
00697         foreach ( $nodeList as $node )
00698         {
00699             if ( $match )
00700             {
00701                 $isMatch = true;
00702                 foreach ( $match['matches'] as $matchItem )
00703                 {
00704                     $operand1 = $matchItem['match-with'];
00705                     $matchKeys = $matchItem['match-keys'];
00706                     $operand2 = $node;
00707                     foreach ( $matchKeys as $matchKey )
00708                     {
00709                         $operand2 = $operand2[$matchKey];
00710                     }
00711                     if ( isset( $matchItem['match-function'] ) )
00712                     {
00713                         $function = $matchItem['match-function'];
00714                         $functionResult = $function( $operand1, $operand2 );
00715                         $wasMatch = $functionResult == 0;
00716                     }
00717                     else
00718                     {
00719                         if ( is_array( $operand1 ) )
00720                             $wasMatch = in_array( $operand2, $operand1 );
00721                         else
00722                             $wasMatch = ( $operand1 == $operand2 );
00723                     }
00724                     if ( !$wasMatch )
00725                     {
00726                         $isMatch = false;
00727                         break;
00728                     }
00729                 }
00730                 if ( $match['type'] == 'equal' )
00731                 {
00732                     if ( !$isMatch )
00733                         continue;
00734                 }
00735                 else if ( $match['type'] == 'before' )
00736                 {
00737                     if ( $isMatch )
00738                         break;
00739                 }
00740                 else if ( $match['type'] = 'after' )
00741                 {
00742                     if ( $isMatch )
00743                     {
00744                         $skipNode = false;
00745                         $match = false;
00746                         continue;
00747                     }
00748                 }
00749             }
00750             if ( $skipNode )
00751                 continue;
00752             if ( $match and isset( $match['filter'] ) )
00753             {
00754                 $isMatch = true;
00755                 foreach ( $match['filter'] as $matchFilterItem )
00756                 {
00757                     foreach ( $matchFilterItem as $matchItem )
00758                     {
00759                         $operand1 = $matchItem['match-with'];
00760                         $matchKeys = $matchItem['match-keys'];
00761                         $operand2 = $node;
00762                         foreach ( $matchKeys as $matchKey )
00763                         {
00764                             $operand2 = $operand2[$matchKey];
00765                         }
00766                         if ( isset( $matchItem['match-function'] ) )
00767                         {
00768                             $function = $matchItem['match-function'];
00769                             $functionResult = $function( $operand1, $operand2 );
00770                             $wasMatch = $functionResult == 0;
00771                         }
00772                         else
00773                         {
00774                             if ( is_array( $operand1 ) )
00775                                 $wasMatch = in_array( $operand2, $operand1 );
00776                             else
00777                                 $wasMatch = ( $operand1 == $operand2 );
00778                         }
00779                         if ( !$wasMatch )
00780                         {
00781                             $isMatch = false;
00782                             break;
00783                         }
00784                     }
00785                     if ( $isMatch )
00786                         break;
00787                 }
00788                 if ( $isMatch )
00789                     continue;
00790             }
00791             $newNodes[] = $node;
00792         }
00793         return $newNodes;
00794     }
00795 
00796     /*!
00797      \static
00798      \return the placement info from the function node \a $node.
00799     */
00800     static function extractFunctionNodePlacement( &$node )
00801     {
00802         return $node[4];
00803     }
00804 
00805     /*!
00806      \static
00807      \return the children of the function node \a $node.
00808     */
00809     static function extractFunctionNodeChildren( &$node )
00810     {
00811         return $node[1];
00812     }
00813 
00814     /*!
00815      \static
00816      \return the parameters of the function node \a $node.
00817     */
00818     static function extractFunctionNodeParameters( &$node )
00819     {
00820         return $node[3];
00821     }
00822 
00823     /*!
00824      \static
00825      \return the parameters of the function node \a $node.
00826     */
00827     static function extractFunctionNodeParameterNames( &$node )
00828     {
00829         return array_keys( $node[3] );
00830     }
00831 
00832     /*!
00833      \static
00834      \return the variable data from the variable node \a $node.
00835     */
00836     static function extractVariableNodeData( &$node )
00837     {
00838         return $node[1];
00839     }
00840 
00841     /*!
00842      \static
00843      \return the name of the function for the function node \a $node.
00844     */
00845     static function extractFunctionNodeName( &$node )
00846     {
00847         return $node[2];
00848     }
00849 
00850     /*!
00851      \static
00852      \return the variable placement from the variable node \a $node.
00853     */
00854     static function extractVariableNodePlacement( &$node )
00855     {
00856         return $node[2];
00857     }
00858 
00859     /*!
00860      \static
00861      \return the parameters for the operator node \a $node.
00862     */
00863     static function extractOperatorNodeParameters( &$node )
00864     {
00865         return array_slice( $node[1], 1 );
00866     }
00867 
00868     /*!
00869      \static
00870      Creates a pre and post hook for the function node \a $node
00871      with the children in between the nodes. This means that a nested
00872      function node will be deflated to a pre/children/post list.
00873     */
00874     static function deflateFunctionNode( &$node, $preHook, $postHook )
00875     {
00876         $newNodes = array();
00877         $children = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
00878         eZTemplateNodeTool::removeFunctionNodeChildren( $node );
00879         $preNode = $node;
00880         $preHookParameters = array();
00881         if ( isset( $preHook['parameters'] ) )
00882             $preHookParameters = $preHook['parameters'];
00883         $preHookFunction = false;
00884         if ( isset( $preHook['function'] ) )
00885             $preHookFunction = $preHook['function'];
00886         eZTemplateNodeTool::createFunctionNodeHook( $preNode, $preHook['name'], $preHookParameters, $preHookFunction );
00887         if ( isset( $preHook['use-parameters'] ) and
00888              !$preHook['use-parameters'] )
00889             eZTemplateNodeTool::removeFunctionNodeParameters( $preNode );
00890         $newNodes[] = $preNode;
00891         $newNodes = array_merge( $newNodes, $children );
00892         $postNode = $node;
00893         $postHookParameters = array();
00894         if ( isset( $postHook['parameters'] ) )
00895             $postHookParameters = $postHook['parameters'];
00896         $postHookFunction = false;
00897         if ( isset( $postHook['function'] ) )
00898             $postHookFunction = $postHook['function'];
00899         eZTemplateNodeTool::createFunctionNodeHook( $postNode, $postHook['name'], $postHookParameters, $postHookFunction );
00900         if ( isset( $postHook['use-parameters'] ) and
00901              !$postHook['use-parameters'] )
00902             eZTemplateNodeTool::removeFunctionNodeParameters( $postNode );
00903         $newNodes[] = $postNode;
00904         return $newNodes;
00905     }
00906 }
00907 
00908 ?>