00001 <?php
00002
00014 class JuelichString {
00015
00023 function
trimFloat($theString) {
00024
if (strpos($theString,
'.' ) == 0) {
00025
return $theString;
00026 }
00027 $cut = 0;
00028 $point = 0;
00029
for ($i = strlen($theString) - 1; $i >= 0; --$i) {
00030
if ($theString[$i] !=
'0' && $cut == 0) {
00031 $cut = $i;
00032 }
00033
if ($theString[$i] ==
'.') {
00034 $point = $i;
00035 }
00036 }
00037
if ($cut == $point) {
00038
return substr($theString, 0, $cut);
00039 }
00040
else {
00041
return substr($theString, 0, $cut + 1);
00042 }
00043 }
00044
00053 function
convertPoint($theString, $mode = 0) {
00054
switch ($mode) {
00055
case 0:
00056 $theString = str_replace(
',',
'.', $theString);
00057
break;
00058
case 1:
00059 $theString = str_replace(
'.',
',', $theString);
00060
break;
00061 }
00062
return $theString;
00063 }
00064
00073 function
formatPrice($raw, $l10n) {
00074
if (empty($raw)) {
00075
switch( $l10n ) {
00076
case 2:
00077
return 'Demander le prix';
00078
break;
00079
case 3:
00080
return 'Ask the price';
00081
break;
00082
default:
00083
return 'Preis auf Anfrage';
00084 }
00085 }
00086
00087 $price = '';
00088 $raw = $this->
trimFloat($raw);
00089 $p = sprintf('%.2f', $raw);
00090 $p = $this->
convertPoint($p, 1);
00091
00092
if (($p / 10000) >= 1) {
00093 $price = substr($p, 0, 2) .
'.' . substr($p, 2);
00094 }
00095 elseif (($p / 1000) >= 1) {
00096 $price = $p[0] .
'.' . substr($p, 1);
00097 }
00098
else {
00099 $price = $p;
00100 }
00101 $price .= ' €';
00102
return $price;
00103 }
00104
00113 function
makeSortName($name) {
00114 $pattern = '/(\d+)/e';
00115 $replace =
"sprintf(\"%05d\", '\\1')";
00116
return preg_replace($pattern, $replace, $name);
00117 }
00118
00126 function
text_k($lang) {
00127 $grenze1 = 200;
00128 $grenze2 = 180;
00129
00130
if (strlen($lang) < $grenze1) {
00131
return $lang;
00132 }
00133
00134 $max = strpos($lang,
'.', $grenze2);
00135
if ($max < $grenze1 && $max != 0) {
00136
return substr($lang, 0, $max);
00137 }
00138
00139 $max = strpos($lang,
' ', $grenze2);
00140
return substr($lang, 0, $max);
00141 }
00142
00150 function
getTimeString($value) {
00151
return strftime('%d.%m.%y, %H:%M', $value);
00152 }
00153
00161 function
getL10nName($
id) {
00162 include_once
TM_PATH . 'constants.php';
00163
switch ($id) {
00164
case L_DEUTSCH:
00165
return 'Deutsch';
00166
case L_FRANZ:
00167
return 'Französisch';
00168
case L_ENG:
00169
return 'Englisch';
00170
case 0:
00171
return 'Sprachunabhängig';
00172
default:
00173
return 'Unbekannte Sprache';
00174 }
00175
return;
00176 }
00177
00187 function
encodeSpecials(&$theString, $flag = 0) {
00188
switch($flag) {
00189
case 0:
00190 $theString = str_replace(' ', '§nbsp§', $theString);
00191 $theString = str_replace('€', '§euro§', $theString);
00192
break;
00193
default:
00194 $theString = str_replace('§nbsp§', ' ', $theString);
00195 $theString = str_replace('§euro§', '€', $theString);
00196
break;
00197 }
00198
return $theString;
00199 }
00200
00209 function
ugly2Pretty($theString) {
00210 $theString = preg_replace(
"/\*|\(|\)|\\\|\/|\"|\&.*?;|Ø/", '', $theString);
00211 $theString = str_replace(
' ',
'_', $theString);
00212 $theString = str_replace(
'Ä', 'Ae', $theString);
00213 $theString = str_replace(
'ä', 'ae', $theString);
00214 $theString = str_replace(
'Ö', 'Oe', $theString);
00215 $theString = str_replace(
'ö', 'oe', $theString);
00216 $theString = str_replace(
'Ü', 'Ue', $theString);
00217 $theString = str_replace(
'ü', 'ue', $theString);
00218 $theString = str_replace(
'ß', 'ss', $theString);
00219
return strtolower($theString);
00220 }
00221
00222 }
00223
00224 ?>