-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
198 lines (166 loc) · 5.42 KB
/
index.php
File metadata and controls
198 lines (166 loc) · 5.42 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
<?php
error_reporting(E_ALL & (~E_NOTICE));
session_start();
require "wiki_format.php";
# Sätt språk
$lang = empty($_REQUEST['lang']) ? 'sv' : $_REQUEST['lang'];
##
# Hämta och formatera sidan
##
$page = isset($_GET['page']) && $_GET['page'] != "Start" ? '/'.$_GET['page'] : '';
$pageclass = 'stacken' . strtolower(preg_replace('/\W+/', '_', $page));
function get_url($lang) {
global $page;
# NOTE This only removes the slash internally, without redirect.
# The /foo/ will be identical to /foo (bad google carma).
$id = rtrim($page, '/');
if ($lang != "sv") {
$id = "{$id}.{$lang}";
}
return "http://wiki.stacken.kth.se/wiki/Stacken{$id}?printable=yes";
}
$url = get_url($lang);
$content = @file_get_contents($url);
$content = str_replace(' ',' ',$content);
# Hack
# Lägg till __SHOW_TOC:Kalender__ på en sida för att visa
# TOC från Stacken/Menu/Kalender i stället för den på sidan.
$show_toc_menu = false;
$content = preg_replace_callback("#__SHOW_TOC:([a-z]+)__#i", function($m) {
global $show_toc_menu;
$show_toc_menu = $m[1];
return '';
}, $content);
# Specialsidor med genererat innehåll
$content = preg_replace("#__SPECIAL:([a-z/.]+)__#ie", "file_get_contents(dirname(__FILE__).'/$1')", $content);
if ($content) {
$xml = new SimpleXMLElement($content);
$content = $xml->body->div->div->div->div;
$last_mod = $xml->body->div->div[3]->ul->li;
# Denna tar bort innehållsförteckningen
unset($content->div[3]->table);
if ($content->table) {
$toc = $content->table->tr->td->ul->asXML();
unset($content->table[0]);
}
$content = $content->asXML();
} else {
# Page not found
# Kolla om vi har en sida på det andra språket som vi kan skicka vidare till
if ($lang == "en") {
if (file_get_contents(get_url("sv"))) {
flash_next_page("No English page available, you have been redirected to the swedish page.");
header("Location: ".(empty($page)?'/Start':$page));
exit;
}
} else if ($lang == "sv") {
if (file_get_contents(get_url("en"))) {
flash_next_page("Det fanns ingen svensk sida, du har blivit vidareskickad till den engelska sidan.");
header("Location: ".(empty($page)?'/Start.en':$page.'.en'));
exit;
}
}
# Om sidan inte finns på webbywiki, prova om den finns på gamla sidan och
# försök att hämta den i stället.
if ($old_page = file_get_contents("http://oldwww.stacken.kth.se/$page")) {
$old_page = str_replace("/css/stacken2012.css",
"http://oldwww.stacken.kth.se/css/stacken2012.css",$old_page);
$old_page = str_replace("/css/print.css",
"http://oldwww.stacken.kth.se/css/print.css",$old_page);
echo utf8_encode($old_page);
exit;
}
header("HTTP/1.0 404 Not Found");
$content = "
<div id=\"bodyContent\">
<p>The requested URL {$page} was not found on this server.</p>
</div>
";
}
##
# Hämta och formatera menyn
##
$menu_url = "http://wiki.stacken.kth.se/wiki/Stacken/Menu?printable=yes";
$cnt = file_get_contents($menu_url);
$cnt = menu_prepare($cnt);
$menu = lang_menu($cnt, $lang);
###
# Hämta och formatera sidmeny (om den finns)
##
preg_match("#/([a-z0-9]+)#i", $page, $m);
$menu_url = "http://wiki.stacken.kth.se/wiki/Stacken/{$m[1]}/Menu?printable=yes";
$cnt = @file_get_contents($menu_url);
if (!empty($cnt) && !empty($page)) {
$cnt = menu_prepare($cnt);
$menu_sub = "<h2>".ucfirst($m[1])."</h2>";
$menu_sub .= lang_menu($cnt, $lang);
}
###
# Hämta och formatera special-TOC
# (den skriver över vanlig TOC)
##
if ($show_toc_menu) {
$url = "http://wiki.stacken.kth.se/wiki/Stacken/Menu/".$show_toc_menu."?printable=yes";
$str = file_get_contents($url);
$str = str_replace(' ',' ',$str);
$xml = new SimpleXMLElement($str);
$cnt = $xml->body->div->div->div->div;
$toc = $cnt->ul->asXML();
}
ob_start();
?>
<html lang="<?=$lang?>">
<head>
<title>Datorföreningen Stacken</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="/style/style.css">
</head>
<body class="<?=$pageclass?>">
<div id="top">
<? if ($lang == "sv"): ?>
<span class="langlink">[<a href="<?=(empty($page))?'/Start':$page?>.en">In english</a>]</span>
<? else: ?>
<span class="langlink">[<a href="<?=(empty($page))?'/Start':$page?>.sv">På svenska</a>]</span>
<? endif; ?>
<span class="helplink">[<a href="/help/web" title="Om Stackens websidor, navigation och utseende.">Hjälp</a>]</span>
<strong><a href="/" title="The Computer Club @ KTH">Stacken</a></strong>
</div>
<div id="wrap">
<div id="preContent">
<?=get_flash_message()?>
</div>
<!-- Sidan importerad från: <?=$url?> -->
<?=wiki_format($content)?>
<!-- Slut på import -->
<div class="menu">
<? if($toc): ?>
<!-- Importera TOC -->
<h2>Innehåll</h2>
<?=wiki_format($toc)?>
<!-- Slut på import -->
<? endif; ?>
<? if($menu_sub): ?>
<!-- Importera undermeny -->
<?=wiki_format($menu_sub)?>
<!-- Slut på import -->
<? endif; ?>
<!-- Menyn importerad från: <?=$menu_url?> -->
<h2><?=($lang=="sv"?'Meny':'Menu')?></h2>
<?=wiki_format($menu)?>
<!-- Slut på import -->
</div>
<div id="footer">
<p class="signed">
<a href="/webmaster">Webmasters</a> @
<a href="/">Stacken</a>
</p>
<p class="dated"><?=$last_mod?></p>
</div>
</div>
</body>
</html>
<?php
$html = ob_get_clean();
echo tidy_html($html);
?>