PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.06.02
E2Pdf – Export Pdf Tool for WordPress v1.06.02
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 1.08.09 All 71 releases
e2pdf / classes / controller / e2pdf-settings.php

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

319 lines 10.7 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 }
101
102 /**
103 * @url admin.php?page=e2pdf-settings&action=adobesign
104 */
105 public function adobesign_action() {
106
107 if ($this->post->get()) {
108
109 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
110 $options = Model_E2pdf_Options::get_options(false, array('adobesign_group'));
111
112 foreach ($options as $group_key => $group) {
113 foreach ($group['options'] as $option_key => $option_value) {
114 if (array_key_exists($option_value['key'], $this->post->get())) {
115 update_option($option_value['key'], $this->post->get($option_value['key']));
116 }
117 }
118 }
119
120 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
121 $request = $model_e2pdf_adobesign->request_code();
122
123 if (isset($request['error'])) {
124 $this->add_notification('error', $request['error']);
125 } elseif (isset($request['redirect'])) {
126 $this->redirect($request['redirect']);
127 } else {
128 $this->add_notification('update', __('Settings saved', 'e2pdf'));
129 }
130 } elseif ($this->get->get('code') && $this->get->get('api_access_point')) {
131 update_option('e2pdf_adobesign_code', $this->get->get('code'));
132 update_option('e2pdf_adobesign_api_access_point', $this->get->get('api_access_point'));
133
134 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
135 $request = $model_e2pdf_adobesign->request_refresh_token();
136
137 if (isset($request['error'])) {
138 $this->add_notification('error', $request['error']);
139 } else {
140 $this->add_notification('update', __('App authorized successfully', 'e2pdf'));
141 }
142 $location = $this->helper->get_url(array('page' => 'e2pdf-settings', 'action' => 'adobesign'));
143 $this->redirect($location);
144 return;
145 }
146
147 $options = Model_E2pdf_Options::get_options(false, array('adobesign_group'));
148
149 $this->view('options', $options);
150 $groups = $this->get_groups();
151 $this->view('groups', $groups);
152 }
153
154 /**
155 * @url admin.php?page=e2pdf-settings&action=docusign
156 */
157 public function docusign_action() {
158
159 if ($this->post->get()) {
160
161 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
162 $options = Model_E2pdf_Options::get_options(false, array('docusign_group'));
163
164 foreach ($options as $group_key => $group) {
165 foreach ($group['options'] as $option_key => $option_value) {
166 if (array_key_exists($option_value['key'], $this->post->get())) {
167 update_option($option_value['key'], $this->post->get($option_value['key']));
168 }
169 }
170 }
171
172 $this->add_notification('update', __('Settings saved', 'e2pdf'));
173 }
174
175 $options = Model_E2pdf_Options::get_options(false, array('docusign_group'));
176
177 $this->view('options', $options);
178 $groups = $this->get_groups();
179 $this->view('groups', $groups);
180 }
181
182 public function extension_action() {
183
184 $group_key = $this->get->get('group');
185
186 if ($this->post->get()) {
187
188 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
189 $options = Model_E2pdf_Options::get_options(false, array($group_key));
190
191 foreach ($options as $group_key => $group) {
192 foreach ($group['options'] as $option_key => $option_value) {
193 if (array_key_exists($option_value['key'], $this->post->get())) {
194 update_option($option_value['key'], $this->post->get($option_value['key']));
195 }
196 }
197 }
198
199 $this->add_notification('update', __('Settings saved', 'e2pdf'));
200 }
201
202 $options = Model_E2pdf_Options::get_options(false, array($group_key));
203 $groups = $this->get_groups();
204
205 $this->view('options', $options);
206 $this->view('groups', $groups);
207 }
208
209 public function extensions_action() {
210
211 if ($this->post->get()) {
212
213 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
214
215 if (!$this->post->get('e2pdf_disabled_extensions')) {
216 update_option('e2pdf_disabled_extensions', array());
217 } else {
218 update_option('e2pdf_disabled_extensions', $this->post->get('e2pdf_disabled_extensions'));
219 }
220
221 $this->add_notification('update', __('Settings saved', 'e2pdf'));
222 }
223
224 $options = Model_E2pdf_Options::get_options(false, array('extensions_group'));
225 $groups = $this->get_groups();
226
227 $this->view('options', $options);
228 $this->view('groups', $groups);
229 }
230
231 /**
232 * Get options list
233 *
234 * @return array() - Options list
235 */
236 public function get_groups() {
237 $groups = Model_E2pdf_Options::get_options(false, array(
238 'static_group',
239 ), true);
240
241 return $groups;
242 }
243
244 /**
245 * Remove font via ajax
246 * action: wp_ajax_e2pdf_delete_font
247 * function: e2pdf_delete_font
248 *
249 * @return json
250 */
251 public function ajax_delete_font() {
252
253 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
254 $font = $this->post->get('data');
255
256 $model_e2pdf_font = new Model_E2pdf_Font();
257 $model_e2pdf_font->delete_font($font);
258
259 $response = array(
260 'redirect' => $this->helper->get_url(array(
261 'page' => 'e2pdf-settings',
262 'action' => 'fonts'
263 )
264 )
265 );
266
267 $this->add_notification('update', __('Font removed successfully', 'e2pdf'));
268 $this->json_response($response);
269 }
270
271 public function ajax_email() {
272 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
273
274 $data = $this->post->get('data');
275 $email = isset($data['email']) ? trim($data['email']) : '';
276 $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';
277
278
279 $model_e2pdf_api = new Model_E2pdf_Api();
280 $model_e2pdf_api->set(array(
281 'action' => 'common/email',
282 'data' => array(
283 'email' => $email,
284 'email_code' => $email_code,
285 'email_confirm' => isset($data['email_code'])
286 )
287 ));
288 $request = $model_e2pdf_api->request();
289
290
291
292 if (isset($request['error'])) {
293 if ($request['error'] === 'incorrect_email') {
294 $response = array(
295 'error' => __('E-mail address incorrect', 'e2pdf')
296 );
297 } elseif ($request['error'] === 'incorrect_code') {
298 $response = array(
299 'error' => __('Confirmation code incorrect', 'e2pdf')
300 );
301 } else {
302 $response = array(
303 'error' => $request['error']
304 );
305 }
306 } elseif (isset($request['success'])) {
307 $response = array(
308 'content' => $request['success']
309 );
310 if ($request['success'] == 'subscribed') {
311 update_option('e2pdf_email', $email);
312 }
313 }
314
315 $this->json_response($response);
316 }
317
318 }
319