[ Index ]
 

Code source de PRADO 3.0.6

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

title

Body

[fermer]

/framework/I18N/core/ -> HTTPNegotiator.php (source)

   1  <?php
   2  
   3  /**
   4   * HTTPNegotiator class file.
   5   *
   6   * This program is free software; you can redistribute it and/or modify
   7   * it under the terms of the BSD License.
   8   *
   9   * Copyright(c) 2004 by Qiang Xue. All rights reserved.
  10   *
  11   * To contact the author write to {@link mailto:qiang.xue@gmail.com Qiang Xue}
  12   * The latest version of PRADO can be obtained from:
  13   * {@link http://prado.sourceforge.net/}
  14   *
  15   * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
  16   * @version $Revision: 1.2 $  $Date: 2005/01/05 03:15:14 $
  17   * @package System.I18N.core
  18   */
  19  
  20  /**
  21   * Include the CultureInfo class.
  22   */
  23  require_once(dirname(__FILE__).'/CultureInfo.php');
  24  
  25  /**
  26   * HTTPNegotiator class.
  27   * 
  28   * Get the language and charset information from the client browser.
  29   *
  30   * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
  31   * @version v1.0, last update on Fri Dec 24 16:01:35 EST 2004
  32   * @package System.I18N.core
  33   */
  34  class HTTPNegotiator
  35  {
  36      /**
  37       * A list of languages accepted by the browser.
  38       * @var array 
  39       */
  40      protected $languages;
  41  
  42      /**
  43       * A list of charsets accepted by the browser
  44       * @var array 
  45       */
  46      protected $charsets;
  47  
  48      /**
  49       * Get a list of languages acceptable by the client browser
  50       * @return array languages ordered in the user browser preferences. 
  51       */
  52  	function getLanguages()
  53      {
  54          if(!is_null($this->languages))
  55              return $this->languages;
  56  
  57          $this->languages = array();
  58  
  59          if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
  60              return $this->languages;
  61  
  62          //$basedir = CultureInfo::dataDir();
  63          //$ext = CultureInfo::fileExt();
  64  
  65          foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) 
  66          {
  67              // Cut off any q-value that might come after a semi-colon
  68              if ($pos = strpos($lang, ';'))
  69                  $lang = trim(substr($lang, 0, $pos));
  70  
  71              if (strstr($lang, '-')) 
  72              {
  73                  $codes = explode('-',$lang);
  74                  if($codes[0] == 'i')
  75                  {
  76                      // Language not listed in ISO 639 that are not variants
  77                      // of any listed language, which can be registerd with the
  78                      // i-prefix, such as i-cherokee
  79                      if(count($codes)>1)
  80                          $lang = $codes[1];
  81                  }
  82                  else
  83                  {
  84                      for($i = 0, $k = count($codes); $i<$k; ++$i)
  85                      {
  86                          if($i == 0)
  87                              $lang = strtolower($codes[0]);
  88                          else
  89                              $lang .= '_'.strtoupper($codes[$i]);
  90                      }
  91                  }
  92              }
  93  
  94              if(CultureInfo::validCulture($lang))
  95                  $this->languages[] = $lang;
  96          }
  97          
  98          return $this->languages;
  99      }
 100  
 101      /**
 102       * Get a list of charsets acceptable by the client browser.
 103       * @return array list of charsets in preferable order. 
 104       */
 105  	function getCharsets()
 106      {
 107          if(!is_null($this->charsets))
 108              return $this->charsets;
 109  
 110          $this->charsets = array();
 111  
 112          if (!isset($_SERVER['HTTP_ACCEPT_CHARSET']))
 113              return $this->charsets;
 114  
 115          foreach (explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']) as $charset) 
 116          {
 117              if (!empty($charset)) 
 118                  $this->charsets[] = preg_replace('/;.*/', '', $charset);
 119          }
 120  
 121          return $this->charsets;
 122      }
 123  }
 124  
 125  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7