PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

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