footer-new.php
5 years ago
footer.php
5 years ago
functions.php
5 years ago
header-new.php
5 years ago
header.php
5 years ago
modal.php
5 years ago
sidebar.php
5 years ago
uninstallSurveyPopup.php
5 years ago
functions.php
302 lines
| 1 | <?php |
| 2 | |
| 3 | function backupGuardShouldShowDiscountNotice() |
| 4 | { |
| 5 | if (SGConfig::get("SG_HIDE_DISCOUNT_NOTICE")) { |
| 6 | return false; |
| 7 | } |
| 8 | |
| 9 | return true; |
| 10 | } |
| 11 | |
| 12 | function checkDueDateDiscount() |
| 13 | { |
| 14 | $startDate = '2019-11-27'; |
| 15 | $endDate = '2019-12-02'; |
| 16 | |
| 17 | $timezone = 'Asia/Yerevan'; |
| 18 | $timeDate = new DateTime('now', new DateTimeZone($timezone)); |
| 19 | $currentTime = strtotime($timeDate->format('Y-m-d H:i:s')); |
| 20 | |
| 21 | $startDate = strtotime($startDate); |
| 22 | $finishDate = strtotime($endDate); |
| 23 | |
| 24 | return ($currentTime > $startDate && $currentTime < $finishDate); |
| 25 | } |
| 26 | |
| 27 | function _backupGuardT($key, $return = false) |
| 28 | { |
| 29 | if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) { |
| 30 | if($return) { |
| 31 | return __($key, "backup-guard-pro"); |
| 32 | } |
| 33 | else { |
| 34 | _e($key, "backup-guard-pro"); |
| 35 | } |
| 36 | } |
| 37 | else { |
| 38 | if($return) { |
| 39 | return $key; |
| 40 | } |
| 41 | else { |
| 42 | echo $key; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | function backupGuardIsAjax() |
| 48 | { |
| 49 | return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); |
| 50 | } |
| 51 | |
| 52 | function selectElement($data, $attributes=array(), $firstOption='', $selectedKey='') |
| 53 | { |
| 54 | $attrString = ''; |
| 55 | foreach($attributes as $attributeKey=>$attributeValue) { |
| 56 | $attrString.= " ".$attributeKey.'="'.$attributeValue.'"'; |
| 57 | |
| 58 | } |
| 59 | $select = '<select'.$attrString.'>'; |
| 60 | if ($firstOption) { |
| 61 | $select.='<option value="0">'.$firstOption.'</option>'; |
| 62 | } |
| 63 | foreach($data as $key=>$val) { |
| 64 | $selected = $selectedKey==$key?' selected="selected"':''; |
| 65 | $select.='<option value="'.$key.'"'.$selected.'>'.$val.'</option>'; |
| 66 | } |
| 67 | $select.='</select>'; |
| 68 | return $select; |
| 69 | } |
| 70 | |
| 71 | function backupGuardParseBackupOptions($options) |
| 72 | { |
| 73 | |
| 74 | $scheduleOptions = array( |
| 75 | 'interval' => '', |
| 76 | 'dayOfInterval' => '', |
| 77 | 'intervalHour' => '', |
| 78 | 'isBackgroundMode' => false, |
| 79 | 'isDatabaseSelected' => false, |
| 80 | 'isFilesSelected' => false, |
| 81 | 'isCustomBackup' => false, |
| 82 | 'selectedDirectories' => array(), |
| 83 | 'excludeDirectories' => array(), |
| 84 | 'selectedClouds' => array(), |
| 85 | 'label' => '' |
| 86 | ); |
| 87 | |
| 88 | if (isset($options['schedule_options'])) { |
| 89 | $scheduleExecutionOptions = json_decode($options['schedule_options'], true); |
| 90 | |
| 91 | $scheduleOptions['interval'] = $scheduleExecutionOptions['interval']; |
| 92 | $scheduleOptions['dayOfInterval'] = $scheduleExecutionOptions['dayOfInterval']; |
| 93 | $scheduleOptions['intervalHour'] = $scheduleExecutionOptions['intervalHour']; |
| 94 | } |
| 95 | |
| 96 | if (isset($options['backup_options'])) { |
| 97 | |
| 98 | $backupOptions = json_decode($options['backup_options'], true); |
| 99 | |
| 100 | $scheduleOptions['isBackgroundMode'] = $backupOptions['SG_BACKUP_IN_BACKGROUND_MODE']?true:false; |
| 101 | $scheduleOptions['isDatabaseSelected'] = $backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE']?true:false; |
| 102 | $scheduleOptions['isFilesSelected'] = $backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE']?true:false; |
| 103 | $backupType = $backupOptions['SG_BACKUP_TYPE']; |
| 104 | |
| 105 | $scheduleOptions['isCustomBackup'] = $backupType==SG_BACKUP_TYPE_FULL?false:true; |
| 106 | |
| 107 | if ($scheduleOptions['isCustomBackup']) { |
| 108 | $scheduleOptions['selectedDirectories'] = explode(',', $backupOptions['SG_BACKUP_FILE_PATHS']); |
| 109 | if ($scheduleOptions['isFilesSelected']) { |
| 110 | $scheduleOptions['excludeDirectories'] = explode(',', $backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE']); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if (strlen($backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES'])) { |
| 115 | $scheduleOptions['selectedClouds'] = explode(',', $backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES']); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (isset($options['label'])) { |
| 120 | $scheduleOptions['label'] = $options['label']; |
| 121 | } |
| 122 | |
| 123 | return $scheduleOptions; |
| 124 | } |
| 125 | |
| 126 | function backupGuardFilterStatusesByActionType($currentBackup, $currentOptions) |
| 127 | { |
| 128 | $filteredStatuses = array(); |
| 129 | if($currentBackup['type'] == SG_ACTION_TYPE_RESTORE) |
| 130 | { |
| 131 | $filteredStatuses[] = SG_ACTION_TYPE_RESTORE.SG_ACTION_STATUS_IN_PROGRESS_FILES; |
| 132 | $filteredStatuses[] = SG_ACTION_TYPE_RESTORE.SG_ACTION_STATUS_IN_PROGRESS_DB; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | $currentOptions = backupGuardActiveOptionToType($currentOptions); |
| 137 | if ($currentOptions['backupDatabase']) $filteredStatuses[] = $currentOptions['backupDatabase']; |
| 138 | if ($currentOptions['backupFiles']) $filteredStatuses[] = $currentOptions['backupFiles']; |
| 139 | if ($currentOptions['ftp']) $filteredStatuses[] = $currentOptions['ftp']; |
| 140 | if ($currentOptions['dropbox']) $filteredStatuses[] = $currentOptions['dropbox']; |
| 141 | if ($currentOptions['gdrive']) $filteredStatuses[] = $currentOptions['gdrive']; |
| 142 | if ($currentOptions['amazon']) $filteredStatuses[] = $currentOptions['amazon']; |
| 143 | if ($currentOptions['oneDrive']) $filteredStatuses[] = $currentOptions['oneDrive']; |
| 144 | if ($currentOptions['backupGuard']) $filteredStatuses[] = $currentOptions['backupGuard']; |
| 145 | } |
| 146 | return $filteredStatuses; |
| 147 | } |
| 148 | |
| 149 | function backupGuardActiveOptionToType($activeOption) |
| 150 | { |
| 151 | $activeOption = json_decode($activeOption, true); |
| 152 | $activeOptions['backupDatabase'] = !empty($activeOption['SG_ACTION_BACKUP_DATABASE_AVAILABLE'])?SG_ACTION_STATUS_IN_PROGRESS_DB:0; |
| 153 | $activeOptions['backupFiles'] = !empty($activeOption['SG_ACTION_BACKUP_FILES_AVAILABLE'])?SG_ACTION_STATUS_IN_PROGRESS_FILES:0; |
| 154 | |
| 155 | $storages = explode(',', @$activeOption['SG_BACKUP_UPLOAD_TO_STORAGES']); |
| 156 | $activeOptions['ftp'] = 0; |
| 157 | $activeOptions['dropbox'] = 0; |
| 158 | $activeOptions['gdrive'] = 0; |
| 159 | $activeOptions['amazon'] = 0; |
| 160 | $activeOptions['oneDrive'] = 0; |
| 161 | $activeOptions['backupGuard'] = 0; |
| 162 | foreach ($storages as $key => $storage) { |
| 163 | switch ($storage) { |
| 164 | case SG_STORAGE_FTP: |
| 165 | $activeOptions['ftp'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_FTP; |
| 166 | break; |
| 167 | case SG_STORAGE_DROPBOX: |
| 168 | $activeOptions['dropbox'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_DROPBOX; |
| 169 | break; |
| 170 | case SG_STORAGE_GOOGLE_DRIVE: |
| 171 | $activeOptions['gdrive'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_GOOGLE_DRIVE; |
| 172 | break; |
| 173 | case SG_STORAGE_AMAZON: |
| 174 | $activeOptions['amazon'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_AMAZON; |
| 175 | break; |
| 176 | case SG_STORAGE_ONE_DRIVE: |
| 177 | $activeOptions['oneDrive'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_ONE_DRIVE; |
| 178 | break; |
| 179 | case SG_STORAGE_BACKUP_GUARD: |
| 180 | $activeOptions['backupGuard'] = SG_ACTION_TYPE_UPLOAD.SG_STORAGE_BACKUP_GUARD; |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | return $activeOptions; |
| 186 | } |
| 187 | |
| 188 | function backupGuardConvertToBytes($from){ |
| 189 | $number=substr($from,0,-2); |
| 190 | switch(strtoupper(substr($from,-2))){ |
| 191 | case "KB": |
| 192 | return $number*1024; |
| 193 | case "MB": |
| 194 | return $number*pow(1024,2); |
| 195 | case "GB": |
| 196 | return $number*pow(1024,3); |
| 197 | case "TB": |
| 198 | return $number*pow(1024,4); |
| 199 | case "PB": |
| 200 | return $number*pow(1024,5); |
| 201 | default: |
| 202 | return $from; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | function backupGuardGetRunningActions() |
| 207 | { |
| 208 | $runningActions = SGBackup::getRunningActions(); |
| 209 | $isAnyActiveActions = count($runningActions); |
| 210 | if($isAnyActiveActions) { |
| 211 | return $runningActions; |
| 212 | } |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | function backupGuardShouldUpdate() |
| 217 | { |
| 218 | $currentVersion = SG_BACKUP_GUARD_VERSION; |
| 219 | $oldVersion = SGConfig::get('SG_BACKUP_GUARD_VERSION', true); |
| 220 | |
| 221 | if (!$oldVersion) { |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | if ($currentVersion !== $oldVersion) { |
| 226 | SGConfig::set('SG_BACKUP_GUARD_VERSION', $currentVersion, true); |
| 227 | SGConfig::set('SG_HIDE_DISCOUNT_NOTICE', '0', true); |
| 228 | SGBoot::didUpdatePluginVersion(); |
| 229 | return SG_FORCE_DB_TABLES_RESET; |
| 230 | } |
| 231 | |
| 232 | if (!checkAllMissedTables()) { |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | return false; |
| 237 | } |
| 238 | |
| 239 | function backupGuardGetDatabaseEngine() |
| 240 | { |
| 241 | global $wpdb; |
| 242 | $dbName = $wpdb->dbname; |
| 243 | $engine = 'InnoDB'; |
| 244 | $engineCheckSql = "SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$dbName'"; |
| 245 | $result = $wpdb->get_results($engineCheckSql, ARRAY_A); |
| 246 | if (!empty($result)) { |
| 247 | $engineCheckSql = "SHOW TABLE STATUS WHERE Name = '".$wpdb->prefix."users' AND Engine = 'MyISAM'"; |
| 248 | $result = $wpdb->get_results($engineCheckSql, ARRAY_A); |
| 249 | if (isset($result[0]['Engine']) && $result[0]['Engine'] == 'MyISAM') { |
| 250 | $engine = 'MyISAM'; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | return $engine; |
| 255 | } |
| 256 | |
| 257 | function backupGuardShouldActivateExtension($extension) |
| 258 | { |
| 259 | $extensionAdapter = SGExtension::getInstance(); |
| 260 | |
| 261 | if (!$extensionAdapter->isExtensionAvailable($extension) || SGConfig::get($extension) || !$extensionAdapter->isExtensionAlreadyInPluginsFolder($extension) || $extensionAdapter->isExtensionActive($extension)) { |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | function backupGuardShouldInstallExtension($extension) |
| 269 | { |
| 270 | $extensionAdapter = SGExtension::getInstance(); |
| 271 | |
| 272 | if (!$extensionAdapter->isExtensionAvailable($extension) || SGConfig::get($extension) || $extensionAdapter->isExtensionAlreadyInPluginsFolder($extension) || $extensionAdapter->isExtensionActive($extension)) { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | function backupGuardLoggedMessage() |
| 280 | { |
| 281 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 282 | if ($pluginCapabilities == BACKUP_GUARD_CAPABILITIES_FREE) { |
| 283 | return ''; |
| 284 | } |
| 285 | |
| 286 | $user = SGConfig::get('SG_LOGGED_USER'); |
| 287 | if (!$user) { |
| 288 | return ''; |
| 289 | } |
| 290 | |
| 291 | $user = unserialize($user); |
| 292 | if (!$user || empty($user['firstname'])) { |
| 293 | return ''; |
| 294 | } |
| 295 | |
| 296 | $html = '<span class="bg-logged-msg-container">'; |
| 297 | $html .= 'Package: '.backupGuardGetProductName() .' | Version: '.SG_BACKUP_GUARD_VERSION; |
| 298 | $html .= ' | Welcome, <b>'.$user['firstname'].'</b>! '; |
| 299 | $html .= '(<a href="javascript:void(0)" onclick="sgBackup.logout()">Log Out</a>)</span>'; |
| 300 | return $html; |
| 301 | } |
| 302 |