Zur Navigation

URLS Suma freundlich gestalten per .htaccess [3]

%20 soll durch _ ersetzt werden + .html

21 Werner (Gast)

schau mal bitte hier: sharpei.bplaced.net

31.10.2010 00:36

22 Jörg Kruse

Auch die Seite ohne Unterstriche lädt die Homepage. War das vor allen Änderungen anders?

31.10.2010 00:42

23 Jörg Kruse

Probier's mal hier mit '%20' anstelle von ' ':

//Load filename from URL
$page = '';
if (isset($_GET['page'])) {
    $page = str_replace('_','%20',$GET['page']);
}
if ($page && file_exists($page.'.txt')) { //If the url contains an existing filename
    $filename = $page.'.txt';  //Load it
} else {
    $filename = 'index.txt';  //Otherwise, default to index.txt
    $htmltitle= 'Home';
}

31.10.2010 00:46

24 Werner (Gast)

ich habe den code ausgetauscht, ändert aber nichts :-(

31.10.2010 00:50

25 Jörg Kruse

Kannst du nochmal das gesamte Script, wie es jetzt ausschaut, posten?

31.10.2010 01:00

26 Werner (Gast)

<?
/****************************************************************
* 10kCMS - v1.0	- (C) 2006 Ethan Piliavin: Use it as you wish.	*
*      http://www.piliavin.com     				*
*								*
*	 - Some code and ideas were shamelessly 'borrowed' from:*
*		STD Page generation system TM (www.cockos.com)	*
*		STDWiki (C) 2005, Brandon Keely			*
*****************************************************************/

//Load filename from URL
$page = '';
if (isset($_GET['page'])) {
    $page = str_replace('_',' ',$GET['page']);
}
if ($page && file_exists($page.'.txt')) { //If the url contains an existing filename
    $filename = $page.'.txt';  //Load it
} else {
    $filename = 'index.txt';  //Otherwise, default to index.txt
    $htmltitle= 'Home';
}

//Load in the file contents
 $fp = fopen($filename,"r");
    if ($fp)
    {   
		//If a title exists, parse it from first line (Start title with ||)
		$firstline = fgets($fp);

		if (substr($firstline, 0, 7) == "[title]")
		{
			$htmltitle = trim(ltrim($firstline, "[title]"));
		}
		else //Otherwise just use the filename
		{	
			rewind($fp); //The first line wasnt a title, so we will need to reread it below as content
		
			$htmltitle = ucfirst(basename($filename, ".txt")); //Use filename as title
			
			//Make sure it doesnt display the ordering info part of the filename
			$ordertest = strstr($htmltitle, '---');
			
			if ($ordertest) //If the order string --- exists in the filename
			{
				$htmltitle = ucwords(substr($ordertest, 3)); //Cut it out and make the rest pretty
			}			
		}
				
		$x = fread($fp, filesize($filename));

		//Setup the search patterns for BBCode-Like Tags
		
            $patterns[0] = '/\[quote\](.+?)\[\/quote\]/is';
            $replacements[0] = '<blockquote>$1</blockquote>';

            $patterns[1] = '/\[sub\](.+?)\[\/sub\]/is';
            $replacements[1] = '<h2>$1</h2>';
            
            $patterns[2] = '/\[u\](.+?)\[\/u\]/is';
            $replacements[2] = '<u>$1</u>';

            $patterns[3] = '/\[b\](.+?)\[\/b\]/is';
            $replacements[3] = '<b>$1</b>';

            $patterns[4] = '/\[i\](.+?)\[\/i\]/is';
            $replacements[4] = '<i>$1</i>';
            
            $patterns[5] = '/\[c\](.+?)\[\/c\]/is';
            $replacements[5] = '<center>$1</center>';
            
            $patterns[6] = '/\[image:([^\]]*)\]/';
            $replacements[6] = '<img src ="$1"></img>';

            $patterns[7] = '/\[mail:([^\]]*)\|([^\]]*)\]/';
            $replacements[7] = '<a href="mailto:$1">$2</a>';

            $patterns[8] = '/\[mail:([^\]]*)\]/';
            $replacements[8] = '<a href="mailto:$1">$1</a>';

            $patterns[9] = '/\[link:([^\]]*)\|([^\]]*)\]/';
            $replacements[9] = '<a href="$1" target="_blank">$2</a>';

            $patterns[10] = '/\[link:([^\]]*)\]/';
            $replacements[10] = '<a href="$1" target="_blank">$1</a>';
            
            ksort($patterns);
            ksort($replacements);
			//Do the replacing
            $x = preg_replace($patterns, $replacements, $x);
            $x = str_replace("[line]", "<hr>", $x);
            $x = str_replace("\n\n", "<p>", $x);
            $x = str_replace("\n", "<br>", $x);
        fclose($fp);  //We are done reading the file!
    }
    
//Begin HTML output
echo "<!Doctype HTML>";
echo "<html><head><meta http-equiv='Content-Type' content='text/html;charset=utf-8'><title>$htmltitle</title>";
echo '<link rel="stylesheet" type="text/css" href="template.css" />';
echo "</head><body>";

//PAGE CONTAINER - OPEN
echo '<div id="container">';

//TOP HEADER
echo '<div id="top"><h1>'.$htmltitle.'</h1></div>';

//NAVIGATION SECTION
echo '<div id="nav">';
    //Loop and output menulinks as unordered list
    echo '<p> <ul id="navlinks">';

    foreach (menulinks() as $link)
    {
    	echo '   <li>'.$link.'</li>';
    }
    echo '</ul></p>';
echo "</div>";

//CONTENT SECTION
echo '<div id="content">';

  //Output the actual textfile
  echo "<p>";
  echo $x; 
  echo '</p>';
echo "</div>";

//FOOTER
echo '<div id="footer">';
echo 'Page last updated on '.date("l, dS F, Y @ h:ia", filemtime($filename)).'. Generated by <a href="http://www.10kcms.com" alt="Simple 10k Single File CMS">10kCMS.</a>';
echo "</div>";

//PAGE CONTAINER - CLOSE
echo "</div>";

//HIDDEN MESSAGE - FREE ADVERTISING!!
echo "<!-- This page was generated by 10kCMS - www.10kCMS.com --> ";

//End HTML output
echo "</BODY></HTML>";

//Function to extract the links and their order from other textfiles in the same folder
function menulinks()
{
	if (($_GET['page'] == 'index') || (!$_GET['page']))  //If we have loaded the index page
	{
		$pagelinks = array('Home');		//Then add the text 'Home' without any link
	}
	else		//Otherwise we must be on a different page
	{
		$pagelinks = array('<a href="'.$PHP_SELF.'?page=index">Home</a>');	//so we must always include the Home link
	}
	
	$files = glob("*.txt"); //Load all the text filenames in this folder
	sort($files);	//Alphebetize the names
	
	
	//Process the filenames (remove ordering info and generate the text and url in an array
	 foreach ($files as $file)
     {
			if (($file != "index.txt") && ($file != "robots.txt")) //Already took care of index, and exclude search engine file from menu
			{
				$file = basename($file, ".txt"); //Remove the .txt from the filenames
        
				// Remove the ordering info from filenames for menu text display
				$ordertest = strstr($file, '---');  //Find location of --- in the filename
				if ($ordertest) //If --- exists in the filename
				{
					$displayfile = substr($ordertest, 3); // we need to remove it
				} 
				else 	//Otherwise there must be no ordering information
				{
					$displayfile = $file;  //So the filename can be used as is
				}
			
				if ( $_GET['page'] == $file ) //If this file is the page that we loaded
				{
					array_push($pagelinks, $displayfile); // then only send text, no link
				}
				else
				{
					array_push($pagelinks, '<a href="'.$PHP_SELF.'?page='.str_replace(' ','_',$file).'">'.$displayfile.'</a>'); //Otherwise send text and link
				}
			}
	}
	return $pagelinks;	
}

?>

Das ist jetzt ohne die letzte Änderung mit dem %20

31.10.2010 01:01

27 Jörg Kruse

Ja, ich hab den - von mir verbrockten - Fehler gefunden. In dem zweiten $_GET fehlte der Unterstrich :( So sollte es hoffentlich funktionieren:

if (isset($_GET['page']) {
    $page = str_replace('_',' ',$_GET['page']);
}

31.10.2010 01:29 | geändert: 31.10.2010 01:30

28 Werner (Gast)

Guten Morgen Jörg,

Du hast es wirklich hingekriegt, jetzt funktioniert es tadellos. Vielen Dank für Deinen Einsatz und Deine Mühe :-)

schönen Sonntag
Werner

31.10.2010 08:09

29 Werner (Gast)

Hallo Jörg,

ich hatte noch den folgenden Code von Dir eingefügt, damit die aktuelle Seite im Menü als nur Text ohne Link erscheint

if ( $page == $file ) //If this file is the page that we loaded

leider funktioniert das aber nicht. Hast Du da vielleicht auch noch eine Idee?

VG
Werner

31.10.2010 17:30

30 Jörg Kruse

Der Abschnitt befinde sich innerhalb einer Funktionsdefinition - man muss die Variable $page dort erst verfügbar machen:

//Function to extract the links and their order from other textfiles in the same folder
function menulinks()
{
	global $page;
	if (($_GET['page'] == 'index') || (!$_GET['page']))  //If we have loaded the index page
	{
		$pagelinks = array('Home');		//Then add the text 'Home' without any link
	}

31.10.2010 18:07 | geändert: 31.10.2010 18:08