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.
Braces   +27 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,7 +6,8 @@  discard block
 block discarded – undo
6 6
  * @author     Sébastien Lucas <[email protected]>
7 7
  */
8 8
 
9
-class Author extends Base {
9
+class Author extends Base
10
+{
10 11
     const ALL_AUTHORS_ID = "cops:authors";
11 12
 
12 13
     const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count";
@@ -18,37 +19,42 @@  discard block
 block discarded – undo
18 19
     public $name;
19 20
     public $sort;
20 21
 
21
-    public function __construct($post) {
22
+    public function __construct($post)
23
+    {
22 24
         $this->id = $post->id;
23 25
         $this->name = str_replace("|", ",", $post->name);
24 26
         $this->sort = $post->sort;
25 27
     }
26 28
 
27
-    public function getUri () {
29
+    public function getUri ()
30
+    {
28 31
         return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id";
29 32
     }
30 33
 
31
-    public function getEntryId () {
34
+    public function getEntryId ()
35
+    {
32 36
         return self::ALL_AUTHORS_ID.":".$this->id;
33 37
     }
34 38
 
35
-    public static function getEntryIdByLetter ($startingLetter) {
39
+    public static function getEntryIdByLetter ($startingLetter)
40
+    {
36 41
         return self::ALL_AUTHORS_ID.":letter:".$startingLetter;
37 42
     }
38 43
 
39
-    public static function getCount() {
44
+    public static function getCount()
45
+    {
40 46
         // str_format (localize("authors.alphabetical", count(array))
41 47
         return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS);
42 48
     }
43 49
 
44
-    public static function getAllAuthorsByFirstLetter() {
50
+    public static function getAllAuthorsByFirstLetter()
51
+    {
45 52
         list (, $result) = parent::executeQuery ("select {0}
46 53
 from authors
47 54
 group by substr (upper (sort), 1, 1)
48 55
 order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array (), -1);
49 56
         $entryArray = array();
50
-        while ($post = $result->fetchObject ())
51
-        {
57
+        while ($post = $result->fetchObject ()) {
52 58
             array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title),
53 59
                 str_format (localize("authorword", $post->count), $post->count), "text",
54 60
                 array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count));
@@ -56,30 +62,36 @@  discard block
 block discarded – undo
56 62
         return $entryArray;
57 63
     }
58 64
 
59
-    public static function getAuthorsByStartingLetter($letter) {
65
+    public static function getAuthorsByStartingLetter($letter)
66
+    {
60 67
         return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%"));
61 68
     }
62 69
 
63
-    public static function getAuthorsForSearch($query) {
70
+    public static function getAuthorsForSearch($query)
71
+    {
64 72
         return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%"));
65 73
     }
66 74
 
67
-    public static function getAllAuthors() {
75
+    public static function getAllAuthors()
76
+    {
68 77
         return self::getEntryArray (self::SQL_ALL_AUTHORS, array ());
69 78
     }
70 79
 
71
-    public static function getEntryArray ($query, $params) {
80
+    public static function getEntryArray ($query, $params)
81
+    {
72 82
         return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author");
73 83
     }
74 84
 
75
-    public static function getAuthorById ($authorId) {
85
+    public static function getAuthorById ($authorId)
86
+    {
76 87
         $result = parent::getDb ()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?');
77 88
         $result->execute (array ($authorId));
78 89
         $post = $result->fetchObject ();
79 90
         return new Author ($post);
80 91
     }
81 92
 
82
-    public static function getAuthorByBookId ($bookId) {
93
+    public static function getAuthorByBookId ($bookId)
94
+    {
83 95
         $result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link
84 96
 where author = authors.id
85 97
 and book = ?');
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.
Braces   +186 added lines, -99 removed lines patch added patch discarded remove patch
@@ -13,12 +13,14 @@  discard block
 block discarded – undo
13 13
 date_default_timezone_set($config['default_timezone']);
14 14
 
15 15
 
16
-function useServerSideRendering () {
16
+function useServerSideRendering ()
17
+{
17 18
     global $config;
18 19
     return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']);
19 20
 }
20 21
 
21
-function serverSideRender ($data) {
22
+function serverSideRender ($data)
23
+{
22 24
     // Get the templates
23 25
     $theme = getCurrentTemplate ();
24 26
     $header = file_get_contents('templates/' . $theme . '/header.html');
@@ -46,28 +48,32 @@  discard block
 block discarded – undo
46 48
     return NULL;
47 49
 }
48 50
 
49
-function getQueryString () {
51
+function getQueryString ()
52
+{
50 53
     if ( isset($_SERVER['QUERY_STRING']) ) {
51 54
         return $_SERVER['QUERY_STRING'];
52 55
     }
53 56
     return "";
54 57
 }
55 58
 
56
-function notFound () {
59
+function notFound ()
60
+{
57 61
     header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
58 62
     header("Status: 404 Not Found");
59 63
 
60 64
     $_SERVER['REDIRECT_STATUS'] = 404;
61 65
 }
62 66
 
63
-function getURLParam ($name, $default = NULL) {
67
+function getURLParam ($name, $default = NULL)
68
+{
64 69
     if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") {
65 70
         return $_GET[$name];
66 71
     }
67 72
     return $default;
68 73
 }
69 74
 
70
-function getCurrentOption ($option) {
75
+function getCurrentOption ($option)
76
+{
71 77
     global $config;
72 78
     if (isset($_COOKIE[$option])) {
73 79
         if (isset($config ["cops_" . $option]) && is_array ($config ["cops_" . $option])) {
@@ -83,19 +89,23 @@  discard block
 block discarded – undo
83 89
     return "";
84 90
 }
85 91
 
86
-function getCurrentCss () {
92
+function getCurrentCss ()
93
+{
87 94
     return "templates/" . getCurrentTemplate () . "/styles/style-" . getCurrentOption ("style") . ".css";
88 95
 }
89 96
 
90
-function getCurrentTemplate () {
97
+function getCurrentTemplate ()
98
+{
91 99
     return getCurrentOption ("template");
92 100
 }
93 101
 
94
-function getUrlWithVersion ($url) {
102
+function getUrlWithVersion ($url)
103
+{
95 104
     return $url . "?v=" . VERSION;
96 105
 }
97 106
 
98
-function xml2xhtml($xml) {
107
+function xml2xhtml($xml)
108
+{
99 109
     return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', '
100 110
         $xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param");
101 111
         return in_array($m[1], $xhtml_tags) ? "<$m[1]$m[2] />" : "<$m[1]$m[2]></$m[1]>";
@@ -135,12 +145,15 @@  discard block
 block discarded – undo
135 145
     $errors = libxml_get_errors();
136 146
 
137 147
     foreach ($errors as $error) {
138
-        if ($error->code == 801) return false;
148
+        if ($error->code == 801) {
149
+            return false;
150
+        }
139 151
     }
140 152
     return true;
141 153
 }
142 154
 
143
-function html2xhtml ($html) {
155
+function html2xhtml ($html)
156
+{
144 157
     $doc = new DOMDocument();
145 158
     libxml_use_internal_errors(true);
146 159
 
@@ -160,7 +173,9 @@  discard block
 block discarded – undo
160 173
     }
161 174
     */
162 175
 
163
-    if (!are_libxml_errors_ok ()) $output = "HTML code not valid.";
176
+    if (!are_libxml_errors_ok ()) {
177
+        $output = "HTML code not valid.";
178
+    }
164 179
 
165 180
     libxml_use_internal_errors(false);
166 181
     return $output;
@@ -170,7 +185,8 @@  discard block
 block discarded – undo
170 185
  * This method is a direct copy-paste from
171 186
  * http://tmont.com/blargh/2010/1/string-format-in-php
172 187
  */
173
-function str_format($format) {
188
+function str_format($format)
189
+{
174 190
     $args = func_get_args();
175 191
     $format = array_shift($args);
176 192
 
@@ -190,7 +206,8 @@  discard block
 block discarded – undo
190 206
  * languages id are normalized : fr-fr -> fr_FR
191 207
  * @return array of languages
192 208
  */
193
-function getAcceptLanguages() {
209
+function getAcceptLanguages()
210
+{
194 211
     $langs = array();
195 212
 
196 213
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
@@ -218,7 +235,9 @@  discard block
 block discarded – undo
218 235
 
219 236
             // set default to 1 for any without q factor
220 237
             foreach ($langs as $lang => $val) {
221
-                if ($val === '') $langs[$lang] = 1;
238
+                if ($val === '') {
239
+                    $langs[$lang] = 1;
240
+                }
222 241
             }
223 242
 
224 243
             // sort list based on value
@@ -233,14 +252,14 @@  discard block
 block discarded – undo
233 252
  * Find the best translation file possible based on the accepted languages
234 253
  * @return array of language and language file
235 254
  */
236
-function getLangAndTranslationFile() {
255
+function getLangAndTranslationFile()
256
+{
237 257
     global $config;
238 258
     $langs = array();
239 259
     $lang = "en";
240 260
     if (!empty($config['cops_language'])) {
241 261
         $lang = $config['cops_language'];
242
-    }
243
-    elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
262
+    } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
244 263
         $langs = getAcceptLanguages();
245 264
     }
246 265
     //echo var_dump($langs);
@@ -263,14 +282,18 @@  discard block
 block discarded – undo
263 282
  * This method is based on this page
264 283
  * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/
265 284
  */
266
-function localize($phrase, $count=-1, $reset=false) {
285
+function localize($phrase, $count=-1, $reset=false)
286
+{
267 287
     global $config;
268
-    if ($count == 0)
269
-        $phrase .= ".none";
270
-    if ($count == 1)
271
-        $phrase .= ".one";
272
-    if ($count > 1)
273
-        $phrase .= ".many";
288
+    if ($count == 0) {
289
+            $phrase .= ".none";
290
+    }
291
+    if ($count == 1) {
292
+            $phrase .= ".one";
293
+    }
294
+    if ($count > 1) {
295
+            $phrase .= ".many";
296
+    }
274 297
 
275 298
     /* Static keyword is used to ensure the file is loaded only once */
276 299
     static $translations = NULL;
@@ -295,8 +318,7 @@  discard block
 block discarded – undo
295 318
                 unset ($translations [$key]);
296 319
             }
297 320
         }
298
-        if ($lang_file_en)
299
-        {
321
+        if ($lang_file_en) {
300 322
             $lang_file_content = file_get_contents($lang_file_en);
301 323
             $translations_en = json_decode($lang_file_content, true);
302 324
             $translations = array_merge ($translations_en, $translations);
@@ -308,7 +330,8 @@  discard block
 block discarded – undo
308 330
     return $phrase;
309 331
 }
310 332
 
311
-function addURLParameter($urlParams, $paramName, $paramValue) {
333
+function addURLParameter($urlParams, $paramName, $paramValue)
334
+{
312 335
     if (empty ($urlParams)) {
313 336
         $urlParams = "";
314 337
     }
@@ -327,17 +350,20 @@  discard block
 block discarded – undo
327 350
     return $start . http_build_query($params);
328 351
 }
329 352
 
330
-function useNormAndUp () {
353
+function useNormAndUp ()
354
+{
331 355
     global $config;
332 356
     return $config ['cops_normalized_search'] == "1";
333 357
 }
334 358
 
335
-function normalizeUtf8String( $s) {
359
+function normalizeUtf8String( $s)
360
+{
336 361
     include_once 'transliteration.php';
337 362
     return _transliteration_process($s);
338 363
 }
339 364
 
340
-function normAndUp ($s) {
365
+function normAndUp ($s)
366
+{
341 367
     return mb_strtoupper (normalizeUtf8String($s), 'UTF-8');
342 368
 }
343 369
 
@@ -356,7 +382,8 @@  discard block
 block discarded – undo
356 382
     public $facetGroup;
357 383
     public $activeFacet;
358 384
 
359
-    public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
385
+    public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE)
386
+    {
360 387
         $this->href = $phref;
361 388
         $this->type = $ptype;
362 389
         $this->rel = $prel;
@@ -365,11 +392,13 @@  discard block
 block discarded – undo
365 392
         $this->activeFacet = $pactiveFacet;
366 393
     }
367 394
 
368
-    public function hrefXhtml () {
395
+    public function hrefXhtml ()
396
+    {
369 397
         return $this->href;
370 398
     }
371 399
 
372
-    public function getScriptName() {
400
+    public function getScriptName()
401
+    {
373 402
         $parts = explode('/', $_SERVER["SCRIPT_NAME"]);
374 403
         return $parts[count($parts) - 1];
375 404
     }
@@ -377,10 +406,15 @@  discard block
 block discarded – undo
377 406
 
378 407
 class LinkNavigation extends Link
379 408
 {
380
-    public function __construct($phref, $prel = NULL, $ptitle = NULL) {
409
+    public function __construct($phref, $prel = NULL, $ptitle = NULL)
410
+    {
381 411
         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;
412
+        if (!is_null (GetUrlParam (DB))) {
413
+            $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
414
+        }
415
+        if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) {
416
+            $this->href = "?" . $this->href;
417
+        }
384 418
         if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) {
385 419
             $this->href = "index.php" . $this->href;
386 420
         } else {
@@ -391,9 +425,12 @@  discard block
 block discarded – undo
391 425
 
392 426
 class LinkFacet extends Link
393 427
 {
394
-    public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
428
+    public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE)
429
+    {
395 430
         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));
431
+        if (!is_null (GetUrlParam (DB))) {
432
+            $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
433
+        }
397 434
         $this->href = parent::getScriptName() . $this->href;
398 435
     }
399 436
 }
@@ -423,7 +460,8 @@  discard block
 block discarded – undo
423 460
         Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png'
424 461
     );
425 462
 
426
-    public function getUpdatedTime () {
463
+    public function getUpdatedTime ()
464
+    {
427 465
         if (!is_null ($this->localUpdated)) {
428 466
             return date (DATE_ATOM, $this->localUpdated);
429 467
         }
@@ -433,7 +471,8 @@  discard block
 block discarded – undo
433 471
         return date (DATE_ATOM, self::$updated);
434 472
     }
435 473
 
436
-    public function getNavLink () {
474
+    public function getNavLink ()
475
+    {
437 476
         foreach ($this->linkArray as $link) {
438 477
             if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; }
439 478
 
@@ -442,7 +481,8 @@  discard block
 block discarded – undo
442 481
         return "#";
443 482
     }
444 483
 
445
-    public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0) {
484
+    public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "", $pcount = 0)
485
+    {
446 486
         global $config;
447 487
         $this->title = $ptitle;
448 488
         $this->id = $pid;
@@ -452,10 +492,8 @@  discard block
 block discarded – undo
452 492
         $this->className = $pclass;
453 493
         $this->numberOfElement = $pcount;
454 494
 
455
-        if ($config['cops_show_icons'] == 1)
456
-        {
457
-            foreach (self::$icons as $reg => $image)
458
-            {
495
+        if ($config['cops_show_icons'] == 1) {
496
+            foreach (self::$icons as $reg => $image) {
459 497
                 if (preg_match ("/" . $reg . "/", $pid)) {
460 498
                     array_push ($this->linkArray, new Link (getUrlWithVersion ($image), "image/png", Link::OPDS_THUMBNAIL_TYPE));
461 499
                     break;
@@ -463,7 +501,9 @@  discard block
 block discarded – undo
463 501
             }
464 502
         }
465 503
 
466
-        if (!is_null (GetUrlParam (DB))) $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id);
504
+        if (!is_null (GetUrlParam (DB))) {
505
+            $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id);
506
+        }
467 507
     }
468 508
 }
469 509
 
@@ -471,24 +511,29 @@  discard block
 block discarded – undo
471 511
 {
472 512
     public $book;
473 513
 
474
-    public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) {
514
+    public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook)
515
+    {
475 516
         parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
476 517
         $this->book = $pbook;
477 518
         $this->localUpdated = $pbook->timestamp;
478 519
     }
479 520
 
480
-    public function getCoverThumbnail () {
521
+    public function getCoverThumbnail ()
522
+    {
481 523
         foreach ($this->linkArray as $link) {
482
-            if ($link->rel == Link::OPDS_THUMBNAIL_TYPE)
483
-                return $link->hrefXhtml ();
524
+            if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) {
525
+                            return $link->hrefXhtml ();
526
+            }
484 527
         }
485 528
         return null;
486 529
     }
487 530
 
488
-    public function getCover () {
531
+    public function getCover ()
532
+    {
489 533
         foreach ($this->linkArray as $link) {
490
-            if ($link->rel == Link::OPDS_IMAGE_TYPE)
491
-                return $link->hrefXhtml ();
534
+            if ($link->rel == Link::OPDS_IMAGE_TYPE) {
535
+                            return $link->hrefXhtml ();
536
+            }
492 537
         }
493 538
         return null;
494 539
     }
@@ -564,7 +609,8 @@  discard block
 block discarded – undo
564 609
         }
565 610
     }
566 611
 
567
-    public function __construct($pid, $pquery, $pn) {
612
+    public function __construct($pid, $pquery, $pn)
613
+    {
568 614
         global $config;
569 615
 
570 616
         $this->idGet = $pid;
@@ -597,23 +643,33 @@  discard block
 block discarded – undo
597 643
             }
598 644
             if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) {
599 645
                 $series = Serie::getCount();
600
-                if (!is_null ($series)) array_push ($this->entryArray, $series);
646
+                if (!is_null ($series)) {
647
+                    array_push ($this->entryArray, $series);
648
+                }
601 649
             }
602 650
             if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) {
603 651
                 $publisher = Publisher::getCount();
604
-                if (!is_null ($publisher)) array_push ($this->entryArray, $publisher);
652
+                if (!is_null ($publisher)) {
653
+                    array_push ($this->entryArray, $publisher);
654
+                }
605 655
             }
606 656
             if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) {
607 657
                 $tags = Tag::getCount();
608
-                if (!is_null ($tags)) array_push ($this->entryArray, $tags);
658
+                if (!is_null ($tags)) {
659
+                    array_push ($this->entryArray, $tags);
660
+                }
609 661
             }
610 662
             if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) {
611 663
                 $rating = Rating::getCount();
612
-                if (!is_null ($rating)) array_push ($this->entryArray, $rating);
664
+                if (!is_null ($rating)) {
665
+                    array_push ($this->entryArray, $rating);
666
+                }
613 667
             }
614 668
             if (!in_array ("language", getCurrentOption ('ignored_categories'))) {
615 669
                 $languages = Language::getCount();
616
-                if (!is_null ($languages)) array_push ($this->entryArray, $languages);
670
+                if (!is_null ($languages)) {
671
+                    array_push ($this->entryArray, $languages);
672
+                }
617 673
             }
618 674
             foreach ($config['cops_calibre_custom_column'] as $lookup) {
619 675
                 $customId = CustomColumn::getCustomId ($lookup);
@@ -623,7 +679,9 @@  discard block
 block discarded – undo
623 679
             }
624 680
             $this->entryArray = array_merge ($this->entryArray, Book::getCount());
625 681
 
626
-            if (Base::isMultipleDatabaseEnabled ()) $this->title =  Base::getDbName ();
682
+            if (Base::isMultipleDatabaseEnabled ()) {
683
+                $this->title =  Base::getDbName ();
684
+            }
627 685
         }
628 686
     }
629 687
 
@@ -659,8 +717,12 @@  discard block
 block discarded – undo
659 717
 
660 718
     public function containsBook ()
661 719
     {
662
-        if (count ($this->entryArray) == 0) return false;
663
-        if (get_class ($this->entryArray [0]) == "EntryBook") return true;
720
+        if (count ($this->entryArray) == 0) {
721
+            return false;
722
+        }
723
+        if (get_class ($this->entryArray [0]) == "EntryBook") {
724
+            return true;
725
+        }
664 726
         return false;
665 727
     }
666 728
 }
@@ -672,8 +734,7 @@  discard block
 block discarded – undo
672 734
         $this->title = localize("authors.title");
673 735
         if (getCurrentOption ("author_split_first_letter") == 1) {
674 736
             $this->entryArray = Author::getAllAuthorsByFirstLetter();
675
-        }
676
-        else {
737
+        } else {
677 738
             $this->entryArray = Author::getAllAuthors();
678 739
         }
679 740
         $this->idPage = Author::ALL_AUTHORS_ID;
@@ -836,8 +897,7 @@  discard block
 block discarded – undo
836 897
         $this->title = localize ("allbooks.title");
837 898
         if (getCurrentOption ("titles_split_first_letter") == 1) {
838 899
             $this->entryArray = Book::getAllBooks();
839
-        }
840
-        else {
900
+        } else {
841 901
             list ($this->entryArray, $this->totalNumber) = Book::getBooks ($this->n);
842 902
         }
843 903
         $this->idPage = Book::ALL_BOOKS_ID;
@@ -852,8 +912,9 @@  discard block
 block discarded – undo
852 912
         $this->idPage = Book::getEntryIdByLetter ($this->idGet);
853 913
 
854 914
         $count = $this->totalNumber;
855
-        if ($count == -1)
856
-            $count = count ($this->entryArray);
915
+        if ($count == -1) {
916
+                    $count = count ($this->entryArray);
917
+        }
857 918
 
858 919
         $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet);
859 920
     }
@@ -878,11 +939,13 @@  discard block
 block discarded – undo
878 939
     const SCOPE_BOOK = "book";
879 940
     const SCOPE_PUBLISHER = "publisher";
880 941
 
881
-    private function useTypeahead () {
942
+    private function useTypeahead ()
943
+    {
882 944
         return !is_null (getURLParam ("search"));
883 945
     }
884 946
 
885
-    private function searchByScope ($scope, $limit = FALSE) {
947
+    private function searchByScope ($scope, $limit = FALSE)
948
+    {
886 949
         $n = $this->n;
887 950
         $numberPerPage = NULL;
888 951
         $queryNormedAndUp = $this->query;
@@ -917,7 +980,8 @@  discard block
 block discarded – undo
917 980
         return $array;
918 981
     }
919 982
 
920
-    public function doSearchByCategory () {
983
+    public function doSearchByCategory ()
984
+    {
921 985
         $database = GetUrlParam (DB);
922 986
         $out = array ();
923 987
         $pagequery = Base::PAGE_OPENSEARCH_QUERY;
@@ -1044,7 +1108,8 @@  discard block
 block discarded – undo
1044 1108
 
1045 1109
 class PageCustomize extends Page
1046 1110
 {
1047
-    private function isChecked ($key, $testedValue = 1) {
1111
+    private function isChecked ($key, $testedValue = 1)
1112
+    {
1048 1113
         $value = getCurrentOption ($key);
1049 1114
         if (is_array ($value)) {
1050 1115
             if (in_array ($testedValue, $value)) {
@@ -1058,14 +1123,16 @@  discard block
 block discarded – undo
1058 1123
         return "";
1059 1124
     }
1060 1125
 
1061
-    private function isSelected ($key, $value) {
1126
+    private function isSelected ($key, $value)
1127
+    {
1062 1128
         if (getCurrentOption ($key) == $value) {
1063 1129
             return "selected='selected'";
1064 1130
         }
1065 1131
         return "";
1066 1132
     }
1067 1133
 
1068
-    private function getStyleList () {
1134
+    private function getStyleList ()
1135
+    {
1069 1136
         $result = array ();
1070 1137
         foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) {
1071 1138
             if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) {
@@ -1167,23 +1234,27 @@  discard block
 block discarded – undo
1167 1234
 
1168 1235
     private static $db = NULL;
1169 1236
 
1170
-    public static function isMultipleDatabaseEnabled () {
1237
+    public static function isMultipleDatabaseEnabled ()
1238
+    {
1171 1239
         global $config;
1172 1240
         return is_array ($config['calibre_directory']);
1173 1241
     }
1174 1242
 
1175
-    public static function useAbsolutePath () {
1243
+    public static function useAbsolutePath ()
1244
+    {
1176 1245
         global $config;
1177 1246
         $path = self::getDbDirectory();
1178 1247
         return preg_match ('/^\//', $path) || // Linux /
1179 1248
                preg_match ('/^\w\:/', $path); // Windows X:
1180 1249
     }
1181 1250
 
1182
-    public static function noDatabaseSelected () {
1251
+    public static function noDatabaseSelected ()
1252
+    {
1183 1253
         return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
1184 1254
     }
1185 1255
 
1186
-    public static function getDbList () {
1256
+    public static function getDbList ()
1257
+    {
1187 1258
         global $config;
1188 1259
         if (self::isMultipleDatabaseEnabled ()) {
1189 1260
             return $config['calibre_directory'];
@@ -1192,7 +1263,8 @@  discard block
 block discarded – undo
1192 1263
         }
1193 1264
     }
1194 1265
 
1195
-    public static function getDbNameList () {
1266
+    public static function getDbNameList ()
1267
+    {
1196 1268
         global $config;
1197 1269
         if (self::isMultipleDatabaseEnabled ()) {
1198 1270
             return array_keys ($config['calibre_directory']);
@@ -1201,10 +1273,13 @@  discard block
 block discarded – undo
1201 1273
         }
1202 1274
     }
1203 1275
 
1204
-    public static function getDbName ($database = NULL) {
1276
+    public static function getDbName ($database = NULL)
1277
+    {
1205 1278
         global $config;
1206 1279
         if (self::isMultipleDatabaseEnabled ()) {
1207
-            if (is_null ($database)) $database = GetUrlParam (DB, 0);
1280
+            if (is_null ($database)) {
1281
+                $database = GetUrlParam (DB, 0);
1282
+            }
1208 1283
             if (!is_null($database) && !preg_match('/^\d+$/', $database)) {
1209 1284
                 return self::error ($database);
1210 1285
             }
@@ -1214,10 +1289,13 @@  discard block
 block discarded – undo
1214 1289
         return "";
1215 1290
     }
1216 1291
 
1217
-    public static function getDbDirectory ($database = NULL) {
1292
+    public static function getDbDirectory ($database = NULL)
1293
+    {
1218 1294
         global $config;
1219 1295
         if (self::isMultipleDatabaseEnabled ()) {
1220
-            if (is_null ($database)) $database = GetUrlParam (DB, 0);
1296
+            if (is_null ($database)) {
1297
+                $database = GetUrlParam (DB, 0);
1298
+            }
1221 1299
             if (!is_null($database) && !preg_match('/^\d+$/', $database)) {
1222 1300
                 return self::error ($database);
1223 1301
             }
@@ -1228,18 +1306,21 @@  discard block
 block discarded – undo
1228 1306
     }
1229 1307
 
1230 1308
 
1231
-    public static function getDbFileName ($database = NULL) {
1309
+    public static function getDbFileName ($database = NULL)
1310
+    {
1232 1311
         return self::getDbDirectory ($database) .'metadata.db';
1233 1312
     }
1234 1313
 
1235
-    private static function error ($database) {
1314
+    private static function error ($database)
1315
+    {
1236 1316
         if (php_sapi_name() != "cli") {
1237 1317
             header("location: checkconfig.php?err=1");
1238 1318
         }
1239 1319
         throw new Exception("Database <{$database}> not found.");
1240 1320
     }
1241 1321
 
1242
-    public static function getDb ($database = NULL) {
1322
+    public static function getDb ($database = NULL)
1323
+    {
1243 1324
         if (is_null (self::$db)) {
1244 1325
             try {
1245 1326
                 if (is_readable (self::getDbFileName ($database))) {
@@ -1257,7 +1338,8 @@  discard block
 block discarded – undo
1257 1338
         return self::$db;
1258 1339
     }
1259 1340
 
1260
-    public static function checkDatabaseAvailability () {
1341
+    public static function checkDatabaseAvailability ()
1342
+    {
1261 1343
         if (self::noDatabaseSelected ()) {
1262 1344
             for ($i = 0; $i < count (self::getDbList ()); $i++) {
1263 1345
                 self::getDb ($i);
@@ -1269,31 +1351,36 @@  discard block
 block discarded – undo
1269 1351
         return true;
1270 1352
     }
1271 1353
 
1272
-    public static function clearDb () {
1354
+    public static function clearDb ()
1355
+    {
1273 1356
         self::$db = NULL;
1274 1357
     }
1275 1358
 
1276
-    public static function executeQuerySingle ($query, $database = NULL) {
1359
+    public static function executeQuerySingle ($query, $database = NULL)
1360
+    {
1277 1361
         return self::getDb ($database)->query($query)->fetchColumn();
1278 1362
     }
1279 1363
 
1280
-    public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) {
1364
+    public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL)
1365
+    {
1281 1366
         if (!$numberOfString) {
1282 1367
             $numberOfString = $table . ".alphabetical";
1283 1368
         }
1284 1369
         $count = self::executeQuerySingle ('select count(*) from ' . $table);
1285
-        if ($count == 0) return NULL;
1370
+        if ($count == 0) {
1371
+            return NULL;
1372
+        }
1286 1373
         $entry = new Entry (localize($table . ".title"), $id,
1287 1374
             str_format (localize($numberOfString, $count), $count), "text",
1288 1375
             array ( new LinkNavigation ("?page=".$pageId)), "", $count);
1289 1376
         return $entry;
1290 1377
     }
1291 1378
 
1292
-    public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) {
1379
+    public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category)
1380
+    {
1293 1381
         list (, $result) = self::executeQuery ($query, $columns, "", $params, -1);
1294 1382
         $entryArray = array();
1295
-        while ($post = $result->fetchObject ())
1296
-        {
1383
+        while ($post = $result->fetchObject ()) {
1297 1384
             $instance = new $category ($post);
1298 1385
             if (property_exists($post, "sort")) {
1299 1386
                 $title = $post->sort;
@@ -1307,7 +1394,8 @@  discard block
 block discarded – undo
1307 1394
         return $entryArray;
1308 1395
     }
1309 1396
 
1310
-    public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
1397
+    public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL)
1398
+    {
1311 1399
         $totalResult = -1;
1312 1400
 
1313 1401
         if (useNormAndUp ()) {
@@ -1319,8 +1407,7 @@  discard block
 block discarded – undo
1319 1407
             $numberPerPage = getCurrentOption ("max_item_per_page");
1320 1408
         }
1321 1409
 
1322
-        if ($numberPerPage != -1 && $n != -1)
1323
-        {
1410
+        if ($numberPerPage != -1 && $n != -1) {
1324 1411
             // First check total number of results
1325 1412
             $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter));
1326 1413
             $result->execute ($params);
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.
Braces   +105 added lines, -82 removed lines patch added patch discarded remove patch
@@ -38,7 +38,8 @@  discard block
 block discarded – undo
38 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
-class Book extends Base {
41
+class Book extends Base
42
+{
42 43
     const ALL_BOOKS_UUID = "urn:uuid";
43 44
     const ALL_BOOKS_ID = "cops:books";
44 45
     const ALL_RECENT_BOOKS_ID = "cops:recentbooks";
@@ -79,7 +80,8 @@  discard block
 block discarded – undo
79 80
     public $format = array ();
80 81
 
81 82
 
82
-    public function __construct($line) {
83
+    public function __construct($line)
84
+    {
83 85
         $this->id = $line->id;
84 86
         $this->title = $line->title;
85 87
         $this->timestamp = strtotime ($line->timestamp);
@@ -97,60 +99,73 @@  discard block
 block discarded – undo
97 99
         $this->rating = $line->rating;
98 100
     }
99 101
 
100
-    public function getEntryId () {
102
+    public function getEntryId ()
103
+    {
101 104
         return self::ALL_BOOKS_UUID.":".$this->uuid;
102 105
     }
103 106
 
104
-    public static function getEntryIdByLetter ($startingLetter) {
107
+    public static function getEntryIdByLetter ($startingLetter)
108
+    {
105 109
         return self::ALL_BOOKS_ID.":letter:".$startingLetter;
106 110
     }
107 111
 
108
-    public function getUri () {
112
+    public function getUri ()
113
+    {
109 114
         return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id";
110 115
     }
111 116
 
112
-    public function getDetailUrl () {
117
+    public function getDetailUrl ()
118
+    {
113 119
         $urlParam = $this->getUri ();
114
-        if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
120
+        if (!is_null (GetUrlParam (DB))) {
121
+            $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
122
+        }
115 123
         return 'index.php' . $urlParam;
116 124
     }
117 125
 
118
-    public function getTitle () {
126
+    public function getTitle ()
127
+    {
119 128
         return $this->title;
120 129
     }
121 130
 
122 131
     /* Other class (author, series, tag, ...) initialization and accessors */
123 132
 
124
-    public function getAuthors () {
133
+    public function getAuthors ()
134
+    {
125 135
         if (is_null ($this->authors)) {
126 136
             $this->authors = Author::getAuthorByBookId ($this->id);
127 137
         }
128 138
         return $this->authors;
129 139
     }
130 140
 
131
-    public function getAuthorsName () {
141
+    public function getAuthorsName ()
142
+    {
132 143
         return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ()));
133 144
     }
134 145
 
135
-    public function getAuthorsSort () {
146
+    public function getAuthorsSort ()
147
+    {
136 148
         return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ()));
137 149
     }
138 150
 
139
-    public function getPublisher () {
151
+    public function getPublisher ()
152
+    {
140 153
         if (is_null ($this->publisher)) {
141 154
             $this->publisher = Publisher::getPublisherByBookId ($this->id);
142 155
         }
143 156
         return $this->publisher;
144 157
     }
145 158
 
146
-    public function getSerie () {
159
+    public function getSerie ()
160
+    {
147 161
         if (is_null ($this->serie)) {
148 162
             $this->serie = Serie::getSerieByBookId ($this->id);
149 163
         }
150 164
         return $this->serie;
151 165
     }
152 166
 
153
-    public function getLanguages () {
167
+    public function getLanguages ()
168
+    {
154 169
         $lang = array ();
155 170
         $result = parent::getDb ()->prepare('select languages.lang_code
156 171
                 from books_languages_link, languages
@@ -158,14 +173,14 @@  discard block
 block discarded – undo
158 173
                 and book = ?
159 174
                 order by item_order');
160 175
         $result->execute (array ($this->id));
161
-        while ($post = $result->fetchObject ())
162
-        {
176
+        while ($post = $result->fetchObject ()) {
163 177
             array_push ($lang, Language::getLanguageString($post->lang_code));
164 178
         }
165 179
         return implode (", ", $lang);
166 180
     }
167 181
 
168
-    public function getTags () {
182
+    public function getTags ()
183
+    {
169 184
         if (is_null ($this->tags)) {
170 185
             $this->tags = array ();
171 186
 
@@ -175,15 +190,15 @@  discard block
 block discarded – undo
175 190
                 and book = ?
176 191
                 order by name');
177 192
             $result->execute (array ($this->id));
178
-            while ($post = $result->fetchObject ())
179
-            {
193
+            while ($post = $result->fetchObject ()) {
180 194
                 array_push ($this->tags, new Tag ($post));
181 195
             }
182 196
         }
183 197
         return $this->tags;
184 198
     }
185 199
 
186
-    public function getTagsName () {
200
+    public function getTagsName ()
201
+    {
187 202
         return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ()));
188 203
     }
189 204
 
@@ -197,9 +212,12 @@  discard block
 block discarded – undo
197 212
 
198 213
     /* End of other class (author, series, tag, ...) initialization and accessors */
199 214
 
200
-    public static function getFilterString () {
215
+    public static function getFilterString ()
216
+    {
201 217
         $filter = getURLParam ("tag", NULL);
202
-        if (empty ($filter)) return "";
218
+        if (empty ($filter)) {
219
+            return "";
220
+        }
203 221
 
204 222
         $exists = true;
205 223
         if (preg_match ("/^!(.*)$/", $filter, $matches)) {
@@ -239,7 +257,8 @@  discard block
 block discarded – undo
239 257
         return reset ($reduced);
240 258
     }
241 259
 
242
-    public function getRating () {
260
+    public function getRating ()
261
+    {
243 262
         if (is_null ($this->rating) || $this->rating == 0) {
244 263
             return "";
245 264
         }
@@ -253,7 +272,8 @@  discard block
 block discarded – undo
253 272
         return $retour;
254 273
     }
255 274
 
256
-    public function getPubDate () {
275
+    public function getPubDate ()
276
+    {
257 277
         if (empty ($this->pubdate)) {
258 278
             return "";
259 279
         }
@@ -264,23 +284,22 @@  discard block
 block discarded – undo
264 284
         return "";
265 285
     }
266 286
 
267
-    public function getComment ($withSerie = true) {
287
+    public function getComment ($withSerie = true)
288
+    {
268 289
         $addition = "";
269 290
         $se = $this->getSerie ();
270 291
         if (!is_null ($se) && $withSerie) {
271 292
             $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n";
272 293
         }
273
-        if (preg_match ("/<\/(div|p|a|span)>/", $this->comment))
274
-        {
294
+        if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) {
275 295
             return $addition . html2xhtml ($this->comment);
276
-        }
277
-        else
278
-        {
296
+        } else {
279 297
             return $addition . htmlspecialchars ($this->comment);
280 298
         }
281 299
     }
282 300
 
283
-    public function getDataFormat ($format) {
301
+    public function getDataFormat ($format)
302
+    {
284 303
         $reduced = array_filter ($this->getDatas (), function ($data) use ($format) {
285 304
             return $data->format == $format;
286 305
         });
@@ -289,23 +308,19 @@  discard block
 block discarded – undo
289 308
 
290 309
     public function getFilePath ($extension, $idData = NULL, $relative = false)
291 310
     {
292
-        if ($extension == "jpg")
293
-        {
311
+        if ($extension == "jpg") {
294 312
             $file = "cover.jpg";
295
-        }
296
-        else
297
-        {
313
+        } else {
298 314
             $data = $this->getDataById ($idData);
299
-            if (!$data) return NULL;
315
+            if (!$data) {
316
+                return NULL;
317
+            }
300 318
             $file = $data->name . "." . strtolower ($data->format);
301 319
         }
302 320
 
303
-        if ($relative)
304
-        {
321
+        if ($relative) {
305 322
             return $this->relativePath."/".$file;
306
-        }
307
-        else
308
-        {
323
+        } else {
309 324
             return $this->path."/".$file;
310 325
         }
311 326
     }
@@ -315,8 +330,7 @@  discard block
 block discarded – undo
315 330
         global $config;
316 331
         $data = $this->getDataById ($idData);
317 332
 
318
-        try
319
-        {
333
+        try {
320 334
             $epub = new EPub ($data->getLocalPath ());
321 335
 
322 336
             $epub->Title ($this->title);
@@ -339,14 +353,13 @@  discard block
 block discarded – undo
339 353
                 $epub->updateForKepub ();
340 354
             }
341 355
             $epub->download ($data->getUpdatedFilenameEpub ());
342
-        }
343
-        catch (Exception $e)
344
-        {
356
+        } catch (Exception $e) {
345 357
             echo "Exception : " . $e->getMessage();
346 358
         }
347 359
     }
348 360
 
349
-    public function getThumbnail ($width, $height, $outputfile = NULL) {
361
+    public function getThumbnail ($width, $height, $outputfile = NULL)
362
+    {
350 363
         if (is_null ($width) && is_null ($height)) {
351 364
             return false;
352 365
         }
@@ -385,17 +398,14 @@  discard block
 block discarded – undo
385 398
     {
386 399
         $linkArray = array();
387 400
 
388
-        if ($this->hasCover)
389
-        {
401
+        if ($this->hasCover) {
390 402
             array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
391 403
 
392 404
             array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL));
393 405
         }
394 406
 
395
-        foreach ($this->getDatas () as $data)
396
-        {
397
-            if ($data->isKnownType ())
398
-            {
407
+        foreach ($this->getDatas () as $data) {
408
+            if ($data->isKnownType ()) {
399 409
                 array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format));
400 410
             }
401 411
         }
@@ -413,17 +423,20 @@  discard block
 block discarded – undo
413 423
     }
414 424
 
415 425
 
416
-    public function getEntry () {
426
+    public function getEntry ()
427
+    {
417 428
         return new EntryBook ($this->getTitle (), $this->getEntryId (),
418 429
             $this->getComment (), "text/html",
419 430
             $this->getLinkArray (), $this);
420 431
     }
421 432
 
422
-    public static function getBookCount($database = NULL) {
433
+    public static function getBookCount($database = NULL)
434
+    {
423 435
         return parent::executeQuerySingle ('select count(*) from books', $database);
424 436
     }
425 437
 
426
-    public static function getCount() {
438
+    public static function getCount()
439
+    {
427 440
         global $config;
428 441
         $nBooks = parent::executeQuerySingle ('select count(*) from books');
429 442
         $result = array();
@@ -442,55 +455,62 @@  discard block
 block discarded – undo
442 455
         return $result;
443 456
     }
444 457
 
445
-    public static function getBooksByAuthor($authorId, $n) {
458
+    public static function getBooksByAuthor($authorId, $n)
459
+    {
446 460
         return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
447 461
     }
448 462
 
449
-    public static function getBooksByRating($ratingId, $n) {
463
+    public static function getBooksByRating($ratingId, $n)
464
+    {
450 465
         return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n);
451 466
     }
452 467
 
453
-    public static function getBooksByPublisher($publisherId, $n) {
468
+    public static function getBooksByPublisher($publisherId, $n)
469
+    {
454 470
         return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n);
455 471
     }
456 472
 
457
-    public static function getBooksBySeries($serieId, $n) {
473
+    public static function getBooksBySeries($serieId, $n)
474
+    {
458 475
         return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
459 476
     }
460 477
 
461
-    public static function getBooksByTag($tagId, $n) {
478
+    public static function getBooksByTag($tagId, $n)
479
+    {
462 480
         return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
463 481
     }
464 482
 
465
-    public static function getBooksByLanguage($languageId, $n) {
483
+    public static function getBooksByLanguage($languageId, $n)
484
+    {
466 485
         return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n);
467 486
     }
468 487
 
469
-    public static function getBooksByCustom($customId, $id, $n) {
488
+    public static function getBooksByCustom($customId, $id, $n)
489
+    {
470 490
         $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
471 491
         return self::getEntryArray ($query, array ($id), $n);
472 492
     }
473 493
 
474
-    public static function getBookById($bookId) {
494
+    public static function getBookById($bookId)
495
+    {
475 496
         $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
476 497
 from books ' . self::SQL_BOOKS_LEFT_JOIN . '
477 498
 where books.id = ?');
478 499
         $result->execute (array ($bookId));
479
-        while ($post = $result->fetchObject ())
480
-        {
500
+        while ($post = $result->fetchObject ()) {
481 501
             $book = new Book ($post);
482 502
             return $book;
483 503
         }
484 504
         return NULL;
485 505
     }
486 506
 
487
-    public static function getBookByDataId($dataId) {
507
+    public static function getBookByDataId($dataId)
508
+    {
488 509
         $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format
489 510
 from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
490 511
 where data.book = books.id and data.id = ?');
491 512
         $result->execute (array ($dataId));
492
-        while ($post = $result->fetchObject ())
493
-        {
513
+        while ($post = $result->fetchObject ()) {
494 514
             $book = new Book ($post);
495 515
             $data = new Data ($post, $book);
496 516
             $data->id = $dataId;
@@ -500,7 +520,8 @@  discard block
 block discarded – undo
500 520
         return NULL;
501 521
     }
502 522
 
503
-    public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
523
+    public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL)
524
+    {
504 525
         $i = 0;
505 526
         $critArray = array ();
506 527
         foreach (array (PageQueryResult::SCOPE_AUTHOR,
@@ -511,8 +532,7 @@  discard block
 block discarded – undo
511 532
             if (in_array($key, getCurrentOption ('ignored_categories')) ||
512 533
                 (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) {
513 534
                 $critArray [$i] = self::BAD_SEARCH;
514
-            }
515
-            else {
535
+            } else {
516 536
                 if (array_key_exists ($key, $query)) {
517 537
                     $critArray [$i] = $query [$key];
518 538
                 } else {
@@ -524,19 +544,20 @@  discard block
 block discarded – undo
524 544
         return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage);
525 545
     }
526 546
 
527
-    public static function getBooks($n) {
547
+    public static function getBooks($n)
548
+    {
528 549
         list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n);
529 550
         return array ($entryArray, $totalNumber);
530 551
     }
531 552
 
532
-    public static function getAllBooks() {
553
+    public static function getAllBooks()
554
+    {
533 555
         list (, $result) = parent::executeQuery ("select {0}
534 556
 from books
535 557
 group by substr (upper (sort), 1, 1)
536 558
 order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1);
537 559
         $entryArray = array();
538
-        while ($post = $result->fetchObject ())
539
-        {
560
+        while ($post = $result->fetchObject ()) {
540 561
             array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title),
541 562
                 str_format (localize("bookword", $post->count), $post->count), "text",
542 563
                 array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count));
@@ -544,15 +565,16 @@  discard block
 block discarded – undo
544 565
         return $entryArray;
545 566
     }
546 567
 
547
-    public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) {
568
+    public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL)
569
+    {
548 570
         return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage);
549 571
     }
550 572
 
551
-    public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) {
573
+    public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL)
574
+    {
552 575
         list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage);
553 576
         $entryArray = array();
554
-        while ($post = $result->fetchObject ())
555
-        {
577
+        while ($post = $result->fetchObject ()) {
556 578
             $book = new Book ($post);
557 579
             array_push ($entryArray, $book->getEntry ());
558 580
         }
@@ -560,7 +582,8 @@  discard block
 block discarded – undo
560 582
     }
561 583
 
562 584
 
563
-    public static function getAllRecentBooks() {
585
+    public static function getAllRecentBooks()
586
+    {
564 587
         global $config;
565 588
         list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1);
566 589
         return $entryArray;
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.
Braces   +44 added lines, -30 removed lines patch added patch discarded remove patch
@@ -6,7 +6,8 @@  discard block
 block discarded – undo
6 6
  * @author     Sébastien Lucas <[email protected]>
7 7
  */
8 8
 
9
-class Data extends Base {
9
+class Data extends Base
10
+{
10 11
     public $id;
11 12
     public $name;
12 13
     public $format;
@@ -54,7 +55,8 @@  discard block
 block discarded – undo
54 55
         'zip'   => 'application/zip'
55 56
     );
56 57
 
57
-    public function __construct($post, $book = null) {
58
+    public function __construct($post, $book = null)
59
+    {
58 60
         $this->id = $post->id;
59 61
         $this->name = $post->name;
60 62
         $this->format = $post->format;
@@ -63,19 +65,20 @@  discard block
 block discarded – undo
63 65
         $this->book = $book;
64 66
     }
65 67
 
66
-    public function isKnownType () {
68
+    public function isKnownType ()
69
+    {
67 70
         return array_key_exists ($this->extension, self::$mimetypes);
68 71
     }
69 72
 
70
-    public function getMimeType () {
73
+    public function getMimeType ()
74
+    {
71 75
         $result = "application/octet-stream";
72 76
         if ($this->isKnownType ()) {
73 77
             return self::$mimetypes [$this->extension];
74 78
         } elseif (function_exists('finfo_open') === true) {
75 79
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
76 80
 
77
-            if (is_resource($finfo) === true)
78
-            {
81
+            if (is_resource($finfo) === true) {
79 82
                 $result = finfo_file($finfo, $this->getLocalPath ());
80 83
             }
81 84
 
@@ -85,27 +88,33 @@  discard block
 block discarded – undo
85 88
         return $result;
86 89
     }
87 90
 
88
-    public function isEpubValidOnKobo () {
91
+    public function isEpubValidOnKobo ()
92
+    {
89 93
         return $this->format == "EPUB" || $this->format == "KEPUB";
90 94
     }
91 95
 
92
-    public function getFilename () {
96
+    public function getFilename ()
97
+    {
93 98
         return $this->name . "." . strtolower ($this->format);
94 99
     }
95 100
 
96
-    public function getUpdatedFilename () {
101
+    public function getUpdatedFilename ()
102
+    {
97 103
         return $this->book->getAuthorsSort () . " - " . $this->book->title;
98 104
     }
99 105
 
100
-    public function getUpdatedFilenameEpub () {
106
+    public function getUpdatedFilenameEpub ()
107
+    {
101 108
         return $this->getUpdatedFilename () . ".epub";
102 109
     }
103 110
 
104
-    public function getUpdatedFilenameKepub () {
111
+    public function getUpdatedFilenameKepub ()
112
+    {
105 113
         return $this->getUpdatedFilename () . ".kepub.epub";
106 114
     }
107 115
 
108
-    public function getDataLink ($rel, $title = NULL) {
116
+    public function getDataLink ($rel, $title = NULL)
117
+    {
109 118
         global $config;
110 119
 
111 120
         if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") {
@@ -115,19 +124,24 @@  discard block
 block discarded – undo
115 124
         return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title);
116 125
     }
117 126
 
118
-    public function getHtmlLink () {
127
+    public function getHtmlLink ()
128
+    {
119 129
         return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href;
120 130
     }
121 131
 
122
-    public function getLocalPath () {
132
+    public function getLocalPath ()
133
+    {
123 134
         return $this->book->path . "/" . $this->getFilename ();
124 135
     }
125 136
 
126
-    public function getHtmlLinkWithRewriting ($title = NULL) {
137
+    public function getHtmlLinkWithRewriting ($title = NULL)
138
+    {
127 139
         global $config;
128 140
 
129 141
         $database = "";
130
-        if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
142
+        if (!is_null (GetUrlParam (DB))) {
143
+            $database = GetUrlParam (DB) . "/";
144
+        }
131 145
 
132 146
         $href = "download/" . $this->id . "/" . $database;
133 147
 
@@ -141,28 +155,27 @@  discard block
 block discarded – undo
141 155
         return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title);
142 156
     }
143 157
 
144
-    public static function getDataByBook ($book) {
158
+    public static function getDataByBook ($book)
159
+    {
145 160
         $out = array ();
146 161
         $result = parent::getDb ()->prepare('select id, format, name
147 162
                                              from data where book = ?');
148 163
         $result->execute (array ($book->id));
149 164
 
150
-        while ($post = $result->fetchObject ())
151
-        {
165
+        while ($post = $result->fetchObject ()) {
152 166
             array_push ($out, new Data ($post, $book));
153 167
         }
154 168
         return $out;
155 169
     }
156 170
 
157
-    public static function handleThumbnailLink ($urlParam, $height) {
171
+    public static function handleThumbnailLink ($urlParam, $height)
172
+    {
158 173
         global $config;
159 174
 
160 175
         if (is_null ($height)) {
161 176
             if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) {
162 177
                 $height = $config['cops_opds_thumbnail_height'];
163
-            }
164
-            else
165
-            {
178
+            } else {
166 179
                 $height = $config['cops_html_thumbnail_height'];
167 180
             }
168 181
         }
@@ -181,14 +194,17 @@  discard block
 block discarded – undo
181 194
 
182 195
         if (Base::useAbsolutePath () ||
183 196
             $rel == Link::OPDS_THUMBNAIL_TYPE ||
184
-            ($type == "epub" && $config['cops_update_epub-metadata']))
185
-        {
186
-            if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type);
197
+            ($type == "epub" && $config['cops_update_epub-metadata'])) {
198
+            if ($type != "jpg") {
199
+                $urlParam = addURLParameter($urlParam, "type", $type);
200
+            }
187 201
             if ($rel == Link::OPDS_THUMBNAIL_TYPE) {
188 202
                 $urlParam = self::handleThumbnailLink($urlParam, $height);
189 203
             }
190 204
             $urlParam = addURLParameter($urlParam, "id", $book->id);
191
-            if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
205
+            if (!is_null (GetUrlParam (DB))) {
206
+                $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
207
+            }
192 208
             if ($config['cops_thumbnail_handling'] != "1" &&
193 209
                 !empty ($config['cops_thumbnail_handling']) &&
194 210
                 $rel == Link::OPDS_THUMBNAIL_TYPE) {
@@ -196,9 +212,7 @@  discard block
 block discarded – undo
196 212
             } else {
197 213
                 return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
198 214
             }
199
-        }
200
-        else
201
-        {
215
+        } else {
202 216
             return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title);
203 217
         }
204 218
     }
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.
Braces   +17 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,7 +6,8 @@  discard block
 block discarded – undo
6 6
  * @author     Michael Pfitzner
7 7
  */
8 8
 
9
-class Rating extends Base {
9
+class Rating extends Base
10
+{
10 11
     const ALL_RATING_ID = "cops:rating";
11 12
 
12 13
     const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
@@ -14,33 +15,38 @@  discard block
 block discarded – undo
14 15
     public $id;
15 16
     public $name;
16 17
 
17
-    public function __construct($pid, $pname) {
18
+    public function __construct($pid, $pname)
19
+    {
18 20
         $this->id = $pid;
19 21
         $this->name = $pname;
20 22
     }
21 23
 
22
-    public function getUri () {
24
+    public function getUri ()
25
+    {
23 26
         return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
24 27
     }
25 28
 
26
-    public function getEntryId () {
29
+    public function getEntryId ()
30
+    {
27 31
         return self::ALL_RATING_ID.":".$this->id;
28 32
     }
29 33
 
30
-    public static function getCount() {
34
+    public static function getCount()
35
+    {
31 36
         // str_format (localize("ratings", count(array))
32 37
         return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
33 38
     }
34 39
 
35
-    public static function getAllRatings() {
40
+    public static function getAllRatings()
41
+    {
36 42
         return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
37 43
     }
38 44
 
39
-    public static function getEntryArray ($query, $params) {
45
+    public static function getEntryArray ($query, $params)
46
+    {
40 47
         list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
41 48
         $entryArray = array();
42
-        while ($post = $result->fetchObject ())
43
-        {
49
+        while ($post = $result->fetchObject ()) {
44 50
             $ratingObj = new Rating ($post->id, $post->rating);
45 51
             $rating=$post->rating/2;
46 52
             $rating = str_format (localize("ratingword", $rating), $rating);
@@ -51,7 +57,8 @@  discard block
 block discarded – undo
51 57
         return $entryArray;
52 58
     }
53 59
 
54
-    public static function getRatingById ($ratingId) {
60
+    public static function getRatingById ($ratingId)
61
+    {
55 62
         $result = parent::getDb ()->prepare('select rating from ratings where id = ?');
56 63
         $result->execute (array ($ratingId));
57 64
         return new Rating ($ratingId, $result->fetchColumn ());
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.
Braces   +17 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,7 +6,8 @@  discard block
 block discarded – undo
6 6
  * @author     Sébastien Lucas <[email protected]>
7 7
  */
8 8
 
9
-class Tag extends Base {
9
+class Tag extends Base
10
+{
10 11
     const ALL_TAGS_ID = "cops:tags";
11 12
     const TAG_COLUMNS = "tags.id as id, tags.name as name, count(*) as count";
12 13
     const SQL_ALL_TAGS = "select {0} from tags, books_tags_link where tags.id = tag group by tags.id, tags.name order by tags.name";
@@ -14,25 +15,30 @@  discard block
 block discarded – undo
14 15
     public $id;
15 16
     public $name;
16 17
 
17
-    public function __construct($post) {
18
+    public function __construct($post)
19
+    {
18 20
         $this->id = $post->id;
19 21
         $this->name = $post->name;
20 22
     }
21 23
 
22
-    public function getUri () {
24
+    public function getUri ()
25
+    {
23 26
         return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
24 27
     }
25 28
 
26
-    public function getEntryId () {
29
+    public function getEntryId ()
30
+    {
27 31
         return self::ALL_TAGS_ID.":".$this->id;
28 32
     }
29 33
 
30
-    public static function getCount() {
34
+    public static function getCount()
35
+    {
31 36
         // str_format (localize("tags.alphabetical", count(array))
32 37
         return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS);
33 38
     }
34 39
 
35
-    public static function getTagById ($tagId) {
40
+    public static function getTagById ($tagId)
41
+    {
36 42
         $result = parent::getDb ()->prepare('select id, name  from tags where id = ?');
37 43
         $result->execute (array ($tagId));
38 44
         if ($post = $result->fetchObject ()) {
@@ -41,17 +47,18 @@  discard block
 block discarded – undo
41 47
         return NULL;
42 48
     }
43 49
 
44
-    public static function getAllTags() {
50
+    public static function getAllTags()
51
+    {
45 52
         return Base::getEntryArrayWithBookNumber (self::SQL_ALL_TAGS, self::TAG_COLUMNS, array (), "Tag");
46 53
     }
47 54
 
48
-    public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
55
+    public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL)
56
+    {
49 57
         $columns  = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
50 58
         $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name';
51 59
         list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage);
52 60
         $entryArray = array();
53
-        while ($post = $result->fetchObject ())
54
-        {
61
+        while ($post = $result->fetchObject ()) {
55 62
             $tag = new Tag ($post);
56 63
             array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
57 64
                 str_format (localize("bookword", $post->count), $post->count), "text",
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.
Braces   +21 added lines, -36 removed lines patch added patch discarded remove patch
@@ -25,7 +25,8 @@  discard block
 block discarded – undo
25 25
  * @return
26 26
  *   Transliterated text.
27 27
  */
28
-function _transliteration_process($string, $unknown = '?', $source_langcode = NULL) {
28
+function _transliteration_process($string, $unknown = '?', $source_langcode = NULL)
29
+{
29 30
   // ASCII is always valid NFC! If we're only ever given plain ASCII, we can
30 31
   // avoid the overhead of initializing the decomposition tables by skipping
31 32
   // out early.
@@ -41,23 +42,17 @@  discard block
 block discarded – undo
41 42
     for ($n = 0; $n < 256; $n++) {
42 43
       if ($n < 0xc0) {
43 44
         $remaining = 0;
44
-      }
45
-      elseif ($n < 0xe0) {
45
+      } elseif ($n < 0xe0) {
46 46
         $remaining = 1;
47
-      }
48
-      elseif ($n < 0xf0) {
47
+      } elseif ($n < 0xf0) {
49 48
         $remaining = 2;
50
-      }
51
-      elseif ($n < 0xf8) {
49
+      } elseif ($n < 0xf8) {
52 50
         $remaining = 3;
53
-      }
54
-      elseif ($n < 0xfc) {
51
+      } elseif ($n < 0xfc) {
55 52
         $remaining = 4;
56
-      }
57
-      elseif ($n < 0xfe) {
53
+      } elseif ($n < 0xfe) {
58 54
         $remaining = 5;
59
-      }
60
-      else {
55
+      } else {
61 56
         $remaining = 0;
62 57
       }
63 58
       $tail_bytes[chr($n)] = $remaining;
@@ -100,15 +95,13 @@  discard block
 block discarded – undo
100 95
           if (--$len && ($c = $str[++$i]) >= "\x80" && $c < "\xc0") {
101 96
             // Legal tail bytes are nice.
102 97
             $sequence .= $c;
103
-          }
104
-          else {
98
+          } else {
105 99
             if ($len == 0) {
106 100
               // Premature end of string! Drop a replacement character into
107 101
               // output to represent the invalid UTF-8 sequence.
108 102
               $result .= $unknown;
109 103
               break 2;
110
-            }
111
-            else {
104
+            } else {
112 105
               // Illegal tail byte; abandon the sequence.
113 106
               $result .= $unknown;
114 107
               // Back up and reprocess this byte; it may itself be a legal
@@ -123,34 +116,27 @@  discard block
 block discarded – undo
123 116
         $n = ord($head);
124 117
         if ($n <= 0xdf) {
125 118
           $ord = ($n - 192) * 64 + (ord($sequence[1]) - 128);
126
-        }
127
-        elseif ($n <= 0xef) {
119
+        } elseif ($n <= 0xef) {
128 120
           $ord = ($n - 224) * 4096 + (ord($sequence[1]) - 128) * 64 + (ord($sequence[2]) - 128);
129
-        }
130
-        elseif ($n <= 0xf7) {
121
+        } elseif ($n <= 0xf7) {
131 122
           $ord = ($n - 240) * 262144 + (ord($sequence[1]) - 128) * 4096 + (ord($sequence[2]) - 128) * 64 + (ord($sequence[3]) - 128);
132
-        }
133
-        elseif ($n <= 0xfb) {
123
+        } elseif ($n <= 0xfb) {
134 124
           $ord = ($n - 248) * 16777216 + (ord($sequence[1]) - 128) * 262144 + (ord($sequence[2]) - 128) * 4096 + (ord($sequence[3]) - 128) * 64 + (ord($sequence[4]) - 128);
135
-        }
136
-        elseif ($n <= 0xfd) {
125
+        } elseif ($n <= 0xfd) {
137 126
           $ord = ($n - 252) * 1073741824 + (ord($sequence[1]) - 128) * 16777216 + (ord($sequence[2]) - 128) * 262144 + (ord($sequence[3]) - 128) * 4096 + (ord($sequence[4]) - 128) * 64 + (ord($sequence[5]) - 128);
138 127
         }
139 128
         $result .= _transliteration_replace($ord, $unknown, $source_langcode);
140 129
         $head = '';
141
-      }
142
-      elseif ($c < "\x80") {
130
+      } elseif ($c < "\x80") {
143 131
         // ASCII byte.
144 132
         $result .= $c;
145 133
         $head = '';
146
-      }
147
-      elseif ($c < "\xc0") {
134
+      } elseif ($c < "\xc0") {
148 135
         // Illegal tail bytes.
149 136
         if ($head == '') {
150 137
           $result .= $unknown;
151 138
         }
152
-      }
153
-      else {
139
+      } else {
154 140
         // Miscellaneous freaks.
155 141
         $result .= $unknown;
156 142
         $head = '';
@@ -175,7 +161,8 @@  discard block
 block discarded – undo
175 161
  * @return
176 162
  *   ASCII replacement character.
177 163
  */
178
-function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) {
164
+function _transliteration_replace($ord, $unknown = '?', $langcode = NULL)
165
+{
179 166
   static $map = array();
180 167
 
181 168
   //GL: set language later
@@ -195,12 +182,10 @@  discard block
 block discarded – undo
195 182
       if ($langcode != 'en' && isset($variant[$langcode])) {
196 183
         // Merge in language specific mappings.
197 184
         $map[$bank][$langcode] = $variant[$langcode] + $base;
198
-      }
199
-      else {
185
+      } else {
200 186
         $map[$bank][$langcode] = $base;
201 187
       }
202
-    }
203
-    else {
188
+    } else {
204 189
       $map[$bank][$langcode] = array();
205 190
     }
206 191
   }
Please login to merge, or discard this patch.
serie.php 1 patch
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -6,7 +6,8 @@  discard block
 block discarded – undo
6 6
  * @author     Sébastien Lucas <[email protected]>
7 7
  */
8 8
 
9
-class Serie extends Base {
9
+class Serie extends Base
10
+{
10 11
     const ALL_SERIES_ID = "cops:series";
11 12
     const SERIES_COLUMNS = "series.id as id, series.name as name, series.sort as sort, count(*) as count";
12 13
     const SQL_ALL_SERIES = "select {0} from series, books_series_link where series.id = series group by series.id, series.name, series.sort order by series.sort";
@@ -15,25 +16,30 @@  discard block
 block discarded – undo
15 16
     public $id;
16 17
     public $name;
17 18
 
18
-    public function __construct($post) {
19
+    public function __construct($post)
20
+    {
19 21
         $this->id = $post->id;
20 22
         $this->name = $post->name;
21 23
     }
22 24
 
23
-    public function getUri () {
25
+    public function getUri ()
26
+    {
24 27
         return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
25 28
     }
26 29
 
27
-    public function getEntryId () {
30
+    public function getEntryId ()
31
+    {
28 32
         return self::ALL_SERIES_ID.":".$this->id;
29 33
     }
30 34
 
31
-    public static function getCount() {
35
+    public static function getCount()
36
+    {
32 37
         // str_format (localize("series.alphabetical", count(array))
33 38
         return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
34 39
     }
35 40
 
36
-    public static function getSerieByBookId ($bookId) {
41
+    public static function getSerieByBookId ($bookId)
42
+    {
37 43
         $result = parent::getDb ()->prepare('select  series.id as id, name
38 44
 from books_series_link, series
39 45
 where series.id = series and book = ?');
@@ -44,7 +50,8 @@  discard block
 block discarded – undo
44 50
         return NULL;
45 51
     }
46 52
 
47
-    public static function getSerieById ($serieId) {
53
+    public static function getSerieById ($serieId)
54
+    {
48 55
         $result = parent::getDb ()->prepare('select id, name  from series where id = ?');
49 56
         $result->execute (array ($serieId));
50 57
         if ($post = $result->fetchObject ()) {
@@ -53,11 +60,13 @@  discard block
 block discarded – undo
53 60
         return NULL;
54 61
     }
55 62
 
56
-    public static function getAllSeries() {
63
+    public static function getAllSeries()
64
+    {
57 65
         return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, self::SERIES_COLUMNS, array (), "Serie");
58 66
     }
59 67
 
60
-    public static function getAllSeriesByQuery($query) {
68
+    public static function getAllSeriesByQuery($query)
69
+    {
61 70
         return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, self::SERIES_COLUMNS, array ('%' . $query . '%'), "Serie");
62 71
     }
63 72
 }
Please login to merge, or discard this patch.
fetch.php 1 patch
Braces   +7 added lines, -15 removed lines patch added patch discarded remove patch
@@ -25,12 +25,9 @@  discard block
 block discarded – undo
25 25
     $bookId = getURLParam ("id", NULL);
26 26
     $type = getURLParam ("type", "jpg");
27 27
     $idData = getURLParam ("data", NULL);
28
-    if (is_null ($bookId))
29
-    {
28
+    if (is_null ($bookId)) {
30 29
         $book = Book::getBookByDataId($idData);
31
-    }
32
-    else
33
-    {
30
+    } else {
34 31
         $book = Book::getBookById($bookId);
35 32
     }
36 33
 
@@ -51,8 +48,7 @@  discard block
 block discarded – undo
51 48
         }
52 49
     }
53 50
 
54
-    switch ($type)
55
-    {
51
+    switch ($type) {
56 52
         case "jpg":
57 53
             header("Content-Type: image/jpeg");
58 54
             //by default, we don't cache
@@ -69,8 +65,7 @@  discard block
 block discarded – undo
69 65
                     //we name the thumbnail from the book's uuid and it's dimensions (width and/or height)
70 66
                     $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam ("width") . 'x' . getURLParam ("height") . '.jpg';
71 67
                     $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName;
72
-                }
73
-                else {
68
+                } else {
74 69
                     //error creating the folder, so we don't cache
75 70
                     $thumbnailCacheFullpath = null;
76 71
                 }
@@ -87,8 +82,7 @@  discard block
 block discarded – undo
87 82
                 if ( $thumbnailCacheFullpath === null ) {
88 83
                     // The cover had to be resized
89 84
                     return;
90
-                }
91
-                else {
85
+                } else {
92 86
                     //return the just cached thumbnail
93 87
                     readfile( $thumbnailCacheFullpath );
94 88
                     return;
@@ -101,8 +95,7 @@  discard block
 block discarded – undo
101 95
             break;
102 96
     }
103 97
     $file = $book->getFilePath ($type, $idData, true);
104
-    if ($type == "epub" && $config['cops_update_epub-metadata'])
105
-    {
98
+    if ($type == "epub" && $config['cops_update_epub-metadata']) {
106 99
         $book->getUpdatedEpub ($idData);
107 100
         return;
108 101
     }
@@ -122,7 +115,6 @@  discard block
 block discarded – undo
122 115
         $fp = fopen($filename, 'rb');
123 116
         header("Content-Length: " . filesize($filename));
124 117
         fpassthru($fp);
125
-    }
126
-    else {
118
+    } else {
127 119
         header ($config['cops_x_accel_redirect'] . ": " . $dir . $file);
128 120
     }
Please login to merge, or discard this patch.