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

WPide.php in WPIDE – File Manager & Code Editor 2.0.16, at WPide.php

778 lines 30.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WPide
4 Plugin URI: https://github.com/WPsites/WPide
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.0.16
7 Author: Simon Dunton
8 Author URI: http://www.wpsites.co.uk
9 */
10
11 // Exit if accessed directly
12 if ( !defined( 'ABSPATH' ) ) exit;
13
14
15 if ( !class_exists( 'wpide' ) ) :
16 class wpide
17
18 {
19
20 public $site_url, $plugin_url;
21
22 /**
23 * The main WPide loader (PHP4 compatable)
24 *
25 * @uses wpide::__construct() Setup the globals needed
26 */
27 public function wpide() {
28 $this->__construct();
29 }
30
31 function __construct() {
32
33 //add WPide to the menu
34 add_action( 'admin_menu', array( $this, 'add_my_menu_page' ) );
35
36 //hook for processing incoming image saves
37 if ( isset($_GET['wpide_save_image']) ){
38
39 //force local file method for testing - you could force other methods 'direct', 'ssh', 'ftpext' or 'ftpsockets'
40 $this->override_fs_method('direct');
41
42 add_action('admin_init', array( $this, 'wpide_save_image') );
43
44 }
45
46
47 //only include this plugin if on theme editor, plugin editor or an ajax call
48 if ( (isset($_GET['page']) && $_GET['page'] === 'wpide') ||
49 preg_match('#admin-ajax\.php$#', $_SERVER['PHP_SELF']) ){
50
51
52 // force local file method until I've worked out how to implement the other methods
53 // main problem being password wouldn't/isn't saved between requests
54 // you could force other methods 'direct', 'ssh', 'ftpext' or 'ftpsockets'
55 $this->override_fs_method('direct');
56
57 // Uncomment any of these calls to add the functionality that you need.
58 add_action('admin_init', array( $this, 'add_admin_js' ) );
59 add_action('admin_init', array( $this, 'add_admin_styles' ) );
60
61 //setup jqueryFiletree list callback
62 add_action('wp_ajax_jqueryFileTree', array( $this, 'jqueryFileTree_get_list' ) );
63 //setup ajax function to get file contents for editing
64 add_action('wp_ajax_wpide_get_file', array( $this, 'wpide_get_file' ) );
65 //setup ajax function to save file contents and do automatic backup if needed
66 add_action('wp_ajax_wpide_save_file', array( $this, 'wpide_save_file' ) );
67 //setup ajax function to create new item (folder, file etc)
68 add_action('wp_ajax_wpide_create_new', array( $this, 'wpide_create_new' ) );
69
70 //setup ajax function to create new item (folder, file etc)
71 add_action('wp_ajax_wpide_image_edit_key', array( $this, 'wpide_image_edit_key' ) );
72
73 //setup ajax function for startup to get some debug info, checking permissions etc
74 add_action('wp_ajax_wpide_startup_check', array( $this, 'wpide_startup_check' ) );
75
76 //add a warning when navigating away from WPide
77 //it has to go after WordPress scripts otherwise WP clears the binding
78 add_action('admin_print_footer_scripts', array( $this, 'add_admin_nav_warning' ), 99 );
79
80 }
81
82
83
84
85
86 $this->site_url = get_bloginfo('url');
87
88
89 }
90
91
92 public function override_fs_method($method = 'direct'){
93
94
95 if ( defined('FS_METHOD') ){
96
97 define('WPIDE_FS_METHOD_FORCED_ELSEWHERE', FS_METHOD); //make a note of the forced method
98
99 }else{
100
101 define('FS_METHOD', $method); //force direct
102
103 }
104
105 }
106
107 public static function add_admin_nav_warning()
108 {
109 ?>
110 <script type="text/javascript">
111
112 jQuery(document).ready(function($) {
113 window.onbeforeunload = function() {
114 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.' ;
115 }
116 });
117
118 </script>
119 <?php
120 }
121
122
123
124
125
126
127 public static function add_admin_js(){
128
129 $plugin_path = plugin_dir_url( __FILE__ );
130 //include file tree
131 wp_enqueue_script('jquery-file-tree', plugins_url("jqueryFileTree.js", __FILE__ ) );
132 //include ace
133 wp_enqueue_script('ace', plugins_url("ace-0.2.0/src/ace.js", __FILE__ ) );
134 //include ace modes for css, javascript & php
135 wp_enqueue_script('ace-mode-css', $plugin_path . 'ace-0.2.0/src/mode-css.js');
136 wp_enqueue_script('ace-mode-javascript', $plugin_path . 'ace-0.2.0/src/mode-javascript.js');
137 wp_enqueue_script('ace-mode-php', $plugin_path . 'ace-0.2.0/src/mode-php.js');
138 //include ace theme
139 wp_enqueue_script('ace-theme', plugins_url("ace-0.2.0/src/theme-dawn.js", __FILE__ ) );//monokai is nice
140 // wordpress-completion tags
141 wp_enqueue_script('wpide-wordpress-completion', plugins_url("js/autocomplete/wordpress.js", __FILE__ ) );
142 // php-completion tags
143 wp_enqueue_script('wpide-php-completion', plugins_url("js/autocomplete/php.js", __FILE__ ) );
144 // load editor
145 wp_enqueue_script('wpide-load-editor', plugins_url("js/load-editor.js", __FILE__ ) );
146 // load autocomplete dropdown
147 wp_enqueue_script('wpide-dd', plugins_url("js/jquery.dd.js", __FILE__ ) );
148
149 // load jquery ui
150 wp_enqueue_script('jquery-ui', plugins_url("js/jquery-ui-1.9.2.custom.min.js", __FILE__ ), array('jquery'), '1.9.2');
151
152 // load color picker
153 wp_enqueue_script('ImageColorPicker', plugins_url("js/ImageColorPicker.js", __FILE__ ), array('jquery'), '0.3');
154
155
156
157 }
158
159 public static function add_admin_styles(){
160
161 //main wpide styles
162 wp_register_style( 'wpide_style', plugins_url('wpide.css', __FILE__) );
163 wp_enqueue_style( 'wpide_style' );
164 //filetree styles
165 wp_register_style( 'wpide_filetree_style', plugins_url('jqueryFileTree.css', __FILE__) );
166 wp_enqueue_style( 'wpide_filetree_style' );
167 //autocomplete dropdown styles
168 wp_register_style( 'wpide_dd_style', plugins_url('dd.css', __FILE__) );
169 wp_enqueue_style( 'wpide_dd_style' );
170
171 //jquery ui styles
172 wp_register_style( 'wpide_jqueryui_style', plugins_url('css/flick/jquery-ui-1.8.20.custom.css', __FILE__) );
173 wp_enqueue_style( 'wpide_jqueryui_style' );
174
175
176 }
177
178
179
180 public static function jqueryFileTree_get_list() {
181 //check the user has the permissions
182 check_admin_referer('plugin-name-action_wpidenonce');
183 if ( !current_user_can('edit_themes') )
184 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
185
186 //setup wp_filesystem api
187 global $wp_filesystem;
188 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
189 $form_fields = null; // for now, but at some point the login info should be passed in here
190 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
191 // no credentials yet, just produced a form for the user to fill in
192 return true; // stop the normal page form from displaying
193 }
194
195 if ( ! WP_Filesystem($creds) )
196 return false;
197
198 $_POST['dir'] = urldecode($_POST['dir']);
199 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
200
201 if( $wp_filesystem->exists($root . $_POST['dir']) ) {
202 //$files = scandir($root . $_POST['dir']);
203 //print_r($files);
204 $files = $wp_filesystem->dirlist($root . $_POST['dir']);
205 //print_r($files);
206
207 echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
208 if( count($files) > 0 ) {
209
210 // All dirs
211 foreach( $files as $file => $file_info ) {
212 if( $file != '.' && $file != '..' && $file_info['type']=='d' ) {
213 echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
214 }
215 }
216 // All files
217 foreach( $files as $file => $file_info ) {
218 if( $file != '.' && $file != '..' && $file_info['type']!='d') {
219 $ext = preg_replace('/^.*\./', '', $file);
220 echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
221 }
222 }
223 }
224 //output toolbar for creating new file, folder etc
225 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>";
226 echo "</ul>";
227 }
228
229 die(); // this is required to return a proper result
230 }
231
232
233 public static function wpide_get_file() {
234 //check the user has the permissions
235 check_admin_referer('plugin-name-action_wpidenonce');
236 if ( !current_user_can('edit_themes') )
237 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
238
239 //setup wp_filesystem api
240 global $wp_filesystem;
241 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
242 $form_fields = null; // for now, but at some point the login info should be passed in here
243 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
244 // no credentials yet, just produced a form for the user to fill in
245 return true; // stop the normal page form from displaying
246 }
247 if ( ! WP_Filesystem($creds) )
248 return false;
249
250
251 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
252 $file_name = $root . stripslashes($_POST['filename']);
253 echo $wp_filesystem->get_contents($file_name);
254 die(); // this is required to return a proper result
255 }
256
257
258
259 public static function wpide_image_edit_key() {
260
261 //check the user has the permissions
262 check_admin_referer('plugin-name-action_wpidenonce');
263 if ( !current_user_can('edit_themes') )
264 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
265
266 //create a nonce based on the image path
267 echo wp_create_nonce( 'wpide_image_edit' . $_POST['file'] );
268
269 }
270
271 public static function wpide_create_new() {
272 //check the user has the permissions
273 check_admin_referer('plugin-name-action_wpidenonce');
274 if ( !current_user_can('edit_themes') )
275 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
276
277 //setup wp_filesystem api
278 global $wp_filesystem;
279 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
280 $form_fields = null; // for now, but at some point the login info should be passed in here
281 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
282 // no credentials yet, just produced a form for the user to fill in
283 return true; // stop the normal page form from displaying
284 }
285 if ( ! WP_Filesystem($creds) )
286 return false;
287
288 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
289
290 //check all required vars are passed
291 if (strlen($_POST['path'])>0 && strlen($_POST['type'])>0 && strlen($_POST['file'])>0){
292
293
294 $filename = sanitize_file_name( $_POST['file'] );
295 $path = $_POST['path'];
296
297 if ($_POST['type'] == "directory"){
298
299 $write_result = $wp_filesystem->mkdir($root . $path . $filename, FS_CHMOD_DIR);
300
301 if ($write_result){
302 die("1"); //created
303 }else{
304 echo "Problem creating directory" . $root . $path . $filename;
305 }
306
307 }else if ($_POST['type'] == "file"){
308
309 //write the file
310 $write_result = $wp_filesystem->put_contents(
311 $root . $path . $filename,
312 '',
313 FS_CHMOD_FILE // predefined mode settings for WP files
314 );
315
316 if ($write_result){
317 die("1"); //created
318 }else{
319 echo "Problem creating file " . $root . $path . $filename;
320 }
321
322 }
323
324
325 //print_r($_POST);
326
327
328 }
329 echo "0";
330 die(); // this is required to return a proper result
331 }
332
333 public static function wpide_save_file() {
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 templates for this site. SORRY').'</p>');
338
339 //check file syntax of PHP files by parsing the PHP
340 if ( preg_match("#\.php$#i", $_POST['filename']) ){
341
342 require('PHP-Parser/lib/bootstrap.php');
343 ini_set('xdebug.max_nesting_level', 2000);
344
345 $code = stripslashes($_POST['content']);
346
347 $parser = new PHPParser_Parser(new PHPParser_Lexer);
348
349 try {
350 $stmts = $parser->parse($code);
351 } catch (PHPParser_Error $e) {
352 echo 'Parse Error: ', $e->getMessage();
353 die();
354 }
355 }
356
357 //setup wp_filesystem api
358 global $wp_filesystem;
359 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
360 $form_fields = null; // for now, but at some point the login info should be passed in here
361 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
362 // no credentials yet, just produced a form for the user to fill in
363 return true; // stop the normal page form from displaying
364 }
365 if ( ! WP_Filesystem($creds) )
366 echo "Cannot initialise the WP file system API";
367
368 //save a copy of the file and create a backup just in case
369 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
370 $file_name = $root . stripslashes($_POST['filename']);
371
372 //set backup filename
373 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
374 //create backup directory if not there
375 $new_file_info = pathinfo($backup_path);
376 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
377
378 //do backup
379 $wp_filesystem->copy( $file_name, $backup_path );
380
381 //save file
382 if( $wp_filesystem->put_contents( $file_name, stripslashes($_POST['content'])) ) {
383 $result = "success";
384 }
385
386 die($result); // this is required to return a proper result
387 }
388
389 public static function wpide_save_image() {
390
391 $filennonce = split("::", $_POST["opt"]); //file::nonce
392
393 //check the user has a valid nonce
394 //we are checking two variations of the nonce, one as-is and another that we have removed a trailing zero from
395 //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
396 if (! wp_verify_nonce( $filennonce[1], 'wpide_image_edit' . $filennonce[0]) &&
397 ! wp_verify_nonce( rtrim($filennonce[1], "0") , 'wpide_image_edit' . $filennonce[0])) {
398 die('Security check'); //die because both checks failed
399 }
400 //check the user has the permissions
401 if ( !current_user_can('edit_themes') )
402 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
403
404
405 $_POST['content'] = base64_decode($_POST["data"]); //image content
406 $_POST['filename'] = $filennonce[0]; //filename
407
408 //setup wp_filesystem api
409 global $wp_filesystem;
410 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
411 $form_fields = null; // for now, but at some point the login info should be passed in here
412 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
413 // no credentials yet, just produced a form for the user to fill in
414 return true; // stop the normal page form from displaying
415 }
416 if ( ! WP_Filesystem($creds) )
417 echo "Cannot initialise the WP file system API";
418
419 //save a copy of the file and create a backup just in case
420 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
421 $file_name = $root . stripslashes($_POST['filename']);
422
423 //set backup filename
424 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
425 //create backup directory if not there
426 $new_file_info = pathinfo($backup_path);
427 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
428
429 //do backup
430 $wp_filesystem->move( $file_name, $backup_path );
431
432
433 //save file
434 if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) {
435 $result = "success";
436 }
437
438 if ($result == "success"){
439 wp_die('<p>'.__('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.').'</p>');
440 }else{
441 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>');
442 }
443 //print_r($_POST);
444
445
446 //return;
447 }
448
449
450 public static function wpide_startup_check() {
451 global $wp_filesystem, $wp_version;
452
453 echo "\n\n\n\nWPIDE STARTUP CHECKS \n";
454 echo "___________________ \n\n";
455
456 //WordPress version
457 if ($wp_version > 3){
458 echo "WordPress version = " . $wp_version . "\n\n";
459 }else{
460 echo "WordPress version = " . $wp_version . " (which is too old to run WPide) \n\n";
461 }
462
463 //check the user has the permissions
464 check_admin_referer('plugin-name-action_wpidenonce');
465 if ( !current_user_can('edit_themes') )
466 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
467
468 if ( defined( 'WPIDE_FS_METHOD_FORCED_ELSEWHERE' ) ){
469 echo "WordPress filesystem API has been forced to use the " . WPIDE_FS_METHOD_FORCED . " method by another plugin/WordPress. \n\n";
470 }
471
472 //setup wp_filesystem api
473 $wpide_filesystem_before = $wp_filesystem;
474
475 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
476 $form_fields = null; // for now, but at some point the login info should be passed in here
477 ob_start();
478 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
479 // if we get here, then we don't have credentials yet,
480 // but have just produced a form for the user to fill in,
481 // so stop processing for now
482 //return true; // stop the normal page form from displaying
483 }
484 ob_end_clean();
485 if ( ! WP_Filesystem($creds) ) {
486
487 echo "There has been a problem initialising the filesystem API \n\n";
488 echo "Filesystem API before this plugin ran: \n\n" . print_r($wpide_filesystem_before, true);
489 echo "Filesystem API now: \n\n" . print_r($wp_filesystem, true);
490
491 }
492 unset($wpide_filesystem_before);
493
494
495 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
496 if ( isset($wp_filesystem) ){
497
498 //Running webservers user and group
499 echo "Web server user/group = " . getenv('APACHE_RUN_USER') . ":" . getenv('APACHE_RUN_GROUP') . "\n";
500 //wp-content user and group
501 echo "wp-content owner/group = " . $wp_filesystem->owner( $root ) . ":" . $wp_filesystem->group( $root ) . "\n\n";
502
503
504 //check we can list wp-content files
505 if( $wp_filesystem->exists( $root ) ){
506
507 $files = $wp_filesystem->dirlist( $root );
508 if ( count($files) > 0){
509 echo "wp-content folder exists and contains ". count($files) ." files \n";
510 }else{
511 echo "wp-content folder exists but we cannot read it's contents \n";
512 }
513 }
514
515 // $wp_filesystem->owner() $wp_filesystem->group() $wp_filesystem->is_writable() $wp_filesystem->is_readable()
516 echo "\nUsing the ".$wp_filesystem->method." method of the WP filesystem API\n";
517
518 //wp-content editable?
519 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";
520
521
522 //plugins folder editable
523 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";
524
525
526 //themes folder editable
527 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";
528
529 }
530
531 echo "___________________ \n\n\n\n";
532
533 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.";
534
535
536 die();
537
538 //set backup filename
539 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
540 //create backup directory if not there
541 $new_file_info = pathinfo($backup_path);
542 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
543
544 //do backup
545 $wp_filesystem->move( $file_name, $backup_path );
546
547
548 //save file
549 if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) {
550 $result = "success";
551 }
552
553 if ($result == "success"){
554 wp_die('<p>'.__('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.').'</p>');
555 }else{
556 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>');
557 }
558
559
560 //return;
561 }
562
563
564
565
566 public function add_my_menu_page() {
567 //add_menu_page("wpide", "wpide","edit_themes", "wpidesettings", array( &$this, 'my_menu_page') );
568 add_menu_page('WPide', 'WPide', 'edit_themes', "wpide", array( &$this, 'my_menu_page' ));
569 }
570
571 public function my_menu_page() {
572 if ( !current_user_can('edit_themes') )
573 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
574
575 $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)
576 if (is_ssl()) $app_url = str_replace("http:", "https:", $app_url);
577
578 ?>
579 <script>
580
581 var wpide_app_path = "<?php echo plugin_dir_url( __FILE__ ); ?>";
582 //dont think this is needed any more.. var wpide_file_root_url = "<?php echo apply_filters("wpide_file_root_url", WP_CONTENT_URL );?>";
583
584 function the_filetree() {
585 jQuery('#wpide_file_browser').fileTree({ script: ajaxurl }, function(parent, file) {
586
587 if ( jQuery(parent).hasClass("create_new") ){ //create new file/folder
588 //to create a new item we need to know the name of it so show input
589
590 var item = eval('('+file+')');
591
592 //hide all inputs just incase one is selected
593 jQuery(".new_item_inputs").hide();
594 //show the input form for this
595 jQuery("div.new_" + item.type).show();
596 jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").focus();
597 jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").attr("rel", file);
598
599
600 }else if ( jQuery(".wpide_tab[rel='"+file+"']").length > 0) { //focus existing tab
601 jQuery(".wpide_tab[sessionrel='"+ jQuery(".wpide_tab[rel='"+file+"']").attr("sessionrel") +"']").click();//focus the already open tab
602 }else{ //open file
603
604 var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)");
605 if ( image_patern.test(file) ){
606 //it's an image so open it for editing
607
608 //using modal+iframe
609 if ("lets not" == "use the modal for now"){
610
611 var NewDialog = jQuery('<div id="MenuDialog">\
612 <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>\
613 </div>');
614 NewDialog.dialog({
615 modal: true,
616 title: "title",
617 show: 'clip',
618 hide: 'clip',
619 width:'800',
620 height:'600'
621 });
622
623 }else{ //open in new tab/window
624
625 var data = { action: 'wpide_image_edit_key', file: file, _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
626 var image_data = '';
627 jQuery.ajaxSetup({async:false}); //we need to wait until we get the response before opening the window
628 jQuery.post(ajaxurl, data, function(response) {
629
630 //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
631 image_data = file+'::'+response;
632
633 });
634
635 jQuery.ajaxSetup({async:true});//enable async again
636
637
638 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" ) ;?>');
639
640 }
641
642 }else{
643 jQuery(parent).addClass('wait');
644
645 wpide_set_file_contents(file, function(){
646
647 //once file loaded remove the wait class/indicator
648 jQuery(parent).removeClass('wait');
649
650 });
651
652 jQuery('#filename').val(file);
653 }
654
655 }
656
657 });
658 }
659
660
661
662 jQuery(document).ready(function($) {
663
664 // Handler for .ready() called.
665 the_filetree() ;
666
667 //inialise the color assist
668 $("#wpide_color_assist img").ImageColorPicker({
669 afterColorSelected: function(event, color){
670 jQuery("#wpide_color_assist_input").val(color);
671 }
672 });
673 $("#wpide_color_assist").hide(); //hide it until it's needed
674
675 $("#wpide_color_assist_send").click(function(e){
676 e.preventDefault();
677 editor.insert( jQuery("#wpide_color_assist_input").val().replace('#', '') );
678
679 $("#wpide_color_assist").hide(); //hide it until it's needed again
680 });
681
682 $(".close_color_picker a").click(function(e){
683 e.preventDefault();
684 $("#wpide_color_assist").hide(); //hide it until it's needed again
685 });
686
687
688
689
690 });
691 </script>
692
693
694
695 <div id="poststuff" class="metabox-holder has-right-sidebar">
696
697 <div id="side-info-column" class="inner-sidebar">
698
699 <div id="wpide_info">
700 <div id="wpide_info_content"></div>
701 </div>
702 <br style="clear:both;" />
703 <div id="wpide_color_assist">
704 <div class="close_color_picker"><a href="close-color-picker">x</a></div>
705 <h3>Colour Assist</h3>
706 <img src='<?php echo plugins_url("images/color-wheel.png", __FILE__ ); ?>' />
707 <input type="button" class="button" id="wpide_color_assist_send" value="&lt; Send to editor" />
708 <input type="text" id="wpide_color_assist_input" name="wpide_color_assist_input" value="" />
709
710 </div>
711
712
713
714 <div id="submitdiv" class="postbox ">
715 <h3 class="hndle"><span>Files</span></h3>
716 <div class="inside">
717 <div class="submitbox" id="submitpost">
718 <div id="minor-publishing">
719 </div>
720 <div id="major-publishing-actions">
721 <div id="wpide_file_browser"></div>
722 <br style="clear:both;" />
723 <div class="new_file new_item_inputs">
724 <label for="new_folder">File name</label><input class="has_data" name="new_file" type="text" rel="" value="" placeholder="Filename.ext" />
725 <a href="#" id="wpide_create_new_file" class="button-primary">CREATE</a>
726 </div>
727 <div class="new_directory new_item_inputs">
728 <label for="new_directory">Directory name</label><input class="has_data" name="new_directory" type="text" rel="" value="" placeholder="Filename.ext" />
729 <a href="#" id="wpide_create_new_directory" class="button-primary">CREATE</a>
730 </div>
731 <div class="clear"></div>
732 </div>
733 </div>
734 </div>
735 </div>
736
737
738 </div>
739
740 <div id="post-body">
741 <div id="wpide_toolbar" class="quicktags-toolbar">
742 <div id="wpide_toolbar_tabs"> </div>
743 <div id="dialog_window_minimized_container"></div>
744 </div>
745
746 <div id="wpide_toolbar_buttons">
747 <div id="wpide_message" class="error highlight"></div>
748 <a href="#"></a> <a href="#"></a> </div>
749
750
751 <div id='fancyeditordiv'></div>
752
753 <form id="wpide_save_container" action="" method="get">
754 <a href="#" id="wpide_save" class="button-primary">SAVE
755 FILE</a>
756 <input type="hidden" id="filename" name="filename" value="" />
757 <?php
758 if ( function_exists('wp_nonce_field') )
759 wp_nonce_field('plugin-name-action_wpidenonce');
760 ?>
761 </form>
762 </div>
763
764
765
766 </div>
767
768 <?php
769 }
770
771 }
772
773 $wpide = new wpide();
774
775 endif; // class_exists check
776
777 ?>
778