/** * @brief get ISBN data for $isbn at ISBNdb * * @param string $isbn ISBN to search for * @param arrayref &$meta * @return int $status (0 on success, ERRORCODE otherwise) */ public static function get($isbn, &$meta) { if ($keyString = Config::getApp('isbndb-key', '')) { $keys = explode(',', $keyString); $key = $keys[rand(0, count($keys) - 1)]; $data = false; $isbn = preg_replace('/[^0-9X]/i', '', $isbn); if (Isbn::validate($isbn)) { $command = 'http://isbndb.com/api/v2/json/' . $key . '/book/' . $isbn; $data = json_decode(file_get_contents($command), true); if (isset($data['error'])) { Util::logWarn("ISBNDB: " . $data['error']); if (!(stripos($data['error'], 'Daily request limit exceeded') === false)) { return Isbn::REQUEST_LIMIT_EXCEEDED; } elseif (!(stripos($data['error'], 'Unable to locate') === false)) { return Isbn::NOT_FOUND; } else { return Isbn::ERROR; } } else { self::parse($data['data'][0], $meta); return Isbn::SUCCESS; } } } return false; }
/** * @brief get ISBN data for $isbn at Google (books) * * @param string $isbn ISBN to search for * @param arrayref &$meta * @return int $status (0 on success, ERRORCODE otherwise) */ public static function get($isbn, &$meta) { $command = 'https://www.googleapis.com/books/v1/volumes?q=isbn:' . $isbn; if ($keyString = Config::getApp('google-key', '')) { $keys = explode(',', $keyString); $key = $keys[rand(0, count($keys) - 1)]; $command .= '&key=' . $key; } $data = json_decode(file_get_contents($command), true); if ($data['totalItems'] > 0) { self::parse($data['items'][0]['volumeInfo'], $meta); return true; } else { $meta['rescan'] = date("Y-m-d\\TH:i:sP", time() + Isbn::RESCAN_NOT_FOUND); return Isbn::NOT_FOUND; } /* not reached */ return Isbn::ERROR; }
<?php /** * ownCloud - Files_Opds app * * Copyright (c) 2014 Frank de Lange * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ namespace OCA\Files_Opds; $l = new \OC_L10N('files_opds'); \OCP\Util::addScript('files_opds', 'admin'); \OCP\Util::addStyle('files_opds', 'settings'); $defaults = new \OC_Defaults(); $formats = array(["epub" => Config::getPreview('OC\\Preview\\Epub') ? 1 : 0], ["pdf" => Config::getPreview('OC\\Preview\\PDF') ? 1 : 0], ["opendocument" => Config::getPreview('OC\\Preview\\OpenDocument') ? 1 : 0], ["msoffice" => Config::getPreview('OC\\Preview\\MSOfficeDoc') ? 1 : 0]); $tmpl = new \OCP\Template('files_opds', 'admin'); $tmpl->assign('feedSubtitle', Config::getApp('feed-subtitle', $l->t("%s OPDS catalog", $defaults->getName()))); $tmpl->assign('isbndbKey', Config::getApp('isbndb-key', '')); $tmpl->assign('googleKey', Config::getApp('google-key', '')); $tmpl->assign('previewFormats', $formats); $tmpl->assign('cover-x', Config::getApp('cover-x', '200')); $tmpl->assign('cover-y', Config::getApp('cover-y', '200')); $tmpl->assign('thumb-x', Config::getApp('thumb-x', '36')); $tmpl->assign('thumb-y', Config::getApp('thumb-y', '36')); return $tmpl->fetchPage();
/** * @brief offer preview for download * * if no preview exists for this file, send icon instead * * @param string $path full path to file * @param string type type of preview requested */ public static function servePreview($path, $type) { \OCP\User::checkLoggedIn(); \OC::$server->getSession()->close(); $i = \OC\Files\Filesystem::getFileInfo($path, false); /* check for predefined cover, if found replace $path with that of cover file */ $meta = Meta::get($i['fileid']); if ($meta['cover']) { $path = pathinfo($path)['dirname'] . '/' . $meta['cover']; $i = \OC\Files\Filesystem::getFileInfo($path, false); } if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($path); switch ($type) { case 'cover': $preview->setMaxX(Config::getApp('cover-x', '200')); $preview->setMaxY(Config::getApp('cover-y', '200')); break; case 'thumbnail': $preview->setMaxX(Config::getApp('thumb-x', '36')); $preview->setMaxY(Config::getApp('thumb-y', '36')); break; } $preview->showPreview(); } else { // no preview, serve icon instead $scheme = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'; header("Location: " . $scheme . "://" . $_SERVER['HTTP_HOST'] . \OC_Helper::mimetypeIcon($i->getMimeType())); /* Note: relative URL should be enough (RFC7231) but some OPDS clients * (especially those in dedicated book readers) might not support them * * header("Location: " . \OC_Helper::mimetypeIcon($i->getMimeType())); */ } }