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

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