PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.06
E2Pdf – Export Pdf Tool for WordPress v1.08.06
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.08.06, at classes/model/e2pdf-loader.php

752 lines 33.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
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
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Loader extends Model_E2pdf_Model {
17
18 private $errors = array();
19 private $e2pdf_admin_pages = array(
20 'toplevel_page_e2pdf',
21 'e2pdf_page_e2pdf-templates',
22 'e2pdf_page_e2pdf-settings',
23 'e2pdf_page_e2pdf-license',
24 'e2pdf_page_e2pdf-debug'
25 );
26
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 */
39 public function load() {
40 $this->load_translation();
41 $this->load_actions();
42 $this->load_filters();
43 $this->load_extensions();
44 $this->load_hooks();
45 $this->load_ajax();
46 $this->load_shortcodes();
47 }
48
49 /**
50 * Load translation
51 */
52 public function load_translation() {
53 load_plugin_textdomain('e2pdf', false, '/e2pdf/languages/');
54 }
55
56 /**
57 * Load ajax
58 */
59 public function load_ajax() {
60 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'));
77 }
78 }
79
80 /**
81 * Load actions
82 */
83 public function load_actions() {
84 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'));
92 }
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'));
96 }
97
98 public function load_filters() {
99
100 }
101
102 public function after_load() {
103 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
104 $this->activate();
105 }
106 }
107
108 /**
109 * Load extensions and its action/filters
110 */
111 public function load_extensions() {
112
113 $model_e2pdf_extension = new Model_E2pdf_Extension();
114 $extensions = $model_e2pdf_extension->extensions();
115 if (!empty($extensions)) {
116 foreach ($extensions as $extension => $extension_name) {
117 $model_e2pdf_extension->load($extension);
118 $model_e2pdf_extension->load_actions();
119 $model_e2pdf_extension->load_filters();
120 $model_e2pdf_extension->load_shortcodes();
121 }
122 }
123 }
124
125 /**
126 * Load filters
127 */
128 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'));
142 }
143
144 /**
145 * Load hooks
146 */
147 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'));
151 }
152
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';
162 }
163 }
164
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'));
172 }
173 }
174
175 /**
176 * Setup settings page
177 */
178 public function admin_settings() {
179 register_setting('e2pdf-settings', 'e2pdf_debug');
180 }
181
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');
190 }
191
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');
194 }
195
196 /**
197 * Load admin javascript
198 *
199 * @param string $page - Current page
200 */
201 public function admin_js($page) {
202
203 if (!in_array($page, $this->e2pdf_admin_pages)) {
204 return;
205 }
206
207 if (get_option('e2pdf_debug') === '1') {
208 $version = strtotime("now");
209 } else {
210 $version = $this->helper->get('version');
211 }
212
213 wp_enqueue_script(
214 'js/e2pdf.backend', plugins_url('js/e2pdf.backend.js', $this->helper->get('plugin_file_path')), array('jquery'), $version
215 );
216
217 $js_lang = $this->get_js('lang');
218 wp_localize_script('js/e2pdf.backend', 'e2pdfLang', $js_lang);
219
220 $js_size = $this->get_js('template_sizes');
221 wp_localize_script('js/e2pdf.backend', 'e2pdfTemplateSizes', $js_size);
222
223 $js_extension = $this->get_js('template_extensions');
224 wp_localize_script('js/e2pdf.backend', 'e2pdfTemplateExtensions', $js_extension);
225
226 $js_params = $this->get_js('params');
227 wp_localize_script('js/e2pdf.backend', 'e2pdfParams', $js_params);
228 }
229
230 /**
231 * Load admin javascript
232 *
233 * @param string $page - Current page
234 */
235 public function frontend_js() {
236
237 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')
239 );
240 wp_enqueue_script(
241 'js/e2pdf.frontend'
242 );
243 }
244
245 public function get_js($type) {
246
247 $data = array();
248
249 switch ($type) {
250 case 'lang':
251 $data = array(
252 'Delete' => __('Delete', 'e2pdf'),
253 'Properties' => __('Properties', 'e2pdf'),
254 '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 'Empty PDF' => __('Empty PDF', 'e2pdf'),
259 'Upload PDF' => __('Upload PDF', 'e2pdf'),
260 'Auto PDF' => __('Auto PDF', 'e2pdf'),
261 'Create PDF' => __('Create PDF', 'e2pdf'),
262 'Extension' => __('Extension', 'e2pdf'),
263 'Size' => __('Size', 'e2pdf'),
264 'Properties' => __('Properties', 'e2pdf'),
265 'Name' => __('Name', 'e2pdf'),
266 'Enter link here' => __('Enter link here', 'e2pdf'),
267 'Z-index' => __('Z-index', 'e2pdf'),
268 'Border' => __('Border', 'e2pdf'),
269 'Background' => __('Background', 'e2pdf'),
270 'Left' => __('Left', 'e2pdf'),
271 'Right' => __('Right', 'e2pdf'),
272 'Top' => __('Top', 'e2pdf'),
273 'Center' => __('Center', 'e2pdf'),
274 'Bottom' => __('Bottom', 'e2pdf'),
275 'Color' => __('Color', 'e2pdf'),
276 'Border Color' => __('Border Color', 'e2pdf'),
277 'Line Height' => __('Line Height', 'e2pdf'),
278 'Padding' => __('Padding', 'e2pdf'),
279 'Width' => __('Width', 'e2pdf'),
280 'Height' => __('Height', 'e2pdf'),
281 'Text Color' => __('Text Color', 'e2pdf'),
282 'Value' => __('Value', 'e2pdf'),
283 'Font' => __('Font', 'e2pdf'),
284 'Options' => __('Options', 'e2pdf'),
285 'Option' => __('Option', 'e2pdf'),
286 '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 'Type' => __('Type', 'e2pdf'),
297 'Scale' => __('Scale', 'e2pdf'),
298 'Width&Height' => __('Width&Height', 'e2pdf'),
299 'Width' => __('Width', 'e2pdf'),
300 'Height' => __('Height', 'e2pdf'),
301 'Choose Image' => __('Choose Image', 'e2pdf'),
302 'PDF Options' => __('PDF Options', 'e2pdf'),
303 'PDF Upload' => __('PDF Upload', 'e2pdf'),
304 'Item' => __('Item', 'e2pdf'),
305 'Position' => __('Position', 'e2pdf'),
306 'Copy' => __('Copy', 'e2pdf'),
307 'Cut' => __('Cut', 'e2pdf'),
308 'Paste' => __('Paste', 'e2pdf'),
309 'Paste in Place' => __('Paste in Place', 'e2pdf'),
310 'Apply' => __('Apply', 'e2pdf'),
311 'Dynamic Height' => __('Dynamic Height', 'e2pdf'),
312 'Text Align' => __('Text Align', 'e2pdf'),
313 'Read-Only' => __('Read-Only', 'e2pdf'),
314 'Multiline' => __('Multiline', 'e2pdf'),
315 '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 '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'),
335 'Hide' => __('Hide', 'e2pdf'),
336 'Show' => __('Show', 'e2pdf'),
337 'Password' => __('Password', 'e2pdf'),
338 'Map Field' => __('Map Field', 'e2pdf'),
339 'Parent' => __('Parent', 'e2pdf'),
340 '--- Select ---' => __('--- Select ---', 'e2pdf'),
341 'Activated' => __('Activated', 'e2pdf'),
342 'Not Activated' => __('Not Activated', 'e2pdf'),
343 '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'),
352 'Code' => __('Code', 'e2pdf'),
353 'Visual Mapper' => __('Visual Mapper', 'e2pdf'),
354 'Auto' => __('Auto', 'e2pdf'),
355 'Actions' => __('Actions', 'e2pdf'),
356 'Save' => __('Save', 'e2pdf'),
357 'Resize' => __('Resize', 'e2pdf'),
358 'Horizontal align' => __('Horizontal align', 'e2pdf'),
359 'Vertical align' => __('Vertical align', 'e2pdf'),
360 'Middle' => __('Middle', 'e2pdf'),
361 'Apply If' => __('Apply If', 'e2pdf'),
362 'Action' => __('Action', 'e2pdf'),
363 'Property' => __('Property', 'e2pdf'),
364 'If' => __('If', 'e2pdf'),
365 'Condition' => __('Condition', 'e2pdf'),
366 'Change' => __('Change', 'e2pdf'),
367 'Any' => __('Any', 'e2pdf'),
368 'All' => __('All', 'e2pdf'),
369 'Order' => __('Order', 'e2pdf'),
370 'E-signature' => __('E-signature', 'e2pdf'),
371 'Contact' => __('Contact', 'e2pdf'),
372 'Location' => __('Location', 'e2pdf'),
373 'Reason' => __('Reason', 'e2pdf'),
374 'Placeholder' => __('Placeholder', 'e2pdf'),
375 'Length' => __('Length', 'e2pdf'),
376 'Comb' => __('Comb', 'e2pdf'),
377 'None' => __('None', 'e2pdf'),
378 'Highlight' => __('Highlight', 'e2pdf'),
379 'Invert' => __('Invert', 'e2pdf'),
380 'Outline' => __('Outline', 'e2pdf'),
381 'Push' => __('Push', 'e2pdf'),
382 'Title' => __('Title', 'e2pdf'),
383 'Status' => __('Status', 'e2pdf'),
384 'Add Action' => __('Add Action', 'e2pdf'),
385 'Shortcodes' => __('Shortcodes', 'e2pdf'),
386 'Labels' => __('Labels', 'e2pdf'),
387 'Field Values' => __('Field Values', 'e2pdf'),
388 'Field Names' => __('Field Names', 'e2pdf'),
389 'Field Name' => __('Field Name', 'e2pdf'),
390 'As Field Name' => __('As Field Name', 'e2pdf'),
391 'Confirm' => __('Confirm', 'e2pdf'),
392 'Cancel' => __('Cancel', 'e2pdf'),
393 'Hide (If Empty)' => __('Hide (If Empty)', 'e2pdf'),
394 'Hide Page (If Empty)' => __('Hide Page (If Empty)', 'e2pdf'),
395 'Preg Replace' => __('Preg Replace', 'e2pdf'),
396 'Pattern' => __('Pattern', 'e2pdf'),
397 'Replacement' => __('Replacement', 'e2pdf'),
398 'Replace Value' => __('Replace Value', 'e2pdf'),
399 'Auto-Close' => __('Auto-Close', 'e2pdf'),
400 'E2Pdf License Key' => __('E2Pdf License Key', 'e2pdf')
401 );
402 break;
403 case 'params':
404 $data = array(
405 'nonce' => wp_create_nonce('e2pdf_ajax'),
406 'plugins_url' => plugins_url('', $this->helper->get('plugin_file_path')),
407 'upload_url' => $this->helper->get_upload_url(),
408 'license_type' => $this->helper->get('license')->get('type')
409 );
410 break;
411 case 'template_sizes':
412 $controller_e2pdf_templates = new Controller_E2pdf_Templates();
413 $data = $controller_e2pdf_templates->get_sizes_list();
414 break;
415 case 'template_extensions':
416 $model_e2pdf_extension = new Model_E2pdf_Extension();
417 $data = $model_e2pdf_extension->extensions();
418 break;
419 default:
420 break;
421 }
422
423 return $data;
424 }
425
426 /**
427 * Check requirenments before activation
428 */
429 public function requirenments() {
430 if (version_compare(PHP_VERSION, '5.3.3', '<')) {
431 throw new Exception(
432 sprintf(__("E2Pdf requires PHP version 5.3.3 or later. Your PHP version is %s", 'e2pdf'), PHP_VERSION)
433 );
434 }
435 }
436
437 public function admin_functions() {
438 $current_screen = get_current_screen();
439 if (!$current_screen || !in_array($current_screen->id, $this->e2pdf_admin_pages)) {
440 return;
441 }
442
443 if ($current_screen->id == 'e2pdf_page_e2pdf-templates' && !isset($_GET['action'])) {
444 $screen_option = array(
445 '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 );
449 add_screen_option('per_page', $screen_option);
450 }
451
452 $this->helper->set('license', new Model_E2pdf_License());
453 }
454
455 public function wp_loaded() {
456 if (!get_transient('e2pdf_adobesign_refresh_token')) {
457 new Model_E2pdf_AdobeSign();
458 }
459 }
460
461 /**
462 * On plugin activation
463 */
464 public function activate() {
465 global $wpdb;
466
467 try {
468 $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) {
471 $this->activate_site($blog_id);
472 }
473 } else {
474 $this->activate_site();
475 }
476 } catch (Exception $e) {
477 echo "<div style='line-height: 70px;'>";
478 echo $e->getMessage();
479 echo "</div>";
480 exit();
481 }
482 }
483
484 public function activate_new_network($blog_id, $user_id, $domain, $path, $site_id, $meta) {
485 if (is_plugin_active_for_network('e2pdf/e2pdf.php')) {
486 $this->activate_site($blog_id);
487 }
488 }
489
490 public function activate_site($blog_id = false) {
491 global $wpdb;
492
493 $db_prefix = $wpdb->prefix;
494
495 $wp_upload_dir = wp_upload_dir();
496
497 if ($blog_id) {
498 switch_to_blog($blog_id);
499 $wp_upload_dir = wp_upload_dir();
500 $db_prefix = $wpdb->get_blog_prefix($blog_id);
501 if (!is_main_site($blog_id)) {
502 $this->helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
503 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
504 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
505 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
506 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
507 }
508 }
509
510 $dirs = array(
511 $this->helper->get('upload_dir'),
512 $this->helper->get('tmp_dir'),
513 $this->helper->get('pdf_dir'),
514 $this->helper->get('fonts_dir'),
515 $this->helper->get('tpl_dir'),
516 );
517
518 if (!is_main_site($blog_id)) {
519 array_unshift($dirs, $wp_upload_dir['basedir']);
520 }
521
522 foreach ($dirs as $dir) {
523 if ($this->helper->create_dir($dir)) {
524 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");
526 }
527 } else {
528 throw new Exception(
529 sprintf(__("Can't create folder %s", 'e2pdf'), $dir)
530 );
531 }
532 }
533
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);
538 }
539 }
540
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");
577
578 if (version_compare(get_option('e2pdf_version'), '0.01.54', '<')) {
579 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` DROP COLUMN `blank`");
580 }
581
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");
587 }
588
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");
596
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'");
599 }
600
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");
608
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");
615
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");
618 }
619
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");
637 }
638
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 }
644
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");
647 }
648
649 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
650 update_option('e2pdf_version', $this->helper->get('version'));
651 }
652
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 if ($blog_id) {
662 restore_current_blog();
663 $wp_upload_dir = wp_upload_dir();
664 $this->helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
665 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
666 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
667 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
668 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
669 }
670 }
671
672 /**
673 * On plugin deactivation
674 */
675 public function deactivate() {
676
677 }
678
679 /**
680 * On plugin uninstall
681 */
682 public static function uninstall() {
683 global $wpdb;
684
685 if (is_multisite() && is_super_admin() && is_main_site()) {
686 foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
687 self::uninstall_site($blog_id);
688 }
689 } else {
690 self::uninstall_site();
691 }
692 }
693
694 public static function uninstall_site($blog_id = false) {
695 global $wpdb;
696
697 $db_prefix = $wpdb->prefix;
698
699 $wp_upload_dir = wp_upload_dir();
700
701 $helper_e2pdf_helper = Helper_E2pdf_Helper::instance();
702
703 if ($blog_id) {
704 switch_to_blog($blog_id);
705 $wp_upload_dir = wp_upload_dir();
706 $db_prefix = $wpdb->get_blog_prefix($blog_id);
707
708 if (!is_main_site($blog_id)) {
709 $helper_e2pdf_helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
710 }
711 }
712
713
714 $model_e2pdf_api = new Model_E2pdf_Api();
715 $model_e2pdf_api->set(array(
716 'action' => 'common/uninstall'
717 ));
718 $model_e2pdf_api->request();
719
720 $options = Model_E2pdf_Options::get_options();
721 foreach ($options as $option_key => $option_value) {
722 delete_option($option_key, $option_value);
723 }
724
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' . '`');
730
731 $wpdb->query($wpdb->prepare('DELETE FROM `' . $db_prefix . 'options' . '` WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_e2pdf_%', '_transient_e2pdf_%'));
732
733 $helper_e2pdf_helper->delete_dir($helper_e2pdf_helper->get('upload_dir'));
734
735 $caps = $helper_e2pdf_helper->get_caps();
736 $roles = wp_roles()->get_names();
737 foreach ($roles as $role_key => $sub_role) {
738 $role = get_role($role_key);
739 foreach ($caps as $cap_key => $cap) {
740 $role->remove_cap($cap_key);
741 }
742 }
743
744 if ($blog_id) {
745 restore_current_blog();
746 $wp_upload_dir = wp_upload_dir();
747 $helper_e2pdf_helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
748 }
749 }
750
751 }
752