From 2f5472519016b3092dea07d6f041b1cb74c3cd13 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Tue, 19 Jun 2018 16:35:15 +0100 Subject: Output the page head/header/footer with PHP Allows putting all the repeated stuff in one place (DRY!), so that if it needs changing it only needs to change once. Start the name of the included file with "@", and disallow the retrieval of files beginning with "@" (returning 404) so that it can't be downloaded, because it won't output anything meaningful. Why "@"? Because it's about the only ASCII punctuation character that doesn't mean anything special to most shells (bash), or programs, and is therefore easy to use as a filename on the command line. I almost went with "+", but it turns out that nvim treats arguments beginning with "+" as options. So "@" it is. --- apache2.conf | 4 ++++ html/@include.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ html/about | 22 ++++-------------- html/contact | 21 ++++-------------- html/index.php | 26 ++++------------------ html/privacy | 21 ++++-------------- html/projects/index.php | 21 ++++-------------- rawdog/page.template | 17 ++++---------- 8 files changed, 87 insertions(+), 104 deletions(-) create mode 100644 html/@include.php diff --git a/apache2.conf b/apache2.conf index fdf764a..7408ee8 100644 --- a/apache2.conf +++ b/apache2.conf @@ -157,6 +157,10 @@ RewriteCond %{LA-U:REQUEST_FILENAME} !-d RewriteRule !\. - [H=application/x-httpd-php] + # Disallow access to files/directories whose names begin with "@", returning a 404. + # This makes those files appear to not exist. + RewriteRule "/@" "-" [R=404,L] + AuthType Basic AuthName "Private area" diff --git a/html/@include.php b/html/@include.php new file mode 100644 index 0000000..2cf50d3 --- /dev/null +++ b/html/@include.php @@ -0,0 +1,59 @@ + elements for the site +function site_head($title) { + return "{$title}\n" + . "\n" + . "\n"; +} + +/// Get a single top-level navigation item for the site +function site_navitem($url, $text, $hide = false) { + $selected = $url == $_SERVER['REQUEST_URI']; + + $hbeg = $hide && !$selected ? '!--' : ''; + $hend = $hide && !$selected ? '--' : ''; + $sel = $selected ? ' class="selected"' : ''; + + return "<{$hbeg}li{$sel}>{$text}"; +} + +/// Get the standard page header elements for the site +function site_header($title) { + return "

{$title}

\n" + . "\n"; +} + +/// Get the standard page footer elements for the site +function site_footer() { + return "
\n" + . "

Spragg Software Services Ltd is registered in England, No. 11248242.\n" + . " Registered office: 82 Upper Hanover Street, Sheffield, S3 7RQ.\n" + . " VAT reg No. 295343283.

\n"; +} + +?> diff --git a/html/about b/html/about index b44e7b2..cace69a 100644 --- a/html/about +++ b/html/about @@ -1,8 +1,7 @@ - + - About - Spragg Software Services Ltd. - +