@@ -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']; |
@@ -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 | } |
@@ -21,13 +21,11 @@ |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if(!is_null($config['cops_basic_authentication']) && |
| 24 | - is_array($config['cops_basic_authentication'])) |
|
| 25 | -{ |
|
| 24 | + is_array($config['cops_basic_authentication'])) { |
|
| 26 | 25 | if (!isset($_SERVER['PHP_AUTH_USER']) || |
| 27 | 26 | (isset($_SERVER['PHP_AUTH_USER']) && |
| 28 | 27 | ($_SERVER['PHP_AUTH_USER']!=$config['cops_basic_authentication']['username'] || |
| 29 | - $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password']))) |
|
| 30 | - { |
|
| 28 | + $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password']))) { |
|
| 31 | 29 | header('WWW-Authenticate: Basic realm="COPS Authentication"'); |
| 32 | 30 | header('HTTP/1.0 401 Unauthorized'); |
| 33 | 31 | echo 'This site is password protected'; |
@@ -13,20 +13,24 @@ discard block |
||
| 13 | 13 | public $id; |
| 14 | 14 | public $lang_code; |
| 15 | 15 | |
| 16 | - public function __construct($pid, $plang_code) { |
|
| 16 | + public function __construct($pid, $plang_code) |
|
| 17 | + { |
|
| 17 | 18 | $this->id = $pid; |
| 18 | 19 | $this->lang_code = $plang_code; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | - public function getUri () { |
|
| 22 | + public function getUri () |
|
| 23 | + { |
|
| 22 | 24 | return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | - public function getEntryId () { |
|
| 27 | + public function getEntryId () |
|
| 28 | + { |
|
| 26 | 29 | return self::ALL_LANGUAGES_ID.":".$this->id; |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - public static function getLanguageString ($code) { |
|
| 32 | + public static function getLanguageString ($code) |
|
| 33 | + { |
|
| 30 | 34 | $string = localize("languages.".$code); |
| 31 | 35 | if (preg_match ("/^languages/", $string)) { |
| 32 | 36 | return $code; |
@@ -34,12 +38,14 @@ discard block |
||
| 34 | 38 | return $string; |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | - public static function getCount() { |
|
| 41 | + public static function getCount() |
|
| 42 | + { |
|
| 38 | 43 | // str_format (localize("languages.alphabetical", count(array)) |
| 39 | 44 | return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | - public static function getLanguageById ($languageId) { |
|
| 47 | + public static function getLanguageById ($languageId) |
|
| 48 | + { |
|
| 43 | 49 | $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
| 44 | 50 | $result->execute (array ($languageId)); |
| 45 | 51 | if ($post = $result->fetchObject ()) { |
@@ -50,15 +56,15 @@ discard block |
||
| 50 | 56 | |
| 51 | 57 | |
| 52 | 58 | |
| 53 | - public static function getAllLanguages() { |
|
| 59 | + public static function getAllLanguages() |
|
| 60 | + { |
|
| 54 | 61 | $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count |
| 55 | 62 | from languages, books_languages_link |
| 56 | 63 | where languages.id = books_languages_link.lang_code |
| 57 | 64 | group by languages.id, books_languages_link.lang_code |
| 58 | 65 | order by languages.lang_code'); |
| 59 | 66 | $entryArray = array(); |
| 60 | - while ($post = $result->fetchObject ()) |
|
| 61 | - { |
|
| 67 | + while ($post = $result->fetchObject ()) { |
|
| 62 | 68 | $language = new Language ($post->id, $post->lang_code); |
| 63 | 69 | array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
| 64 | 70 | str_format (localize("bookword", $post->count), $post->count), "text", |
@@ -15,11 +15,13 @@ discard block |
||
| 15 | 15 | const SCOPE_BOOK = "book"; |
| 16 | 16 | const SCOPE_PUBLISHER = "publisher"; |
| 17 | 17 | |
| 18 | - private function useTypeahead () { |
|
| 18 | + private function useTypeahead () |
|
| 19 | + { |
|
| 19 | 20 | return !is_null (getURLParam ("search")); |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | - private function searchByScope ($scope, $limit = FALSE) { |
|
| 23 | + private function searchByScope ($scope, $limit = FALSE) |
|
| 24 | + { |
|
| 23 | 25 | $n = $this->n; |
| 24 | 26 | $numberPerPage = NULL; |
| 25 | 27 | $queryNormedAndUp = $this->query; |
@@ -54,7 +56,8 @@ discard block |
||
| 54 | 56 | return $array; |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | - public function doSearchByCategory () { |
|
| 59 | + public function doSearchByCategory () |
|
| 60 | + { |
|
| 58 | 61 | $database = GetUrlParam (DB); |
| 59 | 62 | $out = array (); |
| 60 | 63 | $pagequery = Base::PAGE_OPENSEARCH_QUERY; |
@@ -14,48 +14,58 @@ discard block |
||
| 14 | 14 | public $name; |
| 15 | 15 | public $customId; |
| 16 | 16 | |
| 17 | - public function __construct($pid, $pname, $pcustomId) { |
|
| 17 | + public function __construct($pid, $pname, $pcustomId) |
|
| 18 | + { |
|
| 18 | 19 | $this->id = $pid; |
| 19 | 20 | $this->name = $pname; |
| 20 | 21 | $this->customId = $pcustomId; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - public function getUri () { |
|
| 24 | + public function getUri () |
|
| 25 | + { |
|
| 24 | 26 | return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}"; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - public function getEntryId () { |
|
| 29 | + public function getEntryId () |
|
| 30 | + { |
|
| 28 | 31 | return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id; |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - public static function getTableName ($customId) { |
|
| 34 | + public static function getTableName ($customId) |
|
| 35 | + { |
|
| 32 | 36 | return "custom_column_{$customId}"; |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | - public static function getTableLinkName ($customId) { |
|
| 39 | + public static function getTableLinkName ($customId) |
|
| 40 | + { |
|
| 36 | 41 | return "books_custom_column_{$customId}_link"; |
| 37 | 42 | } |
| 38 | 43 | |
| 39 | - public static function getTableLinkColumn ($customId) { |
|
| 44 | + public static function getTableLinkColumn ($customId) |
|
| 45 | + { |
|
| 40 | 46 | return "value"; |
| 41 | 47 | } |
| 42 | 48 | |
| 43 | - public static function getAllCustomsId ($customId) { |
|
| 49 | + public static function getAllCustomsId ($customId) |
|
| 50 | + { |
|
| 44 | 51 | return self::ALL_CUSTOMS_ID . ":" . $customId; |
| 45 | 52 | } |
| 46 | 53 | |
| 47 | - public static function getUriAllCustoms ($customId) { |
|
| 54 | + public static function getUriAllCustoms ($customId) |
|
| 55 | + { |
|
| 48 | 56 | return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}"; |
| 49 | 57 | } |
| 50 | 58 | |
| 51 | - public static function getAllTitle ($customId) { |
|
| 59 | + public static function getAllTitle ($customId) |
|
| 60 | + { |
|
| 52 | 61 | $result = parent::getDb ()->prepare('select name from custom_columns where id = ?'); |
| 53 | 62 | $result->execute (array ($customId)); |
| 54 | 63 | $post = $result->fetchObject (); |
| 55 | 64 | return $post->name; |
| 56 | 65 | } |
| 57 | 66 | |
| 58 | - public static function getCustomId ($lookup) { |
|
| 67 | + public static function getCustomId ($lookup) |
|
| 68 | + { |
|
| 59 | 69 | $result = parent::getDb ()->prepare('select id from custom_columns where label = ?'); |
| 60 | 70 | $result->execute (array ($lookup)); |
| 61 | 71 | if ($post = $result->fetchObject ()) { |
@@ -64,7 +74,8 @@ discard block |
||
| 64 | 74 | return NULL; |
| 65 | 75 | } |
| 66 | 76 | |
| 67 | - public static function getCount($customId) { |
|
| 77 | + public static function getCount($customId) |
|
| 78 | + { |
|
| 68 | 79 | $nCustoms = parent::executeQuerySingle ('select count(*) from ' . self::getTableName ($customId)); |
| 69 | 80 | $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), |
| 70 | 81 | str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", |
@@ -72,7 +83,8 @@ discard block |
||
| 72 | 83 | return $entry; |
| 73 | 84 | } |
| 74 | 85 | |
| 75 | - public static function getCustomById ($customId, $id) { |
|
| 86 | + public static function getCustomById ($customId, $id) |
|
| 87 | + { |
|
| 76 | 88 | $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?'); |
| 77 | 89 | $result->execute (array ($id)); |
| 78 | 90 | if ($post = $result->fetchObject ()) { |
@@ -81,15 +93,15 @@ discard block |
||
| 81 | 93 | return NULL; |
| 82 | 94 | } |
| 83 | 95 | |
| 84 | - public static function getAllCustoms($customId) { |
|
| 96 | + public static function getAllCustoms($customId) |
|
| 97 | + { |
|
| 85 | 98 | $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count |
| 86 | 99 | from {0}, {1} |
| 87 | 100 | where {0}.id = {1}.{2} |
| 88 | 101 | group by {0}.id, {0}.value |
| 89 | 102 | order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($customId), self::getTableLinkColumn ($customId))); |
| 90 | 103 | $entryArray = array(); |
| 91 | - while ($post = $result->fetchObject ()) |
|
| 92 | - { |
|
| 104 | + while ($post = $result->fetchObject ()) { |
|
| 93 | 105 | $customColumn = new CustomColumn ($post->id, $post->name, $customId); |
| 94 | 106 | array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), |
| 95 | 107 | str_format (localize("bookword", $post->count), $post->count), "text", |
@@ -76,7 +76,8 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function __construct($pid, $pquery, $pn) { |
|
| 79 | + public function __construct($pid, $pquery, $pn) |
|
| 80 | + { |
|
| 80 | 81 | global $config; |
| 81 | 82 | |
| 82 | 83 | $this->idGet = $pid; |
@@ -109,23 +110,33 @@ discard block |
||
| 109 | 110 | } |
| 110 | 111 | if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) { |
| 111 | 112 | $series = Serie::getCount(); |
| 112 | - if (!is_null ($series)) array_push ($this->entryArray, $series); |
|
| 113 | + if (!is_null ($series)) { |
|
| 114 | + array_push ($this->entryArray, $series); |
|
| 115 | + } |
|
| 113 | 116 | } |
| 114 | 117 | if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) { |
| 115 | 118 | $publisher = Publisher::getCount(); |
| 116 | - if (!is_null ($publisher)) array_push ($this->entryArray, $publisher); |
|
| 119 | + if (!is_null ($publisher)) { |
|
| 120 | + array_push ($this->entryArray, $publisher); |
|
| 121 | + } |
|
| 117 | 122 | } |
| 118 | 123 | if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) { |
| 119 | 124 | $tags = Tag::getCount(); |
| 120 | - if (!is_null ($tags)) array_push ($this->entryArray, $tags); |
|
| 125 | + if (!is_null ($tags)) { |
|
| 126 | + array_push ($this->entryArray, $tags); |
|
| 127 | + } |
|
| 121 | 128 | } |
| 122 | 129 | if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) { |
| 123 | 130 | $rating = Rating::getCount(); |
| 124 | - if (!is_null ($rating)) array_push ($this->entryArray, $rating); |
|
| 131 | + if (!is_null ($rating)) { |
|
| 132 | + array_push ($this->entryArray, $rating); |
|
| 133 | + } |
|
| 125 | 134 | } |
| 126 | 135 | if (!in_array ("language", getCurrentOption ('ignored_categories'))) { |
| 127 | 136 | $languages = Language::getCount(); |
| 128 | - if (!is_null ($languages)) array_push ($this->entryArray, $languages); |
|
| 137 | + if (!is_null ($languages)) { |
|
| 138 | + array_push ($this->entryArray, $languages); |
|
| 139 | + } |
|
| 129 | 140 | } |
| 130 | 141 | foreach ($config['cops_calibre_custom_column'] as $lookup) { |
| 131 | 142 | $customId = CustomColumn::getCustomId ($lookup); |
@@ -135,7 +146,9 @@ discard block |
||
| 135 | 146 | } |
| 136 | 147 | $this->entryArray = array_merge ($this->entryArray, Book::getCount()); |
| 137 | 148 | |
| 138 | - if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName (); |
|
| 149 | + if (Base::isMultipleDatabaseEnabled ()) { |
|
| 150 | + $this->title = Base::getDbName (); |
|
| 151 | + } |
|
| 139 | 152 | } |
| 140 | 153 | } |
| 141 | 154 | |
@@ -171,8 +184,12 @@ discard block |
||
| 171 | 184 | |
| 172 | 185 | public function containsBook () |
| 173 | 186 | { |
| 174 | - if (count ($this->entryArray) == 0) return false; |
|
| 175 | - if (get_class ($this->entryArray [0]) == "EntryBook") return true; |
|
| 187 | + if (count ($this->entryArray) == 0) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + if (get_class ($this->entryArray [0]) == "EntryBook") { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 176 | 193 | return false; |
| 177 | 194 | } |
| 178 | 195 | } |
@@ -55,7 +55,8 @@ discard block |
||
| 55 | 55 | 'zip' => 'application/zip' |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - public function __construct($post, $book = null) { |
|
| 58 | + public function __construct($post, $book = null) |
|
| 59 | + { |
|
| 59 | 60 | $this->id = $post->id; |
| 60 | 61 | $this->name = $post->name; |
| 61 | 62 | $this->format = $post->format; |
@@ -64,19 +65,20 @@ discard block |
||
| 64 | 65 | $this->book = $book; |
| 65 | 66 | } |
| 66 | 67 | |
| 67 | - public function isKnownType () { |
|
| 68 | + public function isKnownType () |
|
| 69 | + { |
|
| 68 | 70 | return array_key_exists ($this->extension, self::$mimetypes); |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | - public function getMimeType () { |
|
| 73 | + public function getMimeType () |
|
| 74 | + { |
|
| 72 | 75 | $result = "application/octet-stream"; |
| 73 | 76 | if ($this->isKnownType ()) { |
| 74 | 77 | return self::$mimetypes [$this->extension]; |
| 75 | 78 | } elseif (function_exists('finfo_open') === true) { |
| 76 | 79 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 77 | 80 | |
| 78 | - if (is_resource($finfo) === true) |
|
| 79 | - { |
|
| 81 | + if (is_resource($finfo) === true) { |
|
| 80 | 82 | $result = finfo_file($finfo, $this->getLocalPath ()); |
| 81 | 83 | } |
| 82 | 84 | |
@@ -86,27 +88,33 @@ discard block |
||
| 86 | 88 | return $result; |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | - public function isEpubValidOnKobo () { |
|
| 91 | + public function isEpubValidOnKobo () |
|
| 92 | + { |
|
| 90 | 93 | return $this->format == "EPUB" || $this->format == "KEPUB"; |
| 91 | 94 | } |
| 92 | 95 | |
| 93 | - public function getFilename () { |
|
| 96 | + public function getFilename () |
|
| 97 | + { |
|
| 94 | 98 | return $this->name . "." . strtolower ($this->format); |
| 95 | 99 | } |
| 96 | 100 | |
| 97 | - public function getUpdatedFilename () { |
|
| 101 | + public function getUpdatedFilename () |
|
| 102 | + { |
|
| 98 | 103 | return $this->book->getAuthorsSort () . " - " . $this->book->title; |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | - public function getUpdatedFilenameEpub () { |
|
| 106 | + public function getUpdatedFilenameEpub () |
|
| 107 | + { |
|
| 102 | 108 | return $this->getUpdatedFilename () . ".epub"; |
| 103 | 109 | } |
| 104 | 110 | |
| 105 | - public function getUpdatedFilenameKepub () { |
|
| 111 | + public function getUpdatedFilenameKepub () |
|
| 112 | + { |
|
| 106 | 113 | return $this->getUpdatedFilename () . ".kepub.epub"; |
| 107 | 114 | } |
| 108 | 115 | |
| 109 | - public function getDataLink ($rel, $title = NULL) { |
|
| 116 | + public function getDataLink ($rel, $title = NULL) |
|
| 117 | + { |
|
| 110 | 118 | global $config; |
| 111 | 119 | |
| 112 | 120 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
@@ -116,19 +124,24 @@ discard block |
||
| 116 | 124 | return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); |
| 117 | 125 | } |
| 118 | 126 | |
| 119 | - public function getHtmlLink () { |
|
| 127 | + public function getHtmlLink () |
|
| 128 | + { |
|
| 120 | 129 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
| 121 | 130 | } |
| 122 | 131 | |
| 123 | - public function getLocalPath () { |
|
| 132 | + public function getLocalPath () |
|
| 133 | + { |
|
| 124 | 134 | return $this->book->path . "/" . $this->getFilename (); |
| 125 | 135 | } |
| 126 | 136 | |
| 127 | - public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 137 | + public function getHtmlLinkWithRewriting ($title = NULL) |
|
| 138 | + { |
|
| 128 | 139 | global $config; |
| 129 | 140 | |
| 130 | 141 | $database = ""; |
| 131 | - if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/"; |
|
| 142 | + if (!is_null (GetUrlParam (DB))) { |
|
| 143 | + $database = GetUrlParam (DB) . "/"; |
|
| 144 | + } |
|
| 132 | 145 | |
| 133 | 146 | $href = "download/" . $this->id . "/" . $database; |
| 134 | 147 | |
@@ -142,28 +155,27 @@ discard block |
||
| 142 | 155 | return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
| 143 | 156 | } |
| 144 | 157 | |
| 145 | - public static function getDataByBook ($book) { |
|
| 158 | + public static function getDataByBook ($book) |
|
| 159 | + { |
|
| 146 | 160 | $out = array (); |
| 147 | 161 | $result = parent::getDb ()->prepare('select id, format, name |
| 148 | 162 | from data where book = ?'); |
| 149 | 163 | $result->execute (array ($book->id)); |
| 150 | 164 | |
| 151 | - while ($post = $result->fetchObject ()) |
|
| 152 | - { |
|
| 165 | + while ($post = $result->fetchObject ()) { |
|
| 153 | 166 | array_push ($out, new Data ($post, $book)); |
| 154 | 167 | } |
| 155 | 168 | return $out; |
| 156 | 169 | } |
| 157 | 170 | |
| 158 | - public static function handleThumbnailLink ($urlParam, $height) { |
|
| 171 | + public static function handleThumbnailLink ($urlParam, $height) |
|
| 172 | + { |
|
| 159 | 173 | global $config; |
| 160 | 174 | |
| 161 | 175 | if (is_null ($height)) { |
| 162 | 176 | if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
| 163 | 177 | $height = $config['cops_opds_thumbnail_height']; |
| 164 | - } |
|
| 165 | - else |
|
| 166 | - { |
|
| 178 | + } else { |
|
| 167 | 179 | $height = $config['cops_html_thumbnail_height']; |
| 168 | 180 | } |
| 169 | 181 | } |
@@ -182,14 +194,17 @@ discard block |
||
| 182 | 194 | |
| 183 | 195 | if (Base::useAbsolutePath () || |
| 184 | 196 | $rel == Link::OPDS_THUMBNAIL_TYPE || |
| 185 | - ($type == "epub" && $config['cops_update_epub-metadata'])) |
|
| 186 | - { |
|
| 187 | - if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type); |
|
| 197 | + ($type == "epub" && $config['cops_update_epub-metadata'])) { |
|
| 198 | + if ($type != "jpg") { |
|
| 199 | + $urlParam = addURLParameter($urlParam, "type", $type); |
|
| 200 | + } |
|
| 188 | 201 | if ($rel == Link::OPDS_THUMBNAIL_TYPE) { |
| 189 | 202 | $urlParam = self::handleThumbnailLink($urlParam, $height); |
| 190 | 203 | } |
| 191 | 204 | $urlParam = addURLParameter($urlParam, "id", $book->id); |
| 192 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 205 | + if (!is_null (GetUrlParam (DB))) { |
|
| 206 | + $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 207 | + } |
|
| 193 | 208 | if ($config['cops_thumbnail_handling'] != "1" && |
| 194 | 209 | !empty ($config['cops_thumbnail_handling']) && |
| 195 | 210 | $rel == Link::OPDS_THUMBNAIL_TYPE) { |
@@ -197,9 +212,7 @@ discard block |
||
| 197 | 212 | } else { |
| 198 | 213 | return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); |
| 199 | 214 | } |
| 200 | - } |
|
| 201 | - else |
|
| 202 | - { |
|
| 215 | + } else { |
|
| 203 | 216 | return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title); |
| 204 | 217 | } |
| 205 | 218 | } |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | $this->idPage = Book::getEntryIdByLetter ($this->idGet); |
| 15 | 15 | |
| 16 | 16 | $count = $this->totalNumber; |
| 17 | - if ($count == -1) |
|
| 18 | - $count = count ($this->entryArray); |
|
| 17 | + if ($count == -1) { |
|
| 18 | + $count = count ($this->entryArray); |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet); |
| 21 | 22 | } |