| @@ -10,10 +10,13 @@ | ||
| 10 | 10 | use ReflectionClass; |
| 11 | 11 | use ReflectionMethod; |
| 12 | 12 | use Calotes\Helper\HTTP; |
| 13 | 13 | use WP_Defender\Traits\IO; |
| 14 | +use WP_Defender\Traits\Plugin; | |
| 14 | 15 | use WP_Defender\Traits\User; |
| 15 | 16 | use WP_Defender\Traits\Permission; |
| 17 | +use WP_Defender\Component\Hub_Connector; | |
| 18 | +use WP_Defender\Traits\Defender_Dashboard_Client; | |
| 16 | 19 | |
| 17 | 20 | /** |
| 18 | 21 | * The controller class. |
| 19 | 22 | */ |
| @@ -21,8 +24,10 @@ | ||
| 21 | 24 | |
| 22 | 25 | use IO; |
| 23 | 26 | use User; |
| 24 | 27 | use Permission; |
| 28 | + use Plugin; | |
| 29 | + use Defender_Dashboard_Client; | |
| 25 | 30 | |
| 26 | 31 | /** |
| 27 | 32 | * The slug identifier for this controller. |
| 28 | 33 | * |
| @@ -55,9 +60,9 @@ | ||
| 55 | 60 | |
| 56 | 61 | /** |
| 57 | 62 | * Remove all settings, configs generated in this container runtime. |
| 58 | 63 | * |
| 59 | - * @return mixed | |
| 64 | + * @return void | |
| 60 | 65 | */ |
| 61 | 66 | abstract public function remove_settings(); |
| 62 | 67 | |
| 63 | 68 | /** |
| @@ -62,9 +67,9 @@ | ||
| 62 | 67 | |
| 63 | 68 | /** |
| 64 | 69 | * Remove all data. |
| 65 | 70 | * |
| 66 | - * @return mixed | |
| 71 | + * @return void | |
| 67 | 72 | */ |
| 68 | 73 | abstract public function remove_data(); |
| 69 | 74 | |
| 70 | 75 | /** |
| @@ -195,6 +200,66 @@ | ||
| 195 | 200 | public function check_route( string $route ) { |
| 196 | 201 | return defined( 'DEFENDER_DEBUG' ) && true === constant( 'DEFENDER_DEBUG' ) |
| 197 | 202 | ? wp_slash( $route ) |
| 198 | 203 | : $route; |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * Shared data for all controllers (profile, hub connector, isPro, etc.). | |
| 208 | + * | |
| 209 | + * @return array | |
| 210 | + */ | |
| 211 | + protected function get_shared_data(): array { | |
| 212 | + $hub_profile_ui = Hub_Connector::get_profile_data_for_ui(); | |
| 213 | + $profile_data = is_array( $hub_profile_ui ) ? $hub_profile_ui : array(); | |
| 214 | + $wpmudev = wd_di()->get( \WP_Defender\Behavior\WPMUDEV::class ); | |
| 215 | + $scan_api = wd_di()->get( \WP_Defender\Controller\Scan::class )->dump_routes_and_nonces(); | |
| 216 | + | |
| 217 | + // wp_timezone_string() returns a raw offset like "+05:30" for sites that use | |
| 218 | + // a numeric GMT offset instead of a named timezone. Intl.DateTimeFormat does | |
| 219 | + // not accept "+05:30", but it does accept the "UTC+05:30" form in all modern | |
| 220 | + // browsers (Chrome 24+, Firefox 23+, Safari 10+). Prefix the offset so the | |
| 221 | + // JS Intl APIs work correctly without falling back to the browser timezone. | |
| 222 | + $tz_string = wp_timezone_string(); | |
| 223 | + if ( preg_match( '/^[+-]/', $tz_string ) ) { | |
| 224 | + $tz_string = 'UTC' . $tz_string; | |
| 225 | + } | |
| 226 | + | |
| 227 | + $data = array( | |
| 228 | + 'defenderUrl' => network_admin_url( 'admin.php?page=wp-defender' ), | |
| 229 | + 'pluginUrl' => WP_DEFENDER_BASE_URL, | |
| 230 | + 'adminUrl' => network_admin_url(), | |
| 231 | + 'siteUrl' => network_site_url(), | |
| 232 | + 'timeZone' => $tz_string, | |
| 233 | + 'timeZoneOffset' => (int) round( wp_timezone()->getOffset( new \DateTime( 'now' ) ) / 60 ), | |
| 234 | + 'startOfWeek' => (int) get_option( 'start_of_week', 1 ), | |
| 235 | + 'profileData' => $profile_data, | |
| 236 | + 'hubConnector' => wd_di()->get( \WP_Defender\Controller\Hub_Connector::class )->data_frontend(), | |
| 237 | + 'pluginUpdate' => $this->get_plugin_update_notice_data(), | |
| 238 | + 'whiteLabel' => defender_whitelabel_data(), | |
| 239 | + 'activityLog' => wd_di()->get( \WP_Defender\Controller\Activity_Log::class )->data_frontend(), | |
| 240 | + 'hubApiKey' => array( | |
| 241 | + 'available' => $wpmudev->is_apikey_available(), | |
| 242 | + ), | |
| 243 | + 'isWpOrg' => defender_is_wp_org_version(), | |
| 244 | + 'isPro' => $wpmudev->is_pro(), | |
| 245 | + 'hosted' => $wpmudev->is_wpmu_hosting(), | |
| 246 | + 'highContrastMode' => defender_high_contrast(), | |
| 247 | + 'isUnlimitedHosting' => defender_is_unlimited_hosting(), | |
| 248 | + 'scanApi' => array( | |
| 249 | + 'routes' => $scan_api['routes'] ?? array(), | |
| 250 | + 'nonces' => $scan_api['nonces'] ?? array(), | |
| 251 | + ), | |
| 252 | + ); | |
| 253 | + | |
| 254 | + return $data; | |
| 255 | + } | |
| 256 | + | |
| 257 | + /** | |
| 258 | + * Page-specific data for a concrete controller. | |
| 259 | + * | |
| 260 | + * @return array | |
| 261 | + */ | |
| 262 | + protected function get_page_data(): array { | |
| 263 | + return array(); | |
| 199 | 264 | } |
| 200 | 265 | } |