@@ -63,26 +63,31 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function checkRequest() |
65 | 65 | { |
66 | - if (!$this->enabled) |
|
67 | - return false; |
|
66 | + if (!$this->enabled) { |
|
67 | + return false; |
|
68 | + } |
|
68 | 69 | |
69 | 70 | // Try to create the image cache directory if it doesn't exist |
70 | - if (!file_exists($this->cache)) |
|
71 | - if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php')) |
|
71 | + if (!file_exists($this->cache)) { |
|
72 | + if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php')) |
|
72 | 73 | return false; |
74 | + } |
|
73 | 75 | |
74 | - if (empty($_GET['hash']) || empty($_GET['request'])) |
|
75 | - return false; |
|
76 | + if (empty($_GET['hash']) || empty($_GET['request'])) { |
|
77 | + return false; |
|
78 | + } |
|
76 | 79 | |
77 | 80 | $hash = $_GET['hash']; |
78 | 81 | $request = $_GET['request']; |
79 | 82 | |
80 | - if (md5($request . $this->secret) != $hash) |
|
81 | - return false; |
|
83 | + if (md5($request . $this->secret) != $hash) { |
|
84 | + return false; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | // Attempt to cache the request if it doesn't exist |
84 | - if (!$this->isCached($request)) |
|
85 | - return $this->cacheImage($request); |
|
88 | + if (!$this->isCached($request)) { |
|
89 | + return $this->cacheImage($request); |
|
90 | + } |
|
86 | 91 | |
87 | 92 | return true; |
88 | 93 | } |
@@ -111,19 +116,22 @@ discard block |
||
111 | 116 | if (!$cached || time() - $cached['time'] > (5 * 86400)) |
112 | 117 | { |
113 | 118 | @unlink($cached_file); |
114 | - if ($this->checkRequest()) |
|
115 | - $this->serve(); |
|
119 | + if ($this->checkRequest()) { |
|
120 | + $this->serve(); |
|
121 | + } |
|
116 | 122 | redirectexit($request); |
117 | 123 | } |
118 | 124 | |
119 | 125 | // Right, image not cached? Simply redirect, then. |
120 | - if (!$response) |
|
121 | - redirectexit($request); |
|
126 | + if (!$response) { |
|
127 | + redirectexit($request); |
|
128 | + } |
|
122 | 129 | |
123 | 130 | // Make sure we're serving an image |
124 | 131 | $contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : ''); |
125 | - if ($contentParts[0] != 'image') |
|
126 | - exit; |
|
132 | + if ($contentParts[0] != 'image') { |
|
133 | + exit; |
|
134 | + } |
|
127 | 135 | |
128 | 136 | header('Content-type: ' . $cached['content_type']); |
129 | 137 | header('Content-length: ' . $cached['size']); |
@@ -170,8 +178,9 @@ discard block |
||
170 | 178 | $responseCode = $request->result('code'); |
171 | 179 | $response = $request->result(); |
172 | 180 | |
173 | - if (empty($response)) |
|
174 | - return false; |
|
181 | + if (empty($response)) { |
|
182 | + return false; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | if ($responseCode != 200) { |
177 | 186 | return false; |
@@ -181,12 +190,14 @@ discard block |
||
181 | 190 | |
182 | 191 | // Make sure the url is returning an image |
183 | 192 | $contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : ''); |
184 | - if ($contentParts[0] != 'image') |
|
185 | - return false; |
|
193 | + if ($contentParts[0] != 'image') { |
|
194 | + return false; |
|
195 | + } |
|
186 | 196 | |
187 | 197 | // Validate the filesize |
188 | - if ($response['size'] > ($this->maxSize * 1024)) |
|
189 | - return false; |
|
198 | + if ($response['size'] > ($this->maxSize * 1024)) { |
|
199 | + return false; |
|
200 | + } |
|
190 | 201 | |
191 | 202 | return file_put_contents($dest, json_encode(array( |
192 | 203 | 'content_type' => $headers['content-type'], |