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

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