PluginProbe
WPIDE – File Manager & Code Editor / 3.4.2
WPIDE – File Manager & Code Editor v3.4.2
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.2, at App/App.php

448 lines 11.6 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 3
220 );
221
222 add_submenu_page(
223 SLUG,
224 __( 'File Manager', 'wpide' ),
225 __( 'File Manager', 'wpide' ),
226 'manage_options',
227 SLUG.'#/file-manager',
228 [$this, 'bootstrap'],
229 3
230 );
231
232 add_submenu_page(
233 SLUG,
234 __( 'File Editor', 'wpide' ),
235 __( 'File Editor', 'wpide' ),
236 'manage_options',
237 SLUG.'#/file-editor',
238 [$this, 'bootstrap'],
239 3
240 );
241
242 add_submenu_page(
243 SLUG,
244 __( 'DB Manager', 'wpide' ),
245 __( 'DB Manager', 'wpide' ),
246 'manage_options',
247 SLUG.'#/db-manager',
248 [$this, 'bootstrap'],
249 3
250 );
251
252 remove_submenu_page(SLUG, SLUG);
253 }
254
255 public function bootstrap() {
256
257 FileBackup::init();
258 ImageStateData::init();
259 EmptyDir::create(TMP_DIR);
260
261 $config = AppConfig::load();
262 $services = AppServices::load();
263 $request = Request::createFromGlobals();
264 $response = new Response();
265 $sresponse = new StreamedResponse();
266
267 $this->container->set(Config::class, $config);
268 $this->container->set(Services::class, $services);
269 $this->container->set(Container::class, $this->container);
270 $this->container->set(Request::class, $request);
271 $this->container->set(Response::class, $response);
272 $this->container->set(StreamedResponse::class, $sresponse);
273
274 $this->services = [];
275 foreach ($services->get() as $key => $service) {
276 if(empty($service['handler'])) {
277 continue;
278 }
279 $this->container->set($key, $this->container->get($service['handler']));
280 $this->container->get($key)->init(isset($service['config']) ? $service['config'] : []);
281 $this->services[$key] = $this->container->get($key);
282 }
283
284 if(!defined('WPIDE_DOING_TASK')) {
285 if (wp_doing_ajax()) {
286 $response->send();
287 } else {
288 $response->sendContent();
289 }
290 }
291 }
292
293 public function deregisterWpStyles()
294 {
295
296 wp_deregister_style('color');
297 wp_deregister_style('forms');
298 wp_deregister_style('dashboard');
299 wp_deregister_style('list-tables');
300 wp_deregister_style('edit');
301 wp_deregister_style('revisions');
302 wp_deregister_style('media');
303 wp_deregister_style('themes');
304 wp_deregister_style('about');
305 wp_deregister_style('nav-menus');
306 wp_deregister_style('widgets');
307 wp_deregister_style('l10n');
308 wp_deregister_style('site-icon');
309
310 wp_register_style('color', null);
311 wp_register_style('forms', null);
312 wp_register_style('dashboard', null);
313 wp_register_style('list-tables', null);
314 wp_register_style('edit', null);
315 wp_register_style('revisions', null);
316 wp_register_style('media', null);
317 wp_register_style('themes', null);
318 wp_register_style('about', null);
319 wp_register_style('nav-menus', null);
320 wp_register_style('widgets', null);
321 wp_register_style('l10n', null);
322 wp_register_style('site-icon', null);
323
324 }
325
326 public function enqueueCommonAssets()
327 {
328
329 wp_enqueue_style(SLUG.'-fs-notices', ASSETS_URL.'global/css/fs-notices.css', [], VERSION);
330 }
331
332 public function ajaxRequest()
333 {
334 if(!$this->canManage()) {
335 die(esc_html__('Restricted Access', 'wpide'));
336 }
337
338 $this->bootstrap();
339 die();
340 }
341
342 public function isPluginScreen($section = null): bool
343 {
344
345 $screen = function_exists('get_current_screen') ? get_current_screen() : null;
346
347 $slug = SLUG;
348
349 if(!empty($section)) {
350 $slug .= '-'. $section;
351 }
352
353 if(!empty($screen)) {
354 return strpos($screen->base, 'page_' . $slug) !== false;
355 }
356
357 if(!empty($_GET['page'])) {
358 $page = sanitize_text_field($_GET['page']);
359 return strpos($page, $slug) !== false;
360 }
361
362 return false;
363 }
364
365 public function isFreemiusScreen($section = null): bool
366 {
367
368 if($section) {
369 return $this->isPluginScreen($section);
370 }
371
372 if(
373 $this->isPluginScreen('account') ||
374 $this->isPluginScreen('pricing') ||
375 $this->isPluginScreen('contact') ||
376 $this->isPluginScreen('affiliates')
377 ) {
378 return true;
379 }
380
381 return false;
382 }
383
384 public function getAdminUrl(): string {
385
386 return admin_url( 'admin.php?page='.SLUG );
387 }
388
389 public function getAjaxUrl($req = ''): string
390 {
391 return admin_url('admin-ajax.php').'?action=wpide_request&req='.$req;
392 }
393
394 /**
395 * Get external url with utm campaign / content
396 *
397 * @param string|null $utm_content
398 * @param string|null $url
399 *
400 * @return string $link;
401 * @since 1.0.0
402 */
403 public function getExternalUrl(string $utm_content = null, string $url = null): string
404 {
405
406 $url = !empty($url) ? $url : PLUGIN_URL;
407
408 if(!empty($utm_content)) {
409 $url .= '?utm_source='.AUTHOR.'&utm_medium=Plugin&utm_campaign='.SLUG.'&utm_content='.$utm_content;
410 }
411
412 return $url;
413 }
414
415 /**
416 * Filter admin page title
417 */
418 public function setAdminTitle(): string
419 {
420 return NAME;
421 }
422
423 /**
424 * render backend favicon
425 */
426 public function addAdminFavicon () {
427
428 echo '<link rel="shortcut icon" type="image/svg+xml" href="' . ASSETS_URL. '/img/favicon.svg">',"\n";
429 echo '<link rel="shortcut icon" type="image/x-icon" href="' . ASSETS_URL. '/img/favicon.ico">',"\n";
430 echo '<link rel="shortcut icon" type="image/png" href="' . ASSETS_URL. '/img/favicon.png">',"\n";
431 echo '<meta name="theme-color" content="#ffffff">',"\n";
432 }
433
434
435 /**
436 * @return App
437 */
438 public static function instance(): App
439 {
440 if ( is_null( self::$_instance ) ) {
441 self::$_instance = new self();
442 }
443
444 return self::$_instance;
445 }
446
447 }
448