@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | require_once ("config.php"); |
| 13 | 13 | require_once ("base.php"); |
| 14 | 14 | |
| 15 | - header ("Content-Type:text/html; charset=UTF-8"); |
|
| 15 | + header("Content-Type:text/html; charset=UTF-8"); |
|
| 16 | 16 | |
| 17 | - $err = getURLParam ("err", -1); |
|
| 18 | - $full = getURLParam ("full"); |
|
| 17 | + $err = getURLParam("err", -1); |
|
| 18 | + $full = getURLParam("full"); |
|
| 19 | 19 | $error = NULL; |
| 20 | 20 | switch ($err) { |
| 21 | 21 | case 1 : |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | <meta charset="utf-8"> |
| 29 | 29 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 30 | 30 | <title>COPS Configuration Check</title> |
| 31 | - <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" /> |
|
| 31 | + <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss()) ?>" media="screen" /> |
|
| 32 | 32 | </head> |
| 33 | 33 | <body> |
| 34 | 34 | <div class="container"> |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | <div id="content" style="display: none;"></div> |
| 41 | 41 | <section> |
| 42 | 42 | <?php |
| 43 | - if (!is_null ($error)) { |
|
| 43 | + if (!is_null($error)) { |
|
| 44 | 44 | ?> |
| 45 | 45 | <article class="frontpage"> |
| 46 | 46 | <h2>You've been redirected because COPS is not configured properly</h2> |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | <h2>Check if the rendering will be done on client side or server side</h2> |
| 154 | 154 | <h4> |
| 155 | 155 | <?php |
| 156 | - if (useServerSideRendering ()) { |
|
| 156 | + if (useServerSideRendering()) { |
|
| 157 | 157 | echo "Server side rendering"; |
| 158 | 158 | } else { |
| 159 | 159 | echo "Client side rendering"; |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | </article> |
| 164 | 164 | <?php |
| 165 | 165 | $i = 0; |
| 166 | -foreach (Base::getDbList () as $name => $database) { |
|
| 166 | +foreach (Base::getDbList() as $name => $database) { |
|
| 167 | 167 | ?> |
| 168 | 168 | <article class="frontpage"> |
| 169 | 169 | <h2>Check if Calibre database path is not an URL</h2> |
| 170 | 170 | <h4> |
| 171 | 171 | <?php |
| 172 | - if (!preg_match ("#^http#", $database)) { |
|
| 172 | + if (!preg_match("#^http#", $database)) { |
|
| 173 | 173 | echo "OK"; |
| 174 | 174 | } else { |
| 175 | 175 | echo "Calibre path has to be local (no URL allowed)"; |
@@ -181,10 +181,10 @@ discard block |
||
| 181 | 181 | <h2>Check if Calibre database file exists and is readable</h2> |
| 182 | 182 | <h4> |
| 183 | 183 | <?php |
| 184 | - if (is_readable (Base::getDbFileName ($i))) { |
|
| 184 | + if (is_readable(Base::getDbFileName($i))) { |
|
| 185 | 185 | echo "{$name} OK"; |
| 186 | 186 | } else { |
| 187 | - echo "{$name} File " . Base::getDbFileName ($i) . " not found, |
|
| 187 | + echo "{$name} File " . Base::getDbFileName($i) . " not found, |
|
| 188 | 188 | Please check |
| 189 | 189 | <ul> |
| 190 | 190 | <li>Value of \$config['calibre_directory'] in config_local.php</li> |
@@ -196,13 +196,13 @@ discard block |
||
| 196 | 196 | ?> |
| 197 | 197 | </h4> |
| 198 | 198 | </article> |
| 199 | - <?php if (is_readable (Base::getDbFileName ($i))) { ?> |
|
| 199 | + <?php if (is_readable(Base::getDbFileName($i))) { ?> |
|
| 200 | 200 | <article class="frontpage"> |
| 201 | 201 | <h2>Check if Calibre database file can be opened with PHP</h2> |
| 202 | 202 | <h4> |
| 203 | 203 | <?php |
| 204 | 204 | try { |
| 205 | - $db = new PDO('sqlite:'. Base::getDbFileName ($i)); |
|
| 205 | + $db = new PDO('sqlite:' . Base::getDbFileName($i)); |
|
| 206 | 206 | echo "{$name} OK"; |
| 207 | 207 | } catch (Exception $e) { |
| 208 | 208 | echo "{$name} If the file is readable, check your php configuration. Exception detail : " . $e; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | <h4> |
| 216 | 216 | <?php |
| 217 | 217 | try { |
| 218 | - $db = new PDO('sqlite:'. Base::getDbFileName ($i)); |
|
| 218 | + $db = new PDO('sqlite:' . Base::getDbFileName($i)); |
|
| 219 | 219 | $count = $db->query("select count(*) FROM sqlite_master WHERE type='table' AND name in ('books', 'authors', 'tags', 'series')")->fetchColumn(); |
| 220 | 220 | if ($count == 4) { |
| 221 | 221 | echo "{$name} OK"; |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | <h4> |
| 235 | 235 | <?php |
| 236 | 236 | try { |
| 237 | - $db = new PDO('sqlite:'. Base::getDbFileName ($i)); |
|
| 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 | - $result->execute (); |
|
| 240 | - while ($post = $result->fetchObject ()) |
|
| 239 | + $result->execute(); |
|
| 240 | + while ($post = $result->fetchObject()) |
|
| 241 | 241 | { |
| 242 | - if (!is_file (Base::getDbDirectory ($i) . $post->fullpath)) { |
|
| 243 | - echo "<p>" . Base::getDbDirectory ($i) . $post->fullpath . "</p>"; |
|
| 242 | + if (!is_file(Base::getDbDirectory($i) . $post->fullpath)) { |
|
| 243 | + echo "<p>" . Base::getDbDirectory($i) . $post->fullpath . "</p>"; |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | } catch (Exception $e) { |
@@ -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 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | $err = getURLParam ("err", -1); |
| 18 | 18 | $full = getURLParam ("full"); |
| 19 | - $error = NULL; |
|
| 19 | + $error = null; |
|
| 20 | 20 | switch ($err) { |
| 21 | 21 | case 1 : |
| 22 | 22 | $error = "Database error"; |
@@ -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 = ""; |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | // Generate the function for the template |
| 33 | 33 | $template = new doT (); |
| 34 | 34 | $dot = $template->template ($page, array ('bookdetail' => $bookdetail, |
| 35 | - 'header' => $header, |
|
| 36 | - 'footer' => $footer, |
|
| 37 | - 'main' => $main)); |
|
| 35 | + 'header' => $header, |
|
| 36 | + 'footer' => $footer, |
|
| 37 | + 'main' => $main)); |
|
| 38 | 38 | // If there is a syntax error in the function created |
| 39 | 39 | // $dot will be equal to FALSE |
| 40 | 40 | if (!$dot) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | case LIBXML_ERR_WARNING: |
| 126 | 126 | $return .= 'Warning ' . $error->code . ': '; |
| 127 | 127 | break; |
| 128 | - case LIBXML_ERR_ERROR: |
|
| 128 | + case LIBXML_ERR_ERROR: |
|
| 129 | 129 | $return .= 'Error ' . $error->code . ': '; |
| 130 | 130 | break; |
| 131 | 131 | case LIBXML_ERR_FATAL: |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $return .= trim($error->message) . |
| 137 | - "\n Line: " . $error->line . |
|
| 138 | - "\n Column: " . $error->column; |
|
| 137 | + "\n Line: " . $error->line . |
|
| 138 | + "\n Column: " . $error->column; |
|
| 139 | 139 | |
| 140 | 140 | if ($error->file) { |
| 141 | 141 | $return .= "\n File: " . $error->file; |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | require_once 'config.php'; |
| 10 | 10 | |
| 11 | -define ('VERSION', '1.0.0RC4'); |
|
| 12 | -define ('DB', 'db'); |
|
| 11 | +define('VERSION', '1.0.0RC4'); |
|
| 12 | +define('DB', 'db'); |
|
| 13 | 13 | date_default_timezone_set($config['default_timezone']); |
| 14 | 14 | |
| 15 | 15 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | function serverSideRender($data) |
| 23 | 23 | { |
| 24 | 24 | // Get the templates |
| 25 | - $theme = getCurrentTemplate (); |
|
| 25 | + $theme = getCurrentTemplate(); |
|
| 26 | 26 | $header = file_get_contents('templates/' . $theme . '/header.html'); |
| 27 | 27 | $footer = file_get_contents('templates/' . $theme . '/footer.html'); |
| 28 | 28 | $main = file_get_contents('templates/' . $theme . '/main.html'); |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | $page = file_get_contents('templates/' . $theme . '/page.html'); |
| 31 | 31 | |
| 32 | 32 | // Generate the function for the template |
| 33 | - $template = new doT (); |
|
| 34 | - $dot = $template->template ($page, array ('bookdetail' => $bookdetail, |
|
| 33 | + $template = new doT(); |
|
| 34 | + $dot = $template->template($page, array('bookdetail' => $bookdetail, |
|
| 35 | 35 | 'header' => $header, |
| 36 | 36 | 'footer' => $footer, |
| 37 | 37 | 'main' => $main)); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | // Execute the template |
| 44 | 44 | if (!empty ($data)) { |
| 45 | - return $dot ($data); |
|
| 45 | + return $dot($data); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return NULL; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | function notFound() |
| 60 | 60 | { |
| 61 | - header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); |
|
| 61 | + header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); |
|
| 62 | 62 | header('Status: 404 Not Found'); |
| 63 | 63 | |
| 64 | 64 | $_SERVER['REDIRECT_STATUS'] = 404; |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | { |
| 77 | 77 | global $config; |
| 78 | 78 | if (isset($_COOKIE[$option])) { |
| 79 | - if (isset($config ['cops_' . $option]) && is_array ($config ['cops_' . $option])) { |
|
| 80 | - return explode (',', $_COOKIE[$option]); |
|
| 79 | + if (isset($config ['cops_' . $option]) && is_array($config ['cops_' . $option])) { |
|
| 80 | + return explode(',', $_COOKIE[$option]); |
|
| 81 | 81 | } else { |
| 82 | 82 | return $_COOKIE[$option]; |
| 83 | 83 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | function getCurrentCss() |
| 93 | 93 | { |
| 94 | - return 'templates/' . getCurrentTemplate () . '/styles/style-' . getCurrentOption('style') . '.css'; |
|
| 94 | + return 'templates/' . getCurrentTemplate() . '/styles/style-' . getCurrentOption('style') . '.css'; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | function getCurrentTemplate() |
| 98 | 98 | { |
| 99 | - return getCurrentOption ('template'); |
|
| 99 | + return getCurrentOption('template'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | function getUrlWithVersion($url) |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | libxml_use_internal_errors(true); |
| 161 | 161 | |
| 162 | 162 | $doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . |
| 163 | - $html . '</body></html>'); // Load the HTML |
|
| 163 | + $html . '</body></html>'); // Load the HTML |
|
| 164 | 164 | $output = $doc->saveXML($doc->documentElement); // Transform to an Ansi xml stream |
| 165 | 165 | $output = xml2xhtml($output); |
| 166 | - if (preg_match ('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) { |
|
| 166 | + if (preg_match('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) { |
|
| 167 | 167 | $output = $matches [1]; // Remove <html><body> |
| 168 | 168 | } |
| 169 | 169 | /* |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | */ |
| 177 | 177 | |
| 178 | - if (!are_libxml_errors_ok ()) $output = 'HTML code not valid.'; |
|
| 178 | + if (!are_libxml_errors_ok()) $output = 'HTML code not valid.'; |
|
| 179 | 179 | |
| 180 | 180 | libxml_use_internal_errors(false); |
| 181 | 181 | return $output; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | //echo var_dump($langs); |
| 265 | 265 | $lang_file = NULL; |
| 266 | 266 | foreach ($langs as $language => $val) { |
| 267 | - $temp_file = dirname(__FILE__). '/lang/Localization_' . $language . '.json'; |
|
| 267 | + $temp_file = dirname(__FILE__) . '/lang/Localization_' . $language . '.json'; |
|
| 268 | 268 | if (file_exists($temp_file)) { |
| 269 | 269 | $lang = $language; |
| 270 | 270 | $lang_file = $temp_file; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | if (empty ($lang_file)) { |
| 275 | - $lang_file = dirname(__FILE__). '/lang/Localization_' . $lang . '.json'; |
|
| 275 | + $lang_file = dirname(__FILE__) . '/lang/Localization_' . $lang . '.json'; |
|
| 276 | 276 | } |
| 277 | 277 | return array($lang, $lang_file); |
| 278 | 278 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * This method is based on this page |
| 282 | 282 | * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/ |
| 283 | 283 | */ |
| 284 | -function localize($phrase, $count=-1, $reset=false) |
|
| 284 | +function localize($phrase, $count = -1, $reset = false) |
|
| 285 | 285 | { |
| 286 | 286 | global $config; |
| 287 | 287 | if ($count == 0) |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $lang_file_en = NULL; |
| 302 | 302 | list ($lang, $lang_file) = getLangAndTranslationFile(); |
| 303 | 303 | if ($lang != 'en') { |
| 304 | - $lang_file_en = dirname(__FILE__). '/lang/' . 'Localization_en.json'; |
|
| 304 | + $lang_file_en = dirname(__FILE__) . '/lang/' . 'Localization_en.json'; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | $lang_file_content = file_get_contents($lang_file); |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | $translations = json_decode($lang_file_content, true); |
| 310 | 310 | |
| 311 | 311 | /* Clean the array of all unfinished translations */ |
| 312 | - foreach (array_keys ($translations) as $key) { |
|
| 313 | - if (preg_match ('/^##TODO##/', $key)) { |
|
| 312 | + foreach (array_keys($translations) as $key) { |
|
| 313 | + if (preg_match('/^##TODO##/', $key)) { |
|
| 314 | 314 | unset ($translations [$key]); |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -318,10 +318,10 @@ discard block |
||
| 318 | 318 | { |
| 319 | 319 | $lang_file_content = file_get_contents($lang_file_en); |
| 320 | 320 | $translations_en = json_decode($lang_file_content, true); |
| 321 | - $translations = array_merge ($translations_en, $translations); |
|
| 321 | + $translations = array_merge($translations_en, $translations); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | - if (array_key_exists ($phrase, $translations)) { |
|
| 324 | + if (array_key_exists($phrase, $translations)) { |
|
| 325 | 325 | return $translations[$phrase]; |
| 326 | 326 | } |
| 327 | 327 | return $phrase; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $urlParams = ''; |
| 334 | 334 | } |
| 335 | 335 | $start = ''; |
| 336 | - if (preg_match ('#^\?(.*)#', $urlParams, $matches)) { |
|
| 336 | + if (preg_match('#^\?(.*)#', $urlParams, $matches)) { |
|
| 337 | 337 | $start = '?'; |
| 338 | 338 | $urlParams = $matches[1]; |
| 339 | 339 | } |
@@ -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; |
@@ -314,8 +322,7 @@ discard block |
||
| 314 | 322 | unset ($translations [$key]); |
| 315 | 323 | } |
| 316 | 324 | } |
| 317 | - if ($lang_file_en) |
|
| 318 | - { |
|
| 325 | + if ($lang_file_en) { |
|
| 319 | 326 | $lang_file_content = file_get_contents($lang_file_en); |
| 320 | 327 | $translations_en = json_decode($lang_file_content, true); |
| 321 | 328 | $translations = array_merge ($translations_en, $translations); |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | // If there is a syntax error in the function created |
| 39 | 39 | // $dot will be equal to FALSE |
| 40 | 40 | if (!$dot) { |
| 41 | - return FALSE; |
|
| 41 | + return false; |
|
| 42 | 42 | } |
| 43 | 43 | // Execute the template |
| 44 | 44 | if (!empty ($data)) { |
| 45 | 45 | return $dot ($data); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return NULL; |
|
| 48 | + return null; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function getQueryString() |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $_SERVER['REDIRECT_STATUS'] = 404; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | -function getURLParam($name, $default = NULL) |
|
| 67 | +function getURLParam($name, $default = null) |
|
| 68 | 68 | { |
| 69 | 69 | if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != '') { |
| 70 | 70 | return $_GET[$name]; |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $langs = getAcceptLanguages(); |
| 263 | 263 | } |
| 264 | 264 | //echo var_dump($langs); |
| 265 | - $lang_file = NULL; |
|
| 265 | + $lang_file = null; |
|
| 266 | 266 | foreach ($langs as $language => $val) { |
| 267 | 267 | $temp_file = dirname(__FILE__). '/lang/Localization_' . $language . '.json'; |
| 268 | 268 | if (file_exists($temp_file)) { |
@@ -292,13 +292,13 @@ discard block |
||
| 292 | 292 | $phrase .= '.many'; |
| 293 | 293 | |
| 294 | 294 | /* Static keyword is used to ensure the file is loaded only once */ |
| 295 | - static $translations = NULL; |
|
| 295 | + static $translations = null; |
|
| 296 | 296 | if ($reset) { |
| 297 | - $translations = NULL; |
|
| 297 | + $translations = null; |
|
| 298 | 298 | } |
| 299 | 299 | /* If no instance of $translations has occured load the language file */ |
| 300 | 300 | if (is_null($translations)) { |
| 301 | - $lang_file_en = NULL; |
|
| 301 | + $lang_file_en = null; |
|
| 302 | 302 | list ($lang, $lang_file) = getLangAndTranslationFile(); |
| 303 | 303 | if ($lang != 'en') { |
| 304 | 304 | $lang_file_en = dirname(__FILE__). '/lang/' . 'Localization_en.json'; |
@@ -60,6 +60,9 @@ discard block |
||
| 60 | 60 | return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + /** |
|
| 64 | + * @param string $query |
|
| 65 | + */ |
|
| 63 | 66 | public static function getAuthorsForSearch($query) { |
| 64 | 67 | return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
| 65 | 68 | } |
@@ -68,6 +71,9 @@ discard block |
||
| 68 | 71 | return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $query |
|
| 76 | + */ |
|
| 71 | 77 | public static function getEntryArray ($query, $params) { |
| 72 | 78 | return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
| 73 | 79 | } |
@@ -24,69 +24,69 @@ |
||
| 24 | 24 | $this->sort = $post->sort; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function getUri () { |
|
| 28 | - return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; |
|
| 27 | + public function getUri() { |
|
| 28 | + return "?page=" . parent::PAGE_AUTHOR_DETAIL . "&id=$this->id"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function getEntryId () { |
|
| 32 | - return self::ALL_AUTHORS_ID.":".$this->id; |
|
| 31 | + public function getEntryId() { |
|
| 32 | + return self::ALL_AUTHORS_ID . ":" . $this->id; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 36 | - return self::ALL_AUTHORS_ID.":letter:".$startingLetter; |
|
| 35 | + public static function getEntryIdByLetter($startingLetter) { |
|
| 36 | + return self::ALL_AUTHORS_ID . ":letter:" . $startingLetter; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public static function getCount() { |
| 40 | 40 | // str_format (localize("authors.alphabetical", count(array)) |
| 41 | - return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
|
| 41 | + return parent::getCountGeneric("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public static function getAllAuthorsByFirstLetter() { |
| 45 | - list (, $result) = parent::executeQuery ("select {0} |
|
| 45 | + list (, $result) = parent::executeQuery("select {0} |
|
| 46 | 46 | from authors |
| 47 | 47 | group by substr (upper (sort), 1, 1) |
| 48 | -order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array (), -1); |
|
| 48 | +order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array(), -1); |
|
| 49 | 49 | $entryArray = array(); |
| 50 | - while ($post = $result->fetchObject ()) |
|
| 50 | + while ($post = $result->fetchObject()) |
|
| 51 | 51 | { |
| 52 | - array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), |
|
| 53 | - str_format (localize("authorword", $post->count), $post->count), "text", |
|
| 54 | - array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
| 52 | + array_push($entryArray, new Entry($post->title, Author::getEntryIdByLetter($post->title), |
|
| 53 | + str_format(localize("authorword", $post->count), $post->count), "text", |
|
| 54 | + array(new LinkNavigation("?page=" . parent::PAGE_AUTHORS_FIRST_LETTER . "&id=" . rawurlencode($post->title))), "", $post->count)); |
|
| 55 | 55 | } |
| 56 | 56 | return $entryArray; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public static function getAuthorsByStartingLetter($letter) { |
| 60 | - return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
|
| 60 | + return self::getEntryArray(self::SQL_AUTHORS_BY_FIRST_LETTER, array($letter . "%")); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public static function getAuthorsForSearch($query) { |
| 64 | - return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
|
| 64 | + return self::getEntryArray(self::SQL_AUTHORS_FOR_SEARCH, array($query . "%", $query . "%")); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public static function getAllAuthors() { |
| 68 | - return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
|
| 68 | + return self::getEntryArray(self::SQL_ALL_AUTHORS, array()); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public static function getEntryArray ($query, $params) { |
|
| 72 | - return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
|
| 71 | + public static function getEntryArray($query, $params) { |
|
| 72 | + return Base::getEntryArrayWithBookNumber($query, self::AUTHOR_COLUMNS, $params, "Author"); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public static function getAuthorById ($authorId) { |
|
| 76 | - $result = parent::getDb ()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
|
| 77 | - $result->execute (array ($authorId)); |
|
| 78 | - $post = $result->fetchObject (); |
|
| 79 | - return new Author ($post); |
|
| 75 | + public static function getAuthorById($authorId) { |
|
| 76 | + $result = parent::getDb()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
|
| 77 | + $result->execute(array($authorId)); |
|
| 78 | + $post = $result->fetchObject(); |
|
| 79 | + return new Author($post); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public static function getAuthorByBookId ($bookId) { |
|
| 83 | - $result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
| 82 | + public static function getAuthorByBookId($bookId) { |
|
| 83 | + $result = parent::getDb()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
| 84 | 84 | where author = authors.id |
| 85 | 85 | and book = ?'); |
| 86 | - $result->execute (array ($bookId)); |
|
| 87 | - $authorArray = array (); |
|
| 88 | - while ($post = $result->fetchObject ()) { |
|
| 89 | - array_push ($authorArray, new Author ($post)); |
|
| 86 | + $result->execute(array($bookId)); |
|
| 87 | + $authorArray = array(); |
|
| 88 | + while ($post = $result->fetchObject()) { |
|
| 89 | + array_push($authorArray, new Author($post)); |
|
| 90 | 90 | } |
| 91 | 91 | return $authorArray; |
| 92 | 92 | } |
@@ -19,37 +19,42 @@ discard block |
||
| 19 | 19 | public $name; |
| 20 | 20 | public $sort; |
| 21 | 21 | |
| 22 | - public function __construct($post) { |
|
| 22 | + public function __construct($post) |
|
| 23 | + { |
|
| 23 | 24 | $this->id = $post->id; |
| 24 | 25 | $this->name = str_replace("|", ",", $post->name); |
| 25 | 26 | $this->sort = $post->sort; |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | - public function getUri () { |
|
| 29 | + public function getUri () |
|
| 30 | + { |
|
| 29 | 31 | return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | - public function getEntryId () { |
|
| 34 | + public function getEntryId () |
|
| 35 | + { |
|
| 33 | 36 | return self::ALL_AUTHORS_ID.":".$this->id; |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 39 | + public static function getEntryIdByLetter ($startingLetter) |
|
| 40 | + { |
|
| 37 | 41 | return self::ALL_AUTHORS_ID.":letter:".$startingLetter; |
| 38 | 42 | } |
| 39 | 43 | |
| 40 | - public static function getCount() { |
|
| 44 | + public static function getCount() |
|
| 45 | + { |
|
| 41 | 46 | // str_format (localize("authors.alphabetical", count(array)) |
| 42 | 47 | return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
| 43 | 48 | } |
| 44 | 49 | |
| 45 | - public static function getAllAuthorsByFirstLetter() { |
|
| 50 | + public static function getAllAuthorsByFirstLetter() |
|
| 51 | + { |
|
| 46 | 52 | list (, $result) = parent::executeQuery ("select {0} |
| 47 | 53 | from authors |
| 48 | 54 | group by substr (upper (sort), 1, 1) |
| 49 | 55 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array (), -1); |
| 50 | 56 | $entryArray = array(); |
| 51 | - while ($post = $result->fetchObject ()) |
|
| 52 | - { |
|
| 57 | + while ($post = $result->fetchObject ()) { |
|
| 53 | 58 | array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), |
| 54 | 59 | str_format (localize("authorword", $post->count), $post->count), "text", |
| 55 | 60 | array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
@@ -57,30 +62,36 @@ discard block |
||
| 57 | 62 | return $entryArray; |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | - public static function getAuthorsByStartingLetter($letter) { |
|
| 65 | + public static function getAuthorsByStartingLetter($letter) |
|
| 66 | + { |
|
| 61 | 67 | return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
| 62 | 68 | } |
| 63 | 69 | |
| 64 | - public static function getAuthorsForSearch($query) { |
|
| 70 | + public static function getAuthorsForSearch($query) |
|
| 71 | + { |
|
| 65 | 72 | return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | - public static function getAllAuthors() { |
|
| 75 | + public static function getAllAuthors() |
|
| 76 | + { |
|
| 69 | 77 | return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
| 70 | 78 | } |
| 71 | 79 | |
| 72 | - public static function getEntryArray ($query, $params) { |
|
| 80 | + public static function getEntryArray ($query, $params) |
|
| 81 | + { |
|
| 73 | 82 | return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
| 74 | 83 | } |
| 75 | 84 | |
| 76 | - public static function getAuthorById ($authorId) { |
|
| 85 | + public static function getAuthorById ($authorId) |
|
| 86 | + { |
|
| 77 | 87 | $result = parent::getDb ()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
| 78 | 88 | $result->execute (array ($authorId)); |
| 79 | 89 | $post = $result->fetchObject (); |
| 80 | 90 | return new Author ($post); |
| 81 | 91 | } |
| 82 | 92 | |
| 83 | - public static function getAuthorByBookId ($bookId) { |
|
| 93 | + public static function getAuthorByBookId ($bookId) |
|
| 94 | + { |
|
| 84 | 95 | $result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
| 85 | 96 | where author = authors.id |
| 86 | 97 | and book = ?'); |
@@ -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,142 +37,142 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private static $db = NULL; |
| 39 | 39 | |
| 40 | - public static function isMultipleDatabaseEnabled () { |
|
| 40 | + public static function isMultipleDatabaseEnabled() { |
|
| 41 | 41 | global $config; |
| 42 | - return is_array ($config['calibre_directory']); |
|
| 42 | + return is_array($config['calibre_directory']); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function useAbsolutePath () { |
|
| 45 | + public static function useAbsolutePath() { |
|
| 46 | 46 | global $config; |
| 47 | 47 | $path = self::getDbDirectory(); |
| 48 | - return preg_match ('/^\//', $path) || // Linux / |
|
| 49 | - preg_match ('/^\w\:/', $path); // Windows X: |
|
| 48 | + return preg_match('/^\//', $path) || // Linux / |
|
| 49 | + preg_match('/^\w\:/', $path); // Windows X: |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function noDatabaseSelected () { |
|
| 53 | - return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
|
| 52 | + public static function noDatabaseSelected() { |
|
| 53 | + return self::isMultipleDatabaseEnabled() && is_null(GetUrlParam(DB)); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static function getDbList () { |
|
| 56 | + public static function getDbList() { |
|
| 57 | 57 | global $config; |
| 58 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 58 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 59 | 59 | return $config['calibre_directory']; |
| 60 | 60 | } else { |
| 61 | - return array ("" => $config['calibre_directory']); |
|
| 61 | + return array("" => $config['calibre_directory']); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function getDbNameList () { |
|
| 65 | + public static function getDbNameList() { |
|
| 66 | 66 | global $config; |
| 67 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 68 | - return array_keys ($config['calibre_directory']); |
|
| 67 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 68 | + return array_keys($config['calibre_directory']); |
|
| 69 | 69 | } else { |
| 70 | - return array (""); |
|
| 70 | + return array(""); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 74 | + public static function getDbName($database = NULL) { |
|
| 75 | 75 | global $config; |
| 76 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 77 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 76 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 77 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 78 | 78 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 79 | - return self::error ($database); |
|
| 79 | + return self::error($database); |
|
| 80 | 80 | } |
| 81 | - $array = array_keys ($config['calibre_directory']); |
|
| 81 | + $array = array_keys($config['calibre_directory']); |
|
| 82 | 82 | return $array[$database]; |
| 83 | 83 | } |
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 87 | + public static function getDbDirectory($database = NULL) { |
|
| 88 | 88 | global $config; |
| 89 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 90 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 89 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 90 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 91 | 91 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 92 | - return self::error ($database); |
|
| 92 | + return self::error($database); |
|
| 93 | 93 | } |
| 94 | - $array = array_values ($config['calibre_directory']); |
|
| 94 | + $array = array_values($config['calibre_directory']); |
|
| 95 | 95 | return $array[$database]; |
| 96 | 96 | } |
| 97 | 97 | return $config['calibre_directory']; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - public static function getDbFileName ($database = NULL) { |
|
| 102 | - return self::getDbDirectory ($database) .'metadata.db'; |
|
| 101 | + public static function getDbFileName($database = NULL) { |
|
| 102 | + return self::getDbDirectory($database) . 'metadata.db'; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - private static function error ($database) { |
|
| 105 | + private static function error($database) { |
|
| 106 | 106 | if (php_sapi_name() != "cli") { |
| 107 | 107 | header("location: checkconfig.php?err=1"); |
| 108 | 108 | } |
| 109 | 109 | throw new Exception("Database <{$database}> not found."); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public static function getDb ($database = NULL) { |
|
| 113 | - if (is_null (self::$db)) { |
|
| 112 | + public static function getDb($database = NULL) { |
|
| 113 | + if (is_null(self::$db)) { |
|
| 114 | 114 | try { |
| 115 | - if (is_readable (self::getDbFileName ($database))) { |
|
| 116 | - self::$db = new PDO('sqlite:'. self::getDbFileName ($database)); |
|
| 117 | - if (useNormAndUp ()) { |
|
| 118 | - self::$db->sqliteCreateFunction ('normAndUp', 'normAndUp', 1); |
|
| 115 | + if (is_readable(self::getDbFileName($database))) { |
|
| 116 | + self::$db = new PDO('sqlite:' . self::getDbFileName($database)); |
|
| 117 | + if (useNormAndUp()) { |
|
| 118 | + self::$db->sqliteCreateFunction('normAndUp', 'normAndUp', 1); |
|
| 119 | 119 | } |
| 120 | 120 | } else { |
| 121 | - self::error ($database); |
|
| 121 | + self::error($database); |
|
| 122 | 122 | } |
| 123 | 123 | } catch (Exception $e) { |
| 124 | - self::error ($database); |
|
| 124 | + self::error($database); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | return self::$db; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public static function checkDatabaseAvailability () { |
|
| 131 | - if (self::noDatabaseSelected ()) { |
|
| 132 | - for ($i = 0; $i < count (self::getDbList ()); $i++) { |
|
| 133 | - self::getDb ($i); |
|
| 134 | - self::clearDb (); |
|
| 130 | + public static function checkDatabaseAvailability() { |
|
| 131 | + if (self::noDatabaseSelected()) { |
|
| 132 | + for ($i = 0; $i < count(self::getDbList()); $i++) { |
|
| 133 | + self::getDb($i); |
|
| 134 | + self::clearDb(); |
|
| 135 | 135 | } |
| 136 | 136 | } else { |
| 137 | - self::getDb (); |
|
| 137 | + self::getDb(); |
|
| 138 | 138 | } |
| 139 | 139 | return true; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public static function clearDb () { |
|
| 142 | + public static function clearDb() { |
|
| 143 | 143 | self::$db = NULL; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 147 | - return self::getDb ($database)->query($query)->fetchColumn(); |
|
| 146 | + public static function executeQuerySingle($query, $database = NULL) { |
|
| 147 | + return self::getDb($database)->query($query)->fetchColumn(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
| 151 | 151 | if (!$numberOfString) { |
| 152 | 152 | $numberOfString = $table . ".alphabetical"; |
| 153 | 153 | } |
| 154 | - $count = self::executeQuerySingle ('select count(*) from ' . $table); |
|
| 154 | + $count = self::executeQuerySingle('select count(*) from ' . $table); |
|
| 155 | 155 | if ($count == 0) return NULL; |
| 156 | - $entry = new Entry (localize($table . ".title"), $id, |
|
| 157 | - str_format (localize($numberOfString, $count), $count), "text", |
|
| 158 | - array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
|
| 156 | + $entry = new Entry(localize($table . ".title"), $id, |
|
| 157 | + str_format(localize($numberOfString, $count), $count), "text", |
|
| 158 | + array(new LinkNavigation("?page=" . $pageId)), "", $count); |
|
| 159 | 159 | return $entry; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 163 | - list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
|
| 162 | + public static function getEntryArrayWithBookNumber($query, $columns, $params, $category) { |
|
| 163 | + list (, $result) = self::executeQuery($query, $columns, "", $params, -1); |
|
| 164 | 164 | $entryArray = array(); |
| 165 | - while ($post = $result->fetchObject ()) |
|
| 165 | + while ($post = $result->fetchObject()) |
|
| 166 | 166 | { |
| 167 | - $instance = new $category ($post); |
|
| 167 | + $instance = new $category($post); |
|
| 168 | 168 | if (property_exists($post, "sort")) { |
| 169 | 169 | $title = $post->sort; |
| 170 | 170 | } else { |
| 171 | 171 | $title = $post->name; |
| 172 | 172 | } |
| 173 | - array_push ($entryArray, new Entry ($title, $instance->getEntryId (), |
|
| 174 | - str_format (localize("bookword", $post->count), $post->count), "text", |
|
| 175 | - array ( new LinkNavigation ($instance->getUri ())), "", $post->count)); |
|
| 173 | + array_push($entryArray, new Entry($title, $instance->getEntryId(), |
|
| 174 | + str_format(localize("bookword", $post->count), $post->count), "text", |
|
| 175 | + array(new LinkNavigation($instance->getUri())), "", $post->count)); |
|
| 176 | 176 | } |
| 177 | 177 | return $entryArray; |
| 178 | 178 | } |
@@ -180,30 +180,30 @@ discard block |
||
| 180 | 180 | public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
| 181 | 181 | $totalResult = -1; |
| 182 | 182 | |
| 183 | - if (useNormAndUp ()) { |
|
| 183 | + if (useNormAndUp()) { |
|
| 184 | 184 | $query = preg_replace("/upper/", "normAndUp", $query); |
| 185 | 185 | $columns = preg_replace("/upper/", "normAndUp", $columns); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if (is_null ($numberPerPage)) { |
|
| 189 | - $numberPerPage = getCurrentOption ("max_item_per_page"); |
|
| 188 | + if (is_null($numberPerPage)) { |
|
| 189 | + $numberPerPage = getCurrentOption("max_item_per_page"); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | if ($numberPerPage != -1 && $n != -1) |
| 193 | 193 | { |
| 194 | 194 | // First check total number of results |
| 195 | - $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
|
| 196 | - $result->execute ($params); |
|
| 197 | - $totalResult = $result->fetchColumn (); |
|
| 195 | + $result = self::getDb($database)->prepare(str_format($query, "count(*)", $filter)); |
|
| 196 | + $result->execute($params); |
|
| 197 | + $totalResult = $result->fetchColumn(); |
|
| 198 | 198 | |
| 199 | 199 | // Next modify the query and params |
| 200 | 200 | $query .= " limit ?, ?"; |
| 201 | - array_push ($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 201 | + array_push($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter)); |
|
| 205 | - $result->execute ($params); |
|
| 206 | - return array ($totalResult, $result); |
|
| 204 | + $result = self::getDb($database)->prepare(str_format($query, $columns, $filter)); |
|
| 205 | + $result->execute($params); |
|
| 206 | + return array($totalResult, $result); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | } |
@@ -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); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | const COMPATIBILITY_XML_ALDIKO = "aldiko"; |
| 37 | 37 | |
| 38 | - private static $db = NULL; |
|
| 38 | + private static $db = null; |
|
| 39 | 39 | |
| 40 | 40 | public static function isMultipleDatabaseEnabled () { |
| 41 | 41 | global $config; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 74 | + public static function getDbName ($database = null) { |
|
| 75 | 75 | global $config; |
| 76 | 76 | if (self::isMultipleDatabaseEnabled ()) { |
| 77 | 77 | if (is_null ($database)) $database = GetUrlParam (DB, 0); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 87 | + public static function getDbDirectory ($database = null) { |
|
| 88 | 88 | global $config; |
| 89 | 89 | if (self::isMultipleDatabaseEnabled ()) { |
| 90 | 90 | if (is_null ($database)) $database = GetUrlParam (DB, 0); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - public static function getDbFileName ($database = NULL) { |
|
| 101 | + public static function getDbFileName ($database = null) { |
|
| 102 | 102 | return self::getDbDirectory ($database) .'metadata.db'; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | throw new Exception("Database <{$database}> not found."); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public static function getDb ($database = NULL) { |
|
| 112 | + public static function getDb ($database = null) { |
|
| 113 | 113 | if (is_null (self::$db)) { |
| 114 | 114 | try { |
| 115 | 115 | if (is_readable (self::getDbFileName ($database))) { |
@@ -140,19 +140,19 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | public static function clearDb () { |
| 143 | - self::$db = NULL; |
|
| 143 | + self::$db = null; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 146 | + public static function executeQuerySingle ($query, $database = null) { |
|
| 147 | 147 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
|
| 150 | + public static function getCountGeneric($table, $id, $pageId, $numberOfString = null) { |
|
| 151 | 151 | if (!$numberOfString) { |
| 152 | 152 | $numberOfString = $table . ".alphabetical"; |
| 153 | 153 | } |
| 154 | 154 | $count = self::executeQuerySingle ('select count(*) from ' . $table); |
| 155 | - if ($count == 0) return NULL; |
|
| 155 | + if ($count == 0) return null; |
|
| 156 | 156 | $entry = new Entry (localize($table . ".title"), $id, |
| 157 | 157 | str_format (localize($numberOfString, $count), $count), "text", |
| 158 | 158 | array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | return $entryArray; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 180 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = null, $numberPerPage = null) { |
|
| 181 | 181 | $totalResult = -1; |
| 182 | 182 | |
| 183 | 183 | if (useNormAndUp ()) { |
@@ -287,6 +287,9 @@ discard block |
||
| 287 | 287 | return reset ($reduced); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | + /** |
|
| 291 | + * @param string $extension |
|
| 292 | + */ |
|
| 290 | 293 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
| 291 | 294 | { |
| 292 | 295 | if ($extension == "jpg") |
@@ -419,6 +422,9 @@ discard block |
||
| 419 | 422 | $this->getLinkArray (), $this); |
| 420 | 423 | } |
| 421 | 424 | |
| 425 | + /** |
|
| 426 | + * @param integer $database |
|
| 427 | + */ |
|
| 422 | 428 | public static function getBookCount($database = NULL) { |
| 423 | 429 | return parent::executeQuerySingle ('select count(*) from books', $database); |
| 424 | 430 | } |
@@ -500,6 +506,10 @@ discard block |
||
| 500 | 506 | return NULL; |
| 501 | 507 | } |
| 502 | 508 | |
| 509 | + /** |
|
| 510 | + * @param integer $database |
|
| 511 | + * @param integer $numberPerPage |
|
| 512 | + */ |
|
| 503 | 513 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
| 504 | 514 | $i = 0; |
| 505 | 515 | $critArray = array (); |
@@ -544,6 +554,9 @@ discard block |
||
| 544 | 554 | return $entryArray; |
| 545 | 555 | } |
| 546 | 556 | |
| 557 | + /** |
|
| 558 | + * @param integer $numberPerPage |
|
| 559 | + */ |
|
| 547 | 560 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
| 548 | 561 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
| 549 | 562 | } |
@@ -428,15 +428,15 @@ |
||
| 428 | 428 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
| 429 | 429 | $result = array(); |
| 430 | 430 | $entry = new Entry (localize ("allbooks.title"), |
| 431 | - self::ALL_BOOKS_ID, |
|
| 432 | - str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
| 433 | - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
| 431 | + self::ALL_BOOKS_ID, |
|
| 432 | + str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
| 433 | + array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
| 434 | 434 | array_push ($result, $entry); |
| 435 | 435 | if ($config['cops_recentbooks_limit'] > 0) { |
| 436 | 436 | $entry = new Entry (localize ("recent.title"), |
| 437 | - self::ALL_RECENT_BOOKS_ID, |
|
| 438 | - str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
| 439 | - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
| 437 | + self::ALL_RECENT_BOOKS_ID, |
|
| 438 | + str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
| 439 | + array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
| 440 | 440 | array_push ($result, $entry); |
| 441 | 441 | } |
| 442 | 442 | return $result; |
@@ -7,35 +7,35 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // Silly thing because PHP forbid string concatenation in class const |
| 10 | -define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id |
|
| 10 | +define('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id |
|
| 11 | 11 | left outer join books_ratings_link on books_ratings_link.book = books.id |
| 12 | 12 | left outer join ratings on books_ratings_link.rating = ratings.id "); |
| 13 | -define ('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort "); |
|
| 14 | -define ('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 13 | +define('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort "); |
|
| 14 | +define('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 15 | 15 | where books_publishers_link.book = books.id and publisher = ? {1} order by publisher"); |
| 16 | -define ('SQL_BOOKS_BY_FIRST_LETTER', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 16 | +define('SQL_BOOKS_BY_FIRST_LETTER', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 17 | 17 | where upper (books.sort) like ? order by books.sort"); |
| 18 | -define ('SQL_BOOKS_BY_AUTHOR', "select {0} from books_authors_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 18 | +define('SQL_BOOKS_BY_AUTHOR', "select {0} from books_authors_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 19 | 19 | left outer join books_series_link on books_series_link.book = books.id |
| 20 | 20 | where books_authors_link.book = books.id and author = ? {1} order by series desc, series_index asc, pubdate asc"); |
| 21 | -define ('SQL_BOOKS_BY_SERIE', "select {0} from books_series_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 21 | +define('SQL_BOOKS_BY_SERIE', "select {0} from books_series_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 22 | 22 | where books_series_link.book = books.id and series = ? {1} order by series_index"); |
| 23 | -define ('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 23 | +define('SQL_BOOKS_BY_TAG', "select {0} from books_tags_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 24 | 24 | where books_tags_link.book = books.id and tag = ? {1} order by sort"); |
| 25 | -define ('SQL_BOOKS_BY_LANGUAGE', "select {0} from books_languages_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 25 | +define('SQL_BOOKS_BY_LANGUAGE', "select {0} from books_languages_link, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 26 | 26 | where books_languages_link.book = books.id and lang_code = ? {1} order by sort"); |
| 27 | -define ('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 27 | +define('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 28 | 28 | where {2}.book = books.id and {2}.{3} = ? {1} order by sort"); |
| 29 | -define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 29 | +define('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 30 | 30 | where ( |
| 31 | 31 | exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or |
| 32 | 32 | exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or |
| 33 | 33 | exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or |
| 34 | 34 | exists (select null from publishers, books_publishers_link where book = books.id and books_publishers_link.publisher = publishers.id and publishers.name like ?) or |
| 35 | 35 | title like ?) {1} order by books.sort"); |
| 36 | -define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 36 | +define('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 37 | 37 | where 1=1 {1} order by timestamp desc limit "); |
| 38 | -define ('SQL_BOOKS_BY_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 38 | +define('SQL_BOOKS_BY_RATING', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " |
|
| 39 | 39 | where books_ratings_link.book = books.id and ratings.id = ? {1} order by sort"); |
| 40 | 40 | |
| 41 | 41 | class Book extends Base { |
@@ -76,133 +76,133 @@ discard block |
||
| 76 | 76 | public $serie = NULL; |
| 77 | 77 | public $tags = NULL; |
| 78 | 78 | public $languages = NULL; |
| 79 | - public $format = array (); |
|
| 79 | + public $format = array(); |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | public function __construct($line) { |
| 83 | 83 | $this->id = $line->id; |
| 84 | 84 | $this->title = $line->title; |
| 85 | - $this->timestamp = strtotime ($line->timestamp); |
|
| 85 | + $this->timestamp = strtotime($line->timestamp); |
|
| 86 | 86 | $this->pubdate = $line->pubdate; |
| 87 | - $this->path = Base::getDbDirectory () . $line->path; |
|
| 87 | + $this->path = Base::getDbDirectory() . $line->path; |
|
| 88 | 88 | $this->relativePath = $line->path; |
| 89 | 89 | $this->seriesIndex = $line->series_index; |
| 90 | 90 | $this->comment = $line->comment; |
| 91 | 91 | $this->uuid = $line->uuid; |
| 92 | 92 | $this->hasCover = $line->has_cover; |
| 93 | - if (!file_exists ($this->getFilePath ("jpg"))) { |
|
| 93 | + if (!file_exists($this->getFilePath("jpg"))) { |
|
| 94 | 94 | // double check |
| 95 | 95 | $this->hasCover = 0; |
| 96 | 96 | } |
| 97 | 97 | $this->rating = $line->rating; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function getEntryId () { |
|
| 101 | - return self::ALL_BOOKS_UUID.":".$this->uuid; |
|
| 100 | + public function getEntryId() { |
|
| 101 | + return self::ALL_BOOKS_UUID . ":" . $this->uuid; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 105 | - return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
|
| 104 | + public static function getEntryIdByLetter($startingLetter) { |
|
| 105 | + return self::ALL_BOOKS_ID . ":letter:" . $startingLetter; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function getUri () { |
|
| 109 | - return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
|
| 108 | + public function getUri() { |
|
| 109 | + return "?page=" . parent::PAGE_BOOK_DETAIL . "&id=$this->id"; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public function getDetailUrl () { |
|
| 113 | - $urlParam = $this->getUri (); |
|
| 114 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 112 | + public function getDetailUrl() { |
|
| 113 | + $urlParam = $this->getUri(); |
|
| 114 | + if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB)); |
|
| 115 | 115 | return 'index.php' . $urlParam; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function getTitle () { |
|
| 118 | + public function getTitle() { |
|
| 119 | 119 | return $this->title; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /* Other class (author, series, tag, ...) initialization and accessors */ |
| 123 | 123 | |
| 124 | - public function getAuthors () { |
|
| 125 | - if (is_null ($this->authors)) { |
|
| 126 | - $this->authors = Author::getAuthorByBookId ($this->id); |
|
| 124 | + public function getAuthors() { |
|
| 125 | + if (is_null($this->authors)) { |
|
| 126 | + $this->authors = Author::getAuthorByBookId($this->id); |
|
| 127 | 127 | } |
| 128 | 128 | return $this->authors; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function getAuthorsName () { |
|
| 132 | - return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
|
| 131 | + public function getAuthorsName() { |
|
| 132 | + return implode(", ", array_map(function($author) { return $author->name; }, $this->getAuthors())); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function getAuthorsSort () { |
|
| 136 | - return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
|
| 135 | + public function getAuthorsSort() { |
|
| 136 | + return implode(", ", array_map(function($author) { return $author->sort; }, $this->getAuthors())); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function getPublisher () { |
|
| 140 | - if (is_null ($this->publisher)) { |
|
| 141 | - $this->publisher = Publisher::getPublisherByBookId ($this->id); |
|
| 139 | + public function getPublisher() { |
|
| 140 | + if (is_null($this->publisher)) { |
|
| 141 | + $this->publisher = Publisher::getPublisherByBookId($this->id); |
|
| 142 | 142 | } |
| 143 | 143 | return $this->publisher; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function getSerie () { |
|
| 147 | - if (is_null ($this->serie)) { |
|
| 148 | - $this->serie = Serie::getSerieByBookId ($this->id); |
|
| 146 | + public function getSerie() { |
|
| 147 | + if (is_null($this->serie)) { |
|
| 148 | + $this->serie = Serie::getSerieByBookId($this->id); |
|
| 149 | 149 | } |
| 150 | 150 | return $this->serie; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - public function getLanguages () { |
|
| 154 | - $lang = array (); |
|
| 155 | - $result = parent::getDb ()->prepare('select languages.lang_code |
|
| 153 | + public function getLanguages() { |
|
| 154 | + $lang = array(); |
|
| 155 | + $result = parent::getDb()->prepare('select languages.lang_code |
|
| 156 | 156 | from books_languages_link, languages |
| 157 | 157 | where books_languages_link.lang_code = languages.id |
| 158 | 158 | and book = ? |
| 159 | 159 | order by item_order'); |
| 160 | - $result->execute (array ($this->id)); |
|
| 161 | - while ($post = $result->fetchObject ()) |
|
| 160 | + $result->execute(array($this->id)); |
|
| 161 | + while ($post = $result->fetchObject()) |
|
| 162 | 162 | { |
| 163 | - array_push ($lang, Language::getLanguageString($post->lang_code)); |
|
| 163 | + array_push($lang, Language::getLanguageString($post->lang_code)); |
|
| 164 | 164 | } |
| 165 | - return implode (", ", $lang); |
|
| 165 | + return implode(", ", $lang); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function getTags () { |
|
| 169 | - if (is_null ($this->tags)) { |
|
| 170 | - $this->tags = array (); |
|
| 168 | + public function getTags() { |
|
| 169 | + if (is_null($this->tags)) { |
|
| 170 | + $this->tags = array(); |
|
| 171 | 171 | |
| 172 | - $result = parent::getDb ()->prepare('select tags.id as id, name |
|
| 172 | + $result = parent::getDb()->prepare('select tags.id as id, name |
|
| 173 | 173 | from books_tags_link, tags |
| 174 | 174 | where tag = tags.id |
| 175 | 175 | and book = ? |
| 176 | 176 | order by name'); |
| 177 | - $result->execute (array ($this->id)); |
|
| 178 | - while ($post = $result->fetchObject ()) |
|
| 177 | + $result->execute(array($this->id)); |
|
| 178 | + while ($post = $result->fetchObject()) |
|
| 179 | 179 | { |
| 180 | - array_push ($this->tags, new Tag ($post)); |
|
| 180 | + array_push($this->tags, new Tag($post)); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | return $this->tags; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function getTagsName () { |
|
| 187 | - return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
|
| 186 | + public function getTagsName() { |
|
| 187 | + return implode(", ", array_map(function($tag) { return $tag->name; }, $this->getTags())); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - public function getDatas () |
|
| 190 | + public function getDatas() |
|
| 191 | 191 | { |
| 192 | - if (is_null ($this->datas)) { |
|
| 193 | - $this->datas = Data::getDataByBook ($this); |
|
| 192 | + if (is_null($this->datas)) { |
|
| 193 | + $this->datas = Data::getDataByBook($this); |
|
| 194 | 194 | } |
| 195 | 195 | return $this->datas; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
| 199 | 199 | |
| 200 | - public static function getFilterString () { |
|
| 201 | - $filter = getURLParam ("tag", NULL); |
|
| 200 | + public static function getFilterString() { |
|
| 201 | + $filter = getURLParam("tag", NULL); |
|
| 202 | 202 | if (empty ($filter)) return ""; |
| 203 | 203 | |
| 204 | 204 | $exists = true; |
| 205 | - if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
|
| 205 | + if (preg_match("/^!(.*)$/", $filter, $matches)) { |
|
| 206 | 206 | $exists = false; |
| 207 | 207 | $filter = $matches[1]; |
| 208 | 208 | } |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | return "and " . $result; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - public function GetMostInterestingDataToSendToKindle () |
|
| 219 | + public function GetMostInterestingDataToSendToKindle() |
|
| 220 | 220 | { |
| 221 | - $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI"); |
|
| 221 | + $bestFormatForKindle = array("EPUB", "PDF", "AZW3", "MOBI"); |
|
| 222 | 222 | $bestRank = -1; |
| 223 | 223 | $bestData = NULL; |
| 224 | - foreach ($this->getDatas () as $data) { |
|
| 225 | - $key = array_search ($data->format, $bestFormatForKindle); |
|
| 224 | + foreach ($this->getDatas() as $data) { |
|
| 225 | + $key = array_search($data->format, $bestFormatForKindle); |
|
| 226 | 226 | if ($key !== false && $key > $bestRank) { |
| 227 | 227 | $bestRank = $key; |
| 228 | 228 | $bestData = $data; |
@@ -231,16 +231,16 @@ discard block |
||
| 231 | 231 | return $bestData; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - public function getDataById ($idData) |
|
| 234 | + public function getDataById($idData) |
|
| 235 | 235 | { |
| 236 | - $reduced = array_filter ($this->getDatas (), function ($data) use ($idData) { |
|
| 236 | + $reduced = array_filter($this->getDatas(), function($data) use ($idData) { |
|
| 237 | 237 | return $data->id == $idData; |
| 238 | 238 | }); |
| 239 | - return reset ($reduced); |
|
| 239 | + return reset($reduced); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - public function getRating () { |
|
| 243 | - if (is_null ($this->rating) || $this->rating == 0) { |
|
| 242 | + public function getRating() { |
|
| 243 | + if (is_null($this->rating) || $this->rating == 0) { |
|
| 244 | 244 | return ""; |
| 245 | 245 | } |
| 246 | 246 | $retour = ""; |
@@ -253,41 +253,41 @@ discard block |
||
| 253 | 253 | return $retour; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - public function getPubDate () { |
|
| 256 | + public function getPubDate() { |
|
| 257 | 257 | if (empty ($this->pubdate)) { |
| 258 | 258 | return ""; |
| 259 | 259 | } |
| 260 | - $dateY = (int) substr($this->pubdate, 0, 4); |
|
| 260 | + $dateY = (int)substr($this->pubdate, 0, 4); |
|
| 261 | 261 | if ($dateY > 102) { |
| 262 | 262 | return str_pad($dateY, 4, "0", STR_PAD_LEFT); |
| 263 | 263 | } |
| 264 | 264 | return ""; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - public function getComment ($withSerie = true) { |
|
| 267 | + public function getComment($withSerie = true) { |
|
| 268 | 268 | $addition = ""; |
| 269 | - $se = $this->getSerie (); |
|
| 270 | - if (!is_null ($se) && $withSerie) { |
|
| 271 | - $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
|
| 269 | + $se = $this->getSerie(); |
|
| 270 | + if (!is_null($se) && $withSerie) { |
|
| 271 | + $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format(localize("content.series.data"), $this->seriesIndex, htmlspecialchars($se->name)) . "<br />\n"; |
|
| 272 | 272 | } |
| 273 | - if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
|
| 273 | + if (preg_match("/<\/(div|p|a|span)>/", $this->comment)) |
|
| 274 | 274 | { |
| 275 | - return $addition . html2xhtml ($this->comment); |
|
| 275 | + return $addition . html2xhtml($this->comment); |
|
| 276 | 276 | } |
| 277 | 277 | else |
| 278 | 278 | { |
| 279 | - return $addition . htmlspecialchars ($this->comment); |
|
| 279 | + return $addition . htmlspecialchars($this->comment); |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - public function getDataFormat ($format) { |
|
| 284 | - $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
|
| 283 | + public function getDataFormat($format) { |
|
| 284 | + $reduced = array_filter($this->getDatas(), function($data) use ($format) { |
|
| 285 | 285 | return $data->format == $format; |
| 286 | 286 | }); |
| 287 | - return reset ($reduced); |
|
| 287 | + return reset($reduced); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public function getFilePath ($extension, $idData = NULL, $relative = false) |
|
| 290 | + public function getFilePath($extension, $idData = NULL, $relative = false) |
|
| 291 | 291 | { |
| 292 | 292 | if ($extension == "jpg") |
| 293 | 293 | { |
@@ -295,50 +295,50 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | else |
| 297 | 297 | { |
| 298 | - $data = $this->getDataById ($idData); |
|
| 298 | + $data = $this->getDataById($idData); |
|
| 299 | 299 | if (!$data) return NULL; |
| 300 | - $file = $data->name . "." . strtolower ($data->format); |
|
| 300 | + $file = $data->name . "." . strtolower($data->format); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | if ($relative) |
| 304 | 304 | { |
| 305 | - return $this->relativePath."/".$file; |
|
| 305 | + return $this->relativePath . "/" . $file; |
|
| 306 | 306 | } |
| 307 | 307 | else |
| 308 | 308 | { |
| 309 | - return $this->path."/".$file; |
|
| 309 | + return $this->path . "/" . $file; |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - public function getUpdatedEpub ($idData) |
|
| 313 | + public function getUpdatedEpub($idData) |
|
| 314 | 314 | { |
| 315 | 315 | global $config; |
| 316 | - $data = $this->getDataById ($idData); |
|
| 316 | + $data = $this->getDataById($idData); |
|
| 317 | 317 | |
| 318 | 318 | try |
| 319 | 319 | { |
| 320 | - $epub = new EPub ($data->getLocalPath ()); |
|
| 320 | + $epub = new EPub($data->getLocalPath()); |
|
| 321 | 321 | |
| 322 | - $epub->Title ($this->title); |
|
| 323 | - $authorArray = array (); |
|
| 322 | + $epub->Title($this->title); |
|
| 323 | + $authorArray = array(); |
|
| 324 | 324 | foreach ($this->getAuthors() as $author) { |
| 325 | 325 | $authorArray [$author->sort] = $author->name; |
| 326 | 326 | } |
| 327 | - $epub->Authors ($authorArray); |
|
| 328 | - $epub->Language ($this->getLanguages ()); |
|
| 329 | - $epub->Description ($this->getComment (false)); |
|
| 330 | - $epub->Subjects ($this->getTagsName ()); |
|
| 331 | - $epub->Cover2 ($this->getFilePath ("jpg"), "image/jpeg"); |
|
| 332 | - $epub->Calibre ($this->uuid); |
|
| 333 | - $se = $this->getSerie (); |
|
| 334 | - if (!is_null ($se)) { |
|
| 335 | - $epub->Serie ($se->name); |
|
| 336 | - $epub->SerieIndex ($this->seriesIndex); |
|
| 327 | + $epub->Authors($authorArray); |
|
| 328 | + $epub->Language($this->getLanguages()); |
|
| 329 | + $epub->Description($this->getComment(false)); |
|
| 330 | + $epub->Subjects($this->getTagsName()); |
|
| 331 | + $epub->Cover2($this->getFilePath("jpg"), "image/jpeg"); |
|
| 332 | + $epub->Calibre($this->uuid); |
|
| 333 | + $se = $this->getSerie(); |
|
| 334 | + if (!is_null($se)) { |
|
| 335 | + $epub->Serie($se->name); |
|
| 336 | + $epub->SerieIndex($this->seriesIndex); |
|
| 337 | 337 | } |
| 338 | - if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
|
| 339 | - $epub->updateForKepub (); |
|
| 338 | + if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
|
| 339 | + $epub->updateForKepub(); |
|
| 340 | 340 | } |
| 341 | - $epub->download ($data->getUpdatedFilenameEpub ()); |
|
| 341 | + $epub->download($data->getUpdatedFilenameEpub()); |
|
| 342 | 342 | } |
| 343 | 343 | catch (Exception $e) |
| 344 | 344 | { |
@@ -346,25 +346,25 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
| 350 | - if (is_null ($width) && is_null ($height)) { |
|
| 349 | + public function getThumbnail($width, $height, $outputfile = NULL) { |
|
| 350 | + if (is_null($width) && is_null($height)) { |
|
| 351 | 351 | return false; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $file = $this->getFilePath ("jpg"); |
|
| 354 | + $file = $this->getFilePath("jpg"); |
|
| 355 | 355 | // get image size |
| 356 | 356 | if ($size = GetImageSize($file)) { |
| 357 | 357 | $w = $size[0]; |
| 358 | 358 | $h = $size[1]; |
| 359 | 359 | //set new size |
| 360 | - if (!is_null ($width)) { |
|
| 360 | + if (!is_null($width)) { |
|
| 361 | 361 | $nw = $width; |
| 362 | 362 | if ($nw >= $w) { return false; } |
| 363 | - $nh = ($nw*$h)/$w; |
|
| 363 | + $nh = ($nw * $h) / $w; |
|
| 364 | 364 | } else { |
| 365 | 365 | $nh = $height; |
| 366 | 366 | if ($nh >= $h) { return false; } |
| 367 | - $nw = ($nh*$w)/$h; |
|
| 367 | + $nw = ($nh * $w) / $h; |
|
| 368 | 368 | } |
| 369 | 369 | } else { |
| 370 | 370 | return false; |
@@ -372,129 +372,129 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | //draw the image |
| 374 | 374 | $src_img = imagecreatefromjpeg($file); |
| 375 | - $dst_img = imagecreatetruecolor($nw,$nh); |
|
| 376 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);//resizing the image |
|
| 377 | - imagejpeg($dst_img,$outputfile,80); |
|
| 375 | + $dst_img = imagecreatetruecolor($nw, $nh); |
|
| 376 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h); //resizing the image |
|
| 377 | + imagejpeg($dst_img, $outputfile, 80); |
|
| 378 | 378 | imagedestroy($src_img); |
| 379 | 379 | imagedestroy($dst_img); |
| 380 | 380 | |
| 381 | 381 | return true; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - public function getLinkArray () |
|
| 384 | + public function getLinkArray() |
|
| 385 | 385 | { |
| 386 | 386 | $linkArray = array(); |
| 387 | 387 | |
| 388 | 388 | if ($this->hasCover) |
| 389 | 389 | { |
| 390 | - array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
| 390 | + array_push($linkArray, Data::getLink($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
| 391 | 391 | |
| 392 | - array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
| 392 | + array_push($linkArray, Data::getLink($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - foreach ($this->getDatas () as $data) |
|
| 395 | + foreach ($this->getDatas() as $data) |
|
| 396 | 396 | { |
| 397 | - if ($data->isKnownType ()) |
|
| 397 | + if ($data->isKnownType()) |
|
| 398 | 398 | { |
| 399 | - array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
|
| 399 | + array_push($linkArray, $data->getDataLink(Link::OPDS_ACQUISITION_TYPE, $data->format)); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - foreach ($this->getAuthors () as $author) { |
|
| 404 | - array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); |
|
| 403 | + foreach ($this->getAuthors() as $author) { |
|
| 404 | + array_push($linkArray, new LinkNavigation($author->getUri(), "related", str_format(localize("bookentry.author"), localize("splitByLetter.book.other"), $author->name))); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - $serie = $this->getSerie (); |
|
| 408 | - if (!is_null ($serie)) { |
|
| 409 | - array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); |
|
| 407 | + $serie = $this->getSerie(); |
|
| 408 | + if (!is_null($serie)) { |
|
| 409 | + array_push($linkArray, new LinkNavigation($serie->getUri(), "related", str_format(localize("content.series.data"), $this->seriesIndex, $serie->name))); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | return $linkArray; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | |
| 416 | - public function getEntry () { |
|
| 417 | - return new EntryBook ($this->getTitle (), $this->getEntryId (), |
|
| 418 | - $this->getComment (), "text/html", |
|
| 419 | - $this->getLinkArray (), $this); |
|
| 416 | + public function getEntry() { |
|
| 417 | + return new EntryBook($this->getTitle(), $this->getEntryId(), |
|
| 418 | + $this->getComment(), "text/html", |
|
| 419 | + $this->getLinkArray(), $this); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | public static function getBookCount($database = NULL) { |
| 423 | - return parent::executeQuerySingle ('select count(*) from books', $database); |
|
| 423 | + return parent::executeQuerySingle('select count(*) from books', $database); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | public static function getCount() { |
| 427 | 427 | global $config; |
| 428 | - $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
|
| 428 | + $nBooks = parent::executeQuerySingle('select count(*) from books'); |
|
| 429 | 429 | $result = array(); |
| 430 | - $entry = new Entry (localize ("allbooks.title"), |
|
| 430 | + $entry = new Entry(localize("allbooks.title"), |
|
| 431 | 431 | self::ALL_BOOKS_ID, |
| 432 | - str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
| 433 | - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
| 434 | - array_push ($result, $entry); |
|
| 432 | + str_format(localize("allbooks.alphabetical", $nBooks), $nBooks), "text", |
|
| 433 | + array(new LinkNavigation("?page=" . parent::PAGE_ALL_BOOKS)), "", $nBooks); |
|
| 434 | + array_push($result, $entry); |
|
| 435 | 435 | if ($config['cops_recentbooks_limit'] > 0) { |
| 436 | - $entry = new Entry (localize ("recent.title"), |
|
| 436 | + $entry = new Entry(localize("recent.title"), |
|
| 437 | 437 | self::ALL_RECENT_BOOKS_ID, |
| 438 | - str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
| 439 | - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
| 440 | - array_push ($result, $entry); |
|
| 438 | + str_format(localize("recent.list"), $config['cops_recentbooks_limit']), "text", |
|
| 439 | + array(new LinkNavigation("?page=" . parent::PAGE_ALL_RECENT_BOOKS)), "", $config['cops_recentbooks_limit']); |
|
| 440 | + array_push($result, $entry); |
|
| 441 | 441 | } |
| 442 | 442 | return $result; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | public static function getBooksByAuthor($authorId, $n) { |
| 446 | - return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
|
| 446 | + return self::getEntryArray(self::SQL_BOOKS_BY_AUTHOR, array($authorId), $n); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | public static function getBooksByRating($ratingId, $n) { |
| 450 | - return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); |
|
| 450 | + return self::getEntryArray(self::SQL_BOOKS_BY_RATING, array($ratingId), $n); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | public static function getBooksByPublisher($publisherId, $n) { |
| 454 | - return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); |
|
| 454 | + return self::getEntryArray(self::SQL_BOOKS_BY_PUBLISHER, array($publisherId), $n); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | public static function getBooksBySeries($serieId, $n) { |
| 458 | - return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
|
| 458 | + return self::getEntryArray(self::SQL_BOOKS_BY_SERIE, array($serieId), $n); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | public static function getBooksByTag($tagId, $n) { |
| 462 | - return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
|
| 462 | + return self::getEntryArray(self::SQL_BOOKS_BY_TAG, array($tagId), $n); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | public static function getBooksByLanguage($languageId, $n) { |
| 466 | - return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
|
| 466 | + return self::getEntryArray(self::SQL_BOOKS_BY_LANGUAGE, array($languageId), $n); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | public static function getBooksByCustom($customId, $id, $n) { |
| 470 | - $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId)); |
|
| 471 | - return self::getEntryArray ($query, array ($id), $n); |
|
| 470 | + $query = str_format(self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName($customId), CustomColumn::getTableLinkColumn($customId)); |
|
| 471 | + return self::getEntryArray($query, array($id), $n); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | public static function getBookById($bookId) { |
| 475 | - $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
|
| 475 | + $result = parent::getDb()->prepare('select ' . self::BOOK_COLUMNS . ' |
|
| 476 | 476 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 477 | 477 | where books.id = ?'); |
| 478 | - $result->execute (array ($bookId)); |
|
| 479 | - while ($post = $result->fetchObject ()) |
|
| 478 | + $result->execute(array($bookId)); |
|
| 479 | + while ($post = $result->fetchObject()) |
|
| 480 | 480 | { |
| 481 | - $book = new Book ($post); |
|
| 481 | + $book = new Book($post); |
|
| 482 | 482 | return $book; |
| 483 | 483 | } |
| 484 | 484 | return NULL; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | public static function getBookByDataId($dataId) { |
| 488 | - $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
|
| 488 | + $result = parent::getDb()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
|
| 489 | 489 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 490 | 490 | where data.book = books.id and data.id = ?'); |
| 491 | - $result->execute (array ($dataId)); |
|
| 492 | - while ($post = $result->fetchObject ()) |
|
| 491 | + $result->execute(array($dataId)); |
|
| 492 | + while ($post = $result->fetchObject()) |
|
| 493 | 493 | { |
| 494 | - $book = new Book ($post); |
|
| 495 | - $data = new Data ($post, $book); |
|
| 494 | + $book = new Book($post); |
|
| 495 | + $data = new Data($post, $book); |
|
| 496 | 496 | $data->id = $dataId; |
| 497 | - $book->datas = array ($data); |
|
| 497 | + $book->datas = array($data); |
|
| 498 | 498 | return $book; |
| 499 | 499 | } |
| 500 | 500 | return NULL; |
@@ -502,18 +502,18 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
| 504 | 504 | $i = 0; |
| 505 | - $critArray = array (); |
|
| 506 | - foreach (array (PageQueryResult::SCOPE_AUTHOR, |
|
| 505 | + $critArray = array(); |
|
| 506 | + foreach (array(PageQueryResult::SCOPE_AUTHOR, |
|
| 507 | 507 | PageQueryResult::SCOPE_TAG, |
| 508 | 508 | PageQueryResult::SCOPE_SERIES, |
| 509 | 509 | PageQueryResult::SCOPE_PUBLISHER, |
| 510 | 510 | PageQueryResult::SCOPE_BOOK) as $key) { |
| 511 | - if (in_array($key, getCurrentOption ('ignored_categories')) || |
|
| 512 | - (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) { |
|
| 511 | + if (in_array($key, getCurrentOption('ignored_categories')) || |
|
| 512 | + (!array_key_exists($key, $query) && !array_key_exists("all", $query))) { |
|
| 513 | 513 | $critArray [$i] = self::BAD_SEARCH; |
| 514 | 514 | } |
| 515 | 515 | else { |
| 516 | - if (array_key_exists ($key, $query)) { |
|
| 516 | + if (array_key_exists($key, $query)) { |
|
| 517 | 517 | $critArray [$i] = $query [$key]; |
| 518 | 518 | } else { |
| 519 | 519 | $critArray [$i] = $query ["all"]; |
@@ -521,48 +521,48 @@ discard block |
||
| 521 | 521 | } |
| 522 | 522 | $i++; |
| 523 | 523 | } |
| 524 | - return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
|
| 524 | + return self::getEntryArray(self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | public static function getBooks($n) { |
| 528 | - list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n); |
|
| 529 | - return array ($entryArray, $totalNumber); |
|
| 528 | + list ($entryArray, $totalNumber) = self::getEntryArray(self::SQL_BOOKS_ALL, array(), $n); |
|
| 529 | + return array($entryArray, $totalNumber); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | public static function getAllBooks() { |
| 533 | - list (, $result) = parent::executeQuery ("select {0} |
|
| 533 | + list (, $result) = parent::executeQuery("select {0} |
|
| 534 | 534 | from books |
| 535 | 535 | group by substr (upper (sort), 1, 1) |
| 536 | -order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
|
| 536 | +order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString(), array(), -1); |
|
| 537 | 537 | $entryArray = array(); |
| 538 | - while ($post = $result->fetchObject ()) |
|
| 538 | + while ($post = $result->fetchObject()) |
|
| 539 | 539 | { |
| 540 | - array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
|
| 541 | - str_format (localize("bookword", $post->count), $post->count), "text", |
|
| 542 | - array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
| 540 | + array_push($entryArray, new Entry($post->title, Book::getEntryIdByLetter($post->title), |
|
| 541 | + str_format(localize("bookword", $post->count), $post->count), "text", |
|
| 542 | + array(new LinkNavigation("?page=" . parent::PAGE_ALL_BOOKS_LETTER . "&id=" . rawurlencode($post->title))), "", $post->count)); |
|
| 543 | 543 | } |
| 544 | 544 | return $entryArray; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
| 548 | - return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
|
| 548 | + return self::getEntryArray(self::SQL_BOOKS_BY_FIRST_LETTER, array($letter . "%"), $n, $database, $numberPerPage); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 552 | - list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
|
| 551 | + public static function getEntryArray($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 552 | + list ($totalNumber, $result) = parent::executeQuery($query, self::BOOK_COLUMNS, self::getFilterString(), $params, $n, $database, $numberPerPage); |
|
| 553 | 553 | $entryArray = array(); |
| 554 | - while ($post = $result->fetchObject ()) |
|
| 554 | + while ($post = $result->fetchObject()) |
|
| 555 | 555 | { |
| 556 | - $book = new Book ($post); |
|
| 557 | - array_push ($entryArray, $book->getEntry ()); |
|
| 556 | + $book = new Book($post); |
|
| 557 | + array_push($entryArray, $book->getEntry()); |
|
| 558 | 558 | } |
| 559 | - return array ($entryArray, $totalNumber); |
|
| 559 | + return array($entryArray, $totalNumber); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | |
| 563 | 563 | public static function getAllRecentBooks() { |
| 564 | 564 | global $config; |
| 565 | - list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); |
|
| 565 | + list ($entryArray,) = self::getEntryArray(self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array(), -1); |
|
| 566 | 566 | return $entryArray; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -80,7 +80,8 @@ discard block |
||
| 80 | 80 | public $format = array (); |
| 81 | 81 | |
| 82 | 82 | |
| 83 | - public function __construct($line) { |
|
| 83 | + public function __construct($line) |
|
| 84 | + { |
|
| 84 | 85 | $this->id = $line->id; |
| 85 | 86 | $this->title = $line->title; |
| 86 | 87 | $this->timestamp = strtotime ($line->timestamp); |
@@ -98,60 +99,73 @@ discard block |
||
| 98 | 99 | $this->rating = $line->rating; |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | - public function getEntryId () { |
|
| 102 | + public function getEntryId () |
|
| 103 | + { |
|
| 102 | 104 | return self::ALL_BOOKS_UUID.":".$this->uuid; |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 107 | + public static function getEntryIdByLetter ($startingLetter) |
|
| 108 | + { |
|
| 106 | 109 | return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | - public function getUri () { |
|
| 112 | + public function getUri () |
|
| 113 | + { |
|
| 110 | 114 | return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | - public function getDetailUrl () { |
|
| 117 | + public function getDetailUrl () |
|
| 118 | + { |
|
| 114 | 119 | $urlParam = $this->getUri (); |
| 115 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 120 | + if (!is_null (GetUrlParam (DB))) { |
|
| 121 | + $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 122 | + } |
|
| 116 | 123 | return 'index.php' . $urlParam; |
| 117 | 124 | } |
| 118 | 125 | |
| 119 | - public function getTitle () { |
|
| 126 | + public function getTitle () |
|
| 127 | + { |
|
| 120 | 128 | return $this->title; |
| 121 | 129 | } |
| 122 | 130 | |
| 123 | 131 | /* Other class (author, series, tag, ...) initialization and accessors */ |
| 124 | 132 | |
| 125 | - public function getAuthors () { |
|
| 133 | + public function getAuthors () |
|
| 134 | + { |
|
| 126 | 135 | if (is_null ($this->authors)) { |
| 127 | 136 | $this->authors = Author::getAuthorByBookId ($this->id); |
| 128 | 137 | } |
| 129 | 138 | return $this->authors; |
| 130 | 139 | } |
| 131 | 140 | |
| 132 | - public function getAuthorsName () { |
|
| 141 | + public function getAuthorsName () |
|
| 142 | + { |
|
| 133 | 143 | return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
| 134 | 144 | } |
| 135 | 145 | |
| 136 | - public function getAuthorsSort () { |
|
| 146 | + public function getAuthorsSort () |
|
| 147 | + { |
|
| 137 | 148 | return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
| 138 | 149 | } |
| 139 | 150 | |
| 140 | - public function getPublisher () { |
|
| 151 | + public function getPublisher () |
|
| 152 | + { |
|
| 141 | 153 | if (is_null ($this->publisher)) { |
| 142 | 154 | $this->publisher = Publisher::getPublisherByBookId ($this->id); |
| 143 | 155 | } |
| 144 | 156 | return $this->publisher; |
| 145 | 157 | } |
| 146 | 158 | |
| 147 | - public function getSerie () { |
|
| 159 | + public function getSerie () |
|
| 160 | + { |
|
| 148 | 161 | if (is_null ($this->serie)) { |
| 149 | 162 | $this->serie = Serie::getSerieByBookId ($this->id); |
| 150 | 163 | } |
| 151 | 164 | return $this->serie; |
| 152 | 165 | } |
| 153 | 166 | |
| 154 | - public function getLanguages () { |
|
| 167 | + public function getLanguages () |
|
| 168 | + { |
|
| 155 | 169 | $lang = array (); |
| 156 | 170 | $result = parent::getDb ()->prepare('select languages.lang_code |
| 157 | 171 | from books_languages_link, languages |
@@ -159,14 +173,14 @@ discard block |
||
| 159 | 173 | and book = ? |
| 160 | 174 | order by item_order'); |
| 161 | 175 | $result->execute (array ($this->id)); |
| 162 | - while ($post = $result->fetchObject ()) |
|
| 163 | - { |
|
| 176 | + while ($post = $result->fetchObject ()) { |
|
| 164 | 177 | array_push ($lang, Language::getLanguageString($post->lang_code)); |
| 165 | 178 | } |
| 166 | 179 | return implode (", ", $lang); |
| 167 | 180 | } |
| 168 | 181 | |
| 169 | - public function getTags () { |
|
| 182 | + public function getTags () |
|
| 183 | + { |
|
| 170 | 184 | if (is_null ($this->tags)) { |
| 171 | 185 | $this->tags = array (); |
| 172 | 186 | |
@@ -176,15 +190,15 @@ discard block |
||
| 176 | 190 | and book = ? |
| 177 | 191 | order by name'); |
| 178 | 192 | $result->execute (array ($this->id)); |
| 179 | - while ($post = $result->fetchObject ()) |
|
| 180 | - { |
|
| 193 | + while ($post = $result->fetchObject ()) { |
|
| 181 | 194 | array_push ($this->tags, new Tag ($post)); |
| 182 | 195 | } |
| 183 | 196 | } |
| 184 | 197 | return $this->tags; |
| 185 | 198 | } |
| 186 | 199 | |
| 187 | - public function getTagsName () { |
|
| 200 | + public function getTagsName () |
|
| 201 | + { |
|
| 188 | 202 | return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
| 189 | 203 | } |
| 190 | 204 | |
@@ -198,9 +212,12 @@ discard block |
||
| 198 | 212 | |
| 199 | 213 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
| 200 | 214 | |
| 201 | - public static function getFilterString () { |
|
| 215 | + public static function getFilterString () |
|
| 216 | + { |
|
| 202 | 217 | $filter = getURLParam ("tag", NULL); |
| 203 | - if (empty ($filter)) return ""; |
|
| 218 | + if (empty ($filter)) { |
|
| 219 | + return ""; |
|
| 220 | + } |
|
| 204 | 221 | |
| 205 | 222 | $exists = true; |
| 206 | 223 | if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
@@ -240,7 +257,8 @@ discard block |
||
| 240 | 257 | return reset ($reduced); |
| 241 | 258 | } |
| 242 | 259 | |
| 243 | - public function getRating () { |
|
| 260 | + public function getRating () |
|
| 261 | + { |
|
| 244 | 262 | if (is_null ($this->rating) || $this->rating == 0) { |
| 245 | 263 | return ""; |
| 246 | 264 | } |
@@ -254,7 +272,8 @@ discard block |
||
| 254 | 272 | return $retour; |
| 255 | 273 | } |
| 256 | 274 | |
| 257 | - public function getPubDate () { |
|
| 275 | + public function getPubDate () |
|
| 276 | + { |
|
| 258 | 277 | if (empty ($this->pubdate)) { |
| 259 | 278 | return ""; |
| 260 | 279 | } |
@@ -265,23 +284,22 @@ discard block |
||
| 265 | 284 | return ""; |
| 266 | 285 | } |
| 267 | 286 | |
| 268 | - public function getComment ($withSerie = true) { |
|
| 287 | + public function getComment ($withSerie = true) |
|
| 288 | + { |
|
| 269 | 289 | $addition = ""; |
| 270 | 290 | $se = $this->getSerie (); |
| 271 | 291 | if (!is_null ($se) && $withSerie) { |
| 272 | 292 | $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
| 273 | 293 | } |
| 274 | - if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
|
| 275 | - { |
|
| 294 | + if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) { |
|
| 276 | 295 | return $addition . html2xhtml ($this->comment); |
| 277 | - } |
|
| 278 | - else |
|
| 279 | - { |
|
| 296 | + } else { |
|
| 280 | 297 | return $addition . htmlspecialchars ($this->comment); |
| 281 | 298 | } |
| 282 | 299 | } |
| 283 | 300 | |
| 284 | - public function getDataFormat ($format) { |
|
| 301 | + public function getDataFormat ($format) |
|
| 302 | + { |
|
| 285 | 303 | $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
| 286 | 304 | return $data->format == $format; |
| 287 | 305 | }); |
@@ -290,23 +308,19 @@ discard block |
||
| 290 | 308 | |
| 291 | 309 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
| 292 | 310 | { |
| 293 | - if ($extension == "jpg") |
|
| 294 | - { |
|
| 311 | + if ($extension == "jpg") { |
|
| 295 | 312 | $file = "cover.jpg"; |
| 296 | - } |
|
| 297 | - else |
|
| 298 | - { |
|
| 313 | + } else { |
|
| 299 | 314 | $data = $this->getDataById ($idData); |
| 300 | - if (!$data) return NULL; |
|
| 315 | + if (!$data) { |
|
| 316 | + return NULL; |
|
| 317 | + } |
|
| 301 | 318 | $file = $data->name . "." . strtolower ($data->format); |
| 302 | 319 | } |
| 303 | 320 | |
| 304 | - if ($relative) |
|
| 305 | - { |
|
| 321 | + if ($relative) { |
|
| 306 | 322 | return $this->relativePath."/".$file; |
| 307 | - } |
|
| 308 | - else |
|
| 309 | - { |
|
| 323 | + } else { |
|
| 310 | 324 | return $this->path."/".$file; |
| 311 | 325 | } |
| 312 | 326 | } |
@@ -316,8 +330,7 @@ discard block |
||
| 316 | 330 | global $config; |
| 317 | 331 | $data = $this->getDataById ($idData); |
| 318 | 332 | |
| 319 | - try |
|
| 320 | - { |
|
| 333 | + try { |
|
| 321 | 334 | $epub = new EPub ($data->getLocalPath ()); |
| 322 | 335 | |
| 323 | 336 | $epub->Title ($this->title); |
@@ -340,14 +353,13 @@ discard block |
||
| 340 | 353 | $epub->updateForKepub (); |
| 341 | 354 | } |
| 342 | 355 | $epub->download ($data->getUpdatedFilenameEpub ()); |
| 343 | - } |
|
| 344 | - catch (Exception $e) |
|
| 345 | - { |
|
| 356 | + } catch (Exception $e) { |
|
| 346 | 357 | echo "Exception : " . $e->getMessage(); |
| 347 | 358 | } |
| 348 | 359 | } |
| 349 | 360 | |
| 350 | - public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
| 361 | + public function getThumbnail ($width, $height, $outputfile = NULL) |
|
| 362 | + { |
|
| 351 | 363 | if (is_null ($width) && is_null ($height)) { |
| 352 | 364 | return false; |
| 353 | 365 | } |
@@ -386,17 +398,14 @@ discard block |
||
| 386 | 398 | { |
| 387 | 399 | $linkArray = array(); |
| 388 | 400 | |
| 389 | - if ($this->hasCover) |
|
| 390 | - { |
|
| 401 | + if ($this->hasCover) { |
|
| 391 | 402 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
| 392 | 403 | |
| 393 | 404 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
| 394 | 405 | } |
| 395 | 406 | |
| 396 | - foreach ($this->getDatas () as $data) |
|
| 397 | - { |
|
| 398 | - if ($data->isKnownType ()) |
|
| 399 | - { |
|
| 407 | + foreach ($this->getDatas () as $data) { |
|
| 408 | + if ($data->isKnownType ()) { |
|
| 400 | 409 | array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
| 401 | 410 | } |
| 402 | 411 | } |
@@ -414,17 +423,20 @@ discard block |
||
| 414 | 423 | } |
| 415 | 424 | |
| 416 | 425 | |
| 417 | - public function getEntry () { |
|
| 426 | + public function getEntry () |
|
| 427 | + { |
|
| 418 | 428 | return new EntryBook ($this->getTitle (), $this->getEntryId (), |
| 419 | 429 | $this->getComment (), "text/html", |
| 420 | 430 | $this->getLinkArray (), $this); |
| 421 | 431 | } |
| 422 | 432 | |
| 423 | - public static function getBookCount($database = NULL) { |
|
| 433 | + public static function getBookCount($database = NULL) |
|
| 434 | + { |
|
| 424 | 435 | return parent::executeQuerySingle ('select count(*) from books', $database); |
| 425 | 436 | } |
| 426 | 437 | |
| 427 | - public static function getCount() { |
|
| 438 | + public static function getCount() |
|
| 439 | + { |
|
| 428 | 440 | global $config; |
| 429 | 441 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
| 430 | 442 | $result = array(); |
@@ -443,55 +455,62 @@ discard block |
||
| 443 | 455 | return $result; |
| 444 | 456 | } |
| 445 | 457 | |
| 446 | - public static function getBooksByAuthor($authorId, $n) { |
|
| 458 | + public static function getBooksByAuthor($authorId, $n) |
|
| 459 | + { |
|
| 447 | 460 | return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
| 448 | 461 | } |
| 449 | 462 | |
| 450 | - public static function getBooksByRating($ratingId, $n) { |
|
| 463 | + public static function getBooksByRating($ratingId, $n) |
|
| 464 | + { |
|
| 451 | 465 | return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); |
| 452 | 466 | } |
| 453 | 467 | |
| 454 | - public static function getBooksByPublisher($publisherId, $n) { |
|
| 468 | + public static function getBooksByPublisher($publisherId, $n) |
|
| 469 | + { |
|
| 455 | 470 | return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); |
| 456 | 471 | } |
| 457 | 472 | |
| 458 | - public static function getBooksBySeries($serieId, $n) { |
|
| 473 | + public static function getBooksBySeries($serieId, $n) |
|
| 474 | + { |
|
| 459 | 475 | return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
| 460 | 476 | } |
| 461 | 477 | |
| 462 | - public static function getBooksByTag($tagId, $n) { |
|
| 478 | + public static function getBooksByTag($tagId, $n) |
|
| 479 | + { |
|
| 463 | 480 | return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
| 464 | 481 | } |
| 465 | 482 | |
| 466 | - public static function getBooksByLanguage($languageId, $n) { |
|
| 483 | + public static function getBooksByLanguage($languageId, $n) |
|
| 484 | + { |
|
| 467 | 485 | return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
| 468 | 486 | } |
| 469 | 487 | |
| 470 | - public static function getBooksByCustom($customId, $id, $n) { |
|
| 488 | + public static function getBooksByCustom($customId, $id, $n) |
|
| 489 | + { |
|
| 471 | 490 | $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId)); |
| 472 | 491 | return self::getEntryArray ($query, array ($id), $n); |
| 473 | 492 | } |
| 474 | 493 | |
| 475 | - public static function getBookById($bookId) { |
|
| 494 | + public static function getBookById($bookId) |
|
| 495 | + { |
|
| 476 | 496 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
| 477 | 497 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 478 | 498 | where books.id = ?'); |
| 479 | 499 | $result->execute (array ($bookId)); |
| 480 | - while ($post = $result->fetchObject ()) |
|
| 481 | - { |
|
| 500 | + while ($post = $result->fetchObject ()) { |
|
| 482 | 501 | $book = new Book ($post); |
| 483 | 502 | return $book; |
| 484 | 503 | } |
| 485 | 504 | return NULL; |
| 486 | 505 | } |
| 487 | 506 | |
| 488 | - public static function getBookByDataId($dataId) { |
|
| 507 | + public static function getBookByDataId($dataId) |
|
| 508 | + { |
|
| 489 | 509 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
| 490 | 510 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 491 | 511 | where data.book = books.id and data.id = ?'); |
| 492 | 512 | $result->execute (array ($dataId)); |
| 493 | - while ($post = $result->fetchObject ()) |
|
| 494 | - { |
|
| 513 | + while ($post = $result->fetchObject ()) { |
|
| 495 | 514 | $book = new Book ($post); |
| 496 | 515 | $data = new Data ($post, $book); |
| 497 | 516 | $data->id = $dataId; |
@@ -501,7 +520,8 @@ discard block |
||
| 501 | 520 | return NULL; |
| 502 | 521 | } |
| 503 | 522 | |
| 504 | - public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 523 | + public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) |
|
| 524 | + { |
|
| 505 | 525 | $i = 0; |
| 506 | 526 | $critArray = array (); |
| 507 | 527 | foreach (array (PageQueryResult::SCOPE_AUTHOR, |
@@ -512,8 +532,7 @@ discard block |
||
| 512 | 532 | if (in_array($key, getCurrentOption ('ignored_categories')) || |
| 513 | 533 | (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) { |
| 514 | 534 | $critArray [$i] = self::BAD_SEARCH; |
| 515 | - } |
|
| 516 | - else { |
|
| 535 | + } else { |
|
| 517 | 536 | if (array_key_exists ($key, $query)) { |
| 518 | 537 | $critArray [$i] = $query [$key]; |
| 519 | 538 | } else { |
@@ -525,19 +544,20 @@ discard block |
||
| 525 | 544 | return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
| 526 | 545 | } |
| 527 | 546 | |
| 528 | - public static function getBooks($n) { |
|
| 547 | + public static function getBooks($n) |
|
| 548 | + { |
|
| 529 | 549 | list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n); |
| 530 | 550 | return array ($entryArray, $totalNumber); |
| 531 | 551 | } |
| 532 | 552 | |
| 533 | - public static function getAllBooks() { |
|
| 553 | + public static function getAllBooks() |
|
| 554 | + { |
|
| 534 | 555 | list (, $result) = parent::executeQuery ("select {0} |
| 535 | 556 | from books |
| 536 | 557 | group by substr (upper (sort), 1, 1) |
| 537 | 558 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
| 538 | 559 | $entryArray = array(); |
| 539 | - while ($post = $result->fetchObject ()) |
|
| 540 | - { |
|
| 560 | + while ($post = $result->fetchObject ()) { |
|
| 541 | 561 | array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
| 542 | 562 | str_format (localize("bookword", $post->count), $post->count), "text", |
| 543 | 563 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
@@ -545,15 +565,16 @@ discard block |
||
| 545 | 565 | return $entryArray; |
| 546 | 566 | } |
| 547 | 567 | |
| 548 | - public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 568 | + public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) |
|
| 569 | + { |
|
| 549 | 570 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
| 550 | 571 | } |
| 551 | 572 | |
| 552 | - public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 573 | + public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 574 | + { |
|
| 553 | 575 | list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
| 554 | 576 | $entryArray = array(); |
| 555 | - while ($post = $result->fetchObject ()) |
|
| 556 | - { |
|
| 577 | + while ($post = $result->fetchObject ()) { |
|
| 557 | 578 | $book = new Book ($post); |
| 558 | 579 | array_push ($entryArray, $book->getEntry ()); |
| 559 | 580 | } |
@@ -561,7 +582,8 @@ discard block |
||
| 561 | 582 | } |
| 562 | 583 | |
| 563 | 584 | |
| 564 | - public static function getAllRecentBooks() { |
|
| 585 | + public static function getAllRecentBooks() |
|
| 586 | + { |
|
| 565 | 587 | global $config; |
| 566 | 588 | list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); |
| 567 | 589 | return $entryArray; |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | public $seriesIndex; |
| 71 | 71 | public $comment; |
| 72 | 72 | public $rating; |
| 73 | - public $datas = NULL; |
|
| 74 | - public $authors = NULL; |
|
| 75 | - public $publisher = NULL; |
|
| 76 | - public $serie = NULL; |
|
| 77 | - public $tags = NULL; |
|
| 78 | - public $languages = NULL; |
|
| 73 | + public $datas = null; |
|
| 74 | + public $authors = null; |
|
| 75 | + public $publisher = null; |
|
| 76 | + public $serie = null; |
|
| 77 | + public $tags = null; |
|
| 78 | + public $languages = null; |
|
| 79 | 79 | public $format = array (); |
| 80 | 80 | |
| 81 | 81 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
| 199 | 199 | |
| 200 | 200 | public static function getFilterString () { |
| 201 | - $filter = getURLParam ("tag", NULL); |
|
| 201 | + $filter = getURLParam ("tag", null); |
|
| 202 | 202 | if (empty ($filter)) return ""; |
| 203 | 203 | |
| 204 | 204 | $exists = true; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | { |
| 221 | 221 | $bestFormatForKindle = array ("EPUB", "PDF", "AZW3", "MOBI"); |
| 222 | 222 | $bestRank = -1; |
| 223 | - $bestData = NULL; |
|
| 223 | + $bestData = null; |
|
| 224 | 224 | foreach ($this->getDatas () as $data) { |
| 225 | 225 | $key = array_search ($data->format, $bestFormatForKindle); |
| 226 | 226 | if ($key !== false && $key > $bestRank) { |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | return reset ($reduced); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public function getFilePath ($extension, $idData = NULL, $relative = false) |
|
| 290 | + public function getFilePath ($extension, $idData = null, $relative = false) |
|
| 291 | 291 | { |
| 292 | 292 | if ($extension == "jpg") |
| 293 | 293 | { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | else |
| 297 | 297 | { |
| 298 | 298 | $data = $this->getDataById ($idData); |
| 299 | - if (!$data) return NULL; |
|
| 299 | + if (!$data) return null; |
|
| 300 | 300 | $file = $data->name . "." . strtolower ($data->format); |
| 301 | 301 | } |
| 302 | 302 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
| 349 | + public function getThumbnail ($width, $height, $outputfile = null) { |
|
| 350 | 350 | if (is_null ($width) && is_null ($height)) { |
| 351 | 351 | return false; |
| 352 | 352 | } |
@@ -387,9 +387,9 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | if ($this->hasCover) |
| 389 | 389 | { |
| 390 | - array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
|
| 390 | + array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", null)); |
|
| 391 | 391 | |
| 392 | - array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
|
| 392 | + array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", null)); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | foreach ($this->getDatas () as $data) |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | $this->getLinkArray (), $this); |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - public static function getBookCount($database = NULL) { |
|
| 422 | + public static function getBookCount($database = null) { |
|
| 423 | 423 | return parent::executeQuerySingle ('select count(*) from books', $database); |
| 424 | 424 | } |
| 425 | 425 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | $book = new Book ($post); |
| 482 | 482 | return $book; |
| 483 | 483 | } |
| 484 | - return NULL; |
|
| 484 | + return null; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | public static function getBookByDataId($dataId) { |
@@ -497,10 +497,10 @@ discard block |
||
| 497 | 497 | $book->datas = array ($data); |
| 498 | 498 | return $book; |
| 499 | 499 | } |
| 500 | - return NULL; |
|
| 500 | + return null; |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 503 | + public static function getBooksByQuery($query, $n, $database = null, $numberPerPage = null) { |
|
| 504 | 504 | $i = 0; |
| 505 | 505 | $critArray = array (); |
| 506 | 506 | foreach (array (PageQueryResult::SCOPE_AUTHOR, |
@@ -544,11 +544,11 @@ discard block |
||
| 544 | 544 | return $entryArray; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 547 | + public static function getBooksByStartingLetter($letter, $n, $database = null, $numberPerPage = null) { |
|
| 548 | 548 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 551 | + public static function getEntryArray ($query, $params, $n, $database = null, $numberPerPage = null) { |
|
| 552 | 552 | list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
| 553 | 553 | $entryArray = array(); |
| 554 | 554 | while ($post = $result->fetchObject ()) |
@@ -141,6 +141,9 @@ discard block |
||
| 141 | 141 | return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | + /** |
|
| 145 | + * @param Book $book |
|
| 146 | + */ |
|
| 144 | 147 | public static function getDataByBook ($book) { |
| 145 | 148 | $out = array (); |
| 146 | 149 | $result = parent::getDb ()->prepare('select id, format, name |
@@ -154,6 +157,9 @@ discard block |
||
| 154 | 157 | return $out; |
| 155 | 158 | } |
| 156 | 159 | |
| 160 | + /** |
|
| 161 | + * @param string $urlParam |
|
| 162 | + */ |
|
| 157 | 163 | public static function handleThumbnailLink ($urlParam, $height) { |
| 158 | 164 | global $config; |
| 159 | 165 | |
@@ -173,6 +179,10 @@ discard block |
||
| 173 | 179 | return $urlParam; |
| 174 | 180 | } |
| 175 | 181 | |
| 182 | + /** |
|
| 183 | + * @param string $type |
|
| 184 | + * @param string $filename |
|
| 185 | + */ |
|
| 176 | 186 | public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
| 177 | 187 | { |
| 178 | 188 | global $config; |
@@ -58,25 +58,25 @@ discard block |
||
| 58 | 58 | $this->id = $post->id; |
| 59 | 59 | $this->name = $post->name; |
| 60 | 60 | $this->format = $post->format; |
| 61 | - $this->realFormat = str_replace ("ORIGINAL_", "", $post->format); |
|
| 62 | - $this->extension = strtolower ($this->realFormat); |
|
| 61 | + $this->realFormat = str_replace("ORIGINAL_", "", $post->format); |
|
| 62 | + $this->extension = strtolower($this->realFormat); |
|
| 63 | 63 | $this->book = $book; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function isKnownType () { |
|
| 67 | - return array_key_exists ($this->extension, self::$mimetypes); |
|
| 66 | + public function isKnownType() { |
|
| 67 | + return array_key_exists($this->extension, self::$mimetypes); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function getMimeType () { |
|
| 70 | + public function getMimeType() { |
|
| 71 | 71 | $result = "application/octet-stream"; |
| 72 | - if ($this->isKnownType ()) { |
|
| 72 | + if ($this->isKnownType()) { |
|
| 73 | 73 | return self::$mimetypes [$this->extension]; |
| 74 | 74 | } elseif (function_exists('finfo_open') === true) { |
| 75 | 75 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 76 | 76 | |
| 77 | 77 | if (is_resource($finfo) === true) |
| 78 | 78 | { |
| 79 | - $result = finfo_file($finfo, $this->getLocalPath ()); |
|
| 79 | + $result = finfo_file($finfo, $this->getLocalPath()); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | finfo_close($finfo); |
@@ -85,80 +85,80 @@ discard block |
||
| 85 | 85 | return $result; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - public function isEpubValidOnKobo () { |
|
| 88 | + public function isEpubValidOnKobo() { |
|
| 89 | 89 | return $this->format == "EPUB" || $this->format == "KEPUB"; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function getFilename () { |
|
| 93 | - return $this->name . "." . strtolower ($this->format); |
|
| 92 | + public function getFilename() { |
|
| 93 | + return $this->name . "." . strtolower($this->format); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function getUpdatedFilename () { |
|
| 97 | - return $this->book->getAuthorsSort () . " - " . $this->book->title; |
|
| 96 | + public function getUpdatedFilename() { |
|
| 97 | + return $this->book->getAuthorsSort() . " - " . $this->book->title; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function getUpdatedFilenameEpub () { |
|
| 101 | - return $this->getUpdatedFilename () . ".epub"; |
|
| 100 | + public function getUpdatedFilenameEpub() { |
|
| 101 | + return $this->getUpdatedFilename() . ".epub"; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function getUpdatedFilenameKepub () { |
|
| 105 | - return $this->getUpdatedFilename () . ".kepub.epub"; |
|
| 104 | + public function getUpdatedFilenameKepub() { |
|
| 105 | + return $this->getUpdatedFilename() . ".kepub.epub"; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function getDataLink ($rel, $title = NULL) { |
|
| 108 | + public function getDataLink($rel, $title = NULL) { |
|
| 109 | 109 | global $config; |
| 110 | 110 | |
| 111 | 111 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
| 112 | 112 | return $this->getHtmlLinkWithRewriting($title); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); |
|
| 115 | + return self::getLink($this->book, $this->extension, $this->getMimeType(), $rel, $this->getFilename(), $this->id, $title); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function getHtmlLink () { |
|
| 118 | + public function getHtmlLink() { |
|
| 119 | 119 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function getLocalPath () { |
|
| 123 | - return $this->book->path . "/" . $this->getFilename (); |
|
| 122 | + public function getLocalPath() { |
|
| 123 | + return $this->book->path . "/" . $this->getFilename(); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 126 | + public function getHtmlLinkWithRewriting($title = NULL) { |
|
| 127 | 127 | global $config; |
| 128 | 128 | |
| 129 | 129 | $database = ""; |
| 130 | - if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/"; |
|
| 130 | + if (!is_null(GetUrlParam(DB))) $database = GetUrlParam(DB) . "/"; |
|
| 131 | 131 | |
| 132 | 132 | $href = "download/" . $this->id . "/" . $database; |
| 133 | 133 | |
| 134 | 134 | if ($config['cops_provide_kepub'] == "1" && |
| 135 | - $this->isEpubValidOnKobo () && |
|
| 135 | + $this->isEpubValidOnKobo() && |
|
| 136 | 136 | preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
| 137 | - $href .= rawurlencode ($this->getUpdatedFilenameKepub ()); |
|
| 137 | + $href .= rawurlencode($this->getUpdatedFilenameKepub()); |
|
| 138 | 138 | } else { |
| 139 | - $href .= rawurlencode ($this->getFilename ()); |
|
| 139 | + $href .= rawurlencode($this->getFilename()); |
|
| 140 | 140 | } |
| 141 | - return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
|
| 141 | + return new Link($href, $this->getMimeType(), Link::OPDS_ACQUISITION_TYPE, $title); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - public static function getDataByBook ($book) { |
|
| 145 | - $out = array (); |
|
| 146 | - $result = parent::getDb ()->prepare('select id, format, name |
|
| 144 | + public static function getDataByBook($book) { |
|
| 145 | + $out = array(); |
|
| 146 | + $result = parent::getDb()->prepare('select id, format, name |
|
| 147 | 147 | from data where book = ?'); |
| 148 | - $result->execute (array ($book->id)); |
|
| 148 | + $result->execute(array($book->id)); |
|
| 149 | 149 | |
| 150 | - while ($post = $result->fetchObject ()) |
|
| 150 | + while ($post = $result->fetchObject()) |
|
| 151 | 151 | { |
| 152 | - array_push ($out, new Data ($post, $book)); |
|
| 152 | + array_push($out, new Data($post, $book)); |
|
| 153 | 153 | } |
| 154 | 154 | return $out; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public static function handleThumbnailLink ($urlParam, $height) { |
|
| 157 | + public static function handleThumbnailLink($urlParam, $height) { |
|
| 158 | 158 | global $config; |
| 159 | 159 | |
| 160 | - if (is_null ($height)) { |
|
| 161 | - if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
|
| 160 | + if (is_null($height)) { |
|
| 161 | + if (preg_match('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
|
| 162 | 162 | $height = $config['cops_opds_thumbnail_height']; |
| 163 | 163 | } |
| 164 | 164 | else |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | return $urlParam; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 176 | + public static function getLink($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 177 | 177 | { |
| 178 | 178 | global $config; |
| 179 | 179 | |
| 180 | 180 | $urlParam = addURLParameter("", "data", $idData); |
| 181 | 181 | |
| 182 | - if (Base::useAbsolutePath () || |
|
| 182 | + if (Base::useAbsolutePath() || |
|
| 183 | 183 | $rel == Link::OPDS_THUMBNAIL_TYPE || |
| 184 | 184 | ($type == "epub" && $config['cops_update_epub-metadata'])) |
| 185 | 185 | { |
@@ -188,18 +188,18 @@ discard block |
||
| 188 | 188 | $urlParam = self::handleThumbnailLink($urlParam, $height); |
| 189 | 189 | } |
| 190 | 190 | $urlParam = addURLParameter($urlParam, "id", $book->id); |
| 191 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 191 | + if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB)); |
|
| 192 | 192 | if ($config['cops_thumbnail_handling'] != "1" && |
| 193 | 193 | !empty ($config['cops_thumbnail_handling']) && |
| 194 | 194 | $rel == Link::OPDS_THUMBNAIL_TYPE) { |
| 195 | - return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title); |
|
| 195 | + return new Link($config['cops_thumbnail_handling'], $mime, $rel, $title); |
|
| 196 | 196 | } else { |
| 197 | - return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); |
|
| 197 | + return new Link("fetch.php?" . $urlParam, $mime, $rel, $title); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | else |
| 201 | 201 | { |
| 202 | - return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title); |
|
| 202 | + return new Link(str_replace('%2F', '/', rawurlencode($book->path . "/" . $filename)), $mime, $rel, $title); |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -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 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | return $this->getUpdatedFilename () . ".kepub.epub"; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function getDataLink ($rel, $title = NULL) { |
|
| 108 | + public function getDataLink ($rel, $title = null) { |
|
| 109 | 109 | global $config; |
| 110 | 110 | |
| 111 | 111 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | return $this->book->path . "/" . $this->getFilename (); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 126 | + public function getHtmlLinkWithRewriting ($title = null) { |
|
| 127 | 127 | global $config; |
| 128 | 128 | |
| 129 | 129 | $database = ""; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return $urlParam; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 176 | + public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = null, $height = null) |
|
| 177 | 177 | { |
| 178 | 178 | global $config; |
| 179 | 179 | |
@@ -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)); |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | class LinkFacet extends Link |
| 10 | 10 | { |
| 11 | 11 | public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
| 12 | - 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)); |
|
| 12 | + 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 | 14 | $this->href = parent::getScriptName() . $this->href; |
| 15 | 15 | } |
| 16 | 16 | } |
@@ -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,7 +8,7 @@ |
||
| 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 | parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
| 13 | 13 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
| 14 | 14 | $this->href = parent::getScriptName() . $this->href; |
@@ -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)); |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | 11 | public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
| 12 | - 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; |
|
| 15 | - if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
|
| 12 | + 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; |
|
| 15 | + if (preg_match("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
|
| 16 | 16 | $this->href = "index.php" . $this->href; |
| 17 | 17 | } else { |
| 18 | 18 | $this->href = parent::getScriptName() . $this->href; |
@@ -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,7 +8,7 @@ |
||
| 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 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 13 | 13 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
| 14 | 14 | if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
@@ -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'"; |
@@ -45,11 +45,11 @@ |
||
| 45 | 45 | $this->entryArray = array (); |
| 46 | 46 | |
| 47 | 47 | $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, |
| 48 | - PageQueryResult::SCOPE_TAG, |
|
| 49 | - PageQueryResult::SCOPE_SERIES, |
|
| 50 | - PageQueryResult::SCOPE_PUBLISHER, |
|
| 51 | - PageQueryResult::SCOPE_RATING, |
|
| 52 | - "language"); |
|
| 48 | + PageQueryResult::SCOPE_TAG, |
|
| 49 | + PageQueryResult::SCOPE_SERIES, |
|
| 50 | + PageQueryResult::SCOPE_PUBLISHER, |
|
| 51 | + PageQueryResult::SCOPE_RATING, |
|
| 52 | + "language"); |
|
| 53 | 53 | |
| 54 | 54 | $content = ""; |
| 55 | 55 | array_push ($this->entryArray, new Entry ("Template", "", |
@@ -8,10 +8,10 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class PageCustomize extends Page |
| 10 | 10 | { |
| 11 | - private function isChecked ($key, $testedValue = 1) { |
|
| 12 | - $value = getCurrentOption ($key); |
|
| 13 | - if (is_array ($value)) { |
|
| 14 | - if (in_array ($testedValue, $value)) { |
|
| 11 | + private function isChecked($key, $testedValue = 1) { |
|
| 12 | + $value = getCurrentOption($key); |
|
| 13 | + if (is_array($value)) { |
|
| 14 | + if (in_array($testedValue, $value)) { |
|
| 15 | 15 | return "checked='checked'"; |
| 16 | 16 | } |
| 17 | 17 | } else { |
@@ -22,29 +22,29 @@ discard block |
||
| 22 | 22 | return ""; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - private function isSelected ($key, $value) { |
|
| 26 | - if (getCurrentOption ($key) == $value) { |
|
| 25 | + private function isSelected($key, $value) { |
|
| 26 | + if (getCurrentOption($key) == $value) { |
|
| 27 | 27 | return "selected='selected'"; |
| 28 | 28 | } |
| 29 | 29 | return ""; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private function getStyleList () { |
|
| 33 | - $result = array (); |
|
| 34 | - foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) { |
|
| 35 | - if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { |
|
| 36 | - array_push ($result, $m [1]); |
|
| 32 | + private function getStyleList() { |
|
| 33 | + $result = array(); |
|
| 34 | + foreach (glob("templates/" . getCurrentTemplate() . "/styles/style-*.css") as $filename) { |
|
| 35 | + if (preg_match('/styles\/style-(.*?)\.css/', $filename, $m)) { |
|
| 36 | + array_push($result, $m [1]); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | return $result; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function InitializeContent () |
|
| 42 | + public function InitializeContent() |
|
| 43 | 43 | { |
| 44 | - $this->title = localize ("customize.title"); |
|
| 45 | - $this->entryArray = array (); |
|
| 44 | + $this->title = localize("customize.title"); |
|
| 45 | + $this->entryArray = array(); |
|
| 46 | 46 | |
| 47 | - $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, |
|
| 47 | + $ignoredBaseArray = array(PageQueryResult::SCOPE_AUTHOR, |
|
| 48 | 48 | PageQueryResult::SCOPE_TAG, |
| 49 | 49 | PageQueryResult::SCOPE_SERIES, |
| 50 | 50 | PageQueryResult::SCOPE_PUBLISHER, |
@@ -52,49 +52,49 @@ discard block |
||
| 52 | 52 | "language"); |
| 53 | 53 | |
| 54 | 54 | $content = ""; |
| 55 | - array_push ($this->entryArray, new Entry ("Template", "", |
|
| 55 | + array_push($this->entryArray, new Entry("Template", "", |
|
| 56 | 56 | "<span style='cursor: pointer;' onclick='$.cookie(\"template\", \"bootstrap\", { expires: 365 });window.location=$(\".headleft\").attr(\"href\");'>Click to switch to Bootstrap</span>", "text", |
| 57 | - array ())); |
|
| 57 | + array())); |
|
| 58 | 58 | if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { |
| 59 | 59 | $content .= '<select id="style" onchange="updateCookie (this);">'; |
| 60 | - foreach ($this-> getStyleList () as $filename) { |
|
| 61 | - $content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>"; |
|
| 60 | + foreach ($this-> getStyleList() as $filename) { |
|
| 61 | + $content .= "<option value='{$filename}' " . $this->isSelected("style", $filename) . ">{$filename}</option>"; |
|
| 62 | 62 | } |
| 63 | 63 | $content .= '</select>'; |
| 64 | 64 | } else { |
| 65 | - foreach ($this-> getStyleList () as $filename) { |
|
| 66 | - $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>"; |
|
| 65 | + foreach ($this-> getStyleList() as $filename) { |
|
| 66 | + $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>"; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | - array_push ($this->entryArray, new Entry (localize ("customize.style"), "", |
|
| 69 | + array_push($this->entryArray, new Entry(localize("customize.style"), "", |
|
| 70 | 70 | $content, "text", |
| 71 | - array ())); |
|
| 72 | - if (!useServerSideRendering ()) { |
|
| 73 | - $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked ("use_fancyapps") . ' />'; |
|
| 74 | - array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "", |
|
| 71 | + array())); |
|
| 72 | + if (!useServerSideRendering()) { |
|
| 73 | + $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked("use_fancyapps") . ' />'; |
|
| 74 | + array_push($this->entryArray, new Entry(localize("customize.fancybox"), "", |
|
| 75 | 75 | $content, "text", |
| 76 | - array ())); |
|
| 76 | + array())); |
|
| 77 | 77 | } |
| 78 | - $content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption ("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />'; |
|
| 79 | - array_push ($this->entryArray, new Entry (localize ("customize.paging"), "", |
|
| 78 | + $content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />'; |
|
| 79 | + array_push($this->entryArray, new Entry(localize("customize.paging"), "", |
|
| 80 | 80 | $content, "text", |
| 81 | - array ())); |
|
| 82 | - $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />'; |
|
| 83 | - array_push ($this->entryArray, new Entry (localize ("customize.email"), "", |
|
| 81 | + array())); |
|
| 82 | + $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption("email") . '" />'; |
|
| 83 | + array_push($this->entryArray, new Entry(localize("customize.email"), "", |
|
| 84 | 84 | $content, "text", |
| 85 | - array ())); |
|
| 86 | - $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked ("html_tag_filter") . ' />'; |
|
| 87 | - array_push ($this->entryArray, new Entry (localize ("customize.filter"), "", |
|
| 85 | + array())); |
|
| 86 | + $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked("html_tag_filter") . ' />'; |
|
| 87 | + array_push($this->entryArray, new Entry(localize("customize.filter"), "", |
|
| 88 | 88 | $content, "text", |
| 89 | - array ())); |
|
| 89 | + array())); |
|
| 90 | 90 | $content = ""; |
| 91 | 91 | foreach ($ignoredBaseArray as $key) { |
| 92 | - $keyPlural = preg_replace ('/(ss)$/', 's', $key . "s"); |
|
| 93 | - $content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . '</input> '; |
|
| 92 | + $keyPlural = preg_replace('/(ss)$/', 's', $key . "s"); |
|
| 93 | + $content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked("ignored_categories", $key) . ' > ' . localize("{$keyPlural}.title") . '</input> '; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "", |
|
| 96 | + array_push($this->entryArray, new Entry(localize("customize.ignored"), "", |
|
| 97 | 97 | $content, "text", |
| 98 | - array ())); |
|
| 98 | + array())); |
|
| 99 | 99 | } |
| 100 | 100 | } |
@@ -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)) { |