@@ -208,6 +208,9 @@ discard block |
||
| 208 | 208 | return 'index.php' . $urlParam; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | + /** |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 211 | 214 | public function getTitle () { |
| 212 | 215 | return $this->title; |
| 213 | 216 | } |
@@ -395,6 +398,9 @@ discard block |
||
| 395 | 398 | return reset($reduced); |
| 396 | 399 | } |
| 397 | 400 | |
| 401 | + /** |
|
| 402 | + * @param string $extension |
|
| 403 | + */ |
|
| 398 | 404 | public function getFilePath($extension, $idData = NULL, $relative = false) |
| 399 | 405 | { |
| 400 | 406 | /*if ($extension == 'jpg') |
@@ -562,6 +568,9 @@ discard block |
||
| 562 | 568 | $this->getLinkArray(), $this); |
| 563 | 569 | } |
| 564 | 570 | |
| 571 | + /** |
|
| 572 | + * @param integer $database |
|
| 573 | + */ |
|
| 565 | 574 | public static function getBookCount($database = NULL) { |
| 566 | 575 | return parent::executeQuerySingle('select count(*) from books', $database); |
| 567 | 576 | } |
@@ -610,7 +619,7 @@ discard block |
||
| 610 | 619 | } |
| 611 | 620 | |
| 612 | 621 | /** |
| 613 | - * @param $customColumn CustomColumn |
|
| 622 | + * @param CustomColumn $customColumn CustomColumn |
|
| 614 | 623 | * @param $id integer |
| 615 | 624 | * @param $n integer |
| 616 | 625 | * @return array |
@@ -650,6 +659,10 @@ discard block |
||
| 650 | 659 | return NULL; |
| 651 | 660 | } |
| 652 | 661 | |
| 662 | + /** |
|
| 663 | + * @param integer $database |
|
| 664 | + * @param integer $numberPerPage |
|
| 665 | + */ |
|
| 653 | 666 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
| 654 | 667 | $i = 0; |
| 655 | 668 | $critArray = array(); |
@@ -697,6 +710,9 @@ discard block |
||
| 697 | 710 | return $entryArray; |
| 698 | 711 | } |
| 699 | 712 | |
| 713 | + /** |
|
| 714 | + * @param integer $numberPerPage |
|
| 715 | + */ |
|
| 700 | 716 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
| 701 | 717 | return self::getEntryArray(self::SQL_BOOKS_BY_FIRST_LETTER, array($letter . '%'), $n, $database, $numberPerPage); |
| 702 | 718 | } |
@@ -7,55 +7,55 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // Silly thing because PHP forbid string concatenation in class const |
| 10 | -define ('SQL_BOOKS_LEFT_JOIN', 'left outer join comments on comments.book = books.id |
|
| 10 | +define('SQL_BOOKS_LEFT_JOIN', 'left outer join comments on comments.book = books.id |
|
| 11 | 11 | left outer join books_ratings_link on books_ratings_link.book = books.id |
| 12 | 12 | left outer join ratings on books_ratings_link.rating = ratings.id '); |
| 13 | -define ('SQL_BOOKS_ALL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' order by books.sort '); |
|
| 14 | -define ('SQL_BOOKS_BY_PUBLISHER', 'select {0} from books_publishers_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 13 | +define('SQL_BOOKS_ALL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' order by books.sort '); |
|
| 14 | +define('SQL_BOOKS_BY_PUBLISHER', 'select {0} from books_publishers_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 15 | 15 | where books_publishers_link.book = books.id and publisher = ? {1} order by publisher'); |
| 16 | -define ('SQL_BOOKS_BY_FIRST_LETTER', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 16 | +define('SQL_BOOKS_BY_FIRST_LETTER', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 17 | 17 | where upper (books.sort) like ? order by books.sort'); |
| 18 | -define ('SQL_BOOKS_BY_AUTHOR', 'select {0} from books_authors_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 18 | +define('SQL_BOOKS_BY_AUTHOR', 'select {0} from books_authors_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 19 | 19 | left outer join books_series_link on books_series_link.book = books.id |
| 20 | 20 | where books_authors_link.book = books.id and author = ? {1} order by series desc, series_index asc, pubdate asc'); |
| 21 | -define ('SQL_BOOKS_BY_SERIE', 'select {0} from books_series_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 21 | +define('SQL_BOOKS_BY_SERIE', 'select {0} from books_series_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 22 | 22 | where books_series_link.book = books.id and series = ? {1} order by series_index'); |
| 23 | -define ('SQL_BOOKS_BY_TAG', 'select {0} from books_tags_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 23 | +define('SQL_BOOKS_BY_TAG', 'select {0} from books_tags_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 24 | 24 | where books_tags_link.book = books.id and tag = ? {1} order by sort'); |
| 25 | -define ('SQL_BOOKS_BY_LANGUAGE', 'select {0} from books_languages_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 25 | +define('SQL_BOOKS_BY_LANGUAGE', 'select {0} from books_languages_link, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 26 | 26 | where books_languages_link.book = books.id and lang_code = ? {1} order by sort'); |
| 27 | -define ('SQL_BOOKS_BY_CUSTOM', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 27 | +define('SQL_BOOKS_BY_CUSTOM', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 28 | 28 | where {2}.book = books.id and {2}.{3} = ? {1} order by sort'); |
| 29 | -define ('SQL_BOOKS_BY_CUSTOM_BOOL_TRUE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 29 | +define('SQL_BOOKS_BY_CUSTOM_BOOL_TRUE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 30 | 30 | where {2}.book = books.id and {2}.value = 1 {1} order by sort'); |
| 31 | -define ('SQL_BOOKS_BY_CUSTOM_BOOL_FALSE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 31 | +define('SQL_BOOKS_BY_CUSTOM_BOOL_FALSE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 32 | 32 | where {2}.book = books.id and {2}.value = 0 {1} order by sort'); |
| 33 | -define ('SQL_BOOKS_BY_CUSTOM_BOOL_NULL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 33 | +define('SQL_BOOKS_BY_CUSTOM_BOOL_NULL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 34 | 34 | where books.id not in (select book from {2}) {1} order by sort'); |
| 35 | -define ('SQL_BOOKS_BY_CUSTOM_RATING', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 35 | +define('SQL_BOOKS_BY_CUSTOM_RATING', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 36 | 36 | left join {2} on {2}.book = books.id |
| 37 | 37 | left join {3} on {3}.id = {2}.{4} |
| 38 | 38 | where {3}.value = ? order by sort'); |
| 39 | -define ('SQL_BOOKS_BY_CUSTOM_RATING_NULL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 39 | +define('SQL_BOOKS_BY_CUSTOM_RATING_NULL', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 40 | 40 | left join {2} on {2}.book = books.id |
| 41 | 41 | left join {3} on {3}.id = {2}.{4} |
| 42 | 42 | where ((books.id not in (select {2}.book from {2})) or ({3}.value = 0)) {1} order by sort'); |
| 43 | -define ('SQL_BOOKS_BY_CUSTOM_DATE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 43 | +define('SQL_BOOKS_BY_CUSTOM_DATE', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 44 | 44 | where {2}.book = books.id and date({2}.value) = ? {1} order by sort'); |
| 45 | -define ('SQL_BOOKS_BY_CUSTOM_DIRECT', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 45 | +define('SQL_BOOKS_BY_CUSTOM_DIRECT', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 46 | 46 | where {2}.book = books.id and {2}.value = ? {1} order by sort'); |
| 47 | -define ('SQL_BOOKS_BY_CUSTOM_DIRECT_ID', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 47 | +define('SQL_BOOKS_BY_CUSTOM_DIRECT_ID', 'select {0} from {2}, books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 48 | 48 | where {2}.book = books.id and {2}.id = ? {1} order by sort'); |
| 49 | -define ('SQL_BOOKS_QUERY', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 49 | +define('SQL_BOOKS_QUERY', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 50 | 50 | where ( |
| 51 | 51 | exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or |
| 52 | 52 | exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or |
| 53 | 53 | exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or |
| 54 | 54 | exists (select null from publishers, books_publishers_link where book = books.id and books_publishers_link.publisher = publishers.id and publishers.name like ?) or |
| 55 | 55 | title like ?) {1} order by books.sort'); |
| 56 | -define ('SQL_BOOKS_RECENT', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 56 | +define('SQL_BOOKS_RECENT', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 57 | 57 | where 1=1 {1} order by timestamp desc limit '); |
| 58 | -define ('SQL_BOOKS_BY_RATING', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 58 | +define('SQL_BOOKS_BY_RATING', 'select {0} from books ' . SQL_BOOKS_LEFT_JOIN . ' |
|
| 59 | 59 | where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort'); |
| 60 | 60 | |
| 61 | 61 | class Book extends Base |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public $serie = NULL; |
| 106 | 106 | public $tags = NULL; |
| 107 | 107 | public $languages = NULL; |
| 108 | - public $format = array (); |
|
| 108 | + public $format = array(); |
|
| 109 | 109 | private $coverFileName = NULL; |
| 110 | 110 | |
| 111 | 111 | public function __construct($line) { |
@@ -191,24 +191,24 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | public function getEntryId() { |
| 194 | - return self::ALL_BOOKS_UUID.':'.$this->uuid; |
|
| 194 | + return self::ALL_BOOKS_UUID . ':' . $this->uuid; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 198 | - return self::ALL_BOOKS_ID.':letter:'.$startingLetter; |
|
| 197 | + public static function getEntryIdByLetter($startingLetter) { |
|
| 198 | + return self::ALL_BOOKS_ID . ':letter:' . $startingLetter; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - public function getUri () { |
|
| 202 | - return '?page='.parent::PAGE_BOOK_DETAIL.'&id=' . $this->id; |
|
| 201 | + public function getUri() { |
|
| 202 | + return '?page=' . parent::PAGE_BOOK_DETAIL . '&id=' . $this->id; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - public function getDetailUrl () { |
|
| 205 | + public function getDetailUrl() { |
|
| 206 | 206 | $urlParam = $this->getUri(); |
| 207 | - if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam (DB)); |
|
| 207 | + if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB)); |
|
| 208 | 208 | return 'index.php' . $urlParam; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function getTitle () { |
|
| 211 | + public function getTitle() { |
|
| 212 | 212 | return $this->title; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -217,22 +217,22 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * @return Author[] |
| 219 | 219 | */ |
| 220 | - public function getAuthors () { |
|
| 220 | + public function getAuthors() { |
|
| 221 | 221 | if (is_null($this->authors)) { |
| 222 | 222 | $this->authors = Author::getAuthorByBookId($this->id); |
| 223 | 223 | } |
| 224 | 224 | return $this->authors; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - public function getAuthorsName () { |
|
| 228 | - return implode(', ', array_map(function ($author) { return $author->name; }, $this->getAuthors())); |
|
| 227 | + public function getAuthorsName() { |
|
| 228 | + return implode(', ', array_map(function($author) { return $author->name; }, $this->getAuthors())); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - public function getAuthorsSort () { |
|
| 232 | - return implode(', ', array_map(function ($author) { return $author->sort; }, $this->getAuthors())); |
|
| 231 | + public function getAuthorsSort() { |
|
| 232 | + return implode(', ', array_map(function($author) { return $author->sort; }, $this->getAuthors())); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - public function getPublisher () { |
|
| 235 | + public function getPublisher() { |
|
| 236 | 236 | if (is_null($this->publisher)) { |
| 237 | 237 | $this->publisher = Publisher::getPublisherByBookId($this->id); |
| 238 | 238 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @return Tag[] |
| 272 | 272 | */ |
| 273 | 273 | public function getTags() { |
| 274 | - if (is_null ($this->tags)) { |
|
| 274 | + if (is_null($this->tags)) { |
|
| 275 | 275 | $this->tags = array(); |
| 276 | 276 | |
| 277 | 277 | $result = parent::getDb()->prepare('select tags.id as id, name |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | public function getTagsName() { |
| 292 | - return implode(', ', array_map(function ($tag) { return $tag->name; }, $this->getTags())); |
|
| 292 | + return implode(', ', array_map(function($tag) { return $tag->name; }, $this->getTags())); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | public function getDataById($idData) |
| 343 | 343 | { |
| 344 | - $reduced = array_filter($this->getDatas(), function ($data) use ($idData) { |
|
| 344 | + $reduced = array_filter($this->getDatas(), function($data) use ($idData) { |
|
| 345 | 345 | return $data->id == $idData; |
| 346 | 346 | }); |
| 347 | 347 | return reset($reduced); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | if (empty ($this->pubdate)) { |
| 366 | 366 | return ''; |
| 367 | 367 | } |
| 368 | - $dateY = (int) substr($this->pubdate, 0, 4); |
|
| 368 | + $dateY = (int)substr($this->pubdate, 0, 4); |
|
| 369 | 369 | if ($dateY > 102) { |
| 370 | 370 | return str_pad($dateY, 4, '0', STR_PAD_LEFT); |
| 371 | 371 | } |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | public function getComment($withSerie = true) { |
| 376 | 376 | $addition = ''; |
| 377 | - $se = $this->getSerie (); |
|
| 378 | - if (!is_null ($se) && $withSerie) { |
|
| 377 | + $se = $this->getSerie(); |
|
| 378 | + if (!is_null($se) && $withSerie) { |
|
| 379 | 379 | $addition = $addition . '<strong>' . localize('content.series') . '</strong>' . str_format(localize('content.series.data'), $this->seriesIndex, htmlspecialchars($se->name)) . "<br />\n"; |
| 380 | 380 | } |
| 381 | 381 | if (preg_match('/<\/(div|p|a|span)>/', $this->comment)) |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | public function getDataFormat($format) { |
| 392 | - $reduced = array_filter($this->getDatas(), function ($data) use ($format) { |
|
| 392 | + $reduced = array_filter($this->getDatas(), function($data) use ($format) { |
|
| 393 | 393 | return $data->format == $format; |
| 394 | 394 | }); |
| 395 | 395 | return reset($reduced); |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | $epub->Authors($authorArray); |
| 456 | 456 | $epub->Language($this->getLanguages()); |
| 457 | - $epub->Description ($this->getComment(false)); |
|
| 457 | + $epub->Description($this->getComment(false)); |
|
| 458 | 458 | $epub->Subjects($this->getTagsName()); |
| 459 | 459 | // -DC- Use cover file name |
| 460 | 460 | // $epub->Cover2($this->getFilePath('jpg'), 'image/jpeg'); |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $epub->SerieIndex($this->seriesIndex); |
| 467 | 467 | } |
| 468 | 468 | $filename = $data->getUpdatedFilenameEpub(); |
| 469 | - if ($config['cops_provide_kepub'] == '1' && preg_match('/Kobo/', $_SERVER['HTTP_USER_AGENT'])) { |
|
| 469 | + if ($config['cops_provide_kepub'] == '1' && preg_match('/Kobo/', $_SERVER['HTTP_USER_AGENT'])) { |
|
| 470 | 470 | $epub->updateForKepub(); |
| 471 | 471 | $filename = $data->getUpdatedFilenameKepub(); |
| 472 | 472 | } |
@@ -494,11 +494,11 @@ discard block |
||
| 494 | 494 | if (!is_null($width)) { |
| 495 | 495 | $nw = $width; |
| 496 | 496 | if ($nw >= $w) { return false; } |
| 497 | - $nh = ($nw*$h)/$w; |
|
| 497 | + $nh = ($nw * $h) / $w; |
|
| 498 | 498 | } else { |
| 499 | 499 | $nh = $height; |
| 500 | 500 | if ($nh >= $h) { return false; } |
| 501 | - $nw = ($nh*$w)/$h; |
|
| 501 | + $nw = ($nh * $w) / $h; |
|
| 502 | 502 | } |
| 503 | 503 | } else { |
| 504 | 504 | return false; |
@@ -506,16 +506,16 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | //draw the image |
| 508 | 508 | $src_img = imagecreatefromjpeg($file); |
| 509 | - $dst_img = imagecreatetruecolor($nw,$nh); |
|
| 510 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image |
|
| 511 | - imagejpeg($dst_img,$outputfile,80); |
|
| 509 | + $dst_img = imagecreatetruecolor($nw, $nh); |
|
| 510 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h); //resizing the image |
|
| 511 | + imagejpeg($dst_img, $outputfile, 80); |
|
| 512 | 512 | imagedestroy($src_img); |
| 513 | 513 | imagedestroy($dst_img); |
| 514 | 514 | |
| 515 | 515 | return true; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - public function getLinkArray () |
|
| 518 | + public function getLinkArray() |
|
| 519 | 519 | { |
| 520 | 520 | $linkArray = array(); |
| 521 | 521 | |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | $serie = $this->getSerie(); |
| 551 | - if (!is_null ($serie)) { |
|
| 551 | + if (!is_null($serie)) { |
|
| 552 | 552 | array_push($linkArray, new LinkNavigation($serie->getUri(), 'related', str_format(localize('content.series.data'), $this->seriesIndex, $serie->name))); |
| 553 | 553 | } |
| 554 | 554 | |
@@ -573,13 +573,13 @@ discard block |
||
| 573 | 573 | $entry = new Entry(localize('allbooks.title'), |
| 574 | 574 | self::ALL_BOOKS_ID, |
| 575 | 575 | str_format(localize('allbooks.alphabetical', $nBooks), $nBooks), 'text', |
| 576 | - array(new LinkNavigation('?page='.parent::PAGE_ALL_BOOKS)), '', $nBooks); |
|
| 576 | + array(new LinkNavigation('?page=' . parent::PAGE_ALL_BOOKS)), '', $nBooks); |
|
| 577 | 577 | array_push($result, $entry); |
| 578 | 578 | if ($config['cops_recentbooks_limit'] > 0) { |
| 579 | 579 | $entry = new Entry(localize('recent.title'), |
| 580 | 580 | self::ALL_RECENT_BOOKS_ID, |
| 581 | 581 | str_format(localize('recent.list'), $config['cops_recentbooks_limit']), 'text', |
| 582 | - array ( new LinkNavigation ('?page='.parent::PAGE_ALL_RECENT_BOOKS)), '', $config['cops_recentbooks_limit']); |
|
| 582 | + array(new LinkNavigation('?page=' . parent::PAGE_ALL_RECENT_BOOKS)), '', $config['cops_recentbooks_limit']); |
|
| 583 | 583 | array_push($result, $entry); |
| 584 | 584 | } |
| 585 | 585 | return $result; |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | public static function getBooks($n) { |
| 678 | - list ($entryArray, $totalNumber) = self::getEntryArray(self::SQL_BOOKS_ALL , array (), $n); |
|
| 678 | + list ($entryArray, $totalNumber) = self::getEntryArray(self::SQL_BOOKS_ALL, array(), $n); |
|
| 679 | 679 | return array($entryArray, $totalNumber); |
| 680 | 680 | } |
| 681 | 681 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | { |
| 693 | 693 | array_push($entryArray, new Entry($post->title, Book::getEntryIdByLetter($post->title), |
| 694 | 694 | str_format(localize('bookword', $post->count), $post->count), 'text', |
| 695 | - array(new LinkNavigation('?page='.parent::PAGE_ALL_BOOKS_LETTER.'&id='. rawurlencode($post->title))), '', $post->count)); |
|
| 695 | + array(new LinkNavigation('?page=' . parent::PAGE_ALL_BOOKS_LETTER . '&id=' . rawurlencode($post->title))), '', $post->count)); |
|
| 696 | 696 | } |
| 697 | 697 | return $entryArray; |
| 698 | 698 | } |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | |
| 718 | 718 | public static function getAllRecentBooks() { |
| 719 | 719 | global $config; |
| 720 | - list ($entryArray, ) = self::getEntryArray(self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array(), -1); |
|
| 720 | + list ($entryArray,) = self::getEntryArray(self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array(), -1); |
|
| 721 | 721 | return $entryArray; |
| 722 | 722 | } |
| 723 | 723 | |
@@ -37,156 +37,156 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private static $db = NULL; |
| 39 | 39 | |
| 40 | - public static function isMultipleDatabaseEnabled () { |
|
| 40 | + public static function isMultipleDatabaseEnabled() { |
|
| 41 | 41 | global $config; |
| 42 | - return is_array ($config['calibre_directory']); |
|
| 42 | + return is_array($config['calibre_directory']); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function useAbsolutePath () { |
|
| 45 | + public static function useAbsolutePath() { |
|
| 46 | 46 | global $config; |
| 47 | 47 | $path = self::getDbDirectory(); |
| 48 | - return preg_match ('/^\//', $path) || // Linux / |
|
| 49 | - preg_match ('/^\w\:/', $path); // Windows X: |
|
| 48 | + return preg_match('/^\//', $path) || // Linux / |
|
| 49 | + preg_match('/^\w\:/', $path); // Windows X: |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function noDatabaseSelected () { |
|
| 53 | - return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
|
| 52 | + public static function noDatabaseSelected() { |
|
| 53 | + return self::isMultipleDatabaseEnabled() && is_null(GetUrlParam(DB)); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static function getDbList () { |
|
| 56 | + public static function getDbList() { |
|
| 57 | 57 | global $config; |
| 58 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 58 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 59 | 59 | return $config['calibre_directory']; |
| 60 | 60 | } else { |
| 61 | - return array ("" => $config['calibre_directory']); |
|
| 61 | + return array("" => $config['calibre_directory']); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function getDbNameList () { |
|
| 65 | + public static function getDbNameList() { |
|
| 66 | 66 | global $config; |
| 67 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 68 | - return array_keys ($config['calibre_directory']); |
|
| 67 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 68 | + return array_keys($config['calibre_directory']); |
|
| 69 | 69 | } else { |
| 70 | - return array (""); |
|
| 70 | + return array(""); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 74 | + public static function getDbName($database = NULL) { |
|
| 75 | 75 | global $config; |
| 76 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 77 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 76 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 77 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 78 | 78 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 79 | - self::error ($database); |
|
| 79 | + self::error($database); |
|
| 80 | 80 | } |
| 81 | - $array = array_keys ($config['calibre_directory']); |
|
| 81 | + $array = array_keys($config['calibre_directory']); |
|
| 82 | 82 | return $array[$database]; |
| 83 | 83 | } |
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 87 | + public static function getDbDirectory($database = NULL) { |
|
| 88 | 88 | global $config; |
| 89 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 90 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 89 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 90 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 91 | 91 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 92 | - self::error ($database); |
|
| 92 | + self::error($database); |
|
| 93 | 93 | } |
| 94 | - $array = array_values ($config['calibre_directory']); |
|
| 94 | + $array = array_values($config['calibre_directory']); |
|
| 95 | 95 | return $array[$database]; |
| 96 | 96 | } |
| 97 | 97 | return $config['calibre_directory']; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // -DC- Add image directory |
| 101 | - public static function getImgDirectory ($database = NULL) { |
|
| 101 | + public static function getImgDirectory($database = NULL) { |
|
| 102 | 102 | global $config; |
| 103 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 104 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 105 | - $array = array_values ($config['image_directory']); |
|
| 103 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 104 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 105 | + $array = array_values($config['image_directory']); |
|
| 106 | 106 | return $array[$database]; |
| 107 | 107 | } |
| 108 | 108 | return $config['image_directory']; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public static function getDbFileName ($database = NULL) { |
|
| 112 | - return self::getDbDirectory ($database) .'metadata.db'; |
|
| 111 | + public static function getDbFileName($database = NULL) { |
|
| 112 | + return self::getDbDirectory($database) . 'metadata.db'; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - private static function error ($database) { |
|
| 115 | + private static function error($database) { |
|
| 116 | 116 | if (php_sapi_name() != "cli") { |
| 117 | 117 | header("location: checkconfig.php?err=1"); |
| 118 | 118 | } |
| 119 | 119 | throw new Exception("Database <{$database}> not found."); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public static function getDb ($database = NULL) { |
|
| 123 | - if (is_null (self::$db)) { |
|
| 122 | + public static function getDb($database = NULL) { |
|
| 123 | + if (is_null(self::$db)) { |
|
| 124 | 124 | try { |
| 125 | - if (is_readable (self::getDbFileName ($database))) { |
|
| 126 | - self::$db = new PDO('sqlite:'. self::getDbFileName ($database)); |
|
| 127 | - if (useNormAndUp ()) { |
|
| 128 | - self::$db->sqliteCreateFunction ('normAndUp', 'normAndUp', 1); |
|
| 125 | + if (is_readable(self::getDbFileName($database))) { |
|
| 126 | + self::$db = new PDO('sqlite:' . self::getDbFileName($database)); |
|
| 127 | + if (useNormAndUp()) { |
|
| 128 | + self::$db->sqliteCreateFunction('normAndUp', 'normAndUp', 1); |
|
| 129 | 129 | } |
| 130 | 130 | } else { |
| 131 | - self::error ($database); |
|
| 131 | + self::error($database); |
|
| 132 | 132 | } |
| 133 | 133 | } catch (Exception $e) { |
| 134 | - self::error ($database); |
|
| 134 | + self::error($database); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | return self::$db; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public static function checkDatabaseAvailability () { |
|
| 141 | - if (self::noDatabaseSelected ()) { |
|
| 142 | - for ($i = 0; $i < count (self::getDbList ()); $i++) { |
|
| 143 | - self::getDb ($i); |
|
| 144 | - self::clearDb (); |
|
| 140 | + public static function checkDatabaseAvailability() { |
|
| 141 | + if (self::noDatabaseSelected()) { |
|
| 142 | + for ($i = 0; $i < count(self::getDbList()); $i++) { |
|
| 143 | + self::getDb($i); |
|
| 144 | + self::clearDb(); |
|
| 145 | 145 | } |
| 146 | 146 | } else { |
| 147 | - self::getDb (); |
|
| 147 | + self::getDb(); |
|
| 148 | 148 | } |
| 149 | 149 | return true; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - public static function clearDb () { |
|
| 152 | + public static function clearDb() { |
|
| 153 | 153 | self::$db = NULL; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 157 | - return self::getDb ($database)->query($query)->fetchColumn(); |
|
| 156 | + public static function executeQuerySingle($query, $database = NULL) { |
|
| 157 | + return self::getDb($database)->query($query)->fetchColumn(); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
| 161 | 161 | if (!$numberOfString) { |
| 162 | 162 | $numberOfString = $table . ".alphabetical"; |
| 163 | 163 | } |
| 164 | - $count = self::executeQuerySingle ('select count(*) from ' . $table); |
|
| 164 | + $count = self::executeQuerySingle('select count(*) from ' . $table); |
|
| 165 | 165 | if ($count == 0) return NULL; |
| 166 | - $entry = new Entry (localize($table . ".title"), $id, |
|
| 167 | - str_format (localize($numberOfString, $count), $count), "text", |
|
| 168 | - array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
|
| 166 | + $entry = new Entry(localize($table . ".title"), $id, |
|
| 167 | + str_format(localize($numberOfString, $count), $count), "text", |
|
| 168 | + array(new LinkNavigation("?page=" . $pageId)), "", $count); |
|
| 169 | 169 | return $entry; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 172 | + public static function getEntryArrayWithBookNumber($query, $columns, $params, $category) { |
|
| 173 | 173 | /* @var $result PDOStatement */ |
| 174 | 174 | |
| 175 | - list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
|
| 175 | + list (, $result) = self::executeQuery($query, $columns, "", $params, -1); |
|
| 176 | 176 | $entryArray = array(); |
| 177 | - while ($post = $result->fetchObject ()) |
|
| 177 | + while ($post = $result->fetchObject()) |
|
| 178 | 178 | { |
| 179 | 179 | /* @var $instance Author|Tag|Serie|Publisher */ |
| 180 | 180 | |
| 181 | - $instance = new $category ($post); |
|
| 181 | + $instance = new $category($post); |
|
| 182 | 182 | if (property_exists($post, "sort")) { |
| 183 | 183 | $title = $post->sort; |
| 184 | 184 | } else { |
| 185 | 185 | $title = $post->name; |
| 186 | 186 | } |
| 187 | - array_push ($entryArray, new Entry ($title, $instance->getEntryId (), |
|
| 188 | - str_format (localize("bookword", $post->count), $post->count), "text", |
|
| 189 | - array ( new LinkNavigation ($instance->getUri ())), "", $post->count)); |
|
| 187 | + array_push($entryArray, new Entry($title, $instance->getEntryId(), |
|
| 188 | + str_format(localize("bookword", $post->count), $post->count), "text", |
|
| 189 | + array(new LinkNavigation($instance->getUri())), "", $post->count)); |
|
| 190 | 190 | } |
| 191 | 191 | return $entryArray; |
| 192 | 192 | } |
@@ -194,30 +194,30 @@ discard block |
||
| 194 | 194 | public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
| 195 | 195 | $totalResult = -1; |
| 196 | 196 | |
| 197 | - if (useNormAndUp ()) { |
|
| 197 | + if (useNormAndUp()) { |
|
| 198 | 198 | $query = preg_replace("/upper/", "normAndUp", $query); |
| 199 | 199 | $columns = preg_replace("/upper/", "normAndUp", $columns); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if (is_null ($numberPerPage)) { |
|
| 203 | - $numberPerPage = getCurrentOption ("max_item_per_page"); |
|
| 202 | + if (is_null($numberPerPage)) { |
|
| 203 | + $numberPerPage = getCurrentOption("max_item_per_page"); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | if ($numberPerPage != -1 && $n != -1) |
| 207 | 207 | { |
| 208 | 208 | // First check total number of results |
| 209 | - $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
|
| 210 | - $result->execute ($params); |
|
| 211 | - $totalResult = $result->fetchColumn (); |
|
| 209 | + $result = self::getDb($database)->prepare(str_format($query, "count(*)", $filter)); |
|
| 210 | + $result->execute($params); |
|
| 211 | + $totalResult = $result->fetchColumn(); |
|
| 212 | 212 | |
| 213 | 213 | // Next modify the query and params |
| 214 | 214 | $query .= " limit ?, ?"; |
| 215 | - array_push ($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 215 | + array_push($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter)); |
|
| 219 | - $result->execute ($params); |
|
| 220 | - return array ($totalResult, $result); |
|
| 218 | + $result = self::getDb($database)->prepare(str_format($query, $columns, $filter)); |
|
| 219 | + $result->execute($params); |
|
| 220 | + return array($totalResult, $result); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | } |
@@ -19,10 +19,10 @@ discard block |
||
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - $expires = 60*60*24*14; |
|
| 22 | + $expires = 60 * 60 * 24 * 14; |
|
| 23 | 23 | header('Pragma: public'); |
| 24 | 24 | header('Cache-Control: max-age=' . $expires); |
| 25 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); |
|
| 25 | + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); |
|
| 26 | 26 | $bookId = getURLParam('id', NULL); |
| 27 | 27 | $type = getURLParam('type', 'jpg'); |
| 28 | 28 | $idData = getURLParam('data', NULL); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | if (!$book) { |
| 38 | - notFound (); |
|
| 38 | + notFound(); |
|
| 39 | 39 | return; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | //by default, we don't cache |
| 67 | 67 | $thumbnailCacheFullpath = null; |
| 68 | - if ( isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '' ) { |
|
| 68 | + if (isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '') { |
|
| 69 | 69 | $thumbnailCacheFullpath = $config['cops_thumbnail_cache_directory']; |
| 70 | 70 | //if multiple databases, add a subfolder with the database ID |
| 71 | - $thumbnailCacheFullpath .= !is_null(GetUrlParam (DB)) ? 'db-' . GetUrlParam (DB) . DIRECTORY_SEPARATOR : ''; |
|
| 71 | + $thumbnailCacheFullpath .= !is_null(GetUrlParam(DB))?'db-' . GetUrlParam(DB) . DIRECTORY_SEPARATOR:''; |
|
| 72 | 72 | //when there are lots of thumbnails, it's better to save files in subfolders, so if the book's uuid is |
| 73 | 73 | //"01234567-89ab-cdef-0123-456789abcdef", we will save the thumbnail in .../0/12/34567-89ab-cdef-0123-456789abcdef-... |
| 74 | 74 | $thumbnailCacheFullpath .= substr($book->uuid, 0, 1) . DIRECTORY_SEPARATOR . substr($book->uuid, 1, 2) . DIRECTORY_SEPARATOR; |
| 75 | 75 | //check if cache folder exists or create it |
| 76 | - if ( file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true) ) { |
|
| 76 | + if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) { |
|
| 77 | 77 | //we name the thumbnail from the book's uuid and it's dimensions (width and/or height) |
| 78 | 78 | $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam('width') . 'x' . getURLParam('height') . '.' . $type; |
| 79 | 79 | $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName; |
@@ -83,20 +83,20 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( $thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath) ) { |
|
| 86 | + if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) { |
|
| 87 | 87 | //return the already cached thumbnail |
| 88 | - readfile( $thumbnailCacheFullpath ); |
|
| 88 | + readfile($thumbnailCacheFullpath); |
|
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ($book->getThumbnail (getURLParam('width'), getURLParam('height'), $thumbnailCacheFullpath)) { |
|
| 92 | + if ($book->getThumbnail(getURLParam('width'), getURLParam('height'), $thumbnailCacheFullpath)) { |
|
| 93 | 93 | //if we don't cache the thumbnail, imagejpeg() in $book->getThumbnail() already return the image data |
| 94 | - if ( $thumbnailCacheFullpath === null ) { |
|
| 94 | + if ($thumbnailCacheFullpath === null) { |
|
| 95 | 95 | // The cover had to be resized |
| 96 | 96 | return; |
| 97 | 97 | } else { |
| 98 | 98 | //return the just cached thumbnail |
| 99 | - readfile( $thumbnailCacheFullpath ); |
|
| 99 | + readfile($thumbnailCacheFullpath); |
|
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | } |