PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.13
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.13
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Services / AdminNotices.php

AdminNotices.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.13, at app/Services/AdminNotices.php

136 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace FluentForm\App\Services;
2
3 use FluentForm\Framework\Foundation\Application;
4 use FluentForm\Framework\Helpers\ArrayHelper;
5 use FluentForm\View;
6
7 if ( ! defined( 'ABSPATH' ) ) exit;
8
9 class AdminNotices
10 {
11 private $notice = false;
12 private $noticeKey = false;
13 private $noticeDisabledTime = 172800; // 7 days
14 private $noticePrefKey = '_fluentform_notice_pref';
15 private $app;
16 private $pref = false;
17
18 public function __construct(Application $app) {
19 $this->app = $app;
20 }
21
22 public function showNotice()
23 {
24 if($notice = $this->notice) {
25 $this->renderNotice($notice, $notice['name']);
26 }
27 }
28
29 public function addNotice($notice)
30 {
31 $this->notice = $notice;
32 }
33
34 public function noticeActions()
35 {
36 $noticeName = sanitize_text_field($_REQUEST['notice_name']);
37 $noticeType = sanitize_text_field($_REQUEST['action_type']);
38
39 if($noticeName == 'track_data_notice') {
40 $notificationPref = $this->getNoticePref();
41 $notificationPref[$noticeName] = array(
42 'status' => 'no',
43 'email_subscribed' => 'no',
44 'timestamp' => time()
45 );
46 update_option($this->noticePrefKey, $notificationPref, 'no');
47 $this->pref = $notificationPref;
48 }
49
50 $this->disableNotice($noticeName, $noticeType);
51
52 wp_send_json_success(array(
53 'message' => 'success'
54 ), 200);
55 die();
56 }
57
58 public function renderNotice($notice, $notice_key = false)
59 {
60 if(!$this->hasPermission())
61 return;
62
63 if($notice_key) {
64 if(!$this->shouldShowNotice($notice_key)) {
65 return;
66 }
67 }
68
69 wp_enqueue_style('fluentform_admin_notice', fluentformMix('css/admin_notices.css'));
70 wp_enqueue_script('fluentform_admin_notice', fluentformMix('js/admin_notices.js'), array(
71 'jquery'
72 ), FLUENTFORM_VERSION);
73 //print_r($notice);
74 View::render('admin.notices.info', array(
75 'notice' => $notice,
76 'show_logo' => true,
77 'show_hide_nag' => true,
78 'logo_url' => $this->app->publicUrl('img/fluent_icon.png')
79 ));
80 }
81
82 public function hasNotice()
83 {
84 return ($this->notice) ? true : false;
85 }
86
87 private function disableNotice($notice_key, $type = 'temp')
88 {
89 $noticePref = $this->getNoticePref();
90 $noticePref[$type][$notice_key] = time();
91 update_option($this->noticePrefKey, $noticePref, 'no');
92 $this->pref = $noticePref;
93 }
94
95 public function getNoticePref()
96 {
97 if(!$this->pref) {
98 $this->pref = get_option($this->noticePrefKey, array());
99 }
100 return $this->pref;
101 }
102
103 public function shouldShowNotice($noticeName)
104 {
105 $notificationPref = $this->getNoticePref();
106 if(!$notificationPref) {
107 return true;
108 }
109 if( ArrayHelper::get($notificationPref, $noticeName) ) {
110 return false;
111 }
112 return true;
113 }
114
115 private function haveTempHideNotice($noticeName)
116 {
117 $tempHideNotices = get_option('_fluentform_temp_disable_notices');
118 if($tempHideNotices && isset($tempHideNotices['$noticeName']))
119 {
120 $tempDisabledTime = $tempHideNotices['$noticeName'];
121 $difference = time() - intval($tempDisabledTime);
122 if($difference < $this->noticeDisabledTime) {
123 return true;
124 }
125 return false;
126 }
127
128 return false;
129 }
130
131 private function hasPermission()
132 {
133 return current_user_can('fluentform_dashboard_access');
134 }
135 }
136