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

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