Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/popup-bu.../com/classes
File: NotificationCenter.php
<?php
[0] Fix | Delete
namespace sgpb;
[1] Fix | Delete
use sgpb\AdminHelper;
[2] Fix | Delete
[3] Fix | Delete
class SGPBNotificationCenter
[4] Fix | Delete
{
[5] Fix | Delete
private $requestUrl = SG_POPUP_BUILDER_NOTIFICATIONS_URL;
[6] Fix | Delete
private $cronTimeout = 'daily';
[7] Fix | Delete
[8] Fix | Delete
public function __construct()
[9] Fix | Delete
{
[10] Fix | Delete
$this->addActions();
[11] Fix | Delete
$this->activateCron();
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
public function addActions()
[15] Fix | Delete
{
[16] Fix | Delete
add_filter('sgpbCronTimeoutSettings', array($this, 'cronAddMinutes'), 10, 1);
[17] Fix | Delete
add_action('sgpbGetNotifications', array($this, 'updateNotificationsArray'));
[18] Fix | Delete
add_action('wp_ajax_sgpb_dismiss_notification', array($this, 'dismissNotification'));
[19] Fix | Delete
add_action('wp_ajax_sgpb_remove_notification', array($this, 'removeNotification'));
[20] Fix | Delete
add_action('wp_ajax_sgpb_reactivate_notification', array($this, 'reactivateNotification'));
[21] Fix | Delete
add_action('admin_head', array($this, 'menuItemCounter'));
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
public function menuItemCounter()
[25] Fix | Delete
{
[26] Fix | Delete
$count = count(self::getAllActiveNotifications(true));
[27] Fix | Delete
$hidden = '';
[28] Fix | Delete
if (empty($count)) {
[29] Fix | Delete
$hidden = ' sgpb-hide-add-button';
[30] Fix | Delete
}
[31] Fix | Delete
$script = "<script>
[32] Fix | Delete
jQuery(document).ready(function() {
[33] Fix | Delete
jQuery('.sgpb-menu-item-notification').remove();
[34] Fix | Delete
jQuery('.dashicons-menu-icon-sgpb').next().append('<span class=\"sgpb-menu-item-notification".esc_attr($hidden)."\">".esc_html($count)."</span>');
[35] Fix | Delete
});
[36] Fix | Delete
</script>";
[37] Fix | Delete
echo wp_kses($script, AdminHelper::allowed_html_tags());
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
public function setCronTimeout($cronTimeout)
[41] Fix | Delete
{
[42] Fix | Delete
$this->cronTimeout = $cronTimeout;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
public function getCronTimeout()
[46] Fix | Delete
{
[47] Fix | Delete
return $this->cronTimeout;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public function setRequestUrl($requestUrl)
[51] Fix | Delete
{
[52] Fix | Delete
$this->requestUrl = $requestUrl;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
public function getRequestUrl()
[56] Fix | Delete
{
[57] Fix | Delete
return $this->requestUrl;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
public function updateNotificationsArray()
[61] Fix | Delete
{
[62] Fix | Delete
$requestUrl = $this->getRequestUrl();
[63] Fix | Delete
$content = AdminHelper::getFileFromURL($requestUrl);
[64] Fix | Delete
$content = json_decode($content, true);
[65] Fix | Delete
$content = apply_filters('sgpbExtraNotifications', $content);
[66] Fix | Delete
// check later
[67] Fix | Delete
/*if (empty($content)) {
[68] Fix | Delete
update_option('sgpb-all-dismissed-notifications', array());
[69] Fix | Delete
}*/
[70] Fix | Delete
$content = wp_json_encode($content);
[71] Fix | Delete
update_option('sgpb-all-notifications-data', $content);
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
public function sortNotifications($allNotifications)
[75] Fix | Delete
{
[76] Fix | Delete
$allNotifications = json_decode($allNotifications, true);
[77] Fix | Delete
if (empty($allNotifications)) {
[78] Fix | Delete
$allNotifications = array();
[79] Fix | Delete
}
[80] Fix | Delete
$dismissed = self::getAllDismissedNotifications();
[81] Fix | Delete
// for the first time dismissed and active arrays should be empty
[82] Fix | Delete
if (empty($dismissed) && empty($active)) {
[83] Fix | Delete
$notifications = array();
[84] Fix | Delete
foreach ($allNotifications as $notification) {
[85] Fix | Delete
$id = $notification['id'];
[86] Fix | Delete
$notifications[$id] = $id;
[87] Fix | Delete
}
[88] Fix | Delete
update_option('sgpb-all-active-notifications', wp_json_encode($notifications));
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
public function cronAddMinutes($schedules)
[93] Fix | Delete
{
[94] Fix | Delete
$schedules['sgpb_notifications'] = array(
[95] Fix | Delete
'interval' => SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL * 3600,
[96] Fix | Delete
'display' => __('Twice Daily', 'popup-builder')
[97] Fix | Delete
);
[98] Fix | Delete
[99] Fix | Delete
return $schedules;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
public static function getAllActiveNotifications($hideDismissed = false)
[103] Fix | Delete
{
[104] Fix | Delete
$activeNotifications = array();
[105] Fix | Delete
$notifications = get_option('sgpb-all-notifications-data');
[106] Fix | Delete
$notifications = json_decode($notifications, true);
[107] Fix | Delete
if (empty($notifications)) {
[108] Fix | Delete
return array();
[109] Fix | Delete
}
[110] Fix | Delete
asort($notifications);
[111] Fix | Delete
[112] Fix | Delete
$dismissedNotifications = get_option('sgpb-all-dismissed-notifications');
[113] Fix | Delete
$dismissedNotifications = json_decode($dismissedNotifications, true);
[114] Fix | Delete
$extensions = AdminHelper::getAllExtensions();
[115] Fix | Delete
$extensionsKeys = wp_list_pluck($extensions['active'], 'key');
[116] Fix | Delete
foreach ($notifications as $notification) {
[117] Fix | Delete
$id = isset($notification['id']) ? $notification['id'] : '';
[118] Fix | Delete
[119] Fix | Delete
if (isset($notification['hideFor'])) {
[120] Fix | Delete
$hideForExtensions = explode(',', $notification['hideFor']);
[121] Fix | Delete
$arraysIntersect = array_intersect($extensionsKeys, $hideForExtensions);
[122] Fix | Delete
[123] Fix | Delete
// If only one condition -> free, single extension, bundle
[124] Fix | Delete
if (count($hideForExtensions) == 1) {
[125] Fix | Delete
// Free
[126] Fix | Delete
if ($notification['hideFor'] == SGPB_POPUP_PKG_FREE && empty($extensionsKeys) && !class_exists('SGPBActivatorPlugin')) {
[127] Fix | Delete
continue;
[128] Fix | Delete
}
[129] Fix | Delete
// Single extension
[130] Fix | Delete
else if (in_array($notification['hideFor'], $extensionsKeys)) {
[131] Fix | Delete
continue;
[132] Fix | Delete
}
[133] Fix | Delete
// Pro, if it is a free user
[134] Fix | Delete
else if ($notification['hideFor'] == 'pro' && count($extensionsKeys) >= 1) {
[135] Fix | Delete
continue;
[136] Fix | Delete
}
[137] Fix | Delete
// Bundle
[138] Fix | Delete
else if ($notification['hideFor'] == 'bundle') {
[139] Fix | Delete
if (class_exists('SGPBActivatorPlugin') || count($extensionsKeys) >= 10) {
[140] Fix | Delete
continue;
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
// if there is even one detected extension, don’t show notification
[145] Fix | Delete
else if (count($arraysIntersect) > 0) {
[146] Fix | Delete
continue;
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
if ($hideDismissed && isset($dismissedNotifications[$id])) {
[151] Fix | Delete
continue;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
$activeNotifications[] = $notification;
[155] Fix | Delete
}
[156] Fix | Delete
$removedNotifications = get_option('sgpb-all-removed-notifications');
[157] Fix | Delete
$removedNotifications = json_decode($removedNotifications, true);
[158] Fix | Delete
if (empty($removedNotifications)) {
[159] Fix | Delete
return $activeNotifications;
[160] Fix | Delete
}
[161] Fix | Delete
foreach ($removedNotifications as $removedNotificationId) {
[162] Fix | Delete
foreach ($activeNotifications as $key => $activeNotification) {
[163] Fix | Delete
if ($activeNotification['id'] == $removedNotificationId) {
[164] Fix | Delete
unset($activeNotifications[$key]);
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
return $activeNotifications;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
public static function getAllDismissedNotifications()
[173] Fix | Delete
{
[174] Fix | Delete
$notifications = get_option('sgpb-all-dismissed-notifications');
[175] Fix | Delete
if (empty($notifications)) {
[176] Fix | Delete
$notifications = '';
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
return json_decode($notifications, true);
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
public static function getAllRemovedNotifications()
[183] Fix | Delete
{
[184] Fix | Delete
$notifications = get_option('sgpb-all-removed-notifications');
[185] Fix | Delete
if (empty($notifications)) {
[186] Fix | Delete
$notifications = '';
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
return json_decode($notifications, true);
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
public static function displayNotifications($withoutWrapper = false)
[193] Fix | Delete
{
[194] Fix | Delete
$content = '';
[195] Fix | Delete
$allNotifications = self::getAllActiveNotifications();
[196] Fix | Delete
if (empty($allNotifications)) {
[197] Fix | Delete
return $content;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
$count = count(self::getAllActiveNotifications(true));
[201] Fix | Delete
[202] Fix | Delete
foreach ($allNotifications as $notification) {
[203] Fix | Delete
$newNotification = new Notification();
[204] Fix | Delete
$newNotification->setId($notification['id']);
[205] Fix | Delete
$newNotification->setType($notification['type']);
[206] Fix | Delete
$newNotification->setPriority($notification['priority']);
[207] Fix | Delete
$newNotification->setMessage($notification['message']);
[208] Fix | Delete
$content .= $newNotification->render();
[209] Fix | Delete
}
[210] Fix | Delete
$count = '(<span class="sgpb-notifications-count-span">'.$count.'</span>)';
[211] Fix | Delete
[212] Fix | Delete
if ($withoutWrapper) {
[213] Fix | Delete
return $content;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
$content = self::prepareHtml($content, $count);
[217] Fix | Delete
[218] Fix | Delete
return $content;
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
public static function prepareHtml($content = '', $count = 0)
[222] Fix | Delete
{
[223] Fix | Delete
$content = '<div class="sgpb-each-notification-wrapper-js">'.$content.'</div>';
[224] Fix | Delete
$content = '<div class="sgpb-notification-center-wrapper">
[225] Fix | Delete
<h3><span class="dashicons dashicons-flag"></span> Notifications '.$count.'</h3>'.$content.'
[226] Fix | Delete
</div>';
[227] Fix | Delete
[228] Fix | Delete
return $content;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
public function dismissNotification()
[232] Fix | Delete
{
[233] Fix | Delete
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
[234] Fix | Delete
[235] Fix | Delete
$notificationId = isset($_POST['id']) ? sanitize_text_field($_POST['id']) : '';
[236] Fix | Delete
$allDismissedNotifications = self::getAllDismissedNotifications();
[237] Fix | Delete
$allDismissedNotifications[$notificationId] = $notificationId;
[238] Fix | Delete
$allDismissedNotifications = wp_json_encode($allDismissedNotifications);
[239] Fix | Delete
[240] Fix | Delete
update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
[241] Fix | Delete
$result = array();
[242] Fix | Delete
$result['content'] = self::displayNotifications(true);
[243] Fix | Delete
$result['count'] = count(self::getAllActiveNotifications(true));
[244] Fix | Delete
[245] Fix | Delete
wp_send_json($result);
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
public function removeNotification()
[249] Fix | Delete
{
[250] Fix | Delete
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
[251] Fix | Delete
if (!isset($_POST['id'])){
[252] Fix | Delete
wp_die(0);
[253] Fix | Delete
}
[254] Fix | Delete
$notificationId = sanitize_text_field($_POST['id']);
[255] Fix | Delete
$allRemovedNotifications = self::getAllRemovedNotifications();
[256] Fix | Delete
$allRemovedNotifications[$notificationId] = $notificationId;
[257] Fix | Delete
$allRemovedNotifications = wp_json_encode($allRemovedNotifications);
[258] Fix | Delete
[259] Fix | Delete
update_option('sgpb-all-removed-notifications', $allRemovedNotifications);
[260] Fix | Delete
[261] Fix | Delete
wp_die(true);
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
public function reactivateNotification()
[265] Fix | Delete
{
[266] Fix | Delete
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
[267] Fix | Delete
if (!isset($_POST['id'])){
[268] Fix | Delete
wp_die(0);
[269] Fix | Delete
}
[270] Fix | Delete
$notificationId = sanitize_text_field($_POST['id']);
[271] Fix | Delete
$allDismissedNotifications = self::getAllDismissedNotifications();
[272] Fix | Delete
if (isset($allDismissedNotifications[$notificationId])) {
[273] Fix | Delete
unset($allDismissedNotifications[$notificationId]);
[274] Fix | Delete
}
[275] Fix | Delete
$allDismissedNotifications = wp_json_encode($allDismissedNotifications);
[276] Fix | Delete
[277] Fix | Delete
update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
[278] Fix | Delete
$result = array();
[279] Fix | Delete
$result['content'] = self::displayNotifications(true);
[280] Fix | Delete
$result['count'] = count(self::getAllActiveNotifications(true));
[281] Fix | Delete
[282] Fix | Delete
wp_send_json($result);
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
public function activateCron()
[286] Fix | Delete
{
[287] Fix | Delete
if (!wp_next_scheduled('sgpbGetNotifications')) {
[288] Fix | Delete
wp_schedule_event(time(), 'daily', 'sgpbGetNotifications');
[289] Fix | Delete
}
[290] Fix | Delete
}
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
new SGPBNotificationCenter();
[294] Fix | Delete
[295] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function