ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/lib/charconv.php
Revision: 16
Committed: Thu Nov 21 13:07:39 2013 UTC (11 years ago) by matthys
File size: 3330 byte(s)
Log Message:
Cleanup code.

File Contents

# User Rev Content
1 matthys 15 <?php
2     /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3     *
4 matthys 16 * SVN FILE $Id$
5 matthys 15 *
6 matthys 16 * Copyright (C) 2001-2013, the BBClone Team (see doc/authors.txt for details)
7 matthys 15 *
8     * This program is free software: you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation, either version 3 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * See doc/copying.txt for details
19     */
20    
21     //////////////////////////////
22     // Character set conversion //
23     //////////////////////////////
24    
25     function bbc_get_encoding($str) {
26     global $BBC_LANGUAGE;
27    
28     switch ($BBC_LANGUAGE) {
29     case "bg":
30     case "mk":
31     case "ru":
32     case "uk":
33     return mb_detect_encoding($str, "UTF-8, KOI8-R, Windows-1251");
34    
35     case "ja":
36     return mb_detect_encoding($str, "JIS, UTF-8, EUC-JP, SJIS");
37    
38     case "ko":
39     return mb_detect_encoding($str, "UTF-8, EUC-KR, ISO-2022-KR");
40    
41     default:
42     // Note that iso-8859-1 is only a placeholder, the focus lies on detecting UTF-8...
43     return (mb_detect_encoding($str, "UTF-8, iso-8859-1") == "UTF-8") ? "UTF-8" : false;
44     }
45     }
46    
47     function bbc_convert_keys($str, $from, $to) {
48     if (($from !== false) && defined("_BBC_MBSTRING") && preg_match(":iso-8859-|EUC-(JP|KR)|gb2312:", $to) ||
49     (!empty($BBC_CUSTOM_CHARSET) && stristr("UTF", $BBC_CUSTOM_CHARSET))) {
50     return mb_convert_encoding($str, $to, $from);
51     }
52     elseif (($from !== false) && defined("_BBC_ICONV")) return iconv($from, $to."//TRANSLIT", $str);
53     elseif (defined("_BBC_RECODE")) return recode_string($to, $str);
54    
55     else return $str;
56     }
57    
58     // Note: Specify $BBC_CUSTOM_CHARSET to overwrite the default character set.
59     function bbc_convert_lang($str, $from, $char) {
60     global $BBC_LANGUAGE;
61    
62     if (!empty($char)) return bbc_convert_keys($str, $from, $char);
63    
64     switch ($BBC_LANGUAGE) {
65    
66     // Cyrillic encodings
67     case "bg":
68     case "mk":
69     case "ru":
70     case "uk":
71     return bbc_convert_keys($str, $from, "Windows-1251");
72    
73     // Central and East European encodings
74     case "bs":
75     case "cs":
76     case "hu":
77     case "pl":
78     case "ro":
79     case "sk":
80     case "sl":
81     return bbc_convert_keys($str, $from, "iso-8859-2");
82    
83     // Various encodings
84     case "ar":
85     return bbc_convert_keys($str, $from, "Windows-1256");
86    
87     case "el":
88     return bbc_convert_keys($str, $from, "iso-8859-7");
89    
90     case "ja":
91     return bbc_convert_keys($str, $from, "EUC-JP");
92    
93     case "ko":
94     return bbc_convert_keys($str, $from, "EUC-KR");
95    
96     case "lt":
97     return bbc_convert_keys($str, $from, "Windows-1257");
98    
99     case "tr":
100     return bbc_convert_keys($str, $from, "Windows-1254");
101    
102     case "zh-cn":
103     return bbc_convert_keys($str, $from, "gb2312");
104    
105     case "zh-tw":
106     return bbc_convert_keys($str, $from, "big5");
107    
108     // All remaining languages not mentioned anywhere else
109     default:
110     return bbc_convert_keys($str, $from, "iso-8859-15");
111     }
112     }
113     ?>

Properties

Name Value
svn:keywords Id