-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstructure.php
More file actions
33 lines (27 loc) · 926 Bytes
/
Copy pathstructure.php
File metadata and controls
33 lines (27 loc) · 926 Bytes
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
<?php
require 'course-setup.php';
$origin = $_SERVER['HTTP_ORIGIN'];
if (in_array($origin, $HANDOUT_ORIGINS)) {
// allow CORS
header("Access-Control-Allow-Origin: $origin");
}
function parse($json) {
$configjson = file_get_contents($json.'.json');
$config = json_decode($configjson);
return $config;
}
function incl($config) {
global $HANDOUT_TOC_KINDS;
return in_array($config->kind, $HANDOUT_TOC_KINDS) && ! property_exists($config, 'noindex');
}
function entry($config) {
return array(
'handout' => implode('/', array_filter(array($config->kind, $config->handout, $config->part))),
'structure' => $config->structure
);
}
header('Content-Type: application/json');
$configs = array_map(function($name) { return substr($name, 0, -5); }, glob('data/*.json'));
natsort($configs);
print json_encode(array_map(entry, array_values(array_filter(array_map(parse, array_values($configs)), incl))));
?>