GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
tedkulp (author)
Sun Sep 09 01:09:55 -0700 2007
commit  4978453c6368fd40690312e742cc2d7c095cec3a
tree    fbf2395a0e194d61b692bdc9467e422e717629fb
parent  a11ef674ead2618eb15652709b18c9aa06e5c4f0
cmsmadesimple-2-0 / lib / translation.functions.php
100644 91 lines (81 sloc) 2.586 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Translation functions/classes
*
* @package CMS
*/
 
function get_encoding($charset='', $defaultoverrides=true)
{
  global $nls;
  global $current_language;
  global $config;
  global $gCms;
  $variables =& $gCms->variables;
 
  if ($charset != '')
  {
    return $charset;
  }
        else if (isset($variables['current_encoding']) && $variables['current_encoding'] != "" )
        {
   return $variables['current_encoding'];
        }
  else if (isset($config['default_encoding']) && $config['default_encoding'] != "" && $defaultoverrides == true)
  {
    return $config['default_encoding'];
  }
  else if (isset($nls['encoding'][$current_language]))
  {
    return $nls['encoding'][$current_language];
  }
  else
  {
    return "UTF-8"; //can't hurt
  }
}
 
 
function set_encoding($charset)
{
  global $gCms;
  $variables =& $gCms->variables;
  
  if( $charset == '' )
    {
      if( isset($variables['current_encoding']) )
  unset($variables['current_encoding']);
      return;
    }
  $variables['current_encoding'] = $charset;
}
 
// Returns true if $string is valid UTF-8 and false otherwise.
function is_utf8($string)
{
   // From http://w3.org/International/questions/qa-forms-utf-8.html
   return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string);
   
} // function is_utf8
 
# vim:ts=4 sw=4 noet
?>