init(); } /** * @return void */ private function init(){ if(!$this->is_session_started()) session_start(); } /** * @return bool */ private function is_session_started(){ if ( php_sapi_name() !== 'cli' ) { if ( version_compare(phpversion(), '5.4.0', '>=') ) { return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE; } else { return session_id() === '' ? FALSE : TRUE; } } return FALSE; } /** * * @param string|array $args * @param string $type (e.g. success|error) * @param string|array $s * * @return bool */ public function add( $args, $type = '', $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( $this->is_session_started() ){ $_SESSION['wpforo_notice_type'] = $type; if( !isset($_SESSION['wpforo_notices']) ) $_SESSION['wpforo_notices'] = 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'] = array_merge( (array) $_SESSION['wpforo_notices'], (array) $args); $_SESSION['wpforo_notices'] = array_unique($_SESSION['wpforo_notices']); return TRUE; } return FALSE; } /** * * @return bool * */ public function clear(){ if( $this->is_session_started() ){ unset($_SESSION['wpforo_notice_type'], $_SESSION['wpforo_notices']); return TRUE; } return FALSE; } /** * get notices $notices['type'], $notices['text'] * * @return array */ public function get_notices(){ if(!isset($_SESSION['wpforo_notices'])) return array( 'type' => '', 'text' => '' ); if($_SESSION['wpforo_notice_type'] == 'success'){ $class = 'success'; }elseif($_SESSION['wpforo_notice_type'] == 'error'){ $class = 'error'; }else{ $class = ''; } $notices = array(); $notices['type'] = $class; $notices['text'] = ''; foreach($_SESSION['wpforo_notices'] as $notice) if( !is_array($notice) ) $notices['text'] .= wpforo_phrase($notice, FALSE) . '
'; $this->clear(); return $notices; } /** * * @param bool $frontend (default TRUE) * * @return void */ public function show( $frontend = TRUE ){ if(!isset($_SESSION['wpforo_notices'])) return; if($_SESSION['wpforo_notice_type'] == 'success'){ $class = 'success'; }elseif($_SESSION['wpforo_notice_type'] == 'error'){ $class = 'error'; }else{ $class = ''; } $inner = ''; foreach($_SESSION['wpforo_notices'] as $notice) if( !is_array($notice) ) $inner .= wpforo_phrase($notice, FALSE) . '

'; $inner = preg_replace('#()*$#is', '', $inner); ?>

clear(); } public function addonNote() { global $wpforo; $lastHash = get_option('wpforo-addon-note-dismissed'); $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() { global $wpforo; $viewed = ''; foreach ($wpforo->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) { ?>