Moved content.php to includes dir, created a 404-page and a last resort to a default page (404)

This commit is contained in:
Jack-Benny Persson 2014-06-30 19:55:06 +02:00
parent c29b964215
commit bbccef275e
4 changed files with 20 additions and 3 deletions

5
content/404.html Normal file
View File

@ -0,0 +1,5 @@
<h2>404 - Page not found</h2>
<p>
<a href="index.php">Back to blog</a>
</p>

View File

@ -21,6 +21,11 @@ class Page
$this->name . "</a></li>\n");
}
public function getFile()
{
return $this->filename;
}
// For future-uses...
public function getName()
{

View File

@ -19,7 +19,7 @@
-->
<?php
require ("content.php");
require ("includes/content.php");
require ("includes/htmlcode.php");
require ("includes/config.php");
require ("includes/miscfunc.php");
@ -28,6 +28,7 @@ require ("includes/miscfunc.php");
First argument is the name of link as it should appear in the menu, second
argument is the filename of file in content/ without directory, slashed etc.
*/
$pageNotFound = new Page("404", "404.html");
$aboutPage = new Page("About", "about.html");
$contactPage = new Page("Contact", "contact.html");
?>
@ -69,6 +70,8 @@ $contactPage = new Page("Contact", "contact.html");
if (isset($_GET['content']))
{
$content = $_GET['content'];
// Function to remove directories
function nodir($item)
{
return (!is_dir(Page::$contentFolder . $item));
@ -78,14 +81,18 @@ $contactPage = new Page("Contact", "contact.html");
$files = (array_filter($dirContent, "nodir"));
// Iterate through all the files for a match (from ?content=)
foreach($files as $file)
{
preg_match_all("/[a-z_\-0-9]*/i", $file, $withoutExt);
if ($withoutExt[0][0] == $content)
{
include (Page::$contentFolder . $file);
terminate();
}
}
// If no match was found, display a default page (here 404)
include (Page::$contentFolder . $pageNotFound->getFile());
terminate();
}
// Subpage content ends

View File

@ -92,13 +92,13 @@ body
a:link
{
color:#000000;
text-decoration:none;
text-decoration:underline;
}
a:hover
{
color:#000000;
text-decoration:underline;
text-decoration:none;
}
a:visited