| 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.1 2003/02/03 14:49:37 joko Exp $ |
| 13 |
// ------------------------------------------------------------------------- |
| 14 |
// $Log: Encode.php,v $ |
| 15 |
// Revision 1.1 2003/02/03 14:49:37 joko |
| 16 |
// + initial commit |
| 17 |
// + refactored from flib/Application/i18n/TextEncode.php |
| 18 |
// |
| 19 |
// Revision 1.2 2003/02/03 03:40:02 jonen |
| 20 |
// + added function 'toHTML()', for deep asci_2_html encoding (using htmlentities() ) |
| 21 |
// |
| 22 |
// Revision 1.1 2002/11/12 05:42:30 joko |
| 23 |
// + initial checkin |
| 24 |
// |
| 25 |
// ------------------------------------------------------------------------- |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* --- Data::Encode |
| 30 |
* |
| 31 |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 32 |
* @package org.netfrag.glib |
| 33 |
* @subpackage Data |
| 34 |
* @name Data::Encode |
| 35 |
* |
| 36 |
*/ |
| 37 |
class Data_Encode { |
| 38 |
|
| 39 |
var $payload; |
| 40 |
|
| 41 |
function Data_Encode(&$payload, $args = array()) { |
| 42 |
$this->payload = &$payload; |
| 43 |
} |
| 44 |
|
| 45 |
function &get() { |
| 46 |
return $this->payload; |
| 47 |
} |
| 48 |
|
| 49 |
function toUTF8() { |
| 50 |
$this->_iso_2_utf8($this->payload); |
| 51 |
} |
| 52 |
|
| 53 |
function toISO() { |
| 54 |
$this->_utf8_2_iso($this->payload); |
| 55 |
} |
| 56 |
|
| 57 |
function toHTML() { |
| 58 |
$this->_asci_2_html($this->payload); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
function _utf8_2_iso(&$payload) { |
| 63 |
if (is_array($payload)) { |
| 64 |
foreach ($payload as $key => $val) { |
| 65 |
if (is_array($payload[$key])) { |
| 66 |
$this->_utf8_2_iso($payload[$key]); |
| 67 |
} else { |
| 68 |
$this->_utf8_2_iso_scalar($payload[$key]); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
function _iso_2_utf8(&$payload) { |
| 75 |
if (is_array($payload)) { |
| 76 |
foreach ($payload as $key => $val) { |
| 77 |
if (is_array($payload[$key])) { |
| 78 |
$this->_iso_2_utf8($payload[$key]); |
| 79 |
} else { |
| 80 |
$this->_iso_2_utf8_scalar($payload[$key]); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
function _utf8_2_iso_scalar(&$scalar) { |
| 87 |
$scalar = utf8_decode($scalar); |
| 88 |
} |
| 89 |
|
| 90 |
function _iso_2_utf8_scalar(&$scalar) { |
| 91 |
$scalar = utf8_encode($scalar); |
| 92 |
} |
| 93 |
|
| 94 |
function _asci_2_html_scalar(&$scalar) { |
| 95 |
$scalar = htmlentities( trim($scalar) ); |
| 96 |
} |
| 97 |
|
| 98 |
function _asci_2_html(&$payload) { |
| 99 |
if (is_array($payload)) { |
| 100 |
foreach ($payload as $key => $val) { |
| 101 |
if (is_array($payload[$key])) { |
| 102 |
$this->_asci_2_html($payload[$key]); |
| 103 |
} else { |
| 104 |
$this->_asci_2_html_scalar($payload[$key]); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
?> |