forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·129 lines (110 loc) · 5.13 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
error_reporting(0);
$path = '..';
$subtitle = ': Gallery';
$language = '';
if ( !empty($_GET['lan']) ) {
if (file_exists('README-'.$_GET['lan'].'.md')) {
$language = '-'.$_GET['lan'];
}
}
include('../header.php');
include('../chap-header.php');
echo '<div id="content">';
include($path.'/src/parsedown/Parsedown.php');
$Parsedown = new Parsedown();
echo $Parsedown->text(file_get_contents('README'.$language.'.md'));
if (empty($_GET)) {
// Load all the chapters
$dirs = array_filter(glob('../*/'), 'is_dir');
foreach ($dirs as &$folder) {
$chp = '';
preg_match("/\.\.\/(.+)\//", $folder, $matches);
if (count($matches) > 0) {
$chp = $matches[1];
}
if (file_exists($folder.'TITLE'.$language.'.md') and file_exists($folder.'SUMMARY'.$language.'.md')) {
if (file_exists($folder.'README.md')) {
echo '<a href="'.$folder.'">';
echo $Parsedown->text(file_get_contents($folder.'TITLE'.$language.'.md'));
echo '</a>';
} else {
echo $Parsedown->text(file_get_contents($folder.'TITLE'.$language.'.md'));
}
if (file_exists($folder.'SHORT_SUMMARY'.$language.'.md')) {
echo $Parsedown->text(file_get_contents($folder.'SHORT_SUMMARY'.$language.'.md'));
} else if (file_exists($folder.'SUMMARY'.$language.'.md')) {
echo $Parsedown->text(file_get_contents($folder.'SUMMARY'.$language.'.md'));
}
$shaders = array_reverse(glob($folder.'*.frag'));
$shadersTotal = min(count($shaders), 3);
if ($shadersTotal > 0) {
echo '<div class="glslGallery" data="';
for ($i = 0; $i < $shadersTotal; $i++) {
echo $chp.'/'.basename($shaders[$i], '.frag');
if ($i != $shadersTotal-1) {
echo ',';
}
}
echo '" data-properties="clickRun:editor,hoverPreview:false,showAuthor:false,openFrameIcon:false"></div>';
}
if (file_exists($folder.'featured_examples.php') and $shaderTotal == 0) {
$featuredCode = file_get_contents($folder.'featured_examples.php');
preg_match_all("(\d+)", $featuredCode, $ids);
if (count($ids) > 0) {
echo '<div class="glslGallery" data="';
$numIds = min(count($ids[0]), 3);
for ($i = 0; $i < $numIds; $i++) {
echo $ids[0][$i];
if ($i < $numIds - 1) {
echo ",";
}
}
echo '" data-properties="clickRun:editor,hoverPreview:false,showAuthor:false,openFrameIcon:false"></div>';
$shadersTotal = count($ids[0]);
}
} else if (file_exists($folder.'featured_examples.php') and file_exists('FEATURED'.$language.'.md')) {
include($folder.'featured_examples.php');
$shadersTotal += 3;
}
if (count($shaders) > 3 or $shadersTotal > 3) {
echo '<p class="more"><a href="../examples/?chapter='.$chp.'">more</a></p>';
}
}
}
} elseif ( !empty($_GET['chapter'])) {
$chp = $_GET['chapter'];
$folder = '../'.$chp.'/';
if (file_exists($folder.'TITLE'.$language.'.md') and file_exists($folder.'SUMMARY'.$language.'.md')) {
echo $Parsedown->text(file_get_contents($folder.'TITLE'.$language.'.md'));
if (file_exists($folder.'SUMMARY'.$language.'.md')) {
echo $Parsedown->text(file_get_contents($folder.'SUMMARY'.$language.'.md'));
}
$shaders = array_reverse(glob($folder.'*.frag'));
$shadersTotal = count($shaders);
if ($shadersTotal > 0) {
echo '<div class="glslGallery" data="';
for ($i = 0; $i < $shadersTotal; $i++) {
echo $chp.'/'.basename($shaders[$i], '.frag');
if ($i != $shadersTotal-1) {
echo ',';
}
}
echo '" data-properties="clickRun:editor,showAuthor:false,openFrameIcon:false"></div>';
}
if (file_exists($folder.'featured_examples.php') and file_exists('FEATURED'.$language.'.md')) {
if ($shadersTotal != 0) {
echo $Parsedown->text(file_get_contents('FEATURED'.$language.'.md'));
}
include($folder.'featured_examples.php');
}
}
}
echo '
</div>
<hr>
<ul class="navigationBar" >
<li class="navigationBar" onclick="window.location.href=\'../\'"> Home </li>
</ul>';
include("../footer.php");
?>