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