-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathguideline.php
More file actions
80 lines (60 loc) · 1.44 KB
/
guideline.php
File metadata and controls
80 lines (60 loc) · 1.44 KB
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
<?php
$dr = str_replace($_SERVER['SCRIPT_NAME'], '/inc/', $_SERVER['SCRIPT_FILENAME']);
require_once($dr.'setup.php');
$categorys = require_once($dr . "data.php");
$cat_id = (isset($_GET['category']))? $_GET['category'] : false;
$guideline = (isset($_GET['guideline']))? $_GET['guideline'] : false;
$error = false;
if($guideline && $cat_id) {
$filename = "guideline/" . $cat_id . "-" . $guideline . ".txt";
$category = $categorys[$cat_id];
$handle = @fopen($filename, "r");
if ($handle) {
$text = fread($handle, filesize($filename));
fclose($handle);
$title = strtok($text, "\n");
$title = explode("# ", $title);
$title = $title[1];
$heading = $title;
$pattern = '/^(.*\n)/';
$replacement = '';
$text = preg_replace($pattern, $replacement, $text);
} else {
$error = true;
$heading = "That filename looks dodgy.";
}
} else {
$error = true;
$heading = "Missing chapter filename in the URL.";
}
?>
<!DOCTYPE html>
<html lang="en-gb">
<head>
<?php
include($dr . "head.php");
?>
</head>
<body>
<?php
include($dr . "header.php");
?>
<main>
<nav><a href="/#panel-<?php echo $cat_id; ?>" class="back"><img src="/i/chevron-left.svg" alt="Back to"> <?php echo $category; ?></a></nav>
<h1><?php echo smartypants($heading) ?></h1>
<article class="prose">
<?php
if (!$error) {
echo format($text);
} else {
echo format("# Oh dear.\n");
echo format($title);
}
?>
</article>
</main>
<?php
include($dr . "footer.php");
?>
</body>
</html>