This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
69 lines (57 loc) · 2.1 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
<?php
// Exceptions for local testing.
if ($_SERVER['HTTP_HOST'] == 'localhost') {
date_default_timezone_set('America/Los_Angeles');
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
}
// The user has moved or renamed the all important 'config.ini' file.
if (!file_exists(__DIR__.'/config.ini') && !file_exists(__DIR__.'/demo.config.ini')) {
exit(
'Failed to locate a configuration file! Ensure that "config.ini" is in the same folder as the "index.php" file. Perhaps you have moved or renamed the file?'
);
}
if (!file_exists(__DIR__.'/config.ini')) {
$config = parse_ini_file(__DIR__.'/demo.config.ini');
} else {
$config = parse_ini_file(__DIR__.'/config.ini');
}
// $section is the app's main 'route'.
// We tidy this in .htaccess for clean URLs.
$section = FALSE;
if (isset($_GET['section'])) {
$section = $_GET['section'];
}
/**
* Define autoloader.
* @param string $class_name
*/
spl_autoload_register(function($class_name) {
require_once('./classes/class.'.$class_name.'.inc');
});
// Include all helper functions.
require_once('./inc/functions.inc');
$sections_path = $config['demo_mode'] ? '/_demo.sections' : '/_sections';
// Get all of our portfolio sections.
$portfolio_sections_with_ordinal = [];
$portfolio_sections = [];
foreach (glob(__DIR__.'/'.$sections_path.'/*', GLOB_ONLYDIR) as $section_path) {
$base_section_path = basename($section_path);
$portfolio_sections_with_ordinal[] = $base_section_path;
$portfolio_sections[] = removeOrdinalDelimiters($base_section_path);
}
// Check if we have an invalid section.
if ($section && !in_array(dashesToSpaces($section), $portfolio_sections)) {
// If we have an invalid section requested, send a 404 and exit.
header('HTTP/1.0 404 Not Found');
echo (file_get_contents('404.html'));
exit();
}
// We will pass this path to our Section class.
$section_id = array_search(dashesToSpaces($section), $portfolio_sections);
$true_section_path = '.'.$sections_path.'/'.$portfolio_sections_with_ordinal[$section_id];
// We all good cuz. Let's get this party started!
require_once(__DIR__.'/inc/template.inc');
?>