-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_as_json.php
96 lines (81 loc) · 2.45 KB
/
data_as_json.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
90
91
92
93
94
95
96
<?php
date_default_timezone_set("Europe/Copenhagen");
header('Content-Type: application/json');
# Include graphsettings
include("sym-files2/graphsettings.php");
# Get the request
$request = isset($_GET["request"]) ? $_GET["request"] : "";
# Generate the appropriate output
switch ($request) {
case "index":
$return = get_index();
break;
default:
$return = "Unkonwn request: " . (string) $request;
}
# And write it to the page
echo(json_encode($return));
/* *** FUNCTIONS *** */
/**
* Return all relevant information about the available plots
*
* This include the information about the available plots from the
* index and graphsettings object for the available plots.
*/
function get_index(){
# Read in the index XML file and iterate over setups
$setups = Array();
$index_xml = simplexml_load_file('index.xml');
foreach($index_xml as $setup_xml){
$setups[] = get_index_single_setup($setup_xml);
}
return $setups;
}
/**
* Return all relevant information for a single setup. See get_index()
*/
function get_index_single_setup($setup_xml){
# Initialize setup array
$setup = Array(
'codename' => (string) $setup_xml['codename'],
'title' => (string) $setup_xml->setup_title,
'links' => Array(),
);
# Add links
foreach ($setup_xml->link as $link_xml){
$link = get_index_link($link_xml);
if ($link != null){
$setup['links'][] = $link;
}
}
return $setup;
}
/**
* Return all relevant information for a index link
*/
function get_index_link($link_xml){
# Initialize link array
$link = Array('title' => (string) $link_xml->title);
$ref = (string) $link_xml->ref;
# Parse the url arguments
$query = parse_url($ref, PHP_URL_QUERY);
$query_args = Array();
parse_str($query, $query_args);
$link['query_args'] = $query_args;
# Parse the path part of the url and set pagetype
$link['path'] = parse_url($ref, PHP_URL_PATH);
if (strpos($link['path'], 'xyplot.php') !== false){
$link['pagetype'] = 'xyplot';
} elseif (strpos($link['path'], 'dateplot.php') !== false){
$link['pagetype'] = 'dateplot';
# For dateplots, also include the graphsettings
$path_parts = explode('/', ltrim($link['path'], '/'), 2);
$graphsettingsfile = $path_parts[0] . '/graphsettings.xml';
$link['graphsettings'] = plot_settings($query_args['type'], "", False, $graphsettingsfile);
} else {
# If the path is not to xyplot.php or dateplot.php then return null
return null;
}
return $link;
}
?>