| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of TransferPageController |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
* |
| 8 |
* @autoload: a2wl_admin_init |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace AliNext_Lite;; |
| 12 |
|
| 13 |
use Pages; |
| 14 |
|
| 15 |
class TransferPageController extends AbstractAdminPage |
| 16 |
{ |
| 17 |
public const FIELD_HASH = "hash"; |
| 18 |
|
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
parent::__construct( |
| 22 |
Pages::getLabel(Pages::TRANSFER), |
| 23 |
Pages::getLabel(Pages::TRANSFER), |
| 24 |
Capability::pluginAccess(), |
| 25 |
Pages::TRANSFER, |
| 26 |
95 |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
public function render($params = []): void |
| 31 |
{ |
| 32 |
if (!PageGuardHelper::canAccessPage(Pages::TRANSFER)) { |
| 33 |
wp_die($this->getErrorTextNoPermissions()); |
| 34 |
} |
| 35 |
|
| 36 |
$this->saveHandler(); |
| 37 |
$this->model_put(self::FIELD_HASH, $this->getSettingsString()); |
| 38 |
$this->include_view("transfer.php"); |
| 39 |
} |
| 40 |
|
| 41 |
private function getSettingsString(): string |
| 42 |
{ |
| 43 |
$settings = get_option('a2wl_settings', []); |
| 44 |
$settingsJson = json_encode($settings); |
| 45 |
|
| 46 |
return base64_encode($settingsJson); |
| 47 |
} |
| 48 |
|
| 49 |
private function saveHandler(): void |
| 50 |
{ |
| 51 |
if (isset($_POST['transfer_form']) && !empty($_POST[self::FIELD_HASH])) { |
| 52 |
check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE); |
| 53 |
|
| 54 |
$settingsJson = base64_decode($_POST[self::FIELD_HASH]); |
| 55 |
|
| 56 |
if (!$settingsJson) { |
| 57 |
$this->model_put("error", |
| 58 |
esc_html_x('Hash is not correct', 'error text', 'ali2woo') |
| 59 |
); |
| 60 |
|
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$settings = json_decode($settingsJson, true); |
| 65 |
|
| 66 |
if (!$settings) { |
| 67 |
$this->model_put("error", |
| 68 |
esc_html_x('Hash is not correct', 'error text', 'ali2woo') |
| 69 |
); |
| 70 |
|
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
update_option('a2wl_settings', $settings); |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|