|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
5
|
|
|
* |
|
6
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
7
|
|
|
* @author SenorSmartyPants <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class Identifier |
|
11
|
|
|
{ |
|
12
|
|
|
public $id; |
|
13
|
|
|
public $type; |
|
14
|
|
|
public $formattedType; |
|
15
|
|
|
public $val; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($post) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->id = $post->id; |
|
20
|
|
|
$this->type = strtolower($post->type);; |
|
21
|
|
|
$this->val = $post->val; |
|
22
|
|
|
$this->formatType(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function formatType() |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
if ($this->type == 'amazon') { |
|
28
|
|
|
$this->formattedType = "Amazon"; |
|
29
|
|
|
$this->uri = sprintf("https://amazon.com/dp/%s", $this->val); |
|
|
|
|
|
|
30
|
|
|
} else if ($this->type == "asin") { |
|
31
|
|
|
$this->formattedType = $this->type; |
|
32
|
|
|
$this->uri = sprintf("https://amazon.com/dp/%s", $this->val); |
|
33
|
|
|
} else if (substr($this->type, 0, 7) == "amazon_") { |
|
34
|
|
|
$this->formattedType = sprintf("Amazon.co.%s", substr($this->type, 7)); |
|
35
|
|
|
$this->uri = sprintf("https://amazon.co.%s/dp/%s", substr($this->type, 7), $this->val); |
|
36
|
|
|
} else if ($this->type == "isbn") { |
|
37
|
|
|
$this->formattedType = "ISBN"; |
|
38
|
|
|
$this->uri = sprintf("https://www.worldcat.org/isbn/%s", $this->val); |
|
39
|
|
|
} else if ($this->type == "doi") { |
|
40
|
|
|
$this->formattedType = "DOI"; |
|
41
|
|
|
$this->uri = sprintf("https://dx.doi.org/%s", $this->val); |
|
42
|
|
|
} else if ($this->type == "douban") { |
|
43
|
|
|
$this->formattedType = "Douban"; |
|
44
|
|
|
$this->uri = sprintf("https://book.douban.com/subject/%s", $this->val); |
|
45
|
|
|
} else if ($this->type == "goodreads") { |
|
46
|
|
|
$this->formattedType = "Goodreads"; |
|
47
|
|
|
$this->uri = sprintf("https://www.goodreads.com/book/show/%s", $this->val); |
|
48
|
|
|
} else if ($this->type == "google") { |
|
49
|
|
|
$this->formattedType = "Google Books"; |
|
50
|
|
|
$this->uri = sprintf("https://books.google.com/books?id=%s", $this->val); |
|
51
|
|
|
} else if ($this->type == "kobo") { |
|
52
|
|
|
$this->formattedType = "Kobo"; |
|
53
|
|
|
$this->uri = sprintf("https://www.kobo.com/ebook/%s", $this->val); |
|
54
|
|
|
} else if ($this->type == "litres") { |
|
55
|
|
|
$this->formattedType = "ЛитРес"; |
|
56
|
|
|
$this->uri = sprintf("https://www.litres.ru/%s", $this->val); |
|
57
|
|
|
} else if ($this->type == "issn") { |
|
58
|
|
|
$this->formattedType = "ISSN"; |
|
59
|
|
|
$this->uri = sprintf("https://portal.issn.org/resource/ISSN/%s", $this->val); |
|
60
|
|
|
} else if ($this->type == "isfdb") { |
|
61
|
|
|
$this->formattedType = "ISFDB"; |
|
62
|
|
|
$this->uri = sprintf("http://www.isfdb.org/cgi-bin/pl.cgi?%s", $this->val); |
|
63
|
|
|
} else if ($this->type == "lubimyczytac") { |
|
64
|
|
|
$this->formattedType = "Lubimyczytac"; |
|
65
|
|
|
$this->uri = sprintf("https://lubimyczytac.pl/ksiazka/%s/ksiazka", $this->val); |
|
66
|
|
|
} else if ($this->type == "url") { |
|
67
|
|
|
$this->formattedType = $this->type; |
|
68
|
|
|
$this->uri = $this->val; |
|
69
|
|
|
} else { |
|
70
|
|
|
$this->formattedType = $this->type; |
|
71
|
|
|
$this->uri = ''; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getUri() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->uri; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.