forked from banago/simple-php-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
49 lines (42 loc) · 925 Bytes
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Used to store different static data.
*
* @var array
*/
$config = [
'name' => 'Simple PHP Website',
];
/**
* Displays site name. Uses $config global.
*/
function siteName()
{
global $config;
echo $config['name'];
}
/**
* Displays page title. It takes the data from
* URL, it replaces the hyphens with spaces and
* it capitalizes the words.
*/
function pageTitle()
{
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'home';
echo ucwords(str_replace('-', ' ', $page));
}
/**
* Displays page content. It takes the data from
* the static pages inside the pages/ directory.
* When not found, display the 404 error page.
*/
function pageContent()
{
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$path = getcwd().'/pages/'.$page.'.php';
if (file_exists($path)) {
include $path;
} else {
include 'pages/404.php';
}
}