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