66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* getDSpaceCount.php - Proxy für DSpace Authority-Zählung
|
|
*
|
|
* Ruft den DSpace-API-Endpoint getAuthorityCount.php auf und gibt
|
|
* die Anzahl der Datensätze zurück, die den Begriff enthalten.
|
|
*
|
|
* Parameter:
|
|
* - authType: 'Subject' oder 'Person'
|
|
* - query: Der zu suchende Begriff
|
|
*
|
|
* Response: JSON { "query": "...", "authType": "...", "count": n }
|
|
*/
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
// DSpace API Basis-URL
|
|
$DSPACE_API_URL = 'https://bibb-dspace.bibb.de/DSpaceAPI/getAuthorityCount.php';
|
|
|
|
// Parameter
|
|
$authType = isset($_GET['authType']) ? trim($_GET['authType']) : '';
|
|
$query = isset($_GET['query']) ? trim($_GET['query']) : '';
|
|
|
|
// Validierung
|
|
$allowedTypes = array('Subject', 'Person');
|
|
if (!in_array($authType, $allowedTypes)) {
|
|
echo json_encode(array('error' => 'Invalid authType', 'count' => 0));
|
|
exit;
|
|
}
|
|
|
|
if (strlen($query) === 0) {
|
|
echo json_encode(array('error' => 'Missing query', 'count' => 0));
|
|
exit;
|
|
}
|
|
|
|
// DSpace API aufrufen
|
|
$url = $DSPACE_API_URL . '?authType=' . urlencode($authType) . '&query=' . urlencode($query);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'timeout' => 15,
|
|
'header' => "Accept: application/json\r\n"
|
|
),
|
|
'ssl' => array(
|
|
'verify_peer' => false,
|
|
'verify_peer_name' => false
|
|
)
|
|
));
|
|
|
|
$response = @file_get_contents($url, false, $context);
|
|
|
|
if ($response === false) {
|
|
// Fallback: Count 0 zurückgeben, nicht die ganze Anzeige blockieren
|
|
echo json_encode(array(
|
|
'query' => $query,
|
|
'authType' => $authType,
|
|
'count' => -1,
|
|
'error' => 'DSpace API not reachable'
|
|
));
|
|
exit;
|
|
}
|
|
|
|
// Response direkt durchreichen
|
|
echo $response;
|
|
?>
|