1 |
<? |
2 |
/** |
3 |
* This file contains the Data::Encode class. |
4 |
* |
5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
* @package org.netfrag.glib |
7 |
* @name Data::Encode |
8 |
* |
9 |
*/ |
10 |
|
11 |
// ------------------------------------------------------------------------- |
12 |
// $Id: Encode.php,v 1.3 2004/06/16 15:17:03 joko Exp $ |
13 |
// ------------------------------------------------------------------------- |
14 |
// $Log: Encode.php,v $ |
15 |
// Revision 1.3 2004/06/16 15:17:03 joko |
16 |
// now also en-/decodes hash-keys |
17 |
// |
18 |
// Revision 1.2 2003/03/10 23:25:02 joko |
19 |
// + fixed metadata for phpDocumentor |
20 |
// |
21 |
// Revision 1.1 2003/02/03 14:49:37 joko |
22 |
// + initial commit |
23 |
// + refactored from flib/Application/i18n/TextEncode.php |
24 |
// |
25 |
// Revision 1.2 2003/02/03 03:40:02 jonen |
26 |
// + added function 'toHTML()', for deep asci_2_html encoding (using htmlentities() ) |
27 |
// |
28 |
// Revision 1.1 2002/11/12 05:42:30 joko |
29 |
// + initial checkin |
30 |
// |
31 |
// ------------------------------------------------------------------------- |
32 |
|
33 |
|
34 |
/** |
35 |
* --- Data::Encode |
36 |
* |
37 |
* @author Andreas Motl <andreas.motl@ilo.de> |
38 |
* @package org.netfrag.glib |
39 |
* @subpackage Data |
40 |
* @name Data::Encode |
41 |
* |
42 |
*/ |
43 |
class Data_Encode { |
44 |
|
45 |
var $payload; |
46 |
var $result; |
47 |
|
48 |
function Data_Encode(&$payload, $args = array()) { |
49 |
$this->payload = &$payload; |
50 |
} |
51 |
|
52 |
function &get() { |
53 |
return $this->payload; |
54 |
} |
55 |
|
56 |
function get_result() { |
57 |
return $this->result; |
58 |
} |
59 |
|
60 |
function toUTF8() { |
61 |
$this->_iso_2_utf8($this->payload, $this->result); |
62 |
} |
63 |
|
64 |
function toISO() { |
65 |
$this->_utf8_2_iso($this->payload, $this->result); |
66 |
} |
67 |
|
68 |
function toHTML() { |
69 |
$this->_asci_2_html($this->payload); |
70 |
} |
71 |
|
72 |
|
73 |
function _utf8_2_iso_OLD(&$payload) { |
74 |
if (is_array($payload)) { |
75 |
foreach ($payload as $key => $val) { |
76 |
if (is_array($payload[$key])) { |
77 |
$this->_utf8_2_iso($payload[$key]); |
78 |
} else { |
79 |
$this->_utf8_2_iso_scalar($payload[$key]); |
80 |
} |
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
function _iso_2_utf8_OLD(&$payload) { |
86 |
if (is_array($payload)) { |
87 |
foreach ($payload as $key => $val) { |
88 |
if (is_array($payload[$key])) { |
89 |
$this->_iso_2_utf8($payload[$key]); |
90 |
} else { |
91 |
$this->_iso_2_utf8_scalar($payload[$key]); |
92 |
} |
93 |
} |
94 |
} |
95 |
} |
96 |
|
97 |
function _utf8_2_iso(&$payload, &$result) { |
98 |
if (is_array($payload)) { |
99 |
foreach ($payload as $key => $val) { |
100 |
if (is_array($val)) { |
101 |
$this->_utf8_2_iso($val, $result[$key]); |
102 |
} else { |
103 |
$this->_utf8_2_iso_scalar($key); |
104 |
$this->_utf8_2_iso_scalar($val); |
105 |
$result[$key] = $val; |
106 |
} |
107 |
} |
108 |
} elseif (is_string($payload)) { |
109 |
$this->_utf8_2_iso_scalar($payload); |
110 |
$result = $payload; |
111 |
} |
112 |
} |
113 |
|
114 |
function _iso_2_utf8(&$payload, &$result) { |
115 |
if (is_array($payload)) { |
116 |
foreach ($payload as $key => $val) { |
117 |
if (is_array($val)) { |
118 |
$this->_iso_2_utf8($val, $result[$key]); |
119 |
} else { |
120 |
$this->_iso_2_utf8_scalar($key); |
121 |
$this->_iso_2_utf8_scalar($val); |
122 |
$result[$key] = $val; |
123 |
} |
124 |
} |
125 |
} elseif (is_string($payload)) { |
126 |
$this->_iso_2_utf8_scalar($payload); |
127 |
$result = $payload; |
128 |
} |
129 |
} |
130 |
|
131 |
function _utf8_2_iso_scalar(&$scalar) { |
132 |
$scalar = utf8_decode($scalar); |
133 |
} |
134 |
|
135 |
function _iso_2_utf8_scalar(&$scalar) { |
136 |
$scalar = utf8_encode($scalar); |
137 |
} |
138 |
|
139 |
function _asci_2_html_scalar(&$scalar) { |
140 |
$scalar = htmlentities( trim($scalar) ); |
141 |
} |
142 |
|
143 |
function _asci_2_html(&$payload) { |
144 |
if (is_array($payload)) { |
145 |
foreach ($payload as $key => $val) { |
146 |
if (is_array($payload[$key])) { |
147 |
$this->_asci_2_html($payload[$key]); |
148 |
} else { |
149 |
$this->_asci_2_html_scalar($payload[$key]); |
150 |
} |
151 |
} |
152 |
} |
153 |
} |
154 |
|
155 |
|
156 |
} |
157 |
|
158 |
?> |