Completed
Push — master ( 467b3a...9b6d37 )
by Stephanie
13:11
created
classes/models/FrmEDD_SL_Plugin_Updater.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@  discard block
 block discarded – undo
15 15
  * @version 1.6.3
16 16
  */
17 17
 class FrmEDD_SL_Plugin_Updater {
18
-    private $api_url   = '';
19
-    private $api_data  = array();
20
-    private $name      = '';
21
-    private $slug      = '';
22
-    private $version   = '';
23
-
24
-    /**
25
-     * Class constructor.
26
-     *
27
-     * @uses plugin_basename()
28
-     * @uses hook()
29
-     *
30
-     * @param string  $_api_url     The URL pointing to the custom API endpoint.
31
-     * @param string  $_plugin_file Path to the plugin file.
32
-     * @param array   $_api_data    Optional data to send with API calls.
33
-     */
34
-    public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
18
+	private $api_url   = '';
19
+	private $api_data  = array();
20
+	private $name      = '';
21
+	private $slug      = '';
22
+	private $version   = '';
23
+
24
+	/**
25
+	 * Class constructor.
26
+	 *
27
+	 * @uses plugin_basename()
28
+	 * @uses hook()
29
+	 *
30
+	 * @param string  $_api_url     The URL pointing to the custom API endpoint.
31
+	 * @param string  $_plugin_file Path to the plugin file.
32
+	 * @param array   $_api_data    Optional data to send with API calls.
33
+	 */
34
+	public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
35 35
 		global $frm_edd_plugin_data;
36 36
 
37 37
 		$this->api_url  = trailingslashit( $_api_url );
@@ -44,159 +44,159 @@  discard block
 block discarded – undo
44 44
 
45 45
 		// Set up hooks.
46 46
 		$this->init();
47
-    }
48
-
49
-    /**
50
-     * Set up WordPress filters to hook into WP's update process.
51
-     *
52
-     * @uses add_filter()
53
-     *
54
-     * @return void
55
-     */
56
-    public function init() {
57
-        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
58
-        add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
47
+	}
48
+
49
+	/**
50
+	 * Set up WordPress filters to hook into WP's update process.
51
+	 *
52
+	 * @uses add_filter()
53
+	 *
54
+	 * @return void
55
+	 */
56
+	public function init() {
57
+		add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
58
+		add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
59 59
 		add_action( 'admin_init', array( $this, 'show_changelog' ) );
60
-    }
61
-
62
-    /**
63
-     * Check for Updates at the defined API endpoint and modify the update array.
64
-     *
65
-     * This function dives into the update API just when WordPress creates its update array,
66
-     * then adds a custom API call and injects the custom plugin data retrieved from the API.
67
-     * It is reassembled from parts of the native WordPress plugin update code.
68
-     * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
69
-     *
70
-     * @uses api_request()
71
-     *
72
-     * @param array   $_transient_data Update array build by WordPress.
73
-     * @return array Modified update array with custom plugin data.
74
-     */
75
-    public function check_update( $_transient_data ) {
76
-
77
-        global $pagenow;
78
-
79
-        if ( ! is_object( $_transient_data ) ) {
80
-            $_transient_data = new stdClass;
81
-        }
60
+	}
61
+
62
+	/**
63
+	 * Check for Updates at the defined API endpoint and modify the update array.
64
+	 *
65
+	 * This function dives into the update API just when WordPress creates its update array,
66
+	 * then adds a custom API call and injects the custom plugin data retrieved from the API.
67
+	 * It is reassembled from parts of the native WordPress plugin update code.
68
+	 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
69
+	 *
70
+	 * @uses api_request()
71
+	 *
72
+	 * @param array   $_transient_data Update array build by WordPress.
73
+	 * @return array Modified update array with custom plugin data.
74
+	 */
75
+	public function check_update( $_transient_data ) {
76
+
77
+		global $pagenow;
78
+
79
+		if ( ! is_object( $_transient_data ) ) {
80
+			$_transient_data = new stdClass;
81
+		}
82 82
 
83
-        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
83
+		if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
84 84
 
85
-            $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
85
+			$version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
86 86
 
87
-            if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
87
+			if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
88 88
 
89
-                if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
89
+				if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
90 90
 
91 91
 					if ( empty( $version_info->plugin ) ) {
92 92
 						$version_info->plugin = $this->name;
93 93
 					}
94 94
 
95
-                    $_transient_data->response[ $this->name ] = $version_info;
96
-
97
-                }
98
-
99
-                $_transient_data->last_checked = time();
100
-                $_transient_data->checked[ $this->name ] = $this->version;
101
-
102
-            }
103
-        }
104
-
105
-        return $_transient_data;
106
-    }
107
-
108
-    /**
109
-     * Updates information on the "View version x.x details" page with custom data.
110
-     *
111
-     * @uses api_request()
112
-     *
113
-     * @param mixed   $_data
114
-     * @param string  $_action
115
-     * @param object  $_args
116
-     * @return object $_data
117
-     */
118
-    public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
119
-
120
-        if ( $_action != 'plugin_information' ) {
95
+					$_transient_data->response[ $this->name ] = $version_info;
121 96
 
122
-            return $_data;
97
+				}
123 98
 
124
-        }
99
+				$_transient_data->last_checked = time();
100
+				$_transient_data->checked[ $this->name ] = $this->version;
125 101
 
126
-        if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
102
+			}
103
+		}
127 104
 
128
-            return $_data;
105
+		return $_transient_data;
106
+	}
129 107
 
130
-        }
108
+	/**
109
+	 * Updates information on the "View version x.x details" page with custom data.
110
+	 *
111
+	 * @uses api_request()
112
+	 *
113
+	 * @param mixed   $_data
114
+	 * @param string  $_action
115
+	 * @param object  $_args
116
+	 * @return object $_data
117
+	 */
118
+	public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
131 119
 
132
-        $to_send = array(
133
-            'slug'   => $this->slug,
134
-            'is_ssl' => is_ssl(),
135
-            'fields' => array(
136
-                'banners' => false, // These will be supported soon hopefully
137
-                'reviews' => false,
138
-            ),
139
-        );
120
+		if ( $_action != 'plugin_information' ) {
140 121
 
141
-        $api_response = $this->api_request( 'plugin_information', $to_send );
122
+			return $_data;
142 123
 
143
-        if ( false !== $api_response ) {
144
-            $_data = $api_response;
145
-        }
124
+		}
146 125
 
147
-        return $_data;
148
-    }
126
+		if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
149 127
 
128
+			return $_data;
150 129
 
151
-    /**
152
-     * Disable SSL verification in order to prevent download update failures
153
-     *
154
-     * @param array   $args
155
-     * @param string  $url
156
-     * @return object $array
157
-     */
158
-    public function http_request_args( $args, $url ) {
159
-        // If it is an https request and we are performing a package download, disable ssl verification
160
-        if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
161
-            $args['sslverify'] = false;
162
-        }
163
-        return $args;
164
-    }
130
+		}
165 131
 
166
-    /**
167
-     * Calls the API and, if successfull, returns the object delivered by the API.
168
-     *
169
-     * @uses get_bloginfo()
170
-     * @uses wp_remote_post()
171
-     * @uses is_wp_error()
172
-     *
173
-     * @param string  $_action The requested action.
174
-     * @param array   $_data   Parameters for the API action.
175
-     * @return false|object
176
-     */
177
-    private function api_request( $_action, $_data ) {
132
+		$to_send = array(
133
+			'slug'   => $this->slug,
134
+			'is_ssl' => is_ssl(),
135
+			'fields' => array(
136
+				'banners' => false, // These will be supported soon hopefully
137
+				'reviews' => false,
138
+			),
139
+		);
178 140
 
179
-        global $wp_version;
141
+		$api_response = $this->api_request( 'plugin_information', $to_send );
180 142
 
181
-        $data = array_merge( $this->api_data, $_data );
143
+		if ( false !== $api_response ) {
144
+			$_data = $api_response;
145
+		}
182 146
 
183
-        if ( $data['slug'] != $this->slug ) {
184
-            return;
147
+		return $_data;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Disable SSL verification in order to prevent download update failures
153
+	 *
154
+	 * @param array   $args
155
+	 * @param string  $url
156
+	 * @return object $array
157
+	 */
158
+	public function http_request_args( $args, $url ) {
159
+		// If it is an https request and we are performing a package download, disable ssl verification
160
+		if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
161
+			$args['sslverify'] = false;
162
+		}
163
+		return $args;
164
+	}
165
+
166
+	/**
167
+	 * Calls the API and, if successfull, returns the object delivered by the API.
168
+	 *
169
+	 * @uses get_bloginfo()
170
+	 * @uses wp_remote_post()
171
+	 * @uses is_wp_error()
172
+	 *
173
+	 * @param string  $_action The requested action.
174
+	 * @param array   $_data   Parameters for the API action.
175
+	 * @return false|object
176
+	 */
177
+	private function api_request( $_action, $_data ) {
178
+
179
+		global $wp_version;
180
+
181
+		$data = array_merge( $this->api_data, $_data );
182
+
183
+		if ( $data['slug'] != $this->slug ) {
184
+			return;
185 185
 		}
186 186
 
187
-        if ( $this->api_url == home_url() ) {
188
-            return false; // Don't allow a plugin to ping itself
189
-        }
187
+		if ( $this->api_url == home_url() ) {
188
+			return false; // Don't allow a plugin to ping itself
189
+		}
190 190
 
191
-        $api_params = array(
192
-            'edd_action' => 'get_version',
193
-            'license'    => ! empty( $data['license'] ) ? $data['license'] : '',
194
-            'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
195
-            'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
196
-            'slug'       => $data['slug'],
197
-            'author'     => $data['author'],
198
-            'url'        => home_url(),
199
-        );
191
+		$api_params = array(
192
+			'edd_action' => 'get_version',
193
+			'license'    => ! empty( $data['license'] ) ? $data['license'] : '',
194
+			'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
195
+			'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
196
+			'slug'       => $data['slug'],
197
+			'author'     => $data['author'],
198
+			'url'        => home_url(),
199
+		);
200 200
 
201 201
 		$cache_key = 'edd_plugin_' . md5( sanitize_key( $api_params['license'] . $this->version ) . '_' . $api_params['edd_action'] );
202 202
 		$cached_response = get_transient( $cache_key );
@@ -205,24 +205,24 @@  discard block
 block discarded – undo
205 205
 			return $cached_response;
206 206
 		}
207 207
 
208
-        $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
208
+		$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
209 209
 
210
-        if ( ! is_wp_error( $request ) ) {
211
-            $request = json_decode( wp_remote_retrieve_body( $request ) );
212
-        }
210
+		if ( ! is_wp_error( $request ) ) {
211
+			$request = json_decode( wp_remote_retrieve_body( $request ) );
212
+		}
213 213
 
214
-        if ( $request && isset( $request->sections ) ) {
215
-            $request->sections = maybe_unserialize( $request->sections );
214
+		if ( $request && isset( $request->sections ) ) {
215
+			$request->sections = maybe_unserialize( $request->sections );
216 216
 			set_transient( $cache_key, $request, DAY_IN_SECONDS );
217
-        } else {
218
-            $request = false;
217
+		} else {
218
+			$request = false;
219 219
 			set_transient( $cache_key, 0, DAY_IN_SECONDS );
220
-        }
220
+		}
221 221
 
222
-        return $request;
223
-    }
222
+		return $request;
223
+	}
224 224
 
225
-    public function show_changelog() {
225
+	public function show_changelog() {
226 226
 
227 227
 		global $frm_edd_plugin_data;
228 228
 
@@ -278,5 +278,5 @@  discard block
 block discarded – undo
278 278
 		}
279 279
 
280 280
 		exit;
281
-    }
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		$this->slug     = basename( $_plugin_file, '.php' );
41 41
 		$this->version  = $_api_data['version'];
42 42
 
43
-		$frm_edd_plugin_data[ $this->slug ] = $this->api_data;
43
+		$frm_edd_plugin_data[$this->slug] = $this->api_data;
44 44
 
45 45
 		// Set up hooks.
46 46
 		$this->init();
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             $_transient_data = new stdClass;
81 81
         }
82 82
 
83
-        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
83
+        if ( empty( $_transient_data->response ) || empty( $_transient_data->response[$this->name] ) ) {
84 84
 
85 85
             $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
86 86
 
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 						$version_info->plugin = $this->name;
93 93
 					}
94 94
 
95
-                    $_transient_data->response[ $this->name ] = $version_info;
95
+                    $_transient_data->response[$this->name] = $version_info;
96 96
 
97 97
                 }
98 98
 
99 99
                 $_transient_data->last_checked = time();
100
-                $_transient_data->checked[ $this->name ] = $this->version;
100
+                $_transient_data->checked[$this->name] = $this->version;
101 101
 
102 102
             }
103 103
         }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 			wp_die( __( 'You do not have permission to install plugin updates', 'formidable' ), __( 'Error', 'formidable' ), array( 'response' => 403 ) );
243 243
 		}
244 244
 
245
-		$data         = $frm_edd_plugin_data[ $_REQUEST['slug'] ];
245
+		$data         = $frm_edd_plugin_data[$_REQUEST['slug']];
246 246
 		$cache_key    = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' );
247 247
 		$version_info = get_transient( $cache_key );
248 248
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 		}
275 275
 
276
-		if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
276
+		if ( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
277 277
 			echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
278 278
 		}
279 279
 
Please login to merge, or discard this patch.