PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.15
E2Pdf – Export Pdf Tool for WordPress v1.32.15
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-templates.php

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

2,612 lines 119.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 Templates Controller
5 * @copyright Copyright 2017 https://e2pdf.com
6 * @license GPLv3
7 * @version 1
8 * @link https://e2pdf.com
9 * @since 0.00.01
10 */
11 if (!defined('ABSPATH')) {
12 die('Access denied.');
13 }
14
15 class Controller_E2pdf_Templates extends Helper_E2pdf_View {
16
17 /**
18 * @url admin.php?page=e2pdf-templates
19 */
20 public function index_action() {
21 if ($this->post->get('screenoptionnonce')) {
22 if (wp_verify_nonce($this->post->get('screenoptionnonce'), 'screen-options-nonce')) {
23 $this->screen_action();
24 } else {
25 wp_die($this->message('wp_verify_nonce_error'));
26 }
27 } elseif ($this->post->get('_wpnonce')) {
28 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) {
29 if ($this->post->get('action') == '-1' && $this->post->get('action2') == '-1') {
30 if ($this->post->get('s')) {
31 $location = $this->helper->get_url(
32 array(
33 'page' => 'e2pdf-templates',
34 'status' => $this->get->get('status'),
35 'orderby' => $this->get->get('orderby'),
36 'order' => $this->get->get('order'),
37 's' => $this->post->get('s'),
38 )
39 );
40 } else {
41 $location = $this->helper->get_url(
42 array(
43 'page' => 'e2pdf-templates',
44 'status' => $this->get->get('status'),
45 'orderby' => $this->get->get('orderby'),
46 'order' => $this->get->get('order'),
47 )
48 );
49 }
50 $this->redirect($location);
51 } else {
52 $action = $this->post->get('action') != '-1' ? $this->post->get('action') : $this->post->get('action2');
53 if ($this->post->get('post')) {
54 if ($action == 'trash') {
55 foreach ($this->post->get('post') as $key => $value) {
56 $this->trash_template($value);
57 }
58 $this->add_notification('update', sprintf(__('Trashed: %d', 'e2pdf'), count($this->post->get('post'))));
59 } elseif ($action == 'activate') {
60 foreach ($this->post->get('post') as $key => $value) {
61 $this->activate_template($value);
62 }
63 $this->add_notification('update', sprintf(__('Activated: %d', 'e2pdf'), count($this->post->get('post'))));
64 } elseif ($action == 'deactivate') {
65 foreach ($this->post->get('post') as $key => $value) {
66 $this->deactivate_template($value);
67 }
68 $this->add_notification('update', sprintf(__('Deactivated: %d', 'e2pdf'), count($this->post->get('post'))));
69 } elseif ($action == 'restore') {
70 foreach ($this->post->get('post') as $key => $value) {
71 $this->restore_template($value);
72 }
73 $this->add_notification('update', sprintf(__('Restored: %d', 'e2pdf'), count($this->post->get('post'))));
74 } elseif ($action == 'delete') {
75 foreach ($this->post->get('post') as $key => $value) {
76 $this->delete_template($value);
77 }
78 $this->add_notification('update', sprintf(__('Deleted: %d', 'e2pdf'), count($this->post->get('post'))));
79 }
80 $this->helper->get('license')->reload_license();
81 }
82 }
83 } else {
84 wp_die($this->message('wp_verify_nonce_error'));
85 }
86 }
87 }
88
89 /**
90 * @url admin.php?page=e2pdf-templates&action=view&id=$id
91 * @return file
92 */
93 public function view_action() {
94 if ($this->get->get('id')) {
95 $template = new Model_E2pdf_Template();
96 if ($template->load($this->get->get('id'))) {
97 $pages = $template->get('pages');
98 foreach ($pages as $page_key => $page) {
99 if (!empty($page['elements'])) {
100 foreach ($page['elements'] as $element_key => $element) {
101 if (isset($element['type'])) {
102 switch ($element['type']) {
103 case 'e2pdf-image':
104 if (isset($element['properties']['quality']) && $element['properties']['quality']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
105 } else {
106 $element['properties']['quality'] = $template->get('optimization');
107 $pages[$page_key]['elements'][$element_key]['properties']['quality'] = $template->get('optimization');
108 }
109 if ($image = $this->helper->load('image')->get_image($element['value'], null, $element)) {
110 $pages[$page_key]['elements'][$element_key]['value'] = $image;
111 } else {
112 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/upload.svg');
113 $pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1';
114 }
115 break;
116 case 'e2pdf-signature':
117 $esig = isset($element['properties']['esig']) && $element['properties']['esig'] ? true : false;
118 if (!$esig) {
119 if ($image = $this->helper->load('image')->get_image($element['value'])) {
120 $pages[$page_key]['elements'][$element_key]['value'] = $image;
121 } else {
122 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/signature.svg');
123 $pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1';
124 }
125 }
126 break;
127 case 'e2pdf-qrcode':
128 $pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image';
129 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/qrcode.svg');
130 $pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1';
131 break;
132 case 'e2pdf-barcode':
133 $pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image';
134 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/barcode.svg');
135 $pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1';
136 break;
137 case 'e2pdf-graph':
138 $pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image';
139 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/graph.svg');
140 $pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1';
141 break;
142 case 'e2pdf-html':
143 if (isset($pages[$page_key]['elements'][$element_key]['properties']['hide_page_if_empty'])) {
144 unset($pages[$page_key]['elements'][$element_key]['properties']['hide_page_if_empty']);
145 }
146 if (isset($pages[$page_key]['elements'][$element_key]['properties']['hide_if_empty'])) {
147 unset($pages[$page_key]['elements'][$element_key]['properties']['hide_if_empty']);
148 }
149 if (isset($element['properties']['nl2br']) && $element['properties']['nl2br']) {
150 $element['value'] = nl2br($element['value']);
151 }
152 if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) {
153 $element['value'] = $this->helper->load('properties')->html_worker(
154 $element['value']
155 );
156 }
157 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('filter')->filter_html_tags(
158 $element['value']
159 );
160 break;
161 case 'e2pdf-page-number':
162 if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) {
163 $element['value'] = $this->helper->load('properties')->html_worker(
164 $element['value']
165 );
166 }
167 $pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('filter')->filter_html_tags(
168 $element['value']
169 );
170 break;
171 default:
172 break;
173 }
174 }
175 }
176 }
177 }
178
179 $template->set('pages', $pages);
180 $request = $template->render();
181
182 if (isset($request['error'])) {
183 $this->add_notification('error', $request['error']);
184 $this->render('blocks', 'notifications');
185 } else {
186 $this->download_response($template->get('format'), $request['file'], $template->get_name(), 'inline');
187 exit;
188 }
189 } else {
190 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
191 $this->render('blocks', 'notifications');
192 }
193 } else {
194 $location = $this->helper->get_url(
195 array(
196 'page' => 'e2pdf',
197 )
198 );
199 $this->redirect($location);
200 }
201 }
202
203 /**
204 * @url admin.php?page=e2pdf-templates&action=preview
205 */
206 public function preview_action() {
207 $preview = array();
208 if ($this->post->get('preview')) {
209 $preview = json_decode(stripslashes($this->post->get('preview')), true);
210 }
211 if (empty($preview)) {
212 $this->close_tab_response();
213 } else {
214 $data = $preview;
215 $pages = $preview['pages'];
216 unset($preview['pages']);
217 if (wp_verify_nonce(isset($preview['_wpnonce']) ? $preview['_wpnonce'] : '', 'e2pdf_templates')) {
218 $template = new Model_E2pdf_Template();
219 foreach ($data as $key => $value) {
220 $template->set($key, $value);
221 }
222 $template->set('uid', $template->get('uid', true));
223 $template->set('activated', $template->get('activated', true));
224
225 $preview_pages = array();
226 foreach ($pages as $page_key => $page) {
227 $new_page = new Model_E2pdf_Page();
228 foreach ($page as $page_set_key => $page_set_value) {
229 $new_page->set($page_set_key, $page_set_value);
230 }
231 $new_page->set('page_id', $page_key);
232
233 $elements = array();
234 foreach ($page['elements'] as $element_key => $element) {
235 if (isset($element['type'])) {
236 switch ($element['type']) {
237 case 'e2pdf-image':
238 if (isset($element['properties']['quality']) && $element['properties']['quality']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
239 } else {
240 $element['properties']['quality'] = $template->get('optimization');
241 $pages[$page_key]['elements'][$element_key]['properties']['quality'] = $template->get('optimization');
242 }
243 if ($image = $this->helper->load('image')->get_image($element['value'], null, $element)) {
244 $element['value'] = $image;
245 } else {
246 $element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/upload.svg');
247 $element['properties']['preview'] = '1';
248 }
249 break;
250 case 'e2pdf-signature':
251 $esig = isset($element['properties']['esig']) && $element['properties']['esig'] ? true : false;
252 if (!$esig) {
253 if ($image = $this->helper->load('image')->get_image($element['value'])) {
254 $element['value'] = $image;
255 } else {
256 $element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/signature.svg');
257 $element['properties']['preview'] = '1';
258 }
259 }
260 break;
261 case 'e2pdf-qrcode':
262 $element['type'] = 'e2pdf-image';
263 $element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/qrcode.svg');
264 $element['properties']['preview'] = '1';
265 break;
266 case 'e2pdf-barcode':
267 $element['type'] = 'e2pdf-image';
268 $element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/barcode.svg');
269 $element['properties']['preview'] = '1';
270 break;
271 case 'e2pdf-graph':
272 $element['type'] = 'e2pdf-image';
273 $element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/graph.svg');
274 $element['properties']['preview'] = '1';
275 break;
276 case 'e2pdf-html':
277 if (isset($element['properties']['hide_page_if_empty'])) {
278 unset($element['properties']['hide_page_if_empty']);
279 }
280 if (isset($element['properties']['hide_if_empty'])) {
281 unset($element['properties']['hide_if_empty']);
282 }
283 if (isset($element['properties']['nl2br']) && $element['properties']['nl2br']) {
284 $element['value'] = nl2br($element['value']);
285 }
286 if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) {
287 $element['value'] = $this->helper->load('properties')->html_worker(
288 $element['value']
289 );
290 }
291 $element['value'] = $this->helper->load('filter')->filter_html_tags(
292 $element['value']
293 );
294 break;
295 case 'e2pdf-page-number':
296 $element['value'] = str_replace(array('[e2pdf-page-number]', '[e2pdf-page-total]'), array('e2pdf-page-number', 'e2pdf-page-total'), $element['value']);
297 if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) {
298 $element['value'] = $this->helper->load('properties')->html_worker(
299 $element['value']
300 );
301 }
302 $element['value'] = $this->helper->load('filter')->filter_html_tags(
303 $element['value']
304 );
305 break;
306 default:
307 break;
308 }
309 }
310
311 $new_element = new Model_E2pdf_Element();
312 foreach ($element as $element_set_key => $element_set_value) {
313 $new_element->set($element_set_key, $element_set_value);
314 }
315
316 if (isset($element['properties'])) {
317 $element_properties = $element['properties'];
318 } else {
319 $element_properties = array();
320 }
321 $new_element->set('properties', $element_properties);
322 $elements[] = $new_element->get_element();
323 }
324
325 $new_page->set('elements', $elements);
326 $preview_pages[] = $new_page->get_page();
327 }
328
329 $template->set('pages', $preview_pages);
330 $template->load_fonts();
331
332 $type = isset($_GET['type']) ? sanitize_text_field(wp_unslash($_GET['type'])) : false;
333 if ($type == 'php') {
334 $request = $template->render('php');
335 if (isset($request['error'])) {
336 $this->add_notification('error', $request['error']);
337 $this->render('blocks', 'notifications');
338 } else {
339 $this->download_response('php', $request['file'], 'template');
340 exit;
341 }
342 } else {
343 $request = $template->render();
344 if (isset($request['error'])) {
345 $this->add_notification('error', $request['error']);
346 $this->render('blocks', 'notifications');
347 } else {
348 $this->download_response($template->get('format'), $request['file'], $template->get_name(), 'inline', false, true);
349 exit;
350 }
351 }
352 } else {
353 wp_die($this->message('wp_verify_nonce_error'));
354 }
355 }
356 }
357
358 /**
359 * @url admin.php?page=e2pdf-templates&action=create
360 */
361 public function create_action() {
362 $template = new Model_E2pdf_Template();
363 $this->load_metaboxes();
364 $this->load_scripts();
365 $this->load_styles();
366 $this->view('license', $this->helper->get('license'));
367 $this->view('template', $template);
368 }
369
370 /**
371 * @url admin.php?page=e2pdf-templates&action=edit&id=$id
372 */
373 public function edit_action() {
374 if ($this->get->get('id')) {
375 $template = new Model_E2pdf_Template();
376 $revision_id = (int) $this->get->get('revision_id');
377 if ($template->load($this->get->get('id'), true, $revision_id)) {
378 if (is_array($this->helper->get('license')->get('activated_templates'))) {
379 if ($template->get('activated') && !in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) {
380 $template->deactivate();
381 } elseif (!$template->get('activated') && in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) {
382 $template->activate();
383 }
384 }
385 $this->view('license', $this->helper->get('license'));
386 $this->view('template', $template);
387 $this->load_metaboxes();
388 $this->load_scripts();
389 $this->load_styles($template->get('extension'));
390 } else {
391 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
392 $this->render('blocks', 'notifications');
393 }
394 } else {
395 $location = $this->helper->get_url(
396 array(
397 'page' => 'e2pdf-templates',
398 )
399 );
400 $this->redirect($location);
401 }
402 }
403
404 /**
405 * @url admin.php?page=e2pdf-templates&action=trash&id=$id
406 */
407 public function trash_action() {
408 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
409 if ($this->get->get('id')) {
410 $this->trash_template($this->get->get('id'));
411 $this->add_notification('update', sprintf(__('Trashed: %d', 'e2pdf'), '1'));
412 }
413 } else {
414 wp_die($this->message('wp_verify_nonce_error'));
415 }
416 $location = $this->helper->get_url(
417 array(
418 'page' => 'e2pdf-templates',
419 'status' => $this->get->get('status'),
420 'orderby' => $this->get->get('orderby'),
421 'order' => $this->get->get('order'),
422 's' => $this->get->get('s'),
423 )
424 );
425 $this->redirect($location);
426 }
427
428 /**
429 * @url admin.php?page=e2pdf-templates&action=restore&id=$id&status=$status
430 */
431 public function restore_action() {
432 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
433 if ($this->get->get('id')) {
434 $this->restore_template($this->get->get('id'));
435 $this->add_notification('update', sprintf(__('Restored: %d', 'e2pdf'), '1'));
436 }
437 } else {
438 wp_die($this->message('wp_verify_nonce_error'));
439 }
440 $location = $this->helper->get_url(
441 array(
442 'page' => 'e2pdf-templates',
443 'status' => $this->get->get('status'),
444 'orderby' => $this->get->get('orderby'),
445 'order' => $this->get->get('order'),
446 's' => $this->get->get('s'),
447 )
448 );
449 $this->redirect($location);
450 }
451
452 /**
453 * @url admin.php?page=e2pdf-templates&action=delete&id=$id&status=$status
454 */
455 public function delete_action() {
456 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
457 if ($this->get->get('id')) {
458 $this->delete_template($this->get->get('id'));
459 $this->add_notification('update', sprintf(__('Deleted: %d', 'e2pdf'), '1'));
460 }
461 } else {
462 wp_die($this->message('wp_verify_nonce_error'));
463 }
464 $location = $this->helper->get_url(
465 array(
466 'page' => 'e2pdf-templates',
467 'status' => $this->get->get('status'),
468 'orderby' => $this->get->get('orderby'),
469 'order' => $this->get->get('order'),
470 's' => $this->get->get('s'),
471 )
472 );
473 $this->redirect($location);
474 }
475
476 /**
477 * @url admin.php?page=e2pdf-templates&action=duplicate&id=$id
478 */
479 public function duplicate_action() {
480 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
481 if ($this->get->get('id')) {
482 $this->duplicate_template($this->get->get('id'));
483 $this->add_notification('update', sprintf(__('Duplicated: %d', 'e2pdf'), '1'));
484 }
485 } else {
486 wp_die($this->message('wp_verify_nonce_error'));
487 }
488 $location = $this->helper->get_url(
489 array(
490 'page' => 'e2pdf-templates',
491 'status' => $this->get->get('status'),
492 'orderby' => $this->get->get('orderby'),
493 'order' => $this->get->get('order'),
494 's' => $this->get->get('s'),
495 )
496 );
497 $this->redirect($location);
498 }
499
500 /**
501 * @url admin.php?page=e2pdf-templates&action=import
502 */
503 public function import_action() {
504 if ($this->post->get('_wpnonce')) {
505
506 if (!wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) {
507 wp_die($this->message('wp_verify_nonce_error'));
508 }
509
510 $errors = array();
511 $import = $this->files->get('template');
512 $name = $import['name'];
513 $tmp = $import['tmp_name'];
514 $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
515 if (!$tmp) {
516 $this->add_notification('error', __('Choose Template file to upload', 'e2pdf'));
517 } elseif ($import['error']) {
518 $this->add_notification('error', $import['error']);
519 } elseif (!in_array($ext, array('xml'))) {
520 $this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.xml'));
521 } elseif ($import['type'] != 'text/xml') {
522 $this->add_notification('error', __('Invalid Type', 'e2pdf'));
523 } else {
524 $options = $this->post->get('options');
525 $xml = simplexml_load_file($import['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE);
526 if (!isset($xml->template->pages)) {
527 $this->add_notification('error', __('The file is not a valid E2Pdf Template', 'e2pdf'));
528 } else {
529 $pages = $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->pages));
530 if (is_array($pages)) {
531 foreach ($pages as $page_key => $page) {
532 if (isset($page['elements']) && !empty($page['elements'])) {
533 foreach ($page['elements'] as $element_key => $element) {
534 if ($element['type'] === 'e2pdf-image' && isset($element['base64']) && $element['base64']) {
535 if ($options['images']) {
536 $image = base64_decode($element['base64']);
537 $file_name = basename($element['value']);
538 $upload_file = wp_upload_bits($file_name, null, $image);
539 if (!$upload_file['error']) {
540 $wp_filetype = wp_check_filetype($file_name, null);
541 $attachment = array(
542 'post_mime_type' => $wp_filetype['type'],
543 'post_parent' => 0,
544 'post_title' => preg_replace('/\.[^.]+$/', '', $file_name),
545 'post_content' => '',
546 'post_status' => 'inherit',
547 );
548 $attachment_id = wp_insert_attachment($attachment, $upload_file['file'], 0);
549 if (!is_wp_error($attachment_id)) {
550 require_once ABSPATH . 'wp-admin/includes/image.php';
551 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload_file['file']);
552 wp_update_attachment_metadata($attachment_id, $attachment_data);
553 $pages[$page_key]['elements'][$element_key]['value'] = $upload_file['url'];
554 }
555 }
556 }
557 unset($pages[$page_key]['elements'][$element_key]['base64']);
558 }
559 }
560 }
561 }
562 }
563
564 $template = new Model_E2pdf_Template();
565 if ($options['overwrite']) {
566 if ($options['overwrite'] == '1' && $options['template_id']) {
567 $template->load((int) $options['template_id']);
568 } elseif ($options['overwrite'] == '2' && $options['custom_template_id']) {
569 if (!$template->load((int) $options['custom_template_id'])) {
570 $template->set('TMP_ID', (int) $options['custom_template_id']);
571 }
572 } elseif ($options['overwrite'] == '3') {
573 if (!$template->load((int) $xml->template->ID)) {
574 $template->set('TMP_ID', (int) $xml->template->ID);
575 }
576 }
577 }
578 $template->set('title', (string) $xml->template->title);
579 $template->set('flatten', (string) $xml->template->flatten);
580 if (isset($xml->template->tab_order)) {
581 $template->set('tab_order', (string) $xml->template->tab_order);
582 }
583 $template->set('compression', (string) $xml->template->compression);
584 if (isset($xml->template->optimization)) {
585 $template->set('optimization', (string) $xml->template->optimization);
586 }
587 $template->set('appearance', (string) $xml->template->appearance);
588 $template->set('width', (string) $xml->template->width);
589 $template->set('height', (string) $xml->template->height);
590 $template->set('extension', (string) $xml->template->extension);
591 if (isset($xml->template->item)) {
592 $template->set('item', (string) $xml->template->item);
593 }
594 if (isset($xml->template->item1)) {
595 $template->set('item1', (string) $xml->template->item1);
596 }
597 if (isset($xml->template->item2)) {
598 $template->set('item2', (string) $xml->template->item2);
599 }
600
601 $fpro2pdf_backup = false;
602 if ($xml->source) {
603 if ((string) $xml->source == 'fpro2pdf') {
604 $fpro2pdf_backup = true;
605 }
606 }
607
608 $extension = new Model_E2pdf_Extension();
609 $extension->load($template->get('extension'));
610 if ($options['item'] && $xml->item && !$fpro2pdf_backup) {
611 $extension->set('item', $template->get('item'));
612 if ($template->get('item') == '-2') {
613 $extension->set('item1', $template->get('item1'));
614 $extension->set('item2', $template->get('item2'));
615 }
616
617 $updated_items = $extension->import($xml->item, $options);
618 if ($updated_items) {
619 if (isset($updated_items['errors'])) {
620 $errors = array_merge($errors, $updated_items['errors']);
621 } else {
622 if ($template->get('item') == '-2') {
623 if ($template->get('item1') && isset($updated_items[$template->get('item1')])) {
624 $item1 = $updated_items[$template->get('item1')];
625 $template->set('item1', $item1);
626 $extension->set('item1', $item1);
627 } else {
628 $template->set('item1', '');
629 $extension->set('item1', '');
630 }
631 if ($template->get('item2') && isset($updated_items[$template->get('item2')])) {
632 $item2 = $updated_items[$template->get('item2')];
633 $template->set('item2', $item2);
634 $extension->set('item2', $item2);
635 } else {
636 $template->set('item2', '');
637 $extension->set('item2', '');
638 }
639 } else {
640 if (isset($updated_items[$template->get('item')])) {
641 $item = $updated_items[$template->get('item')];
642 $template->set('item', $item);
643 $extension->set('item', $item);
644 } else {
645 $template->set('item', '');
646 $extension->set('item', '');
647 }
648 }
649 }
650 }
651 }
652
653 $template->set('format', (string) $xml->template->format);
654 if (isset($xml->template->resample)) {
655 $template->set('resample', (string) $xml->template->resample);
656 }
657 $template->set(
658 'dataset_title',
659 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title, $options, $xml, $template, $extension)
660 );
661 if (isset($xml->template->dataset_title1)) {
662 $template->set(
663 'dataset_title1',
664 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title1, $options, $xml, $template, $extension)
665 );
666 }
667 if (isset($xml->template->dataset_title2)) {
668 $template->set(
669 'dataset_title2',
670 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title2, $options, $xml, $template, $extension)
671 );
672 }
673 $template->set(
674 'button_title',
675 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->button_title, $options, $xml, $template, $extension)
676 );
677 if (isset($xml->template->dpdf)) {
678 $template->set(
679 'dpdf',
680 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dpdf, $options, $xml, $template, $extension)
681 );
682 }
683 if (isset($xml->template->attachments)) {
684 $template->set(
685 'attachments',
686 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->attachments, $options, $xml, $template, $extension)
687 );
688 }
689 $template->set('inline', (string) $xml->template->inline);
690 $template->set('auto', (string) $xml->template->auto);
691 if (isset($xml->template->rtl)) {
692 $template->set('rtl', (string) $xml->template->rtl);
693 }
694 if (isset($xml->template->font_processor)) {
695 $template->set('font_processor', (string) $xml->template->font_processor);
696 }
697 $template->set(
698 'name',
699 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->name, $options, $xml, $template, $extension)
700 );
701 if (isset($xml->template->savename)) {
702 $template->set(
703 'savename',
704 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->savename, $options, $xml, $template, $extension)
705 );
706 }
707 $template->set(
708 'password',
709 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->password, $options, $xml, $template, $extension)
710 );
711 if (isset($xml->template->owner_password)) {
712 $template->set(
713 'owner_password',
714 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->owner_password, $options, $xml, $template, $extension)
715 );
716 }
717 if (isset($xml->template->permissions)) {
718 $template->set('permissions', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->permissions)));
719 } else {
720 $template->set('permissions', array('printing'));
721 }
722 if (isset($xml->template->hooks)) {
723 $template->set(
724 'hooks',
725 (string) $xml->template->hooks
726 );
727 }
728
729 $template->set(
730 'meta_title',
731 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_title, $options, $xml, $template, $extension)
732 );
733 $template->set(
734 'meta_subject',
735 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_subject, $options, $xml, $template, $extension)
736 );
737 $template->set(
738 'meta_author',
739 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_author, $options, $xml, $template, $extension)
740 );
741 $template->set(
742 'meta_keywords',
743 apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_keywords, $options, $xml, $template, $extension)
744 );
745 if (isset($xml->template->lang_code)) {
746 $template->set('lang_code', (string) $xml->template->lang_code);
747 }
748 $template->set('font', (string) $xml->template->font);
749 $template->set('font_size', (string) $xml->template->font_size);
750 $template->set('font_color', (string) $xml->template->font_color);
751 $template->set('line_height', (string) $xml->template->line_height);
752 if (isset($xml->template->text_align)) {
753 $template->set('text_align', (string) $xml->template->text_align);
754 }
755 $template->set('fonts', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->fonts)));
756 $template->set(
757 'properties',
758 apply_filters('e2pdf_controller_templates_import_properties', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->properties)), $options, $xml, $template, $extension)
759 );
760 $template->set(
761 'actions',
762 apply_filters('e2pdf_controller_templates_import_actions', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->actions)), $options, $xml, $template, $extension)
763 );
764 $template->set(
765 'pages',
766 apply_filters('e2pdf_controller_templates_import_pages', $pages, $options, $xml, $template, $extension)
767 );
768
769 if ($options['fonts'] && $xml->fonts) {
770 $model_e2pdf_font = new Model_E2pdf_Font();
771 $fonts = $model_e2pdf_font->get_fonts();
772
773 if ($xml->fonts) {
774 foreach ($xml->fonts->children() as $key => $font) {
775 $title = (string) $font->title;
776 $name = (string) $font->name;
777 $value = (string) $font->value;
778
779 if ($title == 'Noto Sans' && $name == 'NotoSans-Regular.ttf') {
780 $title = 'Noto Sans Regular';
781 }
782
783 $exist = array_search($title, $fonts);
784 if (!$exist) {
785 if (!file_exists($this->helper->get('fonts_dir') . $name)) {
786 $f_name = $name;
787 } else {
788 $i = 0;
789 do {
790 $f_name = $i . '_' . $name;
791 $i++;
792 } while (file_exists($this->helper->get('fonts_dir') . $f_name));
793 }
794 $font_ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION));
795 if (in_array($font_ext, $model_e2pdf_font->get_allowed_extensions())) {
796 file_put_contents($this->helper->get('fonts_dir') . $f_name, base64_decode($value), LOCK_EX);
797 }
798 }
799 }
800 }
801 }
802
803 if ($xml->pdf && $xml->pdf->source) {
804
805 $pdf_name = md5(time());
806 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
807 $pdf_images_dir = $pdf_dir . 'images/';
808
809 $this->helper->create_dir($pdf_dir);
810 $this->helper->create_dir($pdf_images_dir);
811
812 $pdf_source = (string) $xml->pdf->source;
813 file_put_contents($pdf_dir . $pdf_name . '.pdf', base64_decode($pdf_source), LOCK_EX);
814
815 if ($xml->pdf->images) {
816 foreach ($xml->pdf->images->children() as $key => $image) {
817 $page_id = (string) $image->page_id;
818 $image_source = (string) $image->source;
819 file_put_contents($pdf_dir . 'images/' . $page_id . '.png', base64_decode($image_source), LOCK_EX);
820 }
821 }
822 $template->set('pdf', $pdf_name);
823 }
824
825 if (empty($errors)) {
826 $template->save(true);
827 if ($options['item']) {
828 $extension->after_import((string) $xml->template->ID, $template->get('ID'));
829 }
830 $template->activate();
831 if ($template->get('ID')) {
832 $this->add_notification(
833 'update', sprintf(
834 __('Imported: %1$d: <a target="_blank" href="%2$s">View</a> | <a target="_blank" href="%3$s">Edit</a>', 'e2pdf'),
835 '1',
836 $this->helper->get_url(
837 [
838 'page' => 'e2pdf-templates',
839 'action' => 'view',
840 'id' => $template->get('ID')
841 ]
842 ),
843 $this->helper->get_url(array('page' => 'e2pdf-templates', 'action' => 'edit', 'id' => $template->get('ID')))
844 )
845 );
846 } else {
847 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
848 }
849 } else {
850 foreach ($errors as $key => $error) {
851 $this->add_notification('error', $error);
852 }
853 }
854 }
855 unlink($import['tmp_name']);
856 }
857 }
858
859 $this->view('import_disabled', false);
860 if (!$this->helper->load('xml')->check()) {
861 $this->add_notification('error', sprintf(__('The PHP %s extension is required', 'e2pdf'), 'SimpleXml'));
862 $this->view('import_disabled', true);
863 }
864
865 global $wpdb;
866
867 $order_condition = array(
868 'orderby' => 'ID',
869 'order' => 'desc',
870 );
871 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
872 $tpls = $wpdb->get_results($wpdb->prepare('SELECT `ID`, `title` FROM `' . (new Model_E2pdf_Template())->get_table() . '`' . $orderby . ''));
873 $templates = [
874 '' => __('--- Select ---', 'e2pdf')
875 ];
876 if (!empty($tpls)) {
877 foreach ($tpls as $tpl) {
878 $templates[$tpl->ID] = $tpl->ID . ' | ' . $tpl->title;
879 }
880 }
881
882 $options = array(
883 'overwrite' => [
884 'name' => __('Overwrite Options', 'e2pdf'),
885 'options' => [
886 [
887 'name' => __('Overwrite Template by ID', 'e2pdf'),
888 'key' => 'options[overwrite]',
889 'value' => '',
890 'default_value' => '',
891 'type' => 'select',
892 'options' => [
893 '' => __('Create New E2Pdf Template ID', 'e2pdf'),
894 '1' => __('Existing Template ID', 'e2pdf'),
895 '2' => __('Custom Template ID', 'e2pdf'),
896 '3' => __('Backup Template ID', 'e2pdf'),
897 ]
898 ],
899 [
900 'name' => __('Template ID', 'e2pdf'),
901 'key' => 'options[template_id]',
902 'value' => '',
903 'default_value' => '',
904 'type' => 'select',
905 'options' => $templates,
906 'li' => array(
907 'class' => 'e2pdf-import-overwrite-option e2pdf-hide',
908 ),
909 ],
910 [
911 'name' => __('Template ID', 'e2pdf'),
912 'key' => 'options[custom_template_id]',
913 'value' => '',
914 'default_value' => '',
915 'type' => 'text',
916 'class' => 'e2pdf-numbers',
917 'placeholder' => __('Template ID', 'e2pdf'),
918 'li' => array(
919 'class' => 'e2pdf-import-overwrite-option e2pdf-hide',
920 ),
921 ],
922 ],
923 ],
924 'template' => array(
925 'name' => __('Template Options', 'e2pdf'),
926 'options' => array(
927 array(
928 'name' => __('Import Images', 'e2pdf'),
929 'key' => 'options[images]',
930 'value' => '1',
931 'default_value' => '0',
932 'type' => 'checkbox',
933 'placeholder' => '',
934 ),
935 array(
936 'name' => __('Import Fonts', 'e2pdf'),
937 'key' => 'options[fonts]',
938 'value' => '1',
939 'default_value' => '0',
940 'type' => 'checkbox',
941 'placeholder' => '',
942 ),
943 ),
944 ),
945 'item' => array(
946 'name' => __('Connection Options', 'e2pdf'),
947 'options' => array(
948 array(
949 'name' => __('Import Connection', 'e2pdf'),
950 'key' => 'options[item]',
951 'value' => '0',
952 'default_value' => '0',
953 'type' => 'checkbox',
954 'placeholder' => '',
955 'class' => 'e2pdf-collapse',
956 'data-collapse' => 'e2pdf-import-extension-option',
957 ),
958 ),
959 ),
960 );
961
962 $options = apply_filters('e2pdf_controller_templates_import_options', $options);
963 $this->view('options', $options);
964 $this->view('upload_max_filesize', $this->helper->load('files')->get_upload_max_filesize());
965 }
966
967 /**
968 * @url admin.php?page=e2pdf-templates&action=backup&id=$id
969 */
970 public function download_action() {
971 if ($this->post->get('_wpnonce')) {
972 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) {
973 if ($this->helper->load('xml')->check()) {
974 $options = $this->post->get('options');
975 $xml = $this->helper->load('xml')->create('backup');
976 $template = new Model_E2pdf_Template();
977 if ($template->load($this->post->get('id'))) {
978 if ($template->get('title') != '') {
979 $filename = $template->get('ID') . ' - ' . $template->get('title') . '.' . date('Y-m-d.H-i-s') . '.e2pdf';
980 } else {
981 $filename = date('Y-m-d.H-i-s') . '.e2pdf';
982 }
983 $pages = $template->get('pages');
984 if ($options['images']) {
985 foreach ($pages as $page_key => $page) {
986 if (isset($page['elements']) && !empty($page['elements'])) {
987 foreach ($page['elements'] as $element_key => $element) {
988 if ($element['type'] === 'e2pdf-image') {
989 $file = false;
990 if ($this->helper->load('pdf')->get_extension($element['value'])) {
991 $file = $this->helper->load('pdf')->get_pdf($element['value']);
992 } else {
993 $file = $this->helper->load('image')->get_image($element['value']);
994 }
995 if ($file) {
996 $pages[$page_key]['elements'][$element_key]['base64'] = $file;
997 }
998 }
999 }
1000 }
1001 }
1002 }
1003
1004 /*
1005 * Build Xml
1006 */
1007 $xml->addChildCData('version', $this->helper->get('version'));
1008 $xml->addChildCData('date', date('Y-m-d H:i:s'));
1009
1010 $options_xml = $xml->addChild('options');
1011 foreach ($options as $option_key => $option) {
1012 $options_xml->addChildCData($option_key, $option);
1013 }
1014 $template_xml = $xml->addChild('template');
1015 $template_xml->addChildCData('ID', $template->get('ID'));
1016 $template_xml->addChildCData('title', $template->get('title'));
1017 $template_xml->addChildCData('created_at', $template->get('created_at'));
1018 $template_xml->addChildCData('updated_at', $template->get('updated_at'));
1019 $template_xml->addChildCData('flatten', $template->get('flatten'));
1020 $template_xml->addChildCData('tab_order', $template->get('tab_order'));
1021 $template_xml->addChildCData('compression', $template->get('compression'));
1022 $template_xml->addChildCData('optimization', $template->get('optimization'));
1023 $template_xml->addChildCData('appearance', $template->get('appearance'));
1024 $template_xml->addChildCData('width', $template->get('width'));
1025 $template_xml->addChildCData('height', $template->get('height'));
1026 $template_xml->addChildCData('extension', $template->get('extension'));
1027 $template_xml->addChildCData('item', $template->get('item'));
1028 $template_xml->addChildCData('item1', $template->get('item1'));
1029 $template_xml->addChildCData('item2', $template->get('item2'));
1030 $template_xml->addChildCData('format', $template->get('format'));
1031 $template_xml->addChildCData('resample', $template->get('resample'));
1032 $template_xml->addChildCData(
1033 'dataset_title',
1034 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title'), $options, $template, $template->extension())
1035 );
1036 $template_xml->addChildCData(
1037 'dataset_title1',
1038 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title1'), $options, $template, $template->extension())
1039 );
1040 $template_xml->addChildCData(
1041 'dataset_title2',
1042 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title2'), $options, $template, $template->extension())
1043 );
1044 $template_xml->addChildCData(
1045 'button_title',
1046 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('button_title'), $options, $template, $template->extension())
1047 );
1048 $template_xml->addChildCData(
1049 'dpdf',
1050 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dpdf'), $options, $template, $template->extension())
1051 );
1052 $template_xml->addChildCData(
1053 'attachments',
1054 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('attachments'), $options, $template, $template->extension())
1055 );
1056 $template_xml->addChildCData('inline', $template->get('inline'));
1057 $template_xml->addChildCData('auto', $template->get('auto'));
1058 $template_xml->addChildCData('rtl', $template->get('rtl'));
1059 $template_xml->addChildCData('font_processor', $template->get('font_processor'));
1060 $template_xml->addChildCData(
1061 'name',
1062 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('name'), $options, $template, $template->extension())
1063 );
1064 $template_xml->addChildCData(
1065 'savename',
1066 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('savename'), $options, $template, $template->extension())
1067 );
1068 $template_xml->addChildCData(
1069 'password',
1070 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('password'), $options, $template, $template->extension())
1071 );
1072 $template_xml->addChildCData(
1073 'owner_password',
1074 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('owner_password'), $options, $template, $template->extension())
1075 );
1076 $template_xml->addChildCData('permissions', base64_encode(serialize($template->get('permissions'))));
1077 $template_xml->addChildCData('hooks', $template->get('hooks'));
1078 $template_xml->addChildCData(
1079 'meta_title',
1080 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_title'), $options, $template, $template->extension())
1081 );
1082 $template_xml->addChildCData(
1083 'meta_subject',
1084 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_subject'), $options, $template, $template->extension())
1085 );
1086 $template_xml->addChildCData(
1087 'meta_author',
1088 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_author'), $options, $template, $template->extension())
1089 );
1090 $template_xml->addChildCData(
1091 'meta_keywords',
1092 apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_keywords'), $options, $template, $template->extension())
1093 );
1094 $template_xml->addChildCData('lang_code', $template->get('lang_code'));
1095 $template_xml->addChildCData('font', $template->get('font'));
1096 $template_xml->addChildCData('font_size', $template->get('font_size'));
1097 $template_xml->addChildCData('font_color', $template->get('font_color'));
1098 $template_xml->addChildCData('line_height', $template->get('line_height'));
1099 $template_xml->addChildCData('text_align', $template->get('text_align'));
1100 $template_xml->addChildCData('fonts', base64_encode(serialize($template->get('fonts'))));
1101 $template_xml->addChildCData(
1102 'properties', base64_encode(
1103 serialize(
1104 apply_filters('e2pdf_controller_templates_backup_properties', $template->get('properties'), $options, $template, $template->extension())
1105 )
1106 )
1107 );
1108 $template_xml->addChildCData(
1109 'actions', base64_encode(
1110 serialize(
1111 apply_filters('e2pdf_controller_templates_backup_actions', $template->get('actions'), $options, $template, $template->extension())
1112 )
1113 )
1114 );
1115 $template_xml->addChildCData('pages', base64_encode(
1116 serialize(
1117 apply_filters('e2pdf_controller_templates_backup_pages', $pages, $options, $template, $template->extension())
1118 )
1119 )
1120 );
1121
1122 // include pdf
1123 if ($template->get('pdf')) {
1124 $pdf_xml = $xml->addChild('pdf');
1125 $pdf_xml->addChildCData('source', base64_encode(file_get_contents($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf')));
1126 $pdf_xml_images = $pdf_xml->addChild('images');
1127 foreach ($template->get('pages') as $key => $page) {
1128 $pdf_xml_image = $pdf_xml_images->addChild('image');
1129 $pdf_xml_image->addChildCData('page_id', $page['page_id']);
1130 $pdf_xml_image->addChildCData('source', base64_encode(file_get_contents($this->helper->get('pdf_dir') . $template->get('pdf') . '/images/' . $page['page_id'] . '.png')));
1131 }
1132 }
1133
1134 // include fonts
1135 if ($options['fonts']) {
1136 $fonts_xml = $xml->addChild('fonts');
1137 if ($template->get('fonts')) {
1138 $model_e2pdf_font = new Model_E2pdf_Font();
1139 foreach ($template->get('fonts') as $key => $value) {
1140 $font = $fonts_xml->addChild('font');
1141 $font->addChildCData('title', $value);
1142 $font->addChildCData('name', $key);
1143 $font->addChildCData('value', $model_e2pdf_font->get_font($key));
1144 }
1145 }
1146 }
1147
1148 // include item
1149 if ($options['item']) {
1150 if ($template->extension()->method('backup')) {
1151 $item = $xml->addChild('item');
1152 $template->extension()->backup($item);
1153 }
1154 }
1155 $this->download_response('xml', $this->helper->load('xml')->get_xml(), $filename);
1156 exit;
1157 } else {
1158 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
1159 $this->render('blocks', 'notifications');
1160 }
1161 }
1162 } else {
1163 wp_die($this->message('wp_verify_nonce_error'));
1164 }
1165 }
1166
1167 $this->view('export_disabled', false);
1168
1169 if (!$this->helper->load('xml')->check()) {
1170 $this->add_notification('error', sprintf(__('The PHP %s extension is required', 'e2pdf'), 'SimpleXml'));
1171 $this->view('export_disabled', true);
1172 }
1173
1174 $template = new Model_E2pdf_Template();
1175 if ($template->load($this->get->get('id'))) {
1176
1177 $this->view('template', $template);
1178
1179 $options = array(
1180 'common' => array(
1181 'name' => __('Options', 'e2pdf'),
1182 'options' => array(
1183 array(
1184 'name' => __('Include Connection', 'e2pdf'),
1185 'key' => 'options[item]',
1186 'value' => $template->extension()->method('backup') ? '1' : '0',
1187 'default_value' => 0,
1188 'type' => 'checkbox',
1189 'placeholder' => '',
1190 'disabled' => $template->extension()->method('backup') ? false : 'disabled',
1191 ),
1192 array(
1193 'name' => __('Include Images', 'e2pdf'),
1194 'key' => 'options[images]',
1195 'value' => 1,
1196 'default_value' => 0,
1197 'type' => 'checkbox',
1198 'placeholder' => '',
1199 ),
1200 array(
1201 'name' => __('Include Fonts', 'e2pdf'),
1202 'key' => 'options[fonts]',
1203 'value' => 1,
1204 'default_value' => 0,
1205 'type' => 'checkbox',
1206 'placeholder' => '',
1207 ),
1208 ),
1209 ),
1210 );
1211
1212 $options = apply_filters('e2pdf_controller_templates_backup_options', $options, $template, $template->extension());
1213 $this->view('options', $options);
1214 } else {
1215 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
1216 $this->render('blocks', 'notifications');
1217 }
1218 }
1219
1220 // screen action
1221 public function screen_action() {
1222 $option = $this->post->get('wp_screen_options');
1223 if (is_array($option) && isset($option['option']) && isset($option['value']) && $option['value']) {
1224 update_option($option['option'], $option['value']);
1225 }
1226 $location = $this->helper->get_url(
1227 array(
1228 'page' => 'e2pdf-templates',
1229 )
1230 );
1231 $this->redirect($location);
1232 }
1233
1234 // ajax save form
1235 public function ajax_save_form() {
1236 global $wpdb;
1237 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1238 $data = json_decode($this->post->get('data'), true);
1239 $template = new Model_E2pdf_Template();
1240 if (isset($data['ID'])) {
1241 $template->load($data['ID']);
1242 }
1243 if (!isset($data['permissions'])) {
1244 $data['permissions'] = array();
1245 }
1246 foreach ($data as $key => $value) {
1247 if ($key == 'pdf' && $value) {
1248 if (file_exists($this->helper->get('pdf_dir') . $value . '/' . $value . '.pdf')) {
1249 $template->set($key, $value);
1250 }
1251 } else {
1252 $template->set($key, $value);
1253 }
1254 }
1255 $template_id = $template->save(true);
1256 if (!$template_id) {
1257 if ($wpdb->last_error) {
1258 $response = array(
1259 'error' => $wpdb->last_error,
1260 );
1261 } else {
1262 $response = array(
1263 'error' => __('Something went wrong!', 'e2pdf'),
1264 );
1265 }
1266 } else {
1267 if (isset($data['item']) && $data['item'] == '-1') {
1268 $template->load($template_id);
1269 if ($template->extension()->method('auto_form')) {
1270 $template = $template->extension()->auto_form($template, $data);
1271 } else {
1272 $template->set('item', '');
1273 }
1274 $template->save(true);
1275 }
1276 if (!isset($data['ID'])) {
1277 $template->activate();
1278 }
1279 $response = array(
1280 'redirect' => $this->helper->get_url(
1281 array(
1282 'page' => 'e2pdf-templates',
1283 'action' => 'edit',
1284 'id' => $template->get('ID'),
1285 )
1286 ),
1287 );
1288 $this->add_notification('update', sprintf(__('Updated: %d', 'e2pdf'), '1'));
1289 }
1290 } else {
1291 $response['error'] = $this->message('wp_verify_nonce_error');
1292 }
1293 $this->json_response($response);
1294 }
1295
1296 public function ajax_get_styles() {
1297
1298 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1299 $data = $this->post->get('data');
1300 $content = array();
1301 if (isset($data['extension']) && isset($data['item'])) {
1302 $extension = new Model_E2pdf_Extension();
1303 if ($extension->load($data['extension'])) {
1304 $content = $extension->styles($data['item']);
1305 }
1306 }
1307 $response = array(
1308 'content' => $content,
1309 );
1310 } else {
1311 $response['error'] = $this->message('wp_verify_nonce_error');
1312 }
1313 $this->json_response($response);
1314 }
1315
1316 // ajax extension
1317 public function ajax_extension() {
1318 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1319 $data = $this->post->get('data');
1320 $extension = new Model_E2pdf_Extension();
1321 $content = array();
1322 if ($extension->load($data)) {
1323 $content = $extension->items();
1324 if ($extension->method('merged_items')) {
1325 $select = new stdClass();
1326 $select->id = '-2';
1327 $select->url = '';
1328 $select->name = __('Merged Connections', 'e2pdf');
1329 array_unshift($content, $select);
1330 }
1331 if ($extension->method('auto_form')) {
1332 $select = new stdClass();
1333 $select->id = '-1';
1334 $select->url = '';
1335 $select->name = __('Auto Form from PDF', 'e2pdf');
1336 array_unshift($content, $select);
1337 }
1338 }
1339 $select = new stdClass();
1340 $select->id = '';
1341 $select->url = '';
1342 $select->name = __('--- Select ---', 'e2pdf');
1343 array_unshift($content, $select);
1344 $response = array(
1345 'content' => $content,
1346 );
1347 } else {
1348 $response['error'] = $this->message('wp_verify_nonce_error');
1349 }
1350 $this->json_response($response);
1351 }
1352
1353 // ajax visual mapper
1354 public function ajax_visual_mapper() {
1355 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1356 $data = $this->post->get('data');
1357 $item = isset($data['item']) ? $data['item'] : '';
1358 $item1 = isset($data['item1']) ? $data['item1'] : '';
1359 $item2 = isset($data['item2']) ? $data['item2'] : '';
1360 $extension = new Model_E2pdf_Extension();
1361 $extension->load($data['extension']);
1362 $extension->set('item', $item);
1363 if ($item == '-2') {
1364 $extension->set('item1', $item1);
1365 $extension->set('item2', $item2);
1366 }
1367 $visual_mapper = $extension->visual_mapper();
1368 if ($visual_mapper) {
1369 $response = array(
1370 'content' => $visual_mapper,
1371 );
1372 } elseif (!$item || ($item == '-2' && !$item1 && !$item2)) {
1373 $response = array(
1374 'content' => __('You must set the Connection to use the Visual Mapper', 'e2pdf'),
1375 );
1376 } else {
1377 $response = array(
1378 'content' => __("Sorry, this Extension doesn't support the Visual Mapper", 'e2pdf'),
1379 );
1380 }
1381 } else {
1382 $response['error'] = $this->message('wp_verify_nonce_error');
1383 }
1384 $this->json_response($response);
1385 }
1386
1387 // ajax upload
1388 public function ajax_upload() {
1389
1390 if (!wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1391 $this->json_response(
1392 [
1393 'error' => $this->message('wp_verify_nonce_error'),
1394 ]
1395 );
1396 }
1397
1398 $data = $this->post->get();
1399 $post_extension = $data['extension'];
1400 $item = isset($data['item']) ? $data['item'] : '';
1401 $template_id = isset($data['template_id']) && $data['template_id'] ? $data['template_id'] : false;
1402 $font = isset($data['font']) ? $data['font'] : false;
1403 $font_size = isset($data['font_size']) ? $data['font_size'] : false;
1404 $line_height = isset($data['line_height']) ? $data['line_height'] : false;
1405 $title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf');
1406 $rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0';
1407 $text_align = isset($data['text_align']) ? $data['text_align'] : 'left';
1408 $pdf = $this->files->get('pdf');
1409 $name = strtolower($pdf['name']);
1410 $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1411
1412 if (!empty($pdf['error'])) {
1413 $this->json_response(
1414 [
1415 'error' => $pdf['error'],
1416 ]
1417 );
1418 } elseif (!in_array($ext, array('pdf'))) {
1419 $this->json_response(
1420 [
1421 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1422 ]
1423 );
1424 } elseif ($pdf['type'] != 'application/pdf') {
1425 $this->json_response(
1426 [
1427 'error' => __('Invalid Type', 'e2pdf'),
1428 ]
1429 );
1430 }
1431
1432 wp_raise_memory_limit('admin');
1433 if (get_option('e2pdf_api_protocol', '0') == '1') {
1434 $upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']);
1435 } else {
1436 $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1437 }
1438
1439 $model_e2pdf_api = new Model_E2pdf_Api();
1440 $model_e2pdf_api->set(
1441 array(
1442 'action' => 'template/upload2',
1443 'data' => array(
1444 'title' => $name,
1445 'pdf' => $upload,
1446 ),
1447 )
1448 );
1449 $request = $model_e2pdf_api->request();
1450
1451 if (isset($request['error'])) {
1452 $this->json_response(
1453 [
1454 'error' => $request['error'],
1455 ]
1456 );
1457 }
1458
1459 $extension = new Model_E2pdf_Extension();
1460 if ($post_extension) {
1461 $extension->load($post_extension);
1462 if ($item && $item != '-1') {
1463 $extension->set('item', $item);
1464 }
1465 }
1466
1467 $pdf_name = md5(time());
1468 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1469 $pdf_images_dir = $pdf_dir . 'images/';
1470 $this->helper->create_dir($pdf_dir);
1471 $this->helper->create_dir($pdf_images_dir);
1472 move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1473
1474 try {
1475 $xml_template = [];
1476 $pages = [];
1477 if (class_exists('XMLReader')) {
1478 $reader = new XMLReader();
1479 if (!$reader->XML($request['file'])) {
1480 throw new Exception(__('Failed to parse PDF', 'e2pdf'));
1481 }
1482 while ($reader->read()) {
1483 if ($reader->nodeType == XMLReader::ELEMENT) {
1484 switch ($reader->name) {
1485 case 'template':
1486 $template_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1487 $xml_template = [
1488 'width' => (string) $template_node->width,
1489 'height' => (string) $template_node->height,
1490 'format' => (string) $template_node->format,
1491 'compression' => (string) $template_node->compression,
1492 'appearance' => (string) $template_node->appearance,
1493 'meta_title' => (string) $template_node->meta_title,
1494 'meta_subject' => (string) $template_node->meta_subject,
1495 'meta_author' => (string) $template_node->meta_author,
1496 'meta_keywords' => (string) $template_node->meta_keywords,
1497 'lang_code' => (string) $template_node->lang_code,
1498 'font' => (string) $template_node->font,
1499 'font_size' => (string) $template_node->font_size,
1500 'font_color' => (string) $template_node->font_color,
1501 ];
1502 break;
1503 case 'page':
1504 $page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1505 $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension);
1506 break;
1507 case 'fonts':
1508 $fonts_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1509 foreach ($fonts_node->children() as $font) {
1510 $this->helper->load('xml')->parse_xml_font($font);
1511 }
1512 break;
1513 default:
1514 break;
1515 }
1516 }
1517 }
1518
1519 $reader->close();
1520 unset($reader);
1521 } elseif (is_callable('simplexml_load_string')) {
1522 $xml = simplexml_load_string($request['file'], 'SimpleXMLElement', LIBXML_PARSEHUGE);
1523 if (isset($xml->pages)) {
1524 foreach ($xml->pages->page as $page_node) {
1525 $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension);
1526 }
1527 }
1528 if (isset($xml->template)) {
1529 $xml_template = [
1530 'width' => (string) $xml->template->width,
1531 'height' => (string) $xml->template->height,
1532 'format' => (string) $xml->template->format,
1533 'compression' => (string) $xml->template->compression,
1534 'appearance' => (string) $xml->template->appearance,
1535 'meta_title' => (string) $xml->template->meta_title,
1536 'meta_subject' => (string) $xml->template->meta_subject,
1537 'meta_author' => (string) $xml->template->meta_author,
1538 'meta_keywords' => (string) $xml->template->meta_keywords,
1539 'lang_code' => (string) $xml->template->lang_code,
1540 'font' => (string) $xml->template->font,
1541 'font_size' => (string) $xml->template->font_size,
1542 'font_color' => (string) $xml->template->font_color,
1543 ];
1544 }
1545 if (isset($xml->fonts) && $xml->fonts) {
1546 foreach ($xml->fonts->children() as $key => $font) {
1547 $this->helper->load('xml')->parse_xml_font($font);
1548 }
1549 }
1550 }
1551
1552 if (empty($pages) || !is_array($pages)) {
1553 throw new Exception(__('Failed to parse PDF pages', 'e2pdf'));
1554 }
1555
1556 $this->helper->load('sort')->stable_uasort($pages, 'sort_by_pageid');
1557
1558 $template = new Model_E2pdf_Template();
1559 if ($template_id) {
1560 $template->load($template_id);
1561 $template->set('title', $title);
1562 $template->set('pages', $pages);
1563 $template->set('pdf', $pdf_name);
1564 $template->set('width', $xml_template['width']);
1565 $template->set('height', $xml_template['height']);
1566 $template->set('extension', $post_extension);
1567 $template->set('item', $item);
1568 $template->set('rtl', $rtl);
1569 $template->set('font', $font ? $font : $xml_template['font']);
1570 $template->set('font_size', $font_size ? $font_size : $xml_template['font_size']);
1571 $template->set('line_height', $line_height ? $line_height : $xml_template['font_size']);
1572 $template->set('text_align', $text_align);
1573 } else {
1574 $template->set('title', $title);
1575 $template->set('flatten', '1');
1576 $template->set('format', $xml_template['format']);
1577 $template->set('compression', $xml_template['compression']);
1578 $template->set('appearance', $xml_template['appearance']);
1579 $template->set('width', $xml_template['width']);
1580 $template->set('height', $xml_template['height']);
1581 $template->set('extension', $post_extension);
1582 $template->set('item', $item);
1583 $template->set('dataset_title', '');
1584 $template->set('button_title', '');
1585 $template->set('dpdf', '');
1586 $template->set('attachments', '');
1587 $template->set('inline', '');
1588 $template->set('auto', '');
1589 $template->set('rtl', $rtl);
1590 $template->set('name', '[e2pdf-dataset]');
1591 $template->set('savename', '[e2pdf-dataset]');
1592 $template->set('password', '');
1593 $template->set('meta_title', $xml_template['meta_title']);
1594 $template->set('meta_subject', $xml_template['meta_subject']);
1595 $template->set('meta_author', $xml_template['meta_author']);
1596 $template->set('meta_keywords', $xml_template['meta_keywords']);
1597 $template->set('lang_code', $xml_template['lang_code']);
1598 $template->set('font', $font ? $font : $xml_template['font']);
1599 $template->set('font_size', $font_size ? $font_size : $xml_template['font_size']);
1600 $template->set('line_height', $line_height ? $line_height : $xml_template['font_size']);
1601 $template->set('text_align', $text_align);
1602 $template->set('font_color', $xml_template['font_color']);
1603 $template->set('pages', $pages);
1604 $template->set('pdf', $pdf_name);
1605 }
1606 $template->save(true);
1607
1608 if ($item == '-1' && $extension->method('auto_form')) {
1609 $template = $extension->auto_form($template, $data);
1610 $template->save(true);
1611 }
1612
1613 if (!$template_id) {
1614 $template->activate();
1615 }
1616
1617 $this->json_response(
1618 [
1619 'redirect' => $this->helper->get_url(
1620 [
1621 'page' => 'e2pdf-templates',
1622 'action' => 'edit',
1623 'id' => $template->get('ID'),
1624 ]
1625 ),
1626 ]
1627 );
1628 } catch (Exception $ex) {
1629 if (file_exists($pdf_dir)) {
1630 $this->helper->delete_dir($pdf_dir);
1631 }
1632 $this->json_response(
1633 [
1634 'error' => $ex->getMessage(),
1635 ]
1636 );
1637 }
1638 }
1639
1640 // ajax reupload
1641 public function ajax_reupload() {
1642
1643 if (!wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1644 $this->json_response(
1645 [
1646 'error' => $this->message('wp_verify_nonce_error'),
1647 ]
1648 );
1649 }
1650
1651 $data = $this->post->get();
1652 $new = isset($data['new']) ? $data['new'] : array();
1653 $flush = isset($data['flush']) ? $data['flush'] : array();
1654 $positions = isset($data['positions']) ? $data['positions'] : array();
1655 $template_id = isset($data['template_id']) && $data['template_id'] ? $data['template_id'] : false;
1656 if (!$template_id) {
1657 return false;
1658 }
1659
1660 $pdf = $this->files->get('pdf');
1661 $name = strtolower($pdf['name']);
1662 $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1663
1664 if (!empty($pdf['error'])) {
1665 $this->json_response(
1666 [
1667 'error' => $pdf['error'],
1668 ]
1669 );
1670 } elseif (!in_array($ext, array('pdf'))) {
1671 $this->json_response(
1672 [
1673 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1674 ]
1675 );
1676 } elseif ($pdf['type'] != 'application/pdf') {
1677 $this->json_response(
1678 [
1679 'error' => __('Invalid Type', 'e2pdf'),
1680 ]
1681 );
1682 }
1683
1684 wp_raise_memory_limit('admin');
1685 if (get_option('e2pdf_api_protocol', '0') == '1') {
1686 $upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']);
1687 } else {
1688 $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1689 }
1690
1691 $model_e2pdf_api = new Model_E2pdf_Api();
1692 $model_e2pdf_api->set(
1693 array(
1694 'action' => 'template/upload2',
1695 'data' => array(
1696 'title' => $name,
1697 'pdf' => $upload,
1698 ),
1699 )
1700 );
1701 $request = $model_e2pdf_api->request();
1702
1703 if (isset($request['error'])) {
1704 $this->json_response(
1705 [
1706 'error' => $request['error'],
1707 ]
1708 );
1709 }
1710
1711 $template = new Model_E2pdf_Template();
1712 if (!$template->load($template_id)) {
1713 $this->json_response(
1714 [
1715 'error' => __('Failed to load E2Pdf Template', 'e2pdf'),
1716 ]
1717 );
1718 }
1719
1720 $extension = new Model_E2pdf_Extension();
1721 if ($template->get('extension') && $template->get('item')) {
1722 $extension->load($template->get('extension'));
1723 $extension->set('item', $template->get('item'));
1724 }
1725
1726 $pdf_name = md5(time());
1727 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1728 $pdf_images_dir = $pdf_dir . 'images/';
1729 $this->helper->create_dir($pdf_dir);
1730 $this->helper->create_dir($pdf_images_dir);
1731 move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1732
1733 try {
1734 $pages = [];
1735 $pos_pages = [];
1736 if (class_exists('XMLReader')) {
1737 $reader = new XMLReader();
1738 if (!$reader->XML($request['file'])) {
1739 throw new Exception(__('Failed to parse PDF', 'e2pdf'));
1740 }
1741 while ($reader->read()) {
1742 if ($reader->nodeType == XMLReader::ELEMENT) {
1743 if ($reader->name == 'page') {
1744 $page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1745 $pos_pages[] = (string) $page_node['number'];
1746 }
1747 }
1748 }
1749 $reader->close();
1750 unset($reader);
1751 foreach ($positions as $pos_key => $pos_page) {
1752 if (!in_array($pos_key, $flush)) {
1753 if ($pos_page == '0') {
1754 $flush[] = $pos_key;
1755 } elseif (!in_array($pos_page, $pos_pages, false)) {
1756 throw new Exception(sprintf(__('Invalid position of %s page', 'e2pdf'), $pos_key));
1757 }
1758 }
1759 }
1760 $reader = new XMLReader();
1761 $reader->XML($request['file']);
1762 while ($reader->read()) {
1763 if ($reader->nodeType == XMLReader::ELEMENT) {
1764 switch ($reader->name) {
1765 case 'page':
1766 $page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1767 $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension);
1768 break;
1769 default:
1770 break;
1771 }
1772 }
1773 }
1774 $reader->close();
1775 unset($reader);
1776 } elseif (is_callable('simplexml_load_string')) {
1777 $xml = simplexml_load_string($request['file'], 'SimpleXMLElement', LIBXML_PARSEHUGE);
1778 if (isset($xml->pages)) {
1779 foreach ($xml->pages->page as $page_node) {
1780 $pos_pages[] = (string) $page_node['number'];
1781 }
1782 }
1783 foreach ($positions as $pos_key => $pos_page) {
1784 if (!in_array($pos_key, $flush)) {
1785 if ($pos_page == '0') {
1786 $flush[] = $pos_key;
1787 } elseif (!in_array($pos_page, $pos_pages, false)) {
1788 throw new Exception(sprintf(__('Invalid position of %s page', 'e2pdf'), $pos_key));
1789 }
1790 }
1791 }
1792 if (isset($xml->pages)) {
1793 foreach ($xml->pages->page as $page_node) {
1794 $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension);
1795 }
1796 }
1797 }
1798
1799 if (empty($pages) || !is_array($pages)) {
1800 throw new Exception(__('Failed to parse PDF pages', 'e2pdf'));
1801 }
1802
1803 $this->helper->load('sort')->stable_uasort($pages, 'sort_by_pageid');
1804
1805 $model_e2pdf_element = new Model_E2pdf_Element();
1806 $last_element_id = $model_e2pdf_element->get_last_element_id($template_id);
1807 $original_pages = $template->get('pages');
1808
1809 foreach ($pages as $page_key => $page) {
1810 if (isset($page['elements']) && !empty($page['elements'])) {
1811 foreach ($page['elements'] as $element_key => $element) {
1812 $last_element_id++;
1813 $pages[$page_key]['elements'][$element_key]['element_id'] = $last_element_id;
1814 }
1815 }
1816 foreach ($positions as $pos_key => $pos_page) {
1817 if ($pos_page == $page_key) {
1818 if (in_array($pos_key, $new)) {
1819 if (isset($original_pages[$pos_key]['elements']) && !in_array($pos_key, $flush)) {
1820 $elements = $original_pages[$pos_key]['elements'];
1821 $pages[$page_key]['elements'] = array_merge($pages[$page_key]['elements'], $elements);
1822 }
1823 } else {
1824 if (isset($original_pages[$pos_key]['elements']) && !in_array($pos_key, $flush)) {
1825 $elements = $original_pages[$pos_key]['elements'];
1826 $pages[$page_key]['elements'] = $elements;
1827 } else {
1828 $pages[$page_key]['elements'] = array();
1829 }
1830 }
1831 if (isset($original_pages[$pos_key]['actions'])) {
1832 $pages[$page_key]['actions'] = $original_pages[$pos_key]['actions'];
1833 }
1834 }
1835 }
1836 }
1837
1838 $template->set('pdf', $pdf_name);
1839 $template->set('pages', $pages);
1840 $template->save(true);
1841
1842 $this->json_response(
1843 [
1844 'redirect' => $this->helper->get_url(
1845 array(
1846 'page' => 'e2pdf-templates',
1847 'action' => 'edit',
1848 'id' => $template->get('ID'),
1849 )
1850 ),
1851 ]
1852 );
1853 } catch (Exception $ex) {
1854 if (file_exists($pdf_dir)) {
1855 $this->helper->delete_dir($pdf_dir);
1856 }
1857 $this->json_response(
1858 [
1859 'error' => $ex->getMessage(),
1860 ]
1861 );
1862 }
1863 }
1864
1865 // ajax auto
1866 public function ajax_auto() {
1867 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1868 $data = $this->post->get('data');
1869
1870 $extension = $data['extension'];
1871 $item = isset($data['item']) ? $data['item'] : '';
1872 $item1 = isset($data['item1']) ? $data['item1'] : '';
1873 $item2 = isset($data['item2']) ? $data['item2'] : '';
1874 $font_size = isset($data['font_size']) ? $data['font_size'] : '14';
1875 $line_height = isset($data['line_height']) ? $data['line_height'] : '14';
1876
1877 if (!$extension || !$item) {
1878 return;
1879 }
1880
1881 $model_e2pdf_extension = new Model_E2pdf_Extension();
1882 $model_e2pdf_extension->load($extension);
1883 $model_e2pdf_extension->set('item', $item);
1884 $model_e2pdf_extension->set('item1', $item1);
1885 $model_e2pdf_extension->set('item2', $item2);
1886 $model_e2pdf_extension->set('font_size', $font_size);
1887 $model_e2pdf_extension->set('line_height', $line_height);
1888
1889 if (method_exists($model_e2pdf_extension->extension(), 'auto')) {
1890 $content = $model_e2pdf_extension->auto();
1891 } else {
1892 $content = array();
1893 }
1894
1895 $response = array(
1896 'content' => $content,
1897 );
1898 } else {
1899 $response['error'] = $this->message('wp_verify_nonce_error');
1900 }
1901 $this->json_response($response);
1902 }
1903
1904 // ajax activate template
1905 public function ajax_activate_template() {
1906 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1907 $data = $this->post->get('data');
1908 $id = $data['id'];
1909 if (!$id) {
1910 return;
1911 }
1912 $request = $this->activate_template($id);
1913 if (isset($request['error'])) {
1914 $response = array(
1915 'error' => $request['error'],
1916 );
1917 } else {
1918 $response = array(
1919 'content' => 'activated',
1920 );
1921 }
1922 } else {
1923 $response['error'] = $this->message('wp_verify_nonce_error');
1924 }
1925 $this->json_response($response);
1926 }
1927
1928 // ajax deactivaate template
1929 public function ajax_deactivate_template() {
1930 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1931 $data = $this->post->get('data');
1932 $id = $data['id'];
1933 if (!$id) {
1934 return;
1935 }
1936 $request = $this->deactivate_template($id);
1937 if (isset($request['error'])) {
1938 $response = array(
1939 'error' => $request['error'],
1940 );
1941 } else {
1942 $response = array(
1943 'content' => 'deactivated',
1944 );
1945 }
1946 } else {
1947 $response['error'] = $this->message('wp_verify_nonce_error');
1948 }
1949 $this->json_response($response);
1950 }
1951
1952 // ajax email
1953 public function ajax_email() {
1954 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) {
1955 $data = $this->post->get('data');
1956 $email = isset($data['email']) ? trim($data['email']) : '';
1957 $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';
1958 $model_e2pdf_api = new Model_E2pdf_Api();
1959 $model_e2pdf_api->set(
1960 array(
1961 'action' => 'common/email',
1962 'data' => array(
1963 'email' => $email,
1964 'email_code' => $email_code,
1965 'email_confirm' => isset($data['email_code']),
1966 ),
1967 )
1968 );
1969 $request = $model_e2pdf_api->request();
1970 if (isset($request['error'])) {
1971 if ($request['error'] === 'incorrect_email') {
1972 $response = array(
1973 'error' => __('Invalid E-mail address format', 'e2pdf'),
1974 );
1975 } elseif ($request['error'] === 'incorrect_code') {
1976 $response = array(
1977 'error' => __('Invalid Confirmation Code', 'e2pdf'),
1978 );
1979 } else {
1980 $response = array(
1981 'error' => $request['error'],
1982 );
1983 }
1984 } elseif (isset($request['success'])) {
1985 $response = array(
1986 'content' => $request['success'],
1987 );
1988 if ($request['success'] == 'subscribed') {
1989 update_option('e2pdf_email', $email);
1990 }
1991 }
1992 } else {
1993 $response['error'] = $this->message('wp_verify_nonce_error');
1994 }
1995 $this->json_response($response);
1996 }
1997
1998 // trash template
1999 public function trash_template($id = false) {
2000 $id = (int) $id;
2001 $template = new Model_E2pdf_Template();
2002 if ($id && $template->load($id, false)) {
2003 $template->set('trash', '1');
2004 $template->update(array('trash'));
2005 $this->deactivate_template($template->get('ID'));
2006 return true;
2007 }
2008 return false;
2009 }
2010
2011 // delete template
2012 public function delete_template($id = false) {
2013 $id = (int) $id;
2014 $template = new Model_E2pdf_Template();
2015 if ($id && $template->load($id)) {
2016 $this->deactivate_template($template->get('ID'));
2017 $template->delete();
2018 return true;
2019 }
2020 return false;
2021 }
2022
2023 // restore template
2024 public function restore_template($id = false) {
2025 $id = (int) $id;
2026 $template = new Model_E2pdf_Template();
2027 if ($id && $template->load($id, false)) {
2028 $template->set('trash', '0');
2029 $template->update(array('trash'));
2030 return true;
2031 }
2032 return false;
2033 }
2034
2035 // duplicate template
2036 public function duplicate_template($id = false) {
2037
2038 $id = (int) $id;
2039
2040 $template = new Model_E2pdf_Template();
2041 if ($id && $template->load($id)) {
2042 $title = $template->get('title') . ' ' . __('(Copy)', 'e2pdf');
2043 $template->set('ID', false);
2044 $template->set('title', $title);
2045 $template->set('uid', '');
2046 $template->set('activated', '0');
2047 if ($template->get('pdf')) {
2048 $pdf_name = md5(time());
2049 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
2050 $pdf_images_dir = $pdf_dir . 'images/';
2051
2052 $this->helper->create_dir($pdf_dir);
2053 $this->helper->create_dir($pdf_images_dir);
2054
2055 if (file_exists($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf')) {
2056 $images = glob($this->helper->get('pdf_dir') . $template->get('pdf') . '/images/*');
2057 foreach ($images as $image) {
2058 copy($image, $pdf_images_dir . pathinfo($image, PATHINFO_BASENAME));
2059 }
2060 copy($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf', $this->helper->get('pdf_dir') . $pdf_name . '/' . $pdf_name . '.pdf');
2061 $template->set('pdf', $pdf_name);
2062 }
2063 }
2064 $template->save(true);
2065 return true;
2066 }
2067 return false;
2068 }
2069
2070 // activate template
2071 public function activate_template($id = false) {
2072 $id = (int) $id;
2073 $template = new Model_E2pdf_Template();
2074 if ($id && $template->load($id, false)) {
2075 return $template->activate();
2076 } else {
2077 return array(
2078 'error' => __('Something went wrong!', 'e2pdf'),
2079 );
2080 }
2081 }
2082
2083 // deactivate template
2084 public function deactivate_template($id = false) {
2085 $id = (int) $id;
2086 $template = new Model_E2pdf_Template();
2087 if ($id && $template->load($id, false)) {
2088 return $template->deactivate();
2089 } else {
2090 return array(
2091 'error' => __('Something went wrong!', 'e2pdf'),
2092 );
2093 }
2094 }
2095
2096 // get templates list
2097 public function get_templates_list($filters = array(), $count = false) {
2098 global $wpdb;
2099
2100 $model_e2pdf_template = new Model_E2pdf_Template();
2101 $condition = array();
2102 if (isset($filters['status']) && $filters['status'] == 'trash') {
2103 $condition = array(
2104 'trash' => array(
2105 'condition' => '=',
2106 'value' => '1',
2107 'type' => '%d',
2108 ),
2109 );
2110 } else {
2111 $condition = array(
2112 'trash' => array(
2113 'condition' => '<>',
2114 'value' => '1',
2115 'type' => '%d',
2116 ),
2117 );
2118 }
2119
2120 if (isset($filters['s']) && $filters['s']) {
2121 $condition['title'] = array(
2122 'condition' => 'LIKE',
2123 'value' => '%%' . $filters['s'] . '%%',
2124 'type' => '%s',
2125 'or' => array(
2126 array(
2127 'ID' => array(
2128 'condition' => 'LIKE',
2129 'value' => '%%' . $filters['s'] . '%%',
2130 'type' => '%s',
2131 ),
2132 ),
2133 ),
2134 );
2135 }
2136
2137 $order_condition = array();
2138 $sortable = array('id', 'title', 'updated_at');
2139 if (isset($filters['orderby']) && in_array($filters['orderby'], $sortable) && isset($filters['order'])) {
2140 $order_condition = array(
2141 'orderby' => $filters['orderby'],
2142 'order' => $filters['order'] == 'asc' ? 'asc' : 'desc',
2143 );
2144 } else {
2145 $order_condition = array(
2146 'orderby' => 'id',
2147 'order' => 'desc',
2148 );
2149 }
2150
2151 $limit_condition = array();
2152 if (!$count) {
2153 $paged = isset($filters['paged']) && $filters['paged'] ? $filters['paged'] : '0';
2154 $paged = (int) $paged <= 0 ? 1 : (int) $paged;
2155 $per_page = get_option('e2pdf_templates_screen_per_page', '20');
2156
2157 $limit_condition = array(
2158 'limit' => (int) $per_page,
2159 'offset' => (int) ($paged - 1) * $per_page,
2160 );
2161 }
2162
2163 $where = $this->helper->load('db')->prepare_where($condition);
2164 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
2165 $limit = $this->helper->load('db')->prepare_limit($limit_condition);
2166 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
2167 $tpls = $wpdb->get_results($wpdb->prepare('SELECT `ID` FROM `' . $model_e2pdf_template->get_table() . '`' . $where['sql'] . $orderby . $limit . '', $where['filter']));
2168
2169 if ($count) {
2170 return count($tpls);
2171 }
2172
2173 $templates = array();
2174 foreach ($tpls as $key => $tpl) {
2175 $template = new Model_E2pdf_Template();
2176 $template->load($tpl->ID, false);
2177 if (is_array($this->helper->get('license')->get('activated_templates'))) {
2178 if ($template->get('activated') && !in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) {
2179 $template->deactivate();
2180 } elseif (!$template->get('activated') && in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) {
2181 $template->activate();
2182 }
2183 }
2184 $templates[] = $template;
2185 }
2186 return $templates;
2187 }
2188
2189 // get sizes list
2190 public function get_sizes_list($size = false, $attr = false) {
2191
2192 $sizes = array(
2193 'A4 (PORTRAIT)' => array(
2194 'width' => '595',
2195 'height' => '842',
2196 ),
2197 'A4 (LANDSCAPE)' => array(
2198 'width' => '842',
2199 'height' => '595',
2200 ),
2201 'LETTER' => array(
2202 'width' => '612',
2203 'height' => '792',
2204 ),
2205 'NOTE' => array(
2206 'width' => '540',
2207 'height' => '720',
2208 ),
2209 'LEGAL' => array(
2210 'width' => '612',
2211 'height' => '1008',
2212 ),
2213 'TABLOID' => array(
2214 'width' => '792',
2215 'height' => '1224',
2216 ),
2217 'EXECUTIVE' => array(
2218 'width' => '522',
2219 'height' => '756',
2220 ),
2221 'POSTCARD' => array(
2222 'width' => '283',
2223 'height' => '416',
2224 ),
2225 );
2226
2227 if (!$size) {
2228 return $sizes;
2229 } else {
2230 if (isset($sizes[$size][$attr])) {
2231 return $sizes[$size][$attr];
2232 }
2233 return false;
2234 }
2235 }
2236
2237 // get fonts
2238 public function get_fonts($with_path = false) {
2239 $model_e2pdf_font = new Model_E2pdf_Font();
2240 $fonts = $model_e2pdf_font->get_fonts();
2241
2242 if ($with_path) {
2243 foreach ($fonts as $key => $value) {
2244 $fonts[$key] = array(
2245 'key' => $value,
2246 'subfield' => array(
2247 'path' => $key,
2248 ),
2249 'value' => $value,
2250 );
2251 }
2252 }
2253
2254 return $fonts;
2255 }
2256
2257 // get font sizes
2258 public function get_font_sizes() {
2259 $max_font_size = apply_filters('e2pdf_controller_templates_max_font_size', 512);
2260 $sizes = array();
2261 for ($i = 1; $i <= $max_font_size; $i++) {
2262 $sizes[$i] = $i;
2263 }
2264 return $sizes;
2265 }
2266
2267 // get line heights
2268 public function get_line_heights() {
2269
2270 $max_line_height = apply_filters('e2pdf_controller_templates_max_line_height', 512);
2271 $line_heights = array();
2272 for ($i = 1; $i <= $max_line_height; $i++) {
2273 $line_heights[$i] = $i;
2274 }
2275 return $line_heights;
2276 }
2277
2278 // get lang codes
2279 public function get_lang_codes() {
2280 return array(
2281 '' => '',
2282 'aa' => 'aa',
2283 'ab' => 'ab',
2284 'ae' => 'ae',
2285 'af' => 'af',
2286 'ak' => 'ak',
2287 'am' => 'am',
2288 'an' => 'an',
2289 'ar' => 'ar',
2290 'ar-AE' => 'ar-AE',
2291 'ar-BH' => 'ar-BH',
2292 'ar-DZ' => 'ar-DZ',
2293 'ar-EG' => 'ar-EG',
2294 'ar-IQ' => 'ar-IQ',
2295 'ar-JO' => 'ar-JO',
2296 'ar-KW' => 'ar-KW',
2297 'ar-LB' => 'ar-LB',
2298 'ar-LY' => 'ar-LY',
2299 'ar-MA' => 'ar-MA',
2300 'ar-OM' => 'ar-OM',
2301 'ar-QA' => 'ar-QA',
2302 'ar-SA' => 'ar-SA',
2303 'ar-SY' => 'ar-SY',
2304 'ar-TN' => 'ar-TN',
2305 'ar-YE' => 'ar-YE',
2306 'as' => 'as',
2307 'av' => 'av',
2308 'ay' => 'ay',
2309 'az' => 'az',
2310 'ba' => 'ba',
2311 'be' => 'be',
2312 'bg' => 'bg',
2313 'bh' => 'bh',
2314 'bi' => 'bi',
2315 'bm' => 'bm',
2316 'bn' => 'bn',
2317 'bo' => 'bo',
2318 'br' => 'br',
2319 'bs' => 'bs',
2320 'ca' => 'ca',
2321 'ce' => 'ce',
2322 'ch' => 'ch',
2323 'co' => 'co',
2324 'cr' => 'cr',
2325 'cs' => 'cs',
2326 'cu' => 'cu',
2327 'cv' => 'cv',
2328 'cy' => 'cy',
2329 'da' => 'da',
2330 'de' => 'de',
2331 'de-AT' => 'de-AT',
2332 'de-CH' => 'de-CH',
2333 'de-DE' => 'de-DE',
2334 'de-LI' => 'de-LI',
2335 'de-LU' => 'de-LU',
2336 'div' => 'div',
2337 'dv' => 'dv',
2338 'dz' => 'dz',
2339 'ee' => 'ee',
2340 'el' => 'el',
2341 'en' => 'en',
2342 'en-AU' => 'en-AU',
2343 'en-BZ' => 'en-BZ',
2344 'en-CA' => 'en-CA',
2345 'en-CB' => 'en-CB',
2346 'en-GB' => 'en-GB',
2347 'en-IE' => 'en-IE',
2348 'en-JM' => 'en-JM',
2349 'en-NZ' => 'en-NZ',
2350 'en-PH' => 'en-PH',
2351 'en-TT' => 'en-TT',
2352 'en-US' => 'en-US',
2353 'en-ZA' => 'en-ZA',
2354 'en-ZW' => 'en-ZW',
2355 'eo' => 'eo',
2356 'es' => 'es',
2357 'es-AR' => 'es-AR',
2358 'es-BO' => 'es-BO',
2359 'es-CL' => 'es-CL',
2360 'es-CO' => 'es-CO',
2361 'es-CR' => 'es-CR',
2362 'es-DO' => 'es-DO',
2363 'es-EC' => 'es-EC',
2364 'es-ES' => 'es-ES',
2365 'es-GT' => 'es-GT',
2366 'es-HN' => 'es-HN',
2367 'es-MX' => 'es-MX',
2368 'es-NI' => 'es-NI',
2369 'es-PA' => 'es-PA',
2370 'es-PE' => 'es-PE',
2371 'es-PR' => 'es-PR',
2372 'es-PY' => 'es-PY',
2373 'es-SV' => 'es-SV',
2374 'es-US' => 'es-US',
2375 'es-UY' => 'es-UY',
2376 'es-VE' => 'es-VE',
2377 'et' => 'et',
2378 'eu' => 'eu',
2379 'fa' => 'fa',
2380 'ff' => 'ff',
2381 'fi' => 'fi',
2382 'fj' => 'fj',
2383 'fo' => 'fo',
2384 'fr' => 'fr',
2385 'fr-BE' => 'fr-BE',
2386 'fr-CA' => 'fr-CA',
2387 'fr-CH' => 'fr-CH',
2388 'fr-FR' => 'fr-FR',
2389 'fr-LU' => 'fr-LU',
2390 'fr-MC' => 'fr-MC',
2391 'fy' => 'fy',
2392 'ga' => 'ga',
2393 'gd' => 'gd',
2394 'gl' => 'gl',
2395 'gn' => 'gn',
2396 'gu' => 'gu',
2397 'gv' => 'gv',
2398 'ha' => 'ha',
2399 'he' => 'he',
2400 'hi' => 'hi',
2401 'ho' => 'ho',
2402 'hr' => 'hr',
2403 'hr-BA' => 'hr-BA',
2404 'hr-HR' => 'hr-HR',
2405 'ht' => 'ht',
2406 'hu' => 'hu',
2407 'hy' => 'hy',
2408 'hz' => 'hz',
2409 'ia' => 'ia',
2410 'id' => 'id',
2411 'ie' => 'ie',
2412 'ig' => 'ig',
2413 'ii' => 'ii',
2414 'ik' => 'ik',
2415 'in' => 'in',
2416 'io' => 'io',
2417 'is' => 'is',
2418 'it' => 'it',
2419 'it-CH' => 'it-CH',
2420 'it-IT' => 'it-IT',
2421 'iu' => 'iu',
2422 'iw' => 'iw',
2423 'ja' => 'ja',
2424 'ji' => 'ji',
2425 'jv' => 'jv',
2426 'jw' => 'jw',
2427 'ka' => 'ka',
2428 'kg' => 'kg',
2429 'ki' => 'ki',
2430 'kj' => 'kj',
2431 'kk' => 'kk',
2432 'kl' => 'kl',
2433 'km' => 'km',
2434 'kn' => 'kn',
2435 'ko' => 'ko',
2436 'kok' => 'kok',
2437 'kr' => 'kr',
2438 'ks' => 'ks',
2439 'ku' => 'ku',
2440 'kv' => 'kv',
2441 'kw' => 'kw',
2442 'ky' => 'ky',
2443 'kz' => 'kz',
2444 'la' => 'la',
2445 'lb' => 'lb',
2446 'lg' => 'lg',
2447 'li' => 'li',
2448 'ln' => 'ln',
2449 'lo' => 'lo',
2450 'ls' => 'ls',
2451 'lt' => 'lt',
2452 'lu' => 'lu',
2453 'lv' => 'lv',
2454 'mg' => 'mg',
2455 'mh' => 'mh',
2456 'mi' => 'mi',
2457 'mk' => 'mk',
2458 'ml' => 'ml',
2459 'mn' => 'mn',
2460 'mo' => 'mo',
2461 'mr' => 'mr',
2462 'ms' => 'ms',
2463 'ms-BN' => 'ms-BN',
2464 'ms-MY' => 'ms-MY',
2465 'mt' => 'mt',
2466 'my' => 'my',
2467 'na' => 'na',
2468 'nb' => 'nb',
2469 'nd' => 'nd',
2470 'ne' => 'ne',
2471 'ng' => 'ng',
2472 'nl' => 'nl',
2473 'nl-BE' => 'nl-BE',
2474 'nl-NL' => 'nl-NL',
2475 'nn' => 'nn',
2476 'no' => 'no',
2477 'nr' => 'nr',
2478 'ns' => 'ns',
2479 'nv' => 'nv',
2480 'ny' => 'ny',
2481 'oc' => 'oc',
2482 'oj' => 'oj',
2483 'om' => 'om',
2484 'or' => 'or',
2485 'os' => 'os',
2486 'pa' => 'pa',
2487 'pi' => 'pi',
2488 'pl' => 'pl',
2489 'ps' => 'ps',
2490 'pt' => 'pt',
2491 'pt-BR' => 'pt-BR',
2492 'pt-PT' => 'pt-PT',
2493 'qu' => 'qu',
2494 'qu-BO' => 'qu-BO',
2495 'qu-EC' => 'qu-EC',
2496 'qu-PE' => 'qu-PE',
2497 'rm' => 'rm',
2498 'rn' => 'rn',
2499 'ro' => 'ro',
2500 'ru' => 'ru',
2501 'rw' => 'rw',
2502 'sa' => 'sa',
2503 'sb' => 'sb',
2504 'sc' => 'sc',
2505 'sd' => 'sd',
2506 'se' => 'se',
2507 'se-FI' => 'se-FI',
2508 'se-NO' => 'se-NO',
2509 'se-SE' => 'se-SE',
2510 'sg' => 'sg',
2511 'sh' => 'sh',
2512 'si' => 'si',
2513 'sk' => 'sk',
2514 'sl' => 'sl',
2515 'sm' => 'sm',
2516 'sn' => 'sn',
2517 'so' => 'so',
2518 'sq' => 'sq',
2519 'sr' => 'sr',
2520 'sr-BA' => 'sr-BA',
2521 'sr-SP' => 'sr-SP',
2522 'ss' => 'ss',
2523 'st' => 'st',
2524 'su' => 'su',
2525 'sv' => 'sv',
2526 'sv-FI' => 'sv-FI',
2527 'sv-SE' => 'sv-SE',
2528 'sw' => 'sw',
2529 'sx' => 'sx',
2530 'syr' => 'syr',
2531 'ta' => 'ta',
2532 'te' => 'te',
2533 'tg' => 'tg',
2534 'th' => 'th',
2535 'ti' => 'ti',
2536 'tk' => 'tk',
2537 'tl' => 'tl',
2538 'tn' => 'tn',
2539 'to' => 'to',
2540 'tr' => 'tr',
2541 'ts' => 'ts',
2542 'tt' => 'tt',
2543 'tw' => 'tw',
2544 'ty' => 'ty',
2545 'ug' => 'ug',
2546 'uk' => 'uk',
2547 'ur' => 'ur',
2548 'us' => 'us',
2549 'uz' => 'uz',
2550 've' => 've',
2551 'vi' => 'vi',
2552 'vo' => 'vo',
2553 'wa' => 'wa',
2554 'wo' => 'wo',
2555 'xh' => 'xh',
2556 'yi' => 'yi',
2557 'yo' => 'yo',
2558 'za' => 'za',
2559 'zh' => 'zh',
2560 'zh-CN' => 'zh-CN',
2561 'zh-HK' => 'zh-HK',
2562 'zh-MO' => 'zh-MO',
2563 'zh-SG' => 'zh-SG',
2564 'zh-TW' => 'zh-TW',
2565 'zu' => 'zu',
2566 );
2567 }
2568
2569 // load metaboxes
2570 public function load_metaboxes() {
2571 add_meta_box(
2572 'e2pdf_templates_save', __('Preset', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_save')
2573 );
2574 add_meta_box(
2575 'e2pdf_templates_builder', __('PDF Builder', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_builder')
2576 );
2577 add_meta_box(
2578 'e2pdf_templates_settings', __('Settings', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_settings')
2579 );
2580 }
2581
2582 // load scripts
2583 public function load_scripts() {
2584 wp_enqueue_script('postbox');
2585 wp_enqueue_script('jquery-ui-droppable');
2586 wp_enqueue_script('jquery-ui-resizable');
2587 wp_enqueue_script('jquery-ui-selectable');
2588 wp_enqueue_script('jquery-ui-dialog');
2589 wp_enqueue_script('jquery-ui-autocomplete');
2590 wp_enqueue_script('wp-color-picker');
2591 wp_enqueue_media();
2592 }
2593
2594 // load styles
2595 public function load_styles($ext = false) {
2596 $version = get_option('e2pdf_debug', '0') === '1' ? strtotime('now') : $this->helper->get('version');
2597 wp_enqueue_style('css/e2pdf.jquery-ui', plugins_url('css/jquery-ui.css', $this->helper->get('plugin_file_path')), false, $version, false);
2598 wp_enqueue_style('wp-color-picker');
2599 if ($ext) {
2600 $extension = new Model_E2pdf_Extension();
2601 if ($extension->load($ext)) {
2602 $styles = $extension->styles();
2603 if ($styles && is_array($styles)) {
2604 foreach ($styles as $key => $value) {
2605 wp_enqueue_style('e2pdf-dynamic-style-' . $key, $value, false, $version, false);
2606 }
2607 }
2608 }
2609 }
2610 }
2611 }
2612