| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* File: /controller/e2pdf-license.php |
| 5 |
* |
| 6 |
* @package E2Pdf |
| 7 |
* @license GPLv3 |
| 8 |
* @link https://e2pdf.com |
| 9 |
*/ |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die('Access denied.'); |
| 12 |
} |
| 13 |
|
| 14 |
class Controller_E2pdf_License extends Helper_E2pdf_View { |
| 15 |
|
| 16 |
/** |
| 17 |
* @url admin.php?page=e2pdf-license |
| 18 |
*/ |
| 19 |
public function index_action() { |
| 20 |
$this->load_scripts(); |
| 21 |
$this->load_styles(); |
| 22 |
$this->view('license', $this->helper->get('license')); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Load javascript on license page |
| 27 |
*/ |
| 28 |
public function load_scripts() { |
| 29 |
wp_enqueue_script('jquery-ui-dialog'); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Load style on license page |
| 34 |
*/ |
| 35 |
public function load_styles() { |
| 36 |
$version = get_option('e2pdf_debug', '0') === '1' ? strtotime('now') : $this->helper->get('version'); |
| 37 |
wp_enqueue_style('css/e2pdf.jquery-ui', plugins_url('css/jquery-ui.css', $this->helper->get('plugin_file_path')), false, $version, false); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Change license key via ajax |
| 42 |
* action: wp_ajax_e2pdf_license_key |
| 43 |
* function: e2pdf_license_key |
| 44 |
* @return json |
| 45 |
*/ |
| 46 |
public function ajax_change_license_key() { |
| 47 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_license')) { |
| 48 |
$data = $this->post->get('data'); |
| 49 |
$this->helper->load('license')->change(isset($data['license_key']) ? $data['license_key'] : ''); |
| 50 |
$response = [ |
| 51 |
'redirect' => $this->helper->get_url( |
| 52 |
[ |
| 53 |
'page' => 'e2pdf-license', |
| 54 |
'notification' => isset($request['error']) ? $this->add_notification('error', $request['error']) : $this->add_notification('update', __('License Key Changed', 'e2pdf')), |
| 55 |
] |
| 56 |
), |
| 57 |
]; |
| 58 |
} else { |
| 59 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 60 |
} |
| 61 |
$this->json_response($response); |
| 62 |
} |
| 63 |
|
| 64 |
public function ajax_deactivate_all_templates() { |
| 65 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_license')) { |
| 66 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 67 |
$model_e2pdf_api->set( |
| 68 |
[ |
| 69 |
'action' => 'template/deactivateall', |
| 70 |
] |
| 71 |
); |
| 72 |
$request = $model_e2pdf_api->request(); |
| 73 |
$response = [ |
| 74 |
'redirect' => $this->helper->get_url( |
| 75 |
[ |
| 76 |
'page' => 'e2pdf-license', |
| 77 |
'notification' => isset($request['error']) ? $this->add_notification('error', $request['error']) : $this->add_notification('update', __('Templates Deactivated', 'e2pdf')), |
| 78 |
] |
| 79 |
), |
| 80 |
]; |
| 81 |
} else { |
| 82 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 83 |
} |
| 84 |
$this->json_response($response); |
| 85 |
} |
| 86 |
} |
| 87 |
|