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

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

217 lines 6.9 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 public function extension_action() {
103
104 $group_key = $this->get->get('group');
105
106 if ($this->post->get()) {
107
108 $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
109 $options = Model_E2pdf_Options::get_options(false, array($group_key));
110
111 foreach ($options as $group_key => $group) {
112 foreach ($group['options'] as $option_key => $option_value) {
113 if (array_key_exists($option_value['key'], $this->post->get())) {
114 update_option($option_value['key'], $this->post->get($option_value['key']));
115 }
116 }
117 }
118
119 $this->add_notification('update', __('Settings saved', 'e2pdf'));
120 }
121
122 $options = Model_E2pdf_Options::get_options(false, array($group_key));
123 $groups = $this->get_groups();
124
125 $this->view('options', $options);
126 $this->view('groups', $groups);
127 }
128
129 /**
130 * Get options list
131 *
132 * @return array() - Options list
133 */
134 public function get_groups() {
135 $groups = Model_E2pdf_Options::get_options(false, array(
136 'static_group',
137 ), true);
138
139 return $groups;
140 }
141
142 /**
143 * Remove font via ajax
144 * action: wp_ajax_e2pdf_delete_font
145 * function: e2pdf_delete_font
146 *
147 * @return json
148 */
149 public function ajax_delete_font() {
150
151 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
152 $font = $this->post->get('data');
153
154 $model_e2pdf_font = new Model_E2pdf_Font();
155 $model_e2pdf_font->delete_font($font);
156
157 $response = array(
158 'redirect' => $this->helper->get_url(array(
159 'page' => 'e2pdf-settings',
160 'action' => 'fonts'
161 )
162 )
163 );
164
165 $this->add_notification('update', __('Font removed successfully', 'e2pdf'));
166 $this->json_response($response);
167 }
168
169 public function ajax_email() {
170 $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
171
172 $data = $this->post->get('data');
173 $email = isset($data['email']) ? trim($data['email']) : '';
174 $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';
175
176
177 $model_e2pdf_api = new Model_E2pdf_Api();
178 $model_e2pdf_api->set(array(
179 'action' => 'common/email',
180 'data' => array(
181 'email' => $email,
182 'email_code' => $email_code,
183 'email_confirm' => isset($data['email_code'])
184 )
185 ));
186 $request = $model_e2pdf_api->request();
187
188
189
190 if (isset($request['error'])) {
191 if ($request['error'] === 'incorrect_email') {
192 $response = array(
193 'error' => __('E-mail address incorrect', 'e2pdf')
194 );
195 } elseif ($request['error'] === 'incorrect_code') {
196 $response = array(
197 'error' => __('Confirmation code incorrect', 'e2pdf')
198 );
199 } else {
200 $response = array(
201 'error' => $request['error']
202 );
203 }
204 } elseif (isset($request['success'])) {
205 $response = array(
206 'content' => $request['success']
207 );
208 if ($request['success'] == 'subscribed') {
209 update_option('e2pdf_email', $email);
210 }
211 }
212
213 $this->json_response($response);
214 }
215
216 }
217