-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomizefeed.php
110 lines (98 loc) · 3.14 KB
/
customizefeed.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>libZotero Examples</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header role="banner">
<h1>libZotero Examples</h1>
</header>
<nav>
<ul>
<li><a href="inpage.php">Load Zotero data within a page</a></li>
<li><a href="container.html">Load a frame the load Zotero data into it</a></li>
<li><a href="customizefeed.php">Customize a Zotero items feed</a></li>
<li><a href="createitem.php">Create Item</a></li>
</ul>
</nav>
<form>
<ul>
<li><input type="text" name="collectionKey"></input> CollectionKey</li>
<li><input type="text" name="limit"></input> Limit</li>
<li><input type="text" name="style"></input> Style</li>
<li>
<select name="content">
<option value="json">JSON</option>
<option value="html">html</option>
<option value="none">none</option>
<option value="bib">bib</option>
</select> Content
</li>
<li><input type="submit" /></li>
</ul>
</form>
<?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');
if(isset($_GET['collectionKey'])){
$collectionKey = $_GET['collectionKey'];
}
else{
die;
}
$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;
?>
</body>
</html>