diff --git a/_api.php b/_api.php index 7ee4821..6aa136a 100644 --- a/_api.php +++ b/_api.php @@ -56,6 +56,7 @@ public function getMemberWikis($languageCode = null, $includeFormer = null) $filteredMembers = []; if ($languageCode) { + // If specific language is requested... if($includeFormer) { $filteredMembers = $this->memberWikis->{$languageCode}; } else { @@ -66,14 +67,19 @@ function($val){ }); } } else { - foreach ($this->memberWikis as $key => $data) { - $filteredMembers = array_merge($filteredMembers, $this->memberWikis->{$key}); + // If all languages are requested... + + // Merge language arrays: + $allMemberWikis = []; + foreach ($this->memberWikis as $memberWikis) { + $allMemberWikis = array_merge($allMemberWikis, $memberWikis); } - if($includeFormer) { - $filteredMembers = $this->memberWikis->{$languageCode}; + + if ($includeFormer) { + $filteredMembers = $allMemberWikis; } else { $filteredMembers = array_filter( - $this->memberWikis->{$languageCode}, + $allMemberWikis, function($val){ return !($val->former ?? FALSE); }); diff --git a/go.php b/go.php new file mode 100644 index 0000000..3cd64ab --- /dev/null +++ b/go.php @@ -0,0 +1,68 @@ +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 ($target) { + header("Location: {$target}"); + exit(); + } + } +?> + +
+

NIWA Redirect Service

+ + This URL serves as a gateway to link to any article on any NIWA member wiki. + +

+ + URL format: https://niwanetwork.org/go/{site}/{article} + +

+ + Replace {site} with the site ID from the table below, and {article} with your desired article name. + +

+ + + + + + + + + + + "; + } + ?> +
Site IDSite URL
{$wiki->id}{$wiki->url}
+
+ + \ No newline at end of file diff --git a/style.css b/style.css index 02cee52..17f1a5a 100644 --- a/style.css +++ b/style.css @@ -52,6 +52,18 @@ button[disabled]:hover { cursor: not-allowed; } +table { + border-collapse: collapse; +} +th { + background-color: #e9e9e9; +} +th, td { + padding: 8px; +} +tr:nth-child(odd) { + background-color: #ededed; +} /* Color classes */ .white {