PluginProbe
wpForo Forum / 1.3.1
wpForo Forum v1.3.1
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.3.1, at wpf-includes/class-notices.php

208 lines 6.8 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(!$this->is_session_started()) session_start();
17 }
18
19 /**
20 * @return bool
21 */
22 private function is_session_started(){
23 if ( php_sapi_name() !== 'cli' ) {
24 if ( version_compare(phpversion(), '5.4.0', '>=') ) {
25 return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
26 } else {
27 return session_id() === '' ? FALSE : TRUE;
28 }
29 }
30 return FALSE;
31 }
32
33 /**
34 *
35 * @param mixed $args
36 * @param string $type (e.g. success|error)
37 *
38 * @return bool
39 */
40 public function add( $args, $type = '', $s = array() ){
41 if(!$args) return FALSE;
42 if(!is_array($args)) $args = array($args);
43
44 if( $this->is_session_started() ){
45 $_SESSION['wpforo_notice_type'] = $type;
46 if( !empty($_SESSION['wpforo_notices']) ){
47 foreach($args as $arg) $_SESSION['wpforo_notices'][] = $arg;
48 }else{
49 if( !empty($s) ){
50 foreach($args as $key => $arg){
51 if( isset($s[$key]) ) $args[$key] = sprintf( wpforo_phrase($arg, FALSE), $s[$key] );
52 }
53 }
54 $_SESSION['wpforo_notices'] = $args;
55 }
56 $_SESSION['wpforo_notices'] = array_unique($_SESSION['wpforo_notices']);
57 return TRUE;
58 }
59
60 return FALSE;
61 }
62
63 /**
64 *
65 * @return bool
66 *
67 */
68 public function clear(){
69 if( $this->is_session_started() ){
70 unset($_SESSION['wpforo_notice_type'], $_SESSION['wpforo_notices']);
71 return TRUE;
72 }
73
74 return FALSE;
75 }
76
77 /**
78 * get notices $notices['type'], $notices['text']
79 *
80 * @return array
81 */
82 public function get_notices(){
83 if(!isset($_SESSION['wpforo_notices'])) return array( 'type' => '', 'text' => '' );
84 if($_SESSION['wpforo_notice_type'] == 'success'){
85 $class = 'success';
86 }elseif($_SESSION['wpforo_notice_type'] == 'error'){
87 $class = 'error';
88 }else{
89 $class = '';
90 }
91
92 $notices = array();
93 $notices['type'] = $class;
94 $notices['text'] = '';
95 foreach($_SESSION['wpforo_notices'] as $notice) if( !is_array($notice) ) $notices['text'] .= wpforo_phrase($notice, FALSE) . '<br/>';
96
97 $this->clear();
98 return $notices;
99 }
100
101 /**
102 *
103 * @param bool $frontend (default TRUE)
104 *
105 * @return void
106 */
107 public function show( $frontend = TRUE ){
108 if(!isset($_SESSION['wpforo_notices'])) return;
109 if($_SESSION['wpforo_notice_type'] == 'success'){
110 $class = 'success';
111 }elseif($_SESSION['wpforo_notice_type'] == 'error'){
112 $class = 'error';
113 }else{
114 $class = '';
115 }
116 $inner = '';
117 foreach($_SESSION['wpforo_notices'] as $notice) if( !is_array($notice) ) $inner .= wpforo_phrase($notice, FALSE) . '<br/><br/>';
118 $inner = preg_replace('#(<br\s*/?\s*>)*$#is', '', $inner);
119 ?>
120 <?php if($frontend) : ?>
121 <script type="text/javascript">
122 jQuery(document).ready(function($){
123 <?php if($class) : ?>
124 $("#wpf-msg-box p.wpf-msg-box-triangle-right").removeClass("success").removeClass("error").addClass("<?php echo sanitize_html_class($class) ?>");
125 <?php endif ?>
126 $("#wpf-msg-box p.wpf-msg-box-triangle-right").html("<span><?php echo addslashes(wpforo_kses($inner)) ?></span>");
127 $("#wpf-msg-box").show(150).delay(1000);
128 <?php if($class) : ?>
129 setTimeout(function(){ $("#wpf-msg-box").hide(); }, <?php echo ($class == 'error' ? 6000 : 3000 ) ?>);
130 <?php endif ?>
131 });
132 </script>
133 <?php else : ?>
134 <div class="notice is-dismissible<?php if($class) echo ' notice-' . sanitize_html_class($class) ?>">
135 <p><?php echo wpforo_kses($inner) ?></p>
136 <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e('Dismiss this notice.', 'wpforo') ?></span></button>
137 </div>
138 <?php endif ?>
139 <?php
140 $this->clear();
141 }
142
143
144 public function addonNote() {
145 global $wpforo;
146 $lastHash = get_option('wpforo-addon-note-dismissed');
147 $lastHashArray = explode(',', $lastHash);
148 $currentHash = $this->addonHash();
149 if ($lastHash != $currentHash) {
150 ?>
151 <div class="updated notice wpforo_addon_note is-dismissible" style="margin-top:10px;">
152 <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>
153 <div style="font-size:14px;">
154 <?php
155 foreach ($wpforo->addons as $key => $addon) {
156 if (in_array($addon['title'], $lastHashArray))
157 continue;
158 ?>
159 <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:0px 10px; text-decoration:none;" /> <a href="<?php echo $addon['url'] ?>" style="text-decoration:none;" target="_blank">wpForo <?php echo $addon['title']; ?></a></div>
160 <?php
161 }
162 ?>
163 <div style="clear:both;"></div>
164 </div>
165 <p>&nbsp;&nbsp;&nbsp;<a href="<?php echo admin_url('admin.php?page=wpforo-addons') ?>"><?php _e('View all Addons', 'wpforo'); ?> &raquo;</a></p>
166 </div>
167 <script>jQuery(document).on( 'click', '.wpforo_addon_note .notice-dismiss', function() {jQuery.ajax({url: ajaxurl, data: { action: 'dismiss_wpforo_addon_note'}})})</script>
168 <?php
169 }
170 }
171
172 public function dismissAddonNote() {
173 $hash = $this->addonHash();
174 update_option('wpforo-addon-note-dismissed', $hash);
175 exit();
176 }
177
178 public function dismissAddonNoteOnPage() {
179 $hash = $this->addonHash();
180 update_option('wpforo-addon-note-dismissed', $hash);
181 }
182
183 public function addonHash() {
184 global $wpforo; $viewed = '';
185 foreach ($wpforo->addons as $key => $addon) {
186 $viewed .= $addon['title'] . ',';
187 }
188 $hash = $viewed;
189 return $hash;
190 }
191
192 public function refreshAddonPage() {
193 $lastHash = get_option('wpforo-addon-note-dismissed');
194 $currentHash = $this->addonHash();
195 if ($lastHash != $currentHash) {
196 ?>
197 <script language="javascript">jQuery(document).ready(function () {
198 location.reload();
199 });</script>
200 <?php
201 }
202 }
203
204
205
206 }
207
208 ?>