| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:30:18 2008 ] | [ symfony 0.6.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * sfHTTPNegotiator 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 $Id: sfHTTPNegotiator.class.php 835 2006-02-15 20:57:57Z fabien $ 17 * @package symfony 18 * @subpackage i18n 19 */ 20 21 /** 22 * sfHTTPNegotiator class. 23 * 24 * Get the language and charset information from the client browser. 25 * 26 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com> 27 * @version v1.0, last update on Fri Dec 24 16:01:35 EST 2004 28 * @package System.I18N.core 29 */ 30 class sfHTTPNegotiator 31 { 32 /** 33 * A list of languages accepted by the browser. 34 * @var array 35 */ 36 protected $languages; 37 38 /** 39 * A list of charsets accepted by the browser 40 * @var array 41 */ 42 protected $charsets; 43 44 /** 45 * Get a list of languages acceptable by the client browser 46 * @return array languages ordered in the user browser preferences. 47 */ 48 function getLanguages() 49 { 50 if(!is_null($this->languages)) 51 return $this->languages; 52 53 $this->languages = array(); 54 55 if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) 56 return $this->languages; 57 58 //$basedir = sfCultureInfo::dataDir(); 59 //$ext = sfCultureInfo::fileExt(); 60 61 foreach(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) 62 { 63 // Cut off any q-value that might come after a semi-colon 64 if ($pos = strpos($lang, ';')) 65 $lang = trim(substr($lang, 0, $pos)); 66 67 if (strstr($lang, '-')) 68 { 69 $codes = explode('-',$lang); 70 if($codes[0] == 'i') 71 { 72 // Language not listed in ISO 639 that are not variants 73 // of any listed language, which can be registerd with the 74 // i-prefix, such as i-cherokee 75 if(count($codes)>1) 76 $lang = $codes[1]; 77 } 78 else 79 { 80 for($i = 0; $i<count($codes); $i++) 81 { 82 if($i == 0) 83 $lang = strtolower($codes[0]); 84 else 85 $lang .= '_'.strtoupper($codes[$i]); 86 } 87 } 88 } 89 90 if(sfCultureInfo::validCulture($lang)) 91 $this->languages[] = $lang; 92 } 93 94 return $this->languages; 95 } 96 97 /** 98 * Get a list of charsets acceptable by the client browser. 99 * @return array list of charsets in preferable order. 100 */ 101 function getCharsets() 102 { 103 if(!is_null($this->charsets)) 104 return $this->charsets; 105 106 $this->charsets = array(); 107 108 if (!isset($_SERVER['HTTP_ACCEPT_CHARSET'])) 109 return $this->charsets; 110 111 foreach (explode(',', $_SERVER['HTTP_ACCEPT_CHARSET']) as $charset) 112 { 113 if (!empty($charset)) 114 $this->charsets[] = preg_replace('/;.*/', '', $charset); 115 } 116 117 return $this->charsets; 118 } 119 } 120 121 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |