Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
7 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
7 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfAdminNoticeQueue.php
177 lines
| 1 | <?php |
| 2 | |
| 3 | class wfAdminNoticeQueue { |
| 4 | protected static function _notices() { |
| 5 | return wfConfig::get_ser('adminNoticeQueue', array()); |
| 6 | } |
| 7 | |
| 8 | protected static function _setNotices($notices) { |
| 9 | wfConfig::set_ser('adminNoticeQueue', $notices); |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Adds an admin notice to the display queue. |
| 14 | * |
| 15 | * @param string $severity |
| 16 | * @param string $messageHTML |
| 17 | * @param bool|string $category If not false, notices with the same category will be removed prior to adding this one. |
| 18 | * @param bool|array $users If not false, an array of user IDs the notice should show for. |
| 19 | */ |
| 20 | public static function addAdminNotice($severity, $messageHTML, $category = false, $users = false) { |
| 21 | $notices = self::_notices(); |
| 22 | foreach ($notices as $id => $n) { |
| 23 | $usersMatches = false; |
| 24 | if (isset($n['users'])) { |
| 25 | $usersMatches = wfUtils::sets_equal($n['users'], $users); |
| 26 | } |
| 27 | else if ($users === false) { |
| 28 | $usersMatches = true; |
| 29 | } |
| 30 | |
| 31 | $categoryMatches = false; |
| 32 | if ($category !== false && isset($n['category']) && $n['category'] == $category) { |
| 33 | $categoryMatches = true; |
| 34 | } |
| 35 | |
| 36 | if ($usersMatches && $categoryMatches) { |
| 37 | unset($notices[$id]); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | $id = wfUtils::uuid(); |
| 42 | $notices[$id] = array( |
| 43 | 'severity' => $severity, |
| 44 | 'messageHTML' => $messageHTML, |
| 45 | ); |
| 46 | |
| 47 | if ($category !== false) { |
| 48 | $notices[$id]['category'] = $category; |
| 49 | } |
| 50 | |
| 51 | if ($users !== false) { |
| 52 | $notices[$id]['users'] = $users; |
| 53 | } |
| 54 | |
| 55 | self::_setNotices($notices); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Removes an admin notice using one of three possible search methods: |
| 60 | * |
| 61 | * 1. If $id matches. $category and $users are ignored |
| 62 | * 2. If $category matches. $users must be false for this. |
| 63 | * 3. If $category matches and the notice's user IDs matches $users. |
| 64 | * |
| 65 | * @param bool|int $id |
| 66 | * @param bool|string $category |
| 67 | * @param bool|int[] $users |
| 68 | */ |
| 69 | public static function removeAdminNotice($id = false, $category = false, $users = false) { |
| 70 | if ($id === false && $category === false && $users === false) { |
| 71 | return; |
| 72 | } |
| 73 | else if ($id !== false) { |
| 74 | $category = false; |
| 75 | $users = false; |
| 76 | } |
| 77 | |
| 78 | $notices = self::_notices(); |
| 79 | foreach ($notices as $nid => $n) { |
| 80 | if ($id == $nid) { //ID match |
| 81 | unset($notices[$nid]); |
| 82 | break; |
| 83 | } |
| 84 | else if ($id !== false) { |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | if ($category !== false && isset($n['category']) && $category == $n['category']) { |
| 89 | if ($users !== false) { |
| 90 | if (isset($n['users']) && wfUtils::sets_equal($users, $n['users'])) { |
| 91 | unset($notices[$nid]); |
| 92 | } |
| 93 | } |
| 94 | else { |
| 95 | unset($notices[$nid]); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | self::_setNotices($notices); |
| 100 | } |
| 101 | |
| 102 | public static function hasNotice($category = false, $users = false) { |
| 103 | $notices = self::_notices(); |
| 104 | foreach ($notices as $nid => $n) { |
| 105 | $categoryMatches = false; |
| 106 | if (($category === false && !isset($n['category'])) || ($category !== false && isset($n['category']) && $category == $n['category'])) { |
| 107 | $categoryMatches = true; |
| 108 | } |
| 109 | |
| 110 | $usersMatches = false; |
| 111 | if (($users === false && !isset($n['users'])) || ($users !== false && isset($n['users']) && wfUtils::sets_equal($users, $n['users']))) { |
| 112 | $usersMatches = true; |
| 113 | } |
| 114 | |
| 115 | if ($categoryMatches && $usersMatches) { |
| 116 | return true; |
| 117 | } |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | public static function enqueueAdminNotices() { |
| 123 | $user = wp_get_current_user(); |
| 124 | if ($user->ID == 0) { |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | $networkAdmin = is_multisite() && is_network_admin(); |
| 129 | $notices = self::_notices(); |
| 130 | $added = false; |
| 131 | foreach ($notices as $nid => $n) { |
| 132 | if (isset($n['users']) && array_search($user->ID, $n['users']) === false) { |
| 133 | continue; |
| 134 | } |
| 135 | |
| 136 | $notice = new wfAdminNotice($nid, $n['severity'], $n['messageHTML']); |
| 137 | if ($networkAdmin) { |
| 138 | add_action('network_admin_notices', array($notice, 'displayNotice')); |
| 139 | } |
| 140 | else { |
| 141 | add_action('admin_notices', array($notice, 'displayNotice')); |
| 142 | } |
| 143 | |
| 144 | $added = true; |
| 145 | } |
| 146 | |
| 147 | return $added; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | class wfAdminNotice { |
| 152 | const SEVERITY_CRITICAL = 'critical'; |
| 153 | const SEVERITY_WARNING = 'warning'; |
| 154 | const SEVERITY_INFO = 'info'; |
| 155 | |
| 156 | private $_id; |
| 157 | private $_severity; |
| 158 | private $_messageHTML; |
| 159 | |
| 160 | public function __construct($id, $severity, $messageHTML) { |
| 161 | $this->_id = $id; |
| 162 | $this->_severity = $severity; |
| 163 | $this->_messageHTML = $messageHTML; |
| 164 | } |
| 165 | |
| 166 | public function displayNotice() { |
| 167 | $severityClass = 'notice-info'; |
| 168 | if ($this->_severity == self::SEVERITY_CRITICAL) { |
| 169 | $severityClass = 'notice-error'; |
| 170 | } |
| 171 | else if ($this->_severity == self::SEVERITY_WARNING) { |
| 172 | $severityClass = 'notice-warning'; |
| 173 | } |
| 174 | |
| 175 | echo '<div class="wf-admin-notice notice ' . $severityClass . '" data-notice-id="' . esc_attr($this->_id) . '"><p>' . $this->_messageHTML . '</p><p>' . sprintf(__('<a class="wf-btn wf-btn-default wf-btn-sm wf-dismiss-link" href="#" onclick="wordfenceExt.dismissAdminNotice(\'%s\'); return false;">Dismiss</a>', 'wordfence'), esc_attr($this->_id)) . '</p></div>'; |
| 176 | } |
| 177 | } |