forked from adamdburton/pointshop-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
51 lines (37 loc) · 999 Bytes
/
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
<?php
/*
* This file is part of http://github.com/adamdburton/pointshop-documentation
*
* (c) Adam Burton <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if(!file_exists('./vendor/autoload.php'))
{
die('Run composer install!');
}
DEFINE('PS_DOCS', true);
require './vendor/autoload.php';
require './utils.php';
date_default_timezone_set('Europe/London');
$config = json_decode(file_get_contents('config.json'), true);
$uri = $_SERVER['REQUEST_URI'];
$tree = buildTree($uri);
$page = findInTree($uri, $tree);
if(is_array($page) && !$page['file'])
{
// findInTree returned an array but not a page, must be a folder
$first_child = current($page['children']);
if($first_child)
{
// Redirect to first child
header('Location: ' . $first_child['full_uri']);
}
else
{
// No first child found, 404
$page = null;
}
}
renderPage(preparePage($page), $uri);