false, 'status' => true, 'type' => 'review', 'title' => 'Leave a Review', 'text' => 'Popup Maker team is happy you are using our popups for a while and we hope our plugin helps you to improve the conversion of your website. We’d be very thankful and inspired if you can support us and have your input with your positive feedback.', 'links' => array( array( 'className' => 'sgpm-review', 'label' => 'Leave a Review Here!', 'url' => 'https://wordpress.org/support/plugin/popup-maker-wp/reviews/#new-post' ) ) ); private $notificationBellIconSvg = ''; private $clearAllIconSvg = ''; private $closeNotifictionIconSvg = ''; public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } private function __construct() { $this->init(); } private function init() { $this->addCustomCronSchedule(); $this->validateNotificationEngineOptions(); $notificationsSource = get_option('sgpm_popup_maker_notification_engine_source'); $notificationsSource = maybe_unserialize($notificationsSource); $dismissedNotifications = get_option('sgpm_popup_maker_dismissed_notifacions'); $dismissedNotifications = !is_array($dismissedNotifications) ? array() : json_decode($dismissedNotifications); $this->setActiveNotificationsCount($notificationsSource); $this->activeNotifications = $notificationsSource; $this->dismissedNotifications = $dismissedNotifications; } private function setActiveNotificationsCount($notificationsSource) { if ($notificationsSource && is_array($notificationsSource) && !empty($notificationsSource)) { foreach ($notificationsSource as $notification) { if ($notification['status'] == $this->statusDisabled) continue; $this->activeNotificationsCount++; } } } private function validateNotificationEngineOptions() { $storedNotificationSource = get_option('sgpm_popup_maker_notification_engine_source'); if (!$storedNotificationSource) { add_option('sgpm_popup_maker_notification_engine_source', maybe_serialize(array())); add_option('sgpm_popup_maker_dismissed_notifacions', json_encode(array())); } } private function addCustomCronSchedule() { /* temprory fix : Delete old crons */ wp_clear_scheduled_hook("sgpm_fetch_new_notifications"); wp_unschedule_event(time(), 'sgpm_check_for_new_notifications_every_6_hours'); //add_action('sgpm_fetch_notifications', array($this, 'fetchNewNotifications')); //add_filter('cron_schedules', array($this, 'checkeForNewNotificationsCron')); // add new schedule if (!wp_next_scheduled('sgpm_fetch_notifications')) { //wp_schedule_event(time(), 'twicedaily', 'sgpm_fetch_notifications'); } } public function checkeForNewNotificationsCron($schedules) { $schedules['sgpm_check_for_new_notifications_every_6_hours'] = array( 'interval' => 60*60*6, // Every 6 hours (in seconds) 'display' => __('Popup Maker every 6 hours'), ); return $schedules; } public function fetchNewNotifications() { $newNotifications = array(); $existingNotificationsSource = maybe_unserialize(get_option('sgpm_popup_maker_notification_engine_source')); $dismissedNotifacions = json_decode(get_option('sgpm_popup_maker_dismissed_notifacions'), true); $isValidExistingNotificationsSource = $this->validateExistingNotificationsSource($existingNotificationsSource); if (!$isValidExistingNotificationsSource) { update_option('sgpm_popup_maker_notification_engine_source', maybe_serialize(array())); } if (!is_array($dismissedNotifacions)) { update_option('sgpm_popup_maker_dismissed_notifacions', json_encode(array())); $dismissedNotifacions = array(); } $response = wp_remote_get(SGPM_NOTIFICATIONS_API_URL); $body = wp_remote_retrieve_body($response); if (is_wp_error($response)) { // wp_die("Something went wrong after fetching notifiactions!"); return; } $notificationsSource = json_decode($body, true); $validBody = SGPMBase::validateNotificationsBody($notificationsSource); if (isset($notificationsSource) && $validBody) { foreach ($notificationsSource as $notification) { $hash = $notification['hash']; $status = $notification['status']; if (in_array($hash, $dismissedNotifacions)) continue; foreach ($existingNotificationsSource as $existingNotification) { $existingHash = $existingNotification['hash']; $existingStatus = $existingNotification['status']; if ($existingHash == $hash && $existingStatus != $status) { $existingNotification['status'] = $status; $notification = $existingNotification; // update notification } } array_push($newNotifications, $notification); } update_option('sgpm_popup_maker_notification_engine_source', maybe_serialize($newNotifications)); } } private function validateExistingNotificationsSource($existingNotificationsSource) { $serializedData = maybe_unserialize($existingNotificationsSource); if (is_serialized($serializedData)) { return true; } else { return false; } } public function clearAllNotifications() { $hashArray = array(); $notificationsSource = maybe_unserialize(get_option('sgpm_popup_maker_notification_engine_source')); $dismissedNotifications = json_decode(get_option('sgpm_popup_maker_dismissed_notifacions'), true); foreach ($notificationsSource as $notification) { if (in_array($notification['hash'], $dismissedNotifications)) continue; array_push($dismissedNotifications, $notification['hash']); } update_option('sgpm_popup_maker_notification_engine_source', maybe_serialize(array())); update_option('sgpm_popup_maker_dismissed_notifacions', json_encode($dismissedNotifications)); } public function removeNotification($hash, $notificationId) { if (isset($this->activeNotifications[$notificationId])) { unset($this->activeNotifications[$notificationId]); update_option('sgpm_popup_maker_notification_engine_source', maybe_serialize($this->activeNotifications)); array_push($this->dismissedNotifications, $hash); update_option('sgpm_popup_maker_dismissed_notifacions', json_encode($this->dismissedNotifications)); } } public function setNotificationBadgeData() { $showReviewNotice = $this->allowedToShowReviewNotice(); if ($showReviewNotice) $this->activeNotificationsCount += 1; if ($this->activeNotificationsCount) { ob_start(); ?> validateNotificationEngineOptions(); $innerHtml = $this->getNotificationBody(); if ($innerHtml) { $this->getNotificationShadeWrapper($innerHtml); } } private function allowedToShowReviewNotice() { $showReviewNotice = true; $pastDate = strtotime('-30 days'); $activationDate = get_option('sgpm_popup_maker_activation_date'); $noticeDismissed = get_option('sgpm_popup_maker_dismiss_review_notice'); if ($noticeDismissed == 'true') { $showReviewNotice = false; } else if (!current_user_can('install_plugins')) { $showReviewNotice = false; } else if (!$activationDate || $activationDate > $pastDate) { $showReviewNotice = false; } return $showReviewNotice; } private function getNotificationShadeWrapper($innerHtml) { $wrapper = '