PluginProbe
E2Pdf – Export Pdf Tool for WordPress / trunk
E2Pdf – Export Pdf Tool for WordPress vtrunk
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 1.08.09 All 71 releases
e2pdf / classes / model / e2pdf-notification.php

e2pdf-notification.php in E2Pdf – Export Pdf Tool for WordPress trunk, at classes/model/e2pdf-notification.php

142 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /model/e2pdf-notification.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Model_E2pdf_Notification extends Model_E2pdf_Model {
15
16 private static $instance = null;
17 private $notifications = [];
18
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
33 public function add_notification($type, $text) {
34
35 $notification_id = (int) round(microtime(true) * 1000) . '-' . bin2hex(random_bytes(3));
36 $notifications = $this->load();
37
38 $notifications[$notification_id] = [
39 'type' => $type,
40 'text' => $text,
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;
50 }
51
52 // get notifications
53 public function get_notifications($notification_id = '') {
54
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]);
69 }
70 }
71
72 set_transient('e2pdf_notifications', $notifications, DAY_IN_SECONDS);
73
74 if (!get_option('e2pdf_hide_warnings', '0')) {
75 if ($this->helper->get('license')->get('status') == 'pre_expired') {
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 );
88 }
89
90 if ($this->helper->get('license')->get('status') == 'expired') {
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 );
102 }
103
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 );
112 }
113 }
114
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);
140 }
141 }
142