eZ Publish  [4.0]
ezurloperator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZURLOperator class
00004 //
00005 // Created on: <18-Apr-2002 12:15: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 /*!
00033  \class eZURLOperator ezurloperator.php
00034  \brief Collection of url modifying operators
00035 
00036 */
00037 
00038 class eZURLOperator
00039 {
00040     const HTTP_OPERATOR_TYPE_POST = 1;
00041     const HTTP_OPERATOR_TYPE_GET = 2;
00042     const HTTP_OPERATOR_TYPE_SESSION = 3;
00043 
00044     /*!
00045      Initializes the image operator with the operator name $name.
00046     */
00047     function eZURLOperator( $url_name = 'ezurl',
00048                             $urlroot_name = 'ezroot',
00049                             $ezsys_name = 'ezsys',
00050                             $design_name = 'ezdesign',
00051                             $image_name = 'ezimage',
00052                             $ext_name = 'exturl',
00053                             $httpName = 'ezhttp',
00054                             $iniName = 'ezini',
00055                             $iniNameHasVariable = 'ezini_hasvariable',
00056                             $httpNameHasVariable = 'ezhttp_hasvariable' )
00057     {
00058         $this->Operators = array( $url_name, $urlroot_name, $ezsys_name, $design_name, $image_name, $ext_name, $httpName, $iniName, $iniNameHasVariable, $httpNameHasVariable );
00059         $this->URLName = $url_name;
00060         $this->URLRootName = $urlroot_name;
00061         $this->SysName = $ezsys_name;
00062         $this->DesignName = $design_name;
00063         $this->ImageName = $image_name;
00064         $this->ExtName = $ext_name;
00065         $this->HTTPName = $httpName;
00066         $this->ININame = $iniName;
00067         $this->ININameHasVariable = $iniNameHasVariable;
00068         $this->HTTPNameHasVariable = $httpNameHasVariable;
00069         $this->Sys = eZSys::instance();
00070     }
00071 
00072     function operatorTemplateHints()
00073     {
00074         return array( $this->URLName => array( 'input' => true,
00075                                                'output' => true,
00076                                                'parameters' => true,
00077                                                'element-transformation' => true,
00078                                                'transform-parameters' => true,
00079                                                'input-as-parameter' => 'always',
00080                                                'element-transformation-func' => 'urlTransformation'),
00081                       $this->URLRootName => array( 'input' => true,
00082                                                    'output' => true,
00083                                                    'parameters' => true,
00084                                                    'element-transformation' => true,
00085                                                    'transform-parameters' => true,
00086                                                    'input-as-parameter' => 'always',
00087                                                    'element-transformation-func' => 'urlTransformation'),
00088                       $this->SysName => array( 'input' => true,
00089                                                'output' => true,
00090                                                'parameters' => true,
00091                                                'element-transformation' => true,
00092                                                'transform-parameters' => true,
00093                                                'input-as-parameter' => 'always',
00094                                                'element-transformation-func' => 'urlTransformation'),
00095                       $this->DesignName => array( 'input' => true,
00096                                                   'output' => true,
00097                                                   'parameters' => true,
00098                                                   'element-transformation' => true,
00099                                                   'transform-parameters' => true,
00100                                                   'input-as-parameter' => 'always',
00101                                                   'element-transformation-func' => 'urlTransformation'),
00102                       $this->ImageName => array( 'input' => true,
00103                                                  'output' => true,
00104                                                  'parameters' => true,
00105                                                  'element-transformation' => true,
00106                                                  'transform-parameters' => true,
00107                                                  'input-as-parameter' => 'always',
00108                                                  'element-transformation-func' => 'urlTransformation'),
00109                       $this->ExtName => array( 'input' => true,
00110                                                'output' => true,
00111                                                'parameters' => true,
00112                                                'element-transformation' => true,
00113                                                'transform-parameters' => true,
00114                                                'input-as-parameter' => 'always',
00115                                                'element-transformation-func' => 'urlTransformation'),
00116                       $this->ININame => array( 'input' => true,
00117                                                'output' => true,
00118                                                'parameters' => true,
00119                                                'element-transformation' => true,
00120                                                'transform-parameters' => true,
00121                                                'input-as-parameter' => true,
00122                                                'element-transformation-func' => 'iniTrans'),
00123                       $this->ININameHasVariable => array( 'input' => true,
00124                                                           'output' => true,
00125                                                           'parameters' => true,
00126                                                           'element-transformation' => true,
00127                                                           'transform-parameters' => true,
00128                                                           'input-as-parameter' => true,
00129                                                           'element-transformation-func' => 'iniTrans' )
00130                       );
00131     }
00132 
00133     function iniTrans( $operatorName, &$node, $tpl, &$resourceData,
00134                        $element, $lastElement, $elementList, $elementTree, &$parameters )
00135     {
00136         if ( count ( $parameters ) < 2 )
00137             return false;
00138 
00139         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) &&
00140              eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00141         {
00142             $iniGroup = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00143             $iniVariable = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00144 
00145             $iniName = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : false;
00146             $iniPath = isset( $parameters[3] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[3] ) : false;
00147 
00148             // If we should check for existence of variable.
00149             // You can use like:
00150             //     ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, <Dynamic fetch: if 'true()' value of variable will be fetched dynamically>
00151             //                                                               <Should We Check for existence only: 'hasVariable' or true()> )
00152             //     ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
00153             if ( $operatorName == $this->ININameHasVariable )
00154             {
00155                 $checkExistence = true;
00156             }
00157             else
00158             {
00159                 $checkExistence = isset( $parameters[5] )
00160                                   ? ( eZTemplateNodeTool::elementStaticValue( $parameters[5] ) === true or
00161                                       eZTemplateNodeTool::elementStaticValue( $parameters[5] ) == 'hasVariable' ) ? true : false
00162                                   : false;
00163             }
00164 
00165             if ( count( $parameters ) > 4 )
00166             {
00167                 $inCache = eZTemplateNodeTool::elementStaticValue( $parameters[4] );
00168                 // Check if we should put implementaion of parsing ini variable to compiled php file
00169                 if ( $inCache === true )
00170                 {
00171                     $values = array();
00172                     $values[] = $parameters[0];
00173                     $values[] = $parameters[1];
00174 
00175                     $code = "//include_once( 'lib/ezutils/classes/ezini.php' );\n";
00176 
00177                     if ( $iniPath !== false )
00178                     {
00179                         $values[] = $parameters[2];
00180                         $values[] = $parameters[3];
00181                         $code .= '%tmp1% = eZINI::instance( %3%, %4%, null, null, null, true );' . "\n";
00182                     }
00183                     elseif ( $iniName !== false )
00184                     {
00185                         $values[] = $parameters[2];
00186                         $code .= '%tmp1% = eZINI::instance( %3% );' . "\n";
00187                     }
00188                     else
00189                         $code .= '%tmp1% = eZINI::instance();' . "\n";
00190 
00191                     $checkExist = $checkExistence ? 'true' : 'false';
00192 
00193                     $code .= 'if ( %tmp1%->hasVariable( %1%, %2% ) )' . "\n" .
00194                         '    %output% = ' . "!$checkExist" . ' ? %tmp1%->variable( %1%, %2% ) : true;' . "\n" .
00195                         "else\n" .
00196                         "    %output% = $checkExist ? false : '';\n";
00197 
00198 
00199                     return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) );
00200                 }
00201             }
00202             //include_once( 'lib/ezutils/classes/ezini.php' );
00203 
00204             if ( $iniPath !== false )
00205                 $ini = eZINI::instance( $iniName, $iniPath, null, null, null, true );
00206             elseif ( $iniName !== false )
00207                 $ini = eZINI::instance( $iniName );
00208             else
00209                 $ini = eZINI::instance();
00210 
00211             $value = '';
00212             if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
00213             {
00214                 $value = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
00215             }
00216             else
00217             {
00218                 // If we should check for existence then we return only FALSE
00219                 if ( $checkExistence )
00220                 {
00221                     $value = false;
00222                 }
00223                 else
00224                 {
00225                     if ( $iniName === false )
00226                         $iniName = 'site.ini';
00227                     $tpl->error( $operatorName, "No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
00228                 }
00229             }
00230             return array( eZTemplateNodeTool::createStringElement( $value ) );
00231         }
00232         else
00233             return false;
00234     }
00235 
00236     function urlTransformation( $operatorName, &$node, $tpl, &$resourceData,
00237                                 $element, $lastElement, $elementList, $elementTree, &$parameters )
00238     {
00239         $newElements = array();
00240         $values = array();
00241         $paramCount = 0;
00242         $tmpCount = 0;
00243         switch( $operatorName )
00244         {
00245             case $this->URLName:
00246             {
00247                 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00248                 {
00249                     $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00250 
00251                     $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
00252 
00253                     //include_once( 'lib/ezutils/classes/ezuri.php' );
00254                     eZURI::transformURI( $url, false, $serverURL );
00255 
00256                     $url = $this->applyQuotes( $url, $parameters[1] );
00257                     return array( eZTemplateNodeTool::createStringElement( $url ) );
00258                 }
00259                 $values[] = $parameters[0];
00260                 $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
00261                 $code = <<<CODEPIECE
00262 
00263 //include_once( 'lib/ezutils/classes/ezuri.php' );
00264 eZURI::transformURI( %1%, false, %2% );
00265 
00266 CODEPIECE;
00267 
00268                 ++$paramCount;
00269             } break;
00270 
00271             case $this->URLRootName:
00272             {
00273                 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00274                 {
00275                     $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00276 
00277                     if ( preg_match( "#^[a-zA-Z0-9]+:#", $url ) or
00278                          substr( $url, 0, 2 ) == '//' )
00279                         $url = '/';
00280                     else if ( strlen( $url ) > 0 and
00281                               $url[0] != '/' )
00282                         $url = '/' . $url;
00283 
00284                     $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
00285 
00286                     // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
00287                     //include_once( 'lib/ezutils/classes/ezuri.php' );
00288                     eZURI::transformURI( $url, true, $serverURL );
00289 
00290                     $url = $this->applyQuotes( $url, $parameters[1] );
00291                     return array( eZTemplateNodeTool::createStringElement( $url ) );
00292                 }
00293                 else
00294                 {
00295                     $code ='if ( preg_match( "#^[a-zA-Z0-9]+:#", %1% ) or' . "\n" .
00296                          'substr( %1%, 0, 2 ) == \'//\' )' . "\n" .
00297                          '  %1% = \'/\';' . "\n" .
00298                          'else if ( strlen( %1% ) > 0 and' . "\n" .
00299                          '  %1%[0] != \'/\' )' . "\n" .
00300                          '%1% = \'/\' . %1%;' . "\n";
00301                     $values[] = $parameters[0];
00302                 }
00303                 $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
00304                 $code .= '//include_once( \'lib/ezutils/classes/ezuri.php\' );' . "\n" .
00305                          'eZURI::transformURI( %1%, true, %2% );' . "\n";
00306 
00307                 ++$paramCount;
00308                 ++$tmpCount;
00309             } break;
00310 
00311             case $this->SysName:
00312             {
00313                 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00314                 {
00315                     $sysAttribute = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00316 
00317                     return array( eZTemplateNodeTool::createStringElement( $this->Sys->attribute( $sysAttribute ) ) );
00318                 }
00319                 return false;
00320             } break;
00321 
00322             case $this->DesignName:
00323             {
00324                 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00325                 {
00326                     $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00327 
00328                     $path = $this->eZDesign( $tpl, $path, $operatorName );
00329                     $path = $this->applyQuotes( $path, $parameters[1] );
00330 
00331                     return array( eZTemplateNodeTool::createStringElement( $path ) );
00332                 }
00333 
00334                 $code = ( '%1% = eZURLOperator::eZDesign( $tpl, %1%, "' . $operatorName . '" );' . "\n" );
00335 
00336                 $values[] = $parameters[0];
00337                 ++$paramCount;
00338             } break;
00339 
00340             case $this->ImageName:
00341             {
00342                 $skipSlash = count( $parameters ) > 2 ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) == true : false;
00343 
00344                 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00345                 {
00346                     $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00347 
00348                     $path = eZURLOperator::eZImage( $tpl, $path, $operatorName, $skipSlash );
00349                     $path = $this->applyQuotes( $path, $parameters[1] );
00350 
00351                     return array( eZTemplateNodeTool::createStringElement( $path ) );
00352                 }
00353 
00354                 $code = ( '%1% = eZURLOperator::eZImage( $tpl, %1%, "' . $operatorName . '", %2% );' . "\n" );
00355 
00356                 $values[] = $parameters[0];
00357                 $values[] = array( eZTemplateNodeTool::createBooleanElement( $skipSlash ) );
00358 
00359                 ++$paramCount;
00360             } break;
00361 
00362             case $this->ExtName:
00363             {
00364                 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00365                 {
00366                     $origUrl = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00367 
00368                     //include_once( 'kernel/classes/datatypes/ezurl/ezurl.php' );
00369                     $url = eZURL::urlByMD5( md5( $origUrl ) );
00370                     if ( $url == false )
00371                         eZURL::registerURL( $origUrl );
00372                     else
00373                         $origUrl = $url;
00374 
00375                     $origUrl = $this->applyQuotes( $origUrl, $parameters[1] );
00376 
00377                     return array( eZTemplateNodeTool::createStringElement( $origUrl ) );
00378                 }
00379 
00380                 $code .= '//include_once( \'kernel/classes/datatypes/ezurl/ezurl.php\' );' . "\n" .
00381                      '%tmp1% = eZURL::urlByMD5( md5( %1% ) );' . "\n" .
00382                      'if ( %tmp1% == false )' . "\n" .
00383                      '  eZURL::registerURL( %1% );' . "\n" .
00384                      'else' . "\n" .
00385                      '  %1% = %tmp1%;' . "\n";
00386                 $values[] = $parameters[0];
00387                 ++$tmpCount;
00388                 ++$paramCount;
00389             } break;
00390 
00391         }
00392 
00393         //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00394         $http = eZHTTPTool::instance();
00395 
00396         if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
00397         {
00398             ++$tmpCount;
00399             $code .= '//include_once( \'lib/ezutils/classes/ezhttptool.php\' );' . "\n" .
00400                  '%tmp' . $tmpCount . '% = eZHTTPTool::instance();' . "\n" .
00401                  'if ( isset( %tmp' . $tmpCount . '%->UseFullUrl ) and %tmp' . $tmpCount . '%->UseFullUrl ' . "\n" .
00402                  '                                                 and strncasecmp( %1%, \'/\' , 1 ) === 0 ) // do not prepend the site path if it\'s not a http url%'. "\n" .
00403                  '{' . "\n" .
00404                  ' %1% = %tmp' . $tmpCount . '%->createRedirectUrl( %1%, array( \'pre_url\' => false ) );' . "\n" .
00405                  '}' . "\n";
00406         }
00407 
00408         if ( count( $parameters ) > $paramCount )
00409         {
00410             if ( eZTemplateNodeTool::isStaticElement( $parameters[$paramCount] ) )
00411             {
00412                 $quote = '"';
00413                 $val = eZTemplateNodeTool::elementStaticValue( $parameters[$paramCount] );
00414                 ++$paramCount;
00415 
00416                 if ( $val == 'single' )
00417                     $quote = "'";
00418                 else if ( $val == 'no' )
00419                     $quote = false;
00420                 if ( $quote !== false )
00421                 {
00422                     $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
00423                     $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
00424                 }
00425             }
00426             else
00427             {
00428                 $values[] = $parameters[$paramCount];
00429                 $code .= 'switch (%' . count( $values ) . '%)'          . "\n" .
00430                          '{'                                            . "\n" .
00431                          '    case \'single\':'                         . "\n" .
00432                          '         %1% = \'\\\'\' . %1% . \'\\\'\' ;'   . "\n" .
00433                          '         break;'                              . "\n" .
00434                          '    case \'no\':'                             . "\n" .
00435                          '         break;'                              . "\n" .
00436                          '     default:'                                . "\n" .
00437                          '         %1% = \'"\' . %1% . \'"\' ;'         . "\n" .
00438                          '}'  . "\n";
00439             }
00440         }
00441         else
00442         {
00443             $quote = '"';
00444             $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
00445             $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
00446         }
00447 
00448         $code .= '%output% = %1%;' . "\n";
00449 
00450         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount );
00451 
00452         return $newElements;
00453     }
00454 
00455     /*!
00456      Apply quotes to static text
00457 
00458      \param static text
00459      \param quote parameter
00460      \param if set to true, return only quote value
00461 
00462      \return text with quotes
00463     */
00464     function applyQuotes( $text, &$parameter, $onlyQuote = false )
00465     {
00466         $quote = "\"";
00467         if ( $parameter != null )
00468         {
00469             $val = eZTemplateNodeTool::elementStaticValue( $parameter );
00470             if ( $val == 'single' )
00471                 $quote = "'";
00472             else if ( $val == 'no' )
00473                 $quote = false;
00474         }
00475 
00476         if ( $onlyQuote )
00477         {
00478             return $quote;
00479         }
00480 
00481         //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00482         $http = eZHTTPTool::instance();
00483 
00484         if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
00485                                         and strncasecmp( $text, '/' , 1 ) === 0 ) // do not prepend the site path if it's not a http url
00486         {
00487             $text = $http->createRedirectUrl( $text, array( 'pre_url' => false ) );
00488         }
00489         if ( $quote !== false )
00490             return $quote . $text . $quote;
00491 
00492         return $text;
00493     }
00494 
00495     /*!
00496      Returns the operators in this class.
00497     */
00498     function operatorList()
00499     {
00500         return $this->Operators;
00501     }
00502 
00503     function namedParameterList()
00504     {
00505         return array( 'quote_val' => array( 'type' => 'string',
00506                                             'required' => false,
00507                                             'default' => 'double' ),
00508                       'server_url' => array( 'type' => 'string',
00509                                              'required' => false,
00510                                              'default' => 'relative' ) );
00511     }
00512 
00513     /*!
00514      */
00515     function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters )
00516     {
00517         switch ( $operatorName )
00518         {
00519             case $this->ININameHasVariable:
00520             case $this->ININame:
00521             {
00522                 if ( count( $operatorParameters ) > 0 )
00523                 {
00524                     $iniGroup = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00525                     if ( count( $operatorParameters ) == 1 )
00526                     {
00527                         $tpl->error( $operatorName, "Missing variable name parameter" );
00528                         return;
00529                     }
00530                     $iniVariable = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
00531                     $iniName = isset( $operatorParameters[2] ) ? $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) : false;
00532                     $iniPath = isset( $operatorParameters[3] ) ? $tpl->elementValue( $operatorParameters[3], $rootNamespace, $currentNamespace ) : false;
00533 
00534                     // If we should check for existence of variable.
00535                     // You can use like:
00536                     //     ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, _use under template compiling mode_ , <Should We Check for existence: 'hasVariable' or true()> )
00537                     //     ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
00538                     if ( $operatorName == $this->ININameHasVariable )
00539                     {
00540                         $checkExistence = true;
00541                     }
00542                     else
00543                     {
00544                         $checkExistence = isset( $operatorParameters[5] )
00545                                           ? ( $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) === true or
00546                                               $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
00547                                           : false;
00548                     }
00549                     //include_once( 'lib/ezutils/classes/ezini.php' );
00550 
00551                     if ( $iniPath !== false )
00552                         $ini = eZINI::instance( $iniName, $iniPath, null, null, null, true );
00553                     elseif ( $iniName !== false )
00554                         $ini = eZINI::instance( $iniName );
00555                     else
00556                         $ini = eZINI::instance();
00557 
00558                     if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
00559                     {
00560                         $operatorValue = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
00561                     }
00562                     else
00563                     {
00564                         if ( $checkExistence )
00565                         {
00566                             $operatorValue = false;
00567                             return;
00568                         }
00569                         if ( $iniPath !== false )
00570                         {
00571                             // Return empty string instead of displaying error when using 'path' parameter
00572                             // and DirectAccess mode for ezini.
00573                             $operatorValue = '';
00574                         }
00575                         else
00576                         {
00577                             if ( $iniName === false )
00578                                 $iniName = 'site.ini';
00579                             $tpl->error( $operatorName, "!!!No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
00580                         }
00581                     }
00582                     return;
00583                 }
00584                 else
00585                     $tpl->error( $operatorName, "Missing group name parameter" );
00586             } break;
00587 
00588             case $this->HTTPNameHasVariable:
00589             case $this->HTTPName:
00590             {
00591                 //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00592                 $http = eZHTTPTool::instance();
00593                 if ( count( $operatorParameters ) > 0 )
00594                 {
00595                     $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_POST;
00596                     $httpName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00597                     if ( count( $operatorParameters ) > 1 )
00598                     {
00599                         $httpTypeName = strtolower( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) );
00600                         if ( $httpTypeName == 'post' )
00601                             $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_POST;
00602                         else if ( $httpTypeName == 'get' )
00603                             $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_GET;
00604                         else if ( $httpTypeName == 'session' )
00605                             $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_SESSION;
00606                         else
00607                             $tpl->warning( $operatorName, "Unknown http type '$httpTypeName'" );
00608                     }
00609 
00610                     // If we should check for existence of http variable
00611                     // You can use like:
00612                     //     ezhttp( <Variable>, <Method: post, get, session>, <Should We Check for existence: 'hasVariable' or true()> )
00613                     //     ezhttp_hasvariable( <Variable>, <Method> )
00614                     if ( $operatorName == $this->HTTPNameHasVariable )
00615                     {
00616                         $checkExistence = true;
00617                     }
00618                     else
00619                     {
00620                         $checkExistence = isset( $operatorParameters[2] )
00621                                           ? ( $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) === true or
00622                                               $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
00623                                           : false;
00624                     }
00625                     switch( $httpType )
00626                     {
00627                         case eZURLOperator::HTTP_OPERATOR_TYPE_POST:
00628                         {
00629                             if ( $http->hasPostVariable( $httpName ) )
00630                                 $operatorValue = !$checkExistence ? $http->postVariable( $httpName ) : true;
00631                             else
00632                             {
00633                                 // If only check for existence - return false
00634                                 if ( $checkExistence )
00635                                 {
00636                                     $operatorValue = false;
00637                                     return;
00638                                 }
00639                                 $tpl->error( $operatorName, "Unknown post variable '$httpName'" );
00640                             }
00641                         } break;
00642                         case eZURLOperator::HTTP_OPERATOR_TYPE_GET:
00643                         {
00644                             if ( $http->hasGetVariable( $httpName ) )
00645                                 $operatorValue = !$checkExistence ? $http->getVariable( $httpName ) : true;
00646                             else
00647                             {
00648                                 if ( $checkExistence )
00649                                 {
00650                                     $operatorValue = false;
00651                                     return;
00652                                 }
00653                                 $tpl->error( $operatorName, "Unknown get variable '$httpName'" );
00654                             }
00655                         } break;
00656                         case eZURLOperator::HTTP_OPERATOR_TYPE_SESSION:
00657                         {
00658                             if ( $http->hasSessionVariable( $httpName ) )
00659                                 $operatorValue = !$checkExistence ? $http->sessionVariable( $httpName ) : true;
00660                             else
00661                             {
00662                                 if ( $checkExistence )
00663                                 {
00664                                     $operatorValue = false;
00665                                     return;
00666                                 }
00667                                 $tpl->error( $operatorName, "Unknown session variable '$httpName'" );
00668                             }
00669                         } break;
00670                     }
00671                 }
00672                 else
00673                 {
00674                     $operatorValue = $http;
00675                 }
00676                 return;
00677             } break;
00678 
00679             case $this->URLName:
00680             {
00681                 //include_once( 'lib/ezutils/classes/ezuri.php' );
00682                 eZURI::transformURI( $operatorValue, false, $namedParameters['server_url'] );
00683 
00684             } break;
00685 
00686             case $this->URLRootName:
00687             {
00688                 if ( preg_match( "#^[a-zA-Z0-9]+:#", $operatorValue ) or
00689                      substr( $operatorValue, 0, 2 ) == '//' )
00690                      break;
00691                 if ( strlen( $operatorValue ) > 0 and
00692                      $operatorValue[0] != '/' )
00693                     $operatorValue = '/' . $operatorValue;
00694 
00695                 // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
00696                 //include_once( 'lib/ezutils/classes/ezuri.php' );
00697                 eZURI::transformURI( $operatorValue, true, $namedParameters['server_url'] );
00698 
00699             } break;
00700 
00701             case $this->SysName:
00702             {
00703                 if ( count( $operatorParameters ) == 0 )
00704                     $tpl->warning( 'eZURLOperator' . $operatorName, 'Requires attributename' );
00705                 else
00706                 {
00707                     $sysAttribute = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00708                     if ( !$this->Sys->hasAttribute( $sysAttribute ) )
00709                         $tpl->warning( 'eZURLOperator' . $operatorName, "No such attribute '$sysAttribute' for eZSys" );
00710                     else
00711                         $operatorValue = $this->Sys->attribute( $sysAttribute );
00712                 }
00713                 return;
00714             } break;
00715 
00716             case $this->ImageName:
00717             {
00718                 if ( count( $operatorParameters ) == 2 &&
00719                      $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) == true &&
00720                      strlen( $this->Sys->wwwDir() ) == 0 )
00721                 {
00722                     $skipSlash = true;
00723                 }
00724                 else
00725                 {
00726                     $skipSlash = false;
00727                 }
00728 
00729                 $operatorValue = $this->eZImage( $tpl, $operatorValue, $operatorName, $skipSlash );
00730             } break;
00731 
00732             case $this->ExtName:
00733             {
00734                 //include_once( 'kernel/classes/datatypes/ezurl/ezurl.php' );
00735                 $urlMD5 = md5( $operatorValue );
00736                 $url = eZURL::urlByMD5( $urlMD5 );
00737                 if ( $url === false )
00738                     eZURL::registerURL( $operatorValue );
00739                 else
00740                     $operatorValue = $url;
00741             } break;
00742 
00743             case $this->DesignName:
00744             {
00745                 $operatorValue = $this->eZDesign( $tpl, $operatorValue, $operatorName );
00746             } break;
00747         }
00748         $quote = "\"";
00749         $val = $namedParameters['quote_val'];
00750         if ( $val == 'single' )
00751             $quote = "'";
00752         else if ( $val == 'no' )
00753             $quote = false;
00754 
00755         //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00756         $http = eZHTTPTool::instance();
00757 
00758         if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
00759                                         and strncasecmp( $operatorValue, '/' , 1 ) === 0 ) // do not prepend the site path if it's not a http url
00760         {
00761             $operatorValue = $http->createRedirectUrl( $operatorValue, array( 'pre_url' => false ) );
00762         }
00763         if ( $quote !== false )
00764             $operatorValue = $quote . $operatorValue . $quote;
00765     }
00766 
00767     /*!
00768 
00769     */
00770     static function eZDesign( $tpl, $operatorValue, $operatorName )
00771     {
00772         $sys = eZSys::instance();
00773 
00774         $bases = eZTemplateDesignResource::allDesignBases();
00775         $triedFiles = array();
00776         $fileInfo = eZTemplateDesignResource::fileMatch( $bases, false, $operatorValue, $triedFiles);
00777 
00778         if ( !$fileInfo )
00779         {
00780             $tpl->warning( $operatorName, "Design element $operatorValue does not exist in any design" );
00781             $tpl->warning( $operatorName, "Tried files: " . implode( ', ', $triedFiles ) );
00782             $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00783             $filePath = "design/$siteDesign/$operatorValue";
00784         }
00785         else
00786         {
00787             $filePath = $fileInfo['path'];
00788         }
00789 
00790         $operatorValue = $sys->wwwDir() . '/' . $filePath;
00791         $operatorValue = htmlspecialchars( $operatorValue );
00792 
00793         return $operatorValue;
00794     }
00795 
00796     /*!
00797 
00798     */
00799     static function eZImage( $tpl, $operatorValue, $operatorName, $skipSlash = false )
00800     {
00801         $sys = eZSys::instance();
00802         if ( $skipSlash && strlen( $sys->wwwDir() ) != 0 )
00803         {
00804             $skipSlash = false;
00805         }
00806 
00807         $bases = eZTemplateDesignResource::allDesignBases();
00808         $triedFiles = array();
00809         $fileInfo = eZTemplateDesignResource::fileMatch( $bases, 'images', $operatorValue, $triedFiles );
00810 
00811         if ( !$fileInfo )
00812         {
00813             $tpl->warning( $operatorName, "Image '$operatorValue' does not exist in any design" );
00814             $tpl->warning( $operatorName, "Tried files: " . implode( ', ', $triedFiles ) );
00815             $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00816             $imgPath = "design/$siteDesign/images/$operatorValue";
00817         }
00818         else
00819         {
00820             $imgPath = $fileInfo['path'];
00821         }
00822 
00823         $operatorValue = $skipSlash ? $imgPath : $sys->wwwDir() . '/' . $imgPath;
00824         $operatorValue = htmlspecialchars( $operatorValue );
00825 
00826         return $operatorValue;
00827     }
00828 
00829     public $Operators;
00830     public $URLName, $URLRootName, $DesignName, $ImageName;
00831     public $Sys;
00832 };
00833 
00834 ?>