-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
82 lines (69 loc) · 1.78 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Displays site name.
*/
function site_name()
{
echo config('name');
}
/**
* Displays site url provided in config.
*/
function site_url()
{
echo config('site_url');
}
/**
* Displays site version.
*/
function site_version()
{
echo config('version');
}
/**
* Website navigation.
*/
function nav_menu($sep = ' | ')
{
$nav_menu = '';
$nav_items = config('nav_menu');
foreach ($nav_items as $uri => $name) {
$query_string = str_replace('page=', '', $_SERVER['QUERY_STRING'] ?? '');
$class = $query_string == $uri ? ' active' : '';
$url = config('site_url') . '/' . (config('pretty_uri') || $uri == '' ? '' : '?page=') . $uri;
// Add nav item to list. See the dot in front of equal sign (.=)
$nav_menu .= '<a href="' . $url . '" title="' . $name . '" class="item ' . $class . '">' . $name . '</a>' . $sep;
}
echo trim($nav_menu, $sep);
}
/**
* Displays page title. It takes the data from
* URL, it replaces the hyphens with spaces and
* it capitalizes the words.
*/
function page_title()
{
$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 page_content()
{
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$path = getcwd() . '/' . config('content_path') . '/' . $page . '.phtml';
if (! file_exists($path)) {
$path = getcwd() . '/' . config('content_path') . '/404.phtml';
}
echo file_get_contents($path);
}
/**
* Starts everything and displays the template.
*/
function init()
{
require config('template_path') . '/template.php';
}