-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletters.php
More file actions
89 lines (76 loc) · 2.6 KB
/
Copy pathletters.php
File metadata and controls
89 lines (76 loc) · 2.6 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
<?php
include "env/config.php";
include "lib/helpers.php";
?>
<html>
<?php include "layout/head.html"; ?>
<body>
<?php include "layout/navbar.php"; ?>
<div class="container">
<h4>Letters</h4>
<div class="container-fluid">
<?php
// GET a request to the flask url for the requested tag (or no tags if all annotations)
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $flask_url."/search?limit=$flask_results_max");
// Set user agent to not trigger mod_security rule for no user agent
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (curl; Linux x86_64; Annotonia Status)');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Disable cert checking to bypass curl cert error with Acme.sh certs
// Local only traffic and public data, so not really a risk
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$res = curl_exec($curl);
curl_close($curl);
// organize the annotation responses by letter
$annotations = json_decode($res, true);
$letters = array();
for ($i = 0; $i < $annotations["total"]; $i++) {
$anno = $annotations["rows"][$i];
if (isset($letters[$anno["pageID"]])) {
array_push($letters[$anno["pageID"]], $anno);
} else {
$letters[$anno["pageID"]] = array($anno);
}
}
$files = scandir($catherletters_dir);
foreach ($files as $file) {
$xml = simplexml_load_file($catherletters_dir . $file);
$title = $xml->teiHeader->fileDesc->titleStmt->title;
$id = $xml->teiHeader->fileDesc->publicationStmt->idno;
if (preg_match("/cat\.let[0-9]{4}/i", $id)) {
$id = str_replace("cat.", "", $id);
echo <<<END
<div class="row">
<h4 class="pull-left"><strong>$id: </strong></h4>
<h4><a href="$boilerplate_url$id.html">$title</a></h4>
END;
$letter_annos = $letters[$id];
$anno_count = count($letter_annos);
$tags = array();
for ($i = 0; $i < $anno_count; $i++) {
foreach ($letter_annos[$i]["tags"] as $tag) {
array_push($tags, $tag);
}
}
echo <<<END
<div class="col-md-2">
<a href="$catherletters_url/$id">Cather View</a>
</div>
<div class="col-md-2">
$anno_count annotation(s)
</div>
<div class="col-md-8">
END;
echo generate_tags(array_unique($tags));
echo <<<END
</div>
</div>
<hr>
END;
}
}
?>
</div>
</div>
</body>
</html>