This repository was archived by the owner on May 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.php
More file actions
273 lines (234 loc) · 8.41 KB
/
index.php
File metadata and controls
273 lines (234 loc) · 8.41 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// read configuration files
require_once("php/config.php");
$config = array_merge($config, parse_ini_file("config.ini"));
// all the pages
require_once("php/pages/about.php");
require_once("php/pages/acknowledgements.php");
require_once("php/pages/api.php");
require_once("php/pages/bibliography.php");
require_once("php/pages/browse.php");
require_once("php/pages/chapter.php");
require_once("php/pages/contribute.php");
require_once("php/pages/error.php");
require_once("php/pages/index.php");
require_once("php/pages/taghistory.php");
require_once("php/pages/markdown.php");
require_once("php/pages/missingtag.php");
require_once("php/pages/recentcomments.php");
require_once("php/pages/results.php");
require_once("php/pages/search.php");
require_once("php/pages/statistics.php");
require_once("php/pages/tagdeleted.php");
require_once("php/pages/taginvalid.php");
require_once("php/pages/taglookup.php");
require_once("php/pages/tags.php");
require_once("php/pages/tagview.php");
require_once("php/pages/todo.php");
// mapping the first chapter of each part to the title of the part
$parts = array(
"Introduction" => "Preliminaries",
"Schemes" => "Schemes",
"Chow Homology and Chern Classes" => "Topics in Scheme Theory",
"Algebraic Spaces" => "Algebraic Spaces",
"Chow Groups of Spaces" => "Topics in Geometry",
"Formal Deformation Theory" => "Deformation Theory",
"Algebraic Stacks" => "Algebraic Stacks",
"Moduli Stacks" => "Topics in Moduli Theory",
"Examples" => "Miscellany");
// we try to construct the page object
try {
// initialize the global database object
try {
$database = new PDO("sqlite:" . $config["database"]);
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
print "Something went wrong with the database. If the problem persists, please contact us at <a href='mailto:stacks.project@gmail.com'>stacks.project@gmail.com</a>.";
// if there is actually a persistent error: add output code here to check it
exit();
}
if (empty($_GET["page"]))
$page = "index";
else
$page = $_GET["page"];
// all the possible page building scenarios
switch($page) {
case "about":
$page = new AboutPage($database);
break;
case "acknowledgements":
$page = new AcknowledgementsPage($database);
break;
case "api":
$page = new APIPage($database);
break;
case "bibliography":
if(!empty($_GET["key"])) {
if (bibliographyItemExists($_GET["key"]))
$page = new BibliographyItemPage($database, $_GET["key"]);
else
$page = new NotFoundPage("<p>The bibliography item with the key <var>" . htmlentities($_GET["key"]) . "</var> does not exist.");
}
else
$page = new BibliographyPage($database);
break;
case "browse":
$page = new BrowsePage($database);
break;
case "chapter":
if (!is_numeric($_GET["chapter"]) or strstr($_GET["chapter"], ".") or intval($_GET["chapter"]) <= 0) {
$page = new NotFoundPage("<p>The keys for a chapter should be (strictly) positive integers, but <var>" . htmlentities($_GET["chapter"]) . "</var> was provided.");
break;
}
if (sectionExists($_GET["chapter"]))
$page = new ChapterPage($database, intval($_GET["chapter"]));
else
$page = new NotFoundPage("<p>The chapter with the key <var>" . htmlentities($_GET["chapter"]) . "</var> does not exist.");
break;
case "contribute":
$page = new ContributePage($database);
break;
case "index":
$page = new IndexPage($database);
break;
case "history":
if(!empty($_GET["tag"])) {
$tag = strtoupper($_GET['tag']);
if (!isValidTag($tag)) {
$page = new InvalidTagPage($database, $tag);
}
elseif (tagExists($tag)) {
if (tagIsActive($tag))
$page = new HistoryPage($database, $tag);
else
$page = new TagDeletedPage($database, $tag);
}
else
$page = new MissingTagPage($database, $tag);
}
else
$page = new TagLookupPage($database);
break;
case "markdown":
$page = new MarkdownPage($database);
break;
case "recent-comments":
if (empty($_GET["number"]))
$number = 1;
else
$number = $_GET["number"];
$page = new RecentCommentsPage($database, $number);
break;
case "search":
if (!isset($_GET["keywords"]))
$page = new SearchPage($database);
else {
// TODO set options in new form
$options = array();
// based on SO1017599...
$options["keywords"] = strtr(utf8_decode($_GET["keywords"]), utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
if (isset($_GET["limit"]))
$options["limit"] = $_GET["limit"];
else
$options["limit"] = "all";
if (isset($_GET["exclude-duplicates"]))
$options["exclude-duplicates"] = "on";
$page = new SearchResultsPage($database, $options);
}
break;
case "statistics":
if(!empty($_GET["tag"])) {
$tag = strtoupper($_GET['tag']);
if (!isValidTag($tag)) {
$page = new InvalidTagPage($database, $tag);
}
if (tagExists($tag)) {
if (tagIsActive($tag))
$page = new StatisticsPage($database, $tag);
else
$page = new TagDeletedPage($database, $tag);
}
else
$page = new MissingTagPage($database, $tag);
}
else
$page = new TagLookupPage($database);
break;
case "tag":
if(!empty($_GET["tag"])) {
$tag = strtoupper($_GET['tag']);
if (!isValidTag($tag)) {
$page = new InvalidTagPage($database, $tag);
}
else if (tagExists($tag)) {
if (tagIsActive($tag))
$page = new TagViewPage($database, $tag);
else
$page = new TagDeletedPage($database, $tag);
}
else
$page = new MissingTagPage($database, $tag);
}
else
$page = new TagLookupPage($database);
break;
case "tags":
$page = new TagsPage($database);
break;
case "todo":
$page = new TodoPage($database);
break;
}
// we request these now so that exceptions are thrown
$title = $page->getTitle();
$head = $page->getHead();
$main = $page->getMain();
$sidebar = $page->getSidebar();
}
catch(PDOException $e) {
$page = new ErrorPage($e);
// we request these now so that exceptions are thrown
$title = $page->getTitle();
$head = $page->getHead();
$main = $page->getMain();
$sidebar = $page->getSidebar();
}
?>
<!doctype html>
<html>
<head>
<title>Stacks Project<?php print $title; ?></title>
<link rel='stylesheet' type='text/css' href='<?php print href("css/main.css"); ?>'>
<link rel='icon' type='image/vnd.microsoft.icon' href='<?php print href("stacks.ico"); ?>'>
<link rel='shortcut icon' type='image/vnd.microsoft.icon' href='<?php print href("stacks.ico"); ?>'>
<meta charset='utf-8'>
<?php print $head; ?>
</head>
<body>
<h1><a href='<?php print href(''); ?>'>The Stacks Project</a></h1>
<ul id='menu'>
<li><a href='<?php print href(""); ?>'>home</a>
<li><a href='<?php print href("about"); ?>'>about</a>
<li><a href='<?php print href("tags"); ?>'>tags explained</a>
<li><a href='<?php print href("tag"); ?>'>tag lookup</a>
<li><a href='<?php print href("browse"); ?>'>browse</a>
<li><a href='<?php print href("search"); ?>'>search</a>
<li><a href='<?php print href("bibliography"); ?>'>bibliography</a>
<li><a href='<?php print href("recent-comments"); ?>'>recent comments</a>
<li><a href='<?php print $config["blog"]; ?>'>blog</a>
<li><a href='<?php print href("slogans"); ?>'>add slogans</a>
</ul>
<br style='clear: both;'>
<div id='main'>
<?php print $main; ?>
</div>
<div id='sidebar'>
<?php print $sidebar; ?>
</div>
<br style='clear: both;'>
<p id='backlink'>Back to the <a href='<?php print href(''); ?>'>main page</a>.
</body>
</html>