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 +104 -56 1.00.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,80 +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 - const UPGRADE_URL = 'https://e2pdf.com';
21 -
22 - /**
23 - * Create instance of class Model_E2pdf_Notification
24 - */
25 19 public static function instance() {
26 - if (!isset(self::$instance)) {
20 + if (self::$instance === null) {
27 21 self::$instance = new self();
28 22 }
29 23 return self::$instance;
30 24 }
31 25
32 - /**
33 - * Add notification
34 - *
35 - * @param string $type - Notification type
36 - * @param string $text - Notification text
37 - */
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
38 33 public function add_notification($type, $text) {
39 - $notifications = get_transient('e2pdf_notifications');
40 - $notifications[] = array(
34 +
35 + $notification_id = (int) round(microtime(true) * 1000) . '-' . bin2hex(random_bytes(3));
36 + $notifications = $this->load();
37 +
38 + $notifications[$notification_id] = [
41 39 'type' => $type,
42 40 'text' => $text,
43 - );
44 - 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;
45 50 }
46 51
47 - /**
48 - * Get notifications
49 - *
50 - * @return array - List of notifications
51 - */
52 - public function get_notifications() {
53 - $notifications = get_transient('e2pdf_notifications');
54 - if (!get_option('e2pdf_hide_warnings')) {
52 + // get notifications
53 + public function get_notifications($notification_id = '') {
55 54
56 - if (!is_array($notifications)) {
57 - $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]);
58 69 }
70 + }
59 71
60 - if (get_site_option('e2pdf_force_update')) {
61 - array_unshift($notifications, array(
62 - 'type' => 'error',
63 - 'text' => __("E2Pdf was not able to download needed extensions. Please check for plugin updates at Dashboard -> Updates and update E2Pdf plugin", 'e2pdf')
64 - ));
65 - }
72 + set_transient('e2pdf_notifications', $notifications, DAY_IN_SECONDS);
66 73
74 + if (!get_option('e2pdf_hide_warnings', '0')) {
67 75 if ($this->helper->get('license')->get('status') == 'pre_expired') {
68 - array_unshift($notifications, array(
69 - 'type' => 'notice',
70 - 'text' => sprintf(__("Your E2Pdf License Key will expire at <strong>%s</strong>. Please renew it at <a target='_blank' href='%s'>%s</a>.", 'e2pdf'), $this->helper->get('license')->get('expire'), self::UPGRADE_URL, self::UPGRADE_URL)
71 - ));
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 + );
72 88 }
73 89
74 90 if ($this->helper->get('license')->get('status') == 'expired') {
75 - array_unshift($notifications, array(
76 - 'type' => 'error',
77 - 'text' => sprintf(__("Your E2Pdf License Key has expired. Please renew it at <a target='_blank' href='%s'>%s</a>.", 'e2pdf'), self::UPGRADE_URL, self::UPGRADE_URL)
78 - ));
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 + );
79 102 }
80 103
81 - if ($this->helper->get('license')->get('type') == 'FREE') {
82 - array_unshift($notifications, array(
83 - 'type' => 'notice',
84 - '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'), self::UPGRADE_URL, self::UPGRADE_URL)
85 - ));
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 + );
86 112 }
87 113 }
88 114
89 - set_transient('e2pdf_notifications', array());
90 - 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);
91 140 }
92 -
93 141 }