forked from Overv/Open.GL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
224 lines (192 loc) · 8.37 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
// Requested language
$lang = 'en';
$languages = explode("\n", file_get_contents("content/languages"));
if (isset($_GET['lang']) && in_array($_GET['lang'], $languages)) {
$lang = $_GET['lang'];
}
// Load chapter list
$navitems = explode("\n", file_get_contents("content/articles-" . $lang . "/index"));
$navitemTitles = array();
for ($i = 0; $i < count($navitems); $i++) {
$navitems[$i] = explode("/", $navitems[$i]);
$navitemTitles[$navitems[$i][0]] = $navitems[$i][1];
}
// Requested content
$content = $navitems[0][0];
if (isset($_GET["content"])) $content = $_GET["content"];
// Determine how to load the requested content
$notfound = !preg_match("/^[a-z]+$/", $content) || !file_exists("content/articles-" . $lang . "/" . $content . ".md");
if ($notfound) {
$content = 'notfound';
$contentFile = "content/articles-" . $lang . "/notfound.md";
$contentTitle = "Segmentation fault";
} else {
$contentFile = "content/articles-" . $lang . "/" . $content . ".md";
$contentTitle = $navitemTitles[$content];
}
$contentSource = file_get_contents($contentFile);
// Cache mechanism
$last_modified_time = gmdate("r", max(filemtime('index.php'), filemtime($contentFile))) . " GMT";
$etag = md5(file_get_contents('index.php') . $contentSource);
if ((isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && $_SERVER["HTTP_IF_MODIFIED_SINCE"] == $last_modified_time) ||
(isset($_SERVER["HTTP_IF_NONE_MATCH"]) && str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == $etag))
{
header("HTTP/1.1 304 Not Modified");
exit;
}
header("ETag: " . $etag);
header("Last-Modified: " . $last_modified_time);
header("Cache-Control: public");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>OpenGL - <?php print($contentTitle); ?></title>
<meta name="description" content="An extensive, yet beginner friendly guide to using modern OpenGL for game development on all major platforms." />
<meta name="author" content="Alexander Overvoorde" />
<meta name="keywords" content="opengl, opengl 3.2, deprecated, non-deprecated, tutorial, guide, cross-platform, game, games, graphics, sfml, sdl, glfw, glut, openglut, beginner, easy" />
<link rel="shortcut icon" type="image/png" href="/media/tag.png" />
<link rel="stylesheet" type="text/css" href="/media/stylesheet.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="/media/mobile.css" media="screen and (max-width: 1024px)" />
<script type="text/x-mathjax-config">
// MathJax
MathJax.Hub.Config( {
tex2jax: { inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ] },
menuSettings: { context: "Browser" }
} );
</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="stylesheet" href="/includes/zenburn.min.css" />
<script type="text/javascript" src="//yandex.st/highlightjs/6.1/highlight.min.js"></script>
<script type="text/javascript" src="/includes/glmatrix.js"></script>
<script type="text/javascript">
// Syntax highlighting
hljs.initHighlightingOnLoad();
// Disqus
var disqus_url = "http://open.gl/?content=<?php print( $content ); ?>";
var disqus_identifier = "<?php print( $content ); ?>";
// WebGL demos
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
var callbacks = [];
var frame = function() {
var time = +new Date() / 1000;
for (var i = 0; i < callbacks.length; i++) {
var rect = callbacks[i].canvas.getBoundingClientRect();
if (rect.bottom > 0 && rect.top < window.innerHeight)
callbacks[i].callback( time );
}
requestAnimationFrame(frame);
}
function registerAnimatedCanvas(canvas, callback) {
callbacks.push({canvas: canvas, callback: callback});
}
requestAnimationFrame(frame);
</script>
<!--[if lt IE 9]>
<script src="media/html5shiv.js"></script>
<![endif]-->
<!-- Matomo -->
<script type="text/javascript">
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.open.gl"]);
_paq.push(["setDomains", ["*.open.gl"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.while.io/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '4']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<div id="page">
<!-- Work in progress ribbon -->
<a href="https://github.com/Overv/Open.GL"><img id="ribbon" src="/media/ribbon_fork.png" alt="Fork me!" /></a>
<!-- Navigation items -->
<input type="checkbox" id="nav_toggle" />
<nav>
<label for="nav_toggle" data-open="≡" data-close="✕"></label>
<ul>
<?php
foreach ($navitems as $navitem)
{
if ($navitem[0] == $content)
print( '<li class="selected">' . $navitem[1] . '</li>' . "\n" );
else
print( '<li><a href="/' . $navitem[0] . ($lang == 'en' ? '' : '/' . $lang) . '">' . $navitem[1] . '</a></li>' . "\n" );
}
?>
</ul>
<blockquote style="padding-bottom: 8px; font-size: 14px">
<h2 style="margin: 0">Links</h2>
<a href="https://github.com/Polytonic/Glitter" style="text-decoration: underline">OpenGL boilerplate code</a><br>
<a href="https://github.com/zuck/opengl-examples" style="text-decoration: underline">Easy-to-build code</a><br>
<a href="https://www.youtube.com/playlist?list=PLW3Zl3wyJwWNQjMz941uyOIq3Nw6bcDYC" style="text-decoration: underline">Matrix math tutorials</a><br>
<a href="http://docs.gl" style="text-decoration: underline">OpenGL reference</a>
</blockquote>
<div id="adbox">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Open.GL Responsive -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4259747131061893" data-ad-slot="6609097747" data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</nav>
<!-- Content container -->
<main>
<article>
<?php
include_once("includes/markdown.php");
// Convert links to other chapters
function callback($matches) {
return "($matches[1])";
}
$contentSource = preg_replace_callback("/\\(#([a-z]+)\)/", "callback", $contentSource);
// Correct LaTeX delimiters
function callback2($matches) {
return "\\[" . $matches[1] . "\\]";
}
$contentSource = preg_replace_callback("/\\$\\$([^$]+)\\$\\$/", "callback2", $contentSource);
print(Markdown($contentSource));
?>
</article>
<div id="adbox-article">
<hr />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Open.GL Responsive -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4259747131061893" data-ad-slot="6609097747" data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<?php
if (!$notfound)
{
?>
<!-- Disqus comments -->
<hr />
<aside id="disqus_thread"></aside>
<script type="text/javascript">
var dsq = document.createElement("script");
dsq.type = "text/javascript";
dsq.async = true;
dsq.src = "//opengl.disqus.com/embed.js";
document.getElementsByTagName("head")[0].appendChild( dsq );
</script>
<?php
}
?>
</main>
</div>
</body>
</html>