PluginProbe
wpForo Forum / 1.4.12
wpForo Forum v1.4.12
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / class-notices.php

class-notices.php in wpForo Forum 1.4.12, at wpf-includes/class-notices.php

207 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 class wpForoNotices{
7
8 function __construct(){
9 $this->init();
10 }
11
12 /**
13 * @return void
14 */
15 private function init(){
16 if(!wpforo_is_session_started()) session_start();
17 }
18
19 /**
20 *
21 * @param string|array $args
22 * @param string $type (e.g. success|error)
23 * @param string|array $s
24 *
25 * @return bool
26 */
27 public function add( $args, $type = 'neutral', $s = array() ){
28 if(!$args) return FALSE;
29 $args = (array) $args;
30 if( $s && count($args) == 1 && is_array($s) && isset($s[0]) && !is_array($s[0]) ){
31 $s = array($s);
32 }else{
33 $s = (array) $s;
34 }
35
36 if( wpforo_is_session_started() ){
37 $type = strtolower($type);
38 if( !isset($_SESSION['wpforo_notices']) ) $_SESSION['wpforo_notices'] = array();
39 if( !isset($_SESSION['wpforo_notices'][$type]) ) $_SESSION['wpforo_notices'][$type] = array();
40
41 foreach($args as $key => $arg){
42 if( $s && isset($s[$key]) ){
43 $args[$key] = wpforo_sprintf_array( wpforo_phrase($arg, FALSE), $s[$key] );
44 }else{
45 $args[$key] = wpforo_phrase($arg, FALSE);
46 }
47 }
48
49 $_SESSION['wpforo_notices'][$type] = array_merge( (array) $_SESSION['wpforo_notices'][$type], (array) $args);
50 $_SESSION['wpforo_notices'][$type] = array_unique($_SESSION['wpforo_notices'][$type]);
51 return TRUE;
52 }
53
54 return FALSE;
55 }
56
57 /**
58 *
59 * @return bool
60 *
61 */
62 public function clear(){
63 if( wpforo_is_session_started() ){
64 $_SESSION['wpforo_notices'] = array();
65 return TRUE;
66 }
67
68 return FALSE;
69 }
70
71 /**
72 * <p class="success">success msg text</p><p class="error">error msg text</p>
73 *
74 * @return string
75 */
76 public function get_notices(){
77 $inner = '';
78 if(empty($_SESSION['wpforo_notices'])) return $inner;
79
80 foreach($_SESSION['wpforo_notices'] as $type => $notice){
81 $notice = (array) $notice;
82 foreach ($notice as $msg){
83 if( !is_array($msg) ){
84 $msg = trim($msg);
85 if($msg) $inner .= sprintf('<p class="%s">%s</p>', sanitize_html_class($type), $msg);
86 }
87 }
88 }
89
90 $this->clear();
91 return $inner;
92 }
93
94 /**
95 *
96 * @param bool $frontend (default TRUE)
97 *
98 * @return void
99 */
100 public function show( $frontend = TRUE ){
101 if(empty($_SESSION['wpforo_notices'])) return;
102 $inner = '';
103 $backend_inner = '';
104 foreach($_SESSION['wpforo_notices'] as $type => $notice){
105 $notice = (array) $notice;
106 foreach ($notice as $msg){
107 if( !is_array($msg) ){
108 $msg = trim($msg);
109 if($msg) {
110 $inner .= sprintf('<p class="%s">%s</p>', sanitize_html_class($type), $msg);
111 $backend_inner .= sprintf(
112 '<div class="notice is-dismissible notice-%s">
113 <p>%s</p>
114 <button type="button" class="notice-dismiss">
115 <span class="screen-reader-text">%s</span>
116 </button>
117 </div>',
118 sanitize_html_class($type), wpforo_kses($msg), __('Dismiss this notice.', 'wpforo'));
119 }
120 }
121 }
122 }
123 if($frontend) : ?>
124 <script type="text/javascript">
125 jQuery(document).ready(function($){
126 var msg_box = $("#wpf-msg-box");
127 msg_box.html("<?php echo addslashes(wpforo_kses($inner)) ?>");
128 msg_box.show(150).delay(1000);
129 setTimeout(function(){ $("#wpf-msg-box > p.error").remove(); }, 6500);
130 setTimeout(function(){ $("#wpf-msg-box > p.success").remove(); }, 3000);
131 });
132 </script>
133 <?php else :
134 echo $backend_inner;
135 endif;
136
137 $this->clear();
138 }
139
140
141 public function addonNote() {
142 $lastHash = get_option('wpforo-addon-note-dismissed');
143 $first = get_option('wpforo-addon-note-first');
144 if( !$lastHash ){
145 $hash = $this->addonHash();
146 update_option('wpforo-addon-note-dismissed', $hash);
147 update_option('wpforo-addon-note-first', 'true');
148 }
149 elseif( $lastHash || $first == 'false' ){
150 $lastHashArray = explode(',', $lastHash);
151 $currentHash = $this->addonHash();
152 if ($lastHash != $currentHash) {
153 ?>
154 <div class="updated notice wpforo_addon_note is-dismissible" style="margin-top:10px;">
155 <p style="font-weight:normal; font-size:15px; border-bottom:1px dotted #DCDCDC; padding-bottom:10px; width:95%;"><strong><?php _e('New Addons for Your Forum!', 'wpforo'); ?></strong><br><span style="font-size:14px;"><?php _e('Extend your forum with wpForo addons', 'wpforo'); ?></span></p>
156 <div style="font-size:14px;">
157 <?php
158 foreach (WPF()->addons as $key => $addon) {
159 if (in_array($addon['title'], $lastHashArray))
160 continue;
161 ?>
162 <div style="display:inline-block; min-width:27%; padding-right:10px; margin-bottom:1px;border-bottom:1px dotted #DCDCDC; border-right:1px dotted #DCDCDC; padding-bottom:10px;"><img src="<?php echo $addon['thumb'] ?>" style="height:40px; width:auto; vertical-align:middle; margin:0 10px; text-decoration:none;" /> <a href="<?php echo $addon['url'] ?>" style="text-decoration:none;" target="_blank">wpForo <?php echo $addon['title']; ?></a></div>
163 <?php
164 }
165 ?>
166 <div style="clear:both;"></div>
167 </div>
168 <p>&nbsp;&nbsp;&nbsp;<a href="<?php echo admin_url('admin.php?page=wpforo-addons') ?>"><?php _e('View all Addons', 'wpforo'); ?> &raquo;</a></p>
169 </div>
170 <script>jQuery(document).on( 'click', '.wpforo_addon_note .notice-dismiss', function() {jQuery.ajax({url: ajaxurl, data: { action: 'dismiss_wpforo_addon_note'}})})</script>
171 <?php
172 }
173 }
174 }
175
176 public function dismissAddonNote() {
177 $hash = $this->addonHash();
178 update_option('wpforo-addon-note-dismissed', $hash);
179 exit();
180 }
181
182 public function dismissAddonNoteOnPage() {
183 $hash = $this->addonHash();
184 update_option('wpforo-addon-note-dismissed', $hash);
185 }
186
187 public function addonHash() {
188 $viewed = '';
189 foreach (WPF()->addons as $key => $addon) {
190 $viewed .= $addon['title'] . ',';
191 }
192 $hash = $viewed;
193 return $hash;
194 }
195
196 public function refreshAddonPage() {
197 $lastHash = get_option('wpforo-addon-note-dismissed');
198 $currentHash = $this->addonHash();
199 if ($lastHash != $currentHash) {
200 ?>
201 <script language="javascript">jQuery(document).ready(function () {
202 location.reload();
203 });</script>
204 <?php
205 }
206 }
207 }