PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.9.4
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.9.4
4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Staging / Renderer / SetupRenderer.php
wp-staging / Staging / Renderer Last commit date
SetupRenderer.php 2 days ago
SetupRenderer.php
173 lines
1 <?php
2
3 namespace WPStaging\Staging\Renderer;
4
5 use WPStaging\Staging\Dto\StagingSiteDto;
6 use WPStaging\Staging\Service\AbstractStagingSetup;
7
8 /**
9 * Renders shared setup modal UI fragments.
10 */
11 class SetupRenderer
12 {
13 /**
14 * @var string
15 */
16 private $selectedEngineName = '';
17
18 public function setSelectedEngineName(string $selectedEngineName = ''): self
19 {
20 $this->selectedEngineName = !empty($selectedEngineName) ? $selectedEngineName : esc_html__('Classic', 'wp-staging');
21
22 return $this;
23 }
24
25 public function getSelectedEngineName(): string
26 {
27 return !empty($this->selectedEngineName) ? $this->selectedEngineName : esc_html__('Classic', 'wp-staging');
28 }
29
30 public function icon(string $name, string $class = 'wpstg-h-5 wpstg-w-5', float $strokeWidth = 1.75)
31 {
32 $this->renderPartial('icon', compact('name', 'class', 'strokeWidth'));
33 }
34
35 public function attributes(array $attributes)
36 {
37 $this->renderPartial('attributes', compact('attributes'));
38 }
39
40 public function closeButton(string $class)
41 {
42 $this->renderPartial('close-button', compact('class'));
43 }
44
45 public function stepBadge(string $label)
46 {
47 $this->renderPartial('step-badge', compact('label'));
48 }
49
50 public function modalHeader(string $title, string $description = '', string $titleId = '', string $stepLabel = '', string $extraClass = '', string $afterDescription = '', string $icon = '')
51 {
52 $this->renderPartial('modal-header', compact('title', 'description', 'titleId', 'stepLabel', 'extraClass', 'afterDescription', 'icon'));
53 }
54
55 public function footerButton(string $label, string $class, string $variant = 'secondary', string $icon = '', string $iconPosition = 'start', array $attributes = [])
56 {
57 $this->renderPartial('footer-button', compact('label', 'class', 'variant', 'icon', 'iconPosition', 'attributes'));
58 }
59
60 public function modalFooter(string $status, callable $buttons, string $extraClass = '', string $statusWarning = '')
61 {
62 $this->renderPartial('modal-footer', compact('status', 'buttons', 'extraClass', 'statusWarning'));
63 }
64
65 public function reviewCard(string $title, array $rows)
66 {
67 $this->renderPartial('review-card', compact('title', 'rows'));
68 }
69
70 public function accordionSection(array $args, callable $content)
71 {
72 $this->renderPartial('accordion-section', compact('args', 'content'));
73 }
74
75 public function setupOptionCard(string $name, string $label, string $description, bool $checked = false, array $checkboxOptions = [], string $tooltip = '', bool $proLocked = false)
76 {
77 $this->renderPartial('setup-option-card', compact('name', 'label', 'description', 'checked', 'checkboxOptions', 'tooltip', 'proLocked'));
78 }
79
80 public function proControlRow(string $name, bool $checked, string $label, string $description, string $statusLabel = '', string $badgeLabel = '', string $context = '')
81 {
82 $this->renderPartial('pro-control-row', compact('name', 'checked', 'label', 'description', 'statusLabel', 'badgeLabel', 'context'));
83 }
84
85 public function setupCopyCard(string $checkboxId, string $checkboxClass, string $title, callable $summary, string $buttonClass, string $buttonLabel, string $buttonIcon, $details = null, array $checkboxOptions = [], $afterContent = null)
86 {
87 $this->renderPartial('setup-copy-card', compact('checkboxId', 'checkboxClass', 'title', 'summary', 'buttonClass', 'buttonLabel', 'buttonIcon', 'details', 'checkboxOptions', 'afterContent'));
88 }
89
90 public function readyCard(
91 string $title = '',
92 string $description = '',
93 string $databaseDescription = '',
94 string $filesDescription = '',
95 bool $showRuntimeBehavior = true,
96 string $runtimeDescription = '',
97 string $cardClass = '',
98 string $runtimeTitle = '',
99 string $engineSuffix = '',
100 string $runtimeIcon = 'shield',
101 array $customizeLinks = [],
102 bool $runtimeLocked = false,
103 bool $showCustomizeButton = false
104 ) {
105 $this->renderPartial('ready-card', compact(
106 'title',
107 'description',
108 'databaseDescription',
109 'filesDescription',
110 'showRuntimeBehavior',
111 'runtimeDescription',
112 'cardClass',
113 'runtimeTitle',
114 'engineSuffix',
115 'runtimeIcon',
116 'customizeLinks',
117 'runtimeLocked',
118 'showCustomizeButton'
119 ));
120 }
121
122 public function engineSection(string $setupMode, string $enginePanelId)
123 {
124 $this->renderPartial('engine-section', compact('setupMode', 'enginePanelId'));
125 }
126
127 public function runtimeSection(bool $isCreate, bool $isUpdate, bool $isProLicenseActive, bool $showWooSchedulerSettings, StagingSiteDto $stagingSiteDto, array $runtimeSummaryTooltips)
128 {
129 $this->renderPartial('runtime-section', compact('isCreate', 'isUpdate', 'isProLicenseActive', 'showWooSchedulerSettings', 'stagingSiteDto', 'runtimeSummaryTooltips'));
130 }
131
132 public function destinationSection(bool $isProLicenseActive, bool $isProBuild, bool $isCreate, AbstractStagingSetup $stagingSetup, string $defaultPathBase, string $defaultSiteName, string $productionSiteUrl)
133 {
134 $this->renderPartial('destination-section', compact('isProLicenseActive', 'isProBuild', 'isCreate', 'stagingSetup', 'defaultPathBase', 'defaultSiteName', 'productionSiteUrl'));
135 }
136
137 public function runtimeSummaryValue(string $key, array $tooltips, bool $isProLicenseActive)
138 {
139 $this->renderPartial('runtime-summary-value', compact('key', 'tooltips', 'isProLicenseActive'));
140 }
141
142 public function hasWooSchedulerSettings(AbstractStagingSetup $stagingSetup): bool
143 {
144 return strpos($this->captureCallable([$stagingSetup, 'renderEnableWooSchedulerSettings']), 'wpstg_woo_scheduler_enabled') !== false;
145 }
146
147 public function configurationBody(array $context)
148 {
149 $this->renderPartial('configuration-body', $context);
150 }
151
152 public function createSetupFooter(string $previewSiteUrl)
153 {
154 $this->renderPartial('create-setup-footer', compact('previewSiteUrl'));
155 }
156
157 private function captureCallable(callable $callback): string
158 {
159 ob_start();
160 $callback();
161
162 return (string)ob_get_clean();
163 }
164
165 private function renderPartial(string $partial, array $data = [])
166 {
167 $renderer = $this;
168 extract($data, EXTR_SKIP);
169
170 require WPSTG_VIEWS_DIR . 'staging/_partials/setup-modal/' . $partial . '.php';
171 }
172 }
173