@@ -111,7 +111,8 @@ discard block |
||
111 | 111 | public $format = array (); |
112 | 112 | |
113 | 113 | |
114 | - public function __construct($line) { |
|
114 | + public function __construct($line) |
|
115 | + { |
|
115 | 116 | $this->id = $line->id; |
116 | 117 | $this->title = $line->title; |
117 | 118 | $this->timestamp = strtotime($line->timestamp); |
@@ -129,25 +130,32 @@ discard block |
||
129 | 130 | $this->rating = $line->rating; |
130 | 131 | } |
131 | 132 | |
132 | - public function getEntryId() { |
|
133 | + public function getEntryId() |
|
134 | + { |
|
133 | 135 | return self::ALL_BOOKS_UUID.':'.$this->uuid; |
134 | 136 | } |
135 | 137 | |
136 | - public static function getEntryIdByLetter ($startingLetter) { |
|
138 | + public static function getEntryIdByLetter ($startingLetter) |
|
139 | + { |
|
137 | 140 | return self::ALL_BOOKS_ID.':letter:'.$startingLetter; |
138 | 141 | } |
139 | 142 | |
140 | - public function getUri () { |
|
143 | + public function getUri () |
|
144 | + { |
|
141 | 145 | return '?page='.parent::PAGE_BOOK_DETAIL.'&id=' . $this->id; |
142 | 146 | } |
143 | 147 | |
144 | - public function getDetailUrl () { |
|
148 | + public function getDetailUrl () |
|
149 | + { |
|
145 | 150 | $urlParam = $this->getUri(); |
146 | - if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam (DB)); |
|
151 | + if (!is_null(GetUrlParam(DB))) { |
|
152 | + $urlParam = addURLParameter($urlParam, DB, GetUrlParam (DB)); |
|
153 | + } |
|
147 | 154 | return 'index.php' . $urlParam; |
148 | 155 | } |
149 | 156 | |
150 | - public function getTitle () { |
|
157 | + public function getTitle () |
|
158 | + { |
|
151 | 159 | return $this->title; |
152 | 160 | } |
153 | 161 | |
@@ -156,22 +164,26 @@ discard block |
||
156 | 164 | /** |
157 | 165 | * @return Author[] |
158 | 166 | */ |
159 | - public function getAuthors () { |
|
167 | + public function getAuthors () |
|
168 | + { |
|
160 | 169 | if (is_null($this->authors)) { |
161 | 170 | $this->authors = Author::getAuthorByBookId($this->id); |
162 | 171 | } |
163 | 172 | return $this->authors; |
164 | 173 | } |
165 | 174 | |
166 | - public function getAuthorsName () { |
|
175 | + public function getAuthorsName () |
|
176 | + { |
|
167 | 177 | return implode(', ', array_map(function ($author) { return $author->name; }, $this->getAuthors())); |
168 | 178 | } |
169 | 179 | |
170 | - public function getAuthorsSort () { |
|
180 | + public function getAuthorsSort () |
|
181 | + { |
|
171 | 182 | return implode(', ', array_map(function ($author) { return $author->sort; }, $this->getAuthors())); |
172 | 183 | } |
173 | 184 | |
174 | - public function getPublisher () { |
|
185 | + public function getPublisher () |
|
186 | + { |
|
175 | 187 | if (is_null($this->publisher)) { |
176 | 188 | $this->publisher = Publisher::getPublisherByBookId($this->id); |
177 | 189 | } |
@@ -181,7 +193,8 @@ discard block |
||
181 | 193 | /** |
182 | 194 | * @return Serie |
183 | 195 | */ |
184 | - public function getSerie() { |
|
196 | + public function getSerie() |
|
197 | + { |
|
185 | 198 | if (is_null($this->serie)) { |
186 | 199 | $this->serie = Serie::getSerieByBookId($this->id); |
187 | 200 | } |
@@ -191,7 +204,8 @@ discard block |
||
191 | 204 | /** |
192 | 205 | * @return string |
193 | 206 | */ |
194 | - public function getLanguages() { |
|
207 | + public function getLanguages() |
|
208 | + { |
|
195 | 209 | $lang = array(); |
196 | 210 | $result = parent::getDb()->prepare('select languages.lang_code |
197 | 211 | from books_languages_link, languages |
@@ -199,8 +213,7 @@ discard block |
||
199 | 213 | and book = ? |
200 | 214 | order by item_order'); |
201 | 215 | $result->execute(array($this->id)); |
202 | - while ($post = $result->fetchObject()) |
|
203 | - { |
|
216 | + while ($post = $result->fetchObject()) { |
|
204 | 217 | array_push($lang, Language::getLanguageString($post->lang_code)); |
205 | 218 | } |
206 | 219 | return implode(', ', $lang); |
@@ -209,7 +222,8 @@ discard block |
||
209 | 222 | /** |
210 | 223 | * @return Tag[] |
211 | 224 | */ |
212 | - public function getTags() { |
|
225 | + public function getTags() |
|
226 | + { |
|
213 | 227 | if (is_null ($this->tags)) { |
214 | 228 | $this->tags = array(); |
215 | 229 | |
@@ -219,15 +233,15 @@ discard block |
||
219 | 233 | and book = ? |
220 | 234 | order by name'); |
221 | 235 | $result->execute(array($this->id)); |
222 | - while ($post = $result->fetchObject()) |
|
223 | - { |
|
236 | + while ($post = $result->fetchObject()) { |
|
224 | 237 | array_push($this->tags, new Tag($post)); |
225 | 238 | } |
226 | 239 | } |
227 | 240 | return $this->tags; |
228 | 241 | } |
229 | 242 | |
230 | - public function getTagsName() { |
|
243 | + public function getTagsName() |
|
244 | + { |
|
231 | 245 | return implode(', ', array_map(function ($tag) { return $tag->name; }, $this->getTags())); |
232 | 246 | } |
233 | 247 | |
@@ -235,7 +249,8 @@ discard block |
||
235 | 249 | /** |
236 | 250 | * @return Identifiers[] |
237 | 251 | */ |
238 | - public function getIdentifiers() { |
|
252 | + public function getIdentifiers() |
|
253 | + { |
|
239 | 254 | if (is_null ($this->identifiers)) { |
240 | 255 | $this->identifiers = array(); |
241 | 256 | |
@@ -244,8 +259,7 @@ discard block |
||
244 | 259 | where book = ? |
245 | 260 | order by type'); |
246 | 261 | $result->execute(array($this->id)); |
247 | - while ($post = $result->fetchObject()) |
|
248 | - { |
|
262 | + while ($post = $result->fetchObject()) { |
|
249 | 263 | array_push($this->identifiers, new Identifier($post)); |
250 | 264 | } |
251 | 265 | |
@@ -266,9 +280,12 @@ discard block |
||
266 | 280 | |
267 | 281 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
268 | 282 | |
269 | - public static function getFilterString() { |
|
283 | + public static function getFilterString() |
|
284 | + { |
|
270 | 285 | $filter = getURLParam('tag', NULL); |
271 | - if (empty($filter)) return ''; |
|
286 | + if (empty($filter)) { |
|
287 | + return ''; |
|
288 | + } |
|
272 | 289 | |
273 | 290 | $exists = true; |
274 | 291 | if (preg_match("/^!(.*)$/", $filter, $matches)) { |
@@ -308,7 +325,8 @@ discard block |
||
308 | 325 | return reset($reduced); |
309 | 326 | } |
310 | 327 | |
311 | - public function getRating() { |
|
328 | + public function getRating() |
|
329 | + { |
|
312 | 330 | if (is_null($this->rating) || $this->rating == 0) { |
313 | 331 | return ''; |
314 | 332 | } |
@@ -322,7 +340,8 @@ discard block |
||
322 | 340 | return $retour; |
323 | 341 | } |
324 | 342 | |
325 | - public function getPubDate() { |
|
343 | + public function getPubDate() |
|
344 | + { |
|
326 | 345 | if (empty ($this->pubdate)) { |
327 | 346 | return ''; |
328 | 347 | } |
@@ -333,23 +352,22 @@ discard block |
||
333 | 352 | return ''; |
334 | 353 | } |
335 | 354 | |
336 | - public function getComment($withSerie = true) { |
|
355 | + public function getComment($withSerie = true) |
|
356 | + { |
|
337 | 357 | $addition = ''; |
338 | 358 | $se = $this->getSerie (); |
339 | 359 | if (!is_null ($se) && $withSerie) { |
340 | 360 | $addition = $addition . '<strong>' . localize('content.series') . '</strong>' . str_format(localize('content.series.data'), $this->seriesIndex, htmlspecialchars($se->name)) . "<br />\n"; |
341 | 361 | } |
342 | - if (preg_match('/<\/(div|p|a|span)>/', $this->comment)) |
|
343 | - { |
|
362 | + if (preg_match('/<\/(div|p|a|span)>/', $this->comment)) { |
|
344 | 363 | return $addition . html2xhtml($this->comment); |
345 | - } |
|
346 | - else |
|
347 | - { |
|
364 | + } else { |
|
348 | 365 | return $addition . htmlspecialchars($this->comment); |
349 | 366 | } |
350 | 367 | } |
351 | 368 | |
352 | - public function getDataFormat($format) { |
|
369 | + public function getDataFormat($format) |
|
370 | + { |
|
353 | 371 | $reduced = array_filter($this->getDatas(), function ($data) use ($format) { |
354 | 372 | return $data->format == $format; |
355 | 373 | }); |
@@ -358,23 +376,19 @@ discard block |
||
358 | 376 | |
359 | 377 | public function getFilePath($extension, $idData = NULL, $relative = false) |
360 | 378 | { |
361 | - if ($extension == 'jpg') |
|
362 | - { |
|
379 | + if ($extension == 'jpg') { |
|
363 | 380 | $file = 'cover.jpg'; |
364 | - } |
|
365 | - else |
|
366 | - { |
|
381 | + } else { |
|
367 | 382 | $data = $this->getDataById($idData); |
368 | - if (!$data) return NULL; |
|
383 | + if (!$data) { |
|
384 | + return NULL; |
|
385 | + } |
|
369 | 386 | $file = $data->name . '.' . strtolower($data->format); |
370 | 387 | } |
371 | 388 | |
372 | - if ($relative) |
|
373 | - { |
|
389 | + if ($relative) { |
|
374 | 390 | return $this->relativePath.'/'.$file; |
375 | - } |
|
376 | - else |
|
377 | - { |
|
391 | + } else { |
|
378 | 392 | return $this->path.'/'.$file; |
379 | 393 | } |
380 | 394 | } |
@@ -384,8 +398,7 @@ discard block |
||
384 | 398 | global $config; |
385 | 399 | $data = $this->getDataById($idData); |
386 | 400 | |
387 | - try |
|
388 | - { |
|
401 | + try { |
|
389 | 402 | $epub = new EPub($data->getLocalPath()); |
390 | 403 | |
391 | 404 | $epub->Title($this->title); |
@@ -410,14 +423,13 @@ discard block |
||
410 | 423 | $filename = $data->getUpdatedFilenameKepub(); |
411 | 424 | } |
412 | 425 | $epub->download($filename); |
413 | - } |
|
414 | - catch (Exception $e) |
|
415 | - { |
|
426 | + } catch (Exception $e) { |
|
416 | 427 | echo 'Exception : ' . $e->getMessage(); |
417 | 428 | } |
418 | 429 | } |
419 | 430 | |
420 | - public function getThumbnail($width, $height, $outputfile = NULL) { |
|
431 | + public function getThumbnail($width, $height, $outputfile = NULL) |
|
432 | + { |
|
421 | 433 | if (is_null($width) && is_null($height)) { |
422 | 434 | return false; |
423 | 435 | } |
@@ -456,17 +468,14 @@ discard block |
||
456 | 468 | { |
457 | 469 | $linkArray = array(); |
458 | 470 | |
459 | - if ($this->hasCover) |
|
460 | - { |
|
471 | + if ($this->hasCover) { |
|
461 | 472 | array_push($linkArray, Data::getLink($this, 'jpg', 'image/jpeg', Link::OPDS_IMAGE_TYPE, 'cover.jpg', NULL)); |
462 | 473 | |
463 | 474 | array_push($linkArray, Data::getLink($this, 'jpg', 'image/jpeg', Link::OPDS_THUMBNAIL_TYPE, 'cover.jpg', NULL)); |
464 | 475 | } |
465 | 476 | |
466 | - foreach ($this->getDatas() as $data) |
|
467 | - { |
|
468 | - if ($data->isKnownType()) |
|
469 | - { |
|
477 | + foreach ($this->getDatas() as $data) { |
|
478 | + if ($data->isKnownType()) { |
|
470 | 479 | array_push($linkArray, $data->getDataLink(Link::OPDS_ACQUISITION_TYPE, $data->format)); |
471 | 480 | } |
472 | 481 | } |
@@ -485,17 +494,20 @@ discard block |
||
485 | 494 | } |
486 | 495 | |
487 | 496 | |
488 | - public function getEntry() { |
|
497 | + public function getEntry() |
|
498 | + { |
|
489 | 499 | return new EntryBook($this->getTitle(), $this->getEntryId(), |
490 | 500 | $this->getComment(), 'text/html', |
491 | 501 | $this->getLinkArray(), $this); |
492 | 502 | } |
493 | 503 | |
494 | - public static function getBookCount($database = NULL) { |
|
504 | + public static function getBookCount($database = NULL) |
|
505 | + { |
|
495 | 506 | return parent::executeQuerySingle('select count(*) from books', $database); |
496 | 507 | } |
497 | 508 | |
498 | - public static function getCount() { |
|
509 | + public static function getCount() |
|
510 | + { |
|
499 | 511 | global $config; |
500 | 512 | $nBooks = parent::executeQuerySingle('select count(*) from books'); |
501 | 513 | $result = array(); |
@@ -514,27 +526,33 @@ discard block |
||
514 | 526 | return $result; |
515 | 527 | } |
516 | 528 | |
517 | - public static function getBooksByAuthor($authorId, $n) { |
|
529 | + public static function getBooksByAuthor($authorId, $n) |
|
530 | + { |
|
518 | 531 | return self::getEntryArray(self::SQL_BOOKS_BY_AUTHOR, array($authorId), $n); |
519 | 532 | } |
520 | 533 | |
521 | - public static function getBooksByRating($ratingId, $n) { |
|
534 | + public static function getBooksByRating($ratingId, $n) |
|
535 | + { |
|
522 | 536 | return self::getEntryArray(self::SQL_BOOKS_BY_RATING, array($ratingId), $n); |
523 | 537 | } |
524 | 538 | |
525 | - public static function getBooksByPublisher($publisherId, $n) { |
|
539 | + public static function getBooksByPublisher($publisherId, $n) |
|
540 | + { |
|
526 | 541 | return self::getEntryArray(self::SQL_BOOKS_BY_PUBLISHER, array($publisherId), $n); |
527 | 542 | } |
528 | 543 | |
529 | - public static function getBooksBySeries($serieId, $n) { |
|
544 | + public static function getBooksBySeries($serieId, $n) |
|
545 | + { |
|
530 | 546 | return self::getEntryArray(self::SQL_BOOKS_BY_SERIE, array($serieId), $n); |
531 | 547 | } |
532 | 548 | |
533 | - public static function getBooksByTag($tagId, $n) { |
|
549 | + public static function getBooksByTag($tagId, $n) |
|
550 | + { |
|
534 | 551 | return self::getEntryArray(self::SQL_BOOKS_BY_TAG, array($tagId), $n); |
535 | 552 | } |
536 | 553 | |
537 | - public static function getBooksByLanguage($languageId, $n) { |
|
554 | + public static function getBooksByLanguage($languageId, $n) |
|
555 | + { |
|
538 | 556 | return self::getEntryArray(self::SQL_BOOKS_BY_LANGUAGE, array($languageId), $n); |
539 | 557 | } |
540 | 558 | |
@@ -544,32 +562,33 @@ discard block |
||
544 | 562 | * @param $n integer |
545 | 563 | * @return array |
546 | 564 | */ |
547 | - public static function getBooksByCustom($customColumn, $id, $n) { |
|
565 | + public static function getBooksByCustom($customColumn, $id, $n) |
|
566 | + { |
|
548 | 567 | list($query, $params) = $customColumn->getQuery($id); |
549 | 568 | |
550 | 569 | return self::getEntryArray($query, $params, $n); |
551 | 570 | } |
552 | 571 | |
553 | - public static function getBookById($bookId) { |
|
572 | + public static function getBookById($bookId) |
|
573 | + { |
|
554 | 574 | $result = parent::getDb()->prepare('select ' . self::BOOK_COLUMNS . ' |
555 | 575 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
556 | 576 | where books.id = ?'); |
557 | 577 | $result->execute(array($bookId)); |
558 | - while ($post = $result->fetchObject()) |
|
559 | - { |
|
578 | + while ($post = $result->fetchObject()) { |
|
560 | 579 | $book = new Book($post); |
561 | 580 | return $book; |
562 | 581 | } |
563 | 582 | return NULL; |
564 | 583 | } |
565 | 584 | |
566 | - public static function getBookByDataId($dataId) { |
|
585 | + public static function getBookByDataId($dataId) |
|
586 | + { |
|
567 | 587 | $result = parent::getDb()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
568 | 588 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
569 | 589 | where data.book = books.id and data.id = ?'); |
570 | 590 | $result->execute(array($dataId)); |
571 | - while ($post = $result->fetchObject()) |
|
572 | - { |
|
591 | + while ($post = $result->fetchObject()) { |
|
573 | 592 | $book = new Book($post); |
574 | 593 | $data = new Data($post, $book); |
575 | 594 | $data->id = $dataId; |
@@ -579,7 +598,8 @@ discard block |
||
579 | 598 | return NULL; |
580 | 599 | } |
581 | 600 | |
582 | - public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
601 | + public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) |
|
602 | + { |
|
583 | 603 | $i = 0; |
584 | 604 | $critArray = array(); |
585 | 605 | foreach (array(PageQueryResult::SCOPE_AUTHOR, |
@@ -590,8 +610,7 @@ discard block |
||
590 | 610 | if (in_array($key, getCurrentOption('ignored_categories')) || |
591 | 611 | (!array_key_exists($key, $query) && !array_key_exists('all', $query))) { |
592 | 612 | $critArray[$i] = self::BAD_SEARCH; |
593 | - } |
|
594 | - else { |
|
613 | + } else { |
|
595 | 614 | if (array_key_exists($key, $query)) { |
596 | 615 | $critArray[$i] = $query[$key]; |
597 | 616 | } else { |
@@ -603,12 +622,14 @@ discard block |
||
603 | 622 | return self::getEntryArray(self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
604 | 623 | } |
605 | 624 | |
606 | - public static function getBooks($n) { |
|
625 | + public static function getBooks($n) |
|
626 | + { |
|
607 | 627 | list ($entryArray, $totalNumber) = self::getEntryArray(self::SQL_BOOKS_ALL , array (), $n); |
608 | 628 | return array($entryArray, $totalNumber); |
609 | 629 | } |
610 | 630 | |
611 | - public static function getAllBooks() { |
|
631 | + public static function getAllBooks() |
|
632 | + { |
|
612 | 633 | /* @var $result PDOStatement */ |
613 | 634 | |
614 | 635 | list (, $result) = parent::executeQuery('select {0} |
@@ -617,8 +638,7 @@ discard block |
||
617 | 638 | order by substr (upper (sort), 1, 1)', 'substr (upper (sort), 1, 1) as title, count(*) as count', self::getFilterString(), array(), -1); |
618 | 639 | |
619 | 640 | $entryArray = array(); |
620 | - while ($post = $result->fetchObject()) |
|
621 | - { |
|
641 | + while ($post = $result->fetchObject()) { |
|
622 | 642 | array_push($entryArray, new Entry($post->title, Book::getEntryIdByLetter($post->title), |
623 | 643 | str_format(localize('bookword', $post->count), $post->count), 'text', |
624 | 644 | array(new LinkNavigation('?page='.parent::PAGE_ALL_BOOKS_LETTER.'&id='. rawurlencode($post->title))), '', $post->count)); |
@@ -626,25 +646,27 @@ discard block |
||
626 | 646 | return $entryArray; |
627 | 647 | } |
628 | 648 | |
629 | - public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
649 | + public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) |
|
650 | + { |
|
630 | 651 | return self::getEntryArray(self::SQL_BOOKS_BY_FIRST_LETTER, array($letter . '%'), $n, $database, $numberPerPage); |
631 | 652 | } |
632 | 653 | |
633 | - public static function getEntryArray($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
654 | + public static function getEntryArray($query, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
655 | + { |
|
634 | 656 | /* @var $totalNumber integer */ |
635 | 657 | /* @var $result PDOStatement */ |
636 | 658 | list($totalNumber, $result) = parent::executeQuery($query, self::BOOK_COLUMNS, self::getFilterString(), $params, $n, $database, $numberPerPage); |
637 | 659 | |
638 | 660 | $entryArray = array(); |
639 | - while ($post = $result->fetchObject()) |
|
640 | - { |
|
661 | + while ($post = $result->fetchObject()) { |
|
641 | 662 | $book = new Book($post); |
642 | 663 | array_push($entryArray, $book->getEntry()); |
643 | 664 | } |
644 | 665 | return array($entryArray, $totalNumber); |
645 | 666 | } |
646 | 667 | |
647 | - public static function getAllRecentBooks() { |
|
668 | + public static function getAllRecentBooks() |
|
669 | + { |
|
648 | 670 | global $config; |
649 | 671 | list ($entryArray, ) = self::getEntryArray(self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array(), -1); |
650 | 672 | return $entryArray; |
@@ -656,7 +678,8 @@ discard block |
||
656 | 678 | * @param string[] $columns |
657 | 679 | * @return CustomColumn[] |
658 | 680 | */ |
659 | - public function getCustomColumnValues($columns, $asArray = false) { |
|
681 | + public function getCustomColumnValues($columns, $asArray = false) |
|
682 | + { |
|
660 | 683 | $result = array(); |
661 | 684 | |
662 | 685 | foreach ($columns as $lookup) { |