BackupPluginsDetector.php
2 days ago
FirstInstall.php
2 days ago
FreeOnboarding.php
2 days ago
NextStepRenderer.php
2 days ago
OnboardingAjax.php
2 days ago
OnboardingJourney.php
2 days ago
QueuedBackup.php
2 days ago
NextStepRenderer.php
129 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Onboarding; |
| 4 | |
| 5 | use WPStaging\Core\WPStaging; |
| 6 | use WPStaging\Framework\Utils\Strings; |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | class NextStepRenderer |
| 19 | { |
| 20 | |
| 21 | private $journey; |
| 22 | |
| 23 | |
| 24 | private $onboarding; |
| 25 | |
| 26 | |
| 27 | private $queuedBackup; |
| 28 | |
| 29 | |
| 30 | private $strings; |
| 31 | |
| 32 | public function __construct(FreeOnboarding $onboarding, OnboardingJourney $journey, QueuedBackup $queuedBackup, Strings $strings) |
| 33 | { |
| 34 | $this->onboarding = $onboarding; |
| 35 | $this->journey = $journey; |
| 36 | $this->queuedBackup = $queuedBackup; |
| 37 | $this->strings = $strings; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | public function render(): string |
| 45 | { |
| 46 | |
| 47 | |
| 48 | if ($this->journey->getCompletionReason() === OnboardingJourney::REASON_TWO_CAPABILITIES) { |
| 49 | return $this->renderCard(OnboardingJourney::CAPABILITY_STAGING, '', true, []); |
| 50 | } |
| 51 | |
| 52 | $completedCapability = $this->journey->getAction(OnboardingJourney::POSITION_FIRST); |
| 53 | |
| 54 | if ($completedCapability === '' || !$this->journey->isFirstCapabilityCompleted()) { |
| 55 | return ''; |
| 56 | } |
| 57 | |
| 58 | $secondAction = $this->journey->getAction(OnboardingJourney::POSITION_SECOND); |
| 59 | |
| 60 | return $this->renderCard( |
| 61 | $completedCapability, |
| 62 | $this->journey->getNextCapability(), |
| 63 | $secondAction === '', |
| 64 | $this->describeBackup(), |
| 65 | $this->queuedBackup->isPending() |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | private function describeBackup(): array |
| 80 | { |
| 81 | $details = $this->journey->getCompletedBackupDetails(); |
| 82 | |
| 83 | if (empty($details['name'])) { |
| 84 | return $details; |
| 85 | } |
| 86 | |
| 87 | $details['name'] = $this->strings->maskBackupFilename($details['name']); |
| 88 | |
| 89 | return $details; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | private function renderCard(string $completedCapability, string $nextCapability, bool $isNextStepOffered, array $backupDetails, bool $isBackupInBackground = false): string |
| 100 | { |
| 101 | $stagingSiteUrl = $this->onboarding->getLatestStagingSiteUrl(); |
| 102 | $adminUrl = admin_url('admin.php?page='); |
| 103 | |
| 104 | |
| 105 | |
| 106 | $isNextCapabilityAvailable = !($nextCapability === OnboardingJourney::CAPABILITY_STAGING && $this->onboarding->isHostedOnWordPressCom()); |
| 107 | |
| 108 | ob_start(); |
| 109 | include WPSTG_VIEWS_DIR . 'onboarding/next-step.php'; |
| 110 | |
| 111 | return (string)ob_get_clean(); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | public static function resolve() |
| 121 | { |
| 122 | try { |
| 123 | return WPStaging::make(self::class); |
| 124 | } catch (\Throwable $e) { |
| 125 | return null; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 |