Project

General

Profile

« Previous | Next » 

Revision 452

Added by Matthias about 17 years ago

again copied all changes for WB 2.6.6 from trunk to branches

View differences:

functions.php
338 338
	return $subs;
339 339
}
340 340

  
341
// Function as replecement for php's htmlspecialchars()
342
function my_htmlspecialchars($string) {
343
	$string = umlauts_to_entities($string);
344
	$string = entities_to_umlauts($string);
345
	return($string);
346
}
347

  
348
// Function to convert a string from $from- to $to-encoding, using mysql
349
function my_mysql_iconv($string, $from, $to) {
350
	// keep current character set values:
351
	$character_set_database = mysql_result(mysql_query("SELECT @@character_set_client"),0,0);
352
	$character_set_results = mysql_result(mysql_query("SELECT @@character_set_results"),0,0);
353
	$collation_results = mysql_result(mysql_query("SELECT @@collation_connection"),0,0);
354
	mysql_query("SET character_set_client=$from");
355
	mysql_query("SET character_set_results=$to");
356
	mysql_query("SET collation_connection=utf8_unicode_ci");
357
	$string_escaped = mysql_real_escape_string($string);
358
	$converted_string = mysql_result(mysql_query("SELECT '$string_escaped'"),0,0);
359
	// restore previous character set values:
360
	mysql_query("SET character_set_client=$character_set_database");
361
	mysql_query("SET character_set_results=$character_set_results");
362
	mysql_query("SET collation_connection=$collation_results");
363
	return $converted_string;
364
}
365

  
366
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
367
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
368
	$charset = strtoupper($charset);
369
	if ($charset == '') { $charset = 'ISO-8859-1'; }
370

  
371
	// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
372
	if ($charset == "GB2312") {
373
		$string=my_mysql_iconv($string, 'gb2312', 'utf8');
374
	} elseif ($charset == "ISO-8859-11") {
375
		$string=my_mysql_iconv($string, 'tis620', 'utf8');
376
	} else {
377
		$string=mb_convert_encoding($string, 'UTF-8', $charset);
378
	}
379
	$string=mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
380
	$string=mb_convert_encoding($string, 'UTF-8', 'HTML-ENTITIES');
381
	return($string);
382
}
383

  
384
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
385
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
386
	$charset_out = strtoupper($charset_out);
387
	if ($charset_out == '') {
388
		$charset_out = 'ISO-8859-1';
389
	}
390
	$string = string_to_utf8($string);
391
	if($charset_out != 'UTF-8') {
392
		if ($charset_out == "GB2312") {
393
			$string=my_mysql_iconv($string, 'utf8', 'gb2312');
394
		} elseif ($charset_out == "ISO-8859-11") {
395
			$string=my_mysql_iconv($string, 'utf8', 'tis620');
396
		} else {
397
			$string=mb_convert_encoding($string, $charset_out, 'UTF-8');
398
		}
399
	}
400
	if($convert_htmlspecialchars == 1) {
401
		$string=htmlspecialchars($string);
402
	}
403
	return($string);
404
}
405

  
406
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
407
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET, $convert_htmlspecialchars=1) {
408
	$charset_in = strtoupper($charset_in);
409
	if ($charset_in == "") {
410
		$charset_in = 'ISO-8859-1';
411
	}
412
	$string = string_to_utf8($string, $charset_in);
413
	if($convert_htmlspecialchars == 1) {
414
		$string=htmlspecialchars($string,ENT_QUOTES);
415
	}
416
	$string=mb_convert_encoding($string,'HTML-ENTITIES','UTF-8');
417
	return($string);
418
}
419

  
420
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
421
function entities_to_7bit($string) {
422
	require(WB_PATH.'/framework/convert.php');
423
	$string = strtr($string, $conversion_array);
424
	return($string);
425
}
426

  
341 427
// Function to convert a page title to a page filename
342 428
function page_filename($string) {
343
	// First, translate any non-english characters to their english equivalents
344
	require(WB_PATH.'/framework/convert.php');
345
   $string = strtr($string, $conversion_array);
429
	$string = entities_to_7bit(umlauts_to_entities($string));
346 430
	// Now replace spaces with page spcacer
347 431
	$string = str_replace(' ', PAGE_SPACER, $string);
348 432
	// Now remove all bad characters
......
371 455

  
372 456
// Function to convert a desired media filename to a clean filename
373 457
function media_filename($string) {
374
	// First, translate any non-english characters to their english equivalents
375
	require(WB_PATH.'/framework/convert.php');
376
   $string = strtr($string, $conversion_array);
458
	$string = entities_to_7bit(umlauts_to_entities($string));
377 459
	// Now remove all bad characters
378 460
	$bad = array(
379 461
	'\'', // '
......
667 749
	$directory = WB_PATH.PAGES_DIRECTORY.$link;
668 750
	$filename = $directory.'.php';
669 751
	$directory .= '/';
670
	if(file_exists($filename)) {
752
	if(file_exists($filename) && substr($filename,0,1<>'.')) {
671 753
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
672 754
			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
673 755
		} else {

Also available in: Unified diff