[ 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/ -> eztemplatedofunction.php (source)

   1  <?php
   2  //
   3  // Definition of eZTemplateDoFunction class
   4  //
   5  // Created on: <25-Feb-2005 13:04:30 vs>
   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  /*!
  30    \class eZTemplateDoFunction eztemplatedofunction.php
  31    \ingroup eZTemplateFunctions
  32    \brief DO..WHILE loop
  33  
  34    Syntax:
  35  \code
  36      {do}
  37          [{delimiter}...{/delimiter}]
  38          [{break}]
  39          [{continue}]
  40          [{skip}]
  41      {/do while <condition> [sequence <array> as $seqVar]}
  42  \endcode
  43  
  44    Example:
  45  \code
  46      {do}
  47          One more beer, please.
  48      {/do while eq( $drunk, false() )}
  49  \endcode
  50  */
  51  
  52  define ( 'EZ_TEMPLATE_DO_FUNCTION_NAME', 'do' );
  53  class eZTemplateDoFunction
  54  {
  55      /*!
  56       * Returns an array of the function names, required for eZTemplate::registerFunctions().
  57       */
  58      function &functionList()
  59      {
  60          $functionList = array( EZ_TEMPLATE_DO_FUNCTION_NAME );
  61          return $functionList;
  62      }
  63  
  64      /*!
  65       * Returns the attribute list
  66       * key:   parameter name
  67       * value: can have children
  68       */
  69      function attributeList()
  70      {
  71          return array( 'delimiter' => true,
  72                        'break'     => false,
  73                        'continue'  => false,
  74                        'skip'      => false );
  75      }
  76  
  77  
  78      /*!
  79       * Returns the array with hits for the template compiler.
  80       */
  81      function functionTemplateHints()
  82      {
  83          return array( EZ_TEMPLATE_DO_FUNCTION_NAME => array( 'parameters' => true,
  84                                                               'static' => false,
  85                                                               'transform-parameters' => true,
  86                                                               'tree-transformation' => true ) );
  87      }
  88  
  89      /*!
  90       * Compiles the function and its children into PHP code.
  91       */
  92      function templateNodeTransformation( $functionName, &$node,
  93                                           &$tpl, $parameters, $privateData )
  94      {
  95          // {/do while <condition> [sequence <sequence_array> as $<sequence_var>]}
  96  
  97          $tpl->DoCounter++;
  98          $newNodes      = array();
  99          $nodePlacement = eZTemplateNodeTool::extractFunctionNodePlacement( $node );
 100          $uniqid        =  md5( $nodePlacement[2] ) . "_" . $tpl->DoCounter;
 101  
 102          // initialize loop
 103          require_once ( 'lib/eztemplate/classes/eztemplatecompiledloop.php' );
 104          $loop = new eZTemplateCompiledLoop( EZ_TEMPLATE_DO_FUNCTION_NAME,
 105                                              $newNodes, $parameters, $nodePlacement, $uniqid,
 106                                              $node, $tpl, $privateData );
 107  
 108          $loop->initVars();
 109  
 110          // loop header
 111          $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "while ( 1 ) // do..while\n{" );
 112          $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode();
 113  
 114          $loop->processBody();
 115  
 116          // loop footer
 117          $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['condition'], $nodePlacement, array( 'treat-value-as-non-object' => true ), 'do_cond' );
 118          $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( ! \$do_cond ) break;" );
 119          $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode();
 120          $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "} // do..while" );
 121          $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'do_cond' );
 122  
 123          $loop->cleanup();
 124  
 125          return $newNodes;
 126      }
 127  
 128      /*!
 129       * Actually executes the function and its children (in processed mode).
 130       */
 131      function process( &$tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
 132      {
 133          require_once ( 'lib/eztemplate/classes/eztemplateloop.php' );
 134          $loop = new eZTemplateLoop( EZ_TEMPLATE_DO_FUNCTION_NAME,
 135                                      $functionParameters, $functionChildren, $functionPlacement,
 136                                      $tpl, $textElements, $rootNamespace, $currentNamespace );
 137  
 138          if ( !$loop->initialized() )
 139              return;
 140  
 141          if ( !isset( $functionParameters['condition'] ) )
 142          {
 143              eZDebug::writeError( "Not enough arguments passed to 'do' function"  );
 144              return;
 145          }
 146  
 147          do
 148          {
 149              $loop->setSequenceVar(); // set sequence variable (if specified)
 150              $loop->processDelimiter();
 151              $loop->resetIteration();
 152  
 153              if ( $loop->processChildren() )
 154                  break;
 155  
 156              $loop->incrementSequence();
 157          } while ( $tpl->elementValue( $functionParameters['condition'], $rootNamespace, $currentNamespace, $functionPlacement ) );
 158  
 159          $loop->cleanup();
 160      }
 161  
 162      /*!
 163       * Returns true, telling the template parser that the function can have children.
 164       */
 165      function hasChildren()
 166      {
 167          return true;
 168      }
 169  }
 170  
 171  ?>


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