PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.03.07
E2Pdf – Export Pdf Tool for WordPress v1.03.07
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.03.07, at classes/controller/e2pdf-settings.php

297 lines 10.0 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 /**
210 * Get options list
211 *
212 * @return array() - Options list
213 */
214 public function get_groups() {
215 $groups = Model_E2pdf_Options::get_options(false, array(
216 'static_group',
217 ), true);
218
219 return $groups;
220 }
221
222 /**
223 * Remove font via ajax
224 * action: wp_ajax_e2pdf_delete_font
225 * function: e2pdf_delete_font
226 *
227 * @return json
228 */
229 public function ajax_delete_font() {
230
231 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
232 $font = $this->post->get('data');
233
234 $model_e2pdf_font = new Model_E2pdf_Font();
235 $model_e2pdf_font->delete_font($font);
236
237 $response = array(
238 'redirect' => $this->helper->get_url(array(
239 'page' => 'e2pdf-settings',
240 'action' => 'fonts'
241 )
242 )
243 );
244
245 $this->add_notification('update', __('Font removed successfully', 'e2pdf'));
246 $this->json_response($response);
247 }
248
249 public function ajax_email() {
250 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
251
252 $data = $this->post->get('data');
253 $email = isset($data['email']) ? trim($data['email']) : '';
254 $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';
255
256
257 $model_e2pdf_api = new Model_E2pdf_Api();
258 $model_e2pdf_api->set(array(
259 'action' => 'common/email',
260 'data' => array(
261 'email' => $email,
262 'email_code' => $email_code,
263 'email_confirm' => isset($data['email_code'])
264 )
265 ));
266 $request = $model_e2pdf_api->request();
267
268
269
270 if (isset($request['error'])) {
271 if ($request['error'] === 'incorrect_email') {
272 $response = array(
273 'error' => __('E-mail address incorrect', 'e2pdf')
274 );
275 } elseif ($request['error'] === 'incorrect_code') {
276 $response = array(
277 'error' => __('Confirmation code incorrect', 'e2pdf')
278 );
279 } else {
280 $response = array(
281 'error' => $request['error']
282 );
283 }
284 } elseif (isset($request['success'])) {
285 $response = array(
286 'content' => $request['success']
287 );
288 if ($request['success'] == 'subscribed') {
289 update_option('e2pdf_email', $email);
290 }
291 }
292
293 $this->json_response($response);
294 }
295
296 }
297