-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.php
107 lines (94 loc) · 2.81 KB
/
page.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
<?php
//get artifact to load
if (isset($_GET['v'])) {
if ($_GET['v']) {
$v = strtolower($_GET['v']);
} else $v = 'home';
} else {
$_GET['v'] = 'home';
$v = $_GET['v'];
}
ini_set('display_errors', 0);
require 'assets/private/parser.php';
require 'assets/private/artifact.php';
require 'assets/private/customartifact.php';
require 'assets/private/logcredentials.php';
require 'assets/private/loghelpers.php';
//name of directory for artifact declarations
$pageDirectory = 'pages';
//single parser for all artifacts
$parser = new Parser();
//array holding artifacts
$artifacts = array();
//creates and formats artifacts
createArtifacts();
formatArtifacts();
//load artifact
if (getArtifact($v) != null) {
$artifact = getArtifact($v);
} else if(substr($v, 0, 4) === "tag-") {
//check if looking at generated tag-artifact
$tag = substr($v, 4, strlen($v));
$tagCount = 0;
for ($i = 0; $i < sizeof($artifacts); $i++) {
if ($tagCount > 0) break;
if ($artifacts[$i]->hasTag($tag)) {
$tagCount++;
}
}
if ($tagCount > 0) {
//generate custom artifact
$artifact = new CustomArtifact();
$artifact->attributes['name'] = "Tagged: " . $tag;
$artifact->attributes['title'] = "Artifacts tagged with _[" . $tag . "].";
$artifact->attributes['content'] = '-[' . $tag . ']';
$artifact->path = ['home'];
$parser->firstFormat($artifact);
$parser->secondFormat($artifact);
} else {
//if attempt to create tag artifact results in no found entires, 404
redirect($v);
}
} else if (substr($v, 0, 4) === "404-") {
//if slashes remain, sanitize and redirect
if (strstr($v, '/')) {
redirect(substr($v, 4, $v.length));
}
//create 404
$name = substr($v, 4, $v.length);
$artifact = new CustomArtifact();
$artifact->attributes['name'] = "404 - " . $name;
$artifact->attributes['image'] = "404>1";
$artifact->attributes['image name'] = "#[404]";
$artifact->attributes['white'] = "true";
$artifact->attributes['title'] = "Artifact _[" . $name . "] not found.";
$artifact->attributes['content'] = "
Seems like #[LOGO] hasn't indexed _[" . $name . "] yet, sorry about that.
<br><br>
If you're lost, take a look at the #[index], or check out some of the #[projects].
<br><br>
If you think this page should exist, please contact me through my @[email>mailto:[email protected]].
";
$artifact->path = ['home'];
$parser->firstFormat($artifact);
$parser->secondFormat($artifact);
} else {
//if artifact doesn't exist, load 404
redirect($v);
}
//get template
ob_start();
include 'assets/private/template.php';
$page = ob_get_clean();
echo $page;
function redirect($search) {
$search = sanitize($search);
header('Location: https://v-os.ca/404-' . $search);
die();
}
function sanitize($string) {
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);
$string = htmlspecialchars($string, ENT_QUOTES);
return $string;
}
?>