Moved content.php to includes dir, created a 404-page and a last resort to a default page (404)
This commit is contained in:
parent
c29b964215
commit
bbccef275e
5
content/404.html
Normal file
5
content/404.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<h2>404 - Page not found</h2>
|
||||||
|
<p>
|
||||||
|
<a href="index.php">Back to blog</a>
|
||||||
|
</p>
|
||||||
|
|
@ -21,6 +21,11 @@ class Page
|
|||||||
$this->name . "</a></li>\n");
|
$this->name . "</a></li>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFile()
|
||||||
|
{
|
||||||
|
return $this->filename;
|
||||||
|
}
|
||||||
|
|
||||||
// For future-uses...
|
// For future-uses...
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
-->
|
-->
|
||||||
<?php
|
<?php
|
||||||
require ("content.php");
|
require ("includes/content.php");
|
||||||
require ("includes/htmlcode.php");
|
require ("includes/htmlcode.php");
|
||||||
require ("includes/config.php");
|
require ("includes/config.php");
|
||||||
require ("includes/miscfunc.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
|
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.
|
argument is the filename of file in content/ without directory, slashed etc.
|
||||||
*/
|
*/
|
||||||
|
$pageNotFound = new Page("404", "404.html");
|
||||||
$aboutPage = new Page("About", "about.html");
|
$aboutPage = new Page("About", "about.html");
|
||||||
$contactPage = new Page("Contact", "contact.html");
|
$contactPage = new Page("Contact", "contact.html");
|
||||||
?>
|
?>
|
||||||
@ -69,6 +70,8 @@ $contactPage = new Page("Contact", "contact.html");
|
|||||||
if (isset($_GET['content']))
|
if (isset($_GET['content']))
|
||||||
{
|
{
|
||||||
$content = $_GET['content'];
|
$content = $_GET['content'];
|
||||||
|
|
||||||
|
// Function to remove directories
|
||||||
function nodir($item)
|
function nodir($item)
|
||||||
{
|
{
|
||||||
return (!is_dir(Page::$contentFolder . $item));
|
return (!is_dir(Page::$contentFolder . $item));
|
||||||
@ -78,14 +81,18 @@ $contactPage = new Page("Contact", "contact.html");
|
|||||||
|
|
||||||
$files = (array_filter($dirContent, "nodir"));
|
$files = (array_filter($dirContent, "nodir"));
|
||||||
|
|
||||||
|
// Iterate through all the files for a match (from ?content=)
|
||||||
foreach($files as $file)
|
foreach($files as $file)
|
||||||
{
|
{
|
||||||
preg_match_all("/[a-z_\-0-9]*/i", $file, $withoutExt);
|
preg_match_all("/[a-z_\-0-9]*/i", $file, $withoutExt);
|
||||||
if ($withoutExt[0][0] == $content)
|
if ($withoutExt[0][0] == $content)
|
||||||
{
|
{
|
||||||
include (Page::$contentFolder . $file);
|
include (Page::$contentFolder . $file);
|
||||||
|
terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If no match was found, display a default page (here 404)
|
||||||
|
include (Page::$contentFolder . $pageNotFound->getFile());
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
// Subpage content ends
|
// Subpage content ends
|
||||||
|
@ -92,13 +92,13 @@ body
|
|||||||
a:link
|
a:link
|
||||||
{
|
{
|
||||||
color:#000000;
|
color:#000000;
|
||||||
text-decoration:none;
|
text-decoration:underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover
|
a:hover
|
||||||
{
|
{
|
||||||
color:#000000;
|
color:#000000;
|
||||||
text-decoration:underline;
|
text-decoration:none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:visited
|
a:visited
|
||||||
|
Loading…
x
Reference in New Issue
Block a user