eZ Publish  [4.0]
ezkerneloperator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZKernelOperator class
00004 //
00005 // Created on: <11-Aug-2003 14:04:59 bf>
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 ezkerneloperator.php
00032 */
00033 
00034 /*!
00035   \class eZKerneloperator ezkerneloperator.php
00036   \brief The class eZKernelOperator does handles eZ Publish preferences
00037 
00038 */
00039 class eZKernelOperator
00040 {
00041     /*!
00042      Initializes the object with the name $name
00043     */
00044     function eZKernelOperator( $name = "ezpreference" )
00045     {
00046         $this->Operators = array( $name );
00047     }
00048 
00049     /*!
00050       Returns the template operators.
00051     */
00052     function operatorList()
00053     {
00054         return $this->Operators;
00055     }
00056 
00057     /*!
00058      \return true to tell the template engine that the parameter list exists per operator type.
00059     */
00060     function namedParameterPerOperator()
00061     {
00062         return true;
00063     }
00064 
00065     /*!
00066      See eZTemplateOperator::namedParameterList()
00067     */
00068     function namedParameterList()
00069     {
00070         return array( 'ezpreference' => array( 'name' => array( 'type' => 'string',
00071                                                                 'required' => true,
00072                                                                 'default' => false ) ) );
00073     }
00074 
00075     function operatorTemplateHints()
00076     {
00077         return array( 'ezpreference' => array( 'input' => false,
00078                                                'output' => true,
00079                                                'parameters' => 1,
00080                                                'element-transformation' => true,
00081                                                'transform-parameters' => true,
00082                                                'input-as-parameter' => false,
00083                                                'element-transformation-func' => 'preferencesTransformation') );
00084     }
00085 
00086     function preferencesTransformation( $operatorName, &$node, $tpl, &$resourceData,
00087                                         $element, $lastElement, $elementList, $elementTree, &$parameters )
00088     {
00089         if ( count( $parameters[0] ) == 0 )
00090             return false;
00091         $values = array();
00092         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00093         {
00094             $name = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00095             $nameText = eZPHPCreator::variableText( $name, 0, 0, false );
00096         }
00097         else
00098         {
00099             $nameText = '%1%';
00100             $values[] = $parameters[0];
00101         }
00102         return array( eZTemplateNodeTool::createCodePieceElement( "//include_once( 'kernel/classes/ezpreferences.php' );\n" .
00103                                                                   "%output% = eZPreferences::value( $nameText );\n",
00104                                                                   $values ) );
00105     }
00106 
00107     function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters )
00108     {
00109         switch ( $operatorName )
00110         {
00111             case 'ezpreference':
00112             {
00113                 //include_once( 'kernel/classes/ezpreferences.php' );
00114                 $name = $namedParameters['name'];
00115                 $value = eZPreferences::value( $name );
00116                 $operatorValue = $value;
00117             }break;
00118 
00119             default:
00120             {
00121                 eZDebug::writeError( "Unknown kernel operator: $operatorName" );
00122             }break;
00123         }
00124     }
00125     public $Operators;
00126 }
00127 ?>