PluginProbe
WPIDE – File Manager & Code Editor / 2.0.13
WPIDE – File Manager & Code Editor v2.0.13
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.13, at WPide.php

760 lines 30.2 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.13
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 $WPide->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 //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 echo "Cannot initialise the WP file system API";
349
350 //save a copy of the file and create a backup just in case
351 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
352 $file_name = $root . stripslashes($_POST['filename']);
353
354 //set backup filename
355 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
356 //create backup directory if not there
357 $new_file_info = pathinfo($backup_path);
358 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
359
360 //do backup
361 $wp_filesystem->copy( $file_name, $backup_path );
362
363 //save file
364 if( $wp_filesystem->put_contents( $file_name, stripslashes($_POST['content'])) ) {
365 $result = "success";
366 }
367
368 die($result); // this is required to return a proper result
369 }
370
371 public static function wpide_save_image() {
372
373 $filennonce = split("::", $_POST["opt"]); //file::nonce
374
375 //check the user has a valid nonce
376 //we are checking two variations of the nonce, one as-is and another that we have removed a trailing zero from
377 //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
378 if (! wp_verify_nonce( $filennonce[1], 'wpide_image_edit' . $filennonce[0]) &&
379 ! wp_verify_nonce( rtrim($filennonce[1], "0") , 'wpide_image_edit' . $filennonce[0])) {
380 die('Security check'); //die because both checks failed
381 }
382 //check the user has the permissions
383 if ( !current_user_can('edit_themes') )
384 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
385
386
387 $_POST['content'] = base64_decode($_POST["data"]); //image content
388 $_POST['filename'] = $filennonce[0]; //filename
389
390 //setup wp_filesystem api
391 global $wp_filesystem;
392 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
393 $form_fields = null; // for now, but at some point the login info should be passed in here
394 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
395 // no credentials yet, just produced a form for the user to fill in
396 return true; // stop the normal page form from displaying
397 }
398 if ( ! WP_Filesystem($creds) )
399 echo "Cannot initialise the WP file system API";
400
401 //save a copy of the file and create a backup just in case
402 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
403 $file_name = $root . stripslashes($_POST['filename']);
404
405 //set backup filename
406 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
407 //create backup directory if not there
408 $new_file_info = pathinfo($backup_path);
409 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
410
411 //do backup
412 $wp_filesystem->move( $file_name, $backup_path );
413
414
415 //save file
416 if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) {
417 $result = "success";
418 }
419
420 if ($result == "success"){
421 wp_die('<p>'.__('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.').'</p>');
422 }else{
423 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>');
424 }
425 //print_r($_POST);
426
427
428 //return;
429 }
430
431
432 public static function wpide_startup_check() {
433 global $wp_filesystem, $wp_version;
434
435 echo "\n\n\n\nWPIDE STARTUP CHECKS \n";
436 echo "___________________ \n\n";
437
438 //WordPress version
439 if ($wp_version > 3){
440 echo "WordPress version = " . $wp_version . "\n\n";
441 }else{
442 echo "WordPress version = " . $wp_version . " (which is too old to run WPide) \n\n";
443 }
444
445 //check the user has the permissions
446 check_admin_referer('plugin-name-action_wpidenonce');
447 if ( !current_user_can('edit_themes') )
448 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
449
450 if ( defined( 'WPIDE_FS_METHOD_FORCED_ELSEWHERE' ) ){
451 echo "WordPress filesystem API has been forced to use the " . WPIDE_FS_METHOD_FORCED . " method by another plugin/WordPress. \n\n";
452 }
453
454 //setup wp_filesystem api
455 $wpide_filesystem_before = $wp_filesystem;
456
457 $url = wp_nonce_url('admin.php?page=wpide','plugin-name-action_wpidenonce');
458 $form_fields = null; // for now, but at some point the login info should be passed in here
459 ob_start();
460 if (false === ($creds = request_filesystem_credentials($url, FS_METHOD, false, false, $form_fields) ) ) {
461 // if we get here, then we don't have credentials yet,
462 // but have just produced a form for the user to fill in,
463 // so stop processing for now
464 //return true; // stop the normal page form from displaying
465 }
466 ob_end_clean();
467 if ( ! WP_Filesystem($creds) ) {
468
469 echo "There has been a problem initialising the filesystem API \n\n";
470 echo "Filesystem API before this plugin ran: \n\n" . print_r($wpide_filesystem_before, true);
471 echo "Filesystem API now: \n\n" . print_r($wp_filesystem, true);
472
473 }
474 unset($wpide_filesystem_before);
475
476
477 $root = apply_filters( 'wpide_filesystem_root', WP_CONTENT_DIR );
478 if ( isset($wp_filesystem) ){
479
480 //Running webservers user and group
481 echo "Web server user/group = " . getenv('APACHE_RUN_USER') . ":" . getenv('APACHE_RUN_GROUP') . "\n";
482 //wp-content user and group
483 echo "wp-content owner/group = " . $wp_filesystem->owner( $root ) . ":" . $wp_filesystem->group( $root ) . "\n\n";
484
485
486 //check we can list wp-content files
487 if( $wp_filesystem->exists( $root ) ){
488
489 $files = $wp_filesystem->dirlist( $root );
490 if ( count($files) > 0){
491 echo "wp-content folder exists and contains ". count($files) ." files \n";
492 }else{
493 echo "wp-content folder exists but we cannot read it's contents \n";
494 }
495 }
496
497 // $wp_filesystem->owner() $wp_filesystem->group() $wp_filesystem->is_writable() $wp_filesystem->is_readable()
498 echo "\nUsing the ".$wp_filesystem->method." method of the WP filesystem API\n";
499
500 //wp-content editable?
501 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";
502
503
504 //plugins folder editable
505 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";
506
507
508 //themes folder editable
509 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";
510
511 }
512
513 echo "___________________ \n\n\n\n";
514
515 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.";
516
517
518 die();
519
520 //set backup filename
521 $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
522 //create backup directory if not there
523 $new_file_info = pathinfo($backup_path);
524 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
525
526 //do backup
527 $wp_filesystem->move( $file_name, $backup_path );
528
529
530 //save file
531 if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) {
532 $result = "success";
533 }
534
535 if ($result == "success"){
536 wp_die('<p>'.__('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.').'</p>');
537 }else{
538 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>');
539 }
540
541
542 //return;
543 }
544
545
546
547
548 public function add_my_menu_page() {
549 //add_menu_page("wpide", "wpide","edit_themes", "wpidesettings", array( &$this, 'my_menu_page') );
550 add_menu_page('WPide', 'WPide', 'edit_themes', "wpide", array( &$this, 'my_menu_page' ));
551 }
552
553 public function my_menu_page() {
554 if ( !current_user_can('edit_themes') )
555 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
556
557 $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)
558 if (is_ssl()) $app_url = str_replace("http:", "https:", $app_url);
559
560 ?>
561 <script>
562
563 var wpide_app_path = "<?php echo plugin_dir_url( __FILE__ ); ?>";
564 //dont think this is needed any more.. var wpide_file_root_url = "<?php echo apply_filters("wpide_file_root_url", WP_CONTENT_URL );?>";
565
566 function the_filetree() {
567 jQuery('#wpide_file_browser').fileTree({ script: ajaxurl }, function(parent, file) {
568
569 if ( jQuery(parent).hasClass("create_new") ){ //create new file/folder
570 //to create a new item we need to know the name of it so show input
571
572 var item = eval('('+file+')');
573
574 //hide all inputs just incase one is selected
575 jQuery(".new_item_inputs").hide();
576 //show the input form for this
577 jQuery("div.new_" + item.type).show();
578 jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").focus();
579 jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").attr("rel", file);
580
581
582 }else if ( jQuery(".wpide_tab[rel='"+file+"']").length > 0) { //focus existing tab
583 jQuery(".wpide_tab[sessionrel='"+ jQuery(".wpide_tab[rel='"+file+"']").attr("sessionrel") +"']").click();//focus the already open tab
584 }else{ //open file
585
586 var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)");
587 if ( image_patern.test(file) ){
588 //it's an image so open it for editing
589
590 //using modal+iframe
591 if ("lets not" == "use the modal for now"){
592
593 var NewDialog = jQuery('<div id="MenuDialog">\
594 <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>\
595 </div>');
596 NewDialog.dialog({
597 modal: true,
598 title: "title",
599 show: 'clip',
600 hide: 'clip',
601 width:'800',
602 height:'600'
603 });
604
605 }else{ //open in new tab/window
606
607 var data = { action: 'wpide_image_edit_key', file: file, _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
608 var image_data = '';
609 jQuery.ajaxSetup({async:false}); //we need to wait until we get the response before opening the window
610 jQuery.post(ajaxurl, data, function(response) {
611
612 //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
613 image_data = file+'::'+response;
614
615 });
616
617 jQuery.ajaxSetup({async:true});//enable async again
618
619
620 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" ) ;?>');
621
622 }
623
624 }else{
625 jQuery(parent).addClass('wait');
626
627 wpide_set_file_contents(file, function(){
628
629 //once file loaded remove the wait class/indicator
630 jQuery(parent).removeClass('wait');
631
632 });
633
634 jQuery('#filename').val(file);
635 }
636
637 }
638
639 });
640 }
641
642
643
644 jQuery(document).ready(function($) {
645
646 // Handler for .ready() called.
647 the_filetree() ;
648
649 //inialise the color assist
650 $("#wpide_color_assist img").ImageColorPicker({
651 afterColorSelected: function(event, color){
652 jQuery("#wpide_color_assist_input").val(color);
653 }
654 });
655 $("#wpide_color_assist").hide(); //hide it until it's needed
656
657 $("#wpide_color_assist_send").click(function(e){
658 e.preventDefault();
659 editor.insert( jQuery("#wpide_color_assist_input").val().replace('#', '') );
660
661 $("#wpide_color_assist").hide(); //hide it until it's needed again
662 });
663
664 $(".close_color_picker a").click(function(e){
665 e.preventDefault();
666 $("#wpide_color_assist").hide(); //hide it until it's needed again
667 });
668
669
670
671
672 });
673 </script>
674
675
676
677 <div id="poststuff" class="metabox-holder has-right-sidebar">
678
679 <div id="side-info-column" class="inner-sidebar">
680
681 <div id="wpide_info">
682 <div id="wpide_info_content"></div>
683 </div>
684 <br style="clear:both;" />
685 <div id="wpide_color_assist">
686 <div class="close_color_picker"><a href="close-color-picker">x</a></div>
687 <h3>Colour Assist</h3>
688 <img src='<?php echo plugins_url("images/color-wheel.png", __FILE__ ); ?>' />
689 <input type="button" class="button" id="wpide_color_assist_send" value="&lt; Send to editor" />
690 <input type="text" id="wpide_color_assist_input" name="wpide_color_assist_input" value="" />
691
692 </div>
693
694
695
696 <div id="submitdiv" class="postbox ">
697 <h3 class="hndle"><span>Files</span></h3>
698 <div class="inside">
699 <div class="submitbox" id="submitpost">
700 <div id="minor-publishing">
701 </div>
702 <div id="major-publishing-actions">
703 <div id="wpide_file_browser"></div>
704 <br style="clear:both;" />
705 <div class="new_file new_item_inputs">
706 <label for="new_folder">File name</label><input class="has_data" name="new_file" type="text" rel="" value="" placeholder="Filename.ext" />
707 <a href="#" id="wpide_create_new_file" class="button-primary">CREATE</a>
708 </div>
709 <div class="new_directory new_item_inputs">
710 <label for="new_directory">Directory name</label><input class="has_data" name="new_directory" type="text" rel="" value="" placeholder="Filename.ext" />
711 <a href="#" id="wpide_create_new_directory" class="button-primary">CREATE</a>
712 </div>
713 <div class="clear"></div>
714 </div>
715 </div>
716 </div>
717 </div>
718
719
720 </div>
721
722 <div id="post-body">
723 <div id="wpide_toolbar" class="quicktags-toolbar">
724 <div id="wpide_toolbar_tabs"> </div>
725 <div id="dialog_window_minimized_container"></div>
726 </div>
727
728 <div id="wpide_toolbar_buttons">
729 <div id="wpide_message" class="error highlight"></div>
730 <a href="#"></a> <a href="#"></a> </div>
731
732
733 <div id='fancyeditordiv'></div>
734
735 <form id="wpide_save_container" action="" method="get">
736 <a href="#" id="wpide_save" class="button-primary">SAVE
737 FILE</a>
738 <input type="hidden" id="filename" name="filename" value="" />
739 <?php
740 if ( function_exists('wp_nonce_field') )
741 wp_nonce_field('plugin-name-action_wpidenonce');
742 ?>
743 </form>
744 </div>
745
746
747
748 </div>
749
750 <?php
751 }
752
753 }
754
755 $wpide = new wpide();
756
757 endif; // class_exists check
758
759 ?>
760