@@ -60,6 +60,9 @@ discard block |
||
| 60 | 60 | $_SERVER['REDIRECT_STATUS'] = 404; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | +/** |
|
| 64 | + * @param string $name |
|
| 65 | + */ |
|
| 63 | 66 | function getURLParam ($name, $default = NULL) { |
| 64 | 67 | if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") { |
| 65 | 68 | return $_GET[$name]; |
@@ -95,6 +98,11 @@ discard block |
||
| 95 | 98 | return $url . "?v=" . VERSION; |
| 96 | 99 | } |
| 97 | 100 | |
| 101 | +/** |
|
| 102 | + * @param string $xml |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 98 | 106 | function xml2xhtml($xml) { |
| 99 | 107 | return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', ' |
| 100 | 108 | $xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param"); |
@@ -308,6 +316,9 @@ discard block |
||
| 308 | 316 | return $phrase; |
| 309 | 317 | } |
| 310 | 318 | |
| 319 | +/** |
|
| 320 | + * @param string $paramName |
|
| 321 | + */ |
|
| 311 | 322 | function addURLParameter($urlParams, $paramName, $paramValue) { |
| 312 | 323 | if (empty ($urlParams)) { |
| 313 | 324 | $urlParams = ""; |
@@ -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,16 +350,19 @@ 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 | } |
@@ -84,6 +84,9 @@ discard block |
||
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 87 | 90 | public static function getDbDirectory ($database = NULL) { |
| 88 | 91 | global $config; |
| 89 | 92 | if (self::isMultipleDatabaseEnabled ()) { |
@@ -143,10 +146,18 @@ discard block |
||
| 143 | 146 | self::$db = NULL; |
| 144 | 147 | } |
| 145 | 148 | |
| 149 | + /** |
|
| 150 | + * @param string $query |
|
| 151 | + */ |
|
| 146 | 152 | public static function executeQuerySingle ($query, $database = NULL) { |
| 147 | 153 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 148 | 154 | } |
| 149 | 155 | |
| 156 | + /** |
|
| 157 | + * @param string $table |
|
| 158 | + * @param string $id |
|
| 159 | + * @param string $numberOfString |
|
| 160 | + */ |
|
| 150 | 161 | public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
| 151 | 162 | if (!$numberOfString) { |
| 152 | 163 | $numberOfString = $table . ".alphabetical"; |
@@ -159,6 +170,10 @@ discard block |
||
| 159 | 170 | return $entry; |
| 160 | 171 | } |
| 161 | 172 | |
| 173 | + /** |
|
| 174 | + * @param string $columns |
|
| 175 | + * @param string $category |
|
| 176 | + */ |
|
| 162 | 177 | public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
| 163 | 178 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 164 | 179 | $entryArray = array(); |
@@ -177,6 +192,9 @@ discard block |
||
| 177 | 192 | return $entryArray; |
| 178 | 193 | } |
| 179 | 194 | |
| 195 | + /** |
|
| 196 | + * @param string $filter |
|
| 197 | + */ |
|
| 180 | 198 | public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
| 181 | 199 | $totalResult = -1; |
| 182 | 200 | |
@@ -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 | return 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 | return 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,31 +154,36 @@ 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 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 164 | 185 | $entryArray = array(); |
| 165 | - while ($post = $result->fetchObject ()) |
|
| 166 | - { |
|
| 186 | + while ($post = $result->fetchObject ()) { |
|
| 167 | 187 | $instance = new $category ($post); |
| 168 | 188 | if (property_exists($post, "sort")) { |
| 169 | 189 | $title = $post->sort; |
@@ -177,7 +197,8 @@ discard block |
||
| 177 | 197 | return $entryArray; |
| 178 | 198 | } |
| 179 | 199 | |
| 180 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 200 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 201 | + { |
|
| 181 | 202 | $totalResult = -1; |
| 182 | 203 | |
| 183 | 204 | if (useNormAndUp ()) { |
@@ -189,8 +210,7 @@ discard block |
||
| 189 | 210 | $numberPerPage = getCurrentOption ("max_item_per_page"); |
| 190 | 211 | } |
| 191 | 212 | |
| 192 | - if ($numberPerPage != -1 && $n != -1) |
|
| 193 | - { |
|
| 213 | + if ($numberPerPage != -1 && $n != -1) { |
|
| 194 | 214 | // First check total number of results |
| 195 | 215 | $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
| 196 | 216 | $result->execute ($params); |
@@ -8,6 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkFacet extends Link |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $phref |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
| 12 | 15 | parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
| 13 | 16 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
@@ -8,9 +8,12 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkFacet extends Link |
| 10 | 10 | { |
| 11 | - public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
|
| 11 | + public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) |
|
| 12 | + { |
|
| 12 | 13 | parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
| 13 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 14 | + if (!is_null (GetUrlParam (DB))) { |
|
| 15 | + $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 16 | + } |
|
| 14 | 17 | $this->href = parent::getScriptName() . $this->href; |
| 15 | 18 | } |
| 16 | 19 | } |
@@ -8,6 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $prel |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
| 12 | 15 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 13 | 16 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
@@ -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 { |
@@ -8,6 +8,9 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class PageCustomize extends Page |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $key |
|
| 13 | + */ |
|
| 11 | 14 | private function isChecked ($key, $testedValue = 1) { |
| 12 | 15 | $value = getCurrentOption ($key); |
| 13 | 16 | if (is_array ($value)) { |
@@ -22,6 +25,9 @@ discard block |
||
| 22 | 25 | return ""; |
| 23 | 26 | } |
| 24 | 27 | |
| 28 | + /** |
|
| 29 | + * @param string $key |
|
| 30 | + */ |
|
| 25 | 31 | private function isSelected ($key, $value) { |
| 26 | 32 | if (getCurrentOption ($key) == $value) { |
| 27 | 33 | return "selected='selected'"; |
@@ -8,7 +8,8 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class PageCustomize extends Page |
| 10 | 10 | { |
| 11 | - private function isChecked ($key, $testedValue = 1) { |
|
| 11 | + private function isChecked ($key, $testedValue = 1) |
|
| 12 | + { |
|
| 12 | 13 | $value = getCurrentOption ($key); |
| 13 | 14 | if (is_array ($value)) { |
| 14 | 15 | if (in_array ($testedValue, $value)) { |
@@ -22,14 +23,16 @@ discard block |
||
| 22 | 23 | return ""; |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | - private function isSelected ($key, $value) { |
|
| 26 | + private function isSelected ($key, $value) |
|
| 27 | + { |
|
| 26 | 28 | if (getCurrentOption ($key) == $value) { |
| 27 | 29 | return "selected='selected'"; |
| 28 | 30 | } |
| 29 | 31 | return ""; |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | - private function getStyleList () { |
|
| 34 | + private function getStyleList () |
|
| 35 | + { |
|
| 33 | 36 | $result = array (); |
| 34 | 37 | foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) { |
| 35 | 38 | if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { |
@@ -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 | } |