PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
← All changes | classes/model/e2pdf-api.php +33 -26 1.32.171.32.49 View file →
@@ -14,12 +14,19 @@
14 14 class Model_E2pdf_Api extends Model_E2pdf_Model {
15 15
16 16 protected $api;
17 17
18 + public function __construct() {
19 + parent::__construct();
20 + $this->api = new stdClass();
21 + }
22 +
18 23 // request
19 24 public function request($key = false, $api_server = false) {
20 - if ($this->api->action) {
21 25
26 + $api_action = $this->get('action');
27 + if ($api_action) {
28 +
22 29 // fix for upgrade via dashboard -> updates
23 30 if (method_exists($this->helper, 'set_time_limit')) {
24 31 $this->helper->set_time_limit((int) get_option('e2pdf_request_timeout', '420'));
25 32 }
@@ -24,9 +31,9 @@
24 31 $this->helper->set_time_limit((int) get_option('e2pdf_request_timeout', '420'));
25 32 }
26 33
27 34 // fix for upgrade via dashboard -> updates
28 - if ($this->api->action == 'update/info' && !method_exists($this->helper, 'get_site_url')) {
35 + if ($api_action == 'update/info' && !method_exists($this->helper, 'get_site_url')) {
29 36 return [];
30 37 }
31 38
32 39 $api_protocol = get_option('e2pdf_api_protocol', '0');
@@ -33,9 +40,9 @@
33 40 $api_processor = get_option('e2pdf_debug', '0') && get_option('e2pdf_processor', '0') ? get_option('e2pdf_processor', '0') : '0';
34 41 if ($api_processor == '2') {
35 42 $api_version = '1.16.19';
36 43 } else {
37 - $api_version = '1.32.14';
44 + $api_version = '1.32.39';
38 45 }
39 46
40 47 $data = [
41 48 'api_url' => $this->helper->get_site_url(),
@@ -46,9 +53,9 @@
46 53 ];
47 54 if (!$api_server) {
48 55 $api_server = $this->get_api_server();
49 56 }
50 - $request_url = 'https://' . $api_server . '/' . $this->api->action;
57 + $request_url = 'https://' . $api_server . '/' . $api_action;
51 58
52 59 // phpcs:disable WordPress.WP.AlternativeFunctions
53 60 $ch = apply_filters('e2pdf_api_connection', curl_init($request_url));
54 61 curl_setopt($ch, CURLOPT_USERAGENT, $this->helper->get_site_url());
@@ -84,12 +91,12 @@
84 91 curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
85 92 }
86 93 }
87 94
88 - if (!empty($this->api->data)) {
89 - $data = array_merge($data, $this->api->data);
95 + if (!empty($this->get('data'))) {
96 + $data = array_merge($data, $this->get('data'));
90 97 }
91 - if ($this->api->action === 'template/upload2') {
98 + if ($api_action === 'template/upload2') {
92 99 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
93 100 } else {
94 101 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
95 102 }
@@ -124,19 +131,8 @@
124 131 // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
125 132 $response['file'] = base64_decode($response['file']);
126 133 }
127 134 }
128 -
129 - if (($this->api->action === 'common/activate' || $this->api->action === 'license/update' || $this->api->action === 'license/request') && !empty($response['license_key'])) {
130 - update_option('e2pdf_license', $response['license_key']);
131 - }
132 - if ($this->api->action === 'common/activate' && !empty($response['e2pdf_api']) && get_option('e2pdf_api') === false) {
133 - if ($response['e2pdf_api'] === 'api3.e2pdf.com') {
134 - update_option('e2pdf_api', 'api3.e2pdf.com');
135 - } else {
136 - update_option('e2pdf_api', 'api.e2pdf.com');
137 - }
138 - }
139 135 if (empty($response)) {
140 136 if ($this->get_api_server() === $this->get_api_server($api_server)) {
141 137 $response['error'] = __('Something went wrong!', 'e2pdf');
142 138 } else {
@@ -151,8 +147,22 @@
151 147 } else {
152 148 return false;
153 149 }
154 150 } else {
151 + if ($api_action == 'template/build' || ($api_action == 'license/info' && $this->get('reload') === false)) {
152 + if (isset($response['error']) && $response['error'] == 'Site Url Not Found. Please try to "Reactivate" plugin.') {
153 + $license = $this->helper->load('license');
154 + if ($license && method_exists($license, 'reactivate') && $license->reactivate()) {
155 + return $this->request($key, $api_server);
156 + }
157 + }
158 + if (isset($response['error']) && $response['error'] == 'License Key does not match this site. Please correct License Key to continue usage.') {
159 + $license = $this->helper->load('license');
160 + if ($license && method_exists($license, 'restore') && $license->restore()) {
161 + return $this->request($key, $api_server);
162 + }
163 + }
164 + }
155 165 return $response;
156 166 }
157 167 }
158 168 return false;
@@ -185,18 +195,10 @@
185 195 }
186 196 return $api_server;
187 197 }
188 198
189 - // flush
190 - public function flush() {
191 - $this->api = null;
192 - }
193 -
194 199 // set
195 200 public function set($key, $value = false) {
196 - if (!$this->api) {
197 - $this->api = new stdClass();
198 - }
199 201 if (is_array($key)) {
200 202 foreach ($key as $attr => $value) {
201 203 $this->api->$attr = $value;
202 204 }
@@ -202,8 +204,13 @@
202 204 }
203 205 } else {
204 206 $this->api->$key = $value;
205 207 }
208 + return $this;
209 + }
210 +
211 + public function get($key) {
212 + return property_exists($this->api, $key) ? $this->api->$key : null;
206 213 }
207 214
208 215 // get license
209 216 public function get_license() {