| 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 |
// add notification |
| 17 |
public function add_notification($type, $text) { |
| 18 |
|
| 19 |
$notifications = get_transient('e2pdf_notifications'); |
| 20 |
if (!is_array($notifications)) { |
| 21 |
$notifications = []; |
| 22 |
} |
| 23 |
|
| 24 |
$notifications[] = [ |
| 25 |
'type' => $type, |
| 26 |
'text' => $text, |
| 27 |
]; |
| 28 |
set_transient('e2pdf_notifications', $notifications); |
| 29 |
} |
| 30 |
|
| 31 |
// get notifications |
| 32 |
public function get_notifications() { |
| 33 |
|
| 34 |
$notifications = get_transient('e2pdf_notifications'); |
| 35 |
if (!is_array($notifications)) { |
| 36 |
$notifications = []; |
| 37 |
} |
| 38 |
|
| 39 |
if (!get_option('e2pdf_hide_warnings', '0')) { |
| 40 |
if ($this->helper->get('license')->get('status') == 'pre_expired') { |
| 41 |
/* translators: %s: License Key Expire Date */ |
| 42 |
$message = sprintf(__('Your E2Pdf License Key will expire at <strong>%s</strong>', 'e2pdf'), $this->helper->get('license')->get('expire')); |
| 43 |
if (current_user_can('manage_options') || current_user_can('e2pdf_license')) { |
| 44 |
$message .= ' | ' . sprintf('<a class="e2pdf-link" target="_blank" href="%s">%s »</a>', 'https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license'), __('Renew License Key', 'e2pdf')); |
| 45 |
} |
| 46 |
array_unshift( |
| 47 |
$notifications, |
| 48 |
[ |
| 49 |
'type' => 'notice', |
| 50 |
'text' => $message, |
| 51 |
] |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
if ($this->helper->get('license')->get('status') == 'expired') { |
| 56 |
$message = __('Your E2Pdf License Key has expired', 'e2pdf'); |
| 57 |
if (current_user_can('manage_options') || current_user_can('e2pdf_license')) { |
| 58 |
$message .= ' | ' . sprintf('<a class="e2pdf-link" target="_blank" href="%s">%s »</a>', 'https://e2pdf.com/checkout/license/renew/' . get_option('e2pdf_license'), __('Renew License Key', 'e2pdf')); |
| 59 |
} |
| 60 |
array_unshift( |
| 61 |
$notifications, |
| 62 |
[ |
| 63 |
'type' => 'error', |
| 64 |
'text' => $message, |
| 65 |
] |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
if ($this->helper->get('license')->get('type') == 'FREE' && $this->helper->get('page') == 'e2pdf-templates') { |
| 70 |
array_unshift( |
| 71 |
$notifications, |
| 72 |
[ |
| 73 |
'type' => 'notice', |
| 74 |
'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>', 'https://e2pdf.com/price', __('Upgrade License Key', 'e2pdf')), |
| 75 |
] |
| 76 |
); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if ($this->helper->get('license')->get('error')) { |
| 81 |
foreach ($notifications as $key => $notify) { |
| 82 |
if ($notify['type'] === 'error' && $notify['text'] === $this->helper->get('license')->get('error')) { |
| 83 |
unset($notifications[$key]); |
| 84 |
} |
| 85 |
} |
| 86 |
if ($this->helper->get('license')->get('error') === 'License Key does not match this site. Please correct License Key to continue usage.') { |
| 87 |
$message = __('E2Pdf License Key does not match this site', 'e2pdf'); |
| 88 |
if (current_user_can('manage_options') || current_user_can('e2pdf_license')) { |
| 89 |
$message .= ' | ' . sprintf('<a class="e2pdf-link" id="e2pdf-restore-license-key" href="javascript:void(0)" _wpnonce="%s">%s »</a>', wp_create_nonce('e2pdf_license'), __('Restore License Key', 'e2pdf')); |
| 90 |
} |
| 91 |
} else { |
| 92 |
$message = $this->helper->get('license')->get('error'); |
| 93 |
} |
| 94 |
array_unshift( |
| 95 |
$notifications, |
| 96 |
[ |
| 97 |
'type' => 'error', |
| 98 |
'text' => $message, |
| 99 |
] |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
set_transient('e2pdf_notifications', []); |
| 104 |
return $notifications; |
| 105 |
} |
| 106 |
} |
| 107 |
|