eZ Publish  [4.0]
eztemplatedelimitfunction.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTemplateDelimitFunction class
00004 //
00005 // Created on: <01-Mar-2002 13:49:07 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 /*!
00032   \class eZTemplateDelimitFunction eztemplatedelimitfunction.php
00033   \ingroup eZTemplateFunctions
00034   \brief Displays left and right delimiter in templates
00035 
00036   This class iss a template function for outputting the left and right delimiters.
00037   Since the left and right delimiters are always parsed by the template engine
00038   it's not possible to output these characters. By registering an instance of this
00039   class as template functions you can get these characters with {ldelim} and {rdelim}.
00040 
00041   The name of these functions can also be controlled by passing the names to the
00042   constructor.
00043 
00044   Example:
00045 \code
00046 $tpl->registerFunctions( new eZTemplateDelimitFunction() );
00047 // or custom names
00048 $tpl->registerFunctions( new eZTemplateDelimitFunction( "l", "r" ) );
00049 // alternatively
00050 $obj = new eZTemplateDelimitFunction();
00051 $tpl->registerFunction( "ldelim", $obj );
00052 $tpl->registerFunction( "rdelim", $obj );
00053 \endcode
00054 */
00055 
00056 class eZTemplateDelimitFunction
00057 {
00058     /*!
00059      Initializes the object with a name for the left and right delimiter.
00060      Default is ldelim for left and rdelim for right.
00061     */
00062     function eZTemplateDelimitFunction()
00063     {
00064         $this->LName = 'ldelim';
00065         $this->RName = 'rdelim';
00066     }
00067 
00068     /*!
00069      Returns an array of the function names, required for eZTemplate::registerFunctions.
00070     */
00071     function functionList()
00072     {
00073         return array( $this->LName, $this->RName );
00074     }
00075 
00076     /*!
00077      Returns an array with hints for the template compiler.
00078     */
00079     function functionTemplateHints()
00080     {
00081         return array(
00082             $this->LName => array( 'parameters' => false, 'static' => false, 'tree-transformation' => true ),
00083             $this->RName => array( 'parameters' => false, 'static' => false, 'tree-transformation' => true )
00084         );
00085     }
00086 
00087     function templateNodeTransformation( $functionName, &$node,
00088                                          $tpl, $parameters, $privateData )
00089     {
00090         $newNodes = array();
00091 
00092         if ( $functionName == $this->LName )
00093         {
00094             $newNodes = array ( eZTemplateNodeTool::createTextNode( $tpl->leftDelimiter() ) );
00095         }
00096         else
00097         {
00098             $newNodes = array ( eZTemplateNodeTool::createTextNode( $tpl->rightDelimiter() ) );
00099         }
00100         return $newNodes;
00101     }
00102 
00103     /*!
00104      Outputs the left or right delimiter if the function names match.
00105     */
00106     function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $nspace, $current_nspace )
00107     {
00108         switch ( $functionName )
00109         {
00110             case $this->LName:
00111             {
00112                 $textElements[] = $tpl->leftDelimiter();
00113             } break;
00114             case $this->RName:
00115             {
00116                 $textElements[] = $tpl->rightDelimiter();
00117             } break;
00118         }
00119     }
00120 
00121     /*!
00122      Returns false, telling the template parser that this is a single tag.
00123     */
00124     function hasChildren()
00125     {
00126         return false;
00127     }
00128 
00129     /// The name of the left delimiter tag
00130     public $LName;
00131     /// The name of the right delimiter tag
00132     public $RName;
00133 }
00134 
00135 ?>