eZ Publish  [4.0]
eztemplatemenufunction.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTemplateMenuFunction class
00004 //
00005 // Created on: <10-Mar-2004 15:34:50 wy>
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 eztemplatemenufunction.php
00032 */
00033 
00034 /*!
00035   \class eZTemplateMenuFunction eztemplatemenufunction.php
00036   \brief The class eZTemplateMenuFunction does
00037 
00038 */
00039 
00040 class eZTemplateMenuFunction
00041 {
00042     /*!
00043      Initializes the object with names.
00044     */
00045     function eZTemplateMenuFunction( $blockName = 'menu' )
00046     {
00047         $this->BlockName = $blockName;
00048     }
00049 
00050     /*!
00051      Returns an array containing the name of the block function, default is "block".
00052      The name is specified in the constructor.
00053     */
00054     function functionList()
00055     {
00056         return array( $this->BlockName );
00057     }
00058 
00059     function functionTemplateHints()
00060     {
00061         return array( $this->BlockName => array( 'parameters' => true,
00062                                                  'static' => false,
00063                                                  'transform-children' => false,
00064                                                  'tree-transformation' => true,
00065                                                  'transform-parameters' => true ) );
00066     }
00067 
00068     function templateNodeTransformation( $functionName, &$node,
00069                                          $tpl, $parameters, $privateData )
00070     {
00071         if ( $functionName != $this->BlockName )
00072             return false;
00073 
00074         $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
00075 
00076         if ( !isset( $parameters['name'] ) )
00077             return false;
00078 
00079         $namespaceValue = false;
00080         $newNodes = array();
00081         if ( isset( $parameters["name"] ) )
00082         {
00083             $menuIni = eZINI::instance( "menu.ini" );
00084             $nameData = $parameters["name"];
00085             if ( !eZTemplateNodeTool::isStaticElement( $nameData ) )
00086                 return false;
00087 
00088             $menuName = eZTemplateNodeTool::elementStaticValue( $nameData );
00089 
00090             if ( $menuIni->hasVariable( 'SelectedMenu', $menuName ) )
00091             {
00092                 $menuTemplate = $menuIni->variable( "SelectedMenu", $menuName );
00093 
00094                 if ( $menuTemplate != null )
00095                 {
00096                     $uriString = "design:menu/$menuTemplate.tpl";
00097                     $resourceName = "";
00098                     $templateName = "";
00099                     $resource = $tpl->resourceFor( $uriString, $resourceName, $templateName );
00100                     $resourceData = $tpl->resourceData( $resource, $uriString, $resourceName, $templateName );
00101                     $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
00102 
00103                     $includeNodes = $resource->templateNodeTransformation( $functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue );
00104                     if ( $includeNodes === false )
00105                         return false;
00106 
00107                     $variableList = array();
00108                     foreach ( array_keys( $parameters ) as $parameterName )
00109                     {
00110                         if ( $parameterName == 'name' )
00111                             continue;
00112                         $parameterData =& $parameters[$parameterName];
00113                         $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameterData, false, array(),
00114                                                                               array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName ) );
00115                         $variableList[] = $parameterName;
00116                     }
00117 
00118                     $newNodes = array_merge( $newNodes, $includeNodes );
00119 
00120                     foreach ( $variableList as $variableName )
00121                     {
00122                         $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName ) );
00123                     }
00124                 }
00125                 else
00126                 {
00127                     // to do: not use this function to generate empty code.
00128                     $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "" );
00129                 }
00130             }
00131             else
00132             {
00133                 // to do: not use this function to generate empty code.
00134                 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "" );
00135             }
00136         }
00137         return $newNodes;
00138     }
00139 
00140     /*!
00141      Processes the function with all it's children.
00142     */
00143     function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
00144     {
00145         $params = $functionParameters;
00146         switch ( $functionName )
00147         {
00148             case $this->BlockName:
00149             {
00150                 $name ="";
00151                 $menuIni = eZINI::instance( "menu.ini" );
00152 
00153                 if ( isset( $functionParameters["name"] ) )
00154                 {
00155                     $menuName = $tpl->elementValue( $functionParameters["name"], $rootNamespace, $currentNamespace, $functionPlacement );
00156                     if ( $menuIni->hasVariable( 'SelectedMenu', $menuName ) )
00157                     {
00158                         $menuTemplate = $menuIni->variable( 'SelectedMenu', $menuName );
00159                         if ( $menuTemplate != null )
00160                         {
00161                             $uri = "design:menu/$menuTemplate.tpl";
00162                             $tpl->processURI( $uri, true, $extraParameters, $textElements, $name, $name );
00163                         }
00164                     }
00165                 }
00166             }
00167         }
00168     }
00169 
00170     /*!
00171      Returns false.
00172     */
00173     function hasChildren()
00174     {
00175         return false;
00176     }
00177 }
00178 
00179 ?>