PluginProbe
WPIDE – File Manager & Code Editor / trunk
WPIDE – File Manager & Code Editor vtrunk
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
← All changes | wpide.php +70 -1459 2.5trunk View file →
@@ -1,1459 +1,70 @@
1 -<?php
2 -/*
3 - Plugin Name: WPide
4 - Plugin URI: https://wpide.com/
5 - Description: WordPress code editor with auto-completion of both WordPress and PHP functions with reference, syntax highlighting, line numbers, tabbed editing, automatic backup.
6 - Version: 2.5
7 - Author: WebFactory Ltd
8 - Author URI: https://www.webfactoryltd.com/
9 - Requires at least: 5.0
10 - Requires PHP: 5.2
11 - Tested up to: 5.7
12 - Text Domain: wpide
13 -
14 - Copyright 2021 WebFactory Ltd (email: wpide@webfactoryltd.com)
15 - Copyright 2011 - 2021 Simon @ WPsites
16 -
17 - This program is free software; you can redistribute it and/or modify
18 - it under the terms of the GNU General Public License, version 2, as
19 - published by the Free Software Foundation.
20 -
21 - This program is distributed in the hope that it will be useful,
22 - but WITHOUT ANY WARRANTY; without even the implied warranty of
23 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 - GNU General Public License for more details.
25 -
26 - You should have received a copy of the GNU General Public License
27 - along with this program; if not, write to the Free Software
28 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 -*/
30 -
31 -if (!defined('ABSPATH')) {
32 - die();
33 -}
34 -
35 -require_once 'wf-flyout/wf-flyout.php';
36 -new wf_flyout(__FILE__);
37 -
38 -if (!class_exists('wpide')) :
39 - class wpide
40 - {
41 -
42 - public $site_url, $plugin_url;
43 - private $menu_hook, $version;
44 -
45 -
46 - function __construct()
47 - {
48 -
49 - $this->get_plugin_version();
50 -
51 - // add WPide to the menu
52 - add_action('admin_menu', array($this, 'add_my_menu_page'));
53 -
54 - // hook for processing incoming image saves
55 - if (is_admin() && isset($_GET['wpide_save_image'])) {
56 -
57 - // force local file method for testing - you could force other methods 'direct', 'ssh', 'ftpext' or 'ftpsockets'
58 - $this->override_fs_method('direct');
59 -
60 - add_action('admin_init', array($this, 'wpide_save_image'));
61 - }
62 -
63 - add_action('admin_init', array($this, 'setup_hooks'));
64 -
65 - $this->site_url = get_bloginfo('url');
66 - }
67 -
68 -
69 - public function override_fs_method($method = 'direct')
70 - {
71 - if (defined('FS_METHOD')) {
72 - define('WPIDE_FS_METHOD_FORCED_ELSEWHERE', FS_METHOD); //make a note of the forced method
73 - } else {
74 - define('FS_METHOD', $method); //force direct
75 - }
76 - }
77 -
78 - function is_plugin_page()
79 - {
80 - $current_screen = get_current_screen();
81 -
82 - if ($current_screen->id === $this->menu_hook) {
83 - return true;
84 - } else {
85 - return false;
86 - }
87 - }
88 -
89 - // get plugin version from header
90 - function get_plugin_version()
91 - {
92 - $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
93 - $this->version = $plugin_data['version'];
94 -
95 - return $plugin_data['version'];
96 - } // get_plugin_version
97 -
98 -
99 - public function setup_hooks()
100 - {
101 - // force local file method until I've worked out how to implement the other methods
102 - // main problem being password wouldn't/isn't saved between requests
103 - // you could force other methods 'direct', 'ssh', 'ftpext' or 'ftpsockets'
104 - $this->override_fs_method('direct');
105 -
106 - // Will only enqueue on WPide page
107 - add_action('admin_print_scripts-' . $this->menu_hook, array($this, 'add_admin_js'));
108 - add_action('admin_print_styles-' . $this->menu_hook, array($this, 'add_admin_styles'));
109 -
110 - add_action('admin_print_footer_scripts', array($this, 'print_find_dialog'));
111 -
112 - //setup jqueryFiletree list callback
113 - add_action('wp_ajax_jqueryFileTree', array($this, 'jqueryFileTree_get_list'));
114 - //setup ajax function to get file contents for editing
115 - add_action('wp_ajax_wpide_get_file', array($this, 'wpide_get_file'));
116 - //setup ajax function to save file contents and do automatic backup if needed
117 - add_action('wp_ajax_wpide_save_file', array($this, 'wpide_save_file'));
118 - //setup ajax function to rename file/folder
119 - add_action('wp_ajax_wpide_rename_file', array($this, 'wpide_rename_file'));
120 - //setup ajax function to delete file/folder
121 - add_action('wp_ajax_wpide_delete_file', array($this, 'wpide_delete_file'));
122 - //setup ajax function to handle upload
123 - add_action('wp_ajax_wpide_upload_file', array($this, 'wpide_upload_file'));
124 - //setup ajax function to handle download
125 - add_action('wp_ajax_wpide_download_file', array($this, 'wpide_download_file'));
126 - //setup ajax function to unzip file
127 - add_action('wp_ajax_wpide_unzip_file', array($this, 'wpide_unzip_file'));
128 - //setup ajax function to zip file
129 - add_action('wp_ajax_wpide_zip_file', array($this, 'wpide_zip_file'));
130 - //setup ajax function to create new item (folder, file etc)
131 - add_action('wp_ajax_wpide_create_new', array($this, 'wpide_create_new'));
132 -
133 - //setup ajax function to create new item (folder, file etc)
134 - add_action('wp_ajax_wpide_image_edit_key', array($this, 'wpide_image_edit_key'));
135 -
136 - //setup ajax function for startup to get some debug info, checking permissions etc
137 - add_action('wp_ajax_wpide_startup_check', array($this, 'wpide_startup_check'));
138 -
139 - //add a warning when navigating away from WPide
140 - //it has to go after WordPress scripts otherwise WP clears the binding
141 - // This has been implemented in load-editor.js
142 - // todo:
143 - // add_action('admin_print_footer_scripts', array( $this, 'add_admin_nav_warning' ), 99);
144 -
145 - // Add body class to collapse the wp sidebar nav
146 - add_filter('admin_body_class', array($this, 'hide_wp_sidebar_nav'), 11);
147 -
148 - //hide the update nag
149 - add_action('admin_menu', array($this, 'hide_wp_update_nag'));
150 -
151 - add_filter(
152 - 'plugin_action_links_' . plugin_basename(__FILE__),
153 - array($this, 'plugin_action_links')
154 - );
155 - add_filter('admin_footer_text', array($this, 'admin_footer_text'));
156 - }
157 -
158 -
159 - // add settings link to plugins page
160 - function plugin_action_links($links)
161 - {
162 - $settings_link = '<a href="' . admin_url('admin.php?page=wpide') . '" title="Manage Files">Manage Files</a>';
163 -
164 - array_unshift($links, $settings_link);
165 -
166 - return $links;
167 - } // plugin_action_links
168 -
169 -
170 - // additional powered by text in admin footer; only on WPide page
171 - function admin_footer_text($text)
172 - {
173 - if (!$this->is_plugin_page()) {
174 - return $text;
175 - }
176 -
177 - $text = '<i><a href="https://wpide.com/" title="Visit WPide\'s site for more info" target="_blank">WPide</a> v' . $this->version . ' by <a href="https://www.webfactoryltd.com/" title="Visit our site to get more great plugins" target="_blank">WebFactory Ltd</a>. Please <a target="_blank" href="https://wordpress.org/support/plugin/wpide/reviews/#new-post" title="Rate the plugin">rate the plugin <span>★★★★★</span></a> to help us spread the word. Thank you!</i>';
178 -
179 - return $text;
180 - } // admin_footer_text
181 -
182 -
183 - public function hide_wp_sidebar_nav($classes)
184 - {
185 - global $hook_suffix;
186 -
187 - if (!$this->is_plugin_page()) {
188 - return $classes;
189 - }
190 -
191 - if (apply_filters('wpide_sidebar_folded', $hook_suffix === $this->menu_hook)) {
192 - return str_replace("auto-fold", "", $classes) . ' folded';
193 - }
194 - }
195 -
196 - public function hide_wp_update_nag()
197 - {
198 - if (!$this->is_plugin_page()) {
199 - return;
200 - }
201 -
202 - remove_action('admin_notices', 'update_nag', 3);
203 - }
204 -
205 - public function add_admin_nav_warning()
206 - {
207 -?>
208 - <script type="text/javascript">
209 - jQuery(document).ready(function($) {
210 - window.onbeforeunload = function() {
211 - return 'You are attempting to navigate away from WPide. Make sure you have saved any changes made to your files otherwise they will be forgotten.';
212 - }
213 - });
214 - </script>
215 - <?php
216 - }
217 -
218 - public function add_admin_js()
219 - {
220 - $plugin_path = plugin_dir_url(__FILE__);
221 - //include file tree
222 - wp_enqueue_script('jquery-file-tree', plugins_url("js/jqueryFileTree.js", __FILE__));
223 - //include ace
224 - wp_enqueue_script('ace', plugins_url("js/ace-1.2.0/ace.js", __FILE__));
225 - //include ace modes for css, javascript & php
226 - wp_enqueue_script('ace-mode-css', $plugin_path . 'js/ace-1.2.0/mode-css.js');
227 - wp_enqueue_script('ace-mode-less', $plugin_path . 'js/ace-1.2.0/mode-less.js');
228 - wp_enqueue_script('ace-mode-javascript', $plugin_path . 'js/ace-1.2.0/mode-javascript.js');
229 - wp_enqueue_script('ace-mode-php', $plugin_path . 'js/ace-1.2.0/mode-php.js');
230 - //include ace theme
231 - wp_enqueue_script('ace-theme', plugins_url("js/ace-1.2.0/theme-dawn.js", __FILE__)); //ambiance looks really nice for high contrast
232 - // wordpress-completion tags
233 - wp_enqueue_script('wpide-wordpress-completion', plugins_url("js/autocomplete/wordpress.js", __FILE__));
234 - // php-completion tags
235 - wp_enqueue_script('wpide-php-completion', plugins_url("js/autocomplete/php.js", __FILE__));
236 - // load editor
237 - wp_enqueue_script('wpide-load-editor', plugins_url("js/load-editor.js", __FILE__));
238 - // load filetree menu
239 - wp_enqueue_script('wpide-load-filetree-menu', plugins_url("js/load-filetree-menu.js", __FILE__));
240 - // load autocomplete dropdown
241 - wp_enqueue_script('wpide-dd', plugins_url("js/jquery.dd.js", __FILE__));
242 -
243 - // load jquery ui
244 - wp_enqueue_script('jquery-ui', plugins_url("js/jquery-ui-1.9.2.custom.min.js", __FILE__), array('jquery'), '1.9.2');
245 -
246 - // load color picker
247 - wp_enqueue_script('ImageColorPicker', plugins_url("js/ImageColorPicker.js", __FILE__), array('jquery'), '0.3');
248 - }
249 -
250 - public function add_admin_styles()
251 - {
252 - //main wpide styles
253 - wp_register_style('wpide_style', plugins_url('css/wpide.css', __FILE__));
254 - wp_enqueue_style('wpide_style');
255 - //filetree styles
256 - wp_register_style('wpide_filetree_style', plugins_url('css/jqueryFileTree.css', __FILE__));
257 - wp_enqueue_style('wpide_filetree_style');
258 - //autocomplete dropdown styles
259 - wp_register_style('wpide_dd_style', plugins_url('css/dd.css', __FILE__));
260 - wp_enqueue_style('wpide_dd_style');
261 -
262 - //jquery ui styles
263 - wp_register_style('wpide_jqueryui_style', plugins_url('css/flick/jquery-ui-1.8.20.custom.css', __FILE__));
264 - wp_enqueue_style('wpide_jqueryui_style');
265 - }
266 -
267 - public function jqueryFileTree_get_list()
268 - {
269 - //check the user has the permissions
270 - check_admin_referer('plugin-name-action_wpidenonce');
271 - if (!current_user_can('edit_themes'))
272 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
273 -
274 - //setup wp_filesystem api
275 - global $wp_filesystem;
276 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
277 - $form_fields = null; // for now, but at some point the login info should be passed in here
278 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
279 - // no credentials yet, just produced a form for the user to fill in
280 - return true; // stop the normal page form from displaying
281 - }
282 -
283 - if (!WP_Filesystem($creds))
284 - return false;
285 -
286 - $_POST['dir'] = urldecode($_POST['dir']);
287 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
288 -
289 - if ($wp_filesystem->exists($root . $_POST['dir'])) {
290 -
291 - $files = $wp_filesystem->dirlist($root . $_POST['dir']);
292 -
293 - echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
294 - if (count($files) > 0) {
295 -
296 - //build separate arrays for folders and files
297 - $dir_array = array();
298 - $file_array = array();
299 - foreach ($files as $file => $file_info) {
300 - if ($file != '.' && $file != '..' && $file_info['type'] == 'd') {
301 - $file_string = strtolower(preg_replace("[._-]", "", $file));
302 - $dir_array[$file_string] = $file_info;
303 - } elseif ($file != '.' && $file != '..' && $file_info['type'] == 'f') {
304 - $file_string = strtolower(preg_replace("[._-]", "", $file));
305 - $file_array[$file_string] = $file_info;
306 - }
307 - }
308 -
309 - //shot those arrays
310 - ksort($dir_array);
311 - ksort($file_array);
312 -
313 - // All dirs
314 - foreach ($dir_array as $file => $file_info) {
315 - echo "<li class=\"directory collapsed\" draggable=\"true\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file_info['name']) . "/\" draggable=\"false\">" . htmlentities($file_info['name']) . "</a></li>";
316 - }
317 - // All files
318 - foreach ($file_array as $file => $file_info) {
319 - $ext = preg_replace('/^.*\./', '', $file_info['name']);
320 - echo "<li class=\"file ext_$ext\" draggable=\"true\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file_info['name']) . "\" draggable=\"false\">" . htmlentities($file_info['name']) . "</a></li>";
321 - }
322 - }
323 - //output toolbar for creating new file, folder etc
324 - echo "<li class=\"create_new\"><a class='new_directory' title='Create a new directory here.' href=\"#\" rel=\"{type: 'directory', path: '" . htmlentities($_POST['dir']) . "'}\"></a> <a class='new_file' title='Create a new file here.' href=\"#\" rel=\"{type: 'file', path: '" . htmlentities($_POST['dir']) . "'}\"></a><br style='clear:both;' /></li>";
325 - echo "</ul>";
326 - }
327 -
328 - die(); // this is required to return a proper result
329 - }
330 -
331 -
332 - public function wpide_get_file()
333 - {
334 - //check the user has the permissions
335 - check_admin_referer('plugin-name-action_wpidenonce');
336 - if (!current_user_can('edit_themes'))
337 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
338 -
339 - //setup wp_filesystem api
340 - global $wp_filesystem;
341 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
342 - $form_fields = null; // for now, but at some point the login info should be passed in here
343 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
344 - // no credentials yet, just produced a form for the user to fill in
345 - return true; // stop the normal page form from displaying
346 - }
347 - if (!WP_Filesystem($creds))
348 - return false;
349 -
350 -
351 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
352 - $file_name = $root . stripslashes($_POST['filename']);
353 - echo $wp_filesystem->get_contents($file_name);
354 - die(); // this is required to return a proper result
355 - }
356 -
357 - public function wpide_image_edit_key()
358 - {
359 -
360 - //check the user has the permissions
361 - check_admin_referer('plugin-name-action_wpidenonce');
362 - if (!current_user_can('edit_themes')) {
363 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
364 - }
365 -
366 - //create a nonce based on the image path
367 - echo wp_create_nonce('wpide_image_edit' . $_POST['file']);
368 - }
369 -
370 - public function wpide_create_new()
371 - {
372 - //check the user has the permissions
373 - check_admin_referer('plugin-name-action_wpidenonce');
374 - if (!current_user_can('edit_themes')) {
375 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
376 - }
377 -
378 - //setup wp_filesystem api
379 - global $wp_filesystem;
380 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
381 - $form_fields = null; // for now, but at some point the login info should be passed in here
382 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
383 - // no credentials yet, just produced a form for the user to fill in
384 - return true; // stop the normal page form from displaying
385 - }
386 - if (!WP_Filesystem($creds))
387 - return false;
388 -
389 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
390 -
391 - //check all required vars are passed
392 - if (strlen($_POST['path']) > 0 && strlen($_POST['type']) > 0 && strlen($_POST['file']) > 0) {
393 - $filename = $_POST['file'];
394 - $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
395 - $filename = preg_replace("#\x{00a0}#siu", ' ', $filename);
396 - $filename = str_replace($special_chars, '', $filename);
397 - $filename = str_replace(array('%20', '+'), '-', $filename);
398 - $filename = preg_replace('/[\r\n\t -]+/', '-', $filename);
399 -
400 - $path = $_POST['path'];
401 -
402 - if ($_POST['type'] == "directory") {
403 - $write_result = $wp_filesystem->mkdir($root . $path . $filename, FS_CHMOD_DIR);
404 -
405 - if ($write_result) {
406 - die("1"); //created
407 - } else {
408 - echo "Problem creating directory" . $root . $path . $filename;
409 - }
410 - } else if ($_POST['type'] == "file") {
411 - //write the file
412 - $write_result = $wp_filesystem->put_contents(
413 - $root . $path . $filename,
414 - '',
415 - FS_CHMOD_FILE // predefined mode settings for WP files
416 - );
417 -
418 - if ($write_result) {
419 - die("1"); //created
420 - } else {
421 - echo "Problem creating file " . $root . $path . $filename;
422 - }
423 - }
424 - //print_r($_POST);
425 - }
426 -
427 - echo "0";
428 - die(); // this is required to return a proper result
429 - }
430 -
431 - public function wpide_save_file()
432 - {
433 - //check the user has the permissions
434 - check_admin_referer('plugin-name-action_wpidenonce');
435 - if (!current_user_can('edit_themes')) {
436 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
437 - }
438 -
439 - $is_php = false;
440 -
441 - /*
442 - * Check file syntax of PHP files by parsing the PHP
443 - * If a site is running low on memory this PHP parser library could well tip memory usage over the edge
444 - * Especially if you are editing a large PHP file.
445 - * Might be worth either making this syntax check optional or it only running if memory is available.
446 - * Symptoms: no response on file save, and errors in your log like "Fatal error: Allowed memory size of 8388608 bytes exhausted…"
447 - */
448 - if (preg_match("#\.php$#i", $_POST['filename'])) {
449 -
450 - $is_php = true;
451 -
452 - require('PHP-Parser/lib/bootstrap.php');
453 - ini_set('xdebug.max_nesting_level', 2000);
454 -
455 - $code = stripslashes($_POST['content']);
456 -
457 - $parser = new PHPParser_Parser(new PHPParser_Lexer);
458 -
459 - try {
460 - $stmts = $parser->parse($code);
461 - } catch (PHPParser_Error $e) {
462 - echo 'Parse Error: ', $e->getMessage();
463 - die();
464 - }
465 - }
466 -
467 - //setup wp_filesystem api
468 - global $wp_filesystem;
469 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
470 - $form_fields = null; // for now, but at some point the login info should be passed in here
471 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
472 - // no credentials yet, just produced a form for the user to fill in
473 - return true; // stop the normal page form from displaying
474 - }
475 - if (!WP_Filesystem($creds))
476 - echo "Cannot initialise the WP file system API";
477 -
478 - //save a copy of the file and create a backup just in case
479 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
480 - $file_name = $root . stripslashes($_POST['filename']);
481 -
482 - //set backup filename
483 - $backup_path = 'backups' . preg_replace("#\.php$#i", "_" . date("Y-m-d-H") . ".php", $_POST['filename']);
484 - $backup_path_full = plugin_dir_path(__FILE__) . $backup_path;
485 - //create backup directory if not there
486 - $new_file_info = pathinfo($backup_path_full);
487 - if (!$wp_filesystem->is_dir($new_file_info['dirname'])) wp_mkdir_p($new_file_info['dirname']); //should use the filesytem api here but there isn't a comparable command right now
488 -
489 - if ($is_php) {
490 - //create the backup file adding some php to the file to enable direct restore
491 - global $current_user;
492 - get_currentuserinfo();
493 - $user_md5 = md5(serialize($current_user));
494 -
495 - $restore_php = '<?php /* start WPide restore code */
496 - if ($_POST["restorewpnonce"] === "' . $user_md5 . $_POST['_wpnonce'] . '"){
497 - if ( file_put_contents ( "' . $file_name . '" , preg_replace("#<\?php /\* start WPide(.*)end WPide restore code \*/ \?>#s", "", file_get_contents("' . $backup_path_full . '") ) ) ){
498 - echo "Your file has been restored, overwritting the recently edited file! \n\n The active editor still contains the broken or unwanted code. If you no longer need that content then close the tab and start fresh with the restored file.";
499 - }
500 - }else{
501 - echo "-1";
502 - }
503 - die();
504 - /* end WPide restore code */ ?>';
505 -
506 - file_put_contents($backup_path_full, $restore_php . file_get_contents($file_name));
507 - } else {
508 - //do normal backup
509 - $wp_filesystem->copy($file_name, $backup_path_full);
510 - }
511 -
512 - //save file
513 - if ($wp_filesystem->put_contents($file_name, stripslashes($_POST['content']))) {
514 -
515 - //lets create an extra long nonce to make it less crackable
516 - global $current_user;
517 - get_currentuserinfo();
518 - $user_md5 = md5(serialize($current_user));
519 -
520 - $result = "\"" . $backup_path . ":::" . $user_md5 . "\"";
521 - }
522 -
523 - die($result); // this is required to return a proper result
524 - }
525 -
526 -
527 - public function wpide_rename_file()
528 - {
529 - global $wp_filesystem;
530 -
531 - //check the user has the permissions
532 - check_admin_referer('plugin-name-action_wpidenonce');
533 - if (!current_user_can('manage_options')) {
534 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
535 - }
536 -
537 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
538 - $form_fields = null; // for now, but at some point the login info should be passed in here
539 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
540 - if (false === $creds) {
541 - // no credentials yet, just produced a form for the user to fill in
542 - return true; // stop the normal page form from displaying
543 - }
544 - if (!WP_Filesystem($creds))
545 - echo "Cannot initialise the WP file system API";
546 -
547 -
548 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
549 - $file_name = $root . stripslashes($_POST['filename']);
550 - $new_name = dirname($file_name) . '/' . stripslashes($_POST['newname']);
551 -
552 - if (!$wp_filesystem->exists($file_name)) {
553 - echo 'The target file doesn\'t exist!';
554 - exit;
555 - }
556 -
557 - if ($wp_filesystem->exists($new_name)) {
558 - echo 'The destination file exists!';
559 - exit;
560 - }
561 -
562 - // Move instead of rename
563 - $renamed = $wp_filesystem->move($file_name, $new_name);
564 -
565 - if (!$renamed) {
566 - echo 'The file could not be renamed!';
567 - }
568 - exit;
569 - }
570 -
571 -
572 - public function wpide_delete_file()
573 - {
574 - global $wp_filesystem;
575 -
576 - //check the user has the permissions
577 - check_admin_referer('plugin-name-action_wpidenonce');
578 - if (!current_user_can('manage_options')) {
579 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
580 - }
581 -
582 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
583 - $form_fields = null; // for now, but at some point the login info should be passed in here
584 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
585 - if (false === $creds) {
586 - // no credentials yet, just produced a form for the user to fill in
587 - return true; // stop the normal page form from displaying
588 - }
589 - if (!WP_Filesystem($creds))
590 - echo "Cannot initialise the WP file system API";
591 -
592 -
593 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
594 - $file_name = $root . stripslashes($_POST['filename']);
595 -
596 - if (!$wp_filesystem->exists($file_name)) {
597 - echo 'The file doesn\'t exist!';
598 - exit;
599 - }
600 -
601 - $deleted = $wp_filesystem->delete($file_name);
602 -
603 - if (!$deleted) {
604 - echo 'The file couldn\'t be deleted.';
605 - }
606 -
607 - exit;
608 - }
609 -
610 - public function wpide_upload_file()
611 - {
612 - global $wp_filesystem;
613 -
614 - //check the user has the permissions
615 - check_admin_referer('plugin-name-action_wpidenonce');
616 - if (!current_user_can('manage_options')) {
617 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
618 - }
619 -
620 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
621 - $form_fields = null; // for now, but at some point the login info should be passed in here
622 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
623 - if (false === $creds) {
624 - // no credentials yet, just produced a form for the user to fill in
625 - return true; // stop the normal page form from displaying
626 - }
627 - if (!WP_Filesystem($creds))
628 - echo "Cannot initialise the WP file system API";
629 -
630 -
631 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
632 - $destination_folder = $root . stripslashes($_POST['destination']);
633 -
634 - foreach ($_FILES as $file) {
635 - if (!is_uploaded_file($file['tmp_name'])) {
636 - continue;
637 - }
638 -
639 - $destination = $destination_folder . $file['name'];
640 -
641 - if ($wp_filesystem->exists($destination)) {
642 - exit($file['name'] . ' already exists!');
643 - }
644 -
645 - if (!$wp_filesystem->move($file['tmp_name'], $destination)) {
646 - exit($file['name'] . ' could not be moved.');
647 - }
648 -
649 - if (!$wp_filesystem->chmod($destination)) {
650 - exit($file['name'] . ' could not be chmod.');
651 - }
652 - }
653 - exit;
654 - }
655 -
656 - public function wpide_download_file()
657 - {
658 - global $wp_filesystem;
659 -
660 - //check the user has the permissions
661 - check_admin_referer('plugin-name-action_wpidenonce');
662 - if (!current_user_can('manage_options')) {
663 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
664 - }
665 -
666 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
667 - $form_fields = null; // for now, but at some point the login info should be passed in here
668 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
669 - if (false === $creds) {
670 - // no credentials yet, just produced a form for the user to fill in
671 - return true; // stop the normal page form from displaying
672 - }
673 - if (!WP_Filesystem($creds))
674 - echo "Cannot initialise the WP file system API";
675 -
676 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
677 - $file_name = $root . stripslashes($_POST['filename']);
678 -
679 - if (!$wp_filesystem->exists($file_name)) {
680 - echo 'The file doesn\'t exist!';
681 - exit;
682 - }
683 -
684 - header('Content-Description: File Transfer');
685 - header('Content-Type: application/octet-stream');
686 - header('Content-Disposition: filename="' . basename($file_name) . '"');
687 - header('Expires: 0');
688 - header('Cache-Control: must-revalidate');
689 - header('Pragma: public');
690 -
691 - echo $wp_filesystem->get_contents($file_name);
692 - exit;
693 - }
694 -
695 - public function wpide_zip_file()
696 - {
697 - global $wp_filesystem;
698 -
699 - //check the user has the permissions
700 - check_admin_referer('plugin-name-action_wpidenonce');
701 - if (!current_user_can('manage_options')) {
702 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
703 - }
704 -
705 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
706 - $file_name = $root . stripslashes($_POST['filename']);
707 -
708 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
709 - $form_fields = null; // for now, but at some point the login info should be passed in here
710 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
711 - if (false === $creds) {
712 - // no credentials yet, just produced a form for the user to fill in
713 - return true; // stop the normal page form from displaying
714 - }
715 - if (!WP_Filesystem($creds))
716 - echo "Cannot initialise the WP file system API";
717 -
718 -
719 - if (!$wp_filesystem->exists($file_name)) {
720 - echo 'Error: target file does not exist!';
721 - exit;
722 - }
723 -
724 - $ext = '.zip';
725 - switch (apply_filters('wpide_compression_method', 'zip')) {
726 - case 'gz':
727 - $ext = '.tar.gz';
728 - break;
729 - case 'tar':
730 - $ext = '.tar';
731 - break;
732 - case 'b2z':
733 - $ext = '.b2z';
734 - break;
735 - case 'zip':
736 - $ext = '.zip';
737 - break;
738 - }
739 -
740 - // Unzip a file to its current directory.
741 - if ($wp_filesystem->is_dir($file_name)) {
742 - $output_path = dirname($file_name) . '/' . basename($file_name) . $ext;
743 - } else {
744 - $output_path = $file_name;
745 - $output_path = strstr($file_name, '.', true) . $ext;
746 - }
747 -
748 - $zipped = self::do_zip_file($file_name, $output_path);
749 -
750 - if (is_wp_error($zipped)) {
751 - printf('%s: %s', $zipped->get_error_code(), $zipped->get_error_message());
752 - exit;
753 - }
754 -
755 - exit;
756 - }
757 -
758 - protected function do_zip_file($file, $to)
759 - {
760 - // Unzip can use a lot of memory, but not this much hopefully
761 - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
762 -
763 - $method = apply_filters('wpide_compression_method', 'zip');
764 -
765 - switch ($method) {
766 - case 'gz':
767 - case 'tar':
768 - if (class_exists('PharData') && apply_filters('unzip_file_use_phardata', true)) {
769 - exit('yes');
770 - return self::_zip_archive_phardata($file, $to);
771 - } else {
772 - exit('figure it out');
773 - }
774 -
775 - /* if ( $method === 'gz' ) {
776 - $gz = gzopen( $to );
777 - }
778 -*/
779 - break;
780 - case 'b2z':
781 - exit('B2Z!');
782 - case 'zip':
783 - default:
784 - if ($method !== 'zip') {
785 - trigger_error(sprintf('"%s" is not a valid compression mechanism.', $method));
786 - }
787 -
788 - if (class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true)) {
789 - return self::_zip_file_ziparchive($file, $to);
790 - } else {
791 - // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
792 - return self::_zip_file_pclzip($file, $to);
793 - }
794 - break;
795 - }
796 - }
797 -
798 - protected static function _zip_file_ziparchive($file, $to)
799 - {
800 - $z = new ZipArchive;
801 - $opened = $z->open($to, ZipArchive::CREATE);
802 -
803 - if ($opened !== true) {
804 - switch ($opened) {
805 - case ZipArchive::ER_EXISTS:
806 - return new WP_Error(
807 - 'ZipArchive Error',
808 - 'File already exists',
809 - ZipArchive::ER_EXISTS
810 - );
811 - case ZipArchive::ER_INCONS:
812 - return new WP_Error(
813 - 'ZipArchive Error',
814 - 'Archive inconsistent',
815 - ZipArchive::ER_INCONS
816 - );
817 - case ZipArchive::ER_INVAL:
818 - return new WP_Error(
819 - 'ZipArchive Error',
820 - 'Invalid argument',
821 - ZipArchive::ER_INVAL
822 - );
823 - case ZipArchive::ER_MEMORY:
824 - return new WP_Error(
825 - 'ZipArchive Error',
826 - 'Malloc failure',
827 - ZipArchive::ER_MEMORY
828 - );
829 - case ZipArchive::ER_NOENT:
830 - return new WP_Error(
831 - 'ZipArchive Error',
832 - 'No such file.',
833 - ZipArchive::ER_NOENT
834 - );
835 - case ZipArchive::ER_NOZIP:
836 - return new WP_Error(
837 - 'ZipArchive Error',
838 - 'Not a zip archive.',
839 - ZipArchive::ER_NOZIP
840 - );
841 - case ZipArchive::ER_OPEN:
842 - return new WP_Error(
843 - 'ZipArchive Error',
844 - 'Can\'t open file.',
845 - ZipArchive::ER_OPEN
846 - );
847 - case ZipArchive::ER_READ:
848 - return new WP_Error(
849 - 'ZipArchive Error',
850 - 'Read Error',
851 - ZipArchive::ER_READ
852 - );
853 - case ZipArchive::ER_SEEK:
854 - return new WP_Error(
855 - 'ZipArchive Error',
856 - 'Seek Error',
857 - ZipArchive::ER_SEEK
858 - );
859 -
860 - default:
861 - return new WP_Error(
862 - 'ZipArchive Error',
863 - 'Unknown Error',
864 - $opened
865 - );
866 - break;
867 - }
868 - }
869 -
870 - if (is_dir($file)) {
871 - $base = dirname($file);
872 - $file = untrailingslashit($file);
873 -
874 - $z = self::_zip_folder_ziparchive($base, $file, $to, $z);
875 - if (is_wp_error($z))
876 - return $z;
877 - } else {
878 - $z->addFile($file, basename($file));
879 - }
880 -
881 - $z->close();
882 -
883 - return true;
884 - }
885 -
886 - protected static function _zip_folder_ziparchive($zip_base, $folder, $to, $z)
887 - {
888 - $handle = opendir($folder);
889 - while (1) {
890 - $file = readdir($handle);
891 -
892 - if (false === $file)
893 - break;
894 -
895 - if (($file != '.') && ($file != '..')) {
896 - $filePath = "$folder/$file";
897 - $filePathRel = str_replace($zip_base, '', $filePath);
898 -
899 - if ($filePathRel[0] === '/')
900 - $filePathRel = substr($filePathRel, 1);
901 -
902 - if (is_file($filePath)) {
903 - $z->addFile($filePath, $filePathRel);
904 - } elseif (is_dir($filePath)) {
905 - // Add sub-directory.
906 - $z->addEmptyDir($filePathRel);
907 - self::_zip_folder_ziparchive($zip_base, $filePath, $to, $z);
908 - }
909 - }
910 - }
911 - closedir($handle);
912 -
913 - return $z;
914 - }
915 -
916 - protected static function _zip_file_pclzip($file, $to)
917 - {
918 - require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
919 -
920 - $pz = new PclZip($to);
921 - $created = $pz->create($file, PCLZIP_OPT_REMOVE_PATH, dirname($file));
922 -
923 - if (!$created) {
924 - return new WP_Error('PclZip Error', $pz->errorInfo(true));
925 - }
926 -
927 - return true;
928 - }
929 -
930 - protected static function _zip_file_phardata($file, $to)
931 - {
932 - $p = new PharData($to);
933 -
934 - if (is_dir($file)) {
935 - $p->buildFromDirectory($file);
936 - } else {
937 - $p->addFile($file, basename($file));
938 - }
939 -
940 - return true;
941 - }
942 -
943 - public function wpide_unzip_file()
944 - {
945 - global $wp_filesystem;
946 -
947 - //check the user has the permissions
948 - check_admin_referer('plugin-name-action_wpidenonce');
949 - if (!current_user_can('manage_options')) {
950 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
951 - }
952 -
953 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
954 - $file_name = $root . stripslashes($_POST['filename']);
955 -
956 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
957 - $form_fields = null; // for now, but at some point the login info should be passed in here
958 - $creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields);
959 - if (false === $creds) {
960 - // no credentials yet, just produced a form for the user to fill in
961 - return true; // stop the normal page form from displaying
962 - }
963 - if (!WP_Filesystem($creds))
964 - echo "Cannot initialise the WP file system API";
965 -
966 -
967 - if (!$wp_filesystem->exists($file_name)) {
968 - echo 'Error: Extraction path doesn\'t exist!';
969 - exit;
970 - }
971 -
972 - $unzipped = self::do_unzip_file($file_name, dirname($file_name));
973 -
974 - if (is_wp_error($unzipped)) {
975 - printf('%s: %s', $unzipped->get_error_code(), $unzipped->get_error_message());
976 - exit;
977 - }
978 -
979 - exit;
980 - }
981 -
982 - protected function do_unzip_file($from, $to)
983 - {
984 - if (!file_exists($from)) {
985 - return new WP_Error('file-missing', 'Archive missing.');
986 - }
987 -
988 - $fp = fopen($from, 'rb');
989 - $bytes = fread($fp, 2);
990 - fclose($fp);
991 -
992 - switch ($bytes) {
993 - case "\37\213":
994 - // gz
995 - case 'BZ':
996 - return new WP_Error('unimplemented', 'That method is not yet implemented.');
997 - break;
998 - case 'PK':
999 - return unzip_file($from, $to);
1000 - default:
1001 - return new WP_Error('unknown', 'Unknown archive type');
1002 - }
1003 - }
1004 -
1005 - public function wpide_save_image()
1006 - {
1007 - $filennonce = split("::", $_POST["opt"]); //file::nonce
1008 -
1009 - //check the user has a valid nonce
1010 - //we are checking two variations of the nonce, one as-is and another that we have removed a trailing zero from
1011 - //this is to get around some sort of bug where a nonce generated on another page has a trailing zero and a nonce generated/checked here doesn't have the zero
1012 - if (
1013 - !wp_verify_nonce($filennonce[1], 'wpide_image_edit' . $filennonce[0]) &&
1014 - !wp_verify_nonce(rtrim($filennonce[1], "0"), 'wpide_image_edit' . $filennonce[0])
1015 - ) {
1016 - die('Security check'); //die because both checks failed
1017 - }
1018 - //check the user has the permissions
1019 - if (!current_user_can('edit_themes')) {
1020 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
1021 - }
1022 -
1023 -
1024 - $_POST['content'] = base64_decode($_POST["data"]); //image content
1025 - $_POST['filename'] = $filennonce[0]; //filename
1026 -
1027 - //setup wp_filesystem api
1028 - global $wp_filesystem;
1029 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
1030 - $form_fields = null; // for now, but at some point the login info should be passed in here
1031 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
1032 - // no credentials yet, just produced a form for the user to fill in
1033 - return true; // stop the normal page form from displaying
1034 - }
1035 - if (!WP_Filesystem($creds))
1036 - echo "Cannot initialise the WP file system API";
1037 -
1038 - //save a copy of the file and create a backup just in case
1039 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
1040 - $file_name = $root . stripslashes($_POST['filename']);
1041 -
1042 - //set backup filename
1043 - $backup_path = 'backups' . preg_replace("#\.php$#i", "_" . date("Y-m-d-H") . ".php", $_POST['filename']);
1044 - $backup_path = plugin_dir_path(__FILE__) . $backup_path;
1045 -
1046 - //create backup directory if not there
1047 - $new_file_info = pathinfo($backup_path);
1048 - if (!$wp_filesystem->is_dir($new_file_info['dirname'])) wp_mkdir_p($new_file_info['dirname']); //should use the filesytem api here but there isn't a comparable command right now
1049 -
1050 - //do backup
1051 - $wp_filesystem->move($file_name, $backup_path);
1052 -
1053 - //save file
1054 - if ($wp_filesystem->put_contents($file_name, $_POST['content'])) {
1055 - $result = "success";
1056 - }
1057 -
1058 - if ($result == "success") {
1059 - wp_die('<p>' . __('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.') . '</p>');
1060 - } else {
1061 - wp_die('<p>' . __('<strong>Problem saving image.</strong> <br /><a href="JavaScript:window.close();">Close this window / tab</a> and try editing the image again.') . '</p>');
1062 - }
1063 - //print_r($_POST);
1064 - }
1065 -
1066 -
1067 - public function wpide_startup_check()
1068 - {
1069 - global $wp_filesystem, $wp_version;
1070 -
1071 - echo "\n\n\n\nWPIDE STARTUP CHECKS \n";
1072 - echo "___________________ \n\n";
1073 -
1074 - // WordPress version
1075 - if ($wp_version > 5) {
1076 - echo "WordPress version = " . $wp_version . "\n\n";
1077 - } else {
1078 - echo "WordPress version = " . $wp_version . " (which is too old to run WPide) \n\n";
1079 - }
1080 -
1081 - //check the user has the permissions
1082 - check_admin_referer('plugin-name-action_wpidenonce');
1083 - if (!current_user_can('edit_themes'))
1084 - wp_die('<p>' . __('You do not have sufficient permissions to edit templates for this site. SORRY') . '</p>');
1085 -
1086 - if (defined('WPIDE_FS_METHOD_FORCED_ELSEWHERE')) {
1087 - echo "WordPress filesystem API has been forced to use the " . WPIDE_FS_METHOD_FORCED_ELSEWHERE . " method by another plugin/WordPress. \n\n";
1088 - }
1089 -
1090 - //setup wp_filesystem api
1091 - $wpide_filesystem_before = $wp_filesystem;
1092 -
1093 - $url = wp_nonce_url('admin.php?page=wpide', 'plugin-name-action_wpidenonce');
1094 - $form_fields = null; // for now, but at some point the login info should be passed in here
1095 - ob_start();
1096 - if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields))) {
1097 - // if we get here, then we don't have credentials yet,
1098 - // but have just produced a form for the user to fill in,
1099 - // so stop processing for now
1100 - //return true; // stop the normal page form from displaying
1101 - }
1102 - ob_end_clean();
1103 - if (!WP_Filesystem($creds)) {
1104 -
1105 - echo "There has been a problem initialising the filesystem API \n\n";
1106 - echo "Filesystem API before this plugin ran: \n\n" . print_r($wpide_filesystem_before, true);
1107 - echo "Filesystem API now: \n\n" . print_r($wp_filesystem, true);
1108 - }
1109 - unset($wpide_filesystem_before);
1110 -
1111 -
1112 - $root = apply_filters('wpide_filesystem_root', WP_CONTENT_DIR);
1113 - if (isset($wp_filesystem)) {
1114 -
1115 - //Running webservers user and group
1116 - echo "Web server user/group = " . getenv('APACHE_RUN_USER') . ":" . getenv('APACHE_RUN_GROUP') . "\n";
1117 - //wp-content user and group
1118 - echo "wp-content owner/group = " . $wp_filesystem->owner($root) . ":" . $wp_filesystem->group($root) . "\n\n";
1119 -
1120 -
1121 - //check we can list wp-content files
1122 - if ($wp_filesystem->exists($root)) {
1123 -
1124 - $files = $wp_filesystem->dirlist($root);
1125 - if (count($files) > 0) {
1126 - echo "wp-content folder exists and contains " . count($files) . " files \n";
1127 - } else {
1128 - echo "wp-content folder exists but we cannot read it's contents \n";
1129 - }
1130 - }
1131 -
1132 - // $wp_filesystem->owner() $wp_filesystem->group() $wp_filesystem->is_writable() $wp_filesystem->is_readable()
1133 - echo "\nUsing the " . $wp_filesystem->method . " method of the WP filesystem API\n";
1134 -
1135 - //wp-content editable?
1136 - echo "The wp-content folder " . ($wp_filesystem->is_readable($root) == 1 ? "IS" : "IS NOT") . " readable and " . ($wp_filesystem->is_writable($root) == 1 ? "IS" : "IS NOT") . " writable by this method \n";
1137 -
1138 -
1139 - //plugins folder editable
1140 - echo "The wp-content/plugins folder " . ($wp_filesystem->is_readable($root . "/plugins") == 1 ? "IS" : "IS NOT") . " readable and " . ($wp_filesystem->is_writable($root . "/plugins") == 1 ? "IS" : "IS NOT") . " writable by this method \n";
1141 -
1142 -
1143 - //themes folder editable
1144 - echo "The wp-content/themes folder " . ($wp_filesystem->is_readable($root . "/themes") == 1 ? "IS" : "IS NOT") . " readable and " . ($wp_filesystem->is_writable($root . "/themes") == 1 ? "IS" : "IS NOT") . " writable by this method \n";
1145 - }
1146 -
1147 - echo "___________________ \n\n\n\n";
1148 -
1149 - echo " If the file tree to the right is empty there is a possibility that your server permissions are not compatible with this plugin. \n The startup information above may shed some light on things. \n Paste that information into the support forum for further assistance.";
1150 -
1151 -
1152 - die();
1153 - }
1154 -
1155 - public function add_my_menu_page()
1156 - {
1157 - $this->menu_hook = add_menu_page('WPide', 'WPide', 'edit_themes', "wpide", array($this, 'my_menu_page'), 'dashicons-editor-code');
1158 - }
1159 -
1160 - public function my_menu_page()
1161 - {
1162 - if (!current_user_can('edit_themes')) {
1163 - wp_die('<p>You do not have sufficient permissions to edit files for this site.</p>');
1164 - }
1165 -
1166 - $app_url = get_bloginfo('url'); //need to make this https if we are currently looking on the site using https (even though https for admin might not be forced it can still cause issues)
1167 - if (is_ssl()) $app_url = str_replace("http:", "https:", $app_url);
1168 -
1169 - ?>
1170 - <script>
1171 - var wpide_app_path = "<?php echo plugin_dir_url(__FILE__); ?>";
1172 - //dont think this is needed any more.. var wpide_file_root_url = "<?php echo apply_filters("wpide_file_root_url", WP_CONTENT_URL); ?>";
1173 - var user_nonce_addition = '';
1174 -
1175 - function the_filetree() {
1176 - jQuery('#wpide_file_browser').fileTree({
1177 - script: ajaxurl
1178 - }, function(parent, file) {
1179 -
1180 - if (jQuery(parent).hasClass("create_new")) { //create new file/folder
1181 - //to create a new item we need to know the name of it so show input
1182 -
1183 - var item = eval('(' + file + ')');
1184 -
1185 - //hide all inputs just incase one is selected
1186 - jQuery(".new_item_inputs").hide();
1187 - //show the input form for this
1188 - jQuery("div.new_" + item.type).show();
1189 - jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").focus();
1190 - jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").attr("rel", file);
1191 -
1192 -
1193 - } else if (jQuery(".wpide_tab[rel='" + file + "']").length > 0) { //focus existing tab
1194 - jQuery(".wpide_tab[sessionrel='" + jQuery(".wpide_tab[rel='" + file + "']").attr("sessionrel") + "']").click(); //focus the already open tab
1195 - } else { //open file
1196 -
1197 - var image_pattern = new RegExp("(\\.jpg$|\\.gif$|\\.png$|\\.bmp$)");
1198 - if (image_pattern.test(file)) {
1199 - //it's an image so open it for editing
1200 -
1201 - //using modal+iframe
1202 - if ("lets not" == "use the modal for now") {
1203 -
1204 - var NewDialog = jQuery('<div id="MenuDialog">\
1205 - <iframe src="http://www.sumopaint.com/app/?key=ebcdaezjeojbfgih&target=<?php echo get_bloginfo('url') . "?action=wpide_image_save"; ?>&url=<?php echo get_bloginfo('url') . "/wp-content"; ?>' + file + '&title=Edit image&service=Save back to WPide" width="100%" height="600px"> </iframe>\
1206 - </div>');
1207 - NewDialog.dialog({
1208 - modal: true,
1209 - title: "title",
1210 - show: 'clip',
1211 - hide: 'clip',
1212 - width: '800',
1213 - height: '600'
1214 - });
1215 -
1216 - } else { //open in new tab/window
1217 -
1218 - var data = {
1219 - action: 'wpide_image_edit_key',
1220 - file: file,
1221 - _wpnonce: jQuery('#_wpnonce').val(),
1222 - _wp_http_referer: jQuery('#_wp_http_referer').val()
1223 - };
1224 - var image_data = '';
1225 - jQuery.ajaxSetup({
1226 - async: false
1227 - }); //we need to wait until we get the response before opening the window
1228 - jQuery.post(ajaxurl, data, function(response) {
1229 -
1230 - //with the response (which is a nonce), build the json data to pass to the image editor. The edit key (nonce) is only valid to edit this image
1231 - image_data = file + '::' + response;
1232 -
1233 - });
1234 -
1235 - jQuery.ajaxSetup({
1236 - async: true
1237 - }); //enable async again
1238 -
1239 -
1240 - window.open('http://www.sumopaint.com/app/?key=ebcdaezjeojbfgih&url=<?php echo $app_url . "/wp-content"; ?>' + file + '&opt=' + image_data + '&title=Edit image&service=Save back to WPide&target=<?php echo urlencode($app_url . "/wp-admin/admin.php?wpide_save_image=yes"); ?>');
1241 -
1242 - }
1243 -
1244 - } else {
1245 - jQuery(parent).addClass('wait');
1246 -
1247 - wpide_set_file_contents(file, function() {
1248 -
1249 - //once file loaded remove the wait class/indicator
1250 - jQuery(parent).removeClass('wait');
1251 -
1252 - });
1253 -
1254 - jQuery('#filename').val(file);
1255 - }
1256 -
1257 - }
1258 -
1259 - });
1260 - }
1261 -
1262 -
1263 -
1264 - jQuery(document).ready(function($) {
1265 -
1266 - // $("#fancyeditordiv").css("height", ($('body').height()-120) + 'px' );
1267 -
1268 - // Handler for .ready() called.
1269 - the_filetree();
1270 -
1271 - //inialise the color assist
1272 - $("#wpide_color_assist img").ImageColorPicker({
1273 - afterColorSelected: function(event, color) {
1274 - jQuery("#wpide_color_assist_input").val(color);
1275 - }
1276 - });
1277 - $("#wpide_color_assist").hide(); //hide it until it's needed
1278 -
1279 - $("#wpide_color_assist_send").click(function(e) {
1280 - e.preventDefault();
1281 - editor.insert(jQuery("#wpide_color_assist_input").val().replace('#', ''));
1282 -
1283 - $("#wpide_color_assist").hide(); //hide it until it's needed again
1284 - });
1285 -
1286 - $(".close_color_picker a").click(function(e) {
1287 - e.preventDefault();
1288 - $("#wpide_color_assist").hide(); //hide it until it's needed again
1289 - });
1290 -
1291 - $("#wpide_toolbar_buttons").on('click', "a.restore", function(e) {
1292 - e.preventDefault();
1293 - var file_path = jQuery(".wpide_tab.active", "#wpide_toolbar").data("backup");
1294 -
1295 - jQuery("#wpide_message").hide(); //might be shortly after a save so a message may be showing, which we don't need
1296 - jQuery("#wpide_message").html('<span><strong>File available for restore</strong><p> ' + file_path + '</p><a class="button red restore now" href="' + wpide_app_path + file_path + '">Restore this file now &#10012;</a><a class="button restore cancel" href="#">Cancel &#10007;</a><br /><em class="note"><strong>note: </strong>You can browse all file backups if you navigate to the backups folder (plugins/WPide/backups/..) using the filetree.</em></span>');
1297 - jQuery("#wpide_message").show();
1298 - });
1299 - $("#wpide_toolbar_buttons").on('click', "a.restore.now", function(e) {
1300 - e.preventDefault();
1301 -
1302 - var data = {
1303 - restorewpnonce: user_nonce_addition + jQuery('#_wpnonce').val()
1304 - };
1305 - jQuery.post(wpide_app_path + jQuery(".wpide_tab.active", "#wpide_toolbar").data("backup"), data, function(response) {
1306 -
1307 - if (response == -1) {
1308 - alert("Problem restoring file.");
1309 - } else {
1310 - alert(response);
1311 - jQuery("#wpide_message").hide();
1312 - }
1313 -
1314 - });
1315 -
1316 - });
1317 - $("#wpide_toolbar_buttons").on('click', "a.cancel", function(e) {
1318 - e.preventDefault();
1319 -
1320 - jQuery("#wpide_message").hide(); //might be shortly after a save so a message may be showing, which we don't need
1321 - });
1322 -
1323 - });
1324 - </script>
1325 -
1326 - <div id="poststuff" class="metabox-holder has-right-sidebar">
1327 -
1328 - <div id="side-info-column" class="inner-sidebar">
1329 -
1330 - <div id="wpide_info">
1331 - <div id="wpide_info_content"></div>
1332 - </div>
1333 - <br style="clear:both;" />
1334 - <div id="wpide_color_assist">
1335 - <div class="close_color_picker"><a href="close-color-picker">x</a></div>
1336 - <h3>Colour Assist</h3>
1337 - <img src='<?php echo plugins_url("images/color-wheel.png", __FILE__); ?>' />
1338 - <input type="button" class="button" id="wpide_color_assist_send" value="&lt; Send to editor" />
1339 - <input type="text" id="wpide_color_assist_input" name="wpide_color_assist_input" value="" />
1340 -
1341 - </div>
1342 -
1343 -
1344 -
1345 - <div id="submitdiv" class="postbox ">
1346 - <h3 class="hndle"><span>Files</span></h3>
1347 - <div class="inside">
1348 - <div class="submitbox" id="submitpost">
1349 - <div id="minor-publishing">
1350 - </div>
1351 - <div id="major-publishing-actions">
1352 - <div id="wpide_file_browser"></div>
1353 - <br style="clear:both;" />
1354 - <div class="new_file new_item_inputs">
1355 - <label for="new_folder">File name</label><input class="has_data" name="new_file" type="text" rel="" value="" placeholder="Filename.ext" />
1356 - <a href="#" id="wpide_create_new_file" class="button-primary">CREATE</a>
1357 - </div>
1358 - <div class="new_directory new_item_inputs">
1359 - <label for="new_directory">Directory name</label><input class="has_data" name="new_directory" type="text" rel="" value="" placeholder="Filename.ext" />
1360 - <a href="#" id="wpide_create_new_directory" class="button-primary">CREATE</a>
1361 - </div>
1362 - <div class="clear"></div>
1363 - </div>
1364 - </div>
1365 - </div>
1366 - </div>
1367 -
1368 -
1369 - </div>
1370 -
1371 - <div id="post-body">
1372 - <div id="wpide_toolbar" class="quicktags-toolbar">
1373 - <div id="wpide_toolbar_tabs"> </div>
1374 - <div id="dialog_window_minimized_container"></div>
1375 - </div>
1376 -
1377 - <div id="wpide_toolbar_buttons">
1378 - <div id="wpide_message"></div>
1379 - <a class="button restore" style="display:none;" title="Restore the active tab" href="#">Restore &#10012;</a>
1380 -
1381 - </div>
1382 -
1383 -
1384 - <div id='fancyeditordiv'></div>
1385 -
1386 - <form id="wpide_save_container" action="" method="get">
1387 - <div id="wpide_footer_message"></div>
1388 - <div id="wpide_footer_message_last_saved"></div>
1389 - <div id="wpide_footer_message_unsaved"></div>
1390 -
1391 - <a href="#" id="wpide_save" alt="Keyboard shortcut to save [Ctrl/Cmd + S]" title="Keyboard shortcut to save [Ctrl/Cmd + S]" class="button-primary">SAVE
1392 - FILE</a>
1393 -
1394 - <input type="hidden" id="filename" name="filename" value="" />
1395 - <?php
1396 - if (function_exists('wp_nonce_field'))
1397 - wp_nonce_field('plugin-name-action_wpidenonce');
1398 - ?>
1399 - </form>
1400 -
1401 - </div>
1402 -
1403 - </div>
1404 -
1405 - <?php
1406 - }
1407 -
1408 - public function print_find_dialog()
1409 - {
1410 - if (!$this->is_plugin_page()) {
1411 - return;
1412 - }
1413 - ?>
1414 - <div id="editor_find_dialog" title="Find..." style="padding: 0px; display: none;">
1415 - <?php if (false) : ?>
1416 - <ul>
1417 - <li><a href="#find-inline">Text</a></li>
1418 - <li><a href="#find-func">Function</a></li>
1419 - </ul>
1420 - <?php endif; ?>
1421 - <form id="find-inline" style="position: relative; padding: 4px; margin: 0px; height: 100%; overflow: hidden; width: 400px;">
1422 - <label class="left"> Find<input type="search" name="find" /></label>
1423 - <label class="left"> Replace<input type="search" name="replace" /></label>
1424 - <div class="clear" style="height: 33px;"></div>
1425 -
1426 - <label><input type="checkbox" name="wrap" checked="checked" /> Wrap Around</label>
1427 - <label><input type="checkbox" name="case" /> Case Sensitive</label>
1428 - <label><input type="checkbox" name="whole" /> Match Whole Word</label>
1429 - <label><input type="checkbox" name="regexp" /> Regular Expression</label>
1430 -
1431 - <div class="search_direction">
1432 - Direction:
1433 - <label><input type="radio" name="direction" value="0" /> Up</label>
1434 - <label><input type="radio" name="direction" value="1" checked="checked" /> Down</label>
1435 - </div>
1436 - <div class="right">
1437 - <input type="submit" name="submit" value="Find" class="action_button" />
1438 - <input type="button" name="replace" value="Replace" class="action_button" />
1439 - <input type="button" name="replace_all" value="Replace All" class="action_button" />
1440 - <input type="button" name="cancel" value="Cancel" class="action_button" />
1441 - </div>
1442 - </form>
1443 - <?php if (false) : ?>
1444 - <form id="find-func">
1445 - <label class="left"> Function<input type="search" name="find" /></label>
1446 - <div class="right">
1447 - <input type="submit" name="submit" value="Find Function" class="action_button" />
1448 - </div>
1449 - </form>
1450 - <?php endif; ?>
1451 - </div>
1452 - <div id="editor_goto_dialog" title="Go to..." style="padding: 0px; display: none;"></div>
1453 -<?php
1454 - }
1455 - }
1456 -
1457 - $wpide = new wpide();
1458 -
1459 -endif; // class_exists check
1 +<?php
2 +/**
3 + * WPIDE - File Manager & Code Editor
4 + *
5 + * @author XplodedThemes
6 + * @copyright 2018 XplodedThemes
7 + * @license GPL-2.0+
8 + *
9 + * @wordpress-plugin
10 + * Plugin Name: WPIDE - File Manager & Code Editor
11 + * Plugin URI: https://wpide.com
12 + * Description: WordPress file manager with an advanced code editor / file editor featuring auto-completion of both WordPress and PHP functions with reference, syntax highlighting, line numbers, tabbed editing, automatic backup, image editor & much more!
13 + * Version: 3.5.8
14 + * Requires PHP: 7.4.0
15 + * Requires at least: 5.0
16 + * Author: XplodedThemes
17 + * Author URI: https://xplodedthemes.com
18 + * Text Domain: wpide
19 + * Domain Path: /languages/
20 + * License: GPL-2.0+
21 + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
22 + *
23 + */
24 +namespace WPIDE;
25 +
26 +use WPIDE\App\App;
27 +use WPIDE\App\Classes\Freemius;
28 +
29 +defined( 'ABSPATH' ) || exit;
30 +
31 +$required_php_version = '7.4.0';
32 +
33 +if (version_compare(PHP_VERSION, $required_php_version, '<')) {
34 +
35 + $class = 'notice notice-error';
36 +
37 + $message = sprintf(
38 + __('%s minimum PHP version requirement is %s. The current PHP version is: %s. Either update the PHP version, or use %s %s or below.', 'wpide'),
39 + '<strong>WPIDE</strong>',
40 + '<strong>v' . $required_php_version . '</strong>',
41 + '<strong>v' . PHP_VERSION . '</strong>',
42 + '<strong>WPIDE</strong>',
43 + '<strong>v2.6</strong>'
44 + );
45 +
46 + add_action('admin_notices', function () use ($message, $class) {
47 + echo sprintf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), $message);
48 +
49 + deactivate_plugins( __FILE__ );
50 + });
51 +
52 +}else {
53 +
54 + define('WPIDE_FILE', __FILE__);
55 + define('WPIDE_DIR', __DIR__);
56 +
57 + global $wpide_fs;
58 +
59 + if (!empty($wpide_fs)) {
60 +
61 + $wpide_fs->set_basename(true, __FILE__);
62 +
63 + } else {
64 +
65 + require_once __DIR__ . '/vendor/autoload.php';
66 +
67 + Freemius::init();
68 + App::instance();
69 + }
70 +}