[r6961]: branches / phpGedView-ca / modules / FamilySearch / PHP-FamilySearchAPI / pedigree.php  Maximize  Restore  History

Download this file

220 lines (208 with data), 6.9 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* Pedigree Tree Example
* This script will generate a basic pedigree tree using the FamilySearch API
* to obtain its data.
*
* This pedigree chart expects a person's ID to be passed in as a request parameter
* $rootId. The chart will start with $rootId as the root person and then print
* a 4 generation pedigree chart.
*
* This script uses the PHP-FSAPI library to connect and retrieve data from the
* FamilySearch web service API. It then uses the PHP-FSParse library to parse
* the results. It uses its own functions to print the data.
*
* PHP FamilySearch API Parser
* Copyright (C) 2007 Neumont University
*
* This code was created by students from Neumont University under the
* instruction of John Finlay. Questions and comments regarding this code
* may be directed to him at john.finlay@neumont.edu.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* See LICENSE.txt for the full license. If you did not receive a
* copy of the license with this code, you may find a copy online
* at http://www.opensource.org/licenses/lgpl-license.php\
*
* @author John Finlay
*/
ini_set('error_reporting', E_ALL);
ini_set('include_path', ini_get('include_path').PATH_SEPARATOR."./FSAPI");
include_once("FSAPI/FamilySearchProxy.php");
include_once("FSParse/XMLGEDCOM.php");
//set the username and password for familysearch
$username = '';
$password = '';
//$url = 'http://www.dev.usys.org';
$url = 'https://api.familysearch.org';
$rootId = 'KLB4-5Z7';
if (!empty($_REQUEST['rootId'])) $rootId = $_REQUEST['rootId'];
//-- check for authentication if a preset username and password were not provided
if ((empty($username) || empty($password)) && !isset($_SERVER['PHP_AUTH_USER'])) {
basicAuthentication();
}
else {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$client = new FamilySearchProxy($url, $username, $password, 'JW5J-PMJ8-81JM-P5WT-NBBQ-SPLL-8M7S-VHM3');
$client->authenticate();
if (empty($client->sessionid)) basicAuthentication();
}
//-- create an XML parser
$xmlGed = new XmlGedcom();
$xmlGed->setProxy($client);
//-- get the first person and his ancestors in one shot
$xml = $client->getPersonById($rootId, "parents=summary");
$xmlGed->parseXml($xml);
//--get the first person
$arr = $xmlGed->getPersons();
$person = getPerson($rootId);
//-------------------------------------- setup some helper functions
/**
* Send the appropriate authentication headers
*/
function basicAuthentication($message = '') {
if (empty($message)) $message = 'Unable to authenticate user. Access denied.';
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo $message;
exit;
}
/**
* function to retrieve and parse a person's data from the api
* @return XG_Person
*/
function &getPerson($id) {
global $client, $xmlGed;
/* -- because we set the proxy on the $xmlGed object we can ask for a person
//-- get the person's xml data from the API
$person = null;
$xml = $client->getPersonById($id);
//-- parse the XML
$xmlGed->parseXML($xml);
if (!empty($xmlGed->error)) {
//var_dump($xmlGed->error);
if ($xmlGed->error->getCode()==401) basicAuthentication($xmlGed->error->getMessage());
else {
print "<b style=\"color:red;\">".$xmlGed->error->getMessage()."</b><br />";
print htmlentities($xml);
exit;
}
}
*/
//-- get the person, which would normally be the first person in the array
$person = $xmlGed->getPerson($id);
return $person;
}
/**
* Recursively print out the HTML for a person box. This function
* recurses on the given person's parents until $gen==0 or the given
* person is null
* @param $person XG_Person
*/
function printPersonBox(&$person, $gen=4) {
if ($gen==0) return;
if (is_null($person)) return;
$father = null;
$mother = null;
//-- get the person's default parents
$families = $person->getFamilies();
foreach($families as $family) {
$parents = $family->getParents();
$found = false;
foreach($parents as $parent) if ($parent->getRef()==$person->getId()) $found = true;
if (!$found) {
if (isset($parents[0])) {
$father = getPerson($parents[0]->getRef());
}
if (isset($parents[1])) {
$mother = getPerson($parents[1]->getRef());
}
}
}
//-- get the persons birth and death information
$birthDate = "";
$deathDate = "";
$marriageDate = "";
$birthPlace = "";
$deathPlace = "";
$marriagePlace = "";
$assert = $person->getBirthAssertion();
if (!is_null($assert)) {
$date = $assert->getDate();
if (!is_null($date)) $birthDate = $date->getOriginal();
$place = $assert->getPlace();
if (!is_null($place)) $birthPlace = $place->getOriginal();
}
$assert = $person->getDeathAssertion();
if (!is_null($assert)) {
$date = $assert->getDate();
if (!is_null($date)) $deathDate = $date->getOriginal();
$place = $assert->getPlace();
if (!is_null($place)) $deathPlace = $place->getOriginal();
}
//-- generate the HTML
?>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<div id="<?php print $person->getId();?>" class="personbox">
<a class="name" href="pedigree.php?rootId=<?php print $person->getId();?>"><?php print $person->getPrimaryName()->getFullText(); ?></a><br />
<span class="label"><b>Birth:</b></span> <?php print $birthDate." ".$birthPlace; ?><br />
<span class="label"><b>Death:</b></span> <?php print $deathDate." ".$deathPlace; ?><br />
</div>
</td>
<td>
<table>
<tr>
<td>
<?php printPersonBox($father, $gen-1); ?>
</td>
</tr>
<tr>
<td>
<?php printPersonBox($mother, $gen-1); ?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
//------------------------------------------------------ start the HTML
?>
<html>
<head>
<title>FamilySearch API Pedigree Test</title>
<style>
.personbox {
width: 220px;
height: 80px;
border: solid blue 1px;
background-color: #AAAAFF;
overflow: hidden;
font-size: 10pt;
}
.name {
font-weight: bold;
}
.label {
font-decoration: underline;
}
</style>
</head>
<body>
<h2>Pedigree Chart for <?php if ($person->getPrimaryName()) print $person->getPrimaryName()->getFullText(); ?></h2>
<?php printPersonBox($person, 3); ?>
</body>
</html>