-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
134 lines (105 loc) · 4.86 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
#ini_set('display_errors', 1);
#ini_set('display_startup_errors', 1);
#error_reporting(E_ALL);
####################################
##
## This file (index.php) is essentially a 'routing' file.
## When you type in a url in the browser, this file points you towards the correct template and engine files for that url.
##
## Please correctly choose the $siteroot (in inc/settings.php file) before you start to edit this file.
##
## the structure of ProtoStack is as follows
##
## installation_directory/ - the name of the directory that you uploaded ProtoStack to
## .htaccess - ensures that ProtoStack resolves urls. Do not edit unless necessary
## index.php - this file. routes a requested url to the correct engine and template file.
## engine/
## home.php - this file contains code and variables that you show in the corresponding template file (home.tpl)
## example.php - code for a page that shows some of what you can do with UIkit
## another.php - code for a blank page for you to see how the routing works in this file.
## db-example.php - shows some examples of database operations.
## templates/
## home.tpl - the template that 'echos' variables created in home.php
## header.tpl - the <head> tag and navigation for the site
## footer.tpl - stuff you want at the bottom of each page
## example.tpl - a page that shows some of what you can do with UIkit
## another.tpl - some examples of how the template engine works.
## db-example.tpl - shows some examples of database operations.
##
## whatever files you add - must end with .tpl
## * note that files that end with '-.php' are dynamically generated in this folder. Do not delete them.
##
## inc/ - useful files including style.css, phd.class.php, and template.class.php
## db/ - the flat file database engine, 'PHD'.
##
####################################
# include all the include files required (inc/includes.php contains instructions to include any other files needed)
require('inc/includes.php');
#if this is the homepage
/*
if (count($path) == 0) {
$pageTemplate = 'home'; # name of template, minus the .tpl extension
# call the function that creates the detail for this page
fetchPageStuff($pageTemplate);
} */
if ($path[0] == 'http:'||$path[0] == 'https:') {
$pageTemplate = 'home'; # name of template, minus the .tpl extension
# call the function that creates the detail for this page
fetchPageStuff($pageTemplate);
}
#########
# if not viewing the homepage, what is the name of the directory/file that is used?
else {
if ($path[0] == 'example') {
$pageTemplate = 'example';
# call the function that creates the detail for this page
fetchPageStuff($pageTemplate);
}
#########
# Or is it another directory/file?
else if ($path[0] == 'another') {
$pageTemplate = 'another';
# call the function that creates the detail for this page
fetchPageStuff($pageTemplate);
}
#########
# A page showing examples of how the database works?
else if ($path[0] == 'db-example') {
$pageTemplate = 'db-example';
# call the function that creates the detail for this page
fetchPageStuff($pageTemplate);
}
else {
# if user looks for something that we haven't created, show a 404 error!
header("HTTP/1.0 404 Not Found");
echo "<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found.";
exit();
}
}
###############################################################################################
#this is used for canonical url tags in header markup
$current_url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$tpl->assign('url', $current_url);
## Display the template (load the visible webpage).
$tpl->display();
#this function does the heavy lifting for each page that we route above.
function fetchPageStuff(&$page) {
#global $page;
global $header;
global $footer;
global $fileContents;
global $tpl;
#these lines put the header on to the top of the template file, so that we only have to edit one version of the page header (header.tpl)
$header = file_get_contents('templates/header.tpl');
# same with footer
$footer = file_get_contents('templates/footer.tpl');
$fileContents = file_get_contents('templates/'.$page.'.tpl');
file_put_contents('templates/'.$page.'-.tpl', $header . $fileContents . $footer);
#put the home (in this case) template as the template in use now.
$tpl = new Template('templates/'.$page.'-.tpl');
#include the engine page that that runs php code for this template.
include('engine/'.$page.'.php');
}
?>