forked from krueschan/phpZoteroWebDAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
209 lines (188 loc) · 7.22 KB
/
index.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
208
209
<?php
require_once 'settings.php';
require_once 'inc/include.php';
require_once 'inc/libZotero.php';
include_once 'inc/header.php'; // HTML header including css file
try {
$zotero = new Zotero_Library( 'user', $user_ID, $user_name, $API_key );
} catch( Exception $e ) {
die( 'Error activating libZotero: ' . $e->getMessage() );
}
if( isset( $apc_cache_ttl ) && $apc_cache_ttl )
$zotero->setCacheTtl( $apc_cache_ttl );
$ipp = isset($_REQUEST['ipp']) ? (int)$_REQUEST['ipp'] : $def_ipp;
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : $def_sort;
$sortorder = isset($_REQUEST['sortorder']) ? $_REQUEST['sortorder'] : $def_sortorder;
$page = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1;
$collectionKey = isset( $_REQUEST['collection'] ) ? $_REQUEST['collection'] : false;
$webdav_url=( isset($_SERVER['HTTPS']) ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] . str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) . "webdav_server.php/zotero/";
?>
<h3>
Total size of stored attachments: <u><?php echo format_size( foldersize( get_real_path( $data_dir ) ) ) ?></u>
WebDAV URL: <a href="<?php echo $webdav_url ?>"><?php echo $webdav_url ?></a>
</h3>
<?php
$orders[0] = $sortorder;
if (strcmp($orders[0],"asc")){
$orders[1]='asc';
}else{
$orders[1]='desc';
}
//purge old files from the cache
purge_cache( get_real_path( $cache_dir ), $cache_age );
// get first set of items from API
$start = ($page - 1) * $ipp;
if ($ipp > $fetchlimit) $limit = $fetchlimit; else $limit = $ipp;
// Include collections on index page for traversal
$collections = $zotero->fetchCollections( array( 'collectionKey' => $collectionKey ) );
//print_r($collections);
?>
<div class="collections-div">
<h2><?php echo ( $collectionKey ) ? 'Sub-Collections' : 'Collections' ?></h2>
<?php if( count( $collections ) > 0 ) : ?>
<table>
<thead>
<tr>
<th scope="col">Collection</th>
<th scope="col"># Items</th>
</tr>
</thead>
<tbody>
<?php foreach( $collections as $collection ) : ?>
<?php if( $collection->parentCollectionKey != $collectionKey ) continue; ?>
<tr>
<td><a href="?collection=<?php echo $collection->collectionKey; ?>"><?php echo $collection->name; ?></a></td>
<td><?php echo $collection->numItems; ?> <?php echo ( $collection->numItems == 1 ) ? 'item' : 'items' ; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p class="note">No collections were found.</p>
<?php endif; ?>
</div>
<?php
$fetch_params = array(
'order' => $sort,
'sort' => $sortorder,
// 'content' => 'none',
'limit' => $limit,
'collectionKey' => $collectionKey
);
$fetch_offset = $start;
$items = array();
do {
$fetched = $zotero->fetchItemsTop( array_merge( $fetch_params, array( 'start' => $fetch_offset ) ) );
$items = array_merge( $items, $fetched );
$fetch_offset += count( $items );
if( isset($zotero->getLastFeed()->links['next'])){
$moreItems = true;
} else {
$moreItems = false;
}
} while( count( $items ) < $ipp && count( $fetched ) >= $fetchlimit );
$totalitems = $zotero->getLastFeed()->totalResults;
// MAIN DATA TABLE
// parse result sets, write out data and get more from API if needed
?>
<div class="all-items-div">
<h2><?php echo ( $collectionKey ) ? 'Items in this Collection' : 'All Items'; ?></h2>
<table class="library-items-div">
<thead>
<tr>
<th>Attachments</th>
<th><a href="?page=1&sort=dateAdded">Added</a></th>
<th><a href="?page=1&sort=creator&sortorder=<?php echo $orders[!(boolean) abs(strcmp($sort,"creator"))] ?>">Creator</a></th>
<th><a href="?page=1&sort=date&sortorder=<?php echo $orders[!(boolean) abs(strcmp($sort,"date"))] ?>">Date</a></th>
<th><a href="?page=1&sort=title&sortorder=<?php echo $orders[!(boolean) abs(strcmp($sort,"title"))] ?>">Title</a></th>
</tr>
</thead>
<tbody>
<?php foreach( $items as $item ) { ?>
<tr>
<td><a href="details.php?itemkey=<?php echo $item->itemKey ?>"><?php echo $item->numChildren ?></a></td>
<td><a href="details.php?itemkey=<?php echo $item->itemKey ?>"><?php echo format_date( $item->dateAdded ) ?></a></td>
<td><a href="details.php?itemkey=<?php echo $item->itemKey ?>"><?php echo $item->creatorSummary ?></a></td>
<td><a href="details.php?itemkey=<?php echo $item->itemKey ?>"><?php echo $item->apiObject['date'] ?></a></td>
<td><a href="details.php?itemkey=<?php echo $item->itemKey ?>"><?php echo $item->title ?></a></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td><?php echo(($start +1) . " to " . count( $items ) . " of " . $totalitems); ?></td>
</tr>
</tfoot>
</table>
</div>
<br />
<hr />
<table>
<?php
// NAVIGATION FOOTER
$param_ipp = ($ipp == $def_ipp) ? "": "&ipp=$ipp";
$param_sort = ($sort == $def_sort) ? "": "&sort=$sort";
$param_sortorder = ($sortorder == $def_sortorder) ? "": "&sortorder=$sortorder";
$param_collection = ( $collectionKey ) ? "&collection=$collectionKey" : '';
$i = 1;
echo("<tr><td>Pages</td><td>");
$pages = intval($totalitems / $ipp) + 1;
while ($i <= $pages) {
if ($i != $page) echo("<a href=\"?page=$i" . $param_ipp . $param_sort . $param_sortorder . $param_collection . "\">");
echo ("-$i-");
if ($i != $page) echo("</a>");
echo (" ");
$i = $i + 1;
if ($i > 5) {
if ($i < ($page - 2)) {
$i = $page - 2;
echo (" . . . ");
}
}
if (($i > ($page + 2)) && ($i > 5)) {
if ($i < ($pages - 4)) {
$i = $pages - 4;
echo (" . . . ");
}
}
}
echo ("</td></tr>\n");
echo("<tr><td>Items per Page</td><td>");
$ipp_list = array (1,10,20,50,100,200,500,1000,9999999);
$i = 0;
while ($i <= 7) {
if ($ipp != $ipp_list[$i]) echo("<a href=\"?page=$page&ipp=" . $ipp_list[$i] . $param_sort . $param_sortorder . $param_collection . "\">");
echo ("-$ipp_list[$i]-");
if ($ipp != $ipp_list[$i]) echo("</a>");
echo (" ");
$j = $i + 1;
if (($ipp > $ipp_list[$i]) && ($ipp < $ipp_list[$j])) echo ("-$ipp- ");
$i = $i + 1;
}
echo ("</td></tr>\n");
echo("<tr><td>Sort By</td><td>");
$s_list = array ("dateAdded", "title", "creator", "type", "date", "publisher", "publication", "journalAbbreviation", "language", "dateModified", "accessDate", "libraryCatalog", "callNumber", "rights", "addedBy", "numItems");
$i = 0;
while ($i <= 15) {
if ($sort != $s_list[$i]) echo("<a href=\"?page=$page" . $param_ipp . "&sort=" . $s_list[$i] . $param_sortorder . $param_collection . "\">");
echo ("-$s_list[$i]-");
if ($sort != $s_list[$i]) echo("</a>");
echo (" ");
$i = $i + 1;
}
echo ("</td></tr>\n");
echo("<tr><td>Sort Order</td><td>");
$so_list = array ("asc", "desc");
$i = 0;
while ($i <= 1) {
if ($sortorder != $so_list[$i]) echo("<a href=\"?page=$page" . $param_ipp . $param_sort . "&sortorder=" . $so_list[$i] . $param_collection . "\">");
echo ("-$so_list[$i]-");
if ($sortorder != $so_list[$i]) echo("</a>");
echo (" ");
$i = $i + 1;
}
echo ("</td></tr>\n</table>\n");
?>
</body>
</html>