prepend and append header and footer automatically

This commit is contained in:
Zdenek Borovec 2024-05-08 13:20:18 +02:00
parent baa5698557
commit e36ae0b4b8
16 changed files with 85 additions and 83 deletions

View file

@ -29,7 +29,17 @@ Anyways, let's get to the *how*.
- SQL_USERNAME - SQL_USERNAME
- SQL_PASSWORD - SQL_PASSWORD
- SQL_DATABASE - SQL_DATABASE
- Remember to enable pdo_mysql in yourr php.ini. - Changes to php.ini should include:
- adding the /docs/common/header.hp and /docs/common/footer.php as
the auto_prepend_file and auto_append_file
- Enabling the pdo_mysql extension
- Setting the file_uploads on and setting max upload (and post) size,
if you are going to make use of that function. Please note that it is
meant for admin use only and normal users shouldn't have access to it
as it is unprotected.
- Also make sure that the folder /assets/uploads/ exists and php has write
permissions there - if you are going to use that file upload
functionality, that is.
- If you have problems connecting to the database, you can try - If you have problems connecting to the database, you can try
printing the PDO exception being caught there in the function printing the PDO exception being caught there in the function
`attempt_sql_connect()`, but be careful not to leave it in production, as `attempt_sql_connect()`, but be careful not to leave it in production, as
@ -37,30 +47,13 @@ Anyways, let's get to the *how*.
- The basic skeleton for any document should be: - The basic skeleton for any document should be:
```php ```php
<?php <?php
// This makes for less typing while including the header and the footer. // Display the header with desired title.
// Absolute path to the commons folder.
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
// Include the common site-wide header.
include_once($COMMONS."/header.php");
// Display the header with desired title. This is a separate function for the
// cases where you want to set the title dynamically after doing some
// processing (which requires sql connection from the header for example).
// An example of this are the blogs, which first get their name from the
// databese, and only then display the header with the title being the name
// of the article.
display_header(<PAGETITLE>); display_header(<PAGETITLE>);
?> ?>
<!-- <!--
Your main content here, try to wrap it in <article> tags for nice padding Your main content here, try to wrap it in <article> tags for nice padding
--> -->
<?php
// Write out the footer and close the website.
include_once($COMMONS."/footer.php");
?>
``` ```
- Do check out the already existing css rules before adding your own, the rule - Do check out the already existing css rules before adding your own, the rule
for what you are trying to create might already exist. I might add a more for what you are trying to create might already exist. I might add a more

5
assets/.htaccess Normal file
View file

@ -0,0 +1,5 @@
# Custom error pages
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
ErrorDocument 504 /errors/504.php

17
assets/errors/403.php Normal file
View file

@ -0,0 +1,17 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("403: Forbidden");
?>
<article>
<h2>403: Forbidden</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/3e0cef92-8dad-4085-9db4-e9c8e1437e0a/c7ec620b-1666-4ab9-ad35-ad3daf1b53b2.png" alt="Internet meme image of a confused-looking cat with a text reading &quot;Hey you... What are you doing here??&quot;">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

17
assets/errors/404.php Normal file
View file

@ -0,0 +1,17 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("404: Not Found");
?>
<article>
<h2>404: Not Found</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/7316caee796b4cb280cc769ea5f852fa/32a6269147ce4c6c813d4f0449ae1da9/9f532c593d134c6dad5bc63684fe22c2" alt="GIF of a cat hiding in a cupboard">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

17
assets/errors/500.php Normal file
View file

@ -0,0 +1,17 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("500: Internal Server Error");
?>
<article>
<h2>500: Internal Server Error</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/bddac3669dd44acc8a41e2f935c94a3a/0c5f9e325ba34c02a24f53e50a1cc68d/62aa400be23d4c5ab3f6e2abe666d070" alt="GIF of a very confused cat.">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

17
assets/errors/503.php Normal file
View file

@ -0,0 +1,17 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("503: Service Unavailable");
?>
<article>
<h2>503: Service Unavailable</h2>
<div class="centered-container">
<img src="https://assets.zdenekborovec.cz/upload/db3181344f0249a09fbc2ba1096b35c4/4b974e9c1e214ea4ad57174a33aa1c4f/bb9d675f430f4fd8990fd3a993a7ee96" alt="GIF of a cat going to work in a cardboard box.">
</div>
</article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,8 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
class BlogpostComment class BlogpostComment
{ {
public $comment_id; public $comment_id;
@ -456,6 +452,4 @@ printf("
// Display the blog comments // Display the blog comments
$blogPost->display_comments(); $blogPost->display_comments();
include_once($COMMONS."/footer.php");
?> ?>

View file

@ -1,7 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Blogs"); display_header("Blogs");
/** /**
@ -106,6 +103,4 @@ function display_blog_previews(){
<?php <?php
display_blog_previews(); display_blog_previews();
include_once($COMMONS."/footer.php");
?> ?>

View file

@ -1,8 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Delete account"); display_header("Delete account");
// Error string for the content deletion confirmation // Error string for the content deletion confirmation
@ -163,5 +159,4 @@ else{
Please sign in to delete your account. Please sign in to delete your account.
</article>"); </article>");
} }
include_once($COMMONS."/footer.php");
?> ?>

View file

@ -1,8 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
// If the user does not have the 1000 0000 permission, // If the user does not have the 1000 0000 permission,
// throw a 403: Forbidden error. // throw a 403: Forbidden error.
if(!(bool)($_SESSION["current_user"]->permissions & 128)) { if(!(bool)($_SESSION["current_user"]->permissions & 128)) {
@ -44,7 +40,3 @@ if(isset($_POST["submit"])) {
<input name="userfile" type="file"> <input name="userfile" type="file">
<input name="submit" type="submit" value="Send File"> <input name="submit" type="submit" value="Send File">
</form> </form>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,7 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("About"); display_header("About");
?> ?>
@ -77,7 +74,3 @@ display_header("About");
Beauty is in the eye of the beholder and while I can appreciate this look is unusual, I really dig it. You are always free to make your own custom css for my site, of course. Hmm, now I am thinking about adding built-in customisation support, but that would require user settings, and having users makes no sense until theres some kind of user interaction like a forum, or article comments, or something like that. I will save that one for later. Beauty is in the eye of the beholder and while I can appreciate this look is unusual, I really dig it. You are always free to make your own custom css for my site, of course. Hmm, now I am thinking about adding built-in customisation support, but that would require user settings, and having users makes no sense until theres some kind of user interaction like a forum, or article comments, or something like that. I will save that one for later.
</p> </p>
</article> </article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,8 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Login"); display_header("Login");
// Define previous attempt and error variables and set to empty values. // Define previous attempt and error variables and set to empty values.
@ -131,7 +127,3 @@ if (isset($_POST["submit"])) {
<input name="submit" type="submit" tabindex="3" value="Send"> <input name="submit" type="submit" tabindex="3" value="Send">
</form> </form>
</article> </article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,7 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Privacy policy"); display_header("Privacy policy");
?> ?>

View file

@ -1,7 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Unit conversions"); display_header("Unit conversions");
?> ?>
@ -188,7 +185,3 @@ display_header("Unit conversions");
</tr> </tr>
</table> </table>
</article> </article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,7 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Random tools"); display_header("Random tools");
?> ?>
@ -15,7 +12,3 @@ display_header("Random tools");
</li> </li>
</ul> </ul>
</article> </article>
<?php
include_once($COMMONS."/footer.php");
?>

View file

@ -1,8 +1,4 @@
<?php <?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
display_header("Register"); display_header("Register");
// Define previous attempt and error variables and set to empty values. // Define previous attempt and error variables and set to empty values.
@ -221,7 +217,3 @@ if (isset($_POST["submit"])) {
you minimize this risk. you minimize this risk.
</p> </p>
</article> </article>
<?php
include_once($COMMONS."/footer.php");
?>