@@ -6,7 +6,8 @@ discard block |
||
| 6 | 6 | * @author Sébastien Lucas <[email protected]> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class Serie extends Base { |
|
| 9 | +class Serie extends Base |
|
| 10 | +{ |
|
| 10 | 11 | const ALL_SERIES_ID = "cops:series"; |
| 11 | 12 | const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count"; |
| 12 | 13 | const SQL_ALL_SERIES = "select {0} from series, books_series_link where series.id = series group by series.id, series.name, series.sort order by series.sort"; |
@@ -15,25 +16,30 @@ discard block |
||
| 15 | 16 | public $id; |
| 16 | 17 | public $name; |
| 17 | 18 | |
| 18 | - public function __construct($post) { |
|
| 19 | + public function __construct($post) |
|
| 20 | + { |
|
| 19 | 21 | $this->id = $post->id; |
| 20 | 22 | $this->name = $post->name; |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public function getUri () { |
|
| 25 | + public function getUri () |
|
| 26 | + { |
|
| 24 | 27 | return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id"; |
| 25 | 28 | } |
| 26 | 29 | |
| 27 | - public function getEntryId () { |
|
| 30 | + public function getEntryId () |
|
| 31 | + { |
|
| 28 | 32 | return self::ALL_SERIES_ID.":".$this->id; |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | - public static function getCount() { |
|
| 35 | + public static function getCount() |
|
| 36 | + { |
|
| 32 | 37 | // str_format (localize("series.alphabetical", count(array)) |
| 33 | 38 | return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES); |
| 34 | 39 | } |
| 35 | 40 | |
| 36 | - public static function getSerieByBookId ($bookId) { |
|
| 41 | + public static function getSerieByBookId ($bookId) |
|
| 42 | + { |
|
| 37 | 43 | $result = parent::getDb ()->prepare('select series.id as id, name |
| 38 | 44 | from books_series_link, series |
| 39 | 45 | where series.id = series and book = ?'); |
@@ -44,7 +50,8 @@ discard block |
||
| 44 | 50 | return NULL; |
| 45 | 51 | } |
| 46 | 52 | |
| 47 | - public static function getSerieById ($serieId) { |
|
| 53 | + public static function getSerieById ($serieId) |
|
| 54 | + { |
|
| 48 | 55 | $result = parent::getDb ()->prepare('select id, name from series where id = ?'); |
| 49 | 56 | $result->execute (array ($serieId)); |
| 50 | 57 | if ($post = $result->fetchObject ()) { |
@@ -53,11 +60,13 @@ discard block |
||
| 53 | 60 | return NULL; |
| 54 | 61 | } |
| 55 | 62 | |
| 56 | - public static function getAllSeries() { |
|
| 63 | + public static function getAllSeries() |
|
| 64 | + { |
|
| 57 | 65 | return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array (), "Serie"); |
| 58 | 66 | } |
| 59 | 67 | |
| 60 | - public static function getAllSeriesByQuery($query) { |
|
| 68 | + public static function getAllSeriesByQuery($query) |
|
| 69 | + { |
|
| 61 | 70 | return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array ('%' . $query . '%'), "Serie"); |
| 62 | 71 | } |
| 63 | 72 | } |
@@ -25,12 +25,9 @@ discard block |
||
| 25 | 25 | $bookId = getURLParam ("id", NULL); |
| 26 | 26 | $type = getURLParam ("type", "jpg"); |
| 27 | 27 | $idData = getURLParam ("data", NULL); |
| 28 | - if (is_null ($bookId)) |
|
| 29 | - { |
|
| 28 | + if (is_null ($bookId)) { |
|
| 30 | 29 | $book = Book::getBookByDataId($idData); |
| 31 | - } |
|
| 32 | - else |
|
| 33 | - { |
|
| 30 | + } else { |
|
| 34 | 31 | $book = Book::getBookById($bookId); |
| 35 | 32 | } |
| 36 | 33 | |
@@ -51,8 +48,7 @@ discard block |
||
| 51 | 48 | } |
| 52 | 49 | } |
| 53 | 50 | |
| 54 | - switch ($type) |
|
| 55 | - { |
|
| 51 | + switch ($type) { |
|
| 56 | 52 | case "jpg": |
| 57 | 53 | header("Content-Type: image/jpeg"); |
| 58 | 54 | //by default, we don't cache |
@@ -69,8 +65,7 @@ discard block |
||
| 69 | 65 | //we name the thumbnail from the book's uuid and it's dimensions (width and/or height) |
| 70 | 66 | $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam ("width") . 'x' . getURLParam ("height") . '.jpg'; |
| 71 | 67 | $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName; |
| 72 | - } |
|
| 73 | - else { |
|
| 68 | + } else { |
|
| 74 | 69 | //error creating the folder, so we don't cache |
| 75 | 70 | $thumbnailCacheFullpath = null; |
| 76 | 71 | } |
@@ -87,8 +82,7 @@ discard block |
||
| 87 | 82 | if ( $thumbnailCacheFullpath === null ) { |
| 88 | 83 | // The cover had to be resized |
| 89 | 84 | return; |
| 90 | - } |
|
| 91 | - else { |
|
| 85 | + } else { |
|
| 92 | 86 | //return the just cached thumbnail |
| 93 | 87 | readfile( $thumbnailCacheFullpath ); |
| 94 | 88 | return; |
@@ -101,8 +95,7 @@ discard block |
||
| 101 | 95 | break; |
| 102 | 96 | } |
| 103 | 97 | $file = $book->getFilePath ($type, $idData, true); |
| 104 | - if ($type == "epub" && $config['cops_update_epub-metadata']) |
|
| 105 | - { |
|
| 98 | + if ($type == "epub" && $config['cops_update_epub-metadata']) { |
|
| 106 | 99 | $book->getUpdatedEpub ($idData); |
| 107 | 100 | return; |
| 108 | 101 | } |
@@ -122,7 +115,6 @@ discard block |
||
| 122 | 115 | $fp = fopen($filename, 'rb'); |
| 123 | 116 | header("Content-Length: " . filesize($filename)); |
| 124 | 117 | fpassthru($fp); |
| 125 | - } |
|
| 126 | - else { |
|
| 118 | + } else { |
|
| 127 | 119 | header ($config['cops_x_accel_redirect'] . ": " . $dir . $file); |
| 128 | 120 | } |
@@ -6,7 +6,8 @@ discard block |
||
| 6 | 6 | * @author Michael Pfitzner |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class Rating extends Base { |
|
| 9 | +class Rating extends Base |
|
| 10 | +{ |
|
| 10 | 11 | const ALL_RATING_ID = "cops:rating"; |
| 11 | 12 | |
| 12 | 13 | const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count"; |
@@ -14,33 +15,38 @@ discard block |
||
| 14 | 15 | public $id; |
| 15 | 16 | public $name; |
| 16 | 17 | |
| 17 | - public function __construct($pid, $pname) { |
|
| 18 | + public function __construct($pid, $pname) |
|
| 19 | + { |
|
| 18 | 20 | $this->id = $pid; |
| 19 | 21 | $this->name = $pname; |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | - public function getUri () { |
|
| 24 | + public function getUri () |
|
| 25 | + { |
|
| 23 | 26 | return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | - public function getEntryId () { |
|
| 29 | + public function getEntryId () |
|
| 30 | + { |
|
| 27 | 31 | return self::ALL_RATING_ID.":".$this->id; |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | - public static function getCount() { |
|
| 34 | + public static function getCount() |
|
| 35 | + { |
|
| 31 | 36 | // str_format (localize("ratings", count(array)) |
| 32 | 37 | return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); |
| 33 | 38 | } |
| 34 | 39 | |
| 35 | - public static function getAllRatings() { |
|
| 40 | + public static function getAllRatings() |
|
| 41 | + { |
|
| 36 | 42 | return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
| 37 | 43 | } |
| 38 | 44 | |
| 39 | - public static function getEntryArray ($query, $params) { |
|
| 45 | + public static function getEntryArray ($query, $params) |
|
| 46 | + { |
|
| 40 | 47 | list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1); |
| 41 | 48 | $entryArray = array(); |
| 42 | - while ($post = $result->fetchObject ()) |
|
| 43 | - { |
|
| 49 | + while ($post = $result->fetchObject ()) { |
|
| 44 | 50 | $ratingObj = new Rating ($post->id, $post->rating); |
| 45 | 51 | $rating=$post->rating/2; |
| 46 | 52 | $rating = str_format (localize("ratingword", $rating), $rating); |
@@ -51,7 +57,8 @@ discard block |
||
| 51 | 57 | return $entryArray; |
| 52 | 58 | } |
| 53 | 59 | |
| 54 | - public static function getRatingById ($ratingId) { |
|
| 60 | + public static function getRatingById ($ratingId) |
|
| 61 | + { |
|
| 55 | 62 | $result = parent::getDb ()->prepare('select rating from ratings where id = ?'); |
| 56 | 63 | $result->execute (array ($ratingId)); |
| 57 | 64 | return new Rating ($ratingId, $result->fetchColumn ()); |
@@ -2,7 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | require_once ("config.php"); |
| 4 | 4 | |
| 5 | -function checkConfiguration () { |
|
| 5 | +function checkConfiguration () |
|
| 6 | +{ |
|
| 6 | 7 | global $config; |
| 7 | 8 | |
| 8 | 9 | if (is_null ($config['cops_mail_configuration']) || |
@@ -14,7 +15,8 @@ discard block |
||
| 14 | 15 | return False; |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | -function checkRequest ($idData, $emailDest) { |
|
| 18 | +function checkRequest ($idData, $emailDest) |
|
| 19 | +{ |
|
| 18 | 20 | if (empty ($idData)) { |
| 19 | 21 | return 'No data sent.'; |
| 20 | 22 | } |
@@ -58,9 +60,15 @@ discard block |
||
| 58 | 60 | $mail->Port = 465; |
| 59 | 61 | } |
| 60 | 62 | $mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]); |
| 61 | -if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"]; |
|
| 62 | -if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"]; |
|
| 63 | -if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; |
|
| 63 | +if (!empty ($config['cops_mail_configuration']["smtp.username"])) { |
|
| 64 | + $mail->Username = $config['cops_mail_configuration']["smtp.username"]; |
|
| 65 | +} |
|
| 66 | +if (!empty ($config['cops_mail_configuration']["smtp.password"])) { |
|
| 67 | + $mail->Password = $config['cops_mail_configuration']["smtp.password"]; |
|
| 68 | +} |
|
| 69 | +if (!empty ($config['cops_mail_configuration']["smtp.secure"])) { |
|
| 70 | + $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; |
|
| 71 | +} |
|
| 64 | 72 | |
| 65 | 73 | $mail->From = $config['cops_mail_configuration']["address.from"]; |
| 66 | 74 | $mail->FromName = $config['cops_title_default']; |
@@ -9,7 +9,8 @@ discard block |
||
| 9 | 9 | require_once ("config.php"); |
| 10 | 10 | require_once ("base.php"); |
| 11 | 11 | |
| 12 | -function getComponentContent ($book, $component, $add) { |
|
| 12 | +function getComponentContent ($book, $component, $add) |
|
| 13 | +{ |
|
| 13 | 14 | $data = $book->component ($component); |
| 14 | 15 | |
| 15 | 16 | $callback = function ($m) use ($book, $component, $add) { |
@@ -28,7 +29,9 @@ discard block |
||
| 28 | 29 | $hash = "#" . $matches [2]; |
| 29 | 30 | } |
| 30 | 31 | $comp = $book->getComponentName ($component, $path); |
| 31 | - if (!$comp) return "{$method}'#'{$end}"; |
|
| 32 | + if (!$comp) { |
|
| 33 | + return "{$method}'#'{$end}"; |
|
| 34 | + } |
|
| 32 | 35 | $out = "{$method}'epubfs.php?{$add}comp={$comp}{$hash}'{$end}"; |
| 33 | 36 | if ($end) { |
| 34 | 37 | return $out; |
@@ -48,7 +51,9 @@ discard block |
||
| 48 | 51 | |
| 49 | 52 | $idData = getURLParam ("data", NULL); |
| 50 | 53 | $add = "data=$idData&"; |
| 51 | -if (!is_null (GetUrlParam (DB))) $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 54 | +if (!is_null (GetUrlParam (DB))) { |
|
| 55 | + $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 56 | +} |
|
| 52 | 57 | $myBook = Book::getBookByDataId($idData); |
| 53 | 58 | |
| 54 | 59 | $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); |
@@ -71,8 +76,7 @@ discard block |
||
| 71 | 76 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); |
| 72 | 77 | header ("Content-Type: " . $book->componentContentType($component)); |
| 73 | 78 | echo $data; |
| 74 | -} |
|
| 75 | -catch (Exception $e) { |
|
| 79 | +} catch (Exception $e) { |
|
| 76 | 80 | error_log ($e); |
| 77 | 81 | notFound (); |
| 78 | 82 | } |
| 79 | 83 | \ No newline at end of file |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | * @return |
| 26 | 26 | * Transliterated text. |
| 27 | 27 | */ |
| 28 | -function _transliteration_process($string, $unknown = '?', $source_langcode = NULL) { |
|
| 28 | +function _transliteration_process($string, $unknown = '?', $source_langcode = NULL) |
|
| 29 | +{ |
|
| 29 | 30 | // ASCII is always valid NFC! If we're only ever given plain ASCII, we can |
| 30 | 31 | // avoid the overhead of initializing the decomposition tables by skipping |
| 31 | 32 | // out early. |
@@ -41,23 +42,17 @@ discard block |
||
| 41 | 42 | for ($n = 0; $n < 256; $n++) { |
| 42 | 43 | if ($n < 0xc0) { |
| 43 | 44 | $remaining = 0; |
| 44 | - } |
|
| 45 | - elseif ($n < 0xe0) { |
|
| 45 | + } elseif ($n < 0xe0) { |
|
| 46 | 46 | $remaining = 1; |
| 47 | - } |
|
| 48 | - elseif ($n < 0xf0) { |
|
| 47 | + } elseif ($n < 0xf0) { |
|
| 49 | 48 | $remaining = 2; |
| 50 | - } |
|
| 51 | - elseif ($n < 0xf8) { |
|
| 49 | + } elseif ($n < 0xf8) { |
|
| 52 | 50 | $remaining = 3; |
| 53 | - } |
|
| 54 | - elseif ($n < 0xfc) { |
|
| 51 | + } elseif ($n < 0xfc) { |
|
| 55 | 52 | $remaining = 4; |
| 56 | - } |
|
| 57 | - elseif ($n < 0xfe) { |
|
| 53 | + } elseif ($n < 0xfe) { |
|
| 58 | 54 | $remaining = 5; |
| 59 | - } |
|
| 60 | - else { |
|
| 55 | + } else { |
|
| 61 | 56 | $remaining = 0; |
| 62 | 57 | } |
| 63 | 58 | $tail_bytes[chr($n)] = $remaining; |
@@ -100,15 +95,13 @@ discard block |
||
| 100 | 95 | if (--$len && ($c = $str[++$i]) >= "\x80" && $c < "\xc0") { |
| 101 | 96 | // Legal tail bytes are nice. |
| 102 | 97 | $sequence .= $c; |
| 103 | - } |
|
| 104 | - else { |
|
| 98 | + } else { |
|
| 105 | 99 | if ($len == 0) { |
| 106 | 100 | // Premature end of string! Drop a replacement character into |
| 107 | 101 | // output to represent the invalid UTF-8 sequence. |
| 108 | 102 | $result .= $unknown; |
| 109 | 103 | break 2; |
| 110 | - } |
|
| 111 | - else { |
|
| 104 | + } else { |
|
| 112 | 105 | // Illegal tail byte; abandon the sequence. |
| 113 | 106 | $result .= $unknown; |
| 114 | 107 | // Back up and reprocess this byte; it may itself be a legal |
@@ -123,34 +116,27 @@ discard block |
||
| 123 | 116 | $n = ord($head); |
| 124 | 117 | if ($n <= 0xdf) { |
| 125 | 118 | $ord = ($n - 192) * 64 + (ord($sequence[1]) - 128); |
| 126 | - } |
|
| 127 | - elseif ($n <= 0xef) { |
|
| 119 | + } elseif ($n <= 0xef) { |
|
| 128 | 120 | $ord = ($n - 224) * 4096 + (ord($sequence[1]) - 128) * 64 + (ord($sequence[2]) - 128); |
| 129 | - } |
|
| 130 | - elseif ($n <= 0xf7) { |
|
| 121 | + } elseif ($n <= 0xf7) { |
|
| 131 | 122 | $ord = ($n - 240) * 262144 + (ord($sequence[1]) - 128) * 4096 + (ord($sequence[2]) - 128) * 64 + (ord($sequence[3]) - 128); |
| 132 | - } |
|
| 133 | - elseif ($n <= 0xfb) { |
|
| 123 | + } elseif ($n <= 0xfb) { |
|
| 134 | 124 | $ord = ($n - 248) * 16777216 + (ord($sequence[1]) - 128) * 262144 + (ord($sequence[2]) - 128) * 4096 + (ord($sequence[3]) - 128) * 64 + (ord($sequence[4]) - 128); |
| 135 | - } |
|
| 136 | - elseif ($n <= 0xfd) { |
|
| 125 | + } elseif ($n <= 0xfd) { |
|
| 137 | 126 | $ord = ($n - 252) * 1073741824 + (ord($sequence[1]) - 128) * 16777216 + (ord($sequence[2]) - 128) * 262144 + (ord($sequence[3]) - 128) * 4096 + (ord($sequence[4]) - 128) * 64 + (ord($sequence[5]) - 128); |
| 138 | 127 | } |
| 139 | 128 | $result .= _transliteration_replace($ord, $unknown, $source_langcode); |
| 140 | 129 | $head = ''; |
| 141 | - } |
|
| 142 | - elseif ($c < "\x80") { |
|
| 130 | + } elseif ($c < "\x80") { |
|
| 143 | 131 | // ASCII byte. |
| 144 | 132 | $result .= $c; |
| 145 | 133 | $head = ''; |
| 146 | - } |
|
| 147 | - elseif ($c < "\xc0") { |
|
| 134 | + } elseif ($c < "\xc0") { |
|
| 148 | 135 | // Illegal tail bytes. |
| 149 | 136 | if ($head == '') { |
| 150 | 137 | $result .= $unknown; |
| 151 | 138 | } |
| 152 | - } |
|
| 153 | - else { |
|
| 139 | + } else { |
|
| 154 | 140 | // Miscellaneous freaks. |
| 155 | 141 | $result .= $unknown; |
| 156 | 142 | $head = ''; |
@@ -175,7 +161,8 @@ discard block |
||
| 175 | 161 | * @return |
| 176 | 162 | * ASCII replacement character. |
| 177 | 163 | */ |
| 178 | -function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) { |
|
| 164 | +function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) |
|
| 165 | +{ |
|
| 179 | 166 | static $map = array(); |
| 180 | 167 | |
| 181 | 168 | //GL: set language later |
@@ -195,12 +182,10 @@ discard block |
||
| 195 | 182 | if ($langcode != 'en' && isset($variant[$langcode])) { |
| 196 | 183 | // Merge in language specific mappings. |
| 197 | 184 | $map[$bank][$langcode] = $variant[$langcode] + $base; |
| 198 | - } |
|
| 199 | - else { |
|
| 185 | + } else { |
|
| 200 | 186 | $map[$bank][$langcode] = $base; |
| 201 | 187 | } |
| 202 | - } |
|
| 203 | - else { |
|
| 188 | + } else { |
|
| 204 | 189 | $map[$bank][$langcode] = array(); |
| 205 | 190 | } |
| 206 | 191 | } |
@@ -6,7 +6,8 @@ discard block |
||
| 6 | 6 | * @author At Libitum <[email protected]> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class Publisher extends Base { |
|
| 9 | +class Publisher extends Base |
|
| 10 | +{ |
|
| 10 | 11 | const ALL_PUBLISHERS_ID = "cops:publishers"; |
| 11 | 12 | const PUBLISHERS_COLUMNS = "publishers.id as id, publishers.name as name, count(*) as count"; |
| 12 | 13 | const SQL_ALL_PUBLISHERS = "select {0} from publishers, books_publishers_link where publishers.id = publisher group by publishers.id, publishers.name order by publishers.name"; |
@@ -16,25 +17,30 @@ discard block |
||
| 16 | 17 | public $id; |
| 17 | 18 | public $name; |
| 18 | 19 | |
| 19 | - public function __construct($post) { |
|
| 20 | + public function __construct($post) |
|
| 21 | + { |
|
| 20 | 22 | $this->id = $post->id; |
| 21 | 23 | $this->name = $post->name; |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | - public function getUri () { |
|
| 26 | + public function getUri () |
|
| 27 | + { |
|
| 25 | 28 | return "?page=".parent::PAGE_PUBLISHER_DETAIL."&id=$this->id"; |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | - public function getEntryId () { |
|
| 31 | + public function getEntryId () |
|
| 32 | + { |
|
| 29 | 33 | return self::ALL_PUBLISHERS_ID.":".$this->id; |
| 30 | 34 | } |
| 31 | 35 | |
| 32 | - public static function getCount() { |
|
| 36 | + public static function getCount() |
|
| 37 | + { |
|
| 33 | 38 | // str_format (localize("publishers.alphabetical", count(array)) |
| 34 | 39 | return parent::getCountGeneric ("publishers", self::ALL_PUBLISHERS_ID, parent::PAGE_ALL_PUBLISHERS); |
| 35 | 40 | } |
| 36 | 41 | |
| 37 | - public static function getPublisherByBookId ($bookId) { |
|
| 42 | + public static function getPublisherByBookId ($bookId) |
|
| 43 | + { |
|
| 38 | 44 | $result = parent::getDb ()->prepare('select publishers.id as id, name |
| 39 | 45 | from books_publishers_link, publishers |
| 40 | 46 | where publishers.id = publisher and book = ?'); |
@@ -45,7 +51,8 @@ discard block |
||
| 45 | 51 | return NULL; |
| 46 | 52 | } |
| 47 | 53 | |
| 48 | - public static function getPublisherById ($publisherId) { |
|
| 54 | + public static function getPublisherById ($publisherId) |
|
| 55 | + { |
|
| 49 | 56 | $result = parent::getDb ()->prepare('select id, name |
| 50 | 57 | from publishers where id = ?'); |
| 51 | 58 | $result->execute (array ($publisherId)); |
@@ -55,11 +62,13 @@ discard block |
||
| 55 | 62 | return NULL; |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | - public static function getAllPublishers() { |
|
| 65 | + public static function getAllPublishers() |
|
| 66 | + { |
|
| 59 | 67 | return Base::getEntryArrayWithBookNumber (self::SQL_ALL_PUBLISHERS, self::PUBLISHERS_COLUMNS, array (), "Publisher"); |
| 60 | 68 | } |
| 61 | 69 | |
| 62 | - public static function getAllPublishersByQuery($query) { |
|
| 70 | + public static function getAllPublishersByQuery($query) |
|
| 71 | + { |
|
| 63 | 72 | return Base::getEntryArrayWithBookNumber (self::SQL_PUBLISHERS_FOR_SEARCH, self::PUBLISHERS_COLUMNS, array ('%' . $query . '%'), "Publisher"); |
| 64 | 73 | } |
| 65 | 74 | } |
@@ -13,12 +13,14 @@ discard block |
||
| 13 | 13 | date_default_timezone_set($config['default_timezone']); |
| 14 | 14 | |
| 15 | 15 | |
| 16 | -function useServerSideRendering () { |
|
| 16 | +function useServerSideRendering () |
|
| 17 | +{ |
|
| 17 | 18 | global $config; |
| 18 | 19 | return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']); |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | -function serverSideRender ($data) { |
|
| 22 | +function serverSideRender ($data) |
|
| 23 | +{ |
|
| 22 | 24 | // Get the templates |
| 23 | 25 | $theme = getCurrentTemplate (); |
| 24 | 26 | $header = file_get_contents('templates/' . $theme . '/header.html'); |
@@ -46,28 +48,32 @@ discard block |
||
| 46 | 48 | return NULL; |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | -function getQueryString () { |
|
| 51 | +function getQueryString () |
|
| 52 | +{ |
|
| 50 | 53 | if ( isset($_SERVER['QUERY_STRING']) ) { |
| 51 | 54 | return $_SERVER['QUERY_STRING']; |
| 52 | 55 | } |
| 53 | 56 | return ""; |
| 54 | 57 | } |
| 55 | 58 | |
| 56 | -function notFound () { |
|
| 59 | +function notFound () |
|
| 60 | +{ |
|
| 57 | 61 | header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
| 58 | 62 | header("Status: 404 Not Found"); |
| 59 | 63 | |
| 60 | 64 | $_SERVER['REDIRECT_STATUS'] = 404; |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | -function getURLParam ($name, $default = NULL) { |
|
| 67 | +function getURLParam ($name, $default = NULL) |
|
| 68 | +{ |
|
| 64 | 69 | if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") { |
| 65 | 70 | return $_GET[$name]; |
| 66 | 71 | } |
| 67 | 72 | return $default; |
| 68 | 73 | } |
| 69 | 74 | |
| 70 | -function getCurrentOption ($option) { |
|
| 75 | +function getCurrentOption ($option) |
|
| 76 | +{ |
|
| 71 | 77 | global $config; |
| 72 | 78 | if (isset($_COOKIE[$option])) { |
| 73 | 79 | if (isset($config ["cops_" . $option]) && is_array ($config ["cops_" . $option])) { |
@@ -83,19 +89,23 @@ discard block |
||
| 83 | 89 | return ""; |
| 84 | 90 | } |
| 85 | 91 | |
| 86 | -function getCurrentCss () { |
|
| 92 | +function getCurrentCss () |
|
| 93 | +{ |
|
| 87 | 94 | return "templates/" . getCurrentTemplate () . "/styles/style-" . getCurrentOption ("style") . ".css"; |
| 88 | 95 | } |
| 89 | 96 | |
| 90 | -function getCurrentTemplate () { |
|
| 97 | +function getCurrentTemplate () |
|
| 98 | +{ |
|
| 91 | 99 | return getCurrentOption ("template"); |
| 92 | 100 | } |
| 93 | 101 | |
| 94 | -function getUrlWithVersion ($url) { |
|
| 102 | +function getUrlWithVersion ($url) |
|
| 103 | +{ |
|
| 95 | 104 | return $url . "?v=" . VERSION; |
| 96 | 105 | } |
| 97 | 106 | |
| 98 | -function xml2xhtml($xml) { |
|
| 107 | +function xml2xhtml($xml) |
|
| 108 | +{ |
|
| 99 | 109 | return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', ' |
| 100 | 110 | $xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param"); |
| 101 | 111 | return in_array($m[1], $xhtml_tags) ? "<$m[1]$m[2] />" : "<$m[1]$m[2]></$m[1]>"; |
@@ -135,12 +145,15 @@ discard block |
||
| 135 | 145 | $errors = libxml_get_errors(); |
| 136 | 146 | |
| 137 | 147 | foreach ($errors as $error) { |
| 138 | - if ($error->code == 801) return false; |
|
| 148 | + if ($error->code == 801) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 139 | 151 | } |
| 140 | 152 | return true; |
| 141 | 153 | } |
| 142 | 154 | |
| 143 | -function html2xhtml ($html) { |
|
| 155 | +function html2xhtml ($html) |
|
| 156 | +{ |
|
| 144 | 157 | $doc = new DOMDocument(); |
| 145 | 158 | libxml_use_internal_errors(true); |
| 146 | 159 | |
@@ -160,7 +173,9 @@ discard block |
||
| 160 | 173 | } |
| 161 | 174 | */ |
| 162 | 175 | |
| 163 | - if (!are_libxml_errors_ok ()) $output = "HTML code not valid."; |
|
| 176 | + if (!are_libxml_errors_ok ()) { |
|
| 177 | + $output = "HTML code not valid."; |
|
| 178 | + } |
|
| 164 | 179 | |
| 165 | 180 | libxml_use_internal_errors(false); |
| 166 | 181 | return $output; |
@@ -170,7 +185,8 @@ discard block |
||
| 170 | 185 | * This method is a direct copy-paste from |
| 171 | 186 | * http://tmont.com/blargh/2010/1/string-format-in-php |
| 172 | 187 | */ |
| 173 | -function str_format($format) { |
|
| 188 | +function str_format($format) |
|
| 189 | +{ |
|
| 174 | 190 | $args = func_get_args(); |
| 175 | 191 | $format = array_shift($args); |
| 176 | 192 | |
@@ -190,7 +206,8 @@ discard block |
||
| 190 | 206 | * languages id are normalized : fr-fr -> fr_FR |
| 191 | 207 | * @return array of languages |
| 192 | 208 | */ |
| 193 | -function getAcceptLanguages() { |
|
| 209 | +function getAcceptLanguages() |
|
| 210 | +{ |
|
| 194 | 211 | $langs = array(); |
| 195 | 212 | |
| 196 | 213 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
@@ -218,7 +235,9 @@ discard block |
||
| 218 | 235 | |
| 219 | 236 | // set default to 1 for any without q factor |
| 220 | 237 | foreach ($langs as $lang => $val) { |
| 221 | - if ($val === '') $langs[$lang] = 1; |
|
| 238 | + if ($val === '') { |
|
| 239 | + $langs[$lang] = 1; |
|
| 240 | + } |
|
| 222 | 241 | } |
| 223 | 242 | |
| 224 | 243 | // sort list based on value |
@@ -233,14 +252,14 @@ discard block |
||
| 233 | 252 | * Find the best translation file possible based on the accepted languages |
| 234 | 253 | * @return array of language and language file |
| 235 | 254 | */ |
| 236 | -function getLangAndTranslationFile() { |
|
| 255 | +function getLangAndTranslationFile() |
|
| 256 | +{ |
|
| 237 | 257 | global $config; |
| 238 | 258 | $langs = array(); |
| 239 | 259 | $lang = "en"; |
| 240 | 260 | if (!empty($config['cops_language'])) { |
| 241 | 261 | $lang = $config['cops_language']; |
| 242 | - } |
|
| 243 | - elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 262 | + } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 244 | 263 | $langs = getAcceptLanguages(); |
| 245 | 264 | } |
| 246 | 265 | //echo var_dump($langs); |
@@ -263,14 +282,18 @@ discard block |
||
| 263 | 282 | * This method is based on this page |
| 264 | 283 | * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/ |
| 265 | 284 | */ |
| 266 | -function localize($phrase, $count=-1, $reset=false) { |
|
| 285 | +function localize($phrase, $count=-1, $reset=false) |
|
| 286 | +{ |
|
| 267 | 287 | global $config; |
| 268 | - if ($count == 0) |
|
| 269 | - $phrase .= ".none"; |
|
| 270 | - if ($count == 1) |
|
| 271 | - $phrase .= ".one"; |
|
| 272 | - if ($count > 1) |
|
| 273 | - $phrase .= ".many"; |
|
| 288 | + if ($count == 0) { |
|
| 289 | + $phrase .= ".none"; |
|
| 290 | + } |
|
| 291 | + if ($count == 1) { |
|
| 292 | + $phrase .= ".one"; |
|
| 293 | + } |
|
| 294 | + if ($count > 1) { |
|
| 295 | + $phrase .= ".many"; |
|
| 296 | + } |
|
| 274 | 297 | |
| 275 | 298 | /* Static keyword is used to ensure the file is loaded only once */ |
| 276 | 299 | static $translations = NULL; |
@@ -295,8 +318,7 @@ discard block |
||
| 295 | 318 | unset ($translations [$key]); |
| 296 | 319 | } |
| 297 | 320 | } |
| 298 | - if ($lang_file_en) |
|
| 299 | - { |
|
| 321 | + if ($lang_file_en) { |
|
| 300 | 322 | $lang_file_content = file_get_contents($lang_file_en); |
| 301 | 323 | $translations_en = json_decode($lang_file_content, true); |
| 302 | 324 | $translations = array_merge ($translations_en, $translations); |
@@ -308,7 +330,8 @@ discard block |
||
| 308 | 330 | return $phrase; |
| 309 | 331 | } |
| 310 | 332 | |
| 311 | -function addURLParameter($urlParams, $paramName, $paramValue) { |
|
| 333 | +function addURLParameter($urlParams, $paramName, $paramValue) |
|
| 334 | +{ |
|
| 312 | 335 | if (empty ($urlParams)) { |
| 313 | 336 | $urlParams = ""; |
| 314 | 337 | } |
@@ -327,17 +350,20 @@ discard block |
||
| 327 | 350 | return $start . http_build_query($params); |
| 328 | 351 | } |
| 329 | 352 | |
| 330 | -function useNormAndUp () { |
|
| 353 | +function useNormAndUp () |
|
| 354 | +{ |
|
| 331 | 355 | global $config; |
| 332 | 356 | return $config ['cops_normalized_search'] == "1"; |
| 333 | 357 | } |
| 334 | 358 | |
| 335 | -function normalizeUtf8String( $s) { |
|
| 359 | +function normalizeUtf8String( $s) |
|
| 360 | +{ |
|
| 336 | 361 | include_once 'transliteration.php'; |
| 337 | 362 | return _transliteration_process($s); |
| 338 | 363 | } |
| 339 | 364 | |
| 340 | -function normAndUp ($s) { |
|
| 365 | +function normAndUp ($s) |
|
| 366 | +{ |
|
| 341 | 367 | return mb_strtoupper (normalizeUtf8String($s), 'UTF-8'); |
| 342 | 368 | } |
| 343 | 369 | |
@@ -356,7 +382,8 @@ discard block |
||
| 356 | 382 | public $facetGroup; |
| 357 | 383 | public $activeFacet; |
| 358 | 384 | |
| 359 | - public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
|
| 385 | + public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) |
|
| 386 | + { |
|
| 360 | 387 | $this->href = $phref; |
| 361 | 388 | $this->type = $ptype; |
| 362 | 389 | $this->rel = $prel; |
@@ -365,11 +392,13 @@ discard block |
||
| 365 | 392 | $this->activeFacet = $pactiveFacet; |
| 366 | 393 | } |
| 367 | 394 | |
| 368 | - public function hrefXhtml () { |
|
| 395 | + public function hrefXhtml () |
|
| 396 | + { |
|
| 369 | 397 | return $this->href; |
| 370 | 398 | } |
| 371 | 399 | |
| 372 | - public function getScriptName() { |
|
| 400 | + public function getScriptName() |
|
| 401 | + { |
|
| 373 | 402 | $parts = explode('/', $_SERVER["SCRIPT_NAME"]); |
| 374 | 403 | return $parts[count($parts) - 1]; |
| 375 | 404 | } |
@@ -377,10 +406,15 @@ discard block |
||
| 377 | 406 | |
| 378 | 407 | class LinkNavigation extends Link |
| 379 | 408 | { |
| 380 | - public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
|
| 409 | + public function __construct($phref, $prel = NULL, $ptitle = NULL) |
|
| 410 | + { |
|
| 381 | 411 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 382 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 383 | - if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
|
| 412 | + if (!is_null (GetUrlParam (DB))) { |
|
| 413 | + $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 414 | + } |
|
| 415 | + if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) { |
|
| 416 | + $this->href = "?" . $this->href; |
|
| 417 | + } |
|
| 384 | 418 | if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
| 385 | 419 | $this->href = "index.php" . $this->href; |
| 386 | 420 | } else { |
@@ -391,9 +425,12 @@ discard block |
||
| 391 | 425 | |
| 392 | 426 | class LinkFacet extends Link |
| 393 | 427 | { |
| 394 | - public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
|
| 428 | + public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) |
|
| 429 | + { |
|
| 395 | 430 | parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
| 396 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 431 | + if (!is_null (GetUrlParam (DB))) { |
|
| 432 | + $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 433 | + } |
|
| 397 | 434 | $this->href = parent::getScriptName() . $this->href; |
| 398 | 435 | } |
| 399 | 436 | } |
@@ -423,7 +460,8 @@ discard block |
||
| 423 | 460 | Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png' |
| 424 | 461 | ); |
| 425 | 462 | |
| 426 | - public function getUpdatedTime () { |
|
| 463 | + public function getUpdatedTime () |
|
| 464 | + { |
|
| 427 | 465 | if (!is_null ($this->localUpdated)) { |
| 428 | 466 | return date (DATE_ATOM, $this->localUpdated); |
| 429 | 467 | } |
@@ -433,7 +471,8 @@ discard block |
||
| 433 | 471 | return date (DATE_ATOM, self::$updated); |
| 434 | 472 | } |
| 435 | 473 | |
| 436 | - public function getNavLink () { |
|
| 474 | + public function getNavLink () |
|
| 475 | + { |
|
| 437 | 476 | foreach ($this->linkArray as $link) { |
| 438 | 477 | if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; } |
| 439 | 478 | |
@@ -442,7 +481,8 @@ discard block |
||
| 442 | 481 | return "#"; |
| 443 | 482 | } |
| 444 | 483 | |
| 445 | - public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) { |
|
| 484 | + public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) |
|
| 485 | + { |
|
| 446 | 486 | global $config; |
| 447 | 487 | $this->title = $ptitle; |
| 448 | 488 | $this->id = $pid; |
@@ -452,10 +492,8 @@ discard block |
||
| 452 | 492 | $this->className = $pclass; |
| 453 | 493 | $this->numberOfElement = $pcount; |
| 454 | 494 | |
| 455 | - if ($config['cops_show_icons'] == 1) |
|
| 456 | - { |
|
| 457 | - foreach (self::$icons as $reg => $image) |
|
| 458 | - { |
|
| 495 | + if ($config['cops_show_icons'] == 1) { |
|
| 496 | + foreach (self::$icons as $reg => $image) { |
|
| 459 | 497 | if (preg_match ("/" . $reg . "/", $pid)) { |
| 460 | 498 | array_push ($this->linkArray, new Link (getUrlWithVersion ($image), "image/png", Link::OPDS_THUMBNAIL_TYPE)); |
| 461 | 499 | break; |
@@ -463,7 +501,9 @@ discard block |
||
| 463 | 501 | } |
| 464 | 502 | } |
| 465 | 503 | |
| 466 | - if (!is_null (GetUrlParam (DB))) $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id); |
|
| 504 | + if (!is_null (GetUrlParam (DB))) { |
|
| 505 | + $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id); |
|
| 506 | + } |
|
| 467 | 507 | } |
| 468 | 508 | } |
| 469 | 509 | |
@@ -471,24 +511,29 @@ discard block |
||
| 471 | 511 | { |
| 472 | 512 | public $book; |
| 473 | 513 | |
| 474 | - public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) { |
|
| 514 | + public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) |
|
| 515 | + { |
|
| 475 | 516 | parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray); |
| 476 | 517 | $this->book = $pbook; |
| 477 | 518 | $this->localUpdated = $pbook->timestamp; |
| 478 | 519 | } |
| 479 | 520 | |
| 480 | - public function getCoverThumbnail () { |
|
| 521 | + public function getCoverThumbnail () |
|
| 522 | + { |
|
| 481 | 523 | foreach ($this->linkArray as $link) { |
| 482 | - if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) |
|
| 483 | - return $link->hrefXhtml (); |
|
| 524 | + if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) { |
|
| 525 | + return $link->hrefXhtml (); |
|
| 526 | + } |
|
| 484 | 527 | } |
| 485 | 528 | return null; |
| 486 | 529 | } |
| 487 | 530 | |
| 488 | - public function getCover () { |
|
| 531 | + public function getCover () |
|
| 532 | + { |
|
| 489 | 533 | foreach ($this->linkArray as $link) { |
| 490 | - if ($link->rel == Link::OPDS_IMAGE_TYPE) |
|
| 491 | - return $link->hrefXhtml (); |
|
| 534 | + if ($link->rel == Link::OPDS_IMAGE_TYPE) { |
|
| 535 | + return $link->hrefXhtml (); |
|
| 536 | + } |
|
| 492 | 537 | } |
| 493 | 538 | return null; |
| 494 | 539 | } |
@@ -564,7 +609,8 @@ discard block |
||
| 564 | 609 | } |
| 565 | 610 | } |
| 566 | 611 | |
| 567 | - public function __construct($pid, $pquery, $pn) { |
|
| 612 | + public function __construct($pid, $pquery, $pn) |
|
| 613 | + { |
|
| 568 | 614 | global $config; |
| 569 | 615 | |
| 570 | 616 | $this->idGet = $pid; |
@@ -597,23 +643,33 @@ discard block |
||
| 597 | 643 | } |
| 598 | 644 | if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) { |
| 599 | 645 | $series = Serie::getCount(); |
| 600 | - if (!is_null ($series)) array_push ($this->entryArray, $series); |
|
| 646 | + if (!is_null ($series)) { |
|
| 647 | + array_push ($this->entryArray, $series); |
|
| 648 | + } |
|
| 601 | 649 | } |
| 602 | 650 | if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) { |
| 603 | 651 | $publisher = Publisher::getCount(); |
| 604 | - if (!is_null ($publisher)) array_push ($this->entryArray, $publisher); |
|
| 652 | + if (!is_null ($publisher)) { |
|
| 653 | + array_push ($this->entryArray, $publisher); |
|
| 654 | + } |
|
| 605 | 655 | } |
| 606 | 656 | if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) { |
| 607 | 657 | $tags = Tag::getCount(); |
| 608 | - if (!is_null ($tags)) array_push ($this->entryArray, $tags); |
|
| 658 | + if (!is_null ($tags)) { |
|
| 659 | + array_push ($this->entryArray, $tags); |
|
| 660 | + } |
|
| 609 | 661 | } |
| 610 | 662 | if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) { |
| 611 | 663 | $rating = Rating::getCount(); |
| 612 | - if (!is_null ($rating)) array_push ($this->entryArray, $rating); |
|
| 664 | + if (!is_null ($rating)) { |
|
| 665 | + array_push ($this->entryArray, $rating); |
|
| 666 | + } |
|
| 613 | 667 | } |
| 614 | 668 | if (!in_array ("language", getCurrentOption ('ignored_categories'))) { |
| 615 | 669 | $languages = Language::getCount(); |
| 616 | - if (!is_null ($languages)) array_push ($this->entryArray, $languages); |
|
| 670 | + if (!is_null ($languages)) { |
|
| 671 | + array_push ($this->entryArray, $languages); |
|
| 672 | + } |
|
| 617 | 673 | } |
| 618 | 674 | foreach ($config['cops_calibre_custom_column'] as $lookup) { |
| 619 | 675 | $customId = CustomColumn::getCustomId ($lookup); |
@@ -623,7 +679,9 @@ discard block |
||
| 623 | 679 | } |
| 624 | 680 | $this->entryArray = array_merge ($this->entryArray, Book::getCount()); |
| 625 | 681 | |
| 626 | - if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName (); |
|
| 682 | + if (Base::isMultipleDatabaseEnabled ()) { |
|
| 683 | + $this->title = Base::getDbName (); |
|
| 684 | + } |
|
| 627 | 685 | } |
| 628 | 686 | } |
| 629 | 687 | |
@@ -659,8 +717,12 @@ discard block |
||
| 659 | 717 | |
| 660 | 718 | public function containsBook () |
| 661 | 719 | { |
| 662 | - if (count ($this->entryArray) == 0) return false; |
|
| 663 | - if (get_class ($this->entryArray [0]) == "EntryBook") return true; |
|
| 720 | + if (count ($this->entryArray) == 0) { |
|
| 721 | + return false; |
|
| 722 | + } |
|
| 723 | + if (get_class ($this->entryArray [0]) == "EntryBook") { |
|
| 724 | + return true; |
|
| 725 | + } |
|
| 664 | 726 | return false; |
| 665 | 727 | } |
| 666 | 728 | } |
@@ -672,8 +734,7 @@ discard block |
||
| 672 | 734 | $this->title = localize("authors.title"); |
| 673 | 735 | if (getCurrentOption ("author_split_first_letter") == 1) { |
| 674 | 736 | $this->entryArray = Author::getAllAuthorsByFirstLetter(); |
| 675 | - } |
|
| 676 | - else { |
|
| 737 | + } else { |
|
| 677 | 738 | $this->entryArray = Author::getAllAuthors(); |
| 678 | 739 | } |
| 679 | 740 | $this->idPage = Author::ALL_AUTHORS_ID; |
@@ -836,8 +897,7 @@ discard block |
||
| 836 | 897 | $this->title = localize ("allbooks.title"); |
| 837 | 898 | if (getCurrentOption ("titles_split_first_letter") == 1) { |
| 838 | 899 | $this->entryArray = Book::getAllBooks(); |
| 839 | - } |
|
| 840 | - else { |
|
| 900 | + } else { |
|
| 841 | 901 | list ($this->entryArray, $this->totalNumber) = Book::getBooks ($this->n); |
| 842 | 902 | } |
| 843 | 903 | $this->idPage = Book::ALL_BOOKS_ID; |
@@ -852,8 +912,9 @@ discard block |
||
| 852 | 912 | $this->idPage = Book::getEntryIdByLetter ($this->idGet); |
| 853 | 913 | |
| 854 | 914 | $count = $this->totalNumber; |
| 855 | - if ($count == -1) |
|
| 856 | - $count = count ($this->entryArray); |
|
| 915 | + if ($count == -1) { |
|
| 916 | + $count = count ($this->entryArray); |
|
| 917 | + } |
|
| 857 | 918 | |
| 858 | 919 | $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet); |
| 859 | 920 | } |
@@ -878,11 +939,13 @@ discard block |
||
| 878 | 939 | const SCOPE_BOOK = "book"; |
| 879 | 940 | const SCOPE_PUBLISHER = "publisher"; |
| 880 | 941 | |
| 881 | - private function useTypeahead () { |
|
| 942 | + private function useTypeahead () |
|
| 943 | + { |
|
| 882 | 944 | return !is_null (getURLParam ("search")); |
| 883 | 945 | } |
| 884 | 946 | |
| 885 | - private function searchByScope ($scope, $limit = FALSE) { |
|
| 947 | + private function searchByScope ($scope, $limit = FALSE) |
|
| 948 | + { |
|
| 886 | 949 | $n = $this->n; |
| 887 | 950 | $numberPerPage = NULL; |
| 888 | 951 | $queryNormedAndUp = $this->query; |
@@ -917,7 +980,8 @@ discard block |
||
| 917 | 980 | return $array; |
| 918 | 981 | } |
| 919 | 982 | |
| 920 | - public function doSearchByCategory () { |
|
| 983 | + public function doSearchByCategory () |
|
| 984 | + { |
|
| 921 | 985 | $database = GetUrlParam (DB); |
| 922 | 986 | $out = array (); |
| 923 | 987 | $pagequery = Base::PAGE_OPENSEARCH_QUERY; |
@@ -1044,7 +1108,8 @@ discard block |
||
| 1044 | 1108 | |
| 1045 | 1109 | class PageCustomize extends Page |
| 1046 | 1110 | { |
| 1047 | - private function isChecked ($key, $testedValue = 1) { |
|
| 1111 | + private function isChecked ($key, $testedValue = 1) |
|
| 1112 | + { |
|
| 1048 | 1113 | $value = getCurrentOption ($key); |
| 1049 | 1114 | if (is_array ($value)) { |
| 1050 | 1115 | if (in_array ($testedValue, $value)) { |
@@ -1058,14 +1123,16 @@ discard block |
||
| 1058 | 1123 | return ""; |
| 1059 | 1124 | } |
| 1060 | 1125 | |
| 1061 | - private function isSelected ($key, $value) { |
|
| 1126 | + private function isSelected ($key, $value) |
|
| 1127 | + { |
|
| 1062 | 1128 | if (getCurrentOption ($key) == $value) { |
| 1063 | 1129 | return "selected='selected'"; |
| 1064 | 1130 | } |
| 1065 | 1131 | return ""; |
| 1066 | 1132 | } |
| 1067 | 1133 | |
| 1068 | - private function getStyleList () { |
|
| 1134 | + private function getStyleList () |
|
| 1135 | + { |
|
| 1069 | 1136 | $result = array (); |
| 1070 | 1137 | foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) { |
| 1071 | 1138 | if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { |
@@ -1167,23 +1234,27 @@ discard block |
||
| 1167 | 1234 | |
| 1168 | 1235 | private static $db = NULL; |
| 1169 | 1236 | |
| 1170 | - public static function isMultipleDatabaseEnabled () { |
|
| 1237 | + public static function isMultipleDatabaseEnabled () |
|
| 1238 | + { |
|
| 1171 | 1239 | global $config; |
| 1172 | 1240 | return is_array ($config['calibre_directory']); |
| 1173 | 1241 | } |
| 1174 | 1242 | |
| 1175 | - public static function useAbsolutePath () { |
|
| 1243 | + public static function useAbsolutePath () |
|
| 1244 | + { |
|
| 1176 | 1245 | global $config; |
| 1177 | 1246 | $path = self::getDbDirectory(); |
| 1178 | 1247 | return preg_match ('/^\//', $path) || // Linux / |
| 1179 | 1248 | preg_match ('/^\w\:/', $path); // Windows X: |
| 1180 | 1249 | } |
| 1181 | 1250 | |
| 1182 | - public static function noDatabaseSelected () { |
|
| 1251 | + public static function noDatabaseSelected () |
|
| 1252 | + { |
|
| 1183 | 1253 | return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
| 1184 | 1254 | } |
| 1185 | 1255 | |
| 1186 | - public static function getDbList () { |
|
| 1256 | + public static function getDbList () |
|
| 1257 | + { |
|
| 1187 | 1258 | global $config; |
| 1188 | 1259 | if (self::isMultipleDatabaseEnabled ()) { |
| 1189 | 1260 | return $config['calibre_directory']; |
@@ -1192,7 +1263,8 @@ discard block |
||
| 1192 | 1263 | } |
| 1193 | 1264 | } |
| 1194 | 1265 | |
| 1195 | - public static function getDbNameList () { |
|
| 1266 | + public static function getDbNameList () |
|
| 1267 | + { |
|
| 1196 | 1268 | global $config; |
| 1197 | 1269 | if (self::isMultipleDatabaseEnabled ()) { |
| 1198 | 1270 | return array_keys ($config['calibre_directory']); |
@@ -1201,10 +1273,13 @@ discard block |
||
| 1201 | 1273 | } |
| 1202 | 1274 | } |
| 1203 | 1275 | |
| 1204 | - public static function getDbName ($database = NULL) { |
|
| 1276 | + public static function getDbName ($database = NULL) |
|
| 1277 | + { |
|
| 1205 | 1278 | global $config; |
| 1206 | 1279 | if (self::isMultipleDatabaseEnabled ()) { |
| 1207 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 1280 | + if (is_null ($database)) { |
|
| 1281 | + $database = GetUrlParam (DB, 0); |
|
| 1282 | + } |
|
| 1208 | 1283 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 1209 | 1284 | return self::error ($database); |
| 1210 | 1285 | } |
@@ -1214,10 +1289,13 @@ discard block |
||
| 1214 | 1289 | return ""; |
| 1215 | 1290 | } |
| 1216 | 1291 | |
| 1217 | - public static function getDbDirectory ($database = NULL) { |
|
| 1292 | + public static function getDbDirectory ($database = NULL) |
|
| 1293 | + { |
|
| 1218 | 1294 | global $config; |
| 1219 | 1295 | if (self::isMultipleDatabaseEnabled ()) { |
| 1220 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 1296 | + if (is_null ($database)) { |
|
| 1297 | + $database = GetUrlParam (DB, 0); |
|
| 1298 | + } |
|
| 1221 | 1299 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 1222 | 1300 | return self::error ($database); |
| 1223 | 1301 | } |
@@ -1228,18 +1306,21 @@ discard block |
||
| 1228 | 1306 | } |
| 1229 | 1307 | |
| 1230 | 1308 | |
| 1231 | - public static function getDbFileName ($database = NULL) { |
|
| 1309 | + public static function getDbFileName ($database = NULL) |
|
| 1310 | + { |
|
| 1232 | 1311 | return self::getDbDirectory ($database) .'metadata.db'; |
| 1233 | 1312 | } |
| 1234 | 1313 | |
| 1235 | - private static function error ($database) { |
|
| 1314 | + private static function error ($database) |
|
| 1315 | + { |
|
| 1236 | 1316 | if (php_sapi_name() != "cli") { |
| 1237 | 1317 | header("location: checkconfig.php?err=1"); |
| 1238 | 1318 | } |
| 1239 | 1319 | throw new Exception("Database <{$database}> not found."); |
| 1240 | 1320 | } |
| 1241 | 1321 | |
| 1242 | - public static function getDb ($database = NULL) { |
|
| 1322 | + public static function getDb ($database = NULL) |
|
| 1323 | + { |
|
| 1243 | 1324 | if (is_null (self::$db)) { |
| 1244 | 1325 | try { |
| 1245 | 1326 | if (is_readable (self::getDbFileName ($database))) { |
@@ -1257,7 +1338,8 @@ discard block |
||
| 1257 | 1338 | return self::$db; |
| 1258 | 1339 | } |
| 1259 | 1340 | |
| 1260 | - public static function checkDatabaseAvailability () { |
|
| 1341 | + public static function checkDatabaseAvailability () |
|
| 1342 | + { |
|
| 1261 | 1343 | if (self::noDatabaseSelected ()) { |
| 1262 | 1344 | for ($i = 0; $i < count (self::getDbList ()); $i++) { |
| 1263 | 1345 | self::getDb ($i); |
@@ -1269,31 +1351,36 @@ discard block |
||
| 1269 | 1351 | return true; |
| 1270 | 1352 | } |
| 1271 | 1353 | |
| 1272 | - public static function clearDb () { |
|
| 1354 | + public static function clearDb () |
|
| 1355 | + { |
|
| 1273 | 1356 | self::$db = NULL; |
| 1274 | 1357 | } |
| 1275 | 1358 | |
| 1276 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 1359 | + public static function executeQuerySingle ($query, $database = NULL) |
|
| 1360 | + { |
|
| 1277 | 1361 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 1278 | 1362 | } |
| 1279 | 1363 | |
| 1280 | - public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
|
| 1364 | + public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) |
|
| 1365 | + { |
|
| 1281 | 1366 | if (!$numberOfString) { |
| 1282 | 1367 | $numberOfString = $table . ".alphabetical"; |
| 1283 | 1368 | } |
| 1284 | 1369 | $count = self::executeQuerySingle ('select count(*) from ' . $table); |
| 1285 | - if ($count == 0) return NULL; |
|
| 1370 | + if ($count == 0) { |
|
| 1371 | + return NULL; |
|
| 1372 | + } |
|
| 1286 | 1373 | $entry = new Entry (localize($table . ".title"), $id, |
| 1287 | 1374 | str_format (localize($numberOfString, $count), $count), "text", |
| 1288 | 1375 | array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
| 1289 | 1376 | return $entry; |
| 1290 | 1377 | } |
| 1291 | 1378 | |
| 1292 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 1379 | + public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) |
|
| 1380 | + { |
|
| 1293 | 1381 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 1294 | 1382 | $entryArray = array(); |
| 1295 | - while ($post = $result->fetchObject ()) |
|
| 1296 | - { |
|
| 1383 | + while ($post = $result->fetchObject ()) { |
|
| 1297 | 1384 | $instance = new $category ($post); |
| 1298 | 1385 | if (property_exists($post, "sort")) { |
| 1299 | 1386 | $title = $post->sort; |
@@ -1307,7 +1394,8 @@ discard block |
||
| 1307 | 1394 | return $entryArray; |
| 1308 | 1395 | } |
| 1309 | 1396 | |
| 1310 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 1397 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 1398 | + { |
|
| 1311 | 1399 | $totalResult = -1; |
| 1312 | 1400 | |
| 1313 | 1401 | if (useNormAndUp ()) { |
@@ -1319,8 +1407,7 @@ discard block |
||
| 1319 | 1407 | $numberPerPage = getCurrentOption ("max_item_per_page"); |
| 1320 | 1408 | } |
| 1321 | 1409 | |
| 1322 | - if ($numberPerPage != -1 && $n != -1) |
|
| 1323 | - { |
|
| 1410 | + if ($numberPerPage != -1 && $n != -1) { |
|
| 1324 | 1411 | // First check total number of results |
| 1325 | 1412 | $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
| 1326 | 1413 | $result->execute ($params); |
@@ -13,14 +13,16 @@ discard block |
||
| 13 | 13 | private $xmlStream = NULL; |
| 14 | 14 | private $updated = NULL; |
| 15 | 15 | |
| 16 | - private function getUpdatedTime () { |
|
| 16 | + private function getUpdatedTime () |
|
| 17 | + { |
|
| 17 | 18 | if (is_null ($this->updated)) { |
| 18 | 19 | $this->updated = time(); |
| 19 | 20 | } |
| 20 | 21 | return date (DATE_ATOM, $this->updated); |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - private function getXmlStream () { |
|
| 24 | + private function getXmlStream () |
|
| 25 | + { |
|
| 24 | 26 | if (is_null ($this->xmlStream)) { |
| 25 | 27 | $this->xmlStream = new XMLWriter(); |
| 26 | 28 | $this->xmlStream->openMemory(); |
@@ -29,7 +31,8 @@ discard block |
||
| 29 | 31 | return $this->xmlStream; |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | - public function getOpenSearch () { |
|
| 34 | + public function getOpenSearch () |
|
| 35 | + { |
|
| 33 | 36 | global $config; |
| 34 | 37 | $xml = new XMLWriter (); |
| 35 | 38 | $xml->openMemory (); |
@@ -58,7 +61,9 @@ discard block |
||
| 58 | 61 | $xml->startElement ("Url"); |
| 59 | 62 | $xml->writeAttribute ("type", 'application/atom+xml'); |
| 60 | 63 | $urlparam = "?query={searchTerms}"; |
| 61 | - if (!is_null (GetUrlParam (DB))) $urlparam = addURLParameter ($urlparam, DB, GetUrlParam (DB)); |
|
| 64 | + if (!is_null (GetUrlParam (DB))) { |
|
| 65 | + $urlparam = addURLParameter ($urlparam, DB, GetUrlParam (DB)); |
|
| 66 | + } |
|
| 62 | 67 | $urlparam = str_replace ("%7B", "{", $urlparam); |
| 63 | 68 | $urlparam = str_replace ("%7D", "}", $urlparam); |
| 64 | 69 | $xml->writeAttribute ("template", $config['cops_full_url'] . 'feed.php' . $urlparam); |
@@ -72,7 +77,8 @@ discard block |
||
| 72 | 77 | return $xml->outputMemory(true); |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | - private function startXmlDocument ($page) { |
|
| 80 | + private function startXmlDocument ($page) |
|
| 81 | + { |
|
| 76 | 82 | global $config; |
| 77 | 83 | self::getXmlStream ()->startDocument('1.0','UTF-8'); |
| 78 | 84 | self::getXmlStream ()->startElement ("feed"); |
@@ -84,21 +90,19 @@ discard block |
||
| 84 | 90 | self::getXmlStream ()->startElement ("title"); |
| 85 | 91 | self::getXmlStream ()->text ($page->title); |
| 86 | 92 | self::getXmlStream ()->endElement (); |
| 87 | - if ($page->subtitle != "") |
|
| 88 | - { |
|
| 93 | + if ($page->subtitle != "") { |
|
| 89 | 94 | self::getXmlStream ()->startElement ("subtitle"); |
| 90 | 95 | self::getXmlStream ()->text ($page->subtitle); |
| 91 | 96 | self::getXmlStream ()->endElement (); |
| 92 | 97 | } |
| 93 | 98 | self::getXmlStream ()->startElement ("id"); |
| 94 | - if ($page->idPage) |
|
| 95 | - { |
|
| 99 | + if ($page->idPage) { |
|
| 96 | 100 | $idPage = $page->idPage; |
| 97 | - if (!is_null (GetUrlParam (DB))) $idPage = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $idPage); |
|
| 101 | + if (!is_null (GetUrlParam (DB))) { |
|
| 102 | + $idPage = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $idPage); |
|
| 103 | + } |
|
| 98 | 104 | self::getXmlStream ()->text ($idPage); |
| 99 | - } |
|
| 100 | - else |
|
| 101 | - { |
|
| 105 | + } else { |
|
| 102 | 106 | self::getXmlStream ()->text ($_SERVER['REQUEST_URI']); |
| 103 | 107 | } |
| 104 | 108 | self::getXmlStream ()->endElement (); |
@@ -124,14 +128,14 @@ discard block |
||
| 124 | 128 | $link = new LinkNavigation ("?" . getQueryString (), "self"); |
| 125 | 129 | self::renderLink ($link); |
| 126 | 130 | $urlparam = "?"; |
| 127 | - if (!is_null (GetUrlParam (DB))) $urlparam = addURLParameter ($urlparam, DB, GetUrlParam (DB)); |
|
| 131 | + if (!is_null (GetUrlParam (DB))) { |
|
| 132 | + $urlparam = addURLParameter ($urlparam, DB, GetUrlParam (DB)); |
|
| 133 | + } |
|
| 128 | 134 | if ($config['cops_generate_invalid_opds_stream'] == 0 || preg_match("/(MantanoReader|FBReader)/", $_SERVER['HTTP_USER_AGENT'])) { |
| 129 | 135 | // Good and compliant way of handling search |
| 130 | 136 | $urlparam = addURLParameter ($urlparam, "page", Base::PAGE_OPENSEARCH); |
| 131 | 137 | $link = new Link ("feed.php" . $urlparam, "application/opensearchdescription+xml", "search", "Search here"); |
| 132 | - } |
|
| 133 | - else |
|
| 134 | - { |
|
| 138 | + } else { |
|
| 135 | 139 | // Bad way, will be removed when OPDS client are fixed |
| 136 | 140 | $urlparam = addURLParameter ($urlparam, "query", "{searchTerms}"); |
| 137 | 141 | $urlparam = str_replace ("%7B", "{", $urlparam); |
@@ -148,13 +152,15 @@ discard block |
||
| 148 | 152 | } |
| 149 | 153 | } |
| 150 | 154 | |
| 151 | - private function endXmlDocument () { |
|
| 155 | + private function endXmlDocument () |
|
| 156 | + { |
|
| 152 | 157 | self::getXmlStream ()->endElement (); |
| 153 | 158 | self::getXmlStream ()->endDocument (); |
| 154 | 159 | return self::getXmlStream ()->outputMemory(true); |
| 155 | 160 | } |
| 156 | 161 | |
| 157 | - private function renderLink ($link) { |
|
| 162 | + private function renderLink ($link) |
|
| 163 | + { |
|
| 158 | 164 | self::getXmlStream ()->startElement ("link"); |
| 159 | 165 | self::getXmlStream ()->writeAttribute ("href", $link->href); |
| 160 | 166 | self::getXmlStream ()->writeAttribute ("type", $link->type); |
@@ -173,7 +179,8 @@ discard block |
||
| 173 | 179 | self::getXmlStream ()->endElement (); |
| 174 | 180 | } |
| 175 | 181 | |
| 176 | - private function getPublicationDate($book) { |
|
| 182 | + private function getPublicationDate($book) |
|
| 183 | + { |
|
| 177 | 184 | $dateYmd = substr($book->pubdate, 0, 10); |
| 178 | 185 | $pubdate = \DateTime::createFromFormat('Y-m-d', $dateYmd); |
| 179 | 186 | if ($pubdate === false || |
@@ -184,7 +191,8 @@ discard block |
||
| 184 | 191 | return $pubdate->format("Y-m-d"); |
| 185 | 192 | } |
| 186 | 193 | |
| 187 | - private function renderEntry ($entry) { |
|
| 194 | + private function renderEntry ($entry) |
|
| 195 | + { |
|
| 188 | 196 | self::getXmlStream ()->startElement ("title"); |
| 189 | 197 | self::getXmlStream ()->text ($entry->title); |
| 190 | 198 | self::getXmlStream ()->endElement (); |
@@ -244,11 +252,11 @@ discard block |
||
| 244 | 252 | |
| 245 | 253 | } |
| 246 | 254 | |
| 247 | - public function render ($page) { |
|
| 255 | + public function render ($page) |
|
| 256 | + { |
|
| 248 | 257 | global $config; |
| 249 | 258 | self::startXmlDocument ($page); |
| 250 | - if ($page->isPaginated ()) |
|
| 251 | - { |
|
| 259 | + if ($page->isPaginated ()) { |
|
| 252 | 260 | self::getXmlStream ()->startElement ("opensearch:totalResults"); |
| 253 | 261 | self::getXmlStream ()->text ($page->totalNumber); |
| 254 | 262 | self::getXmlStream ()->endElement (); |