xref: /web-php/js/search-index.php (revision a3dd1214)
1<?php
2
3use phpweb\I18n\Languages;
4
5$lang = $_GET["lang"] ?? "en";
6if (empty($_SERVER["DOCUMENT_ROOT"])) {
7    $_SERVER["DOCUMENT_ROOT"] = __DIR__ . "/../";
8}
9include __DIR__ . '/../include/prepend.inc';
10if (!isset(Languages::ACTIVE_ONLINE_LANGUAGES[$lang])) {
11    header("Location: http://php.net");
12}
13
14/*
15$types = array(
16    "phpdoc:varentry",
17    "refentry",
18    "phpdoc:exceptionref",
19    "phpdoc:classref",
20    "section",
21    "chapter",
22    "book",
23    "reference",
24    "set",
25    "appendix",
26    "article",
27);
28 */
29
30$indexfile = $_SERVER["DOCUMENT_ROOT"] . "/manual/$lang/search-index.json";
31$descfile = $_SERVER["DOCUMENT_ROOT"] . "/manual/$lang/search-description.json";
32
33/* {{{ Cache this */
34$time = max(filemtime($indexfile), filemtime($descfile));
35$tsstring = gmdate("D, d M Y H:i:s ", $time) . "GMT";
36if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) &&
37    ($_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring)) {
38    header("HTTP/1.1 304 Not Modified");
39    exit;
40}
41
42header("Last-Modified: " . $tsstring);
43header("Content-Type: application/javascript");
44/* }}} */
45
46$s = file_get_contents($indexfile);
47$js = json_decode($s, true);
48
49$index = [];
50foreach ($js as $item) {
51    if ($item[0]) {
52        /* key: ID/filename, 0=>*/
53        $index[$item[1]] = [$item[0], "", $item[2]];
54    }
55}
56
57$s = file_get_contents($descfile);
58$js = json_decode($s, true);
59
60foreach ($js as $k => $item) {
61    if ($item && isset($index[$k])) {
62        $index[$k][1] = $item;
63    }
64}
65
66echo json_encode($index);
67