PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.53
E2Pdf – Export Pdf Tool for WordPress v1.32.53
1.32.53 1.32.51 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 All 74 releases
← All changes | classes/model/e2pdf-api.php +36 -27 1.32.18 → 1.32.53 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.52';
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 }
@@ -98,9 +105,11 @@
98 105 $curl_errno = curl_errno($ch);
99 106 $curl_error = curl_error($ch);
100 107 $curl_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
101 108 $curl_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
102 - curl_close($ch);
109 + if (PHP_VERSION_ID < 80000) {
110 + curl_close($ch);
111 + }
103 112 // phpcs:enable
104 113
105 114 if ($curl_errno > 0) {
106 115 if ($this->get_api_server() === $this->get_api_server($api_server)) {
@@ -124,19 +133,8 @@
124 133 // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
125 134 $response['file'] = base64_decode($response['file']);
126 135 }
127 136 }
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 137 if (empty($response)) {
140 138 if ($this->get_api_server() === $this->get_api_server($api_server)) {
141 139 $response['error'] = __('Something went wrong!', 'e2pdf');
142 140 } else {
@@ -151,8 +149,22 @@
151 149 } else {
152 150 return false;
153 151 }
154 152 } else {
153 + if ($api_action == 'template/build' || ($api_action == 'license/info' && $this->get('reload') === false)) {
154 + if (isset($response['error']) && $response['error'] == 'Site Url Not Found. Please try to "Reactivate" plugin.') {
155 + $license = $this->helper->load('license');
156 + if ($license && method_exists($license, 'reactivate') && $license->reactivate()) {
157 + return $this->request($key, $api_server);
158 + }
159 + }
160 + if (isset($response['error']) && $response['error'] == 'License Key does not match this site. Please correct License Key to continue usage.') {
161 + $license = $this->helper->load('license');
162 + if ($license && method_exists($license, 'restore') && $license->restore()) {
163 + return $this->request($key, $api_server);
164 + }
165 + }
166 + }
155 167 return $response;
156 168 }
157 169 }
158 170 return false;
@@ -185,18 +197,10 @@
185 197 }
186 198 return $api_server;
187 199 }
188 200
189 - // flush
190 - public function flush() {
191 - $this->api = null;
192 - }
193 -
194 201 // set
195 202 public function set($key, $value = false) {
196 - if (!$this->api) {
197 - $this->api = new stdClass();
198 - }
199 203 if (is_array($key)) {
200 204 foreach ($key as $attr => $value) {
201 205 $this->api->$attr = $value;
202 206 }
@@ -202,8 +206,13 @@
202 206 }
203 207 } else {
204 208 $this->api->$key = $value;
205 209 }
210 + return $this;
211 + }
212 +
213 + public function get($key) {
214 + return property_exists($this->api, $key) ? $this->api->$key : null;
206 215 }
207 216
208 217 // get license
209 218 public function get_license() {