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 / controller / e2pdf-settings.php

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

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