| @@ -11,1049 +11,878 @@ | ||
| 11 | 11 | * Class MainWP_System_Handler |
| 12 | 12 | * |
| 13 | 13 | * @package MainWP\Dashboard |
| 14 | 14 | */ |
| 15 | -class MainWP_System_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 15 | +class MainWP_System_Handler { | |
| 16 | 16 | |
| 17 | - // phpcs:disable WordPress.WP.AlternativeFunctions -- use system functions | |
| 17 | + // phpcs:disable WordPress.WP.AlternativeFunctions -- use system functions | |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * Private static variable to hold the single instance of the class. | |
| 21 | - * | |
| 22 | - * @static | |
| 23 | - * | |
| 24 | - * @var mixed Default null | |
| 25 | - */ | |
| 26 | - private static $instance = null; | |
| 19 | + /** | |
| 20 | + * Private static variable to hold the single instance of the class. | |
| 21 | + * | |
| 22 | + * @static | |
| 23 | + * | |
| 24 | + * @var mixed Default null | |
| 25 | + */ | |
| 26 | + private static $instance = null; | |
| 27 | 27 | |
| 28 | - /** | |
| 29 | - * Private variable to hold the upgrade version info. | |
| 30 | - * | |
| 31 | - * @var null Version info. | |
| 32 | - */ | |
| 33 | - private $upgradeVersionInfo = null; | |
| 28 | + /** | |
| 29 | + * Private variable to hold the upgrade version info. | |
| 30 | + * | |
| 31 | + * @var null Version info. | |
| 32 | + */ | |
| 33 | + private $upgradeVersionInfo = null; | |
| 34 | 34 | |
| 35 | - /** | |
| 36 | - * Method instance() | |
| 37 | - * | |
| 38 | - * Create public static instance. | |
| 39 | - * | |
| 40 | - * @static | |
| 41 | - * @return MainWP_System | |
| 42 | - */ | |
| 43 | - public static function instance() { | |
| 44 | - if ( null === static::$instance ) { | |
| 45 | - static::$instance = new self(); | |
| 46 | - } | |
| 35 | + /** | |
| 36 | + * Method instance() | |
| 37 | + * | |
| 38 | + * Create public static instance. | |
| 39 | + * | |
| 40 | + * @static | |
| 41 | + * @return MainWP_System | |
| 42 | + */ | |
| 43 | + public static function instance() { | |
| 44 | + if ( null == self::$instance ) { | |
| 45 | + self::$instance = new self(); | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - return static::$instance; | |
| 49 | - } | |
| 48 | + return self::$instance; | |
| 49 | + } | |
| 50 | 50 | |
| 51 | - /** | |
| 52 | - * MainWP_System_Handler constructor. | |
| 53 | - * | |
| 54 | - * Run each time the class is called. | |
| 55 | - * | |
| 56 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name() | |
| 57 | - */ | |
| 58 | - public function __construct() { | |
| 59 | - add_filter( 'mainwp-extension-enabled-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); // @deprecated Use 'mainwp_extension_enabled_check' instead. | |
| 60 | - add_filter( 'mainwp_extension_enabled_check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); | |
| 51 | + /** | |
| 52 | + * MainWP_System_Handler constructor. | |
| 53 | + * | |
| 54 | + * Run each time the class is called. | |
| 55 | + * | |
| 56 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name() | |
| 57 | + */ | |
| 58 | + public function __construct() { | |
| 59 | + add_filter( 'mainwp-extension-enabled-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); // @deprecated Use 'mainwp_extension_enabled_check' instead. | |
| 60 | + add_filter( 'mainwp_extension_enabled_check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); | |
| 61 | 61 | |
| 62 | - /** | |
| 63 | - * This hook allows you to get a list of sites via the 'mainwp-getsites' filter. | |
| 64 | - * | |
| 65 | - * @link http://codex.mainwp.com/#mainwp-getsites | |
| 66 | - * | |
| 67 | - * @see \MainWP_Extensions::hook_get_sites | |
| 68 | - */ | |
| 69 | - add_filter( 'mainwp-getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getsites' instead. | |
| 70 | - add_filter( 'mainwp-getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getdbsites' instead. | |
| 62 | + /** | |
| 63 | + * This hook allows you to get a list of sites via the 'mainwp-getsites' filter. | |
| 64 | + * | |
| 65 | + * @link http://codex.mainwp.com/#mainwp-getsites | |
| 66 | + * | |
| 67 | + * @see \MainWP_Extensions::hook_get_sites | |
| 68 | + */ | |
| 69 | + add_filter( 'mainwp-getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getsites' instead. | |
| 70 | + add_filter( 'mainwp-getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getdbsites' instead. | |
| 71 | 71 | |
| 72 | - add_filter( 'mainwp_getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); | |
| 73 | - add_filter( 'mainwp_getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); | |
| 74 | - add_filter( 'mainwp_get_db_websites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_websites' ), 10, 5 ); | |
| 72 | + add_filter( 'mainwp_getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); | |
| 73 | + add_filter( 'mainwp_getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); | |
| 75 | 74 | |
| 76 | - /** | |
| 77 | - * This hook allows you to get a information about groups via the 'mainwp-getgroups' filter. | |
| 78 | - * | |
| 79 | - * @link http://codex.mainwp.com/#mainwp-getgroups | |
| 80 | - * | |
| 81 | - * @see \MainWP_Extensions::hook_get_groups | |
| 82 | - */ | |
| 83 | - add_filter( 'mainwp-getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); // @deprecated Use 'mainwp_getgroups' instead. | |
| 84 | - add_filter( 'mainwp_getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); | |
| 85 | - add_action( 'mainwp_fetchurlsauthed', array( &$this, 'filter_fetch_urls_authed' ), 10, 7 ); | |
| 86 | - add_filter( 'mainwp_fetchurlauthed', array( &$this, 'filter_fetch_url_authed' ), 10, 6 ); | |
| 87 | - add_filter( 'mainwp_getsqlwebsites_for_current_user', array( static::class, 'hook_get_sql_websites_for_current_user' ), 10, 4 ); | |
| 88 | - add_filter( 'mainwp_fetchurlverifyaction', array( &$this, 'hook_fetch_url_verify_action' ), 10, 4 ); | |
| 75 | + /** | |
| 76 | + * This hook allows you to get a information about groups via the 'mainwp-getgroups' filter. | |
| 77 | + * | |
| 78 | + * @link http://codex.mainwp.com/#mainwp-getgroups | |
| 79 | + * | |
| 80 | + * @see \MainWP_Extensions::hook_get_groups | |
| 81 | + */ | |
| 82 | + add_filter( 'mainwp-getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); // @deprecated Use 'mainwp_getgroups' instead. | |
| 83 | + add_filter( 'mainwp_getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); | |
| 84 | + add_action( 'mainwp_fetchurlsauthed', array( &$this, 'filter_fetch_urls_authed' ), 10, 7 ); | |
| 85 | + add_filter( 'mainwp_fetchurlauthed', array( &$this, 'filter_fetch_url_authed' ), 10, 6 ); | |
| 89 | 86 | |
| 90 | - add_filter( | |
| 91 | - 'mainwp_getdashboardsites', | |
| 92 | - array( | |
| 93 | - MainWP_Extensions_Handler::get_class_name(), | |
| 94 | - 'hook_get_dashboard_sites', | |
| 95 | - ), | |
| 96 | - 10, | |
| 97 | - 7 | |
| 98 | - ); | |
| 87 | + add_filter( 'mainwp_getsqlwebsites_for_current_user', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sql_websites_for_current_user' ), 10, 4 ); | |
| 99 | 88 | |
| 100 | - // @deprecated Use 'mainwp_manager_getextensions' instead. | |
| 101 | - add_filter( | |
| 102 | - 'mainwp-manager-getextensions', | |
| 103 | - array( | |
| 104 | - MainWP_Extensions_Handler::get_class_name(), | |
| 105 | - 'hook_get_all_extensions', | |
| 106 | - ) | |
| 107 | - ); | |
| 89 | + add_filter( | |
| 90 | + 'mainwp_getdashboardsites', | |
| 91 | + array( | |
| 92 | + MainWP_Extensions_Handler::get_class_name(), | |
| 93 | + 'hook_get_dashboard_sites', | |
| 94 | + ), | |
| 95 | + 10, | |
| 96 | + 7 | |
| 97 | + ); | |
| 108 | 98 | |
| 109 | - add_filter( | |
| 110 | - 'mainwp_manager_getextensions', | |
| 111 | - array( | |
| 112 | - MainWP_Extensions_Handler::get_class_name(), | |
| 113 | - 'hook_get_all_extensions', | |
| 114 | - ) | |
| 115 | - ); | |
| 99 | + // @deprecated Use 'mainwp_manager_getextensions' instead. | |
| 100 | + add_filter( | |
| 101 | + 'mainwp-manager-getextensions', | |
| 102 | + array( | |
| 103 | + MainWP_Extensions_Handler::get_class_name(), | |
| 104 | + 'hook_get_all_extensions', | |
| 105 | + ) | |
| 106 | + ); | |
| 116 | 107 | |
| 117 | - add_action( 'admin_init', array( &$this, 'admin_init' ) ); | |
| 108 | + add_filter( | |
| 109 | + 'mainwp_manager_getextensions', | |
| 110 | + array( | |
| 111 | + MainWP_Extensions_Handler::get_class_name(), | |
| 112 | + 'hook_get_all_extensions', | |
| 113 | + ) | |
| 114 | + ); | |
| 118 | 115 | |
| 119 | - if ( false !== get_option( 'mainwp_upgradeVersionInfo' ) && '' !== get_option( 'mainwp_upgradeVersionInfo' ) ) { | |
| 120 | - $this->upgradeVersionInfo = get_option( 'mainwp_upgradeVersionInfo' ); | |
| 121 | - if ( ! is_object( $this->upgradeVersionInfo ) ) { | |
| 122 | - $this->upgradeVersionInfo = new \stdClass(); | |
| 123 | - } | |
| 124 | - } | |
| 125 | - } | |
| 116 | + if ( '' != get_option( 'mainwp_upgradeVersionInfo' ) ) { | |
| 117 | + $this->upgradeVersionInfo = get_option( 'mainwp_upgradeVersionInfo' ); | |
| 118 | + if ( ! is_object( $this->upgradeVersionInfo ) ) { | |
| 119 | + $this->upgradeVersionInfo = new \stdClass(); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + } | |
| 126 | 123 | |
| 127 | - /** | |
| 128 | - * Method filter_fetch_urls_authed() | |
| 129 | - * | |
| 130 | - * Filter fetch authorized urls. | |
| 131 | - * | |
| 132 | - * @param mixed $pluginFile MainWP extention. | |
| 133 | - * @param string $key MainWP Licence Key. | |
| 134 | - * @param object $dbwebsites Child Sites. | |
| 135 | - * @param string $what Function to perform. | |
| 136 | - * @param array $params Function paramerters. | |
| 137 | - * @param mixed $handle Function handle. | |
| 138 | - * @param mixed $output Function output. | |
| 139 | - * | |
| 140 | - * @return mixed MainWP_Extensions_Handler::hook_fetch_urls_authed() Hook fetch authorized URLs. | |
| 141 | - * | |
| 142 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_urls_authed() | |
| 143 | - */ | |
| 144 | - public function filter_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ) { | |
| 145 | - return MainWP_Extensions_Handler::hook_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ); | |
| 146 | - } | |
| 124 | + /** | |
| 125 | + * Method filter_fetch_urls_authed() | |
| 126 | + * | |
| 127 | + * Filter fetch authorized urls. | |
| 128 | + * | |
| 129 | + * @param mixed $pluginFile MainWP extention. | |
| 130 | + * @param string $key MainWP Licence Key. | |
| 131 | + * @param object $dbwebsites Child Sites. | |
| 132 | + * @param string $what Function to perform. | |
| 133 | + * @param array $params Function paramerters. | |
| 134 | + * @param mixed $handle Function handle. | |
| 135 | + * @param mixed $output Function output. | |
| 136 | + * | |
| 137 | + * @return mixed MainWP_Extensions_Handler::hook_fetch_urls_authed() Hook fetch authorized URLs. | |
| 138 | + * | |
| 139 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_urls_authed() | |
| 140 | + */ | |
| 141 | + public function filter_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ) { | |
| 142 | + return MainWP_Extensions_Handler::hook_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output, $is_external_hook = true ); | |
| 143 | + } | |
| 147 | 144 | |
| 148 | - /** | |
| 149 | - * Method filter_fetch_url_authed() | |
| 150 | - * | |
| 151 | - * Filter fetch Authorized URL. | |
| 152 | - * | |
| 153 | - * @param mixed $pluginFile MainWP extention. | |
| 154 | - * @param string $key MainWP licence key. | |
| 155 | - * @param int $websiteId Website ID. | |
| 156 | - * @param string $what Function to perform. | |
| 157 | - * @param array $params Function paramerters. | |
| 158 | - * @param null $raw_response Raw response. | |
| 159 | - * | |
| 160 | - * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL. | |
| 161 | - * | |
| 162 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_url_authed() | |
| 163 | - */ | |
| 164 | - public function filter_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response = null ) { | |
| 165 | - return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response ); | |
| 166 | - } | |
| 145 | + /** | |
| 146 | + * Method filter_fetch_url_authed() | |
| 147 | + * | |
| 148 | + * Filter fetch Authorized URL. | |
| 149 | + * | |
| 150 | + * @param mixed $pluginFile MainWP extention. | |
| 151 | + * @param string $key MainWP licence key. | |
| 152 | + * @param int $websiteId Website ID. | |
| 153 | + * @param string $what Function to perform. | |
| 154 | + * @param array $params Function paramerters. | |
| 155 | + * @param null $raw_response Raw response. | |
| 156 | + * | |
| 157 | + * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL. | |
| 158 | + * | |
| 159 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_url_authed() | |
| 160 | + */ | |
| 161 | + public function filter_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response = null ) { | |
| 162 | + return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response ); | |
| 163 | + } | |
| 167 | 164 | |
| 168 | - /** | |
| 169 | - * Method hook_fetch_url_verify_action() | |
| 170 | - * | |
| 171 | - * Filter fetch Authorized URL. | |
| 172 | - * | |
| 173 | - * @param mixed $pluginFile MainWP extention. | |
| 174 | - * @param string $childKey Extension child key. | |
| 175 | - * @param int $websiteId Website ID. | |
| 176 | - * @param array $params Function paramerters. | |
| 177 | - * | |
| 178 | - * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL. | |
| 179 | - */ | |
| 180 | - public function hook_fetch_url_verify_action( $pluginFile, $childKey, $websiteId, $params ) { | |
| 181 | - if ( ! is_array( $params ) || ! isset( $params['actionnonce'] ) ) { | |
| 182 | - return false; | |
| 183 | - } | |
| 184 | - $what = 'verify_action'; | |
| 185 | - return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $childKey, $websiteId, $what, $params ); | |
| 186 | - } | |
| 165 | + /** | |
| 166 | + * Method apply_filter() | |
| 167 | + * | |
| 168 | + * Apply filter | |
| 169 | + * | |
| 170 | + * @param string $filter The filter. | |
| 171 | + * @param array $value Input value. | |
| 172 | + * | |
| 173 | + * @return array $output Output array. | |
| 174 | + * | |
| 175 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_verify() | |
| 176 | + */ | |
| 177 | + public function apply_filters( $filter, $value = array() ) { | |
| 187 | 178 | |
| 188 | - /** | |
| 189 | - * Method apply_filter() | |
| 190 | - * | |
| 191 | - * Apply filter | |
| 192 | - * | |
| 193 | - * @param string $filter The filter. | |
| 194 | - * @param array $value Input value. | |
| 195 | - * | |
| 196 | - * @return array $output Output array. | |
| 197 | - * | |
| 198 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_verify() | |
| 199 | - */ | |
| 200 | - public function apply_filters( $filter, $value = array() ) { | |
| 179 | + if ( 'mainwp-getmetaboxes' === $filter ) { | |
| 180 | + $output = apply_filters_deprecated( 'mainwp-getmetaboxes', array( $value ), '4.0.7.2', 'mainwp_getmetaboxes' ); // @deprecated Use 'mainwp_getmetaboxes' instead. | |
| 181 | + } else { | |
| 182 | + $output = apply_filters( $filter, $value ); | |
| 183 | + } | |
| 201 | 184 | |
| 202 | - if ( 'mainwp-getmetaboxes' === $filter ) { | |
| 203 | - $output = apply_filters_deprecated( 'mainwp-getmetaboxes', array( $value ), '4.0.7.2', 'mainwp_getmetaboxes' ); // @deprecated Use 'mainwp_getmetaboxes' instead. NOSONAR - not IP. | |
| 204 | - } else { | |
| 205 | - $output = apply_filters( $filter, $value ); | |
| 206 | - } | |
| 185 | + if ( ! is_array( $output ) ) { | |
| 186 | + return array(); | |
| 187 | + } | |
| 188 | + $count = count( $output ); | |
| 189 | + for ( $i = 0; $i < $count; $i ++ ) { | |
| 207 | 190 | |
| 208 | - if ( ! is_array( $output ) ) { | |
| 209 | - return array(); | |
| 210 | - } | |
| 211 | - return $output; | |
| 212 | - } | |
| 191 | + if ( 'mainwp_getmetaboxes' === $filter ) { | |
| 192 | + // pass custom widget. | |
| 193 | + if ( isset( $output[ $i ]['custom'] ) && $output[ $i ]['custom'] && isset( $output[ $i ]['plugin'] ) ) { | |
| 194 | + continue; | |
| 195 | + } | |
| 196 | + } | |
| 213 | 197 | |
| 214 | - /** | |
| 215 | - * Method admin_init() | |
| 216 | - * | |
| 217 | - * Do nothing if current user is not an Admin. | |
| 218 | - */ | |
| 219 | - public function admin_init() { // phpcs:ignore -- NOSONAR - complex function. | |
| 220 | - if ( ! MainWP_System_Utility::is_admin() ) { | |
| 221 | - return; | |
| 222 | - } | |
| 198 | + if ( ! isset( $output[ $i ]['plugin'] ) || ! isset( $output[ $i ]['key'] ) ) { | |
| 199 | + unset( $output[ $i ] ); | |
| 200 | + continue; | |
| 201 | + } | |
| 223 | 202 | |
| 224 | - global $pagenow; | |
| 203 | + if ( ! MainWP_Extensions_Handler::hook_verify( $output[ $i ]['plugin'], $output[ $i ]['key'] ) ) { | |
| 204 | + unset( $output[ $i ] ); | |
| 205 | + continue; | |
| 206 | + } | |
| 207 | + } | |
| 225 | 208 | |
| 226 | - if ( 'plugins.php' === $pagenow && isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 227 | - $this->check_upgrade(); | |
| 228 | - delete_site_transient( 'update_plugins' ); // to forced refresh 'update_plugins' transient. | |
| 229 | - wp_safe_redirect( admin_url( 'plugins.php' ) ); | |
| 230 | - exit; | |
| 231 | - } | |
| 232 | - } | |
| 209 | + return $output; | |
| 210 | + } | |
| 233 | 211 | |
| 212 | + /** | |
| 213 | + * Method handle_manage_sites_screen_settings() | |
| 214 | + * | |
| 215 | + * Handle manage sites screen settings | |
| 216 | + */ | |
| 217 | + public function handle_manage_sites_screen_settings() { | |
| 218 | + if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) { | |
| 219 | + $show_cols = array(); | |
| 220 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 221 | + if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 222 | + $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 223 | + $show_cols[ $col ] = 1; | |
| 224 | + } | |
| 225 | + } | |
| 226 | + if ( isset( $_POST['show_columns_name'] ) ) { | |
| 227 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 228 | + if ( ! isset( $show_cols[ $col ] ) ) { | |
| 229 | + $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 230 | + } | |
| 231 | + } | |
| 232 | + } | |
| 233 | + $user = wp_get_current_user(); | |
| 234 | + if ( $user ) { | |
| 235 | + $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 236 | + if ( 'grid' !== $val && 'table' !== $val ) { | |
| 237 | + $val = 'grid'; | |
| 238 | + } | |
| 239 | + update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 240 | + update_user_option( $user->ID, 'mainwp_settings_show_manage_sites_columns', $show_cols, true ); | |
| 241 | + update_option( 'mainwp_default_sites_per_page', ( isset( $_POST['mainwp_default_sites_per_page'] ) ? intval( $_POST['mainwp_default_sites_per_page'] ) : 25 ) ); | |
| 242 | + } | |
| 243 | + } elseif ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SreenshotsSitesScrOptions' ) ) { | |
| 244 | + $user = wp_get_current_user(); | |
| 245 | + if ( $user ) { | |
| 246 | + $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 247 | + if ( 'grid' !== $val && 'table' !== $val ) { | |
| 248 | + $val = 'grid'; | |
| 249 | + } | |
| 250 | + update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + } | |
| 234 | 254 | |
| 255 | + /** | |
| 256 | + * Method handle_monitoring_sites_screen_settings() | |
| 257 | + * | |
| 258 | + * Handle monitoring sites screen settings | |
| 259 | + */ | |
| 260 | + public function handle_monitoring_sites_screen_settings() { | |
| 261 | + if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MonitoringSitesScrOptions' ) ) { | |
| 262 | + $show_cols = array(); | |
| 263 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 264 | + if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 265 | + $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 266 | + $show_cols[ $col ] = 1; | |
| 267 | + } | |
| 268 | + } | |
| 269 | + if ( isset( $_POST['show_columns_name'] ) ) { | |
| 270 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 271 | + if ( ! isset( $show_cols[ $col ] ) ) { | |
| 272 | + $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 273 | + } | |
| 274 | + } | |
| 275 | + } | |
| 235 | 276 | |
| 236 | - /** | |
| 237 | - * Method hook_get_sql_websites_for_current_user() | |
| 238 | - * | |
| 239 | - * Get sql websites for current user. | |
| 240 | - * | |
| 241 | - * @param mixed $input_value First input filter value. | |
| 242 | - * @param string $pluginFile Extension plugin file to verify. | |
| 243 | - * @param string $key The child-key. | |
| 244 | - * @param mixed $params Input params data. | |
| 245 | - * | |
| 246 | - * @return string sql. | |
| 247 | - */ | |
| 248 | - public static function hook_get_sql_websites_for_current_user( $input_value, $pluginFile, $key, $params ) { | |
| 249 | - unset( $input_value ); | |
| 250 | - if ( ! MainWP_Extensions_Handler::hook_verify( $pluginFile, $key ) ) { | |
| 251 | - return false; | |
| 252 | - } | |
| 253 | - return MainWP_DB::instance()->get_sql_wp_for_current_user( $params ); | |
| 254 | - } | |
| 255 | - /** | |
| 256 | - * Method handle_manage_sites_screen_settings() | |
| 257 | - * | |
| 258 | - * Handle manage sites screen settings | |
| 259 | - */ | |
| 260 | - public function handle_manage_sites_screen_settings() { // phpcs:ignore -- NOSONAR - required to achieve desired results, pull request solutions appreciated. | |
| 261 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) { | |
| 262 | - $show_cols = array(); | |
| 263 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 264 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 265 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 266 | - $show_cols[ $col ] = 1; | |
| 267 | - } | |
| 268 | - } | |
| 269 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 270 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 271 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 272 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 273 | - } | |
| 274 | - } | |
| 275 | - } | |
| 276 | - MainWP_Utility::update_option( 'mainwp_use_favicon', 1 ); | |
| 277 | - MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) ); | |
| 278 | - $user = wp_get_current_user(); | |
| 279 | - if ( $user ) { | |
| 280 | - $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 281 | - if ( 'grid' !== $val && 'table' !== $val ) { | |
| 282 | - $val = 'grid'; | |
| 283 | - } | |
| 284 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 285 | - update_user_option( $user->ID, 'mainwp_settings_show_manage_sites_columns', $show_cols, true ); | |
| 286 | - update_option( 'mainwp_default_sites_per_page', ( isset( $_POST['mainwp_default_sites_per_page'] ) ? intval( $_POST['mainwp_default_sites_per_page'] ) : 25 ) ); | |
| 287 | - } | |
| 288 | - } elseif ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SreenshotsSitesScrOptions' ) ) { | |
| 289 | - $user = wp_get_current_user(); | |
| 290 | - if ( $user ) { | |
| 291 | - $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 292 | - if ( 'grid' !== $val && 'table' !== $val ) { | |
| 293 | - $val = 'grid'; | |
| 294 | - } | |
| 295 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 296 | - } | |
| 297 | - } | |
| 298 | - } | |
| 277 | + $user = wp_get_current_user(); | |
| 278 | + if ( $user ) { | |
| 279 | + update_user_option( $user->ID, 'mainwp_settings_show_monitoring_sites_columns', $show_cols, true ); | |
| 280 | + update_option( 'mainwp_default_monitoring_sites_per_page', ( isset( $_POST['mainwp_default_monitoring_sites_per_page'] ) ? intval( $_POST['mainwp_default_monitoring_sites_per_page'] ) : 25 ) ); | |
| 281 | + } | |
| 282 | + } | |
| 283 | + } | |
| 299 | 284 | |
| 300 | - /** | |
| 301 | - * Method handle_monitoring_sites_screen_settings() | |
| 302 | - * | |
| 303 | - * Handle monitoring sites screen settings | |
| 304 | - */ | |
| 305 | - public function handle_monitoring_sites_screen_settings() { // phpcs:ignore -- NOSONAR - complex. | |
| 306 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MonitoringSitesScrOptions' ) ) { | |
| 307 | - $show_cols = array(); | |
| 308 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 309 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 310 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 311 | - $show_cols[ $col ] = 1; | |
| 312 | - } | |
| 313 | - } | |
| 314 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 315 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 316 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 317 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 318 | - } | |
| 319 | - } | |
| 320 | - } | |
| 285 | + /** | |
| 286 | + * Method handle_clients_screen_settings() | |
| 287 | + * | |
| 288 | + * Handle manage clients screen settings | |
| 289 | + */ | |
| 290 | + public function handle_clients_screen_settings() { | |
| 291 | + if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageClientsScrOptions' ) ) { | |
| 292 | + $show_cols = array(); | |
| 293 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 294 | + if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 295 | + $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 296 | + $show_cols[ $col ] = 1; | |
| 297 | + } | |
| 298 | + } | |
| 299 | + if ( isset( $_POST['show_columns_name'] ) ) { | |
| 300 | + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 301 | + if ( ! isset( $show_cols[ $col ] ) ) { | |
| 302 | + $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 303 | + } | |
| 304 | + } | |
| 305 | + } | |
| 321 | 306 | |
| 322 | - $user = wp_get_current_user(); | |
| 323 | - if ( $user ) { | |
| 324 | - update_user_option( $user->ID, 'mainwp_settings_show_monitoring_sites_columns', $show_cols, true ); | |
| 325 | - update_option( 'mainwp_default_monitoring_sites_per_page', ( isset( $_POST['mainwp_default_monitoring_sites_per_page'] ) ? intval( $_POST['mainwp_default_monitoring_sites_per_page'] ) : 25 ) ); | |
| 326 | - } | |
| 307 | + $user = wp_get_current_user(); | |
| 308 | + if ( $user ) { | |
| 309 | + update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true ); | |
| 310 | + update_option( 'mainwp_default_manage_clients_per_page', ( isset( $_POST['mainwp_default_manage_clients_per_page'] ) ? intval( $_POST['mainwp_default_manage_clients_per_page'] ) : 25 ) ); | |
| 311 | + } | |
| 312 | + } | |
| 313 | + } | |
| 327 | 314 | |
| 328 | - update_option( 'mainwp_disableSitesChecking', ( ! isset( $_POST['mainwp_disableSitesChecking'] ) ? 1 : 0 ) ); | |
| 329 | 315 | |
| 330 | - $val = isset( $_POST['mainwp_frequency_sitesChecking'] ) ? intval( $_POST['mainwp_frequency_sitesChecking'] ) : 1440; | |
| 331 | - update_option( 'mainwp_frequencySitesChecking', $val ); | |
| 316 | + /** | |
| 317 | + * Method handle_mainwp_tools_settings() | |
| 318 | + * | |
| 319 | + * Handle mainwp tools settings. | |
| 320 | + * | |
| 321 | + * @uses \MainWP\Dashboard\MainWP_Twitter::clear_all_twitter_messages() | |
| 322 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 323 | + */ | |
| 324 | + public function handle_mainwp_tools_settings() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 332 | 325 | |
| 333 | - update_option( 'mainwp_disableSitesHealthMonitoring', ( ! isset( $_POST['mainwp_disable_sitesHealthMonitoring'] ) ? 1 : 0 ) ); | |
| 326 | + $user = wp_get_current_user(); | |
| 334 | 327 | |
| 335 | - $val = isset( $_POST['mainwp_site_healthThreshold'] ) ? intval( $_POST['mainwp_site_healthThreshold'] ) : 80; | |
| 336 | - update_option( 'mainwp_sitehealthThreshold', $val ); | |
| 337 | - } | |
| 338 | - } | |
| 328 | + $update_selected_mainwp_themes = false; | |
| 339 | 329 | |
| 340 | - /** | |
| 341 | - * Method handle_clients_screen_settings() | |
| 342 | - * | |
| 343 | - * Handle manage clients screen settings | |
| 344 | - */ | |
| 345 | - public function handle_clients_screen_settings() { // phpcs:ignore -- NOSONAR - complex. | |
| 346 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageClientsScrOptions' ) ) { | |
| 347 | - $show_cols = array(); | |
| 348 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 349 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 350 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 351 | - $show_cols[ $col ] = 1; | |
| 352 | - } | |
| 353 | - } | |
| 354 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 355 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 356 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 357 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 358 | - } | |
| 359 | - } | |
| 360 | - } | |
| 330 | + if ( isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] ) { | |
| 331 | + if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) { | |
| 332 | + if ( isset( $_POST['mainwp_restore_info_messages'] ) && ! empty( $_POST['mainwp_restore_info_messages'] ) ) { | |
| 333 | + delete_user_option( $user->ID, 'mainwp_notice_saved_status' ); | |
| 334 | + } else { | |
| 335 | + MainWP_Utility::update_option( 'mainwp_enable_managed_cr_for_wc', ( ! isset( $_POST['enable_managed_cr_for_wc'] ) ? 0 : 1 ) ); | |
| 336 | + $enabled_twit = ! isset( $_POST['mainwp_hide_twitters_message'] ) ? 0 : 1; | |
| 337 | + MainWP_Utility::update_option( 'mainwp_hide_twitters_message', $enabled_twit ); | |
| 338 | + if ( ! $enabled_twit ) { | |
| 339 | + MainWP_Twitter::clear_all_twitter_messages(); | |
| 340 | + } | |
| 341 | + } | |
| 361 | 342 | |
| 362 | - $user = wp_get_current_user(); | |
| 363 | - if ( $user ) { | |
| 364 | - update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true ); | |
| 365 | - update_option( 'mainwp_default_manage_clients_per_page', ( isset( $_POST['mainwp_default_manage_clients_per_page'] ) ? intval( $_POST['mainwp_default_manage_clients_per_page'] ) : 25 ) ); | |
| 366 | - } | |
| 367 | - } | |
| 368 | - } | |
| 343 | + if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 344 | + $update_selected_mainwp_themes = true; | |
| 345 | + } | |
| 346 | + } | |
| 347 | + } | |
| 369 | 348 | |
| 370 | - /** | |
| 371 | - * Method handle_clients_screen_settings() | |
| 372 | - * | |
| 373 | - * Handle manage clients screen settings | |
| 374 | - */ | |
| 375 | - public function handle_updates_screen_settings() { | |
| 376 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'UpdatesScrOptions' ) ) { | |
| 377 | - $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ); | |
| 378 | - MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val ); | |
| 379 | - $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ); | |
| 380 | - MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val ); | |
| 381 | - $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) ); | |
| 382 | - MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val ); | |
| 383 | - $val = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 ); | |
| 384 | - MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $val ); | |
| 385 | - $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 ); | |
| 386 | - MainWP_Utility::update_option( 'mainwp_show_language_updates', $val ); | |
| 387 | - $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) ); | |
| 388 | - MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val ); | |
| 389 | - } | |
| 390 | - } | |
| 349 | + if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPSelectThemes' ) ) { | |
| 350 | + $update_selected_mainwp_themes = true; | |
| 351 | + } | |
| 391 | 352 | |
| 353 | + if ( $update_selected_mainwp_themes ) { | |
| 354 | + if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 355 | + $custom_theme = sanitize_text_field( wp_unslash( $_POST['mainwp_settings_custom_theme'] ) ); | |
| 356 | + update_user_option( $user->ID, 'mainwp_selected_theme', $custom_theme ); | |
| 357 | + } | |
| 358 | + } | |
| 392 | 359 | |
| 393 | - /** | |
| 394 | - * Method handle_mainwp_tools_settings() | |
| 395 | - * | |
| 396 | - * Handle mainwp tools settings. | |
| 397 | - * | |
| 398 | - * @uses \MainWP\Dashboard\MainWP_Twitter::clear_all_twitter_messages() | |
| 399 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 400 | - */ | |
| 401 | - public function handle_mainwp_tools_settings() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 360 | + $update_screen_options = false; | |
| 361 | + if ( isset( $_POST['wp_nonce'] ) && ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) || wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) ) { | |
| 362 | + $update_screen_options = true; | |
| 363 | + } | |
| 402 | 364 | |
| 403 | - $user = wp_get_current_user(); | |
| 365 | + if ( $update_screen_options ) { | |
| 366 | + $show_wids = array(); | |
| 367 | + if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 368 | + $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 369 | + foreach ( $selected_wids as $name ) { | |
| 370 | + $show_wids[ $name ] = 1; | |
| 371 | + } | |
| 372 | + } | |
| 404 | 373 | |
| 405 | - $update_selected_mainwp_themes = false; | |
| 374 | + if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 375 | + $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 376 | + foreach ( $name_wids as $name ) { | |
| 377 | + if ( ! isset( $show_wids[ $name ] ) ) { | |
| 378 | + $show_wids[ $name ] = 0; | |
| 379 | + } | |
| 380 | + } | |
| 381 | + } | |
| 406 | 382 | |
| 407 | - if ( isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) { | |
| 408 | - if ( isset( $_POST['mainwp_restore_info_messages'] ) && ! empty( $_POST['mainwp_restore_info_messages'] ) ) { | |
| 409 | - delete_user_option( $user->ID, 'mainwp_notice_saved_status' ); | |
| 410 | - } | |
| 411 | - $enabled_tours = ! isset( $_POST['mainwp-guided-tours-option'] ) ? 0 : 1; | |
| 412 | - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enabled_tours ); | |
| 383 | + $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 ); | |
| 384 | + if ( $user ) { | |
| 385 | + update_user_option( $user->ID, 'mainwp_settings_show_widgets', $show_wids, true ); | |
| 386 | + update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 387 | + } | |
| 413 | 388 | |
| 414 | - if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 415 | - $update_selected_mainwp_themes = true; | |
| 416 | - } | |
| 417 | - } | |
| 389 | + MainWP_Utility::update_option( 'mainwp_hide_update_everything', ( ! isset( $_POST['hide_update_everything'] ) ? 0 : 1 ) ); | |
| 390 | + MainWP_Utility::update_option( 'mainwp_number_overview_columns', ( isset( $_POST['number_overview_columns'] ) ? intval( $_POST['number_overview_columns'] ) : 2 ) ); | |
| 418 | 391 | |
| 419 | - if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPSelectThemes' ) ) { | |
| 420 | - $update_selected_mainwp_themes = true; | |
| 421 | - } | |
| 392 | + if ( isset( $_POST['reset_overview_settings'] ) && ! empty( $_POST['reset_overview_settings'] ) && isset( $_POST['reset_overview_which_settings'] ) && 'overview_settings' == $_POST['reset_overview_which_settings'] ) { | |
| 393 | + update_user_option( $user->ID, 'mainwp_widgets_sorted_toplevel_page_mainwp_tab', false, true ); | |
| 394 | + update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_managesites', false, true ); | |
| 395 | + } | |
| 396 | + } | |
| 422 | 397 | |
| 423 | - if ( $update_selected_mainwp_themes && isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 424 | - $custom_theme = sanitize_text_field( wp_unslash( $_POST['mainwp_settings_custom_theme'] ) ); | |
| 425 | - update_user_option( $user->ID, 'mainwp_selected_theme', $custom_theme ); | |
| 426 | - } | |
| 398 | + $update_clients_screen_options = false; | |
| 399 | + if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPClientsScrOptions' ) ) { | |
| 400 | + $update_clients_screen_options = true; | |
| 401 | + } | |
| 402 | + if ( $update_clients_screen_options ) { | |
| 427 | 403 | |
| 428 | - $update_screen_options = false; | |
| 429 | - if ( isset( $_POST['wp_nonce'] ) && ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) || wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) ) { | |
| 430 | - $update_screen_options = true; | |
| 431 | - } | |
| 404 | + $show_wids = array(); | |
| 405 | + if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 406 | + $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 407 | + foreach ( $selected_wids as $name ) { | |
| 408 | + $show_wids[ $name ] = 1; | |
| 409 | + } | |
| 410 | + } | |
| 432 | 411 | |
| 433 | - if ( $update_screen_options ) { | |
| 434 | - $show_wids = array(); | |
| 435 | - if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 436 | - $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 437 | - foreach ( $selected_wids as $name ) { | |
| 438 | - $show_wids[ $name ] = 1; | |
| 439 | - } | |
| 440 | - } | |
| 412 | + if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 413 | + $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 414 | + foreach ( $name_wids as $name ) { | |
| 415 | + if ( ! isset( $show_wids[ $name ] ) ) { | |
| 416 | + $show_wids[ $name ] = 0; | |
| 417 | + } | |
| 418 | + } | |
| 419 | + } | |
| 441 | 420 | |
| 442 | - if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 443 | - $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 444 | - foreach ( $name_wids as $name ) { | |
| 445 | - if ( ! isset( $show_wids[ $name ] ) ) { | |
| 446 | - $show_wids[ $name ] = 0; | |
| 447 | - } | |
| 448 | - } | |
| 449 | - } | |
| 421 | + if ( $user ) { | |
| 422 | + update_user_option( $user->ID, 'mainwp_clients_show_widgets', $show_wids, true ); | |
| 423 | + } | |
| 450 | 424 | |
| 451 | - $show_cols = array(); | |
| 452 | - if ( isset( $_POST['mainwp_show_columns'] ) && is_array( $_POST['mainwp_show_columns'] ) ) { | |
| 453 | - $selected_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_columns'] ) ); | |
| 454 | - foreach ( $selected_cols as $name ) { | |
| 455 | - $show_cols[ $name ] = 1; | |
| 456 | - } | |
| 457 | - } | |
| 425 | + MainWP_Utility::update_option( 'mainwp_number_clients_overview_columns', ( isset( $_POST['number_overview_columns'] ) ? intval( $_POST['number_overview_columns'] ) : 2 ) ); | |
| 458 | 426 | |
| 459 | - if ( isset( $_POST['mainwp_columns_name'] ) && is_array( $_POST['mainwp_columns_name'] ) ) { | |
| 460 | - $name_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_columns_name'] ) ); | |
| 461 | - foreach ( $name_cols as $name ) { | |
| 462 | - if ( ! isset( $show_cols[ $name ] ) ) { | |
| 463 | - $show_cols[ $name ] = 0; | |
| 464 | - } | |
| 465 | - } | |
| 466 | - } | |
| 427 | + if ( isset( $_POST['reset_client_overview_settings'] ) && ! empty( $_POST['reset_client_overview_settings'] ) ) { | |
| 428 | + update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_manageclients', false, true ); | |
| 429 | + } | |
| 430 | + } | |
| 431 | + } | |
| 467 | 432 | |
| 468 | - $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 ); | |
| 469 | - if ( $user ) { | |
| 470 | - update_user_option( $user->ID, 'mainwp_settings_show_widgets', $show_wids, true ); | |
| 471 | - update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 472 | 433 | |
| 473 | - if ( isset( $_POST['mainwp_manageposts_show_columns_settings'] ) ) { | |
| 474 | - update_user_option( $user->ID, 'mainwp_manageposts_show_columns', $show_cols, true ); | |
| 475 | - } | |
| 434 | + /** | |
| 435 | + * Method handle_rest_api_settings() | |
| 436 | + * | |
| 437 | + * Handle rest api settings | |
| 438 | + */ | |
| 439 | + public function handle_rest_api_settings() { | |
| 440 | + if ( isset( $_POST['submit'] ) && isset( $_GET['page'] ) && 'RESTAPI' === $_GET['page'] ) { | |
| 441 | + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'RESTAPI' ) ) { | |
| 442 | + MainWP_Utility::update_option( 'mainwp_enable_rest_api', ( ! isset( $_POST['mainwp_enable_rest_api'] ) ? 0 : 1 ) ); | |
| 476 | 443 | |
| 477 | - if ( isset( $_POST['mainwp_managepages_show_columns_settings'] ) ) { | |
| 478 | - update_user_option( $user->ID, 'mainwp_managepages_show_columns', $show_cols, true ); | |
| 479 | - } | |
| 444 | + } | |
| 445 | + } | |
| 446 | + } | |
| 480 | 447 | |
| 481 | - if ( isset( $_POST['mainwp_manageusers_show_columns_settings'] ) ) { | |
| 482 | - update_user_option( $user->ID, 'mainwp_manageusers_show_columns', $show_cols, true ); | |
| 483 | - } | |
| 484 | - } | |
| 448 | + /** | |
| 449 | + * Method handle_settings_post() | |
| 450 | + * | |
| 451 | + * Handle saving settings page. | |
| 452 | + * | |
| 453 | + * @uses \MainWP\Dashboard\MainWP_Backup_Handler::handle_settings_post() | |
| 454 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 455 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 456 | + * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_settings_post() | |
| 457 | + * @uses \MainWP\Dashboard\MainWP_Settings::handle_settings_post() | |
| 458 | + */ | |
| 459 | + public function handle_settings_post() { | |
| 460 | + if ( isset( $_GET['page'] ) && ( isset( $_POST['wp_nonce'] ) || isset( $_POST['wp_scr_options_nonce'] ) ) ) { | |
| 461 | + $this->include_pluggable(); | |
| 462 | + $this->handle_mainwp_tools_settings(); | |
| 463 | + $this->handle_rest_api_settings(); | |
| 464 | + $this->handle_manage_sites_screen_settings(); | |
| 465 | + $this->handle_monitoring_sites_screen_settings(); | |
| 466 | + $this->handle_clients_screen_settings(); | |
| 467 | + } | |
| 485 | 468 | |
| 486 | - MainWP_Utility::update_option( 'mainwp_hide_update_everything', ( ! isset( $_POST['hide_update_everything'] ) ? 0 : 1 ) ); | |
| 469 | + if ( isset( $_POST['select_mainwp_options_siteview'] ) ) { | |
| 470 | + $this->include_pluggable(); | |
| 471 | + if ( check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 472 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 473 | + $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) ); | |
| 474 | + MainWP_DB_Common::instance()->update_user_extension( $userExtension ); | |
| 475 | + } | |
| 476 | + } | |
| 487 | 477 | |
| 488 | - if ( isset( $_POST['reset_overview_settings'] ) && ! empty( $_POST['reset_overview_settings'] ) && isset( $_POST['reset_overview_which_settings'] ) && 'overview_settings' === $_POST['reset_overview_which_settings'] ) { | |
| 489 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_toplevel_page_mainwp_tab', false, true ); | |
| 490 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_managesites', false, true ); | |
| 491 | - } | |
| 492 | - } | |
| 478 | + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) ) { | |
| 479 | + $this->include_pluggable(); | |
| 480 | + if ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) { | |
| 481 | + $updated = MainWP_Settings::handle_settings_post(); | |
| 482 | + $updated |= MainWP_Backup_Handler::handle_settings_post(); | |
| 483 | + $updated |= MainWP_Monitoring_Handler::handle_settings_post(); | |
| 484 | + $msg = ''; | |
| 485 | + if ( $updated ) { | |
| 486 | + $msg = '&message=saved'; | |
| 487 | + } | |
| 488 | + wp_safe_redirect( admin_url( 'admin.php?page=Settings' . $msg ) ); | |
| 489 | + exit(); | |
| 490 | + } | |
| 491 | + } | |
| 493 | 492 | |
| 494 | - $update_clients_screen_options = false; | |
| 495 | - if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPClientsScrOptions' ) ) { | |
| 496 | - $update_clients_screen_options = true; | |
| 497 | - } | |
| 498 | - if ( $update_clients_screen_options ) { | |
| 493 | + if ( isset( $_POST['mainwp_sidebar_position'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'onchange_sidebarposition' ) ) { | |
| 494 | + $val = isset( $_POST['mainwp_sidebar_position'] ) && $_POST['mainwp_sidebar_position'] ? 1 : 0; | |
| 495 | + $user = wp_get_current_user(); | |
| 496 | + if ( $user ) { | |
| 497 | + update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 498 | + } | |
| 499 | + return true; | |
| 500 | + } | |
| 499 | 501 | |
| 500 | - $show_wids = array(); | |
| 501 | - if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 502 | - $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 503 | - foreach ( $selected_wids as $name ) { | |
| 504 | - $show_wids[ $name ] = 1; | |
| 505 | - } | |
| 506 | - } | |
| 502 | + if ( isset( $_GET['viewmode'] ) && isset( $_GET['modenonce'] ) ) { | |
| 503 | + $viewmode = sanitize_text_field( wp_unslash( $_GET['viewmode'] ) ); | |
| 504 | + $nonce = sanitize_key( $_GET['modenonce'] ); | |
| 505 | + if ( ( 'table' === $viewmode || 'grid' === $viewmode ) && wp_verify_nonce( sanitize_key( $nonce ), 'viewmode' ) ) { | |
| 506 | + $user = wp_get_current_user(); | |
| 507 | + if ( $user ) { | |
| 508 | + update_user_option( $user->ID, 'mainwp_sitesviewmode', $viewmode, true ); | |
| 509 | + wp_safe_redirect( admin_url( 'admin.php?page=managesites' ) ); | |
| 510 | + exit; | |
| 511 | + } | |
| 512 | + } | |
| 513 | + } | |
| 514 | + } | |
| 507 | 515 | |
| 508 | - if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 509 | - $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 510 | - foreach ( $name_wids as $name ) { | |
| 511 | - if ( ! isset( $show_wids[ $name ] ) ) { | |
| 512 | - $show_wids[ $name ] = 0; | |
| 513 | - } | |
| 514 | - } | |
| 515 | - } | |
| 516 | + /** | |
| 517 | + * Method include_pluggable() | |
| 518 | + * | |
| 519 | + * Include pluggable functions. | |
| 520 | + */ | |
| 521 | + public function include_pluggable() { | |
| 522 | + // may causing of conflict with Post S m t p plugin. | |
| 523 | + if ( ! function_exists( 'wp_create_nonce' ) ) { | |
| 524 | + include_once ABSPATH . WPINC . '/pluggable.php'; | |
| 525 | + } | |
| 526 | + } | |
| 516 | 527 | |
| 517 | - if ( $user ) { | |
| 518 | - update_user_option( $user->ID, 'mainwp_clients_show_widgets', $show_wids, true ); | |
| 519 | - } | |
| 528 | + /** | |
| 529 | + * Method plugins_api_info() | |
| 530 | + * | |
| 531 | + * Get MainWP Extension api information. | |
| 532 | + * | |
| 533 | + * @param mixed $false Return value. | |
| 534 | + * @param mixed $action Action being performed. | |
| 535 | + * @param mixed $arg Action arguments. Should be the plugin slug. | |
| 536 | + * | |
| 537 | + * @return mixed $info|$false | |
| 538 | + * | |
| 539 | + * @uses \MainWP\Dashboard\MainWP_API_Handler::get_update_information() | |
| 540 | + * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions() | |
| 541 | + * @uses \MainWP\Dashboard\MainWP_System::get_plugin_slug() | |
| 542 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_slugs() | |
| 543 | + */ | |
| 544 | + public function plugins_api_info( $false, $action, $arg ) { | |
| 545 | + if ( 'plugin_information' !== $action ) { | |
| 546 | + return $false; | |
| 547 | + } | |
| 520 | 548 | |
| 521 | - if ( isset( $_POST['reset_client_overview_settings'] ) && ! empty( $_POST['reset_client_overview_settings'] ) ) { | |
| 522 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_manageclients', false, true ); | |
| 523 | - } | |
| 524 | - } | |
| 525 | - } | |
| 549 | + if ( is_array( $arg ) ) { | |
| 550 | + $arg = (object) $arg; | |
| 551 | + } | |
| 526 | 552 | |
| 527 | - /** | |
| 528 | - * Method handle_settings_post() | |
| 529 | - * | |
| 530 | - * Handle saving settings page. | |
| 531 | - * | |
| 532 | - * @uses \MainWP\Dashboard\MainWP_Backup_Handler::handle_settings_post() | |
| 533 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 534 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 535 | - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_settings_post() | |
| 536 | - * @uses \MainWP\Dashboard\MainWP_Settings::handle_settings_post() | |
| 537 | - */ | |
| 538 | - public function handle_settings_post() { // phpcs:ignore -- NOSONAR - complex method. | |
| 553 | + if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) { | |
| 554 | + return $false; | |
| 555 | + } | |
| 539 | 556 | |
| 540 | - if ( isset( $_GET['page'] ) && ( isset( $_POST['wp_nonce'] ) || isset( $_POST['wp_scr_options_nonce'] ) ) ) { | |
| 541 | - $this->include_pluggable(); | |
| 542 | - $this->handle_mainwp_tools_settings(); | |
| 543 | - $this->handle_manage_sites_screen_settings(); | |
| 544 | - $this->handle_monitoring_sites_screen_settings(); | |
| 545 | - $this->handle_clients_screen_settings(); | |
| 546 | - $this->handle_updates_screen_settings(); | |
| 547 | - } | |
| 557 | + if ( dirname( MainWP_System::instance()->get_plugin_slug() ) === $arg->slug ) { | |
| 558 | + return $false; | |
| 559 | + } | |
| 548 | 560 | |
| 549 | - if ( isset( $_POST['select_mainwp_options_siteview'] ) ) { | |
| 550 | - $this->include_pluggable(); | |
| 551 | - if ( check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 552 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 553 | - $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) ); | |
| 554 | - MainWP_DB_Common::instance()->update_user_extension( $userExtension ); | |
| 555 | - } | |
| 556 | - } | |
| 561 | + $result = MainWP_Extensions_Handler::get_slugs(); | |
| 562 | + $am_slugs = $result['am_slugs']; | |
| 557 | 563 | |
| 558 | - if ( isset( $_POST['select_mainwp_options_plugintheme_view'] ) ) { | |
| 559 | - $this->include_pluggable(); | |
| 560 | - if ( check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 561 | - $view_per = ( empty( $_POST['select_mainwp_options_plugintheme_view'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_plugintheme_view'] ) ); | |
| 562 | - $which = isset( $_POST['whichview'] ) ? sanitize_text_field( wp_unslash( $_POST['whichview'] ) ) : ''; | |
| 563 | - if ( 'plugin' === $which ) { | |
| 564 | - MainWP_Utility::update_user_option( 'mainwp_manage_plugin_view', $view_per ); | |
| 565 | - } else { | |
| 566 | - MainWP_Utility::update_user_option( 'mainwp_manage_theme_view', $view_per ); | |
| 567 | - } | |
| 568 | - } | |
| 569 | - } | |
| 564 | + if ( '' !== $am_slugs ) { | |
| 565 | + $am_slugs = explode( ',', $am_slugs ); | |
| 566 | + if ( false !== strpos( $arg->slug, '/' ) ) { // to fix. | |
| 567 | + $dir_slug = dirname( $arg->slug ); | |
| 568 | + } else { | |
| 569 | + $dir_slug = $arg->slug; | |
| 570 | + } | |
| 571 | + if ( in_array( $dir_slug, $am_slugs ) ) { | |
| 572 | + $info = MainWP_API_Handler::get_update_information( $dir_slug ); | |
| 573 | + if ( is_object( $info ) && property_exists( $info, 'sections' ) ) { | |
| 574 | + if ( ! is_array( $info->sections ) || ! isset( $info->sections['changelog'] ) || empty( $info->sections['changelog'] ) ) { | |
| 575 | + $exts_data = MainWP_Extensions_View::get_available_extensions(); | |
| 576 | + if ( isset( $exts_data[ $arg->slug ] ) ) { | |
| 577 | + $ext_info = $exts_data[ $arg->slug ]; | |
| 578 | + $changelog_link = rtrim( $ext_info['link'], '/' ); | |
| 579 | + $info->sections['changelog'] = '<a href="' . $changelog_link . '#tab-changelog" target="_blank">' . $changelog_link . '#tab-changelog</a>'; | |
| 580 | + } | |
| 581 | + } | |
| 582 | + return $info; | |
| 583 | + } | |
| 584 | + return $info; | |
| 585 | + } | |
| 586 | + } | |
| 570 | 587 | |
| 571 | - if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) ) { | |
| 572 | - $this->include_pluggable(); | |
| 573 | - if ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) { | |
| 574 | - $updated = MainWP_Settings::handle_settings_post(); | |
| 575 | - $updated |= MainWP_Backup_Handler::handle_settings_post(); | |
| 576 | - $updated |= MainWP_Monitoring_Handler::handle_settings_post(); | |
| 577 | - $msg = ''; | |
| 578 | - if ( $updated ) { | |
| 579 | - $msg = '&message=saved'; | |
| 580 | - } | |
| 581 | - wp_safe_redirect( admin_url( 'admin.php?page=Settings' . $msg ) ); | |
| 582 | - exit(); | |
| 583 | - } | |
| 584 | - } | |
| 588 | + return $false; | |
| 589 | + } | |
| 585 | 590 | |
| 586 | - if ( isset( $_POST['mainwp_sidebar_position'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'onchange_sidebarposition' ) ) { | |
| 587 | - $val = isset( $_POST['mainwp_sidebar_position'] ) && ! empty( $_POST['mainwp_sidebar_position'] ) ? 1 : 0; | |
| 588 | - $user = wp_get_current_user(); | |
| 589 | - if ( $user ) { | |
| 590 | - update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 591 | - } | |
| 592 | - return true; | |
| 593 | - } | |
| 591 | + /** | |
| 592 | + * Method check_update_custom() | |
| 593 | + * | |
| 594 | + * Check MainWP Extensions for updates. | |
| 595 | + * | |
| 596 | + * @param object $transient Transient information. | |
| 597 | + * | |
| 598 | + * @return object $transient Transient information. | |
| 599 | + * | |
| 600 | + * @uses \MainWP\Dashboard\MainWP_API_Handler::get_upgrade_information() | |
| 601 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 602 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 603 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 604 | + */ | |
| 605 | + public function check_update_custom( $transient ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 606 | + if ( isset( $_POST['action'] ) && ( ( 'update-plugin' === $_POST['action'] ) || ( 'update-selected' === $_POST['action'] ) ) && is_object( $transient ) && property_exists( $transient, 'response' ) ) { | |
| 607 | + $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); | |
| 608 | + if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' == $_POST['action'] ) { | |
| 594 | 609 | |
| 595 | - if ( isset( $_GET['viewmode'] ) && isset( $_GET['modenonce'] ) ) { | |
| 596 | - $viewmode = sanitize_text_field( wp_unslash( $_GET['viewmode'] ) ); | |
| 597 | - $nonce = sanitize_key( $_GET['modenonce'] ); | |
| 598 | - if ( ( 'table' === $viewmode || 'grid' === $viewmode ) && wp_verify_nonce( sanitize_key( $nonce ), 'viewmode' ) ) { | |
| 599 | - $user = wp_get_current_user(); | |
| 600 | - if ( $user ) { | |
| 601 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $viewmode, true ); | |
| 602 | - wp_safe_redirect( admin_url( 'admin.php?page=managesites' ) ); | |
| 603 | - exit; | |
| 604 | - } | |
| 605 | - } | |
| 606 | - } | |
| 607 | - } | |
| 610 | + if ( empty( $transient->response ) ) { | |
| 611 | + $transient->response = array(); | |
| 612 | + } | |
| 608 | 613 | |
| 609 | - /** | |
| 610 | - * Method include_pluggable() | |
| 611 | - * | |
| 612 | - * Include pluggable functions. | |
| 613 | - */ | |
| 614 | - public function include_pluggable() { | |
| 615 | - // may causing of conflict with Post S m t p plugin. | |
| 616 | - if ( ! function_exists( 'wp_create_nonce' ) ) { | |
| 617 | - include_once ABSPATH . WPINC . '/pluggable.php'; // NOSONAR - WP compatible. | |
| 618 | - } | |
| 619 | - } | |
| 614 | + $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); | |
| 615 | + if ( isset( $extensions[ $plugin_slug ] ) ) { | |
| 620 | 616 | |
| 621 | - /** | |
| 622 | - * Method plugins_api_extension_info() | |
| 623 | - * | |
| 624 | - * Get MainWP Extension api information. | |
| 625 | - * | |
| 626 | - * @param mixed $input_value Return value. | |
| 627 | - * @param mixed $action Action being performed. | |
| 628 | - * @param mixed $arg Action arguments. Should be the plugin slug. | |
| 629 | - * | |
| 630 | - * @return mixed $info|$input_value | |
| 631 | - * | |
| 632 | - * @uses \MainWP\Dashboard\MainWP_API_Handler::get_update_information() | |
| 633 | - * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions() | |
| 634 | - * @uses \MainWP\Dashboard\MainWP_System::get_plugin_slug() | |
| 635 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_slugs() | |
| 636 | - */ | |
| 637 | - public function plugins_api_extension_info( $input_value, $action, $arg ) { // phpcs:ignore -- NOSONAR - complex. | |
| 638 | - if ( 'plugin_information' !== $action ) { | |
| 639 | - return $input_value; | |
| 640 | - } | |
| 617 | + if ( ! is_object( $transient->response[ $plugin_slug ] ) || ! property_exists( $transient->response[ $plugin_slug ], 'new_version' ) ) { | |
| 618 | + return $transient; | |
| 619 | + } | |
| 641 | 620 | |
| 642 | - if ( is_array( $arg ) ) { | |
| 643 | - $arg = (object) $arg; | |
| 644 | - } | |
| 621 | + if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { | |
| 622 | + return $transient; | |
| 623 | + } | |
| 645 | 624 | |
| 646 | - if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) { | |
| 647 | - return $input_value; | |
| 648 | - } | |
| 625 | + $api_slug = dirname( $plugin_slug ); | |
| 626 | + $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); | |
| 649 | 627 | |
| 650 | - if ( dirname( MainWP_System::instance()->get_plugin_slug() ) === $arg->slug ) { | |
| 651 | - return $input_value; | |
| 652 | - } | |
| 628 | + if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'latest_version' ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 629 | + $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); | |
| 630 | + } | |
| 653 | 631 | |
| 654 | - $result = MainWP_Extensions_Handler::get_slugs(); | |
| 655 | - $am_slugs = $result['am_slugs']; | |
| 632 | + return $transient; | |
| 633 | + } | |
| 634 | + } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { | |
| 656 | 635 | |
| 657 | - if ( '' !== $am_slugs ) { | |
| 658 | - $am_slugs = explode( ',', $am_slugs ); | |
| 659 | - if ( false !== strpos( $arg->slug, '/' ) ) { // to fix. | |
| 660 | - $dir_slug = dirname( $arg->slug ); | |
| 661 | - } else { | |
| 662 | - $dir_slug = $arg->slug; | |
| 663 | - } | |
| 664 | - if ( in_array( $dir_slug, $am_slugs ) ) { | |
| 665 | - $info = MainWP_API_Handler::get_update_information( $dir_slug ); | |
| 666 | - if ( is_object( $info ) && property_exists( $info, 'sections' ) ) { | |
| 667 | - if ( ! is_array( $info->sections ) || ! isset( $info->sections['changelog'] ) || empty( $info->sections['changelog'] ) ) { | |
| 668 | - $exts_data = MainWP_Extensions_View::get_available_extensions(); | |
| 669 | - if ( isset( $exts_data[ $arg->slug ] ) ) { | |
| 670 | - $ext_info = $exts_data[ $arg->slug ]; | |
| 671 | - $changelog_link = rtrim( $ext_info['changelog_url'], '/' ); | |
| 672 | - $info->sections['changelog'] = '<a href="' . $changelog_link . '" target="_blank">' . $changelog_link . '</a>'; | |
| 673 | - } | |
| 674 | - } | |
| 675 | - return $info; | |
| 676 | - } | |
| 677 | - return $info; | |
| 678 | - } | |
| 679 | - } | |
| 636 | + if ( empty( $transient->response ) ) { | |
| 637 | + $transient->response = array(); | |
| 638 | + } | |
| 680 | 639 | |
| 681 | - return $input_value; | |
| 682 | - } | |
| 640 | + $updated = false; | |
| 641 | + foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { | |
| 642 | + if ( isset( $extensions[ $plugin_slug ] ) ) { | |
| 683 | 643 | |
| 684 | - /** | |
| 685 | - * Method plugins_api_wp_plugins_api_result() | |
| 686 | - * | |
| 687 | - * Hook after get plugins api information. | |
| 688 | - * | |
| 689 | - * @param mixed $res api information value. | |
| 690 | - * @param mixed $action Action being performed. | |
| 691 | - * @param mixed $arg Action arguments. Should be the plugin slug. | |
| 692 | - * | |
| 693 | - * @return mixed $res | |
| 694 | - */ | |
| 695 | - public function plugins_api_wp_plugins_api_result( $res, $action, $arg ) { // phpcs:ignore -- NOSONAR - complex. | |
| 644 | + if ( ! isset( $transient->response[ $plugin_slug ] ) ) { | |
| 645 | + $transient->response[ $plugin_slug ] = new \stdClass(); | |
| 646 | + } | |
| 696 | 647 | |
| 697 | - if ( 'plugin_information' !== $action ) { | |
| 698 | - return $res; | |
| 699 | - } | |
| 648 | + if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { | |
| 649 | + continue; | |
| 650 | + } | |
| 651 | + $api_slug = dirname( $plugin_slug ); | |
| 652 | + $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); | |
| 653 | + if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'latest_version' ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 700 | 654 | |
| 701 | - if ( is_object( $res ) && property_exists( $res, 'slug' ) && property_exists( $res, 'sections' ) ) { | |
| 702 | - return $res; | |
| 703 | - } | |
| 655 | + $this->upgradeVersionInfo->result[ $api_slug ] = $rslt; | |
| 656 | + $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); | |
| 657 | + $updated = true; | |
| 658 | + } | |
| 659 | + } | |
| 660 | + } | |
| 661 | + if ( $updated ) { | |
| 662 | + MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo ); | |
| 663 | + } | |
| 704 | 664 | |
| 705 | - if ( ! isset( $_GET['wpplugin'] ) || ! is_numeric( $_GET['wpplugin'] ) || empty( $_GET['wpplugin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 706 | - return $res; | |
| 707 | - } | |
| 665 | + return $transient; | |
| 666 | + } | |
| 667 | + } | |
| 708 | 668 | |
| 709 | - if ( is_array( $arg ) ) { | |
| 710 | - $arg = (object) $arg; | |
| 711 | - } | |
| 669 | + if ( empty( $transient->checked ) ) { | |
| 670 | + return $transient; | |
| 671 | + } | |
| 712 | 672 | |
| 713 | - if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) { | |
| 714 | - return $res; | |
| 715 | - } | |
| 673 | + if ( isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { | |
| 674 | + $this->check_upgrade(); | |
| 675 | + } | |
| 716 | 676 | |
| 717 | - $site_id = intval( $_GET['wpplugin'] ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 677 | + if ( null != $this->upgradeVersionInfo && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 678 | + foreach ( $this->upgradeVersionInfo->result as $rslt ) { | |
| 679 | + if ( ! isset( $rslt->slug ) ) { | |
| 680 | + continue; | |
| 681 | + } | |
| 718 | 682 | |
| 719 | - if ( $site_id ) { | |
| 720 | - $website = MainWP_DB::instance()->get_website_by_id( $site_id ); | |
| 721 | - if ( $website && ! empty( $website->plugin_upgrades ) ) { | |
| 722 | - $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 683 | + $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); | |
| 684 | + if ( isset( $transient->checked[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $transient->checked[ $plugin_slug ], '>' ) ) { | |
| 685 | + $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); | |
| 686 | + } | |
| 687 | + } | |
| 688 | + } | |
| 723 | 689 | |
| 724 | - if ( is_array( $plugin_upgrades ) ) { | |
| 725 | - $found_update = false; | |
| 726 | - $empty_sections = false; | |
| 727 | - foreach ( $plugin_upgrades as $plugin_slug => $info ) { | |
| 728 | - if ( false !== strpos( $plugin_slug, $arg->slug ) && isset( $info['update'] ) ) { | |
| 729 | - $found_update = true; | |
| 730 | - if ( isset( $info['update']['slug'] ) && $arg->slug === $info['update']['slug'] && isset( $info['update']['new_version'] ) && ! empty( $info['update']['new_version'] ) && isset( $info['update']['sections'] ) && ! empty( $info['update']['sections'] ) ) { | |
| 731 | - $info_update = (object) $info['update']; | |
| 732 | - $info_update->external = false; | |
| 733 | - return $info_update; | |
| 734 | - } | |
| 735 | - $empty_sections = true; | |
| 736 | - break; | |
| 737 | - } | |
| 738 | - } | |
| 690 | + return $transient; | |
| 691 | + } | |
| 739 | 692 | |
| 740 | - if ( $found_update && $empty_sections ) { | |
| 741 | - try { | |
| 742 | - $info = MainWP_Connect::fetch_url_authed( | |
| 743 | - $website, | |
| 744 | - 'plugin_action', | |
| 745 | - array( | |
| 746 | - 'action' => 'changelog_info', // try to get changelog from the child site. | |
| 747 | - 'slug' => $arg->slug, | |
| 748 | - ) | |
| 749 | - ); | |
| 750 | - if ( is_array( $info ) && isset( $info['update'] ) && ! empty( $info['update']['sections'] ) ) { | |
| 751 | - $info_update = (object) $info['update']; | |
| 752 | - $info_update->external = true; | |
| 753 | - return $info_update; | |
| 754 | - } | |
| 755 | - } catch ( \Exception $e ) { | |
| 756 | - // error happen. | |
| 757 | - } | |
| 758 | - } | |
| 759 | - } | |
| 760 | - } | |
| 761 | - } | |
| 762 | 693 | |
| 763 | - return $res; | |
| 764 | - } | |
| 694 | + /** | |
| 695 | + * Method map_rslt_obj() | |
| 696 | + * | |
| 697 | + * Map resulting object. | |
| 698 | + * | |
| 699 | + * @param object $result Resulting information. | |
| 700 | + * | |
| 701 | + * @return object $obj Mapped resulting object. | |
| 702 | + */ | |
| 703 | + public static function map_rslt_obj( $result ) { | |
| 704 | + $obj = new \stdClass(); | |
| 705 | + $obj->slug = $result->slug; | |
| 706 | + $obj->new_version = $result->latest_version; | |
| 707 | + $obj->url = 'https://mainwp.com/'; | |
| 708 | + $obj->package = $result->download_url; | |
| 765 | 709 | |
| 766 | - /** | |
| 767 | - * Method check_update_custom() | |
| 768 | - * | |
| 769 | - * Check MainWP Extensions for updates. | |
| 770 | - * | |
| 771 | - * @param object $transient Transient information. | |
| 772 | - * | |
| 773 | - * @return object $transient Transient information. | |
| 774 | - * | |
| 775 | - * @uses \MainWP\Dashboard\MainWP_API_Handler::get_upgrade_information() | |
| 776 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 777 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 778 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 779 | - */ | |
| 780 | - public function check_update_custom( $transient ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 781 | - if ( isset( $_POST['action'] ) && ( ( 'update-plugin' === $_POST['action'] ) || ( 'update-selected' === $_POST['action'] ) ) && is_object( $transient ) && property_exists( $transient, 'response' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 782 | - $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); | |
| 783 | - if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 710 | + return $obj; | |
| 711 | + } | |
| 784 | 712 | |
| 785 | - if ( empty( $transient->response ) ) { | |
| 786 | - $transient->response = array(); | |
| 787 | - } | |
| 713 | + /** | |
| 714 | + * Method check_upgrade() | |
| 715 | + * | |
| 716 | + * Check if Extension has an update. | |
| 717 | + * | |
| 718 | + * @uses \MainWP\Dashboard\MainWP_API_Handler::check_exts_upgrade() | |
| 719 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 720 | + */ | |
| 721 | + private function check_upgrade() { | |
| 722 | + $result = MainWP_API_Handler::check_exts_upgrade(); | |
| 723 | + if ( null == $this->upgradeVersionInfo ) { | |
| 724 | + $this->upgradeVersionInfo = new \stdClass(); | |
| 725 | + } | |
| 726 | + $this->upgradeVersionInfo->updated = time(); | |
| 727 | + if ( ! empty( $result ) ) { | |
| 728 | + $this->upgradeVersionInfo->result = $result; | |
| 729 | + } | |
| 730 | + MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo ); | |
| 731 | + } | |
| 788 | 732 | |
| 789 | - $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 790 | - if ( isset( $extensions[ $plugin_slug ] ) ) { | |
| 733 | + /** | |
| 734 | + * Method pre_check_update_custom() | |
| 735 | + * | |
| 736 | + * Pre-check for extension updates. | |
| 737 | + * | |
| 738 | + * @param object $transient Transient information. | |
| 739 | + * | |
| 740 | + * @return object $transient Transient information. | |
| 741 | + * | |
| 742 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 743 | + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 744 | + */ | |
| 745 | + public function pre_check_update_custom( $transient ) { | |
| 746 | + if ( ! isset( $transient->checked ) ) { | |
| 747 | + return $transient; | |
| 748 | + } | |
| 791 | 749 | |
| 792 | - if ( ! isset( $transient->response[ $plugin_slug ] ) || ! is_object( $transient->response[ $plugin_slug ] ) || ! property_exists( $transient->response[ $plugin_slug ], 'new_version' ) ) { | |
| 793 | - return $transient; | |
| 794 | - } | |
| 750 | + if ( ( null == $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) { | |
| 751 | + $this->check_upgrade(); | |
| 752 | + } | |
| 795 | 753 | |
| 796 | - if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { | |
| 797 | - return $transient; | |
| 798 | - } | |
| 754 | + if ( empty( $transient->response ) ) { | |
| 755 | + $transient->response = array(); | |
| 756 | + } | |
| 799 | 757 | |
| 800 | - $api_slug = dirname( $plugin_slug ); | |
| 801 | - $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); | |
| 758 | + if ( null != $this->upgradeVersionInfo && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 759 | + $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); | |
| 760 | + foreach ( $this->upgradeVersionInfo->result as $rslt ) { | |
| 761 | + $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); | |
| 762 | + if ( isset( $extensions[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 763 | + $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); | |
| 764 | + } | |
| 765 | + } | |
| 766 | + } | |
| 802 | 767 | |
| 803 | - if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 804 | - $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt ); | |
| 805 | - } | |
| 768 | + return $transient; | |
| 769 | + } | |
| 806 | 770 | |
| 807 | - return $transient; | |
| 808 | - } | |
| 809 | - } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 771 | + /** | |
| 772 | + * Method upload_file() | |
| 773 | + * | |
| 774 | + * Upload a file. | |
| 775 | + * | |
| 776 | + * @param mixed $file File to upload. | |
| 777 | + * | |
| 778 | + * @return void | |
| 779 | + * | |
| 780 | + * @uses \MainWP\Dashboard\MainWP_Utility::ends_with() | |
| 781 | + */ | |
| 782 | + public function upload_file( $file ) { | |
| 783 | + header( 'Content-Description: File Transfer' ); | |
| 784 | + if ( MainWP_Utility::ends_with( $file, '.tar.gz' ) ) { | |
| 785 | + header( 'Content-Type: application/x-gzip' ); | |
| 786 | + header( 'Content-Encoding: gzip' ); | |
| 787 | + } else { | |
| 788 | + header( 'Content-Type: application/octet-stream' ); | |
| 789 | + } | |
| 790 | + header( 'Content-Disposition: attachment; filename="' . basename( $file ) . '"' ); | |
| 791 | + header( 'Expires: 0' ); | |
| 792 | + header( 'Cache-Control: must-revalidate' ); | |
| 793 | + header( 'Pragma: public' ); | |
| 794 | + header( 'Content-Length: ' . filesize( $file ) ); | |
| 795 | + while ( ob_get_level() ) { | |
| 796 | + ob_end_clean(); | |
| 797 | + } | |
| 798 | + $this->readfile_chunked( $file ); | |
| 799 | + exit(); | |
| 800 | + } | |
| 810 | 801 | |
| 811 | - if ( empty( $transient->response ) ) { | |
| 812 | - $transient->response = array(); | |
| 813 | - } | |
| 802 | + /** | |
| 803 | + * Method readfile_chunked() | |
| 804 | + * | |
| 805 | + * Read Chunked File. | |
| 806 | + * | |
| 807 | + * @param mixed $filename Name of file. | |
| 808 | + * | |
| 809 | + * @return mixed echo $buffer|false|$handle. | |
| 810 | + */ | |
| 811 | + public function readfile_chunked( $filename ) { | |
| 812 | + $chunksize = 1024; | |
| 813 | + $handle = fopen( $filename, 'rb' ); | |
| 814 | + if ( false === $handle ) { | |
| 815 | + return false; | |
| 816 | + } | |
| 814 | 817 | |
| 815 | - $updated = false; | |
| 816 | - foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 817 | - if ( isset( $extensions[ $plugin_slug ] ) ) { | |
| 818 | + while ( ! feof( $handle ) ) { | |
| 819 | + $buffer = fread( $handle, $chunksize ); | |
| 820 | + echo $buffer; | |
| 821 | + if ( ob_get_length() ) { | |
| 822 | + ob_flush(); | |
| 823 | + flush(); | |
| 824 | + } | |
| 825 | + $buffer = null; | |
| 826 | + } | |
| 818 | 827 | |
| 819 | - if ( ! isset( $transient->response[ $plugin_slug ] ) ) { | |
| 820 | - $transient->response[ $plugin_slug ] = new \stdClass(); | |
| 821 | - } | |
| 828 | + return fclose( $handle ); | |
| 829 | + } | |
| 822 | 830 | |
| 823 | - if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { | |
| 824 | - continue; | |
| 825 | - } | |
| 826 | - $api_slug = dirname( $plugin_slug ); | |
| 827 | - $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); | |
| 828 | - if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 829 | - $this->upgradeVersionInfo->result[ $api_slug ] = $rslt; | |
| 830 | - $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt ); | |
| 831 | - $updated = true; | |
| 832 | - } | |
| 833 | - } | |
| 834 | - } | |
| 835 | - if ( $updated ) { | |
| 836 | - MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo ); | |
| 837 | - } | |
| 831 | + /** | |
| 832 | + * Method activate_redirection() | |
| 833 | + * | |
| 834 | + * Redirect after activating MainWP Extension. | |
| 835 | + * | |
| 836 | + * @param mixed $location Location to redirect to. | |
| 837 | + * | |
| 838 | + * @return $location Admin URL + the page to redirect to. | |
| 839 | + */ | |
| 840 | + public function activate_redirect( $location ) { | |
| 841 | + $location = admin_url( 'admin.php?page=Extensions' ); | |
| 842 | + return $location; | |
| 843 | + } | |
| 838 | 844 | |
| 839 | - return $transient; | |
| 840 | - } | |
| 841 | - } | |
| 845 | + /** | |
| 846 | + * Method activate_extension() | |
| 847 | + * | |
| 848 | + * Activate MainWP Extension. | |
| 849 | + * | |
| 850 | + * @param mixed $ext_key Extension API Key. | |
| 851 | + * @param array $info Extension Info. | |
| 852 | + * | |
| 853 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 854 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager_Password_Management::generate_password() | |
| 855 | + */ | |
| 856 | + public function activate_extension( $ext_key, $info = array() ) { | |
| 842 | 857 | |
| 843 | - if ( empty( $transient->checked ) ) { | |
| 844 | - return $transient; | |
| 845 | - } | |
| 858 | + add_filter( 'wp_redirect', array( $this, 'activate_redirect' ) ); | |
| 846 | 859 | |
| 847 | - if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 848 | - foreach ( $this->upgradeVersionInfo->result as $rslt ) { | |
| 849 | - if ( ! isset( $rslt->slug ) ) { | |
| 850 | - continue; | |
| 851 | - } | |
| 860 | + if ( is_array( $info ) && isset( $info['product_id'] ) && isset( $info['software_version'] ) ) { | |
| 861 | + $act_info = array( | |
| 862 | + 'product_id' => $info['product_id'], | |
| 863 | + 'software_version' => $info['software_version'], | |
| 864 | + 'activated_key' => 'Deactivated', | |
| 865 | + 'instance_id' => MainWP_Api_Manager_Password_Management::generate_password( 12, false ), | |
| 866 | + ); | |
| 867 | + MainWP_Api_Manager::instance()->set_activation_info( $ext_key, $act_info ); | |
| 868 | + } | |
| 869 | + } | |
| 852 | 870 | |
| 853 | - $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); | |
| 854 | - if ( isset( $transient->checked[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $transient->checked[ $plugin_slug ], '>' ) ) { | |
| 855 | - $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt ); | |
| 856 | - } | |
| 857 | - } | |
| 858 | - } | |
| 871 | + /** | |
| 872 | + * Method deactivate_extension() | |
| 873 | + * | |
| 874 | + * Deactivate MaiNWP Extension. | |
| 875 | + * | |
| 876 | + * @param mixed $ext_key Exnension API Key. | |
| 877 | + * | |
| 878 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 879 | + */ | |
| 880 | + public function deactivate_extension( $ext_key ) { | |
| 881 | + // try to deactivate license. | |
| 882 | + $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key(); | |
| 883 | + $result = MainWP_Api_Manager::instance()->license_key_deactivation( $ext_key, $mainwp_api_key ); | |
| 859 | 884 | |
| 860 | - return $transient; | |
| 861 | - } | |
| 885 | + MainWP_Api_Manager::instance()->remove_activation_info( $ext_key ); | |
| 886 | + } | |
| 862 | 887 | |
| 863 | - | |
| 864 | - /** | |
| 865 | - * Method map_rslt_obj() | |
| 866 | - * | |
| 867 | - * Map resulting object. | |
| 868 | - * | |
| 869 | - * @param object $result Resulting information. | |
| 870 | - * | |
| 871 | - * @return object $obj Mapped resulting object. | |
| 872 | - */ | |
| 873 | - public static function map_rslt_obj( $result ) { | |
| 874 | - $obj = new \stdClass(); | |
| 875 | - $obj->slug = $result->slug; | |
| 876 | - $obj->new_version = $result->new_version; | |
| 877 | - $obj->url = 'https://mainwp.com/'; | |
| 878 | - $obj->package = $result->package; | |
| 879 | - | |
| 880 | - return $obj; | |
| 881 | - } | |
| 882 | - | |
| 883 | - /** | |
| 884 | - * Method check_upgrade() | |
| 885 | - * | |
| 886 | - * Check if Extension has an update. | |
| 887 | - * | |
| 888 | - * @uses \MainWP\Dashboard\MainWP_API_Handler::check_exts_upgrade() | |
| 889 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 890 | - */ | |
| 891 | - private function check_upgrade() { | |
| 892 | - $result = MainWP_API_Handler::check_exts_upgrade(); | |
| 893 | - if ( null === $this->upgradeVersionInfo ) { | |
| 894 | - $this->upgradeVersionInfo = new \stdClass(); | |
| 895 | - } | |
| 896 | - $this->upgradeVersionInfo->updated = time(); | |
| 897 | - if ( ! empty( $result ) ) { | |
| 898 | - $this->upgradeVersionInfo->result = $result; | |
| 899 | - } | |
| 900 | - MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', $this->upgradeVersionInfo ); | |
| 901 | - } | |
| 902 | - | |
| 903 | - /** | |
| 904 | - * Method pre_check_update_custom() | |
| 905 | - * | |
| 906 | - * Pre-check for extension updates. | |
| 907 | - * | |
| 908 | - * @param object $transient Transient information. | |
| 909 | - * | |
| 910 | - * @return object $transient Transient information. | |
| 911 | - * | |
| 912 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 913 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 914 | - */ | |
| 915 | - public function pre_check_update_custom( $transient ) { | |
| 916 | - if ( ! isset( $transient->checked ) ) { | |
| 917 | - return $transient; | |
| 918 | - } | |
| 919 | - | |
| 920 | - if ( ( null === $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) { | |
| 921 | - $this->check_upgrade(); | |
| 922 | - } | |
| 923 | - | |
| 924 | - if ( empty( $transient->response ) ) { | |
| 925 | - $transient->response = array(); | |
| 926 | - } | |
| 927 | - | |
| 928 | - if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 929 | - $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); | |
| 930 | - foreach ( $this->upgradeVersionInfo->result as $rslt ) { | |
| 931 | - $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); | |
| 932 | - if ( isset( $extensions[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 933 | - $transient->response[ $plugin_slug ] = static::map_rslt_obj( $rslt ); | |
| 934 | - } | |
| 935 | - } | |
| 936 | - } | |
| 937 | - | |
| 938 | - return $transient; | |
| 939 | - } | |
| 940 | - | |
| 941 | - /** | |
| 942 | - * Method upload_file() | |
| 943 | - * | |
| 944 | - * Upload a file. | |
| 945 | - * | |
| 946 | - * @param mixed $file File to upload. | |
| 947 | - * | |
| 948 | - * @return void | |
| 949 | - * | |
| 950 | - * @uses \MainWP\Dashboard\MainWP_Utility::ends_with() | |
| 951 | - */ | |
| 952 | - public function upload_file( $file ) { | |
| 953 | - header( 'Content-Description: File Transfer' ); | |
| 954 | - $dwl_fname = basename( $file ); | |
| 955 | - if ( 'tar.gz' === $dwl_fname || '.tar.gz' === $dwl_fname ) { | |
| 956 | - $dwl_fname = 'noname.tar.gz'; // to fix name of zip file. | |
| 957 | - } | |
| 958 | - header( 'Content-Type: application/octet-stream' ); | |
| 959 | - header( 'Content-Disposition: attachment; filename="' . $dwl_fname . '"' ); | |
| 960 | - header( 'Expires: 0' ); | |
| 961 | - header( 'Cache-Control: must-revalidate' ); | |
| 962 | - header( 'Pragma: public' ); | |
| 963 | - header( 'Content-Length: ' . filesize( $file ) ); | |
| 964 | - while ( ob_get_level() ) { | |
| 965 | - ob_end_clean(); | |
| 966 | - } | |
| 967 | - $this->readfile_chunked( $file ); | |
| 968 | - exit(); | |
| 969 | - } | |
| 970 | - | |
| 971 | - /** | |
| 972 | - * Method readfile_chunked() | |
| 973 | - * | |
| 974 | - * Read Chunked File. | |
| 975 | - * | |
| 976 | - * @param mixed $filename Name of file. | |
| 977 | - * | |
| 978 | - * @return mixed echo $buffer|false|$handle. | |
| 979 | - */ | |
| 980 | - public function readfile_chunked( $filename ) { | |
| 981 | - $chunksize = 1024; | |
| 982 | - $handle = fopen( $filename, 'rb' ); | |
| 983 | - if ( false === $handle ) { | |
| 984 | - return false; | |
| 985 | - } | |
| 986 | - | |
| 987 | - while ( ! feof( $handle ) ) { | |
| 988 | - $buffer = fread( $handle, $chunksize ); | |
| 989 | - echo $buffer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 990 | - if ( ob_get_length() ) { | |
| 991 | - ob_flush(); | |
| 992 | - flush(); | |
| 993 | - } | |
| 994 | - $buffer = null; | |
| 995 | - } | |
| 996 | - | |
| 997 | - return fclose( $handle ); | |
| 998 | - } | |
| 999 | - | |
| 1000 | - /** | |
| 1001 | - * Method activate_redirection() | |
| 1002 | - * | |
| 1003 | - * Redirect after activating MainWP Extension. | |
| 1004 | - * | |
| 1005 | - * @param mixed $location Location to redirect to. | |
| 1006 | - * | |
| 1007 | - * @return $location Admin URL + the page to redirect to. | |
| 1008 | - */ | |
| 1009 | - public function activate_redirect( $location ) { | |
| 1010 | - unset( $location ); | |
| 1011 | - return admin_url( 'admin.php?page=Extensions' ); | |
| 1012 | - } | |
| 1013 | - | |
| 1014 | - /** | |
| 1015 | - * Method activate_extension() | |
| 1016 | - * | |
| 1017 | - * Activate MainWP Extension. | |
| 1018 | - * | |
| 1019 | - * @param mixed $ext_key Extension API Key. | |
| 1020 | - * @param array $info Extension Info. | |
| 1021 | - * | |
| 1022 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 1023 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager_Password_Management::generate_password() | |
| 1024 | - */ | |
| 1025 | - public function activate_extension( $ext_key, $info = array() ) { | |
| 1026 | - | |
| 1027 | - add_filter( 'wp_redirect', array( $this, 'activate_redirect' ) ); | |
| 1028 | - | |
| 1029 | - if ( is_array( $info ) && isset( $info['product_id'] ) && isset( $info['software_version'] ) ) { | |
| 1030 | - $act_info = array( | |
| 1031 | - 'product_id' => $info['product_id'], | |
| 1032 | - 'software_version' => $info['software_version'], | |
| 1033 | - 'activated_key' => 'Deactivated', | |
| 1034 | - 'instance_id' => MainWP_Api_Manager_Password_Management::generate_password( 12, false ), | |
| 1035 | - ); | |
| 1036 | - MainWP_Api_Manager::instance()->set_activation_info( $ext_key, $act_info ); | |
| 1037 | - } | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | - /** | |
| 1041 | - * Method deactivate_extension() | |
| 1042 | - * | |
| 1043 | - * Deactivate MaiNWP Extension. | |
| 1044 | - * | |
| 1045 | - * @param mixed $ext_key Exnension API Key. | |
| 1046 | - * @param bool $dashboard_only Deactive API Key on dashboard only. | |
| 1047 | - * | |
| 1048 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 1049 | - */ | |
| 1050 | - public function deactivate_extension( $ext_key, $dashboard_only = false ) { | |
| 1051 | - // try to deactivate license. | |
| 1052 | - if ( ! $dashboard_only ) { | |
| 1053 | - $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key(); | |
| 1054 | - MainWP_Api_Manager::instance()->license_key_deactivation( $ext_key, $mainwp_api_key ); | |
| 1055 | - } | |
| 1056 | - | |
| 1057 | - MainWP_Api_Manager::instance()->remove_activation_info( $ext_key ); | |
| 1058 | - } | |
| 1059 | 888 | } |