| @@ -12,9 +12,8 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @uses MainWP_Install_Bulk() |
| 14 | 14 | */ |
| 15 | 15 | class MainWP_Plugins_Handler { |
| 16 | - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated. | |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | 18 | * Get Class Name. |
| 20 | 19 | * |
| @@ -30,59 +29,33 @@ | ||
| 30 | 29 | * @param mixed $data Search Data. |
| 31 | 30 | * @param object $website Child Sites. |
| 32 | 31 | * @param mixed $output Output. |
| 33 | 32 | * |
| 33 | + * @uses MainWP_Error_Helper::get_error_message() | |
| 34 | + * @uses MainWP_Exception() | |
| 35 | + * @uses MainWP_Error_Helper::get_error_message() | |
| 36 | + * | |
| 34 | 37 | * @return mixed error|array. |
| 35 | - * | |
| 36 | - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() | |
| 37 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response() | |
| 38 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 39 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response() | |
| 40 | 38 | */ |
| 41 | 39 | public static function plugins_search_handler( $data, $website, &$output ) { |
| 42 | - if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) { | |
| 43 | - return; | |
| 44 | - } | |
| 45 | 40 | if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) { |
| 46 | - $result = $results[1]; | |
| 47 | - $result_data = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. | |
| 41 | + $result = $results[1]; | |
| 42 | + $plugins = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. | |
| 48 | 43 | unset( $results ); |
| 49 | - if ( isset( $result_data['error'] ) ) { | |
| 50 | - $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( $result_data['error'], $website->url ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 44 | + if ( isset( $plugins['error'] ) ) { | |
| 45 | + $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( $plugins['error'], $website->url ) ); | |
| 51 | 46 | return; |
| 52 | 47 | } |
| 53 | 48 | |
| 54 | - $plugins = isset( $result_data['data'] ) && is_array( $result_data['data'] ) ? $result_data['data'] : array(); | |
| 55 | - | |
| 56 | - $not_found = true; | |
| 57 | - | |
| 58 | 49 | foreach ( $plugins as $plugin ) { |
| 59 | 50 | if ( ! isset( $plugin['name'] ) ) { |
| 60 | 51 | continue; |
| 61 | 52 | } |
| 62 | - $plugin['websiteid'] = $website->id; | |
| 63 | - $plugin['websiteurl'] = $website->url; | |
| 64 | - $plugin['websitename'] = $website->name; | |
| 53 | + $plugin['websiteid'] = $website->id; | |
| 54 | + $plugin['websiteurl'] = $website->url; | |
| 65 | 55 | |
| 66 | 56 | $output->plugins[] = $plugin; |
| 67 | - $not_found = false; | |
| 68 | 57 | } |
| 69 | - | |
| 70 | - if ( 'not_installed' === $output->status ) { | |
| 71 | - if ( $not_found ) { | |
| 72 | - $installed = isset( $result_data['installed_plugins'] ) && is_array( $result_data['installed_plugins'] ) ? $result_data['installed_plugins'] : array(); | |
| 73 | - foreach ( $installed as $plugin ) { | |
| 74 | - if ( ! isset( $plugin['name'] ) ) { | |
| 75 | - continue; | |
| 76 | - } | |
| 77 | - $plugin['websiteid'] = $website->id; | |
| 78 | - $plugin['websiteurl'] = $website->url; | |
| 79 | - $plugin['websitename'] = $website->name; | |
| 80 | - $output->plugins_installed[] = $plugin; | |
| 81 | - } | |
| 82 | - } | |
| 83 | - } | |
| 84 | - | |
| 85 | 58 | unset( $plugins ); |
| 86 | 59 | } else { |
| 87 | 60 | $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) ); |
| 88 | 61 | } |
| @@ -102,32 +75,24 @@ | ||
| 102 | 75 | public static function delete_plugins() { |
| 103 | 76 | self::action( 'delete' ); |
| 104 | 77 | } |
| 105 | 78 | |
| 106 | - /** | |
| 107 | - * Ignore Plugin. | |
| 108 | - * | |
| 109 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 110 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 111 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 112 | - */ | |
| 79 | + /** Ignore Plugin. */ | |
| 113 | 80 | public static function ignore_updates() { |
| 114 | - // phpcs:disable WordPress.Security.NonceVerification | |
| 115 | 81 | $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; |
| 116 | 82 | |
| 117 | 83 | if ( empty( $websiteId ) ) { |
| 118 | - die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 84 | + die( wp_json_encode( array( 'error' => __( 'Invalid request. Please try again.', 'mainwp' ) ) ) ); | |
| 119 | 85 | } |
| 120 | 86 | |
| 121 | 87 | $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); |
| 122 | 88 | |
| 123 | 89 | if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { |
| 124 | - die( wp_json_encode( array( 'error' => esc_html__( 'You are not allowed to edit this website.', 'mainwp' ) ) ) ); | |
| 90 | + die( wp_json_encode( array( 'error' => __( 'You are not allowed to edit this website.', 'mainwp' ) ) ) ); | |
| 125 | 91 | } |
| 126 | 92 | |
| 127 | - $plugins = isset( $_POST['plugins'] ) ? wp_unslash( $_POST['plugins'] ) : false; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 128 | - $names = isset( $_POST['names'] ) ? wp_unslash( $_POST['names'] ) : array(); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 129 | - // phpcs:enable | |
| 93 | + $plugins = isset( $_POST['plugins'] ) ? wp_unslash( $_POST['plugins'] ) : false; | |
| 94 | + $names = isset( $_POST['names'] ) ? wp_unslash( $_POST['names'] ) : array(); | |
| 130 | 95 | |
| 131 | 96 | $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); |
| 132 | 97 | |
| 133 | 98 | if ( ! is_array( $decodedIgnoredPlugins ) ) { |
| @@ -135,9 +100,9 @@ | ||
| 135 | 100 | } |
| 136 | 101 | |
| 137 | 102 | if ( is_array( $plugins ) ) { |
| 138 | 103 | $_count = count( $plugins ); |
| 139 | - for ( $i = 0; $i < $_count; $i++ ) { | |
| 104 | + for ( $i = 0; $i < $_count; $i ++ ) { | |
| 140 | 105 | $slug = $plugins[ $i ]; |
| 141 | 106 | $name = $names[ $i ]; |
| 142 | 107 | if ( ! isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 143 | 108 | $decodedIgnoredPlugins[ $slug ] = urldecode( $name ); |
| @@ -174,42 +139,24 @@ | ||
| 174 | 139 | * |
| 175 | 140 | * @param mixed $pAction activate|deactivate|delete. |
| 176 | 141 | * |
| 177 | 142 | * @return mixed error|true |
| 178 | - * | |
| 179 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 180 | - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() | |
| 181 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 182 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 183 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 184 | 143 | */ |
| 185 | 144 | public static function action( $pAction ) { |
| 186 | - // phpcs:disable WordPress.Security.NonceVerification | |
| 187 | 145 | $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; |
| 188 | 146 | |
| 189 | 147 | if ( empty( $websiteId ) ) { |
| 190 | - die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 148 | + die( wp_json_encode( array( 'error' => __( 'Invalid request. Please try again.', 'mainwp' ) ) ) ); | |
| 191 | 149 | } |
| 192 | 150 | |
| 193 | 151 | $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); |
| 194 | 152 | |
| 195 | 153 | if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { |
| 196 | - die( wp_json_encode( array( 'error' => esc_html__( 'You are not allowed to edit this website.', 'mainwp' ) ) ) ); | |
| 154 | + die( wp_json_encode( array( 'error' => __( 'You are not allowed to edit this website.', 'mainwp' ) ) ) ); | |
| 197 | 155 | } |
| 198 | 156 | |
| 199 | - if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 200 | - die( | |
| 201 | - wp_json_encode( | |
| 202 | - array( | |
| 203 | - 'error' => esc_html__( 'Suspended site.', 'mainwp' ), | |
| 204 | - 'errorCode' => 'SUSPENDED_SITE', | |
| 205 | - ) | |
| 206 | - ) | |
| 207 | - ); | |
| 208 | - } | |
| 209 | - | |
| 210 | 157 | try { |
| 211 | - $plugins = isset( $_POST['plugins'] ) ? wp_unslash( $_POST['plugins'] ) : array(); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 158 | + $plugins = isset( $_POST['plugins'] ) ? wp_unslash( $_POST['plugins'] ) : ''; | |
| 212 | 159 | $plugin = implode( '||', $plugins ); |
| 213 | 160 | $plugin = urldecode( $plugin ); |
| 214 | 161 | |
| 215 | 162 | /** |
| @@ -242,23 +189,16 @@ | ||
| 242 | 189 | } catch ( MainWP_Exception $e ) { |
| 243 | 190 | die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) ); |
| 244 | 191 | } |
| 245 | 192 | |
| 246 | - // phpcs:enable | |
| 247 | - | |
| 248 | 193 | if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) { |
| 249 | - die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error. Please try again.', 'mainwp' ) ) ) ); | |
| 194 | + die( wp_json_encode( array( 'error' => __( 'Unexpected error. Please try again.', 'mainwp' ) ) ) ); | |
| 250 | 195 | } |
| 251 | 196 | |
| 252 | 197 | die( wp_json_encode( array( 'result' => true ) ) ); |
| 253 | 198 | } |
| 254 | 199 | |
| 255 | - /** | |
| 256 | - * Trust Plugin $_POST. | |
| 257 | - * | |
| 258 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 259 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 260 | - */ | |
| 200 | + /** Trust Plugin $_POST. */ | |
| 261 | 201 | public static function trust_post() { |
| 262 | 202 | $userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 263 | 203 | $trustedPlugins = json_decode( $userExtension->trusted_plugins, true ); |
| 264 | 204 | if ( ! is_array( $trustedPlugins ) ) { |
| @@ -263,12 +203,10 @@ | ||
| 263 | 203 | $trustedPlugins = json_decode( $userExtension->trusted_plugins, true ); |
| 264 | 204 | if ( ! is_array( $trustedPlugins ) ) { |
| 265 | 205 | $trustedPlugins = array(); |
| 266 | 206 | } |
| 267 | - // phpcs:disable WordPress.Security.NonceVerification | |
| 268 | 207 | $action = isset( $_POST['do'] ) ? sanitize_text_field( wp_unslash( $_POST['do'] ) ) : ''; |
| 269 | - $slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 270 | - // phpcs:enable | |
| 208 | + $slugs = isset( $_POST['slugs'] ) && is_array( $_POST['slugs'] ) ? wp_unslash( $_POST['slugs'] ) : ''; | |
| 271 | 209 | if ( ! is_array( $slugs ) ) { |
| 272 | 210 | return; |
| 273 | 211 | } |
| 274 | 212 | if ( 'trust' !== $action && 'untrust' !== $action ) { |
| @@ -295,11 +233,8 @@ | ||
| 295 | 233 | /** |
| 296 | 234 | * Update Trusted Plugin list. |
| 297 | 235 | * |
| 298 | 236 | * @param mixed $slug Plugin Slug. |
| 299 | - * | |
| 300 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 301 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 302 | 237 | */ |
| 303 | 238 | public static function trust_plugin( $slug ) { |
| 304 | 239 | $userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 305 | 240 | $trustedPlugins = json_decode( $userExtension->trusted_plugins, true ); |
| @@ -320,14 +255,11 @@ | ||
| 320 | 255 | * |
| 321 | 256 | * @param mixed $slug Plugin Slug. |
| 322 | 257 | * |
| 323 | 258 | * @return boolean true|false. |
| 324 | - * | |
| 325 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 326 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 327 | 259 | */ |
| 328 | 260 | public static function check_auto_update_plugin( $slug ) { |
| 329 | - if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) { | |
| 261 | + if ( 1 != get_option( 'mainwp_automaticDailyUpdate' ) ) { | |
| 330 | 262 | return false; |
| 331 | 263 | } |
| 332 | 264 | $userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 333 | 265 | $trustedPlugins = json_decode( $userExtension->trusted_plugins, true ); |
| @@ -338,16 +270,12 @@ | ||
| 338 | 270 | } |
| 339 | 271 | |
| 340 | 272 | /** |
| 341 | 273 | * Save the trusted plugin note. |
| 342 | - * | |
| 343 | - * @uses \MainWP\Dashboard\MainWP_Utility::esc_content() | |
| 344 | 274 | */ |
| 345 | 275 | public static function save_trusted_plugin_note() { |
| 346 | - // phpcs:disable WordPress.Security.NonceVerification | |
| 347 | - $slug = isset( $_POST['slug'] ) ? urldecode( wp_unslash( $_POST['slug'] ) ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 348 | - $note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 349 | - // phpcs:enable | |
| 276 | + $slug = isset( $_POST['slug'] ) ? urldecode( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 277 | + $note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : ''; | |
| 350 | 278 | $esc_note = MainWP_Utility::esc_content( $note ); |
| 351 | 279 | $userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 352 | 280 | $trustedPluginsNotes = json_decode( $userExtension->trusted_plugins_notes, true ); |
| 353 | 281 | if ( ! is_array( $trustedPluginsNotes ) ) { |
| @@ -356,5 +284,6 @@ | ||
| 356 | 284 | $trustedPluginsNotes[ $slug ] = $esc_note; |
| 357 | 285 | $userExtension->trusted_plugins_notes = wp_json_encode( $trustedPluginsNotes ); |
| 358 | 286 | MainWP_DB_Common::instance()->update_user_extension( $userExtension ); |
| 359 | 287 | } |
| 288 | + | |
| 360 | 289 | } |