forked from piernov/zotprime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalItemsController.php
65 lines (54 loc) · 2.17 KB
/
GlobalItemsController.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
<?php
/*
***** BEGIN LICENSE BLOCK *****
This file is part of the Zotero Data Server.
Copyright © 2017 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
require('ApiController.php');
class GlobalItemsController extends ApiController {
public function globalItems() {
$this->allowMethods(['GET']);
$params = [];
if (!empty($_GET['q'])) {
if (strlen($_GET['q']) < 3) {
$this->e400("Query string must be at least 3 characters length");
}
$params['q'] = $_GET['q'];
}
else if (!empty($_GET['doi'])) {
$params['doi'] = $_GET['doi'];
}
else if (!empty($_GET['isbn'])) {
$params['isbn'] = $_GET['isbn'];
}
else {
$this->e400("One of the following query parameters must be used: q, doi, isbn");
}
$params['start'] = $this->queryParams['start'];
$params['limit'] = $this->queryParams['limit'];
$result = Zotero_GlobalItems::getGlobalItems($params);
for ($i = 0, $len = sizeOf($result['data']); $i < $len; $i++) {
unset($result['data'][$i]['libraryItems']);
unset($result['data'][$i]['meta']['instanceCount']);
$result['data'][$i]['meta']['numLibraries'] = $result['data'][$i]['meta']['librariesCount'];
unset($result['data'][$i]['meta']['librariesCount']);
}
header('Content-Type: application/json');
header('Total-Results: ' . $result['totalResults']);
echo Zotero_Utilities::formatJSON($result['data']);
$this->end();
}
}