<?
/****************************************************************
* 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
if (isset($_GET['page']) && (file_exists($_GET['page'].'.txt'))) //If the url contains an existing filename
{
$filename = $_GET['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='.$file.'">'.$displayfile.'</a>'); //Otherwise send text and link
}
}
}
return $pagelinks;
}
?>
Das ist der code der Index.php
Ich hatte bisher nur die Zeile
array_push($pagelinks, '<a href="'.$PHP_SELF.'?page='.$file.'">'.$displayfile.'</a>'); //Otherwise send text and link
in
array_push($pagelinks, '<a href="'.$PHP_SELF.'?page='.str_replace(' ','_',$file).'">'.$displayfile.'</a>'); //Otherwise send text and link
geändert, dann wurden aber nur noch die Seiten geladen, bei der die txt Datei kein Leerzeichen enthielt.
Was müßte Deiner Meinung nach geändert werden das es funktioniert?
VG
Werner