-
Notifications
You must be signed in to change notification settings - Fork 95
/
index.php
60 lines (44 loc) · 1.73 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
<?php
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'docs';
if (isset($_REQUEST['doc']) && !empty($_REQUEST['doc'])) {
$doc = $dir . '/' . $_REQUEST['doc'];
if (($fullpath = realpath($doc)) && file_exists($fullpath) && stripos($fullpath, $dir, 0) === 0) {
echo '<script type="text/javascript" src="libraries/jquery/jquery.js"></script>';
echo '<link href="assets/js/prettify/prettify.css" type="text/css" rel="stylesheet" />';
echo '<script type="text/javascript" src="assets/js/prettify/prettify.js"></script>';
echo '<link rel="stylesheet" href="assets/css/styles.css">';
echo '<div class="box box-text documentation">';
$output = file_get_contents($fullpath);
$output = preg_replace('#src="\.\.\/\.\.\/\.\.\/#', 'src="', $output);
echo $output;
echo '</div>';
echo '<script type="text/javascript">addEventListener("load", function (event) { prettyPrint() }, false);</script>';
}
} else {
$iterator = new RecursiveDirectoryIterator($dir);
$renderer = function ($iterator) use (&$renderer, $dir) {
$html = array();
foreach ($iterator as $path) {
if ($path->isDir()) {
$html[] = "\n<li>";
$html[] = $path->getBaseName();
$html[] = '<ul>';
$html[] = $renderer(new RecursiveDirectoryIterator($path));
$html[] = '</ul>';
$html[] = '</li>';
} else {
$link = ltrim(preg_replace('/^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', $dir), '/').'/i', '', str_replace(DIRECTORY_SEPARATOR, '/', $path)), '/');
$html[] = "\n<li>";
$html[] = '<a href="index.php?doc='.urlencode($link).'">'.$path->getBaseName().'</a>';
$html[] = '</li>';
}
}
return implode("\n", $html);
}
?>
<h1>Documentation</h1>
<ul class="sections">
<?php echo $renderer($iterator); ?>
</ul>
<?php
}