WPide - Version 2.0.1

Version Description

  • You can now create new files/folders
Download this release

Release Info

Developer WPsites
Plugin Icon 128x128 WPide
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0 to 2.0.1

WPide.php CHANGED
@@ -3,13 +3,13 @@
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
7
  Author: Simon Dunton
8
  Author URI: http://www.wpsites.co.uk
9
  */
10
 
11
 
12
-
13
  class WPide2
14
 
15
  {
@@ -39,6 +39,9 @@ class WPide2
39
  add_action('wp_ajax_wpide_get_file', 'WPide2::wpide_get_file' );
40
  //setup ajax function to save file contents and do automatic backup if needed
41
  add_action('wp_ajax_wpide_save_file', 'WPide2::wpide_save_file' );
 
 
 
42
 
43
  }
44
 
@@ -121,8 +124,9 @@ class WPide2
121
  $files = $wp_filesystem->dirlist($root . $_POST['dir']);
122
  //print_r($files);
123
 
124
- if( count($files) > 2 ) { /* The 2 accounts for . and .. */
125
- echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
 
126
  // All dirs
127
  foreach( $files as $file => $file_info ) {
128
  if( $file != '.' && $file != '..' && $file_info['type']=='d' ) {
@@ -136,8 +140,10 @@ class WPide2
136
  echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
137
  }
138
  }
139
- echo "</ul>";
140
  }
 
 
 
141
  }
142
 
143
  die(); // this is required to return a proper result
@@ -162,6 +168,61 @@ class WPide2
162
  die(); // this is required to return a proper result
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  public static function wpide_save_file() {
166
  //check the user has the permissions
167
  check_admin_referer('plugin-name-action_wpidenonce');
@@ -181,7 +242,7 @@ class WPide2
181
  $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
182
  //create backup directory if not there
183
  $new_file_info = pathinfo($backup_path);
184
- if (!$wp_filesystem->is_dir($new_file_info['dirname'])) $wp_filesystem->mkdir($new_file_info['dirname'], 0775);
185
 
186
  //do backup
187
  $wp_filesystem->copy( $file_name, $backup_path );
@@ -205,33 +266,50 @@ class WPide2
205
 
206
  var wpide_app_path = "<?php echo plugin_dir_url( __FILE__ ); ?>";
207
 
208
-
209
- jQuery(document).ready( function($) {
210
- $('#wpide_file_browser').fileTree({ script: ajaxurl }, function(parent, file) {
211
 
212
- if ( $(".wpide_tab[rel='"+file+"']").length > 0) {
213
- $(".wpide_tab[sessionrel='"+ $(".wpide_tab[rel='"+file+"']").attr("sessionrel") +"']").click();//focus the already open tab
214
- }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
- var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)$");
217
  if ( image_patern.test(file) ){
218
  alert("Image editing is not currently available. It's a planned feature using http://pixlr.com/");
219
  }else{
220
- $(parent).addClass('wait');
221
 
222
  wpide_set_file_contents(file, function(){
223
 
224
  //once file loaded remove the wait class/indicator
225
- $(parent).removeClass('wait');
226
 
227
  });
228
 
229
- $('#filename').val(file);
230
  }
231
 
232
  }
233
 
234
  });
 
 
 
 
 
235
  });
236
  </script>
237
 
@@ -258,7 +336,14 @@ class WPide2
258
  <div id="major-publishing-actions">
259
  <div id="wpide_file_browser"></div>
260
  <br style="clear:both;" />
261
-
 
 
 
 
 
 
 
262
  <div class="clear"></div>
263
  </div>
264
  </div>
@@ -300,4 +385,4 @@ class WPide2
300
 
301
  }
302
  add_action("init", create_function('', 'new WPide2();'));
303
- ?>
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.1
7
  Author: Simon Dunton
8
  Author URI: http://www.wpsites.co.uk
9
  */
10
 
11
 
12
+
13
  class WPide2
14
 
15
  {
39
  add_action('wp_ajax_wpide_get_file', 'WPide2::wpide_get_file' );
40
  //setup ajax function to save file contents and do automatic backup if needed
41
  add_action('wp_ajax_wpide_save_file', 'WPide2::wpide_save_file' );
42
+ //setup ajax function to create new item (folder, file etc)
43
+ add_action('wp_ajax_wpide_create_new', 'WPide2::wpide_create_new' );
44
+
45
 
46
  }
47
 
124
  $files = $wp_filesystem->dirlist($root . $_POST['dir']);
125
  //print_r($files);
126
 
127
+ echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
128
+ if( count($files) > 0 ) {
129
+
130
  // All dirs
131
  foreach( $files as $file => $file_info ) {
132
  if( $file != '.' && $file != '..' && $file_info['type']=='d' ) {
140
  echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
141
  }
142
  }
 
143
  }
144
+ //output toolbar for creating new file, folder etc
145
+ 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>";
146
+ echo "</ul>";
147
  }
148
 
149
  die(); // this is required to return a proper result
168
  die(); // this is required to return a proper result
169
  }
170
 
171
+ public static function wpide_create_new() {
172
+ //check the user has the permissions
173
+ check_admin_referer('plugin-name-action_wpidenonce');
174
+ if ( !current_user_can('edit_themes') )
175
+ wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
176
+
177
+ //setup wp_filesystem api
178
+ global $wp_filesystem;
179
+ if ( ! WP_Filesystem($creds) )
180
+ return false;
181
+
182
+ $root = WP_CONTENT_DIR;
183
+
184
+ //check all required vars are passed
185
+ if (strlen($_POST['path'])>0 && strlen($_POST['type'])>0 && strlen($_POST['file'])>0){
186
+
187
+
188
+ $filename = sanitize_file_name( $_POST['file'] );
189
+ $path = $_POST['path'];
190
+
191
+ if ($_POST['type'] == "directory"){
192
+
193
+ $write_result = $wp_filesystem->mkdir($root . $path . $filename, FS_CHMOD_DIR);
194
+
195
+ if ($write_result){
196
+ die("1"); //created
197
+ }else{
198
+ echo "Problem creating directory" . $root . $path . $filename;
199
+ }
200
+
201
+ }else if ($_POST['type'] == "file"){
202
+
203
+ $write_result = $wp_filesystem->put_contents(
204
+ $root . $path . $filename,
205
+ ' ',
206
+ FS_CHMOD_FILE // predefined mode settings for WP files
207
+ );
208
+
209
+ if ($write_result){
210
+ die("1"); //created
211
+ }else{
212
+ echo "Problem creating file " . $root . $path . $filename;
213
+ }
214
+
215
+ }
216
+
217
+
218
+ //print_r($_POST);
219
+
220
+
221
+ }
222
+ echo "0";
223
+ die(); // this is required to return a proper result
224
+ }
225
+
226
  public static function wpide_save_file() {
227
  //check the user has the permissions
228
  check_admin_referer('plugin-name-action_wpidenonce');
242
  $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
243
  //create backup directory if not there
244
  $new_file_info = pathinfo($backup_path);
245
+ 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
246
 
247
  //do backup
248
  $wp_filesystem->copy( $file_name, $backup_path );
266
 
267
  var wpide_app_path = "<?php echo plugin_dir_url( __FILE__ ); ?>";
268
 
269
+ function the_filetree() {
270
+ jQuery('#wpide_file_browser').fileTree({ script: ajaxurl }, function(parent, file) {
 
271
 
272
+ if ( jQuery(parent).hasClass("create_new") ){ //create new file/folder
273
+ //to create a new item we need to know the name of it so show input
274
+
275
+ var item = eval('('+file+')');
276
+
277
+ //hide all inputs just incase one is selected
278
+ jQuery(".new_item_inputs").hide();
279
+ //show the input form for this
280
+ jQuery("div.new_" + item.type).show();
281
+ jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").focus();
282
+ jQuery("div.new_" + item.type + " input[name='new_" + item.type + "']").attr("rel", file);
283
+
284
+
285
+ }else if ( jQuery(".wpide_tab[rel='"+file+"']").length > 0) { //focus existing tab
286
+ jQuery(".wpide_tab[sessionrel='"+ jQuery(".wpide_tab[rel='"+file+"']").attr("sessionrel") +"']").click();//focus the already open tab
287
+ }else{ //open file
288
 
289
+ var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)jQuery");
290
  if ( image_patern.test(file) ){
291
  alert("Image editing is not currently available. It's a planned feature using http://pixlr.com/");
292
  }else{
293
+ jQuery(parent).addClass('wait');
294
 
295
  wpide_set_file_contents(file, function(){
296
 
297
  //once file loaded remove the wait class/indicator
298
+ jQuery(parent).removeClass('wait');
299
 
300
  });
301
 
302
+ jQuery('#filename').val(file);
303
  }
304
 
305
  }
306
 
307
  });
308
+ }
309
+
310
+ jQuery(document).ready(function() {
311
+ // Handler for .ready() called.
312
+ the_filetree() ;
313
  });
314
  </script>
315
 
336
  <div id="major-publishing-actions">
337
  <div id="wpide_file_browser"></div>
338
  <br style="clear:both;" />
339
+ <div class="new_file new_item_inputs">
340
+ <label for="new_folder">File name</label><input class="has_data" name="new_file" type="text" rel="" value="" placeholder="Filename.ext" />
341
+ <a href="#" id="wpide_create_new_file" class="button-primary">CREATE</a>
342
+ </div>
343
+ <div class="new_directory new_item_inputs">
344
+ <label for="new_directory">Directory name</label><input class="has_data" name="new_directory" type="text" rel="" value="" placeholder="Filename.ext" />
345
+ <a href="#" id="wpide_create_new_directory" class="button-primary">CREATE</a>
346
+ </div>
347
  <div class="clear"></div>
348
  </div>
349
  </div>
385
 
386
  }
387
  add_action("init", create_function('', 'new WPide2();'));
388
+ ?>
banner-772x250.jpg ADDED
Binary file
images/new-file.png ADDED
Binary file
images/new-folder.png ADDED
Binary file
jqueryFileTree.css CHANGED
@@ -21,7 +21,9 @@ UL.jqueryFileTree A {
21
  padding: 0px 2px;
22
  }
23
 
24
- UL.jqueryFileTree A:hover {
 
 
25
  background: #BDF;
26
  }
27
 
@@ -88,4 +90,48 @@ UL.jqueryFileTree A:hover {
88
  .jqueryFileTree LI.ext_wmv { background: url(images/film.png) left top no-repeat; }
89
  .jqueryFileTree LI.ext_xls { background: url(images/xls.png) left top no-repeat; }
90
  .jqueryFileTree LI.ext_xml { background: url(images/code.png) left top no-repeat; }
91
- .jqueryFileTree LI.ext_zip { background: url(images/zip.png) left top no-repeat; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  padding: 0px 2px;
22
  }
23
 
24
+ UL.jqueryFileTree LI.directory > A:hover,
25
+ UL.jqueryFileTree LI.file > A:hover
26
+ {
27
  background: #BDF;
28
  }
29
 
90
  .jqueryFileTree LI.ext_wmv { background: url(images/film.png) left top no-repeat; }
91
  .jqueryFileTree LI.ext_xls { background: url(images/xls.png) left top no-repeat; }
92
  .jqueryFileTree LI.ext_xml { background: url(images/code.png) left top no-repeat; }
93
+ .jqueryFileTree LI.ext_zip { background: url(images/zip.png) left top no-repeat; }
94
+
95
+ a.new_directory{
96
+ background: url(images/new-folder.png) center no-repeat;
97
+ }
98
+
99
+ a.new_file{
100
+ background: url(images/new-file.png) center center no-repeat;
101
+ }
102
+
103
+ ul.jqueryFileTree .new_file,
104
+ ul.jqueryFileTree .new_directory{
105
+ width:20px;
106
+ height:20px;
107
+ padding:2px;
108
+ float:left;
109
+ display:block;
110
+ opacity:0.6;
111
+ }
112
+ ul.jqueryFileTree .new_file:hover,
113
+ ul.jqueryFileTree .new_directory:hover{
114
+ width:20px;
115
+ height:20px;
116
+ padding:2px;
117
+ float:left;
118
+ display:block;
119
+ opacity:1;
120
+ }
121
+
122
+ div.new_directory,
123
+ div.new_file{
124
+ display:none;
125
+ }
126
+
127
+ #major-publishing-actions input[type='text'],
128
+ #major-publishing-actions input[type='text']{
129
+ text-align:left;
130
+ width:150px;
131
+ }
132
+
133
+ #major-publishing-actions label{
134
+ display: block;
135
+ font-weight: bold;
136
+ padding-left: 3px;
137
+ }
js/load-editor.js CHANGED
@@ -667,5 +667,50 @@ jQuery(document).ready(function($) {
667
  });
668
 
669
  //END COMMANDS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
670
 
671
  });//end jquery load
667
  });
668
 
669
  //END COMMANDS
670
+
671
+
672
+ //click action for new directory/file submit link
673
+ $("#wpide_create_new_directory, #wpide_create_new_file").click(function(e){
674
+ e.preventDefault();
675
+
676
+ var data_input = jQuery(this).parent().find("input.has_data");
677
+ var item = eval('('+ data_input.attr("rel") +')');
678
+
679
+ //item.path file|directory
680
+ var data = { action: 'wpide_create_new', path: item.path, type: item.type, file: data_input.val(), _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
681
+
682
+ jQuery.post(ajaxurl, data, function(response) {
683
+
684
+ if (response == "1"){
685
+ //remove the file/dir name from the text input
686
+ data_input.val("");
687
+
688
+ if ( jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").length == 0){
689
+
690
+ //if no parent then we are adding something to the wp-content folder so regenerate the whole filetree
691
+ the_filetree();
692
+
693
+ }
694
+
695
+ //click the parent once to hide
696
+ jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").click();
697
+
698
+ //hide the parent input block
699
+ data_input.parent().hide();
700
+
701
+ //click the parent once again to show with new folder and focus on this area
702
+ jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").click();
703
+ jQuery("ul.jqueryFileTree a[rel='"+ item.path +"']").focus();
704
+
705
+ }else if (response == "-1"){
706
+ alert("Permission/security problem. Refresh WPide and try again.");
707
+ }else{
708
+ alert(response);
709
+ }
710
+
711
+
712
+ });
713
+
714
+ });
715
 
716
  });//end jquery load
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: WPsites, Thomas Wieczorek
3
  Tags: code, theme editor, plugin editor, code editor
4
  Requires at least: 3.0
5
  Tested up to: 3.3.2
6
- Stable tag: 2.0
7
 
8
  WordPress code editor with auto completion of both WordPress and PHP functions with reference, syntax highlighting, line numbers, tabbed editing, automatic backup.
9
 
@@ -22,6 +22,7 @@ This plugin would not be possible without the Ajax.org Cloud9 Editor (http://ace
22
  * Code autocomplete for WordPress and PHP functions along with function description, arguments and return value where applicable
23
  * Automatic backup of every file you edit. (one daily backup and one hourly backup of each file stored in plugins/WPide/backups/filepath)
24
  * File tree allowing you to access and edit any file in your wp-content folder (plugins, themes, uploads etc)
 
25
  * Highlight matching parentheses
26
  * Code folding
27
  * Auto indentation
@@ -30,7 +31,6 @@ This plugin would not be possible without the Ajax.org Cloud9 Editor (http://ace
30
 
31
  = Feature ideas and improvements: =
32
 
33
- * Create new files and directories
34
  * Image editing (combining many of the tools available in most Paint programs with high-quality features that have become ubiquitous in image editing programs)
35
  * Improve the code autocomplete command information, providing more information on the commands, adding links through to the WordPress codex and PHP.net website for further info.
36
  * Add find and replace functionality
@@ -52,12 +52,16 @@ Thomas Wieczorek - http://www.wieczo.net
52
 
53
  1. Upload the WPide folder to the `/wp-content/plugins/` directory
54
  1. Activate the plugin through the 'Plugins' menu in WordPress
 
55
 
56
  == Frequently Asked Questions ==
57
 
58
- = Does this plugin work on Internet Explorer =
59
 
60
- No support for Internet Explorer right now
 
 
 
61
 
62
  == Screenshots ==
63
 
@@ -65,6 +69,9 @@ No support for Internet Explorer right now
65
 
66
  == Changelog ==
67
 
 
 
 
68
  = 2.0 =
69
  * Recreated this plugin as a dedicated WPide section/app rather than extending the built in plugin/theme editor (just incase WP remove it)
70
  * Now using the WP filesystem API (although currently restricted to local access)
3
  Tags: code, theme editor, plugin editor, code editor
4
  Requires at least: 3.0
5
  Tested up to: 3.3.2
6
+ Stable tag: 2.0.1
7
 
8
  WordPress code editor with auto completion of both WordPress and PHP functions with reference, syntax highlighting, line numbers, tabbed editing, automatic backup.
9
 
22
  * Code autocomplete for WordPress and PHP functions along with function description, arguments and return value where applicable
23
  * Automatic backup of every file you edit. (one daily backup and one hourly backup of each file stored in plugins/WPide/backups/filepath)
24
  * File tree allowing you to access and edit any file in your wp-content folder (plugins, themes, uploads etc)
25
+ * Create new files and directories
26
  * Highlight matching parentheses
27
  * Code folding
28
  * Auto indentation
31
 
32
  = Feature ideas and improvements: =
33
 
 
34
  * Image editing (combining many of the tools available in most Paint programs with high-quality features that have become ubiquitous in image editing programs)
35
  * Improve the code autocomplete command information, providing more information on the commands, adding links through to the WordPress codex and PHP.net website for further info.
36
  * Add find and replace functionality
52
 
53
  1. Upload the WPide folder to the `/wp-content/plugins/` directory
54
  1. Activate the plugin through the 'Plugins' menu in WordPress
55
+ 1. Access WPide by clicking the WPide menu item in your main administration menu
56
 
57
  == Frequently Asked Questions ==
58
 
59
+ = Can I override the default file permissions when creating files/directories on the local filesystem =
60
 
61
+ Yes you can using the below WordPress settings in wp-config.php which will effect files created with WPide and files added during the WordPress upgrade process.
62
+
63
+ define('FS_CHMOD_DIR', (0755 & ~ umask()));
64
+ define('FS_CHMOD_FILE', (0644 & ~ umask()));
65
 
66
  == Screenshots ==
67
 
69
 
70
  == Changelog ==
71
 
72
+ = 2.0.1 =
73
+ * You can now create new files/folders
74
+
75
  = 2.0 =
76
  * Recreated this plugin as a dedicated WPide section/app rather than extending the built in plugin/theme editor (just incase WP remove it)
77
  * Now using the WP filesystem API (although currently restricted to local access)