PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/duplicator/duplicator.php

https://bitbucket.org/nathancorbier/wastark.com
PHP | 302 lines | 152 code | 40 blank | 110 comment | 18 complexity | d330d79d2fbb64fdb5076b260dadf63d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. Plugin Name: Duplicator
  4. Plugin URI: http://www.lifeinthegrid.com/duplicator/
  5. Description: Create a full WordPress backup of your files and database with one click. Duplicate and move an entire site from one location to another in 3 easy steps. Create full snapshot of your site at any point in time.
  6. Version: 0.4.2
  7. Author: LifeInTheGrid
  8. Author URI: http://www.lifeinthegrid.com
  9. License: GPLv2 or later
  10. */
  11. /* ================================================================================
  12. Copyright 2011-2012 Cory Lamle
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License, version 2, as
  15. published by the Free Software Foundation.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. SOURCE CONTRIBUTORS:
  24. Gaurav Aggarwal
  25. ================================================================================ */
  26. require_once("define.php");
  27. if (is_admin() == true) {
  28. $_tmpDuplicatorOptions = get_option('duplicator_options', false);
  29. $GLOBALS['duplicator_opts'] = ($_tmpDuplicatorOptions == false) ? array() : @unserialize($_tmpDuplicatorOptions);
  30. //OPTIONS
  31. $GLOBALS['duplicator_opts']['dbhost'] = isset($GLOBALS['duplicator_opts']['dbhost']) ? $GLOBALS['duplicator_opts']['dbhost'] : '';
  32. $GLOBALS['duplicator_opts']['dbname'] = isset($GLOBALS['duplicator_opts']['dbname']) ? $GLOBALS['duplicator_opts']['dbname'] : '';
  33. $GLOBALS['duplicator_opts']['dbuser'] = isset($GLOBALS['duplicator_opts']['dbuser']) ? $GLOBALS['duplicator_opts']['dbuser'] : '';
  34. $GLOBALS['duplicator_opts']['dbadd_drop'] = isset($GLOBALS['duplicator_opts']['dbadd_drop']) ? $GLOBALS['duplicator_opts']['dbadd_drop'] : '0';
  35. $GLOBALS['duplicator_opts']['url_new'] = isset($GLOBALS['duplicator_opts']['url_new'] ) ? $GLOBALS['duplicator_opts']['url_new'] : '';
  36. $GLOBALS['duplicator_opts']['email-me'] = isset($GLOBALS['duplicator_opts']['email-me']) ? $GLOBALS['duplicator_opts']['email-me'] : '0';
  37. $GLOBALS['duplicator_opts']['log_level'] = isset($GLOBALS['duplicator_opts']['log_level']) ? $GLOBALS['duplicator_opts']['log_level'] : '0';
  38. $GLOBALS['duplicator_opts']['email_others'] = isset($GLOBALS['duplicator_opts']['email_others']) ? $GLOBALS['duplicator_opts']['email_others'] : '';
  39. $GLOBALS['duplicator_opts']['skip_ext'] = isset($GLOBALS['duplicator_opts']['skip_ext']) ? $GLOBALS['duplicator_opts']['skip_ext'] : '';
  40. $GLOBALS['duplicator_opts']['dir_bypass'] = isset($GLOBALS['duplicator_opts']['dir_bypass']) ? $GLOBALS['duplicator_opts']['dir_bypass'] : '';
  41. $GLOBALS['duplicator_opts']['rm_snapshot'] = isset($GLOBALS['duplicator_opts']['rm_snapshot']) ? $GLOBALS['duplicator_opts']['rm_snapshot'] : '1';
  42. //Default Arrays
  43. $GLOBALS['duplicator_bypass-array'] = explode(";", $GLOBALS['duplicator_opts']['dir_bypass'], -1);
  44. $GLOBALS['duplicator_bypass-array'] = count($GLOBALS['duplicator_bypass-array']) ? $GLOBALS['duplicator_bypass-array'] : null;
  45. $GLOBALS['duplicator_skip_ext-array'] = explode(";", $GLOBALS['duplicator_opts']['skip_ext']) ? explode(";", $GLOBALS['duplicator_opts']['skip_ext']) : array();
  46. require_once 'inc/functions.php';
  47. require_once 'inc/class.zip.php';
  48. require_once 'inc/actions.php';
  49. /* ACTIVATION
  50. Only called when plugin is activated */
  51. function duplicator_activate() {
  52. global $wpdb;
  53. $table_name = $wpdb->prefix . "duplicator";
  54. //PRIMARY KEY must have 2 spaces before for dbDelta
  55. $sql = "CREATE TABLE `{$table_name}` (
  56. id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  57. token VARCHAR(25) NOT NULL,
  58. packname VARCHAR(250) NOT NULL,
  59. zipname VARCHAR(250) NOT NULL,
  60. zipsize INT (11),
  61. created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  62. owner VARCHAR(60) NOT NULL,
  63. settings LONGTEXT NOT NULL)" ;
  64. require_once(DUPLICATOR_WPROOTPATH . 'wp-admin/includes/upgrade.php');
  65. @dbDelta($sql);
  66. $duplicator_opts = array(
  67. 'dbhost' =>'localhost',
  68. 'dbname' =>'',
  69. 'dbuser' =>'',
  70. 'url_new' =>'',
  71. 'email-me' =>"{$GLOBALS['duplicator_opts']['email-me']}",
  72. 'email_others' =>"{$GLOBALS['duplicator_opts']['email_others']}",
  73. 'dir_bypass' =>"{$GLOBALS['duplicator_opts']['dir_bypass']}",
  74. 'log_level' =>'0',
  75. 'skip_ext' =>"{$GLOBALS['duplicator_opts']['skip_ext']}",
  76. 'rm_snapshot' =>"{$GLOBALS['duplicator_opts']['rm_snapshot']}");
  77. update_option('duplicator_version_plugin', DUPLICATOR_VERSION);
  78. update_option('duplicator_options', serialize($duplicator_opts));
  79. //CLEANUP LEGACY
  80. //PRE 0.2.9
  81. delete_option('duplicator_version_database');
  82. $wpdb->query("ALTER TABLE `{$table_name}` CHANGE bid id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT");
  83. $wpdb->query("ALTER TABLE `{$table_name}` DROP COLUMN ver_db");
  84. $wpdb->query("ALTER TABLE `{$table_name}` DROP COLUMN ver_plug");
  85. $wpdb->query("ALTER TABLE `{$table_name}` DROP COLUMN status");
  86. $wpdb->query("ALTER TABLE `{$table_name}` DROP COLUMN type");
  87. //Setup All Directories
  88. duplicator_init_snapshotpath();
  89. }
  90. /* UPDATE
  91. register_activation_hook is not called when a plugin is updated
  92. so we need to use the following function */
  93. function duplicator_update() {
  94. if (DUPLICATOR_VERSION != get_option("duplicator_version_plugin")) {
  95. duplicator_activate();
  96. }
  97. }
  98. /* DEACTIVATION
  99. Only called when plugin is deactivated */
  100. function duplicator_deactivate() {
  101. //No actions needed yet
  102. }
  103. /* UNINSTALL
  104. Uninstall all duplicator logic */
  105. function duplicator_uninstall() {
  106. global $wpdb;
  107. $table_name = $wpdb->prefix . "duplicator";
  108. $wpdb->query("DROP TABLE `{$table_name}`");
  109. delete_option('duplicator_version_plugin');
  110. delete_option('duplicator_options');
  111. if ($GLOBALS['duplicator_opts']['rm_snapshot']) {
  112. $ssdir = duplicator_safe_path(DUPLICATOR_SSDIR_PATH);
  113. //Sanity check for strange setup
  114. $check = glob("{$ssdir}/wp-config.php");
  115. if (count($check) == 0) {
  116. //PHP is sometimes flaky so lets do a sanity check
  117. foreach (glob("{$ssdir}/*_database.sql") as $file) { if (strstr($file, '_database.sql')) {@unlink("{$file}");} }
  118. foreach (glob("{$ssdir}/*_installer.php") as $file) { if (strstr($file, '_installer.php')) {@unlink("{$file}");} }
  119. foreach (glob("{$ssdir}/*_package.zip") as $file) { if (strstr($file, '_package.zip')) {@unlink("{$file}");} }
  120. foreach (glob("{$ssdir}/*.log") as $file) { if (strstr($file, '.log')) {@unlink("{$file}");} }
  121. //Check for core files and only continue removing data if the snapshots directory
  122. //has not been edited by 3rd party sources, this helps to keep the system stable
  123. $files = glob("{$ssdir}/*");
  124. if(is_array($files) && count($files) == 3)
  125. {
  126. $defaults = array("{$ssdir}/index.php", "{$ssdir}/robots.txt", "{$ssdir}/dtoken.php");
  127. $compare = array_diff($defaults, $files);
  128. if (count($compare) == 0) {
  129. foreach($defaults as $file) {@unlink("{$file}");}
  130. @unlink("{$ssdir}/.htaccess");
  131. @rmdir($ssdir);
  132. }
  133. //No packages have ever been created
  134. } else if(is_array($files) && count($files) == 1) {
  135. $defaults = array("{$ssdir}/index.php");
  136. $compare = array_diff($defaults, $files);
  137. if (count($compare) == 0) {
  138. @unlink("{$ssdir}/index.php");
  139. @rmdir($ssdir);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. /* META LINK ADDONS
  146. Adds links to the plugins manager page */
  147. function duplicator_meta_links( $links, $file ) {
  148. $plugin = plugin_basename(__FILE__);
  149. // create link
  150. if ( $file == $plugin ) {
  151. $links[] = '<a href="' . DUPLICATOR_HELPLINK . '" title="' . __( 'FAQ', 'wpduplicator' ) . '" target="_blank">' . __( 'FAQ', 'wpduplicator' ) . '</a>';
  152. $links[] = '<a href="' . DUPLICATOR_GIVELINK . '" title="' . __( 'Partner', 'wpduplicator' ) . '" target="_blank">' . __( 'Partner', 'wpduplicator' ) . '</a>';
  153. $links[] = '<a href="' . DUPLICATOR_CERTIFIED .'" title="' . __( 'Approved Hosts', 'wpduplicator' ) . '" target="_blank">' . __( 'Approved Hosts', 'wpduplicator' ) . '</a>';
  154. return $links;
  155. }
  156. return $links;
  157. }
  158. //HOOKS & ACTIONS
  159. load_plugin_textdomain('wpduplicator' , FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
  160. register_activation_hook(__FILE__ , 'duplicator_activate');
  161. register_deactivation_hook(__FILE__ , 'duplicator_deactivate');
  162. register_uninstall_hook(__FILE__ , 'duplicator_uninstall');
  163. add_action('plugins_loaded', 'duplicator_update');
  164. add_action('admin_init', 'duplicator_init' );
  165. add_action('admin_menu', 'duplicator_menu');
  166. add_action('wp_ajax_duplicator_system_check', 'duplicator_system_check');
  167. add_action('wp_ajax_duplicator_system_directory', 'duplicator_system_directory');
  168. add_action('wp_ajax_duplicator_delete', 'duplicator_delete');
  169. add_action('wp_ajax_duplicator_create', 'duplicator_create');
  170. add_action('wp_ajax_duplicator_settings', 'duplicator_settings');
  171. add_filter('plugin_action_links', 'duplicator_manage_link', 10, 2 );
  172. add_filter('plugin_row_meta', 'duplicator_meta_links', 10, 2 );
  173. /**
  174. * DUPLICATOR_INIT
  175. * Init routines */
  176. function duplicator_init() {
  177. /* Register our stylesheet. */
  178. wp_register_style('jquery-ui', DUPLICATOR_PLUGIN_URL . 'css/jquery-ui.css', null , "1.9.2" );
  179. wp_register_style('duplicator_style', DUPLICATOR_PLUGIN_URL . 'css/style.css' );
  180. }
  181. /**
  182. * DUPLICATOR_VIEWS
  183. * Inlcude all visual elements */
  184. function duplicator_main_page() {include 'inc/page.main.php';}
  185. //Diagnostics Page
  186. function duplicator_diag_page() {include 'inc/page.diag.php';}
  187. //Support Page
  188. function duplicator_support_page() {include 'inc/page.support.php';}
  189. //All About Page
  190. function duplicator_about_page() {include 'inc/page.about.php';}
  191. /**
  192. * DUPLICATOR_MENU
  193. * Loads the menu item into the WP tools section and queues the actions for only this plugin */
  194. function duplicator_menu() {
  195. //Main Menu
  196. $page_main = add_menu_page('Duplicator', 'Duplicator', "import", basename(__FILE__), 'duplicator_main_page', plugins_url('duplicator/img/create.png'));
  197. add_submenu_page(basename(__FILE__), __('Dashboard', 'wpduplicator'), __('Dashboard', 'wpduplicator'), "import" , basename(__FILE__), 'duplicator_main_page');
  198. //Sub Menus
  199. $page_diag = add_submenu_page(basename(__FILE__), __('Diagnostics', 'wpduplicator'), __('Diagnostics', 'wpduplicator'), 'import', 'duplicator_diag_page', 'duplicator_diag_page');
  200. $page_support = add_submenu_page(basename(__FILE__), __('Support', 'wpduplicator'), __('Support', 'wpduplicator'), 'import', 'duplicator_support_page', 'duplicator_support_page');
  201. $page_about = add_submenu_page(basename(__FILE__), __('All About', 'wpduplicator'), __('All About', 'wpduplicator'), 'import', 'duplicator_about_page', 'duplicator_about_page');
  202. //Apply scripts and styles
  203. add_action('admin_print_scripts-' . $page_main, 'duplicator_scripts');
  204. add_action('admin_print_styles-' . $page_main, 'duplicator_styles' );
  205. add_action('admin_print_styles-' . $page_diag, 'duplicator_styles' );
  206. add_action('admin_print_styles-' . $page_about, 'duplicator_styles' );
  207. add_action('admin_print_styles-' . $page_support, 'duplicator_styles' );
  208. }
  209. /**
  210. * DUPLICATOR_SCRIPTS
  211. * Loads the required javascript libs only for this plugin */
  212. function duplicator_scripts() {
  213. wp_enqueue_script('jquery');
  214. wp_enqueue_script('jquery-ui-core');
  215. wp_enqueue_script('jquery-ui-dialog');
  216. wp_enqueue_script('jquery-ui-button');
  217. wp_enqueue_script('jquery-ui-tabs');
  218. }
  219. /**
  220. * DUPLICATOR_STYLES
  221. * Loads the required css links only for this plugin */
  222. function duplicator_styles() {
  223. wp_enqueue_style('jquery-ui');
  224. wp_enqueue_style('duplicator_style');
  225. }
  226. /**
  227. * DUPLICATOR_MANAGE_LINK
  228. * Adds the manage link in the plugins list */
  229. function duplicator_manage_link($links, $file) {
  230. static $this_plugin;
  231. if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);
  232. if ($file == $this_plugin){
  233. $settings_link = '<a href="admin.php?page=duplicator.php">'. __("Manage", 'wpduplicator') .'</a>';
  234. array_unshift($links, $settings_link);
  235. }
  236. return $links;
  237. }
  238. //Use WordPress Debugging log file. file is written to wp-content/debug.log
  239. //trace with tail command to see real-time issues.
  240. if(!function_exists('duplicator_debug')){
  241. function duplicator_debug( $message ) {
  242. if( WP_DEBUG === true ){
  243. if( is_array( $message ) || is_object( $message ) ){
  244. error_log( print_r( $message, true ) );
  245. } else {
  246. error_log( $message );
  247. }
  248. }
  249. }
  250. }
  251. }
  252. ?>