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

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