PageRenderTime 83ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backwpup/backwpup.php

https://bitbucket.org/cesarmedrano/cesarmedrano
PHP | 334 lines | 182 code | 49 blank | 103 comment | 67 complexity | 818c7788143b3f6039961af5a883233f MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: BackWPup
  4. * Plugin URI: https://marketpress.com/product/backwpup-pro/
  5. * Description: WordPress Backup and more...
  6. * Author: Inpsyde GmbH
  7. * Author URI: http://inpsyde.com
  8. * Version: 3.0.6
  9. * Text Domain: backwpup
  10. * Domain Path: /languages/
  11. * Network: true
  12. * License: GPLv3
  13. * License URI: http://www.gnu.org/licenses/gpl-3.0
  14. * Slug: backwpup
  15. */
  16. /**
  17. * Copyright (C) 2012-2013 Inpsyde GmbH (email: info@inpsyde.com)
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version 2
  22. * of the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  32. */
  33. if ( ! class_exists( 'BackWPup' ) ) {
  34. // Don't activate on anything less than PHP 5.2.4 or WordPress 3.1
  35. if ( version_compare( PHP_VERSION, '5.2.6', '<' ) || version_compare( get_bloginfo( 'version' ), '3.2', '<' ) ) {
  36. require_once ABSPATH . 'wp-admin/includes/plugin.php';
  37. deactivate_plugins( basename( __FILE__ ) );
  38. if ( isset( $_GET['action'] ) && ( $_GET['action'] == 'activate' || $_GET['action'] == 'error_scrape' ) )
  39. die( __( 'BackWPup requires PHP version 5.2.6 or greater and WordPress 3.2 or greater.', 'backwpup' ) );
  40. }
  41. //Start Plugin
  42. if ( function_exists( 'add_filter' ) )
  43. add_action( 'plugins_loaded', array( 'BackWPup', 'getInstance' ), 11 );
  44. /**
  45. * Main BackWPup Plugin Class
  46. */
  47. final class BackWPup {
  48. private static $instance = NULL;
  49. private static $plugin_data = array();
  50. private static $destinations = array();
  51. private static $job_types = array();
  52. private static $wizards = array();
  53. /**
  54. * Set needed filters and actions and load
  55. */
  56. private function __construct() {
  57. // Nothing else matters if we're on WP-MS and not on the main site
  58. if ( is_multisite() && ! is_main_site() )
  59. return;
  60. //auto loader
  61. if ( function_exists( 'spl_autoload_register' ) ) //register auto load
  62. spl_autoload_register( array( $this, 'autoloader' ) );
  63. else //auto loader fallback
  64. $this->autoloader_fallback();
  65. //WP-Cron
  66. add_action( 'backwpup_cron', array( 'BackWPup_Cron', 'run' ) );
  67. add_action( 'backwpup_check_cleanup', array( 'BackWPup_Cron', 'check_cleanup' ) );
  68. //deactivation hook
  69. register_deactivation_hook( __FILE__, array( 'BackWPup_Install', 'deactivate' ) );
  70. //Things that must do in plugin init
  71. add_action( 'init', array( $this, 'plugin_init' ) );
  72. //start upgrade if needed
  73. if ( get_site_option( 'backwpup_version' ) != self::get_plugin_data( 'Version' ) && class_exists( 'BackWPup_Install' ) )
  74. BackWPup_Install::activate();
  75. //Frontend
  76. if ( ! is_admin() && is_main_site() && class_exists( 'BackWPup_FrontEnd' ) )
  77. BackWPup_FrontEnd::getInstance();
  78. //load Pro Features
  79. if ( is_file( dirname( __FILE__ ) . '/inc/features/class-features.php' ) )
  80. require dirname( __FILE__ ) . '/inc/features/class-features.php';
  81. //only in backend
  82. if ( is_admin() && ( current_user_can( 'backwpup' ) || $GLOBALS[ 'pagenow' ] == 'plugins.php' ) && class_exists( 'BackWPup_Admin' ) )
  83. BackWPup_Admin::getInstance();
  84. //work with wp-cli
  85. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  86. require dirname( __FILE__ ) . '/inc/class-wp-cli.php';
  87. WP_CLI::addCommand( 'backwpup', 'BackWPup_WP_CLI' );
  88. }
  89. }
  90. /**
  91. * @static
  92. *
  93. * @return self
  94. */
  95. public static function getInstance() {
  96. if (NULL === self::$instance) {
  97. self::$instance = new self;
  98. }
  99. return self::$instance;
  100. }
  101. private function __clone() {}
  102. /**
  103. * get information about the Plugin
  104. *
  105. * @param string $name Name of info to get or NULL to get all
  106. * @return string|array
  107. */
  108. public static function get_plugin_data( $name = NULL ) {
  109. if ( $name )
  110. $name = strtolower( $name );
  111. if ( empty( self::$plugin_data ) ) {
  112. self::$plugin_data = get_file_data( __FILE__, array(
  113. 'name' => 'Plugin Name',
  114. 'pluginuri' => 'Plugin URI',
  115. 'version' => 'Version',
  116. 'description' => 'Description',
  117. 'author' => 'Author',
  118. 'authoruri' => 'Author URI',
  119. 'textdomain' => 'Text Domain',
  120. 'domainpath' => 'Domain Path',
  121. 'slug' => 'Slug',
  122. 'license' => 'License',
  123. 'licenseuri' => 'License URI'
  124. ), 'plugin' );
  125. //Translate some vars
  126. self::$plugin_data[ 'name' ] = trim( self::$plugin_data[ 'name' ] );
  127. self::$plugin_data[ 'pluginuri' ] = trim( self::$plugin_data[ 'pluginuri' ] );
  128. self::$plugin_data[ 'description' ] = trim( self::$plugin_data[ 'description' ] );
  129. self::$plugin_data[ 'author' ] = trim( self::$plugin_data[ 'author' ] );
  130. self::$plugin_data[ 'authoruri' ] = trim( self::$plugin_data[ 'authoruri' ] );
  131. //set some extra vars
  132. self::$plugin_data[ 'basename' ] = plugin_basename( dirname( __FILE__ ) );
  133. self::$plugin_data[ 'mainfile' ] = __FILE__ ;
  134. self::$plugin_data[ 'plugindir' ] = untrailingslashit( dirname( __FILE__ ) ) ;
  135. if ( defined( 'WP_TEMP_DIR' ) && is_dir( WP_TEMP_DIR ) ) {
  136. self::$plugin_data[ 'temp' ] = trailingslashit( str_replace( '\\', '/', WP_TEMP_DIR ) ) . 'backwpup-' . substr( md5( md5( SECURE_AUTH_KEY ) ), - 5 ) . '/';
  137. } else {
  138. $upload_dir = wp_upload_dir();
  139. self::$plugin_data[ 'temp' ] = trailingslashit( str_replace( '\\', '/',$upload_dir[ 'basedir' ] ) ) . 'backwpup-' . substr( md5( md5( SECURE_AUTH_KEY ) ), - 5 ) . '-temp/';
  140. }
  141. self::$plugin_data[ 'running_file' ] = self::$plugin_data[ 'temp' ] . 'backwpup-' . substr( md5( NONCE_SALT ), 13, 6 ) . '-working.php';
  142. self::$plugin_data[ 'url' ] = plugins_url( '', __FILE__ );
  143. //get unmodified WP Versions
  144. include ABSPATH . WPINC . '/version.php';
  145. /** @var $wp_version string */
  146. self::$plugin_data[ 'wp_version' ] = $wp_version;
  147. //Build User Agent
  148. self::$plugin_data[ 'user-agent' ] = self::$plugin_data[ 'name' ].'/' . self::$plugin_data[ 'version' ] . '; WordPress/' . self::$plugin_data[ 'wp_version' ] . '; ' . home_url();
  149. }
  150. if ( ! empty( $name ) )
  151. return self::$plugin_data[ $name ];
  152. else
  153. return self::$plugin_data;
  154. }
  155. /**
  156. * include not existing classes automatically
  157. *
  158. * @param string $class_name Class to load from file
  159. */
  160. private function autoloader( $class_name ) {
  161. //BackWPup classes to load
  162. if ( strstr( $class_name, 'BackWPup_' ) ) {
  163. $class_file_name = DIRECTORY_SEPARATOR . 'class-' . strtolower( str_replace( array( 'BackWPup_', '_' ), array( '', '-' ), $class_name ) ) . '.php';
  164. if ( class_exists( 'BackWPup_Features', FALSE ) && is_file( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'features' . $class_file_name ) )
  165. require dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'features' . $class_file_name;
  166. elseif ( is_file( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'inc' . $class_file_name ) )
  167. require dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'inc' . $class_file_name;
  168. }
  169. }
  170. /**
  171. * load all classes if spl auto loader not exists
  172. */
  173. private function autoloader_fallback() {
  174. //add class files that should excluded that are classes that extra loaded with require or needs spl_autoload_register to work
  175. $loaded_class_files = array( 'class-auto-update.php', 'class-documentation.php', 'class-features.php',
  176. 'class-destination-msazure.php', 'class-destination-msazure-pro.php',
  177. 'class-destination-email.php', 'class-destination-email-pro.php',
  178. 'class-destination-rsc.php', 'class-destination-rsc-pro.php',
  179. 'class-destination-s3.php', 'class-destination-s3-pro.php',
  180. 'class-destination-s3-v1.php', 'class-destination-s3-v1-pro.php',
  181. 'class-destinations.php', 'class-jobtypes.php', 'class-wizards.php',
  182. 'class-wp-cli.php' );
  183. //load first abstraction classes
  184. require dirname( __FILE__ ) . '/inc/class-destinations.php';
  185. require dirname( __FILE__ ) . '/inc/class-jobtypes.php';
  186. if ( is_file( dirname( __FILE__ ) . '/inc/features/class-features.php' ) )
  187. require dirname( __FILE__ ) . '/inc/features/class-wizards.php';
  188. require_once ABSPATH . '/wp-admin/includes/class-wp-list-table.php';
  189. //load normal classes
  190. foreach( glob( dirname( __FILE__ ) . '/inc/class-*.php' ) as $class ) {
  191. if ( ! in_array( basename( $class ), $loaded_class_files ) )
  192. require $class;
  193. }
  194. //load features
  195. if ( is_file( dirname( __FILE__ ) . '/inc/features/class-features.php' ) ) {
  196. foreach( glob( dirname( __FILE__ ) . '/inc/features/class-*.php' ) as $class ) {
  197. if ( ! in_array( basename( $class ), $loaded_class_files ) )
  198. require $class;
  199. }
  200. }
  201. }
  202. /**
  203. * Plugin init function
  204. *
  205. * @return void
  206. */
  207. public function plugin_init() {
  208. //Add Admin Bar
  209. if ( ! defined( 'DOING_CRON' ) && current_user_can( 'backwpup' ) && current_user_can( 'backwpup' ) && is_admin_bar_showing() && get_site_option( 'backwpup_cfg_showadminbar', FALSE ) )
  210. BackWPup_Adminbar::getInstance();
  211. }
  212. /**
  213. * Get a array of instances for Backup Destination's
  214. *
  215. * @return array
  216. */
  217. public static function get_destinations() {
  218. if ( ! empty( self::$destinations ) )
  219. return self::$destinations;
  220. //add BackWPup Destinations
  221. self::$destinations[ 'FOLDER' ] = new BackWPup_Destination_Folder;
  222. if ( class_exists( 'BackWPup_Destination_Email' ) )
  223. self::$destinations[ 'EMAIL' ] = new BackWPup_Destination_Email;
  224. if ( function_exists( 'ftp_login' ) )
  225. self::$destinations[ 'FTP' ] = new BackWPup_Destination_Ftp;
  226. if ( function_exists( 'curl_exec' ) )
  227. self::$destinations[ 'DROPBOX' ] = new BackWPup_Destination_Dropbox;
  228. if ( function_exists( 'curl_exec' ) && version_compare( PHP_VERSION, '5.3.3', '>=' ) && class_exists( 'BackWPup_Destination_S3' ) )
  229. self::$destinations[ 'S3' ] = new BackWPup_Destination_S3;
  230. elseif ( function_exists( 'curl_exec' ) && class_exists( 'BackWPup_Destination_S3_V1' ) )
  231. self::$destinations[ 'S3' ] = new BackWPup_Destination_S3_V1;
  232. if ( version_compare( PHP_VERSION, '5.3.2', '>=' ) && class_exists( 'BackWPup_Destination_MSAzure' ) )
  233. self::$destinations[ 'MSAZURE' ] = new BackWPup_Destination_MSAzure;
  234. if ( function_exists( 'curl_exec' ) && version_compare( PHP_VERSION, '5.3.0', '>=' ) && class_exists( 'BackWPup_Destination_RSC' ) )
  235. self::$destinations[ 'RSC' ] = new BackWPup_Destination_RSC;
  236. if ( function_exists( 'curl_exec' ) )
  237. self::$destinations[ 'SUGARSYNC' ] = new BackWPup_Destination_SugarSync;
  238. self::$destinations = apply_filters( 'backwpup_destinations', self::$destinations );
  239. //remove destinations can't load
  240. foreach ( self::$destinations as $key => $destination ) {
  241. if ( empty( $destination ) || ! is_object( $destination ) )
  242. unset( self::$destinations[ $key ] );
  243. }
  244. return self::$destinations;
  245. }
  246. /**
  247. * Gets a array of instances from Job types
  248. *
  249. * @return array
  250. */
  251. public static function get_job_types() {
  252. if ( !empty( self::$job_types ) )
  253. return self::$job_types;
  254. self::$job_types[ 'DBDUMP' ]= new BackWPup_JobType_DBDump;
  255. self::$job_types[ 'FILE' ] = new BackWPup_JobType_File;
  256. self::$job_types[ 'WPEXP' ] = new BackWPup_JobType_WPEXP;
  257. self::$job_types[ 'WPPLUGIN' ] = new BackWPup_JobType_WPPlugin;
  258. self::$job_types[ 'DBOPTIMIZE' ]= new BackWPup_JobType_DBOptimize;
  259. self::$job_types[ 'DBCHECK' ] = new BackWPup_JobType_DBCheck;
  260. self::$job_types = apply_filters( 'backwpup_job_types', self::$job_types );
  261. //remove types can't load
  262. foreach ( self::$job_types as $key => $job_type ) {
  263. if ( empty( $job_type ) || ! is_object( $job_type ) )
  264. unset( self::$job_types[ $key ] );
  265. }
  266. return self::$job_types;
  267. }
  268. /**
  269. * Gets a array of instances from Wizards Pro version Only
  270. *
  271. * @return array
  272. */
  273. public static function get_wizards() {
  274. if ( !empty( self::$wizards ) )
  275. return self::$wizards;
  276. self::$wizards = apply_filters( 'backwpup_wizards', self::$wizards );
  277. //remove wizards can't load
  278. foreach ( self::$wizards as $key => $wizard ) {
  279. if ( empty( $wizard ) || ! is_object( $wizard ) )
  280. unset( self::$wizards[ $key ] );
  281. }
  282. return self::$wizards;
  283. }
  284. }
  285. }