@@ -37,23 +37,27 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private static $db = NULL; |
| 39 | 39 | |
| 40 | - public static function isMultipleDatabaseEnabled () { |
|
| 40 | + public static function isMultipleDatabaseEnabled () |
|
| 41 | + { |
|
| 41 | 42 | global $config; |
| 42 | 43 | return is_array ($config['calibre_directory']); |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - public static function useAbsolutePath () { |
|
| 46 | + public static function useAbsolutePath () |
|
| 47 | + { |
|
| 46 | 48 | global $config; |
| 47 | 49 | $path = self::getDbDirectory(); |
| 48 | 50 | return preg_match ('/^\//', $path) || // Linux / |
| 49 | 51 | preg_match ('/^\w\:/', $path); // Windows X: |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - public static function noDatabaseSelected () { |
|
| 54 | + public static function noDatabaseSelected () |
|
| 55 | + { |
|
| 53 | 56 | return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
| 54 | 57 | } |
| 55 | 58 | |
| 56 | - public static function getDbList () { |
|
| 59 | + public static function getDbList () |
|
| 60 | + { |
|
| 57 | 61 | global $config; |
| 58 | 62 | if (self::isMultipleDatabaseEnabled ()) { |
| 59 | 63 | return $config['calibre_directory']; |
@@ -62,7 +66,8 @@ discard block |
||
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - public static function getDbNameList () { |
|
| 69 | + public static function getDbNameList () |
|
| 70 | + { |
|
| 66 | 71 | global $config; |
| 67 | 72 | if (self::isMultipleDatabaseEnabled ()) { |
| 68 | 73 | return array_keys ($config['calibre_directory']); |
@@ -71,10 +76,13 @@ discard block |
||
| 71 | 76 | } |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 79 | + public static function getDbName ($database = NULL) |
|
| 80 | + { |
|
| 75 | 81 | global $config; |
| 76 | 82 | if (self::isMultipleDatabaseEnabled ()) { |
| 77 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 83 | + if (is_null ($database)) { |
|
| 84 | + $database = GetUrlParam (DB, 0); |
|
| 85 | + } |
|
| 78 | 86 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 79 | 87 | self::error ($database); |
| 80 | 88 | } |
@@ -84,10 +92,13 @@ discard block |
||
| 84 | 92 | return ""; |
| 85 | 93 | } |
| 86 | 94 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 95 | + public static function getDbDirectory ($database = NULL) |
|
| 96 | + { |
|
| 88 | 97 | global $config; |
| 89 | 98 | if (self::isMultipleDatabaseEnabled ()) { |
| 90 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 99 | + if (is_null ($database)) { |
|
| 100 | + $database = GetUrlParam (DB, 0); |
|
| 101 | + } |
|
| 91 | 102 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 92 | 103 | self::error ($database); |
| 93 | 104 | } |
@@ -98,18 +109,21 @@ discard block |
||
| 98 | 109 | } |
| 99 | 110 | |
| 100 | 111 | |
| 101 | - public static function getDbFileName ($database = NULL) { |
|
| 112 | + public static function getDbFileName ($database = NULL) |
|
| 113 | + { |
|
| 102 | 114 | return self::getDbDirectory ($database) .'metadata.db'; |
| 103 | 115 | } |
| 104 | 116 | |
| 105 | - private static function error ($database) { |
|
| 117 | + private static function error ($database) |
|
| 118 | + { |
|
| 106 | 119 | if (php_sapi_name() != "cli") { |
| 107 | 120 | header("location: checkconfig.php?err=1"); |
| 108 | 121 | } |
| 109 | 122 | throw new Exception("Database <{$database}> not found."); |
| 110 | 123 | } |
| 111 | 124 | |
| 112 | - public static function getDb ($database = NULL) { |
|
| 125 | + public static function getDb ($database = NULL) |
|
| 126 | + { |
|
| 113 | 127 | if (is_null (self::$db)) { |
| 114 | 128 | try { |
| 115 | 129 | if (is_readable (self::getDbFileName ($database))) { |
@@ -127,7 +141,8 @@ discard block |
||
| 127 | 141 | return self::$db; |
| 128 | 142 | } |
| 129 | 143 | |
| 130 | - public static function checkDatabaseAvailability () { |
|
| 144 | + public static function checkDatabaseAvailability () |
|
| 145 | + { |
|
| 131 | 146 | if (self::noDatabaseSelected ()) { |
| 132 | 147 | for ($i = 0; $i < count (self::getDbList ()); $i++) { |
| 133 | 148 | self::getDb ($i); |
@@ -139,33 +154,38 @@ discard block |
||
| 139 | 154 | return true; |
| 140 | 155 | } |
| 141 | 156 | |
| 142 | - public static function clearDb () { |
|
| 157 | + public static function clearDb () |
|
| 158 | + { |
|
| 143 | 159 | self::$db = NULL; |
| 144 | 160 | } |
| 145 | 161 | |
| 146 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 162 | + public static function executeQuerySingle ($query, $database = NULL) |
|
| 163 | + { |
|
| 147 | 164 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 148 | 165 | } |
| 149 | 166 | |
| 150 | - public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
|
| 167 | + public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) |
|
| 168 | + { |
|
| 151 | 169 | if (!$numberOfString) { |
| 152 | 170 | $numberOfString = $table . ".alphabetical"; |
| 153 | 171 | } |
| 154 | 172 | $count = self::executeQuerySingle ('select count(*) from ' . $table); |
| 155 | - if ($count == 0) return NULL; |
|
| 173 | + if ($count == 0) { |
|
| 174 | + return NULL; |
|
| 175 | + } |
|
| 156 | 176 | $entry = new Entry (localize($table . ".title"), $id, |
| 157 | 177 | str_format (localize($numberOfString, $count), $count), "text", |
| 158 | 178 | array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
| 159 | 179 | return $entry; |
| 160 | 180 | } |
| 161 | 181 | |
| 162 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 182 | + public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) |
|
| 183 | + { |
|
| 163 | 184 | /* @var $result PDOStatement */ |
| 164 | 185 | |
| 165 | 186 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 166 | 187 | $entryArray = array(); |
| 167 | - while ($post = $result->fetchObject ()) |
|
| 168 | - { |
|
| 188 | + while ($post = $result->fetchObject ()) { |
|
| 169 | 189 | /* @var $instance Author|Tag|Serie|Publisher */ |
| 170 | 190 | |
| 171 | 191 | $instance = new $category ($post); |
@@ -181,7 +201,8 @@ discard block |
||
| 181 | 201 | return $entryArray; |
| 182 | 202 | } |
| 183 | 203 | |
| 184 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 204 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 205 | + { |
|
| 185 | 206 | $totalResult = -1; |
| 186 | 207 | |
| 187 | 208 | if (useNormAndUp ()) { |
@@ -193,8 +214,7 @@ discard block |
||
| 193 | 214 | $numberPerPage = getCurrentOption ("max_item_per_page"); |
| 194 | 215 | } |
| 195 | 216 | |
| 196 | - if ($numberPerPage != -1 && $n != -1) |
|
| 197 | - { |
|
| 217 | + if ($numberPerPage != -1 && $n != -1) { |
|
| 198 | 218 | // First check total number of results |
| 199 | 219 | $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
| 200 | 220 | $result->execute ($params); |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | public $facetGroup; |
| 22 | 22 | public $activeFacet; |
| 23 | 23 | |
| 24 | - public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
|
| 24 | + public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) |
|
| 25 | + { |
|
| 25 | 26 | $this->href = $phref; |
| 26 | 27 | $this->type = $ptype; |
| 27 | 28 | $this->rel = $prel; |
@@ -30,11 +31,13 @@ discard block |
||
| 30 | 31 | $this->activeFacet = $pactiveFacet; |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | - public function hrefXhtml () { |
|
| 34 | + public function hrefXhtml () |
|
| 35 | + { |
|
| 34 | 36 | return $this->href; |
| 35 | 37 | } |
| 36 | 38 | |
| 37 | - public function getScriptName() { |
|
| 39 | + public function getScriptName() |
|
| 40 | + { |
|
| 38 | 41 | $parts = explode('/', $_SERVER["SCRIPT_NAME"]); |
| 39 | 42 | return $parts[count($parts) - 1]; |
| 40 | 43 | } |
@@ -78,7 +78,8 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function __construct($pid, $pquery, $pn) { |
|
| 81 | + public function __construct($pid, $pquery, $pn) |
|
| 82 | + { |
|
| 82 | 83 | global $config; |
| 83 | 84 | |
| 84 | 85 | $this->idGet = $pid; |
@@ -111,23 +112,33 @@ discard block |
||
| 111 | 112 | } |
| 112 | 113 | if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) { |
| 113 | 114 | $series = Serie::getCount(); |
| 114 | - if (!is_null ($series)) array_push ($this->entryArray, $series); |
|
| 115 | + if (!is_null ($series)) { |
|
| 116 | + array_push ($this->entryArray, $series); |
|
| 117 | + } |
|
| 115 | 118 | } |
| 116 | 119 | if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) { |
| 117 | 120 | $publisher = Publisher::getCount(); |
| 118 | - if (!is_null ($publisher)) array_push ($this->entryArray, $publisher); |
|
| 121 | + if (!is_null ($publisher)) { |
|
| 122 | + array_push ($this->entryArray, $publisher); |
|
| 123 | + } |
|
| 119 | 124 | } |
| 120 | 125 | if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) { |
| 121 | 126 | $tags = Tag::getCount(); |
| 122 | - if (!is_null ($tags)) array_push ($this->entryArray, $tags); |
|
| 127 | + if (!is_null ($tags)) { |
|
| 128 | + array_push ($this->entryArray, $tags); |
|
| 129 | + } |
|
| 123 | 130 | } |
| 124 | 131 | if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) { |
| 125 | 132 | $rating = Rating::getCount(); |
| 126 | - if (!is_null ($rating)) array_push ($this->entryArray, $rating); |
|
| 133 | + if (!is_null ($rating)) { |
|
| 134 | + array_push ($this->entryArray, $rating); |
|
| 135 | + } |
|
| 127 | 136 | } |
| 128 | 137 | if (!in_array ("language", getCurrentOption ('ignored_categories'))) { |
| 129 | 138 | $languages = Language::getCount(); |
| 130 | - if (!is_null ($languages)) array_push ($this->entryArray, $languages); |
|
| 139 | + if (!is_null ($languages)) { |
|
| 140 | + array_push ($this->entryArray, $languages); |
|
| 141 | + } |
|
| 131 | 142 | } |
| 132 | 143 | foreach ($config['cops_calibre_custom_column'] as $lookup) { |
| 133 | 144 | $customColumn = CustomColumnType::createByLookup($lookup); |
@@ -137,7 +148,9 @@ discard block |
||
| 137 | 148 | } |
| 138 | 149 | $this->entryArray = array_merge ($this->entryArray, Book::getCount()); |
| 139 | 150 | |
| 140 | - if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName (); |
|
| 151 | + if (Base::isMultipleDatabaseEnabled ()) { |
|
| 152 | + $this->title = Base::getDbName (); |
|
| 153 | + } |
|
| 141 | 154 | } |
| 142 | 155 | } |
| 143 | 156 | |
@@ -173,8 +186,12 @@ discard block |
||
| 173 | 186 | |
| 174 | 187 | public function containsBook () |
| 175 | 188 | { |
| 176 | - if (count ($this->entryArray) == 0) return false; |
|
| 177 | - if (get_class ($this->entryArray [0]) == "EntryBook") return true; |
|
| 189 | + if (count ($this->entryArray) == 0) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + if (get_class ($this->entryArray [0]) == "EntryBook") { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 178 | 195 | return false; |
| 179 | 196 | } |
| 180 | 197 | } |
@@ -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 | } |
@@ -8,10 +8,15 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | - public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
|
| 11 | + public function __construct($phref, $prel = NULL, $ptitle = NULL) |
|
| 12 | + { |
|
| 12 | 13 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 13 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 14 | - if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
|
| 14 | + if (!is_null (GetUrlParam (DB))) { |
|
| 15 | + $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 16 | + } |
|
| 17 | + if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) { |
|
| 18 | + $this->href = "?" . $this->href; |
|
| 19 | + } |
|
| 15 | 20 | if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
| 16 | 21 | $this->href = "index.php" . $this->href; |
| 17 | 22 | } else { |
@@ -31,7 +31,8 @@ discard block |
||
| 31 | 31 | Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png' |
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - public function getUpdatedTime () { |
|
| 34 | + public function getUpdatedTime () |
|
| 35 | + { |
|
| 35 | 36 | if (!is_null ($this->localUpdated)) { |
| 36 | 37 | return date (DATE_ATOM, $this->localUpdated); |
| 37 | 38 | } |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | return date (DATE_ATOM, self::$updated); |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | - public function getNavLink () { |
|
| 45 | + public function getNavLink () |
|
| 46 | + { |
|
| 45 | 47 | foreach ($this->linkArray as $link) { |
| 46 | 48 | /* @var $link LinkNavigation */ |
| 47 | 49 | |
@@ -52,7 +54,8 @@ discard block |
||
| 52 | 54 | return "#"; |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | - public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) { |
|
| 57 | + public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) |
|
| 58 | + { |
|
| 56 | 59 | global $config; |
| 57 | 60 | $this->title = $ptitle; |
| 58 | 61 | $this->id = $pid; |
@@ -62,10 +65,8 @@ discard block |
||
| 62 | 65 | $this->className = $pclass; |
| 63 | 66 | $this->numberOfElement = $pcount; |
| 64 | 67 | |
| 65 | - if ($config['cops_show_icons'] == 1) |
|
| 66 | - { |
|
| 67 | - foreach (self::$icons as $reg => $image) |
|
| 68 | - { |
|
| 68 | + if ($config['cops_show_icons'] == 1) { |
|
| 69 | + foreach (self::$icons as $reg => $image) { |
|
| 69 | 70 | if (preg_match ("/" . $reg . "/", $pid)) { |
| 70 | 71 | array_push ($this->linkArray, new Link (getUrlWithVersion ($image), "image/png", Link::OPDS_THUMBNAIL_TYPE)); |
| 71 | 72 | break; |
@@ -73,6 +74,8 @@ discard block |
||
| 73 | 74 | } |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | - if (!is_null (GetUrlParam (DB))) $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id); |
|
| 77 | + if (!is_null (GetUrlParam (DB))) { |
|
| 78 | + $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id); |
|
| 79 | + } |
|
| 77 | 80 | } |
| 78 | 81 | } |
@@ -149,7 +149,9 @@ discard block |
||
| 149 | 149 | $errors = libxml_get_errors(); |
| 150 | 150 | |
| 151 | 151 | foreach ($errors as $error) { |
| 152 | - if ($error->code == 801) return false; |
|
| 152 | + if ($error->code == 801) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 153 | 155 | } |
| 154 | 156 | return true; |
| 155 | 157 | } |
@@ -175,7 +177,9 @@ discard block |
||
| 175 | 177 | } |
| 176 | 178 | */ |
| 177 | 179 | |
| 178 | - if (!are_libxml_errors_ok ()) $output = 'HTML code not valid.'; |
|
| 180 | + if (!are_libxml_errors_ok ()) { |
|
| 181 | + $output = 'HTML code not valid.'; |
|
| 182 | + } |
|
| 179 | 183 | |
| 180 | 184 | libxml_use_internal_errors(false); |
| 181 | 185 | return $output; |
@@ -235,7 +239,9 @@ discard block |
||
| 235 | 239 | |
| 236 | 240 | // set default to 1 for any without q factor |
| 237 | 241 | foreach ($langs as $lang => $val) { |
| 238 | - if ($val === '') $langs[$lang] = 1; |
|
| 242 | + if ($val === '') { |
|
| 243 | + $langs[$lang] = 1; |
|
| 244 | + } |
|
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // sort list based on value |
@@ -257,8 +263,7 @@ discard block |
||
| 257 | 263 | $lang = 'en'; |
| 258 | 264 | if (!empty($config['cops_language'])) { |
| 259 | 265 | $lang = $config['cops_language']; |
| 260 | - } |
|
| 261 | - elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 266 | + } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 262 | 267 | $langs = getAcceptLanguages(); |
| 263 | 268 | } |
| 264 | 269 | //echo var_dump($langs); |
@@ -284,12 +289,15 @@ discard block |
||
| 284 | 289 | function localize($phrase, $count=-1, $reset=false) |
| 285 | 290 | { |
| 286 | 291 | global $config; |
| 287 | - if ($count == 0) |
|
| 288 | - $phrase .= '.none'; |
|
| 289 | - if ($count == 1) |
|
| 290 | - $phrase .= '.one'; |
|
| 291 | - if ($count > 1) |
|
| 292 | - $phrase .= '.many'; |
|
| 292 | + if ($count == 0) { |
|
| 293 | + $phrase .= '.none'; |
|
| 294 | + } |
|
| 295 | + if ($count == 1) { |
|
| 296 | + $phrase .= '.one'; |
|
| 297 | + } |
|
| 298 | + if ($count > 1) { |
|
| 299 | + $phrase .= '.many'; |
|
| 300 | + } |
|
| 293 | 301 | |
| 294 | 302 | /* Static keyword is used to ensure the file is loaded only once */ |
| 295 | 303 | static $translations = NULL; |
@@ -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'; |
@@ -237,8 +237,7 @@ |
||
| 237 | 237 | $db = new PDO('sqlite:' . Base::getDbFileName($i)); |
| 238 | 238 | $result = $db->prepare('select books.path || "/" || data.name || "." || lower (format) as fullpath from data join books on data.book = books.id'); |
| 239 | 239 | $result->execute(); |
| 240 | - while ($post = $result->fetchObject()) |
|
| 241 | - { |
|
| 240 | + while ($post = $result->fetchObject()) { |
|
| 242 | 241 | if (!is_file (Base::getDbDirectory($i) . $post->fullpath)) { |
| 243 | 242 | echo '<p>' . Base::getDbDirectory($i) . $post->fullpath . '</p>'; |
| 244 | 243 | } |