PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
← All changes | classes/model/e2pdf-notification.php +111 -44 1.08.001.32.49 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Notification Helper
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.00.01
4 + * File: /model/e2pdf-notification.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
@@ -14,61 +12,130 @@
14 12 }
15 13
16 14 class Model_E2pdf_Notification extends Model_E2pdf_Model {
17 15
18 - protected static $instance = NULL;
16 + private static $instance = null;
17 + private $notifications = [];
19 18
20 - /**
21 - * Add notification
22 - *
23 - * @param string $type - Notification type
24 - * @param string $text - Notification text
25 - */
19 + public static function instance() {
20 + if (self::$instance === null) {
21 + self::$instance = new self();
22 + }
23 + return self::$instance;
24 + }
25 +
26 + // load
27 + public function load() {
28 + $notifications = get_transient('e2pdf_notifications');
29 + return (is_array($notifications) && !empty($notifications)) ? $notifications : [];
30 + }
31 +
32 + // add notification
26 33 public function add_notification($type, $text) {
27 - $notifications = get_transient('e2pdf_notifications');
28 - $notifications[] = array(
34 +
35 + $notification_id = (int) round(microtime(true) * 1000) . '-' . bin2hex(random_bytes(3));
36 + $notifications = $this->load();
37 +
38 + $notifications[$notification_id] = [
29 39 'type' => $type,
30 40 'text' => $text,
31 - );
32 - set_transient('e2pdf_notifications', $notifications);
41 + 'expires' => time() + 10,
42 + ];
43 + set_transient('e2pdf_notifications', $notifications, DAY_IN_SECONDS);
44 +
45 + $this->notifications[$notification_id] = [
46 + 'type' => $type,
47 + 'text' => $text,
48 + ];
49 + return $notification_id;
33 50 }
34 51
35 - /**
36 - * Get notifications
37 - *
38 - * @return array - List of notifications
39 - */
40 - public function get_notifications() {
41 - $notifications = get_transient('e2pdf_notifications');
42 - if (!get_option('e2pdf_hide_warnings')) {
52 + // get notifications
53 + public function get_notifications($notification_id = '') {
43 54
44 - if (!is_array($notifications)) {
45 - $notifications = array();
55 + $notifications = $this->load();
56 + $now = time();
57 +
58 + if ($notification_id && isset($notifications[$notification_id])) {
59 + $this->notifications[$notification_id] = [
60 + 'type' => $notifications[$notification_id]['type'],
61 + 'text' => $notifications[$notification_id]['text'],
62 + ];
63 + unset($notifications[$notification_id]);
64 + }
65 +
66 + foreach ($notifications as $id => $entry) {
67 + if (isset($this->notifications[$id]) || $now >= $entry['expires']) {
68 + unset($notifications[$id]);
46 69 }
70 + }
47 71
72 + set_transient('e2pdf_notifications', $notifications, DAY_IN_SECONDS);
73 +
74 + if (!get_option('e2pdf_hide_warnings', '0')) {
48 75 if ($this->helper->get('license')->get('status') == 'pre_expired') {
49 - array_unshift($notifications, array(
50 - 'type' => 'notice',
51 - 'text' => sprintf(__("Your E2Pdf License Key will expire at <strong>%s</strong>. Please click <a target='_blank' href='%s'>here</a> to renew it.", 'e2pdf'), $this->helper->get('license')->get('expire'), 'https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license'))
52 - ));
76 + /* translators: %s: License Key Expire Date */
77 + $message = sprintf(__('Your E2Pdf License Key will expire at <strong>%s</strong>', 'e2pdf'), $this->helper->get('license')->get('expire'));
78 + if (current_user_can('manage_options') || current_user_can('e2pdf_license')) {
79 + $message .= ' | ' . sprintf('<a class="e2pdf-link" target="_blank" href="%s">%s »</a>', esc_url('https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license')), __('Renew License Key', 'e2pdf'));
80 + }
81 + array_unshift(
82 + $this->notifications,
83 + [
84 + 'type' => 'notice',
85 + 'text' => $message,
86 + ]
87 + );
53 88 }
54 89
55 90 if ($this->helper->get('license')->get('status') == 'expired') {
56 - array_unshift($notifications, array(
57 - 'type' => 'error',
58 - 'text' => sprintf(__("Your E2Pdf License Key has expired. Please click <a target='_blank' href='%s'>here</a> to renew it.", 'e2pdf'), 'https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license'))
59 - ));
91 + $message = __('Your E2Pdf License Key has expired', 'e2pdf');
92 + if (current_user_can('manage_options') || current_user_can('e2pdf_license')) {
93 + $message .= ' | ' . sprintf('<a class="e2pdf-link" target="_blank" href="%s">%s »</a>', esc_url('https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license')), __('Renew License Key', 'e2pdf'));
94 + }
95 + array_unshift(
96 + $this->notifications,
97 + [
98 + 'type' => 'error',
99 + 'text' => $message,
100 + ]
101 + );
60 102 }
61 103
62 - if ($this->helper->get('license')->get('type') == 'FREE') {
63 - array_unshift($notifications, array(
64 - 'type' => 'notice',
65 - 'text' => sprintf(__("You are using FREE license type. Up to 1 page and up to 1 template allowed. Please check <a target='_blank' href='%s'>%s</a> for upgrade options.", 'e2pdf'), 'https://e2pdf.com/price', 'https://e2pdf.com')
66 - ));
104 + if ($this->helper->get('license')->get('type') == 'FREE' && $this->helper->get('page') == 'e2pdf-templates') {
105 + array_unshift(
106 + $this->notifications,
107 + [
108 + 'type' => 'notice',
109 + 'text' => sprintf(__('You are using E2Pdf FREE License Type', 'e2pdf') . ' | ' . __('Up to 1 Page and up to 1 Template allowed', 'e2pdf') . ' | <a class="e2pdf-link" target="_blank" href="%s">%s »</a>', esc_url('https://e2pdf.com/price'), __('Upgrade License Key', 'e2pdf')),
110 + ]
111 + );
67 112 }
68 113 }
69 114
70 - set_transient('e2pdf_notifications', array());
71 - return $notifications;
115 + if ($this->helper->get('license')->get('error')) {
116 + foreach ($this->notifications as $key => $notify) {
117 + if ($notify['type'] === 'error' && $notify['text'] === $this->helper->get('license')->get('error')) {
118 + unset($this->notifications[$key]);
119 + }
120 + }
121 + if ($this->helper->get('license')->get('error') === 'License Key does not match this site. Please correct License Key to continue usage.') {
122 + $message = __('E2Pdf License Key does not match this site', 'e2pdf');
123 + if (current_user_can('manage_options') || current_user_can('e2pdf_license')) {
124 + /* translators: 1: Support URL 2: Support URL */
125 + $message .= ' | ' . sprintf(__('Failed to Restore License Key. Contact Support at <a target="_blank" href="%1$s">%2$s</a>', 'e2pdf'), 'https://e2pdf.com/support/contact', 'https://e2pdf.com/support/contact');
126 + }
127 + } else {
128 + $message = $this->helper->get('license')->get('error');
129 + }
130 + array_unshift(
131 + $this->notifications,
132 + [
133 + 'type' => 'error',
134 + 'text' => $message,
135 + ]
136 + );
137 + }
138 +
139 + return array_values($this->notifications);
72 140 }
73 -
74 141 }