PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.18
E2Pdf – Export Pdf Tool for WordPress v1.32.18
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 1.08.09 All 71 releases
e2pdf / classes / model / e2pdf-loader.php

e2pdf-loader.php in E2Pdf – Export Pdf Tool for WordPress 1.32.18, at classes/model/e2pdf-loader.php

1,252 lines 64.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /model/e2pdf-loader.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Model_E2pdf_Loader extends Model_E2pdf_Model {
15
16 private $e2pdf_admin_pages = [
17 'toplevel_page_e2pdf',
18 'e2pdf_page_e2pdf-templates',
19 'e2pdf_page_e2pdf-integrations',
20 'e2pdf_page_e2pdf-settings',
21 'e2pdf_page_e2pdf-license',
22 'e2pdf_page_e2pdf-debug',
23 ];
24
25 // load
26 public function load() {
27 $this->load_translation();
28 $this->load_actions();
29 $this->load_filters();
30 $this->load_extensions();
31 $this->load_hooks();
32 $this->load_ajax();
33 $this->load_shortcodes();
34 }
35
36 // load translation
37 public function load_translation() {
38 load_plugin_textdomain('e2pdf', false, '/e2pdf/languages/');
39 }
40
41 // load ajax
42 public function load_ajax() {
43 if (is_admin()) {
44 add_action('wp_ajax_e2pdf_save_form', [new Controller_E2pdf_Templates(), 'ajax_save_form']);
45 add_action('wp_ajax_e2pdf_auto', [new Controller_E2pdf_Templates(), 'ajax_auto']);
46 add_action('wp_ajax_e2pdf_upload', [new Controller_E2pdf_Templates(), 'ajax_upload']);
47 add_action('wp_ajax_e2pdf_reupload', [new Controller_E2pdf_Templates(), 'ajax_reupload']);
48 add_action('wp_ajax_e2pdf_extension', [new Controller_E2pdf_Templates(), 'ajax_extension']);
49 add_action('wp_ajax_e2pdf_activate_template', [new Controller_E2pdf_Templates(), 'ajax_activate_template']);
50 add_action('wp_ajax_e2pdf_deactivate_template', [new Controller_E2pdf_Templates(), 'ajax_deactivate_template']);
51 add_action('wp_ajax_e2pdf_visual_mapper', [new Controller_E2pdf_Templates(), 'ajax_visual_mapper']);
52 add_action('wp_ajax_e2pdf_get_styles', [new Controller_E2pdf_Templates(), 'ajax_get_styles']);
53 add_action('wp_ajax_e2pdf_email', [new Controller_E2pdf_Templates(), 'ajax_email']);
54 add_action('wp_ajax_e2pdf_license_key', [new Controller_E2pdf_License(), 'ajax_change_license_key']);
55 add_action('wp_ajax_e2pdf_restore_license_key', [new Controller_E2pdf_License(), 'ajax_restore_license_key']);
56 add_action('wp_ajax_e2pdf_deactivate_all_templates', [new Controller_E2pdf_License(), 'ajax_deactivate_all_templates']);
57 add_action('wp_ajax_e2pdf_templates', [new Controller_E2pdf(), 'ajax_templates']);
58 add_action('wp_ajax_e2pdf_dataset', [new Controller_E2pdf(), 'ajax_dataset']);
59 add_action('wp_ajax_e2pdf_datasets_refresh', [new Controller_E2pdf(), 'ajax_datasets_refresh']);
60 add_action('wp_ajax_e2pdf_delete_item', [new Controller_E2pdf(), 'ajax_delete_item']);
61 add_action('wp_ajax_e2pdf_delete_items', [new Controller_E2pdf(), 'ajax_delete_items']);
62 add_action('wp_ajax_e2pdf_delete_font', [new Controller_E2pdf_Settings(), 'ajax_delete_font']);
63 add_action('wp_ajax_e2pdf_bulk_create', [new Controller_E2pdf(), 'ajax_bulk_create']);
64 add_action('wp_ajax_e2pdf_bulk_action', [new Controller_E2pdf(), 'ajax_bulk_action']);
65 add_action('wp_ajax_e2pdf_bulk_progress', [new Controller_E2pdf(), 'ajax_bulk_progress']);
66 }
67 }
68
69 // load actions
70 public function load_actions() {
71 if (is_admin()) {
72 add_action('wpmu_new_blog', [&$this, 'action_wpmu_new_blog']);
73 add_action('admin_menu', [&$this, 'action_admin_menu']);
74 add_action('admin_init', [&$this, 'action_admin_init']);
75 add_action('admin_enqueue_scripts', [&$this, 'action_admin_enqueue_scripts']);
76 add_action('current_screen', [&$this, 'action_current_screen']);
77 add_action('plugins_loaded', [&$this, 'action_plugins_loaded']);
78 }
79 add_action('wp_enqueue_scripts', [&$this, 'action_wp_enqueue_scripts']);
80 add_action('wp', [Helper_E2pdf_View::instance(), 'render_frontend_page'], 5);
81 add_action('wp_loaded', [&$this, 'action_wp_loaded']);
82 add_action('init', [&$this, 'action_init'], 0);
83 add_action('e2pdf_bulk_export_cron', [new Controller_E2pdf(), 'cron_bulk_export']);
84 add_action('e2pdf_cache_pdfs_cron', [&$this, 'cron_cache_pdfs']);
85 add_action('e2pdf_cache_tmp_cron', [&$this, 'cron_cache_tmp']);
86
87 /**
88 * WPBakery Page Builder Actions
89 * https://wpbakery.com/
90 */
91 add_action('vc_before_init', [&$this, 'action_vc_before_init']);
92 }
93
94 // init action
95 public function action_init() {
96 if ($this->helper->get('page') == 'e2pdf-download') {
97 /**
98 * Compatibility fix with Minify HTML
99 * https://wordpress.org/plugins/minify-html-markup/
100 */
101 remove_action('init', 'teckel_init_minify_html', 1);
102
103 /**
104 * Compatibility fix with Minimal Coming Soon – Coming Soon Page
105 * https://wordpress.org/plugins/minimal-coming-soon-maintenance-mode/
106 */
107 remove_action('init', 'csmm_plugin_init');
108
109 /**
110 * Weglot Translate – Translate your WordPress website and go multilingual
111 * https://wordpress.org/plugins/weglot/
112 */
113 add_filter('weglot_active_translation_before_treat_page', '__return_false');
114
115 /**
116 * Compatibility fix with UltimateMember Homepage Redirect
117 * https://wordpress.org/plugins/ultimate-member/
118 */
119 if (class_exists('UM') && method_exists(UM(), 'access')) {
120 remove_filter('the_posts', [UM()->access(), 'filter_protected_posts'], 99);
121 }
122
123 /**
124 * Compatibility fix with Foxtool All-in-One: Contact chat button, Custom login, Media optimize images
125 * https://wordpress.org/plugins/foxtool/
126 */
127 remove_action('init', 'foxtool_init_minify_html', 1);
128
129 /**
130 * Compatibility fix with Image Optimizer, Resizer and CDN – Sirv
131 * https://wordpress.org/plugins/sirv/
132 */
133 remove_action('init', 'sirv_init', 20);
134 }
135
136 if (get_option('e2pdf_mod_rewrite', '0')) {
137 global $wp_rewrite;
138
139 $rewrite_url = rtrim(str_replace('%uid%', '([A-Za-z0-9]+)', get_option('e2pdf_mod_rewrite_url', 'e2pdf/%uid%/')), '/');
140
141 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
142 if (!empty($_SERVER['REQUEST_URI']) && preg_match('#' . $rewrite_url . '#', wp_unslash($_SERVER['REQUEST_URI']))) {
143 /**
144 * Compatibility fix with Minify HTML
145 * https://wordpress.org/plugins/minify-html-markup/
146 */
147 remove_action('init', 'teckel_init_minify_html', 1);
148
149 /**
150 * Compatibility fix with Minimal Coming Soon – Coming Soon Page
151 * https://wordpress.org/plugins/minimal-coming-soon-maintenance-mode/
152 */
153 remove_action('init', 'csmm_plugin_init');
154
155 /**
156 * Weglot Translate – Translate your WordPress website and go multilingual
157 * https://wordpress.org/plugins/weglot/
158 */
159 add_filter('weglot_active_translation_before_treat_page', '__return_false');
160
161 /**
162 * Compatibility fix with Foxtool All-in-One: Contact chat button, Custom login, Media optimize images
163 * https://wordpress.org/plugins/foxtool/
164 */
165 remove_action('init', 'foxtool_init_minify_html', 1);
166
167 /**
168 * Compatibility fix with Image Optimizer, Resizer and CDN – Sirv
169 * https://wordpress.org/plugins/sirv/
170 */
171 remove_action('init', 'sirv_init', 20);
172 }
173
174 $rules = [
175 '^' . $rewrite_url,
176 '^' . $wp_rewrite->index . '/' . $rewrite_url,
177 ];
178 $rewrite_to = 'index.php?e2pdf=1&uid=$matches[1]';
179 add_rewrite_rule($rules[0], $rewrite_to, 'top');
180 add_rewrite_rule($rules[1], $rewrite_to, 'top');
181
182 /**
183 * Polylang
184 * https://wordpress.org/plugins/polylang/
185 */
186 if (function_exists('pll_the_languages')) {
187 $languages = pll_the_languages(['raw' => 1]);
188 if (!empty($languages)) {
189 $settings = get_option('polylang');
190 $languages = array_keys($languages);
191 if (isset($settings['hide_default']) && isset($settings['default_lang']) && $settings['hide_default']) {
192 $languages = array_diff($languages, [$settings['default_lang']]);
193 }
194 if (!empty($languages)) {
195 $prefix = ((isset($settings['rewrite']) && $settings['rewrite']) ? '' : 'language/') . '(' . implode('|', $languages) . ')/';
196 $rules[] = '^' . $prefix . $rewrite_url;
197 $rules[] = '^' . $prefix . $wp_rewrite->index . '/' . $rewrite_url;
198 $rewrite_to = 'index.php?e2pdf=1&uid=$matches[2]';
199 add_rewrite_rule($rules[2], $rewrite_to, 'top');
200 add_rewrite_rule($rules[3], $rewrite_to, 'top');
201 }
202 }
203 }
204
205 $rewrite_rules = get_option('rewrite_rules');
206 foreach ($rules as $rule) {
207 if (!isset($rewrite_rules[$rule])) {
208 flush_rewrite_rules(false);
209 break;
210 }
211 }
212 }
213 }
214
215 // bulk export cron
216 public function cronjob() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
217 }
218
219 // clear pdfs cache
220 public function cron_cache_pdfs() {
221 $this->helper->load('cache')->purge_pdfs_cache_ttl();
222 }
223
224 // clear tmp cache
225 public function cron_cache_tmp() {
226 $this->helper->load('cache')->purge_tmp_cache();
227 }
228
229 // load filters
230 public function load_filters() {
231
232 if (get_option('e2pdf_dev_update', '0')) {
233 add_filter('pre_set_site_transient_update_plugins', [&$this, 'filter_pre_set_site_transient_update_plugins']);
234 }
235
236 add_filter('pre_do_shortcode_tag', [&$this, 'filter_pre_do_shortcode_tag'], 10, 2);
237
238 /**
239 * SiteGround Optimizer HTML Minify compatibility fix filter
240 * https://wordpress.org/plugins/sg-cachepress/
241 */
242 add_filter('sgo_html_minify_exclude_urls', [&$this, 'filter_sgo_html_minify_exclude_urls']);
243
244 if (get_option('e2pdf_mod_rewrite', '0')) {
245 add_filter('query_vars', [&$this, 'filter_query_vars']);
246 }
247
248 // phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval
249 add_filter('cron_schedules', [&$this, 'filter_cron_schedules']);
250
251 /**
252 * WPBakery Page Builder Filters
253 * https://wpbakery.com/
254 */
255 add_filter('vc_grid_item_shortcodes', [&$this, 'filter_vc_grid_item_shortcodes']);
256 add_filter('vc_gitem_template_attribute_e2pdf_download', [&$this, 'filter_vc_gitem_template_attribute_e2pdf_download'], 10, 2);
257 add_filter('vc_gitem_template_attribute_e2pdf_view', [&$this, 'filter_vc_gitem_template_attribute_e2pdf_view'], 10, 2);
258 }
259
260 // plugins loaded action
261 public function action_plugins_loaded() {
262 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
263 $this->activate();
264 }
265 }
266
267 // load extensions
268 public function load_extensions() {
269 $model_e2pdf_extension = new Model_E2pdf_Extension();
270 $extensions = $model_e2pdf_extension->extensions();
271 if (!empty($extensions)) {
272 foreach ($extensions as $extension => $extension_name) {
273 $model_e2pdf_extension->load($extension);
274 $model_e2pdf_extension->load_actions();
275 $model_e2pdf_extension->load_filters();
276 $model_e2pdf_extension->load_shortcodes();
277 }
278 }
279 }
280
281 // load shortcodes
282 public function load_shortcodes() {
283 $shortcode_handler = new Model_E2pdf_Shortcode();
284 foreach ($this->helper->shortcodes() as $shortcode) {
285 $method = str_replace('-', '_', $shortcode);
286 if (method_exists($shortcode_handler, $method)) {
287 add_shortcode($shortcode, [$shortcode_handler, $method]);
288 }
289 }
290 }
291
292 // load hooks
293 public function load_hooks() {
294 register_activation_hook($this->helper->get('plugin_file_path'), [&$this, 'activate']);
295 register_deactivation_hook($this->helper->get('plugin_file_path'), [&$this, 'deactivate']);
296 register_uninstall_hook($this->helper->get('plugin_file_path'), ['Model_E2pdf_Loader', 'uninstall']);
297 if (false !== strpos($this->helper->load('server')->get('REQUEST_URI'), '/e2pdf-rpc/')) {
298 add_action('wp_loaded', [Helper_E2pdf_View::instance(), 'rpc'], 5);
299 }
300 }
301
302 // admin body loading class
303 public function filter_admin_body_loading_class($classes) {
304 $classes .= ' e2pdf-loading';
305 return $classes;
306 }
307
308 // url rewrite
309 public function filter_query_vars($tags) {
310 global $wp;
311
312 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
313 if (!empty($_GET['e2pdf']) || strpos($wp->matched_query, 'e2pdf=1') === 0) {
314 $tags[] = 'e2pdf';
315 $tags[] = 'uid';
316 }
317 return $tags;
318 }
319
320 // custom cronjob time
321 public function filter_cron_schedules($schedules) {
322 $schedules['e2pdf_bulk_export_interval'] = [
323 'interval' => 3,
324 'display' => __('E2Pdf Bulk Export Interval', 'e2pdf'),
325 ];
326 return $schedules;
327 }
328
329 // filter sgo html minify
330 public function filter_sgo_html_minify_exclude_urls($exclude_urls) {
331 if (is_array($exclude_urls)) {
332 $exclude_urls[] = '/?page=e2pdf-download&uid=*';
333 if (get_option('e2pdf_download_inline_chrome_ios_fix', '0') == '1') {
334 $exclude_urls[] = '/*?page=e2pdf-download&uid=*';
335 }
336 if (get_option('e2pdf_mod_rewrite', '0')) {
337 $exclude_urls[] = '/' . rtrim(str_replace('%uid%', '*', get_option('e2pdf_mod_rewrite_url', 'e2pdf/%uid%/')), '/') . '*';
338 }
339 }
340 return $exclude_urls;
341 }
342
343 // release candidate updates
344 public function filter_pre_set_site_transient_update_plugins($transient) {
345
346 if (!is_object($transient)) {
347 return $transient;
348 }
349
350 $model_e2pdf_api = new Model_E2pdf_Api();
351 $model_e2pdf_api->set(
352 [
353 'action' => 'update/info',
354 ]
355 );
356 $request = $model_e2pdf_api->request();
357
358 if (isset($request['package'])) {
359 if (isset($transient->response[$this->helper->get('plugin')])) {
360 $update_info = $transient->response[$this->helper->get('plugin')];
361 } elseif (isset($transient->no_update[$this->helper->get('plugin')])) {
362 $update_info = $transient->no_update[$this->helper->get('plugin')];
363 } else {
364 $update_info = new stdClass();
365 $update_info->id = $this->helper->get('plugin');
366 $update_info->url = 'https://e2pdf.com';
367 $update_info->slug = $this->helper->get('slug');
368 $update_info->plugin = $this->helper->get('plugin');
369 $update_info->package = $request['package'];
370 $update_info->new_version = $request['version'];
371 $update_info->tested = $request['tested'];
372 $update_info->icons = $request['icons'];
373 $update_info->banners = $request['banners'];
374 }
375 if (version_compare($this->helper->get('version'), $request['version'], '<')) {
376 $update_info->package = $request['package'];
377 $update_info->new_version = $request['version'];
378 $update_info->tested = $request['tested'];
379 $transient->response[$this->helper->get('plugin')] = $update_info;
380 if (isset($transient->no_update[$this->helper->get('plugin')])) {
381 unset($transient->no_update[$this->helper->get('plugin')]);
382 }
383 }
384 }
385
386 return $transient;
387 }
388
389 // vc_gitem_template_attribute_e2pdf_download filter
390 public function filter_vc_gitem_template_attribute_e2pdf_download($value, $data) {
391
392 $post = isset($data['post']) ? $data['post'] : null;
393 $data = isset($data['data']) ? $data['data'] : '';
394
395 $atts = [];
396 parse_str($data, $atts);
397 if (!empty($post->ID)) {
398 $atts['dataset'] = $post->ID;
399 }
400 $atts = array_filter((array) $atts, 'strlen');
401 return (new Model_E2pdf_Shortcode())->e2pdf_download($atts);
402 }
403
404 // vc_gitem_template_attribute_e2pdf_view filter
405 public function filter_vc_gitem_template_attribute_e2pdf_view($value, $data) {
406
407 $post = isset($data['post']) ? $data['post'] : null;
408 $data = isset($data['data']) ? $data['data'] : '';
409
410 $atts = [];
411 parse_str($data, $atts);
412 if (!empty($post->ID)) {
413 $atts['dataset'] = $post->ID;
414 }
415 $atts = array_filter((array) $atts, 'strlen');
416 return (new Model_E2pdf_Shortcode())->e2pdf_view($atts);
417 }
418
419 // vc_grid_item_shortcodes filter
420 public function filter_vc_grid_item_shortcodes($shortcodes) {
421 if (class_exists('Vc_Grid_Item_Editor') && method_exists('Vc_Grid_Item_Editor', 'postType')) {
422 $shortcodes['e2pdf_vc_download_item'] = [
423 'name' => '[e2pdf-download]',
424 'base' => 'e2pdf-vc-download-item',
425 'icon' => 'vc_general vc_element-icon e2pdf_vc_element-icon',
426 'category' => esc_html__('Content', 'js_composer'),
427 'description' => esc_html__('Display E2Pdf PDF Download', 'e2pdf'),
428 'post_type' => Vc_Grid_Item_Editor::postType(),
429 'params' => $this->helper->load('vc')->params('e2pdf-download'),
430 ];
431 }
432 return $shortcodes;
433 }
434
435 // pre_do_shortcode_tag filter
436 public function filter_pre_do_shortcode_tag($output, $tag) {
437 if (in_array($tag, $this->helper->shortcodes(), true) && !$this->process_shortcodes()) {
438 return '[' . $tag . '::disabled]';
439 }
440 return $output;
441 }
442
443 // process shortcodes
444 public function process_shortcodes() {
445 $process_shortcodes = is_preview() && !current_user_can('publish_posts') ? false : true;
446 return apply_filters('e2pdf_process_shortcodes', $process_shortcodes);
447 }
448
449 // vc_before_init action
450 public function action_vc_before_init() {
451 if (function_exists('vc_map')) {
452 vc_map(
453 [
454 'name' => '[e2pdf-download]',
455 'description' => esc_html__('Display E2Pdf PDF Download', 'e2pdf'),
456 'base' => 'e2pdf-vc-download',
457 'class' => '',
458 'icon' => 'vc_general vc_element-icon e2pdf_vc_element-icon',
459 'category' => esc_html__('Content', 'js_composer'),
460 'params' => $this->helper->load('vc')->params('e2pdf-download'),
461 ]
462 );
463 vc_map(
464 [
465 'name' => '[e2pdf-view]',
466 'description' => esc_html__('Display E2Pdf PDF View', 'e2pdf'),
467 'base' => 'e2pdf-vc-view',
468 'class' => '',
469 'icon' => 'vc_general vc_element-icon e2pdf_vc_element-icon',
470 'category' => esc_html__('Content', 'js_composer'),
471 'params' => $this->helper->load('vc')->params('e2pdf-view'),
472 ]
473 );
474 }
475 }
476
477 // admin_menu action
478 public function action_admin_menu() {
479 ob_start();
480 $caps = $this->helper->get_caps();
481 if (current_user_can('manage_options')) {
482 foreach ($caps as $cap_key => $cap) {
483 $caps[$cap_key]['cap'] = 'manage_options';
484 }
485 }
486 add_menu_page('e2pdf', 'E2Pdf', $caps['e2pdf']['cap'], 'e2pdf', [Helper_E2pdf_View::instance(), 'render_page'], $this->get_icon(), '26');
487 add_submenu_page('e2pdf', __('Create PDF', 'e2pdf'), __('Create PDF', 'e2pdf'), $caps['e2pdf']['cap'], 'e2pdf', [Helper_E2pdf_View::instance(), 'render_page']);
488 add_submenu_page('e2pdf', __('Templates', 'e2pdf'), __('Templates', 'e2pdf'), $caps['e2pdf_templates']['cap'], 'e2pdf-templates', [Helper_E2pdf_View::instance(), 'render_page']);
489 add_submenu_page('e2pdf', __('Integrations', 'e2pdf'), __('Integrations', 'e2pdf'), $caps['e2pdf_settings']['cap'], 'e2pdf-integrations', [Helper_E2pdf_View::instance(), 'render_page']);
490 add_submenu_page('e2pdf', __('Settings', 'e2pdf'), __('Settings', 'e2pdf'), $caps['e2pdf_settings']['cap'], 'e2pdf-settings', [Helper_E2pdf_View::instance(), 'render_page']);
491 add_submenu_page('e2pdf', __('License', 'e2pdf'), __('License', 'e2pdf'), $caps['e2pdf_license']['cap'], 'e2pdf-license', [Helper_E2pdf_View::instance(), 'render_page']);
492 if (get_option('e2pdf_debug', '0') === '1') {
493 add_submenu_page('e2pdf', __('Debug', 'e2pdf'), __('Debug', 'e2pdf'), $caps['e2pdf_debug']['cap'], 'e2pdf-debug', [Helper_E2pdf_View::instance(), 'render_page']);
494 }
495 }
496
497 // icon
498 public function get_icon() {
499 $icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBpZD0idXVpZC00NjQyOGQyMi0wMzg2LTQ1ZmItODEyZC03YzViMTg0NDhlZDciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDU4MCA1MDIuNTMiPgogIDxkZWZzPgogICAgPHN0eWxlPgogICAgICAuY2xzLTEgewogICAgICAgIGZpbGw6ICNhN2FhYWQ7CiAgICAgIH0KICAgIDwvc3R5bGU+CiAgPC9kZWZzPgogIDxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTY4LjI5LDBjLTEyLjM1LDAtMjMuOTMsMy4zMS0zMy45LDkuMDctMTAuMjksNS45NS0xOC44NywxNC41NC0yNC44MiwyNC44M0MzLjgsNDMuODcuNDksNTUuNDUuNDksNjcuOHYyMzcuMzRjMCwxMi4zNSwzLjMsMjMuOTMsOS4wNywzMy45MSw1Ljk1LDEwLjI5LDE0LjU0LDE4Ljg3LDI0LjgzLDI0LjgyLDkuOTcsNS43OCwyMS41NSw5LjA3LDMzLjksOS4wN2gyNDQuMTNjLS45MS00LjMzLTEuMzgtOC44MS0xLjM4LTEzLjQsMC03LjYxLDEuMy0xNC45MywzLjcxLTIxLjczLDQuNjYtMTMuMTksMTMuNDQtMjQuNDMsMjQuNzktMzIuMTh2LTYxLjY0Yy0zLjY3LTMuODktNS45MS05LjEzLTUuOTEtMTQuODlzMi4yNC0xMSw1LjkxLTE0Ljg5VjBINjguMjlaTTkwLjMzLDc3Ljc4aDE1OS4zNmMxMC45LDAsMTkuNzUsOS43NCwxOS43NSwyMS43M3MtOC44NSwyMS43NC0xOS43NSwyMS43NEg5MC4zM2MtMTAuOTEsMC0xOS43NC05LjczLTE5Ljc0LTIxLjc0czguODMtMjEuNzMsMTkuNzQtMjEuNzNaTTI0OS42OSwyOTUuMTdIOTAuMzNjLTEwLjkxLDAtMTkuNzQtOS43My0xOS43NC0yMS43NHM4LjgzLTIxLjc0LDE5Ljc0LTIxLjc0aDE1OS4zNmMxMC45LDAsMTkuNzUsOS43NCwxOS43NSwyMS43NHMtOC44NSwyMS43NC0xOS43NSwyMS43NFpNMjQ5LjY5LDIwOC4yMUg5MC4zM2MtMTAuOTEsMC0xOS43NC05LjczLTE5Ljc0LTIxLjc0czguODMtMjEuNzQsMTkuNzQtMjEuNzRoMTU5LjM2YzEwLjksMCwxOS43NSw5Ljc0LDE5Ljc1LDIxLjc0cy04Ljg1LDIxLjc0LTE5Ljc1LDIxLjc0WiIvPgogIDxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTU3MC45MSwxNjMuNDljLTUuOTUtMTAuMjktMTQuNTMtMTguODctMjQuODMtMjQuODMtOS45Ni01Ljc2LTIxLjU0LTkuMDctMzMuODktOS4wN0gyNDAuOTR2MzUuMTRoOC43NWMxMC45LDAsMTkuNzUsOS43NCwxOS43NSwyMS43NHMtOC44NSwyMS43NC0xOS43NSwyMS43NGgtOC43NXY0My40OGg4Ljc1YzEwLjksMCwxOS43NSw5Ljc0LDE5Ljc1LDIxLjc0cy04Ljg1LDIxLjc0LTE5Ljc1LDIxLjc0aC04Ljc1djIwNy4zNmgyNzEuMjVjMTIuMzUsMCwyMy45My0zLjI5LDMzLjg5LTkuMDcsMTAuMy01Ljk1LDE4Ljg5LTE0LjUyLDI0Ljg0LTI0LjgyLDUuNzctOS45OCw5LjA3LTIxLjU2LDkuMDctMzMuOTF2LTIzNy4zNGMwLTEyLjM1LTMuMzEtMjMuOTMtOS4wOC0zMy45Wk00ODguMTYsNDI0Ljc2aC0xMTIuNzRjLTI4LjAzLS4zNS01MS44MS0xOC4zOS02MC42Ny00My40OC0uOTYtMi43LTEuNzQtNS40OS0yLjMzLTguMzQtLjkxLTQuMzMtMS4zOC04LjgxLTEuMzgtMTMuNCwwLTcuNjEsMS4zLTE0LjkzLDMuNzEtMjEuNzMsNC42Ni0xMy4xOSwxMy40NC0yNC40MywyNC43OS0zMi4xOCwxMC40Ni03LjEzLDIzLjEtMTEuMzEsMzYuNzMtMTEuMzFoNjUuMjJjMTIsMCwyMS43NC05LjczLDIxLjc0LTIxLjc0cy05Ljc0LTIxLjc0LTIxLjc0LTIxLjc0aC04Ni4xMmMtNi4yNSwwLTExLjg4LTIuNjMtMTUuODMtNi44NS0zLjY3LTMuODktNS45MS05LjEzLTUuOTEtMTQuODlzMi4yNC0xMSw1LjkxLTE0Ljg5YzMuOTYtNC4yMSw5LjU4LTYuODQsMTUuODMtNi44NGg4Ni45NmMyNi4zNy4zMiw0OC45NiwxNi4zMSw1OC45MywzOS4wOCwzLjUsOC4wMSw1LjQ1LDE2Ljg0LDUuNDUsMjYuMTMsMCwzNi4wMi0yOS4yLDY1LjIzLTY1LjIyLDY1LjIzaC02NS4yMmMtMTIuMDIsMC0yMS43NCw5LjcyLTIxLjc0LDIxLjczczkuNzIsMjEuNzQsMjEuNzQsMjEuNzRoMTExLjg5YzExLjk5LDAsMjEuNzMsOS43NCwyMS43MywyMS43NHMtOS43NCwyMS43NC0yMS43MywyMS43NFoiLz4KPC9zdmc+';
500 return $icon;
501 }
502
503 // settings page
504 public function action_admin_init() {
505 register_setting('e2pdf-settings', 'e2pdf_debug');
506 }
507
508 // admin_enqueue_scripts action
509 public function action_admin_enqueue_scripts($page) {
510 $version = get_option('e2pdf_debug', '0') === '1' ? strtotime('now') : $this->helper->get('version');
511 wp_register_style('e2pdf.backend.global', plugins_url('css/e2pdf.backend.global.css', $this->helper->get('plugin_file_path')), [], $version);
512 wp_enqueue_style('e2pdf.backend.global');
513 if (!in_array($page, $this->e2pdf_admin_pages, false)) {
514 return;
515 }
516
517 if ($page == 'e2pdf_page_e2pdf-templates') {
518 wp_enqueue_script(
519 'js/e2pdf.purify', plugins_url('js/dompurify/purify.min.js', $this->helper->get('plugin_file_path')), ['jquery'], $version, false
520 );
521 wp_enqueue_script(
522 'js/e2pdf.backend', plugins_url('js/e2pdf.backend.js', $this->helper->get('plugin_file_path')), ['jquery', 'js/e2pdf.purify'], $version, false
523 );
524 } else {
525 wp_enqueue_script(
526 'js/e2pdf.backend', plugins_url('js/e2pdf.backend.js', $this->helper->get('plugin_file_path')), ['jquery'], $version, false
527 );
528 }
529 wp_localize_script('js/e2pdf.backend', 'e2pdf_lang', $this->get_js('lang'));
530 wp_localize_script('js/e2pdf.backend', 'e2pdf_params', $this->get_js('params'));
531 wp_register_style('e2pdf.backend', plugins_url('css/e2pdf.backend.css', $this->helper->get('plugin_file_path')), [], $version);
532 wp_enqueue_style('e2pdf.backend');
533 }
534
535 // wp_enqueue_scripts action
536 public function action_wp_enqueue_scripts() {
537 $version = get_option('e2pdf_debug', '0') === '1' ? strtotime('now') : $this->helper->get('version');
538 wp_enqueue_style('css/e2pdf.frontend.global', plugins_url('css/e2pdf.frontend.global.css', $this->helper->get('plugin_file_path')), [], $version, 'all');
539 wp_register_script(
540 'js/e2pdf.frontend', plugins_url('js/e2pdf.frontend.js', $this->helper->get('plugin_file_path')), ['jquery'], $version, false
541 );
542 wp_enqueue_script(
543 'js/e2pdf.frontend'
544 );
545 }
546
547 // get fontend javascript
548 public function get_js($type) {
549 $data = [];
550 switch ($type) {
551 case 'lang':
552 $data = [
553 'Page will be removed! Continue?' => __('Page will be removed! Continue?', 'e2pdf'),
554 'Font will be removed! Continue?' => __('Font will be removed! Continue?', 'e2pdf'),
555 'Changes will not be saved! Continue?' => __('Changes will not be saved! Continue?', 'e2pdf'),
556 'Saved Template will be overwritten! Continue?' => __('Saved Template will be overwritten! Continue?', 'e2pdf'),
557 'All pages will be removed! Continue?' => __('All pages will be removed! Continue?', 'e2pdf'),
558 'Adding new pages not available in "Uploaded PDF"' => __('Adding new pages not available in "Uploaded PDF"', 'e2pdf'),
559 'Dataset will be removed! Continue?' => __('Dataset will be removed! Continue?', 'e2pdf'),
560 'All datasets will be removed! Continue?' => __('All datasets will be removed! Continue?', 'e2pdf'),
561 'WARNING: Template has changes after last save! Changes will be lost! Continue?' => __('WARNING: Template has changes after last save! Changes will be lost! Continue?', 'e2pdf'),
562 'Element will be removed! Continue?' => __('Element will be removed! Continue?', 'e2pdf'),
563 'Elements will be removed! Continue?' => __('Elements will be removed! Continue?', 'e2pdf'),
564 'Action will be removed! Continue?' => __('Action will be removed! Continue?', 'e2pdf'),
565 'Condition will be removed! Continue?' => __('Condition will be removed! Continue?', 'e2pdf'),
566 'All Field Values will be overwritten! Continue?' => __('All Field Values will be overwritten! Continue?', 'e2pdf'),
567 'Website will be forced to use "FREE" License Key! Continue?' => __('Website will be forced to use "FREE" License Key! Continue?', 'e2pdf'),
568 'Not Available in Revision Edit Mode' => __('Not Available in Revision Edit Mode', 'e2pdf'),
569 'The WYSIWYG editor is disabled for this HTML object' => __('The WYSIWYG editor is disabled for this HTML object', 'e2pdf'),
570 'WYSIWYG can only be applied within HTML elements' => __('WYSIWYG can only be applied within HTML elements', 'e2pdf'),
571 'Only single-page PDFs are allowed with the "FREE" license type' => __('Only single-page PDFs are allowed with the "FREE" license type', 'e2pdf'),
572 'Last condition can\'t be removed' => __('Last condition can\'t be removed', 'e2pdf'),
573 'In Progress...' => __('In Progress...', 'e2pdf'),
574 'Delete' => __('Delete', 'e2pdf'),
575 'Properties' => __('Properties', 'e2pdf'),
576 'License Key' => __('License Key', 'e2pdf'),
577 'Empty PDF' => __('Empty PDF', 'e2pdf'),
578 'Upload PDF' => __('Upload PDF', 'e2pdf'),
579 'Auto PDF' => __('Auto PDF', 'e2pdf'),
580 'Create PDF' => __('Create PDF', 'e2pdf'),
581 'Extension' => __('Extension', 'e2pdf'),
582 'Size' => __('Size', 'e2pdf'),
583 'Properties' => __('Properties', 'e2pdf'),
584 'Enter link here' => __('Enter link here', 'e2pdf'),
585 'Border' => __('Border', 'e2pdf'),
586 'Background' => __('Background', 'e2pdf'),
587 'Left' => __('Left', 'e2pdf'),
588 'Right' => __('Right', 'e2pdf'),
589 'Top' => __('Top', 'e2pdf'),
590 'Center' => __('Center', 'e2pdf'),
591 'Bottom' => __('Bottom', 'e2pdf'),
592 'Justify' => __('Justify', 'e2pdf'),
593 'Border Color' => __('Border Color', 'e2pdf'),
594 'Border Radius' => __('Border Radius', 'e2pdf'),
595 'Line Height' => __('Line Height', 'e2pdf'),
596 'Width' => __('Width', 'e2pdf'),
597 'Height' => __('Height', 'e2pdf'),
598 'Value' => __('Value', 'e2pdf'),
599 'Font' => __('Font', 'e2pdf'),
600 'Option' => __('Option', 'e2pdf'),
601 'Group' => __('Group', 'e2pdf'),
602 'Type' => __('Type', 'e2pdf'),
603 'Scale' => __('Scale', 'e2pdf'),
604 'Width&Height' => __('Width&Height', 'e2pdf'),
605 'Choose Image' => __('Choose Image', 'e2pdf'),
606 'Options' => __('Options', 'e2pdf'),
607 'PDF Upload' => __('PDF Upload', 'e2pdf'),
608 'Global Actions' => __('Global Actions', 'e2pdf'),
609 'Global Properties' => __('Global Properties', 'e2pdf'),
610 'Connection' => __('Connection', 'e2pdf'),
611 'Map Field' => __('Map Field', 'e2pdf'),
612 'Insert Mapped' => __('Insert Mapped', 'e2pdf'),
613 'Resize' => __('Resize', 'e2pdf'),
614 'Copy' => __('Copy', 'e2pdf'),
615 'Cut' => __('Cut', 'e2pdf'),
616 'Paste' => __('Paste', 'e2pdf'),
617 'Paste in Place' => __('Paste in Place', 'e2pdf'),
618 'Apply' => __('Apply', 'e2pdf'),
619 'Dynamic Height' => __('Dynamic Height', 'e2pdf'),
620 'Multipage' => __('Multipage', 'e2pdf'),
621 'Text Align' => __('Text Align', 'e2pdf'),
622 'Read-Only' => __('Read-Only', 'e2pdf'),
623 'Multiline' => __('Multiline', 'e2pdf'),
624 'Required' => __('Required', 'e2pdf'),
625 'Page Options' => __('Page Options', 'e2pdf'),
626 'Direction' => __('Direction', 'e2pdf'),
627 'Hide' => __('Hide', 'e2pdf'),
628 'Unhide' => __('Unhide', 'e2pdf'),
629 'Password' => __('Password', 'e2pdf'),
630 'Visual Mapper' => __('Visual Mapper', 'e2pdf'),
631 'Parent' => __('Parent', 'e2pdf'),
632 '--- Select ---' => __('--- Select ---', 'e2pdf'),
633 'Activated' => __('Activated', 'e2pdf'),
634 'Not Activated' => __('Not Activated', 'e2pdf'),
635 'Page ID' => __('Page ID', 'e2pdf'),
636 'Page ID inside Upload PDF' => __('Page ID inside Upload PDF', 'e2pdf'),
637 'Render Fields from Upload PDF' => __('Render Fields from Upload PDF', 'e2pdf'),
638 'Delete created E2Pdf Fields' => __('Delete created E2Pdf Fields', 'e2pdf'),
639 'Keep Image Ratio' => __('Keep Image Ratio', 'e2pdf'),
640 'Keep Lower Size' => __('Keep Lower Size', 'e2pdf'),
641 'Lock Aspect Ratio' => __('Lock Aspect Ratio', 'e2pdf'),
642 'Fill Image' => __('Fill Image', 'e2pdf'),
643 'Page' => __('Page', 'e2pdf'),
644 'Resolution' => __('Resolution', 'e2pdf'),
645 'Disable Text to Image' => __('Disable Text to Image', 'e2pdf'),
646 'Confirmation Code' => __('Confirmation Code', 'e2pdf'),
647 'Code' => __('Code', 'e2pdf'),
648 'Visual Mapper' => __('Visual Mapper', 'e2pdf'),
649 'Auto' => __('Auto', 'e2pdf'),
650 'Actions' => __('Actions', 'e2pdf'),
651 'Save' => __('Save', 'e2pdf'),
652 'Horizontal Align' => __('Horizontal Align', 'e2pdf'),
653 'Vertical Align' => __('Vertical Align', 'e2pdf'),
654 'Middle' => __('Middle', 'e2pdf'),
655 'Apply If' => __('Apply If', 'e2pdf'),
656 'Action' => __('Action', 'e2pdf'),
657 'Property' => __('Property', 'e2pdf'),
658 'If' => __('If', 'e2pdf'),
659 'Condition' => __('Condition', 'e2pdf'),
660 'Any' => __('Any', 'e2pdf'),
661 'All' => __('All', 'e2pdf'),
662 'Sort' => __('Sort', 'e2pdf'),
663 'E-Signature' => __('E-Signature', 'e2pdf'),
664 'Contact' => __('Contact', 'e2pdf'),
665 'Location' => __('Location', 'e2pdf'),
666 'Reason' => __('Reason', 'e2pdf'),
667 'Placeholder' => __('Placeholder', 'e2pdf'),
668 'Length' => __('Length', 'e2pdf'),
669 'Comb' => __('Comb', 'e2pdf'),
670 'None' => __('None', 'e2pdf'),
671 'Highlight' => __('Highlight', 'e2pdf'),
672 'Invert' => __('Invert', 'e2pdf'),
673 'Outline' => __('Outline', 'e2pdf'),
674 'Push' => __('Push', 'e2pdf'),
675 'Title' => __('Title', 'e2pdf'),
676 'Status' => __('Status', 'e2pdf'),
677 'Add Action' => __('Add Action', 'e2pdf'),
678 'Shortcodes' => __('Shortcodes', 'e2pdf'),
679 'Labels' => __('Labels', 'e2pdf'),
680 'Field Values' => __('Field Values', 'e2pdf'),
681 'Field Names' => __('Field Names', 'e2pdf'),
682 'Field Name' => __('Field Name', 'e2pdf'),
683 'As Field Name' => __('As Field Name', 'e2pdf'),
684 'Confirm' => __('Confirm', 'e2pdf'),
685 'Cancel' => __('Cancel', 'e2pdf'),
686 'Hide (If Empty)' => __('Hide (If Empty)', 'e2pdf'),
687 'Hide Page (If Empty)' => __('Hide Page (If Empty)', 'e2pdf'),
688 'Replace Value' => __('Replace Value', 'e2pdf'),
689 'Auto-Close' => __('Auto-Close', 'e2pdf'),
690 'New Lines to BR' => __('New Lines to BR', 'e2pdf'),
691 'Disable WYSIWYG Editor' => __('Disable WYSIWYG Editor', 'e2pdf'),
692 'CSS Priority' => __('CSS Priority', 'e2pdf'),
693 'CSS Style' => __('CSS Style', 'e2pdf'),
694 'Enabling WYSIWYG can affect "HTML" Source' => __('Enabling WYSIWYG can affect "HTML" Source', 'e2pdf'),
695 'Hidden Fields' => __('Hidden Fields', 'e2pdf'),
696 'Error Message' => __('Error Message', 'e2pdf'),
697 'Redirect URL' => __('Redirect URL', 'e2pdf'),
698 'Element' => __('Element', 'e2pdf'),
699 'Elements' => __('Elements', 'e2pdf'),
700 'Position Top' => __('Position Top', 'e2pdf'),
701 'Position Left' => __('Position Left', 'e2pdf'),
702 'Padding Top' => __('Padding Top', 'e2pdf'),
703 'Padding Bottom' => __('Padding Bottom', 'e2pdf'),
704 'Padding Left' => __('Padding Left', 'e2pdf'),
705 'Padding Right' => __('Padding Right', 'e2pdf'),
706 'Margin Top' => __('Margin Top', 'e2pdf'),
707 'Margin Bottom' => __('Margin Bottom', 'e2pdf'),
708 'Margin Left' => __('Margin Left', 'e2pdf'),
709 'Margin Right' => __('Margin Right', 'e2pdf'),
710 'Border Color' => __('Border Color', 'e2pdf'),
711 'Border Top' => __('Border Top', 'e2pdf'),
712 'Border Bottom' => __('Border Bottom', 'e2pdf'),
713 'Border Left' => __('Border Left', 'e2pdf'),
714 'Border Right' => __('Border Right', 'e2pdf'),
715 'Field' => __('Field', 'e2pdf'),
716 'Style' => __('Style', 'e2pdf'),
717 'Lock / Hide' => __('Lock / Hide', 'e2pdf'),
718 'Font Color' => __('Font Color', 'e2pdf'),
719 'Font Size' => __('Font Size', 'e2pdf'),
720 'Text Align' => __('Text Align', 'e2pdf'),
721 'Rotation' => __('Rotation', 'e2pdf'),
722 'Preg Replace Pattern' => __('Preg Replace Pattern', 'e2pdf'),
723 'Preg Replace Replacement' => __('Preg Replace Replacement', 'e2pdf'),
724 'Preg Match All Pattern' => __('Preg Match All Pattern', 'e2pdf'),
725 'Preg Match All Output' => __('Preg Match All Output', 'e2pdf'),
726 'Preg Filters' => __('Preg Filters', 'e2pdf'),
727 'Char Spacing' => __('Char Spacing', 'e2pdf'),
728 'Color' => __('Color', 'e2pdf'),
729 'QR Code' => __('QR Code', 'e2pdf'),
730 'Barcode' => __('Barcode', 'e2pdf'),
731 'Format' => __('Format', 'e2pdf'),
732 'Precision' => __('Precision', 'e2pdf'),
733 'L - Smallest' => __('L - Smallest', 'e2pdf'),
734 'M - Medium' => __('M - Medium', 'e2pdf'),
735 'Q - High' => __('Q - High', 'e2pdf'),
736 'H - Best' => __('H - Best', 'e2pdf'),
737 'All Templates for this Website will be deactivated! Continue?' => __('All Templates for this Website will be deactivated! Continue?', 'e2pdf'),
738 'Pre-uploaded PDF will be removed from E2Pdf Template! Continue?' => __('Pre-uploaded PDF will be removed from E2Pdf Template! Continue?', 'e2pdf'),
739 'Quiet Zone Size' => __('Quiet Zone Size', 'e2pdf'),
740 'Hide Label' => __('Hide Label', 'e2pdf'),
741 'Lock' => __('Lock', 'e2pdf'),
742 'Unlock' => __('Unlock', 'e2pdf'),
743 'Opacity' => __('Opacity', 'e2pdf'),
744 'Auto Font Size' => __('Auto Font Size', 'e2pdf'),
745 'Max Upload File Size' => __('Max Upload File Size', 'e2pdf'),
746 'The bulk export task will be removed! Continue?' => __('The bulk export task will be removed! Continue?', 'e2pdf'),
747 'The bulk export task will be stopped! Continue?' => __('The bulk export task will be stopped! Continue?', 'e2pdf'),
748 'The bulk export task will be started! Continue?' => __('The bulk export task will be started! Continue?', 'e2pdf'),
749 'Search...' => __('Search...', 'e2pdf'),
750 'Show Element' => __('Show Element', 'e2pdf'),
751 'Hide Element' => __('Hide Element', 'e2pdf'),
752 'Show Page' => __('Show Page', 'e2pdf'),
753 'Hide Page' => __('Hide Page', 'e2pdf'),
754 'Change to' => __('Change to', 'e2pdf'),
755 'Merge' => __('Merge', 'e2pdf'),
756 'Change Property' => __('Change Property', 'e2pdf'),
757 'Format' => __('Format', 'e2pdf'),
758 'Insert Before' => __('Insert Before', 'e2pdf'),
759 'Insert After' => __('Insert After', 'e2pdf'),
760 'Full Replacement' => __('Full Replacement', 'e2pdf'),
761 'Search / Replace' => __('Search / Replace', 'e2pdf'),
762 'Contains' => __('Contains', 'e2pdf'),
763 'Not Contains' => __('Not Contains', 'e2pdf'),
764 'In Array' => __('In Array', 'e2pdf'),
765 'Array Key Exists' => __('Array Key Exists', 'e2pdf'),
766 'Else' => __('Else', 'e2pdf'),
767 'Append' => __('Append', 'e2pdf'),
768 'Vertical' => __('Vertical', 'e2pdf'),
769 'Horizontal' => __('Horizontal', 'e2pdf'),
770 'Palette' => __('Palette', 'e2pdf'),
771 'Line / Stroke Color' => __('Line / Stroke Color', 'e2pdf'),
772 'Graph' => __('Graph', 'e2pdf'),
773 'Markers' => __('Markers', 'e2pdf'),
774 'Grid' => __('Grid', 'e2pdf'),
775 'Axis' => __('Axis', 'e2pdf'),
776 'Legend' => __('Legend', 'e2pdf'),
777 'Structure' => __('Structure', 'e2pdf'),
778 'Space' => __('Space', 'e2pdf'),
779 'Position' => __('Position', 'e2pdf'),
780 'Vertical Label' => __('Vertical Label', 'e2pdf'),
781 'Horizontal Label' => __('Horizontal Label', 'e2pdf'),
782 'Label' => __('Label', 'e2pdf'),
783 'Axis Overlap' => __('Axis Overlap', 'e2pdf'),
784 'Grid Spacing' => __('Grid Spacing', 'e2pdf'),
785 'Grid Spacing (V)' => __('Grid Spacing (V)', 'e2pdf'),
786 'Grid Spacing (H)' => __('Grid Spacing (H)', 'e2pdf'),
787 'Grid Division (V)' => __('Grid Division (V)', 'e2pdf'),
788 'Grid Division (H)' => __('Grid Division (H)', 'e2pdf'),
789 'Axis Color' => __('Axis Color', 'e2pdf'),
790 'Grid Color' => __('Grid Color', 'e2pdf'),
791 'Bar Label Color' => __('Bar Label Color', 'e2pdf'),
792 'Position (V)' => __('Position (V)', 'e2pdf'),
793 'Position (H)' => __('Position (H)', 'e2pdf'),
794 'Bar Labels' => __('Bar Labels', 'e2pdf'),
795 'Marker' => __('Marker', 'e2pdf'),
796 'Grid Subdivision Color' => __('Grid Subdivision Color', 'e2pdf'),
797 'Sub Divisions' => __('Sub Divisions', 'e2pdf'),
798 'Axis (V)' => __('Axis (V)', 'e2pdf'),
799 'Axis (H)' => __('Axis (H)', 'e2pdf'),
800 'Text' => __('Text', 'e2pdf'),
801 'Enable' => __('Enable', 'e2pdf'),
802 'Min' => __('Min', 'e2pdf'),
803 'Max' => __('Max', 'e2pdf'),
804 'Fill Under' => __('Fill Under', 'e2pdf'),
805 'Reverse' => __('Reverse', 'e2pdf'),
806 'Sort' => __('Sort', 'e2pdf'),
807 'Percentage' => __('Percentage', 'e2pdf'),
808 'Legend Text Side' => __('Legend Text Side', 'e2pdf'),
809 'Columns' => __('Columns', 'e2pdf'),
810 'Padding (X)' => __('Padding (X)', 'e2pdf'),
811 'Padding (Y)' => __('Padding (Y)', 'e2pdf'),
812 'Stroke Color' => __('Stroke Color', 'e2pdf'),
813 'Stroke Width' => __('Stroke Width', 'e2pdf'),
814 'Bubble Scale' => __('Bubble Scale', 'e2pdf'),
815 'Units' => __('Units', 'e2pdf'),
816 'Increment' => __('Increment', 'e2pdf'),
817 'Stack Group' => __('Stack Group', 'e2pdf'),
818 'Line Dataset' => __('Line Dataset', 'e2pdf'),
819 'Project Angle' => __('Project Angle', 'e2pdf'),
820 'Legends' => __('Legends', 'e2pdf'),
821 'Colors' => __('Colors', 'e2pdf'),
822 'Line Curve' => __('Line Curve', 'e2pdf'),
823 'Margin (H)' => __('Margin (H)', 'e2pdf'),
824 'Margin (V)' => __('Margin (V)', 'e2pdf'),
825 'Units Label' => __('Units Label', 'e2pdf'),
826 'Dynamic Line / Stroke Color' => __('Dynamic Line / Stroke Color', 'e2pdf'),
827 'Dynamic Marker Color' => __('Dynamic Marker Color', 'e2pdf'),
828 'Inner' => __('Inner', 'e2pdf'),
829 'Outer' => __('Outer', 'e2pdf'),
830 'Align' => __('Align', 'e2pdf'),
831 'Offset (X)' => __('Offset (X)', 'e2pdf'),
832 'Offset (Y)' => __('Offset (Y)', 'e2pdf'),
833 'Link URL' => __('Link URL', 'e2pdf'),
834 'Link Type' => __('Link Type', 'e2pdf'),
835 'Link Label' => __('Link Label', 'e2pdf'),
836 'Url' => __('Url', 'e2pdf'),
837 'Attachment' => __('Attachment', 'e2pdf'),
838 'Image' => __('Image', 'e2pdf'),
839 'Media Library' => __('Media Library', 'e2pdf'),
840 'Underline' => __('Underline', 'e2pdf'),
841 'Page Number' => __('Page Number', 'e2pdf'),
842 'Adjust Page Number' => __('Adjust Page Number', 'e2pdf'),
843 'Adjust Page Total' => __('Adjust Page Total', 'e2pdf'),
844 'Preload Images' => __('Preload Images', 'e2pdf'),
845 'Hooks' => __('Hooks', 'e2pdf'),
846 'Display PDF download at' => __('Display PDF download at', 'e2pdf'),
847 'Optimization' => __('Optimization', 'e2pdf'),
848 'Inherit' => __('Inherit', 'e2pdf'),
849 'Not Optimized' => __('Not Optimized', 'e2pdf'),
850 'Low Quality' => __('Low Quality', 'e2pdf'),
851 'Basic Quality' => __('Basic Quality', 'e2pdf'),
852 'Good Quality' => __('Good Quality', 'e2pdf'),
853 'Best Quality' => __('Best Quality', 'e2pdf'),
854 'Ultra Quality' => __('Ultra Quality', 'e2pdf'),
855 'Error: Empty "if" and "value" detected in action condition' => __('Error: Empty "if" and "value" detected in action condition', 'e2pdf'),
856 'No Read-Only' => __('No Read-Only', 'e2pdf'),
857 'No Border' => __('No Border', 'e2pdf'),
858 'Quick Props' => __('Quick Props', 'e2pdf'),
859 'The Template ID used in the backup will be overwritten. Continue?' => __('The Template ID used in the backup will be overwritten. Continue?', 'e2pdf'),
860 /* translators: %d: Template ID */
861 'This will overwrite the Template ID "%d". Continue?' => __('This will overwrite the Template ID "%d". Continue?', 'e2pdf'),
862 ];
863 break;
864 case 'params':
865 $nonces = [];
866 $caps = $this->helper->get_caps();
867 foreach ($caps as $cap) {
868 $nonces[$cap['cap']] = current_user_can('manage_options') || current_user_can($cap['cap']) ? wp_create_nonce($cap['cap']) : '';
869 }
870 $controller_e2pdf_templates = new Controller_E2pdf_Templates();
871 $model_e2pdf_extension = new Model_E2pdf_Extension();
872 $data = [
873 'nonce' => $nonces,
874 'plugins_url' => plugins_url('', $this->helper->get('plugin_file_path')),
875 'upload_url' => $this->helper->get_upload_url(),
876 'license_type' => $this->helper->get('license')->get('type'),
877 'upload_max_filesize' => $this->helper->load('files')->get_upload_max_filesize(),
878 'extensions' => $model_e2pdf_extension->extensions(),
879 'template_sizes' => $controller_e2pdf_templates->get_sizes_list(),
880 'css_styles' => array_keys($this->helper->load('properties')->css_styles()),
881 'undo_limit' => get_option('e2pdf_undo_limit', '20'),
882 ];
883 break;
884 case 'frontend_params':
885 $data = [
886 'pdfjs' => plugins_url('assets/pdf.js', $this->helper->get('plugin_file_path')),
887 ];
888 break;
889 default:
890 break;
891 }
892 return $data;
893 }
894
895 // requirenments
896 public function requirenments() {
897 if (version_compare(PHP_VERSION, '5.4', '<')) {
898 throw new Exception(
899 /* translators: %s: PHP Version */
900 sprintf(__('E2Pdf requires PHP version 5.4 or later. Your PHP version is %s', 'e2pdf'), PHP_VERSION)
901 );
902 }
903
904 if (!function_exists('curl_version')) {
905 throw new Exception(
906 /* translators: %s: PHP Extension */
907 sprintf(__('The PHP %s extension is required', 'e2pdf'), 'CURL')
908 );
909 }
910 }
911
912 // current_screen action
913 public function action_current_screen() {
914 $current_screen = get_current_screen();
915 if (!$current_screen || !in_array($current_screen->id, $this->e2pdf_admin_pages, false)) {
916 return;
917 }
918
919 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
920 if ($current_screen->id == 'toplevel_page_e2pdf' || ($current_screen->id == 'e2pdf_page_e2pdf-templates' && isset($_GET['action']) && $_GET['action'] == 'edit')) {
921 add_filter('admin_body_class', [&$this, 'filter_admin_body_loading_class']);
922 }
923
924 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
925 if ($current_screen->id == 'e2pdf_page_e2pdf-templates' && !isset($_GET['action'])) {
926 $screen_option = [
927 'label' => __('Templates per page', 'e2pdf') . ':',
928 'default' => get_option('e2pdf_templates_screen_per_page') ? get_option('e2pdf_templates_screen_per_page') : '20',
929 'option' => 'e2pdf_templates_screen_per_page',
930 ];
931 add_screen_option('per_page', $screen_option);
932 }
933
934 $this->helper->set('license', new Model_E2pdf_License());
935 if ($this->helper->get('license')->get('error') === 'Site Url Not Found. Please try to "Reactivate" plugin.') {
936 update_option('e2pdf_version', '1.00.00');
937 $this->action_plugins_loaded();
938 $this->helper->set('license', new Model_E2pdf_License());
939 }
940 }
941
942 // wp_loaded action
943 public function action_wp_loaded() {
944 if (get_option('e2pdf_adobesign_refresh_token') && !get_transient('e2pdf_adobesign_refresh_token')) {
945 new Model_E2pdf_AdobeSign();
946 }
947 }
948
949 // activate website wrapper
950 public function activate($network = false) {
951 global $wpdb;
952
953 try {
954 $this->requirenments();
955 if (is_multisite() && $network) {
956 foreach ($wpdb->get_col('SELECT blog_id FROM `' . $wpdb->blogs . '`') as $blog_id) {
957 $this->activate_site($blog_id);
958 }
959 } else {
960 $this->activate_site();
961 }
962 } catch (Exception $ex) {
963 echo '<div style="line-height: 70px;">';
964 echo $ex->getMessage();
965 echo '</div>';
966 exit();
967 }
968 }
969
970 // deactivate website wrapper
971 public function deactivate($network = false) {
972 global $wpdb;
973 if (is_multisite() && $network) {
974 foreach ($wpdb->get_col('SELECT blog_id FROM `' . $wpdb->blogs . '`') as $blog_id) {
975 $this->activate_site($blog_id);
976 }
977 } else {
978 $this->deactivate_site();
979 }
980 }
981
982 // wpmu_new_blog action
983 public function action_wpmu_new_blog($blog_id) {
984 if (is_plugin_active_for_network('e2pdf/e2pdf.php')) {
985 $this->activate_site($blog_id);
986 }
987 }
988
989 // activate site
990 public function activate_site($blog_id = false) {
991 global $wpdb;
992
993 $db_prefix = $wpdb->prefix;
994
995 if ($blog_id) {
996 switch_to_blog($blog_id);
997 $db_prefix = $wpdb->get_blog_prefix($blog_id);
998 if (!is_main_site($blog_id)) {
999 $this->helper->set('upload_dir', $this->helper->get_wp_upload_dir('basedir') . '/e2pdf/');
1000 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
1001 $this->helper->set('cache_dir', $this->helper->get('upload_dir') . 'tmp/cache/');
1002 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
1003 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
1004 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
1005 $this->helper->set('viewer_dir', $this->helper->get('upload_dir') . 'viewer/');
1006 $this->helper->set('bulk_dir', $this->helper->get('upload_dir') . 'bulks/');
1007 $this->helper->set('wpcf7_dir', $this->helper->get('upload_dir') . 'wpcf7/');
1008 }
1009 }
1010
1011 $dirs = [
1012 $this->helper->get('upload_dir'),
1013 $this->helper->get('tmp_dir'),
1014 $this->helper->get('cache_dir'),
1015 $this->helper->get('pdf_dir'),
1016 $this->helper->get('fonts_dir'),
1017 $this->helper->get('tpl_dir'),
1018 $this->helper->get('viewer_dir'),
1019 $this->helper->get('bulk_dir'),
1020 $this->helper->get('wpcf7_dir'),
1021 ];
1022
1023 if (!is_main_site($blog_id)) {
1024 array_unshift($dirs, $this->helper->get_wp_upload_dir('basedir'));
1025 }
1026
1027 foreach ($dirs as $dir) {
1028 if ($this->helper->create_dir($dir)) {
1029 if ($dir == $this->helper->get('fonts_dir')) {
1030 if (!file_exists($this->helper->get('fonts_dir') . 'NotoSans-Regular.ttf') || version_compare(get_option('e2pdf_version'), '1.10.05', '<')) {
1031 copy($this->helper->get('plugin_dir') . 'data/fonts/NotoSans-Regular.ttf', $this->helper->get('fonts_dir') . 'NotoSans-Regular.ttf');
1032 }
1033 } elseif ($dir == $this->helper->get('viewer_dir')) {
1034 if (!file_exists($this->helper->get('viewer_dir') . 'style.css')) {
1035 $this->helper->create_file($this->helper->get('viewer_dir') . 'style.css');
1036 }
1037 } elseif ($dir == $this->helper->get('bulk_dir') || $dir == $this->helper->get('cache_dir') || $dir == $this->helper->get('tmp_dir')) {
1038 $htaccess = $dir . '.htaccess';
1039 if (!file_exists($htaccess)) {
1040 $this->helper->create_file($htaccess, 'DENY FROM ALL');
1041 }
1042 }
1043 } else {
1044 throw new Exception(
1045 /* translators: %s: directory */
1046 sprintf(__("Can't create folder %s", 'e2pdf'), $dir)
1047 );
1048 }
1049 }
1050
1051 $this->helper->load('db')->db_init($db_prefix);
1052
1053 if (get_option('e2pdf_version') === false) {
1054 update_option('e2pdf_download_loader', '1');
1055 update_option('e2pdf_api_protocol', '1');
1056 }
1057
1058 if (class_exists('TRP_Translate_Press')) {
1059 if (get_option('e2pdf_pdf_translation') === false && get_option('e2pdf_translatepress_translation') !== false) {
1060 update_option('e2pdf_pdf_translation', get_option('e2pdf_translatepress_translation'));
1061 }
1062 }
1063
1064 if (get_option('e2pdf_pdf_translation_check') === false) {
1065 if (get_option('e2pdf_pdf_translation') === false && get_option('e2pdf_version') !== false && function_exists('icl_register_string')) {
1066 update_option('e2pdf_pdf_translation', '0');
1067 }
1068 update_option('e2pdf_pdf_translation_check', '1');
1069 }
1070
1071 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
1072 update_option('e2pdf_version', $this->helper->get('version'));
1073 }
1074
1075 if (get_option('e2pdf_nonce_key') === false) {
1076 if (function_exists('wp_generate_password')) {
1077 update_option('e2pdf_nonce_key', wp_generate_password('64'));
1078 }
1079 }
1080
1081 if (get_option('e2pdf_wc_invoice_template_id') !== false) {
1082 update_option('e2pdf_wc_my_orders_actions_template_id', get_option('e2pdf_wc_invoice_template_id'));
1083 }
1084 if (get_option('e2pdf_wc_invoice_statuses') !== false) {
1085 update_option('e2pdf_wc_my_orders_actions_template_id_status', get_option('e2pdf_wc_invoice_statuses'));
1086 }
1087 if (get_option('e2pdf_wc_checkout_template_id_order') !== false) {
1088 update_option('e2pdf_wc_checkout_template_id_priority', get_option('e2pdf_wc_checkout_template_id_order'));
1089 }
1090 if (get_option('e2pdf_wc_cart_template_id_order') !== false) {
1091 update_option('e2pdf_wc_cart_template_id_priority', get_option('e2pdf_wc_cart_template_id_order'));
1092 }
1093 if (get_option('e2pdf_version') && version_compare(get_option('e2pdf_version'), '1.16.14', '<') && get_option('e2pdf_wc_cart_template_id') && get_option('e2pdf_wc_cart_template_id_priority') === false) {
1094 update_option('e2pdf_wc_cart_template_id_priority', '99');
1095 }
1096
1097 if (get_option('e2pdf_zapier_api_key') === false) {
1098 if (function_exists('wp_generate_password')) {
1099 update_option('e2pdf_zapier_api_key', strtoupper(wordwrap(wp_generate_password('24', false), 4, '-', true)));
1100 }
1101 }
1102
1103 if (get_option('e2pdf_adobe_api_key') === false) {
1104 if (function_exists('wp_generate_password')) {
1105 update_option('e2pdf_adobe_api_key', strtoupper(wordwrap(wp_generate_password('24', false), 4, '-', true)));
1106 }
1107 }
1108
1109 if (get_option('e2pdf_gdrive_api_key') === false) {
1110 if (function_exists('wp_generate_password')) {
1111 update_option('e2pdf_gdrive_api_key', strtoupper(wordwrap(wp_generate_password('24', false), 4, '-', true)));
1112 }
1113 }
1114
1115 if (get_option('e2pdf_adobe_api_version') === false) {
1116 if (get_option('e2pdf_adobesign_client_id', '') && get_option('e2pdf_adobesign_client_secret', '')) {
1117 update_option('e2pdf_adobe_api_version', '0');
1118 } else {
1119 update_option('e2pdf_adobe_api_version', '1');
1120 }
1121 }
1122
1123 delete_option('e2pdf_developer');
1124 delete_option('e2pdf_developer_ips');
1125 delete_option('e2pdf_translatepress_translation');
1126 delete_option('e2pdf_wc_invoice_template_id');
1127 delete_option('e2pdf_wc_invoice_statuses');
1128 delete_option('e2pdf_wc_checkout_template_id_order');
1129 delete_option('e2pdf_wc_cart_template_id_order');
1130 delete_option('e2pdf_hash_timeout');
1131
1132 $model_e2pdf_api = new Model_E2pdf_Api();
1133 $model_e2pdf_api->set(
1134 [
1135 'action' => 'common/activate',
1136 ]
1137 );
1138 $model_e2pdf_api->request();
1139
1140 $model_e2pdf_license = new Model_E2pdf_License();
1141 $model_e2pdf_license->load_templates();
1142
1143 wp_clear_scheduled_hook('e2pdf_cronjob');
1144 if (!wp_next_scheduled('e2pdf_cache_tmp_cron')) {
1145 wp_schedule_event(time(), 'daily', 'e2pdf_cache_tmp_cron');
1146 }
1147
1148 if ($blog_id) {
1149 restore_current_blog();
1150 $this->helper->set('upload_dir', $this->helper->get_wp_upload_dir('basedir') . '/e2pdf/');
1151 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
1152 $this->helper->set('cache_dir', $this->helper->get('upload_dir') . 'tmp/cache/');
1153 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
1154 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
1155 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
1156 $this->helper->set('viewer_dir', $this->helper->get('upload_dir') . 'viewer/');
1157 $this->helper->set('bulk_dir', $this->helper->get('upload_dir') . 'bulks/');
1158 $this->helper->set('wpcf7_dir', $this->helper->get('upload_dir') . 'wpcf7/');
1159 }
1160 }
1161
1162 // deactivate site
1163 public function deactivate_site($blog_id = false) {
1164 if ($blog_id) {
1165 switch_to_blog($blog_id);
1166 }
1167 wp_clear_scheduled_hook('e2pdf_bulk_export_cron');
1168 wp_clear_scheduled_hook('e2pdf_cache_pdfs_cron');
1169 wp_clear_scheduled_hook('e2pdf_cache_tmp_cron');
1170 if ($blog_id) {
1171 restore_current_blog();
1172 }
1173 }
1174
1175 // uninstall
1176 public static function uninstall() {
1177 global $wpdb;
1178
1179 if (is_multisite()) {
1180 foreach ($wpdb->get_col('SELECT blog_id FROM `' . $wpdb->blogs . '`') as $blog_id) {
1181 self::uninstall_site($blog_id);
1182 }
1183 } else {
1184 self::uninstall_site();
1185 }
1186 }
1187
1188 // uninstall site
1189 public static function uninstall_site($blog_id = false) {
1190 global $wpdb;
1191
1192 $db_prefix = $wpdb->prefix;
1193 $helper = Helper_E2pdf_Helper::instance();
1194
1195 if ($blog_id) {
1196 switch_to_blog($blog_id);
1197 $db_prefix = $wpdb->get_blog_prefix($blog_id);
1198 if (!is_main_site($blog_id)) {
1199 $helper->set('upload_dir', $helper->get_wp_upload_dir('basedir') . '/e2pdf/');
1200 }
1201 }
1202
1203 wp_clear_scheduled_hook('e2pdf_bulk_export_cron');
1204 wp_clear_scheduled_hook('e2pdf_cache_pdfs_cron');
1205 wp_clear_scheduled_hook('e2pdf_cache_tmp_cron');
1206
1207 $model_e2pdf_api = new Model_E2pdf_Api();
1208 $model_e2pdf_api->set(
1209 [
1210 'action' => 'common/uninstall',
1211 ]
1212 );
1213 $model_e2pdf_api->request();
1214
1215 $options = Model_E2pdf_Options::get_options();
1216 foreach ($options as $option_key => $option_value) {
1217 delete_option($option_key);
1218 }
1219 delete_option('e2pdf_adobe_api_key');
1220 delete_option('e2pdf_adobe_api_version');
1221 delete_option('e2pdf_cache_tmp_ttl');
1222 delete_option('e2pdf_pdf_translation_check');
1223
1224 // phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared
1225 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_templates`');
1226 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_entries`');
1227 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_datasets`');
1228 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_pages`');
1229 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_elements`');
1230 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_revisions`');
1231 // phpcs:enable
1232 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1233 $wpdb->query($wpdb->prepare('DELETE FROM `' . $db_prefix . 'options` WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_e2pdf_%', '_transient_timeout_e2pdf_%'));
1234
1235 $helper->delete_dir($helper->get('upload_dir'));
1236
1237 $caps = $helper->get_caps();
1238 $roles = wp_roles()->get_names();
1239 foreach ($roles as $role_key => $sub_role) {
1240 $role = get_role($role_key);
1241 foreach ($caps as $cap_key => $cap) {
1242 $role->remove_cap($cap_key);
1243 }
1244 }
1245
1246 if ($blog_id) {
1247 restore_current_blog();
1248 $helper->set('upload_dir', $helper->get_wp_upload_dir('basedir') . '/e2pdf/');
1249 }
1250 }
1251 }
1252