backup
Last commit date
com
5 years ago
languages
7 years ago
public
5 years ago
BackupGuard.php
5 years ago
README.txt
5 years ago
backup.php
5 years ago
index.php
10 years ago
BackupGuard.php
1082 lines
| 1 | <?php |
| 2 | |
| 3 | // hook to wordpres widget |
| 4 | function backup_guard_register_widget() |
| 5 | { |
| 6 | if (!class_exists('SGWordPressWidget')) { |
| 7 | @include_once(SG_WIDGET_PATH.'SGWordPressWidget.php'); |
| 8 | } |
| 9 | |
| 10 | register_widget('SGWordPressWidget'); |
| 11 | } |
| 12 | add_action('widgets_init', 'backup_guard_register_widget'); |
| 13 | |
| 14 | //The code that runs during plugin activation. |
| 15 | function activate_backup_guard() |
| 16 | { |
| 17 | //check if database should be updated |
| 18 | if (backupGuardShouldUpdate()) { |
| 19 | SGBoot::install(); |
| 20 | SGBoot::didInstallForFirstTime(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | // The code that runs during plugin deactivation. |
| 25 | function uninstall_backup_guard() |
| 26 | { |
| 27 | SGBoot::uninstall(); |
| 28 | } |
| 29 | |
| 30 | function deactivate_backup_guard() |
| 31 | { |
| 32 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 33 | if ($pluginCapabilities != BACKUP_GUARD_CAPABILITIES_FREE) { |
| 34 | require_once(SG_LIB_PATH.'SGAuthClient.php'); |
| 35 | $res = SGAuthClient::getInstance()->logout(); |
| 36 | SGConfig::set('SG_LICENSE_CHECK_TS', 0, true); |
| 37 | SGConfig::set('SG_LOGGED_USER', '', true); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | function backupGuardMaybeShortenEddFilename($return, $package) |
| 42 | { |
| 43 | if (strpos($package, 'backup-guard') !== false) { |
| 44 | add_filter('wp_unique_filename', 'backupGuardShortenEddFilename', 10, 2); |
| 45 | } |
| 46 | return $return; |
| 47 | } |
| 48 | |
| 49 | function backupGuardShortenEddFilename($filename, $ext) |
| 50 | { |
| 51 | $filename = substr($filename, 0, 20).$ext; |
| 52 | remove_filter('wp_unique_filename', 'backupGuardShortenEddFilename', 10); |
| 53 | return $filename; |
| 54 | } |
| 55 | |
| 56 | add_filter('upgrader_pre_download', 'backupGuardMaybeShortenEddFilename', 10, 4); |
| 57 | |
| 58 | register_activation_hook(SG_BACKUP_GUARD_MAIN_FILE, 'activate_backup_guard'); |
| 59 | register_uninstall_hook(SG_BACKUP_GUARD_MAIN_FILE, 'uninstall_backup_guard'); |
| 60 | register_deactivation_hook(SG_BACKUP_GUARD_MAIN_FILE, 'deactivate_backup_guard'); |
| 61 | //add_action('admin_footer', 'before_deactivate_backup_guard'); |
| 62 | |
| 63 | function before_deactivate_backup_guard() |
| 64 | { |
| 65 | wp_enqueue_style('before-deactivate-backup-guard-css', plugin_dir_url(__FILE__).'public/css/deactivationSurvey.css'); |
| 66 | wp_enqueue_script('before-deactivate-backup-guard-js', plugin_dir_url(__FILE__).'public/js/deactivationSurvey.js', array('jquery')); |
| 67 | |
| 68 | wp_localize_script('before-deactivate-backup-guard-js', 'BG_BACKUP_STRINGS_DEACTIVATE', array( |
| 69 | 'nonce' => wp_create_nonce('backupGuardAjaxNonce'), |
| 70 | 'areYouSure' => _backupGuardT('Are you sure?', true), |
| 71 | 'invalidCloud' => _backupGuardT('Please select at least 1 cloud', true) |
| 72 | )); |
| 73 | |
| 74 | require_once(plugin_dir_path(__FILE__).'public/include/uninstallSurveyPopup.php'); |
| 75 | } |
| 76 | |
| 77 | // Register Admin Menus for single and multisite |
| 78 | if (is_multisite()) { |
| 79 | add_action('network_admin_menu', 'backup_guard_admin_menu'); |
| 80 | } |
| 81 | else { |
| 82 | add_action('admin_menu', 'backup_guard_admin_menu'); |
| 83 | } |
| 84 | |
| 85 | function backup_guard_admin_menu() |
| 86 | { |
| 87 | $capability = 'manage_options'; |
| 88 | if (defined('SG_USER_MODE') && SG_USER_MODE) { |
| 89 | $capability = 'read'; |
| 90 | } |
| 91 | |
| 92 | add_menu_page('Backups', 'BackupGuard', $capability, 'backup_guard_backups', 'includeAllPages', 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MzAuMzQgNjYzLjAzIj48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2ZmZjt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPkFydGJvYXJkIDI8L3RpdGxlPjxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTUzMC4xMSwxODUuNzljLTcxLjktOC44Mi0xMzcuNzMtNDAtMTkwLTg2LjU3djkyLjY1YTI4MC41OSwyODAuNTksMCwwLDAsMTE2LjUyLDUyYy05LjE0LDg5LjQzLTUyLDE2OS41NS0xMTYuNTIsMjI4Ljg3djkwLjRDNDU5Ljg0LDQ3Ny4xMyw1MzAuNiwzMzMuNDIsNTMwLjExLDE4NS43OVoiLz48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik0xNzQuMjksMjQ0YTI4MC40NiwyODAuNDYsMCwwLDAsMTE1Ljc3LTUxLjExVjEwMGMtNTIuNDQsNDYuMjgtMTE3LjYyLDc3LTE4OS44Myw4NS4xNUM5OS41NCwzMzMsMTcwLjIyLDQ3Ni44MiwyOTAuMDYsNTYzVjQ3Mi4wOUMyMjYsNDEyLjg2LDE4My40MiwzMzMuMDYsMTc0LjI5LDI0NFoiLz48L3N2Zz4=', 74); |
| 93 | |
| 94 | add_submenu_page('backup_guard_backups', _backupGuardT('Backups', true), _backupGuardT('Backups', true), $capability, 'backup_guard_backups', 'includeAllPages'); |
| 95 | add_submenu_page('backup_guard_backups', _backupGuardT('Cloud', true), _backupGuardT('Cloud', true), $capability, 'backup_guard_cloud', 'includeAllPages'); |
| 96 | add_submenu_page('backup_guard_backups', _backupGuardT('Schedule', true), _backupGuardT('Schedule', true), $capability, 'backup_guard_schedule', 'includeAllPages'); |
| 97 | |
| 98 | add_submenu_page('backup_guard_backups', _backupGuardT('Settings', true), _backupGuardT('Settings', true), $capability, 'backup_guard_settings', 'includeAllPages'); |
| 99 | |
| 100 | add_submenu_page('backup_guard_backups', _backupGuardT('System Info.', true), _backupGuardT('System Info.', true), $capability, 'backup_guard_system_info', 'includeAllPages'); |
| 101 | |
| 102 | add_submenu_page('backup_guard_backups', _backupGuardT('Services', true), _backupGuardT('Services', true), $capability, 'backup_guard_services', 'includeAllPages'); |
| 103 | add_submenu_page('backup_guard_backups', _backupGuardT('Video Tutorials', true), _backupGuardT('Video Tutorials', true), $capability, 'backup_guard_videoTutorials', 'includeAllPages'); |
| 104 | add_submenu_page('backup_guard_backups', _backupGuardT('Support', true), _backupGuardT('Support', true), $capability, 'backup_guard_support', 'includeAllPages'); |
| 105 | |
| 106 | //Check if should show upgrade page |
| 107 | if (SGBoot::isFeatureAvailable('SHOW_UPGRADE_PAGE')) { |
| 108 | add_submenu_page('backup_guard_backups', _backupGuardT('Why upgrade?', true), _backupGuardT('Why upgrade?', true), $capability, 'backup_guard_pro_features', 'includeAllPages'); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | function getBackupPageContentClassName($pageName = '') |
| 113 | { |
| 114 | $hiddenClassName = 'sg-visibility-hidden'; |
| 115 | $page = $_GET['page']; |
| 116 | |
| 117 | if (strpos($page, $pageName)) { |
| 118 | $hiddenClassName = ''; |
| 119 | } |
| 120 | |
| 121 | return $hiddenClassName; |
| 122 | } |
| 123 | |
| 124 | function includeAllPages() |
| 125 | { |
| 126 | if (!backupGuardValidateLicense()) { |
| 127 | return false; |
| 128 | } |
| 129 | backup_guard_backups_page(); |
| 130 | backup_guard_cloud_page(); |
| 131 | backup_guard_system_info_page(); |
| 132 | backup_guard_services_page(); |
| 133 | backup_guard_pro_features_page(); |
| 134 | backup_guard_support_page(); |
| 135 | backup_guard_schedule_page(); |
| 136 | backup_guard_settings_page(); |
| 137 | |
| 138 | require_once(plugin_dir_path(__FILE__).'public/pagesContent.php'); |
| 139 | |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | function backup_guard_system_info_page() |
| 144 | { |
| 145 | if (backupGuardValidateLicense()) { |
| 146 | //require_once(plugin_dir_path(__FILE__).'public/systemInfo.php'); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | function backup_guard_services_page() |
| 151 | { |
| 152 | if (backupGuardValidateLicense()) { |
| 153 | //require_once(plugin_dir_path(__FILE__).'public/services.php'); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | //Pro features page |
| 158 | function backup_guard_pro_features_page() |
| 159 | { |
| 160 | // require_once(plugin_dir_path(__FILE__).'public/proFeatures.php'); |
| 161 | } |
| 162 | |
| 163 | function backup_guard_security_page() |
| 164 | { |
| 165 | require_once(plugin_dir_path(__FILE__).'public/security.php'); |
| 166 | } |
| 167 | |
| 168 | //Support page |
| 169 | function backup_guard_support_page() |
| 170 | { |
| 171 | if (backupGuardValidateLicense()) { |
| 172 | // require_once(plugin_dir_path(__FILE__).'public/support.php'); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | //Backups Page |
| 177 | function backup_guard_backups_page() |
| 178 | { |
| 179 | if (backupGuardValidateLicense()) { |
| 180 | wp_enqueue_script('backup-guard-iframe-transport-js', plugin_dir_url(__FILE__).'public/js/jquery.iframe-transport.js', array('jquery')); |
| 181 | wp_enqueue_script('backup-guard-fileupload-js', plugin_dir_url(__FILE__).'public/js/jquery.fileupload.js', array('jquery')); |
| 182 | wp_enqueue_script('backup-guard-jstree-js', plugin_dir_url(__FILE__).'public/js/jstree.min.js', array('jquery')); |
| 183 | wp_enqueue_script('backup-guard-jstree-checkbox-js', plugin_dir_url(__FILE__).'public/js/jstree.checkbox.js', array('jquery')); |
| 184 | wp_enqueue_script('backup-guard-jstree-wholerow-js', plugin_dir_url(__FILE__).'public/js/jstree.wholerow.js', array('jquery')); |
| 185 | wp_enqueue_script('backup-guard-jstree-types-js', plugin_dir_url(__FILE__).'public/js/jstree.types.js', array('jquery')); |
| 186 | wp_enqueue_style('backup-guard-jstree-css', plugin_dir_url(__FILE__).'public/css/default/style.min.css'); |
| 187 | wp_enqueue_script('backup-guard-backups-js', plugin_dir_url(__FILE__).'public/js/sgbackup.js', array('jquery', 'jquery-effects-core', 'jquery-effects-transfer', 'jquery-ui-widget')); |
| 188 | |
| 189 | // Localize the script with new data |
| 190 | wp_localize_script('backup-guard-backups-js', 'BG_BACKUP_STRINGS', array( |
| 191 | 'confirm' => _backupGuardT('Are you sure you want to cancel import?', true), |
| 192 | 'nonce' => wp_create_nonce('backupGuardAjaxNonce'), |
| 193 | 'invalidBackupOption' => _backupGuardT('Please choose at least one option.', true), |
| 194 | 'invalidDirectorySelected' => _backupGuardT('Please choose at least one directory.', true), |
| 195 | 'invalidCloud' => _backupGuardT('Please choose at least one cloud.', true), |
| 196 | 'backupInProgress' => _backupGuardT('Backing Up...', true), |
| 197 | 'errorMessage' => _backupGuardT('Something went wrong. Please try again.', true), |
| 198 | 'noBackupsAvailable' => _backupGuardT('No backups found.', true), |
| 199 | 'invalidImportOption' => _backupGuardT('Please select one of the options.', true), |
| 200 | 'invalidDownloadFile' => _backupGuardT('Please choose one of the files.', true), |
| 201 | 'import' => _backupGuardT('Import', true), |
| 202 | 'importInProgress' => _backupGuardT('Importing please wait...', true), |
| 203 | 'fileUploadFailed' => _backupGuardT('File upload failed.', true) |
| 204 | )); |
| 205 | |
| 206 | // require_once(plugin_dir_path( __FILE__ ).'public/backups.php'); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | //Cloud Page |
| 211 | function backup_guard_cloud_page() |
| 212 | { |
| 213 | if (backupGuardValidateLicense()) { |
| 214 | wp_enqueue_style('backup-guard-switch-css', plugin_dir_url(__FILE__).'public/css/bootstrap-switch.min.css'); |
| 215 | wp_enqueue_script('backup-guard-switch-js', plugin_dir_url(__FILE__).'public/js/bootstrap-switch.min.js', array('jquery'), SG_BACKUP_GUARD_VERSION, true); |
| 216 | wp_enqueue_script('backup-guard-jquery-validate-js', plugin_dir_url(__FILE__).'public/js/jquery.validate.min.js', array('jquery', 'backup-guard-switch-js'), SG_BACKUP_GUARD_VERSION, true); |
| 217 | wp_enqueue_script('backup-guard-cloud-js', plugin_dir_url(__FILE__).'public/js/sgcloud.js', array('jquery', 'backup-guard-switch-js'), SG_BACKUP_GUARD_VERSION, true); |
| 218 | |
| 219 | // Localize the script with new data |
| 220 | wp_localize_script('backup-guard-cloud-js', 'BG_CLOUD_STRINGS', array( |
| 221 | 'invalidImportFile' => _backupGuardT('Please select a file.', true), |
| 222 | 'invalidFileSize' => _backupGuardT('File is too large.', true), |
| 223 | 'connectionInProgress' => _backupGuardT('Connecting...', true), |
| 224 | 'invalidDestinationFolder' => _backupGuardT('Destination folder is required.', true), |
| 225 | 'successMessage' => _backupGuardT('Successfully saved.', true) |
| 226 | )); |
| 227 | |
| 228 | //require_once(plugin_dir_path(__FILE__).'public/cloud.php'); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | //Schedule Page |
| 233 | function backup_guard_schedule_page() |
| 234 | { |
| 235 | if (backupGuardValidateLicense()) { |
| 236 | wp_enqueue_style('backup-guard-switch-css', plugin_dir_url(__FILE__).'public/css/bootstrap-switch.min.css'); |
| 237 | wp_enqueue_script('backup-guard-switch-js', plugin_dir_url(__FILE__).'public/js/bootstrap-switch.min.js', array('jquery'), '1.0.0', true); |
| 238 | wp_enqueue_script('backup-guard-schedule-js', plugin_dir_url(__FILE__).'public/js/sgschedule.js', array('jquery'), '1.0.0', true); |
| 239 | |
| 240 | // Localize the script with new data |
| 241 | wp_localize_script('backup-guard-schedule-js', 'BG_SCHEDULE_STRINGS', array( |
| 242 | 'deletionError' => _backupGuardT('Unable to delete schedule', true), |
| 243 | 'confirm' => _backupGuardT('Are you sure?', true), |
| 244 | 'invalidBackupOption' => _backupGuardT('Please choose at least one option.', true), |
| 245 | 'invalidDirectorySelected' => _backupGuardT('Please choose at least one directory.', true), |
| 246 | 'invalidCloud' => _backupGuardT('Please choose at least one cloud.', true), |
| 247 | 'savingInProgress' => _backupGuardT('Saving...', true), |
| 248 | 'successMessage' => _backupGuardT('You have successfully activated schedule.', true), |
| 249 | 'saveButtonText' => _backupGuardT('Save', true) |
| 250 | )); |
| 251 | |
| 252 | // require_once(plugin_dir_path( __FILE__ ).'public/schedule.php'); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | //Settings Page |
| 257 | function backup_guard_settings_page() |
| 258 | { |
| 259 | if (backupGuardValidateLicense()) { |
| 260 | wp_enqueue_style('backup-guard-switch-css', plugin_dir_url(__FILE__).'public/css/bootstrap-switch.min.css'); |
| 261 | wp_enqueue_script('backup-guard-switch-js', plugin_dir_url(__FILE__).'public/js/bootstrap-switch.min.js', array('jquery'), '1.0.0', true); |
| 262 | wp_enqueue_script('backup-guard-settings-js', plugin_dir_url(__FILE__).'public/js/sgsettings.js', array('jquery'), '1.0.0', true ); |
| 263 | |
| 264 | // Localize the script with new data |
| 265 | wp_localize_script('backup-guard-settings-js', 'BG_SETTINGS_STRINGS', array( |
| 266 | 'invalidEmailAddress' => _backupGuardT('Please enter valid email.', true), |
| 267 | 'invalidFileName' => _backupGuardT('Please enter valid file name.', true), |
| 268 | 'invalidRetentionNumber' => _backupGuardT('Please enter a valid retention number.', true), |
| 269 | 'successMessage' => _backupGuardT('Successfully saved.', true), |
| 270 | 'savingInProgress' => _backupGuardT('Saving...', true), |
| 271 | 'retentionConfirmationFirstPart' => _backupGuardT('Are you sure you want to keep the latest', true), |
| 272 | 'retentionConfirmationSecondPart' => _backupGuardT('backups? All older backups will be deleted.', true), |
| 273 | 'saveButtonText' => _backupGuardT('Save', true) |
| 274 | )); |
| 275 | |
| 276 | //require_once(plugin_dir_path(__FILE__).'public/settings.php'); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | function backup_guard_login_page() |
| 281 | { |
| 282 | wp_enqueue_script('backup-guard-login-js', plugin_dir_url(__FILE__).'public/js/sglogin.js', array('jquery'), '1.0.0', true); |
| 283 | |
| 284 | require_once(plugin_dir_path(__FILE__).'public/login.php'); |
| 285 | } |
| 286 | |
| 287 | function backup_guard_link_license_page() |
| 288 | { |
| 289 | wp_enqueue_script('backup-guard-license-js', plugin_dir_url(__FILE__).'public/js/sglicense.js', array('jquery'), '1.0.0', true); |
| 290 | // Localize the script with new data |
| 291 | wp_localize_script('backup-guard-license-js', 'BG_LICENSE_STRINGS', array( |
| 292 | 'invalidLicense' => _backupGuardT('Please choose a license first', true), |
| 293 | 'availableLicenses' => _backupGuardT('There are no available licenses for using the selected product', true) |
| 294 | )); |
| 295 | |
| 296 | require_once(plugin_dir_path(__FILE__).'public/link_license.php'); |
| 297 | } |
| 298 | |
| 299 | add_action('admin_enqueue_scripts', 'enqueue_backup_guard_scripts'); |
| 300 | function enqueue_backup_guard_scripts($hook) |
| 301 | { |
| 302 | wp_enqueue_script('backup-guard-discount-notice', plugin_dir_url(__FILE__).'public/js/sgNoticeDismiss.js', array('jquery'), '1.0', true); |
| 303 | |
| 304 | if (!strpos($hook,'backup_guard')) { |
| 305 | if($hook == "index.php"){ |
| 306 | wp_enqueue_script('backup-guard-chart-manager', plugin_dir_url(__FILE__).'public/js/Chart.bundle.min.js'); |
| 307 | } |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | wp_enqueue_style('backup-guard-spinner', plugin_dir_url(__FILE__).'public/css/spinner.css'); |
| 312 | wp_enqueue_style('backup-guard-wordpress', plugin_dir_url(__FILE__).'public/css/bgstyle.wordpress.css'); |
| 313 | wp_enqueue_style('backup-guard-less', plugin_dir_url(__FILE__).'public/css/bgstyle.less.css'); |
| 314 | wp_enqueue_style('backup-guard-styles', plugin_dir_url(__FILE__).'public/css/styles.css'); |
| 315 | |
| 316 | echo '<script type="text/javascript">sgBackup={};'; |
| 317 | $sgAjaxRequestFrequency = SGConfig::get('SG_AJAX_REQUEST_FREQUENCY'); |
| 318 | if (!$sgAjaxRequestFrequency) { |
| 319 | $sgAjaxRequestFrequency = SG_AJAX_DEFAULT_REQUEST_FREQUENCY; |
| 320 | } |
| 321 | echo 'SG_AJAX_REQUEST_FREQUENCY = "'.$sgAjaxRequestFrequency.'";'; |
| 322 | echo 'function getAjaxUrl(url) {'. |
| 323 | 'if (url==="cloudDropbox" || url==="cloudGdrive" || url==="cloudOneDrive") return "'.admin_url('admin-post.php?action=backup_guard_').'"+url+"&token='.wp_create_nonce('backupGuardAjaxNonce').'";'. |
| 324 | 'return "'.admin_url('admin-ajax.php').'";}</script>'; |
| 325 | |
| 326 | wp_enqueue_media(); |
| 327 | wp_enqueue_script('backup-guard-less-framework', plugin_dir_url(__FILE__).'public/js/less.min.js', array('jquery'), '1.0.0', true); |
| 328 | wp_enqueue_script('backup-guard-bootstrap-framework', plugin_dir_url(__FILE__).'public/js/bootstrap.min.js', array('jquery'), '1.0.0', true); |
| 329 | wp_enqueue_script('backup-guard-sgrequest-js', plugin_dir_url(__FILE__).'public/js/sgrequesthandler.js', array('jquery'), '1.0.0', true); |
| 330 | wp_enqueue_script('backup-guard-sgwprequest-js', plugin_dir_url(__FILE__).'public/js/sgrequesthandler.wordpress.js', array('jquery'), '1.0.0', true); |
| 331 | |
| 332 | wp_enqueue_style('backup-guard-rateyo-css', plugin_dir_url(__FILE__).'public/css/jquery.rateyo.css'); |
| 333 | wp_enqueue_script('backup-guard-rateyo-js', plugin_dir_url(__FILE__).'public/js/jquery.rateyo.js'); |
| 334 | |
| 335 | wp_enqueue_script('backup-guard-main-js', plugin_dir_url(__FILE__).'public/js/main.js', array('jquery'), '1.0.0', true); |
| 336 | wp_enqueue_script('backup-popup.js', plugin_dir_url(__FILE__).'public/js/popup.js', array('jquery'), '1.0.0', true); |
| 337 | wp_enqueue_style('popupTheme.css', plugin_dir_url(__FILE__).'public/css/popupTheme.css'); |
| 338 | |
| 339 | // Localize the script with new data |
| 340 | wp_localize_script('backup-guard-main-js', 'BG_MAIN_STRINGS', array( |
| 341 | 'confirmCancel' => _backupGuardT('Are you sure you want to cancel?', true) |
| 342 | )); |
| 343 | |
| 344 | wp_localize_script('backup-guard-main-js', 'BG_BACKUP_STRINGS', array( |
| 345 | 'nonce' => wp_create_nonce('backupGuardAjaxNonce') |
| 346 | )); |
| 347 | } |
| 348 | |
| 349 | // adding actions to handle modal ajax requests |
| 350 | add_action( 'wp_ajax_backup_guard_modalManualBackup', 'backup_guard_get_manual_modal'); |
| 351 | add_action( 'wp_ajax_backup_guard_modalManualRestore', 'backup_guard_get_manual_restore_modal'); |
| 352 | add_action( 'wp_ajax_backup_guard_modalImport', 'backup_guard_get_import_modal'); |
| 353 | add_action( 'wp_ajax_backup_guard_modalFtpSettings', 'backup_guard_get_ftp_modal'); |
| 354 | add_action( 'wp_ajax_backup_guard_modalAmazonSettings', 'backup_guard_get_amazon_modal'); |
| 355 | add_action( 'wp_ajax_backup_guard_modalPrivacy', 'backup_guard_get_privacy_modal'); |
| 356 | add_action( 'wp_ajax_backup_guard_modalTerms', 'backup_guard_get_terms_modal'); |
| 357 | add_action( 'wp_ajax_backup_guard_modalReview', 'backup_guard_get_review_modal'); |
| 358 | add_action( 'wp_ajax_backup_guard_getFileDownloadProgress', 'backup_guard_get_file_download_progress'); |
| 359 | add_action( 'wp_ajax_backup_guard_modalCreateSchedule', 'backup_guard_create_schedule'); |
| 360 | add_action( 'wp_ajax_backup_guard_getBackupContent', 'backup_guard_get_backup_content'); |
| 361 | |
| 362 | add_action( 'wp_ajax_backup_guard_modalBackupGuardDetails', 'backup_guard_get_backup_guard_modal'); |
| 363 | |
| 364 | function backup_guard_get_backup_guard_modal() |
| 365 | { |
| 366 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 367 | require_once(SG_PUBLIC_AJAX_PATH.'modalBackupGuardDetails.php'); |
| 368 | exit(); |
| 369 | } |
| 370 | |
| 371 | function backup_guard_get_file_download_progress() |
| 372 | { |
| 373 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 374 | require_once(SG_PUBLIC_AJAX_PATH.'getFileDownloadProgress.php'); |
| 375 | exit(); |
| 376 | } |
| 377 | |
| 378 | function backup_guard_create_schedule() |
| 379 | { |
| 380 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 381 | require_once(SG_PUBLIC_AJAX_PATH.'modalCreateSchedule.php'); |
| 382 | exit(); |
| 383 | } |
| 384 | |
| 385 | function backup_guard_get_manual_modal() |
| 386 | { |
| 387 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 388 | if (current_user_can( 'activate_plugins' ) || (defined('SG_USER_MODE') && SG_USER_MODE)) { |
| 389 | require_once(SG_PUBLIC_AJAX_PATH.'modalManualBackup.php'); |
| 390 | } |
| 391 | exit(); |
| 392 | } |
| 393 | |
| 394 | function backup_guard_get_manual_restore_modal() |
| 395 | { |
| 396 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 397 | require_once(SG_PUBLIC_AJAX_PATH.'modalManualRestore.php'); |
| 398 | exit(); |
| 399 | } |
| 400 | |
| 401 | function backup_guard_get_backup_content() |
| 402 | { |
| 403 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 404 | require_once (SG_PUBLIC_AJAX_PATH.'getBackupContent.php'); |
| 405 | exit(); |
| 406 | } |
| 407 | |
| 408 | function backup_guard_get_import_modal() |
| 409 | { |
| 410 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 411 | require_once(SG_PUBLIC_AJAX_PATH.'modalImport.php'); |
| 412 | exit(); |
| 413 | } |
| 414 | |
| 415 | function backup_guard_get_ftp_modal() |
| 416 | { |
| 417 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 418 | require_once(SG_PUBLIC_AJAX_PATH.'modalFtpSettings.php'); |
| 419 | exit(); |
| 420 | } |
| 421 | |
| 422 | function backup_guard_get_amazon_modal() |
| 423 | { |
| 424 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 425 | require_once(SG_PUBLIC_AJAX_PATH.'modalAmazonSettings.php'); |
| 426 | exit(); |
| 427 | } |
| 428 | |
| 429 | function backup_guard_get_privacy_modal() |
| 430 | { |
| 431 | require_once(SG_PUBLIC_AJAX_PATH.'modalPrivacy.php'); |
| 432 | } |
| 433 | |
| 434 | function backup_guard_get_terms_modal() |
| 435 | { |
| 436 | require_once(SG_PUBLIC_AJAX_PATH.'modalTerms.php'); |
| 437 | exit(); |
| 438 | } |
| 439 | |
| 440 | function backup_guard_get_review_modal() |
| 441 | { |
| 442 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 443 | require_once(SG_PUBLIC_AJAX_PATH.'modalReview.php'); |
| 444 | exit(); |
| 445 | } |
| 446 | |
| 447 | function backup_guard_register_ajax_callbacks() |
| 448 | { |
| 449 | if (is_super_admin() || (defined('SG_USER_MODE') && SG_USER_MODE)) { |
| 450 | // adding actions to handle ajax and post requests |
| 451 | add_action('wp_ajax_backup_guard_cancelBackup', 'backup_guard_cancel_backup'); |
| 452 | add_action('wp_ajax_backup_guard_checkBackupCreation', 'backup_guard_check_backup_creation'); |
| 453 | add_action('wp_ajax_backup_guard_checkRestoreCreation', 'backup_guard_check_restore_creation'); |
| 454 | add_action('wp_ajax_backup_guard_cloudDropbox', 'backup_guard_cloud_dropbox'); |
| 455 | add_action('wp_ajax_backup_guard_send_usage_status', 'backup_guard_send_usage_status'); |
| 456 | |
| 457 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 458 | if ($pluginCapabilities != BACKUP_GUARD_CAPABILITIES_FREE) { |
| 459 | require_once dirname(__FILE__).'/BackupGuardPro.php'; |
| 460 | } |
| 461 | add_action('wp_ajax_backup_guard_curlChecker', 'backup_guard_curl_checker'); |
| 462 | add_action('wp_ajax_backup_guard_deleteBackup', 'backup_guard_delete_backup'); |
| 463 | add_action('wp_ajax_backup_guard_getAction', 'backup_guard_get_action'); |
| 464 | add_action('wp_ajax_backup_guard_getRunningActions', 'backup_guard_get_running_actions'); |
| 465 | add_action('wp_ajax_backup_guard_importBackup', 'backup_guard_get_import_backup'); |
| 466 | add_action('wp_ajax_backup_guard_resetStatus', 'backup_guard_reset_status'); |
| 467 | add_action('wp_ajax_backup_guard_restore', 'backup_guard_restore'); |
| 468 | add_action('wp_ajax_backup_guard_saveCloudFolder', 'backup_guard_save_cloud_folder'); |
| 469 | add_action('wp_ajax_backup_guard_schedule', 'backup_guard_schedule'); |
| 470 | add_action('wp_ajax_backup_guard_settings', 'backup_guard_settings'); |
| 471 | add_action('wp_ajax_backup_guard_setReviewPopupState', 'backup_guard_set_review_popup_state'); |
| 472 | add_action('wp_ajax_backup_guard_sendUsageStatistics', 'backup_guard_send_usage_statistics'); |
| 473 | add_action('wp_ajax_backup_guard_hideNotice', 'backup_guard_hide_notice'); |
| 474 | add_action('wp_ajax_backup_guard_downloadFromCloud', 'backup_guard_download_from_cloud'); |
| 475 | add_action('wp_ajax_backup_guard_listStorage', 'backup_guard_list_storage'); |
| 476 | add_action('wp_ajax_backup_guard_cancelDownload', 'backup_guard_cancel_download'); |
| 477 | add_action('wp_ajax_backup_guard_awake', 'backup_guard_awake'); |
| 478 | add_action('wp_ajax_backup_guard_manualBackup', 'backup_guard_manual_backup'); |
| 479 | add_action('admin_post_backup_guard_downloadBackup', 'backup_guard_download_backup'); |
| 480 | add_action('wp_ajax_backup_guard_login', 'backup_guard_login'); |
| 481 | add_action('wp_ajax_backup_guard_logout', 'backup_guard_logout'); |
| 482 | add_action('wp_ajax_backup_guard_link_license', 'backup_guard_link_license'); |
| 483 | add_action('wp_ajax_backup_guard_importKeyFile', 'backup_guard_import_key_file'); |
| 484 | add_action('wp_ajax_backup_guard_isFeatureAvailable', 'backup_guard_is_feature_available'); |
| 485 | add_action('wp_ajax_backup_guard_dismiss_discount_notice', 'backup_guard_dismiss_discount_notice'); |
| 486 | add_action('wp_ajax_backup_guard_checkFreeMigration', 'backup_guard_check_free_migration'); |
| 487 | add_action('wp_ajax_backup_guard_checkPHPVersionCompatibility', 'backup_guard_check_php_version_compatibility'); |
| 488 | add_action('wp_ajax_backup_guard_setUserInfoVerificationPopupState', 'backup_guard_set_user_info_verification_popup_state'); |
| 489 | add_action('wp_ajax_backup_guard_storeSubscriberInfo', 'backup_guard_store_subscriber_info'); |
| 490 | add_action('wp_ajax_backup_guard_storeSurveyResult', 'backup_guard_store_survey_result'); |
| 491 | add_action('wp_ajax_backup_guard_reviewDontShow', 'backup_guard_review_dont_show'); |
| 492 | add_action('wp_ajax_backup_guard_review_later', 'backup_guard_review_later'); |
| 493 | add_action('wp_ajax_backup_guard_closeFreeBanner', 'wp_ajax_backup_guard_close_free_banner'); |
| 494 | // related to cloud |
| 495 | add_action('wp_ajax_backup_guard_isBgUserExists', 'backup_guard_is_bg_user_exists'); |
| 496 | add_action('wp_ajax_backup_guard_createCloudUser', 'backup_guard_create_cloud_user'); |
| 497 | add_action('wp_ajax_backup_guard_bgAutoLogin', 'backup_guard_bg_auto_login'); |
| 498 | add_action('wp_ajax_backup_guard_bgLogin', 'backup_guard_bg_login'); |
| 499 | add_action('wp_ajax_backup_guard_chooseProfile', 'backup_guard_choose_profile'); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | function wp_ajax_backup_guard_close_free_banner() |
| 504 | { |
| 505 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 506 | SGConfig::set('SG_CLOSE_FREE_BANNER', 1); |
| 507 | wp_die(); |
| 508 | } |
| 509 | |
| 510 | function backup_guard_review_dont_show() |
| 511 | { |
| 512 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 513 | SGConfig::set('closeReviewBanner', 1); |
| 514 | wp_die(); |
| 515 | } |
| 516 | |
| 517 | function backup_guard_review_later() |
| 518 | { |
| 519 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 520 | require_once(SG_PUBLIC_AJAX_PATH.'reviewBannerActions.php'); |
| 521 | wp_die(); |
| 522 | } |
| 523 | |
| 524 | function backup_guard_choose_profile() |
| 525 | { |
| 526 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 527 | require_once(SG_PUBLIC_AJAX_PATH.'chooseProfile.php'); |
| 528 | } |
| 529 | |
| 530 | function backup_guard_bg_login() |
| 531 | { |
| 532 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 533 | require_once(SG_PUBLIC_AJAX_PATH.'bgLogin.php'); |
| 534 | } |
| 535 | |
| 536 | function backup_guard_bg_auto_login() |
| 537 | { |
| 538 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 539 | require_once(SG_PUBLIC_AJAX_PATH.'bgAutoLogin.php'); |
| 540 | } |
| 541 | |
| 542 | function backup_guard_create_cloud_user() |
| 543 | { |
| 544 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 545 | require_once(SG_PUBLIC_AJAX_PATH.'createCloudUser.php'); |
| 546 | } |
| 547 | |
| 548 | function backup_guard_is_bg_user_exists() |
| 549 | { |
| 550 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 551 | require_once(SG_PUBLIC_AJAX_PATH.'isBgUserExists.php'); |
| 552 | } |
| 553 | |
| 554 | function backup_guard_store_survey_result() |
| 555 | { |
| 556 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 557 | require_once(SG_PUBLIC_AJAX_PATH.'storeSurveyResult.php'); |
| 558 | } |
| 559 | |
| 560 | function backup_guard_store_subscriber_info() |
| 561 | { |
| 562 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 563 | require_once(SG_PUBLIC_AJAX_PATH.'storeSubscriberInfo.php'); |
| 564 | } |
| 565 | |
| 566 | function backup_guard_set_user_info_verification_popup_state() |
| 567 | { |
| 568 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 569 | require_once(SG_PUBLIC_AJAX_PATH.'setUserInfoVerificationPopupState.php'); |
| 570 | } |
| 571 | |
| 572 | function backup_guard_dismiss_discount_notice() |
| 573 | { |
| 574 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 575 | require_once(SG_PUBLIC_AJAX_PATH.'dismissDiscountNotice.php'); |
| 576 | } |
| 577 | |
| 578 | function backup_guard_is_feature_available() |
| 579 | { |
| 580 | require_once(SG_PUBLIC_AJAX_PATH.'isFeatureAvailable.php'); |
| 581 | } |
| 582 | |
| 583 | function backup_guard_check_free_migration() |
| 584 | { |
| 585 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 586 | require_once(SG_PUBLIC_AJAX_PATH.'checkFreeMigration.php'); |
| 587 | die; |
| 588 | } |
| 589 | |
| 590 | function backup_guard_check_php_version_compatibility() |
| 591 | { |
| 592 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 593 | require_once(SG_PUBLIC_AJAX_PATH.'checkPHPVersionCompatibility.php'); |
| 594 | } |
| 595 | |
| 596 | add_action('init', 'backup_guard_init'); |
| 597 | add_action('wp_ajax_nopriv_backup_guard_awake', 'backup_guard_awake_nopriv'); |
| 598 | add_action('admin_post_backup_guard_cloudDropbox', 'backup_guard_cloud_dropbox'); |
| 599 | |
| 600 | function backup_guard_import_key_file() |
| 601 | { |
| 602 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 603 | require_once(SG_PUBLIC_AJAX_PATH.'importKeyFile.php'); |
| 604 | } |
| 605 | |
| 606 | function backup_guard_awake() |
| 607 | { |
| 608 | $method = SG_RELOAD_METHOD_AJAX; |
| 609 | require_once(SG_PUBLIC_AJAX_PATH.'awake.php'); |
| 610 | } |
| 611 | |
| 612 | function backup_guard_awake_nopriv() |
| 613 | { |
| 614 | $token = @$_GET['token']; |
| 615 | $method = @$_GET['method']; |
| 616 | |
| 617 | if (backupGuardValidateApiCall($token)) { |
| 618 | require_once(SG_PUBLIC_AJAX_PATH.'awake.php'); |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | function backup_guard_cancel_download() |
| 623 | { |
| 624 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 625 | require_once(SG_PUBLIC_AJAX_PATH.'cancelDownload.php'); |
| 626 | } |
| 627 | |
| 628 | function backup_guard_list_storage() |
| 629 | { |
| 630 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 631 | require_once(SG_PUBLIC_AJAX_PATH.'listStorage.php'); |
| 632 | } |
| 633 | |
| 634 | function backup_guard_download_from_cloud() |
| 635 | { |
| 636 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 637 | require_once(SG_PUBLIC_AJAX_PATH.'downloadFromCloud.php'); |
| 638 | } |
| 639 | |
| 640 | function backup_guard_hide_notice() |
| 641 | { |
| 642 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 643 | require_once(SG_PUBLIC_AJAX_PATH.'hideNotice.php'); |
| 644 | } |
| 645 | |
| 646 | function backup_guard_cancel_backup() |
| 647 | { |
| 648 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 649 | require_once(SG_PUBLIC_AJAX_PATH.'cancelBackup.php'); |
| 650 | } |
| 651 | |
| 652 | function backup_guard_check_backup_creation() |
| 653 | { |
| 654 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 655 | require_once(SG_PUBLIC_AJAX_PATH.'checkBackupCreation.php'); |
| 656 | } |
| 657 | |
| 658 | function backup_guard_check_restore_creation() |
| 659 | { |
| 660 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 661 | require_once(SG_PUBLIC_AJAX_PATH.'checkRestoreCreation.php'); |
| 662 | } |
| 663 | |
| 664 | function backup_guard_cloud_dropbox() |
| 665 | { |
| 666 | if (current_user_can('activate_plugins') || (defined('SG_USER_MODE') && SG_USER_MODE)) { |
| 667 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 668 | require_once(SG_PUBLIC_AJAX_PATH . 'cloudDropbox.php'); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | function backup_guard_send_usage_status() |
| 673 | { |
| 674 | |
| 675 | if (current_user_can('activate_plugins') || (defined('SG_USER_MODE') && SG_USER_MODE)) { |
| 676 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 677 | require_once(SG_PUBLIC_AJAX_PATH . 'sendUsageStatus.php'); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | function backup_guard_curl_checker() |
| 682 | { |
| 683 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 684 | require_once(SG_PUBLIC_AJAX_PATH.'curlChecker.php'); |
| 685 | } |
| 686 | |
| 687 | function backup_guard_delete_backup() |
| 688 | { |
| 689 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 690 | require_once(SG_PUBLIC_AJAX_PATH.'deleteBackup.php'); |
| 691 | } |
| 692 | |
| 693 | function backup_guard_download_backup() |
| 694 | { |
| 695 | require_once(SG_PUBLIC_AJAX_PATH.'downloadBackup.php'); |
| 696 | } |
| 697 | |
| 698 | function backup_guard_get_action() |
| 699 | { |
| 700 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 701 | require_once(SG_PUBLIC_AJAX_PATH.'getAction.php'); |
| 702 | } |
| 703 | |
| 704 | function backup_guard_get_running_actions() |
| 705 | { |
| 706 | require_once(SG_PUBLIC_AJAX_PATH.'getRunningActions.php'); |
| 707 | } |
| 708 | |
| 709 | function backup_guard_get_import_backup() |
| 710 | { |
| 711 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 712 | require_once(SG_PUBLIC_AJAX_PATH.'importBackup.php'); |
| 713 | } |
| 714 | |
| 715 | function backup_guard_manual_backup() |
| 716 | { |
| 717 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 718 | require_once(SG_PUBLIC_AJAX_PATH.'manualBackup.php'); |
| 719 | } |
| 720 | |
| 721 | function backup_guard_reset_status() |
| 722 | { |
| 723 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 724 | require_once(SG_PUBLIC_AJAX_PATH.'resetStatus.php'); |
| 725 | } |
| 726 | |
| 727 | function backup_guard_restore() |
| 728 | { |
| 729 | require_once(SG_PUBLIC_AJAX_PATH.'restore.php'); |
| 730 | } |
| 731 | |
| 732 | function backup_guard_save_cloud_folder() |
| 733 | { |
| 734 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 735 | require_once(SG_PUBLIC_AJAX_PATH.'saveCloudFolder.php'); |
| 736 | } |
| 737 | |
| 738 | function backup_guard_schedule() |
| 739 | { |
| 740 | require_once(SG_PUBLIC_AJAX_PATH.'schedule.php'); |
| 741 | } |
| 742 | |
| 743 | function backup_guard_settings() |
| 744 | { |
| 745 | require_once(SG_PUBLIC_AJAX_PATH.'settings.php'); |
| 746 | } |
| 747 | |
| 748 | function backup_guard_set_review_popup_state() |
| 749 | { |
| 750 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 751 | require_once(SG_PUBLIC_AJAX_PATH.'setReviewPopupState.php'); |
| 752 | } |
| 753 | |
| 754 | function backup_guard_send_usage_statistics() |
| 755 | { |
| 756 | require_once(SG_PUBLIC_AJAX_PATH.'sendUsageStatistics.php'); |
| 757 | } |
| 758 | |
| 759 | function backup_guard_login() |
| 760 | { |
| 761 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 762 | require_once(SG_PUBLIC_AJAX_PATH.'login.php'); |
| 763 | } |
| 764 | |
| 765 | function backup_guard_logout() |
| 766 | { |
| 767 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 768 | require_once(SG_PUBLIC_AJAX_PATH.'logout.php'); |
| 769 | } |
| 770 | |
| 771 | function backup_guard_link_license() |
| 772 | { |
| 773 | check_ajax_referer('backupGuardAjaxNonce', 'token'); |
| 774 | require_once(SG_PUBLIC_AJAX_PATH.'linkLicense.php'); |
| 775 | } |
| 776 | |
| 777 | //adds once weekly to the existing schedules. |
| 778 | add_filter('cron_schedules', 'backup_guard_cron_add_weekly'); |
| 779 | function backup_guard_cron_add_weekly($schedules) |
| 780 | { |
| 781 | $schedules['weekly'] = array( |
| 782 | 'interval' => 60*60*24*7, |
| 783 | 'display' => 'Once weekly' |
| 784 | ); |
| 785 | return $schedules; |
| 786 | } |
| 787 | |
| 788 | //adds once monthly to the existing schedules. |
| 789 | add_filter('cron_schedules', 'backup_guard_cron_add_monthly'); |
| 790 | function backup_guard_cron_add_monthly($schedules) |
| 791 | { |
| 792 | $schedules['monthly'] = array( |
| 793 | 'interval' => 60*60*24*30, |
| 794 | 'display' => 'Once monthly' |
| 795 | ); |
| 796 | return $schedules; |
| 797 | } |
| 798 | |
| 799 | //adds once yearly to the existing schedules. |
| 800 | add_filter('cron_schedules', 'backup_guard_cron_add_yearly'); |
| 801 | function backup_guard_cron_add_yearly($schedules) |
| 802 | { |
| 803 | $schedules['yearly'] = array( |
| 804 | 'interval' => 60*60*24*30*12, |
| 805 | 'display' => 'Once yearly' |
| 806 | ); |
| 807 | return $schedules; |
| 808 | } |
| 809 | |
| 810 | function backup_guard_init() |
| 811 | { |
| 812 | backup_guard_register_ajax_callbacks(); |
| 813 | // backupGuardPluginRedirect(); |
| 814 | |
| 815 | //check if database should be updated |
| 816 | if (backupGuardShouldUpdate()) { |
| 817 | SGBoot::install(); |
| 818 | } |
| 819 | |
| 820 | backupGuardSymlinksCleanup(SG_SYMLINK_PATH); |
| 821 | } |
| 822 | |
| 823 | add_action(SG_SCHEDULE_ACTION, 'backup_guard_schedule_action', 10, 1); |
| 824 | |
| 825 | function backup_guard_schedule_action($id) |
| 826 | { |
| 827 | require_once(SG_PUBLIC_PATH.'cron/sg_backup.php'); |
| 828 | } |
| 829 | |
| 830 | function sgBackupAdminInit() { |
| 831 | //load pro plugin updater |
| 832 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 833 | $isLoggedIn = is_user_logged_in(); |
| 834 | |
| 835 | if ($pluginCapabilities != BACKUP_GUARD_CAPABILITIES_FREE && $isLoggedIn) { |
| 836 | require_once(dirname(__FILE__).'/plugin-update-checker/plugin-update-checker.php'); |
| 837 | require_once(dirname(__FILE__).'/plugin-update-checker/Puc/v4/Utils.php'); |
| 838 | require_once(dirname(__FILE__).'/plugin-update-checker/Puc/v4/UpdateChecker.php'); |
| 839 | require_once(dirname(__FILE__).'/plugin-update-checker/Puc/v4/Scheduler.php'); |
| 840 | require_once(SG_LIB_PATH.'SGAuthClient.php'); |
| 841 | |
| 842 | $licenseKey = SGConfig::get('SG_LICENSE_KEY'); |
| 843 | |
| 844 | $updateChecker = Puc_v4_Factory::buildUpdateChecker( |
| 845 | BackupGuard\Config::URL.'/products/details/'.$licenseKey, |
| 846 | SG_BACKUP_GUARD_MAIN_FILE, |
| 847 | SG_PRODUCT_IDENTIFIER |
| 848 | ); |
| 849 | |
| 850 | $updateChecker->addHttpRequestArgFilter(array( |
| 851 | SGAuthClient::getInstance(), |
| 852 | 'filterUpdateChecks' |
| 853 | )); |
| 854 | } |
| 855 | |
| 856 | require_once(SG_LIB_PATH.'SGStatsRequests.php'); |
| 857 | SGStatsRequests::initialSync(); |
| 858 | } |
| 859 | |
| 860 | add_action('admin_init', 'sgBackupAdminInit'); |
| 861 | |
| 862 | if (SGBoot::isFeatureAvailable('ALERT_BEFORE_UPDATE')) { |
| 863 | add_filter('upgrader_pre_download', 'backupGuardOnBeforeUpdateDownload', 10, 3); |
| 864 | add_action('core_upgrade_preamble', 'backupGuardOnUpgradeScreenActivate'); |
| 865 | add_action('current_screen', 'backupGuardOnScreenActivate'); |
| 866 | } |
| 867 | |
| 868 | // Register the new dashboard widget with the 'wp_dashboard_setup' action |
| 869 | add_action('wp_dashboard_setup', 'backup_guard_add_dashboard_widgets'); |
| 870 | |
| 871 | function backup_guard_add_dashboard_widgets() |
| 872 | { |
| 873 | require_once(SG_CORE_PATH.'SGConfig.php'); |
| 874 | |
| 875 | $userId = get_current_user_id(); |
| 876 | $userData = get_userdata($userId); |
| 877 | $userRoles = $userData->roles; |
| 878 | $isAdminUser = false; |
| 879 | for($i = 0; $i < count($userRoles); $i++) { |
| 880 | if ($userRoles[$i] == "administrator") { |
| 881 | $isAdminUser = true; |
| 882 | break; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | if (!$isAdminUser ) { |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | $isShowStatisticsWidgetEnabled = SGConfig::get('SG_SHOW_STATISTICS_WIDGET'); |
| 891 | if (!$isShowStatisticsWidgetEnabled) { |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | |
| 896 | require_once(plugin_dir_path( __FILE__ ).'public/dashboardWidget.php'); |
| 897 | wp_add_dashboard_widget('backupGuardWidget', 'Backup Guard', 'backup_guard_dashboard_widget_function'); |
| 898 | } |
| 899 | |
| 900 | add_action('plugins_loaded', 'backupGuardloadTextDomain'); |
| 901 | function backupGuardloadTextDomain() |
| 902 | { |
| 903 | $backupGuardLangDir = plugin_dir_path(__FILE__).'languages/'; |
| 904 | $backupGuardLangDir = apply_filters('backupguardLanguagesDirectory', $backupGuardLangDir); |
| 905 | |
| 906 | $locale = apply_filters('bg_plugin_locale', get_locale(), BACKUP_GUARD_TEXTDOMAIN); |
| 907 | $mofile = sprintf('%1$s-%2$s.mo', BACKUP_GUARD_TEXTDOMAIN, $locale); |
| 908 | |
| 909 | $mofileLocal = $backupGuardLangDir.$mofile; |
| 910 | |
| 911 | if (file_exists($mofileLocal)) { |
| 912 | // Look in local /wp-content/plugins/popup-builder/languages/ folder |
| 913 | load_textdomain(BACKUP_GUARD_TEXTDOMAIN, $mofileLocal); |
| 914 | } |
| 915 | else { |
| 916 | // Load the default language files |
| 917 | load_plugin_textdomain(BACKUP_GUARD_TEXTDOMAIN, false, $backupGuardLangDir); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | if (backupGuardShouldShowDiscountNotice() && checkDueDateDiscount()) { |
| 922 | add_action('admin_notices', 'backup_guard_discount_notice'); |
| 923 | } |
| 924 | |
| 925 | function backup_guard_discount_notice() |
| 926 | { |
| 927 | $capabilities = backupGuardGetCapabilities(); |
| 928 | $upgradeUrl = BG_UPGRADE_URL; |
| 929 | ?> |
| 930 | <div class="backup-guard-discount-notice updated notice is-dismissible"> |
| 931 | <div class="sgbg-col sgbg-col1"></div> |
| 932 | <div class="sgbg-col sgbg-col2"></div> |
| 933 | <div class="sgbg-col sgbg-col3"> |
| 934 | <div class="sgbg-text-col-1"> |
| 935 | -50% |
| 936 | </div> |
| 937 | <div class="sgbg-text-col-2"> |
| 938 | <div class="sgbg-discount-text-1">Discount</div> |
| 939 | <div class="sgbg-discount-text-2">All Backup Guard Solutions</div> |
| 940 | </div> |
| 941 | </div> |
| 942 | <div class="sgbg-col sgbg-col4"> |
| 943 | <a href="https://backup-guard.com/products/backup-wordpress" target="_blank"><button class="sgbg-button">Click Here</button></a> |
| 944 | </div> |
| 945 | </div> |
| 946 | <style> |
| 947 | .backup-guard-discount-notice.updated.notice.is-dismissible { |
| 948 | padding: 0; |
| 949 | border-left-color: #FFFFFF !important; |
| 950 | background-color: #000000; |
| 951 | height: 160px; |
| 952 | } |
| 953 | .backup-guard-discount-notice button:before { |
| 954 | color: #ffffff !important; |
| 955 | } |
| 956 | .sgbg-col { |
| 957 | display: inline-block; |
| 958 | width: 25%; |
| 959 | height: 100%; |
| 960 | padding: 0 25px; |
| 961 | box-sizing: border-box; |
| 962 | } |
| 963 | .sgbg-col1 { |
| 964 | width: 10%; |
| 965 | background-color: #FFFFFF; |
| 966 | background-image: url("<?php echo SG_IMAGE_URL ?>BgBFLogo.jpg"); |
| 967 | background-size: 80%; |
| 968 | background-repeat: no-repeat; |
| 969 | background-position: center; |
| 970 | } |
| 971 | .sgbg-col2 { |
| 972 | width: 20%; |
| 973 | background-image: url("<?php echo SG_IMAGE_URL ?>BF.png"); |
| 974 | background-size: contain; |
| 975 | margin-left: 70px; |
| 976 | background-position: center; |
| 977 | background-repeat: no-repeat; |
| 978 | } |
| 979 | .sgbg-col3 { |
| 980 | vertical-align: top; |
| 981 | width: 45%; |
| 982 | margin-top: 55px; |
| 983 | } |
| 984 | .sgbg-col4 { |
| 985 | width: 10%; |
| 986 | } |
| 987 | .sgbg-text-col-1, |
| 988 | .sgbg-text-col-2 { |
| 989 | width: 49%; |
| 990 | display: inline-block; |
| 991 | color: #FFFFFF; |
| 992 | } |
| 993 | .sgbg-text-col-1 { |
| 994 | font-size: 100px; |
| 995 | line-height: 0; |
| 996 | font-weight: bold; |
| 997 | text-align: right; |
| 998 | padding-right: 26px; |
| 999 | box-sizing: border-box; |
| 1000 | } |
| 1001 | .sgbg-discount-text-2 { |
| 1002 | font-size: 19px; |
| 1003 | } |
| 1004 | .sgbg-discount-text-1 { |
| 1005 | font-size: 60px; |
| 1006 | padding-bottom: 27px; |
| 1007 | font-weight: bold; |
| 1008 | } |
| 1009 | .sgbg-col4 { |
| 1010 | vertical-align: top; |
| 1011 | } |
| 1012 | .sgbg-button { |
| 1013 | width: 183px; |
| 1014 | height: 67px; |
| 1015 | font-size: 20px; |
| 1016 | border: #ffffff; |
| 1017 | border-radius: 10px; |
| 1018 | margin-top: 48px; |
| 1019 | background-color: #FFFFFF; |
| 1020 | color: #000000; |
| 1021 | cursor: pointer !important; |
| 1022 | } |
| 1023 | .sgbg-button:hover { |
| 1024 | background-color: #000000; |
| 1025 | border: 1px solid #FFFFFF; |
| 1026 | color: #FFFFFF; |
| 1027 | } |
| 1028 | .backup-guard-discount-notice .notice-dismiss::before { |
| 1029 | content: "x"; |
| 1030 | font-weight: 300; |
| 1031 | font-family: Arial, sans-serif; |
| 1032 | } |
| 1033 | |
| 1034 | @media (max-width: 1810px) { |
| 1035 | .sgbg-text-col-1 { |
| 1036 | font-size: 80px; |
| 1037 | } |
| 1038 | .sgbg-discount-text-1 { |
| 1039 | font-size: 43px; |
| 1040 | } |
| 1041 | .sgbg-discount-text-2 { |
| 1042 | font-size: 15px; |
| 1043 | } |
| 1044 | .sgbg-discount-text-1 { |
| 1045 | padding-bottom: 18px; |
| 1046 | } |
| 1047 | .sgbg-col3 { |
| 1048 | margin-top: 60px; |
| 1049 | } |
| 1050 | } |
| 1051 | @media (max-width: 1477px) { |
| 1052 | .sgbg-discount-text-2 { |
| 1053 | font-size: 12px; |
| 1054 | } |
| 1055 | .sgbg-discount-text-1 { |
| 1056 | font-size: 35px; |
| 1057 | } |
| 1058 | .sgbg-discount-text-1 { |
| 1059 | padding-bottom: 13px; |
| 1060 | } |
| 1061 | .sgbg-col { |
| 1062 | padding: 0; |
| 1063 | } |
| 1064 | .sgbg-col2 { |
| 1065 | margin-left: 40px; |
| 1066 | } |
| 1067 | .sgbg-col2 { |
| 1068 | margin-left: 0; |
| 1069 | } |
| 1070 | } |
| 1071 | </style> |
| 1072 | <?php |
| 1073 | } |
| 1074 | |
| 1075 | add_action('admin_notices', 'backup_guard_review_banner'); |
| 1076 | function backup_guard_review_banner() |
| 1077 | { |
| 1078 | require_once(SG_LIB_PATH.'SGReviewManager.php'); |
| 1079 | $reviewManager = new SGReviewManager(); |
| 1080 | $reviewManager->renderContent(); |
| 1081 | } |
| 1082 |