diff --git a/lang/Localization_en.json b/lang/Localization_en.json index 0cd7b3fd1..c67d14dfe 100644 --- a/lang/Localization_en.json +++ b/lang/Localization_en.json @@ -56,6 +56,7 @@ "languages.alphabetical.none": "Alphabetical index of absolutely no languages", "languages.alphabetical.one": "Alphabetical index of the single language", "languages.title": "Languages", + "links.title": "Links", "mail.messagenotsent": "Message could not be sent.", "mail.messagesent": "Message has been sent", "paging.next.alternate": "Next", diff --git a/lib/Book.php b/lib/Book.php index f8d18f40c..a35776a23 100644 --- a/lib/Book.php +++ b/lib/Book.php @@ -58,6 +58,8 @@ define ('SQL_BOOKS_BY_RATING', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort'); +require('Identifier.php'); + class Book extends Base { const ALL_BOOKS_UUID = 'urn:uuid'; @@ -104,6 +106,7 @@ class Book extends Base public $publisher = NULL; public $serie = NULL; public $tags = NULL; + public $identifiers = NULL; public $languages = NULL; public $format = array (); @@ -228,6 +231,28 @@ public function getTagsName() { return implode(', ', array_map(function ($tag) { return $tag->name; }, $this->getTags())); } + + /** + * @return Identifiers[] + */ + public function getIdentifiers() { + if (is_null ($this->identifiers)) { + $this->identifiers = array(); + + $result = parent::getDb()->prepare('select type, val, id + from identifiers + where book = ? + order by type'); + $result->execute(array($this->id)); + while ($post = $result->fetchObject()) + { + array_push($this->identifiers, new Identifier($post)); + } + + } + return $this->identifiers; + } + /** * @return Data[] */ diff --git a/lib/Identifier.php b/lib/Identifier.php new file mode 100644 index 000000000..26682922e --- /dev/null +++ b/lib/Identifier.php @@ -0,0 +1,79 @@ + + */ + +class Identifier +{ + public $id; + public $type; + public $formattedType; + public $val; + + public function __construct($post) + { + $this->id = $post->id; + $this->type = strtolower($post->type);; + $this->val = $post->val; + $this->formatType(); + } + + function formatType() + { + if ($this->type == 'amazon') { + $this->formattedType = "Amazon"; + $this->uri = sprintf("https://amazon.com/dp/%s", $this->val); + } else if ($this->type == "asin") { + $this->formattedType = $this->type; + $this->uri = sprintf("https://amazon.com/dp/%s", $this->val); + } else if (substr($this->type, 0, 7) == "amazon_") { + $this->formattedType = sprintf("Amazon.co.%s", substr($this->type, 7)); + $this->uri = sprintf("https://amazon.co.%s/dp/%s", substr($this->type, 7), $this->val); + } else if ($this->type == "isbn") { + $this->formattedType = "ISBN"; + $this->uri = sprintf("https://www.worldcat.org/isbn/%s", $this->val); + } else if ($this->type == "doi") { + $this->formattedType = "DOI"; + $this->uri = sprintf("https://dx.doi.org/%s", $this->val); + } else if ($this->type == "douban") { + $this->formattedType = "Douban"; + $this->uri = sprintf("https://book.douban.com/subject/%s", $this->val); + } else if ($this->type == "goodreads") { + $this->formattedType = "Goodreads"; + $this->uri = sprintf("https://www.goodreads.com/book/show/%s", $this->val); + } else if ($this->type == "google") { + $this->formattedType = "Google Books"; + $this->uri = sprintf("https://books.google.com/books?id=%s", $this->val); + } else if ($this->type == "kobo") { + $this->formattedType = "Kobo"; + $this->uri = sprintf("https://www.kobo.com/ebook/%s", $this->val); + } else if ($this->type == "litres") { + $this->formattedType = "ЛитРес"; + $this->uri = sprintf("https://www.litres.ru/%s", $this->val); + } else if ($this->type == "issn") { + $this->formattedType = "ISSN"; + $this->uri = sprintf("https://portal.issn.org/resource/ISSN/%s", $this->val); + } else if ($this->type == "isfdb") { + $this->formattedType = "ISFDB"; + $this->uri = sprintf("http://www.isfdb.org/cgi-bin/pl.cgi?%s", $this->val); + } else if ($this->type == "lubimyczytac") { + $this->formattedType = "Lubimyczytac"; + $this->uri = sprintf("https://lubimyczytac.pl/ksiazka/%s/ksiazka", $this->val); + } else if ($this->type == "url") { + $this->formattedType = $this->type; + $this->uri = $this->val; + } else { + $this->formattedType = $this->type; + $this->uri = ''; + } + } + + public function getUri() + { + return $this->uri; + } +} diff --git a/lib/JSON_renderer.php b/lib/JSON_renderer.php index 851ea0487..12fd2a6be 100644 --- a/lib/JSON_renderer.php +++ b/lib/JSON_renderer.php @@ -107,6 +107,12 @@ public static function getFullBookContentArray ($book) { $link = new LinkNavigation ($tag->getUri ()); array_push ($out ["tags"], array ("name" => $tag->name, "url" => $link->hrefXhtml ())); } + + $out ["identifiers"] = array (); + foreach ($book->getIdentifiers () as $ident) { + array_push ($out ["identifiers"], array ("name" => $ident->formattedType, "url" => $ident->getUri ())); + } + $out ["customcolumns_preview"] = $book->getCustomColumnValues($config['cops_calibre_custom_column_preview'], true); return $out; @@ -146,6 +152,7 @@ public static function addCompleteArray ($in) { "authorsTitle" => localize("authors.title"), "bookwordTitle" => localize("bookword.title"), "tagsTitle" => localize("tags.title"), + "linksTitle" => localize("links.title"), "seriesTitle" => localize("series.title"), "customizeTitle" => localize ("customize.title"), "aboutTitle" => localize ("about.title"),