| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf License Controller |
| 5 |
* |
| 6 |
* @copyright Copyright 2017 https://e2pdf.com |
| 7 |
* @license GPL v2 |
| 8 |
* @version 1 |
| 9 |
* @link https://e2pdf.com |
| 10 |
* @since 0.00.01 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Controller_E2pdf_License extends Helper_E2pdf_View { |
| 17 |
|
| 18 |
/** |
| 19 |
* @url admin.php?page=e2pdf-license |
| 20 |
*/ |
| 21 |
public function index_action() { |
| 22 |
|
| 23 |
$this->load_scripts(); |
| 24 |
$this->load_styles(); |
| 25 |
if ($this->helper->get('license')->get('error')) { |
| 26 |
$this->add_notification('error', $this->helper->get('license')->get('error')); |
| 27 |
} |
| 28 |
$this->view('license', $this->helper->get('license')); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Load javascript on license page |
| 33 |
*/ |
| 34 |
public function load_scripts() { |
| 35 |
|
| 36 |
wp_enqueue_script('jquery-ui-dialog'); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Load style on license page |
| 41 |
*/ |
| 42 |
public function load_styles() { |
| 43 |
|
| 44 |
wp_enqueue_style('plugin_name-admin-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css', false, false, false); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Change license key via ajax |
| 49 |
* action: wp_ajax_e2pdf_license_key |
| 50 |
* function: e2pdf_license_key |
| 51 |
* |
| 52 |
* @return json |
| 53 |
*/ |
| 54 |
public function ajax_change_license_key() { |
| 55 |
|
| 56 |
$data = $this->post->get('data'); |
| 57 |
|
| 58 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 59 |
$model_e2pdf_api->set(array( |
| 60 |
'action' => 'license/update', |
| 61 |
'data' => array( |
| 62 |
'license_key' => trim($data['license_key']) |
| 63 |
) |
| 64 |
)); |
| 65 |
$request = $model_e2pdf_api->request(); |
| 66 |
|
| 67 |
if (isset($request['error'])) { |
| 68 |
$this->add_notification('error', $request['error']); |
| 69 |
} else { |
| 70 |
$this->add_notification('update', __('License Key updated successfully', 'e2pdf')); |
| 71 |
} |
| 72 |
|
| 73 |
$response = array( |
| 74 |
'redirect' => $this->helper->get_url(array( |
| 75 |
'page' => 'e2pdf-license', |
| 76 |
) |
| 77 |
) |
| 78 |
); |
| 79 |
$this->json_response($response); |
| 80 |
} |
| 81 |
|
| 82 |
} |
| 83 |
|