| @@ -186,43 +186,36 @@ | ||
| 186 | 186 | */ |
| 187 | 187 | public function fonts_action() { |
| 188 | 188 | $model_e2pdf_font = new Model_E2pdf_Font(); |
| 189 | 189 | if ($this->post->get('_wpnonce')) { |
| 190 | - if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) { | |
| 191 | - $font = $this->files->get('font'); | |
| 192 | - $name = $font['name']; | |
| 193 | - $tmp = $font['tmp_name']; | |
| 194 | - $filename = pathinfo($name, PATHINFO_FILENAME); | |
| 195 | - $extension = strtolower(pathinfo($name, PATHINFO_EXTENSION)); | |
| 196 | - $name = $filename . '.' . $extension; | |
| 197 | - $fonts = $model_e2pdf_font->get_fonts(); | |
| 190 | + | |
| 191 | + if (!wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) { | |
| 192 | + wp_die($this->message('wp_verify_nonce_error')); | |
| 193 | + } | |
| 194 | + | |
| 195 | + $file = $this->helper->load('files')->upload($this->files->get('font'), $model_e2pdf_font->get_allowed_extensions()); | |
| 196 | + if (isset($file['error'])) { | |
| 197 | + $this->add_notification('error', $file['error']); | |
| 198 | + } else { | |
| 198 | 199 | $font_name = false; |
| 199 | 200 | $exist = false; |
| 200 | - if (in_array($extension, $model_e2pdf_font->get_allowed_extensions())) { | |
| 201 | - $font_name = $model_e2pdf_font->get_font_info(false, 4, $tmp); | |
| 202 | - if ($font_name) { | |
| 203 | - $exist = array_search($font_name, $fonts); | |
| 204 | - } | |
| 201 | + $fonts = $model_e2pdf_font->get_fonts(); | |
| 202 | + $font_name = $model_e2pdf_font->get_font_info(false, 4, $file['tmp_name']); | |
| 203 | + $name = pathinfo($file['name'], PATHINFO_FILENAME) . '.' . $file['ext']; | |
| 204 | + if ($font_name) { | |
| 205 | + $exist = array_search($font_name, $fonts); | |
| 205 | 206 | } |
| 206 | - if (!$tmp) { | |
| 207 | - $this->add_notification('error', __('Choose Font file to upload', 'e2pdf')); | |
| 208 | - } elseif ($font['error']) { | |
| 209 | - $this->add_notification('error', $font['error']); | |
| 210 | - } elseif (!in_array($extension, $model_e2pdf_font->get_allowed_extensions())) { | |
| 211 | - $this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.' . implode(', .', $model_e2pdf_font->get_allowed_extensions()))); | |
| 212 | - } elseif (!$font_name) { | |
| 207 | + if (!$font_name) { | |
| 213 | 208 | $this->add_notification('error', __('Invalid Type', 'e2pdf')); |
| 214 | 209 | } elseif (array_key_exists($name, $fonts) || $exist) { |
| 215 | 210 | $this->add_notification('error', __('A Font with this name already exists', 'e2pdf')); |
| 216 | - } elseif (move_uploaded_file($font['tmp_name'], $this->helper->get('fonts_dir') . $name)) { | |
| 217 | - if (file_exists($this->helper->get('fonts_dir') . $name)) { | |
| 211 | + } else { | |
| 212 | + if (!move_uploaded_file($file['tmp_name'], $this->helper->get('fonts_dir') . $name)) { | |
| 213 | + $this->add_notification('error', __('Failed to move uploaded file', 'e2pdf')); | |
| 214 | + } else { | |
| 218 | 215 | $this->add_notification('update', __('Font Uploaded', 'e2pdf')); |
| 219 | - } else { | |
| 220 | - $this->add_notification('error', __('Something went wrong!', 'e2pdf')); | |
| 221 | 216 | } |
| 222 | 217 | } |
| 223 | - } else { | |
| 224 | - wp_die($this->message('wp_verify_nonce_error')); | |
| 225 | 218 | } |
| 226 | 219 | } |
| 227 | 220 | |
| 228 | 221 | $fonts = $model_e2pdf_font->get_fonts(); |