-
Notifications
You must be signed in to change notification settings - Fork 1
/
embed.php
63 lines (55 loc) · 1.97 KB
/
embed.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
<?php
define('ROOT_DIR', dirname(dirname(__FILE__)));
set_include_path('.' . PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . get_include_path());
require_once('zoteroconfig.php');
require_once('library/libZoteroSingle.php');
$library = new Zotero_Library($libraryType, $userID, $userSlug, $apiKey);
$collectionKey = !empty($_GET['collectionKey']) ? $_GET['collectionKey'] : '';
$limit = !empty($_GET['limit']) ? $_GET['limit'] : 10;
$style = !empty($_GET['style']) ? $_GET['style'] : '';
$content = !empty($_GET['content']) ? $_GET['content'] : 'html';
$format = !empty($_GET['format']) ? $_GET['format'] : 'atom';
$fetchParameters = array('limit'=>$limit, 'style'=>$style, 'collectionKey'=>$collectionKey, 'content'=>$content, 'format'=>$format);
foreach($fetchParameters as $key=>$val){
if(empty($val)){
unset($fetchParameters[$key]);
}
}
$items = $library->loadItemsTop($fetchParameters);
//var_dump($items);
//output the list of fetched items with the chosen fields
$output = '';
switch($content){
case 'html':
case 'bib':
foreach($items as $item){
$output .= $item->content;
}
break;
case 'json':
$output .= "<ul class='zoteroItems'>";
$displayFields = array('title', 'creator', 'dateAdded');
foreach($items as $item){
$output .= "<li class='zoteroItem'>";
foreach($displayFields as $field){
$output .= htmlspecialchars($item->formatItemField($field) . " - ");
}
$output .= "</li>";
}
$output .= "</ul>";
break;
case 'none':
$output .= "<ul class='zoteroItems'>";
foreach($items as $item){
$output .= "<li class='zoteroItem'>";
foreach($displayFields as $field){
$output .= htmlspecialchars($item->title) . ' - ' . $item->itemKey;
}
$output .= "</li>";
}
$output .= "</ul>";
break;
}
echo $output;
?>