PluginProbe
WPIDE – File Manager & Code Editor / 3.4.3
WPIDE – File Manager & Code Editor v3.4.3
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / App / App.php

App.php in WPIDE – File Manager & Code Editor 3.4.3, at App/App.php

467 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPIDE\App;
3
4 use WPIDE\App\Classes\Migrations;
5 use WPIDE\App\Classes\RecommendedPlugins;
6 use WPIDE\App\Classes\ReviewNotice;
7 use WPIDE\App\Classes\Notices;
8 use WPIDE\App\Config\Config;
9 use WPIDE\App\Container\Container;
10 use WPIDE\App\Helpers\EmptyDir;
11 use WPIDE\App\Helpers\FileBackup;
12 use WPIDE\App\Helpers\ImageStateData;
13 use WPIDE\App\Kernel\Request;
14 use WPIDE\App\Kernel\Response;
15 use WPIDE\App\Kernel\StreamedResponse;
16 use WPIDE\App\Services\Services;
17 use WPIDE\App\Services\Storage\LocalFileSystem;
18 use const WPIDE\Constants\AUTHOR;
19 use const WPIDE\Constants\CONTENT_DIR;
20 use const WPIDE\Constants\DIR;
21 use const WPIDE\Constants\TMP_DIR;
22 use const WPIDE\Constants\URL;
23 use const WPIDE\Constants\ASSETS_URL;
24 use const WPIDE\Constants\FATAL_ERROR_DROPIN;
25 use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION;
26 use const WPIDE\Constants\FATAL_ERROR_DROPIN_VERSION_OPT;
27 use const WPIDE\Constants\NAME;
28 use const WPIDE\Constants\SLUG;
29 use const WPIDE\Constants\PLUGIN_URL;
30 use const WPIDE\Constants\VERSION;
31
32 class App
33 {
34 public static $_instance;
35
36 private $container;
37 private $dependencyNotice;
38
39 protected $notices = [];
40 public $services = [];
41
42 public function __construct()
43 {
44
45 register_activation_hook(WPIDE_FILE, [$this, 'activate']);
46 register_deactivation_hook(WPIDE_FILE, [$this, 'deactivate']);
47
48 add_action( 'plugins_loaded', [$this, 'load']);
49
50 $this->container = new Container();
51
52 }
53
54 public function activate() {
55 $this->installDropIn();
56 }
57
58 public function deactivate() {
59 $this->unInstallDropIn();
60 }
61
62 /**
63 * @throws \DI\DependencyException
64 * @throws \DI\NotFoundException
65 */
66 public function resolve($name)
67 {
68 return $this->container->get($name);
69 }
70
71 /**
72 * @throws \DI\DependencyException
73 * @throws \DI\NotFoundException
74 */
75 public function cache() {
76
77 return $this->resolve('WPIDE\App\Services\Cache\Cache');
78 }
79
80 public function call($callable, array $parameters)
81 {
82 return $this->container->call($callable, $parameters);
83 }
84
85 public function prefix($suffix = null): string
86 {
87 return SLUG . (!empty($suffix) ? '_' . $suffix : '');
88 }
89
90 public function isLatestDropIn(): bool
91 {
92
93 $currentVersion = get_option(FATAL_ERROR_DROPIN_VERSION_OPT, null);
94
95 return $currentVersion === FATAL_ERROR_DROPIN_VERSION;
96 }
97
98 public function dropInExists() {
99
100 $fs = LocalFileSystem::load(CONTENT_DIR);
101
102 return $fs->fileExists(FATAL_ERROR_DROPIN);
103 }
104
105 public function installDropIn() {
106
107 $fs = LocalFileSystem::load(CONTENT_DIR);
108
109 if($fs->fileExists(FATAL_ERROR_DROPIN)) {
110 $this->unInstallDropIn();
111 }
112
113 $fs->copyFile('plugins/'.basename(DIR).'/wp-content/'.FATAL_ERROR_DROPIN, './');
114
115 update_option(FATAL_ERROR_DROPIN_VERSION_OPT, FATAL_ERROR_DROPIN_VERSION);
116 }
117
118 public function unInstallDropIn() {
119
120 $fs = LocalFileSystem::load(CONTENT_DIR);
121
122 if($fs->fileExists(FATAL_ERROR_DROPIN)) {
123 $fs->deleteFile(FATAL_ERROR_DROPIN);
124 }
125 }
126
127 public function load()
128 {
129
130 if(!$this->dependencyCheck() || !is_admin()) {
131 return;
132 }
133
134 if(!$this->dropInExists() || !$this->isLatestDropIn()) {
135 $this->installDropIn();
136 }
137
138 $this->loadTextDomain();
139 $this->loadHooks();
140
141 Migrations::init();
142 ReviewNotice::init();
143 RecommendedPlugins::init();
144 }
145
146 protected function loadTextDomain() {
147
148 load_plugin_textdomain(
149 SLUG,
150 false,
151 basename( dirname( WPIDE_FILE ) ) . '/languages/'
152 );
153 }
154
155 protected function dependencyCheck(): bool
156 {
157
158 if(!empty($this->dependencyNotice)) {
159 echo $this->dependencyNotice;
160 }
161
162 // Perform checks here
163 // $class = 'notice notice-error';
164 // $message = '';
165 // $this->dependencyNotice = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message);
166
167 if(!empty($this->dependencyNotice)) {
168 add_action('admin_notices', [$this, 'dependencyCheck']);
169 return false;
170 }
171
172 return true;
173 }
174
175 protected function loadHooks()
176 {
177
178 add_action('admin_menu', [$this, 'adminMenu' ]);
179 add_action("wp_ajax_wpide_request", [$this, "ajaxRequest"]);
180 add_action("admin_init", [$this, "registerTasks"]);
181 add_action('admin_enqueue_scripts', [ $this, 'enqueueCommonAssets' ]);
182
183 if($this->isPluginScreen()) {
184
185 add_filter('admin_title', [$this, 'setAdminTitle']);
186 add_action('admin_head', [$this, 'addAdminFavicon']);
187 add_action("admin_menu", [$this, "setCurrentScreen"], -1);
188 add_action('admin_menu', [Notices::class, 'init']);
189 add_filter('screen_options_show_screen', '__return_false');
190 add_action('admin_enqueue_scripts', [ $this, 'deregisterWpStyles' ]);
191 }
192 }
193
194 public function registerTasks() {
195
196 //TestTask::register();
197 }
198
199 public function setCurrentScreen() {
200
201 set_current_screen(SLUG);
202 }
203
204 public function canManage(): bool
205 {
206 return current_user_can('manage_options');
207 }
208
209 public function adminMenu()
210 {
211
212 add_menu_page(
213 NAME,
214 NAME,
215 'manage_options',
216 SLUG,
217 [$this, 'bootstrap'],
218 'dashicons-editor-code'
219 );
220
221 add_submenu_page(
222 SLUG,
223 __( 'File Manager', 'wpide' ),
224 __( 'File Manager', 'wpide' ),
225 'manage_options',
226 SLUG.'#/file-manager',
227 [$this, 'bootstrap'],
228 1
229 );
230
231 add_submenu_page(
232 SLUG,
233 __( 'File Editor', 'wpide' ),
234 __( 'File Editor', 'wpide' ),
235 'manage_options',
236 SLUG.'#/file-editor',
237 [$this, 'bootstrap'],
238 2
239 );
240
241 add_submenu_page(
242 SLUG,
243 __( 'DB Manager', 'wpide' ),
244 __( 'DB Manager', 'wpide' ),
245 'manage_options',
246 SLUG.'#/db-manager',
247 [$this, 'bootstrap'],
248 3
249 );
250
251 add_submenu_page(
252 SLUG,
253 __( 'Settings', 'wpide' ),
254 __( 'Settings', 'wpide' ),
255 'manage_options',
256 SLUG.'#/settings',
257 [$this, 'bootstrap'],
258 4
259 );
260
261 add_submenu_page(
262 SLUG,
263 '',
264 '',
265 'manage_options',
266 '#divider',
267 null,
268 5
269 );
270
271 remove_submenu_page(SLUG, SLUG);
272 }
273
274 public function bootstrap() {
275
276 FileBackup::init();
277 ImageStateData::init();
278 EmptyDir::create(TMP_DIR);
279
280 $config = AppConfig::load();
281 $services = AppServices::load();
282 $request = Request::createFromGlobals();
283 $response = new Response();
284 $sresponse = new StreamedResponse();
285
286 $this->container->set(Config::class, $config);
287 $this->container->set(Services::class, $services);
288 $this->container->set(Container::class, $this->container);
289 $this->container->set(Request::class, $request);
290 $this->container->set(Response::class, $response);
291 $this->container->set(StreamedResponse::class, $sresponse);
292
293 $this->services = [];
294 foreach ($services->get() as $key => $service) {
295 if(empty($service['handler'])) {
296 continue;
297 }
298 $this->container->set($key, $this->container->get($service['handler']));
299 $this->container->get($key)->init(isset($service['config']) ? $service['config'] : []);
300 $this->services[$key] = $this->container->get($key);
301 }
302
303 if(!defined('WPIDE_DOING_TASK')) {
304 if (wp_doing_ajax()) {
305 $response->send();
306 } else {
307 $response->sendContent();
308 }
309 }
310 }
311
312 public function deregisterWpStyles()
313 {
314
315 wp_deregister_style('color');
316 wp_deregister_style('forms');
317 wp_deregister_style('dashboard');
318 wp_deregister_style('list-tables');
319 wp_deregister_style('edit');
320 wp_deregister_style('revisions');
321 wp_deregister_style('media');
322 wp_deregister_style('themes');
323 wp_deregister_style('about');
324 wp_deregister_style('nav-menus');
325 wp_deregister_style('widgets');
326 wp_deregister_style('l10n');
327 wp_deregister_style('site-icon');
328
329 wp_register_style('color', null);
330 wp_register_style('forms', null);
331 wp_register_style('dashboard', null);
332 wp_register_style('list-tables', null);
333 wp_register_style('edit', null);
334 wp_register_style('revisions', null);
335 wp_register_style('media', null);
336 wp_register_style('themes', null);
337 wp_register_style('about', null);
338 wp_register_style('nav-menus', null);
339 wp_register_style('widgets', null);
340 wp_register_style('l10n', null);
341 wp_register_style('site-icon', null);
342
343 }
344
345 public function enqueueCommonAssets()
346 {
347
348 wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/global.css', [], VERSION);
349 }
350
351 public function ajaxRequest()
352 {
353 if(!$this->canManage()) {
354 die(esc_html__('Restricted Access', 'wpide'));
355 }
356
357 $this->bootstrap();
358 die();
359 }
360
361 public function isPluginScreen($section = null): bool
362 {
363
364 $screen = function_exists('get_current_screen') ? get_current_screen() : null;
365
366 $slug = SLUG;
367
368 if(!empty($section)) {
369 $slug .= '-'. $section;
370 }
371
372 if(!empty($screen)) {
373 return strpos($screen->base, 'page_' . $slug) !== false;
374 }
375
376 if(!empty($_GET['page'])) {
377 $page = sanitize_text_field($_GET['page']);
378 return strpos($page, $slug) !== false;
379 }
380
381 return false;
382 }
383
384 public function isFreemiusScreen($section = null): bool
385 {
386
387 if($section) {
388 return $this->isPluginScreen($section);
389 }
390
391 if(
392 $this->isPluginScreen('account') ||
393 $this->isPluginScreen('pricing') ||
394 $this->isPluginScreen('contact') ||
395 $this->isPluginScreen('affiliates')
396 ) {
397 return true;
398 }
399
400 return false;
401 }
402
403 public function getAdminUrl(): string {
404
405 return admin_url( 'admin.php?page='.SLUG );
406 }
407
408 public function getAjaxUrl($req = ''): string
409 {
410 return admin_url('admin-ajax.php').'?action=wpide_request&req='.$req;
411 }
412
413 /**
414 * Get external url with utm campaign / content
415 *
416 * @param string|null $utm_content
417 * @param string|null $url
418 *
419 * @return string $link;
420 * @since 1.0.0
421 */
422 public function getExternalUrl(string $utm_content = null, string $url = null): string
423 {
424
425 $url = !empty($url) ? $url : PLUGIN_URL;
426
427 if(!empty($utm_content)) {
428 $url .= '?utm_source='.AUTHOR.'&utm_medium=Plugin&utm_campaign='.SLUG.'&utm_content='.$utm_content;
429 }
430
431 return $url;
432 }
433
434 /**
435 * Filter admin page title
436 */
437 public function setAdminTitle(): string
438 {
439 return NAME;
440 }
441
442 /**
443 * render backend favicon
444 */
445 public function addAdminFavicon () {
446
447 echo '<link rel="shortcut icon" type="image/svg+xml" href="' . ASSETS_URL. '/img/favicon.svg">',"\n";
448 echo '<link rel="shortcut icon" type="image/x-icon" href="' . ASSETS_URL. '/img/favicon.ico">',"\n";
449 echo '<link rel="shortcut icon" type="image/png" href="' . ASSETS_URL. '/img/favicon.png">',"\n";
450 echo '<meta name="theme-color" content="#ffffff">',"\n";
451 }
452
453
454 /**
455 * @return App
456 */
457 public static function instance(): App
458 {
459 if ( is_null( self::$_instance ) ) {
460 self::$_instance = new self();
461 }
462
463 return self::$_instance;
464 }
465
466 }
467