PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.06
E2Pdf – Export Pdf Tool for WordPress v1.08.06
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
e2pdf / classes / model / e2pdf-api.php

e2pdf-api.php in E2Pdf – Export Pdf Tool for WordPress 1.08.06, at classes/model/e2pdf-api.php

153 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Api Model
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 Model_E2pdf_Api extends Model_E2pdf_Model {
17
18 protected $api = NULL;
19
20 function __construct() {
21 parent::__construct();
22 }
23
24 /**
25 * Submit API Request to Remote Server
26 *
27 * @param string $key - Return Value by Key
28 *
29 * @return mixed
30 */
31 public function request($key = false) {
32 if ($this->api->action) {
33
34 $data = array(
35 'api_url' => site_url(),
36 'api_license_key' => $this->get_license(),
37 'api_processor' => get_option('e2pdf_processor') ? get_option('e2pdf_processor') : 0,
38 );
39
40 $api_server = apply_filters('e2pdf_api_server', 'api.e2pdf.com');
41 $request_url = 'https://' . $api_server . '/' . $this->api->action;
42
43 $timeout = get_option('e2pdf_connection_timeout') === false ? 300 : get_option('e2pdf_connection_timeout');
44
45 $ch = curl_init($request_url);
46 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
47 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
48 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
49 if (!ini_get('safe_mode') && !ini_get('open_basedir')) {
50 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
51 }
52 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
53
54 if (!empty($this->api->data)) {
55 $data = array_merge($data, $this->api->data);
56 }
57
58 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
59
60 $json = curl_exec($ch);
61 $curl_errno = curl_errno($ch);
62 $curl_error = curl_error($ch);
63 curl_close($ch);
64
65 if ($curl_errno > 0) {
66 $response['error'] = "[{$curl_errno}] {$curl_error}";
67 } else {
68
69 if (($this->api->action === 'template/build' || $this->api->action === 'template/parse') && get_option('e2pdf_developer')) {
70 if (in_array($this->helper->get_ip(), Model_E2pdf_Options::get_option('e2pdf_developer_ips'))) {
71 $data = array(
72 'request_url' => $request_url,
73 'data' => $data,
74 'response' => $json
75 );
76 var_dump("<PRE>");
77 var_dump($data);
78 die();
79 }
80 }
81
82 $result = json_decode($json, true);
83 $response = $result['response'];
84
85
86 if (($this->api->action === 'common/activate' || $this->api->action === 'license/update') && isset($response['license_key'])) {
87 update_option('e2pdf_license', $response['license_key']);
88 }
89
90 if (empty($response)) {
91 $response['error'] = __("Something went wrong!", "e2pdf");
92 }
93 }
94
95 if ($key) {
96 if (isset($response[$key])) {
97 return $response[$key];
98 } else {
99 return false;
100 }
101 } else {
102 return $response;
103 }
104 }
105 return false;
106 }
107
108 /**
109 * Remove API Request options
110 */
111 public function flush() {
112 $this->api = null;
113 }
114
115 /**
116 * Set options for API Request
117 *
118 * @param string $key - Key
119 * @param mixed $value - Value
120 */
121 public function set($key, $value = false) {
122 if (!$this->api) {
123 $this->api = new stdClass();
124 }
125 if (is_array($key)) {
126 foreach ($key as $attr => $value) {
127 $this->api->$attr = $value;
128 }
129 } else {
130 $this->api->$key = $value;
131 }
132 }
133
134 /**
135 * Get License
136 *
137 * @return string - License Key
138 */
139 public function get_license() {
140 return get_option('e2pdf_license');
141 }
142
143 /**
144 * Get Domain
145 *
146 * @return string - Domain
147 */
148 public function get_domain() {
149 return site_url();
150 }
151
152 }
153