| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Installer; |
| 4 |
|
| 5 |
/** |
| 6 |
* Handle the plumbing of an installer step |
| 7 |
* |
| 8 |
* Class InstallerStep |
| 9 |
* |
| 10 |
* @package Codelight\GDPR\Installer |
| 11 |
*/ |
| 12 |
abstract class InstallerStep |
| 13 |
{ |
| 14 |
/* @var string */ |
| 15 |
protected $stepType; |
| 16 |
|
| 17 |
/* @var string */ |
| 18 |
protected $slug; |
| 19 |
|
| 20 |
/* @var string */ |
| 21 |
protected $type; |
| 22 |
|
| 23 |
/* @var string */ |
| 24 |
protected $template; |
| 25 |
|
| 26 |
/* @var int */ |
| 27 |
protected $activeSteps; |
| 28 |
|
| 29 |
/* @var string */ |
| 30 |
protected $errors; |
| 31 |
|
| 32 |
/** |
| 33 |
* Render a step for viewing |
| 34 |
*/ |
| 35 |
public function run() |
| 36 |
{ |
| 37 |
$this->enqueue(); |
| 38 |
$this->renderHeader(); |
| 39 |
$this->renderContent(); |
| 40 |
$this->renderNonce(); |
| 41 |
$this->renderFooter(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Validate the form submission |
| 46 |
* |
| 47 |
* @return bool |
| 48 |
*/ |
| 49 |
public function validate() |
| 50 |
{ |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Validate the nonce |
| 56 |
* |
| 57 |
* @return bool |
| 58 |
*/ |
| 59 |
public function validateNonce() |
| 60 |
{ |
| 61 |
return isset($_POST['gdpr_nonce']) && wp_verify_nonce($_POST['gdpr_nonce'], $this->slug); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Process the form submission |
| 66 |
*/ |
| 67 |
public function submit() |
| 68 |
{ |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
/** |
| 74 |
* Display error notice or something |
| 75 |
*/ |
| 76 |
public function getErrors() |
| 77 |
{ |
| 78 |
return $this->errors; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Register WP's default assets and plugin installer assets |
| 83 |
*/ |
| 84 |
protected function enqueue() |
| 85 |
{ |
| 86 |
global $gdpr; |
| 87 |
wp_enqueue_style('common'); |
| 88 |
wp_enqueue_style('buttons'); |
| 89 |
|
| 90 |
/** |
| 91 |
* GDPR installer custom styles |
| 92 |
*/ |
| 93 |
wp_enqueue_style( |
| 94 |
'gdpr-installer', |
| 95 |
$gdpr->PluginUrl . 'assets/gdpr-installer.css' |
| 96 |
); |
| 97 |
|
| 98 |
wp_enqueue_style( |
| 99 |
'select2css', |
| 100 |
$gdpr->PluginUrl . 'assets/select2-4.0.5.css' |
| 101 |
); |
| 102 |
|
| 103 |
wp_enqueue_script('jquery'); |
| 104 |
wp_enqueue_script('jquery-ui-core'); |
| 105 |
wp_enqueue_script('jquery-ui-widget'); |
| 106 |
wp_enqueue_script('jquery-ui-mouse'); |
| 107 |
wp_enqueue_script('jquery-ui-sortable'); |
| 108 |
wp_enqueue_script('jquery-ui-tabs'); |
| 109 |
wp_enqueue_script( |
| 110 |
'select2', |
| 111 |
$gdpr->PluginUrl . 'assets/select2-4.0.3.js', |
| 112 |
['jquery'] |
| 113 |
); |
| 114 |
wp_enqueue_script( |
| 115 |
'conditional-show', |
| 116 |
$gdpr->PluginUrl . 'assets/conditional-show.js', |
| 117 |
['jquery'] |
| 118 |
); |
| 119 |
|
| 120 |
//global $wp_scripts; |
| 121 |
//$ui = $wp_scripts->query('jquery-ui-core'); |
| 122 |
//wp_enqueue_style('jquery-ui-smoothness', "//ajax.googleapis.com/ajax/libs/jqueryui/{$ui->ver}/themes/smoothness/jquery-ui.min.css", false, null); |
| 123 |
|
| 124 |
wp_enqueue_script( |
| 125 |
'jquery-repeater', |
| 126 |
$gdpr->PluginUrl . 'assets/jquery.repeater.min.js', |
| 127 |
['jquery'] |
| 128 |
); |
| 129 |
|
| 130 |
/** |
| 131 |
* Installer javascript |
| 132 |
*/ |
| 133 |
wp_enqueue_script( |
| 134 |
'gdpr-installer', |
| 135 |
$gdpr->PluginUrl . 'assets/gdpr-installer.js', |
| 136 |
['jquery', 'select2'] |
| 137 |
); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Render the installer page header - html head, form, logo |
| 142 |
*/ |
| 143 |
protected function renderHeader() |
| 144 |
{ |
| 145 |
echo gdpr('view')->render('installer/header', ['activeSteps' => $this->activeSteps]); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Render the installer page content - should be overridden by child class |
| 150 |
*/ |
| 151 |
protected function renderContent() |
| 152 |
{ |
| 153 |
echo gdpr('view')->render($this->template); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Create and render the nonce based on the name of the current step |
| 158 |
*/ |
| 159 |
protected function renderNonce() |
| 160 |
{ |
| 161 |
$nonce = wp_create_nonce($this->slug); |
| 162 |
echo gdpr('view')->render('installer/nonce', compact('nonce')); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Render the footer - nav buttons and closing tags |
| 167 |
*/ |
| 168 |
protected function renderFooter() |
| 169 |
{ |
| 170 |
echo gdpr('view')->render('installer/footer'); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* @return string |
| 175 |
*/ |
| 176 |
public function getUrl() |
| 177 |
{ |
| 178 |
global $gdpr; |
| 179 |
return $gdpr->InstallerWizardUrl . $this->slug; |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* @return string |
| 184 |
*/ |
| 185 |
public function getSlug() |
| 186 |
{ |
| 187 |
if (is_null($this->slug)) { |
| 188 |
trigger_error("GDPR: Slug not defined for step!", E_USER_ERROR); |
| 189 |
} |
| 190 |
|
| 191 |
return $this->slug; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* @return string |
| 196 |
*/ |
| 197 |
public function getType() |
| 198 |
{ |
| 199 |
if (is_null($this->type)) { |
| 200 |
trigger_error("GDPR: Type not defined for step {$this->slug}", E_USER_ERROR); |
| 201 |
} |
| 202 |
|
| 203 |
return $this->type; |
| 204 |
} |
| 205 |
} |
| 206 |
|