PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.23
E2Pdf – Export Pdf Tool for WordPress v1.32.23
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 / model / e2pdf-loader.php

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

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