PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.0.5
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.0.5
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-api-manager-plugin-update.php +105 -176 5.14.0.5 View file →
@@ -1,210 +1,139 @@
1 1 <?php
2 -/**
3 - * MainWP API Manager Update Handler
4 - *
5 - * This class handles updates for MainWP Extension.
6 - *
7 - * @package MainWP API Manager/Update Handler
8 - */
9 2
10 -namespace MainWP\Dashboard;
3 +if ( !defined( 'ABSPATH' ) ) {
4 + exit;
5 +} // Exit if accessed directly
11 6
12 -// Exit if accessed directly.
13 -if ( ! defined( 'ABSPATH' ) ) {
14 - exit;
15 -}
16 -
17 7 /**
18 - * Class MainWP_Api_Manager_Plugin_Update
8 + * Todd Lahman LLC Updater - Single Updater Class
19 9 *
20 - * MainWP API Manager Update Handler.
10 + * @package Update API Manager/Update Handler
11 + * @author Todd Lahman LLC
12 + * @copyright Copyright (c) Todd Lahman LLC
13 + * @since 1.0.0
21 14 *
22 - * @package MainWP API Manager/Update Handler
23 - * @author Todd Lahman LLC
24 - * @copyright Copyright (c) Todd Lahman LLC
25 - * @since 1.0.0
26 15 */
27 -class MainWP_Api_Manager_Plugin_Update { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 +class MainWP_Api_Manager_Plugin_Update {
28 17
29 - /**
30 - * Protected static variable to hold the instance.
31 - *
32 - * @var null Default value.
33 - */
34 - protected static $instance = null;
18 + /**
19 + * @var The single instance of the class
20 + */
21 + protected static $_instance = null;
35 22
36 - /**
37 - * Method instance()
38 - *
39 - * @static
40 - * @return class instance
41 - */
42 - public static function instance() {
43 - if ( is_null( static::$instance ) ) {
44 - static::$instance = new self();
45 - }
23 + /**
24 + * @static
25 + * @return class instance
26 + */
27 + public static function instance() {
28 + if ( is_null( self::$_instance ) ) {
29 + self::$_instance = new self();
30 + }
46 31
47 - return static::$instance;
48 - }
32 + return self::$_instance;
33 + }
49 34
50 - /**
51 - * MainWP_Api_Manager_Plugin_Update constructor.
52 - *
53 - * Run each time the class is called.
54 - */
55 - public function __construct() {
56 - // API data.
57 - }
35 + public function __construct() {
36 + // API data
37 + }
58 38
59 - /**
60 - * Create upgrade request API URL.
61 - *
62 - * @param array $args Request arguments.
63 - *
64 - * @return string Build URL.
65 - *
66 - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url()
67 - */
68 - private function create_upgrade_api_url( $args ) {
69 - $upgrade_url = esc_url_raw( add_query_arg( 'mainwp-api', 'am-software-api', MainWP_Api_Manager::instance()->get_upgrade_url() ) );
39 + // Update API URL
40 + private function create_upgrade_api_url( $args, $bulk_check = true ) {
41 + if ( $bulk_check ) {
42 + $upgrade_url = esc_url_raw( add_query_arg( 'mainwp-api', 'am-software-api', MainWP_Api_Manager::instance()->getUpgradeUrl() ) );
43 + } else {
44 + $upgrade_url = esc_url_raw( add_query_arg( 'wc-api', 'upgrade-api', MainWP_Api_Manager::instance()->getUpgradeUrl() ) );
45 + }
70 46
71 - $query_url = '';
72 - foreach ( $args as $key => $value ) {
73 - $query_url .= $key . '=' . rawurlencode( $value ) . '&';
47 + $query_url = '';
48 + foreach ( $args as $key => $value ) {
49 + $query_url .= $key . '=' . urlencode( $value ) . '&';
74 50 }
75 - $query_url = rtrim( $query_url, '&' );
51 + $query_url = rtrim( $query_url, '&' );
76 52
77 - return $upgrade_url . '&' . $query_url;
78 - }
53 + return $upgrade_url . '&' . $query_url; //http_build_query( $args );
54 + }
79 55
80 - /**
81 - * Returns plugin information in an array.
82 - *
83 - * @param array $plugin Plugin to check.
84 - *
85 - * @return array Plugin information.
86 - */
87 - public function update_check( $plugin ) {
56 + public function update_check( $plugin ) {
88 57
89 - $args = array(
90 - 'request' => 'pluginupdatecheck',
91 - 'plugin_name' => $plugin['plugin_name'],
92 - 'version' => $plugin['software_version'],
93 - 'product_id' => $plugin['product_id'],
94 - 'api_key' => $plugin['api_key'],
95 - 'instance' => $plugin['instance'],
96 - 'software_version' => $plugin['software_version'],
97 - 'extra' => isset( $plugin['extra'] ) ? $plugin['extra'] : '',
98 - );
58 + $args = array(
59 + 'request' => 'pluginupdatecheck',
60 + 'plugin_name' => $plugin[ 'plugin_name' ],
61 + 'version' => $plugin[ 'software_version' ],
62 + 'product_id' => $plugin[ 'product_id' ],
63 + 'api_key' => $plugin[ 'api_key' ],
64 + 'activation_email' => $plugin[ 'activation_email' ],
65 + 'instance' => $plugin[ 'instance' ],
66 + 'domain' => $plugin[ 'domain' ],
67 + 'software_version' => $plugin[ 'software_version' ],
68 + 'extra' => isset( $plugin[ 'extra' ] ) ? $plugin[ 'extra' ] : '',
69 + );
99 70
100 - // Check for a plugin update.
101 - return $this->plugin_information( $args ); // pluginupdatecheck.
102 - }
71 + // Check for a plugin update
72 + return $this->plugin_information( $args );
73 + }
103 74
104 -
105 - /**
106 - * Check if bulkupdateapi is true|false & grab domain name adn extensions list.
107 - *
108 - * @param array $plugins List of plugins (extensions).
109 - *
110 - * @return array Plugin Information & bulkupdatecheck.
111 - */
112 - public function bulk_update_check( $plugins ) {
113 -
75 + public function bulk_update_check( $plugins ) {
114 76 $args = array(
115 - 'request' => 'bulkupdatecheck',
116 - 'extensions' => base64_encode( wp_json_encode( $plugins ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
117 - 'json' => true,
77 + 'request' => 'bulkupdatecheck',
78 + 'domain' => MainWP_Api_Manager::instance()->get_domain(),
79 + 'extensions' => base64_encode( serialize( $plugins ) ),
118 80 );
81 + return $this->plugin_information( $args, true ); /// bulk update check
82 + }
119 83
120 - $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
84 + public function request( $args ) {
85 + $args[ 'request' ] = 'plugininformation';
121 86
122 - if ( ! empty( $mainwp_api_key ) ) {
123 - $args['api_key'] = $mainwp_api_key;
124 - }
87 + $response = $this->plugin_information( $args );
125 88
126 - return $this->plugin_information( $args, true ); // bulkupdatecheck.
127 - }
89 + // If everything is okay return the $response
90 + if ( isset( $response ) && is_object( $response ) && $response !== false ) {
91 + return $response;
92 + }
93 + }
128 94
95 + /**
96 + * Sends and receives data to and from the server API
97 + *
98 + * @access public
99 + * @since 1.0.0
100 + * @return object $response
101 + */
102 + public function plugin_information( $args, $bulk_check = false ) {
103 + $target_url = $this->create_upgrade_api_url( $args, $bulk_check );
104 + $apisslverify = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( get_option( 'mainwp_api_sslVerifyCertificate' ) == 1 ) ) ? 1 : 0;
105 + $request = wp_remote_get( $target_url, array( 'timeout' => 50, 'sslverify' => $apisslverify ) );
129 106
130 - /**
131 - * Check $args, if there is a response, an object exists & response is not false.
132 - *
133 - * @param array $args Request arguments.
134 - *
135 - * @return array|false $response Plugin information.
136 - */
137 - public function request( $args ) {
138 - $args['request'] = 'plugininformation';
107 + if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) {
108 + return false;
109 + }
139 110
140 - $response = $this->plugin_information( $args ); // plugininformation.
111 + if ( $bulk_check ) {
112 + $response = wp_remote_retrieve_body( $request );
113 + $response = unserialize( base64_decode( $response ) );
114 + } else {
115 + $response = unserialize( wp_remote_retrieve_body( $request ) );
116 + }
141 117
142 - // If everything is okay return the response.
143 - if ( isset( $response ) && is_object( $response ) && false !== $response ) {
118 + /**
119 + * For debugging errors from the API
120 + * For errors like: unserialize(): Error at offset 0 of 170 bytes
121 + * Comment out $response above first
122 + */
123 + if ( !$bulk_check ) {
124 + if ( is_object( $response ) ) {
125 + if ( isset( $response->package ) ) {
126 + $response->package = apply_filters( 'mainwp_api_manager_upgrade_url', $response->package );
127 + }
144 128 return $response;
145 129 }
146 - }
130 + } else if ( is_array( $response ) ) {
131 + return $response;
132 + }
147 133
148 - /**
149 - * Sends and receives data to and from the server API.
150 - *
151 - * @access public
152 - *
153 - * @param array $args Request arguments.
154 - * @param bool $bulk_check Check if updating in bulk true|false.
155 - *
156 - * @return array|false Plugin information.
157 - * @since 1.0.0
158 - *
159 - * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze()
160 - */
161 - public function plugin_information( $args, $bulk_check = false ) {
134 + return false;
135 + }
162 136
163 - $args['object'] = MainWP_Api_Manager::instance()->get_domain();
164 -
165 - $target_url = $this->create_upgrade_api_url( $args );
166 - $default = array(
167 - 'timeout' => 150,
168 - 'sslverify' => 1,
169 - );
170 -
171 - $params = apply_filters( 'mainwp_plugin_information_sslverify', $default, $args );
172 -
173 - $request = wp_remote_get(
174 - $target_url,
175 - $params
176 - );
177 -
178 - if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
179 - return false;
180 - }
181 -
182 - $response = wp_remote_retrieve_body( $request );
183 -
184 - if ( isset( $args['json'] ) ) { // bulkupdatecheck: json.
185 - $response = json_decode( $response, true );
186 - } else { // pluginupdatecheck, plugininformation : serialize.
187 - $response = unserialize( $response ); // phpcs:ignore -- data from extensions, to compatible.
188 - }
189 -
190 - /**
191 - * For debugging errors from the API
192 - * For errors like: unserialize(): Error at offset 0 of 170 bytes
193 - * Comment out $response above first
194 - */
195 - if ( ! $bulk_check ) {
196 - if ( is_object( $response ) ) {
197 - if ( isset( $response->package ) ) {
198 - $response->package = apply_filters( 'mainwp_api_manager_upgrade_package_url', $response->package, $response );
199 - }
200 - return $response;
201 - }
202 - } elseif ( is_array( $response ) ) {
203 - return $response;
204 - }
205 -
206 - return false;
207 - }
208 137 }
209 138
210 -// End of class.
139 +// End of class