-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
145 lines (124 loc) · 3.52 KB
/
index.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/* @author holman
*
*/
require_once 'php/twig.php';
$START_PT = array(0, 0);
$START_DIR = 'N';
// map x to list of y's where (x, y) is a valid place to look around
$VALID_LOCS = array(
'0' => array(1, 4, 6, 9),
'3' => array(1, 4, 6, 9),
'6' => array(1, 4, 6, 9),
);
// will be filled in
$bio_map = array();
$lang_map = array();
$filter_map = array();
$min_pt = null;
$max_pt = null;
$pts = array();
// lets read in the bios, and make a map
$fin = fopen('data/bios.csv', 'r');
$cat_actions = array(
'People' => function(&$info) use (&$bio_map, &$min_pt, &$max_pt) {
$my_pts = array();
// picture not taken yet if not in this loop
if ($info[3] !== '' && $info[4] !== '') {
$x_list = explode(',', $info[3]);
$y_list = explode(',', $info[4]);
foreach ($x_list as $idx => $x) {
$x = intval($x);
$y = intval($y_list[$idx]);
if (empty($min_pt)) $min_pt = $max_pt = array($x, $y);
else {
if ($min_pt[0] > $x) $min_pt[0] = $x;
else if ($max_pt[0] < $x) $max_pt[0] = $x;
if ($min_pt[1] > $y) $min_pt[1] = $y;
else if ($max_pt[1] < $y) $max_pt[1] = $y;
}
array_push($my_pts, array($x, $y));
}
}
$trim = function($str) { return trim($str); };
$bio_map[$info[0]] = array(
'name' => $info[1],
'short_name' => $info[2],
'pts' => $my_pts,
'role' => $info[5],
'languages' => empty($info[6]) ? array()
: array_map($trim, explode(',', $info[6])),
'countries' => empty($info[7]) ? array()
: array_map($trim, explode(',', $info[7])),
'eng' => array(
'lang' => $info[8],
'editor' => $info[9],
),
'filters' => empty($info[10]) ? array()
: array_map($trim, explode(',', $info[10])),
'quote' => $info[11],
'detailed_info' => $info[12]
);
},
'Places' => function(&$info) {},
'Languages' => function(&$info) use (&$lang_map) {
$lang_map[$info[0]] = $info[1];
},
'Filters' => function(&$info) use (&$filter_map) {
$filter_map[$info[0]] = $info[1];
}
);
$curr_cat = '';
if (!feof($fin)) {
while (!feof($fin)) {
$line = trim(fgets($fin));
if (empty($line)) break;
$info = explode('|', $line);
if (empty($info[0])) continue;
if (array_key_exists($info[0], $cat_actions)) {
$line = fgets($fin); // get rid of header line
$curr_cat = $info[0];
continue;
}
if (!empty($curr_cat)) $cat_actions[$curr_cat]($info);
}
}
ksort($bio_map);
// Make loc types array
for ($i = $min_pt[0]; $i <= $max_pt[0]; $i++) {
if (array_key_exists($i, $VALID_LOCS)) {
$loc_types[$i] = array_combine($VALID_LOCS[$i], array_fill(0, sizeof($VALID_LOCS[$i]), 'loc'));
}
else $loc_types[$i] = array();
}
// fill loc arrays with people
foreach ($bio_map as $key => &$bio) {
foreach ($bio['pts'] as $pt) {
$loc_types[$pt[0]][$pt[1]] = $key;
}
}
$loc_types[$START_PT[0]][$START_PT[1]] = 'start';
// Render the page from template
twig\Render('app.html',
array(
'bio_map' => $bio_map,
'dir_name' => array(
array('NW', 'N', 'NE'),
array('W', 'mid', 'E'),
array('SW', 'S', 'SE')
),
'JS_VARS_FROM_SERVER_JSON' => json_encode(array(
'vars' => array(
'filter_map' => $filter_map,
'min_pt' => $min_pt,
'max_pt' => $max_pt,
'loc_types' => $loc_types,
'START_PT' => $START_PT,
'START_DIR' => $START_DIR
),
'bio_map' => $bio_map,
'lang_map' => $lang_map,
)),
)
);
?>