-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.json
175 lines (169 loc) · 6.73 KB
/
person.json
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
<?php
//set correct content-type for json output
header('Content-Type: application/json');
//pass database parameters and connect to database
include_once './meta/assets/database-params.inc';
//bring special functions and utilities onto page
include './meta/inc/utilities.php';
//check if the $id variable was passed in url, escape the string for mysql, and validate that it is a numeric value - pass id value to select record
if (isset($_GET['id']) and is_numeric($_GET['id'])) {
$id = strip_tags($connectLibstaff->real_escape_string((int)$_GET['id']));
} else {
echo 'Query type not supported.';
exit;
}
//get and set url protocol
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
//set and sanitize global variables for URL construction
$server = isset($_SERVER['SERVER_NAME']) ? htmlentities(strip_tags($_SERVER['SERVER_NAME'])) : null;
$path = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags(dirname($_SERVER['PHP_SELF']))) : null;
$fileName = isset($_SERVER['SCRIPT_NAME']) ? htmlentities(strip_tags(basename($_SERVER['SCRIPT_NAME']))) : null;
$fileNameURI = isset($_SERVER['REQUEST_URI']) ? htmlentities(strip_tags($_SERVER['REQUEST_URI'])) : null;
$fileExtension = isset($_SERVER['PATH_INFO']) ? pathinfo($fileName, PATHINFO_EXTENSION) : null;
//request selected staff data fields
$query = "SELECT * FROM linked_people.person WHERE person_status = 'a' AND person_id='$id'";
$getPerson = $connectLibstaff->query($query);
if ($getPerson->num_rows == 0) {
header("HTTP/1.0 404 Not Found", true, 404);
readfile("https://lib.montana.edu/error.php");
exit();
}
//Display selected staff entry fields in a list
while ($row = $getPerson->fetch_object()) {
$person_id = stripslashes($row->person_id);
$person_fname = stripslashes($row->givenName);
$person_lname = stripslashes($row->familyName);
$person_name = stripslashes($row->givenName . ' ' . $row->familyName);
$person_title = stripslashes($row->jobTitle);
$person_dept = stripslashes($row->memberOf);
$person_affiliation = stripslashes($row->affiliation);
$person_room = stripslashes($row->workLocation);
$person_phone = stripslashes($row->telephone);
$person_email = stripslashes($row->email);
$person_emailHidden = stripslashes(formatEmailLink($row->email));
$person_vita = stripslashes($row->person_vita);
$person_web = stripslashes($row->url);
$person_image = $protocol.$server.$path.'/meta/img/photos/'.stripslashes($row->image);
$person_identifier = stripslashes(htmlentities($row->identifier));
$person_same_as = stripslashes(htmlentities($row->sameAs));
$person_privacy = $row->person_privacy;
?>
{
"@context": "https://schema.org/",
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id; ?>",
"@type": "Person",
"name": "<?php echo $person_name; ?>",
"description": "Description of <?php echo $person_name; ?>'s skills, expertise, and networks",
"identifier": "<?php echo $protocol.$server.$path.'/about/'.$id; ?>",
"jobTitle": "<?php echo $person_title; ?>",
"memberOf": "<?php echo $person_dept; ?>",
"email": "<?php echo $person_email; ?>",
"image": "<?php echo $person_image; ?>",
"telephone": "<?php echo $person_phone; ?>",
<?php
if (strlen($person_web) > 3) {
?>
"url": "<?php echo $person_web; ?>",
<?php
}
?>
"affiliation": "<?php echo $person_affiliation; ?>",
"worksFor": {
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#organization'; ?>",
"@type": "EducationalOrganization",
"name": "<?php echo $person_affiliation; ?> Library",
"sameAs": [
"<?php echo 'https://dbpedia.org/resource/Montana_State_University_Library'; ?>",
"<?php echo 'http://www.freebase.com/m/0j3y9r1'; ?>",
"<?php echo 'https://www.wikidata.org/entity/Q15255419'; ?>",
"<?php echo 'https://www.worldcat.org/wcr/organization/data/56245'; ?>"
],
"member": {
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#member'; ?>",
"@type": "OrganizationRole",
"name": "<?php echo $person_name; ?>",
"sameAs": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#person'; ?>",
"roleName": "<?php echo $person_title; ?>"
}
},
"address": {
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#address'; ?>",
"@type": "PostalAddress",
"streetAddress": "P.O. Box 173320",
"addressLocality": "Bozeman",
"addressRegion": "MT",
"postalCode": "59717-3320"
},
"knows": {
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#colleague'; ?>",
"@type": "Person",
"colleague": [
<?php
//get person's colleagues
$query = "SELECT person_id FROM linked_people.person WHERE person_status = 'a' AND memberOf='$person_dept'";
$getColleagues = $connectLibstaff->query($query);
if ($getColleagues->num_rows == 0) {
?>
"No colleagues assigned to this person."
<?php
}
$separator = "";
while ($row = $getColleagues->fetch_object()) {
$colleague_id = $row->person_id;
$colleague_url = $protocol.$server.$path.'/about/'.$colleague_id;
//print list of colleagues
echo $separator.'"'.$colleague_url.'"';
$separator = ",\n";
}
?>
]
},
"makesOffer": {
"@id": "<?php echo $protocol.$server.$path.'/'.$fileName.'?id='.$id.'#offer'; ?>",
"@type": "Offer",
"category": [
<?php
//get person's expertise topics
$query = "SELECT *
FROM linked_people.person, linked_people.create_action, linked_people.create_action_match
WHERE person.person_id = '$id'
AND create_action_match.create_id = create_action.create_id
AND create_action_match.person_id = '$id'
AND person.person_status = 'a'";
$getPersonExpertise = $connectLibstaff->query($query);
if ($getPersonExpertise->num_rows == 0) {
?>
"No expertise or skill(s) assigned to this person."
<?php
}
$separator = "";
while ($row = $getPersonExpertise->fetch_object()) {
$expertise_id = $row->create_id;
$expertise = $row->object;
$expertise_url = $row->object_uri;
//print list of expertise topics
echo $separator.'"'.$expertise_url.'"';
$separator = ",\n";
}
?>
]
},
"sameAs" : [
<?php
if (strlen($person_identifier) < 3 && strlen($person_same_as) < 3) {
echo '"No equivalency mapped for this person."'."\n";
}
if (strlen($person_identifier) > 3 && strlen($person_same_as) > 3) {
echo '"'.$person_identifier.'"'.",\n";
echo '"'.$person_same_as.'"';
}
if (strlen($person_identifier) > 3 && strlen($person_same_as) < 3) {
echo '"'.$person_identifier.'"'."\n";
}
if (strlen($person_same_as) > 3 && strlen($person_identifier) < 3) {
echo '"'.$person_same_as.'"'."\n";
}
}//end initial while loop
?>
]
}