init(); } /** * @return void */ private function init(){ if( !wpforo_is_session_started() && ( !is_admin() || (!empty($_GET['page']) && strpos($_GET['page'], 'wpforo-') !== false ) || (wpforo_is_ajax() && !empty($_POST['action']) && false !== strpos($_POST['action'], 'wpforo')) )) session_start(); } /** * * @param string|array $args * @param string $type (e.g. success|error) * @param string|array $s * * @return bool */ public function add( $args, $type = 'neutral', $s = array() ){ if(!$args) return FALSE; $args = (array) $args; if( $s && count($args) == 1 && is_array($s) && isset($s[0]) && !is_array($s[0]) ){ $s = array($s); }else{ $s = (array) $s; } if( wpforo_is_session_started() ){ $type = strtolower($type); if( !isset($_SESSION['wpforo_notices']) ) $_SESSION['wpforo_notices'] = array(); if( !isset($_SESSION['wpforo_notices'][$type]) ) $_SESSION['wpforo_notices'][$type] = array(); foreach($args as $key => $arg){ if( $s && isset($s[$key]) ){ $args[$key] = wpforo_sprintf_array( wpforo_phrase($arg, FALSE), $s[$key] ); }else{ $args[$key] = wpforo_phrase($arg, FALSE); } } $_SESSION['wpforo_notices'][$type] = array_merge( (array) $_SESSION['wpforo_notices'][$type], (array) $args); $_SESSION['wpforo_notices'][$type] = array_unique($_SESSION['wpforo_notices'][$type]); return TRUE; } return FALSE; } /** * * @return bool * */ public function clear(){ if( wpforo_is_session_started() ){ $_SESSION['wpforo_notices'] = array(); return TRUE; } return FALSE; } /** *

success msg text

error msg text

* * @return string */ public function get_notices(){ $inner = ''; if(empty($_SESSION['wpforo_notices'])) return $inner; foreach($_SESSION['wpforo_notices'] as $type => $notice){ $notice = (array) $notice; foreach ($notice as $msg){ if( !is_array($msg) ){ $msg = trim($msg); if($msg) $inner .= sprintf('

%s

', sanitize_html_class($type), $msg); } } } $this->clear(); return $inner; } /** * * show collected wpforo notices * * @return void */ public function show(){ if(empty($_SESSION['wpforo_notices'])) return; if( wpforo_is_admin() ){ $this->backend($_SESSION['wpforo_notices']); }else{ $this->frontend($_SESSION['wpforo_notices']); } $this->clear(); } private function backend($notices){ $inner = ''; foreach($notices as $type => $notice){ $notice = (array) $notice; foreach ($notice as $msg){ if( !is_array($msg) && ($msg = trim($msg)) ){ $inner .= sprintf( '

%s

', sanitize_html_class($type), wpforo_kses($msg), __('Dismiss this notice.', 'wpforo')); } } } echo '
' . $inner . '
'; } private function frontend($notices){ $inner = ''; foreach($notices as $type => $notice){ $notice = (array) $notice; foreach ($notice as $msg){ if( !is_array($msg) && ($msg = trim($msg)) ){ $inner .= sprintf('

%s

', sanitize_html_class($type), $msg); } } } ?> addonHash(); update_option('wpforo-addon-note-dismissed', $hash); update_option('wpforo-addon-note-first', 'true'); } elseif( $lastHash || $first == 'false' ){ $lastHashArray = explode(',', $lastHash); $currentHash = $this->addonHash(); if ($lastHash != $currentHash) { ?>


addons as $key => $addon) { if (in_array($addon['title'], $lastHashArray)) continue; ?>
wpForo

    »

addonHash(); update_option('wpforo-addon-note-dismissed', $hash); exit(); } public function dismissAddonNoteOnPage() { $hash = $this->addonHash(); update_option('wpforo-addon-note-dismissed', $hash); } public function addonHash() { $viewed = ''; foreach (WPF()->addons as $key => $addon) { $viewed .= $addon['title'] . ','; } $hash = $viewed; return $hash; } public function refreshAddonPage() { $lastHash = get_option('wpforo-addon-note-dismissed'); $currentHash = $this->addonHash(); if ($lastHash != $currentHash) { ?>