Completed
Branch master (31966b)
by Markus
09:57
created
author.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -60,6 +60,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -24,69 +24,69 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
base.php 2 patches
Doc Comments   +50 added lines patch added patch discarded remove patch
@@ -60,6 +60,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 = "";
@@ -369,6 +380,9 @@  discard block
 block discarded – undo
369 380
         return $this->href;
370 381
     }
371 382
 
383
+    /**
384
+     * @return string
385
+     */
372 386
     public function getScriptName() {
373 387
         $parts = explode('/', $_SERVER["SCRIPT_NAME"]);
374 388
         return $parts[count($parts) - 1];
@@ -377,6 +391,9 @@  discard block
 block discarded – undo
377 391
 
378 392
 class LinkNavigation extends Link
379 393
 {
394
+    /**
395
+     * @param string $prel
396
+     */
380 397
     public function __construct($phref, $prel = NULL, $ptitle = NULL) {
381 398
         parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
382 399
         if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
@@ -391,6 +408,9 @@  discard block
 block discarded – undo
391 408
 
392 409
 class LinkFacet extends Link
393 410
 {
411
+    /**
412
+     * @param string $phref
413
+     */
394 414
     public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
395 415
         parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet);
396 416
         if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
@@ -471,6 +491,12 @@  discard block
 block discarded – undo
471 491
 {
472 492
     public $book;
473 493
 
494
+    /**
495
+     * @param string $pid
496
+     * @param string $pcontent
497
+     * @param string $pcontentType
498
+     * @param Book $pbook
499
+     */
474 500
     public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) {
475 501
         parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
476 502
         $this->book = $pbook;
@@ -1044,6 +1070,9 @@  discard block
 block discarded – undo
1044 1070
 
1045 1071
 class PageCustomize extends Page
1046 1072
 {
1073
+    /**
1074
+     * @param string $key
1075
+     */
1047 1076
     private function isChecked ($key, $testedValue = 1) {
1048 1077
         $value = getCurrentOption ($key);
1049 1078
         if (is_array ($value)) {
@@ -1058,6 +1087,9 @@  discard block
 block discarded – undo
1058 1087
         return "";
1059 1088
     }
1060 1089
 
1090
+    /**
1091
+     * @param string $key
1092
+     */
1061 1093
     private function isSelected ($key, $value) {
1062 1094
         if (getCurrentOption ($key) == $value) {
1063 1095
             return "selected='selected'";
@@ -1214,6 +1246,9 @@  discard block
 block discarded – undo
1214 1246
         return "";
1215 1247
     }
1216 1248
 
1249
+    /**
1250
+     * @return string
1251
+     */
1217 1252
     public static function getDbDirectory ($database = NULL) {
1218 1253
         global $config;
1219 1254
         if (self::isMultipleDatabaseEnabled ()) {
@@ -1273,10 +1308,18 @@  discard block
 block discarded – undo
1273 1308
         self::$db = NULL;
1274 1309
     }
1275 1310
 
1311
+    /**
1312
+     * @param string $query
1313
+     */
1276 1314
     public static function executeQuerySingle ($query, $database = NULL) {
1277 1315
         return self::getDb ($database)->query($query)->fetchColumn();
1278 1316
     }
1279 1317
 
1318
+    /**
1319
+     * @param string $table
1320
+     * @param string $id
1321
+     * @param string $numberOfString
1322
+     */
1280 1323
     public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) {
1281 1324
         if (!$numberOfString) {
1282 1325
             $numberOfString = $table . ".alphabetical";
@@ -1289,6 +1332,10 @@  discard block
 block discarded – undo
1289 1332
         return $entry;
1290 1333
     }
1291 1334
 
1335
+    /**
1336
+     * @param string $columns
1337
+     * @param string $category
1338
+     */
1292 1339
     public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) {
1293 1340
         list (, $result) = self::executeQuery ($query, $columns, "", $params, -1);
1294 1341
         $entryArray = array();
@@ -1307,6 +1354,9 @@  discard block
 block discarded – undo
1307 1354
         return $entryArray;
1308 1355
     }
1309 1356
 
1357
+    /**
1358
+     * @param string $filter
1359
+     */
1310 1360
     public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
1311 1361
         $totalResult = -1;
1312 1362
 
Please login to merge, or discard this patch.
Spacing   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
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
 
16
-function useServerSideRendering () {
16
+function useServerSideRendering() {
17 17
     global $config;
18 18
     return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']);
19 19
 }
20 20
 
21
-function serverSideRender ($data) {
21
+function serverSideRender($data) {
22 22
     // Get the templates
23
-    $theme = getCurrentTemplate ();
23
+    $theme = getCurrentTemplate();
24 24
     $header = file_get_contents('templates/' . $theme . '/header.html');
25 25
     $footer = file_get_contents('templates/' . $theme . '/footer.html');
26 26
     $main = file_get_contents('templates/' . $theme . '/main.html');
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
     $page = file_get_contents('templates/' . $theme . '/page.html');
29 29
 
30 30
     // Generate the function for the template
31
-    $template = new doT ();
32
-    $dot = $template->template ($page, array ("bookdetail" => $bookdetail,
31
+    $template = new doT();
32
+    $dot = $template->template($page, array("bookdetail" => $bookdetail,
33 33
                                               "header" => $header,
34 34
                                               "footer" => $footer,
35 35
                                               "main" => $main));
@@ -40,38 +40,38 @@  discard block
 block discarded – undo
40 40
     }
41 41
     // Execute the template
42 42
     if (!empty ($data)) {
43
-        return $dot ($data);
43
+        return $dot($data);
44 44
     }
45 45
 
46 46
     return NULL;
47 47
 }
48 48
 
49
-function getQueryString () {
50
-    if ( isset($_SERVER['QUERY_STRING']) ) {
49
+function getQueryString() {
50
+    if (isset($_SERVER['QUERY_STRING'])) {
51 51
         return $_SERVER['QUERY_STRING'];
52 52
     }
53 53
     return "";
54 54
 }
55 55
 
56
-function notFound () {
57
-    header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
56
+function notFound() {
57
+    header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
58 58
     header("Status: 404 Not Found");
59 59
 
60 60
     $_SERVER['REDIRECT_STATUS'] = 404;
61 61
 }
62 62
 
63
-function getURLParam ($name, $default = NULL) {
63
+function getURLParam($name, $default = NULL) {
64 64
     if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") {
65 65
         return $_GET[$name];
66 66
     }
67 67
     return $default;
68 68
 }
69 69
 
70
-function getCurrentOption ($option) {
70
+function getCurrentOption($option) {
71 71
     global $config;
72 72
     if (isset($_COOKIE[$option])) {
73
-        if (isset($config ["cops_" . $option]) && is_array ($config ["cops_" . $option])) {
74
-            return explode (",", $_COOKIE[$option]);
73
+        if (isset($config ["cops_" . $option]) && is_array($config ["cops_" . $option])) {
74
+            return explode(",", $_COOKIE[$option]);
75 75
         } else {
76 76
             return $_COOKIE[$option];
77 77
         }
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
     return "";
84 84
 }
85 85
 
86
-function getCurrentCss () {
87
-    return "templates/" . getCurrentTemplate () . "/styles/style-" . getCurrentOption ("style") . ".css";
86
+function getCurrentCss() {
87
+    return "templates/" . getCurrentTemplate() . "/styles/style-" . getCurrentOption("style") . ".css";
88 88
 }
89 89
 
90
-function getCurrentTemplate () {
91
-    return getCurrentOption ("template");
90
+function getCurrentTemplate() {
91
+    return getCurrentOption("template");
92 92
 }
93 93
 
94
-function getUrlWithVersion ($url) {
94
+function getUrlWithVersion($url) {
95 95
     return $url . "?v=" . VERSION;
96 96
 }
97 97
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     return "$return\n\n--------------------------------------------\n\n";
131 131
 }
132 132
 
133
-function are_libxml_errors_ok ()
133
+function are_libxml_errors_ok()
134 134
 {
135 135
     $errors = libxml_get_errors();
136 136
 
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
     return true;
141 141
 }
142 142
 
143
-function html2xhtml ($html) {
143
+function html2xhtml($html) {
144 144
     $doc = new DOMDocument();
145 145
     libxml_use_internal_errors(true);
146 146
 
147 147
     $doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' .
148
-                        $html  . '</body></html>'); // Load the HTML
148
+                        $html . '</body></html>'); // Load the HTML
149 149
     $output = $doc->saveXML($doc->documentElement); // Transform to an Ansi xml stream
150 150
     $output = xml2xhtml($output);
151
-    if (preg_match ('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) {
151
+    if (preg_match('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) {
152 152
         $output = $matches [1]; // Remove <html><body>
153 153
     }
154 154
     /*
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     }
161 161
     */
162 162
 
163
-    if (!are_libxml_errors_ok ()) $output = "HTML code not valid.";
163
+    if (!are_libxml_errors_ok()) $output = "HTML code not valid.";
164 164
 
165 165
     libxml_use_internal_errors(false);
166 166
     return $output;
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     //echo var_dump($langs);
247 247
     $lang_file = NULL;
248 248
     foreach ($langs as $language => $val) {
249
-        $temp_file = dirname(__FILE__). '/lang/Localization_' . $language . '.json';
249
+        $temp_file = dirname(__FILE__) . '/lang/Localization_' . $language . '.json';
250 250
         if (file_exists($temp_file)) {
251 251
             $lang = $language;
252 252
             $lang_file = $temp_file;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         }
255 255
     }
256 256
     if (empty ($lang_file)) {
257
-        $lang_file = dirname(__FILE__). '/lang/Localization_' . $lang . '.json';
257
+        $lang_file = dirname(__FILE__) . '/lang/Localization_' . $lang . '.json';
258 258
     }
259 259
     return array($lang, $lang_file);
260 260
 }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
  * This method is based on this page
264 264
  * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/
265 265
  */
266
-function localize($phrase, $count=-1, $reset=false) {
266
+function localize($phrase, $count = -1, $reset = false) {
267 267
     global $config;
268 268
     if ($count == 0)
269 269
         $phrase .= ".none";
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         $lang_file_en = NULL;
283 283
         list ($lang, $lang_file) = getLangAndTranslationFile();
284 284
         if ($lang != "en") {
285
-            $lang_file_en = dirname(__FILE__). '/lang/' . 'Localization_en.json';
285
+            $lang_file_en = dirname(__FILE__) . '/lang/' . 'Localization_en.json';
286 286
         }
287 287
 
288 288
         $lang_file_content = file_get_contents($lang_file);
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
         $translations = json_decode($lang_file_content, true);
291 291
 
292 292
         /* Clean the array of all unfinished translations */
293
-        foreach (array_keys ($translations) as $key) {
294
-            if (preg_match ("/^##TODO##/", $key)) {
293
+        foreach (array_keys($translations) as $key) {
294
+            if (preg_match("/^##TODO##/", $key)) {
295 295
                 unset ($translations [$key]);
296 296
             }
297 297
         }
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
         {
300 300
             $lang_file_content = file_get_contents($lang_file_en);
301 301
             $translations_en = json_decode($lang_file_content, true);
302
-            $translations = array_merge ($translations_en, $translations);
302
+            $translations = array_merge($translations_en, $translations);
303 303
         }
304 304
     }
305
-    if (array_key_exists ($phrase, $translations)) {
305
+    if (array_key_exists($phrase, $translations)) {
306 306
         return $translations[$phrase];
307 307
     }
308 308
     return $phrase;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
         $urlParams = "";
314 314
     }
315 315
     $start = "";
316
-    if (preg_match ("#^\?(.*)#", $urlParams, $matches)) {
316
+    if (preg_match("#^\?(.*)#", $urlParams, $matches)) {
317 317
         $start = "?";
318 318
         $urlParams = $matches[1];
319 319
     }
@@ -327,18 +327,18 @@  discard block
 block discarded – undo
327 327
     return $start . http_build_query($params);
328 328
 }
329 329
 
330
-function useNormAndUp () {
330
+function useNormAndUp() {
331 331
     global $config;
332 332
     return $config ['cops_normalized_search'] == "1";
333 333
 }
334 334
 
335
-function normalizeUtf8String( $s) {
335
+function normalizeUtf8String($s) {
336 336
     include_once 'transliteration.php';
337 337
     return _transliteration_process($s);
338 338
 }
339 339
 
340
-function normAndUp ($s) {
341
-    return mb_strtoupper (normalizeUtf8String($s), 'UTF-8');
340
+function normAndUp($s) {
341
+    return mb_strtoupper(normalizeUtf8String($s), 'UTF-8');
342 342
 }
343 343
 
344 344
 class Link
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
         $this->activeFacet = $pactiveFacet;
366 366
     }
367 367
 
368
-    public function hrefXhtml () {
368
+    public function hrefXhtml() {
369 369
         return $this->href;
370 370
     }
371 371
 
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
 class LinkNavigation extends Link
379 379
 {
380 380
     public function __construct($phref, $prel = NULL, $ptitle = NULL) {
381
-        parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
382
-        if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
383
-        if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href;
384
-        if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) {
381
+        parent::__construct($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
382
+        if (!is_null(GetUrlParam(DB))) $this->href = addURLParameter($this->href, DB, GetUrlParam(DB));
383
+        if (!preg_match("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href;
384
+        if (preg_match("/(bookdetail|getJSON).php/", parent::getScriptName())) {
385 385
             $this->href = "index.php" . $this->href;
386 386
         } else {
387 387
             $this->href = parent::getScriptName() . $this->href;
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
 class LinkFacet extends Link
393 393
 {
394 394
     public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
395
-        parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet);
396
-        if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
395
+        parent::__construct($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet);
396
+        if (!is_null(GetUrlParam(DB))) $this->href = addURLParameter($this->href, DB, GetUrlParam(DB));
397 397
         $this->href = parent::getScriptName() . $this->href;
398 398
     }
399 399
 }
@@ -423,21 +423,21 @@  discard block
 block discarded – undo
423 423
         Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png'
424 424
     );
425 425
 
426
-    public function getUpdatedTime () {
427
-        if (!is_null ($this->localUpdated)) {
428
-            return date (DATE_ATOM, $this->localUpdated);
426
+    public function getUpdatedTime() {
427
+        if (!is_null($this->localUpdated)) {
428
+            return date(DATE_ATOM, $this->localUpdated);
429 429
         }
430
-        if (is_null (self::$updated)) {
430
+        if (is_null(self::$updated)) {
431 431
             self::$updated = time();
432 432
         }
433
-        return date (DATE_ATOM, self::$updated);
433
+        return date(DATE_ATOM, self::$updated);
434 434
     }
435 435
 
436
-    public function getNavLink () {
436
+    public function getNavLink() {
437 437
         foreach ($this->linkArray as $link) {
438 438
             if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; }
439 439
 
440
-            return $link->hrefXhtml ();
440
+            return $link->hrefXhtml();
441 441
         }
442 442
         return "#";
443 443
     }
@@ -456,14 +456,14 @@  discard block
 block discarded – undo
456 456
         {
457 457
             foreach (self::$icons as $reg => $image)
458 458
             {
459
-                if (preg_match ("/" . $reg . "/", $pid)) {
460
-                    array_push ($this->linkArray, new Link (getUrlWithVersion ($image), "image/png", Link::OPDS_THUMBNAIL_TYPE));
459
+                if (preg_match("/" . $reg . "/", $pid)) {
460
+                    array_push($this->linkArray, new Link(getUrlWithVersion($image), "image/png", Link::OPDS_THUMBNAIL_TYPE));
461 461
                     break;
462 462
                 }
463 463
             }
464 464
         }
465 465
 
466
-        if (!is_null (GetUrlParam (DB))) $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id);
466
+        if (!is_null(GetUrlParam(DB))) $this->id = str_replace("cops:", "cops:" . GetUrlParam(DB) . ":", $this->id);
467 467
     }
468 468
 }
469 469
 
@@ -472,23 +472,23 @@  discard block
 block discarded – undo
472 472
     public $book;
473 473
 
474 474
     public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) {
475
-        parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
475
+        parent::__construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
476 476
         $this->book = $pbook;
477 477
         $this->localUpdated = $pbook->timestamp;
478 478
     }
479 479
 
480
-    public function getCoverThumbnail () {
480
+    public function getCoverThumbnail() {
481 481
         foreach ($this->linkArray as $link) {
482 482
             if ($link->rel == Link::OPDS_THUMBNAIL_TYPE)
483
-                return $link->hrefXhtml ();
483
+                return $link->hrefXhtml();
484 484
         }
485 485
         return null;
486 486
     }
487 487
 
488
-    public function getCover () {
488
+    public function getCover() {
489 489
         foreach ($this->linkArray as $link) {
490 490
             if ($link->rel == Link::OPDS_IMAGE_TYPE)
491
-                return $link->hrefXhtml ();
491
+                return $link->hrefXhtml();
492 492
         }
493 493
         return null;
494 494
     }
@@ -510,55 +510,55 @@  discard block
 block discarded – undo
510 510
     public $totalNumber = -1;
511 511
     public $entryArray = array();
512 512
 
513
-    public static function getPage ($pageId, $id, $query, $n)
513
+    public static function getPage($pageId, $id, $query, $n)
514 514
     {
515 515
         switch ($pageId) {
516 516
             case Base::PAGE_ALL_AUTHORS :
517
-                return new PageAllAuthors ($id, $query, $n);
517
+                return new PageAllAuthors($id, $query, $n);
518 518
             case Base::PAGE_AUTHORS_FIRST_LETTER :
519
-                return new PageAllAuthorsLetter ($id, $query, $n);
519
+                return new PageAllAuthorsLetter($id, $query, $n);
520 520
             case Base::PAGE_AUTHOR_DETAIL :
521
-                return new PageAuthorDetail ($id, $query, $n);
521
+                return new PageAuthorDetail($id, $query, $n);
522 522
             case Base::PAGE_ALL_TAGS :
523
-                return new PageAllTags ($id, $query, $n);
523
+                return new PageAllTags($id, $query, $n);
524 524
             case Base::PAGE_TAG_DETAIL :
525
-                return new PageTagDetail ($id, $query, $n);
525
+                return new PageTagDetail($id, $query, $n);
526 526
             case Base::PAGE_ALL_LANGUAGES :
527
-                return new PageAllLanguages ($id, $query, $n);
527
+                return new PageAllLanguages($id, $query, $n);
528 528
             case Base::PAGE_LANGUAGE_DETAIL :
529
-                return new PageLanguageDetail ($id, $query, $n);
529
+                return new PageLanguageDetail($id, $query, $n);
530 530
             case Base::PAGE_ALL_CUSTOMS :
531
-                return new PageAllCustoms ($id, $query, $n);
531
+                return new PageAllCustoms($id, $query, $n);
532 532
             case Base::PAGE_CUSTOM_DETAIL :
533
-                return new PageCustomDetail ($id, $query, $n);
533
+                return new PageCustomDetail($id, $query, $n);
534 534
             case Base::PAGE_ALL_RATINGS :
535
-                return new PageAllRating ($id, $query, $n);
535
+                return new PageAllRating($id, $query, $n);
536 536
             case Base::PAGE_RATING_DETAIL :
537
-                return new PageRatingDetail ($id, $query, $n);
537
+                return new PageRatingDetail($id, $query, $n);
538 538
             case Base::PAGE_ALL_SERIES :
539
-                return new PageAllSeries ($id, $query, $n);
539
+                return new PageAllSeries($id, $query, $n);
540 540
             case Base::PAGE_ALL_BOOKS :
541
-                return new PageAllBooks ($id, $query, $n);
541
+                return new PageAllBooks($id, $query, $n);
542 542
             case Base::PAGE_ALL_BOOKS_LETTER:
543
-                return new PageAllBooksLetter ($id, $query, $n);
543
+                return new PageAllBooksLetter($id, $query, $n);
544 544
             case Base::PAGE_ALL_RECENT_BOOKS :
545
-                return new PageRecentBooks ($id, $query, $n);
545
+                return new PageRecentBooks($id, $query, $n);
546 546
             case Base::PAGE_SERIE_DETAIL :
547
-                return new PageSerieDetail ($id, $query, $n);
547
+                return new PageSerieDetail($id, $query, $n);
548 548
             case Base::PAGE_OPENSEARCH_QUERY :
549
-                return new PageQueryResult ($id, $query, $n);
549
+                return new PageQueryResult($id, $query, $n);
550 550
             case Base::PAGE_BOOK_DETAIL :
551
-                return new PageBookDetail ($id, $query, $n);
551
+                return new PageBookDetail($id, $query, $n);
552 552
             case Base::PAGE_ALL_PUBLISHERS:
553
-                return new PageAllPublishers ($id, $query, $n);
553
+                return new PageAllPublishers($id, $query, $n);
554 554
             case Base::PAGE_PUBLISHER_DETAIL :
555
-                return new PagePublisherDetail ($id, $query, $n);
555
+                return new PagePublisherDetail($id, $query, $n);
556 556
             case Base::PAGE_ABOUT :
557
-                return new PageAbout ($id, $query, $n);
557
+                return new PageAbout($id, $query, $n);
558 558
             case Base::PAGE_CUSTOMIZE :
559
-                return new PageCustomize ($id, $query, $n);
559
+                return new PageCustomize($id, $query, $n);
560 560
             default:
561
-                $page = new Page ($id, $query, $n);
561
+                $page = new Page($id, $query, $n);
562 562
                 $page->idPage = "cops:catalog";
563 563
                 return $page;
564 564
         }
@@ -571,106 +571,106 @@  discard block
 block discarded – undo
571 571
         $this->query = $pquery;
572 572
         $this->n = $pn;
573 573
         $this->favicon = $config['cops_icon'];
574
-        $this->authorName = empty($config['cops_author_name']) ? utf8_encode('Sébastien Lucas') : $config['cops_author_name'];
575
-        $this->authorUri = empty($config['cops_author_uri']) ? 'http://blog.slucas.fr' : $config['cops_author_uri'];
576
-        $this->authorEmail = empty($config['cops_author_email']) ? '[email protected]' : $config['cops_author_email'];
574
+        $this->authorName = empty($config['cops_author_name'])?utf8_encode('Sébastien Lucas'):$config['cops_author_name'];
575
+        $this->authorUri = empty($config['cops_author_uri'])?'http://blog.slucas.fr':$config['cops_author_uri'];
576
+        $this->authorEmail = empty($config['cops_author_email'])?'[email protected]':$config['cops_author_email'];
577 577
     }
578 578
 
579
-    public function InitializeContent ()
579
+    public function InitializeContent()
580 580
     {
581 581
         global $config;
582 582
         $this->title = $config['cops_title_default'];
583 583
         $this->subtitle = $config['cops_subtitle_default'];
584
-        if (Base::noDatabaseSelected ()) {
584
+        if (Base::noDatabaseSelected()) {
585 585
             $i = 0;
586
-            foreach (Base::getDbNameList () as $key) {
587
-                $nBooks = Book::getBookCount ($i);
588
-                array_push ($this->entryArray, new Entry ($key, "cops:{$i}:catalog",
589
-                                        str_format (localize ("bookword", $nBooks), $nBooks), "text",
590
-                                        array ( new LinkNavigation ("?" . DB . "={$i}")), "", $nBooks));
586
+            foreach (Base::getDbNameList() as $key) {
587
+                $nBooks = Book::getBookCount($i);
588
+                array_push($this->entryArray, new Entry($key, "cops:{$i}:catalog",
589
+                                        str_format(localize("bookword", $nBooks), $nBooks), "text",
590
+                                        array(new LinkNavigation("?" . DB . "={$i}")), "", $nBooks));
591 591
                 $i++;
592
-                Base::clearDb ();
592
+                Base::clearDb();
593 593
             }
594 594
         } else {
595
-            if (!in_array (PageQueryResult::SCOPE_AUTHOR, getCurrentOption ('ignored_categories'))) {
596
-                array_push ($this->entryArray, Author::getCount());
595
+            if (!in_array(PageQueryResult::SCOPE_AUTHOR, getCurrentOption('ignored_categories'))) {
596
+                array_push($this->entryArray, Author::getCount());
597 597
             }
598
-            if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) {
598
+            if (!in_array(PageQueryResult::SCOPE_SERIES, getCurrentOption('ignored_categories'))) {
599 599
                 $series = Serie::getCount();
600
-                if (!is_null ($series)) array_push ($this->entryArray, $series);
600
+                if (!is_null($series)) array_push($this->entryArray, $series);
601 601
             }
602
-            if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) {
602
+            if (!in_array(PageQueryResult::SCOPE_PUBLISHER, getCurrentOption('ignored_categories'))) {
603 603
                 $publisher = Publisher::getCount();
604
-                if (!is_null ($publisher)) array_push ($this->entryArray, $publisher);
604
+                if (!is_null($publisher)) array_push($this->entryArray, $publisher);
605 605
             }
606
-            if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) {
606
+            if (!in_array(PageQueryResult::SCOPE_TAG, getCurrentOption('ignored_categories'))) {
607 607
                 $tags = Tag::getCount();
608
-                if (!is_null ($tags)) array_push ($this->entryArray, $tags);
608
+                if (!is_null($tags)) array_push($this->entryArray, $tags);
609 609
             }
610
-            if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) {
610
+            if (!in_array(PageQueryResult::SCOPE_RATING, getCurrentOption('ignored_categories'))) {
611 611
                 $rating = Rating::getCount();
612
-                if (!is_null ($rating)) array_push ($this->entryArray, $rating);
612
+                if (!is_null($rating)) array_push($this->entryArray, $rating);
613 613
             }
614
-            if (!in_array ("language", getCurrentOption ('ignored_categories'))) {
614
+            if (!in_array("language", getCurrentOption('ignored_categories'))) {
615 615
                 $languages = Language::getCount();
616
-                if (!is_null ($languages)) array_push ($this->entryArray, $languages);
616
+                if (!is_null($languages)) array_push($this->entryArray, $languages);
617 617
             }
618 618
             foreach ($config['cops_calibre_custom_column'] as $lookup) {
619
-                $customId = CustomColumn::getCustomId ($lookup);
620
-                if (!is_null ($customId)) {
621
-                    array_push ($this->entryArray, CustomColumn::getCount($customId));
619
+                $customId = CustomColumn::getCustomId($lookup);
620
+                if (!is_null($customId)) {
621
+                    array_push($this->entryArray, CustomColumn::getCount($customId));
622 622
                 }
623 623
             }
624
-            $this->entryArray = array_merge ($this->entryArray, Book::getCount());
624
+            $this->entryArray = array_merge($this->entryArray, Book::getCount());
625 625
 
626
-            if (Base::isMultipleDatabaseEnabled ()) $this->title =  Base::getDbName ();
626
+            if (Base::isMultipleDatabaseEnabled()) $this->title = Base::getDbName();
627 627
         }
628 628
     }
629 629
 
630
-    public function isPaginated ()
630
+    public function isPaginated()
631 631
     {
632
-        return (getCurrentOption ("max_item_per_page") != -1 &&
632
+        return (getCurrentOption("max_item_per_page") != -1 &&
633 633
                 $this->totalNumber != -1 &&
634
-                $this->totalNumber > getCurrentOption ("max_item_per_page"));
634
+                $this->totalNumber > getCurrentOption("max_item_per_page"));
635 635
     }
636 636
 
637
-    public function getNextLink ()
637
+    public function getNextLink()
638 638
     {
639
-        $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
640
-        if (($this->n) * getCurrentOption ("max_item_per_page") < $this->totalNumber) {
641
-            return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", localize ("paging.next.alternate"));
639
+        $currentUrl = preg_replace("/\&n=.*?$/", "", "?" . getQueryString());
640
+        if (($this->n) * getCurrentOption("max_item_per_page") < $this->totalNumber) {
641
+            return new LinkNavigation($currentUrl . "&n=" . ($this->n + 1), "next", localize("paging.next.alternate"));
642 642
         }
643 643
         return NULL;
644 644
     }
645 645
 
646
-    public function getPrevLink ()
646
+    public function getPrevLink()
647 647
     {
648
-        $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
648
+        $currentUrl = preg_replace("/\&n=.*?$/", "", "?" . getQueryString());
649 649
         if ($this->n > 1) {
650
-            return new LinkNavigation ($currentUrl . "&n=" . ($this->n - 1), "previous", localize ("paging.previous.alternate"));
650
+            return new LinkNavigation($currentUrl . "&n=" . ($this->n - 1), "previous", localize("paging.previous.alternate"));
651 651
         }
652 652
         return NULL;
653 653
     }
654 654
 
655
-    public function getMaxPage ()
655
+    public function getMaxPage()
656 656
     {
657
-        return ceil ($this->totalNumber / getCurrentOption ("max_item_per_page"));
657
+        return ceil($this->totalNumber / getCurrentOption("max_item_per_page"));
658 658
     }
659 659
 
660
-    public function containsBook ()
660
+    public function containsBook()
661 661
     {
662
-        if (count ($this->entryArray) == 0) return false;
663
-        if (get_class ($this->entryArray [0]) == "EntryBook") return true;
662
+        if (count($this->entryArray) == 0) return false;
663
+        if (get_class($this->entryArray [0]) == "EntryBook") return true;
664 664
         return false;
665 665
     }
666 666
 }
667 667
 
668 668
 class PageAllAuthors extends Page
669 669
 {
670
-    public function InitializeContent ()
670
+    public function InitializeContent()
671 671
     {
672 672
         $this->title = localize("authors.title");
673
-        if (getCurrentOption ("author_split_first_letter") == 1) {
673
+        if (getCurrentOption("author_split_first_letter") == 1) {
674 674
             $this->entryArray = Author::getAllAuthorsByFirstLetter();
675 675
         }
676 676
         else {
@@ -682,28 +682,28 @@  discard block
 block discarded – undo
682 682
 
683 683
 class PageAllAuthorsLetter extends Page
684 684
 {
685
-    public function InitializeContent ()
685
+    public function InitializeContent()
686 686
     {
687
-        $this->idPage = Author::getEntryIdByLetter ($this->idGet);
688
-        $this->entryArray = Author::getAuthorsByStartingLetter ($this->idGet);
689
-        $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("authorword", count ($this->entryArray)), count ($this->entryArray)), $this->idGet);
687
+        $this->idPage = Author::getEntryIdByLetter($this->idGet);
688
+        $this->entryArray = Author::getAuthorsByStartingLetter($this->idGet);
689
+        $this->title = str_format(localize("splitByLetter.letter"), str_format(localize("authorword", count($this->entryArray)), count($this->entryArray)), $this->idGet);
690 690
     }
691 691
 }
692 692
 
693 693
 class PageAuthorDetail extends Page
694 694
 {
695
-    public function InitializeContent ()
695
+    public function InitializeContent()
696 696
     {
697
-        $author = Author::getAuthorById ($this->idGet);
698
-        $this->idPage = $author->getEntryId ();
697
+        $author = Author::getAuthorById($this->idGet);
698
+        $this->idPage = $author->getEntryId();
699 699
         $this->title = $author->name;
700
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByAuthor ($this->idGet, $this->n);
700
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByAuthor($this->idGet, $this->n);
701 701
     }
702 702
 }
703 703
 
704 704
 class PageAllPublishers extends Page
705 705
 {
706
-    public function InitializeContent ()
706
+    public function InitializeContent()
707 707
     {
708 708
         $this->title = localize("publishers.title");
709 709
         $this->entryArray = Publisher::getAllPublishers();
@@ -713,18 +713,18 @@  discard block
 block discarded – undo
713 713
 
714 714
 class PagePublisherDetail extends Page
715 715
 {
716
-    public function InitializeContent ()
716
+    public function InitializeContent()
717 717
     {
718
-        $publisher = Publisher::getPublisherById ($this->idGet);
718
+        $publisher = Publisher::getPublisherById($this->idGet);
719 719
         $this->title = $publisher->name;
720
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByPublisher ($this->idGet, $this->n);
721
-        $this->idPage = $publisher->getEntryId ();
720
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByPublisher($this->idGet, $this->n);
721
+        $this->idPage = $publisher->getEntryId();
722 722
     }
723 723
 }
724 724
 
725 725
 class PageAllTags extends Page
726 726
 {
727
-    public function InitializeContent ()
727
+    public function InitializeContent()
728 728
     {
729 729
         $this->title = localize("tags.title");
730 730
         $this->entryArray = Tag::getAllTags();
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 
735 735
 class PageAllLanguages extends Page
736 736
 {
737
-    public function InitializeContent ()
737
+    public function InitializeContent()
738 738
     {
739 739
         $this->title = localize("languages.title");
740 740
         $this->entryArray = Language::getAllLanguages();
@@ -744,52 +744,52 @@  discard block
 block discarded – undo
744 744
 
745 745
 class PageCustomDetail extends Page
746 746
 {
747
-    public function InitializeContent ()
747
+    public function InitializeContent()
748 748
     {
749
-        $customId = getURLParam ("custom", NULL);
750
-        $custom = CustomColumn::getCustomById ($customId, $this->idGet);
751
-        $this->idPage = $custom->getEntryId ();
749
+        $customId = getURLParam("custom", NULL);
750
+        $custom = CustomColumn::getCustomById($customId, $this->idGet);
751
+        $this->idPage = $custom->getEntryId();
752 752
         $this->title = $custom->name;
753
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByCustom ($customId, $this->idGet, $this->n);
753
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByCustom($customId, $this->idGet, $this->n);
754 754
     }
755 755
 }
756 756
 
757 757
 class PageAllCustoms extends Page
758 758
 {
759
-    public function InitializeContent ()
759
+    public function InitializeContent()
760 760
     {
761
-        $customId = getURLParam ("custom", NULL);
762
-        $this->title = CustomColumn::getAllTitle ($customId);
761
+        $customId = getURLParam("custom", NULL);
762
+        $this->title = CustomColumn::getAllTitle($customId);
763 763
         $this->entryArray = CustomColumn::getAllCustoms($customId);
764
-        $this->idPage = CustomColumn::getAllCustomsId ($customId);
764
+        $this->idPage = CustomColumn::getAllCustomsId($customId);
765 765
     }
766 766
 }
767 767
 
768 768
 class PageTagDetail extends Page
769 769
 {
770
-    public function InitializeContent ()
770
+    public function InitializeContent()
771 771
     {
772
-        $tag = Tag::getTagById ($this->idGet);
773
-        $this->idPage = $tag->getEntryId ();
772
+        $tag = Tag::getTagById($this->idGet);
773
+        $this->idPage = $tag->getEntryId();
774 774
         $this->title = $tag->name;
775
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByTag ($this->idGet, $this->n);
775
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByTag($this->idGet, $this->n);
776 776
     }
777 777
 }
778 778
 
779 779
 class PageLanguageDetail extends Page
780 780
 {
781
-    public function InitializeContent ()
781
+    public function InitializeContent()
782 782
     {
783
-        $language = Language::getLanguageById ($this->idGet);
784
-        $this->idPage = $language->getEntryId ();
783
+        $language = Language::getLanguageById($this->idGet);
784
+        $this->idPage = $language->getEntryId();
785 785
         $this->title = $language->lang_code;
786
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByLanguage ($this->idGet, $this->n);
786
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByLanguage($this->idGet, $this->n);
787 787
     }
788 788
 }
789 789
 
790 790
 class PageAllSeries extends Page
791 791
 {
792
-    public function InitializeContent ()
792
+    public function InitializeContent()
793 793
     {
794 794
         $this->title = localize("series.title");
795 795
         $this->entryArray = Serie::getAllSeries();
@@ -799,18 +799,18 @@  discard block
 block discarded – undo
799 799
 
800 800
 class PageSerieDetail extends Page
801 801
 {
802
-    public function InitializeContent ()
802
+    public function InitializeContent()
803 803
     {
804
-        $serie = Serie::getSerieById ($this->idGet);
804
+        $serie = Serie::getSerieById($this->idGet);
805 805
         $this->title = $serie->name;
806
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksBySeries ($this->idGet, $this->n);
807
-        $this->idPage = $serie->getEntryId ();
806
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksBySeries($this->idGet, $this->n);
807
+        $this->idPage = $serie->getEntryId();
808 808
     }
809 809
 }
810 810
 
811 811
 class PageAllRating extends Page
812 812
 {
813
-    public function InitializeContent ()
813
+    public function InitializeContent()
814 814
     {
815 815
         $this->title = localize("ratings.title");
816 816
         $this->entryArray = Rating::getAllRatings();
@@ -820,25 +820,25 @@  discard block
 block discarded – undo
820 820
 
821 821
 class PageRatingDetail extends Page
822 822
 {
823
-    public function InitializeContent ()
823
+    public function InitializeContent()
824 824
     {
825
-        $rating = Rating::getRatingById ($this->idGet);
826
-        $this->idPage = $rating->getEntryId ();
827
-        $this->title =str_format (localize ("ratingword", $rating->name/2), $rating->name/2);
828
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByRating ($this->idGet, $this->n);
825
+        $rating = Rating::getRatingById($this->idGet);
826
+        $this->idPage = $rating->getEntryId();
827
+        $this->title = str_format(localize("ratingword", $rating->name / 2), $rating->name / 2);
828
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByRating($this->idGet, $this->n);
829 829
     }
830 830
 }
831 831
 
832 832
 class PageAllBooks extends Page
833 833
 {
834
-    public function InitializeContent ()
834
+    public function InitializeContent()
835 835
     {
836
-        $this->title = localize ("allbooks.title");
837
-        if (getCurrentOption ("titles_split_first_letter") == 1) {
836
+        $this->title = localize("allbooks.title");
837
+        if (getCurrentOption("titles_split_first_letter") == 1) {
838 838
             $this->entryArray = Book::getAllBooks();
839 839
         }
840 840
         else {
841
-            list ($this->entryArray, $this->totalNumber) = Book::getBooks ($this->n);
841
+            list ($this->entryArray, $this->totalNumber) = Book::getBooks($this->n);
842 842
         }
843 843
         $this->idPage = Book::ALL_BOOKS_ID;
844 844
     }
@@ -846,25 +846,25 @@  discard block
 block discarded – undo
846 846
 
847 847
 class PageAllBooksLetter extends Page
848 848
 {
849
-    public function InitializeContent ()
849
+    public function InitializeContent()
850 850
     {
851
-        list ($this->entryArray, $this->totalNumber) = Book::getBooksByStartingLetter ($this->idGet, $this->n);
852
-        $this->idPage = Book::getEntryIdByLetter ($this->idGet);
851
+        list ($this->entryArray, $this->totalNumber) = Book::getBooksByStartingLetter($this->idGet, $this->n);
852
+        $this->idPage = Book::getEntryIdByLetter($this->idGet);
853 853
 
854 854
         $count = $this->totalNumber;
855 855
         if ($count == -1)
856
-            $count = count ($this->entryArray);
856
+            $count = count($this->entryArray);
857 857
 
858
-        $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet);
858
+        $this->title = str_format(localize("splitByLetter.letter"), str_format(localize("bookword", $count), $count), $this->idGet);
859 859
     }
860 860
 }
861 861
 
862 862
 class PageRecentBooks extends Page
863 863
 {
864
-    public function InitializeContent ()
864
+    public function InitializeContent()
865 865
     {
866
-        $this->title = localize ("recent.title");
867
-        $this->entryArray = Book::getAllRecentBooks ();
866
+        $this->title = localize("recent.title");
867
+        $this->entryArray = Book::getAllRecentBooks();
868 868
         $this->idPage = Book::ALL_RECENT_BOOKS_ID;
869 869
     }
870 870
 }
@@ -878,16 +878,16 @@  discard block
 block discarded – undo
878 878
     const SCOPE_BOOK = "book";
879 879
     const SCOPE_PUBLISHER = "publisher";
880 880
 
881
-    private function useTypeahead () {
882
-        return !is_null (getURLParam ("search"));
881
+    private function useTypeahead() {
882
+        return !is_null(getURLParam("search"));
883 883
     }
884 884
 
885
-    private function searchByScope ($scope, $limit = FALSE) {
885
+    private function searchByScope($scope, $limit = FALSE) {
886 886
         $n = $this->n;
887 887
         $numberPerPage = NULL;
888 888
         $queryNormedAndUp = $this->query;
889
-        if (useNormAndUp ()) {
890
-            $queryNormedAndUp = normAndUp ($this->query);
889
+        if (useNormAndUp()) {
890
+            $queryNormedAndUp = normAndUp($this->query);
891 891
         }
892 892
         if ($limit) {
893 893
             $n = 1;
@@ -895,59 +895,59 @@  discard block
 block discarded – undo
895 895
         }
896 896
         switch ($scope) {
897 897
             case self::SCOPE_BOOK :
898
-                $array = Book::getBooksByStartingLetter ('%' . $queryNormedAndUp, $n, NULL, $numberPerPage);
898
+                $array = Book::getBooksByStartingLetter('%' . $queryNormedAndUp, $n, NULL, $numberPerPage);
899 899
                 break;
900 900
             case self::SCOPE_AUTHOR :
901
-                $array = Author::getAuthorsForSearch ('%' . $queryNormedAndUp);
901
+                $array = Author::getAuthorsForSearch('%' . $queryNormedAndUp);
902 902
                 break;
903 903
             case self::SCOPE_SERIES :
904
-                $array = Serie::getAllSeriesByQuery ($queryNormedAndUp);
904
+                $array = Serie::getAllSeriesByQuery($queryNormedAndUp);
905 905
                 break;
906 906
             case self::SCOPE_TAG :
907
-                $array = Tag::getAllTagsByQuery ($queryNormedAndUp, $n, NULL, $numberPerPage);
907
+                $array = Tag::getAllTagsByQuery($queryNormedAndUp, $n, NULL, $numberPerPage);
908 908
                 break;
909 909
             case self::SCOPE_PUBLISHER :
910
-                $array = Publisher::getAllPublishersByQuery ($queryNormedAndUp);
910
+                $array = Publisher::getAllPublishersByQuery($queryNormedAndUp);
911 911
                 break;
912 912
             default:
913
-                $array = Book::getBooksByQuery (
914
-                    array ("all" => "%" . $queryNormedAndUp . "%"), $n);
913
+                $array = Book::getBooksByQuery(
914
+                    array("all" => "%" . $queryNormedAndUp . "%"), $n);
915 915
         }
916 916
 
917 917
         return $array;
918 918
     }
919 919
 
920
-    public function doSearchByCategory () {
921
-        $database = GetUrlParam (DB);
922
-        $out = array ();
920
+    public function doSearchByCategory() {
921
+        $database = GetUrlParam(DB);
922
+        $out = array();
923 923
         $pagequery = Base::PAGE_OPENSEARCH_QUERY;
924
-        $dbArray = array ("");
924
+        $dbArray = array("");
925 925
         $d = $database;
926 926
         $query = $this->query;
927 927
         // Special case when no databases were chosen, we search on all databases
928
-        if (Base::noDatabaseSelected ()) {
929
-            $dbArray = Base::getDbNameList ();
928
+        if (Base::noDatabaseSelected()) {
929
+            $dbArray = Base::getDbNameList();
930 930
             $d = 0;
931 931
         }
932 932
         foreach ($dbArray as $key) {
933
-            if (Base::noDatabaseSelected ()) {
934
-                array_push ($this->entryArray, new Entry ($key, DB . ":query:{$d}",
933
+            if (Base::noDatabaseSelected()) {
934
+                array_push($this->entryArray, new Entry($key, DB . ":query:{$d}",
935 935
                                         " ", "text",
936
-                                        array ( new LinkNavigation ("?" . DB . "={$d}")), "tt-header"));
937
-                Base::getDb ($d);
936
+                                        array(new LinkNavigation("?" . DB . "={$d}")), "tt-header"));
937
+                Base::getDb($d);
938 938
             }
939
-            foreach (array (PageQueryResult::SCOPE_BOOK,
939
+            foreach (array(PageQueryResult::SCOPE_BOOK,
940 940
                             PageQueryResult::SCOPE_AUTHOR,
941 941
                             PageQueryResult::SCOPE_SERIES,
942 942
                             PageQueryResult::SCOPE_TAG,
943 943
                             PageQueryResult::SCOPE_PUBLISHER) as $key) {
944
-                if (in_array($key, getCurrentOption ('ignored_categories'))) {
944
+                if (in_array($key, getCurrentOption('ignored_categories'))) {
945 945
                     continue;
946 946
                 }
947
-                $array = $this->searchByScope ($key, TRUE);
947
+                $array = $this->searchByScope($key, TRUE);
948 948
 
949 949
                 $i = 0;
950
-                if (count ($array) == 2 && is_array ($array [0])) {
950
+                if (count($array) == 2 && is_array($array [0])) {
951 951
                     $total = $array [1];
952 952
                     $array = $array [0];
953 953
                 } else {
@@ -960,32 +960,32 @@  discard block
 block discarded – undo
960 960
                     // str_format (localize("seriesword", count($array))
961 961
                     // str_format (localize("tagword", count($array))
962 962
                     // str_format (localize("publisherword", count($array))
963
-                    array_push ($this->entryArray, new Entry (str_format (localize ("search.result.{$key}"), $this->query), DB . ":query:{$d}:{$key}",
964
-                                        str_format (localize("{$key}word", $total), $total), "text",
965
-                                        array ( new LinkNavigation ("?page={$pagequery}&query={$query}&db={$d}&scope={$key}")),
966
-                                        Base::noDatabaseSelected () ? "" : "tt-header", $total));
963
+                    array_push($this->entryArray, new Entry(str_format(localize("search.result.{$key}"), $this->query), DB . ":query:{$d}:{$key}",
964
+                                        str_format(localize("{$key}word", $total), $total), "text",
965
+                                        array(new LinkNavigation("?page={$pagequery}&query={$query}&db={$d}&scope={$key}")),
966
+                                        Base::noDatabaseSelected()?"":"tt-header", $total));
967 967
                 }
968
-                if (!Base::noDatabaseSelected () && $this->useTypeahead ()) {
968
+                if (!Base::noDatabaseSelected() && $this->useTypeahead()) {
969 969
                     foreach ($array as $entry) {
970
-                        array_push ($this->entryArray, $entry);
970
+                        array_push($this->entryArray, $entry);
971 971
                         $i++;
972 972
                         if ($i > 4) { break; };
973 973
                     }
974 974
                 }
975 975
             }
976 976
             $d++;
977
-            if (Base::noDatabaseSelected ()) {
978
-                Base::clearDb ();
977
+            if (Base::noDatabaseSelected()) {
978
+                Base::clearDb();
979 979
             }
980 980
         }
981 981
         return $out;
982 982
     }
983 983
 
984
-    public function InitializeContent ()
984
+    public function InitializeContent()
985 985
     {
986
-        $scope = getURLParam ("scope");
986
+        $scope = getURLParam("scope");
987 987
         if (empty ($scope)) {
988
-            $this->title = str_format (localize ("search.result"), $this->query);
988
+            $this->title = str_format(localize("search.result"), $this->query);
989 989
         } else {
990 990
             // Comment to help the perl i18n script
991 991
             // str_format (localize ("search.result.author"), $this->query)
@@ -993,31 +993,31 @@  discard block
 block discarded – undo
993 993
             // str_format (localize ("search.result.series"), $this->query)
994 994
             // str_format (localize ("search.result.book"), $this->query)
995 995
             // str_format (localize ("search.result.publisher"), $this->query)
996
-            $this->title = str_format (localize ("search.result.{$scope}"), $this->query);
996
+            $this->title = str_format(localize("search.result.{$scope}"), $this->query);
997 997
         }
998 998
 
999 999
         $crit = "%" . $this->query . "%";
1000 1000
 
1001 1001
         // Special case when we are doing a search and no database is selected
1002
-        if (Base::noDatabaseSelected () && !$this->useTypeahead ()) {
1002
+        if (Base::noDatabaseSelected() && !$this->useTypeahead()) {
1003 1003
             $i = 0;
1004
-            foreach (Base::getDbNameList () as $key) {
1005
-                Base::clearDb ();
1006
-                list ($array, $totalNumber) = Book::getBooksByQuery (array ("all" => $crit), 1, $i, 1);
1007
-                array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}",
1008
-                                        str_format (localize ("bookword", $totalNumber), $totalNumber), "text",
1009
-                                        array ( new LinkNavigation ("?" . DB . "={$i}&page=9&query=" . $this->query)), "", $totalNumber));
1004
+            foreach (Base::getDbNameList() as $key) {
1005
+                Base::clearDb();
1006
+                list ($array, $totalNumber) = Book::getBooksByQuery(array("all" => $crit), 1, $i, 1);
1007
+                array_push($this->entryArray, new Entry($key, DB . ":query:{$i}",
1008
+                                        str_format(localize("bookword", $totalNumber), $totalNumber), "text",
1009
+                                        array(new LinkNavigation("?" . DB . "={$i}&page=9&query=" . $this->query)), "", $totalNumber));
1010 1010
                 $i++;
1011 1011
             }
1012 1012
             return;
1013 1013
         }
1014 1014
         if (empty ($scope)) {
1015
-            $this->doSearchByCategory ();
1015
+            $this->doSearchByCategory();
1016 1016
             return;
1017 1017
         }
1018 1018
 
1019
-        $array = $this->searchByScope ($scope);
1020
-        if (count ($array) == 2 && is_array ($array [0])) {
1019
+        $array = $this->searchByScope($scope);
1020
+        if (count($array) == 2 && is_array($array [0])) {
1021 1021
             list ($this->entryArray, $this->totalNumber) = $array;
1022 1022
         } else {
1023 1023
             $this->entryArray = $array;
@@ -1027,27 +1027,27 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 class PageBookDetail extends Page
1029 1029
 {
1030
-    public function InitializeContent ()
1030
+    public function InitializeContent()
1031 1031
     {
1032
-        $this->book = Book::getBookById ($this->idGet);
1032
+        $this->book = Book::getBookById($this->idGet);
1033 1033
         $this->title = $this->book->title;
1034 1034
     }
1035 1035
 }
1036 1036
 
1037 1037
 class PageAbout extends Page
1038 1038
 {
1039
-    public function InitializeContent ()
1039
+    public function InitializeContent()
1040 1040
     {
1041
-        $this->title = localize ("about.title");
1041
+        $this->title = localize("about.title");
1042 1042
     }
1043 1043
 }
1044 1044
 
1045 1045
 class PageCustomize extends Page
1046 1046
 {
1047
-    private function isChecked ($key, $testedValue = 1) {
1048
-        $value = getCurrentOption ($key);
1049
-        if (is_array ($value)) {
1050
-            if (in_array ($testedValue, $value)) {
1047
+    private function isChecked($key, $testedValue = 1) {
1048
+        $value = getCurrentOption($key);
1049
+        if (is_array($value)) {
1050
+            if (in_array($testedValue, $value)) {
1051 1051
                 return "checked='checked'";
1052 1052
             }
1053 1053
         } else {
@@ -1058,29 +1058,29 @@  discard block
 block discarded – undo
1058 1058
         return "";
1059 1059
     }
1060 1060
 
1061
-    private function isSelected ($key, $value) {
1062
-        if (getCurrentOption ($key) == $value) {
1061
+    private function isSelected($key, $value) {
1062
+        if (getCurrentOption($key) == $value) {
1063 1063
             return "selected='selected'";
1064 1064
         }
1065 1065
         return "";
1066 1066
     }
1067 1067
 
1068
-    private function getStyleList () {
1069
-        $result = array ();
1070
-        foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) {
1071
-            if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) {
1072
-                array_push ($result, $m [1]);
1068
+    private function getStyleList() {
1069
+        $result = array();
1070
+        foreach (glob("templates/" . getCurrentTemplate() . "/styles/style-*.css") as $filename) {
1071
+            if (preg_match('/styles\/style-(.*?)\.css/', $filename, $m)) {
1072
+                array_push($result, $m [1]);
1073 1073
             }
1074 1074
         }
1075 1075
         return $result;
1076 1076
     }
1077 1077
 
1078
-    public function InitializeContent ()
1078
+    public function InitializeContent()
1079 1079
     {
1080
-        $this->title = localize ("customize.title");
1081
-        $this->entryArray = array ();
1080
+        $this->title = localize("customize.title");
1081
+        $this->entryArray = array();
1082 1082
 
1083
-        $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR,
1083
+        $ignoredBaseArray = array(PageQueryResult::SCOPE_AUTHOR,
1084 1084
                                    PageQueryResult::SCOPE_TAG,
1085 1085
                                    PageQueryResult::SCOPE_SERIES,
1086 1086
                                    PageQueryResult::SCOPE_PUBLISHER,
@@ -1088,50 +1088,50 @@  discard block
 block discarded – undo
1088 1088
                                    "language");
1089 1089
 
1090 1090
         $content = "";
1091
-        array_push ($this->entryArray, new Entry ("Template", "",
1091
+        array_push($this->entryArray, new Entry("Template", "",
1092 1092
                                         "<span style='cursor: pointer;' onclick='$.cookie(\"template\", \"bootstrap\", { expires: 365 });window.location=$(\".headleft\").attr(\"href\");'>Click to switch to Bootstrap</span>", "text",
1093
-                                        array ()));
1093
+                                        array()));
1094 1094
         if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
1095 1095
             $content .= '<select id="style" onchange="updateCookie (this);">';
1096
-            foreach ($this-> getStyleList () as $filename) {
1097
-                $content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>";
1096
+            foreach ($this-> getStyleList() as $filename) {
1097
+                $content .= "<option value='{$filename}' " . $this->isSelected("style", $filename) . ">{$filename}</option>";
1098 1098
             }
1099 1099
             $content .= '</select>';
1100 1100
         } else {
1101
-            foreach ($this-> getStyleList () as $filename) {
1102
-                $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>";
1101
+            foreach ($this-> getStyleList() as $filename) {
1102
+                $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>";
1103 1103
             }
1104 1104
         }
1105
-        array_push ($this->entryArray, new Entry (localize ("customize.style"), "",
1105
+        array_push($this->entryArray, new Entry(localize("customize.style"), "",
1106 1106
                                         $content, "text",
1107
-                                        array ()));
1108
-        if (!useServerSideRendering ()) {
1109
-            $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked ("use_fancyapps") . ' />';
1110
-            array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "",
1107
+                                        array()));
1108
+        if (!useServerSideRendering()) {
1109
+            $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked("use_fancyapps") . ' />';
1110
+            array_push($this->entryArray, new Entry(localize("customize.fancybox"), "",
1111 1111
                                             $content, "text",
1112
-                                            array ()));
1112
+                                            array()));
1113 1113
         }
1114
-        $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]+$" />';
1115
-        array_push ($this->entryArray, new Entry (localize ("customize.paging"), "",
1114
+        $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]+$" />';
1115
+        array_push($this->entryArray, new Entry(localize("customize.paging"), "",
1116 1116
                                         $content, "text",
1117
-                                        array ()));
1118
-        $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />';
1119
-        array_push ($this->entryArray, new Entry (localize ("customize.email"), "",
1117
+                                        array()));
1118
+        $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption("email") . '" />';
1119
+        array_push($this->entryArray, new Entry(localize("customize.email"), "",
1120 1120
                                         $content, "text",
1121
-                                        array ()));
1122
-        $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked ("html_tag_filter") . ' />';
1123
-        array_push ($this->entryArray, new Entry (localize ("customize.filter"), "",
1121
+                                        array()));
1122
+        $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked("html_tag_filter") . ' />';
1123
+        array_push($this->entryArray, new Entry(localize("customize.filter"), "",
1124 1124
                                         $content, "text",
1125
-                                        array ()));
1125
+                                        array()));
1126 1126
         $content = "";
1127 1127
         foreach ($ignoredBaseArray as $key) {
1128
-            $keyPlural = preg_replace ('/(ss)$/', 's', $key . "s");
1129
-            $content .=  '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . '</input> ';
1128
+            $keyPlural = preg_replace('/(ss)$/', 's', $key . "s");
1129
+            $content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked("ignored_categories", $key) . ' > ' . localize("{$keyPlural}.title") . '</input> ';
1130 1130
         }
1131 1131
 
1132
-        array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "",
1132
+        array_push($this->entryArray, new Entry(localize("customize.ignored"), "",
1133 1133
                                         $content, "text",
1134
-                                        array ()));
1134
+                                        array()));
1135 1135
     }
1136 1136
 }
1137 1137
 
@@ -1167,142 +1167,142 @@  discard block
 block discarded – undo
1167 1167
 
1168 1168
     private static $db = NULL;
1169 1169
 
1170
-    public static function isMultipleDatabaseEnabled () {
1170
+    public static function isMultipleDatabaseEnabled() {
1171 1171
         global $config;
1172
-        return is_array ($config['calibre_directory']);
1172
+        return is_array($config['calibre_directory']);
1173 1173
     }
1174 1174
 
1175
-    public static function useAbsolutePath () {
1175
+    public static function useAbsolutePath() {
1176 1176
         global $config;
1177 1177
         $path = self::getDbDirectory();
1178
-        return preg_match ('/^\//', $path) || // Linux /
1179
-               preg_match ('/^\w\:/', $path); // Windows X:
1178
+        return preg_match('/^\//', $path) || // Linux /
1179
+               preg_match('/^\w\:/', $path); // Windows X:
1180 1180
     }
1181 1181
 
1182
-    public static function noDatabaseSelected () {
1183
-        return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
1182
+    public static function noDatabaseSelected() {
1183
+        return self::isMultipleDatabaseEnabled() && is_null(GetUrlParam(DB));
1184 1184
     }
1185 1185
 
1186
-    public static function getDbList () {
1186
+    public static function getDbList() {
1187 1187
         global $config;
1188
-        if (self::isMultipleDatabaseEnabled ()) {
1188
+        if (self::isMultipleDatabaseEnabled()) {
1189 1189
             return $config['calibre_directory'];
1190 1190
         } else {
1191
-            return array ("" => $config['calibre_directory']);
1191
+            return array("" => $config['calibre_directory']);
1192 1192
         }
1193 1193
     }
1194 1194
 
1195
-    public static function getDbNameList () {
1195
+    public static function getDbNameList() {
1196 1196
         global $config;
1197
-        if (self::isMultipleDatabaseEnabled ()) {
1198
-            return array_keys ($config['calibre_directory']);
1197
+        if (self::isMultipleDatabaseEnabled()) {
1198
+            return array_keys($config['calibre_directory']);
1199 1199
         } else {
1200
-            return array ("");
1200
+            return array("");
1201 1201
         }
1202 1202
     }
1203 1203
 
1204
-    public static function getDbName ($database = NULL) {
1204
+    public static function getDbName($database = NULL) {
1205 1205
         global $config;
1206
-        if (self::isMultipleDatabaseEnabled ()) {
1207
-            if (is_null ($database)) $database = GetUrlParam (DB, 0);
1206
+        if (self::isMultipleDatabaseEnabled()) {
1207
+            if (is_null($database)) $database = GetUrlParam(DB, 0);
1208 1208
             if (!is_null($database) && !preg_match('/^\d+$/', $database)) {
1209
-                return self::error ($database);
1209
+                return self::error($database);
1210 1210
             }
1211
-            $array = array_keys ($config['calibre_directory']);
1211
+            $array = array_keys($config['calibre_directory']);
1212 1212
             return  $array[$database];
1213 1213
         }
1214 1214
         return "";
1215 1215
     }
1216 1216
 
1217
-    public static function getDbDirectory ($database = NULL) {
1217
+    public static function getDbDirectory($database = NULL) {
1218 1218
         global $config;
1219
-        if (self::isMultipleDatabaseEnabled ()) {
1220
-            if (is_null ($database)) $database = GetUrlParam (DB, 0);
1219
+        if (self::isMultipleDatabaseEnabled()) {
1220
+            if (is_null($database)) $database = GetUrlParam(DB, 0);
1221 1221
             if (!is_null($database) && !preg_match('/^\d+$/', $database)) {
1222
-                return self::error ($database);
1222
+                return self::error($database);
1223 1223
             }
1224
-            $array = array_values ($config['calibre_directory']);
1224
+            $array = array_values($config['calibre_directory']);
1225 1225
             return  $array[$database];
1226 1226
         }
1227 1227
         return $config['calibre_directory'];
1228 1228
     }
1229 1229
 
1230 1230
 
1231
-    public static function getDbFileName ($database = NULL) {
1232
-        return self::getDbDirectory ($database) .'metadata.db';
1231
+    public static function getDbFileName($database = NULL) {
1232
+        return self::getDbDirectory($database) . 'metadata.db';
1233 1233
     }
1234 1234
 
1235
-    private static function error ($database) {
1235
+    private static function error($database) {
1236 1236
         if (php_sapi_name() != "cli") {
1237 1237
             header("location: checkconfig.php?err=1");
1238 1238
         }
1239 1239
         throw new Exception("Database <{$database}> not found.");
1240 1240
     }
1241 1241
 
1242
-    public static function getDb ($database = NULL) {
1243
-        if (is_null (self::$db)) {
1242
+    public static function getDb($database = NULL) {
1243
+        if (is_null(self::$db)) {
1244 1244
             try {
1245
-                if (is_readable (self::getDbFileName ($database))) {
1246
-                    self::$db = new PDO('sqlite:'. self::getDbFileName ($database));
1247
-                    if (useNormAndUp ()) {
1248
-                        self::$db->sqliteCreateFunction ('normAndUp', 'normAndUp', 1);
1245
+                if (is_readable(self::getDbFileName($database))) {
1246
+                    self::$db = new PDO('sqlite:' . self::getDbFileName($database));
1247
+                    if (useNormAndUp()) {
1248
+                        self::$db->sqliteCreateFunction('normAndUp', 'normAndUp', 1);
1249 1249
                     }
1250 1250
                 } else {
1251
-                    self::error ($database);
1251
+                    self::error($database);
1252 1252
                 }
1253 1253
             } catch (Exception $e) {
1254
-                self::error ($database);
1254
+                self::error($database);
1255 1255
             }
1256 1256
         }
1257 1257
         return self::$db;
1258 1258
     }
1259 1259
 
1260
-    public static function checkDatabaseAvailability () {
1261
-        if (self::noDatabaseSelected ()) {
1262
-            for ($i = 0; $i < count (self::getDbList ()); $i++) {
1263
-                self::getDb ($i);
1264
-                self::clearDb ();
1260
+    public static function checkDatabaseAvailability() {
1261
+        if (self::noDatabaseSelected()) {
1262
+            for ($i = 0; $i < count(self::getDbList()); $i++) {
1263
+                self::getDb($i);
1264
+                self::clearDb();
1265 1265
             }
1266 1266
         } else {
1267
-            self::getDb ();
1267
+            self::getDb();
1268 1268
         }
1269 1269
         return true;
1270 1270
     }
1271 1271
 
1272
-    public static function clearDb () {
1272
+    public static function clearDb() {
1273 1273
         self::$db = NULL;
1274 1274
     }
1275 1275
 
1276
-    public static function executeQuerySingle ($query, $database = NULL) {
1277
-        return self::getDb ($database)->query($query)->fetchColumn();
1276
+    public static function executeQuerySingle($query, $database = NULL) {
1277
+        return self::getDb($database)->query($query)->fetchColumn();
1278 1278
     }
1279 1279
 
1280 1280
     public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) {
1281 1281
         if (!$numberOfString) {
1282 1282
             $numberOfString = $table . ".alphabetical";
1283 1283
         }
1284
-        $count = self::executeQuerySingle ('select count(*) from ' . $table);
1284
+        $count = self::executeQuerySingle('select count(*) from ' . $table);
1285 1285
         if ($count == 0) return NULL;
1286
-        $entry = new Entry (localize($table . ".title"), $id,
1287
-            str_format (localize($numberOfString, $count), $count), "text",
1288
-            array ( new LinkNavigation ("?page=".$pageId)), "", $count);
1286
+        $entry = new Entry(localize($table . ".title"), $id,
1287
+            str_format(localize($numberOfString, $count), $count), "text",
1288
+            array(new LinkNavigation("?page=" . $pageId)), "", $count);
1289 1289
         return $entry;
1290 1290
     }
1291 1291
 
1292
-    public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) {
1293
-        list (, $result) = self::executeQuery ($query, $columns, "", $params, -1);
1292
+    public static function getEntryArrayWithBookNumber($query, $columns, $params, $category) {
1293
+        list (, $result) = self::executeQuery($query, $columns, "", $params, -1);
1294 1294
         $entryArray = array();
1295
-        while ($post = $result->fetchObject ())
1295
+        while ($post = $result->fetchObject())
1296 1296
         {
1297
-            $instance = new $category ($post);
1297
+            $instance = new $category($post);
1298 1298
             if (property_exists($post, "sort")) {
1299 1299
                 $title = $post->sort;
1300 1300
             } else {
1301 1301
                 $title = $post->name;
1302 1302
             }
1303
-            array_push ($entryArray, new Entry ($title, $instance->getEntryId (),
1304
-                str_format (localize("bookword", $post->count), $post->count), "text",
1305
-                array ( new LinkNavigation ($instance->getUri ())), "", $post->count));
1303
+            array_push($entryArray, new Entry($title, $instance->getEntryId(),
1304
+                str_format(localize("bookword", $post->count), $post->count), "text",
1305
+                array(new LinkNavigation($instance->getUri())), "", $post->count));
1306 1306
         }
1307 1307
         return $entryArray;
1308 1308
     }
@@ -1310,30 +1310,30 @@  discard block
 block discarded – undo
1310 1310
     public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
1311 1311
         $totalResult = -1;
1312 1312
 
1313
-        if (useNormAndUp ()) {
1313
+        if (useNormAndUp()) {
1314 1314
             $query = preg_replace("/upper/", "normAndUp", $query);
1315 1315
             $columns = preg_replace("/upper/", "normAndUp", $columns);
1316 1316
         }
1317 1317
 
1318
-        if (is_null ($numberPerPage)) {
1319
-            $numberPerPage = getCurrentOption ("max_item_per_page");
1318
+        if (is_null($numberPerPage)) {
1319
+            $numberPerPage = getCurrentOption("max_item_per_page");
1320 1320
         }
1321 1321
 
1322 1322
         if ($numberPerPage != -1 && $n != -1)
1323 1323
         {
1324 1324
             // First check total number of results
1325
-            $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter));
1326
-            $result->execute ($params);
1327
-            $totalResult = $result->fetchColumn ();
1325
+            $result = self::getDb($database)->prepare(str_format($query, "count(*)", $filter));
1326
+            $result->execute($params);
1327
+            $totalResult = $result->fetchColumn();
1328 1328
 
1329 1329
             // Next modify the query and params
1330 1330
             $query .= " limit ?, ?";
1331
-            array_push ($params, ($n - 1) * $numberPerPage, $numberPerPage);
1331
+            array_push($params, ($n - 1) * $numberPerPage, $numberPerPage);
1332 1332
         }
1333 1333
 
1334
-        $result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter));
1335
-        $result->execute ($params);
1336
-        return array ($totalResult, $result);
1334
+        $result = self::getDb($database)->prepare(str_format($query, $columns, $filter));
1335
+        $result->execute($params);
1336
+        return array($totalResult, $result);
1337 1337
     }
1338 1338
 
1339 1339
 }
Please login to merge, or discard this patch.
book.php 2 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -287,6 +287,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -7,35 +7,35 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
data.php 2 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -141,6 +141,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -58,25 +58,25 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
rating.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -36,6 +36,9 @@
 block discarded – undo
36 36
         return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
37 37
     }
38 38
 
39
+    /**
40
+     * @param string $query
41
+     */
39 42
     public static function getEntryArray ($query, $params) {
40 43
         list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
41 44
         $entryArray = array();
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     const ALL_RATING_ID = "cops:rating";
11 11
 
12 12
     const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
13
-    const SQL_ALL_RATINGS ="select {0} from ratings, books_ratings_link where books_ratings_link.rating = ratings.id group by ratings.id order by ratings.rating";
13
+    const SQL_ALL_RATINGS = "select {0} from ratings, books_ratings_link where books_ratings_link.rating = ratings.id group by ratings.id order by ratings.rating";
14 14
     public $id;
15 15
     public $name;
16 16
 
@@ -19,41 +19,41 @@  discard block
 block discarded – undo
19 19
         $this->name = $pname;
20 20
     }
21 21
 
22
-    public function getUri () {
23
-        return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
22
+    public function getUri() {
23
+        return "?page=" . parent::PAGE_RATING_DETAIL . "&id=$this->id";
24 24
     }
25 25
 
26
-    public function getEntryId () {
27
-        return self::ALL_RATING_ID.":".$this->id;
26
+    public function getEntryId() {
27
+        return self::ALL_RATING_ID . ":" . $this->id;
28 28
     }
29 29
 
30 30
     public static function getCount() {
31 31
         // str_format (localize("ratings", count(array))
32
-        return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
32
+        return parent::getCountGeneric("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
33 33
     }
34 34
 
35 35
     public static function getAllRatings() {
36
-        return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
36
+        return self::getEntryArray(self::SQL_ALL_RATINGS, array());
37 37
     }
38 38
 
39
-    public static function getEntryArray ($query, $params) {
40
-        list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
39
+    public static function getEntryArray($query, $params) {
40
+        list (, $result) = parent::executeQuery($query, self::RATING_COLUMNS, "", $params, -1);
41 41
         $entryArray = array();
42
-        while ($post = $result->fetchObject ())
42
+        while ($post = $result->fetchObject())
43 43
         {
44
-            $ratingObj = new Rating ($post->id, $post->rating);
45
-            $rating=$post->rating/2;
46
-            $rating = str_format (localize("ratingword", $rating), $rating);
47
-            array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
48
-                str_format (localize("bookword", $post->count), $post->count), "text",
49
-                array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
44
+            $ratingObj = new Rating($post->id, $post->rating);
45
+            $rating = $post->rating / 2;
46
+            $rating = str_format(localize("ratingword", $rating), $rating);
47
+            array_push($entryArray, new Entry($rating, $ratingObj->getEntryId(),
48
+                str_format(localize("bookword", $post->count), $post->count), "text",
49
+                array(new LinkNavigation($ratingObj->getUri())), "", $post->count));
50 50
         }
51 51
         return $entryArray;
52 52
     }
53 53
 
54
-    public static function getRatingById ($ratingId) {
55
-        $result = parent::getDb ()->prepare('select rating from ratings where id = ?');
56
-        $result->execute (array ($ratingId));
57
-        return new Rating ($ratingId, $result->fetchColumn ());
54
+    public static function getRatingById($ratingId) {
55
+        $result = parent::getDb()->prepare('select rating from ratings where id = ?');
56
+        $result->execute(array($ratingId));
57
+        return new Rating($ratingId, $result->fetchColumn());
58 58
     }
59 59
 }
Please login to merge, or discard this patch.
tag.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -45,6 +45,9 @@
 block discarded – undo
45 45
         return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
46 46
     }
47 47
 
48
+    /**
49
+     * @param integer $numberPerPage
50
+     */
48 51
     public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
49 52
         $columns  = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
50 53
         $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name';
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,44 +19,44 @@
 block discarded – undo
19 19
         $this->name = $post->name;
20 20
     }
21 21
 
22
-    public function getUri () {
23
-        return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
22
+    public function getUri() {
23
+        return "?page=" . parent::PAGE_TAG_DETAIL . "&id=$this->id";
24 24
     }
25 25
 
26
-    public function getEntryId () {
27
-        return self::ALL_TAGS_ID.":".$this->id;
26
+    public function getEntryId() {
27
+        return self::ALL_TAGS_ID . ":" . $this->id;
28 28
     }
29 29
 
30 30
     public static function getCount() {
31 31
         // str_format (localize("tags.alphabetical", count(array))
32
-        return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
32
+        return parent::getCountGeneric("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
33 33
     }
34 34
 
35
-    public static function getTagById ($tagId) {
36
-        $result = parent::getDb ()->prepare('select id, name  from tags where id = ?');
37
-        $result->execute (array ($tagId));
38
-        if ($post = $result->fetchObject ()) {
39
-            return new Tag ($post);
35
+    public static function getTagById($tagId) {
36
+        $result = parent::getDb()->prepare('select id, name  from tags where id = ?');
37
+        $result->execute(array($tagId));
38
+        if ($post = $result->fetchObject()) {
39
+            return new Tag($post);
40 40
         }
41 41
         return NULL;
42 42
     }
43 43
 
44 44
     public static function getAllTags() {
45
-        return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
45
+        return Base::getEntryArrayWithBookNumber(self::SQL_ALL_TAGS, self::TAG_COLUMNS, array(), "Tag");
46 46
     }
47 47
 
48 48
     public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
49
-        $columns  = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
49
+        $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
50 50
         $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name';
51
-        list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage);
51
+        list ($totalNumber, $result) = parent::executeQuery($sql, $columns, "", array('%' . $query . '%'), $n, $database, $numberPerPage);
52 52
         $entryArray = array();
53
-        while ($post = $result->fetchObject ())
53
+        while ($post = $result->fetchObject())
54 54
         {
55
-            $tag = new Tag ($post);
56
-            array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
57
-                str_format (localize("bookword", $post->count), $post->count), "text",
58
-                array ( new LinkNavigation ($tag->getUri ()))));
55
+            $tag = new Tag($post);
56
+            array_push($entryArray, new Entry($tag->name, $tag->getEntryId(),
57
+                str_format(localize("bookword", $post->count), $post->count), "text",
58
+                array(new LinkNavigation($tag->getUri()))));
59 59
         }
60
-        return array ($entryArray, $totalNumber);
60
+        return array($entryArray, $totalNumber);
61 61
     }
62 62
 }
Please login to merge, or discard this patch.
transliteration.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@
 block discarded – undo
163 163
 /**
164 164
  * Replaces a Unicode character using the transliteration database.
165 165
  *
166
- * @param $ord
166
+ * @param integer $ord
167 167
  *   An ordinal Unicode character code.
168 168
  * @param $unknown
169 169
  *   Replacement string for characters that do not have a suitable ASCII
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     // Counting down is faster. I'm *so* sorry.
91 91
     $len = $chunk + 1;
92 92
 
93
-    for ($i = -1; --$len; ) {
93
+    for ($i = -1; --$len;) {
94 94
       $c = $str[++$i];
95 95
       if ($remaining = $tail_bytes[$c]) {
96 96
         // UTF-8 head byte!
@@ -207,5 +207,5 @@  discard block
 block discarded – undo
207 207
 
208 208
   $ord = $ord & 255;
209 209
 
210
-  return isset($map[$bank][$langcode][$ord]) ? $map[$bank][$langcode][$ord] : $unknown;
210
+  return isset($map[$bank][$langcode][$ord])?$map[$bank][$langcode][$ord]:$unknown;
211 211
 }
Please login to merge, or discard this patch.
serie.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -20,44 +20,44 @@
 block discarded – undo
20 20
         $this->name = $post->name;
21 21
     }
22 22
 
23
-    public function getUri () {
24
-        return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
23
+    public function getUri() {
24
+        return "?page=" . parent::PAGE_SERIE_DETAIL . "&id=$this->id";
25 25
     }
26 26
 
27
-    public function getEntryId () {
28
-        return self::ALL_SERIES_ID.":".$this->id;
27
+    public function getEntryId() {
28
+        return self::ALL_SERIES_ID . ":" . $this->id;
29 29
     }
30 30
 
31 31
     public static function getCount() {
32 32
         // str_format (localize("series.alphabetical", count(array))
33
-        return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
33
+        return parent::getCountGeneric("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
34 34
     }
35 35
 
36
-    public static function getSerieByBookId ($bookId) {
37
-        $result = parent::getDb ()->prepare('select  series.id as id, name
36
+    public static function getSerieByBookId($bookId) {
37
+        $result = parent::getDb()->prepare('select  series.id as id, name
38 38
 from books_series_link, series
39 39
 where series.id = series and book = ?');
40
-        $result->execute (array ($bookId));
41
-        if ($post = $result->fetchObject ()) {
42
-            return new Serie ($post);
40
+        $result->execute(array($bookId));
41
+        if ($post = $result->fetchObject()) {
42
+            return new Serie($post);
43 43
         }
44 44
         return NULL;
45 45
     }
46 46
 
47
-    public static function getSerieById ($serieId) {
48
-        $result = parent::getDb ()->prepare('select id, name  from series where id = ?');
49
-        $result->execute (array ($serieId));
50
-        if ($post = $result->fetchObject ()) {
51
-            return new Serie ($post);
47
+    public static function getSerieById($serieId) {
48
+        $result = parent::getDb()->prepare('select id, name  from series where id = ?');
49
+        $result->execute(array($serieId));
50
+        if ($post = $result->fetchObject()) {
51
+            return new Serie($post);
52 52
         }
53 53
         return NULL;
54 54
     }
55 55
 
56 56
     public static function getAllSeries() {
57
-        return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array (), "Serie");
57
+        return Base::getEntryArrayWithBookNumber(self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array(), "Serie");
58 58
     }
59 59
 
60 60
     public static function getAllSeriesByQuery($query) {
61
-        return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array ('%' . $query . '%'), "Serie");
61
+        return Base::getEntryArrayWithBookNumber(self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array('%' . $query . '%'), "Serie");
62 62
     }
63 63
 }
Please login to merge, or discard this patch.
fetch.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
     if ($config ['cops_fetch_protect'] == "1") {
14 14
         session_start();
15 15
         if (!isset($_SESSION['connected'])) {
16
-            notFound ();
16
+            notFound();
17 17
             return;
18 18
         }
19 19
     }
20 20
 
21
-    $expires = 60*60*24*14;
21
+    $expires = 60 * 60 * 24 * 14;
22 22
     header("Pragma: public");
23
-    header("Cache-Control: maxage=".$expires);
24
-    header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
25
-    $bookId = getURLParam ("id", NULL);
26
-    $type = getURLParam ("type", "jpg");
27
-    $idData = getURLParam ("data", NULL);
28
-    if (is_null ($bookId))
23
+    header("Cache-Control: maxage=" . $expires);
24
+    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
25
+    $bookId = getURLParam("id", NULL);
26
+    $type = getURLParam("type", "jpg");
27
+    $idData = getURLParam("data", NULL);
28
+    if (is_null($bookId))
29 29
     {
30 30
         $book = Book::getBookByDataId($idData);
31 31
     }
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
     }
36 36
 
37 37
     if (!$book) {
38
-        notFound ();
38
+        notFound();
39 39
         return;
40 40
     }
41 41
 
42 42
     if ($book && ($type == "jpg" || empty ($config['calibre_internal_directory']))) {
43 43
         if ($type == "jpg") {
44
-            $file = $book->getFilePath ($type);
44
+            $file = $book->getFilePath($type);
45 45
         } else {
46
-            $file = $book->getFilePath ($type, $idData);
46
+            $file = $book->getFilePath($type, $idData);
47 47
         }
48
-        if (!$file || !file_exists ($file)) {
49
-            notFound ();
48
+        if (!$file || !file_exists($file)) {
49
+            notFound();
50 50
             return;
51 51
         }
52 52
     }
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
             header("Content-Type: image/jpeg");
58 58
             //by default, we don't cache
59 59
             $thumbnailCacheFullpath = null;
60
-            if ( isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '' ) {
60
+            if (isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '') {
61 61
                 $thumbnailCacheFullpath = $config['cops_thumbnail_cache_directory'];
62 62
                 //if multiple databases, add a subfolder with the database ID
63
-                $thumbnailCacheFullpath .= !is_null (GetUrlParam (DB)) ? 'db-' . GetUrlParam (DB) . DIRECTORY_SEPARATOR : '';
63
+                $thumbnailCacheFullpath .= !is_null(GetUrlParam(DB))?'db-' . GetUrlParam(DB) . DIRECTORY_SEPARATOR:'';
64 64
                 //when there are lots of thumbnails, it's better to save files in subfolders, so if the book's uuid is
65 65
                 //"01234567-89ab-cdef-0123-456789abcdef", we will save the thumbnail in .../0/12/34567-89ab-cdef-0123-456789abcdef-...
66 66
                 $thumbnailCacheFullpath .= substr($book->uuid, 0, 1) . DIRECTORY_SEPARATOR . substr($book->uuid, 1, 2) . DIRECTORY_SEPARATOR;
67 67
                 //check if cache folder exists or create it
68
-                if ( file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true) ) {
68
+                if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) {
69 69
                     //we name the thumbnail from the book's uuid and it's dimensions (width and/or height)
70
-                    $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam ("width") . 'x' . getURLParam ("height") . '.jpg';
70
+                    $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam("width") . 'x' . getURLParam("height") . '.jpg';
71 71
                     $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName;
72 72
                 }
73 73
                 else {
@@ -76,45 +76,45 @@  discard block
 block discarded – undo
76 76
                 }
77 77
             }
78 78
 
79
-            if ( $thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath) ) {
79
+            if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) {
80 80
                 //return the already cached thumbnail
81
-                readfile( $thumbnailCacheFullpath );
81
+                readfile($thumbnailCacheFullpath);
82 82
                 return;
83 83
             }
84 84
 
85
-            if ($book->getThumbnail (getURLParam ("width"), getURLParam ("height"), $thumbnailCacheFullpath)) {
85
+            if ($book->getThumbnail(getURLParam("width"), getURLParam("height"), $thumbnailCacheFullpath)) {
86 86
                 //if we don't cache the thumbnail, imagejpeg() in $book->getThumbnail() already return the image data
87
-                if ( $thumbnailCacheFullpath === null ) {
87
+                if ($thumbnailCacheFullpath === null) {
88 88
                     // The cover had to be resized
89 89
                     return;
90 90
                 }
91 91
                 else {
92 92
                     //return the just cached thumbnail
93
-                    readfile( $thumbnailCacheFullpath );
93
+                    readfile($thumbnailCacheFullpath);
94 94
                     return;
95 95
                 }
96 96
             }
97 97
             break;
98 98
         default:
99
-            $data = $book->getDataById ($idData);
100
-            header("Content-Type: " . $data->getMimeType ());
99
+            $data = $book->getDataById($idData);
100
+            header("Content-Type: " . $data->getMimeType());
101 101
             break;
102 102
     }
103
-    $file = $book->getFilePath ($type, $idData, true);
103
+    $file = $book->getFilePath($type, $idData, true);
104 104
     if ($type == "epub" && $config['cops_update_epub-metadata'])
105 105
     {
106
-        $book->getUpdatedEpub ($idData);
106
+        $book->getUpdatedEpub($idData);
107 107
         return;
108 108
     }
109 109
     if ($type == "jpg") {
110
-        header('Content-Disposition: filename="' . basename ($file) . '"');
110
+        header('Content-Disposition: filename="' . basename($file) . '"');
111 111
     } else {
112
-        header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
112
+        header('Content-Disposition: attachment; filename="' . basename($file) . '"');
113 113
     }
114 114
 
115 115
     $dir = $config['calibre_internal_directory'];
116 116
     if (empty ($config['calibre_internal_directory'])) {
117
-        $dir = Base::getDbDirectory ();
117
+        $dir = Base::getDbDirectory();
118 118
     }
119 119
 
120 120
     if (empty ($config['cops_x_accel_redirect'])) {
@@ -124,5 +124,5 @@  discard block
 block discarded – undo
124 124
         fpassthru($fp);
125 125
     }
126 126
     else {
127
-        header ($config['cops_x_accel_redirect'] . ": " . $dir . $file);
127
+        header($config['cops_x_accel_redirect'] . ": " . $dir . $file);
128 128
     }
Please login to merge, or discard this patch.