| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* File: /controller/frontend/e2pdf-rpc-v1.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_Frontend_E2pdf_Rpc_V1 extends Helper_E2pdf_View { |
| 15 |
|
| 16 |
// zapier rpc service |
| 17 |
public function zapier($rpc) { |
| 18 |
if (is_a($rpc, 'Model_E2pdf_Rpc')) { |
| 19 |
switch ($rpc->get('action')) { |
| 20 |
case 'auth': |
| 21 |
if ($rpc->get_arg('api_key') == get_option('e2pdf_zapier_api_key')) { |
| 22 |
wp_send_json_success(); |
| 23 |
} else { |
| 24 |
wp_send_json_error(null, 401); |
| 25 |
} |
| 26 |
break; |
| 27 |
default: |
| 28 |
break; |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// adobe rpc service |
| 34 |
public function adobe($rpc) { |
| 35 |
if (is_a($rpc, 'Model_E2pdf_Rpc')) { |
| 36 |
switch ($rpc->get('action')) { |
| 37 |
case 'auth': |
| 38 |
if ($rpc->get_arg('api_key') == get_option('e2pdf_adobe_api_key')) { |
| 39 |
if ($rpc->get_arg('code')) { |
| 40 |
$this->redirect( |
| 41 |
$this->helper->get_url( |
| 42 |
[ |
| 43 |
'page' => 'e2pdf-integrations', |
| 44 |
'action' => 'adobesign', |
| 45 |
'code' => $rpc->get_arg('code'), |
| 46 |
'_wpnonce' => wp_create_nonce('e2pdf_adobe'), |
| 47 |
] |
| 48 |
) |
| 49 |
); |
| 50 |
} |
| 51 |
} |
| 52 |
break; |
| 53 |
default: |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// gdrive rpc service |
| 60 |
public function gdrive($rpc) { |
| 61 |
if (is_a($rpc, 'Model_E2pdf_Rpc')) { |
| 62 |
switch ($rpc->get('action')) { |
| 63 |
case 'auth': |
| 64 |
if ($rpc->get_arg('api_key') == get_option('e2pdf_gdrive_api_key')) { |
| 65 |
if ($rpc->get_arg('code') || $rpc->get_arg('error')) { |
| 66 |
if ($rpc->get_arg('code')) { |
| 67 |
(new Model_E2pdf_Gdrive())->get_token($rpc->get_arg('code')); |
| 68 |
} |
| 69 |
$this->redirect( |
| 70 |
$this->helper->get_url( |
| 71 |
[ |
| 72 |
'page' => 'e2pdf-integrations', |
| 73 |
'action' => 'gdrive', |
| 74 |
] |
| 75 |
) |
| 76 |
); |
| 77 |
} |
| 78 |
} else { |
| 79 |
wp_send_json_error(null, 401); |
| 80 |
} |
| 81 |
break; |
| 82 |
default: |
| 83 |
break; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public function restore($rpc) { |
| 89 |
if (is_a($rpc, 'Model_E2pdf_Rpc')) { |
| 90 |
switch ($rpc->get('action')) { |
| 91 |
case 'request': |
| 92 |
if (get_transient('e2pdf_restore_key') && $rpc->get_arg('restore_key') === get_transient('e2pdf_restore_key')) { |
| 93 |
wp_send_json_success([ |
| 94 |
'restore_key' => get_transient('e2pdf_restore_key') |
| 95 |
]); |
| 96 |
} else { |
| 97 |
wp_send_json_error(null, 401); |
| 98 |
} |
| 99 |
break; |
| 100 |
default: |
| 101 |
break; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|