Changeset 5200 for trunk/include/functions.inc.php
- Timestamp:
- Mar 20, 2010, 9:59:54 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions.inc.php
r5196 r5200 33 33 34 34 //----------------------------------------------------------- generic functions 35 function get_extra_fields($order_by_fields) 36 { 37 $fields = str_ireplace(array(' order by ', ' desc', ' asc'), 35 function get_extra_fields($order_by_fields) 36 { 37 $fields = str_ireplace(array(' order by ', ' desc', ' asc'), 38 38 array('', '', ''), 39 39 $order_by_fields 40 40 ); 41 41 if (!empty($fields)) 42 { 42 { 43 43 $fields = ','.$fields; 44 44 } … … 415 415 list($language_name) = @file($path.'/iso.txt'); 416 416 417 $langdef = explode('.',$file); 418 if (count($langdef)>1) // (langCode,encoding) 419 { 420 $langdef[1] = strtolower($langdef[1]); 421 422 if ( 423 $target_charset==$langdef[1] 424 or 425 ($target_charset=='utf-8' and $langdef[1]=='iso-8859-1') 426 or 427 ($target_charset=='iso-8859-1' and 428 in_array( substr($langdef[0],2), array('en','fr','de','es','it','nl'))) 429 ) 430 { 431 $language_name = convert_charset($language_name, 432 $langdef[1], $target_charset); 433 $languages[ $langdef[0] ] = $language_name; 434 } 435 else 436 continue; // the language encoding is not compatible with our charset 437 } 438 else 439 { // UTF-8 440 $language_name = convert_charset($language_name, 441 'utf-8', $target_charset); 442 $languages[$file] = $language_name; 443 } 417 $languages[$file] = convert_charset($language_name, $target_charset); 444 418 } 445 419 } … … 730 704 // plugins want remove some themes based on user status maybe? 731 705 $themes = trigger_event('get_pwg_themes', $themes); 732 706 733 707 return $themes; 734 708 } … … 1241 1215 } 1242 1216 $target_charset = strtolower($target_charset); 1243 $source_charset = '';1244 1217 $source_file = ''; 1245 1218 foreach ($languages as $language) 1246 1219 { 1247 $dir = $dirname.$language; 1248 1249 if ($target_charset!='utf-8') 1250 { 1251 // exact charset match - no conversion required 1252 $f = $dir.'.'.$target_charset.'/'.$filename; 1253 if (file_exists($f)) 1254 { 1255 $source_file = $f; 1256 break; 1257 } 1258 } 1259 1260 // UTF-8 ? 1261 $f = $dir.'/'.$filename; 1220 $f = $dirname.$language.'/'.$filename; 1262 1221 if (file_exists($f)) 1263 1222 { 1264 $source_charset = 'utf-8';1265 1223 $source_file = $f; 1266 1224 break; … … 1280 1238 if ( !isset($lang_info) ) $lang_info=array(); 1281 1239 1282 if ( !empty($source_charset) and $source_charset!=$target_charset)1240 if ( 'utf-8'!=$target_charset) 1283 1241 { 1284 1242 if ( is_array($load_lang) ) … … 1288 1246 if ( is_array($v) ) 1289 1247 { 1290 $func = create_function('$v', 'return convert_charset($v, "'.$ source_charset.'","'.$target_charset.'");' );1248 $func = create_function('$v', 'return convert_charset($v, "'.$target_charset.'");' ); 1291 1249 $lang[$k] = array_map($func, $v); 1292 1250 } 1293 1251 else 1294 $lang[$k] = convert_charset($v, $ source_charset, $target_charset);1252 $lang[$k] = convert_charset($v, $target_charset); 1295 1253 } 1296 1254 } … … 1299 1257 foreach ($load_lang_info as $k => $v) 1300 1258 { 1301 $lang_info[$k] = convert_charset($v, $ source_charset, $target_charset);1259 $lang_info[$k] = convert_charset($v, $target_charset); 1302 1260 } 1303 1261 } … … 1313 1271 { 1314 1272 $content = @file_get_contents($source_file); 1315 if ( !empty($source_charset) and $source_charset!=$target_charset) 1316 { 1317 $content = convert_charset($content, $source_charset, $target_charset); 1318 } 1273 $content = convert_charset($content, $target_charset); 1319 1274 return $content; 1320 1275 } … … 1324 1279 1325 1280 /** 1326 * converts a string from acharacter set to another character set1281 * converts a string from utf-8 character set to another character set 1327 1282 * @param string str the string to be converted 1328 * @param string source_charset the character set in which the string is encoded1329 1283 * @param string dest_charset the destination character set 1330 1284 */ 1331 function convert_charset($str, $source_charset, $dest_charset) 1332 { 1333 if ($source_charset==$dest_charset) 1285 function convert_charset($str, $dest_charset) 1286 { 1287 if ($dest_charset=='utf-8') 1288 { 1334 1289 return $str; 1335 if ($source_charset=='iso-8859-1' and $dest_charset=='utf-8') 1336 { 1337 return utf8_encode($str); 1338 } 1339 if ($source_charset=='utf-8' and $dest_charset=='iso-8859-1') 1290 } 1291 if ($dest_charset=='iso-8859-1') 1340 1292 { 1341 1293 return utf8_decode($str); … … 1343 1295 if (function_exists('iconv')) 1344 1296 { 1345 return iconv( $source_charset, $dest_charset, $str);1297 return iconv('utf-8', $dest_charset, $str); 1346 1298 } 1347 1299 if (function_exists('mb_convert_encoding')) 1348 1300 { 1349 return mb_convert_encoding( $str, $dest_charset, $source_charset);1301 return mb_convert_encoding( $str, $dest_charset, 'utf-8' ); 1350 1302 } 1351 1303 return $str; //???
Note: See TracChangeset
for help on using the changeset viewer.