PHP 8.2.31
Preview: wfNotification.php Size: 6.70 KB
/home/nshryvcy/blissfulnepal.com/wp-content/plugins/wordfence/lib/wfNotification.php

<?php
class wfNotification implements JsonSerializable {
	const PRIORITY_LOW = 1500;
	const PRIORITY_DEFAULT = 1000;
	const PRIORITY_HIGH = 500;
	const PRIORITY_HIGH_CRITICAL = 501;
	const PRIORITY_HIGH_WARNING = 502;
	
	protected $_id;
	protected $_category;
	protected $_priority;
	protected $_ctime;
	protected $_html;
	protected $_links;
	
	public static function notifications($since = 0) {
		global $wpdb;
		$table_wfNotifications = wfDB::networkTable('wfNotifications');
		$rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE `new` = 1 AND `ctime` > %d ORDER BY `priority` ASC, `ctime` DESC", $since), ARRAY_A);
		$notifications = array();
		foreach ($rawNotifications as $raw) {
			$notifications[] = new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true);
		}
		return $notifications;
	}
	
	public static function getNotificationForID($id) {
		global $wpdb;
		$table_wfNotifications = wfDB::networkTable('wfNotifications');
		$rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE `id` = %s ORDER BY `priority` ASC, `ctime` DESC", $id), ARRAY_A);
		if (count($rawNotifications) == 1) {
			$raw = $rawNotifications[0];
			return new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true);
		}
		return null;
	}
	
	public static function getNotificationForCategory($category, $requireNew = true) {
		global $wpdb;
		$table_wfNotifications = wfDB::networkTable('wfNotifications');
		$rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE " . ($requireNew ? '`new` = 1 AND ' : '') . "`category` = %s ORDER BY `priority` ASC, `ctime` DESC LIMIT 1", $category), ARRAY_A);
		if (count($rawNotifications) == 1) {
			$raw = $rawNotifications[0];
			return new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true);
		}
		return null;
	}
	
	public static function reconcileNotificationsWithOptions() {
		$notification_updatesNeeded = wfConfig::get('notification_updatesNeeded');
		$notification_securityAlerts = wfConfig::get('notification_securityAlerts') || !wfConfig::p();
		$notification_promotions = wfConfig::get('notification_promotions') || !wfConfig::p();
		$notification_blogHighlights = wfConfig::get('notification_blogHighlights') || !wfConfig::p();
		$notification_productUpdates = wfConfig::get('notification_productUpdates') || !wfConfig::p();
		$notification_scanStatus = wfConfig::get('notification_scanStatus');
		
		$notifications = self::notifications();
		foreach ($notifications as $n) {
			$category = $n->category;
			
			if (preg_match('/^release/i', $category) && !$notification_productUpdates) { $n->markAsRead(); }
			if (preg_match('/^digest/i', $category) && !$notification_blogHighlights) { $n->markAsRead(); }
			if (preg_match('/^alert/i', $category) && !$notification_securityAlerts) { $n->markAsRead(); }
			if (preg_match('/^promo/i', $category) && !$notification_promotions) { $n->markAsRead(); }
			
			switch ($category) {
				case 'wfplugin_scan':
					if (!$notification_scanStatus) { $n->markAsRead(); }
					break;
				case 'wfplugin_updates':
					if (!$notification_updatesNeeded) { $n->markAsRead(); }
					break;
				case 'wfplugin_keyconflict':
				default:
					//Allow it
					break;
			}
		}
	}
	
	public function __construct($id, $priority, $html, $category = null, $ctime = null, $links = null, $memoryOnly = false) {
		if ($id === null) {
			$id = 'site-' . wfUtils::base32_encode(pack('I', wfConfig::atomicInc('lastNotificationID')));
		}
		
		if ($category === null) {
			$category = '';
		}
		
		if ($ctime === null) {
			$ctime = time();
		} 
		
		if (!is_array($links)) {
			$links = array();
		}
		
		$this->_id = $id;
		$this->_category = $category;
		$this->_priority = $priority;
		$this->_ctime = $ctime;
		$this->_html = $html;
		$this->_links = $links;
		
		global $wpdb;
		if (!$memoryOnly) {
			$linksJSON = json_encode($links);
			
			$notification_updatesNeeded = wfConfig::get('notification_updatesNeeded');
			$notification_securityAlerts = wfConfig::get('notification_securityAlerts') || !wfConfig::p();
			$notification_promotions = wfConfig::get('notification_promotions') || !wfConfig::p();
			$notification_blogHighlights = wfConfig::get('notification_blogHighlights') || !wfConfig::p();
			$notification_productUpdates = wfConfig::get('notification_productUpdates') || !wfConfig::p();
			$notification_scanStatus = wfConfig::get('notification_scanStatus');
			
			if (preg_match('/^release/i', $category) && !$notification_productUpdates) { return; }
			if (preg_match('/^digest/i', $category) && !$notification_blogHighlights) { return; }
			if (preg_match('/^alert/i', $category) && !$notification_securityAlerts) { return; }
			if (preg_match('/^promo/i', $category) && !$notification_promotions) { return; }
			
			switch ($category) {
				case 'wfplugin_scan':
					if (!$notification_scanStatus) { return; }
					break;
				case 'wfplugin_updates':
					if (!$notification_updatesNeeded) { return; }
					break;
				case 'wfplugin_keyconflict':
				default:
					//Allow it
					break;
			}
			
			$table_wfNotifications = wfDB::networkTable('wfNotifications');
			if (!empty($category)) {
				$existing = self::getNotificationForCategory($category);
				if ($existing) {
					$wpdb->query($wpdb->prepare("UPDATE {$table_wfNotifications} SET priority = %d, ctime = %d, html = %s, links = %s WHERE id = %s", $priority, $ctime, $html, $linksJSON, $existing->id));
					return;
				}
			}
			
			$wpdb->query($wpdb->prepare("INSERT IGNORE INTO {$table_wfNotifications} (id, category, priority, ctime, html, links) VALUES (%s, %s, %d, %d, %s, %s)", $id, $category, $priority, $ctime, $html, $linksJSON));
		}
	}
	
	public function __get($key){
		if ($key == 'id') { return $this->_id; }
		else if ($key == 'category') { return $this->_category; }
		else if ($key == 'priority') { return $this->_priority; }
		else if ($key == 'ctime') { return $this->_ctime; }
		else if ($key == 'html') { return $this->_html; }
		else if ($key == 'links') { return $this->_links; }
		throw new InvalidArgumentException();
	}
	
	public function markAsRead() {
		global $wpdb;
		$table_wfNotifications = wfDB::networkTable('wfNotifications');
		$wpdb->query($wpdb->prepare("UPDATE {$table_wfNotifications} SET `new` = 0 WHERE `id` = %s", $this->_id));
	}
	
	#[\ReturnTypeWillChange]
	public function jsonSerialize() {
		return array(
			'id' => $this->_id,
			'category' => $this->_category,
			'priority' => $this->_priority,
			'ctime' => $this->_ctime,
			'html' => $this->_html,
			'links' => $this->_links,
		);
	}
}

Directory Contents

Dirs: 4 × Files: 109

Name Size Perms Modified Actions
audit-log DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
dashboard DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
Diff DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
rest-api DIR
- drwxr-xr-x 2026-06-03 14:57:34
Edit Download
354 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
425 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.63 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.85 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.39 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.82 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.34 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.62 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.86 MB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.17 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
580 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.46 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.94 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
317 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.01 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.05 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.15 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.86 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.87 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.68 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
12.49 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
38.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
408 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
991 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.30 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.80 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.64 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
185 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.51 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.72 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
20.55 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.38 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.19 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.10 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
47.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.90 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
256.83 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.77 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
25.94 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.25 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
127.17 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.92 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.29 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.05 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.02 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.25 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
352.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
11.49 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
66.92 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.89 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.72 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.97 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.13 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
878 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.23 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
303 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
266 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.80 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.70 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.56 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
29.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
199.14 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.33 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
10.95 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
9.81 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
58.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.27 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
5.20 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
754 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
6.70 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
8.93 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.40 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
377 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
15.98 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
127.73 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.04 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.01 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
403 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
408 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.07 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
4.09 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.77 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
11.93 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.21 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
24.95 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.14 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
27.23 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
131.69 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
15.59 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
535 B lrw-r--r-- 2026-06-03 14:57:34
Edit Download
2.22 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.47 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
1.75 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
392.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
3.35 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
42.60 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
28.19 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download
18.35 KB lrw-r--r-- 2026-06-03 14:57:34
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).