From 2f5b8734c4723a699ad5f3b049d80d7f15d2175c Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sat, 28 Jun 2014 15:13:12 +0200 Subject: [PATCH] Worked out a class to easily include subpages/content and put the footer in a function --- content.php | 35 ++++++++++++++++++++ content/about.html | 4 +++ content/contact.html | 6 ++++ includes/dbconnect.php | 4 +-- includes/htmlcode.php | 12 +++++++ includes/miscfunc.php | 8 +++++ index.php | 74 +++++++++++++++++++++++++++++++----------- 7 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 content.php create mode 100644 content/about.html create mode 100644 content/contact.html create mode 100644 includes/miscfunc.php diff --git a/content.php b/content.php new file mode 100644 index 0000000..37d8534 --- /dev/null +++ b/content.php @@ -0,0 +1,35 @@ +name = $name; + $this->filename = $filename; + } + + public function createPage() + { + include ("{$contentFolder}{$this->filename}.html"); + } + + public function createMenuItem() + { + // Match just the name, without the .html, .php etc parc + preg_match_all("/[a-z_\-0-9]*/i", $this->filename, $out); + $bareFilename = $out[0][0]; + + // Print the menu item + print ("
  • " . + $this->name . "
  • \n"); + } + + public function getName() + { + return $this->name; + } +} + +?> diff --git a/content/about.html b/content/about.html new file mode 100644 index 0000000..ff1a7e4 --- /dev/null +++ b/content/about.html @@ -0,0 +1,4 @@ +

    About

    +

    +This is my blog about everything and nothing, please enjoy! +

    diff --git a/content/contact.html b/content/contact.html new file mode 100644 index 0000000..bc99cbf --- /dev/null +++ b/content/contact.html @@ -0,0 +1,6 @@ +

    Contact

    +

    +Please feel free to contact me at name@example.tld +

    + + diff --git a/includes/dbconnect.php b/includes/dbconnect.php index c79d11d..f1b9d5f 100644 --- a/includes/dbconnect.php +++ b/includes/dbconnect.php @@ -3,10 +3,10 @@ require "config.php"; // Connect to MySQL database $link = mysql_connect($host, $user, $password) - or die("Could not connect..."); + or terminate("Could not connect..."); mysql_select_db($database) - or die("Could not open database"); + or terminate("Could not open database"); ?> diff --git a/includes/htmlcode.php b/includes/htmlcode.php index f084c18..133e862 100644 --- a/includes/htmlcode.php +++ b/includes/htmlcode.php @@ -15,4 +15,16 @@ function end_html() print "\n\n\n\n"; } +function footer() +{ + print " + +
    +

    © 2014 - Jack-Benny Persson

    +
    + + + +"; +} ?> diff --git a/includes/miscfunc.php b/includes/miscfunc.php new file mode 100644 index 0000000..a74dd99 --- /dev/null +++ b/includes/miscfunc.php @@ -0,0 +1,8 @@ + diff --git a/index.php b/index.php index df7a9eb..6bc3122 100644 --- a/index.php +++ b/index.php @@ -18,6 +18,19 @@ --> + @@ -35,10 +48,12 @@ - -