Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lang/Localization_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions lib/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ();

Expand Down Expand Up @@ -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[]
*/
Expand Down
79 changes: 79 additions & 0 deletions lib/Identifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author SenorSmartyPants <senorsmartypants@gmail.com>
*/

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;
}
}
7 changes: 7 additions & 0 deletions lib/JSON_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down