| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace WPIDE\App; |
| 3 | 3 | |
| 4 | +use WPIDE\App\Classes\Freemius; | |
| 4 | 5 | use WPIDE\App\Classes\Migrations; |
| 5 | 6 | use WPIDE\App\Classes\RecommendedPlugins; |
| 7 | +use WPIDE\App\Classes\PromoNotice; | |
| 6 | 8 | use WPIDE\App\Classes\ReviewNotice; |
| 7 | 9 | use WPIDE\App\Classes\Notices; |
| 8 | 10 | use WPIDE\App\Config\Config; |
| 9 | 11 | use WPIDE\App\Container\Container; |
| @@ -14,20 +16,20 @@ | ||
| 14 | 16 | use WPIDE\App\Kernel\Response; |
| 15 | 17 | use WPIDE\App\Kernel\StreamedResponse; |
| 16 | 18 | use WPIDE\App\Services\Services; |
| 17 | 19 | use WPIDE\App\Services\Storage\LocalFileSystem; |
| 18 | -use WPIDE\App\Tasks\TestTask; | |
| 19 | -use const WPIDE\Constants\ASSETS_URL; | |
| 20 | 20 | use const WPIDE\Constants\AUTHOR; |
| 21 | 21 | use const WPIDE\Constants\CONTENT_DIR; |
| 22 | 22 | use const WPIDE\Constants\DIR; |
| 23 | 23 | use const WPIDE\Constants\TMP_DIR; |
| 24 | -use const WPIDE\Constants\URL; | |
| 24 | +use const WPIDE\Constants\ASSETS_URL; | |
| 25 | 25 | use const WPIDE\Constants\FATAL_ERROR_DROPIN; |
| 26 | +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION; | |
| 27 | +use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION_OPT; | |
| 26 | 28 | use const WPIDE\Constants\NAME; |
| 27 | 29 | use const WPIDE\Constants\SLUG; |
| 28 | 30 | use const WPIDE\Constants\PLUGIN_URL; |
| 29 | -use const WPIDE\Constants\REQUIRED_PHP_VERSION; | |
| 31 | +use const WPIDE\Constants\VERSION; | |
| 30 | 32 | |
| 31 | 33 | class App |
| 32 | 34 | { |
| 33 | 35 | public static $_instance; |
| @@ -33,8 +35,9 @@ | ||
| 33 | 35 | public static $_instance; |
| 34 | 36 | |
| 35 | 37 | private $container; |
| 36 | 38 | private $dependencyNotice; |
| 39 | + private $isNetworkActive; | |
| 37 | 40 | |
| 38 | 41 | protected $notices = []; |
| 39 | 42 | public $services = []; |
| 40 | 43 | |
| @@ -75,8 +78,17 @@ | ||
| 75 | 78 | |
| 76 | 79 | return $this->resolve('WPIDE\App\Services\Cache\Cache'); |
| 77 | 80 | } |
| 78 | 81 | |
| 82 | + /** | |
| 83 | + * @throws \DI\DependencyException | |
| 84 | + * @throws \DI\NotFoundException | |
| 85 | + */ | |
| 86 | + public function transient() { | |
| 87 | + | |
| 88 | + return $this->resolve('WPIDE\App\Services\Transient\Transient'); | |
| 89 | + } | |
| 90 | + | |
| 79 | 91 | public function call($callable, array $parameters) |
| 80 | 92 | { |
| 81 | 93 | return $this->container->call($callable, $parameters); |
| 82 | 94 | } |
| @@ -85,16 +97,34 @@ | ||
| 85 | 97 | { |
| 86 | 98 | return SLUG . (!empty($suffix) ? '_' . $suffix : ''); |
| 87 | 99 | } |
| 88 | 100 | |
| 101 | + public function isLatestDropIn(): bool | |
| 102 | + { | |
| 103 | + | |
| 104 | + $currentVersion = get_option(FATAL_ERROR_DROPIN_VERSION_OPT, null); | |
| 105 | + | |
| 106 | + return $currentVersion === FATAL_ERROR_DROPIN_VERSION; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function dropInExists(): bool | |
| 110 | + { | |
| 111 | + $fs = LocalFileSystem::load(CONTENT_DIR); | |
| 112 | + | |
| 113 | + return $fs->fileExists(FATAL_ERROR_DROPIN); | |
| 114 | + } | |
| 115 | + | |
| 89 | 116 | public function installDropIn() { |
| 90 | 117 | |
| 91 | 118 | $fs = LocalFileSystem::load(CONTENT_DIR); |
| 92 | 119 | |
| 93 | - if(!$fs->fileExists(FATAL_ERROR_DROPIN)) { | |
| 120 | + if($fs->fileExists(FATAL_ERROR_DROPIN)) { | |
| 121 | + $this->unInstallDropIn(); | |
| 122 | + } | |
| 94 | 123 | |
| 95 | - $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './'); | |
| 96 | - } | |
| 124 | + $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './'); | |
| 125 | + | |
| 126 | + update_option(FATAL_ERROR_DROPIN_VERSION_OPT, FATAL_ERROR_DROPIN_VERSION); | |
| 97 | 127 | } |
| 98 | 128 | |
| 99 | 129 | public function unInstallDropIn() { |
| 100 | 130 | |
| @@ -104,8 +134,11 @@ | ||
| 104 | 134 | $fs->deleteFile(FATAL_ERROR_DROPIN); |
| 105 | 135 | } |
| 106 | 136 | } |
| 107 | 137 | |
| 138 | + /** | |
| 139 | + * @throws \Exception | |
| 140 | + */ | |
| 108 | 141 | public function load() |
| 109 | 142 | { |
| 110 | 143 | |
| 111 | 144 | if(!$this->dependencyCheck() || !is_admin()) { |
| @@ -111,13 +144,20 @@ | ||
| 111 | 144 | if(!$this->dependencyCheck() || !is_admin()) { |
| 112 | 145 | return; |
| 113 | 146 | } |
| 114 | 147 | |
| 148 | + if(!$this->dropInExists() || !$this->isLatestDropIn()) { | |
| 149 | + $this->installDropIn(); | |
| 150 | + } | |
| 151 | + | |
| 115 | 152 | $this->loadTextDomain(); |
| 116 | 153 | $this->loadHooks(); |
| 117 | 154 | |
| 118 | 155 | Migrations::init(); |
| 119 | - ReviewNotice::init(); | |
| 156 | + PromoNotice::init(); | |
| 157 | + if(!PromoNotice::enabled()) { | |
| 158 | + ReviewNotice::init(); | |
| 159 | + } | |
| 120 | 160 | RecommendedPlugins::init(); |
| 121 | 161 | } |
| 122 | 162 | |
| 123 | 163 | protected function loadTextDomain() { |
| @@ -135,22 +175,13 @@ | ||
| 135 | 175 | if(!empty($this->dependencyNotice)) { |
| 136 | 176 | echo $this->dependencyNotice; |
| 137 | 177 | } |
| 138 | 178 | |
| 139 | - if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) { | |
| 179 | + // Perform checks here | |
| 180 | + // $class = 'notice notice-error'; | |
| 181 | + // $message = ''; | |
| 182 | + // $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message); | |
| 140 | 183 | |
| 141 | - $class = 'notice notice-error'; | |
| 142 | - | |
| 143 | - $message = sprintf( | |
| 144 | - __( '%s minimum PHP version requirement is %s. You are using: %s', 'wpide' ), | |
| 145 | - '<strong>'.NAME.'</strong>', | |
| 146 | - '<strong>'.REQUIRED_PHP_VERSION.'</strong>', | |
| 147 | - '<strong>'.PHP_VERSION.'</strong>' | |
| 148 | - ); | |
| 149 | - | |
| 150 | - $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message); | |
| 151 | - } | |
| 152 | - | |
| 153 | 184 | if(!empty($this->dependencyNotice)) { |
| 154 | 185 | add_action('admin_notices', [$this, 'dependencyCheck']); |
| 155 | 186 | return false; |
| 156 | 187 | } |
| @@ -160,19 +191,36 @@ | ||
| 160 | 191 | |
| 161 | 192 | protected function loadHooks() |
| 162 | 193 | { |
| 163 | 194 | |
| 164 | - add_action('admin_menu', [$this, 'adminMenu' ]); | |
| 165 | - add_action("wpide_ajax_request", [$this, "ajaxRequest"]); | |
| 195 | + if($this->showAdminMenu()) { | |
| 196 | + add_action('admin_menu', [$this, 'adminMenu' ]); | |
| 197 | + add_action('network_admin_menu', [$this, 'adminMenu']); | |
| 198 | + } | |
| 199 | + | |
| 200 | + add_action("wp_ajax_wpide_request", [$this, "ajaxRequest"]); | |
| 166 | 201 | add_action("admin_init", [$this, "registerTasks"]); |
| 202 | + add_action('admin_enqueue_scripts', [ $this, 'enqueueCommonAssets' ]); | |
| 167 | 203 | |
| 168 | 204 | if($this->isPluginScreen()) { |
| 169 | 205 | |
| 206 | + // When network active, If trying to load plugin admin url, redirect back to network root | |
| 207 | + if(!$this->showAdminMenu() && !$this->isFreemiusScreen() && !Freemius::sdk()->is_activation_mode() && !Freemius::showSubmenus()) { | |
| 208 | + wp_redirect(network_admin_url()); | |
| 209 | + die(); | |
| 210 | + } | |
| 211 | + | |
| 170 | 212 | add_filter('admin_title', [$this, 'setAdminTitle']); |
| 213 | + | |
| 214 | + add_action('network_admin_menu', [$this, 'addAdminFavicon']); | |
| 215 | + add_action("network_admin_menu", [$this, "setCurrentScreen"], -1); | |
| 216 | + add_action('network_admin_menu', [Notices::class, 'init']); | |
| 217 | + | |
| 171 | 218 | add_action('admin_head', [$this, 'addAdminFavicon']); |
| 219 | + add_action("admin_menu", [$this, "setCurrentScreen"], -1); | |
| 172 | 220 | add_action('admin_menu', [Notices::class, 'init']); |
| 221 | + | |
| 173 | 222 | add_filter('screen_options_show_screen', '__return_false'); |
| 174 | - add_filter('admin_body_class', [$this, 'bodyClasses'], 10, 1); | |
| 175 | 223 | add_action('admin_enqueue_scripts', [ $this, 'deregisterWpStyles' ]); |
| 176 | 224 | } |
| 177 | 225 | } |
| 178 | 226 | |
| @@ -177,19 +225,76 @@ | ||
| 177 | 225 | } |
| 178 | 226 | |
| 179 | 227 | public function registerTasks() { |
| 180 | 228 | |
| 181 | - TestTask::register(); | |
| 229 | + //TestTask::register(); | |
| 182 | 230 | } |
| 183 | 231 | |
| 232 | + public function setCurrentScreen() { | |
| 233 | + | |
| 234 | + set_current_screen(SLUG); | |
| 235 | + } | |
| 236 | + | |
| 184 | 237 | public function canManage(): bool |
| 185 | 238 | { |
| 186 | 239 | return current_user_can('manage_options'); |
| 187 | 240 | } |
| 188 | 241 | |
| 242 | + public function showAdminMenu(): bool | |
| 243 | + { | |
| 244 | + | |
| 245 | + if(fs_is_network_admin()) { | |
| 246 | + | |
| 247 | + return $this->isNetworkActive() && (WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED || !Freemius::sdk()->is_network_delegated_connection()); | |
| 248 | + } | |
| 249 | + | |
| 250 | + return true; | |
| 251 | + } | |
| 252 | + | |
| 189 | 253 | public function adminMenu() |
| 190 | 254 | { |
| 191 | 255 | |
| 256 | + $menuTopItems = apply_filters('wpide_admin_menu_top_items', [ | |
| 257 | + [ | |
| 258 | + 'title' => __( 'File Manager', 'wpide' ), | |
| 259 | + 'slug' => SLUG.'#/file-manager', | |
| 260 | + 'callback' => [$this, 'bootstrap'], | |
| 261 | + 'position' => 10 | |
| 262 | + ], | |
| 263 | + [ | |
| 264 | + 'title' => __( 'File Editor', 'wpide' ), | |
| 265 | + 'slug' => SLUG.'#/file-editor', | |
| 266 | + 'callback' => [$this, 'bootstrap'], | |
| 267 | + 'position' => 20 | |
| 268 | + ], | |
| 269 | + [ | |
| 270 | + 'title' => __( 'Image Editor', 'wpide' ), | |
| 271 | + 'slug' => SLUG.'#/image-editor', | |
| 272 | + 'callback' => [$this, 'bootstrap'], | |
| 273 | + 'position' => 20 | |
| 274 | + ], | |
| 275 | + [ | |
| 276 | + 'title' => __( 'DB Manager', 'wpide' ), | |
| 277 | + 'slug' => SLUG.'#/db-manager', | |
| 278 | + 'callback' => [$this, 'bootstrap'], | |
| 279 | + 'position' => 30 | |
| 280 | + ], | |
| 281 | + [ | |
| 282 | + 'title' => __( 'Config Manager', 'wpide' ), | |
| 283 | + 'slug' => SLUG.'#/config-manager', | |
| 284 | + 'callback' => [$this, 'bootstrap'], | |
| 285 | + 'position' => 30 | |
| 286 | + ], | |
| 287 | + [ | |
| 288 | + 'title' => __( 'Settings', 'wpide' ), | |
| 289 | + 'slug' => SLUG.'#/settings', | |
| 290 | + 'callback' => [$this, 'bootstrap'], | |
| 291 | + 'position' => 40 | |
| 292 | + ] | |
| 293 | + ]); | |
| 294 | + | |
| 295 | + $menuBottomItems = apply_filters('wpide_admin_menu_bottom_items', []); | |
| 296 | + | |
| 192 | 297 | add_menu_page( |
| 193 | 298 | NAME, |
| 194 | 299 | NAME, |
| 195 | 300 | 'manage_options', |
| @@ -194,43 +299,54 @@ | ||
| 194 | 299 | NAME, |
| 195 | 300 | 'manage_options', |
| 196 | 301 | SLUG, |
| 197 | 302 | [$this, 'bootstrap'], |
| 198 | - 'dashicons-editor-code', | |
| 199 | - 3 | |
| 303 | + 'dashicons-editor-code' | |
| 200 | 304 | ); |
| 201 | 305 | |
| 202 | - add_submenu_page( | |
| 203 | - SLUG, | |
| 204 | - __( 'File Manager', 'wpide' ), | |
| 205 | - __( 'File Manager', 'wpide' ), | |
| 206 | - 'manage_options', | |
| 207 | - SLUG.'#/file-manager', | |
| 208 | - [$this, 'bootstrap'], | |
| 209 | - 3 | |
| 210 | - ); | |
| 306 | + $highestPosition = 0; | |
| 307 | + foreach ($menuTopItems as $item) { | |
| 308 | + add_submenu_page( | |
| 309 | + SLUG, | |
| 310 | + $item['title'], | |
| 311 | + $item['title'], | |
| 312 | + 'manage_options', | |
| 313 | + $item['slug'], | |
| 314 | + $item['callback'], | |
| 315 | + $item['position'] | |
| 316 | + ); | |
| 211 | 317 | |
| 318 | + if ($item['position'] > $highestPosition) { | |
| 319 | + $highestPosition = $item['position']; | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 212 | 323 | add_submenu_page( |
| 213 | 324 | SLUG, |
| 214 | - __( 'File Editor', 'wpide' ), | |
| 215 | - __( 'File Editor', 'wpide' ), | |
| 325 | + '', | |
| 326 | + '', | |
| 216 | 327 | 'manage_options', |
| 217 | - SLUG.'#/file-editor', | |
| 218 | - [$this, 'bootstrap'], | |
| 219 | - 3 | |
| 328 | + '#divider', | |
| 329 | + '', | |
| 330 | + $highestPosition + 10 | |
| 220 | 331 | ); |
| 221 | 332 | |
| 222 | - add_submenu_page( | |
| 223 | - SLUG, | |
| 224 | - __( 'DB Manager', 'wpide' ), | |
| 225 | - __( 'DB Manager', 'wpide' ), | |
| 226 | - 'manage_options', | |
| 227 | - SLUG.'#/db-manager', | |
| 228 | - [$this, 'bootstrap'], | |
| 229 | - 3 | |
| 230 | - ); | |
| 333 | + foreach ($menuBottomItems as $item) { | |
| 334 | + add_submenu_page( | |
| 335 | + SLUG, | |
| 336 | + $item['title'], | |
| 337 | + $item['title'], | |
| 338 | + 'manage_options', | |
| 339 | + $item['slug'], | |
| 340 | + $item['callback'], | |
| 341 | + $item['position'] | |
| 342 | + ); | |
| 343 | + } | |
| 231 | 344 | |
| 232 | 345 | remove_submenu_page(SLUG, SLUG); |
| 346 | + | |
| 347 | + do_action('wpide_admin_menu'); | |
| 348 | + | |
| 233 | 349 | } |
| 234 | 350 | |
| 235 | 351 | public function bootstrap() { |
| 236 | 352 | |
| @@ -252,8 +368,11 @@ | ||
| 252 | 368 | $this->container->set(StreamedResponse::class, $sresponse); |
| 253 | 369 | |
| 254 | 370 | $this->services = []; |
| 255 | 371 | foreach ($services->get() as $key => $service) { |
| 372 | + if(empty($service['handler'])) { | |
| 373 | + continue; | |
| 374 | + } | |
| 256 | 375 | $this->container->set($key, $this->container->get($service['handler'])); |
| 257 | 376 | $this->container->get($key)->init(isset($service['config']) ? $service['config'] : []); |
| 258 | 377 | $this->services[$key] = $this->container->get($key); |
| 259 | 378 | } |
| @@ -266,18 +385,8 @@ | ||
| 266 | 385 | } |
| 267 | 386 | } |
| 268 | 387 | } |
| 269 | 388 | |
| 270 | - public function bodyClasses($classes): string | |
| 271 | - { | |
| 272 | - | |
| 273 | - if(!$this->isFreemiusScreen()) { | |
| 274 | - $classes = $classes . " folded"; | |
| 275 | - } | |
| 276 | - | |
| 277 | - return $classes; | |
| 278 | - } | |
| 279 | - | |
| 280 | 389 | public function deregisterWpStyles() |
| 281 | 390 | { |
| 282 | 391 | |
| 283 | 392 | wp_deregister_style('color'); |
| @@ -293,24 +402,30 @@ | ||
| 293 | 402 | wp_deregister_style('widgets'); |
| 294 | 403 | wp_deregister_style('l10n'); |
| 295 | 404 | wp_deregister_style('site-icon'); |
| 296 | 405 | |
| 297 | - wp_register_style('color', null); | |
| 298 | - wp_register_style('forms', null); | |
| 299 | - wp_register_style('dashboard', null); | |
| 300 | - wp_register_style('list-tables', null); | |
| 301 | - wp_register_style('edit', null); | |
| 302 | - wp_register_style('revisions', null); | |
| 303 | - wp_register_style('media', null); | |
| 304 | - wp_register_style('themes', null); | |
| 305 | - wp_register_style('about', null); | |
| 306 | - wp_register_style('nav-menus', null); | |
| 307 | - wp_register_style('widgets', null); | |
| 308 | - wp_register_style('l10n', null); | |
| 309 | - wp_register_style('site-icon', null); | |
| 406 | + wp_register_style('color', ''); | |
| 407 | + wp_register_style('forms', ''); | |
| 408 | + wp_register_style('dashboard', ''); | |
| 409 | + wp_register_style('list-tables', ''); | |
| 410 | + wp_register_style('edit', ''); | |
| 411 | + wp_register_style('revisions', ''); | |
| 412 | + wp_register_style('media', ''); | |
| 413 | + wp_register_style('themes', ''); | |
| 414 | + wp_register_style('about', ''); | |
| 415 | + wp_register_style('nav-menus', ''); | |
| 416 | + wp_register_style('widgets', ''); | |
| 417 | + wp_register_style('l10n', ''); | |
| 418 | + wp_register_style('site-icon', ''); | |
| 310 | 419 | |
| 311 | 420 | } |
| 312 | 421 | |
| 422 | + public function enqueueCommonAssets() | |
| 423 | + { | |
| 424 | + | |
| 425 | + wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/global.css', [], VERSION); | |
| 426 | + } | |
| 427 | + | |
| 313 | 428 | public function ajaxRequest() |
| 314 | 429 | { |
| 315 | 430 | if(!$this->canManage()) { |
| 316 | 431 | die(esc_html__('Restricted Access', 'wpide')); |
| @@ -342,11 +457,15 @@ | ||
| 342 | 457 | |
| 343 | 458 | return false; |
| 344 | 459 | } |
| 345 | 460 | |
| 346 | - public function isFreemiusScreen(): bool | |
| 461 | + public function isFreemiusScreen($section = null): bool | |
| 347 | 462 | { |
| 348 | 463 | |
| 464 | + if($section) { | |
| 465 | + return $this->isPluginScreen($section); | |
| 466 | + } | |
| 467 | + | |
| 349 | 468 | if( |
| 350 | 469 | $this->isPluginScreen('account') || |
| 351 | 470 | $this->isPluginScreen('pricing') || |
| 352 | 471 | $this->isPluginScreen('contact') || |
| @@ -357,16 +476,34 @@ | ||
| 357 | 476 | |
| 358 | 477 | return false; |
| 359 | 478 | } |
| 360 | 479 | |
| 361 | - public function getAdminUrl(): string { | |
| 480 | + public function isNetworkActive(): bool | |
| 481 | + { | |
| 362 | 482 | |
| 363 | - return admin_url( 'admin.php?page='.SLUG ); | |
| 483 | + if(!isset($this->isNetworkActive)) { | |
| 484 | + | |
| 485 | + $plugin = basename(WPIDE_DIR) . '/' . basename(WPIDE_FILE); | |
| 486 | + $this->isNetworkActive = is_plugin_active_for_network($plugin); | |
| 487 | + } | |
| 488 | + | |
| 489 | + return $this->isNetworkActive; | |
| 364 | 490 | } |
| 365 | 491 | |
| 492 | + public function getAdminUrl($section = null, $network = false): string { | |
| 493 | + | |
| 494 | + $admin_url_function = $network ? 'network_admin_url' : 'admin_url'; | |
| 495 | + | |
| 496 | + $url = 'admin.php?page='.SLUG; | |
| 497 | + if(!empty($section)) { | |
| 498 | + $url .= '#/'.$section; | |
| 499 | + } | |
| 500 | + return $admin_url_function( $url ); | |
| 501 | + } | |
| 502 | + | |
| 366 | 503 | public function getAjaxUrl($req = ''): string |
| 367 | 504 | { |
| 368 | - return URL.'ajax.php?action=request&req='.$req; | |
| 505 | + return admin_url('admin-ajax.php').'?action=wpide_request&req='.$req; | |
| 369 | 506 | } |
| 370 | 507 | |
| 371 | 508 | /** |
| 372 | 509 | * Get external url with utm campaign / content |