2014-03-19 23:27:26 +07:00
< ? php
/*
Plugin Name : MainWP Remote Backup Extension
2016-01-25 18:12:46 +01:00
Plugin URI : https :// mainwp . com
2014-03-19 23:27:26 +07:00
Description : MainWP Remote Backup Extension is an extension for the MainWP plugin that enables you store your backups on different off site locations .
2016-03-04 14:01:28 +01:00
Version : 1.1
2014-03-19 23:27:26 +07:00
Author : MainWP
2016-01-25 18:12:46 +01:00
Author URI : https :// mainwp . com
Icon URI :
2015-04-17 18:55:12 +07:00
Documentation URI : http :// docs . mainwp . com / category / mainwp - extensions / mainwp - remote - backups - extension /
2014-03-19 23:27:26 +07:00
*/
2015-04-17 18:55:12 +07:00
if ( ! defined ( 'MAINWP_REMOTE_BACKUP_PLUGIN_FILE' )) {
define ( 'MAINWP_REMOTE_BACKUP_PLUGIN_FILE' , __FILE__ );
}
2014-03-19 23:27:26 +07:00
class MainWPRemoteBackupExtension
{
public static $instance = null ;
public $plugin_handle = " mainwp-remote-backup-extension " ;
protected $plugin_url ;
protected $mainWPRemoteBackup ;
private $plugin_slug ;
static function Instance ()
{
if ( MainWPRemoteBackupExtension :: $instance == null ) MainWPRemoteBackupExtension :: $instance = new MainWPRemoteBackupExtension ();
return MainWPRemoteBackupExtension :: $instance ;
}
2014-04-02 19:42:20 +02:00
static function isActivated ()
{
return self :: $instance != null ;
}
2014-03-19 23:27:26 +07:00
public function __construct ()
{
$this -> plugin_url = plugin_dir_url ( __FILE__ );
$this -> plugin_slug = plugin_basename ( __FILE__ );
add_action ( 'init' , array ( & $this , 'init' ));
add_filter ( 'plugin_row_meta' , array ( & $this , 'plugin_row_meta' ), 10 , 2 );
2015-12-12 01:12:04 +07:00
add_action ( 'after_plugin_row' , array ( & $this , 'after_plugin_row' ), 10 , 3 );
2014-03-19 23:27:26 +07:00
MainWPRemoteBackupDB :: Instance () -> install ();
MainWPRemoteDestination :: init ();
$this -> mainWPRemoteBackup = new MainWPRemoteBackupSystem ();
add_action ( 'admin_init' , array ( & $this , 'admin_init' ));
add_action ( 'mainwp_backups_remote_settings' , array ( 'MainWPRemoteDestinationUI' , 'mainwp_backups_remote_settings' ));
add_filter ( 'mainwp_backups_remote_get_destinations' , array ( 'MainWPRemoteDestinationUI' , 'mainwp_backups_remote_get_destinations' ), 10 , 2 );
add_action ( 'mainwp_remote_backup_extension_cronremotedestinationcheck_action' , array ( 'MainWPRemoteBackupSystem' , 'mainwp_remote_backup_extension_cronremotedestinationcheck_action' ));
2014-04-02 19:42:20 +02:00
$useWPCron = ( get_option ( 'mainwp_wp_cron' ) === false ) || ( get_option ( 'mainwp_wp_cron' ) == 1 );
if (( $sched = wp_next_scheduled ( 'mainwp_remote_backup_extension_cronremotedestinationcheck_action' )) == false )
{
if ( $useWPCron ) wp_schedule_event ( time (), 'daily' , 'mainwp_remote_backup_extension_cronremotedestinationcheck_action' );
}
else
{
if ( ! $useWPCron ) wp_unschedule_event ( $sched , 'mainwp_remote_backup_extension_cronremotedestinationcheck_action' );
}
2014-03-19 23:27:26 +07:00
}
2014-08-07 23:10:13 +07:00
2014-03-19 23:27:26 +07:00
public function init ()
{
2014-08-04 22:37:48 +02:00
$this -> mainWPRemoteBackup -> init ();
2014-03-19 23:27:26 +07:00
}
public function plugin_row_meta ( $plugin_meta , $plugin_file )
{
if ( $this -> plugin_slug != $plugin_file ) return $plugin_meta ;
2016-02-02 23:30:54 +07:00
$slug = basename ( $plugin_file , " .php " );
$api_data = get_option ( $slug . '_APIManAdder' );
if ( ! is_array ( $api_data ) || ! isset ( $api_data [ 'activated_key' ]) || $api_data [ 'activated_key' ] != 'Activated' || ! isset ( $api_data [ 'api_key' ]) || empty ( $api_data [ 'api_key' ]) ) {
return $plugin_meta ;
}
2014-03-19 23:27:26 +07:00
$plugin_meta [] = '<a href="?do=checkUpgrade" title="Check for updates.">Check for updates now</a>' ;
return $plugin_meta ;
}
2015-12-12 01:12:04 +07:00
public function after_plugin_row ( $plugin_file , $plugin_data , $status ) {
if ( $this -> plugin_slug != $plugin_file ) {
return ;
}
$slug = basename ( $plugin_file , " .php " );
$api_data = get_option ( $slug . '_APIManAdder' );
if ( ! is_array ( $api_data ) || ! isset ( $api_data [ 'activated_key' ]) || $api_data [ 'activated_key' ] != 'Activated' ){
if ( ! isset ( $api_data [ 'api_key' ]) || empty ( $api_data [ 'api_key' ])) {
?>
< style type = " text/css " >
tr #<?php echo $slug;?> td, tr#<?php echo $slug;?> th{
box - shadow : none ;
}
</ style >
< tr class = " plugin-update-tr active " >< td colspan = " 3 " class = " plugin-update colspanchange " >< div class = " update-message api-deactivate " >
2016-02-02 23:30:54 +07:00
< ? php echo ( sprintf ( __ ( " API not activated check your %sMainWP account%s for updates. For automatic update notification please activate the API. " , " mainwp " ), '<a href="https://mainwp.com/my-account" target="_blank">' , '</a>' )); ?>
2015-12-12 01:12:04 +07:00
</ div ></ td ></ tr >
< ? php
}
}
}
2014-03-19 23:27:26 +07:00
public function admin_init ()
{
wp_enqueue_style ( 'mainwp-remote-backup-extension-css' , $this -> plugin_url . 'css/mainwp-remote-backup.css' );
wp_enqueue_script ( 'mainwp-remote-backup-extension-js' , $this -> plugin_url . 'js/mainwp-remote-backup.js' );
wp_localize_script ( 'mainwp-remote-backup-extension-js' , 'mainwp_remote_backup_security_nonces' , $this -> mainWPRemoteBackup -> security_nonces );
}
}
2014-12-09 15:05:59 +07:00
function mainwp_remote_backup_extension_autoload ( $class_name )
{
2015-02-18 21:43:28 +01:00
if ( stristr ( $class_name , '\\' ))
{
$class_name = str_replace ( '\\' , DIRECTORY_SEPARATOR , $class_name );
2015-05-11 20:27:00 +02:00
if ( stristr ( $class_name , 'Dropbox' )) $class_name = str_replace ( '_' , DIRECTORY_SEPARATOR , $class_name );
2015-02-18 21:43:28 +01:00
$file = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . str_replace ( basename ( __FILE__ ), '' , plugin_basename ( __FILE__ )) . 'libs' . DIRECTORY_SEPARATOR . $class_name . '.php' ;
if ( file_exists ( $file ))
{
require_once ( $file );
}
return ;
}
2014-12-09 15:05:59 +07:00
$allowedLoadingTypes = array ( 'class' );
foreach ( $allowedLoadingTypes as $allowedLoadingType )
{
$class_file = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . str_replace ( basename ( __FILE__ ), '' , plugin_basename ( __FILE__ )) . $allowedLoadingType . DIRECTORY_SEPARATOR . $class_name . '.' . $allowedLoadingType . '.php' ;
if ( file_exists ( $class_file ))
{
require_once ( $class_file );
}
}
}
if ( function_exists ( 'spl_autoload_register' ))
{
spl_autoload_register ( 'mainwp_remote_backup_extension_autoload' );
}
else
{
function __autoload ( $class_name )
{
mainwp_remote_backup_extension_autoload ( $class_name );
}
}
2014-08-07 23:10:13 +07:00
register_activation_hook ( __FILE__ , 'remote_backup_extension_activate' );
2014-12-09 15:05:59 +07:00
register_deactivation_hook ( __FILE__ , 'remote_backup_extension_deactivate' );
2014-08-07 23:10:13 +07:00
function remote_backup_extension_activate ()
{
update_option ( 'mainwp_remote_backup_extension_activated' , 'yes' );
2014-12-09 15:05:59 +07:00
$extensionActivator = new MainWPRemoteBackupExtensionActivator ();
2016-02-02 23:30:54 +07:00
$extensionActivator -> activate ();
2014-12-09 15:05:59 +07:00
}
function remote_backup_extension_deactivate ()
{
$extensionActivator = new MainWPRemoteBackupExtensionActivator ();
$extensionActivator -> deactivate ();
2014-08-07 23:10:13 +07:00
}
2014-03-19 23:27:26 +07:00
class MainWPRemoteBackupExtensionActivator
{
protected $mainwpMainActivated = false ;
protected $childEnabled = false ;
protected $childKey = false ;
protected $childFile ;
2014-12-09 15:05:59 +07:00
protected $plugin_handle = " mainwp-remote-backup-extension " ;
protected $product_id = " MainWP Remote Backup Extension " ;
2016-03-04 14:01:28 +01:00
protected $software_version = " 1.1 " ;
2014-12-09 15:05:59 +07:00
2014-03-19 23:27:26 +07:00
public function __construct ()
{
$this -> childFile = __FILE__ ;
add_filter ( 'mainwp-getextensions' , array ( & $this , 'get_this_extension' ));
$this -> mainwpMainActivated = apply_filters ( 'mainwp-activated-check' , false );
if ( $this -> mainwpMainActivated !== false )
{
$this -> activate_this_plugin ();
}
else
{
add_action ( 'mainwp-activated' , array ( & $this , 'activate_this_plugin' ));
}
2014-08-07 23:10:13 +07:00
add_action ( 'admin_init' , array ( & $this , 'admin_init' ));
2014-03-19 23:27:26 +07:00
add_action ( 'admin_notices' , array ( & $this , 'mainwp_error_notice' ));
}
2014-08-07 23:10:13 +07:00
function admin_init () {
if ( get_option ( 'mainwp_remote_backup_extension_activated' ) == 'yes' )
{
delete_option ( 'mainwp_remote_backup_extension_activated' );
wp_redirect ( admin_url ( 'admin.php?page=Extensions' ));
return ;
}
}
2014-03-19 23:27:26 +07:00
function get_this_extension ( $pArray )
{
2014-12-09 15:05:59 +07:00
$pArray [] = array ( 'plugin' => __FILE__ , 'api' => $this -> plugin_handle , 'mainwp' => true , 'callback' => array ( & $this , 'settings' ), 'apiManager' => true );
2014-03-19 23:27:26 +07:00
return $pArray ;
}
2014-03-29 19:05:52 +01:00
function settings ()
{
do_action ( 'mainwp-pageheader-extensions' , __FILE__ );
2016-02-02 23:30:54 +07:00
?>
< ? php self :: QSGRemoteBackups (); ?>
< div class = " mainwp_info-box " >
< ? php _e ( 'This extension does not have the settings page. It just adds specific options to the backup feature. Check this <a href="http://docs.mainwp.com/backup-remote-destinations/" target="_blank">document</a> if you need help with this extension.' , 'mainwp' ); ?>
</ div >
< ? php
2014-03-29 19:05:52 +01:00
do_action ( 'mainwp-pagefooter-extensions' , __FILE__ );
}
2015-04-17 18:55:12 +07:00
function QSGRemoteBackups () {
$plugin_data = get_plugin_data ( MAINWP_REMOTE_BACKUP_PLUGIN_FILE , false );
$description = $plugin_data [ 'Description' ];
$extraHeaders = array ( 'DocumentationURI' => 'Documentation URI' );
$file_data = get_file_data ( MAINWP_REMOTE_BACKUP_PLUGIN_FILE , $extraHeaders );
$documentation_url = $file_data [ 'DocumentationURI' ];
?>
< div class = " mainwp_ext_info_box " id = " rb-pth-notice-box " >
< div class = " mainwp-ext-description " >< ? php echo $description ; ?> </div><br/>
< b >< ? php echo __ ( " Need Help? " ); ?> </b> <?php echo __("Review the Extension"); ?> <a href="<?php echo $documentation_url; ?>" target="_blank"><i class="fa fa-book"></i> <?php echo __('Documentation'); ?></a>.
< a href = " # " id = " mainwp-rb-quick-start-guide " >< i class = " fa fa-info-circle " ></ i > < ? php _e ( 'Show Quick Start Guide' , 'mainwp' ); ?> </a></div>
< div class = " mainwp_ext_info_box " id = " mainwp-rb-tips " style = " color: #333!important; text-shadow: none!important; " >
< span >< a href = " # " class = " mainwp-show-tut " number = " 1 " >< i class = " fa fa-book " ></ i > < ? php _e ( 'Dropbox' , 'mainwp' ) ?> </a> <a href="#" class="mainwp-show-tut" number="2"><i class="fa fa-book"></i> <?php _e('Copy.com','mainwp') ?></a> <a href="#" class="mainwp-show-tut" number="3"><i class="fa fa-book"></i> <?php _e('Amazon S3','mainwp') ?></a> <a href="#" class="mainwp-show-tut" number="4"><i class="fa fa-book"></i> <?php _e('FTP','mainwp') ?></a></span><span><a href="#" id="mainwp-rb-tips-dismiss" style="float: right;"><i class="fa fa-times-circle"></i> <?php _e('Dismiss','mainwp'); ?></a></span>
< div class = " clear " ></ div >
< div id = " mainwp-rb-tuts " >
< div class = " mainwp-rb-tut " number = " 1 " >
< h3 > Dropbox </ h3 >
< p > When creating a backup or backup task , to use the Dropbox as a remote backup destination :</ p >
< ul >
< li > Click the Remote Destination button in the " Store Backup in " option </ li >
< li > After popup appears , click the Add New . External source options will show . To select the Dropbox , click the Add button .</ li >
< li > Two new options will appear . Here you need to enter destination Title and Directory . Destination Title assigned here is used only for easier management in cases you have set multiple sources . If you want you can leave it as it is ( New Dropbox Destination ) . In the Directory field enter a name for the default backups directory .</ li >
< li > When ready , click the Connect to Dropbox button . Click on this button will open the Dropbox login screen , enter your login details and click the Sign In button . < strong > In case this window doesn’t open , be sure to turn off your popup blocker .</ strong ></ li >
< li > Once you Sign In , Dropbox will ask you if you want to allow MainWP to access your Dropbox . Click the Allow button .</ li >
< li > After you get the success message , return to dashboard and click the Yes , I’ve authorized MainWP to Dropbox button .</ li >
< li > Click the Test Settings button , if it returns success message click the Save Destination button .</ li >
</ ul >
</ div >
< div class = " mainwp-rb-tut " number = " 2 " >
< h3 > Copy . com </ h3 >
< p > When creating a backup or backup task , to use the Copy . com as a remote backup destination :</ p >
< ul >
< li > Click the Remote Destination button in the " Store Backup in " option </ li >
< li > After popup appears , click the Add New . External source options will show . To select the Copy . com , click the Add button .</ li >
< li > Two new options will appear . Here you need to enter destination Title and Directory . Destination Title assigned here is used only for easier management in cases you have set multiple sources . If you want you can leave it as it is ( New Copy . com Destination ) . In the Directory field enter a name for the default backups directory .</ li >
< li > When ready , click the Connect to Copy . com button . Click on this button will open the Copy . com login screen , enter your login details and click the Sign In button . < strong > In case this window doesn’t open , be sure to turn off your popup blocker .</ strong ></ li >
< li > Once you Sign In , Copy . com will ask you if you want to allow MainWP to access your Copy . com . Click the Allow button .</ li >
< li > After you get the success message , return to dashboard and click the Yes , I’ve authorized MainWP to Copy . com button .</ li >
< li > Click the Test Settings button , if it returns success message click the Save Destination button .</ li >
</ ul >
</ div >
< div class = " mainwp-rb-tut " number = " 3 " >
< h3 > Amazon S3 </ h3 >
< p > When creating a backup or backup task , to use the Amazon S3 as a remote backup destination :</ p >
< ul >
< li > Click the Remote Destination button in the " Store Backup in " option </ li >
< li > After choosing Remote Destination for keeping your backups , to select the Amazon S3 , click the Add button next to the Amazon icon .</ li >
< li > Settings fields will appear , here you need to provide a few details for proper use of the external source .</ li >
< li >
< ul >
< li > Destination title , something that will help you to manage your locations easier in future ; </ li >
< li > Access Key ID and Secret Key , provided by Amazon in your account ; </ li >
< li > Bucket , default backups bucket ; </ li >
< li > Sub - directory .</ li >
</ ul >
</ li >
< li > Once you have added all necessary info , Click the Test Settings button . If it returns the success message , click the Save Settings button and you are ready to use your Amazon S3 bucket .</ li >
</ ul >
</ div >
< div class = " mainwp-rb-tut " number = " 4 " >
< h3 > FTP </ h3 >
< p > When creating a backup or backup task , to use the FTP as a remote backup destination :</ p >
< ul >
< li > Click the Remote Destination button in the " Store Backup in " option </ li >
< li > After choosing Remote Destination for keeping your backups , to use the remote FTP location , click the Add button next to the FTP icon .</ li >
< li > Settings fields will appear , you need to enter following :</ li >
< li >
< ul >
< li > Title </ li >
< li > Server address </ li >
< li > Server port </ li >
< li > Username </ li >
< li > Password </ li >
< li > Remote path </ li >
</ ul >
</ li >
< li > Also you have options to use SSL and Active Mode . When done with settings , use the Test Settings button to check if you have entered correct info . If the success message is returned , click the Save Settings button and you are ready to go .</ li >
</ ul >
</ div >
</ div >
</ div >
< ? php
}
2014-03-19 23:27:26 +07:00
function activate_this_plugin ()
{
$this -> mainwpMainActivated = apply_filters ( 'mainwp-activated-check' , $this -> mainwpMainActivated );
2016-02-02 23:30:54 +07:00
$this -> childEnabled = apply_filters ( 'mainwp-extension-enabled-check' , __FILE__ );
2014-03-19 23:27:26 +07:00
$this -> childKey = $this -> childEnabled [ 'key' ];
2014-10-29 19:11:13 +07:00
if ( function_exists ( " mainwp_current_user_can " ) && ! mainwp_current_user_can ( " extension " , " mainwp-remote-backup-extension " ))
2015-02-18 21:43:28 +01:00
return ;
2014-03-19 23:27:26 +07:00
new MainWPRemoteBackupExtension ();
}
public function getChildKey ()
{
return $this -> childKey ;
}
function mainwp_error_notice ()
{
global $current_screen ;
if ( $current_screen -> parent_base == 'plugins' && $this -> mainwpMainActivated == false )
{
2016-02-02 23:30:54 +07:00
echo '<div class="error"><p>MainWP Remote Backup Extension ' . __ ( 'requires <a href="http://mainwp.com/" target="_blank">MainWP Dashboard Plugin</a> to be activated in order to work. Please install and activate <a href="http://mainwp.com/" target="_blank">MainWP Dashboard Plugin</a> first.' ) . '</p></div>' ;
2014-03-19 23:27:26 +07:00
}
}
2014-12-09 15:05:59 +07:00
public function update_option ( $option_name , $option_value )
2014-03-19 23:27:26 +07:00
{
2014-12-09 15:05:59 +07:00
$success = add_option ( $option_name , $option_value , '' , 'no' );
2014-03-19 23:27:26 +07:00
2014-12-09 15:05:59 +07:00
if ( ! $success )
{
$success = update_option ( $option_name , $option_value );
}
return $success ;
}
public function activate () {
$options = array ( 'product_id' => $this -> product_id ,
'activated_key' => 'Deactivated' ,
'instance_id' => apply_filters ( 'mainwp-extensions-apigeneratepassword' , 12 , false ),
'software_version' => $this -> software_version
);
$this -> update_option ( $this -> plugin_handle . " _APIManAdder " , $options );
}
public function deactivate () {
$this -> update_option ( $this -> plugin_handle . " _APIManAdder " , '' );
}
2014-03-19 23:27:26 +07:00
}
function mainwp_remote_backup_extension_dir ()
{
return WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname ( plugin_basename ( __FILE__ )) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR ;
}
2016-01-25 18:12:46 +01:00
new MainWPRemoteBackupExtensionActivator ();