PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.00
E2Pdf – Export Pdf Tool for WordPress v1.08.00
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 / controller / e2pdf-settings.php

e2pdf-settings.php in E2Pdf – Export Pdf Tool for WordPress 1.08.00, at classes/controller/e2pdf-settings.php

320 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Settings Controller
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 Controller_E2pdf_Settings extends Helper_E2pdf_View {
17
18 /**
19 * @url admin.php?page=e2pdf-settings
20 */
21 public function index_action() {
22 if ($this->post->get()) {
23 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
24 $options = Model_E2pdf_Options::get_options(false, array('common_group'));
25 foreach ($options as $group_key => $group) {
26 foreach ($group['options'] as $option_key => $option_value) {
27 if (array_key_exists($option_value['key'], $this->post->get())) {
28 update_option($option_value['key'], $this->post->get($option_value['key']));
29 }
30 }
31 }
32 $this->add_notification('update', __('Settings saved', 'e2pdf'));
33 }
34
35 $options = Model_E2pdf_Options::get_options(false, array('common_group'));
36 $groups = $this->get_groups();
37
38 $this->view('options', $options);
39 $this->view('groups', $groups);
40 }
41
42 /**
43 * @url admin.php?page=e2pdf-settings&action=fonts
44 */
45 public function fonts_action() {
46
47 $model_e2pdf_font = new Model_E2pdf_Font();
48 $groups = $this->get_groups();
49
50 if ($this->post->get()) {
51 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
52
53 $allowed_ext = array(
54 'ttf'
55 );
56
57 $font = $this->files->get('font');
58
59 $name = $font['name'];
60 $tmp = $font['tmp_name'];
61
62
63 $filename = pathinfo($name, PATHINFO_FILENAME);
64 $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
65 $name = $filename . "." . $ext;
66
67 $fonts = $model_e2pdf_font->get_fonts();
68
69 $font_info = false;
70 $exist = false;
71
72 if (in_array($ext, $allowed_ext)) {
73 $font_info = $model_e2pdf_font->get_font_info(false, 4, $tmp);
74 if ($font_info) {
75 $exist = array_search($font_info, $fonts);
76 }
77 }
78
79 if (!$tmp) {
80 $this->add_notification('error', __('Please choose font to upload', 'e2pdf'));
81 } else if ($font['error']) {
82 $this->add_notification('error', $font['error']);
83 } elseif (!in_array($ext, $allowed_ext)) {
84 $this->add_notification('error', __('Incorrect file extension', 'e2pdf'));
85 } elseif (!$font_info) {
86 $this->add_notification('error', __('Incompatible type', 'e2pdf'));
87 } elseif (array_key_exists($name, $fonts)) {
88 $this->add_notification('error', __('Font with this filename already exists', 'e2pdf'));
89 } elseif ($exist) {
90 $this->add_notification('error', __('Font with this name already exists', 'e2pdf'));
91 } elseif (move_uploaded_file($font['tmp_name'], $this->helper->get('fonts_dir') . $name)) {
92 $this->add_notification('update', __('Font uploaded successfully', 'e2pdf'));
93 }
94 }
95
96 $fonts = $model_e2pdf_font->get_fonts();
97
98 $this->view('fonts', $fonts);
99 $this->view('groups', $groups);
100 $this->view('upload_max_filesize', $this->helper->load('files')->get_upload_max_filesize());
101 }
102
103 /**
104 * @url admin.php?page=e2pdf-settings&action=adobesign
105 */
106 public function adobesign_action() {
107
108 if ($this->post->get()) {
109
110 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
111 $options = Model_E2pdf_Options::get_options(false, array('adobesign_group'));
112
113 foreach ($options as $group_key => $group) {
114 foreach ($group['options'] as $option_key => $option_value) {
115 if (array_key_exists($option_value['key'], $this->post->get())) {
116 update_option($option_value['key'], $this->post->get($option_value['key']));
117 }
118 }
119 }
120
121 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
122 $request = $model_e2pdf_adobesign->request_code();
123
124 if (isset($request['error'])) {
125 $this->add_notification('error', $request['error']);
126 } elseif (isset($request['redirect'])) {
127 $this->redirect($request['redirect']);
128 } else {
129 $this->add_notification('update', __('Settings saved', 'e2pdf'));
130 }
131 } elseif ($this->get->get('code') && $this->get->get('api_access_point')) {
132 update_option('e2pdf_adobesign_code', $this->get->get('code'));
133 update_option('e2pdf_adobesign_api_access_point', $this->get->get('api_access_point'));
134
135 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
136 $request = $model_e2pdf_adobesign->request_refresh_token();
137
138 if (isset($request['error'])) {
139 $this->add_notification('error', $request['error']);
140 } else {
141 $this->add_notification('update', __('App authorized successfully', 'e2pdf'));
142 }
143 $location = $this->helper->get_url(array('page' => 'e2pdf-settings', 'action' => 'adobesign'));
144 $this->redirect($location);
145 return;
146 }
147
148 $options = Model_E2pdf_Options::get_options(false, array('adobesign_group'));
149
150 $this->view('options', $options);
151 $groups = $this->get_groups();
152 $this->view('groups', $groups);
153 }
154
155 /**
156 * @url admin.php?page=e2pdf-settings&action=docusign
157 */
158 public function docusign_action() {
159
160 if ($this->post->get()) {
161
162 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
163 $options = Model_E2pdf_Options::get_options(false, array('docusign_group'));
164
165 foreach ($options as $group_key => $group) {
166 foreach ($group['options'] as $option_key => $option_value) {
167 if (array_key_exists($option_value['key'], $this->post->get())) {
168 update_option($option_value['key'], $this->post->get($option_value['key']));
169 }
170 }
171 }
172
173 $this->add_notification('update', __('Settings saved', 'e2pdf'));
174 }
175
176 $options = Model_E2pdf_Options::get_options(false, array('docusign_group'));
177
178 $this->view('options', $options);
179 $groups = $this->get_groups();
180 $this->view('groups', $groups);
181 }
182
183 public function extension_action() {
184
185 $group_key = $this->get->get('group');
186
187 if ($this->post->get()) {
188
189 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
190 $options = Model_E2pdf_Options::get_options(false, array($group_key));
191
192 foreach ($options as $group_key => $group) {
193 foreach ($group['options'] as $option_key => $option_value) {
194 if (array_key_exists($option_value['key'], $this->post->get())) {
195 update_option($option_value['key'], $this->post->get($option_value['key']));
196 }
197 }
198 }
199
200 $this->add_notification('update', __('Settings saved', 'e2pdf'));
201 }
202
203 $options = Model_E2pdf_Options::get_options(false, array($group_key));
204 $groups = $this->get_groups();
205
206 $this->view('options', $options);
207 $this->view('groups', $groups);
208 }
209
210 public function extensions_action() {
211
212 if ($this->post->get()) {
213
214 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
215
216 if (!$this->post->get('e2pdf_disabled_extensions')) {
217 update_option('e2pdf_disabled_extensions', array());
218 } else {
219 update_option('e2pdf_disabled_extensions', $this->post->get('e2pdf_disabled_extensions'));
220 }
221
222 $this->add_notification('update', __('Settings saved', 'e2pdf'));
223 }
224
225 $options = Model_E2pdf_Options::get_options(false, array('extensions_group'));
226 $groups = $this->get_groups();
227
228 $this->view('options', $options);
229 $this->view('groups', $groups);
230 }
231
232 /**
233 * Get options list
234 *
235 * @return array() - Options list
236 */
237 public function get_groups() {
238 $groups = Model_E2pdf_Options::get_options(false, array(
239 'static_group',
240 ), true);
241
242 return $groups;
243 }
244
245 /**
246 * Remove font via ajax
247 * action: wp_ajax_e2pdf_delete_font
248 * function: e2pdf_delete_font
249 *
250 * @return json
251 */
252 public function ajax_delete_font() {
253
254 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
255 $font = $this->post->get('data');
256
257 $model_e2pdf_font = new Model_E2pdf_Font();
258 $model_e2pdf_font->delete_font($font);
259
260 $response = array(
261 'redirect' => $this->helper->get_url(array(
262 'page' => 'e2pdf-settings',
263 'action' => 'fonts'
264 )
265 )
266 );
267
268 $this->add_notification('update', __('Font removed successfully', 'e2pdf'));
269 $this->json_response($response);
270 }
271
272 public function ajax_email() {
273 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
274
275 $data = $this->post->get('data');
276 $email = isset($data['email']) ? trim($data['email']) : '';
277 $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';
278
279
280 $model_e2pdf_api = new Model_E2pdf_Api();
281 $model_e2pdf_api->set(array(
282 'action' => 'common/email',
283 'data' => array(
284 'email' => $email,
285 'email_code' => $email_code,
286 'email_confirm' => isset($data['email_code'])
287 )
288 ));
289 $request = $model_e2pdf_api->request();
290
291
292
293 if (isset($request['error'])) {
294 if ($request['error'] === 'incorrect_email') {
295 $response = array(
296 'error' => __('E-mail address incorrect', 'e2pdf')
297 );
298 } elseif ($request['error'] === 'incorrect_code') {
299 $response = array(
300 'error' => __('Confirmation code incorrect', 'e2pdf')
301 );
302 } else {
303 $response = array(
304 'error' => $request['error']
305 );
306 }
307 } elseif (isset($request['success'])) {
308 $response = array(
309 'content' => $request['success']
310 );
311 if ($request['success'] == 'subscribed') {
312 update_option('e2pdf_email', $email);
313 }
314 }
315
316 $this->json_response($response);
317 }
318
319 }
320