| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 4 |
|
| 5 |
class UpdraftPlus_Temporary_Clone_Status { |
| 6 |
|
| 7 |
/** |
| 8 |
* WP is Installed |
| 9 |
*/ |
| 10 |
const INSTALLED = 1; |
| 11 |
|
| 12 |
/** |
| 13 |
* Data is uploading |
| 14 |
*/ |
| 15 |
const UPLOADING = 2; |
| 16 |
|
| 17 |
/** |
| 18 |
* Data is uploaded and is restoring |
| 19 |
*/ |
| 20 |
const RESTORING = 3; |
| 21 |
|
| 22 |
/** |
| 23 |
* The current status number |
| 24 |
* |
| 25 |
* @var int |
| 26 |
*/ |
| 27 |
public $current_status; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor for the class. |
| 31 |
*/ |
| 32 |
public function __construct() { |
| 33 |
add_action('init', array($this, 'init')); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* This function is called via the WordPress init action, it will check if the page is not the admin backend and output the clone status |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function init() { |
| 42 |
if (is_admin() || (defined('WP_CLI') && WP_CLI) || 'GET' != $_SERVER['REQUEST_METHOD']) return; |
| 43 |
|
| 44 |
$this->output_status_page(); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Outputs the clone status |
| 49 |
* |
| 50 |
* @param bool $die - Defines if should die at the end |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function output_status_page($die = true) { |
| 54 |
$this->current_status = $this->get_status(); |
| 55 |
$this->page_start(); |
| 56 |
echo '<div class="updraftclone_content_container">'; |
| 57 |
|
| 58 |
echo '<img class="updraftclone_logo" alt="UpdraftClone Logo" src="'.trailingslashit(UPDRAFTPLUS_URL).'images/updraftclone_logo_white.png">'; |
| 59 |
echo $this->get_content(); |
| 60 |
?> |
| 61 |
<div class="status-box"> |
| 62 |
<section class="progress"> |
| 63 |
<div class="progress-item <?php echo $this->get_progress_item_class(self::INSTALLED); ?>"> |
| 64 |
<div class="progress-item__bar"></div> |
| 65 |
<span class="icon"><?php echo $this->get_progress_item_icon(self::INSTALLED); ?></span> |
| 66 |
<?php _e('WordPress installed', 'updraftplus'); ?> |
| 67 |
</div> |
| 68 |
<div class="progress-item <?php echo $this->get_progress_item_class(self::UPLOADING); ?>"> |
| 69 |
<div class="progress-item__bar"></div> |
| 70 |
<span class="icon"><?php echo $this->get_progress_item_icon(self::UPLOADING); ?></span> |
| 71 |
<?php |
| 72 |
if (self::UPLOADING >= $this->current_status) { |
| 73 |
_e('Receiving site data', 'updraftplus'); |
| 74 |
} else { |
| 75 |
_e('Site data received', 'updraftplus'); |
| 76 |
} |
| 77 |
?> |
| 78 |
</div> |
| 79 |
<div class="progress-item <?php echo $this->get_progress_item_class(self::RESTORING); ?>"> |
| 80 |
<div class="progress-item__bar"></div> |
| 81 |
<span class="icon"><?php echo $this->get_progress_item_icon(self::RESTORING); ?></span> |
| 82 |
<?php |
| 83 |
if (self::RESTORING >= $this->current_status) { |
| 84 |
_e('Deploying site data', 'updraftplus'); |
| 85 |
} else { |
| 86 |
_e('Site data has been deployed', 'updraftplus'); |
| 87 |
} |
| 88 |
?> |
| 89 |
</div> |
| 90 |
<div class="progress-item"> |
| 91 |
<div class="progress-item__bar"></div> |
| 92 |
<span class="icon"><?php echo $this->get_progress_item_icon(); ?></span> |
| 93 |
<?php |
| 94 |
_e('Clone ready', 'updraftplus'); |
| 95 |
?> |
| 96 |
</div> |
| 97 |
</section> |
| 98 |
<?php echo '<p class="status-description">' . $this->get_status_description() . '</p>'; ?> |
| 99 |
|
| 100 |
</div> |
| 101 |
|
| 102 |
<?php |
| 103 |
echo '</div>'; |
| 104 |
$this->page_end(); |
| 105 |
if ($die) die(); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* This function will output the start of the updraftclone status page |
| 110 |
* |
| 111 |
* @return void |
| 112 |
*/ |
| 113 |
public function page_start() { |
| 114 |
echo '<!DOCTYPE html> |
| 115 |
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar" lang="en-US"> |
| 116 |
<head> |
| 117 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 118 |
<meta http-equiv="refresh" content="60"> |
| 119 |
<meta name="robots" content="noindex, nofollow"> |
| 120 |
<title>UpdraftClone</title> |
| 121 |
<style> |
| 122 |
|
| 123 |
@-webkit-keyframes rotateIcon { |
| 124 |
|
| 125 |
from { |
| 126 |
-webkit-transform: rotate(0); |
| 127 |
transform: rotate(0); |
| 128 |
} |
| 129 |
|
| 130 |
to { |
| 131 |
-webkit-transform: rotate(360deg); |
| 132 |
transform: rotate(360deg); |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
@keyframes rotateIcon { |
| 138 |
|
| 139 |
from { |
| 140 |
-webkit-transform: rotate(0); |
| 141 |
transform: rotate(0); |
| 142 |
} |
| 143 |
|
| 144 |
to { |
| 145 |
-webkit-transform: rotate(360deg); |
| 146 |
transform: rotate(360deg); |
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
body { |
| 152 |
background-color: #EDEDED; |
| 153 |
margin: 0; |
| 154 |
padding: 20px; |
| 155 |
} |
| 156 |
p { |
| 157 |
padding: 0; |
| 158 |
margin: 15px 0; |
| 159 |
line-height: 1.2; |
| 160 |
} |
| 161 |
body:before { |
| 162 |
content: \' \'; |
| 163 |
position: absolute; |
| 164 |
background: #db6939; |
| 165 |
display: block; |
| 166 |
height: 477px; |
| 167 |
top: 0; |
| 168 |
left: 0; |
| 169 |
width: 100%; |
| 170 |
z-index: 1; |
| 171 |
} |
| 172 |
a { |
| 173 |
color: #ffceb9; |
| 174 |
} |
| 175 |
.updraftclone_content_container { |
| 176 |
position: relative; |
| 177 |
z-index: 2; |
| 178 |
margin:auto; |
| 179 |
margin-top:40px; |
| 180 |
width:80%; |
| 181 |
max-width: 520px; |
| 182 |
text-align:center; |
| 183 |
color: #ffffff; |
| 184 |
font-family: Source Sans Pro, Helvetica, Arial, Lucida, sans-serif; |
| 185 |
font-weight: 300; |
| 186 |
font-size: 16px; |
| 187 |
} |
| 188 |
.updraftclone_logo { |
| 189 |
width: 50%; |
| 190 |
} |
| 191 |
|
| 192 |
.status-box { |
| 193 |
max-width: 520px; |
| 194 |
margin: 0 auto; |
| 195 |
background: #FFF; |
| 196 |
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1); |
| 197 |
color: #43322B; |
| 198 |
} |
| 199 |
section.progress { |
| 200 |
display: -webkit-box; |
| 201 |
display: -ms-flexbox; |
| 202 |
display: flex; |
| 203 |
position: relative; |
| 204 |
} |
| 205 |
|
| 206 |
.progress-item { |
| 207 |
-webkit-box-flex: 1; |
| 208 |
-ms-flex: 1; |
| 209 |
flex: 1; |
| 210 |
position: relative; |
| 211 |
padding: 10px; |
| 212 |
padding-bottom: 20px; |
| 213 |
} |
| 214 |
|
| 215 |
.progress-item.active { |
| 216 |
font-weight: bold; |
| 217 |
} |
| 218 |
|
| 219 |
.progress-item__bar { |
| 220 |
height: 10px; |
| 221 |
position: absolute; |
| 222 |
top: 0; |
| 223 |
width: 100%; |
| 224 |
left: 0; |
| 225 |
} |
| 226 |
|
| 227 |
.done .progress-item__bar { |
| 228 |
background: #43322B; |
| 229 |
} |
| 230 |
|
| 231 |
.active .progress-item__bar { |
| 232 |
background: #43322B; |
| 233 |
overflow: hidden; |
| 234 |
} |
| 235 |
|
| 236 |
.active .progress-item__bar:before { |
| 237 |
content: \' \'; |
| 238 |
display: block; |
| 239 |
width: 10px; |
| 240 |
height: 10px; |
| 241 |
position: absolute; |
| 242 |
background: #43322B; |
| 243 |
right: 0; |
| 244 |
top: 0; |
| 245 |
border-top: 10px solid #FFF; |
| 246 |
border-right: 10px solid #FFF; |
| 247 |
-webkit-transform: translateY(-5px) translateX(10px) rotate(45deg); |
| 248 |
transform: translateY(-5px) translateX(10px) rotate(45deg); |
| 249 |
} |
| 250 |
|
| 251 |
section.progress:before { |
| 252 |
content: \' \'; |
| 253 |
position: absolute; |
| 254 |
display: block; |
| 255 |
height: 10px; |
| 256 |
top: 0; |
| 257 |
left: 0; |
| 258 |
width: 100%; |
| 259 |
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.21); |
| 260 |
} |
| 261 |
span.icon { |
| 262 |
display: block; |
| 263 |
padding-top: 15px; |
| 264 |
padding-bottom: 10px; |
| 265 |
} |
| 266 |
span.icon svg { |
| 267 |
display: inline-block; |
| 268 |
max-width: 28px; |
| 269 |
fill: #C4C4C4; |
| 270 |
color: currentColor; |
| 271 |
} |
| 272 |
|
| 273 |
.done span.icon svg { |
| 274 |
fill: green; |
| 275 |
} |
| 276 |
|
| 277 |
.active span.icon svg { |
| 278 |
fill: #43322B; |
| 279 |
-webkit-animation-name: rotateIcon; |
| 280 |
animation-name: rotateIcon; |
| 281 |
-webkit-animation-duration: 1.8s; |
| 282 |
animation-duration: 1.8s; |
| 283 |
-webkit-animation-iteration-count: infinite; |
| 284 |
animation-iteration-count: infinite; |
| 285 |
-webkit-animation-timing-function: linear; |
| 286 |
animation-timing-function: linear; |
| 287 |
} |
| 288 |
|
| 289 |
.progress-item:not(.done):not(.active) { |
| 290 |
color: #C4C4C4; |
| 291 |
} |
| 292 |
.done { |
| 293 |
color: green; |
| 294 |
} |
| 295 |
|
| 296 |
p.status-description { |
| 297 |
margin: 0; |
| 298 |
padding: 20px; |
| 299 |
border-top: 1px solid #EBEBEB; |
| 300 |
} |
| 301 |
|
| 302 |
@media (max-width: 520px) { |
| 303 |
.progress-item:not(.active) { |
| 304 |
display: none; |
| 305 |
} |
| 306 |
} |
| 307 |
</style> |
| 308 |
</head> |
| 309 |
<body>'; |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* This function will output the end of the updraftclone status page |
| 314 |
* |
| 315 |
* @return void |
| 316 |
*/ |
| 317 |
public function page_end() { |
| 318 |
?> |
| 319 |
<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" style="display: none;"> |
| 320 |
<symbol viewBox="0 0 20 20" id="yes-alt"><title>yes-alt</title><g><path d="M10 2c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm-.615 12.66h-1.34l-3.24-4.54 1.34-1.25 2.57 2.4 5.14-5.93 1.34.94-5.81 8.38z"/></g></symbol> |
| 321 |
<symbol viewBox="0 0 20 20" id="yes"><title>yes</title><g><path d="M14.83 4.89l1.34.94-5.81 8.38H9.02L5.78 9.67l1.34-1.25 2.57 2.4z"/></g></symbol> |
| 322 |
<symbol viewBox="0 0 20 20" id="update"><title>update</title><g><path d="M10.2 3.28c3.53 0 6.43 2.61 6.92 6h2.08l-3.5 4-3.5-4h2.32c-.45-1.97-2.21-3.45-4.32-3.45-1.45 0-2.73.71-3.54 1.78L4.95 5.66C6.23 4.2 8.11 3.28 10.2 3.28zm-.4 13.44c-3.52 0-6.43-2.61-6.92-6H.8l3.5-4c1.17 1.33 2.33 2.67 3.5 4H5.48c.45 1.97 2.21 3.45 4.32 3.45 1.45 0 2.73-.71 3.54-1.78l1.71 1.95c-1.28 1.46-3.15 2.38-5.25 2.38z"/></g></symbol> |
| 323 |
<symbol viewBox="0 0 20 20" id="clock"><title>clock</title><g><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm0 14c3.31 0 6-2.69 6-6s-2.69-6-6-6-6 2.69-6 6 2.69 6 6 6zm-.71-5.29c.07.05.14.1.23.15l-.02.02L14 13l-3.03-3.19L10 5l-.97 4.81h.01c0 .02-.01.05-.02.09S9 9.97 9 10c0 .28.1.52.29.71z"/></g></symbol> |
| 324 |
</svg> |
| 325 |
</body> |
| 326 |
</html> |
| 327 |
<?php |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* This function will get and return the clone status title ready to be displayed on the page |
| 332 |
* |
| 333 |
* @return string - the clone status title |
| 334 |
*/ |
| 335 |
public function get_status_title() { |
| 336 |
|
| 337 |
$code = ""; |
| 338 |
|
| 339 |
switch ($this->current_status) { |
| 340 |
case self::INSTALLED: |
| 341 |
$code = __("WordPress installed", "updraftplus"); |
| 342 |
break; |
| 343 |
case self::UPLOADING: |
| 344 |
$code = __("Receiving site data", "updraftplus"); |
| 345 |
break; |
| 346 |
case self::RESTORING: |
| 347 |
$code = __("Deploying site data", "updraftplus"); |
| 348 |
break; |
| 349 |
default: |
| 350 |
$code = ""; |
| 351 |
break; |
| 352 |
} |
| 353 |
|
| 354 |
return $code; |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* This function will get and return the clone status description ready to be displayed on the page |
| 359 |
* |
| 360 |
* @return string - the clone status description |
| 361 |
*/ |
| 362 |
public function get_status_description() { |
| 363 |
global $updraftplus; |
| 364 |
|
| 365 |
$description = ""; |
| 366 |
|
| 367 |
switch ($this->current_status) { |
| 368 |
case self::INSTALLED: |
| 369 |
$description = __('WordPress installed; now awaiting the site data to be sent.', 'updraftplus'); |
| 370 |
break; |
| 371 |
case self::UPLOADING: |
| 372 |
$backup_details = $this->get_backup_details(); |
| 373 |
$description = sprintf(__('The sending of the site data has begun. So far %s data archives totalling %s have been received', 'updraftplus'), '<strong>'.$backup_details['sets'].'</strong>', '<strong>'.round($backup_details['uploaded'], 2).' MB</strong>'); |
| 374 |
break; |
| 375 |
case self::RESTORING: |
| 376 |
UpdraftPlus_Backup_History::rebuild(); |
| 377 |
$backup_details = $this->get_backup_details(); |
| 378 |
$description = __('The site data has all been received, and its import has begun.', 'updraftplus').' '.sprintf(__('%s archives remain', 'updraftplus'), '<strong>'.$backup_details['sets'].'</strong>'); |
| 379 |
break; |
| 380 |
default: |
| 381 |
$description = "(?)"; |
| 382 |
break; |
| 383 |
} |
| 384 |
|
| 385 |
return $description; |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* This function will return information about the backup such as the amount of sets and the size of the backup set |
| 390 |
* |
| 391 |
* @return array - an array with backup information |
| 392 |
*/ |
| 393 |
public function get_backup_details() { |
| 394 |
global $updraftplus; |
| 395 |
|
| 396 |
$backup_history = UpdraftPlus_Backup_History::get_history(); |
| 397 |
$backupable_entities = $updraftplus->get_backupable_file_entities(); |
| 398 |
$sets = 0; |
| 399 |
$uploaded = 0; |
| 400 |
|
| 401 |
foreach ($backupable_entities as $key => $info) { |
| 402 |
foreach ($backup_history as $timestamp => $backup) { |
| 403 |
if (isset($backup[$key]) && isset($backup[$key.'-size'])) { |
| 404 |
$sets += count($backup[$key]); |
| 405 |
$uploaded += $backup[$key.'-size']; |
| 406 |
} |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
$uploaded = round($uploaded / 1048576, 1); |
| 411 |
|
| 412 |
return array('uploaded' => $uploaded, 'sets' => $sets); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* This function will get and return the clone content ready to be displayed on the page |
| 417 |
* |
| 418 |
* @return string - the clone content |
| 419 |
*/ |
| 420 |
public function get_content() { |
| 421 |
$content = '<p>'.__('Your UpdraftClone is still setting up.', 'updraftplus').' '.sprintf(__('You can check the progress here or in %s', 'updraftplus'), '<a href="https://updraftplus.com/my-account/clones/" target="_blank">'.__('your UpdraftPlus.com account', 'updraftplus')).'</a></p>'; |
| 422 |
$content .= '<p><a href="https://updraftplus.com/faq-category/updraftclone/" target="_blank">'.__('To read FAQs/documentation about UpdraftClone, go here.', 'updraftplus').'</a></p>'; |
| 423 |
return $content; |
| 424 |
} |
| 425 |
|
| 426 |
/** |
| 427 |
* This function will work out what stage the clone is in and return the correct status code |
| 428 |
* |
| 429 |
* @return int - the clone status code |
| 430 |
*/ |
| 431 |
public function get_status() { |
| 432 |
global $updraftplus; |
| 433 |
|
| 434 |
$backup_history = UpdraftPlus_Backup_History::get_history(); |
| 435 |
|
| 436 |
if (empty($backup_history)) return self::INSTALLED; |
| 437 |
|
| 438 |
$updraft_dir = trailingslashit($updraftplus->backups_dir_location()); |
| 439 |
|
| 440 |
if (file_exists($updraft_dir.'ready_for_restore')) return self::RESTORING; |
| 441 |
|
| 442 |
return self::UPLOADING; |
| 443 |
} |
| 444 |
|
| 445 |
/** |
| 446 |
* Get the progress item class |
| 447 |
* |
| 448 |
* @param int $number The status number |
| 449 |
* @return string |
| 450 |
*/ |
| 451 |
private function get_progress_item_class($number) { |
| 452 |
return ($number === $this->current_status) ? 'active' : (($number < $this->current_status) ? 'done' : ''); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Get the progress item icon |
| 457 |
* |
| 458 |
* @param int $number The status number |
| 459 |
* @return string |
| 460 |
*/ |
| 461 |
private function get_progress_item_icon($number = 1000) { |
| 462 |
$icon = '<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">'; |
| 463 |
$icon .= '<use href="#'.(($number === $this->current_status) ? 'update' : (($number < $this->current_status) ? 'yes' : 'clock')).'" />'; |
| 464 |
$icon .= '</svg>'; |
| 465 |
return $icon; |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
if (defined('UPDRAFTPLUS_THIS_IS_CLONE') && 1 == UPDRAFTPLUS_THIS_IS_CLONE) { |
| 470 |
$updraftplus_temporary_clone_status = new UpdraftPlus_Temporary_Clone_Status(); |
| 471 |
} |
| 472 |
|