site_url = get_bloginfo('url'); } public static function add_admin_head() { } public static function add_admin_js(){ $plugin_path = plugin_dir_url( __FILE__ ); //include file tree wp_enqueue_script('jquery-file-tree', plugins_url("jqueryFileTree.js", __FILE__ ) ); //include ace wp_enqueue_script('ace', plugins_url("ace-0.2.0/src/ace.js", __FILE__ ) ); //include ace modes for css, javascript & php wp_enqueue_script('ace-mode-css', $plugin_path . 'ace-0.2.0/src/mode-css.js'); wp_enqueue_script('ace-mode-javascript', $plugin_path . 'ace-0.2.0/src/mode-javascript.js'); wp_enqueue_script('ace-mode-php', $plugin_path . 'ace-0.2.0/src/mode-php.js'); //include ace theme wp_enqueue_script('ace-theme', plugins_url("ace-0.2.0/src/theme-dawn.js", __FILE__ ) );//monokai is nice // wordpress-completion tags wp_enqueue_script('wpide-wordpress-completion', plugins_url("js/autocomplete.wordpress.js", __FILE__ ) ); // php-completion tags wp_enqueue_script('wpide-php-completion', plugins_url("js/autocomplete.php.js", __FILE__ ) ); // load editor wp_enqueue_script('wpide-load-editor', plugins_url("js/load-editor.js", __FILE__ ) ); // load autocomplete dropdown wp_enqueue_script('wpide-dd', plugins_url("js/jquery.dd.js", __FILE__ ) ); // load jquery ui wp_enqueue_script('jquery-ui', plugins_url("js/jquery-ui-1.8.20.custom.min.js", __FILE__ ), array('jquery'), '1.8.20'); } public static function add_admin_styles(){ //main wpide styles wp_register_style( 'wpide_style', plugins_url('wpide.css', __FILE__) ); wp_enqueue_style( 'wpide_style' ); //filetree styles wp_register_style( 'wpide_filetree_style', plugins_url('jqueryFileTree.css', __FILE__) ); wp_enqueue_style( 'wpide_filetree_style' ); //autocomplete dropdown styles wp_register_style( 'wpide_dd_style', plugins_url('dd.css', __FILE__) ); wp_enqueue_style( 'wpide_dd_style' ); //jquery ui styles wp_register_style( 'wpide_jqueryui_style', plugins_url('css/flick/jquery-ui-1.8.20.custom.css', __FILE__) ); wp_enqueue_style( 'wpide_jqueryui_style' ); } public static function jqueryFileTree_get_list() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //setup wp_filesystem api global $wp_filesystem; if ( ! WP_Filesystem($creds) ) return false; $_POST['dir'] = urldecode($_POST['dir']); $root = WP_CONTENT_DIR; if( $wp_filesystem->exists($root . $_POST['dir']) ) { //$files = scandir($root . $_POST['dir']); //print_r($files); $files = $wp_filesystem->dirlist($root . $_POST['dir']); //print_r($files); echo ""; } die(); // this is required to return a proper result } public static function wpide_get_file() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //setup wp_filesystem api global $wp_filesystem; if ( ! WP_Filesystem($creds) ) return false; $root = WP_CONTENT_DIR; $file_name = $root . stripslashes($_POST['filename']); echo $wp_filesystem->get_contents($file_name); die(); // this is required to return a proper result } public static function wpide_image_edit_key() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //create a nonce based on the image path echo wp_create_nonce( 'wpide_image_edit' . $_POST['file'] ); } public static function wpide_create_new() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //setup wp_filesystem api global $wp_filesystem; if ( ! WP_Filesystem($creds) ) return false; $root = WP_CONTENT_DIR; //check all required vars are passed if (strlen($_POST['path'])>0 && strlen($_POST['type'])>0 && strlen($_POST['file'])>0){ $filename = sanitize_file_name( $_POST['file'] ); $path = $_POST['path']; if ($_POST['type'] == "directory"){ $write_result = $wp_filesystem->mkdir($root . $path . $filename, FS_CHMOD_DIR); if ($write_result){ die("1"); //created }else{ echo "Problem creating directory" . $root . $path . $filename; } }else if ($_POST['type'] == "file"){ $write_result = $wp_filesystem->put_contents( $root . $path . $filename, ' ', FS_CHMOD_FILE // predefined mode settings for WP files ); if ($write_result){ die("1"); //created }else{ echo "Problem creating file " . $root . $path . $filename; } } //print_r($_POST); } echo "0"; die(); // this is required to return a proper result } public static function wpide_save_file() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //setup wp_filesystem api global $wp_filesystem; if ( ! WP_Filesystem($creds) ) echo "Cannot initialise the WP file system API"; //save a copy of the file and create a backup just in case $root = WP_CONTENT_DIR; $file_name = $root . stripslashes($_POST['filename']); //set backup filename $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH"); //create backup directory if not there $new_file_info = pathinfo($backup_path); 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 //do backup $wp_filesystem->copy( $file_name, $backup_path ); //save file if( $wp_filesystem->put_contents( $file_name, stripslashes($_POST['content'])) ) { $result = "success"; } die($result); // this is required to return a proper result } public static function wpide_save_image() { $filennonce = split("::", $_POST["opt"]); //file::nonce //check the user has a valid nonce //we are checking two variations of the nonce, one as-is and another that we have removed a trailing zero from //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 if (! wp_verify_nonce( $filennonce[1], 'wpide_image_edit' . $filennonce[0]) && ! wp_verify_nonce( rtrim($filennonce[1], "0") , 'wpide_image_edit' . $filennonce[0])) { die('Security check'); //die because both checks failed } //check the user has the permissions if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); $_POST['content'] = base64_decode($_POST["data"]); //image content $_POST['filename'] = $filennonce[0]; //filename //setup wp_filesystem api global $wp_filesystem; if ( ! WP_Filesystem($creds) ) echo "Cannot initialise the WP file system API"; //save a copy of the file and create a backup just in case $root = WP_CONTENT_DIR; $file_name = $root . stripslashes($_POST['filename']); //set backup filename $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH"); //create backup directory if not there $new_file_info = pathinfo($backup_path); 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 //do backup $wp_filesystem->move( $file_name, $backup_path ); //save file if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) { $result = "success"; } if ($result == "success"){ wp_die('

'.__('Image saved.
You may close this window / tab.').'

'); }else{ wp_die('

'.__('Problem saving image.
Close this window / tab and try editing the image again.').'

'); } //print_r($_POST); //return; } public static function wpide_startup_check() { //check the user has the permissions check_admin_referer('plugin-name-action_wpidenonce'); if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); //setup wp_filesystem api global $wp_filesystem, $wp_version; if ( ! WP_Filesystem($creds) ) return false; $root = WP_CONTENT_DIR; echo "\n\n\n\nWPIDE STARUP CHECKS \n"; echo "___________________ \n\n"; //WordPress version if ($wp_version > 3){ echo "WordPress version = " . $wp_version . "\n\n"; }else{ echo "WordPress version = " . $wp_version . " (which is too old to run WPide) \n\n"; } //Running webservers user and group echo "Web server user/group = " . getenv('APACHE_RUN_USER') . ":" . getenv('APACHE_RUN_GROUP') . "\n"; //wp-content user and group echo "wp-content owner/group = " . $wp_filesystem->owner( $root ) . ":" . $wp_filesystem->group( $root ) . "\n\n"; //check we can list wp-content files if( $wp_filesystem->exists( $root ) ){ $files = $wp_filesystem->dirlist( $root ); if ( count($files) > 0){ echo "wp-content folder exists and contains ". count($files) ." files \n"; }else{ echo "wp-content folder exists but we cannot read it's contents \n"; } } // $wp_filesystem->owner() $wp_filesystem->group() $wp_filesystem->is_writable() $wp_filesystem->is_readable() echo "\nUsing the ".$wp_filesystem->method." method of the WP filesystem API\n"; //wp-content editable? 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"; //plugins folder editable 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"; //themes folder editable 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"; echo "___________________ \n\n\n\n"; 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."; die(); //set backup filename $backup_path = ABSPATH .'wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/' . str_replace( str_replace('\\', "/", ABSPATH), '', $file_name) .'.'.date("YmdH"); //create backup directory if not there $new_file_info = pathinfo($backup_path); 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 //do backup $wp_filesystem->move( $file_name, $backup_path ); //save file if( $wp_filesystem->put_contents( $file_name, $_POST['content']) ) { $result = "success"; } if ($result == "success"){ wp_die('

'.__('Image saved.
You may close this window / tab.').'

'); }else{ wp_die('

'.__('Problem saving image.
Close this window / tab and try editing the image again.').'

'); } //return; } public function add_my_menu_page() { //add_menu_page("wpide", "wpide","edit_themes", "wpidesettings", array( &$this, 'my_menu_page') ); add_menu_page('WPide', 'WPide', 'edit_themes', "wpide", array( &$this, 'my_menu_page' )); } public function my_menu_page() { if ( !current_user_can('edit_themes') ) wp_die('

'.__('You do not have sufficient permissions to edit templates for this site. SORRY').'

'); $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) if (is_ssl()) $app_url = str_replace("http:", "https:", $app_url); ?>

Files


CREATE
CREATE
SAVE FILE