Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 519)
+++ trunk/CHANGELOG	(revision 520)
@@ -11,6 +11,8 @@
 ! = Update/Change
 
 ------------------------------------- 2.7.0 -------------------------------------
+09-Jan-2008 Matthias Gallas
+#	Fixed ticket #542 (Thanks to Thorn)
 23-Dec-2007 Matthias Gallas
 !	Changed all copyright notices to include now 2008
 21-Sep-2007 Matthias Gallas
Index: trunk/wb/framework/functions.php
===================================================================
--- trunk/wb/framework/functions.php	(revision 519)
+++ trunk/wb/framework/functions.php	(revision 520)
@@ -879,7 +879,8 @@
 function page_filename($string) {
 	$string = entities_to_7bit(umlauts_to_entities($string));
 	// Now replace spaces with page spcacer
-	$string = str_replace(' ', PAGE_SPACER, $string);
+	$string = trim($string);
+	$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
 	// Now remove all bad characters
 	$bad = array(
 	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
@@ -892,12 +893,6 @@
 	$string = str_replace($bad, '', $string);
 	// Now convert to lower-case
 	$string = strtolower($string);
-	// Now remove multiple page spacers
-	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
-	// Clean any page spacers at the end of string
-	$string = str_replace(PAGE_SPACER, ' ', $string);
-	$string = trim($string);
-	$string = str_replace(' ', PAGE_SPACER, $string);
 	// If there are any weird language characters, this will protect us against possible problems they could cause
 	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
 	// Finally, return the cleaned string
