Completed
Branch master (31966b)
by Markus
09:57
created
author.php 1 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.
epubreader.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,9 @@
 block discarded – undo
15 15
 
16 16
 $idData = getURLParam ("data", NULL);
17 17
 $add = "data=$idData&";
18
-if (!is_null (GetUrlParam (DB))) $add .= DB . "=" . GetUrlParam (DB) . "&";
18
+if (!is_null (GetUrlParam (DB))) {
19
+    $add .= DB . "=" . GetUrlParam (DB) . "&";
20
+}
19 21
 $myBook = Book::getBookByDataId($idData);
20 22
 
21 23
 $book = new EPub ($myBook->getFilePath ("EPUB", $idData));
Please login to merge, or discard this patch.
feed.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@
 block discarded – undo
14 14
     $page = getURLParam ("page", Base::PAGE_INDEX);
15 15
     $query = getURLParam ("query");
16 16
     $n = getURLParam ("n", "1");
17
-    if ($query)
18
-        $page = Base::PAGE_OPENSEARCH_QUERY;
17
+    if ($query) {
18
+            $page = Base::PAGE_OPENSEARCH_QUERY;
19
+    }
19 20
     $qid = getURLParam ("id");
20 21
 
21 22
     if ($config ['cops_fetch_protect'] == "1") {
Please login to merge, or discard this patch.
JSON_renderer.php 1 patch
Braces   +16 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,12 +10,12 @@  discard block
 block discarded – undo
10 10
 
11 11
 class JSONRenderer
12 12
 {
13
-    public static function getBookContentArray ($book) {
13
+    public static function getBookContentArray ($book)
14
+    {
14 15
         global $config;
15 16
         $i = 0;
16 17
         $preferedData = array ();
17
-        foreach ($config['cops_prefered_format'] as $format)
18
-        {
18
+        foreach ($config['cops_prefered_format'] as $format) {
19 19
             if ($i == 2) { break; }
20 20
             if ($data = $book->getDataFormat ($format)) {
21 21
                 $i++;
@@ -61,7 +61,8 @@  discard block
 block discarded – undo
61 61
                       "seriesurl" => $su);
62 62
     }
63 63
 
64
-    public static function getFullBookContentArray ($book) {
64
+    public static function getFullBookContentArray ($book)
65
+    {
65 66
         global $config;
66 67
         $out = self::getBookContentArray ($book);
67 68
         $database = GetUrlParam (DB);
@@ -95,7 +96,8 @@  discard block
 block discarded – undo
95 96
         return $out;
96 97
     }
97 98
 
98
-    public static function getContentArray ($entry) {
99
+    public static function getContentArray ($entry)
100
+    {
99 101
         if ($entry instanceof EntryBook) {
100 102
             $out = array ( "title" => $entry->title);
101 103
             $out ["book"] = self::getBookContentArray ($entry->book);
@@ -104,7 +106,8 @@  discard block
 block discarded – undo
104 106
         return array ( "title" => $entry->title, "content" => $entry->content, "navlink" => $entry->getNavLink (), "number" => $entry->numberOfElement );
105 107
     }
106 108
 
107
-    public static function getContentArrayTypeahead ($page) {
109
+    public static function getContentArrayTypeahead ($page)
110
+    {
108 111
         $out = array ();
109 112
         foreach ($page->entryArray as $entry) {
110 113
             if ($entry instanceof EntryBook) {
@@ -120,7 +123,8 @@  discard block
 block discarded – undo
120 123
         return $out;
121 124
     }
122 125
 
123
-    public static function addCompleteArray ($in) {
126
+    public static function addCompleteArray ($in)
127
+    {
124 128
         global $config;
125 129
         $out = $in;
126 130
 
@@ -167,7 +171,8 @@  discard block
 block discarded – undo
167 171
         return $out;
168 172
     }
169 173
 
170
-    public static function getJson ($complete = false) {
174
+    public static function getJson ($complete = false)
175
+    {
171 176
         global $config;
172 177
         $page = getURLParam ("page", Base::PAGE_INDEX);
173 178
         $query = getURLParam ("query");
@@ -236,7 +241,9 @@  discard block
 block discarded – undo
236 241
         }
237 242
 
238 243
         $out ["homeurl"] = "index.php";
239
-        if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] .  "?" . addURLParameter ("", DB, $database);
244
+        if ($page != Base::PAGE_INDEX && !is_null ($database)) {
245
+            $out ["homeurl"] = $out ["homeurl"] .  "?" . addURLParameter ("", DB, $database);
246
+        }
240 247
 
241 248
         return $out;
242 249
     }
Please login to merge, or discard this patch.
book.php 1 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.
tag.php 1 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.
language.php 1 patch
Braces   +17 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,26 +6,31 @@  discard block
 block discarded – undo
6 6
  * @author     Sébastien Lucas <[email protected]>
7 7
  */
8 8
 
9
-class Language extends Base {
9
+class Language extends Base
10
+{
10 11
     const ALL_LANGUAGES_ID = "cops:languages";
11 12
 
12 13
     public $id;
13 14
     public $lang_code;
14 15
 
15
-    public function __construct($pid, $plang_code) {
16
+    public function __construct($pid, $plang_code)
17
+    {
16 18
         $this->id = $pid;
17 19
         $this->lang_code = $plang_code;
18 20
     }
19 21
 
20
-    public function getUri () {
22
+    public function getUri ()
23
+    {
21 24
         return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id";
22 25
     }
23 26
 
24
-    public function getEntryId () {
27
+    public function getEntryId ()
28
+    {
25 29
         return self::ALL_LANGUAGES_ID.":".$this->id;
26 30
     }
27 31
 
28
-    public static function getLanguageString ($code) {
32
+    public static function getLanguageString ($code)
33
+    {
29 34
         $string = localize("languages.".$code);
30 35
         if (preg_match ("/^languages/", $string)) {
31 36
             return $code;
@@ -33,12 +38,14 @@  discard block
 block discarded – undo
33 38
         return $string;
34 39
     }
35 40
 
36
-    public static function getCount() {
41
+    public static function getCount()
42
+    {
37 43
         // str_format (localize("languages.alphabetical", count(array))
38 44
         return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES);
39 45
     }
40 46
 
41
-    public static function getLanguageById ($languageId) {
47
+    public static function getLanguageById ($languageId)
48
+    {
42 49
         $result = parent::getDb ()->prepare('select id, lang_code  from languages where id = ?');
43 50
         $result->execute (array ($languageId));
44 51
         if ($post = $result->fetchObject ()) {
@@ -49,15 +56,15 @@  discard block
 block discarded – undo
49 56
 
50 57
 
51 58
 
52
-    public static function getAllLanguages() {
59
+    public static function getAllLanguages()
60
+    {
53 61
         $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
54 62
 from languages, books_languages_link
55 63
 where languages.id = books_languages_link.lang_code
56 64
 group by languages.id, books_languages_link.lang_code
57 65
 order by languages.lang_code');
58 66
         $entryArray = array();
59
-        while ($post = $result->fetchObject ())
60
-        {
67
+        while ($post = $result->fetchObject ()) {
61 68
             $language = new Language ($post->id, $post->lang_code);
62 69
             array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
63 70
                 str_format (localize("bookword", $post->count), $post->count), "text",
Please login to merge, or discard this patch.
config.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,13 +21,11 @@
 block discarded – undo
21 21
 }
22 22
 
23 23
 if(!is_null($config['cops_basic_authentication']) &&
24
-    is_array($config['cops_basic_authentication']))
25
-{
24
+    is_array($config['cops_basic_authentication'])) {
26 25
     if (!isset($_SERVER['PHP_AUTH_USER']) ||
27 26
         (isset($_SERVER['PHP_AUTH_USER']) &&
28 27
         ($_SERVER['PHP_AUTH_USER']!=$config['cops_basic_authentication']['username'] ||
29
-        $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password'])))
30
-    {
28
+        $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password']))) {
31 29
         header('WWW-Authenticate: Basic realm="COPS Authentication"');
32 30
         header('HTTP/1.0 401 Unauthorized');
33 31
         echo 'This site is password protected';
Please login to merge, or discard this patch.
data.php 1 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.