[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/shop/classes/exchangeratehandlers/ezecb/ -> ezecbhandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZECBHandler class
   4  //
   5  // Created on: <12-Mar-2006 13:06:15 dl>
   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  /*! \file ezecbhandler.php
  30  */
  31  
  32  include_once ( 'kernel/shop/classes/exchangeratehandlers/ezexchangeratesupdatehandler.php' );
  33  
  34  class eZECBHandler extends eZExchangeRatesUpdateHandler
  35  {
  36      function eZECBHandler()
  37      {
  38          $this->ServerName = false;
  39          $this->ServerPort = false;
  40          $this->RatesURI = false;
  41  
  42          eZExchangeRatesUpdateHandler::eZExchangeRatesUpdateHandler();
  43      }
  44  
  45      function initialize( $params = array() )
  46      {
  47          eZExchangeRatesUpdateHandler::initialize( $params );
  48  
  49          $shopINI =& eZINI::instance( 'shop.ini' );
  50          if ( !isset( $params['ServerName'] ) )
  51          {
  52              $params['ServerName'] = '';
  53              if ( $shopINI->hasVariable( 'ECBExchangeRatesSettings', 'ServerName' ) )
  54                  $params['ServerName'] = $shopINI->variable( 'ECBExchangeRatesSettings', 'ServerName' );
  55          }
  56  
  57          if ( !isset( $params['ServerPort'] ) )
  58          {
  59              $params['ServerPort'] = '';
  60              if ( $shopINI->hasVariable( 'ECBExchangeRatesSettings', 'ServerPort' ) )
  61                  $params['ServerPort'] = $shopINI->variable( 'ECBExchangeRatesSettings', 'ServerPort' );
  62          }
  63  
  64          if ( !isset( $params['RatesURI'] ) )
  65          {
  66              $params['RatesURI'] = '';
  67              if ( $shopINI->hasVariable( 'ECBExchangeRatesSettings', 'RatesURI' ) )
  68                  $params['RatesURI'] = $shopINI->variable( 'ECBExchangeRatesSettings', 'RatesURI' );
  69          }
  70  
  71          if ( !isset( $params['BaseCurrency'] ) )
  72          {
  73              // the ECB returns currencies against 'EUR'
  74              $params['BaseCurrency'] = 'EUR';
  75          }
  76  
  77          $this->setServerName( $params['ServerName'] );
  78          $this->setServerPort( $params['ServerPort'] );
  79          $this->setRatesURI( $params['RatesURI'] );
  80          $this->setBaseCurrency( $params['BaseCurrency'] );
  81      }
  82  
  83      function requestRates()
  84      {
  85          $error = array( 'code' => EZ_EXCHANGE_RATES_HANDLER_OK,
  86                          'description' => ezi18n( 'kernel/shop', "'Autorates' were retrieved successfully" ) );
  87  
  88          $serverName = $this->serverName();
  89          $serverPort = $this->serverPort();
  90          $ratesURI = $this->ratesURI();
  91  
  92          $ratesList = array();
  93  
  94          include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  95          $buf = eZHTTPTool::sendHTTPRequest( "{$serverName}/{$ratesURI}", $serverPort,  false, 'eZ publish', false );
  96          if ( $buf )
  97          {
  98              $header = false;
  99              $body = false;
 100  
 101              if ( eZHTTPTool::parseHTTPResponse( $buf, $header, $body ) )
 102              {
 103                  if ( $header['content-type'] === 'text/xml' )
 104                  {
 105                      // parse xml
 106                      include_once ( 'lib/ezxml/classes/ezxml.php' );
 107                      $xml = new eZXML();
 108                      $domDocument =& $xml->domTree( $body );
 109  
 110                      $rootNode =& $domDocument->root();
 111                      $cubeNode = $rootNode->elementFirstChildByName( 'Cube' );
 112                      if ( $cubeNode )
 113                      {
 114                          $currencyNodes = $cubeNode->children();
 115                          foreach ( $currencyNodes as $currencyNode )
 116                          {
 117                              $currencyCode = $currencyNode->attributeValue( 'currency' );
 118                              $rateValue = $currencyNode->attributeValue( 'rate' );
 119                              $ratesList[$currencyCode] = $rateValue;
 120                          }
 121                      }
 122                  }
 123                  else
 124                  {
 125                      $error['code'] = EZ_EXCHANGE_RATES_HANDLER_REQUEST_RATES_FAILED;
 126                      $error['description'] = ezi18n( 'kernel/shop', "Unknown body format in HTTP response. Expected 'text/xml'" );
 127                  }
 128              }
 129              else
 130              {
 131                  $error['code'] = EZ_EXCHANGE_RATES_HANDLER_REQUEST_RATES_FAILED;
 132                  $error['description'] = ezi18n( 'kernel/shop', "Invalid HTTP response" );
 133              }
 134          }
 135          else
 136          {
 137              $error['code'] = EZ_EXCHANGE_RATES_HANDLER_REQUEST_RATES_FAILED;
 138              $error['description'] = ezi18n( 'kernel/shop', "Unable to send http request: %1:%2/%3", null, array( $serverName, $serverPort, $ratesURI ) );
 139          }
 140  
 141          $this->setRateList( $ratesList );
 142          return $error;
 143      }
 144  
 145      function setServerName( $serverName )
 146      {
 147          $this->ServerName = $serverName;
 148      }
 149  
 150      function serverName()
 151      {
 152          return $this->ServerName;
 153      }
 154  
 155      function setServerPort( $serverPort )
 156      {
 157          $this->ServerPort = $serverPort;
 158      }
 159  
 160      function setRatesURI( $ratesURI )
 161      {
 162          $this->RatesURI = $ratesURI;
 163      }
 164  
 165      function serverPort()
 166      {
 167          return $this->ServerPort;
 168      }
 169  
 170      function ratesURI()
 171      {
 172          return $this->RatesURI;
 173      }
 174  
 175      var $ServerName;
 176      var $ServerPort;
 177      var $RatesURI;
 178  }
 179  
 180  ?>


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