Completed
Pull Request — release-2.1 (#3798)
by John
07:17
created
proxy.php 1 patch
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -61,26 +61,31 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function checkRequest()
63 63
 	{
64
-		if (!$this->enabled)
65
-			return false;
64
+		if (!$this->enabled) {
65
+					return false;
66
+		}
66 67
 
67 68
 		// Try to create the image cache directory if it doesn't exist
68
-		if (!file_exists($this->cache))
69
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
69
+		if (!file_exists($this->cache)) {
70
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
70 71
 				return false;
72
+		}
71 73
 
72
-		if (empty($_GET['hash']) || empty($_GET['request']))
73
-			return false;
74
+		if (empty($_GET['hash']) || empty($_GET['request'])) {
75
+					return false;
76
+		}
74 77
 
75 78
 		$hash = $_GET['hash'];
76 79
 		$request = $_GET['request'];
77 80
 
78
-		if (md5($request . $this->secret) != $hash)
79
-			return false;
81
+		if (md5($request . $this->secret) != $hash) {
82
+					return false;
83
+		}
80 84
 
81 85
 		// Attempt to cache the request if it doesn't exist
82
-		if (!$this->isCached($request))
83
-			return $this->cacheImage($request);
86
+		if (!$this->isCached($request)) {
87
+					return $this->cacheImage($request);
88
+		}
84 89
 
85 90
 		return true;
86 91
 	}
@@ -101,19 +106,22 @@  discard block
 block discarded – undo
101 106
 		if (!$cached || time() - $cached['time'] > (5 * 86400))
102 107
 		{
103 108
 			@unlink($cached_file);
104
-			if ($this->checkRequest())
105
-				$this->serve();
109
+			if ($this->checkRequest()) {
110
+							$this->serve();
111
+			}
106 112
 			exit;
107 113
 		}
108 114
 
109 115
 		// Right, image not cached? Simply redirect, then.
110
-		if (!$this->checkRequest())
111
-			header('Location: ' . $request);
116
+		if (!$this->checkRequest()) {
117
+					header('Location: ' . $request);
118
+		}
112 119
 
113 120
 		// Make sure we're serving an image
114 121
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
115
-		if ($contentParts[0] != 'image')
116
-			exit;
122
+		if ($contentParts[0] != 'image') {
123
+					exit;
124
+		}
117 125
 
118 126
 		header('Content-type: ' . $cached['content_type']);
119 127
 		header('Content-length: ' . $cached['size']);
@@ -159,19 +167,22 @@  discard block
 block discarded – undo
159 167
 		$request = $curl->get_url_data($request);
160 168
 		$response = $request->result();
161 169
 
162
-		if (empty($response))
163
-			return false;
170
+		if (empty($response)) {
171
+					return false;
172
+		}
164 173
 
165 174
 		$headers = $response['headers'];
166 175
 
167 176
 		// Make sure the url is returning an image
168 177
 		$contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : '');
169
-		if ($contentParts[0] != 'image')
170
-			return false;
178
+		if ($contentParts[0] != 'image') {
179
+					return false;
180
+		}
171 181
 
172 182
 		// Validate the filesize
173
-		if ($response['size'] > ($this->maxSize * 1024))
174
-			return false;
183
+		if ($response['size'] > ($this->maxSize * 1024)) {
184
+					return false;
185
+		}
175 186
 
176 187
 		return file_put_contents($dest, json_encode(array(
177 188
 			'content_type' => $headers['content-type'],
Please login to merge, or discard this patch.