Test Setup Failed
Pull Request — master (#496)
by
unknown
02:08
created
lib/Data.php 1 patch
Braces   +47 added lines, -31 removed lines patch added patch discarded remove patch
@@ -55,7 +55,8 @@  discard block
 block discarded – undo
55 55
         'zip'   => 'application/zip'
56 56
     );
57 57
 
58
-    public function __construct($post, $book = null) {
58
+    public function __construct($post, $book = null)
59
+    {
59 60
         $this->id = $post->id;
60 61
         $this->name = $post->name;
61 62
         $this->format = $post->format;
@@ -64,19 +65,20 @@  discard block
 block discarded – undo
64 65
         $this->book = $book;
65 66
     }
66 67
 
67
-    public function isKnownType () {
68
+    public function isKnownType ()
69
+    {
68 70
         return array_key_exists ($this->extension, self::$mimetypes);
69 71
     }
70 72
 
71
-    public function getMimeType () {
73
+    public function getMimeType ()
74
+    {
72 75
         $result = "application/octet-stream";
73 76
         if ($this->isKnownType ()) {
74 77
             return self::$mimetypes [$this->extension];
75 78
         } elseif (function_exists('finfo_open') === true) {
76 79
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
77 80
 
78
-            if (is_resource($finfo) === true)
79
-            {
81
+            if (is_resource($finfo) === true) {
80 82
                 $result = finfo_file($finfo, $this->getLocalPath ());
81 83
             }
82 84
 
@@ -86,29 +88,35 @@  discard block
 block discarded – undo
86 88
         return $result;
87 89
     }
88 90
 
89
-    public function isEpubValidOnKobo () {
91
+    public function isEpubValidOnKobo ()
92
+    {
90 93
         return $this->format == "EPUB" || $this->format == "KEPUB";
91 94
     }
92 95
 
93
-    public function getFilename () {
96
+    public function getFilename ()
97
+    {
94 98
         return $this->name . "." . strtolower ($this->format);
95 99
     }
96 100
 
97
-    public function getUpdatedFilename () {
101
+    public function getUpdatedFilename ()
102
+    {
98 103
         return $this->book->getAuthorsSort () . " - " . $this->book->title;
99 104
     }
100 105
 
101
-    public function getUpdatedFilenameEpub () {
106
+    public function getUpdatedFilenameEpub ()
107
+    {
102 108
         return $this->getUpdatedFilename () . ".epub";
103 109
     }
104 110
 
105
-    public function getUpdatedFilenameKepub () {
111
+    public function getUpdatedFilenameKepub ()
112
+    {
106 113
         $str = $this->getUpdatedFilename () . ".kepub.epub";
107 114
         return str_replace(array(':', '#', '&'),
108 115
                            array('-', '-', ' '), $str );
109 116
     }
110 117
 
111
-    public function getDataLink ($rel, $title = NULL, $view = false) {
118
+    public function getDataLink ($rel, $title = NULL, $view = false)
119
+    {
112 120
         global $config;
113 121
 
114 122
         if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") {
@@ -118,23 +126,29 @@  discard block
 block discarded – undo
118 126
         return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title, NULL, $view);
119 127
     }
120 128
 
121
-    public function getHtmlLink () {
129
+    public function getHtmlLink ()
130
+    {
122 131
         return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href;
123 132
     }
124 133
 
125
-    public function getViewHtmlLink () {
134
+    public function getViewHtmlLink ()
135
+    {
126 136
         return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE, NULL, true)->href;
127 137
     }
128 138
 
129
-    public function getLocalPath () {
139
+    public function getLocalPath ()
140
+    {
130 141
         return $this->book->path . "/" . $this->getFilename ();
131 142
     }
132 143
 
133
-    public function getHtmlLinkWithRewriting ($title = NULL, $view = false) {
144
+    public function getHtmlLinkWithRewriting ($title = NULL, $view = false)
145
+    {
134 146
         global $config;
135 147
 
136 148
         $database = "";
137
-        if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
149
+        if (!is_null (GetUrlParam (DB))) {
150
+            $database = GetUrlParam (DB) . "/";
151
+        }
138 152
 
139 153
         $prefix = "download";
140 154
         if ($view) {
@@ -152,7 +166,8 @@  discard block
 block discarded – undo
152 166
         return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title);
153 167
     }
154 168
 
155
-    public static function getDataByBook ($book) {
169
+    public static function getDataByBook ($book)
170
+    {
156 171
         global $config;
157 172
 
158 173
         $out = array ();
@@ -169,22 +184,20 @@  discard block
 block discarded – undo
169 184
         $result = parent::getDb ()->prepare($sql);
170 185
         $result->execute (array ($book->id));
171 186
 
172
-        while ($post = $result->fetchObject ())
173
-        {
187
+        while ($post = $result->fetchObject ()) {
174 188
             array_push ($out, new Data ($post, $book));
175 189
         }
176 190
         return $out;
177 191
     }
178 192
 
179
-    public static function handleThumbnailLink ($urlParam, $height) {
193
+    public static function handleThumbnailLink ($urlParam, $height)
194
+    {
180 195
         global $config;
181 196
 
182 197
         if (is_null ($height)) {
183 198
             if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) {
184 199
                 $height = $config['cops_opds_thumbnail_height'];
185
-            }
186
-            else
187
-            {
200
+            } else {
188 201
                 $height = $config['cops_html_thumbnail_height'];
189 202
             }
190 203
         }
@@ -200,18 +213,23 @@  discard block
 block discarded – undo
200 213
         global $config;
201 214
 
202 215
         $urlParam = addURLParameter("", "data", $idData);
203
-        if ($view) $urlParam = addURLParameter($urlParam, "view", 1);
216
+        if ($view) {
217
+            $urlParam = addURLParameter($urlParam, "view", 1);
218
+        }
204 219
 
205 220
         if (Base::useAbsolutePath () ||
206 221
             $rel == Link::OPDS_THUMBNAIL_TYPE ||
207
-            ($type == "epub" && $config['cops_update_epub-metadata']))
208
-        {
209
-            if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type);
222
+            ($type == "epub" && $config['cops_update_epub-metadata'])) {
223
+            if ($type != "jpg") {
224
+                $urlParam = addURLParameter($urlParam, "type", $type);
225
+            }
210 226
             if ($rel == Link::OPDS_THUMBNAIL_TYPE) {
211 227
                 $urlParam = self::handleThumbnailLink($urlParam, $height);
212 228
             }
213 229
             $urlParam = addURLParameter($urlParam, "id", $book->id);
214
-            if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
230
+            if (!is_null (GetUrlParam (DB))) {
231
+                $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
232
+            }
215 233
             if ($config['cops_thumbnail_handling'] != "1" &&
216 234
                 !empty ($config['cops_thumbnail_handling']) &&
217 235
                 $rel == Link::OPDS_THUMBNAIL_TYPE) {
@@ -219,9 +237,7 @@  discard block
 block discarded – undo
219 237
             } else {
220 238
                 return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
221 239
             }
222
-        }
223
-        else
224
-        {
240
+        } else {
225 241
             return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title);
226 242
         }
227 243
     }
Please login to merge, or discard this patch.