Completed
Pull Request — master (#223)
by
unknown
01:56
created
classes/external/php/plugin-update-checker/Puc/v4p4/Autoloader.php 1 patch
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.
classes/external/php/plugin-update-checker/Puc/v4p4/DebugBar/Extension.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -1,177 +1,177 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
3 3
 
4
-	class Puc_v4p4_DebugBar_Extension {
5
-		const RESPONSE_BODY_LENGTH_LIMIT = 4000;
6
-
7
-		/** @var Puc_v4p4_UpdateChecker */
8
-		protected $updateChecker;
9
-		protected $panelClass = 'Puc_v4p4_DebugBar_Panel';
10
-
11
-		public function __construct($updateChecker, $panelClass = null) {
12
-			$this->updateChecker = $updateChecker;
13
-			if ( isset($panelClass) ) {
14
-				$this->panelClass = $panelClass;
15
-			}
16
-
17
-			add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
18
-			add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
19
-
20
-			add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
21
-		}
22
-
23
-		/**
24
-		 * Register the PUC Debug Bar panel.
25
-		 *
26
-		 * @param array $panels
27
-		 * @return array
28
-		 */
29
-		public function addDebugBarPanel($panels) {
30
-			if ( $this->updateChecker->userCanInstallUpdates() ) {
31
-				$panels[] = new $this->panelClass($this->updateChecker);
32
-			}
33
-			return $panels;
34
-		}
35
-
36
-		/**
37
-		 * Enqueue our Debug Bar scripts and styles.
38
-		 */
39
-		public function enqueuePanelDependencies() {
40
-			wp_enqueue_style(
41
-				'puc-debug-bar-style-v4',
42
-				$this->getLibraryUrl("/css/puc-debug-bar.css"),
43
-				array('debug-bar'),
44
-				'20171124'
45
-			);
46
-
47
-			wp_enqueue_script(
48
-				'puc-debug-bar-js-v4',
49
-				$this->getLibraryUrl("/js/debug-bar.js"),
50
-				array('jquery'),
51
-				'20170516'
52
-			);
53
-		}
54
-
55
-		/**
56
-		 * Run an update check and output the result. Useful for making sure that
57
-		 * the update checking process works as expected.
58
-		 */
59
-		public function ajaxCheckNow() {
60
-			if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
61
-				return;
62
-			}
63
-			$this->preAjaxRequest();
64
-			$update = $this->updateChecker->checkForUpdates();
65
-			if ( $update !== null ) {
66
-				echo "An update is available:";
67
-				echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
68
-			} else {
69
-				echo 'No updates found.';
70
-			}
71
-
72
-			$errors = $this->updateChecker->getLastRequestApiErrors();
73
-			if ( !empty($errors) ) {
74
-				printf('<p>The update checker encountered %d API error%s.</p>', count($errors), (count($errors) > 1) ? 's' : '');
75
-
76
-				foreach (array_values($errors) as $num => $item) {
77
-					$wpError = $item['error'];
78
-					/** @var WP_Error $wpError */
79
-					printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
80
-
81
-					echo '<dl>';
82
-					printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
83
-
84
-					if ( isset($item['url']) ) {
85
-						printf('<dt>Requested URL:</dt><dd><code>%s</code></dd>', esc_html($item['url']));
86
-					}
87
-
88
-					if ( isset($item['httpResponse']) ) {
89
-						if ( is_wp_error($item['httpResponse']) ) {
90
-							$httpError = $item['httpResponse'];
91
-							/** @var WP_Error $httpError */
92
-							printf(
93
-								'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
94
-								esc_html($httpError->get_error_message()),
95
-								esc_html($httpError->get_error_code())
96
-							);
97
-						} else {
98
-							//Status code.
99
-							printf(
100
-								'<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
101
-								wp_remote_retrieve_response_code($item['httpResponse']),
102
-								wp_remote_retrieve_response_message($item['httpResponse'])
103
-							);
104
-
105
-							//Headers.
106
-							echo '<dt>Response headers:</dt><dd><pre>';
107
-							foreach (wp_remote_retrieve_headers($item['httpResponse']) as $name => $value) {
108
-								printf("%s: %s\n", esc_html($name), esc_html($value));
109
-							}
110
-							echo '</pre></dd>';
111
-
112
-							//Body.
113
-							$body = wp_remote_retrieve_body($item['httpResponse']);
114
-							if ( $body === '' ) {
115
-								$body = '(Empty response.)';
116
-							} else if ( strlen($body) > self::RESPONSE_BODY_LENGTH_LIMIT ) {
117
-								$length = strlen($body);
118
-								$body = substr($body, 0, self::RESPONSE_BODY_LENGTH_LIMIT)
119
-									. sprintf("\n(Long string truncated. Total length: %d bytes.)", $length);
120
-							}
121
-
122
-							printf('<dt>Response body:</dt><dd><pre>%s</pre></dd>', esc_html($body));
123
-						}
124
-					}
125
-					echo '<dl>';
126
-				}
127
-			}
128
-
129
-			exit;
130
-		}
131
-
132
-		/**
133
-		 * Check access permissions and enable error display (for debugging).
134
-		 */
135
-		protected function preAjaxRequest() {
136
-			if ( !$this->updateChecker->userCanInstallUpdates() ) {
137
-				die('Access denied');
138
-			}
139
-			check_ajax_referer('puc-ajax');
140
-
141
-			error_reporting(E_ALL);
142
-			@ini_set('display_errors', 'On');
143
-		}
144
-
145
-		/**
146
-		 * @param string $filePath
147
-		 * @return string
148
-		 */
149
-		private function getLibraryUrl($filePath) {
150
-			$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
151
-
152
-			//Where is the library located inside the WordPress directory structure?
153
-			$absolutePath = Puc_v4p4_Factory::normalizePath($absolutePath);
154
-
155
-			$pluginDir = Puc_v4p4_Factory::normalizePath(WP_PLUGIN_DIR);
156
-			$muPluginDir = Puc_v4p4_Factory::normalizePath(WPMU_PLUGIN_DIR);
157
-			$themeDir = Puc_v4p4_Factory::normalizePath(get_theme_root());
158
-
159
-			if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
160
-				//It's part of a plugin.
161
-				return plugins_url(basename($absolutePath), $absolutePath);
162
-			} else if ( strpos($absolutePath, $themeDir) === 0 ) {
163
-				//It's part of a theme.
164
-				$relativePath = substr($absolutePath, strlen($themeDir) + 1);
165
-				$template = substr($relativePath, 0, strpos($relativePath, '/'));
166
-				$baseUrl = get_theme_root_uri($template);
167
-
168
-				if ( !empty($baseUrl) && $relativePath ) {
169
-					return $baseUrl . '/' . $relativePath;
170
-				}
171
-			}
172
-
173
-			return '';
174
-		}
175
-	}
4
+    class Puc_v4p4_DebugBar_Extension {
5
+        const RESPONSE_BODY_LENGTH_LIMIT = 4000;
6
+
7
+        /** @var Puc_v4p4_UpdateChecker */
8
+        protected $updateChecker;
9
+        protected $panelClass = 'Puc_v4p4_DebugBar_Panel';
10
+
11
+        public function __construct($updateChecker, $panelClass = null) {
12
+            $this->updateChecker = $updateChecker;
13
+            if ( isset($panelClass) ) {
14
+                $this->panelClass = $panelClass;
15
+            }
16
+
17
+            add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
18
+            add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
19
+
20
+            add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
21
+        }
22
+
23
+        /**
24
+         * Register the PUC Debug Bar panel.
25
+         *
26
+         * @param array $panels
27
+         * @return array
28
+         */
29
+        public function addDebugBarPanel($panels) {
30
+            if ( $this->updateChecker->userCanInstallUpdates() ) {
31
+                $panels[] = new $this->panelClass($this->updateChecker);
32
+            }
33
+            return $panels;
34
+        }
35
+
36
+        /**
37
+         * Enqueue our Debug Bar scripts and styles.
38
+         */
39
+        public function enqueuePanelDependencies() {
40
+            wp_enqueue_style(
41
+                'puc-debug-bar-style-v4',
42
+                $this->getLibraryUrl("/css/puc-debug-bar.css"),
43
+                array('debug-bar'),
44
+                '20171124'
45
+            );
46
+
47
+            wp_enqueue_script(
48
+                'puc-debug-bar-js-v4',
49
+                $this->getLibraryUrl("/js/debug-bar.js"),
50
+                array('jquery'),
51
+                '20170516'
52
+            );
53
+        }
54
+
55
+        /**
56
+         * Run an update check and output the result. Useful for making sure that
57
+         * the update checking process works as expected.
58
+         */
59
+        public function ajaxCheckNow() {
60
+            if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
61
+                return;
62
+            }
63
+            $this->preAjaxRequest();
64
+            $update = $this->updateChecker->checkForUpdates();
65
+            if ( $update !== null ) {
66
+                echo "An update is available:";
67
+                echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
68
+            } else {
69
+                echo 'No updates found.';
70
+            }
71
+
72
+            $errors = $this->updateChecker->getLastRequestApiErrors();
73
+            if ( !empty($errors) ) {
74
+                printf('<p>The update checker encountered %d API error%s.</p>', count($errors), (count($errors) > 1) ? 's' : '');
75
+
76
+                foreach (array_values($errors) as $num => $item) {
77
+                    $wpError = $item['error'];
78
+                    /** @var WP_Error $wpError */
79
+                    printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
80
+
81
+                    echo '<dl>';
82
+                    printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
83
+
84
+                    if ( isset($item['url']) ) {
85
+                        printf('<dt>Requested URL:</dt><dd><code>%s</code></dd>', esc_html($item['url']));
86
+                    }
87
+
88
+                    if ( isset($item['httpResponse']) ) {
89
+                        if ( is_wp_error($item['httpResponse']) ) {
90
+                            $httpError = $item['httpResponse'];
91
+                            /** @var WP_Error $httpError */
92
+                            printf(
93
+                                '<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
94
+                                esc_html($httpError->get_error_message()),
95
+                                esc_html($httpError->get_error_code())
96
+                            );
97
+                        } else {
98
+                            //Status code.
99
+                            printf(
100
+                                '<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
101
+                                wp_remote_retrieve_response_code($item['httpResponse']),
102
+                                wp_remote_retrieve_response_message($item['httpResponse'])
103
+                            );
104
+
105
+                            //Headers.
106
+                            echo '<dt>Response headers:</dt><dd><pre>';
107
+                            foreach (wp_remote_retrieve_headers($item['httpResponse']) as $name => $value) {
108
+                                printf("%s: %s\n", esc_html($name), esc_html($value));
109
+                            }
110
+                            echo '</pre></dd>';
111
+
112
+                            //Body.
113
+                            $body = wp_remote_retrieve_body($item['httpResponse']);
114
+                            if ( $body === '' ) {
115
+                                $body = '(Empty response.)';
116
+                            } else if ( strlen($body) > self::RESPONSE_BODY_LENGTH_LIMIT ) {
117
+                                $length = strlen($body);
118
+                                $body = substr($body, 0, self::RESPONSE_BODY_LENGTH_LIMIT)
119
+                                    . sprintf("\n(Long string truncated. Total length: %d bytes.)", $length);
120
+                            }
121
+
122
+                            printf('<dt>Response body:</dt><dd><pre>%s</pre></dd>', esc_html($body));
123
+                        }
124
+                    }
125
+                    echo '<dl>';
126
+                }
127
+            }
128
+
129
+            exit;
130
+        }
131
+
132
+        /**
133
+         * Check access permissions and enable error display (for debugging).
134
+         */
135
+        protected function preAjaxRequest() {
136
+            if ( !$this->updateChecker->userCanInstallUpdates() ) {
137
+                die('Access denied');
138
+            }
139
+            check_ajax_referer('puc-ajax');
140
+
141
+            error_reporting(E_ALL);
142
+            @ini_set('display_errors', 'On');
143
+        }
144
+
145
+        /**
146
+         * @param string $filePath
147
+         * @return string
148
+         */
149
+        private function getLibraryUrl($filePath) {
150
+            $absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
151
+
152
+            //Where is the library located inside the WordPress directory structure?
153
+            $absolutePath = Puc_v4p4_Factory::normalizePath($absolutePath);
154
+
155
+            $pluginDir = Puc_v4p4_Factory::normalizePath(WP_PLUGIN_DIR);
156
+            $muPluginDir = Puc_v4p4_Factory::normalizePath(WPMU_PLUGIN_DIR);
157
+            $themeDir = Puc_v4p4_Factory::normalizePath(get_theme_root());
158
+
159
+            if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
160
+                //It's part of a plugin.
161
+                return plugins_url(basename($absolutePath), $absolutePath);
162
+            } else if ( strpos($absolutePath, $themeDir) === 0 ) {
163
+                //It's part of a theme.
164
+                $relativePath = substr($absolutePath, strlen($themeDir) + 1);
165
+                $template = substr($relativePath, 0, strpos($relativePath, '/'));
166
+                $baseUrl = get_theme_root_uri($template);
167
+
168
+                if ( !empty($baseUrl) && $relativePath ) {
169
+                    return $baseUrl . '/' . $relativePath;
170
+                }
171
+            }
172
+
173
+            return '';
174
+        }
175
+    }
176 176
 
177 177
 endif;
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/DebugBar/ThemePanel.php 1 patch
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.
classes/external/php/plugin-update-checker/Puc/v4p4/DebugBar/Panel.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -2,164 +2,164 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
4 4
 
5
-	class Puc_v4p4_DebugBar_Panel extends Debug_Bar_Panel {
6
-		/** @var Puc_v4p4_UpdateChecker */
7
-		protected $updateChecker;
8
-
9
-		private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
10
-
11
-		public function __construct($updateChecker) {
12
-			$this->updateChecker = $updateChecker;
13
-			$title = sprintf(
14
-				'<span class="puc-debug-menu-link-%s">PUC (%s)</span>',
15
-				esc_attr($this->updateChecker->getUniqueName('uid')),
16
-				$this->updateChecker->slug
17
-			);
18
-			parent::__construct($title);
19
-		}
20
-
21
-		public function render() {
22
-			printf(
23
-				'<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
24
-				esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
25
-				esc_attr($this->updateChecker->slug),
26
-				esc_attr($this->updateChecker->getUniqueName('uid')),
27
-				esc_attr(wp_create_nonce('puc-ajax'))
28
-			);
29
-
30
-			$this->displayConfiguration();
31
-			$this->displayStatus();
32
-			$this->displayCurrentUpdate();
33
-
34
-			echo '</div>';
35
-		}
36
-
37
-		private function displayConfiguration() {
38
-			echo '<h3>Configuration</h3>';
39
-			echo '<table class="puc-debug-data">';
40
-			$this->displayConfigHeader();
41
-			$this->row('Slug', htmlentities($this->updateChecker->slug));
42
-			$this->row('DB option', htmlentities($this->updateChecker->optionName));
43
-
44
-			$requestInfoButton = $this->getMetadataButton();
45
-			$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
46
-
47
-			$scheduler = $this->updateChecker->scheduler;
48
-			if ( $scheduler->checkPeriod > 0 ) {
49
-				$this->row('Automatic checks', 'Every ' . $scheduler->checkPeriod . ' hours');
50
-			} else {
51
-				$this->row('Automatic checks', 'Disabled');
52
-			}
53
-
54
-			if ( isset($scheduler->throttleRedundantChecks) ) {
55
-				if ( $scheduler->throttleRedundantChecks && ($scheduler->checkPeriod > 0) ) {
56
-					$this->row(
57
-						'Throttling',
58
-						sprintf(
59
-							'Enabled. If an update is already available, check for updates every %1$d hours instead of every %2$d hours.',
60
-							$scheduler->throttledCheckPeriod,
61
-							$scheduler->checkPeriod
62
-						)
63
-					);
64
-				} else {
65
-					$this->row('Throttling', 'Disabled');
66
-				}
67
-			}
68
-
69
-			$this->updateChecker->onDisplayConfiguration($this);
70
-
71
-			echo '</table>';
72
-		}
73
-
74
-		protected function displayConfigHeader() {
75
-			//Do nothing. This should be implemented in subclasses.
76
-		}
77
-
78
-		protected function getMetadataButton() {
79
-			return '';
80
-		}
81
-
82
-		private function displayStatus() {
83
-			echo '<h3>Status</h3>';
84
-			echo '<table class="puc-debug-data">';
85
-			$state = $this->updateChecker->getUpdateState();
86
-			$checkNowButton = '';
87
-			if ( function_exists('get_submit_button')  ) {
88
-				$checkNowButton = get_submit_button(
89
-					'Check Now',
90
-					'secondary',
91
-					'puc-check-now-button',
92
-					false,
93
-					array('id' => $this->updateChecker->getUniqueName('check-now-button'))
94
-				);
95
-			}
96
-
97
-			if ( $state->getLastCheck() > 0 ) {
98
-				$this->row('Last check', $this->formatTimeWithDelta($state->getLastCheck()) . ' ' . $checkNowButton . $this->responseBox);
99
-			} else {
100
-				$this->row('Last check', 'Never');
101
-			}
102
-
103
-			$nextCheck = wp_next_scheduled($this->updateChecker->scheduler->getCronHookName());
104
-			$this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
105
-
106
-			if ( $state->getCheckedVersion() !== '' ) {
107
-				$this->row('Checked version', htmlentities($state->getCheckedVersion()));
108
-				$this->row('Cached update', $state->getUpdate());
109
-			}
110
-			$this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
111
-			echo '</table>';
112
-		}
113
-
114
-		private function displayCurrentUpdate() {
115
-			$update = $this->updateChecker->getUpdate();
116
-			if ( $update !== null ) {
117
-				echo '<h3>An Update Is Available</h3>';
118
-				echo '<table class="puc-debug-data">';
119
-				$fields = $this->getUpdateFields();
120
-				foreach($fields as $field) {
121
-					if ( property_exists($update, $field) ) {
122
-						$this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
123
-					}
124
-				}
125
-				echo '</table>';
126
-			} else {
127
-				echo '<h3>No updates currently available</h3>';
128
-			}
129
-		}
130
-
131
-		protected function getUpdateFields() {
132
-			return array('version', 'download_url', 'slug',);
133
-		}
134
-
135
-		private function formatTimeWithDelta($unixTime) {
136
-			if ( empty($unixTime) ) {
137
-				return 'Never';
138
-			}
139
-
140
-			$delta = time() - $unixTime;
141
-			$result = human_time_diff(time(), $unixTime);
142
-			if ( $delta < 0 ) {
143
-				$result = 'after ' . $result;
144
-			} else {
145
-				$result = $result . ' ago';
146
-			}
147
-			$result .= ' (' . $this->formatTimestamp($unixTime) . ')';
148
-			return $result;
149
-		}
150
-
151
-		private function formatTimestamp($unixTime) {
152
-			return gmdate('Y-m-d H:i:s', $unixTime + (get_option('gmt_offset') * 3600));
153
-		}
154
-
155
-		public function row($name, $value) {
156
-			if ( is_object($value) || is_array($value) ) {
157
-				$value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
158
-			} else if ($value === null) {
159
-				$value = '<code>null</code>';
160
-			}
161
-			printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
162
-		}
163
-	}
5
+    class Puc_v4p4_DebugBar_Panel extends Debug_Bar_Panel {
6
+        /** @var Puc_v4p4_UpdateChecker */
7
+        protected $updateChecker;
8
+
9
+        private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
10
+
11
+        public function __construct($updateChecker) {
12
+            $this->updateChecker = $updateChecker;
13
+            $title = sprintf(
14
+                '<span class="puc-debug-menu-link-%s">PUC (%s)</span>',
15
+                esc_attr($this->updateChecker->getUniqueName('uid')),
16
+                $this->updateChecker->slug
17
+            );
18
+            parent::__construct($title);
19
+        }
20
+
21
+        public function render() {
22
+            printf(
23
+                '<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
24
+                esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
25
+                esc_attr($this->updateChecker->slug),
26
+                esc_attr($this->updateChecker->getUniqueName('uid')),
27
+                esc_attr(wp_create_nonce('puc-ajax'))
28
+            );
29
+
30
+            $this->displayConfiguration();
31
+            $this->displayStatus();
32
+            $this->displayCurrentUpdate();
33
+
34
+            echo '</div>';
35
+        }
36
+
37
+        private function displayConfiguration() {
38
+            echo '<h3>Configuration</h3>';
39
+            echo '<table class="puc-debug-data">';
40
+            $this->displayConfigHeader();
41
+            $this->row('Slug', htmlentities($this->updateChecker->slug));
42
+            $this->row('DB option', htmlentities($this->updateChecker->optionName));
43
+
44
+            $requestInfoButton = $this->getMetadataButton();
45
+            $this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
46
+
47
+            $scheduler = $this->updateChecker->scheduler;
48
+            if ( $scheduler->checkPeriod > 0 ) {
49
+                $this->row('Automatic checks', 'Every ' . $scheduler->checkPeriod . ' hours');
50
+            } else {
51
+                $this->row('Automatic checks', 'Disabled');
52
+            }
53
+
54
+            if ( isset($scheduler->throttleRedundantChecks) ) {
55
+                if ( $scheduler->throttleRedundantChecks && ($scheduler->checkPeriod > 0) ) {
56
+                    $this->row(
57
+                        'Throttling',
58
+                        sprintf(
59
+                            'Enabled. If an update is already available, check for updates every %1$d hours instead of every %2$d hours.',
60
+                            $scheduler->throttledCheckPeriod,
61
+                            $scheduler->checkPeriod
62
+                        )
63
+                    );
64
+                } else {
65
+                    $this->row('Throttling', 'Disabled');
66
+                }
67
+            }
68
+
69
+            $this->updateChecker->onDisplayConfiguration($this);
70
+
71
+            echo '</table>';
72
+        }
73
+
74
+        protected function displayConfigHeader() {
75
+            //Do nothing. This should be implemented in subclasses.
76
+        }
77
+
78
+        protected function getMetadataButton() {
79
+            return '';
80
+        }
81
+
82
+        private function displayStatus() {
83
+            echo '<h3>Status</h3>';
84
+            echo '<table class="puc-debug-data">';
85
+            $state = $this->updateChecker->getUpdateState();
86
+            $checkNowButton = '';
87
+            if ( function_exists('get_submit_button')  ) {
88
+                $checkNowButton = get_submit_button(
89
+                    'Check Now',
90
+                    'secondary',
91
+                    'puc-check-now-button',
92
+                    false,
93
+                    array('id' => $this->updateChecker->getUniqueName('check-now-button'))
94
+                );
95
+            }
96
+
97
+            if ( $state->getLastCheck() > 0 ) {
98
+                $this->row('Last check', $this->formatTimeWithDelta($state->getLastCheck()) . ' ' . $checkNowButton . $this->responseBox);
99
+            } else {
100
+                $this->row('Last check', 'Never');
101
+            }
102
+
103
+            $nextCheck = wp_next_scheduled($this->updateChecker->scheduler->getCronHookName());
104
+            $this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
105
+
106
+            if ( $state->getCheckedVersion() !== '' ) {
107
+                $this->row('Checked version', htmlentities($state->getCheckedVersion()));
108
+                $this->row('Cached update', $state->getUpdate());
109
+            }
110
+            $this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
111
+            echo '</table>';
112
+        }
113
+
114
+        private function displayCurrentUpdate() {
115
+            $update = $this->updateChecker->getUpdate();
116
+            if ( $update !== null ) {
117
+                echo '<h3>An Update Is Available</h3>';
118
+                echo '<table class="puc-debug-data">';
119
+                $fields = $this->getUpdateFields();
120
+                foreach($fields as $field) {
121
+                    if ( property_exists($update, $field) ) {
122
+                        $this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
123
+                    }
124
+                }
125
+                echo '</table>';
126
+            } else {
127
+                echo '<h3>No updates currently available</h3>';
128
+            }
129
+        }
130
+
131
+        protected function getUpdateFields() {
132
+            return array('version', 'download_url', 'slug',);
133
+        }
134
+
135
+        private function formatTimeWithDelta($unixTime) {
136
+            if ( empty($unixTime) ) {
137
+                return 'Never';
138
+            }
139
+
140
+            $delta = time() - $unixTime;
141
+            $result = human_time_diff(time(), $unixTime);
142
+            if ( $delta < 0 ) {
143
+                $result = 'after ' . $result;
144
+            } else {
145
+                $result = $result . ' ago';
146
+            }
147
+            $result .= ' (' . $this->formatTimestamp($unixTime) . ')';
148
+            return $result;
149
+        }
150
+
151
+        private function formatTimestamp($unixTime) {
152
+            return gmdate('Y-m-d H:i:s', $unixTime + (get_option('gmt_offset') * 3600));
153
+        }
154
+
155
+        public function row($name, $value) {
156
+            if ( is_object($value) || is_array($value) ) {
157
+                $value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
158
+            } else if ($value === null) {
159
+                $value = '<code>null</code>';
160
+            }
161
+            printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
162
+        }
163
+    }
164 164
 
165 165
 endif;
166 166
\ No newline at end of file
Please login to merge, or discard this patch.
external/php/plugin-update-checker/Puc/v4p4/DebugBar/PluginExtension.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,33 +1,33 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_DebugBar_PluginExtension', false) ):
3 3
 
4
-	class Puc_v4p4_DebugBar_PluginExtension extends Puc_v4p4_DebugBar_Extension {
5
-		/** @var Puc_v4p4_Plugin_UpdateChecker */
6
-		protected $updateChecker;
4
+    class Puc_v4p4_DebugBar_PluginExtension extends Puc_v4p4_DebugBar_Extension {
5
+        /** @var Puc_v4p4_Plugin_UpdateChecker */
6
+        protected $updateChecker;
7 7
 
8
-		public function __construct($updateChecker) {
9
-			parent::__construct($updateChecker, 'Puc_v4p4_DebugBar_PluginPanel');
8
+        public function __construct($updateChecker) {
9
+            parent::__construct($updateChecker, 'Puc_v4p4_DebugBar_PluginPanel');
10 10
 
11
-			add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
12
-		}
11
+            add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
12
+        }
13 13
 
14
-		/**
15
-		 * Request plugin info and output it.
16
-		 */
17
-		public function ajaxRequestInfo() {
18
-			if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
19
-				return;
20
-			}
21
-			$this->preAjaxRequest();
22
-			$info = $this->updateChecker->requestInfo();
23
-			if ( $info !== null ) {
24
-				echo 'Successfully retrieved plugin info from the metadata URL:';
25
-				echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
26
-			} else {
27
-				echo 'Failed to retrieve plugin info from the metadata URL.';
28
-			}
29
-			exit;
30
-		}
31
-	}
14
+        /**
15
+         * Request plugin info and output it.
16
+         */
17
+        public function ajaxRequestInfo() {
18
+            if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
19
+                return;
20
+            }
21
+            $this->preAjaxRequest();
22
+            $info = $this->updateChecker->requestInfo();
23
+            if ( $info !== null ) {
24
+                echo 'Successfully retrieved plugin info from the metadata URL:';
25
+                echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
26
+            } else {
27
+                echo 'Failed to retrieve plugin info from the metadata URL.';
28
+            }
29
+            exit;
30
+        }
31
+    }
32 32
 
33 33
 endif;
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
external/php/plugin-update-checker/Puc/v4p4/DebugBar/PluginPanel.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -2,37 +2,37 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_DebugBar_PluginPanel', false) ):
4 4
 
5
-	class Puc_v4p4_DebugBar_PluginPanel extends Puc_v4p4_DebugBar_Panel {
6
-		/**
7
-		 * @var Puc_v4p4_Plugin_UpdateChecker
8
-		 */
9
-		protected $updateChecker;
5
+    class Puc_v4p4_DebugBar_PluginPanel extends Puc_v4p4_DebugBar_Panel {
6
+        /**
7
+         * @var Puc_v4p4_Plugin_UpdateChecker
8
+         */
9
+        protected $updateChecker;
10 10
 
11
-		protected function displayConfigHeader() {
12
-			$this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
13
-			parent::displayConfigHeader();
14
-		}
11
+        protected function displayConfigHeader() {
12
+            $this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
13
+            parent::displayConfigHeader();
14
+        }
15 15
 
16
-		protected function getMetadataButton() {
17
-			$requestInfoButton = '';
18
-			if ( function_exists('get_submit_button') ) {
19
-				$requestInfoButton = get_submit_button(
20
-					'Request Info',
21
-					'secondary',
22
-					'puc-request-info-button',
23
-					false,
24
-					array('id' => $this->updateChecker->getUniqueName('request-info-button'))
25
-				);
26
-			}
27
-			return $requestInfoButton;
28
-		}
16
+        protected function getMetadataButton() {
17
+            $requestInfoButton = '';
18
+            if ( function_exists('get_submit_button') ) {
19
+                $requestInfoButton = get_submit_button(
20
+                    'Request Info',
21
+                    'secondary',
22
+                    'puc-request-info-button',
23
+                    false,
24
+                    array('id' => $this->updateChecker->getUniqueName('request-info-button'))
25
+                );
26
+            }
27
+            return $requestInfoButton;
28
+        }
29 29
 
30
-		protected function getUpdateFields() {
31
-			return array_merge(
32
-				parent::getUpdateFields(),
33
-				array('homepage', 'upgrade_notice', 'tested',)
34
-			);
35
-		}
36
-	}
30
+        protected function getUpdateFields() {
31
+            return array_merge(
32
+                parent::getUpdateFields(),
33
+                array('homepage', 'upgrade_notice', 'tested',)
34
+            );
35
+        }
36
+    }
37 37
 
38 38
 endif;
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Scheduler.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -1,177 +1,177 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( !class_exists('Puc_v4p4_Scheduler', false) ):
3 3
 
4
-	/**
5
-	 * The scheduler decides when and how often to check for updates.
6
-	 * It calls @see Puc_v4p4_UpdateChecker::checkForUpdates() to perform the actual checks.
7
-	 */
8
-	class Puc_v4p4_Scheduler {
9
-		public $checkPeriod = 12; //How often to check for updates (in hours).
10
-		public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
11
-		public $throttledCheckPeriod = 72;
12
-
13
-		protected $hourlyCheckHooks = array('load-update.php');
14
-
15
-		/**
16
-		 * @var Puc_v4p4_UpdateChecker
17
-		 */
18
-		protected $updateChecker;
19
-
20
-		private $cronHook = null;
21
-
22
-		/**
23
-		 * Scheduler constructor.
24
-		 *
25
-		 * @param Puc_v4p4_UpdateChecker $updateChecker
26
-		 * @param int $checkPeriod How often to check for updates (in hours).
27
-		 * @param array $hourlyHooks
28
-		 */
29
-		public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('load-plugins.php')) {
30
-			$this->updateChecker = $updateChecker;
31
-			$this->checkPeriod = $checkPeriod;
32
-
33
-			//Set up the periodic update checks
34
-			$this->cronHook = $this->updateChecker->getUniqueName('cron_check_updates');
35
-			if ( $this->checkPeriod > 0 ){
36
-
37
-				//Trigger the check via Cron.
38
-				//Try to use one of the default schedules if possible as it's less likely to conflict
39
-				//with other plugins and their custom schedules.
40
-				$defaultSchedules = array(
41
-					1  => 'hourly',
42
-					12 => 'twicedaily',
43
-					24 => 'daily',
44
-				);
45
-				if ( array_key_exists($this->checkPeriod, $defaultSchedules) ) {
46
-					$scheduleName = $defaultSchedules[$this->checkPeriod];
47
-				} else {
48
-					//Use a custom cron schedule.
49
-					$scheduleName = 'every' . $this->checkPeriod . 'hours';
50
-					add_filter('cron_schedules', array($this, '_addCustomSchedule'));
51
-				}
52
-
53
-				if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
54
-					wp_schedule_event(time(), $scheduleName, $this->cronHook);
55
-				}
56
-				add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
57
-
58
-				//In case Cron is disabled or unreliable, we also manually trigger
59
-				//the periodic checks while the user is browsing the Dashboard.
60
-				add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );
61
-
62
-				//Like WordPress itself, we check more often on certain pages.
63
-				/** @see wp_update_plugins */
64
-				add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
65
-				//"load-update.php" and "load-plugins.php" or "load-themes.php".
66
-				$this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
67
-				foreach($this->hourlyCheckHooks as $hook) {
68
-					add_action($hook, array($this, 'maybeCheckForUpdates'));
69
-				}
70
-				//This hook fires after a bulk update is complete.
71
-				add_action('upgrader_process_complete', array($this, 'maybeCheckForUpdates'), 11, 0);
72
-
73
-			} else {
74
-				//Periodic checks are disabled.
75
-				wp_clear_scheduled_hook($this->cronHook);
76
-			}
77
-		}
78
-
79
-		/**
80
-		 * Check for updates if the configured check interval has already elapsed.
81
-		 * Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
82
-		 *
83
-		 * You can override the default behaviour by using the "puc_check_now-$slug" filter.
84
-		 * The filter callback will be passed three parameters:
85
-		 *     - Current decision. TRUE = check updates now, FALSE = don't check now.
86
-		 *     - Last check time as a Unix timestamp.
87
-		 *     - Configured check period in hours.
88
-		 * Return TRUE to check for updates immediately, or FALSE to cancel.
89
-		 *
90
-		 * This method is declared public because it's a hook callback. Calling it directly is not recommended.
91
-		 */
92
-		public function maybeCheckForUpdates(){
93
-			if ( empty($this->checkPeriod) ){
94
-				return;
95
-			}
96
-
97
-			$state = $this->updateChecker->getUpdateState();
98
-			$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
99
-
100
-			//Let plugin authors substitute their own algorithm.
101
-			$shouldCheck = apply_filters(
102
-				$this->updateChecker->getUniqueName('check_now'),
103
-				$shouldCheck,
104
-				$state->getLastCheck(),
105
-				$this->checkPeriod
106
-			);
107
-
108
-			if ( $shouldCheck ) {
109
-				$this->updateChecker->checkForUpdates();
110
-			}
111
-		}
112
-
113
-		/**
114
-		 * Calculate the actual check period based on the current status and environment.
115
-		 *
116
-		 * @return int Check period in seconds.
117
-		 */
118
-		protected function getEffectiveCheckPeriod() {
119
-			$currentFilter = current_filter();
120
-			if ( in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete')) ) {
121
-				//Check more often when the user visits "Dashboard -> Updates" or does a bulk update.
122
-				$period = 60;
123
-			} else if ( in_array($currentFilter, $this->hourlyCheckHooks) ) {
124
-				//Also check more often on /wp-admin/update.php and the "Plugins" or "Themes" page.
125
-				$period = 3600;
126
-			} else if ( $this->throttleRedundantChecks && ($this->updateChecker->getUpdate() !== null) ) {
127
-				//Check less frequently if it's already known that an update is available.
128
-				$period = $this->throttledCheckPeriod * 3600;
129
-			} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
130
-				//WordPress cron schedules are not exact, so lets do an update check even
131
-				//if slightly less than $checkPeriod hours have elapsed since the last check.
132
-				$cronFuzziness = 20 * 60;
133
-				$period = $this->checkPeriod * 3600 - $cronFuzziness;
134
-			} else {
135
-				$period = $this->checkPeriod * 3600;
136
-			}
137
-
138
-			return $period;
139
-		}
140
-
141
-		/**
142
-		 * Add our custom schedule to the array of Cron schedules used by WP.
143
-		 *
144
-		 * @param array $schedules
145
-		 * @return array
146
-		 */
147
-		public function _addCustomSchedule($schedules){
148
-			if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
149
-				$scheduleName = 'every' . $this->checkPeriod . 'hours';
150
-				$schedules[$scheduleName] = array(
151
-					'interval' => $this->checkPeriod * 3600,
152
-					'display' => sprintf('Every %d hours', $this->checkPeriod),
153
-				);
154
-			}
155
-			return $schedules;
156
-		}
157
-
158
-		/**
159
-		 * Remove the scheduled cron event that the library uses to check for updates.
160
-		 *
161
-		 * @return void
162
-		 */
163
-		public function removeUpdaterCron(){
164
-			wp_clear_scheduled_hook($this->cronHook);
165
-		}
166
-
167
-		/**
168
-		 * Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
169
-		 *
170
-		 * @return string
171
-		 */
172
-		public function getCronHookName() {
173
-			return $this->cronHook;
174
-		}
175
-	}
4
+    /**
5
+     * The scheduler decides when and how often to check for updates.
6
+     * It calls @see Puc_v4p4_UpdateChecker::checkForUpdates() to perform the actual checks.
7
+     */
8
+    class Puc_v4p4_Scheduler {
9
+        public $checkPeriod = 12; //How often to check for updates (in hours).
10
+        public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
11
+        public $throttledCheckPeriod = 72;
12
+
13
+        protected $hourlyCheckHooks = array('load-update.php');
14
+
15
+        /**
16
+         * @var Puc_v4p4_UpdateChecker
17
+         */
18
+        protected $updateChecker;
19
+
20
+        private $cronHook = null;
21
+
22
+        /**
23
+         * Scheduler constructor.
24
+         *
25
+         * @param Puc_v4p4_UpdateChecker $updateChecker
26
+         * @param int $checkPeriod How often to check for updates (in hours).
27
+         * @param array $hourlyHooks
28
+         */
29
+        public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('load-plugins.php')) {
30
+            $this->updateChecker = $updateChecker;
31
+            $this->checkPeriod = $checkPeriod;
32
+
33
+            //Set up the periodic update checks
34
+            $this->cronHook = $this->updateChecker->getUniqueName('cron_check_updates');
35
+            if ( $this->checkPeriod > 0 ){
36
+
37
+                //Trigger the check via Cron.
38
+                //Try to use one of the default schedules if possible as it's less likely to conflict
39
+                //with other plugins and their custom schedules.
40
+                $defaultSchedules = array(
41
+                    1  => 'hourly',
42
+                    12 => 'twicedaily',
43
+                    24 => 'daily',
44
+                );
45
+                if ( array_key_exists($this->checkPeriod, $defaultSchedules) ) {
46
+                    $scheduleName = $defaultSchedules[$this->checkPeriod];
47
+                } else {
48
+                    //Use a custom cron schedule.
49
+                    $scheduleName = 'every' . $this->checkPeriod . 'hours';
50
+                    add_filter('cron_schedules', array($this, '_addCustomSchedule'));
51
+                }
52
+
53
+                if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
54
+                    wp_schedule_event(time(), $scheduleName, $this->cronHook);
55
+                }
56
+                add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
57
+
58
+                //In case Cron is disabled or unreliable, we also manually trigger
59
+                //the periodic checks while the user is browsing the Dashboard.
60
+                add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );
61
+
62
+                //Like WordPress itself, we check more often on certain pages.
63
+                /** @see wp_update_plugins */
64
+                add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
65
+                //"load-update.php" and "load-plugins.php" or "load-themes.php".
66
+                $this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
67
+                foreach($this->hourlyCheckHooks as $hook) {
68
+                    add_action($hook, array($this, 'maybeCheckForUpdates'));
69
+                }
70
+                //This hook fires after a bulk update is complete.
71
+                add_action('upgrader_process_complete', array($this, 'maybeCheckForUpdates'), 11, 0);
72
+
73
+            } else {
74
+                //Periodic checks are disabled.
75
+                wp_clear_scheduled_hook($this->cronHook);
76
+            }
77
+        }
78
+
79
+        /**
80
+         * Check for updates if the configured check interval has already elapsed.
81
+         * Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
82
+         *
83
+         * You can override the default behaviour by using the "puc_check_now-$slug" filter.
84
+         * The filter callback will be passed three parameters:
85
+         *     - Current decision. TRUE = check updates now, FALSE = don't check now.
86
+         *     - Last check time as a Unix timestamp.
87
+         *     - Configured check period in hours.
88
+         * Return TRUE to check for updates immediately, or FALSE to cancel.
89
+         *
90
+         * This method is declared public because it's a hook callback. Calling it directly is not recommended.
91
+         */
92
+        public function maybeCheckForUpdates(){
93
+            if ( empty($this->checkPeriod) ){
94
+                return;
95
+            }
96
+
97
+            $state = $this->updateChecker->getUpdateState();
98
+            $shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
99
+
100
+            //Let plugin authors substitute their own algorithm.
101
+            $shouldCheck = apply_filters(
102
+                $this->updateChecker->getUniqueName('check_now'),
103
+                $shouldCheck,
104
+                $state->getLastCheck(),
105
+                $this->checkPeriod
106
+            );
107
+
108
+            if ( $shouldCheck ) {
109
+                $this->updateChecker->checkForUpdates();
110
+            }
111
+        }
112
+
113
+        /**
114
+         * Calculate the actual check period based on the current status and environment.
115
+         *
116
+         * @return int Check period in seconds.
117
+         */
118
+        protected function getEffectiveCheckPeriod() {
119
+            $currentFilter = current_filter();
120
+            if ( in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete')) ) {
121
+                //Check more often when the user visits "Dashboard -> Updates" or does a bulk update.
122
+                $period = 60;
123
+            } else if ( in_array($currentFilter, $this->hourlyCheckHooks) ) {
124
+                //Also check more often on /wp-admin/update.php and the "Plugins" or "Themes" page.
125
+                $period = 3600;
126
+            } else if ( $this->throttleRedundantChecks && ($this->updateChecker->getUpdate() !== null) ) {
127
+                //Check less frequently if it's already known that an update is available.
128
+                $period = $this->throttledCheckPeriod * 3600;
129
+            } else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
130
+                //WordPress cron schedules are not exact, so lets do an update check even
131
+                //if slightly less than $checkPeriod hours have elapsed since the last check.
132
+                $cronFuzziness = 20 * 60;
133
+                $period = $this->checkPeriod * 3600 - $cronFuzziness;
134
+            } else {
135
+                $period = $this->checkPeriod * 3600;
136
+            }
137
+
138
+            return $period;
139
+        }
140
+
141
+        /**
142
+         * Add our custom schedule to the array of Cron schedules used by WP.
143
+         *
144
+         * @param array $schedules
145
+         * @return array
146
+         */
147
+        public function _addCustomSchedule($schedules){
148
+            if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
149
+                $scheduleName = 'every' . $this->checkPeriod . 'hours';
150
+                $schedules[$scheduleName] = array(
151
+                    'interval' => $this->checkPeriod * 3600,
152
+                    'display' => sprintf('Every %d hours', $this->checkPeriod),
153
+                );
154
+            }
155
+            return $schedules;
156
+        }
157
+
158
+        /**
159
+         * Remove the scheduled cron event that the library uses to check for updates.
160
+         *
161
+         * @return void
162
+         */
163
+        public function removeUpdaterCron(){
164
+            wp_clear_scheduled_hook($this->cronHook);
165
+        }
166
+
167
+        /**
168
+         * Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
169
+         *
170
+         * @return string
171
+         */
172
+        public function getCronHookName() {
173
+            return $this->cronHook;
174
+        }
175
+    }
176 176
 
177 177
 endif;
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Theme/Update.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -2,83 +2,83 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_Theme_Update', false) ):
4 4
 
5
-	class Puc_v4p4_Theme_Update extends Puc_v4p4_Update {
6
-		public $details_url = '';
5
+    class Puc_v4p4_Theme_Update extends Puc_v4p4_Update {
6
+        public $details_url = '';
7 7
 
8
-		protected static $extraFields = array('details_url');
8
+        protected static $extraFields = array('details_url');
9 9
 
10
-		/**
11
-		 * Transform the metadata into the format used by WordPress core.
12
-		 * Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
13
-		 *
14
-		 * @return array
15
-		 */
16
-		public function toWpFormat() {
17
-			$update = array(
18
-				'theme' => $this->slug,
19
-				'new_version' => $this->version,
20
-				'url' => $this->details_url,
21
-			);
10
+        /**
11
+         * Transform the metadata into the format used by WordPress core.
12
+         * Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
13
+         *
14
+         * @return array
15
+         */
16
+        public function toWpFormat() {
17
+            $update = array(
18
+                'theme' => $this->slug,
19
+                'new_version' => $this->version,
20
+                'url' => $this->details_url,
21
+            );
22 22
 
23
-			if ( !empty($this->download_url) ) {
24
-				$update['package'] = $this->download_url;
25
-			}
23
+            if ( !empty($this->download_url) ) {
24
+                $update['package'] = $this->download_url;
25
+            }
26 26
 
27
-			return $update;
28
-		}
27
+            return $update;
28
+        }
29 29
 
30
-		/**
31
-		 * Create a new instance of Theme_Update from its JSON-encoded representation.
32
-		 *
33
-		 * @param string $json Valid JSON string representing a theme information object.
34
-		 * @return self New instance of ThemeUpdate, or NULL on error.
35
-		 */
36
-		public static function fromJson($json) {
37
-			$instance = new self();
38
-			if ( !parent::createFromJson($json, $instance) ) {
39
-				return null;
40
-			}
41
-			return $instance;
42
-		}
30
+        /**
31
+         * Create a new instance of Theme_Update from its JSON-encoded representation.
32
+         *
33
+         * @param string $json Valid JSON string representing a theme information object.
34
+         * @return self New instance of ThemeUpdate, or NULL on error.
35
+         */
36
+        public static function fromJson($json) {
37
+            $instance = new self();
38
+            if ( !parent::createFromJson($json, $instance) ) {
39
+                return null;
40
+            }
41
+            return $instance;
42
+        }
43 43
 
44
-		/**
45
-		 * Create a new instance by copying the necessary fields from another object.
46
-		 *
47
-		 * @param StdClass|Puc_v4p4_Theme_Update $object The source object.
48
-		 * @return Puc_v4p4_Theme_Update The new copy.
49
-		 */
50
-		public static function fromObject($object) {
51
-			$update = new self();
52
-			$update->copyFields($object, $update);
53
-			return $update;
54
-		}
44
+        /**
45
+         * Create a new instance by copying the necessary fields from another object.
46
+         *
47
+         * @param StdClass|Puc_v4p4_Theme_Update $object The source object.
48
+         * @return Puc_v4p4_Theme_Update The new copy.
49
+         */
50
+        public static function fromObject($object) {
51
+            $update = new self();
52
+            $update->copyFields($object, $update);
53
+            return $update;
54
+        }
55 55
 
56
-		/**
57
-		 * Basic validation.
58
-		 *
59
-		 * @param StdClass $apiResponse
60
-		 * @return bool|WP_Error
61
-		 */
62
-		protected function validateMetadata($apiResponse) {
63
-			$required = array('version', 'details_url');
64
-			foreach($required as $key) {
65
-				if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
66
-					return new WP_Error(
67
-						'tuc-invalid-metadata',
68
-						sprintf('The theme metadata is missing the required "%s" key.', $key)
69
-					);
70
-				}
71
-			}
72
-			return true;
73
-		}
56
+        /**
57
+         * Basic validation.
58
+         *
59
+         * @param StdClass $apiResponse
60
+         * @return bool|WP_Error
61
+         */
62
+        protected function validateMetadata($apiResponse) {
63
+            $required = array('version', 'details_url');
64
+            foreach($required as $key) {
65
+                if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
66
+                    return new WP_Error(
67
+                        'tuc-invalid-metadata',
68
+                        sprintf('The theme metadata is missing the required "%s" key.', $key)
69
+                    );
70
+                }
71
+            }
72
+            return true;
73
+        }
74 74
 
75
-		protected function getFieldNames() {
76
-			return array_merge(parent::getFieldNames(), self::$extraFields);
77
-		}
75
+        protected function getFieldNames() {
76
+            return array_merge(parent::getFieldNames(), self::$extraFields);
77
+        }
78 78
 
79
-		protected function getPrefixedFilter($tag) {
80
-			return parent::getPrefixedFilter($tag) . '_theme';
81
-		}
82
-	}
79
+        protected function getPrefixedFilter($tag) {
80
+            return parent::getPrefixedFilter($tag) . '_theme';
81
+        }
82
+    }
83 83
 
84 84
 endif;
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
classes/external/php/plugin-update-checker/Puc/v4p4/Theme/UpdateChecker.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -2,176 +2,176 @@
 block discarded – undo
2 2
 
3 3
 if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
4 4
 
5
-	class Puc_v4p4_Theme_UpdateChecker extends Puc_v4p4_UpdateChecker {
6
-		protected $filterSuffix = 'theme';
7
-		protected $updateTransient = 'update_themes';
8
-		protected $translationType = 'theme';
9
-
10
-		/**
11
-		 * @var string Theme directory name.
12
-		 */
13
-		protected $stylesheet;
14
-
15
-		/**
16
-		 * @var WP_Theme Theme object.
17
-		 */
18
-		protected $theme;
19
-
20
-		public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
21
-			if ( $stylesheet === null ) {
22
-				$stylesheet = get_stylesheet();
23
-			}
24
-			$this->stylesheet = $stylesheet;
25
-			$this->theme = wp_get_theme($this->stylesheet);
26
-
27
-			parent::__construct(
28
-				$metadataUrl,
29
-				$stylesheet,
30
-				$customSlug ? $customSlug : $stylesheet,
31
-				$checkPeriod,
32
-				$optionName
33
-			);
34
-		}
35
-
36
-		/**
37
-		 * For themes, the update array is indexed by theme directory name.
38
-		 *
39
-		 * @return string
40
-		 */
41
-		protected function getUpdateListKey() {
42
-			return $this->directoryName;
43
-		}
44
-
45
-		/**
46
-		 * Retrieve the latest update (if any) from the configured API endpoint.
47
-		 *
48
-		 * @return Puc_v4p4_Update|null An instance of Update, or NULL when no updates are available.
49
-		 */
50
-		public function requestUpdate() {
51
-			list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p4_Theme_Update', 'request_update');
52
-
53
-			if ( $themeUpdate !== null ) {
54
-				/** @var Puc_v4p4_Theme_Update $themeUpdate */
55
-				$themeUpdate->slug = $this->slug;
56
-			}
57
-
58
-			$themeUpdate = $this->filterUpdateResult($themeUpdate, $result);
59
-			return $themeUpdate;
60
-		}
61
-
62
-		public function userCanInstallUpdates() {
63
-			return current_user_can('update_themes');
64
-		}
65
-
66
-		/**
67
-		 * Get the currently installed version of the plugin or theme.
68
-		 *
69
-		 * @return string Version number.
70
-		 */
71
-		public function getInstalledVersion() {
72
-			return $this->theme->get('Version');
73
-		}
74
-
75
-		/**
76
-		 * @return string
77
-		 */
78
-		public function getAbsoluteDirectoryPath() {
79
-			if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
80
-				return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
81
-			}
82
-			return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
83
-		}
84
-
85
-		/**
86
-		 * Create an instance of the scheduler.
87
-		 *
88
-		 * @param int $checkPeriod
89
-		 * @return Puc_v4p4_Scheduler
90
-		 */
91
-		protected function createScheduler($checkPeriod) {
92
-			return new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-themes.php'));
93
-		}
94
-
95
-		/**
96
-		 * Is there an update being installed right now for this theme?
97
-		 *
98
-		 * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
99
-		 * @return bool
100
-		 */
101
-		public function isBeingUpgraded($upgrader = null) {
102
-			return $this->upgraderStatus->isThemeBeingUpgraded($this->stylesheet, $upgrader);
103
-		}
104
-
105
-		protected function createDebugBarExtension() {
106
-			return new Puc_v4p4_DebugBar_Extension($this, 'Puc_v4p4_DebugBar_ThemePanel');
107
-		}
108
-
109
-		/**
110
-		 * Register a callback for filtering query arguments.
111
-		 *
112
-		 * The callback function should take one argument - an associative array of query arguments.
113
-		 * It should return a modified array of query arguments.
114
-		 *
115
-		 * @param callable $callback
116
-		 * @return void
117
-		 */
118
-		public function addQueryArgFilter($callback){
119
-			$this->addFilter('request_update_query_args', $callback);
120
-		}
121
-
122
-		/**
123
-		 * Register a callback for filtering arguments passed to wp_remote_get().
124
-		 *
125
-		 * The callback function should take one argument - an associative array of arguments -
126
-		 * and return a modified array or arguments. See the WP documentation on wp_remote_get()
127
-		 * for details on what arguments are available and how they work.
128
-		 *
129
-		 * @uses add_filter() This method is a convenience wrapper for add_filter().
130
-		 *
131
-		 * @param callable $callback
132
-		 * @return void
133
-		 */
134
-		public function addHttpRequestArgFilter($callback) {
135
-			$this->addFilter('request_update_options', $callback);
136
-		}
137
-
138
-		/**
139
-		 * Register a callback for filtering theme updates retrieved from the external API.
140
-		 *
141
-		 * The callback function should take two arguments. If the theme update was retrieved
142
-		 * successfully, the first argument passed will be an instance of Theme_Update. Otherwise,
143
-		 * it will be NULL. The second argument will be the corresponding return value of
144
-		 * wp_remote_get (see WP docs for details).
145
-		 *
146
-		 * The callback function should return a new or modified instance of Theme_Update or NULL.
147
-		 *
148
-		 * @uses add_filter() This method is a convenience wrapper for add_filter().
149
-		 *
150
-		 * @param callable $callback
151
-		 * @return void
152
-		 */
153
-		public function addResultFilter($callback) {
154
-			$this->addFilter('request_update_result', $callback, 10, 2);
155
-		}
156
-
157
-		/**
158
-		 * @return array
159
-		 */
160
-		protected function getHeaderNames() {
161
-			return array(
162
-				'Name'        => 'Theme Name',
163
-				'ThemeURI'    => 'Theme URI',
164
-				'Description' => 'Description',
165
-				'Author'      => 'Author',
166
-				'AuthorURI'   => 'Author URI',
167
-				'Version'     => 'Version',
168
-				'Template'    => 'Template',
169
-				'Status'      => 'Status',
170
-				'Tags'        => 'Tags',
171
-				'TextDomain'  => 'Text Domain',
172
-				'DomainPath'  => 'Domain Path',
173
-			);
174
-		}
175
-	}
5
+    class Puc_v4p4_Theme_UpdateChecker extends Puc_v4p4_UpdateChecker {
6
+        protected $filterSuffix = 'theme';
7
+        protected $updateTransient = 'update_themes';
8
+        protected $translationType = 'theme';
9
+
10
+        /**
11
+         * @var string Theme directory name.
12
+         */
13
+        protected $stylesheet;
14
+
15
+        /**
16
+         * @var WP_Theme Theme object.
17
+         */
18
+        protected $theme;
19
+
20
+        public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
21
+            if ( $stylesheet === null ) {
22
+                $stylesheet = get_stylesheet();
23
+            }
24
+            $this->stylesheet = $stylesheet;
25
+            $this->theme = wp_get_theme($this->stylesheet);
26
+
27
+            parent::__construct(
28
+                $metadataUrl,
29
+                $stylesheet,
30
+                $customSlug ? $customSlug : $stylesheet,
31
+                $checkPeriod,
32
+                $optionName
33
+            );
34
+        }
35
+
36
+        /**
37
+         * For themes, the update array is indexed by theme directory name.
38
+         *
39
+         * @return string
40
+         */
41
+        protected function getUpdateListKey() {
42
+            return $this->directoryName;
43
+        }
44
+
45
+        /**
46
+         * Retrieve the latest update (if any) from the configured API endpoint.
47
+         *
48
+         * @return Puc_v4p4_Update|null An instance of Update, or NULL when no updates are available.
49
+         */
50
+        public function requestUpdate() {
51
+            list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p4_Theme_Update', 'request_update');
52
+
53
+            if ( $themeUpdate !== null ) {
54
+                /** @var Puc_v4p4_Theme_Update $themeUpdate */
55
+                $themeUpdate->slug = $this->slug;
56
+            }
57
+
58
+            $themeUpdate = $this->filterUpdateResult($themeUpdate, $result);
59
+            return $themeUpdate;
60
+        }
61
+
62
+        public function userCanInstallUpdates() {
63
+            return current_user_can('update_themes');
64
+        }
65
+
66
+        /**
67
+         * Get the currently installed version of the plugin or theme.
68
+         *
69
+         * @return string Version number.
70
+         */
71
+        public function getInstalledVersion() {
72
+            return $this->theme->get('Version');
73
+        }
74
+
75
+        /**
76
+         * @return string
77
+         */
78
+        public function getAbsoluteDirectoryPath() {
79
+            if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
80
+                return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
81
+            }
82
+            return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
83
+        }
84
+
85
+        /**
86
+         * Create an instance of the scheduler.
87
+         *
88
+         * @param int $checkPeriod
89
+         * @return Puc_v4p4_Scheduler
90
+         */
91
+        protected function createScheduler($checkPeriod) {
92
+            return new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-themes.php'));
93
+        }
94
+
95
+        /**
96
+         * Is there an update being installed right now for this theme?
97
+         *
98
+         * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
99
+         * @return bool
100
+         */
101
+        public function isBeingUpgraded($upgrader = null) {
102
+            return $this->upgraderStatus->isThemeBeingUpgraded($this->stylesheet, $upgrader);
103
+        }
104
+
105
+        protected function createDebugBarExtension() {
106
+            return new Puc_v4p4_DebugBar_Extension($this, 'Puc_v4p4_DebugBar_ThemePanel');
107
+        }
108
+
109
+        /**
110
+         * Register a callback for filtering query arguments.
111
+         *
112
+         * The callback function should take one argument - an associative array of query arguments.
113
+         * It should return a modified array of query arguments.
114
+         *
115
+         * @param callable $callback
116
+         * @return void
117
+         */
118
+        public function addQueryArgFilter($callback){
119
+            $this->addFilter('request_update_query_args', $callback);
120
+        }
121
+
122
+        /**
123
+         * Register a callback for filtering arguments passed to wp_remote_get().
124
+         *
125
+         * The callback function should take one argument - an associative array of arguments -
126
+         * and return a modified array or arguments. See the WP documentation on wp_remote_get()
127
+         * for details on what arguments are available and how they work.
128
+         *
129
+         * @uses add_filter() This method is a convenience wrapper for add_filter().
130
+         *
131
+         * @param callable $callback
132
+         * @return void
133
+         */
134
+        public function addHttpRequestArgFilter($callback) {
135
+            $this->addFilter('request_update_options', $callback);
136
+        }
137
+
138
+        /**
139
+         * Register a callback for filtering theme updates retrieved from the external API.
140
+         *
141
+         * The callback function should take two arguments. If the theme update was retrieved
142
+         * successfully, the first argument passed will be an instance of Theme_Update. Otherwise,
143
+         * it will be NULL. The second argument will be the corresponding return value of
144
+         * wp_remote_get (see WP docs for details).
145
+         *
146
+         * The callback function should return a new or modified instance of Theme_Update or NULL.
147
+         *
148
+         * @uses add_filter() This method is a convenience wrapper for add_filter().
149
+         *
150
+         * @param callable $callback
151
+         * @return void
152
+         */
153
+        public function addResultFilter($callback) {
154
+            $this->addFilter('request_update_result', $callback, 10, 2);
155
+        }
156
+
157
+        /**
158
+         * @return array
159
+         */
160
+        protected function getHeaderNames() {
161
+            return array(
162
+                'Name'        => 'Theme Name',
163
+                'ThemeURI'    => 'Theme URI',
164
+                'Description' => 'Description',
165
+                'Author'      => 'Author',
166
+                'AuthorURI'   => 'Author URI',
167
+                'Version'     => 'Version',
168
+                'Template'    => 'Template',
169
+                'Status'      => 'Status',
170
+                'Tags'        => 'Tags',
171
+                'TextDomain'  => 'Text Domain',
172
+                'DomainPath'  => 'Domain Path',
173
+            );
174
+        }
175
+    }
176 176
 
177 177
 endif;
178 178
\ No newline at end of file
Please login to merge, or discard this patch.