Skip to content

Commit

Permalink
epubs
Browse files Browse the repository at this point in the history
  • Loading branch information
dismorfo committed Apr 30, 2024
1 parent 839bef3 commit c68e94a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 16 deletions.
21 changes: 13 additions & 8 deletions inc/loaders/epubs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
*
* @return object
*/
function dlts_epub_load($identifier, $version = 'v0') {
function dlts_epub_load($identifier, $map_array, $_index) {

$version = $map_array[1];

$publisher = $map_array[3]->code;

$reset_cache = true;

$identifier = filter_xss($identifier);
$result = $result = db_query('SELECT * FROM dlts_viewer_epubs WHERE identifier = :identifier', [ ':identifier' => $identifier ])->fetchObject();
if (!empty($result->identifier)) {
$data = dlts_viewer_supafolio_book($result->identifier, true);
switch ($version) {
case 'v0':
return dlts_viewer_epubs_metadata_v0($data);
}

$result = dlts_viewer_epubs_metadata($version, $publisher, $identifier, $reset_cache);

if (!isset($result['error'])) {
return $result;
}
return FALSE;
}
15 changes: 15 additions & 0 deletions inc/routes/epub.inc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ function _dlts_viewer_menu_epub() {
'access content',
],
'page arguments' => [ 1, 3, 4 ],
'load arguments' => array('%map', '%index'),
'page callback' => 'dlts_viewer_epubs_indexer',
'delivery callback' => 'drupal_json_output',
'file' => 'inc/types/epub.inc',
'type' => MENU_CALLBACK,
];

$items['api/v1/epubs/%dlts_publisher/%dlts_epub/opt/indexer'] = [
'title' => 'Query repository',
'load arguments' => array('%map', '%index'),
'description' => 'Query epubs API.',
'access arguments' => [
'access content',
],
'page arguments' => [ 1, 3, 4 ],
'page callback' => 'dlts_viewer_epubs_indexer',
'delivery callback' => 'drupal_json_output',
'file' => 'inc/types/epub.inc',
Expand Down
58 changes: 50 additions & 8 deletions inc/types/epub.inc
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ function dlts_viewer_epubs_metadata_v1($data) {

$format = $data->pages;

$series = [];

$metadata = [
'publicationPlace' => 'New York',
'dateBook' => '', // need source
Expand All @@ -664,30 +666,31 @@ function dlts_viewer_epubs_metadata_v1($data) {
'language' => $custom->language,
'license' => $license->label,
'licenseAbbreviation' => $license->abbreviation,
'licenseAbbreviationFacet' => $license->label,
'licenseIcon' => $license->icon,
'licenseLink' => $license->link,
'pressUrl' => "https://nyupress.org/$isbnForPrimaryFormat",
'publisher' => $publisher,
'series' => $series,
'subjects' => $unique_subjects,
'subjectsFacet' => $unique_subjects,
// 'subjectsFacet' => $unique_subjects,
'subtitle' => $data->subtitle,
'title' => $title,
'titleSort' => $data->title_without_prefix,
'contributor' => $authors_display,
'contributors' => json_encode($authors_display),
'doi' => $custom->permanent_url,
'dateOpenAccess' => '', // need source
'yearBook' => '', // need source
'yearOpenAccess' => '', // need source
'seriesOpenAcess' => '', // need source
// 'seriesOpenAcess' => '', // need source
'isbnHardcover' => $custom->hardcover,
'isbnPaperback' => $custom->paperback,
'isbnEbook' => $custom->ebook,
'isbnLibrary' => $custom->library,
'isDownloadable' => $custom->open_access_is_downloadable,
'hasVideo' => $custom->video,
'hasHiResImages' => $custom->hi_res_images,
// hack; must fix solr before removing this.
'collection_code' => 'nyupress'
];

return $metadata;
Expand Down Expand Up @@ -721,25 +724,26 @@ function dlts_viewer_epubs_metadata($version = 'v0', $publisher, $identifier, $r
];
} else {
switch ($version) {
case 0:
case 'v1':
return dlts_viewer_epubs_metadata_v1($data);
break;
default:
return dlts_viewer_epubs_metadata_v0($data);
}

}
}
}
else {
return [
'error' => 'error',
'status' => 'error',
'message' => 'DLTS Viewer - ePub not available.',
];
}
} else {
return [
'message' => "Action not allowed for $name.",
'status' => 'error',
'error' => 'error',
];
}
}
Expand Down Expand Up @@ -807,12 +811,50 @@ function dlts_viewer_epubs_metadata($version = 'v0', $publisher, $identifier, $r
}
}

function dlts_viewer_epubs_indexer_v1($version = 'v0', $_publisher, $epub) {

// Fix this. Should use conf variable.
$discovery = variable_get('opensquare', null);

$solrurl = $discovery['solr'];

$solrurl = 'http://sites_solr:8983/solr/opensquare-v2';

$epub = (object) $epub;

$epub->id = $epub->openSquareId;

$options = [
'method' => 'POST',
'data' => json_encode([$epub]),
];

$response = drupal_http_request("$solrurl/update/json?_=" . time() . "&commit=true&commitWithin=1000&overwrite=true&wt=json", $options);

if ($response->code == '200' && isset($response->data)) {
$r = json_decode($response->data);
$r->status_message = 'Successful request';
$r->message = [ 'docs' => $epub ];
$r->status = $response->code;
return $r;
} else {
return [
'status_message' => $response->status_message,
'code' => $response->code,
'error' => $response->error,
'message' => json_decode($response->data),
];
}
}

/**
* Undocumented function.
*/
function dlts_viewer_epubs_indexer($version = 'v0', $_publisher, $epub) {

// something wrong with format field.
if ($version === 'v1') {
return dlts_viewer_epubs_indexer_v1($version, $_publisher, $epub);
}

// Fix this. Should use conf variable.
$discovery = variable_get('opensquare', null);
Expand Down

0 comments on commit c68e94a

Please sign in to comment.