-
Notifications
You must be signed in to change notification settings - Fork 16
/
go.php
89 lines (72 loc) · 2.04 KB
/
go.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
<?php
$title = 'Forwarding Service';
include('_api.php');
$dataHelper = new NiwaDataHelper();
$wikis = $dataHelper->getMemberWikis();
$url = $_SERVER['REQUEST_URI'];
$urlParts = parse_url($url);
$path = $urlParts['path'];
$pathSegments = explode('/', $path);
if (count($pathSegments) > 2) {
$site = $pathSegments[2] ?? null;
$article = implode('/', array_slice($pathSegments, 3)) ?? null;
$target = null;
foreach ($wikis as $wiki) {
if ($wiki->id === $site) {
$target = $wiki->url;
$target = str_replace('$1', $article, $target);
if ($article) {
$target = rtrim($target, '/');
}
}
}
if ($target) {
header("Location: {$target}");
exit();
}
}
include('_header.php');
?>
<style>
.beta {
box-sizing: border-box;
width: 100%;
padding: 1em;
background-color: #f4ebab;
border: 2px solid #f5e366;
border-radius: 10px;
}
</style>
<div class="main">
<h1>NIWA Forwarding Service</h1>
<div class="beta">
This forwarding service is currently in <b>beta</b>. Site IDs are subject to change.
</div>
<br />
This URL serves as a gateway to link to any article on any NIWA member wiki.
<br /><br />
URL format: <code>https://niwanetwork.org/go/{site}/{article}</code>
<br /><br />
Replace <code>{site}</code> with the site ID from the table below, and <code>{article}</code> with your desired article name.
<br /><br />
<table>
<tr>
<th>Site ID</th>
<th>Site URL</th>
</tr>
<?php
foreach ($wikis as $wiki) {
echo "
<tr>
<td>{$wiki->id}</td>
<td>{$wiki->url}</td>
</tr>
";
}
?>
</table>
</div>
<?php
include('_sidebar.php');
include('_footer.php');
?>