-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
78 lines (64 loc) · 1.64 KB
/
index.php
File metadata and controls
78 lines (64 loc) · 1.64 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
<?php
date_default_timezone_set('Europe/Prague');
define('RECIPT_DIR', 'recepty');
if ($_SERVER['REQUEST_URI'] === '/') {
header('Location: /index.php/');
}
$filterPath = filterPathInfo($_SERVER['PATH_INFO']);
$firstPage = false;
if (empty($filterPath)) {
$firstPage = true;
printHead('Recepty na pivní bašty');
echo "<h1>Recepty na pivní bašty</h1>";
}
$fullPath = sprintf('./%s/%s', RECIPT_DIR, $filterPath);
if (is_dir($fullPath)) {
printHead($filterPath);
$pathParts = explode('/', $fullPath);
printf('<h1>%s</h1>', ucfirst(array_pop($pathParts)));
if (!$firstPage) {
printf('<a href=".."><span style="font-size: xx-large;">⇐</span> Zpět</a>');
}
$content = scandir($fullPath);
printf('<ul>');
foreach ($content as $item) {
if ($item !== '.' && $item !== '..') {
printf('<li><a href="./%s/">%s</a></li>', $item, $item);
}
}
print('</ul>');
} elseif (is_file($fullPath)) {
printHead($filterPath);
echo '<div>'.nl2br(file_get_contents($fullPath)).'</div>';
printf('<br><a href=".."><span style="font-size: xx-large;">⇐</span> Zpět</a>');
} else {
header('Location: /index.php/');
}
printTail();
function filterPathInfo($pathInfo)
{
$parts = explode('/', $pathInfo);
$filterParts = array_filter($parts, function($var) {
return (!empty($var) && $var !== '.' && $var !== '..' );
});
return implode('/', $filterParts);
}
function printHead($title)
{
echo <<<EOF
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>$title</title>
</head>
<body>
EOF;
}
function printTail()
{
//© 2013 integer, autoři receptů uvedeni u receptů
echo <<<EOF
</body>
</html>
EOF;
}