PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.14 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 All 196 releases
fluentform / app / Http / Controllers / AdminNoticeController.php

AdminNoticeController.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Http/Controllers/AdminNoticeController.php

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