[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/eztemplate/classes/ -> eztemplatenodetool.php (source)

   1  <?php
   2  //
   3  // Definition of eZTemplateNodeTool class
   4  //
   5  // Created on: <13-May-2003 14:12:01 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file eztemplatenodetool.php
  30  */
  31  
  32  /*!
  33    \class eZTemplateNodeTool eztemplatenodetool.php
  34    \ingroup eZTemplate
  35    \brief Various tool functions for working with template nodes
  36  
  37  */
  38  
  39  class eZTemplateNodeTool
  40  {
  41      /*!
  42       Constructor
  43      */
  44      function eZTemplateNodeTool()
  45      {
  46      }
  47  
  48      /*!
  49       \static
  50       Removes the children from the function node \a $node.
  51      */
  52      function removeFunctionNodeChildren( &$node )
  53      {
  54          $node[1] = false;
  55      }
  56  
  57      /*!
  58       \static
  59       Removes the parameters from the function node \a $node.
  60      */
  61      function removeFunctionNodeParameters( &$node )
  62      {
  63          $node[3] = false;
  64      }
  65  
  66      /*!
  67       \static
  68       Removes the placement info from the function node \a $node.
  69      */
  70      function removeFunctionNodePlacement( &$node )
  71      {
  72          $node[4] = false;
  73      }
  74  
  75      /*!
  76       \static
  77       Creates an element which represents nothing (void).
  78      */
  79      function createVoidElement()
  80      {
  81          return array( EZ_TEMPLATE_TYPE_VOID );
  82      }
  83  
  84      /*!
  85       \static
  86       Creates an element which represents the static value and returns it,
  87       the type of the variable determines the type of the element.
  88      */
  89      function createConstantElement( $constant, $variablePlacement = false )
  90      {
  91          if ( is_array( $constant ) )
  92              return eZTemplateNodeTool::createArrayElement( $constant, $variablePlacement );
  93          else if ( is_string( $constant ) )
  94              return eZTemplateNodeTool::createStringElement( $constant, $variablePlacement );
  95          else if ( is_bool( $constant ) )
  96              return eZTemplateNodeTool::createBooleanElement( $constant, $variablePlacement );
  97          else if ( is_numeric( $constant ) )
  98              return eZTemplateNodeTool::createNumericElement( $constant, $variablePlacement );
  99          else
 100              return eZTemplateNodeTool::createVoidElement();
 101      }
 102  
 103      /*!
 104       \static
 105       \deprecated Use createConstantElement instead.
 106      */
 107      function createStaticElement( $static, $variablePlacement = false )
 108      {
 109          if ( is_array( $static ) )
 110              return eZTemplateNodeTool::createArrayElement( $static, $variablePlacement );
 111          else if ( is_string( $static ) )
 112              return eZTemplateNodeTool::createStringElement( $static, $variablePlacement );
 113          else if ( is_bool( $static ) )
 114              return eZTemplateNodeTool::createBooleanElement( $static, $variablePlacement );
 115          else if ( is_numeric( $static ) )
 116              return eZTemplateNodeTool::createNumericElement( $static, $variablePlacement );
 117          else
 118              return eZTemplateNodeTool::createVoidElement();
 119      }
 120  
 121      /*!
 122       \static
 123       Creates an element which represents a string and returns it.
 124      */
 125      function createStringElement( $string, $variablePlacement = false )
 126      {
 127          return array( EZ_TEMPLATE_TYPE_STRING,
 128                        $string, $variablePlacement );
 129      }
 130  
 131      /*!
 132       \static
 133       Creates an element which represents a number (float or integer) and returns it.
 134      */
 135      function createNumericElement( $number, $variablePlacement = false )
 136      {
 137          return array( EZ_TEMPLATE_TYPE_NUMERIC,
 138                        $number, $variablePlacement );
 139      }
 140  
 141      /*!
 142       \static
 143       Creates an element which represents an identifier and returns it.
 144      */
 145      function createIdentifierElement( $identifier, $variablePlacement = false )
 146      {
 147          return array( EZ_TEMPLATE_TYPE_IDENTIFIER,
 148                        $identifier, $variablePlacement );
 149      }
 150  
 151      /*!
 152       \static
 153       Creates an element which represents an array and returns it.
 154  
 155       \param array key list, static.
 156       \param array values as php code.
 157       \param values.
 158      */
 159      function createDynamicArrayElement( &$arrayKeys, &$arrayValues, $variablePlacement = false )
 160      {
 161          return array( EZ_TEMPLATE_TYPE_DYNAMIC_ARRAY,
 162                        $arrayKeys, $arrayValues, $variablePlacement );
 163      }
 164  
 165      /*!
 166       \static
 167       Creates an element which represents an array and returns it.
 168      */
 169      function createArrayElement( $array, $variablePlacement = false )
 170      {
 171          return array( EZ_TEMPLATE_TYPE_ARRAY,
 172                        $array, $variablePlacement );
 173      }
 174  
 175      /*!
 176       \static
 177       Creates an element which represents a boolean and returns it.
 178      */
 179      function createBooleanElement( $boolean, $variablePlacement = false )
 180      {
 181          if ( !is_bool( $boolean ) )
 182              $boolean = (bool)$boolean;
 183          return array( EZ_TEMPLATE_TYPE_BOOLEAN,
 184                        $boolean, $variablePlacement );
 185      }
 186  
 187      /*!
 188       \static
 189       Creates an element which represents an array and returns it.
 190      */
 191      function createPHPVariableElement( $variableName, $variablePlacement = false )
 192      {
 193          return array( EZ_TEMPLATE_TYPE_PHP_VARIABLE,
 194                        $variableName, $variablePlacement );
 195      }
 196  
 197      /*!
 198       \static
 199       Creates an element which represents an variable lookup and returns it.
 200       \param $namespaceScope Type of variable lookup, can be one of:
 201                              - \b EZ_TEMPLATE_NAMESPACE_SCOPE_GLOBAL, Look for variables at the very top of the namespace tree
 202                              - \b EZ_TEMPLATE_NAMESPACE_SCOPE_LOCAL, Look for variables at the top of the current file being processed
 203                              - \b EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, Look for variables from the current namespace
 204      */
 205      function createVariableElement( $variableName, $namespaceName, $namespaceScope = EZ_TEMPLATE_NAMESPACE_SCOPE_LOCAL, $variablePlacement = false )
 206      {
 207          return array( EZ_TEMPLATE_TYPE_VARIABLE,
 208                        array( $namespaceName, $namespaceScope, $variableName ), $variablePlacement );
 209      }
 210  
 211      /*!
 212       \static
 213       Creates an element which does lookup on an attribute and returns it.
 214       \param $attributeValues Must be an array with elements that result in scalar value or string.
 215      */
 216      function createAttributeLookupElement( $attributeValues = array(), $variablePlacement = false )
 217      {
 218          if ( is_numeric( $attributeValues ) )
 219              $attributeValues = array( eZTemplateNodeTool::createNumericElement( $attributeValues, $variablePlacement ) );
 220          else if ( !is_array( $attributeValues ) )
 221              $attributeValues = array( eZTemplateNodeTool::createStringElement( $attributeValues, $variablePlacement ) );
 222          return array( EZ_TEMPLATE_TYPE_ATTRIBUTE,
 223                        $attributeValues, $variablePlacement );
 224      }
 225  
 226      /*!
 227       \static
 228       Creates an element which represents an operator and returns it.
 229       \param $name The name of the operator to run.
 230       \param $parameters An array with parameters, each parameter is an array of variable elements.
 231      */
 232      function createOperatorElement( $name, $parameters = array(), $variablePlacement = false )
 233      {
 234          return array( EZ_TEMPLATE_TYPE_ATTRIBUTE,
 235                        array_merge( array( $name ), $parameters ), $variablePlacement );
 236      }
 237  
 238      /*!
 239       \return The value of the constant element or \c null if the element is not constant.
 240       \note Make sure the element is checked with isConstantElement() before running this.
 241       \note Can also be used on PHP variable elements, it will then fetch the variable name.
 242      */
 243      function elementConstantValue( $elements )
 244      {
 245          if ( eZTemplateNodeTool::isConstantElement( $elements ) or
 246               eZTemplateNodeTool::isPHPVariableElement( $elements ) )
 247              return $elements[0][1];
 248          return null;
 249      }
 250  
 251      /*!
 252       \static
 253       \deprecated Use elementConstantValue instead.
 254      */
 255      function elementStaticValue( $elements )
 256      {
 257          if ( eZTemplateNodeTool::isConstantElement( $elements ) or
 258               eZTemplateNodeTool::isPHPVariableElement( $elements ) )
 259              return $elements[0][1];
 260          return null;
 261      }
 262  
 263      /*!
 264       \return the array keys of the Dynamic array
 265      */
 266      function elementDynamicArrayKeys( $elements )
 267      {
 268          if ( !eZTemplateNodeTool::isDynamicArrayElement( $elements ) )
 269              return null;
 270          return $elements[0][1];
 271      }
 272  
 273      /*!
 274       \return assosiative array of parameters in Dynamic Array
 275      */
 276      function elementDynamicArray( $elements )
 277      {
 278          if ( !eZTemplateNodeTool::isDynamicArrayElement( $elements ) )
 279              return null;
 280          return $elements[0][2];
 281      }
 282  
 283  
 284      /*!
 285       \return \c true if the element list \a $elements is considered to have a constant value.
 286               It is considered constant if the following is true:
 287               - The start value is either numeric, text, identifier, array or boolean
 288               - It has no operators
 289               - It has no attribute lookup
 290      */
 291      function isConstantElement( $elements )
 292      {
 293          $constantElements = array( EZ_TEMPLATE_TYPE_VOID,
 294                                     EZ_TEMPLATE_TYPE_STRING, EZ_TEMPLATE_TYPE_IDENTIFIER,
 295                                     EZ_TEMPLATE_TYPE_NUMERIC, EZ_TEMPLATE_TYPE_BOOLEAN, EZ_TEMPLATE_TYPE_ARRAY );
 296  
 297          if ( count( $elements ) == 0 )
 298              return false;
 299          if ( count( $elements ) > 1 )
 300              return false;
 301  
 302          if ( in_array( $elements[0][0], $constantElements ) )
 303              return true;
 304          return false;
 305      }
 306  
 307      /*!
 308       \deprecated Use isConstantElement instead.
 309      */
 310      function isStaticElement( $elements )
 311      {
 312          $staticElements = array( EZ_TEMPLATE_TYPE_VOID,
 313                                   EZ_TEMPLATE_TYPE_STRING, EZ_TEMPLATE_TYPE_IDENTIFIER,
 314                                   EZ_TEMPLATE_TYPE_NUMERIC, EZ_TEMPLATE_TYPE_BOOLEAN, EZ_TEMPLATE_TYPE_ARRAY );
 315  
 316          if ( count( $elements ) == 0 )
 317              return false;
 318          if ( count( $elements ) > 1 )
 319              return false;
 320  
 321          if ( in_array( $elements[0][0], $staticElements ) )
 322              return true;
 323          return false;
 324      }
 325  
 326      /*!
 327       \return \c true if the element list \a $elements is considered to be an internal code piece.
 328      */
 329      function isInternalCodePiece( $elements )
 330      {
 331          if ( isset( $elements[0][0]) && ( $elements[0][0] == EZ_TEMPLATE_TYPE_INTERNAL_CODE_PIECE ) )
 332              return true;
 333          return false;
 334      }
 335  
 336      /*!
 337       \return \c true if the element list \a $elements is considered to be a variable element.
 338      */
 339      function isVariableElement( $elements )
 340      {
 341          if ( isset( $elements[0][0] ) && ( $elements[0][0] == EZ_TEMPLATE_TYPE_VARIABLE ) )
 342              return true;
 343          return false;
 344      }
 345  
 346      /*!
 347       \return \c true if the element list \a $elements is considered to have a PHP variable element.
 348               The following must be true.
 349               - The start value is PHP variable
 350               - It has no operators
 351               - It has no attribute lookup
 352      */
 353      function isPHPVariableElement( $elements )
 354      {
 355          if ( count( $elements ) == 0 )
 356              return false;
 357          if ( count( $elements ) > 1 )
 358              return false;
 359  
 360          if ( $elements[0][0] == EZ_TEMPLATE_TYPE_PHP_VARIABLE )
 361              return true;
 362          return false;
 363      }
 364  
 365      /*!
 366       \return \c true if the element list \a $elements is considered to be numerical.
 367               It is considered constant if the following is true:
 368               - The start value is numeric (integer or float)
 369               - It has no operators
 370               - It has no attribute lookup
 371       \sa isConstantElement
 372       \note If you don't care about pure integers or floats use isConstantElement instead and just use the
 373             element value as numerical value.
 374      */
 375      function isNumericElement( $elements )
 376      {
 377          $constantElements = array( EZ_TEMPLATE_TYPE_NUMERIC );
 378  
 379          if ( count( $elements ) == 0 )
 380              return false;
 381  
 382          if ( in_array( $elements[0][0], $constantElements ) )
 383              return true;
 384          return false;
 385      }
 386  
 387      /*!
 388       \return \c true if the element list \a $elements is considered to be a string.
 389               It is considered constant if the following is true:
 390               - The start value is string or identifier
 391               - It has no operators
 392               - It has no attribute lookup
 393       \sa isConstantElement
 394       \note If you don't care about pure strings use isConstantElement instead and just use the
 395             element value as string value.
 396      */
 397      function isStringElement( $elements )
 398      {
 399          $constantElements = array( EZ_TEMPLATE_TYPE_STRING, EZ_TEMPLATE_TYPE_IDENTIFIER );
 400  
 401          if ( count( $elements ) == 0 )
 402              return false;
 403  
 404          if ( in_array( $elements[0][0], $constantElements ) )
 405              return true;
 406          return false;
 407      }
 408  
 409      /*!
 410       \return \c true if the element list \a $elements is considered to be an identifier.
 411               It is considered constant if the following is true:
 412               - The start value is identifier
 413               - It has no operators
 414               - It has no attribute lookup
 415       \sa isConstantElement
 416       \note If you don't care about pure identifiers use isStringElement or isConstantElement instead.
 417      */
 418      function isIdentifierElement( $elements )
 419      {
 420          $constantElements = array( EZ_TEMPLATE_TYPE_IDENTIFIER );
 421  
 422          if ( count( $elements ) == 0 )
 423              return false;
 424  
 425          if ( in_array( $elements[0][0], $constantElements ) )
 426              return true;
 427          return false;
 428      }
 429  
 430      /*!
 431       \return \c true if the element list \a $elements is considered to be a boolean.
 432               It is considered constant if the following is true:
 433               - The start value is boolean
 434               - It has no operators
 435               - It has no attribute lookup
 436       \sa isConstantElement
 437       \note If you don't care about pure booleans use isConstantElement instead and just use the
 438             element value as boolean value.
 439      */
 440      function isBooleanElement( $elements )
 441      {
 442          $constantElements = array( EZ_TEMPLATE_TYPE_BOOLEAN );
 443  
 444          if ( count( $elements ) == 0 )
 445              return false;
 446  
 447          if ( in_array( $elements[0][0], $constantElements ) )
 448              return true;
 449          return false;
 450      }
 451  
 452      /*!
 453        \static
 454        Check if element id Dynamic Array
 455      */
 456      function isDynamicArrayElement( $elements )
 457      {
 458          if ( count( $elements ) == 0 )
 459              return false;
 460  
 461          if ( $elements[0][0] == EZ_TEMPLATE_TYPE_DYNAMIC_ARRAY )
 462              return true;
 463          return false;
 464      }
 465  
 466      /*!
 467       \return \c true if the element list \a $elements is considered to be an array.
 468               It is considered constant if the following is true:
 469               - The start value is array
 470               - It has no operators
 471               - It has no attribute lookup
 472       \sa isConstantElement
 473      */
 474      function isArrayElement( $elements )
 475      {
 476          $constantElements = array( EZ_TEMPLATE_TYPE_ARRAY );
 477  
 478          if ( count( $elements ) == 0 )
 479              return false;
 480  
 481          if ( in_array( $elements[0][0], $constantElements ) )
 482              return true;
 483          return false;
 484      }
 485  
 486      /*!
 487       \static
 488       Creates a new function node hook with name \a $hookName and optional parameters \a $hookParameters
 489       and function data \a $hookFunction and returns it.
 490      */
 491      function createFunctionNodeHook( &$node, $hookName, $hookParameters = array(), $hookFunction = false )
 492      {
 493          $node[5] = array( 'name' => $hookName,
 494                            'parameters' => $hookParameters,
 495                            'function' => $hookFunction );
 496      }
 497  
 498      /*!
 499       \static
 500       Creates a new variable node and returns it.
 501      */
 502      function createVariableNode( $originalNode = false, $variableData = false, $variablePlacement = false,
 503                                   $parameters = array(), $variableAssignmentName = false, $onlyExisting = false,
 504                                   $overWrite = true, $assignFromVariable = false, $rememberSet = false )
 505      {
 506          $node = array();
 507          if ( $originalNode )
 508              $node = $originalNode;
 509          else
 510          {
 511              $node[0] = EZ_TEMPLATE_NODE_VARIABLE;
 512              $node[1] = $variableAssignmentName;
 513              if ( is_array( $variableData ) )
 514                  $node[2] = $variableData;
 515              else if ( $assignFromVariable )
 516                  $node[2] = array( array( EZ_TEMPLATE_TYPE_PHP_VARIABLE,
 517                                           $variableData,
 518                                           false ) );
 519              else if ( is_bool( $variableData ) )
 520                  $node[2] = array( array( EZ_TEMPLATE_TYPE_BOOLEAN,
 521                                           $variableData,
 522                                           false ) );
 523              else if ( is_string( $variableData ) )
 524                  $node[2] = array( array( EZ_TEMPLATE_TYPE_STRING,
 525                                           $variableData,
 526                                           false ) );
 527              else if ( is_numeric( $variableData ) )
 528                  $node[2] = array( array( EZ_TEMPLATE_TYPE_NUMERIC,
 529                                           $variableData,
 530                                           false ) );
 531              else
 532                  $node[2] = array( array( EZ_TEMPLATE_TYPE_STRING,
 533                                           $variableData,
 534                                           false ) );
 535              $node[3] = $variablePlacement;
 536          }
 537          $node[4] = $parameters;
 538          $node[5] = $onlyExisting;
 539          $node[6] = $overWrite;
 540          $node[7] = $rememberSet;
 541          return $node;
 542      }
 543  
 544      function createCodePieceElement( $codePiece, $values = false, $placement = false, $tmpValues = false, $knownTypes = true )
 545      {
 546          $element = array( EZ_TEMPLATE_TYPE_INTERNAL_CODE_PIECE,
 547                            $codePiece,
 548                            $placement,
 549                            $values, $tmpValues, $knownTypes );
 550          return $element;
 551      }
 552  
 553      function createTextNode( $text )
 554      {
 555          $node = array( EZ_TEMPLATE_NODE_TEXT, false, $text, false );
 556          return $node;
 557      }
 558  
 559      function createWarningNode( $text, $label, $placement = false, $parameters = array() )
 560      {
 561          $node = array( EZ_TEMPLATE_NODE_INTERNAL_WARNING,
 562                         $text, $label,
 563                         $parameters, $placement );
 564          return $node;
 565      }
 566  
 567      function createErrorNode( $text, $label, $placement = false, $parameters = array() )
 568      {
 569          $node = array( EZ_TEMPLATE_NODE_INTERNAL_ERROR,
 570                         $text, $label,
 571                         $parameters, $placement );
 572          return $node;
 573      }
 574  
 575      function createCodePieceNode( $codePiece, $parameters = array() )
 576      {
 577          $node = array( EZ_TEMPLATE_NODE_INTERNAL_CODE_PIECE,
 578                         $codePiece,
 579                         $parameters );
 580          return $node;
 581      }
 582  
 583      function createVariableUnsetNode( $variableName, $parameters = array() )
 584      {
 585          $node = array( EZ_TEMPLATE_NODE_INTERNAL_VARIABLE_UNSET,
 586                         $variableName,
 587                         $parameters );
 588          return $node;
 589      }
 590  
 591      /*!
 592       Creates a new template node that will assign the content of the current output variable
 593       to the variable named \a $variableName.
 594  
 595       The assignment type is by default text concat (.) and can be changed using \a $assignmentType.
 596       \param $parameters An array with optional parameters, can contain the followin:
 597              - spacing - The number of spaces to added for each line this expression creates.
 598      */
 599      function createWriteToOutputVariableNode( $variableName, $parameters = array(), $assignmentType = EZ_PHPCREATOR_VARIABLE_APPEND_TEXT )
 600      {
 601          $node = array( EZ_TEMPLATE_NODE_INTERNAL_OUTPUT_ASSIGN,
 602                         $variableName,
 603                         $parameters,
 604                         $assignmentType );
 605          return $node;
 606      }
 607  
 608      /*!
 609       Creates a new template node that will assign the content of the current output variable
 610       to the variable named \a $variableName.
 611  
 612       The assignment type is by default variable assignment (=) and can be changed using \a $assignmentType.
 613       \param $parameters An array with optional parameters, can contain the followin:
 614              - spacing - The number of spaces to added for each line this expression creates.
 615      */
 616      function createAssignFromOutputVariableNode( $variableName, $parameters = array(), $assignmentType = EZ_PHPCREATOR_VARIABLE_ASSIGNMENT )
 617      {
 618          $node = array( EZ_TEMPLATE_NODE_INTERNAL_OUTPUT_READ,
 619                         $variableName,
 620                         $parameters,
 621                         $assignmentType );
 622          return $node;
 623      }
 624  
 625      function createOutputVariableIncreaseNode( $parameters = array() )
 626      {
 627          $node = array( EZ_TEMPLATE_NODE_INTERNAL_OUTPUT_INCREASE,
 628                         $parameters );
 629          return $node;
 630      }
 631  
 632      function createOutputVariableDecreaseNode( $parameters = array() )
 633      {
 634          $node = array( EZ_TEMPLATE_NODE_INTERNAL_OUTPUT_DECREASE,
 635                         $parameters );
 636          return $node;
 637      }
 638  
 639      function createSpacingIncreaseNode( $spacing = 4, $parameters = array() )
 640      {
 641          $node = array( EZ_TEMPLATE_NODE_INTERNAL_SPACING_INCREASE,
 642                         $spacing, $parameters );
 643          return $node;
 644      }
 645  
 646      function createSpacingDecreaseNode( $spacing = 4, $parameters = array() )
 647      {
 648          $node = array( EZ_TEMPLATE_NODE_INTERNAL_SPACING_DECREASE,
 649                         $spacing, $parameters );
 650          return $node;
 651      }
 652  
 653      function createNamespaceChangeNode( $variableData, $parameters = array() )
 654      {
 655          if ( is_string( $variableData ) )
 656              $variableData = array( eZTemplateNodeTool::createStringElement( $variableData ) );
 657          else if ( is_numeric( $variableData ) )
 658              $variableData = array( eZTemplateNodeTool::createNumericElement( $variableData ) );
 659          $node = array( EZ_TEMPLATE_NODE_INTERNAL_NAMESPACE_CHANGE,
 660                         $variableData,
 661                         $parameters );
 662          return $node;
 663      }
 664  
 665      function createNamespaceRestoreNode( $parameters = array() )
 666      {
 667          $node = array( EZ_TEMPLATE_NODE_INTERNAL_NAMESPACE_RESTORE,
 668                         $parameters );
 669          return $node;
 670      }
 671  
 672      function createResourceAcquisitionNode( $resourceName, $templateName, $fileName,
 673                                              $method, $extraParameters, $placement = false,
 674                                              $parameters = array(), $newRootNamespace = false, $resourceVariableName = false )
 675      {
 676          $node = array( EZ_TEMPLATE_NODE_INTERNAL_RESOURCE_ACQUISITION,
 677                         $resourceName, $templateName, $fileName,
 678                         $method, $extraParameters, $placement );
 679          if ( count( $parameters ) > 0 )
 680              $node[] = $parameters;
 681          else
 682              $node[] = false;
 683          $node[] = $newRootNamespace;
 684          $node[] = $resourceVariableName;
 685          return $node;
 686      }
 687  
 688      function extractNodes( $nodeList, $parameters = array() )
 689      {
 690          $match = false;
 691          if ( isset( $parameters['match'] ) )
 692              $match = $parameters['match'];
 693          $newNodes = array();
 694          $skipNode = false;
 695          if ( $match['type'] == 'after' )
 696              $skipNode = true;
 697  
 698          if ( !is_array( $nodeList ) )
 699          {
 700              return $newNodes;
 701          }
 702          foreach ( $nodeList as $node )
 703          {
 704              if ( $match )
 705              {
 706                  $isMatch = true;
 707                  foreach ( $match['matches'] as $matchItem )
 708                  {
 709                      $operand1 = $matchItem['match-with'];
 710                      $matchKeys = $matchItem['match-keys'];
 711                      $operand2 = $node;
 712                      foreach ( $matchKeys as $matchKey )
 713                      {
 714                          $operand2 = $operand2[$matchKey];
 715                      }
 716                      if ( isset( $matchItem['match-function'] ) )
 717                      {
 718                          $function = $matchItem['match-function'];
 719                          $functionResult = $function( $operand1, $operand2 );
 720                          $wasMatch = $functionResult == 0;
 721                      }
 722                      else
 723                      {
 724                          if ( is_array( $operand1 ) )
 725                              $wasMatch = in_array( $operand2, $operand1 );
 726                          else
 727                              $wasMatch = ( $operand1 == $operand2 );
 728                      }
 729                      if ( !$wasMatch )
 730                      {
 731                          $isMatch = false;
 732                          break;
 733                      }
 734                  }
 735                  if ( $match['type'] == 'equal' )
 736                  {
 737                      if ( !$isMatch )
 738                          continue;
 739                  }
 740                  else if ( $match['type'] == 'before' )
 741                  {
 742                      if ( $isMatch )
 743                          break;
 744                  }
 745                  else if ( $match['type'] = 'after' )
 746                  {
 747                      if ( $isMatch )
 748                      {
 749                          $skipNode = false;
 750                          $match = false;
 751                          continue;
 752                      }
 753                  }
 754              }
 755              if ( $skipNode )
 756                  continue;
 757              if ( $match and isset( $match['filter'] ) )
 758              {
 759                  $isMatch = true;
 760                  foreach ( $match['filter'] as $matchFilterItem )
 761                  {
 762                      foreach ( $matchFilterItem as $matchItem )
 763                      {
 764                          $operand1 = $matchItem['match-with'];
 765                          $matchKeys = $matchItem['match-keys'];
 766                          $operand2 = $node;
 767                          foreach ( $matchKeys as $matchKey )
 768                          {
 769                              $operand2 = $operand2[$matchKey];
 770                          }
 771                          if ( isset( $matchItem['match-function'] ) )
 772                          {
 773                              $function = $matchItem['match-function'];
 774                              $functionResult = $function( $operand1, $operand2 );
 775                              $wasMatch = $functionResult == 0;
 776                          }
 777                          else
 778                          {
 779                              if ( is_array( $operand1 ) )
 780                                  $wasMatch = in_array( $operand2, $operand1 );
 781                              else
 782                                  $wasMatch = ( $operand1 == $operand2 );
 783                          }
 784                          if ( !$wasMatch )
 785                          {
 786                              $isMatch = false;
 787                              break;
 788                          }
 789                      }
 790                      if ( $isMatch )
 791                          break;
 792                  }
 793                  if ( $isMatch )
 794                      continue;
 795              }
 796              $newNodes[] = $node;
 797          }
 798          return $newNodes;
 799      }
 800  
 801      /*!
 802       \static
 803       \return the placement info from the function node \a $node.
 804      */
 805      function extractFunctionNodePlacement( &$node )
 806      {
 807          return $node[4];
 808      }
 809  
 810      /*!
 811       \static
 812       \return the children of the function node \a $node.
 813      */
 814      function extractFunctionNodeChildren( &$node )
 815      {
 816          return $node[1];
 817      }
 818  
 819      /*!
 820       \static
 821       \return the parameters of the function node \a $node.
 822      */
 823      function extractFunctionNodeParameters( &$node )
 824      {
 825          return $node[3];
 826      }
 827  
 828      /*!
 829       \static
 830       \return the parameters of the function node \a $node.
 831      */
 832      function extractFunctionNodeParameterNames( &$node )
 833      {
 834          return array_keys( $node[3] );
 835      }
 836  
 837      /*!
 838       \static
 839       \return the variable data from the variable node \a $node.
 840      */
 841      function extractVariableNodeData( &$node )
 842      {
 843          return $node[1];
 844      }
 845  
 846      /*!
 847       \static
 848       \return the name of the function for the function node \a $node.
 849      */
 850      function extractFunctionNodeName( &$node )
 851      {
 852          return $node[2];
 853      }
 854  
 855      /*!
 856       \static
 857       \return the variable placement from the variable node \a $node.
 858      */
 859      function extractVariableNodePlacement( &$node )
 860      {
 861          return $node[2];
 862      }
 863  
 864      /*!
 865       \static
 866       \return the parameters for the operator node \a $node.
 867      */
 868      function extractOperatorNodeParameters( &$node )
 869      {
 870          return array_slice( $node[1], 1 );
 871      }
 872  
 873      /*!
 874       \static
 875       Creates a pre and post hook for the function node \a $node
 876       with the children in between the nodes. This means that a nested
 877       function node will be deflated to a pre/children/post list.
 878      */
 879      function deflateFunctionNode( &$node, $preHook, $postHook )
 880      {
 881          $newNodes = array();
 882          $children = eZTemplateNodeTool::extractFunctionNodeChildren( $node );
 883          eZTemplateNodeTool::removeFunctionNodeChildren( $node );
 884          $preNode = $node;
 885          $preHookParameters = array();
 886          if ( isset( $preHook['parameters'] ) )
 887              $preHookParameters = $preHook['parameters'];
 888          $preHookFunction = false;
 889          if ( isset( $preHook['function'] ) )
 890              $preHookFunction = $preHook['function'];
 891          eZTemplateNodeTool::createFunctionNodeHook( $preNode, $preHook['name'], $preHookParameters, $preHookFunction );
 892          if ( isset( $preHook['use-parameters'] ) and
 893               !$preHook['use-parameters'] )
 894              eZTemplateNodeTool::removeFunctionNodeParameters( $preNode );
 895          $newNodes[] = $preNode;
 896          $newNodes = array_merge( $newNodes, $children );
 897          $postNode = $node;
 898          $postHookParameters = array();
 899          if ( isset( $postHook['parameters'] ) )
 900              $postHookParameters = $postHook['parameters'];
 901          $postHookFunction = false;
 902          if ( isset( $postHook['function'] ) )
 903              $postHookFunction = $postHook['function'];
 904          eZTemplateNodeTool::createFunctionNodeHook( $postNode, $postHook['name'], $postHookParameters, $postHookFunction );
 905          if ( isset( $postHook['use-parameters'] ) and
 906               !$postHook['use-parameters'] )
 907              eZTemplateNodeTool::removeFunctionNodeParameters( $postNode );
 908          $newNodes[] = $postNode;
 909          return $newNodes;
 910      }
 911  }
 912  
 913  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7