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

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