-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
198 lines (157 loc) · 4.55 KB
/
index.php
File metadata and controls
198 lines (157 loc) · 4.55 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Lineage</title>
<meta name="description" content="">
<meta name="author" content="Ryan Ludwig">
<script src="assets/js/modernizr-2.0.6._development.js"></script>
<!-- get the device max resolution -->
<script>var device_width=Math.max(screen.width);</script>
<!-- don't forget google analytics here -->
</head>
<body>
<div id="main" role="main">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$data_source = 'data_files/momsfamilytree.xml';
parse_the_feed($data_source);
function parse_the_feed($feedquery) {
$data=simplexml_load_file("$feedquery");
//echo out each indiviual
foreach($data->individuals->i as $individual) :
$id = $individual['id'];
$first_name = $individual->f;
$last_name = $individual->l;
$display_name = $individual->dn;
$maiden_name = $individual->id;
$birth = $individual['b'];
$death = $individual['d'];
$gender = $individual['g'];
$email = $individual->mEmail;
$has_children = $individual['p'];
$child_of = $individual['c'];
echo '<div class="person">';
echo '<a name="id_' . $id . '"></a>';
echo '<h3>' . $display_name . '</h3>';
echo '<ul>';
if ($gender) {
echo '<li>';
if ($gender == "M") {
echo "Male";
}else if ($gender == "F") {
echo "Female";
}
echo '</li>';
}
if ($birth) {
echo '<li>Born: ' . format_date($birth) . '</li>';
}
if ($death) {
echo '<li>Died: ' . format_date($death) . '</li>';
}
if ($birth && $death) {
echo '<li>Lived ' . calculate_lifespan($birth, $death) . '</li>';
}
if ($email) {
echo '<li>Email: <a href="mailto:' . $email . '">' . $email . '</a></li>';
}
if ($has_children) {
echo '<li>Children';
echo '<ul>';
echo return_children($data, $has_children);
echo '</ul>';
echo '</li>';
}
if ($child_of) {
echo '<li>Parents';
echo '<ul>';
echo return_parents($data, $child_of);
echo '</ul>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
endforeach;
}
function format_date($date) {
//remove the excess 0;
$newdate = substr_replace($date ,"",-1);
$theyear = substr($newdate,0, 4);
$themonth = substr($newdate, 4,2);
$theday = substr($newdate, 6, 2);
$output = $theyear . '-' . $themonth . '-' . $theday;
return $output;
}
function return_name_from_id($data, $passed_id) {
foreach($data->individuals->i as $individual) :
$id = $individual['id'];
$display_name = $individual->dn;
if ((string) $passed_id == $id) {
echo '<a href="#id_' . $passed_id . '">' . $display_name . '</a>';
}
endforeach;
}
function calculate_lifespan($birth, $death) {
//remove the excess 0;
$birth = substr_replace($birth ,"",-1);
$death = substr_replace($death ,"",-1);
$lifespan = $death - $birth;
$days = substr($lifespan, -2);
$months = substr($lifespan, -3, -2);
$years = substr($lifespan, -7, -4);
$output = $years . ' years';
return $output;
}
function return_children($data, $passed_id) {
foreach($data->families->f as $family) :
$family_id = $family['id'];
$children = $family['c'];
if ((string) $family_id == $passed_id) {
$children_raw = $children;
$children_array = explode(",", $children_raw);
foreach($children_array as $child){
echo '<li>';
return_name_from_id($data, $child);
echo '</li>';
}
}
endforeach;
}
function return_parents($data, $passed_id) {
foreach($data->families->f as $family) :
$family_id = $family['id'];
$husband = $family['h'];
$wife = $family['w'];
if ((string) $family_id == $passed_id) {
if ($husband) {
echo '<li>';
return_name_from_id($data, $husband);
echo '</li>';
}
if ($wife) {
echo '<li>';
//echo $wife;
return_name_from_id($data, $wife);
echo '</li>';
}
}
endforeach;
}
?>
</div>
<!-- CDN jQuery with local fallback -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write("<script src='assets/js/jquery-1.7.1.min.js'><\/script>")
</script>
<script>
$(function() {
});
</script>
</body>
</html>