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