-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.json
113 lines (106 loc) · 3.94 KB
/
item.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
<?php
//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 = htmlentities(strip_tags($_SERVER['SERVER_NAME']));
$path = htmlentities(strip_tags(dirname($_SERVER['PHP_SELF'])));
$fileName = htmlentities(strip_tags(basename($_SERVER['SCRIPT_NAME'])));
$fileNameURI = htmlentities(strip_tags($_SERVER['REQUEST_URI']));
//get id variable from URL
$id = isset($_GET['id']) ? strip_tags((int)$_GET['id']) : null;
function readTime($text) {
$words = str_word_count(strip_tags($text));
$minutes = floor($words / 200);
if($minutes != 0) {
return $minutes;
} else {
return '< 1';
}
}
//set header for json file and allow cross-domain requests
header('Content-type: application/json');
header("access-control-allow-origin: *");
//bring database parameters and functions onto page
include_once './meta/assets/dbconnect.inc';
//get data to generate chapter data
$query = 'SELECT * FROM schema_fiction.bodymatter WHERE id = '.$id;
$result = $dbconn->query($query) or die($dbconn->error.__LINE__);
if($result->num_rows > 0) {
while($item = $result->fetch_object()) {
$item_id = $item->id;
$item_name = $item->name;
$item_creator = $item->creator;
$item_publisher = $item->publisher;
$item_body = $item->text;
$item_image = $item->image;
$item_date_created = $item->dateCreated;
$item_date_modified = $item->dateModified;
$item_genre = $item->additionalType;
$item_about = $item->additionalType2;
$item_learning_resource_type = $item->learningResourceType;
$item_language = $item->inLanguage;
//estimate read time, set here for global use
$readTime = readTime($item_body);
?>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "CreativeWork",
"@id": "<?php echo $protocol.$server.$path; ?>/",
"mainEntity": {
"@type": "Book",
"name": "Opsis: Literary Arts Journal at Montana State University (MSU)",
"description": "Opsis is the literature and arts magazine of Montana State University",
"image": "<?php echo $protocol.$server.$path; ?>/meta/img/opsis.png",
"datePublished": "<?php echo $item_date_created; ?>",
"inLanguage": "<?php echo $item_language; ?>",
"genre": "Journals (Publications)",
"learningResourceType": "<?php echo $item_learning_resource_type; ?>",
"creator": {
"@type": "Person",
"name": "Multiple Authors"
}
},
"Article": {
"@type": "Article",
"@id": "<?php echo $protocol.$server.$path; ?>/item/<?php echo $item_id; ?>",
"name": "<?php echo $item_name; ?>",
"author": {
"@type": "Person",
"name": "<?php echo $item_creator; ?>"
},
"image": "<?php echo addslashes($item_image); ?>",
"articleBody": "<?php echo urlencode($item_body); ?>",
"url": "<?php echo $protocol.$server.$path; ?>/item/<?php echo $item_id; ?>",
"timeRequired": "PT<?php echo $readTime; ?>M",
"datePublished": "<?php echo $item_date_created; ?>",
"publisher": {
"@type": "Organization",
"name": "<?php echo $item_publisher; ?>"
},
"additionalType": "http://dbpedia.org/resource/<?php echo str_replace(' ', '_', $item_genre); ?>",
"additionalType": "http://dbpedia.org/resource/<?php echo str_replace(' ', '_', $item_about); ?>",
"potentialAction": {
"@type": "ReadAction",
"actionStatus": "PendingActionStatus",
"target": {
"@type": "EntryPoint",
"urlTemplate": "<?php echo $protocol.$server.$path; ?>/item/<?php echo $item_id; ?>"
}
}
},
"publisher": {
"@type": "Organization",
"@id": "http://dbpedia.org/resource/Montana_State_University",
"name": "<?php echo $item_publisher; ?>",
"sameAs": "http://dbpedia.org/resource/Montana_State_University"
},
"url": "<?php echo $protocol.$server.$path; ?>/"
}
</script>
<?php
}
$result->close();
}
$dbconn->close();
?>