forked from mqu/geneanet
/
index.php
91 lines (71 loc) · 1.63 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
<?php
/* Geneanet Page live browser, decoder */
namespace Geneanet;
require_once(__DIR__."/autoload.php");
error_reporting(E_ALL);
/*
ini_set('include_path', '.:lib' . ini_get('include_path'));
require_once('lib/Config.php');
require_once('lib/Person.php');
require_once('lib/Geneanet.php');
require_once('lib/DbCache.php');
*/
$config = new Config();
$geneanet = new GeneanetServer();
if (!$geneanet->login($config->get('connexion/user'), $config->get('connexion/passwd'))) {
printf($geneanet->lastError() . "\n");
exit(0);
}
$grabber = new Grabber($geneanet);
$grabber->setDelay($config->get('grabber/delay'));
if ($config->get('connexion/proxy') != '') {
$grabber->setProxy($config->get('connexion/proxy'));
}
$cache = new DbCache('var/cache.sqlite');
$parser = new GeneanetEntryParser();
if (isset($_REQUEST['url'])) {
$url = sprintf("http://gw3.geneanet.org/%s", $_REQUEST['url']);
} else {
$url = $config->get('geneanet/default-url');
}
printf("url = '%s'<br>\n", $url);
$html = $cache->getFromCache($url, 3600);
if ($html === false) {
$html = $geneanet->get($url);
if (preg_match('#Bad Request#i', $html)) {
$html == false;
} else {
$cache->insertIntoCache($url, $html);
}
}
if ($html !== false) {
$person = $parser->parse($html);
}
?>
<table>
<tr>
<td style="vertical-align:top;">
<?php
if ($html !== false) {
echo $person->toHtml();
}
?>
<pre>
<?php
// print_r($person);
?>
</pre>
</td>
<td style="vertical-align:top;" width="70%">
<frame>
<?php
if ($html !== false) {
echo $html;
} else {
echo "bad request : $url";
}
?>
</frame>
</td>
</tr>
</table>