| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
Plugin Name: WPide |
| 5 |
Plugin URI: https://github.com/WPsites/WPide |
| 6 |
Description: Replace the default WordPress code editor for plugins and themes. Adding syntax highlighting, autocomplete of WordPress functions + PHP, line numbers, auto backup of files before editing. |
| 7 |
Version: 1.0.6 |
| 8 |
Author: Simon Dunton |
| 9 |
Author URI: http://www.wpsites.co.uk |
| 10 |
|
| 11 |
*/ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class WPide |
| 16 |
|
| 17 |
{ |
| 18 |
|
| 19 |
|
| 20 |
function __construct() { |
| 21 |
|
| 22 |
// Uncomment any of these calls to add the functionality that you need. |
| 23 |
add_action('admin_head', 'WPide::add_admin_head'); |
| 24 |
add_action('admin_init', 'WPide::add_admin_js'); |
| 25 |
|
| 26 |
//setup ajax function to save a backup |
| 27 |
add_action('wp_ajax_ace_backup_call', 'WPide::ace_backup_call'); |
| 28 |
|
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
public static function add_admin_head() |
| 33 |
{ |
| 34 |
|
| 35 |
?> |
| 36 |
|
| 37 |
<style type="text/css"> |
| 38 |
#quicktags, #post-status-info, #editor-toolbar, #newcontent, .ace_print_margin { display: none; } |
| 39 |
#fancyeditordiv { |
| 40 |
position: relative; |
| 41 |
width: 500px; |
| 42 |
height: 400px; |
| 43 |
} |
| 44 |
#template div{margin-right:0 !important;} |
| 45 |
</style> |
| 46 |
|
| 47 |
<?php |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public static function add_admin_js() |
| 52 |
{ |
| 53 |
$plugin_path = get_bloginfo('url').'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/'; |
| 54 |
//include ace |
| 55 |
wp_enqueue_script('ace', $plugin_path . 'ace-0.2.0/src/ace.js'); |
| 56 |
//include ace modes for css, javascript & php |
| 57 |
wp_enqueue_script('ace-mode-css', $plugin_path . 'ace-0.2.0/src/mode-css.js'); |
| 58 |
wp_enqueue_script('ace-mode-javascript', $plugin_path . 'ace-0.2.0/src/mode-javascript.js'); |
| 59 |
wp_enqueue_script('ace-mode-php', $plugin_path . 'ace-0.2.0/src/mode-php.js'); |
| 60 |
//include ace theme |
| 61 |
wp_enqueue_script('ace-theme', $plugin_path . 'ace-0.2.0/src/theme-dawn.js');//monokai is nice |
| 62 |
// html tags for completion |
| 63 |
wp_enqueue_script('wpide-editor-completion', $plugin_path . 'js/html-tags.js'); |
| 64 |
// load & prepare editor |
| 65 |
wp_enqueue_script('wpide-editor-load', $plugin_path . 'js/load-editor.js'); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public static function ace_backup_call() { |
| 70 |
|
| 71 |
$backup_path = get_bloginfo('url').'/wp-content/plugins/' . basename(dirname(__FILE__)) .'/backups/'; |
| 72 |
$file_name = $_POST['filename']; |
| 73 |
$edit_type = $_POST['edittype']; |
| 74 |
|
| 75 |
if ($edit_type==='theme'){ |
| 76 |
$theme_root = get_theme_root(); |
| 77 |
$short_path = str_replace($theme_root, '', $file_name); |
| 78 |
|
| 79 |
$new_file_path_daily = WP_PLUGIN_DIR.'/wpide/backups/themes'.$short_path.'.'.date("Ymd"); |
| 80 |
$new_file_path_hourly = WP_PLUGIN_DIR.'/wpide/backups/themes'.$short_path.'.'.date("YmdH"); |
| 81 |
|
| 82 |
$new_file_info = pathinfo($new_file_path_daily); |
| 83 |
|
| 84 |
if (!is_dir($new_file_info['dirname'])) mkdir($new_file_info['dirname'], 0777, true); //make directory if not exist |
| 85 |
|
| 86 |
//check for todays backup if non existant then create |
| 87 |
if (!file_exists($new_file_path_daily)){ |
| 88 |
$backup_result = copy($file_name, $new_file_path_daily); //make a copy of the file |
| 89 |
|
| 90 |
//check for a backup this hour if doesn't exist then create |
| 91 |
}else if(!file_exists($new_file_path_hourly)){ |
| 92 |
$backup_result = copy($file_name, $new_file_path_hourly); //make a copy of the file |
| 93 |
} |
| 94 |
|
| 95 |
//do no further backups since one intial backup for today and an hourly one is plenty! |
| 96 |
|
| 97 |
}else if ($edit_type==='plugin'){ |
| 98 |
|
| 99 |
$plugin_root = WP_PLUGIN_DIR; |
| 100 |
$short_path = str_replace($plugin_root, '', $file_name); |
| 101 |
|
| 102 |
$new_file_path_daily = WP_PLUGIN_DIR.'/wpide/backups/plugins/'.$short_path.'.'.date("Ymd"); |
| 103 |
$new_file_path_hourly = WP_PLUGIN_DIR.'/wpide/backups/plugins/'.$short_path.'.'.date("YmdH"); |
| 104 |
|
| 105 |
$new_file_info = pathinfo($new_file_path_daily); |
| 106 |
|
| 107 |
if (!is_dir($new_file_info['dirname'])) mkdir($new_file_info['dirname'], 0777, true); //make directory if not exist |
| 108 |
|
| 109 |
//check for todays backup if non existant then create |
| 110 |
if (!file_exists($new_file_path_daily)){ |
| 111 |
$backup_result = copy($plugin_root.'/'.$file_name, $new_file_path_daily); //make a copy of the file |
| 112 |
|
| 113 |
//check for a backup this hour if doesn't exist then create |
| 114 |
}else if(!file_exists($new_file_path_hourly)){ |
| 115 |
$backup_result = copy($plugin_root.'/'.$file_name, $new_file_path_hourly); //make a copy of the file |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
//do no further backups since one intial backup for today and an hourly one is plenty! |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
if ($backup_result){ |
| 124 |
echo "success"; |
| 125 |
} |
| 126 |
|
| 127 |
//echo "final debug info : " . WP_PLUGIN_DIR.'/wpide/backups/'.$short_path.'.backup'; |
| 128 |
die(); // this is required to return a proper result |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
//only include this plugin if on theme or plugin editors (Or Multisite network equivalents) or an ajax call |
| 135 |
$is_ms = ''; |
| 136 |
if ( is_multisite() ) |
| 137 |
$is_ms = 'network/'; |
| 138 |
|
| 139 |
if ( $_SERVER['PHP_SELF'] === '/wp-admin/' . $is_ms . 'plugin-editor.php' || |
| 140 |
$_SERVER['PHP_SELF'] === '/wp-admin/' . $is_ms . 'theme-editor.php' || |
| 141 |
$_SERVER['PHP_SELF'] === '/wp-admin/admin-ajax.php' ){ |
| 142 |
|
| 143 |
add_action( 'init', create_function( '', 'new WPide();' ) ); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
add_filter("plugin_row_meta", 'wpide_dev_links', 10, 2); |
| 148 |
|
| 149 |
function wpide_dev_links($links, $file) { |
| 150 |
static $this_plugin; |
| 151 |
|
| 152 |
if (!$this_plugin) { |
| 153 |
$this_plugin = plugin_basename(__FILE__); |
| 154 |
} |
| 155 |
|
| 156 |
// check to make sure we are on the correct plugin |
| 157 |
if ($file === $this_plugin) { |
| 158 |
// the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page |
| 159 |
$settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/plugins.php?page=install-required-plugins" style="font-weight:bold;">Download and install V2 Development version</a>'; |
| 160 |
// add the link to the list |
| 161 |
array_push($links, $settings_link); |
| 162 |
} |
| 163 |
return $links; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
/** |
| 172 |
* Include the TGM_Plugin_Activation class. |
| 173 |
*/ |
| 174 |
require_once dirname( __FILE__ ) . '/tgm-plugin-activation/class-tgm-plugin-activation.php'; |
| 175 |
|
| 176 |
add_action( 'tgmpa_register', 'wpide_run_dev' ); |
| 177 |
/** |
| 178 |
* Register the required plugins for this theme. |
| 179 |
* |
| 180 |
* In this example, we register two plugins - one included with the TGMPA library |
| 181 |
* and one from the .org repo. |
| 182 |
* |
| 183 |
* The variable passed to tgmpa_register_plugins() should be an array of plugin |
| 184 |
* arrays. |
| 185 |
* |
| 186 |
* This function is hooked into tgmpa_init, which is fired within the |
| 187 |
* TGM_Plugin_Activation class constructor. |
| 188 |
*/ |
| 189 |
function wpide_run_dev() { |
| 190 |
|
| 191 |
/** |
| 192 |
* Array of plugin arrays. Required keys are name and slug. |
| 193 |
* If the source is NOT from the .org repo, then source is also required. |
| 194 |
*/ |
| 195 |
$plugins = array( |
| 196 |
|
| 197 |
// This is an example of how to include a plugin from the WordPress Plugin Repository |
| 198 |
array( |
| 199 |
'name' => 'WPide V2 Dev', |
| 200 |
'slug' => 'WPideV2', |
| 201 |
'version' => '2.0', |
| 202 |
'required' => false, |
| 203 |
'external_url' => 'https://github.com/WPsites/WPide/tree/v2dev', |
| 204 |
'source' => 'https://github.com/WPsites/WPide/zipball/v2dev', |
| 205 |
), |
| 206 |
|
| 207 |
); |
| 208 |
|
| 209 |
// Change this to your theme text domain, used for internationalising strings |
| 210 |
$theme_text_domain = 'tgmpa'; |
| 211 |
|
| 212 |
/** |
| 213 |
* Array of configuration settings. Amend each line as needed. |
| 214 |
* If you want the default strings to be available under your own theme domain, |
| 215 |
* leave the strings uncommented. |
| 216 |
* Some of the strings are added into a sprintf, so see the comments at the |
| 217 |
* end of each line for what each argument will be. |
| 218 |
*/ |
| 219 |
$config = array( |
| 220 |
'domain' => $theme_text_domain, // Text domain - likely want to be the same as your theme. |
| 221 |
'default_path' => '', // Default absolute path to pre-packaged plugins |
| 222 |
'parent_menu_slug' => 'plugins.php', // Default parent menu slug |
| 223 |
'parent_url_slug' => 'plugins.php', // Default parent URL slug |
| 224 |
'menu' => 'install-required-plugins', // Menu slug |
| 225 |
'has_notices' => true, // Show admin notices or not |
| 226 |
'is_automatic' => true, // Automatically activate plugins after installation or not |
| 227 |
'message' => '', // Message to output right before the plugins table |
| 228 |
'strings' => array( |
| 229 |
'page_title' => __( 'Install Suggested Plugins', $theme_text_domain ), |
| 230 |
'menu_title' => __( 'Install Plugins', $theme_text_domain ), |
| 231 |
'installing' => __( 'Installing Plugin: %s', $theme_text_domain ), // %1$s = plugin name |
| 232 |
'oops' => __( 'Something went wrong with the plugin API.', $theme_text_domain ), |
| 233 |
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ), // %1$s = plugin name(s) |
| 234 |
'notice_can_install_recommended' => _n_noop( 'The V2 Development branch of WPide is available for testing - With new features such as multi tab editing.<br />Word of warning: this is the cutting edge development version which could contain bugs so use at your own risk! ', 'WPide recommends the following plugins: %1$s.' ), // %1$s = plugin name(s) |
| 235 |
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ), // %1$s = plugin name(s) |
| 236 |
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s) |
| 237 |
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s) |
| 238 |
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ), // %1$s = plugin name(s) |
| 239 |
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ), // %1$s = plugin name(s) |
| 240 |
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ), // %1$s = plugin name(s) |
| 241 |
'install_link' => _n_noop( 'Begin installing the development version of WPide', 'Begin installing plugins' ), |
| 242 |
'activate_link' => _n_noop( 'Activate WPide V2 Dev', 'Activate installed plugins' ), |
| 243 |
'return' => __( 'Return to Suggested Plugins Installer', $theme_text_domain ), |
| 244 |
'plugin_activated' => __( 'Plugin activated successfully.', $theme_text_domain ), |
| 245 |
'complete' => __( 'All plugins installed and activated successfully. %s', $theme_text_domain ) // %1$s = dashboard link |
| 246 |
) |
| 247 |
); |
| 248 |
|
| 249 |
tgmpa( $plugins, $config ); |
| 250 |
|
| 251 |
} |
| 252 |
?> |
| 253 |
|