PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.2.6
JetBackup – Backup, Restore & Migrate v1.2.6
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / SGReviewManager.php
backup / com / lib Last commit date
BackupGuard 6 years ago Dropbox 6 years ago Request 6 years ago SGArchive.php 6 years ago SGAuthClient.php 6 years ago SGCallback.php 6 years ago SGCdrEntry.php 6 years ago SGCharsetHandler.php 6 years ago SGDBState.php 6 years ago SGEntry.php 6 years ago SGFileEntry.php 6 years ago SGFileState.php 6 years ago SGMigrateState.php 6 years ago SGMysqldump.php 6 years ago SGReloadHandler.php 6 years ago SGReloader.php 6 years ago SGReloaderState.php 6 years ago SGReviewManager.php 6 years ago SGState.php 6 years ago SGUploadHandler.php 6 years ago SGUploadState.php 6 years ago
SGReviewManager.php
387 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: 30px;
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 display: inline-block;
163 }
164 .sg-backup-img-wrapper {
165 width: 256px;
166 float: left;
167 background-color: #FFFFFF;
168 height: 100%;
169 }
170 .sg-backup-review-description-wrapper {
171 max-width: 100%;
172 vertical-align: top;
173 }
174 .sgpb-popup-dialog-main-div-wrapper .sg-backup-review-description {
175 padding: 0 30px;
176 }
177 .banner-x {
178 position: absolute;
179 right: 14px;
180 top: 5px;
181 display: inline !important;
182 cursor: pointer;
183 width: auto !important;
184 height: auto !important;
185 }
186 .banner-x:hover {
187 background-color: #071cb6 !important;
188 color: #ffffff !important;
189 border: none !important;
190 }
191 @media (max-width: 1350px) {
192 .sg-backup-wow {
193 font-size: 27px;
194 }
195 .sgpb-popup-dialog-main-div-wrapper .sg-backup-review-description {
196 padding: 0 5px;
197 }
198 }
199
200 </style>
201 <div id="sg-backup-review-wrapper" class="sg-backup-review-wrapper">
202 <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>
203 <div class="sg-backup-img-wrapper">
204 <img src="<?php echo SG_IMAGE_URL; ?>sgBackupVerticalLogo.png" width="200px" height="181px">
205 </div>
206 <div class="sg-backup-review-description-wrapper">
207 <div class="sg-backup-review-description">
208 <!-- <h2 class="sg-backup-custom-content"></h2>-->
209 <h2 class="sg-backup-review-h2"><?php echo $customContent; ?></h2>
210 <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>
211 </div>
212 <div class="sg-backup-buttons-wrapper">
213 <button class="press press-grey sg-backup-review-button sg-backup-button-1 sg-already-did-review"><?php _e('I already did'); ?></button>
214 <button class="press press-lightblue sg-backup-review-button sg-backup-button-3 sg-backup-you-worth-it"><?php _e('You worth it!'); ?></button>
215 <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>
216 </div>
217 </div>
218 </div>
219 <script type="text/javascript">
220 var closeBackupGuardReviewPopup = function ()
221 {
222 if (window.backupGuardReviewPopup) {
223 window.backupGuardReviewPopup.close();
224 }
225 };
226 var sgBackupDontShowAgain = function() {
227 closeBackupGuardReviewPopup();
228 jQuery('.sg-backup-review-wrapper').remove();
229 var data = {
230 action: 'backup_guard_reviewDontShow',
231 token: BG_BACKUP_STRINGS.nonce
232 };
233 jQuery.post(ajaxurl, data, function () {
234 });
235 };
236 var backupGuardReviewBannerButtons = function() {
237 jQuery('.sg-backup-button-3').bind('click', function () {
238 sgBackupDontShowAgain();
239 window.open("<?php echo BACKUP_GUARD_WORDPRESS_REVIEW_URL; ?>")
240 });
241 jQuery('.sg-backup-button-1').bind('click', function () {
242 sgBackupDontShowAgain();
243 });
244 jQuery('.sg-backup-backup-button-2').bind('click', function () {
245 closeBackupGuardReviewPopup();
246 jQuery('.sg-backup-review-wrapper').remove();
247 var type = jQuery(this).data('message-type');
248
249 var data = {
250 action: 'backup_guard_review_later',
251 type: type,
252 token: BG_BACKUP_STRINGS.nonce
253 };
254 jQuery.post(ajaxurl, data, function () {
255 });
256 });
257 }
258 backupGuardReviewBannerButtons();
259
260 jQuery(window).bind('sgpbDidOpen', function() {
261 backupGuardReviewBannerButtons();
262 });
263 </script>
264 <?php
265 $content = ob_get_contents();
266 ob_end_clean();
267
268 return $content;
269 }
270
271 private function isAllowDaysReview()
272 {
273 $shouldOpen = false;
274 $periodNextTime = SGConfig::get('openNextTime');
275
276 $dontShowAgain = SGConfig::get('closeReviewBanner');
277 // When period next time does not exits it means the user is old
278 if (!$periodNextTime) {
279 $usageDays = $this->getBackupTableCreationDate();
280 SGConfig::set('usageDays', $usageDays);
281 // For old users
282 if (defined('SG_BACKUP_REVIEW_PERIOD') && $usageDays > SG_BACKUP_REVIEW_PERIOD && !$dontShowAgain) {
283 return true;
284 }
285
286 $remainingDays = SG_BACKUP_REVIEW_PERIOD - $usageDays;
287
288 $popupTimeZone = 'America/New_York';
289 $timeDate = new \DateTime('now', new DateTimeZone($popupTimeZone));
290 $timeDate->modify('+'.$remainingDays.' day');
291
292 $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
293 SGConfig::set('openNextTime', $timeNow);
294
295 return false;
296 }
297
298 $currentData = new \DateTime('now');
299 $timeNow = $currentData->format('Y-m-d H:i:s');
300 $timeNow = strtotime($timeNow);
301
302 if ($periodNextTime < $timeNow) {
303 $shouldOpen = true;
304 }
305
306 return $shouldOpen;
307 }
308
309 private function getBackupTableCreationDate()
310 {
311 $sgdb = SGDatabase::getInstance();
312
313 $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));
314
315 if (empty($results) || empty($results[0]['create_time'])) {
316 return 0;
317 }
318
319 $createTime = $results[0]['create_time'];
320 $createTime = strtotime($createTime);
321 SGConfig::set('installDate', $createTime);
322 $diff = time() - $createTime;
323 $days = floor($diff/(60*60*24));
324
325 return $days;
326 }
327
328 public static function getBackupCounts()
329 {
330 $sgdb = SGDatabase::getInstance();
331 $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);
332
333 if (empty($result[0]['countBackups'])) {
334 return 0;
335 }
336
337 return (int)$result[0]['countBackups'];;
338 }
339
340 private function isAllowToShowReviewByCount()
341 {
342 $status = false;
343
344 $backupsCount = SGReviewManager::getBackupCounts();
345
346 if (empty($backupsCount)) {
347 return $status;
348 }
349
350 $backupCountReview = SGConfig::get('backupReviewCount');
351 if (empty($backupCountReview)) {
352 $backupCountReview = SG_BACKUP_REVIEW_BACKUP_COUNT;
353 }
354
355 return ($backupsCount >= $backupCountReview);
356 }
357
358 public static function getBackupRestoreCounts()
359 {
360 $sgdb = SGDatabase::getInstance();
361 $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);
362
363 if (empty($result[0]['countRestores'])) {
364 return 0;
365 }
366
367 return (int)$result[0]['countRestores'];
368 }
369
370 private function isSuccessFullRestore()
371 {
372 $status = false;
373
374 $countRestores = SGReviewManager::getBackupRestoreCounts();
375
376 if (empty($countRestores)) {
377 return $status;
378 }
379
380 $restoreReviewCount = SGConfig::get('restoreReviewCount');
381 if (empty($restoreReviewCount)) {
382 $restoreReviewCount = SG_BACKUP_REVIEW_RESTORE_COUNT;
383 }
384
385 return ($countRestores >= $restoreReviewCount);
386 }
387 }