These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * COPS (Calibre OPDS PHP Server) class file |
||
4 | * |
||
5 | * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
||
6 | * @author Sébastien Lucas <[email protected]> |
||
7 | */ |
||
8 | |||
9 | require_once('base.php'); |
||
10 | require_once('serie.php'); |
||
11 | require_once('author.php'); |
||
12 | require_once('rating.php'); |
||
13 | require_once('publisher.php'); |
||
14 | require_once('tag.php'); |
||
15 | require_once('language.php'); |
||
16 | require_once("customcolumn.php"); |
||
17 | require_once('data.php'); |
||
18 | require_once('resources/php-epub-meta/epub.php'); |
||
19 | |||
20 | // Silly thing because PHP forbid string concatenation in class const |
||
21 | define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id |
||
22 | left outer join books_ratings_link on books_ratings_link.book = books.id |
||
23 | left outer join ratings on books_ratings_link.rating = ratings.id "); |
||
24 | define ('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort "); |
||
25 | define ('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
26 | where books_publishers_link.book = books.id and publisher = ? {1} order by publisher"); |
||
27 | define ('SQL_BOOKS_BY_FIRST_LETTER', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
28 | where upper (books.sort) like ? order by books.sort"); |
||
29 | define ('SQL_BOOKS_BY_AUTHOR', "select {0} from books_authors_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
30 | left outer join books_series_link on books_series_link.book = books.id |
||
31 | where books_authors_link.book = books.id and author = ? {1} order by series desc, series_index asc, pubdate asc"); |
||
32 | define ('SQL_BOOKS_BY_SERIE', "select {0} from books_series_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
33 | where books_series_link.book = books.id and series = ? {1} order by series_index"); |
||
34 | define ('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
35 | where books_tags_link.book = books.id and tag = ? {1} order by sort"); |
||
36 | define ('SQL_BOOKS_BY_LANGUAGE', "select {0} from books_languages_link, books " . SQL_BOOKS_LEFT_JOIN . " |
||
37 | where books_languages_link.book = books.id and lang_code = ? {1} order by sort"); |
||
38 | define ('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
39 | where {2}.book = books.id and {2}.{3} = ? {1} order by sort"); |
||
40 | define ('SQL_BOOKS_BY_CUSTOM_BOOL_TRUE', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
41 | where {2}.book = books.id and {2}.value = 1 {1} order by sort"); |
||
42 | define ('SQL_BOOKS_BY_CUSTOM_BOOL_FALSE', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
43 | where {2}.book = books.id and {2}.value = 0 {1} order by sort"); |
||
44 | define ('SQL_BOOKS_BY_CUSTOM_BOOL_NULL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
45 | where books.id not in (select book from {2}) {1} order by sort"); |
||
46 | define ('SQL_BOOKS_BY_CUSTOM_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
47 | left join {2} on {2}.book = books.id |
||
48 | left join {3} on {3}.id = {2}.{4} |
||
49 | where {3}.value = ? order by sort"); |
||
50 | define ('SQL_BOOKS_BY_CUSTOM_RATING_NULL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
51 | left join {2} on {2}.book = books.id |
||
52 | left join {3} on {3}.id = {2}.{4} |
||
53 | where ((books.id not in (select {2}.book from {2})) or ({3}.value = 0)) {1} order by sort"); |
||
54 | define ('SQL_BOOKS_BY_CUSTOM_DATE', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
55 | where {2}.book = books.id and date({2}.value) = ? {1} order by sort"); |
||
56 | define ('SQL_BOOKS_BY_CUSTOM_DIRECT', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
57 | where {2}.book = books.id and {2}.value = ? {1} order by sort"); |
||
58 | define ('SQL_BOOKS_BY_CUSTOM_DIRECT_ID', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
||
59 | where {2}.book = books.id and {2}.id = ? {1} order by sort"); |
||
60 | define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
61 | where ( |
||
62 | exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or |
||
63 | exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or |
||
64 | exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or |
||
65 | exists (select null from publishers, books_publishers_link where book = books.id and books_publishers_link.publisher = publishers.id and publishers.name like ?) or |
||
66 | title like ?) {1} order by books.sort"); |
||
67 | define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
68 | where 1=1 {1} order by timestamp desc limit "); |
||
69 | define ('SQL_BOOKS_BY_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
||
70 | where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort"); |
||
71 | |||
72 | class Book extends Base { |
||
73 | const ALL_BOOKS_UUID = "urn:uuid"; |
||
74 | const ALL_BOOKS_ID = "cops:books"; |
||
75 | const ALL_RECENT_BOOKS_ID = "cops:recentbooks"; |
||
76 | const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating"; |
||
77 | |||
78 | const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN; |
||
79 | const SQL_BOOKS_ALL = SQL_BOOKS_ALL; |
||
80 | const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER; |
||
81 | const SQL_BOOKS_BY_FIRST_LETTER = SQL_BOOKS_BY_FIRST_LETTER; |
||
82 | const SQL_BOOKS_BY_AUTHOR = SQL_BOOKS_BY_AUTHOR; |
||
83 | const SQL_BOOKS_BY_SERIE = SQL_BOOKS_BY_SERIE; |
||
84 | const SQL_BOOKS_BY_TAG = SQL_BOOKS_BY_TAG; |
||
85 | const SQL_BOOKS_BY_LANGUAGE = SQL_BOOKS_BY_LANGUAGE; |
||
86 | const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM; |
||
87 | const SQL_BOOKS_BY_CUSTOM_BOOL_TRUE = SQL_BOOKS_BY_CUSTOM_BOOL_TRUE; |
||
88 | const SQL_BOOKS_BY_CUSTOM_BOOL_FALSE = SQL_BOOKS_BY_CUSTOM_BOOL_FALSE; |
||
89 | const SQL_BOOKS_BY_CUSTOM_BOOL_NULL = SQL_BOOKS_BY_CUSTOM_BOOL_NULL; |
||
90 | const SQL_BOOKS_BY_CUSTOM_RATING = SQL_BOOKS_BY_CUSTOM_RATING; |
||
91 | const SQL_BOOKS_BY_CUSTOM_RATING_NULL = SQL_BOOKS_BY_CUSTOM_RATING_NULL; |
||
92 | const SQL_BOOKS_BY_CUSTOM_DATE = SQL_BOOKS_BY_CUSTOM_DATE; |
||
93 | 75 | const SQL_BOOKS_BY_CUSTOM_DIRECT = SQL_BOOKS_BY_CUSTOM_DIRECT; |
|
94 | 75 | const SQL_BOOKS_BY_CUSTOM_DIRECT_ID = SQL_BOOKS_BY_CUSTOM_DIRECT_ID; |
|
95 | 75 | const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY; |
|
96 | 75 | const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; |
|
97 | 75 | const SQL_BOOKS_BY_RATING = SQL_BOOKS_BY_RATING; |
|
98 | 75 | ||
99 | 75 | const BAD_SEARCH = "QQQQQ"; |
|
100 | 75 | ||
101 | 75 | public $id; |
|
102 | 75 | public $title; |
|
103 | 75 | public $timestamp; |
|
104 | 75 | public $pubdate; |
|
105 | public $path; |
||
106 | 41 | public $uuid; |
|
107 | 41 | public $hasCover; |
|
108 | 75 | public $relativePath; |
|
109 | 75 | public $seriesIndex; |
|
110 | public $comment; |
||
111 | 40 | public $rating; |
|
112 | 40 | public $datas = NULL; |
|
113 | public $authors = NULL; |
||
114 | public $publisher = NULL; |
||
115 | 4 | public $serie = NULL; |
|
116 | 4 | public $tags = NULL; |
|
117 | public $languages = NULL; |
||
118 | public $format = array (); |
||
119 | 3 | ||
120 | 3 | ||
121 | public function __construct($line) { |
||
122 | $this->id = $line->id; |
||
123 | 3 | $this->title = $line->title; |
|
124 | 3 | $this->timestamp = strtotime ($line->timestamp); |
|
125 | 3 | $this->pubdate = $line->pubdate; |
|
126 | 3 | $this->path = Base::getDbDirectory () . $line->path; |
|
127 | $this->relativePath = $line->path; |
||
128 | $this->seriesIndex = $line->series_index; |
||
129 | 41 | $this->comment = $line->comment; |
|
130 | 41 | $this->uuid = $line->uuid; |
|
131 | $this->hasCover = $line->has_cover; |
||
132 | if (!file_exists ($this->getFilePath ("jpg"))) { |
||
133 | // double check |
||
134 | $this->hasCover = 0; |
||
135 | 46 | } |
|
136 | 46 | $this->rating = $line->rating; |
|
137 | 46 | } |
|
138 | 46 | ||
139 | 46 | public function getEntryId () { |
|
140 | return self::ALL_BOOKS_UUID.":".$this->uuid; |
||
141 | } |
||
142 | |||
143 | public static function getEntryIdByLetter ($startingLetter) { |
||
144 | return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
||
145 | } |
||
146 | |||
147 | public function getUri () { |
||
148 | return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
||
149 | } |
||
150 | 4 | ||
151 | 4 | public function getDetailUrl () { |
|
152 | 4 | $urlParam = $this->getUri (); |
|
153 | 4 | if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
154 | 4 | return 'index.php' . $urlParam; |
|
155 | } |
||
156 | |||
157 | 45 | public function getTitle () { |
|
158 | 45 | return $this->title; |
|
159 | 45 | } |
|
160 | 45 | ||
161 | 45 | /* Other class (author, series, tag, ...) initialization and accessors */ |
|
162 | |||
163 | /** |
||
164 | 9 | * @return Author[] |
|
165 | 9 | */ |
|
166 | 9 | public function getAuthors () { |
|
167 | if (is_null ($this->authors)) { |
||
168 | $this->authors = Author::getAuthorByBookId ($this->id); |
||
169 | } |
||
170 | 9 | return $this->authors; |
|
171 | 9 | } |
|
172 | 9 | ||
173 | public function getAuthorsName () { |
||
174 | 9 | return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
|
175 | 9 | } |
|
176 | 9 | ||
177 | public function getAuthorsSort () { |
||
178 | return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
||
179 | 9 | } |
|
180 | 9 | ||
181 | 9 | public function getPublisher () { |
|
182 | if (is_null ($this->publisher)) { |
||
183 | 9 | $this->publisher = Publisher::getPublisherByBookId ($this->id); |
|
184 | } |
||
185 | return $this->publisher; |
||
186 | } |
||
187 | 9 | ||
188 | 9 | /** |
|
189 | 9 | * @return Serie |
|
190 | */ |
||
191 | 9 | public function getSerie () { |
|
192 | 9 | if (is_null ($this->serie)) { |
|
193 | 9 | $this->serie = Serie::getSerieByBookId ($this->id); |
|
194 | 9 | } |
|
195 | return $this->serie; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | 59 | public function getLanguages () { |
|
202 | $lang = array (); |
||
203 | 59 | $result = parent::getDb ()->prepare('select languages.lang_code |
|
0 ignored issues
–
show
|
|||
204 | 59 | from books_languages_link, languages |
|
205 | 59 | where books_languages_link.lang_code = languages.id |
|
206 | 59 | and book = ? |
|
207 | order by item_order'); |
||
208 | $result->execute (array ($this->id)); |
||
209 | while ($post = $result->fetchObject ()) |
||
210 | { |
||
211 | 56 | array_push ($lang, Language::getLanguageString($post->lang_code)); |
|
212 | 56 | } |
|
213 | 56 | return implode (", ", $lang); |
|
214 | } |
||
215 | 3 | ||
216 | 3 | /** |
|
217 | 1 | * @return Tag[] |
|
218 | 1 | */ |
|
219 | 1 | public function getTags () { |
|
220 | if (is_null ($this->tags)) { |
||
221 | 3 | $this->tags = array (); |
|
222 | |||
223 | 3 | $result = parent::getDb ()->prepare('select tags.id as id, name |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getTags() ). Are you sure this is correct? If so, you might want to change this to $this->getDb() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
224 | 1 | from books_tags_link, tags |
|
225 | 1 | where tag = tags.id |
|
226 | and book = ? |
||
227 | 3 | order by name'); |
|
228 | $result->execute (array ($this->id)); |
||
229 | while ($post = $result->fetchObject ()) |
||
230 | 4 | { |
|
231 | array_push ($this->tags, new Tag ($post)); |
||
232 | 4 | } |
|
233 | 4 | } |
|
234 | 4 | return $this->tags; |
|
235 | 4 | } |
|
236 | 4 | ||
237 | 4 | public function getTagsName () { |
|
238 | 4 | return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
|
239 | 4 | } |
|
240 | 4 | ||
241 | 4 | /** |
|
242 | 4 | * @return Data[] |
|
243 | */ |
||
244 | public function getDatas () |
||
245 | 3 | { |
|
246 | if (is_null ($this->datas)) { |
||
247 | $this->datas = Data::getDataByBook ($this); |
||
248 | 3 | } |
|
249 | 3 | return $this->datas; |
|
250 | 3 | } |
|
251 | |||
252 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
||
253 | 7 | ||
254 | 7 | public static function getFilterString () { |
|
255 | 2 | $filter = getURLParam ("tag", NULL); |
|
256 | if (empty ($filter)) return ""; |
||
257 | 5 | ||
258 | 5 | $exists = true; |
|
259 | 5 | if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
|
260 | 5 | $exists = false; |
|
261 | 5 | $filter = $matches[1]; |
|
262 | 3 | } |
|
263 | 3 | ||
264 | 5 | $result = "exists (select null from books_tags_link, tags where books_tags_link.book = books.id and books_tags_link.tag = tags.id and tags.name = '" . $filter . "')"; |
|
265 | |||
266 | if (!$exists) { |
||
267 | 14 | $result = "not " . $result; |
|
268 | 14 | } |
|
269 | 2 | ||
270 | return "and " . $result; |
||
271 | 12 | } |
|
272 | 12 | ||
273 | 11 | public function GetMostInterestingDataToSendToKindle () |
|
274 | { |
||
275 | 1 | $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI"); |
|
276 | $bestRank = -1; |
||
277 | $bestData = NULL; |
||
278 | 41 | foreach ($this->getDatas () as $data) { |
|
279 | 41 | $key = array_search ($data->format, $bestFormatForKindle); |
|
280 | 41 | if ($key !== false && $key > $bestRank) { |
|
281 | 41 | $bestRank = $key; |
|
282 | 36 | $bestData = $data; |
|
283 | 36 | } |
|
284 | 41 | } |
|
285 | 41 | return $bestData; |
|
286 | 35 | } |
|
287 | |||
288 | public function getDataById ($idData) |
||
289 | { |
||
290 | 29 | $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) { |
|
291 | return $data->id == $idData; |
||
292 | }); |
||
293 | return reset ($reduced); |
||
294 | } |
||
295 | 11 | ||
296 | 11 | public function getRating () { |
|
297 | 11 | if (is_null ($this->rating) || $this->rating == 0) { |
|
298 | 11 | return ""; |
|
299 | } |
||
300 | $retour = ""; |
||
301 | 75 | for ($i = 0; $i < $this->rating / 2; $i++) { |
|
302 | $retour .= "★"; |
||
303 | 75 | } |
|
304 | 75 | for ($i = 0; $i < 5 - $this->rating / 2; $i++) { |
|
305 | 75 | $retour .= "☆"; |
|
306 | 75 | } |
|
307 | return $retour; |
||
308 | } |
||
309 | 2 | ||
310 | 2 | public function getPubDate () { |
|
311 | 2 | if (empty ($this->pubdate)) { |
|
312 | return ""; |
||
313 | } |
||
314 | $dateY = (int) substr($this->pubdate, 0, 4); |
||
315 | 75 | if ($dateY > 102) { |
|
316 | 3 | return str_pad($dateY, 4, "0", STR_PAD_LEFT); |
|
317 | } |
||
318 | return ""; |
||
319 | } |
||
320 | 75 | ||
321 | public function getComment ($withSerie = true) { |
||
322 | $addition = ""; |
||
323 | $se = $this->getSerie (); |
||
324 | if (!is_null ($se) && $withSerie) { |
||
325 | $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
||
326 | } |
||
327 | if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
||
328 | { |
||
329 | return $addition . html2xhtml ($this->comment); |
||
330 | } |
||
331 | else |
||
332 | { |
||
333 | return $addition . htmlspecialchars ($this->comment); |
||
334 | } |
||
335 | } |
||
336 | |||
337 | public function getDataFormat ($format) { |
||
338 | $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
||
339 | return $data->format == $format; |
||
340 | }); |
||
341 | return reset ($reduced); |
||
342 | } |
||
343 | |||
344 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
||
345 | { |
||
346 | if ($extension == "jpg") |
||
347 | { |
||
348 | $file = "cover.jpg"; |
||
349 | } |
||
350 | else |
||
351 | { |
||
352 | $data = $this->getDataById ($idData); |
||
353 | if (!$data) return NULL; |
||
354 | $file = $data->name . "." . strtolower ($data->format); |
||
355 | } |
||
356 | |||
357 | if ($relative) |
||
358 | { |
||
359 | return $this->relativePath."/".$file; |
||
360 | 3 | } |
|
361 | 3 | else |
|
362 | 1 | { |
|
363 | return $this->path."/".$file; |
||
364 | } |
||
365 | 3 | } |
|
366 | |||
367 | 3 | public function getUpdatedEpub ($idData) |
|
368 | 3 | { |
|
369 | 3 | global $config; |
|
370 | $data = $this->getDataById ($idData); |
||
371 | 3 | ||
372 | 2 | try |
|
373 | 2 | { |
|
374 | 1 | $epub = new EPub ($data->getLocalPath ()); |
|
375 | 1 | ||
376 | 2 | $epub->Title ($this->title); |
|
377 | 2 | $authorArray = array (); |
|
378 | 1 | foreach ($this->getAuthors() as $author) { |
|
379 | $authorArray [$author->sort] = $author->name; |
||
380 | 2 | } |
|
381 | $epub->Authors ($authorArray); |
||
382 | $epub->Language ($this->getLanguages ()); |
||
383 | $epub->Description ($this->getComment (false)); |
||
384 | $epub->Subjects ($this->getTagsName ()); |
||
385 | 2 | $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg"); |
|
386 | 2 | $epub->Calibre ($this->uuid); |
|
387 | 2 | $se = $this->getSerie (); |
|
388 | 2 | if (!is_null ($se)) { |
|
389 | 2 | $epub->Serie ($se->name); |
|
390 | 2 | $epub->SerieIndex ($this->seriesIndex); |
|
391 | } |
||
392 | 2 | if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
|
393 | $epub->updateForKepub (); |
||
394 | } |
||
395 | 42 | $epub->download ($data->getUpdatedFilenameEpub ()); |
|
396 | } |
||
397 | 42 | catch (Exception $e) |
|
398 | { |
||
399 | 42 | echo "Exception : " . $e->getMessage(); |
|
400 | 42 | } |
|
401 | 18 | } |
|
402 | |||
403 | 18 | public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
404 | 18 | if (is_null ($width) && is_null ($height)) { |
|
405 | return false; |
||
406 | 42 | } |
|
407 | |||
408 | 42 | $file = $this->getFilePath ("jpg"); |
|
409 | 42 | // get image size |
|
410 | 42 | if ($size = GetImageSize($file)) { |
|
411 | 42 | $w = $size[0]; |
|
412 | 42 | $h = $size[1]; |
|
413 | //set new size |
||
414 | 42 | if (!is_null ($width)) { |
|
415 | 42 | $nw = $width; |
|
416 | 42 | if ($nw >= $w) { return false; } |
|
417 | $nh = ($nw*$h)/$w; |
||
418 | 42 | } else { |
|
419 | 42 | $nh = $height; |
|
420 | 39 | if ($nh >= $h) { return false; } |
|
421 | 39 | $nw = ($nh*$w)/$h; |
|
422 | } |
||
423 | 42 | } else { |
|
424 | return false; |
||
425 | } |
||
426 | |||
427 | 39 | //draw the image |
|
428 | 39 | $src_img = imagecreatefromjpeg($file); |
|
429 | 39 | $dst_img = imagecreatetruecolor($nw,$nh); |
|
430 | 39 | imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image |
|
431 | imagejpeg($dst_img,$outputfile,80); |
||
432 | imagedestroy($src_img); |
||
433 | 3 | imagedestroy($dst_img); |
|
434 | 3 | ||
435 | return true; |
||
436 | } |
||
437 | 10 | ||
438 | 10 | public function getLinkArray () |
|
439 | 10 | { |
|
440 | 10 | $linkArray = array(); |
|
441 | 10 | ||
442 | 10 | if ($this->hasCover) |
|
443 | 10 | { |
|
444 | 10 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
445 | 10 | ||
446 | 10 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
447 | 10 | } |
|
448 | 10 | ||
449 | 10 | foreach ($this->getDatas () as $data) |
|
450 | 10 | { |
|
451 | 10 | if ($data->isKnownType ()) |
|
452 | 10 | { |
|
453 | 10 | array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
|
454 | } |
||
455 | } |
||
456 | 8 | ||
457 | 8 | foreach ($this->getAuthors () as $author) { |
|
458 | /* @var $author Author */ |
||
459 | array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); |
||
460 | 1 | } |
|
461 | 1 | ||
462 | $serie = $this->getSerie (); |
||
463 | if (!is_null ($serie)) { |
||
464 | 2 | array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); |
|
465 | 2 | } |
|
466 | |||
467 | return $linkArray; |
||
468 | 2 | } |
|
469 | 2 | ||
470 | |||
471 | public function getEntry () { |
||
472 | 2 | return new EntryBook ($this->getTitle (), $this->getEntryId (), |
|
473 | 2 | $this->getComment (), "text/html", |
|
474 | $this->getLinkArray (), $this); |
||
475 | } |
||
476 | 2 | ||
477 | 2 | public static function getBookCount($database = NULL) { |
|
478 | return parent::executeQuerySingle ('select count(*) from books', $database); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuerySingle() instead of getBookCount() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuerySingle() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
479 | } |
||
480 | 3 | ||
481 | 3 | public static function getCount() { |
|
482 | 3 | global $config; |
|
483 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuerySingle() instead of getCount() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuerySingle() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
484 | $result = array(); |
||
485 | 36 | $entry = new Entry (localize ("allbooks.title"), |
|
486 | 36 | self::ALL_BOOKS_ID, |
|
487 | 36 | str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
488 | 36 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
489 | 36 | array_push ($result, $entry); |
|
490 | 36 | if ($config['cops_recentbooks_limit'] > 0) { |
|
491 | $entry = new Entry (localize ("recent.title"), |
||
492 | 35 | self::ALL_RECENT_BOOKS_ID, |
|
493 | 35 | str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
494 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
||
495 | 1 | array_push ($result, $entry); |
|
496 | } |
||
497 | return $result; |
||
498 | 1 | } |
|
499 | 1 | ||
500 | 1 | public static function getBooksByAuthor($authorId, $n) { |
|
501 | 1 | return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
|
502 | 1 | } |
|
503 | 1 | ||
504 | public static function getBooksByRating($ratingId, $n) { |
||
505 | 1 | return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); |
|
506 | 1 | } |
|
507 | 1 | ||
508 | 1 | public static function getBooksByPublisher($publisherId, $n) { |
|
509 | 1 | return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); |
|
510 | } |
||
511 | |||
512 | public static function getBooksBySeries($serieId, $n) { |
||
513 | return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
||
514 | 2 | } |
|
515 | 2 | ||
516 | 2 | public static function getBooksByTag($tagId, $n) { |
|
517 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
|
518 | 2 | } |
|
519 | 2 | ||
520 | 2 | public static function getBooksByLanguage($languageId, $n) { |
|
521 | 2 | return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
|
522 | 2 | } |
|
523 | 2 | ||
524 | /** |
||
525 | * @param $customColumn CustomColumn |
||
526 | * @param $id integer |
||
527 | 2 | * @param $n integer |
|
528 | * @return array |
||
529 | */ |
||
530 | 2 | public static function getBooksByCustom($customColumn, $id, $n) { |
|
531 | list($query, $params) = $customColumn->getQuery($id); |
||
532 | |||
533 | 2 | return self::getEntryArray ($query, $params, $n); |
|
534 | 2 | } |
|
535 | 2 | ||
536 | public static function getBookById($bookId) { |
||
537 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getBookById() ). Are you sure this is correct? If so, you might want to change this to $this->getDb() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
538 | 1 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
|
539 | 1 | where books.id = ?'); |
|
540 | 1 | $result->execute (array ($bookId)); |
|
541 | while ($post = $result->fetchObject ()) |
||
542 | { |
||
543 | 3 | $book = new Book ($post); |
|
544 | 3 | return $book; |
|
545 | } |
||
546 | return NULL; |
||
547 | 3 | } |
|
548 | 3 | ||
549 | 3 | public static function getBookByDataId($dataId) { |
|
550 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getBookByDataId() ). Are you sure this is correct? If so, you might want to change this to $this->getDb() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
551 | 3 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
|
552 | 3 | where data.book = books.id and data.id = ?'); |
|
553 | 3 | $result->execute (array ($dataId)); |
|
554 | 3 | while ($post = $result->fetchObject ()) |
|
555 | 3 | { |
|
556 | $book = new Book ($post); |
||
557 | $data = new Data ($post, $book); |
||
558 | 25 | $data->id = $dataId; |
|
559 | 25 | $book->datas = array ($data); |
|
560 | return $book; |
||
561 | } |
||
562 | 53 | return NULL; |
|
563 | 53 | } |
|
564 | 53 | ||
565 | 53 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
566 | $i = 0; |
||
567 | 39 | $critArray = array (); |
|
568 | 39 | foreach (array (PageQueryResult::SCOPE_AUTHOR, |
|
569 | 39 | PageQueryResult::SCOPE_TAG, |
|
570 | 53 | PageQueryResult::SCOPE_SERIES, |
|
571 | PageQueryResult::SCOPE_PUBLISHER, |
||
572 | PageQueryResult::SCOPE_BOOK) as $key) { |
||
573 | if (in_array($key, getCurrentOption ('ignored_categories')) || |
||
574 | 5 | (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) { |
|
575 | 5 | $critArray [$i] = self::BAD_SEARCH; |
|
576 | 5 | } |
|
577 | 5 | else { |
|
578 | if (array_key_exists ($key, $query)) { |
||
579 | $critArray [$i] = $query [$key]; |
||
580 | } else { |
||
581 | $critArray [$i] = $query ["all"]; |
||
582 | } |
||
583 | } |
||
584 | $i++; |
||
585 | } |
||
586 | return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
||
587 | } |
||
588 | |||
589 | public static function getBooks($n) { |
||
590 | list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n); |
||
591 | return array ($entryArray, $totalNumber); |
||
592 | } |
||
593 | |||
594 | public static function getAllBooks() { |
||
595 | /* @var $result PDOStatement */ |
||
596 | |||
597 | list (, $result) = parent::executeQuery ("select {0} |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuery() instead of getAllBooks() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuery() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
598 | from books |
||
599 | group by substr (upper (sort), 1, 1) |
||
600 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
||
601 | |||
602 | $entryArray = array(); |
||
603 | while ($post = $result->fetchObject ()) |
||
604 | { |
||
605 | array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
||
606 | str_format (localize("bookword", $post->count), $post->count), "text", |
||
607 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
||
608 | } |
||
609 | return $entryArray; |
||
610 | } |
||
611 | |||
612 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
||
613 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
||
614 | } |
||
615 | |||
616 | public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
||
617 | /* @var $totalNumber integer */ |
||
618 | /* @var $result PDOStatement */ |
||
619 | list($totalNumber, $result) = parent::executeQuery($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuery() instead of getEntryArray() ). Are you sure this is correct? If so, you might want to change this to $this->executeQuery() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
620 | |||
621 | $entryArray = array(); |
||
622 | while ($post = $result->fetchObject()) |
||
623 | { |
||
624 | $book = new Book ($post); |
||
625 | array_push ($entryArray, $book->getEntry()); |
||
626 | } |
||
627 | return array ($entryArray, $totalNumber); |
||
628 | } |
||
629 | |||
630 | public static function getAllRecentBooks() { |
||
631 | global $config; |
||
632 | list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); |
||
633 | return $entryArray; |
||
634 | } |
||
635 | |||
636 | /** |
||
637 | * The values of all the specified columns |
||
638 | * |
||
639 | * @param string[] $columns |
||
640 | * @return CustomColumn[] |
||
641 | */ |
||
642 | public function getCustomColumnValues($columns) { |
||
643 | $result = array(); |
||
644 | |||
645 | foreach ($columns as $lookup) { |
||
646 | $col = CustomColumnType::createByLookup($lookup); |
||
647 | if (! is_null($col)) { |
||
648 | $cust = $col->getCustomByBook($this); |
||
649 | if (! is_null($cust)) { |
||
650 | array_push($result, $cust); |
||
651 | } |
||
652 | } |
||
653 | } |
||
654 | |||
655 | return $result; |
||
656 | } |
||
657 | } |
||
658 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.