Plugin Directory

Changeset 539139 for wpide


Ignore:
Timestamp:
05/02/2012 07:10:19 PM (13 years ago)
Author:
WPsites
Message:

Upload 2.0.2

Location:
wpide
Files:
400 added
3 edited

Legend:

Unmodified
Added
Removed
  • wpide/trunk/WPide.php

    r538485r539139 
    44Plugin URI: https://.com/WPsites/WPide
    55Description: 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
     6Version: 2.0.2
    77Author: Simon Dunton
    88Author URI: http://www.wpsites.co.uk
     
    2121        //add WPide to the menu
    2222        add_action( 'admin_menu',  array( &$this, 'add_my_menu_page' ) );
     23       
     24        //hook for processing incoming image saves
     25        if ( isset($_GET['wpide_save_image']) ){
     26           
     27            //force local file method for testing - you could force other methods 'direct', 'ssh', 'ftpext' or 'ftpsockets'
     28            define('FS_METHOD', 'direct');
     29           
     30            add_action('admin_init', array($this, 'wpide_save_image'));
     31           
     32        }
    2333       
    2434        //only include this plugin if on theme editor, plugin editor or an ajax call
     
    4353            add_action('wp_ajax_wpide_create_new', 'WPide2::wpide_create_new' );
    4454           
     55            //setup ajax function to create new item (folder, file etc)
     56            add_action('wp_ajax_wpide_image_edit_key', 'WPide2::wpide_image_edit_key' );
     57           
     58           
     59           
    4560       
    4661        }
     62       
     63
     64       
     65
    4766       
    4867        $WPide->site_url = get_bloginfo('url');
     
    84103            // load autocomplete dropdown
    85104            wp_enqueue_script('wpide-dd', plugins_url("js/jquery.dd.js", __FILE__ ) );
     105           
     106             // load jquery ui 
     107            wp_enqueue_script('jquery-ui', plugins_url("js/jquery-ui-1.8.20.custom.min.js", __FILE__ ), array('jquery'),  '1.8.20');
     108           
     109           
    86110   
    87111   
     
    100124         wp_enqueue_style( 'wpide_dd_style' );
    101125         
     126         //jquery ui styles
     127         wp_register_style( 'wpide_jqueryui_style', plugins_url('css/flick/jquery-ui-1.8.20.custom.css', __FILE__) );
     128         wp_enqueue_style( 'wpide_jqueryui_style' );
     129   
    102130       
    103131    }
     
    169197    }
    170198   
     199   
     200   
     201    public static function wpide_image_edit_key() {
     202       
     203        //check the user has the permissions
     204        check_admin_referer('plugin-name-action_wpidenonce');
     205        if ( !current_user_can('edit_themes') )
     206            wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
     207       
     208        //create a nonce based on the image path
     209        echo wp_create_nonce( 'wpide_image_edit' . $_POST['file'] );
     210       
     211    }
     212   
    171213    public static function wpide_create_new() {
    172214        //check the user has the permissions
     
    249291       
    250292        //save file
    251         if( $wp_filesystem->put_contents( $file_name, stripslashes($_POST['content'])) ) echo "success";
    252         die(); // this is required to return a proper result
    253     }
     293        if( $wp_filesystem->put_contents( $file_name, stripslashes($_POST['content'])) ) {
     294            $result = "success";
     295        }
     296       
     297        die($result); // this is required to return a proper result
     298    }
     299   
     300    public static function wpide_save_image() {
     301       
     302            $filennonce = split("::", $_POST["opt"]); //file::nonce
     303           
     304            //check the user has a valid nonce
     305            //we are checking two variations of the nonce, one as-is and another that we have removed a trailing zero from
     306            //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
     307            if (! wp_verify_nonce( $filennonce[1], 'wpide_image_edit' . $filennonce[0]) &&
     308                ! wp_verify_nonce( rtrim($filennonce[1], "0") , 'wpide_image_edit' . $filennonce[0])) {
     309                die('Security check'); //die because both checks failed
     310            }
     311            //check the user has the permissions
     312            if ( !current_user_can('edit_themes') )
     313            wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
     314       
     315   
     316            $_POST['content'] = base64_decode($_POST["data"]); //image content
     317            $_POST['filename'] = $filennonce[0]; //filename
     318           
     319            //setup wp_filesystem api
     320            global $wp_filesystem;
     321           
     322            if ( ! WP_Filesystem($creds) )
     323                echo "Cannot initialise the WP file system API";
     324           
     325            //save a copy of the file and create a backup just in case
     326            $root = WP_CONTENT_DIR;
     327            $file_name = $root . stripslashes($_POST['filename']);
     328           
     329            //set backup filename
     330            $backup_path =  ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH");
     331            //create backup directory if not there
     332            $new_file_info = pathinfo($backup_path);
     333            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
     334           
     335            //do backup
     336            $wp_filesystem->move( $file_name, $backup_path );
     337           
     338       
     339            //save file
     340            if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) {
     341                $result = "success";
     342            }
     343           
     344            if ($result == "success"){
     345                wp_die('<p>'.__('<strong>Image saved.</strong> <br />You may <a href="JavaScript:window.close();">close this window / tab</a>.').'</p>');
     346            }else{
     347                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>');
     348            }
     349            //print_r($_POST);
     350   
     351       
     352        //return;
     353    }
     354   
    254355   
    255356    public function add_my_menu_page() {
     
    261362        if ( !current_user_can('edit_themes') )
    262363        wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'</p>');
     364       
     365        $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)
     366        if (is_ssl()) $app_url = str_replace("http:", "https:", $app_url);
    263367       
    264368        ?>
     
    287391                    }else{ //open file
    288392                   
    289                     var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)jQuery");
     393                    var image_patern =new RegExp("(\.jpg|\.gif|\.png|\.bmp)");
    290394                    if ( image_patern.test(file) ){
    291                         alert("Image editing is not currently available. It's a planned feature using http://pixlr.com/");
     395                        //it's an image so open it for editing
     396                       
     397                        //using modal+iframe
     398                        if ("lets not" == "use the modal for now"){
     399                           
     400                         var NewDialog = jQuery('<div id="MenuDialog">\
     401                            <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>\
     402                            </div>');
     403                            NewDialog.dialog({
     404                            modal: true,
     405                            title: "title",
     406                            show: 'clip',
     407                            hide: 'clip',
     408                            width:'800',
     409                            height:'600'
     410                            });
     411   
     412                        }else{ //open in new tab/window
     413                           
     414                            var data = { action: 'wpide_image_edit_key', file: file, _wpnonce: jQuery('#_wpnonce').val(), _wp_http_referer: jQuery('#_wp_http_referer').val() };
     415                            var image_data = '';
     416                            jQuery.ajaxSetup({async:false}); //we need to wait until we get the response before opening the window
     417                            jQuery.post(ajaxurl, data, function(response) {
     418                               
     419                                //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
     420                                image_data = file+'::'+response;
     421                               
     422                            });
     423                           
     424                           
     425                            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" ) ;?>');
     426                       
     427                        }
     428                   
    292429                    }else{
    293430                        jQuery(parent).addClass('wait');
     
    308445            }
    309446           
    310             jQuery(document).ready(function() {
     447            jQuery(document).ready(function($) {
    311448                // Handler for .ready() called.
    312449                the_filetree() ;
     450               
     451               
     452           
     453               
     454               
     455               
    313456            });
    314457        </script>
     
    357500                <div id="wpide_toolbar" class="quicktags-toolbar">
    358501                  <div id="wpide_toolbar_tabs"> </div>
     502                  <div id="dialog_window_minimized_container"></div>
    359503                </div>
    360504                           
  • wpide/trunk/readme.txt

    r538485r539139 
    44Requires at least: 3.0
    55Tested up to: 3.3.2
    6 Stable tag: 2.0.1
     6Stable tag: 2.0.2
    77
    88WordPress code editor with auto completion of both WordPress and PHP functions with reference, syntax highlighting, line numbers, tabbed editing, automatic backup.
     
    1414Please come forward (either on or the WordPress support forum) with any bugs, annoyances or any improvements you can suggest. I'd like this plugin to be the best it can be and that's only going to happen if users chip in with their feedback. Code contributions welcome, over on .
    1515
    16 This plugin would not be possible without the Ajax.org Cloud9 Editor (http://ace.ajax.org/) which is the embeded code editor that powers much of the functionality.
     16This plugin would not be possible without the Ajax.org Cloud9 Editor (http://ace.ajax.org/) which is the embedded code editor that powers much of the functionality.
    1717
    1818= Current Features: =
     
    2828*   Auto indentation
    2929*   Tabbed interface for editing multiple files (editing both plugin and theme files at the same time)
    30 *   Using the WordPress filesystem API, although currently direct access is forced (edit WPide.php in the constructor to change this behaviour) ftp/ssh connections aren't setup yet, since WP will not remember a password need to work out how that will work. Maybe use modal to request password when you save but be able to click save all and save a batch with that password. Passwords defined in wp-config.php are persistent and would fix this problem but people don't generaly add those details. Open to ideas here.
     30*   Using the WordPress filesystem API, although currently direct access is forced (edit WPide.php in the constructor to change this behaviour) ftp/ssh connections aren't setup yet, since WP will not remember a password need to work out how that will work. Maybe use modal to request password when you save but be able to click save all and save a batch with that password. Passwords defined in wp-config.php are persistent and would fix this problem but people don't generally add those details. Open to ideas here.
     31*   Image editing/drawing (requires Flash -  will move over to HTML5 when there is a decent alternative)
    3132
    3233= Feature ideas and improvements: =
    3334
    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)
    3535*   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.
    3636*   Add find and replace functionality
     
    6464define('FS_CHMOD_FILE', (0644 & ~ umask()));
    6565
     66= Whenever I try to edit an image the application says that it could not load the image =
     67Either the image contains no image data (its a new empty file) or the image is not accessible to the image editor. Your images need to be accessible to the web. i.e. if you're developing a site on your local machine behind a router/firewall your local web server could not be accessible to the web.
     68
    6669== Screenshots ==
    6770
    68711. Editor view, showing line numbers and syntax highlighting.
     722. Image editor in action
     733. Showing auto complete, function reference and file tree.
    6974
    7075== Changelog ==
     76
     77= 2.0.2 =
     78* Image editing is now available using the SumoPaint image editor and drawing application http://www.sumopaint.com/
    7179
    7280= 2.0.1 =
Note: See TracChangeset for help on using the changeset viewer.