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