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

727 lines 32.2 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
41 $this->load_translation();
42 $this->load_actions();
43 $this->load_filters();
44 $this->load_extensions();
45 $this->load_hooks();
46 $this->load_ajax();
47 $this->load_shortcodes();
48 }
49
50 public function load_translation() {
51 load_plugin_textdomain('e2pdf', false, '/e2pdf/languages/');
52 }
53
54 /**
55 * Load ajax
56 */
57 public function load_ajax() {
58 if (is_admin()) {
59 add_action('wp_ajax_e2pdf_save_form', array(new Controller_E2pdf_Templates(), 'ajax_save_form'));
60 add_action('wp_ajax_e2pdf_auto', array(new Controller_E2pdf_Templates(), 'ajax_auto'));
61 add_action('wp_ajax_e2pdf_upload', array(new Controller_E2pdf_Templates(), 'ajax_upload'));
62 add_action('wp_ajax_e2pdf_reupload', array(new Controller_E2pdf_Templates(), 'ajax_reupload'));
63 add_action('wp_ajax_e2pdf_extension', array(new Controller_E2pdf_Templates(), 'ajax_extension'));
64 add_action('wp_ajax_e2pdf_activate_template', array(new Controller_E2pdf_Templates(), 'ajax_activate_template'));
65 add_action('wp_ajax_e2pdf_deactivate_template', array(new Controller_E2pdf_Templates(), 'ajax_deactivate_template'));
66 add_action('wp_ajax_e2pdf_visual_mapper', array(new Controller_E2pdf_Templates(), 'ajax_visual_mapper'));
67 add_action('wp_ajax_e2pdf_get_styles', array(new Controller_E2pdf_Templates(), 'ajax_get_styles'));
68 add_action('wp_ajax_e2pdf_license_key', array(new Controller_E2pdf_License(), 'ajax_change_license_key'));
69 add_action('wp_ajax_e2pdf_templates', array(new Controller_E2pdf(), 'ajax_templates'));
70 add_action('wp_ajax_e2pdf_dataset', array(new Controller_E2pdf(), 'ajax_dataset'));
71 add_action('wp_ajax_e2pdf_delete_item', array(new Controller_E2pdf(), 'ajax_delete_item'));
72 add_action('wp_ajax_e2pdf_delete_items', array(new Controller_E2pdf(), 'ajax_delete_items'));
73 add_action('wp_ajax_e2pdf_delete_font', array(new Controller_E2pdf_Settings(), 'ajax_delete_font'));
74 add_action('wp_ajax_e2pdf_email', array(new Controller_E2pdf_Settings(), 'ajax_email'));
75 }
76 }
77
78 /**
79 * Load actions
80 */
81 public function load_actions() {
82 if (is_admin()) {
83 add_action('wpmu_new_blog', array(&$this, 'activate_new_network'), 10, 6);
84 add_action('admin_menu', array(&$this, 'admin_menu'));
85 add_action('admin_init', array(&$this, 'admin_settings'));
86 add_action('admin_enqueue_scripts', array(&$this, 'admin_js'));
87 add_action('admin_enqueue_scripts', array(&$this, 'admin_css'));
88 add_action('current_screen', array(&$this, 'admin_functions'));
89 add_action('plugins_loaded', array(&$this, 'after_load'));
90 }
91 add_action('wp_enqueue_scripts', array(&$this, 'frontend_js'));
92 add_action('wp', array(Helper_E2pdf_View::instance(), 'render_frontend_page'));
93 add_action('wp_loaded', array(&$this, 'wp_loaded'));
94 }
95
96 public function load_filters() {
97
98 }
99
100 public function after_load() {
101 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
102 $this->activate();
103 }
104 }
105
106 /**
107 * Load extensions and its action/filters
108 */
109 public function load_extensions() {
110
111 $model_e2pdf_extension = new Model_E2pdf_Extension();
112 $extensions = $model_e2pdf_extension->extensions();
113 if (!empty($extensions)) {
114 foreach ($extensions as $extension => $extension_name) {
115 $model_e2pdf_extension->load($extension);
116 $model_e2pdf_extension->load_actions();
117 $model_e2pdf_extension->load_filters();
118 $model_e2pdf_extension->load_shortcodes();
119 }
120 }
121 }
122
123 /**
124 * Load filters
125 */
126 public function load_shortcodes() {
127 add_shortcode('e2pdf-download', array(new Model_E2pdf_Shortcode(), 'e2pdf_download'));
128 add_shortcode('e2pdf-attachment', array(new Model_E2pdf_Shortcode(), 'e2pdf_attachment'));
129 add_shortcode('e2pdf-adobesign', array(new Model_E2pdf_Shortcode(), 'e2pdf_adobesign'));
130 add_shortcode('e2pdf-save', array(new Model_E2pdf_Shortcode(), 'e2pdf_save'));
131 add_shortcode('e2pdf-view', array(new Model_E2pdf_Shortcode(), 'e2pdf_view'));
132 add_shortcode('e2pdf-format-number', array(new Model_E2pdf_Shortcode(), 'e2pdf_format_number'));
133 add_shortcode('e2pdf-format-date', array(new Model_E2pdf_Shortcode(), 'e2pdf_format_date'));
134 add_shortcode('e2pdf-format-output', array(new Model_E2pdf_Shortcode(), 'e2pdf_format_output'));
135 add_shortcode('e2pdf-user', array(new Model_E2pdf_Shortcode(), 'e2pdf_user'));
136 add_shortcode('e2pdf-wp', array(new Model_E2pdf_Shortcode(), 'e2pdf_wp'));
137 add_shortcode('e2pdf-content', array(new Model_E2pdf_Shortcode(), 'e2pdf_content'));
138 add_shortcode('e2pdf-exclude', array(new Model_E2pdf_Shortcode(), 'e2pdf_exclude'));
139 add_shortcode('e2pdf-filter', array(new Model_E2pdf_Shortcode(), 'e2pdf_filter'));
140 }
141
142 /**
143 * Load hooks
144 */
145 public function load_hooks() {
146 register_activation_hook($this->helper->get('plugin_file_path'), array(&$this, 'activate'));
147 register_deactivation_hook($this->helper->get('plugin_file_path'), array(&$this, 'deactivate'));
148 register_uninstall_hook($this->helper->get('plugin_file_path'), array('Model_E2pdf_Loader', 'uninstall'));
149 }
150
151 /**
152 * Load admin menu
153 */
154 public function admin_menu() {
155 ob_start();
156 add_menu_page('e2pdf', 'E2Pdf', 'manage_options', 'e2pdf', array(Helper_E2pdf_View::instance(), 'render_page'), '', '26');
157 add_submenu_page('e2pdf', __('Export', 'e2pdf'), __('Export', 'e2pdf'), 'manage_options', 'e2pdf', array(Helper_E2pdf_View::instance(), 'render_page'));
158 add_submenu_page('e2pdf', __('Templates', 'e2pdf'), __('Templates', 'e2pdf'), 'manage_options', 'e2pdf-templates', array(Helper_E2pdf_View::instance(), 'render_page'));
159 add_submenu_page('e2pdf', __('Settings', 'e2pdf'), __('Settings', 'e2pdf'), 'manage_options', 'e2pdf-settings', array(Helper_E2pdf_View::instance(), 'render_page'));
160 add_submenu_page('e2pdf', __('License', 'e2pdf'), __('License', 'e2pdf'), 'manage_options', 'e2pdf-license', array(Helper_E2pdf_View::instance(), 'render_page'));
161 if (get_option('e2pdf_debug') === '1') {
162 add_submenu_page('e2pdf', __('Debug', 'e2pdf'), __('Debug', 'e2pdf'), 'manage_options', 'e2pdf-debug', array(Helper_E2pdf_View::instance(), 'render_page'));
163 }
164 }
165
166 /**
167 * Setup settings page
168 */
169 public function admin_settings() {
170 register_setting('e2pdf-settings', 'e2pdf_debug');
171 }
172
173 /**
174 * Load admin css
175 */
176 public function admin_css($page) {
177 if (get_option('e2pdf_debug') === '1') {
178 $version = strtotime("now");
179 } else {
180 $version = $this->helper->get('version');
181 }
182
183 wp_register_style('e2pdf.backend', plugins_url('css/e2pdf.backend.css', $this->helper->get('plugin_file_path')), array(), $version);
184 wp_enqueue_style('e2pdf.backend');
185 }
186
187 /**
188 * Load admin javascript
189 *
190 * @param string $page - Current page
191 */
192 public function admin_js($page) {
193
194 if (!in_array($page, $this->e2pdf_admin_pages)) {
195 return;
196 }
197
198 if (get_option('e2pdf_debug') === '1') {
199 $version = strtotime("now");
200 } else {
201 $version = $this->helper->get('version');
202 }
203
204 wp_enqueue_script(
205 'js/e2pdf.backend', plugins_url('js/e2pdf.backend.js', $this->helper->get('plugin_file_path')), array('jquery'), $version
206 );
207
208 $js_lang = $this->get_js('lang');
209 wp_localize_script('js/e2pdf.backend', 'e2pdfLang', $js_lang);
210
211 $js_size = $this->get_js('template_sizes');
212 wp_localize_script('js/e2pdf.backend', 'e2pdfTemplateSizes', $js_size);
213
214 $js_extension = $this->get_js('template_extensions');
215 wp_localize_script('js/e2pdf.backend', 'e2pdfTemplateExtensions', $js_extension);
216
217 $js_params = $this->get_js('params');
218 wp_localize_script('js/e2pdf.backend', 'e2pdfParams', $js_params);
219 }
220
221 /**
222 * Load admin javascript
223 *
224 * @param string $page - Current page
225 */
226 public function frontend_js() {
227
228 wp_register_script(
229 'js/e2pdf.frontend', plugins_url('js/e2pdf.frontend.js', $this->helper->get('plugin_file_path')), array('jquery'), $this->helper->get('version')
230 );
231 wp_enqueue_script(
232 'js/e2pdf.frontend'
233 );
234 }
235
236 public function get_js($type) {
237
238 $data = array();
239
240 switch ($type) {
241 case 'lang':
242 $data = array(
243 'Delete' => __('Delete', 'e2pdf'),
244 'Properties' => __('Properties', 'e2pdf'),
245 'License Key' => __('License Key', 'e2pdf'),
246 'Submit' => __('Submit', 'e2pdf'),
247 'Are you sure want to remove page?' => __('Are you sure want to remove page?', 'e2pdf'),
248 'Are you sure want to remove font?' => __('Are you sure want to remove font?', 'e2pdf'),
249 'Empty PDF' => __('Empty PDF', 'e2pdf'),
250 'Upload PDF' => __('Upload PDF', 'e2pdf'),
251 'Auto PDF' => __('Auto PDF', 'e2pdf'),
252 'Create PDF' => __('Create PDF', 'e2pdf'),
253 'Extension' => __('Extension', 'e2pdf'),
254 'Size' => __('Size', 'e2pdf'),
255 'Properties' => __('Properties', 'e2pdf'),
256 'Name' => __('Name', 'e2pdf'),
257 'Enter link here' => __('Enter link here', 'e2pdf'),
258 'Z-index' => __('Z-index', 'e2pdf'),
259 'Border' => __('Border', 'e2pdf'),
260 'Background' => __('Background', 'e2pdf'),
261 'Left' => __('Left', 'e2pdf'),
262 'Right' => __('Right', 'e2pdf'),
263 'Top' => __('Top', 'e2pdf'),
264 'Center' => __('Center', 'e2pdf'),
265 'Bottom' => __('Bottom', 'e2pdf'),
266 'Color' => __('Color', 'e2pdf'),
267 'Border Color' => __('Border Color', 'e2pdf'),
268 'Line Height' => __('Line Height', 'e2pdf'),
269 'Padding' => __('Padding', 'e2pdf'),
270 'Width' => __('Width', 'e2pdf'),
271 'Height' => __('Height', 'e2pdf'),
272 'Text Color' => __('Text Color', 'e2pdf'),
273 'Value' => __('Value', 'e2pdf'),
274 'Font' => __('Font', 'e2pdf'),
275 'Options' => __('Options', 'e2pdf'),
276 'Option' => __('Option', 'e2pdf'),
277 'Group' => __('Group', 'e2pdf'),
278 'Group Name' => __('Group Name', 'e2pdf'),
279 'Group Value' => __('Group Value', 'e2pdf'),
280 'Selector' => __('Selector', 'e2pdf'),
281 'Check' => __('Check', 'e2pdf'),
282 'Circle' => __('Circle', 'e2pdf'),
283 'Cross' => __('Cross', 'e2pdf'),
284 'Diamond' => __('Diamond', 'e2pdf'),
285 'Square' => __('Square', 'e2pdf'),
286 'Star' => __('Star', 'e2pdf'),
287 'Type' => __('Type', 'e2pdf'),
288 'Scale' => __('Scale', 'e2pdf'),
289 'Width&Height' => __('Width&Height', 'e2pdf'),
290 'Width' => __('Width', 'e2pdf'),
291 'Height' => __('Height', 'e2pdf'),
292 'Choose Image' => __('Choose Image', 'e2pdf'),
293 'PDF Options' => __('PDF Options', 'e2pdf'),
294 'PDF Upload' => __('PDF Upload', 'e2pdf'),
295 'Item' => __('Item', 'e2pdf'),
296 'Position' => __('Position', 'e2pdf'),
297 'Copy' => __('Copy', 'e2pdf'),
298 'Cut' => __('Cut', 'e2pdf'),
299 'Paste' => __('Paste', 'e2pdf'),
300 'Paste in Place' => __('Paste in Place', 'e2pdf'),
301 'Apply' => __('Apply', 'e2pdf'),
302 'Dynamic Height' => __('Dynamic Height', 'e2pdf'),
303 'Text Align' => __('Text Align', 'e2pdf'),
304 'Readonly' => __('Readonly', 'e2pdf'),
305 'Multiline' => __('Multiline', 'e2pdf'),
306 'Required' => __('Required', 'e2pdf'),
307 'Settings' => __('Settings', 'e2pdf'),
308 'Relative' => __('Relative', 'e2pdf'),
309 'Page Size' => __('Page Size', 'e2pdf'),
310 'Custom' => __('Custom', 'e2pdf'),
311 'Size Preset' => __('Size Preset', 'e2pdf'),
312 'Page Options' => __('Page Options', 'e2pdf'),
313 'Select' => __('Select', 'e2pdf'),
314 'Saved Template will be overwritten! Are you sure want to continue?' => __('Saved Template will be overwritten! Are you sure want to continue?', 'e2pdf'),
315 'All pages will be removed! Are you sure want to continue?' => __('All pages will be removed! Are you sure want to continue?', 'e2pdf'),
316 'Adding new pages not available in "Uploaded PDF"' => __('Adding new pages not available in "Uploaded PDF"', 'e2pdf'),
317 'Dataset will be removed! Are you sure want to continue?' => __('Dataset will be removed! Are you sure want to continue?', 'e2pdf'),
318 'All datasets will be removed! Are you sure want to continue?' => __('All datasets will be removed! Are you sure want to continue?', 'e2pdf'),
319 'WARNING: Template has changes after last save! Changes will be lost!' => __('WARNING: Template has changes after last save! Changes will be lost!', 'e2pdf'),
320 'Element will be removed! Are you sure want to continue?' => __('Element will be removed! Are you sure want to continue?', 'e2pdf'),
321 'Elements will be removed! Are you sure want to continue?' => __('Elements will be removed! Are you sure want to continue?', 'e2pdf'),
322 'Action will be removed! Are you sure want to continue?' => __('Action will be removed! Are you sure want to continue?', 'e2pdf'),
323 'Condition will be removed! Are you sure want to continue?' => __('Condition will be removed! Are you sure want to continue?', 'e2pdf'),
324 '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'),
325 'RTL' => __('RTL', 'e2pdf'),
326 'Hide' => __('Hide', 'e2pdf'),
327 'Show' => __('Show', 'e2pdf'),
328 'Password' => __('Password', 'e2pdf'),
329 'Map Field' => __('Map Field', 'e2pdf'),
330 'Parent' => __('Parent', 'e2pdf'),
331 'Hide Empty' => __('Hide Empty', 'e2pdf'),
332 '--- Select ---' => __('--- Select ---', 'e2pdf'),
333 'Activated' => __('Activated', 'e2pdf'),
334 'Not Activated' => __('Not Activated', 'e2pdf'),
335 'Page ID' => __('Page ID', 'e2pdf'),
336 'New Position' => __('New Position', 'e2pdf'),
337 'Render New Fields' => __('Render New Fields', 'e2pdf'),
338 'Flush Elements' => __('Flush Elements', 'e2pdf'),
339 'Keep dimension' => __('Keep dimension', 'e2pdf'),
340 'ID' => __('ID', 'e2pdf'),
341 'Only 1 page allowed with "FREE" license type' => __('Only 1 page allowed with "FREE" license type', 'e2pdf'),
342 'Last condition can\'t be removed' => __('Last condition can\'t be removed', 'e2pdf'),
343 'Confirmation code' => __('Confirmation code', 'e2pdf'),
344 'Code' => __('Code', 'e2pdf'),
345 'Visual Mapper' => __('Visual Mapper', 'e2pdf'),
346 'Auto' => __('Auto', 'e2pdf'),
347 'Actions' => __('Actions', 'e2pdf'),
348 'Save' => __('Save', 'e2pdf'),
349 'Resize' => __('Resize', 'e2pdf'),
350 'Horizontal align' => __('Horizontal align', 'e2pdf'),
351 'Vertical align' => __('Vertical align', 'e2pdf'),
352 'Middle' => __('Middle', 'e2pdf'),
353 'Apply If' => __('Apply If', 'e2pdf'),
354 'Action' => __('Action', 'e2pdf'),
355 'Property' => __('Property', 'e2pdf'),
356 'If' => __('If', 'e2pdf'),
357 'Condition' => __('Condition', 'e2pdf'),
358 'Change' => __('Change', 'e2pdf'),
359 'Any' => __('Any', 'e2pdf'),
360 'All' => __('All', 'e2pdf'),
361 'Order' => __('Order', 'e2pdf'),
362 'E-signature' => __('E-signature', 'e2pdf'),
363 'Contact' => __('Contact', 'e2pdf'),
364 'Location' => __('Location', 'e2pdf'),
365 'Reason' => __('Reason', 'e2pdf'),
366 'Placeholder' => __('Placeholder', 'e2pdf'),
367 'Length' => __('Length', 'e2pdf'),
368 'Comb' => __('Comb', 'e2pdf'),
369 'None' => __('None', 'e2pdf'),
370 'Highlight' => __('Highlight', 'e2pdf'),
371 'Invert' => __('Invert', 'e2pdf'),
372 'Outline' => __('Outline', 'e2pdf'),
373 'Push' => __('Push', 'e2pdf'),
374 'Title' => __('Title', 'e2pdf'),
375 'Status' => __('Status', 'e2pdf'),
376 'Add Action' => __('Add Action', 'e2pdf'),
377 'Shortcodes' => __('Shortcodes', 'e2pdf'),
378 'Labels' => __('Labels', 'e2pdf'),
379 'Field Values' => __('Field Values', 'e2pdf'),
380 'Field Names' => __('Field Names', 'e2pdf'),
381 'Field Name' => __('Field Name', 'e2pdf'),
382 'As Field Name' => __('As Field Name', 'e2pdf'),
383 'Confirm' => __('Confirm', 'e2pdf'),
384 'Cancel' => __('Cancel', 'e2pdf')
385 );
386 break;
387 case 'params':
388 $data = array(
389 'nonce' => wp_create_nonce('e2pdf_ajax'),
390 'plugins_url' => plugins_url('', $this->helper->get('plugin_file_path')),
391 'upload_url' => $this->helper->get_upload_url(),
392 'license_type' => $this->helper->get('license')->get('type')
393 );
394 break;
395 case 'template_sizes':
396 $controller_e2pdf_templates = new Controller_E2pdf_Templates();
397 $data = $controller_e2pdf_templates->get_sizes_list();
398 break;
399 case 'template_extensions':
400 $model_e2pdf_extension = new Model_E2pdf_Extension();
401 $data = $model_e2pdf_extension->extensions();
402 break;
403 default:
404 break;
405 }
406
407 return $data;
408 }
409
410 /**
411 * Check requirenments before activation
412 */
413 public function requirenments() {
414 if (version_compare(PHP_VERSION, '5.3.3', '<')) {
415 throw new Exception(
416 sprintf(__("E2Pdf requires PHP version 5.3.3 or later. Your PHP version is %s", 'e2pdf'), PHP_VERSION)
417 );
418 }
419 }
420
421 public function admin_functions() {
422 $current_screen = get_current_screen();
423 if (!$current_screen || !in_array($current_screen->id, $this->e2pdf_admin_pages)) {
424 return;
425 }
426
427 if ($current_screen->id == 'e2pdf_page_e2pdf-templates' && !isset($_GET['action'])) {
428 $screen_option = array(
429 'label' => __('Templates per page', 'e2pdf') . ':',
430 'default' => get_option('e2pdf_templates_screen_per_page') ? get_option('e2pdf_templates_screen_per_page') : '20',
431 'option' => 'e2pdf_templates_screen_per_page'
432 );
433 add_screen_option('per_page', $screen_option);
434 }
435
436 $this->helper->set('license', new Model_E2pdf_License());
437 }
438
439 public function wp_loaded() {
440 if (!get_transient('e2pdf_adobesign_refresh_token')) {
441 new Model_E2pdf_AdobeSign();
442 }
443 }
444
445 /**
446 * On plugin activation
447 */
448 public function activate() {
449 global $wpdb;
450
451 try {
452 $this->requirenments();
453 if (is_multisite() && is_super_admin() && is_main_site()) {
454 foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
455 $this->activate_site($blog_id);
456 }
457 } else {
458 $this->activate_site();
459 }
460 } catch (Exception $e) {
461 echo "<div style='line-height: 70px;'>";
462 echo $e->getMessage();
463 echo "</div>";
464 exit();
465 }
466 }
467
468 public function activate_new_network($blog_id, $user_id, $domain, $path, $site_id, $meta) {
469 if (is_plugin_active_for_network('e2pdf/e2pdf.php')) {
470 $this->activate_site($blog_id);
471 }
472 }
473
474 public function activate_site($blog_id = false) {
475 global $wpdb;
476
477 $db_prefix = $wpdb->prefix;
478
479 $wp_upload_dir = wp_upload_dir();
480
481 if ($blog_id) {
482 switch_to_blog($blog_id);
483 $wp_upload_dir = wp_upload_dir();
484 $db_prefix = $wpdb->get_blog_prefix($blog_id);
485 if (!is_main_site($blog_id)) {
486 $this->helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
487 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
488 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
489 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
490 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
491 }
492 }
493
494 $dirs = array(
495 $this->helper->get('upload_dir'),
496 $this->helper->get('tmp_dir'),
497 $this->helper->get('pdf_dir'),
498 $this->helper->get('fonts_dir'),
499 $this->helper->get('tpl_dir'),
500 );
501
502 if (!is_main_site($blog_id)) {
503 array_unshift($dirs, $wp_upload_dir['basedir']);
504 }
505
506 foreach ($dirs as $dir) {
507 if ($this->helper->create_dir($dir)) {
508 if ($dir == $this->helper->get('fonts_dir')) {
509 copy($this->helper->get('plugin_dir') . "data/fonts/NotoSans-Regular.ttf", $this->helper->get('fonts_dir') . "NotoSans-Regular.ttf");
510 }
511 } else {
512 throw new Exception(
513 sprintf(__("Can't create folder %s", 'e2pdf'), $dir)
514 );
515 }
516 }
517
518 $options = Model_E2pdf_Options::get_options();
519 foreach ($options as $option_key => $option_value) {
520 if (get_option($option_key) === false) {
521 add_option($option_key, $option_value);
522 }
523 }
524
525 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "e2pdf_templates` (
526 `ID` int(11) NOT NULL AUTO_INCREMENT,
527 `uid` varchar(255) NOT NULL,
528 `pdf` text,
529 `title` text,
530 `created_at` datetime NOT NULL,
531 `updated_at` datetime NOT NULL,
532 `flatten` enum('0','1','2') NOT NULL DEFAULT '0',
533 `compression` int(1) NOT NULL DEFAULT '-1',
534 `appearance` enum('0','1') NOT NULL DEFAULT '0',
535 `width` int(11) NOT NULL DEFAULT '0',
536 `height` int(11) NOT NULL DEFAULT '0',
537 `extension` varchar(255) NOT NULL,
538 `item` varchar(255) NOT NULL,
539 `format` enum('pdf') NOT NULL DEFAULT 'pdf',
540 `dataset_title` text NOT NULL,
541 `button_title` text NOT NULL,
542 `inline` enum('0','1') NOT NULL DEFAULT '0',
543 `auto` enum('0','1') NOT NULL DEFAULT '0',
544 `name` text NOT NULL,
545 `password` text NOT NULL,
546 `meta_title` text NOT NULL,
547 `meta_subject` text NOT NULL,
548 `meta_author` text NOT NULL,
549 `meta_keywords` text NOT NULL,
550 `font` varchar(255) NOT NULL,
551 `font_size` varchar(255) NOT NULL,
552 `font_color` varchar(255) NOT NULL,
553 `line_height` varchar(255) NOT NULL,
554 `fonts` longtext NOT NULL,
555 `trash` enum('0','1') NOT NULL DEFAULT '0',
556 `activated` enum('0','1') NOT NULL DEFAULT '0',
557 `locked` enum('0','1') NOT NULL DEFAULT '0',
558 `author` int(11) NOT NULL,
559 PRIMARY KEY (`ID`)
560 ) CHARSET=utf8 COLLATE=utf8_general_ci");
561
562 if (version_compare(get_option('e2pdf_version'), '0.01.54', '<')) {
563 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` DROP COLUMN `blank`");
564 }
565
566 if (version_compare(get_option('e2pdf_version'), '1.06.00', '<')) {
567 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `meta_title` text NOT NULL AFTER password");
568 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `meta_subject` text NOT NULL AFTER meta_title");
569 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `meta_author` text NOT NULL AFTER meta_subject");
570 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `meta_keywords` text NOT NULL AFTER meta_author");
571 }
572
573 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "e2pdf_entries` (
574 `ID` int(11) NOT NULL AUTO_INCREMENT,
575 `uid` varchar(255) NOT NULL,
576 `entry` longtext,
577 `pdf_num` int(11) NOT NULL DEFAULT '0',
578 PRIMARY KEY (`ID`)
579 ) CHARSET=utf8 COLLATE=utf8_general_ci");
580
581 if (version_compare(get_option('e2pdf_version'), '0.01.33', '<')) {
582 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_entries` ADD COLUMN `pdf_num` int(11) NOT NULL DEFAULT '0'");
583 }
584
585 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "e2pdf_datasets` (
586 `ID` int(11) NOT NULL AUTO_INCREMENT,
587 `extension` varchar(255) NOT NULL,
588 `item` varchar(255) NOT NULL,
589 `entry` longtext,
590 PRIMARY KEY (`ID`)
591 ) CHARSET=utf8 COLLATE=utf8_general_ci");
592
593 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "e2pdf_pages` (
594 `page_id` int(11) NOT NULL DEFAULT '0',
595 `template_id` int(11) NOT NULL DEFAULT '0',
596 `properties` longtext NOT NULL,
597 `actions` longtext NOT NULL
598 ) CHARSET=utf8 COLLATE=utf8_general_ci");
599
600 if (version_compare(get_option('e2pdf_version'), '0.01.63', '<')) {
601 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_pages` ADD COLUMN `actions` longtext NOT NULL");
602 }
603
604 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "e2pdf_elements` (
605 `page_id` int(11) NOT NULL DEFAULT '0',
606 `template_id` int(11) NOT NULL DEFAULT '0',
607 `element_id` int(11) NOT NULL DEFAULT '0',
608 `name` text NOT NULL,
609 `type` varchar(255) NOT NULL,
610 `top` int(11) NOT NULL DEFAULT '0',
611 `left` int(11) NOT NULL DEFAULT '0',
612 `width` int(11) NOT NULL DEFAULT '0',
613 `height` int(11) NOT NULL DEFAULT '0',
614 `value` longtext NOT NULL,
615 `properties` longtext NOT NULL,
616 `actions` longtext NOT NULL
617 ) CHARSET=utf8 COLLATE=utf8_general_ci");
618
619 if (version_compare(get_option('e2pdf_version'), '0.01.63', '<')) {
620 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_elements` ADD COLUMN `actions` longtext NOT NULL");
621 }
622
623 if (version_compare(get_option('e2pdf_version'), '1.04.00', '<')) {
624 $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 ");
625 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_pages` DROP COLUMN `ID`");
626 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_elements` DROP COLUMN `ID`");
627 }
628
629 if (version_compare(get_option('e2pdf_version'), '1.06.00', '<')) {
630 $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_elements` ADD COLUMN `name` text NOT NULL AFTER element_id");
631 }
632
633 if (get_option('e2pdf_version') !== $this->helper->get('version')) {
634 update_option('e2pdf_version', $this->helper->get('version'));
635 }
636
637 $model_e2pdf_api = new Model_E2pdf_Api();
638 $model_e2pdf_api->set(array(
639 'action' => 'common/activate'
640 ));
641 $model_e2pdf_api->request();
642
643 $model_e2pdf_license = new Model_E2pdf_License();
644
645 if ($blog_id) {
646 restore_current_blog();
647 $wp_upload_dir = wp_upload_dir();
648 $this->helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
649 $this->helper->set('tmp_dir', $this->helper->get('upload_dir') . 'tmp/');
650 $this->helper->set('pdf_dir', $this->helper->get('upload_dir') . 'pdf/');
651 $this->helper->set('fonts_dir', $this->helper->get('upload_dir') . 'fonts/');
652 $this->helper->set('tpl_dir', $this->helper->get('upload_dir') . 'tpl/');
653 }
654 }
655
656 /**
657 * On plugin deactivation
658 */
659 public function deactivate() {
660
661 }
662
663 /**
664 * On plugin uninstall
665 */
666 public static function uninstall() {
667 global $wpdb;
668
669 if (is_multisite() && is_super_admin() && is_main_site()) {
670 foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
671 self::uninstall_site($blog_id);
672 }
673 } else {
674 self::uninstall_site();
675 }
676 }
677
678 public static function uninstall_site($blog_id = false) {
679 global $wpdb;
680
681 $db_prefix = $wpdb->prefix;
682
683 $wp_upload_dir = wp_upload_dir();
684
685 $helper_e2pdf_helper = Helper_E2pdf_Helper::instance();
686
687 if ($blog_id) {
688 switch_to_blog($blog_id);
689 $wp_upload_dir = wp_upload_dir();
690 $db_prefix = $wpdb->get_blog_prefix($blog_id);
691
692 if (!is_main_site($blog_id)) {
693 $helper_e2pdf_helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
694 }
695 }
696
697
698 $model_e2pdf_api = new Model_E2pdf_Api();
699 $model_e2pdf_api->set(array(
700 'action' => 'common/uninstall'
701 ));
702 $model_e2pdf_api->request();
703
704 $options = Model_E2pdf_Options::get_options();
705 foreach ($options as $option_key => $option_value) {
706 delete_option($option_key, $option_value);
707 }
708
709 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_templates' . '`');
710 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_entries' . '`');
711 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_datasets' . '`');
712 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_pages' . '`');
713 $wpdb->query('DROP TABLE IF EXISTS `' . $db_prefix . 'e2pdf_elements' . '`');
714
715 $wpdb->query($wpdb->prepare('DELETE FROM `' . $db_prefix . 'options' . '` WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_e2pdf_%', '_transient_e2pdf_%'));
716
717 $helper_e2pdf_helper->delete_dir($helper_e2pdf_helper->get('upload_dir'));
718
719 if ($blog_id) {
720 restore_current_blog();
721 $wp_upload_dir = wp_upload_dir();
722 $helper_e2pdf_helper->set('upload_dir', $wp_upload_dir['basedir'] . '/e2pdf/');
723 }
724 }
725
726 }
727