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