types = array_merge( [ 'neutral', 'error', 'success' ], apply_filters( 'wpforo_notice_types', [] ) ); $this->types = array_map( 'strtolower', array_unique( $this->types ) ); } private function init_timeouts() { foreach( $this->types as $type ) $this->timeouts[ $type ] = $this->get_timeout( $type ); } private function get_timeout( $type ) { switch( $type ) { case "success": $durr = 4000; break; case "neutral": $durr = 0; break; default: $durr = 8000; } return apply_filters( "wpforo_notice_timeout_{$type}", $durr ); } public function get_timeouts() { return $this->timeouts; } private function reset() { foreach( $this->types as $type ) $this->notices[ $type ] = []; } public function is_empty() { foreach( $this->notices as $notice ) if( ! empty( $notice ) ) return false; return true; } public function __construct() { $this->init_types(); $this->reset(); add_action( 'wpforo_before_init', [ $this, 'init' ] ); } public function init() { $this->init_timeouts(); if( WPF()->session_token ) { $sql = "SELECT DISTINCT `key`, `value` FROM `" . WPF()->tables->logs . "` WHERE `sessionid` = %s AND `key` IN('" . implode( "','", $this->types ) . "')"; if( $notices = (array) WPF()->db->get_results( WPF()->db->prepare( $sql, WPF()->session_token ), ARRAY_A ) ) { foreach( $notices as $notice ) { if( trim( (string) $notice['value'] ) ) { $this->notices[ $notice['key'] ] = array_merge( $this->notices[ $notice['key'] ], wpforo_is_json( $notice['value'] ) ? json_decode( $notice['value'], true ) : (array) $notice['value'] ); } } } } } /** * * @param string|array $args * @param string $type (e.g. success|error) * @param string|array $s * * @return bool */ public function add( $args, $type = 'neutral', $s = [] ) { if( ! $args ) return false; $args = (array) $args; if( $s && count( $args ) === 1 && is_array( $s ) && isset( $s[0] ) && ! is_array( $s[0] ) ) { $s = [ $s ]; } else { $s = (array) $s; } if( WPF()->session_token ) { $type = strtolower( (string) $type ); 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 ); } } $this->notices[ $type ] = array_merge( (array) $this->notices[ $type ], (array) $args ); $this->notices[ $type ] = array_unique( $this->notices[ $type ] ); if( ! wpforo_is_ajax() ) { $insert_id_backup = WPF()->db->insert_id; WPF()->db->insert( WPF()->tables->logs, [ 'sessionid' => WPF()->session_token, 'key' => $type, 'value' => wp_json_encode( (array) $args ), ], [ '%s', '%s', '%s' ] ); WPF()->db->insert_id = $insert_id_backup; } return true; } return false; } /** * * @return bool * */ public function clear() { if( WPF()->session_token ) { $this->reset(); WPF()->db->delete( WPF()->tables->logs, [ 'sessionid' => WPF()->session_token ], [ '%s' ] ); return true; } return false; } /** *

success msg text

error msg text

* * @return string */ public function get_notices(): string { $inner = ''; if( ! $this->is_empty() ) { foreach( $this->notices as $type => $notice ) { $notice = (array) $notice; foreach( $notice as $msg ) { if( ! is_array( $msg ) ) { if( $msg = trim( (string) $msg ) ) $inner .= sprintf( '

%s

', sanitize_html_class( $type ), $msg ); } } } $this->clear(); } return $inner; } /** * * show collected wpforo notices * * @return void */ public function show() { if( $this->is_empty() ) return; if( wpforo_is_admin() ) { $this->backend( $this->notices ); } else { $this->frontend( $this->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( (string) $msg ) ) ) { $inner .= sprintf( '

%s

', sanitize_html_class( $type ), wpforo_kses( $msg ) ); } } } 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( (string) $msg ) ) ) { $inner .= sprintf( PHP_EOL . 'wpforo_notice_show("%1$s", "%2$s");' . PHP_EOL, addslashes( wpforo_kses( $msg ) ), sanitize_html_class( $type ) ); } } } ?> addonHash(); update_option( 'wpforo_addon_note_dismissed', $hash ); update_option( 'wpforo_addon_note_first', 'true' ); } else { $lastHashArray = explode( ',', $lastHash ); $currentHash = $this->addonHash(); if( $lastHash != $currentHash ) { ?>


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( wpforo_get_addons_info() as $addon ) { $viewed .= $addon['title'] . ','; } return $viewed; } public function refreshAddonPage() { $lastHash = get_option( 'wpforo_addon_note_dismissed' ); $currentHash = $this->addonHash(); if( $lastHash != $currentHash ) { ?> cache->cache_plugins_status(); if( ! empty( $not_excluded_plugins ) ) { foreach( $not_excluded_plugins as $plugin ) { $excluded .= ',' . $plugin['name']; } } wpforo_update_option( 'wpforo_excluded_cache', trim( (string) $excluded, ',' ) ); exit(); } }