[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/common/ -> ezurloperator.php (source)

   1  <?php
   2  //
   3  // Definition of eZURLOperator class
   4  //
   5  // Created on: <18-Apr-2002 12:15:07 amos>
   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  /*!
  31   \class eZURLOperator ezurloperator.php
  32   \brief Collection of url modifying operators
  33  
  34  */
  35  
  36  define( 'EZ_HTTP_OPERATOR_TYPE_POST', 1 );
  37  define( 'EZ_HTTP_OPERATOR_TYPE_GET', 2 );
  38  define( 'EZ_HTTP_OPERATOR_TYPE_SESSION', 3 );
  39  
  40  class eZURLOperator
  41  {
  42      /*!
  43       Initializes the image operator with the operator name $name.
  44      */
  45      function eZURLOperator( $url_name = 'ezurl',
  46                              $urlroot_name = 'ezroot',
  47                              $ezsys_name = 'ezsys',
  48                              $design_name = 'ezdesign',
  49                              $image_name = 'ezimage',
  50                              $ext_name = 'exturl',
  51                              $httpName = 'ezhttp',
  52                              $iniName = 'ezini',
  53                              $iniNameHasVariable = 'ezini_hasvariable',
  54                              $httpNameHasVariable = 'ezhttp_hasvariable' )
  55      {
  56          $this->Operators = array( $url_name, $urlroot_name, $ezsys_name, $design_name, $image_name, $ext_name, $httpName, $iniName, $iniNameHasVariable, $httpNameHasVariable );
  57          $this->URLName = $url_name;
  58          $this->URLRootName = $urlroot_name;
  59          $this->SysName = $ezsys_name;
  60          $this->DesignName = $design_name;
  61          $this->ImageName = $image_name;
  62          $this->ExtName = $ext_name;
  63          $this->HTTPName = $httpName;
  64          $this->ININame = $iniName;
  65          $this->ININameHasVariable = $iniNameHasVariable;
  66          $this->HTTPNameHasVariable = $httpNameHasVariable;
  67          $this->Sys =& eZSys::instance();
  68      }
  69  
  70      function operatorTemplateHints()
  71      {
  72          return array( $this->URLName => array( 'input' => true,
  73                                                 'output' => true,
  74                                                 'parameters' => true,
  75                                                 'element-transformation' => true,
  76                                                 'transform-parameters' => true,
  77                                                 'input-as-parameter' => 'always',
  78                                                 'element-transformation-func' => 'urlTransformation'),
  79                        $this->URLRootName => array( 'input' => true,
  80                                                     'output' => true,
  81                                                     'parameters' => true,
  82                                                     'element-transformation' => true,
  83                                                     'transform-parameters' => true,
  84                                                     'input-as-parameter' => 'always',
  85                                                     'element-transformation-func' => 'urlTransformation'),
  86                        $this->SysName => array( 'input' => true,
  87                                                 'output' => true,
  88                                                 'parameters' => true,
  89                                                 'element-transformation' => true,
  90                                                 'transform-parameters' => true,
  91                                                 'input-as-parameter' => 'always',
  92                                                 'element-transformation-func' => 'urlTransformation'),
  93                        $this->DesignName => array( 'input' => true,
  94                                                    'output' => true,
  95                                                    'parameters' => true,
  96                                                    'element-transformation' => true,
  97                                                    'transform-parameters' => true,
  98                                                    'input-as-parameter' => 'always',
  99                                                    'element-transformation-func' => 'urlTransformation'),
 100                        $this->ImageName => array( 'input' => true,
 101                                                   'output' => true,
 102                                                   'parameters' => true,
 103                                                   'element-transformation' => true,
 104                                                   'transform-parameters' => true,
 105                                                   'input-as-parameter' => 'always',
 106                                                   'element-transformation-func' => 'urlTransformation'),
 107                        $this->ExtName => array( 'input' => true,
 108                                                 'output' => true,
 109                                                 'parameters' => true,
 110                                                 'element-transformation' => true,
 111                                                 'transform-parameters' => true,
 112                                                 'input-as-parameter' => 'always',
 113                                                 'element-transformation-func' => 'urlTransformation'),
 114                        $this->ININame => array( 'input' => true,
 115                                                 'output' => true,
 116                                                 'parameters' => true,
 117                                                 'element-transformation' => true,
 118                                                 'transform-parameters' => true,
 119                                                 'input-as-parameter' => true,
 120                                                 'element-transformation-func' => 'iniTrans'),
 121                        $this->ININameHasVariable => array( 'input' => true,
 122                                                            'output' => true,
 123                                                            'parameters' => true,
 124                                                            'element-transformation' => true,
 125                                                            'transform-parameters' => true,
 126                                                            'input-as-parameter' => true,
 127                                                            'element-transformation-func' => 'iniTrans' )
 128                        );
 129      }
 130  
 131      function iniTrans( $operatorName, &$node, &$tpl, &$resourceData,
 132                         &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
 133      {
 134          if ( count ( $parameters ) < 2 )
 135              return false;
 136  
 137          if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) &&
 138               eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
 139          {
 140              $iniGroup = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 141              $iniVariable = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
 142  
 143              $iniName = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : false;
 144              $iniPath = isset( $parameters[3] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[3] ) : false;
 145  
 146              // If we should check for existence of variable.
 147              // You can use like:
 148              //     ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, <Dynamic fetch: if 'true()' value of variable will be fetched dynamically>
 149              //                                                               <Should We Check for existence only: 'hasVariable' or true()> )
 150              //     ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
 151              if ( $operatorName == $this->ININameHasVariable )
 152              {
 153                  $checkExistence = true;
 154              }
 155              else
 156              {
 157                  $checkExistence = isset( $parameters[5] )
 158                                    ? ( eZTemplateNodeTool::elementStaticValue( $parameters[5] ) === true or
 159                                        eZTemplateNodeTool::elementStaticValue( $parameters[5] ) == 'hasVariable' ) ? true : false
 160                                    : false;
 161              }
 162  
 163              if ( count( $parameters ) > 4 )
 164              {
 165                  $inCache = eZTemplateNodeTool::elementStaticValue( $parameters[4] );
 166                  // Check if we should put implementaion of parsing ini variable to compiled php file
 167                  if ( $inCache === true )
 168                  {
 169                      $values = array();
 170                      $values[] = $parameters[0];
 171                      $values[] = $parameters[1];
 172  
 173                      $code = "include_once ( 'lib/ezutils/classes/ezini.php' );\n";
 174  
 175                      if ( $iniPath !== false )
 176                      {
 177                          $values[] = $parameters[2];
 178                          $values[] = $parameters[3];
 179                          $code .= '%tmp1% =& eZINI::instance( %3%, %4%, null, null, null, true );' . "\n";
 180                      }
 181                      elseif ( $iniName !== false )
 182                      {
 183                          $values[] = $parameters[2];
 184                          $code .= '%tmp1% =& eZINI::instance( %3% );' . "\n";
 185                      }
 186                      else
 187                          $code .= '%tmp1% =& eZINI::instance();' . "\n";
 188  
 189                      $checkExist = $checkExistence ? 'true' : 'false';
 190  
 191                      $code .= 'if ( %tmp1%->hasVariable( %1%, %2% ) )' . "\n" .
 192                          '    %output% = ' . "!$checkExist" . ' ? %tmp1%->variable( %1%, %2% ) : true;' . "\n" .
 193                          "else\n" .
 194                          "    %output% = $checkExist ? false : '';\n";
 195  
 196  
 197                      return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) );
 198                  }
 199              }
 200              include_once ( 'lib/ezutils/classes/ezini.php' );
 201  
 202              if ( $iniPath !== false )
 203                  $ini =& eZINI::instance( $iniName, $iniPath, null, null, null, true );
 204              elseif ( $iniName !== false )
 205                  $ini =& eZINI::instance( $iniName );
 206              else
 207                  $ini =& eZINI::instance();
 208  
 209              $value = '';
 210              if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
 211              {
 212                  $value = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
 213              }
 214              else
 215              {
 216                  // If we should check for existence then we return only FALSE
 217                  if ( $checkExistence )
 218                  {
 219                      $value = false;
 220                  }
 221                  else
 222                  {
 223                      if ( $iniName === false )
 224                          $iniName = 'site.ini';
 225                      $tpl->error( $operatorName, "No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
 226                  }
 227              }
 228              return array( eZTemplateNodeTool::createStringElement( $value ) );
 229          }
 230          else
 231              return false;
 232      }
 233  
 234      function urlTransformation( $operatorName, &$node, &$tpl, &$resourceData,
 235                                  &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
 236      {
 237          $newElements = array();
 238          $values = array();
 239          $paramCount = 0;
 240          $tmpCount = 0;
 241          switch( $operatorName )
 242          {
 243              case $this->URLName:
 244              {
 245                  if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
 246                  {
 247                      $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 248  
 249                      $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
 250  
 251                      include_once ( 'lib/ezutils/classes/ezuri.php' );
 252                      eZURI::transformURI( $url, false, $serverURL );
 253  
 254                      $url = $this->applyQuotes( $url, $parameters[1] );
 255                      return array( eZTemplateNodeTool::createStringElement( $url ) );
 256                  }
 257                  $values[] = $parameters[0];
 258                  $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
 259                  $code = <<<CODEPIECE
 260  
 261  include_once ( 'lib/ezutils/classes/ezuri.php' );
 262  eZURI::transformURI( %1%, false, %2% );
 263  
 264  CODEPIECE;
 265  
 266                  ++$paramCount;
 267              } break;
 268  
 269              case $this->URLRootName:
 270              {
 271                  if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
 272                  {
 273                      $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 274  
 275                      if ( preg_match( "#^[a-zA-Z0-9]+:#", $url ) or
 276                           substr( $url, 0, 2 ) == '//' )
 277                          $url = '/';
 278                      else if ( strlen( $url ) > 0 and
 279                                $url[0] != '/' )
 280                          $url = '/' . $url;
 281  
 282                      $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
 283  
 284                      // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
 285                      include_once ( 'lib/ezutils/classes/ezuri.php' );
 286                      eZURI::transformURI( $url, true, $serverURL );
 287  
 288                      $url = $this->applyQuotes( $url, $parameters[1] );
 289                      return array( eZTemplateNodeTool::createStringElement( $url ) );
 290                  }
 291                  else
 292                  {
 293                      $code ='if ( preg_match( "#^[a-zA-Z0-9]+:#", %1% ) or' . "\n" .
 294                           'substr( %1%, 0, 2 ) == \'//\' )' . "\n" .
 295                           '  %1% = \'/\';' . "\n" .
 296                           'else if ( strlen( %1% ) > 0 and' . "\n" .
 297                           '  %1%[0] != \'/\' )' . "\n" .
 298                           '%1% = \'/\' . %1%;' . "\n";
 299                      $values[] = $parameters[0];
 300                  }
 301                  $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
 302                  $code .= 'include_once( \'lib/ezutils/classes/ezuri.php\' );' . "\n" .
 303                           'eZURI::transformURI( %1%, true, %2% );' . "\n";
 304  
 305                  ++$paramCount;
 306                  ++$tmpCount;
 307              } break;
 308  
 309              case $this->SysName:
 310              {
 311                  if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
 312                  {
 313                      $sysAttribute = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
 314  
 315                      return array( eZTemplateNodeTool::createStringElement( $this->Sys->attribute( $sysAttribute ) ) );
 316                  }
 317                  return false;
 318              } break;
 319  
 320              case $this->DesignName:
 321              {
 322                  if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
 323                  {
 324                      $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 325  
 326                      $matches = eZTemplateDesignResource::fileMatchingRules( false, $path );
 327  
 328                      $designResource =& eZTemplateDesignResource::instance();
 329                      $matchKeys = $designResource->keys();
 330                      $matchedKeys = array();
 331  
 332                      include_once ( 'kernel/common/ezoverride.php' );
 333                      $match = eZOverride::selectFile( $matches, $matchKeys, $matchedKeys, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );
 334                      if ( $match === null )
 335                      {
 336                          return false;
 337                      }
 338  
 339                      $path = $match["file"];
 340                      $path = $this->Sys->wwwDir() . '/' . $path;
 341                      $path = htmlspecialchars( $path );
 342  
 343                      $path = $this->applyQuotes( $path, $parameters[1] );
 344  
 345                      return array( eZTemplateNodeTool::createStringElement( $path ) );
 346                  }
 347  
 348                  $code = ( '%tmp1% =& eZTemplateDesignResource::instance();' . "\n" .
 349                            'include_once( \'kernel/common/ezoverride.php\' );' . "\n" .
 350                            '%tmp2% = array();' . "\n" .
 351                            '%tmp3% = eZOverride::selectFile( eZTemplateDesignResource::fileMatchingRules( false, %1% ), %tmp1%->keys(), %tmp2%, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );' . "\n" .
 352                            'if ( %tmp3% === null )' . "\n" .
 353                            '{' . "\n" .
 354                            '    %tmp3% = array();' . "\n" .
 355                            '}' . "\n" .
 356                            'else' . "\n" .
 357                            '{' . "\n" .
 358                            '    %1% = %tmp3%["file"];' . "\n" .
 359                            '    %1% = %2% . "/" . %1%;' . "\n" .
 360                            '    %1% = htmlspecialchars( %1% );' . "\n" .
 361                            '}' . "\n" );
 362  
 363                  $values[] = $parameters[0];
 364                  $values[] = array( eZTemplateNodeTool::createStringElement( $this->Sys->wwwDir() ) );
 365                  $tmpCount += 3;
 366                  ++$paramCount;
 367              } break;
 368  
 369              case $this->ImageName:
 370              {
 371                  if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
 372                  {
 373                      $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 374                      $skipSlash = false;
 375                      if ( count( $parameters ) > 2 )
 376                      {
 377                          $skipSlash = eZTemplateNodeTool::elementStaticValue( $parameters[2] );
 378                      }
 379  
 380                      $bases = eZTemplateDesignResource::allDesignBases();
 381                      $no_slash_prefix = false;
 382                      if ( $skipSlash == true && strlen( $this->Sys->wwwDir() ) == 0 )
 383                          $no_slash_prefix = true;
 384  
 385                      $imageFound = false;
 386                      foreach ( $bases as $base )
 387                      {
 388                          if ( file_exists( $base . "/images/" . $path ) )
 389                          {
 390                              if ( $no_slash_prefix == true )
 391                                  $path = $base . '/images/' . $path;
 392                              else
 393                                  $path = $this->Sys->wwwDir() . '/' . $base . '/images/'. $path;
 394                              break;
 395                          }
 396                      }
 397  
 398                      $path = htmlspecialchars( $path );
 399  
 400                      $path = $this->applyQuotes( $path, $parameters[1] );
 401  
 402                      return array( eZTemplateNodeTool::createStringElement( $path ) );
 403                  }
 404                  else
 405                  {
 406                      $values = array();
 407                      $values[] = $parameters[0];
 408  
 409                      $no_slash_prefix = false;
 410                      if ( count ( $parameters ) > 2 )
 411                      {
 412                          if ( eZTemplateNodeTool::elementStaticValue( $parameters[2] ) == true && strlen( $wwwDir ) )
 413                          {
 414                              $no_slash_prefix = true;
 415                          }
 416                      }
 417  
 418                      $ini =& eZINI::instance();
 419                      $values[] = array( eZTemplateNodeTool::createStringElement( $this->Sys->wwwDir() ) );
 420                      $values[] = array( eZTemplateNodeTool::createArrayElement( eZTemplateDesignResource::allDesignBases() ) );
 421                      $code = 'foreach ( %3% as %tmp1% )'."\n{\n";
 422                      $code .= '    if ( file_exists( %tmp1% . \'/images/\' . %1% ) )' . "\n" . '    {' . "\n";
 423                      if ( $no_slash_prefix == true )
 424                      {
 425                          $code .= '        %output% = %tmp1% . \'/images/\' . %1%;' . "\n";
 426                      }
 427                      else
 428                      {
 429                          $code .= '        %output% = %2% . \'/\' . %tmp1% . \'/images/\' . %1%;' . "\n";
 430                      }
 431                      $code .= '        break;'."\n";
 432                      $code .= "    }\n}\n" . '%output% = htmlspecialchars( %output% );' . "\n";
 433  
 434                      $quote = $this->applyQuotes( '', $parameters[1], true );
 435  
 436                      if ( $quote )
 437                      {
 438                          $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
 439                          $code .= '%output% = %4% . %output% . %4%;' . "\n";
 440                      }
 441  
 442                      return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 2 ) );
 443                  }
 444              } break;
 445  
 446              case $this->ExtName:
 447              {
 448                  if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
 449                  {
 450                      $origUrl = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
 451  
 452                      include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
 453                      $url = eZURL::urlByMD5( md5( $origUrl ) );
 454                      if ( $url == false )
 455                          eZURL::registerURL( $origUrl );
 456                      else
 457                          $origUrl = $url;
 458  
 459                      $origUrl = $this->applyQuotes( $origUrl, $parameters[1] );
 460  
 461                      return array( eZTemplateNodeTool::createStringElement( $origUrl ) );
 462                  }
 463  
 464                  $code .= 'include_once( \'kernel/classes/datatypes/ezurl/ezurl.php\' );' . "\n" .
 465                       '%tmp1% = eZURL::urlByMD5( md5( %1% ) );' . "\n" .
 466                       'if ( %tmp1% == false )' . "\n" .
 467                       '  eZURL::registerURL( %1% );' . "\n" .
 468                       'else' . "\n" .
 469                       '  %1% = %tmp1%;' . "\n";
 470                  $values[] = $parameters[0];
 471                  ++$tmpCount;
 472                  ++$paramCount;
 473              } break;
 474  
 475          }
 476  
 477          include_once ( 'lib/ezutils/classes/ezhttptool.php' );
 478          $http =& eZHTTPTool::instance();
 479  
 480          if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
 481          {
 482              ++$tmpCount;
 483              $code .= 'include_once( \'lib/ezutils/classes/ezhttptool.php\' );' . "\n" .
 484                   '%tmp' . $tmpCount . '% =& eZHTTPTool::instance();' . "\n" .
 485                   'if ( isset( %tmp' . $tmpCount . '%->UseFullUrl ) and %tmp' . $tmpCount . '%->UseFullUrl )' . "\n" .
 486                   '{' . "\n" .
 487                   ' %1% = %tmp' . $tmpCount . '%->createRedirectUrl( %1%, array( \'pre_url\' => false ) );' . "\n" .
 488                   '}' . "\n";
 489          }
 490  
 491          $quote = '"';
 492          if ( count( $parameters ) > $paramCount )
 493          {
 494              $val = eZTemplateNodeTool::elementStaticValue( $parameters[$paramCount] );
 495              ++$paramCount;
 496              if ( $val == 'single' )
 497                  $quote = "'";
 498              else if ( $val == 'no' )
 499                  $quote = false;
 500          }
 501  
 502          if ( $quote !== false )
 503          {
 504              $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
 505              $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
 506          }
 507  
 508          $code .= '%output% = %1%;' . "\n";
 509  
 510          $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount );
 511  
 512          return $newElements;
 513      }
 514  
 515      /*!
 516       Apply quotes to static text
 517  
 518       \param static text
 519       \param quote parameter
 520       \param if set to true, return only quote value
 521  
 522       \return text with quotes
 523      */
 524      function applyQuotes( $text, &$parameter, $onlyQuote = false )
 525      {
 526          $quote = "\"";
 527          if ( $parameter != null )
 528          {
 529              $val = eZTemplateNodeTool::elementStaticValue( $parameter );
 530              if ( $val == 'single' )
 531                  $quote = "'";
 532              else if ( $val == 'no' )
 533                  $quote = false;
 534          }
 535  
 536          if ( $onlyQuote )
 537          {
 538              return $quote;
 539          }
 540  
 541          include_once ( 'lib/ezutils/classes/ezhttptool.php' );
 542          $http =& eZHTTPTool::instance();
 543  
 544          if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
 545          {
 546              $text = $http->createRedirectUrl( $text, array( 'pre_url' => false ) );
 547          }
 548          if ( $quote !== false )
 549              return $quote . $text . $quote;
 550  
 551          return $text;
 552      }
 553  
 554      /*!
 555       Returns the operators in this class.
 556      */
 557      function &operatorList()
 558      {
 559          return $this->Operators;
 560      }
 561  
 562      function namedParameterList()
 563      {
 564          return array( 'quote_val' => array( 'type' => 'string',
 565                                              'required' => false,
 566                                              'default' => 'double' ),
 567                        'server_url' => array( 'type' => 'string',
 568                                               'required' => false,
 569                                               'default' => 'relative' ) );
 570      }
 571  
 572      /*!
 573       */
 574      function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
 575      {
 576          switch ( $operatorName )
 577          {
 578              case $this->ININameHasVariable:
 579              case $this->ININame:
 580              {
 581                  if ( count( $operatorParameters ) > 0 )
 582                  {
 583                      $iniGroup = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
 584                      if ( count( $operatorParameters ) == 1 )
 585                      {
 586                          $tpl->error( $operatorName, "Missing variable name parameter" );
 587                          return;
 588                      }
 589                      $iniVariable = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
 590                      $iniName = isset( $operatorParameters[2] ) ? $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) : false;
 591                      $iniPath = isset( $operatorParameters[3] ) ? $tpl->elementValue( $operatorParameters[3], $rootNamespace, $currentNamespace ) : false;
 592  
 593                      // If we should check for existence of variable.
 594                      // You can use like:
 595                      //     ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, _use under template compiling mode_ , <Should We Check for existence: 'hasVariable' or true()> )
 596                      //     ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
 597                      if ( $operatorName == $this->ININameHasVariable )
 598                      {
 599                          $checkExistence = true;
 600                      }
 601                      else
 602                      {
 603                          $checkExistence = isset( $operatorParameters[5] )
 604                                            ? ( $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) === true or
 605                                                $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
 606                                            : false;
 607                      }
 608                      include_once ( 'lib/ezutils/classes/ezini.php' );
 609  
 610                      if ( $iniPath !== false )
 611                          $ini =& eZINI::instance( $iniName, $iniPath, null, null, null, true );
 612                      elseif ( $iniName !== false )
 613                          $ini =& eZINI::instance( $iniName );
 614                      else
 615                          $ini =& eZINI::instance();
 616  
 617                      if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
 618                      {
 619                          $operatorValue = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
 620                      }
 621                      else
 622                      {
 623                          if ( $checkExistence )
 624                          {
 625                              $operatorValue = false;
 626                              return;
 627                          }
 628                          if ( $iniPath !== false )
 629                          {
 630                              // Return empty string instead of displaying error when using 'path' parameter
 631                              // and DirectAccess mode for ezini.
 632                              $operatorValue = '';
 633                          }
 634                          else
 635                          {
 636                              if ( $iniName === false )
 637                                  $iniName = 'site.ini';
 638                              $tpl->error( $operatorName, "!!!No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
 639                          }
 640                      }
 641                      return;
 642                  }
 643                  else
 644                      $tpl->error( $operatorName, "Missing group name parameter" );
 645              } break;
 646  
 647              case $this->HTTPNameHasVariable:
 648              case $this->HTTPName:
 649              {
 650                  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
 651                  $http =& eZHTTPTool::instance();
 652                  if ( count( $operatorParameters ) > 0 )
 653                  {
 654                      $httpType = EZ_HTTP_OPERATOR_TYPE_POST;
 655                      $httpName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
 656                      if ( count( $operatorParameters ) > 1 )
 657                      {
 658                          $httpTypeName = strtolower( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) );
 659                          if ( $httpTypeName == 'post' )
 660                              $httpType = EZ_HTTP_OPERATOR_TYPE_POST;
 661                          else if ( $httpTypeName == 'get' )
 662                              $httpType = EZ_HTTP_OPERATOR_TYPE_GET;
 663                          else if ( $httpTypeName == 'session' )
 664                              $httpType = EZ_HTTP_OPERATOR_TYPE_SESSION;
 665                          else
 666                              $tpl->warning( $operatorName, "Unknown http type '$httpTypeName'" );
 667                      }
 668  
 669                      // If we should check for existence of http variable
 670                      // You can use like:
 671                      //     ezhttp( <Variable>, <Method: post, get, session>, <Should We Check for existence: 'hasVariable' or true()> )
 672                      //     ezhttp_hasvariable( <Variable>, <Method> )
 673                      if ( $operatorName == $this->HTTPNameHasVariable )
 674                      {
 675                          $checkExistence = true;
 676                      }
 677                      else
 678                      {
 679                          $checkExistence = isset( $operatorParameters[2] )
 680                                            ? ( $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) === true or
 681                                                $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
 682                                            : false;
 683                      }
 684                      switch( $httpType )
 685                      {
 686                          case EZ_HTTP_OPERATOR_TYPE_POST:
 687                          {
 688                              if ( $http->hasPostVariable( $httpName ) )
 689                                  $operatorValue = !$checkExistence ? $http->postVariable( $httpName ) : true;
 690                              else
 691                              {
 692                                  // If only check for existence - return false
 693                                  if ( $checkExistence )
 694                                  {
 695                                      $operatorValue = false;
 696                                      return;
 697                                  }
 698                                  $tpl->error( $operatorName, "Unknown post variable '$httpName'" );
 699                              }
 700                          } break;
 701                          case EZ_HTTP_OPERATOR_TYPE_GET:
 702                          {
 703                              if ( $http->hasGetVariable( $httpName ) )
 704                                  $operatorValue = !$checkExistence ? $http->getVariable( $httpName ) : true;
 705                              else
 706                              {
 707                                  if ( $checkExistence )
 708                                  {
 709                                      $operatorValue = false;
 710                                      return;
 711                                  }
 712                                  $tpl->error( $operatorName, "Unknown get variable '$httpName'" );
 713                              }
 714                          } break;
 715                          case EZ_HTTP_OPERATOR_TYPE_SESSION:
 716                          {
 717                              if ( $http->hasSessionVariable( $httpName ) )
 718                                  $operatorValue = !$checkExistence ? $http->sessionVariable( $httpName ) : true;
 719                              else
 720                              {
 721                                  if ( $checkExistence )
 722                                  {
 723                                      $operatorValue = false;
 724                                      return;
 725                                  }
 726                                  $tpl->error( $operatorName, "Unknown session variable '$httpName'" );
 727                              }
 728                          } break;
 729                      }
 730                  }
 731                  else
 732                  {
 733                      $operatorValue = $http;
 734                  }
 735                  return;
 736              } break;
 737  
 738              case $this->URLName:
 739              {
 740                  include_once ( 'lib/ezutils/classes/ezuri.php' );
 741                  eZURI::transformURI( $operatorValue, false, $namedParameters['server_url'] );
 742  
 743              } break;
 744  
 745              case $this->URLRootName:
 746              {
 747                  if ( preg_match( "#^[a-zA-Z0-9]+:#", $operatorValue ) or
 748                       substr( $operatorValue, 0, 2 ) == '//' )
 749                       break;
 750                  if ( strlen( $operatorValue ) > 0 and
 751                       $operatorValue[0] != '/' )
 752                      $operatorValue = '/' . $operatorValue;
 753  
 754                  // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
 755                  include_once ( 'lib/ezutils/classes/ezuri.php' );
 756                  eZURI::transformURI( $operatorValue, true, $namedParameters['server_url'] );
 757  
 758              } break;
 759  
 760              case $this->SysName:
 761              {
 762                  if ( count( $operatorParameters ) == 0 )
 763                      $tpl->warning( 'eZURLOperator' . $operatorName, 'Requires attributename' );
 764                  else
 765                  {
 766                      $sysAttribute = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
 767                      if ( !$this->Sys->hasAttribute( $sysAttribute ) )
 768                          $tpl->warning( 'eZURLOperator' . $operatorName, "No such attribute '$sysAttribute' for eZSys" );
 769                      else
 770                          $operatorValue = $this->Sys->attribute( $sysAttribute );
 771                  }
 772                  return;
 773              } break;
 774  
 775              case $this->ImageName:
 776              {
 777                  $ini =& eZINI::instance();
 778                  $std_base = eZTemplateDesignResource::designSetting( 'standard' );
 779                  $site_base = eZTemplateDesignResource::designSetting( 'site' );
 780                  $std_file = "design/$std_base/images/$operatorValue";
 781                  $site_file = "design/$site_base/images/$operatorValue";
 782                  $no_slash_prefix = false;
 783                  if ( count( $operatorParameters ) == 2 )
 784                  {
 785                      if ( $operatorParameters[1] == true && strlen( $this->Sys->wwwDir() ) == 0 )
 786                          $no_slash_prefix = true;
 787                  }
 788  
 789                  $bases = eZTemplateDesignResource::allDesignBases();
 790  
 791                  $imageFound = false;
 792                  foreach ( $bases as $base )
 793                  {
 794                      if ( file_exists( $base . "/images/" . $operatorValue ) )
 795                      {
 796                          if ( $no_slash_prefix == true )
 797                              $operatorValue = $base . '/images/' . $operatorValue;
 798                          else
 799                              $operatorValue = $this->Sys->wwwDir() . '/' . $base . '/images/'. $operatorValue;
 800                          $operatorValue = htmlspecialchars( $operatorValue );
 801                          $imageFound = true;
 802                          break;
 803                      }
 804                  }
 805  
 806                  if ( !$imageFound )
 807                  {
 808                      $tpl->warning( $operatorName, "Image '$operatorValue' does not exist in any design" );
 809                  }
 810              } break;
 811  
 812              case $this->ExtName:
 813              {
 814                  include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
 815                  $urlMD5 = md5( $operatorValue );
 816                  $url = eZURL::urlByMD5( $urlMD5 );
 817                  if ( $url === false )
 818                      eZURL::registerURL( $operatorValue );
 819                  else
 820                      $operatorValue = $url;
 821              } break;
 822  
 823              case $this->DesignName:
 824              {
 825                  $path = $operatorValue;
 826                  $matches = eZTemplateDesignResource::fileMatchingRules( false, $path );
 827  
 828                  $designResource =& eZTemplateDesignResource::instance();
 829                  $matchKeys = $designResource->keys();
 830                  $matchedKeys = array();
 831  
 832                  include_once ( 'kernel/common/ezoverride.php' );
 833                  $match = eZOverride::selectFile( $matches, $matchKeys, $matchedKeys, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );
 834                  if ( $match === null )
 835                  {
 836                      $tpl->warning( 'eZURLOperator', "Design element $operatorValue does not exist in any design" );
 837                      return false;
 838                  }
 839  
 840                  $file = $match["file"];
 841                  $operatorValue = $this->Sys->wwwDir() . "/$file";
 842                  $operatorValue = htmlspecialchars( $operatorValue );
 843  
 844              } break;
 845          }
 846          $quote = "\"";
 847          $val = $namedParameters['quote_val'];
 848          if ( $val == 'single' )
 849              $quote = "'";
 850          else if ( $val == 'no' )
 851              $quote = false;
 852  
 853          include_once ( 'lib/ezutils/classes/ezhttptool.php' );
 854          $http =& eZHTTPTool::instance();
 855  
 856          if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
 857          {
 858              $operatorValue = $http->createRedirectUrl( $operatorValue, array( 'pre_url' => false ) );
 859          }
 860          if ( $quote !== false )
 861              $operatorValue = $quote . $operatorValue . $quote;
 862      }
 863  
 864      var $Operators;
 865      var $URLName, $URLRootName, $DesignName, $ImageName;
 866      var $Sys;
 867  };
 868  
 869  ?>


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