BackupGuard
5 years ago
Dropbox
5 years ago
Request
5 years ago
SGArchive.php
5 years ago
SGAuthClient.php
5 years ago
SGCallback.php
5 years ago
SGCdrEntry.php
5 years ago
SGCharsetHandler.php
5 years ago
SGDBState.php
5 years ago
SGEntry.php
5 years ago
SGFileEntry.php
5 years ago
SGFileState.php
5 years ago
SGMigrateState.php
5 years ago
SGMysqldump.php
5 years ago
SGReloadHandler.php
5 years ago
SGReloader.php
5 years ago
SGReloaderState.php
5 years ago
SGReviewManager.php
5 years ago
SGState.php
5 years ago
SGStatsRequests.php
5 years ago
SGUploadHandler.php
5 years ago
SGUploadState.php
5 years ago
SGReviewManager.php
421 lines
| 1 | <?php |
| 2 | |
| 3 | class SGReviewManager |
| 4 | { |
| 5 | public function renderContent() |
| 6 | { |
| 7 | $dontShowAgain = SGConfig::get('closeReviewBanner'); |
| 8 | if ($dontShowAgain) { |
| 9 | return ''; |
| 10 | } |
| 11 | // review with backup Count |
| 12 | $allowReviewCount = $this->isAllowToShowReviewByCount(); |
| 13 | if ($allowReviewCount) { |
| 14 | // show review |
| 15 | $key = 'backupCount'; |
| 16 | $backupCountReview = $this->getBackupCounts(); |
| 17 | $customContent = 'Yay! We see that you have made '.$backupCountReview.' backups.'; |
| 18 | echo $this->reviewContentMessage($customContent, $key); |
| 19 | return ''; |
| 20 | } |
| 21 | // review after successfully restore |
| 22 | $isSuccessFullRestore = $this->isSuccessFullRestore(); |
| 23 | if ($isSuccessFullRestore) { |
| 24 | // after successfully restore |
| 25 | $key = 'restoreCount'; |
| 26 | $restoreReviewCount = $this->getBackupRestoreCounts(); |
| 27 | $customContent = 'Yay! Congrats, you have restored your website for the '.$restoreReviewCount.' st time!'; |
| 28 | echo $this->reviewContentMessage($customContent, $key); |
| 29 | return ''; |
| 30 | } |
| 31 | |
| 32 | // review after X days |
| 33 | $isAllowDaysReview = $this->isAllowDaysReview(); |
| 34 | if ($isAllowDaysReview) { |
| 35 | $key = 'dayCount'; |
| 36 | $usageDays = $this->getBackupUsageDays(); |
| 37 | $customContent = 'Yay! You are a part of the BG team for over '.$usageDays.' days now! Hope you enjoy our service!'; |
| 38 | echo $this->reviewContentMessage($customContent, $key); |
| 39 | return ''; |
| 40 | } |
| 41 | |
| 42 | return ''; |
| 43 | } |
| 44 | |
| 45 | public static function getBackupUsageDays() |
| 46 | { |
| 47 | $installDate = SGConfig::get('installDate'); |
| 48 | |
| 49 | $timeDate = new \DateTime('now'); |
| 50 | $timeNow = strtotime($timeDate->format('Y-m-d H:i:s')); |
| 51 | $diff = $timeNow-$installDate; |
| 52 | $days = floor($diff/(60*60*24)); |
| 53 | |
| 54 | return $days; |
| 55 | } |
| 56 | |
| 57 | public function reviewContentMessage($customContent, $type) |
| 58 | { |
| 59 | ob_start(); |
| 60 | ?> |
| 61 | <style> |
| 62 | .sg-backup-buttons-wrapper .press{ |
| 63 | box-sizing:border-box; |
| 64 | cursor:pointer; |
| 65 | display:inline-block; |
| 66 | margin:0; |
| 67 | padding:0.5em 0.75em; |
| 68 | text-decoration:none; |
| 69 | transition:background 0.15s linear |
| 70 | width: 148px; |
| 71 | height: 50px; |
| 72 | } |
| 73 | .sg-backup-buttons-wrapper .press-grey { |
| 74 | border:2px solid #FFFFFF; |
| 75 | color: #FFF; |
| 76 | } |
| 77 | .sg-backup-buttons-wrapper .press-lightblue { |
| 78 | background-color:#ffffff; |
| 79 | border:2px solid #FFFFFF; |
| 80 | color: rgba(0,29,182,1); |
| 81 | margin: 0 20px; |
| 82 | } |
| 83 | .sg-backup-buttons-wrapper .press-lightblue:hover { |
| 84 | background-color: rgba(0, 0, 0, 0); |
| 85 | color: #FFFFFF; |
| 86 | } |
| 87 | .sg-backup-buttons-wrapper { |
| 88 | text-align: center; |
| 89 | } |
| 90 | .sg-backup-review-wrapper { |
| 91 | position: relative; |
| 92 | text-align: center; |
| 93 | background-color: #001DB6; |
| 94 | height: 185px; |
| 95 | box-sizing: border-box; |
| 96 | background-image: url(<?php echo SG_IMAGE_URL.'reviewBg.png' ?>); |
| 97 | margin-top: 45px; |
| 98 | margin-right: 20px; |
| 99 | } |
| 100 | .sgpb-popup-dialog-main-div-wrapper .sg-backup-review-wrapper { |
| 101 | margin-top: 0px; |
| 102 | margin-right: 0px ; |
| 103 | } |
| 104 | .sgpb-popup-dialog-main-div-wrapper .banner-x { |
| 105 | display: none !important; |
| 106 | } |
| 107 | .sg-backup-review-wrapper p { |
| 108 | color: #FFFFFF; |
| 109 | } |
| 110 | .sg-backup-review-h1 { |
| 111 | font-size: 22px; |
| 112 | font-weight: normal; |
| 113 | line-height: 1.384; |
| 114 | } |
| 115 | .sg-backup-review-h2 { |
| 116 | font-size: 23px; |
| 117 | font-weight: bold; |
| 118 | color: #FFFFFF; |
| 119 | margin: 10px 0; |
| 120 | margin-top: 27px; |
| 121 | } |
| 122 | :root { |
| 123 | --main-bg-color: #1ac6ff; |
| 124 | } |
| 125 | .sg-backup-review-strong { |
| 126 | color: var(--main-bg-color); |
| 127 | } |
| 128 | .sg-backup-review-mt20 { |
| 129 | margin-top: 10px; |
| 130 | color: #FFFFFF !important; |
| 131 | margin-bottom: 20px; |
| 132 | } |
| 133 | .sg-backup-wow { |
| 134 | font-size: 35px; |
| 135 | color: #FFFFFF; |
| 136 | margin: 15px 0; |
| 137 | padding-top: 16px; |
| 138 | } |
| 139 | .sg-backup-review-button { |
| 140 | font-size: 15px !important; |
| 141 | font-weight: bold; |
| 142 | border-radius: 8px !important; |
| 143 | width: 120px !important; |
| 144 | height: 40px !important; |
| 145 | } |
| 146 | .sg-backup-button-1, .sg-backup-backup-button-2 { |
| 147 | background-color: rgba(0, 0, 0, 0) !important; |
| 148 | color: #ffffff !important; |
| 149 | } |
| 150 | .sg-backup-button-1:hover, .sg-backup-backup-button-2:hover { |
| 151 | background-color: #FFFFFF !important; |
| 152 | color: #001DB6 !important; |
| 153 | border: 2px solid #FFFFFF; |
| 154 | } |
| 155 | .sg-backup-custom-content { |
| 156 | color: #FFFFFF; |
| 157 | font-size: 20px; |
| 158 | margin: 14px 0; |
| 159 | } |
| 160 | .sg-backup-img-wrapper, |
| 161 | .sg-backup-review-description-wrapper { |
| 162 | padding-top: 1px; |
| 163 | } |
| 164 | #sgpb-popup-dialog-main-div .sg-backup-img-wrapper, |
| 165 | #sgpb-popup-dialog-main-div .sg-backup-review-description-wrapper { |
| 166 | display: inline-block; |
| 167 | } |
| 168 | .sg-backup-img-wrapper { |
| 169 | width: 256px; |
| 170 | float: left; |
| 171 | background-color: #FFFFFF; |
| 172 | height: 100%; |
| 173 | } |
| 174 | .sg-backup-review-description-wrapper { |
| 175 | max-width: 100%; |
| 176 | vertical-align: top; |
| 177 | } |
| 178 | .sgpb-popup-dialog-main-div-wrapper .sg-backup-review-description { |
| 179 | padding: 0 30px; |
| 180 | } |
| 181 | .banner-x { |
| 182 | position: absolute; |
| 183 | right: 14px; |
| 184 | top: 5px; |
| 185 | display: inline !important; |
| 186 | cursor: pointer; |
| 187 | width: auto !important; |
| 188 | height: auto !important; |
| 189 | } |
| 190 | .banner-x:hover { |
| 191 | background-color: #071cb6 !important; |
| 192 | color: #ffffff !important; |
| 193 | border: none !important; |
| 194 | } |
| 195 | @media (max-width: 1350px) { |
| 196 | .sg-backup-wow { |
| 197 | font-size: 27px; |
| 198 | } |
| 199 | .sgpb-popup-dialog-main-div-wrapper .sg-backup-review-description { |
| 200 | padding: 0 5px; |
| 201 | } |
| 202 | } |
| 203 | @media (max-width: 1173px) { |
| 204 | .sg-backup-img-wrapper {width: 202px;} |
| 205 | .sg-backup-review-h2 { |
| 206 | margin-top: 24px; |
| 207 | } |
| 208 | #sgpb-popup-dialog-main-div .sg-backup-review-mt20 {margin-bottom: 20px;} |
| 209 | } |
| 210 | @media (max-width: 1027px) { |
| 211 | #sgpb-popup-dialog-main-div .sg-backup-img-wrapper, |
| 212 | #sgpb-popup-dialog-main-div .sg-backup-review-description-wrapper { |
| 213 | display: inherit; |
| 214 | } |
| 215 | #sgpb-popup-dialog-main-div .sg-backup-review-h2 {margin-top: 18px;} |
| 216 | } |
| 217 | @media (max-width: 815px) { |
| 218 | .sg-backup-review-mt20 {margin-bottom: 10px;} |
| 219 | .sg-backup-review-h2 { |
| 220 | margin-top: 23px; |
| 221 | } |
| 222 | } |
| 223 | @media (max-width: 735px) {#sgpb-popup-dialog-main-div .sg-backup-review-h2 {margin-top: 10px;}} |
| 224 | @media (max-width: 715px) { |
| 225 | .sg-backup-review-mt20 {margin-bottom: 10px;} |
| 226 | .sg-backup-review-h2 { |
| 227 | margin-top: 15px; |
| 228 | } |
| 229 | } |
| 230 | @media (max-width: 640px) { |
| 231 | .sg-backup-img-wrapper {display: none;} |
| 232 | .sg-backup-review-h2 {margin-top: 22px} |
| 233 | } |
| 234 | </style> |
| 235 | <div id="sg-backup-review-wrapper" class="sg-backup-review-wrapper"> |
| 236 | <span class="banner-x sg-backup-review-button sg-backup-backup-button-2 sg-backup-show-popup-period" data-message-type="<?php echo $type; ?>">x</span> |
| 237 | <div class="sg-backup-img-wrapper"> |
| 238 | <img src="<?php echo SG_IMAGE_URL; ?>sgBackupVerticalLogo.png" width="200px" height="181px"> |
| 239 | </div> |
| 240 | <div class="sg-backup-review-description-wrapper"> |
| 241 | <div class="sg-backup-review-description"> |
| 242 | <!-- <h2 class="sg-backup-custom-content"></h2>--> |
| 243 | <h2 class="sg-backup-review-h2"><?php echo $customContent; ?></h2> |
| 244 | <p class="sg-backup-review-mt20"><?php _e('Have your input in the development of our plugin, and we’ll get better and happier. Leave your 5-star positive review and help <br> us go further to the perfection!'); ?></p> |
| 245 | </div> |
| 246 | <div class="sg-backup-buttons-wrapper"> |
| 247 | <button class="press press-grey sg-backup-review-button sg-backup-button-1 sg-already-did-review"><?php _e('I already did'); ?></button> |
| 248 | <button class="press press-lightblue sg-backup-review-button sg-backup-button-3 sg-backup-you-worth-it"><?php _e('You worth it!'); ?></button> |
| 249 | <button class="press press-grey sg-backup-review-button sg-backup-backup-button-2 sg-backup-show-popup-period" data-message-type="<?php echo $type; ?>"><?php _e('Maybe later'); ?></button> |
| 250 | </div> |
| 251 | </div> |
| 252 | </div> |
| 253 | <script type="text/javascript"> |
| 254 | var closeBackupGuardReviewPopup = function () |
| 255 | { |
| 256 | if (window.backupGuardReviewPopup) { |
| 257 | window.backupGuardReviewPopup.close(); |
| 258 | } |
| 259 | }; |
| 260 | var sgBackupDontShowAgain = function() { |
| 261 | closeBackupGuardReviewPopup(); |
| 262 | jQuery('.sg-backup-review-wrapper').remove(); |
| 263 | var data = { |
| 264 | action: 'backup_guard_reviewDontShow', |
| 265 | token: BG_BACKUP_STRINGS.nonce |
| 266 | }; |
| 267 | jQuery.post(ajaxurl, data, function () { |
| 268 | }); |
| 269 | }; |
| 270 | var backupGuardReviewBannerButtons = function() { |
| 271 | jQuery('.sg-backup-button-3').bind('click', function () { |
| 272 | sgBackupDontShowAgain(); |
| 273 | window.open("<?php echo BACKUP_GUARD_WORDPRESS_REVIEW_URL; ?>") |
| 274 | }); |
| 275 | jQuery('.sg-backup-button-1').bind('click', function () { |
| 276 | sgBackupDontShowAgain(); |
| 277 | }); |
| 278 | jQuery('.sg-backup-backup-button-2').bind('click', function () { |
| 279 | closeBackupGuardReviewPopup(); |
| 280 | jQuery('.sg-backup-review-wrapper').remove(); |
| 281 | var type = jQuery(this).data('message-type'); |
| 282 | |
| 283 | var data = { |
| 284 | action: 'backup_guard_review_later', |
| 285 | type: type, |
| 286 | token: BG_BACKUP_STRINGS.nonce |
| 287 | }; |
| 288 | jQuery.post(ajaxurl, data, function () { |
| 289 | }); |
| 290 | }); |
| 291 | } |
| 292 | backupGuardReviewBannerButtons(); |
| 293 | |
| 294 | jQuery(window).bind('sgpbDidOpen', function() { |
| 295 | backupGuardReviewBannerButtons(); |
| 296 | }); |
| 297 | </script> |
| 298 | <?php |
| 299 | $content = ob_get_contents(); |
| 300 | ob_end_clean(); |
| 301 | |
| 302 | return $content; |
| 303 | } |
| 304 | |
| 305 | private function isAllowDaysReview() |
| 306 | { |
| 307 | $shouldOpen = false; |
| 308 | $periodNextTime = SGConfig::get('openNextTime'); |
| 309 | |
| 310 | $dontShowAgain = SGConfig::get('closeReviewBanner'); |
| 311 | // When period next time does not exits it means the user is old |
| 312 | if (!$periodNextTime) { |
| 313 | $usageDays = $this->getBackupTableCreationDate(); |
| 314 | SGConfig::set('usageDays', $usageDays); |
| 315 | // For old users |
| 316 | if (defined('SG_BACKUP_REVIEW_PERIOD') && $usageDays > SG_BACKUP_REVIEW_PERIOD && !$dontShowAgain) { |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | $remainingDays = SG_BACKUP_REVIEW_PERIOD - $usageDays; |
| 321 | |
| 322 | $popupTimeZone = 'America/New_York'; |
| 323 | $timeDate = new \DateTime('now', new DateTimeZone($popupTimeZone)); |
| 324 | $timeDate->modify('+'.$remainingDays.' day'); |
| 325 | |
| 326 | $timeNow = strtotime($timeDate->format('Y-m-d H:i:s')); |
| 327 | SGConfig::set('openNextTime', $timeNow); |
| 328 | |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | $currentData = new \DateTime('now'); |
| 333 | $timeNow = $currentData->format('Y-m-d H:i:s'); |
| 334 | $timeNow = strtotime($timeNow); |
| 335 | |
| 336 | if ($periodNextTime < $timeNow) { |
| 337 | $shouldOpen = true; |
| 338 | } |
| 339 | |
| 340 | return $shouldOpen; |
| 341 | } |
| 342 | |
| 343 | private function getBackupTableCreationDate() |
| 344 | { |
| 345 | $sgdb = SGDatabase::getInstance(); |
| 346 | |
| 347 | $results = $sgdb->query('SELECT table_name, create_time FROM information_schema.tables WHERE table_schema="%s" AND table_name="%s"', array(DB_NAME, SG_ACTION_TABLE_NAME)); |
| 348 | |
| 349 | if (empty($results) || empty($results[0]['create_time'])) { |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | $createTime = $results[0]['create_time']; |
| 354 | $createTime = strtotime($createTime); |
| 355 | SGConfig::set('installDate', $createTime); |
| 356 | $diff = time() - $createTime; |
| 357 | $days = floor($diff/(60*60*24)); |
| 358 | |
| 359 | return $days; |
| 360 | } |
| 361 | |
| 362 | public static function getBackupCounts() |
| 363 | { |
| 364 | $sgdb = SGDatabase::getInstance(); |
| 365 | $result = $sgdb->query('SELECT count(id) as countBackups FROM '.SG_ACTION_TABLE_NAME.' WHERE type='.SG_ACTION_TYPE_BACKUP.' AND status='.SG_ACTION_STATUS_FINISHED); |
| 366 | |
| 367 | if (empty($result[0]['countBackups'])) { |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | return (int)$result[0]['countBackups'];; |
| 372 | } |
| 373 | |
| 374 | private function isAllowToShowReviewByCount() |
| 375 | { |
| 376 | $status = false; |
| 377 | |
| 378 | $backupsCount = SGReviewManager::getBackupCounts(); |
| 379 | |
| 380 | if (empty($backupsCount)) { |
| 381 | return $status; |
| 382 | } |
| 383 | |
| 384 | $backupCountReview = SGConfig::get('backupReviewCount'); |
| 385 | if (empty($backupCountReview)) { |
| 386 | $backupCountReview = SG_BACKUP_REVIEW_BACKUP_COUNT; |
| 387 | } |
| 388 | |
| 389 | return ($backupsCount >= $backupCountReview); |
| 390 | } |
| 391 | |
| 392 | public static function getBackupRestoreCounts() |
| 393 | { |
| 394 | $sgdb = SGDatabase::getInstance(); |
| 395 | $result = $sgdb->query('SELECT count(id) as countRestores FROM '.SG_ACTION_TABLE_NAME.' WHERE type='.SG_ACTION_TYPE_RESTORE.' AND status='.SG_ACTION_STATUS_FINISHED); |
| 396 | |
| 397 | if (empty($result[0]['countRestores'])) { |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | return (int)$result[0]['countRestores']; |
| 402 | } |
| 403 | |
| 404 | private function isSuccessFullRestore() |
| 405 | { |
| 406 | $status = false; |
| 407 | |
| 408 | $countRestores = SGReviewManager::getBackupRestoreCounts(); |
| 409 | |
| 410 | if (empty($countRestores)) { |
| 411 | return $status; |
| 412 | } |
| 413 | |
| 414 | $restoreReviewCount = SGConfig::get('restoreReviewCount'); |
| 415 | if (empty($restoreReviewCount)) { |
| 416 | $restoreReviewCount = SG_BACKUP_REVIEW_RESTORE_COUNT; |
| 417 | } |
| 418 | |
| 419 | return ($countRestores >= $restoreReviewCount); |
| 420 | } |
| 421 | } |