-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtaxonomy.php
207 lines (199 loc) · 9.38 KB
/
taxonomy.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
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
<!DOCTYPE html>
<?php
/***
*
*
* See:
* https://github.com/tigerhawkvok/asm-mammal-database/issues/50
***/
# $show_debug = true;
if ($show_debug === true) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
error_log('taxonomy is running in debug mode!');
$debug = true;
# compat
} else {
# Rigorously avoid errors in production
ini_set('display_errors', 0);
}
require dirname(__FILE__)."/CONFIG.php";
require_once(dirname(__FILE__)."/core/core.php");
$db = new DBHelper($default_database, $default_sql_user, $default_sql_password, $default_sql_url, $default_table, $db_cols);
$updatesSinceAssessmentYear = 2005;
?>
<html>
<head>
<?php
$title = "Taxonomy Information";
$pageDescription = "Information about recent taxonomy changes and mammal taxonomy assignment";
?>
<title><?php echo $title;
?></title>
<?php include_once dirname(__FILE__)."/modular/header.php";
?>
<script type="text/javascript">
(function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
s.src='//<?php echo $shortUrl; ?>/bower_components/whichbrowser/detect.php?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();
/*window.onerror = function(e) {
console.warn("Error thrown: "+e);
return true;
}*/
</script>
</head>
<?php
require_once dirname(__FILE__)."/modular/bodyFrame.php";
echo $bodyOpen;
?>
<h1 id="title" class="col-xs-12">
Taxonomy Information
</h1>
<h2 class="col-xs-12">Data Differences from MSW3</h2>
<div class="col-xs-12 clearfix">
<?php
/***
* To find new taxa, check the authories newer than $updatesSinceAssessmentYear
***/
$yearsToCheck = array();
# Because of the way we stored the authorities,
# we want to enumerate all the years between then and now
$thisYear = date("Y");
$examinedYear = $updatesSinceAssessmentYear;
while ($examinedYear < $thisYear) {
$examinedYear++;
$yearsToCheck[] = $examinedYear;
}
$taxa = array();
foreach ($yearsToCheck as $year) {
$searchCriteria = array(
"authority_year" => strval($year),
"species_authority" => strval($year),
"genus_authority" => strval($year),
);
$results = $db->getQueryResults($searchCriteria, "*", "OR", true, true);
$taxa = array_merge($taxa, $results);
}
$buffer = "";
$migratedTaxa = array();
$novelTaxa = array();
foreach ($taxa as $taxon) {
$years = json_decode($taxon["authority_year"], true);
if (!is_array($years)) {
$gYear = preg_replace('/^.*?([0-9]{4}).*$/im', '$1', $taxon["genus_authority"]);
$sYear = preg_replace('/^.*?([0-9]{4}).*$/im', '$1', $taxon["species_authority"]);
} else {
$gYear = key($years);
$sYear = current($years);
}
if (empty($gYear)) {
$gYear = $sYear;
} elseif (empty($sYear)) {
$sYear = $gYear;
}
$sYear = intval($sYear);
$gYear = intval($gYear);
if ($sYear < $gYear) {
# This is a migrated taxon
$migratedTaxa[] = $taxon;
continue;
} else {
# Either this was added to an existing genus
# Or created at the same time
# In either case, we want the species authority
$novelTaxa[] = $taxon;
$authority = preg_replace('/^(.*?)[,;:]? *(?:[0-9]{4})? *$/im', '$1', $taxon["species_authority"]);
$authority = html_entity_decode($authority);
}
$year = $sYear > $gYear ? $sYear : $gYear;
if (!empty($taxon["species_authority_citation"])) {
if (stripos($taxon["species_authority_citation"], "isbn")) {
$citation = $taxon["species_authority_citation"];
} else {
$citation = "<a href='http://dx.doi.org/".$taxon["species_authority_citation"]."' class='newwindow doi btn btn-xs btn-primary'>doi:".$taxon["species_authority_citation"]."</a>";
}
} else {
$citation = "";
}
$buffer .= "\n<li><span class='sciname'><span class='genus'>".$taxon["genus"]."</span> <span class='species'>".$taxon["species"]."</span></span> in <span class='has-authority' data-toggle='tooltip' title='$authority'>$year</span> <paper-icon-button class='click' data-href='$protocol://$shortUrl/species-account/id=".$taxon["id"]."' icon='icons:visibility' title='See account for ".ucwords($taxon["genus"])." ".$taxon["species"]."' data-toggle='tooltip'></paper-icon-button> $citation</li>\n";
}
echo "<h3>There have been ".sizeof($novelTaxa)." taxa changes since $updatesSinceAssessmentYear</h3> <ul>";
echo $buffer;
echo "</ul>";
/***
* To find migrations, find species with species authories
* younger than the modified date, but genus authories newer
*
* Add to this deprecateds with modified after date
***/
foreach ($yearsToCheck as $year) {
$search = array(
"deprecated_scientific" => "$".$year,
);
$results = $db->getQueryResults($search, "*", "OR", true, true);
$list = array();
foreach ($results as $result) {
# Check each item in the deprecated list
# Append to list if the genera don't match
$dep = json_decode($result["deprecated_scientific"], true);
$graduateTaxon = array();
$updateYearRef = $updatesSinceAssessmentYear;
foreach ($dep as $taxon => $authorityString) {
# We're only interested in genera
$genus = explode(" ", $taxon)[0];
if (strtolower($taxon["genus"]) == strtolower($genus)) {
continue;
}
# Get the rest
$authorityParts = explode(":", $authorityString);
$authority = $authorityParts[0];
$authorityYearParts = explode("$", $authorityParts[1]);
$authorityYear = $authorityYearParts[0];
$updateYear = $authorityYearParts[1];
if (empty($updateYear)) {
$updateYear = $updatesSinceAssessmentYear;
}
if ($updateYear > $updateYearRef || empty($graduateTaxon)) {
$graduateTaxon = array(
"changeYear" => $updateYear,
"authority" => $authority,
"authorityYear" => $authorityYear,
"oldTaxon" => $taxon,
"oldGenus" => $genus,
);
$updateYearRef = $updateYear;
}
}
$result["graduated"] = $graduateTaxon;
$list[] = $result;
}
$migratedTaxa = array_merge($migratedTaxa, $list);
}
$buffer = "";
echo "<h3>There have been ".sizeof($migratedTaxa)." taxa with genus migrations since $updatesSinceAssessmentYear</h3> <ul>";
foreach ($migratedTaxa as $taxon) {
# Do the thing, Ju-Li!
$year = $taxon["graduated"]["changeYear"];
$genus = $taxon["graduated"]["oldGenus"];
if (!empty($taxon["species_authority_citation"])) {
if (stripos($taxon["species_authority_citation"], "isbn")) {
$citation = $taxon["species_authority_citation"];
} else {
$citation = "<a href='http://dx.doi.org/".$taxon["species_authority_citation"]."' class='newwindow doi btn btn-xs btn-primary'>doi:".$taxon["species_authority_citation"]."</a>";
}
} else {
$citation = "";
}
$buffer .= "\n<li><span class='sciname'><span class='genus'>".$taxon["genus"]."</span> <span class='species'>".$taxon["species"]."</span></span> migrated from <span class='genus'>".$genus."</span> in $year <paper-icon-button class='click' data-href='$protocol://$shortUrl/species-account/id=".$taxon["id"]."' icon='icons:visibility' title='See account for ".ucwords($taxon["genus"])." ".$taxon["species"]."' data-toggle='tooltip'></paper-icon-button></li>\n";
}
echo $buffer;
echo "</ul>"
?>
</div>
<?php
echo $bodyClose;
?>
</html>