Completed
Pull Request — master (#223)
by
unknown
01:56
created
classes/external/php/plugin-update-checker/Puc/v4p4/Vcs/GitHubApi.php 2 patches
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -2,412 +2,412 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_Vcs_GitHubApi', false) ):
4 4
 
5
-	class Puc_v4p4_Vcs_GitHubApi extends Puc_v4p4_Vcs_Api {
6
-		/**
7
-		 * @var string GitHub username.
8
-		 */
9
-		protected $userName;
10
-		/**
11
-		 * @var string GitHub repository name.
12
-		 */
13
-		protected $repositoryName;
14
-
15
-		/**
16
-		 * @var string Either a fully qualified repository URL, or just "user/repo-name".
17
-		 */
18
-		protected $repositoryUrl;
19
-
20
-		/**
21
-		 * @var string GitHub authentication token. Optional.
22
-		 */
23
-		protected $accessToken;
24
-
25
-		/**
26
-		 * @var bool Whether to download release assets instead of the auto-generated source code archives.
27
-		 */
28
-		protected $releaseAssetsEnabled = false;
29
-
30
-		/**
31
-		 * @var string|null Regular expression that's used to filter release assets by name. Optional.
32
-		 */
33
-		protected $assetFilterRegex = null;
34
-
35
-		/**
36
-		 * @var string|null The unchanging part of a release asset URL. Used to identify download attempts.
37
-		 */
38
-		protected $assetApiBaseUrl = null;
39
-
40
-		public function __construct($repositoryUrl, $accessToken = null) {
41
-			$path = @parse_url($repositoryUrl, PHP_URL_PATH);
42
-			if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
43
-				$this->userName = $matches['username'];
44
-				$this->repositoryName = $matches['repository'];
45
-			} else {
46
-				throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
47
-			}
48
-
49
-			parent::__construct($repositoryUrl, $accessToken);
50
-		}
51
-
52
-		/**
53
-		 * Get the latest release from GitHub.
54
-		 *
55
-		 * @return Puc_v4p4_Vcs_Reference|null
56
-		 */
57
-		public function getLatestRelease() {
58
-			$release = $this->api('/repos/:user/:repo/releases/latest');
59
-			if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
60
-				return null;
61
-			}
62
-
63
-			$reference = new Puc_v4p4_Vcs_Reference(array(
64
-				'name'        => $release->tag_name,
65
-				'version'     => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
66
-				'downloadUrl' => $this->signDownloadUrl($release->zipball_url),
67
-				'updated'     => $release->created_at,
68
-				'apiResponse' => $release,
69
-			));
70
-
71
-			if ( isset($release->assets[0]) ) {
72
-				$reference->downloadCount = $release->assets[0]->download_count;
73
-			}
74
-
75
-			if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
76
-				//Use the first release asset that matches the specified regular expression.
77
-				$matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
78
-				if ( !empty($matchingAssets) ) {
79
-					if ( $this->isAuthenticationEnabled() ) {
80
-						/**
81
-						 * Keep in mind that we'll need to add an "Accept" header to download this asset.
82
-						 * @see setReleaseDownloadHeader()
83
-						 */
84
-						$reference->downloadUrl = $this->signDownloadUrl($matchingAssets[0]->url);
85
-					} else {
86
-						//It seems that browser_download_url only works for public repositories.
87
-						//Using an access_token doesn't help. Maybe OAuth would work?
88
-						$reference->downloadUrl = $matchingAssets[0]->browser_download_url;
89
-					}
90
-
91
-					$reference->downloadCount = $matchingAssets[0]->download_count;
92
-				}
93
-			}
94
-
95
-			if ( !empty($release->body) ) {
96
-				/** @noinspection PhpUndefinedClassInspection */
97
-				$reference->changelog = Parsedown::instance()->text($release->body);
98
-			}
99
-
100
-			return $reference;
101
-		}
102
-
103
-		/**
104
-		 * Get the tag that looks like the highest version number.
105
-		 *
106
-		 * @return Puc_v4p4_Vcs_Reference|null
107
-		 */
108
-		public function getLatestTag() {
109
-			$tags = $this->api('/repos/:user/:repo/tags');
110
-
111
-			if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
112
-				return null;
113
-			}
114
-
115
-			$versionTags = $this->sortTagsByVersion($tags);
116
-			if ( empty($versionTags) ) {
117
-				return null;
118
-			}
119
-
120
-			$tag = $versionTags[0];
121
-			return new Puc_v4p4_Vcs_Reference(array(
122
-				'name'        => $tag->name,
123
-				'version'     => ltrim($tag->name, 'v'),
124
-				'downloadUrl' => $this->signDownloadUrl($tag->zipball_url),
125
-				'apiResponse' => $tag,
126
-			));
127
-		}
128
-
129
-		/**
130
-		 * Get a branch by name.
131
-		 *
132
-		 * @param string $branchName
133
-		 * @return null|Puc_v4p4_Vcs_Reference
134
-		 */
135
-		public function getBranch($branchName) {
136
-			$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
137
-			if ( is_wp_error($branch) || empty($branch) ) {
138
-				return null;
139
-			}
140
-
141
-			$reference = new Puc_v4p4_Vcs_Reference(array(
142
-				'name'        => $branch->name,
143
-				'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
144
-				'apiResponse' => $branch,
145
-			));
146
-
147
-			if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
148
-				$reference->updated = $branch->commit->commit->author->date;
149
-			}
150
-
151
-			return $reference;
152
-		}
153
-
154
-		/**
155
-		 * Get the latest commit that changed the specified file.
156
-		 *
157
-		 * @param string $filename
158
-		 * @param string $ref Reference name (e.g. branch or tag).
159
-		 * @return StdClass|null
160
-		 */
161
-		public function getLatestCommit($filename, $ref = 'master') {
162
-			$commits = $this->api(
163
-				'/repos/:user/:repo/commits',
164
-				array(
165
-					'path' => $filename,
166
-					'sha'  => $ref,
167
-				)
168
-			);
169
-			if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
170
-				return $commits[0];
171
-			}
172
-			return null;
173
-		}
174
-
175
-		/**
176
-		 * Get the timestamp of the latest commit that changed the specified branch or tag.
177
-		 *
178
-		 * @param string $ref Reference name (e.g. branch or tag).
179
-		 * @return string|null
180
-		 */
181
-		public function getLatestCommitTime($ref) {
182
-			$commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
183
-			if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
184
-				return $commits[0]->commit->author->date;
185
-			}
186
-			return null;
187
-		}
188
-
189
-		/**
190
-		 * Perform a GitHub API request.
191
-		 *
192
-		 * @param string $url
193
-		 * @param array $queryParams
194
-		 * @return mixed|WP_Error
195
-		 */
196
-		protected function api($url, $queryParams = array()) {
197
-			$baseUrl = $url;
198
-			$url = $this->buildApiUrl($url, $queryParams);
199
-
200
-			$options = array('timeout' => 10);
201
-			if ( !empty($this->httpFilterName) ) {
202
-				$options = apply_filters($this->httpFilterName, $options);
203
-			}
204
-			$response = wp_remote_get($url, $options);
205
-			if ( is_wp_error($response) ) {
206
-				do_action('puc_api_error', $response, null, $url, $this->slug);
207
-				return $response;
208
-			}
209
-
210
-			$code = wp_remote_retrieve_response_code($response);
211
-			$body = wp_remote_retrieve_body($response);
212
-			if ( $code === 200 ) {
213
-				$document = json_decode($body);
214
-				return $document;
215
-			}
216
-
217
-			$error = new WP_Error(
218
-				'puc-github-http-error',
219
-				sprintf('GitHub API error. Base URL: "%s",  HTTP status code: %d.', $baseUrl, $code)
220
-			);
221
-			do_action('puc_api_error', $error, $response, $url, $this->slug);
222
-
223
-			return $error;
224
-		}
225
-
226
-		/**
227
-		 * Build a fully qualified URL for an API request.
228
-		 *
229
-		 * @param string $url
230
-		 * @param array $queryParams
231
-		 * @return string
232
-		 */
233
-		protected function buildApiUrl($url, $queryParams) {
234
-			$variables = array(
235
-				'user' => $this->userName,
236
-				'repo' => $this->repositoryName,
237
-			);
238
-			foreach ($variables as $name => $value) {
239
-				$url = str_replace('/:' . $name, '/' . urlencode($value), $url);
240
-			}
241
-			$url = 'https://api.github.com' . $url;
242
-
243
-			if ( !empty($this->accessToken) ) {
244
-				$queryParams['access_token'] = $this->accessToken;
245
-			}
246
-			if ( !empty($queryParams) ) {
247
-				$url = add_query_arg($queryParams, $url);
248
-			}
249
-
250
-			return $url;
251
-		}
252
-
253
-		/**
254
-		 * Get the contents of a file from a specific branch or tag.
255
-		 *
256
-		 * @param string $path File name.
257
-		 * @param string $ref
258
-		 * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
259
-		 */
260
-		public function getRemoteFile($path, $ref = 'master') {
261
-			$apiUrl = '/repos/:user/:repo/contents/' . $path;
262
-			$response = $this->api($apiUrl, array('ref' => $ref));
263
-
264
-			if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
265
-				return null;
266
-			}
267
-			return base64_decode($response->content);
268
-		}
269
-
270
-		/**
271
-		 * Generate a URL to download a ZIP archive of the specified branch/tag/etc.
272
-		 *
273
-		 * @param string $ref
274
-		 * @return string
275
-		 */
276
-		public function buildArchiveDownloadUrl($ref = 'master') {
277
-			$url = sprintf(
278
-				'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
279
-				urlencode($this->userName),
280
-				urlencode($this->repositoryName),
281
-				urlencode($ref)
282
-			);
283
-			if ( !empty($this->accessToken) ) {
284
-				$url = $this->signDownloadUrl($url);
285
-			}
286
-			return $url;
287
-		}
288
-
289
-		/**
290
-		 * Get a specific tag.
291
-		 *
292
-		 * @param string $tagName
293
-		 * @return Puc_v4p4_Vcs_Reference|null
294
-		 */
295
-		public function getTag($tagName) {
296
-			//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
297
-			throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
298
-		}
299
-
300
-		public function setAuthentication($credentials) {
301
-			parent::setAuthentication($credentials);
302
-			$this->accessToken = is_string($credentials) ? $credentials : null;
303
-		}
304
-
305
-		/**
306
-		 * Figure out which reference (i.e tag or branch) contains the latest version.
307
-		 *
308
-		 * @param string $configBranch Start looking in this branch.
309
-		 * @return null|Puc_v4p4_Vcs_Reference
310
-		 */
311
-		public function chooseReference($configBranch) {
312
-			$updateSource = null;
313
-
314
-			if ( $configBranch === 'master' ) {
315
-				//Use the latest release.
316
-				$updateSource = $this->getLatestRelease();
317
-				if ( $updateSource === null ) {
318
-					//Failing that, use the tag with the highest version number.
319
-					$updateSource = $this->getLatestTag();
320
-				}
321
-			}
322
-			//Alternatively, just use the branch itself.
323
-			if ( empty($updateSource) ) {
324
-				$updateSource = $this->getBranch($configBranch);
325
-			}
326
-
327
-			return $updateSource;
328
-		}
329
-
330
-		/**
331
-		 * @param string $url
332
-		 * @return string
333
-		 */
334
-		public function signDownloadUrl($url) {
335
-			if ( empty($this->credentials) ) {
336
-				return $url;
337
-			}
338
-			return add_query_arg('access_token', $this->credentials, $url);
339
-		}
340
-
341
-		/**
342
-		 * Enable updating via release assets.
343
-		 *
344
-		 * If the latest release contains no usable assets, the update checker
345
-		 * will fall back to using the automatically generated ZIP archive.
346
-		 *
347
-		 * Private repositories will only work with WordPress 3.7 or later.
348
-		 *
349
-		 * @param string|null $fileNameRegex Optional. Use only those assets where the file name matches this regex.
350
-		 */
351
-		public function enableReleaseAssets($fileNameRegex = null) {
352
-			$this->releaseAssetsEnabled = true;
353
-			$this->assetFilterRegex = $fileNameRegex;
354
-			$this->assetApiBaseUrl = sprintf(
355
-				'//api.github.com/repos/%1$s/%2$s/releases/assets/',
356
-				$this->userName,
357
-				$this->repositoryName
358
-			);
359
-
360
-			//Optimization: Instead of filtering all HTTP requests, let's do it only when
361
-			//WordPress is about to download an update.
362
-			add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
363
-		}
364
-
365
-		/**
366
-		 * Does this asset match the file name regex?
367
-		 *
368
-		 * @param stdClass $releaseAsset
369
-		 * @return bool
370
-		 */
371
-		protected function matchesAssetFilter($releaseAsset) {
372
-			if ( $this->assetFilterRegex === null ) {
373
-				//The default is to accept all assets.
374
-				return true;
375
-			}
376
-			return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
377
-		}
378
-
379
-		/**
380
-		 * @internal
381
-		 * @param bool $result
382
-		 * @return bool
383
-		 */
384
-		public function addHttpRequestFilter($result) {
385
-			static $filterAdded = false;
386
-			if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) {
387
-				add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2);
388
-				$filterAdded = true;
389
-			}
390
-			return $result;
391
-		}
392
-
393
-		/**
394
-		 * Set the HTTP header that's necessary to download private release assets.
395
-		 *
396
-		 * See GitHub docs:
397
-		 * @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
398
-		 *
399
-		 * @internal
400
-		 * @param array $requestArgs
401
-		 * @param string $url
402
-		 * @return array
403
-		 */
404
-		public function setReleaseDownloadHeader($requestArgs, $url = '') {
405
-			//Is WordPress trying to download one of our assets?
406
-			if ( strpos($url, $this->assetApiBaseUrl) !== false ) {
407
-				$requestArgs['headers']['accept'] = 'application/octet-stream';
408
-			}
409
-			return $requestArgs;
410
-		}
411
-	}
5
+    class Puc_v4p4_Vcs_GitHubApi extends Puc_v4p4_Vcs_Api {
6
+        /**
7
+         * @var string GitHub username.
8
+         */
9
+        protected $userName;
10
+        /**
11
+         * @var string GitHub repository name.
12
+         */
13
+        protected $repositoryName;
14
+
15
+        /**
16
+         * @var string Either a fully qualified repository URL, or just "user/repo-name".
17
+         */
18
+        protected $repositoryUrl;
19
+
20
+        /**
21
+         * @var string GitHub authentication token. Optional.
22
+         */
23
+        protected $accessToken;
24
+
25
+        /**
26
+         * @var bool Whether to download release assets instead of the auto-generated source code archives.
27
+         */
28
+        protected $releaseAssetsEnabled = false;
29
+
30
+        /**
31
+         * @var string|null Regular expression that's used to filter release assets by name. Optional.
32
+         */
33
+        protected $assetFilterRegex = null;
34
+
35
+        /**
36
+         * @var string|null The unchanging part of a release asset URL. Used to identify download attempts.
37
+         */
38
+        protected $assetApiBaseUrl = null;
39
+
40
+        public function __construct($repositoryUrl, $accessToken = null) {
41
+            $path = @parse_url($repositoryUrl, PHP_URL_PATH);
42
+            if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
43
+                $this->userName = $matches['username'];
44
+                $this->repositoryName = $matches['repository'];
45
+            } else {
46
+                throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
47
+            }
48
+
49
+            parent::__construct($repositoryUrl, $accessToken);
50
+        }
51
+
52
+        /**
53
+         * Get the latest release from GitHub.
54
+         *
55
+         * @return Puc_v4p4_Vcs_Reference|null
56
+         */
57
+        public function getLatestRelease() {
58
+            $release = $this->api('/repos/:user/:repo/releases/latest');
59
+            if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
60
+                return null;
61
+            }
62
+
63
+            $reference = new Puc_v4p4_Vcs_Reference(array(
64
+                'name'        => $release->tag_name,
65
+                'version'     => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
66
+                'downloadUrl' => $this->signDownloadUrl($release->zipball_url),
67
+                'updated'     => $release->created_at,
68
+                'apiResponse' => $release,
69
+            ));
70
+
71
+            if ( isset($release->assets[0]) ) {
72
+                $reference->downloadCount = $release->assets[0]->download_count;
73
+            }
74
+
75
+            if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
76
+                //Use the first release asset that matches the specified regular expression.
77
+                $matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
78
+                if ( !empty($matchingAssets) ) {
79
+                    if ( $this->isAuthenticationEnabled() ) {
80
+                        /**
81
+                         * Keep in mind that we'll need to add an "Accept" header to download this asset.
82
+                         * @see setReleaseDownloadHeader()
83
+                         */
84
+                        $reference->downloadUrl = $this->signDownloadUrl($matchingAssets[0]->url);
85
+                    } else {
86
+                        //It seems that browser_download_url only works for public repositories.
87
+                        //Using an access_token doesn't help. Maybe OAuth would work?
88
+                        $reference->downloadUrl = $matchingAssets[0]->browser_download_url;
89
+                    }
90
+
91
+                    $reference->downloadCount = $matchingAssets[0]->download_count;
92
+                }
93
+            }
94
+
95
+            if ( !empty($release->body) ) {
96
+                /** @noinspection PhpUndefinedClassInspection */
97
+                $reference->changelog = Parsedown::instance()->text($release->body);
98
+            }
99
+
100
+            return $reference;
101
+        }
102
+
103
+        /**
104
+         * Get the tag that looks like the highest version number.
105
+         *
106
+         * @return Puc_v4p4_Vcs_Reference|null
107
+         */
108
+        public function getLatestTag() {
109
+            $tags = $this->api('/repos/:user/:repo/tags');
110
+
111
+            if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
112
+                return null;
113
+            }
114
+
115
+            $versionTags = $this->sortTagsByVersion($tags);
116
+            if ( empty($versionTags) ) {
117
+                return null;
118
+            }
119
+
120
+            $tag = $versionTags[0];
121
+            return new Puc_v4p4_Vcs_Reference(array(
122
+                'name'        => $tag->name,
123
+                'version'     => ltrim($tag->name, 'v'),
124
+                'downloadUrl' => $this->signDownloadUrl($tag->zipball_url),
125
+                'apiResponse' => $tag,
126
+            ));
127
+        }
128
+
129
+        /**
130
+         * Get a branch by name.
131
+         *
132
+         * @param string $branchName
133
+         * @return null|Puc_v4p4_Vcs_Reference
134
+         */
135
+        public function getBranch($branchName) {
136
+            $branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
137
+            if ( is_wp_error($branch) || empty($branch) ) {
138
+                return null;
139
+            }
140
+
141
+            $reference = new Puc_v4p4_Vcs_Reference(array(
142
+                'name'        => $branch->name,
143
+                'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
144
+                'apiResponse' => $branch,
145
+            ));
146
+
147
+            if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
148
+                $reference->updated = $branch->commit->commit->author->date;
149
+            }
150
+
151
+            return $reference;
152
+        }
153
+
154
+        /**
155
+         * Get the latest commit that changed the specified file.
156
+         *
157
+         * @param string $filename
158
+         * @param string $ref Reference name (e.g. branch or tag).
159
+         * @return StdClass|null
160
+         */
161
+        public function getLatestCommit($filename, $ref = 'master') {
162
+            $commits = $this->api(
163
+                '/repos/:user/:repo/commits',
164
+                array(
165
+                    'path' => $filename,
166
+                    'sha'  => $ref,
167
+                )
168
+            );
169
+            if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
170
+                return $commits[0];
171
+            }
172
+            return null;
173
+        }
174
+
175
+        /**
176
+         * Get the timestamp of the latest commit that changed the specified branch or tag.
177
+         *
178
+         * @param string $ref Reference name (e.g. branch or tag).
179
+         * @return string|null
180
+         */
181
+        public function getLatestCommitTime($ref) {
182
+            $commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
183
+            if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
184
+                return $commits[0]->commit->author->date;
185
+            }
186
+            return null;
187
+        }
188
+
189
+        /**
190
+         * Perform a GitHub API request.
191
+         *
192
+         * @param string $url
193
+         * @param array $queryParams
194
+         * @return mixed|WP_Error
195
+         */
196
+        protected function api($url, $queryParams = array()) {
197
+            $baseUrl = $url;
198
+            $url = $this->buildApiUrl($url, $queryParams);
199
+
200
+            $options = array('timeout' => 10);
201
+            if ( !empty($this->httpFilterName) ) {
202
+                $options = apply_filters($this->httpFilterName, $options);
203
+            }
204
+            $response = wp_remote_get($url, $options);
205
+            if ( is_wp_error($response) ) {
206
+                do_action('puc_api_error', $response, null, $url, $this->slug);
207
+                return $response;
208
+            }
209
+
210
+            $code = wp_remote_retrieve_response_code($response);
211
+            $body = wp_remote_retrieve_body($response);
212
+            if ( $code === 200 ) {
213
+                $document = json_decode($body);
214
+                return $document;
215
+            }
216
+
217
+            $error = new WP_Error(
218
+                'puc-github-http-error',
219
+                sprintf('GitHub API error. Base URL: "%s",  HTTP status code: %d.', $baseUrl, $code)
220
+            );
221
+            do_action('puc_api_error', $error, $response, $url, $this->slug);
222
+
223
+            return $error;
224
+        }
225
+
226
+        /**
227
+         * Build a fully qualified URL for an API request.
228
+         *
229
+         * @param string $url
230
+         * @param array $queryParams
231
+         * @return string
232
+         */
233
+        protected function buildApiUrl($url, $queryParams) {
234
+            $variables = array(
235
+                'user' => $this->userName,
236
+                'repo' => $this->repositoryName,
237
+            );
238
+            foreach ($variables as $name => $value) {
239
+                $url = str_replace('/:' . $name, '/' . urlencode($value), $url);
240
+            }
241
+            $url = 'https://api.github.com' . $url;
242
+
243
+            if ( !empty($this->accessToken) ) {
244
+                $queryParams['access_token'] = $this->accessToken;
245
+            }
246
+            if ( !empty($queryParams) ) {
247
+                $url = add_query_arg($queryParams, $url);
248
+            }
249
+
250
+            return $url;
251
+        }
252
+
253
+        /**
254
+         * Get the contents of a file from a specific branch or tag.
255
+         *
256
+         * @param string $path File name.
257
+         * @param string $ref
258
+         * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
259
+         */
260
+        public function getRemoteFile($path, $ref = 'master') {
261
+            $apiUrl = '/repos/:user/:repo/contents/' . $path;
262
+            $response = $this->api($apiUrl, array('ref' => $ref));
263
+
264
+            if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
265
+                return null;
266
+            }
267
+            return base64_decode($response->content);
268
+        }
269
+
270
+        /**
271
+         * Generate a URL to download a ZIP archive of the specified branch/tag/etc.
272
+         *
273
+         * @param string $ref
274
+         * @return string
275
+         */
276
+        public function buildArchiveDownloadUrl($ref = 'master') {
277
+            $url = sprintf(
278
+                'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
279
+                urlencode($this->userName),
280
+                urlencode($this->repositoryName),
281
+                urlencode($ref)
282
+            );
283
+            if ( !empty($this->accessToken) ) {
284
+                $url = $this->signDownloadUrl($url);
285
+            }
286
+            return $url;
287
+        }
288
+
289
+        /**
290
+         * Get a specific tag.
291
+         *
292
+         * @param string $tagName
293
+         * @return Puc_v4p4_Vcs_Reference|null
294
+         */
295
+        public function getTag($tagName) {
296
+            //The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
297
+            throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
298
+        }
299
+
300
+        public function setAuthentication($credentials) {
301
+            parent::setAuthentication($credentials);
302
+            $this->accessToken = is_string($credentials) ? $credentials : null;
303
+        }
304
+
305
+        /**
306
+         * Figure out which reference (i.e tag or branch) contains the latest version.
307
+         *
308
+         * @param string $configBranch Start looking in this branch.
309
+         * @return null|Puc_v4p4_Vcs_Reference
310
+         */
311
+        public function chooseReference($configBranch) {
312
+            $updateSource = null;
313
+
314
+            if ( $configBranch === 'master' ) {
315
+                //Use the latest release.
316
+                $updateSource = $this->getLatestRelease();
317
+                if ( $updateSource === null ) {
318
+                    //Failing that, use the tag with the highest version number.
319
+                    $updateSource = $this->getLatestTag();
320
+                }
321
+            }
322
+            //Alternatively, just use the branch itself.
323
+            if ( empty($updateSource) ) {
324
+                $updateSource = $this->getBranch($configBranch);
325
+            }
326
+
327
+            return $updateSource;
328
+        }
329
+
330
+        /**
331
+         * @param string $url
332
+         * @return string
333
+         */
334
+        public function signDownloadUrl($url) {
335
+            if ( empty($this->credentials) ) {
336
+                return $url;
337
+            }
338
+            return add_query_arg('access_token', $this->credentials, $url);
339
+        }
340
+
341
+        /**
342
+         * Enable updating via release assets.
343
+         *
344
+         * If the latest release contains no usable assets, the update checker
345
+         * will fall back to using the automatically generated ZIP archive.
346
+         *
347
+         * Private repositories will only work with WordPress 3.7 or later.
348
+         *
349
+         * @param string|null $fileNameRegex Optional. Use only those assets where the file name matches this regex.
350
+         */
351
+        public function enableReleaseAssets($fileNameRegex = null) {
352
+            $this->releaseAssetsEnabled = true;
353
+            $this->assetFilterRegex = $fileNameRegex;
354
+            $this->assetApiBaseUrl = sprintf(
355
+                '//api.github.com/repos/%1$s/%2$s/releases/assets/',
356
+                $this->userName,
357
+                $this->repositoryName
358
+            );
359
+
360
+            //Optimization: Instead of filtering all HTTP requests, let's do it only when
361
+            //WordPress is about to download an update.
362
+            add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
363
+        }
364
+
365
+        /**
366
+         * Does this asset match the file name regex?
367
+         *
368
+         * @param stdClass $releaseAsset
369
+         * @return bool
370
+         */
371
+        protected function matchesAssetFilter($releaseAsset) {
372
+            if ( $this->assetFilterRegex === null ) {
373
+                //The default is to accept all assets.
374
+                return true;
375
+            }
376
+            return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
377
+        }
378
+
379
+        /**
380
+         * @internal
381
+         * @param bool $result
382
+         * @return bool
383
+         */
384
+        public function addHttpRequestFilter($result) {
385
+            static $filterAdded = false;
386
+            if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) {
387
+                add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2);
388
+                $filterAdded = true;
389
+            }
390
+            return $result;
391
+        }
392
+
393
+        /**
394
+         * Set the HTTP header that's necessary to download private release assets.
395
+         *
396
+         * See GitHub docs:
397
+         * @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
398
+         *
399
+         * @internal
400
+         * @param array $requestArgs
401
+         * @param string $url
402
+         * @return array
403
+         */
404
+        public function setReleaseDownloadHeader($requestArgs, $url = '') {
405
+            //Is WordPress trying to download one of our assets?
406
+            if ( strpos($url, $this->assetApiBaseUrl) !== false ) {
407
+                $requestArgs['headers']['accept'] = 'application/octet-stream';
408
+            }
409
+            return $requestArgs;
410
+        }
411
+    }
412 412
 
413 413
 endif;
414 414
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( !class_exists('Puc_v4p4_Vcs_GitHubApi', false) ):
3
+if (!class_exists('Puc_v4p4_Vcs_GitHubApi', false)):
4 4
 
5 5
 	class Puc_v4p4_Vcs_GitHubApi extends Puc_v4p4_Vcs_Api {
6 6
 		/**
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 
40 40
 		public function __construct($repositoryUrl, $accessToken = null) {
41 41
 			$path = @parse_url($repositoryUrl, PHP_URL_PATH);
42
-			if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
42
+			if (preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches)) {
43 43
 				$this->userName = $matches['username'];
44 44
 				$this->repositoryName = $matches['repository'];
45 45
 			} else {
46
-				throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
46
+				throw new InvalidArgumentException('Invalid GitHub repository URL: "'.$repositoryUrl.'"');
47 47
 			}
48 48
 
49 49
 			parent::__construct($repositoryUrl, $accessToken);
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		 */
57 57
 		public function getLatestRelease() {
58 58
 			$release = $this->api('/repos/:user/:repo/releases/latest');
59
-			if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
59
+			if (is_wp_error($release) || !is_object($release) || !isset($release->tag_name)) {
60 60
 				return null;
61 61
 			}
62 62
 
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 				'apiResponse' => $release,
69 69
 			));
70 70
 
71
-			if ( isset($release->assets[0]) ) {
71
+			if (isset($release->assets[0])) {
72 72
 				$reference->downloadCount = $release->assets[0]->download_count;
73 73
 			}
74 74
 
75
-			if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
75
+			if ($this->releaseAssetsEnabled && isset($release->assets, $release->assets[0])) {
76 76
 				//Use the first release asset that matches the specified regular expression.
77 77
 				$matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
78
-				if ( !empty($matchingAssets) ) {
79
-					if ( $this->isAuthenticationEnabled() ) {
78
+				if (!empty($matchingAssets)) {
79
+					if ($this->isAuthenticationEnabled()) {
80 80
 						/**
81 81
 						 * Keep in mind that we'll need to add an "Accept" header to download this asset.
82 82
 						 * @see setReleaseDownloadHeader()
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 				}
93 93
 			}
94 94
 
95
-			if ( !empty($release->body) ) {
95
+			if (!empty($release->body)) {
96 96
 				/** @noinspection PhpUndefinedClassInspection */
97 97
 				$reference->changelog = Parsedown::instance()->text($release->body);
98 98
 			}
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 		public function getLatestTag() {
109 109
 			$tags = $this->api('/repos/:user/:repo/tags');
110 110
 
111
-			if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
111
+			if (is_wp_error($tags) || empty($tags) || !is_array($tags)) {
112 112
 				return null;
113 113
 			}
114 114
 
115 115
 			$versionTags = $this->sortTagsByVersion($tags);
116
-			if ( empty($versionTags) ) {
116
+			if (empty($versionTags)) {
117 117
 				return null;
118 118
 			}
119 119
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 		 * @return null|Puc_v4p4_Vcs_Reference
134 134
 		 */
135 135
 		public function getBranch($branchName) {
136
-			$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
137
-			if ( is_wp_error($branch) || empty($branch) ) {
136
+			$branch = $this->api('/repos/:user/:repo/branches/'.$branchName);
137
+			if (is_wp_error($branch) || empty($branch)) {
138 138
 				return null;
139 139
 			}
140 140
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 				'apiResponse' => $branch,
145 145
 			));
146 146
 
147
-			if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
147
+			if (isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date)) {
148 148
 				$reference->updated = $branch->commit->commit->author->date;
149 149
 			}
150 150
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 					'sha'  => $ref,
167 167
 				)
168 168
 			);
169
-			if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
169
+			if (!is_wp_error($commits) && is_array($commits) && isset($commits[0])) {
170 170
 				return $commits[0];
171 171
 			}
172 172
 			return null;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		 */
181 181
 		public function getLatestCommitTime($ref) {
182 182
 			$commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
183
-			if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
183
+			if (!is_wp_error($commits) && is_array($commits) && isset($commits[0])) {
184 184
 				return $commits[0]->commit->author->date;
185 185
 			}
186 186
 			return null;
@@ -198,18 +198,18 @@  discard block
 block discarded – undo
198 198
 			$url = $this->buildApiUrl($url, $queryParams);
199 199
 
200 200
 			$options = array('timeout' => 10);
201
-			if ( !empty($this->httpFilterName) ) {
201
+			if (!empty($this->httpFilterName)) {
202 202
 				$options = apply_filters($this->httpFilterName, $options);
203 203
 			}
204 204
 			$response = wp_remote_get($url, $options);
205
-			if ( is_wp_error($response) ) {
205
+			if (is_wp_error($response)) {
206 206
 				do_action('puc_api_error', $response, null, $url, $this->slug);
207 207
 				return $response;
208 208
 			}
209 209
 
210 210
 			$code = wp_remote_retrieve_response_code($response);
211 211
 			$body = wp_remote_retrieve_body($response);
212
-			if ( $code === 200 ) {
212
+			if ($code === 200) {
213 213
 				$document = json_decode($body);
214 214
 				return $document;
215 215
 			}
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 				'repo' => $this->repositoryName,
237 237
 			);
238 238
 			foreach ($variables as $name => $value) {
239
-				$url = str_replace('/:' . $name, '/' . urlencode($value), $url);
239
+				$url = str_replace('/:'.$name, '/'.urlencode($value), $url);
240 240
 			}
241
-			$url = 'https://api.github.com' . $url;
241
+			$url = 'https://api.github.com'.$url;
242 242
 
243
-			if ( !empty($this->accessToken) ) {
243
+			if (!empty($this->accessToken)) {
244 244
 				$queryParams['access_token'] = $this->accessToken;
245 245
 			}
246
-			if ( !empty($queryParams) ) {
246
+			if (!empty($queryParams)) {
247 247
 				$url = add_query_arg($queryParams, $url);
248 248
 			}
249 249
 
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 		 * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
259 259
 		 */
260 260
 		public function getRemoteFile($path, $ref = 'master') {
261
-			$apiUrl = '/repos/:user/:repo/contents/' . $path;
261
+			$apiUrl = '/repos/:user/:repo/contents/'.$path;
262 262
 			$response = $this->api($apiUrl, array('ref' => $ref));
263 263
 
264
-			if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
264
+			if (is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64')) {
265 265
 				return null;
266 266
 			}
267 267
 			return base64_decode($response->content);
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 				urlencode($this->repositoryName),
281 281
 				urlencode($ref)
282 282
 			);
283
-			if ( !empty($this->accessToken) ) {
283
+			if (!empty($this->accessToken)) {
284 284
 				$url = $this->signDownloadUrl($url);
285 285
 			}
286 286
 			return $url;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 		 */
295 295
 		public function getTag($tagName) {
296 296
 			//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
297
-			throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
297
+			throw new LogicException('The '.__METHOD__.' method is not implemented and should not be used.');
298 298
 		}
299 299
 
300 300
 		public function setAuthentication($credentials) {
@@ -311,16 +311,16 @@  discard block
 block discarded – undo
311 311
 		public function chooseReference($configBranch) {
312 312
 			$updateSource = null;
313 313
 
314
-			if ( $configBranch === 'master' ) {
314
+			if ($configBranch === 'master') {
315 315
 				//Use the latest release.
316 316
 				$updateSource = $this->getLatestRelease();
317
-				if ( $updateSource === null ) {
317
+				if ($updateSource === null) {
318 318
 					//Failing that, use the tag with the highest version number.
319 319
 					$updateSource = $this->getLatestTag();
320 320
 				}
321 321
 			}
322 322
 			//Alternatively, just use the branch itself.
323
-			if ( empty($updateSource) ) {
323
+			if (empty($updateSource)) {
324 324
 				$updateSource = $this->getBranch($configBranch);
325 325
 			}
326 326
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		 * @return string
333 333
 		 */
334 334
 		public function signDownloadUrl($url) {
335
-			if ( empty($this->credentials) ) {
335
+			if (empty($this->credentials)) {
336 336
 				return $url;
337 337
 			}
338 338
 			return add_query_arg('access_token', $this->credentials, $url);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 		 * @return bool
370 370
 		 */
371 371
 		protected function matchesAssetFilter($releaseAsset) {
372
-			if ( $this->assetFilterRegex === null ) {
372
+			if ($this->assetFilterRegex === null) {
373 373
 				//The default is to accept all assets.
374 374
 				return true;
375 375
 			}
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 		 */
384 384
 		public function addHttpRequestFilter($result) {
385 385
 			static $filterAdded = false;
386
-			if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) {
386
+			if ($this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled()) {
387 387
 				add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2);
388 388
 				$filterAdded = true;
389 389
 			}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 		 */
404 404
 		public function setReleaseDownloadHeader($requestArgs, $url = '') {
405 405
 			//Is WordPress trying to download one of our assets?
406
-			if ( strpos($url, $this->assetApiBaseUrl) !== false ) {
406
+			if (strpos($url, $this->assetApiBaseUrl) !== false) {
407 407
 				$requestArgs['headers']['accept'] = 'application/octet-stream';
408 408
 			}
409 409
 			return $requestArgs;
Please login to merge, or discard this patch.
external/php/plugin-update-checker/Puc/v4p4/Vcs/PluginUpdateChecker.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,217 +1,217 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
3 3
 
4
-	class Puc_v4p4_Vcs_PluginUpdateChecker extends Puc_v4p4_Plugin_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
5
-		/**
6
-		 * @var string The branch where to look for updates. Defaults to "master".
7
-		 */
8
-		protected $branch = 'master';
9
-
10
-		/**
11
-		 * @var Puc_v4p4_Vcs_Api Repository API client.
12
-		 */
13
-		protected $api = null;
14
-
15
-		/**
16
-		 * Puc_v4p4_Vcs_PluginUpdateChecker constructor.
17
-		 *
18
-		 * @param Puc_v4p4_Vcs_Api $api
19
-		 * @param string $pluginFile
20
-		 * @param string $slug
21
-		 * @param int $checkPeriod
22
-		 * @param string $optionName
23
-		 * @param string $muPluginFile
24
-		 */
25
-		public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
26
-			$this->api = $api;
27
-			$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
28
-
29
-			parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
30
-
31
-			$this->api->setSlug($this->slug);
32
-		}
33
-
34
-		public function requestInfo($unusedParameter = null) {
35
-			//We have to make several remote API requests to gather all the necessary info
36
-			//which can take a while on slow networks.
37
-			if ( function_exists('set_time_limit') ) {
38
-				@set_time_limit(60);
39
-			}
40
-
41
-			$api = $this->api;
42
-			$api->setLocalDirectory($this->getAbsoluteDirectoryPath());
43
-
44
-			$info = new Puc_v4p4_Plugin_Info();
45
-			$info->filename = $this->pluginFile;
46
-			$info->slug = $this->slug;
47
-
48
-			$this->setInfoFromHeader($this->getPluginHeader(), $info);
49
-
50
-			//Pick a branch or tag.
51
-			$updateSource = $api->chooseReference($this->branch);
52
-			if ( $updateSource ) {
53
-				$ref = $updateSource->name;
54
-				$info->version = $updateSource->version;
55
-				$info->last_updated = $updateSource->updated;
56
-				$info->download_url = $updateSource->downloadUrl;
57
-
58
-				if ( !empty($updateSource->changelog) ) {
59
-					$info->sections['changelog'] = $updateSource->changelog;
60
-				}
61
-				if ( isset($updateSource->downloadCount) ) {
62
-					$info->downloaded = $updateSource->downloadCount;
63
-				}
64
-			} else {
65
-				//There's probably a network problem or an authentication error.
66
-				do_action(
67
-					'puc_api_error',
68
-					new WP_Error(
69
-						'puc-no-update-source',
70
-						'Could not retrieve version information from the repository. '
71
-						. 'This usually means that the update checker either can\'t connect '
72
-						. 'to the repository or it\'s configured incorrectly.'
73
-					),
74
-					null, null, $this->slug
75
-				);
76
-				return null;
77
-			}
78
-
79
-			//Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata
80
-			//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
81
-			$mainPluginFile = basename($this->pluginFile);
82
-			$remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
83
-			if ( !empty($remotePlugin) ) {
84
-				$remoteHeader = $this->getFileHeader($remotePlugin);
85
-				$this->setInfoFromHeader($remoteHeader, $info);
86
-			}
87
-
88
-			//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
89
-			//a lot of useful information like the required/tested WP version, changelog, and so on.
90
-			if ( $this->readmeTxtExistsLocally() ) {
91
-				$this->setInfoFromRemoteReadme($ref, $info);
92
-			}
93
-
94
-			//The changelog might be in a separate file.
95
-			if ( empty($info->sections['changelog']) ) {
96
-				$info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
97
-				if ( empty($info->sections['changelog']) ) {
98
-					$info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
99
-				}
100
-			}
101
-
102
-			if ( empty($info->last_updated) ) {
103
-				//Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date.
104
-				$latestCommitTime = $api->getLatestCommitTime($ref);
105
-				if ( $latestCommitTime !== null ) {
106
-					$info->last_updated = $latestCommitTime;
107
-				}
108
-			}
109
-
110
-			$info = apply_filters($this->getUniqueName('request_info_result'), $info, null);
111
-			return $info;
112
-		}
113
-
114
-		/**
115
-		 * Check if the currently installed version has a readme.txt file.
116
-		 *
117
-		 * @return bool
118
-		 */
119
-		protected function readmeTxtExistsLocally() {
120
-			$pluginDirectory = $this->getAbsoluteDirectoryPath();
121
-			if ( empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
122
-				return false;
123
-			}
124
-			return is_file($pluginDirectory . '/' . $this->api->getLocalReadmeName());
125
-		}
126
-
127
-		/**
128
-		 * Copy plugin metadata from a file header to a Plugin Info object.
129
-		 *
130
-		 * @param array $fileHeader
131
-		 * @param Puc_v4p4_Plugin_Info $pluginInfo
132
-		 */
133
-		protected function setInfoFromHeader($fileHeader, $pluginInfo) {
134
-			$headerToPropertyMap = array(
135
-				'Version' => 'version',
136
-				'Name' => 'name',
137
-				'PluginURI' => 'homepage',
138
-				'Author' => 'author',
139
-				'AuthorName' => 'author',
140
-				'AuthorURI' => 'author_homepage',
141
-
142
-				'Requires WP' => 'requires',
143
-				'Tested WP' => 'tested',
144
-				'Requires at least' => 'requires',
145
-				'Tested up to' => 'tested',
146
-			);
147
-			foreach ($headerToPropertyMap as $headerName => $property) {
148
-				if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
149
-					$pluginInfo->$property = $fileHeader[$headerName];
150
-				}
151
-			}
152
-
153
-			if ( !empty($fileHeader['Description']) ) {
154
-				$pluginInfo->sections['description'] = $fileHeader['Description'];
155
-			}
156
-		}
157
-
158
-		/**
159
-		 * Copy plugin metadata from the remote readme.txt file.
160
-		 *
161
-		 * @param string $ref GitHub tag or branch where to look for the readme.
162
-		 * @param Puc_v4p4_Plugin_Info $pluginInfo
163
-		 */
164
-		protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
165
-			$readme = $this->api->getRemoteReadme($ref);
166
-			if ( empty($readme) ) {
167
-				return;
168
-			}
169
-
170
-			if ( isset($readme['sections']) ) {
171
-				$pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
172
-			}
173
-			if ( !empty($readme['tested_up_to']) ) {
174
-				$pluginInfo->tested = $readme['tested_up_to'];
175
-			}
176
-			if ( !empty($readme['requires_at_least']) ) {
177
-				$pluginInfo->requires = $readme['requires_at_least'];
178
-			}
179
-
180
-			if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
181
-				$pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
182
-			}
183
-		}
184
-
185
-		public function setBranch($branch) {
186
-			$this->branch = $branch;
187
-			return $this;
188
-		}
189
-
190
-		public function setAuthentication($credentials) {
191
-			$this->api->setAuthentication($credentials);
192
-			return $this;
193
-		}
194
-
195
-		public function getVcsApi() {
196
-			return $this->api;
197
-		}
198
-
199
-		public function getUpdate() {
200
-			$update = parent::getUpdate();
201
-
202
-			if ( isset($update) && !empty($update->download_url) ) {
203
-				$update->download_url = $this->api->signDownloadUrl($update->download_url);
204
-			}
205
-
206
-			return $update;
207
-		}
208
-
209
-		public function onDisplayConfiguration($panel) {
210
-			parent::onDisplayConfiguration($panel);
211
-			$panel->row('Branch', $this->branch);
212
-			$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
213
-			$panel->row('API client', get_class($this->api));
214
-		}
215
-	}
4
+    class Puc_v4p4_Vcs_PluginUpdateChecker extends Puc_v4p4_Plugin_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
5
+        /**
6
+         * @var string The branch where to look for updates. Defaults to "master".
7
+         */
8
+        protected $branch = 'master';
9
+
10
+        /**
11
+         * @var Puc_v4p4_Vcs_Api Repository API client.
12
+         */
13
+        protected $api = null;
14
+
15
+        /**
16
+         * Puc_v4p4_Vcs_PluginUpdateChecker constructor.
17
+         *
18
+         * @param Puc_v4p4_Vcs_Api $api
19
+         * @param string $pluginFile
20
+         * @param string $slug
21
+         * @param int $checkPeriod
22
+         * @param string $optionName
23
+         * @param string $muPluginFile
24
+         */
25
+        public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
26
+            $this->api = $api;
27
+            $this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
28
+
29
+            parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
30
+
31
+            $this->api->setSlug($this->slug);
32
+        }
33
+
34
+        public function requestInfo($unusedParameter = null) {
35
+            //We have to make several remote API requests to gather all the necessary info
36
+            //which can take a while on slow networks.
37
+            if ( function_exists('set_time_limit') ) {
38
+                @set_time_limit(60);
39
+            }
40
+
41
+            $api = $this->api;
42
+            $api->setLocalDirectory($this->getAbsoluteDirectoryPath());
43
+
44
+            $info = new Puc_v4p4_Plugin_Info();
45
+            $info->filename = $this->pluginFile;
46
+            $info->slug = $this->slug;
47
+
48
+            $this->setInfoFromHeader($this->getPluginHeader(), $info);
49
+
50
+            //Pick a branch or tag.
51
+            $updateSource = $api->chooseReference($this->branch);
52
+            if ( $updateSource ) {
53
+                $ref = $updateSource->name;
54
+                $info->version = $updateSource->version;
55
+                $info->last_updated = $updateSource->updated;
56
+                $info->download_url = $updateSource->downloadUrl;
57
+
58
+                if ( !empty($updateSource->changelog) ) {
59
+                    $info->sections['changelog'] = $updateSource->changelog;
60
+                }
61
+                if ( isset($updateSource->downloadCount) ) {
62
+                    $info->downloaded = $updateSource->downloadCount;
63
+                }
64
+            } else {
65
+                //There's probably a network problem or an authentication error.
66
+                do_action(
67
+                    'puc_api_error',
68
+                    new WP_Error(
69
+                        'puc-no-update-source',
70
+                        'Could not retrieve version information from the repository. '
71
+                        . 'This usually means that the update checker either can\'t connect '
72
+                        . 'to the repository or it\'s configured incorrectly.'
73
+                    ),
74
+                    null, null, $this->slug
75
+                );
76
+                return null;
77
+            }
78
+
79
+            //Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata
80
+            //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
81
+            $mainPluginFile = basename($this->pluginFile);
82
+            $remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
83
+            if ( !empty($remotePlugin) ) {
84
+                $remoteHeader = $this->getFileHeader($remotePlugin);
85
+                $this->setInfoFromHeader($remoteHeader, $info);
86
+            }
87
+
88
+            //Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
89
+            //a lot of useful information like the required/tested WP version, changelog, and so on.
90
+            if ( $this->readmeTxtExistsLocally() ) {
91
+                $this->setInfoFromRemoteReadme($ref, $info);
92
+            }
93
+
94
+            //The changelog might be in a separate file.
95
+            if ( empty($info->sections['changelog']) ) {
96
+                $info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
97
+                if ( empty($info->sections['changelog']) ) {
98
+                    $info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
99
+                }
100
+            }
101
+
102
+            if ( empty($info->last_updated) ) {
103
+                //Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date.
104
+                $latestCommitTime = $api->getLatestCommitTime($ref);
105
+                if ( $latestCommitTime !== null ) {
106
+                    $info->last_updated = $latestCommitTime;
107
+                }
108
+            }
109
+
110
+            $info = apply_filters($this->getUniqueName('request_info_result'), $info, null);
111
+            return $info;
112
+        }
113
+
114
+        /**
115
+         * Check if the currently installed version has a readme.txt file.
116
+         *
117
+         * @return bool
118
+         */
119
+        protected function readmeTxtExistsLocally() {
120
+            $pluginDirectory = $this->getAbsoluteDirectoryPath();
121
+            if ( empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
122
+                return false;
123
+            }
124
+            return is_file($pluginDirectory . '/' . $this->api->getLocalReadmeName());
125
+        }
126
+
127
+        /**
128
+         * Copy plugin metadata from a file header to a Plugin Info object.
129
+         *
130
+         * @param array $fileHeader
131
+         * @param Puc_v4p4_Plugin_Info $pluginInfo
132
+         */
133
+        protected function setInfoFromHeader($fileHeader, $pluginInfo) {
134
+            $headerToPropertyMap = array(
135
+                'Version' => 'version',
136
+                'Name' => 'name',
137
+                'PluginURI' => 'homepage',
138
+                'Author' => 'author',
139
+                'AuthorName' => 'author',
140
+                'AuthorURI' => 'author_homepage',
141
+
142
+                'Requires WP' => 'requires',
143
+                'Tested WP' => 'tested',
144
+                'Requires at least' => 'requires',
145
+                'Tested up to' => 'tested',
146
+            );
147
+            foreach ($headerToPropertyMap as $headerName => $property) {
148
+                if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
149
+                    $pluginInfo->$property = $fileHeader[$headerName];
150
+                }
151
+            }
152
+
153
+            if ( !empty($fileHeader['Description']) ) {
154
+                $pluginInfo->sections['description'] = $fileHeader['Description'];
155
+            }
156
+        }
157
+
158
+        /**
159
+         * Copy plugin metadata from the remote readme.txt file.
160
+         *
161
+         * @param string $ref GitHub tag or branch where to look for the readme.
162
+         * @param Puc_v4p4_Plugin_Info $pluginInfo
163
+         */
164
+        protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
165
+            $readme = $this->api->getRemoteReadme($ref);
166
+            if ( empty($readme) ) {
167
+                return;
168
+            }
169
+
170
+            if ( isset($readme['sections']) ) {
171
+                $pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
172
+            }
173
+            if ( !empty($readme['tested_up_to']) ) {
174
+                $pluginInfo->tested = $readme['tested_up_to'];
175
+            }
176
+            if ( !empty($readme['requires_at_least']) ) {
177
+                $pluginInfo->requires = $readme['requires_at_least'];
178
+            }
179
+
180
+            if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
181
+                $pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
182
+            }
183
+        }
184
+
185
+        public function setBranch($branch) {
186
+            $this->branch = $branch;
187
+            return $this;
188
+        }
189
+
190
+        public function setAuthentication($credentials) {
191
+            $this->api->setAuthentication($credentials);
192
+            return $this;
193
+        }
194
+
195
+        public function getVcsApi() {
196
+            return $this->api;
197
+        }
198
+
199
+        public function getUpdate() {
200
+            $update = parent::getUpdate();
201
+
202
+            if ( isset($update) && !empty($update->download_url) ) {
203
+                $update->download_url = $this->api->signDownloadUrl($update->download_url);
204
+            }
205
+
206
+            return $update;
207
+        }
208
+
209
+        public function onDisplayConfiguration($panel) {
210
+            parent::onDisplayConfiguration($panel);
211
+            $panel->row('Branch', $this->branch);
212
+            $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
213
+            $panel->row('API client', get_class($this->api));
214
+        }
215
+    }
216 216
 
217 217
 endif;
218 218
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
2
+if (!class_exists('Puc_v4p4_Vcs_PluginUpdateChecker')):
3 3
 
4 4
 	class Puc_v4p4_Vcs_PluginUpdateChecker extends Puc_v4p4_Plugin_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
5 5
 		/**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		public function requestInfo($unusedParameter = null) {
35 35
 			//We have to make several remote API requests to gather all the necessary info
36 36
 			//which can take a while on slow networks.
37
-			if ( function_exists('set_time_limit') ) {
37
+			if (function_exists('set_time_limit')) {
38 38
 				@set_time_limit(60);
39 39
 			}
40 40
 
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
 
50 50
 			//Pick a branch or tag.
51 51
 			$updateSource = $api->chooseReference($this->branch);
52
-			if ( $updateSource ) {
52
+			if ($updateSource) {
53 53
 				$ref = $updateSource->name;
54 54
 				$info->version = $updateSource->version;
55 55
 				$info->last_updated = $updateSource->updated;
56 56
 				$info->download_url = $updateSource->downloadUrl;
57 57
 
58
-				if ( !empty($updateSource->changelog) ) {
58
+				if (!empty($updateSource->changelog)) {
59 59
 					$info->sections['changelog'] = $updateSource->changelog;
60 60
 				}
61
-				if ( isset($updateSource->downloadCount) ) {
61
+				if (isset($updateSource->downloadCount)) {
62 62
 					$info->downloaded = $updateSource->downloadCount;
63 63
 				}
64 64
 			} else {
@@ -80,29 +80,29 @@  discard block
 block discarded – undo
80 80
 			//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
81 81
 			$mainPluginFile = basename($this->pluginFile);
82 82
 			$remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
83
-			if ( !empty($remotePlugin) ) {
83
+			if (!empty($remotePlugin)) {
84 84
 				$remoteHeader = $this->getFileHeader($remotePlugin);
85 85
 				$this->setInfoFromHeader($remoteHeader, $info);
86 86
 			}
87 87
 
88 88
 			//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
89 89
 			//a lot of useful information like the required/tested WP version, changelog, and so on.
90
-			if ( $this->readmeTxtExistsLocally() ) {
90
+			if ($this->readmeTxtExistsLocally()) {
91 91
 				$this->setInfoFromRemoteReadme($ref, $info);
92 92
 			}
93 93
 
94 94
 			//The changelog might be in a separate file.
95
-			if ( empty($info->sections['changelog']) ) {
95
+			if (empty($info->sections['changelog'])) {
96 96
 				$info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
97
-				if ( empty($info->sections['changelog']) ) {
97
+				if (empty($info->sections['changelog'])) {
98 98
 					$info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
99 99
 				}
100 100
 			}
101 101
 
102
-			if ( empty($info->last_updated) ) {
102
+			if (empty($info->last_updated)) {
103 103
 				//Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date.
104 104
 				$latestCommitTime = $api->getLatestCommitTime($ref);
105
-				if ( $latestCommitTime !== null ) {
105
+				if ($latestCommitTime !== null) {
106 106
 					$info->last_updated = $latestCommitTime;
107 107
 				}
108 108
 			}
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		protected function readmeTxtExistsLocally() {
120 120
 			$pluginDirectory = $this->getAbsoluteDirectoryPath();
121
-			if ( empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
121
+			if (empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.')) {
122 122
 				return false;
123 123
 			}
124
-			return is_file($pluginDirectory . '/' . $this->api->getLocalReadmeName());
124
+			return is_file($pluginDirectory.'/'.$this->api->getLocalReadmeName());
125 125
 		}
126 126
 
127 127
 		/**
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
 				'Tested up to' => 'tested',
146 146
 			);
147 147
 			foreach ($headerToPropertyMap as $headerName => $property) {
148
-				if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
148
+				if (isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName])) {
149 149
 					$pluginInfo->$property = $fileHeader[$headerName];
150 150
 				}
151 151
 			}
152 152
 
153
-			if ( !empty($fileHeader['Description']) ) {
153
+			if (!empty($fileHeader['Description'])) {
154 154
 				$pluginInfo->sections['description'] = $fileHeader['Description'];
155 155
 			}
156 156
 		}
@@ -163,21 +163,21 @@  discard block
 block discarded – undo
163 163
 		 */
164 164
 		protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
165 165
 			$readme = $this->api->getRemoteReadme($ref);
166
-			if ( empty($readme) ) {
166
+			if (empty($readme)) {
167 167
 				return;
168 168
 			}
169 169
 
170
-			if ( isset($readme['sections']) ) {
170
+			if (isset($readme['sections'])) {
171 171
 				$pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
172 172
 			}
173
-			if ( !empty($readme['tested_up_to']) ) {
173
+			if (!empty($readme['tested_up_to'])) {
174 174
 				$pluginInfo->tested = $readme['tested_up_to'];
175 175
 			}
176
-			if ( !empty($readme['requires_at_least']) ) {
176
+			if (!empty($readme['requires_at_least'])) {
177 177
 				$pluginInfo->requires = $readme['requires_at_least'];
178 178
 			}
179 179
 
180
-			if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
180
+			if (isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version])) {
181 181
 				$pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
182 182
 			}
183 183
 		}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		public function getUpdate() {
200 200
 			$update = parent::getUpdate();
201 201
 
202
-			if ( isset($update) && !empty($update->download_url) ) {
202
+			if (isset($update) && !empty($update->download_url)) {
203 203
 				$update->download_url = $this->api->signDownloadUrl($update->download_url);
204 204
 			}
205 205
 
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/StateStore.php 2 patches
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -2,206 +2,206 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_StateStore', false) ):
4 4
 
5
-	class Puc_v4p4_StateStore {
6
-		/**
7
-		 * @var int Last update check timestamp.
8
-		 */
9
-		protected $lastCheck = 0;
10
-
11
-		/**
12
-		 * @var string Version number.
13
-		 */
14
-		protected $checkedVersion = '';
15
-
16
-		/**
17
-		 * @var Puc_v4p4_Update|null Cached update.
18
-		 */
19
-		protected $update = null;
20
-
21
-		/**
22
-		 * @var string Site option name.
23
-		 */
24
-		private $optionName = '';
25
-
26
-		/**
27
-		 * @var bool Whether we've already tried to load the state from the database.
28
-		 */
29
-		private $isLoaded = false;
30
-
31
-		public function __construct($optionName) {
32
-			$this->optionName = $optionName;
33
-		}
34
-
35
-		/**
36
-		 * Get time elapsed since the last update check.
37
-		 *
38
-		 * If there are no recorded update checks, this method returns a large arbitrary number
39
-		 * (i.e. time since the Unix epoch).
40
-		 *
41
-		 * @return int Elapsed time in seconds.
42
-		 */
43
-		public function timeSinceLastCheck() {
44
-			$this->lazyLoad();
45
-			return time() - $this->lastCheck;
46
-		}
47
-
48
-		/**
49
-		 * @return int
50
-		 */
51
-		public function getLastCheck() {
52
-			$this->lazyLoad();
53
-			return $this->lastCheck;
54
-		}
55
-
56
-		/**
57
-		 * Set the time of the last update check to the current timestamp.
58
-		 *
59
-		 * @return $this
60
-		 */
61
-		public function setLastCheckToNow() {
62
-			$this->lazyLoad();
63
-			$this->lastCheck = time();
64
-			return $this;
65
-		}
66
-
67
-		/**
68
-		 * @return null|Puc_v4p4_Update
69
-		 */
70
-		public function getUpdate() {
71
-			$this->lazyLoad();
72
-			return $this->update;
73
-		}
74
-
75
-		/**
76
-		 * @param Puc_v4p4_Update|null $update
77
-		 * @return $this
78
-		 */
79
-		public function setUpdate(Puc_v4p4_Update $update = null) {
80
-			$this->lazyLoad();
81
-			$this->update = $update;
82
-			return $this;
83
-		}
84
-
85
-		/**
86
-		 * @return string
87
-		 */
88
-		public function getCheckedVersion() {
89
-			$this->lazyLoad();
90
-			return $this->checkedVersion;
91
-		}
92
-
93
-		/**
94
-		 * @param string $version
95
-		 * @return $this
96
-		 */
97
-		public function setCheckedVersion($version) {
98
-			$this->lazyLoad();
99
-			$this->checkedVersion = strval($version);
100
-			return $this;
101
-		}
102
-
103
-		/**
104
-		 * Get translation updates.
105
-		 *
106
-		 * @return array
107
-		 */
108
-		public function getTranslations() {
109
-			$this->lazyLoad();
110
-			if ( isset($this->update, $this->update->translations) ) {
111
-				return $this->update->translations;
112
-			}
113
-			return array();
114
-		}
115
-
116
-		/**
117
-		 * Set translation updates.
118
-		 *
119
-		 * @param array $translationUpdates
120
-		 */
121
-		public function setTranslations($translationUpdates) {
122
-			$this->lazyLoad();
123
-			if ( isset($this->update) ) {
124
-				$this->update->translations = $translationUpdates;
125
-				$this->save();
126
-			}
127
-		}
128
-
129
-		public function save() {
130
-			$state = new stdClass();
131
-
132
-			$state->lastCheck = $this->lastCheck;
133
-			$state->checkedVersion = $this->checkedVersion;
134
-
135
-			if ( isset($this->update)) {
136
-				$state->update = $this->update->toStdClass();
137
-
138
-				$updateClass = get_class($this->update);
139
-				$state->updateClass = $updateClass;
140
-				$prefix = $this->getLibPrefix();
141
-				if ( Puc_v4p4_Utils::startsWith($updateClass, $prefix) ) {
142
-					$state->updateBaseClass = substr($updateClass, strlen($prefix));
143
-				}
144
-			}
145
-
146
-			update_site_option($this->optionName, $state);
147
-			$this->isLoaded = true;
148
-		}
149
-
150
-		/**
151
-		 * @return $this
152
-		 */
153
-		public function lazyLoad() {
154
-			if ( !$this->isLoaded ) {
155
-				$this->load();
156
-			}
157
-			return $this;
158
-		}
159
-
160
-		protected function load() {
161
-			$this->isLoaded = true;
162
-
163
-			$state = get_site_option($this->optionName, null);
164
-
165
-			if ( !is_object($state) ) {
166
-				$this->lastCheck = 0;
167
-				$this->checkedVersion = '';
168
-				$this->update = null;
169
-				return;
170
-			}
171
-
172
-			$this->lastCheck = intval(Puc_v4p4_Utils::get($state, 'lastCheck', 0));
173
-			$this->checkedVersion = Puc_v4p4_Utils::get($state, 'checkedVersion', '');
174
-			$this->update = null;
175
-
176
-			if ( isset($state->update) ) {
177
-				//This mess is due to the fact that the want the update class from this version
178
-				//of the library, not the version that saved the update.
179
-
180
-				$updateClass = null;
181
-				if ( isset($state->updateBaseClass) ) {
182
-					$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
183
-				} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
184
-					$updateClass = $state->updateClass;
185
-				}
186
-
187
-				if ( $updateClass !== null ) {
188
-					$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
189
-				}
190
-			}
191
-		}
192
-
193
-		public function delete() {
194
-			delete_site_option($this->optionName);
195
-
196
-			$this->lastCheck = 0;
197
-			$this->checkedVersion = '';
198
-			$this->update = null;
199
-		}
200
-
201
-		private function getLibPrefix() {
202
-			$parts = explode('_', __CLASS__, 3);
203
-			return $parts[0] . '_' . $parts[1] . '_';
204
-		}
205
-	}
5
+    class Puc_v4p4_StateStore {
6
+        /**
7
+         * @var int Last update check timestamp.
8
+         */
9
+        protected $lastCheck = 0;
10
+
11
+        /**
12
+         * @var string Version number.
13
+         */
14
+        protected $checkedVersion = '';
15
+
16
+        /**
17
+         * @var Puc_v4p4_Update|null Cached update.
18
+         */
19
+        protected $update = null;
20
+
21
+        /**
22
+         * @var string Site option name.
23
+         */
24
+        private $optionName = '';
25
+
26
+        /**
27
+         * @var bool Whether we've already tried to load the state from the database.
28
+         */
29
+        private $isLoaded = false;
30
+
31
+        public function __construct($optionName) {
32
+            $this->optionName = $optionName;
33
+        }
34
+
35
+        /**
36
+         * Get time elapsed since the last update check.
37
+         *
38
+         * If there are no recorded update checks, this method returns a large arbitrary number
39
+         * (i.e. time since the Unix epoch).
40
+         *
41
+         * @return int Elapsed time in seconds.
42
+         */
43
+        public function timeSinceLastCheck() {
44
+            $this->lazyLoad();
45
+            return time() - $this->lastCheck;
46
+        }
47
+
48
+        /**
49
+         * @return int
50
+         */
51
+        public function getLastCheck() {
52
+            $this->lazyLoad();
53
+            return $this->lastCheck;
54
+        }
55
+
56
+        /**
57
+         * Set the time of the last update check to the current timestamp.
58
+         *
59
+         * @return $this
60
+         */
61
+        public function setLastCheckToNow() {
62
+            $this->lazyLoad();
63
+            $this->lastCheck = time();
64
+            return $this;
65
+        }
66
+
67
+        /**
68
+         * @return null|Puc_v4p4_Update
69
+         */
70
+        public function getUpdate() {
71
+            $this->lazyLoad();
72
+            return $this->update;
73
+        }
74
+
75
+        /**
76
+         * @param Puc_v4p4_Update|null $update
77
+         * @return $this
78
+         */
79
+        public function setUpdate(Puc_v4p4_Update $update = null) {
80
+            $this->lazyLoad();
81
+            $this->update = $update;
82
+            return $this;
83
+        }
84
+
85
+        /**
86
+         * @return string
87
+         */
88
+        public function getCheckedVersion() {
89
+            $this->lazyLoad();
90
+            return $this->checkedVersion;
91
+        }
92
+
93
+        /**
94
+         * @param string $version
95
+         * @return $this
96
+         */
97
+        public function setCheckedVersion($version) {
98
+            $this->lazyLoad();
99
+            $this->checkedVersion = strval($version);
100
+            return $this;
101
+        }
102
+
103
+        /**
104
+         * Get translation updates.
105
+         *
106
+         * @return array
107
+         */
108
+        public function getTranslations() {
109
+            $this->lazyLoad();
110
+            if ( isset($this->update, $this->update->translations) ) {
111
+                return $this->update->translations;
112
+            }
113
+            return array();
114
+        }
115
+
116
+        /**
117
+         * Set translation updates.
118
+         *
119
+         * @param array $translationUpdates
120
+         */
121
+        public function setTranslations($translationUpdates) {
122
+            $this->lazyLoad();
123
+            if ( isset($this->update) ) {
124
+                $this->update->translations = $translationUpdates;
125
+                $this->save();
126
+            }
127
+        }
128
+
129
+        public function save() {
130
+            $state = new stdClass();
131
+
132
+            $state->lastCheck = $this->lastCheck;
133
+            $state->checkedVersion = $this->checkedVersion;
134
+
135
+            if ( isset($this->update)) {
136
+                $state->update = $this->update->toStdClass();
137
+
138
+                $updateClass = get_class($this->update);
139
+                $state->updateClass = $updateClass;
140
+                $prefix = $this->getLibPrefix();
141
+                if ( Puc_v4p4_Utils::startsWith($updateClass, $prefix) ) {
142
+                    $state->updateBaseClass = substr($updateClass, strlen($prefix));
143
+                }
144
+            }
145
+
146
+            update_site_option($this->optionName, $state);
147
+            $this->isLoaded = true;
148
+        }
149
+
150
+        /**
151
+         * @return $this
152
+         */
153
+        public function lazyLoad() {
154
+            if ( !$this->isLoaded ) {
155
+                $this->load();
156
+            }
157
+            return $this;
158
+        }
159
+
160
+        protected function load() {
161
+            $this->isLoaded = true;
162
+
163
+            $state = get_site_option($this->optionName, null);
164
+
165
+            if ( !is_object($state) ) {
166
+                $this->lastCheck = 0;
167
+                $this->checkedVersion = '';
168
+                $this->update = null;
169
+                return;
170
+            }
171
+
172
+            $this->lastCheck = intval(Puc_v4p4_Utils::get($state, 'lastCheck', 0));
173
+            $this->checkedVersion = Puc_v4p4_Utils::get($state, 'checkedVersion', '');
174
+            $this->update = null;
175
+
176
+            if ( isset($state->update) ) {
177
+                //This mess is due to the fact that the want the update class from this version
178
+                //of the library, not the version that saved the update.
179
+
180
+                $updateClass = null;
181
+                if ( isset($state->updateBaseClass) ) {
182
+                    $updateClass = $this->getLibPrefix() . $state->updateBaseClass;
183
+                } else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
184
+                    $updateClass = $state->updateClass;
185
+                }
186
+
187
+                if ( $updateClass !== null ) {
188
+                    $this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
189
+                }
190
+            }
191
+        }
192
+
193
+        public function delete() {
194
+            delete_site_option($this->optionName);
195
+
196
+            $this->lastCheck = 0;
197
+            $this->checkedVersion = '';
198
+            $this->update = null;
199
+        }
200
+
201
+        private function getLibPrefix() {
202
+            $parts = explode('_', __CLASS__, 3);
203
+            return $parts[0] . '_' . $parts[1] . '_';
204
+        }
205
+    }
206 206
 
207 207
 endif;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( !class_exists('Puc_v4p4_StateStore', false) ):
3
+if (!class_exists('Puc_v4p4_StateStore', false)):
4 4
 
5 5
 	class Puc_v4p4_StateStore {
6 6
 		/**
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		 */
108 108
 		public function getTranslations() {
109 109
 			$this->lazyLoad();
110
-			if ( isset($this->update, $this->update->translations) ) {
110
+			if (isset($this->update, $this->update->translations)) {
111 111
 				return $this->update->translations;
112 112
 			}
113 113
 			return array();
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		 */
121 121
 		public function setTranslations($translationUpdates) {
122 122
 			$this->lazyLoad();
123
-			if ( isset($this->update) ) {
123
+			if (isset($this->update)) {
124 124
 				$this->update->translations = $translationUpdates;
125 125
 				$this->save();
126 126
 			}
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
 			$state->lastCheck = $this->lastCheck;
133 133
 			$state->checkedVersion = $this->checkedVersion;
134 134
 
135
-			if ( isset($this->update)) {
135
+			if (isset($this->update)) {
136 136
 				$state->update = $this->update->toStdClass();
137 137
 
138 138
 				$updateClass = get_class($this->update);
139 139
 				$state->updateClass = $updateClass;
140 140
 				$prefix = $this->getLibPrefix();
141
-				if ( Puc_v4p4_Utils::startsWith($updateClass, $prefix) ) {
141
+				if (Puc_v4p4_Utils::startsWith($updateClass, $prefix)) {
142 142
 					$state->updateBaseClass = substr($updateClass, strlen($prefix));
143 143
 				}
144 144
 			}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		 * @return $this
152 152
 		 */
153 153
 		public function lazyLoad() {
154
-			if ( !$this->isLoaded ) {
154
+			if (!$this->isLoaded) {
155 155
 				$this->load();
156 156
 			}
157 157
 			return $this;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 
163 163
 			$state = get_site_option($this->optionName, null);
164 164
 
165
-			if ( !is_object($state) ) {
165
+			if (!is_object($state)) {
166 166
 				$this->lastCheck = 0;
167 167
 				$this->checkedVersion = '';
168 168
 				$this->update = null;
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
 			$this->checkedVersion = Puc_v4p4_Utils::get($state, 'checkedVersion', '');
174 174
 			$this->update = null;
175 175
 
176
-			if ( isset($state->update) ) {
176
+			if (isset($state->update)) {
177 177
 				//This mess is due to the fact that the want the update class from this version
178 178
 				//of the library, not the version that saved the update.
179 179
 
180 180
 				$updateClass = null;
181
-				if ( isset($state->updateBaseClass) ) {
182
-					$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
183
-				} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
181
+				if (isset($state->updateBaseClass)) {
182
+					$updateClass = $this->getLibPrefix().$state->updateBaseClass;
183
+				} else if (isset($state->updateClass) && class_exists($state->updateClass)) {
184 184
 					$updateClass = $state->updateClass;
185 185
 				}
186 186
 
187
-				if ( $updateClass !== null ) {
187
+				if ($updateClass !== null) {
188 188
 					$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
189 189
 				}
190 190
 			}
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 
201 201
 		private function getLibPrefix() {
202 202
 			$parts = explode('_', __CLASS__, 3);
203
-			return $parts[0] . '_' . $parts[1] . '_';
203
+			return $parts[0].'_'.$parts[1].'_';
204 204
 		}
205 205
 	}
206 206
 
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/OAuthSignature.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -2,87 +2,87 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
4 4
 
5
-	/**
6
-	 * A basic signature generator for zero-legged OAuth 1.0.
7
-	 */
8
-	class Puc_v4p4_OAuthSignature {
9
-		private $consumerKey = '';
10
-		private $consumerSecret = '';
5
+    /**
6
+     * A basic signature generator for zero-legged OAuth 1.0.
7
+     */
8
+    class Puc_v4p4_OAuthSignature {
9
+        private $consumerKey = '';
10
+        private $consumerSecret = '';
11 11
 
12
-		public function __construct($consumerKey, $consumerSecret) {
13
-			$this->consumerKey = $consumerKey;
14
-			$this->consumerSecret = $consumerSecret;
15
-		}
12
+        public function __construct($consumerKey, $consumerSecret) {
13
+            $this->consumerKey = $consumerKey;
14
+            $this->consumerSecret = $consumerSecret;
15
+        }
16 16
 
17
-		/**
18
-		 * Sign a URL using OAuth 1.0.
19
-		 *
20
-		 * @param string $url The URL to be signed. It may contain query parameters.
21
-		 * @param string $method HTTP method such as "GET", "POST" and so on.
22
-		 * @return string The signed URL.
23
-		 */
24
-		public function sign($url, $method = 'GET') {
25
-			$parameters = array();
17
+        /**
18
+         * Sign a URL using OAuth 1.0.
19
+         *
20
+         * @param string $url The URL to be signed. It may contain query parameters.
21
+         * @param string $method HTTP method such as "GET", "POST" and so on.
22
+         * @return string The signed URL.
23
+         */
24
+        public function sign($url, $method = 'GET') {
25
+            $parameters = array();
26 26
 
27
-			//Parse query parameters.
28
-			$query = @parse_url($url, PHP_URL_QUERY);
29
-			if ( !empty($query) ) {
30
-				parse_str($query, $parsedParams);
31
-				if ( is_array($parameters) ) {
32
-					$parameters = $parsedParams;
33
-				}
34
-				//Remove the query string from the URL. We'll replace it later.
35
-				$url = substr($url, 0, strpos($url, '?'));
36
-			}
27
+            //Parse query parameters.
28
+            $query = @parse_url($url, PHP_URL_QUERY);
29
+            if ( !empty($query) ) {
30
+                parse_str($query, $parsedParams);
31
+                if ( is_array($parameters) ) {
32
+                    $parameters = $parsedParams;
33
+                }
34
+                //Remove the query string from the URL. We'll replace it later.
35
+                $url = substr($url, 0, strpos($url, '?'));
36
+            }
37 37
 
38
-			$parameters = array_merge(
39
-				$parameters,
40
-				array(
41
-					'oauth_consumer_key' => $this->consumerKey,
42
-					'oauth_nonce' => $this->nonce(),
43
-					'oauth_signature_method' => 'HMAC-SHA1',
44
-					'oauth_timestamp' => time(),
45
-					'oauth_version' => '1.0',
46
-				)
47
-			);
48
-			unset($parameters['oauth_signature']);
38
+            $parameters = array_merge(
39
+                $parameters,
40
+                array(
41
+                    'oauth_consumer_key' => $this->consumerKey,
42
+                    'oauth_nonce' => $this->nonce(),
43
+                    'oauth_signature_method' => 'HMAC-SHA1',
44
+                    'oauth_timestamp' => time(),
45
+                    'oauth_version' => '1.0',
46
+                )
47
+            );
48
+            unset($parameters['oauth_signature']);
49 49
 
50
-			//Parameters must be sorted alphabetically before signing.
51
-			ksort($parameters);
50
+            //Parameters must be sorted alphabetically before signing.
51
+            ksort($parameters);
52 52
 
53
-			//The most complicated part of the request - generating the signature.
54
-			//The string to sign contains the HTTP method, the URL path, and all of
55
-			//our query parameters. Everything is URL encoded. Then we concatenate
56
-			//them with ampersands into a single string to hash.
57
-			$encodedVerb = urlencode($method);
58
-			$encodedUrl = urlencode($url);
59
-			$encodedParams = urlencode(http_build_query($parameters, '', '&'));
53
+            //The most complicated part of the request - generating the signature.
54
+            //The string to sign contains the HTTP method, the URL path, and all of
55
+            //our query parameters. Everything is URL encoded. Then we concatenate
56
+            //them with ampersands into a single string to hash.
57
+            $encodedVerb = urlencode($method);
58
+            $encodedUrl = urlencode($url);
59
+            $encodedParams = urlencode(http_build_query($parameters, '', '&'));
60 60
 
61
-			$stringToSign = $encodedVerb . '&' . $encodedUrl . '&' . $encodedParams;
61
+            $stringToSign = $encodedVerb . '&' . $encodedUrl . '&' . $encodedParams;
62 62
 
63
-			//Since we only have one OAuth token (the consumer secret) we only have
64
-			//to use it as our HMAC key. However, we still have to append an & to it
65
-			//as if we were using it with additional tokens.
66
-			$secret = urlencode($this->consumerSecret) . '&';
63
+            //Since we only have one OAuth token (the consumer secret) we only have
64
+            //to use it as our HMAC key. However, we still have to append an & to it
65
+            //as if we were using it with additional tokens.
66
+            $secret = urlencode($this->consumerSecret) . '&';
67 67
 
68
-			//The signature is a hash of the consumer key and the base string. Note
69
-			//that we have to get the raw output from hash_hmac and base64 encode
70
-			//the binary data result.
71
-			$parameters['oauth_signature'] = base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
68
+            //The signature is a hash of the consumer key and the base string. Note
69
+            //that we have to get the raw output from hash_hmac and base64 encode
70
+            //the binary data result.
71
+            $parameters['oauth_signature'] = base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
72 72
 
73
-			return ($url . '?' . http_build_query($parameters));
74
-		}
73
+            return ($url . '?' . http_build_query($parameters));
74
+        }
75 75
 
76
-		/**
77
-		 * Generate a random nonce.
78
-		 *
79
-		 * @return string
80
-		 */
81
-		private function nonce() {
82
-			$mt = microtime();
83
-			$rand = mt_rand();
84
-			return md5($mt . '_' . $rand);
85
-		}
86
-	}
76
+        /**
77
+         * Generate a random nonce.
78
+         *
79
+         * @return string
80
+         */
81
+        private function nonce() {
82
+            $mt = microtime();
83
+            $rand = mt_rand();
84
+            return md5($mt . '_' . $rand);
85
+        }
86
+    }
87 87
 
88 88
 endif;
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
3
+if (!class_exists('Puc_v4p4_OAuthSignature', false)):
4 4
 
5 5
 	/**
6 6
 	 * A basic signature generator for zero-legged OAuth 1.0.
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
 
27 27
 			//Parse query parameters.
28 28
 			$query = @parse_url($url, PHP_URL_QUERY);
29
-			if ( !empty($query) ) {
29
+			if (!empty($query)) {
30 30
 				parse_str($query, $parsedParams);
31
-				if ( is_array($parameters) ) {
31
+				if (is_array($parameters)) {
32 32
 					$parameters = $parsedParams;
33 33
 				}
34 34
 				//Remove the query string from the URL. We'll replace it later.
@@ -58,19 +58,19 @@  discard block
 block discarded – undo
58 58
 			$encodedUrl = urlencode($url);
59 59
 			$encodedParams = urlencode(http_build_query($parameters, '', '&'));
60 60
 
61
-			$stringToSign = $encodedVerb . '&' . $encodedUrl . '&' . $encodedParams;
61
+			$stringToSign = $encodedVerb.'&'.$encodedUrl.'&'.$encodedParams;
62 62
 
63 63
 			//Since we only have one OAuth token (the consumer secret) we only have
64 64
 			//to use it as our HMAC key. However, we still have to append an & to it
65 65
 			//as if we were using it with additional tokens.
66
-			$secret = urlencode($this->consumerSecret) . '&';
66
+			$secret = urlencode($this->consumerSecret).'&';
67 67
 
68 68
 			//The signature is a hash of the consumer key and the base string. Note
69 69
 			//that we have to get the raw output from hash_hmac and base64 encode
70 70
 			//the binary data result.
71 71
 			$parameters['oauth_signature'] = base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
72 72
 
73
-			return ($url . '?' . http_build_query($parameters));
73
+			return ($url.'?'.http_build_query($parameters));
74 74
 		}
75 75
 
76 76
 		/**
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		private function nonce() {
82 82
 			$mt = microtime();
83 83
 			$rand = mt_rand();
84
-			return md5($mt . '_' . $rand);
84
+			return md5($mt.'_'.$rand);
85 85
 		}
86 86
 	}
87 87
 
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Metadata.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -1,132 +1,132 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_Metadata', false) ):
3 3
 
4
-	/**
5
-	 * A base container for holding information about updates and plugin metadata.
6
-	 *
7
-	 * @author Janis Elsts
8
-	 * @copyright 2016
9
-	 * @access public
10
-	 */
11
-	abstract class Puc_v4p4_Metadata {
12
-
13
-		/**
14
-		 * Create an instance of this class from a JSON document.
15
-		 *
16
-		 * @abstract
17
-		 * @param string $json
18
-		 * @return self
19
-		 */
20
-		public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
21
-			throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
22
-		}
23
-
24
-		/**
25
-		 * @param string $json
26
-		 * @param self $target
27
-		 * @return bool
28
-		 */
29
-		protected static function createFromJson($json, $target) {
30
-			/** @var StdClass $apiResponse */
31
-			$apiResponse = json_decode($json);
32
-			if ( empty($apiResponse) || !is_object($apiResponse) ){
33
-				$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
34
-				do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
35
-				trigger_error($errorMessage, E_USER_NOTICE);
36
-				return false;
37
-			}
38
-
39
-			$valid = $target->validateMetadata($apiResponse);
40
-			if ( is_wp_error($valid) ){
41
-				do_action('puc_api_error', $valid);
42
-				trigger_error($valid->get_error_message(), E_USER_NOTICE);
43
-				return false;
44
-			}
45
-
46
-			foreach(get_object_vars($apiResponse) as $key => $value){
47
-				$target->$key = $value;
48
-			}
49
-
50
-			return true;
51
-		}
52
-
53
-		/**
54
-		 * No validation by default! Subclasses should check that the required fields are present.
55
-		 *
56
-		 * @param StdClass $apiResponse
57
-		 * @return bool|WP_Error
58
-		 */
59
-		protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
60
-			return true;
61
-		}
62
-
63
-		/**
64
-		 * Create a new instance by copying the necessary fields from another object.
65
-		 *
66
-		 * @abstract
67
-		 * @param StdClass|self $object The source object.
68
-		 * @return self The new copy.
69
-		 */
70
-		public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
71
-			throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
72
-		}
73
-
74
-		/**
75
-		 * Create an instance of StdClass that can later be converted back to an
76
-		 * update or info container. Useful for serialization and caching, as it
77
-		 * avoids the "incomplete object" problem if the cached value is loaded
78
-		 * before this class.
79
-		 *
80
-		 * @return StdClass
81
-		 */
82
-		public function toStdClass() {
83
-			$object = new stdClass();
84
-			$this->copyFields($this, $object);
85
-			return $object;
86
-		}
87
-
88
-		/**
89
-		 * Transform the metadata into the format used by WordPress core.
90
-		 *
91
-		 * @return object
92
-		 */
93
-		abstract public function toWpFormat();
94
-
95
-		/**
96
-		 * Copy known fields from one object to another.
97
-		 *
98
-		 * @param StdClass|self $from
99
-		 * @param StdClass|self $to
100
-		 */
101
-		protected function copyFields($from, $to) {
102
-			$fields = $this->getFieldNames();
103
-
104
-			if ( property_exists($from, 'slug') && !empty($from->slug) ) {
105
-				//Let plugins add extra fields without having to create subclasses.
106
-				$fields = apply_filters($this->getPrefixedFilter('retain_fields') . '-' . $from->slug, $fields);
107
-			}
108
-
109
-			foreach ($fields as $field) {
110
-				if ( property_exists($from, $field) ) {
111
-					$to->$field = $from->$field;
112
-				}
113
-			}
114
-		}
115
-
116
-		/**
117
-		 * @return string[]
118
-		 */
119
-		protected function getFieldNames() {
120
-			return array();
121
-		}
122
-
123
-		/**
124
-		 * @param string $tag
125
-		 * @return string
126
-		 */
127
-		protected function getPrefixedFilter($tag) {
128
-			return 'puc_' . $tag;
129
-		}
130
-	}
4
+    /**
5
+     * A base container for holding information about updates and plugin metadata.
6
+     *
7
+     * @author Janis Elsts
8
+     * @copyright 2016
9
+     * @access public
10
+     */
11
+    abstract class Puc_v4p4_Metadata {
12
+
13
+        /**
14
+         * Create an instance of this class from a JSON document.
15
+         *
16
+         * @abstract
17
+         * @param string $json
18
+         * @return self
19
+         */
20
+        public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
21
+            throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
22
+        }
23
+
24
+        /**
25
+         * @param string $json
26
+         * @param self $target
27
+         * @return bool
28
+         */
29
+        protected static function createFromJson($json, $target) {
30
+            /** @var StdClass $apiResponse */
31
+            $apiResponse = json_decode($json);
32
+            if ( empty($apiResponse) || !is_object($apiResponse) ){
33
+                $errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
34
+                do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
35
+                trigger_error($errorMessage, E_USER_NOTICE);
36
+                return false;
37
+            }
38
+
39
+            $valid = $target->validateMetadata($apiResponse);
40
+            if ( is_wp_error($valid) ){
41
+                do_action('puc_api_error', $valid);
42
+                trigger_error($valid->get_error_message(), E_USER_NOTICE);
43
+                return false;
44
+            }
45
+
46
+            foreach(get_object_vars($apiResponse) as $key => $value){
47
+                $target->$key = $value;
48
+            }
49
+
50
+            return true;
51
+        }
52
+
53
+        /**
54
+         * No validation by default! Subclasses should check that the required fields are present.
55
+         *
56
+         * @param StdClass $apiResponse
57
+         * @return bool|WP_Error
58
+         */
59
+        protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
60
+            return true;
61
+        }
62
+
63
+        /**
64
+         * Create a new instance by copying the necessary fields from another object.
65
+         *
66
+         * @abstract
67
+         * @param StdClass|self $object The source object.
68
+         * @return self The new copy.
69
+         */
70
+        public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
71
+            throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
72
+        }
73
+
74
+        /**
75
+         * Create an instance of StdClass that can later be converted back to an
76
+         * update or info container. Useful for serialization and caching, as it
77
+         * avoids the "incomplete object" problem if the cached value is loaded
78
+         * before this class.
79
+         *
80
+         * @return StdClass
81
+         */
82
+        public function toStdClass() {
83
+            $object = new stdClass();
84
+            $this->copyFields($this, $object);
85
+            return $object;
86
+        }
87
+
88
+        /**
89
+         * Transform the metadata into the format used by WordPress core.
90
+         *
91
+         * @return object
92
+         */
93
+        abstract public function toWpFormat();
94
+
95
+        /**
96
+         * Copy known fields from one object to another.
97
+         *
98
+         * @param StdClass|self $from
99
+         * @param StdClass|self $to
100
+         */
101
+        protected function copyFields($from, $to) {
102
+            $fields = $this->getFieldNames();
103
+
104
+            if ( property_exists($from, 'slug') && !empty($from->slug) ) {
105
+                //Let plugins add extra fields without having to create subclasses.
106
+                $fields = apply_filters($this->getPrefixedFilter('retain_fields') . '-' . $from->slug, $fields);
107
+            }
108
+
109
+            foreach ($fields as $field) {
110
+                if ( property_exists($from, $field) ) {
111
+                    $to->$field = $from->$field;
112
+                }
113
+            }
114
+        }
115
+
116
+        /**
117
+         * @return string[]
118
+         */
119
+        protected function getFieldNames() {
120
+            return array();
121
+        }
122
+
123
+        /**
124
+         * @param string $tag
125
+         * @return string
126
+         */
127
+        protected function getPrefixedFilter($tag) {
128
+            return 'puc_' . $tag;
129
+        }
130
+    }
131 131
 
132 132
 endif;
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !class_exists('Puc_v4p4_Metadata', false) ):
2
+if (!class_exists('Puc_v4p4_Metadata', false)):
3 3
 
4 4
 	/**
5 5
 	 * A base container for holding information about updates and plugin metadata.
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		 * @return self
19 19
 		 */
20 20
 		public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
21
-			throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
21
+			throw new LogicException('The '.__METHOD__.' method must be implemented by subclasses');
22 22
 		}
23 23
 
24 24
 		/**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		protected static function createFromJson($json, $target) {
30 30
 			/** @var StdClass $apiResponse */
31 31
 			$apiResponse = json_decode($json);
32
-			if ( empty($apiResponse) || !is_object($apiResponse) ){
32
+			if (empty($apiResponse) || !is_object($apiResponse)) {
33 33
 				$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
34 34
 				do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
35 35
 				trigger_error($errorMessage, E_USER_NOTICE);
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
 			}
38 38
 
39 39
 			$valid = $target->validateMetadata($apiResponse);
40
-			if ( is_wp_error($valid) ){
40
+			if (is_wp_error($valid)) {
41 41
 				do_action('puc_api_error', $valid);
42 42
 				trigger_error($valid->get_error_message(), E_USER_NOTICE);
43 43
 				return false;
44 44
 			}
45 45
 
46
-			foreach(get_object_vars($apiResponse) as $key => $value){
46
+			foreach (get_object_vars($apiResponse) as $key => $value) {
47 47
 				$target->$key = $value;
48 48
 			}
49 49
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 * @return self The new copy.
69 69
 		 */
70 70
 		public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
71
-			throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
71
+			throw new LogicException('The '.__METHOD__.' method must be implemented by subclasses');
72 72
 		}
73 73
 
74 74
 		/**
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 		protected function copyFields($from, $to) {
102 102
 			$fields = $this->getFieldNames();
103 103
 
104
-			if ( property_exists($from, 'slug') && !empty($from->slug) ) {
104
+			if (property_exists($from, 'slug') && !empty($from->slug)) {
105 105
 				//Let plugins add extra fields without having to create subclasses.
106
-				$fields = apply_filters($this->getPrefixedFilter('retain_fields') . '-' . $from->slug, $fields);
106
+				$fields = apply_filters($this->getPrefixedFilter('retain_fields').'-'.$from->slug, $fields);
107 107
 			}
108 108
 
109 109
 			foreach ($fields as $field) {
110
-				if ( property_exists($from, $field) ) {
110
+				if (property_exists($from, $field)) {
111 111
 					$to->$field = $from->$field;
112 112
 				}
113 113
 			}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * @return string
126 126
 		 */
127 127
 		protected function getPrefixedFilter($tag) {
128
-			return 'puc_' . $tag;
128
+			return 'puc_'.$tag;
129 129
 		}
130 130
 	}
131 131
 
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Update.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,34 +1,34 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_Update', false) ):
3 3
 
4
-	/**
5
-	 * A simple container class for holding information about an available update.
6
-	 *
7
-	 * @author Janis Elsts
8
-	 * @access public
9
-	 */
10
-	abstract class Puc_v4p4_Update extends Puc_v4p4_Metadata {
11
-		public $slug;
12
-		public $version;
13
-		public $download_url;
14
-		public $translations = array();
4
+    /**
5
+     * A simple container class for holding information about an available update.
6
+     *
7
+     * @author Janis Elsts
8
+     * @access public
9
+     */
10
+    abstract class Puc_v4p4_Update extends Puc_v4p4_Metadata {
11
+        public $slug;
12
+        public $version;
13
+        public $download_url;
14
+        public $translations = array();
15 15
 
16
-		/**
17
-		 * @return string[]
18
-		 */
19
-		protected function getFieldNames() {
20
-			return array('slug', 'version', 'download_url', 'translations');
21
-		}
16
+        /**
17
+         * @return string[]
18
+         */
19
+        protected function getFieldNames() {
20
+            return array('slug', 'version', 'download_url', 'translations');
21
+        }
22 22
 
23
-		public function toWpFormat() {
24
-			$update = new stdClass();
23
+        public function toWpFormat() {
24
+            $update = new stdClass();
25 25
 
26
-			$update->slug = $this->slug;
27
-			$update->new_version = $this->version;
28
-			$update->package = $this->download_url;
26
+            $update->slug = $this->slug;
27
+            $update->new_version = $this->version;
28
+            $update->package = $this->download_url;
29 29
 
30
-			return $update;
31
-		}
32
-	}
30
+            return $update;
31
+        }
32
+    }
33 33
 
34 34
 endif;
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-if ( !class_exists('Puc_v4p4_Update', false) ):
2
+if (!class_exists('Puc_v4p4_Update', false)):
3 3
 
4 4
 	/**
5 5
 	 * A simple container class for holding information about an available update.
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Factory.php 2 patches
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,292 +1,292 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_Factory', false) ):
3 3
 
4
-	/**
5
-	 * A factory that builds update checker instances.
6
-	 *
7
-	 * When multiple versions of the same class have been loaded (e.g. PluginUpdateChecker 4.0
8
-	 * and 4.1), this factory will always use the latest available minor version. Register class
9
-	 * versions by calling {@link PucFactory::addVersion()}.
10
-	 *
11
-	 * At the moment it can only build instances of the UpdateChecker class. Other classes are
12
-	 * intended mainly for internal use and refer directly to specific implementations.
13
-	 */
14
-	class Puc_v4p4_Factory {
15
-		protected static $classVersions = array();
16
-		protected static $sorted = false;
4
+    /**
5
+     * A factory that builds update checker instances.
6
+     *
7
+     * When multiple versions of the same class have been loaded (e.g. PluginUpdateChecker 4.0
8
+     * and 4.1), this factory will always use the latest available minor version. Register class
9
+     * versions by calling {@link PucFactory::addVersion()}.
10
+     *
11
+     * At the moment it can only build instances of the UpdateChecker class. Other classes are
12
+     * intended mainly for internal use and refer directly to specific implementations.
13
+     */
14
+    class Puc_v4p4_Factory {
15
+        protected static $classVersions = array();
16
+        protected static $sorted = false;
17 17
 
18
-		protected static $myMajorVersion = '';
19
-		protected static $latestCompatibleVersion = '';
18
+        protected static $myMajorVersion = '';
19
+        protected static $latestCompatibleVersion = '';
20 20
 
21
-		/**
22
-		 * Create a new instance of the update checker.
23
-		 *
24
-		 * This method automatically detects if you're using it for a plugin or a theme and chooses
25
-		 * the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
26
-		 *
27
-		 * @see Puc_v4p4_UpdateChecker::__construct
28
-		 *
29
-		 * @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
30
-		 * @param string $fullPath Full path to the main plugin file or to the theme directory.
31
-		 * @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
32
-		 * @param int $checkPeriod How often to check for updates (in hours).
33
-		 * @param string $optionName Where to store book-keeping info about update checks.
34
-		 * @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
35
-		 * @return Puc_v4p4_Plugin_UpdateChecker|Puc_v4p4_Theme_UpdateChecker|Puc_v4p4_Vcs_BaseChecker
36
-		 */
37
-		public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
38
-			$fullPath = self::normalizePath($fullPath);
39
-			$id = null;
21
+        /**
22
+         * Create a new instance of the update checker.
23
+         *
24
+         * This method automatically detects if you're using it for a plugin or a theme and chooses
25
+         * the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
26
+         *
27
+         * @see Puc_v4p4_UpdateChecker::__construct
28
+         *
29
+         * @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
30
+         * @param string $fullPath Full path to the main plugin file or to the theme directory.
31
+         * @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
32
+         * @param int $checkPeriod How often to check for updates (in hours).
33
+         * @param string $optionName Where to store book-keeping info about update checks.
34
+         * @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
35
+         * @return Puc_v4p4_Plugin_UpdateChecker|Puc_v4p4_Theme_UpdateChecker|Puc_v4p4_Vcs_BaseChecker
36
+         */
37
+        public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
38
+            $fullPath = self::normalizePath($fullPath);
39
+            $id = null;
40 40
 
41
-			//Plugin or theme?
42
-			$themeDirectory = self::getThemeDirectoryName($fullPath);
43
-			if ( self::isPluginFile($fullPath) ) {
44
-				$type = 'Plugin';
45
-				$id = $fullPath;
46
-			} else if ( $themeDirectory !== null ) {
47
-				$type = 'Theme';
48
-				$id = $themeDirectory;
49
-			} else {
50
-				throw new RuntimeException(sprintf(
51
-					'The update checker cannot determine if "%s" is a plugin or a theme. ' .
52
-					'This is a bug. Please contact the PUC developer.',
53
-					htmlentities($fullPath)
54
-				));
55
-			}
41
+            //Plugin or theme?
42
+            $themeDirectory = self::getThemeDirectoryName($fullPath);
43
+            if ( self::isPluginFile($fullPath) ) {
44
+                $type = 'Plugin';
45
+                $id = $fullPath;
46
+            } else if ( $themeDirectory !== null ) {
47
+                $type = 'Theme';
48
+                $id = $themeDirectory;
49
+            } else {
50
+                throw new RuntimeException(sprintf(
51
+                    'The update checker cannot determine if "%s" is a plugin or a theme. ' .
52
+                    'This is a bug. Please contact the PUC developer.',
53
+                    htmlentities($fullPath)
54
+                ));
55
+            }
56 56
 
57
-			//Which hosting service does the URL point to?
58
-			$service = self::getVcsService($metadataUrl);
57
+            //Which hosting service does the URL point to?
58
+            $service = self::getVcsService($metadataUrl);
59 59
 
60
-			$apiClass = null;
61
-			if ( empty($service) ) {
62
-				//The default is to get update information from a remote JSON file.
63
-				$checkerClass = $type . '_UpdateChecker';
64
-			} else {
65
-				//You can also use a VCS repository like GitHub.
66
-				$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
67
-				$apiClass = $service . 'Api';
68
-			}
60
+            $apiClass = null;
61
+            if ( empty($service) ) {
62
+                //The default is to get update information from a remote JSON file.
63
+                $checkerClass = $type . '_UpdateChecker';
64
+            } else {
65
+                //You can also use a VCS repository like GitHub.
66
+                $checkerClass = 'Vcs_' . $type . 'UpdateChecker';
67
+                $apiClass = $service . 'Api';
68
+            }
69 69
 
70
-			$checkerClass = self::getCompatibleClassVersion($checkerClass);
71
-			if ( $checkerClass === null ) {
72
-				trigger_error(
73
-					sprintf(
74
-						'PUC %s does not support updates for %ss %s',
75
-						htmlentities(self::$latestCompatibleVersion),
76
-						strtolower($type),
77
-						$service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
78
-					),
79
-					E_USER_ERROR
80
-				);
81
-				return null;
82
-			}
70
+            $checkerClass = self::getCompatibleClassVersion($checkerClass);
71
+            if ( $checkerClass === null ) {
72
+                trigger_error(
73
+                    sprintf(
74
+                        'PUC %s does not support updates for %ss %s',
75
+                        htmlentities(self::$latestCompatibleVersion),
76
+                        strtolower($type),
77
+                        $service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
78
+                    ),
79
+                    E_USER_ERROR
80
+                );
81
+                return null;
82
+            }
83 83
       
84
-			if ( !isset($apiClass) ) {
85
-				//Plain old update checker.
86
-				return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
87
-			} else {
88
-				//VCS checker + an API client.
89
-				$apiClass = self::getCompatibleClassVersion($apiClass);
90
-				if ( $apiClass === null ) {
91
-					trigger_error(sprintf(
92
-						'PUC %s does not support %s',
93
-						htmlentities(self::$latestCompatibleVersion),
94
-						htmlentities($service)
95
-					), E_USER_ERROR);
96
-					return null;
97
-				}
84
+            if ( !isset($apiClass) ) {
85
+                //Plain old update checker.
86
+                return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
87
+            } else {
88
+                //VCS checker + an API client.
89
+                $apiClass = self::getCompatibleClassVersion($apiClass);
90
+                if ( $apiClass === null ) {
91
+                    trigger_error(sprintf(
92
+                        'PUC %s does not support %s',
93
+                        htmlentities(self::$latestCompatibleVersion),
94
+                        htmlentities($service)
95
+                    ), E_USER_ERROR);
96
+                    return null;
97
+                }
98 98
 
99
-				return new $checkerClass(
100
-					new $apiClass($metadataUrl),
101
-					$id,
102
-					$slug,
103
-					$checkPeriod,
104
-					$optionName,
105
-					$muPluginFile
106
-				);
107
-			}
108
-		}
99
+                return new $checkerClass(
100
+                    new $apiClass($metadataUrl),
101
+                    $id,
102
+                    $slug,
103
+                    $checkPeriod,
104
+                    $optionName,
105
+                    $muPluginFile
106
+                );
107
+            }
108
+        }
109 109
 
110
-		/**
111
-		 *
112
-		 * Normalize a filesystem path. Introduced in WP 3.9.
113
-		 * Copying here allows use of the class on earlier versions.
114
-		 * This version adapted from WP 4.8.2 (unchanged since 4.5.0)
115
-		 *
116
-		 * @param string $path Path to normalize.
117
-		 * @return string Normalized path.
118
-		 */
119
-		public static function normalizePath($path) {
120
-			if ( function_exists('wp_normalize_path') ) {
121
-				return wp_normalize_path($path);
122
-			}
123
-			$path = str_replace('\\', '/', $path);
124
-			$path = preg_replace('|(?<=.)/+|', '/', $path);
125
-			if ( substr($path, 1, 1) === ':' ) {
126
-				$path = ucfirst($path);
127
-			}
128
-			return $path;
129
-		}
110
+        /**
111
+         *
112
+         * Normalize a filesystem path. Introduced in WP 3.9.
113
+         * Copying here allows use of the class on earlier versions.
114
+         * This version adapted from WP 4.8.2 (unchanged since 4.5.0)
115
+         *
116
+         * @param string $path Path to normalize.
117
+         * @return string Normalized path.
118
+         */
119
+        public static function normalizePath($path) {
120
+            if ( function_exists('wp_normalize_path') ) {
121
+                return wp_normalize_path($path);
122
+            }
123
+            $path = str_replace('\\', '/', $path);
124
+            $path = preg_replace('|(?<=.)/+|', '/', $path);
125
+            if ( substr($path, 1, 1) === ':' ) {
126
+                $path = ucfirst($path);
127
+            }
128
+            return $path;
129
+        }
130 130
 		
131
-		/**
132
-		 * Check if the path points to a plugin file.
133
-		 *
134
-		 * @param string $absolutePath Normalized path.
135
-		 * @return bool
136
-		 */
137
-		protected static function isPluginFile($absolutePath) {
138
-			//Is the file inside the "plugins" or "mu-plugins" directory?
139
-			$pluginDir = self::normalizePath(WP_PLUGIN_DIR);
140
-			$muPluginDir = self::normalizePath(WPMU_PLUGIN_DIR);
141
-			if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
142
-				return true;
143
-			}
131
+        /**
132
+         * Check if the path points to a plugin file.
133
+         *
134
+         * @param string $absolutePath Normalized path.
135
+         * @return bool
136
+         */
137
+        protected static function isPluginFile($absolutePath) {
138
+            //Is the file inside the "plugins" or "mu-plugins" directory?
139
+            $pluginDir = self::normalizePath(WP_PLUGIN_DIR);
140
+            $muPluginDir = self::normalizePath(WPMU_PLUGIN_DIR);
141
+            if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
142
+                return true;
143
+            }
144 144
 
145
-			//Is it a file at all? Caution: is_file() can fail if the parent dir. doesn't have the +x permission set.
146
-			if ( !is_file($absolutePath) ) {
147
-				return false;
148
-			}
145
+            //Is it a file at all? Caution: is_file() can fail if the parent dir. doesn't have the +x permission set.
146
+            if ( !is_file($absolutePath) ) {
147
+                return false;
148
+            }
149 149
 
150
-			//Does it have a valid plugin header?
151
-			//This is a last-ditch check for plugins symlinked from outside the WP root.
152
-			if ( function_exists('get_file_data') ) {
153
-				$headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
154
-				return !empty($headers['Name']);
155
-			}
150
+            //Does it have a valid plugin header?
151
+            //This is a last-ditch check for plugins symlinked from outside the WP root.
152
+            if ( function_exists('get_file_data') ) {
153
+                $headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
154
+                return !empty($headers['Name']);
155
+            }
156 156
 
157
-			return false;
158
-		}
157
+            return false;
158
+        }
159 159
 
160
-		/**
161
-		 * Get the name of the theme's directory from a full path to a file inside that directory.
162
-		 * E.g. "/abc/public_html/wp-content/themes/foo/whatever.php" => "foo".
163
-		 *
164
-		 * Note that subdirectories are currently not supported. For example,
165
-		 * "/xyz/wp-content/themes/my-theme/includes/whatever.php" => NULL.
166
-		 *
167
-		 * @param string $absolutePath Normalized path.
168
-		 * @return string|null Directory name, or NULL if the path doesn't point to a theme.
169
-		 */
170
-		protected static function getThemeDirectoryName($absolutePath) {
171
-			if ( is_file($absolutePath) ) {
172
-				$absolutePath = dirname($absolutePath);
173
-			}
160
+        /**
161
+         * Get the name of the theme's directory from a full path to a file inside that directory.
162
+         * E.g. "/abc/public_html/wp-content/themes/foo/whatever.php" => "foo".
163
+         *
164
+         * Note that subdirectories are currently not supported. For example,
165
+         * "/xyz/wp-content/themes/my-theme/includes/whatever.php" => NULL.
166
+         *
167
+         * @param string $absolutePath Normalized path.
168
+         * @return string|null Directory name, or NULL if the path doesn't point to a theme.
169
+         */
170
+        protected static function getThemeDirectoryName($absolutePath) {
171
+            if ( is_file($absolutePath) ) {
172
+                $absolutePath = dirname($absolutePath);
173
+            }
174 174
 
175
-			if ( file_exists($absolutePath . '/style.css') ) {
176
-				return basename($absolutePath);
177
-			}
178
-			return null;
179
-		}
175
+            if ( file_exists($absolutePath . '/style.css') ) {
176
+                return basename($absolutePath);
177
+            }
178
+            return null;
179
+        }
180 180
 
181
-		/**
182
-		 * Get the name of the hosting service that the URL points to.
183
-		 *
184
-		 * @param string $metadataUrl
185
-		 * @return string|null
186
-		 */
187
-		private static function getVcsService($metadataUrl) {
188
-			$service = null;
181
+        /**
182
+         * Get the name of the hosting service that the URL points to.
183
+         *
184
+         * @param string $metadataUrl
185
+         * @return string|null
186
+         */
187
+        private static function getVcsService($metadataUrl) {
188
+            $service = null;
189 189
 
190
-			//Which hosting service does the URL point to?
191
-			$host = @parse_url($metadataUrl, PHP_URL_HOST);
192
-			$path = @parse_url($metadataUrl, PHP_URL_PATH);
193
-			//Check if the path looks like "/user-name/repository".
194
-			$usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
195
-			if ( preg_match($usernameRepoRegex, $path) ) {
196
-				$knownServices = array(
197
-					'github.com' => 'GitHub',
198
-					'bitbucket.org' => 'BitBucket',
199
-					'gitlab.com' => 'GitLab',
200
-				);
201
-				if ( isset($knownServices[$host]) ) {
202
-					$service = $knownServices[$host];
203
-				}
204
-			}
190
+            //Which hosting service does the URL point to?
191
+            $host = @parse_url($metadataUrl, PHP_URL_HOST);
192
+            $path = @parse_url($metadataUrl, PHP_URL_PATH);
193
+            //Check if the path looks like "/user-name/repository".
194
+            $usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
195
+            if ( preg_match($usernameRepoRegex, $path) ) {
196
+                $knownServices = array(
197
+                    'github.com' => 'GitHub',
198
+                    'bitbucket.org' => 'BitBucket',
199
+                    'gitlab.com' => 'GitLab',
200
+                );
201
+                if ( isset($knownServices[$host]) ) {
202
+                    $service = $knownServices[$host];
203
+                }
204
+            }
205 205
       
206
-			return $service;
207
-		}
206
+            return $service;
207
+        }
208 208
 
209
-		/**
210
-		 * Get the latest version of the specified class that has the same major version number
211
-		 * as this factory class.
212
-		 *
213
-		 * @param string $class Partial class name.
214
-		 * @return string|null Full class name.
215
-		 */
216
-		protected static function getCompatibleClassVersion($class) {
217
-			if ( isset(self::$classVersions[$class][self::$latestCompatibleVersion]) ) {
218
-				return self::$classVersions[$class][self::$latestCompatibleVersion];
219
-			}
220
-			return null;
221
-		}
209
+        /**
210
+         * Get the latest version of the specified class that has the same major version number
211
+         * as this factory class.
212
+         *
213
+         * @param string $class Partial class name.
214
+         * @return string|null Full class name.
215
+         */
216
+        protected static function getCompatibleClassVersion($class) {
217
+            if ( isset(self::$classVersions[$class][self::$latestCompatibleVersion]) ) {
218
+                return self::$classVersions[$class][self::$latestCompatibleVersion];
219
+            }
220
+            return null;
221
+        }
222 222
 
223
-		/**
224
-		 * Get the specific class name for the latest available version of a class.
225
-		 *
226
-		 * @param string $class
227
-		 * @return null|string
228
-		 */
229
-		public static function getLatestClassVersion($class) {
230
-			if ( !self::$sorted ) {
231
-				self::sortVersions();
232
-			}
223
+        /**
224
+         * Get the specific class name for the latest available version of a class.
225
+         *
226
+         * @param string $class
227
+         * @return null|string
228
+         */
229
+        public static function getLatestClassVersion($class) {
230
+            if ( !self::$sorted ) {
231
+                self::sortVersions();
232
+            }
233 233
 
234
-			if ( isset(self::$classVersions[$class]) ) {
235
-				return reset(self::$classVersions[$class]);
236
-			} else {
237
-				return null;
238
-			}
239
-		}
234
+            if ( isset(self::$classVersions[$class]) ) {
235
+                return reset(self::$classVersions[$class]);
236
+            } else {
237
+                return null;
238
+            }
239
+        }
240 240
 
241
-		/**
242
-		 * Sort available class versions in descending order (i.e. newest first).
243
-		 */
244
-		protected static function sortVersions() {
245
-			foreach ( self::$classVersions as $class => $versions ) {
246
-				uksort($versions, array(__CLASS__, 'compareVersions'));
247
-				self::$classVersions[$class] = $versions;
248
-			}
249
-			self::$sorted = true;
250
-		}
241
+        /**
242
+         * Sort available class versions in descending order (i.e. newest first).
243
+         */
244
+        protected static function sortVersions() {
245
+            foreach ( self::$classVersions as $class => $versions ) {
246
+                uksort($versions, array(__CLASS__, 'compareVersions'));
247
+                self::$classVersions[$class] = $versions;
248
+            }
249
+            self::$sorted = true;
250
+        }
251 251
 
252
-		protected static function compareVersions($a, $b) {
253
-			return -version_compare($a, $b);
254
-		}
252
+        protected static function compareVersions($a, $b) {
253
+            return -version_compare($a, $b);
254
+        }
255 255
 
256
-		/**
257
-		 * Register a version of a class.
258
-		 *
259
-		 * @access private This method is only for internal use by the library.
260
-		 *
261
-		 * @param string $generalClass Class name without version numbers, e.g. 'PluginUpdateChecker'.
262
-		 * @param string $versionedClass Actual class name, e.g. 'PluginUpdateChecker_1_2'.
263
-		 * @param string $version Version number, e.g. '1.2'.
264
-		 */
265
-		public static function addVersion($generalClass, $versionedClass, $version) {
266
-			if ( empty(self::$myMajorVersion) ) {
267
-				$nameParts = explode('_', __CLASS__, 3);
268
-				self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
269
-			}
256
+        /**
257
+         * Register a version of a class.
258
+         *
259
+         * @access private This method is only for internal use by the library.
260
+         *
261
+         * @param string $generalClass Class name without version numbers, e.g. 'PluginUpdateChecker'.
262
+         * @param string $versionedClass Actual class name, e.g. 'PluginUpdateChecker_1_2'.
263
+         * @param string $version Version number, e.g. '1.2'.
264
+         */
265
+        public static function addVersion($generalClass, $versionedClass, $version) {
266
+            if ( empty(self::$myMajorVersion) ) {
267
+                $nameParts = explode('_', __CLASS__, 3);
268
+                self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
269
+            }
270 270
 
271
-			//Store the greatest version number that matches our major version.
272
-			$components = explode('.', $version);
273
-			if ( $components[0] === self::$myMajorVersion ) {
271
+            //Store the greatest version number that matches our major version.
272
+            $components = explode('.', $version);
273
+            if ( $components[0] === self::$myMajorVersion ) {
274 274
 
275
-				if (
276
-					empty(self::$latestCompatibleVersion)
277
-					|| version_compare($version, self::$latestCompatibleVersion, '>')
278
-				) {
279
-					self::$latestCompatibleVersion = $version;
280
-				}
275
+                if (
276
+                    empty(self::$latestCompatibleVersion)
277
+                    || version_compare($version, self::$latestCompatibleVersion, '>')
278
+                ) {
279
+                    self::$latestCompatibleVersion = $version;
280
+                }
281 281
 
282
-			}
282
+            }
283 283
 
284
-			if ( !isset(self::$classVersions[$generalClass]) ) {
285
-				self::$classVersions[$generalClass] = array();
286
-			}
287
-			self::$classVersions[$generalClass][$version] = $versionedClass;
288
-			self::$sorted = false;
289
-		}
290
-	}
284
+            if ( !isset(self::$classVersions[$generalClass]) ) {
285
+                self::$classVersions[$generalClass] = array();
286
+            }
287
+            self::$classVersions[$generalClass][$version] = $versionedClass;
288
+            self::$sorted = false;
289
+        }
290
+    }
291 291
 
292 292
 endif;
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !class_exists('Puc_v4p4_Factory', false) ):
2
+if (!class_exists('Puc_v4p4_Factory', false)):
3 3
 
4 4
 	/**
5 5
 	 * A factory that builds update checker instances.
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 
41 41
 			//Plugin or theme?
42 42
 			$themeDirectory = self::getThemeDirectoryName($fullPath);
43
-			if ( self::isPluginFile($fullPath) ) {
43
+			if (self::isPluginFile($fullPath)) {
44 44
 				$type = 'Plugin';
45 45
 				$id = $fullPath;
46
-			} else if ( $themeDirectory !== null ) {
46
+			} else if ($themeDirectory !== null) {
47 47
 				$type = 'Theme';
48 48
 				$id = $themeDirectory;
49 49
 			} else {
50 50
 				throw new RuntimeException(sprintf(
51
-					'The update checker cannot determine if "%s" is a plugin or a theme. ' .
51
+					'The update checker cannot determine if "%s" is a plugin or a theme. '.
52 52
 					'This is a bug. Please contact the PUC developer.',
53 53
 					htmlentities($fullPath)
54 54
 				));
@@ -58,36 +58,36 @@  discard block
 block discarded – undo
58 58
 			$service = self::getVcsService($metadataUrl);
59 59
 
60 60
 			$apiClass = null;
61
-			if ( empty($service) ) {
61
+			if (empty($service)) {
62 62
 				//The default is to get update information from a remote JSON file.
63
-				$checkerClass = $type . '_UpdateChecker';
63
+				$checkerClass = $type.'_UpdateChecker';
64 64
 			} else {
65 65
 				//You can also use a VCS repository like GitHub.
66
-				$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
67
-				$apiClass = $service . 'Api';
66
+				$checkerClass = 'Vcs_'.$type.'UpdateChecker';
67
+				$apiClass = $service.'Api';
68 68
 			}
69 69
 
70 70
 			$checkerClass = self::getCompatibleClassVersion($checkerClass);
71
-			if ( $checkerClass === null ) {
71
+			if ($checkerClass === null) {
72 72
 				trigger_error(
73 73
 					sprintf(
74 74
 						'PUC %s does not support updates for %ss %s',
75 75
 						htmlentities(self::$latestCompatibleVersion),
76 76
 						strtolower($type),
77
-						$service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
77
+						$service ? ('hosted on '.htmlentities($service)) : 'using JSON metadata'
78 78
 					),
79 79
 					E_USER_ERROR
80 80
 				);
81 81
 				return null;
82 82
 			}
83 83
       
84
-			if ( !isset($apiClass) ) {
84
+			if (!isset($apiClass)) {
85 85
 				//Plain old update checker.
86 86
 				return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
87 87
 			} else {
88 88
 				//VCS checker + an API client.
89 89
 				$apiClass = self::getCompatibleClassVersion($apiClass);
90
-				if ( $apiClass === null ) {
90
+				if ($apiClass === null) {
91 91
 					trigger_error(sprintf(
92 92
 						'PUC %s does not support %s',
93 93
 						htmlentities(self::$latestCompatibleVersion),
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
 		 * @return string Normalized path.
118 118
 		 */
119 119
 		public static function normalizePath($path) {
120
-			if ( function_exists('wp_normalize_path') ) {
120
+			if (function_exists('wp_normalize_path')) {
121 121
 				return wp_normalize_path($path);
122 122
 			}
123 123
 			$path = str_replace('\\', '/', $path);
124 124
 			$path = preg_replace('|(?<=.)/+|', '/', $path);
125
-			if ( substr($path, 1, 1) === ':' ) {
125
+			if (substr($path, 1, 1) === ':') {
126 126
 				$path = ucfirst($path);
127 127
 			}
128 128
 			return $path;
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
 			//Is the file inside the "plugins" or "mu-plugins" directory?
139 139
 			$pluginDir = self::normalizePath(WP_PLUGIN_DIR);
140 140
 			$muPluginDir = self::normalizePath(WPMU_PLUGIN_DIR);
141
-			if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
141
+			if ((strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0)) {
142 142
 				return true;
143 143
 			}
144 144
 
145 145
 			//Is it a file at all? Caution: is_file() can fail if the parent dir. doesn't have the +x permission set.
146
-			if ( !is_file($absolutePath) ) {
146
+			if (!is_file($absolutePath)) {
147 147
 				return false;
148 148
 			}
149 149
 
150 150
 			//Does it have a valid plugin header?
151 151
 			//This is a last-ditch check for plugins symlinked from outside the WP root.
152
-			if ( function_exists('get_file_data') ) {
152
+			if (function_exists('get_file_data')) {
153 153
 				$headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
154 154
 				return !empty($headers['Name']);
155 155
 			}
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 		 * @return string|null Directory name, or NULL if the path doesn't point to a theme.
169 169
 		 */
170 170
 		protected static function getThemeDirectoryName($absolutePath) {
171
-			if ( is_file($absolutePath) ) {
171
+			if (is_file($absolutePath)) {
172 172
 				$absolutePath = dirname($absolutePath);
173 173
 			}
174 174
 
175
-			if ( file_exists($absolutePath . '/style.css') ) {
175
+			if (file_exists($absolutePath.'/style.css')) {
176 176
 				return basename($absolutePath);
177 177
 			}
178 178
 			return null;
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 			$path = @parse_url($metadataUrl, PHP_URL_PATH);
193 193
 			//Check if the path looks like "/user-name/repository".
194 194
 			$usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
195
-			if ( preg_match($usernameRepoRegex, $path) ) {
195
+			if (preg_match($usernameRepoRegex, $path)) {
196 196
 				$knownServices = array(
197 197
 					'github.com' => 'GitHub',
198 198
 					'bitbucket.org' => 'BitBucket',
199 199
 					'gitlab.com' => 'GitLab',
200 200
 				);
201
-				if ( isset($knownServices[$host]) ) {
201
+				if (isset($knownServices[$host])) {
202 202
 					$service = $knownServices[$host];
203 203
 				}
204 204
 			}
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		 * @return string|null Full class name.
215 215
 		 */
216 216
 		protected static function getCompatibleClassVersion($class) {
217
-			if ( isset(self::$classVersions[$class][self::$latestCompatibleVersion]) ) {
217
+			if (isset(self::$classVersions[$class][self::$latestCompatibleVersion])) {
218 218
 				return self::$classVersions[$class][self::$latestCompatibleVersion];
219 219
 			}
220 220
 			return null;
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 		 * @return null|string
228 228
 		 */
229 229
 		public static function getLatestClassVersion($class) {
230
-			if ( !self::$sorted ) {
230
+			if (!self::$sorted) {
231 231
 				self::sortVersions();
232 232
 			}
233 233
 
234
-			if ( isset(self::$classVersions[$class]) ) {
234
+			if (isset(self::$classVersions[$class])) {
235 235
 				return reset(self::$classVersions[$class]);
236 236
 			} else {
237 237
 				return null;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 		 * Sort available class versions in descending order (i.e. newest first).
243 243
 		 */
244 244
 		protected static function sortVersions() {
245
-			foreach ( self::$classVersions as $class => $versions ) {
245
+			foreach (self::$classVersions as $class => $versions) {
246 246
 				uksort($versions, array(__CLASS__, 'compareVersions'));
247 247
 				self::$classVersions[$class] = $versions;
248 248
 			}
@@ -263,14 +263,14 @@  discard block
 block discarded – undo
263 263
 		 * @param string $version Version number, e.g. '1.2'.
264 264
 		 */
265 265
 		public static function addVersion($generalClass, $versionedClass, $version) {
266
-			if ( empty(self::$myMajorVersion) ) {
266
+			if (empty(self::$myMajorVersion)) {
267 267
 				$nameParts = explode('_', __CLASS__, 3);
268 268
 				self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
269 269
 			}
270 270
 
271 271
 			//Store the greatest version number that matches our major version.
272 272
 			$components = explode('.', $version);
273
-			if ( $components[0] === self::$myMajorVersion ) {
273
+			if ($components[0] === self::$myMajorVersion) {
274 274
 
275 275
 				if (
276 276
 					empty(self::$latestCompatibleVersion)
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
 			}
283 283
 
284
-			if ( !isset(self::$classVersions[$generalClass]) ) {
284
+			if (!isset(self::$classVersions[$generalClass])) {
285 285
 				self::$classVersions[$generalClass] = array();
286 286
 			}
287 287
 			self::$classVersions[$generalClass][$version] = $versionedClass;
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Autoloader.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -2,48 +2,48 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_Autoloader', false) ):
4 4
 
5
-	class Puc_v4p4_Autoloader {
6
-		private $prefix = '';
7
-		private $rootDir = '';
8
-		private $libraryDir = '';
9
-
10
-		private $staticMap;
11
-
12
-		public function __construct() {
13
-			$this->rootDir = dirname(__FILE__) . '/';
14
-			$nameParts = explode('_', __CLASS__, 3);
15
-			$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
16
-
17
-			$this->libraryDir = realpath($this->rootDir . '../..') . '/';
18
-			$this->staticMap = array(
19
-				'PucReadmeParser' => 'vendor/readme-parser.php',
20
-				'Parsedown' => 'vendor/ParsedownLegacy.php',
21
-			);
22
-			if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
23
-				$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
24
-			}
25
-
26
-			spl_autoload_register(array($this, 'autoload'));
27
-		}
28
-
29
-		public function autoload($className) {
30
-			if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
31
-				/** @noinspection PhpIncludeInspection */
32
-				include ($this->libraryDir . $this->staticMap[$className]);
33
-				return;
34
-			}
35
-
36
-			if (strpos($className, $this->prefix) === 0) {
37
-				$path = substr($className, strlen($this->prefix));
38
-				$path = str_replace('_', '/', $path);
39
-				$path = $this->rootDir . $path . '.php';
40
-
41
-				if (file_exists($path)) {
42
-					/** @noinspection PhpIncludeInspection */
43
-					include $path;
44
-				}
45
-			}
46
-		}
47
-	}
5
+    class Puc_v4p4_Autoloader {
6
+        private $prefix = '';
7
+        private $rootDir = '';
8
+        private $libraryDir = '';
9
+
10
+        private $staticMap;
11
+
12
+        public function __construct() {
13
+            $this->rootDir = dirname(__FILE__) . '/';
14
+            $nameParts = explode('_', __CLASS__, 3);
15
+            $this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
16
+
17
+            $this->libraryDir = realpath($this->rootDir . '../..') . '/';
18
+            $this->staticMap = array(
19
+                'PucReadmeParser' => 'vendor/readme-parser.php',
20
+                'Parsedown' => 'vendor/ParsedownLegacy.php',
21
+            );
22
+            if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
23
+                $this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
24
+            }
25
+
26
+            spl_autoload_register(array($this, 'autoload'));
27
+        }
28
+
29
+        public function autoload($className) {
30
+            if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
31
+                /** @noinspection PhpIncludeInspection */
32
+                include ($this->libraryDir . $this->staticMap[$className]);
33
+                return;
34
+            }
35
+
36
+            if (strpos($className, $this->prefix) === 0) {
37
+                $path = substr($className, strlen($this->prefix));
38
+                $path = str_replace('_', '/', $path);
39
+                $path = $this->rootDir . $path . '.php';
40
+
41
+                if (file_exists($path)) {
42
+                    /** @noinspection PhpIncludeInspection */
43
+                    include $path;
44
+                }
45
+            }
46
+        }
47
+    }
48 48
 
49 49
 endif;
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( !class_exists('Puc_v4p4_Autoloader', false) ):
3
+if (!class_exists('Puc_v4p4_Autoloader', false)):
4 4
 
5 5
 	class Puc_v4p4_Autoloader {
6 6
 		private $prefix = '';
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 		private $staticMap;
11 11
 
12 12
 		public function __construct() {
13
-			$this->rootDir = dirname(__FILE__) . '/';
13
+			$this->rootDir = dirname(__FILE__).'/';
14 14
 			$nameParts = explode('_', __CLASS__, 3);
15
-			$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
15
+			$this->prefix = $nameParts[0].'_'.$nameParts[1].'_';
16 16
 
17
-			$this->libraryDir = realpath($this->rootDir . '../..') . '/';
17
+			$this->libraryDir = realpath($this->rootDir.'../..').'/';
18 18
 			$this->staticMap = array(
19 19
 				'PucReadmeParser' => 'vendor/readme-parser.php',
20 20
 				'Parsedown' => 'vendor/ParsedownLegacy.php',
21 21
 			);
22
-			if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
22
+			if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
23 23
 				$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
24 24
 			}
25 25
 
@@ -27,16 +27,16 @@  discard block
 block discarded – undo
27 27
 		}
28 28
 
29 29
 		public function autoload($className) {
30
-			if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
30
+			if (isset($this->staticMap[$className]) && file_exists($this->libraryDir.$this->staticMap[$className])) {
31 31
 				/** @noinspection PhpIncludeInspection */
32
-				include ($this->libraryDir . $this->staticMap[$className]);
32
+				include ($this->libraryDir.$this->staticMap[$className]);
33 33
 				return;
34 34
 			}
35 35
 
36 36
 			if (strpos($className, $this->prefix) === 0) {
37 37
 				$path = substr($className, strlen($this->prefix));
38 38
 				$path = str_replace('_', '/', $path);
39
-				$path = $this->rootDir . $path . '.php';
39
+				$path = $this->rootDir.$path.'.php';
40 40
 
41 41
 				if (file_exists($path)) {
42 42
 					/** @noinspection PhpIncludeInspection */
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/DebugBar/ThemePanel.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -2,20 +2,20 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_DebugBar_ThemePanel', false) ):
4 4
 
5
-	class Puc_v4p4_DebugBar_ThemePanel extends Puc_v4p4_DebugBar_Panel {
6
-		/**
7
-		 * @var Puc_v4p4_Theme_UpdateChecker
8
-		 */
9
-		protected $updateChecker;
5
+    class Puc_v4p4_DebugBar_ThemePanel extends Puc_v4p4_DebugBar_Panel {
6
+        /**
7
+         * @var Puc_v4p4_Theme_UpdateChecker
8
+         */
9
+        protected $updateChecker;
10 10
 
11
-		protected function displayConfigHeader() {
12
-			$this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
13
-			parent::displayConfigHeader();
14
-		}
11
+        protected function displayConfigHeader() {
12
+            $this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
13
+            parent::displayConfigHeader();
14
+        }
15 15
 
16
-		protected function getUpdateFields() {
17
-			return array_merge(parent::getUpdateFields(), array('details_url'));
18
-		}
19
-	}
16
+        protected function getUpdateFields() {
17
+            return array_merge(parent::getUpdateFields(), array('details_url'));
18
+        }
19
+    }
20 20
 
21 21
 endif;
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( !class_exists('Puc_v4p4_DebugBar_ThemePanel', false) ):
3
+if (!class_exists('Puc_v4p4_DebugBar_ThemePanel', false)):
4 4
 
5 5
 	class Puc_v4p4_DebugBar_ThemePanel extends Puc_v4p4_DebugBar_Panel {
6 6
 		/**
Please login to merge, or discard this patch.