'; const TCOLUMN_CLOSE = ''; const LI_CLOSE = ''; const LI_START = '
| ' . __( 'Check', 'onecom-sp' ) . self::THEAD_CLOSE; $html .= ' | ' . __( 'Result', OC_SP_TEXTDOMAIN ) . self::THEAD_CLOSE; $html .= $this->oc_get_dynamic_th( $check_type ); $html .= ' | |
|---|---|---|
| ' . __( 'one.com spam detection' ) . self::TCOLUMN_CLOSE; $html .= " | "; $html .= ' | ' . $check_array['reason'] . ' |
| ' . __( $value['description'], OC_SP_TEXTDOMAIN ) . self::TCOLUMN_CLOSE; $html .= ' | ' . $result . self::TCOLUMN_CLOSE; $html .= " | |
| ' . __( 'Final Result', OC_SP_TEXTDOMAIN ) . ' | '; $html .= "" . $final_result['final_result'] . " | $settings_disabled |
' . __( 'It is recommended to use default settings of plugin in case you are seeing spams not getting blocked effectively.', OC_SP_TEXTDOMAIN ) . '
'; } else { $settings_disabled = ''; } return $settings_disabled; } /** * @param $spam_detected * @return array * returns final status for the checks column in diagnostics table */ public function oc_get_final_dg_status( $spam_detected ) { $result = array(); if ( ! empty( $spam_detected ) ) { $result['final_result'] = __( 'The details provided by you are detected as spam', OC_SP_TEXTDOMAIN ); $result['border'] = 'border-spam'; } else { $result['final_result'] = __( 'No spam Detected', OC_SP_TEXTDOMAIN ); $result['border'] = 'border-nospam'; } return $result; } /** * @return bool * auto clears spam logs stored in the wp_options table. * if the records exceed 500 or the logs are older than 30 days. */ public function oc_auto_clear_logs() { $spam_logs = oc_get_sp_options( 'onecom_sp_spam_logs' ); $spam_count = 0; $additional_info = array( 'additional_info' => json_encode( array( 'logs_cleared_by' => 'auto_cleared', 'blocked_spams' => $spam_logs['spam_count'] ?? '', ) ), ); if ( $spam_logs && isset( $spam_logs['records'] ) && ! empty( $spam_logs['records'] ) ) { $spam_count = count( $spam_logs['records'] ); $sorted = $this->oc_get_sorted_list( strtotime( '-30 days' ), current_time( 'timestamp' ), $spam_logs['records'], 'clearLog' ); } if ( $spam_count >= 500 ) { $spam_logs['records'] = array_slice( $spam_logs['records'], 500 ); $spam_logs['spam_count'] = count( $spam_logs['records'] ); } elseif ( ! empty( $sorted ) ) { foreach ( $sorted as $key => $value ) { unset( $spam_logs['records'][ $key ] ); } $spam_logs['spam_count'] = count( $spam_logs['records'] ); } else { return false; } ( class_exists( 'OCPushStats' ) ? \OCPushStats::push_stats_performance_cache( 'delete', 'setting', 'logs', ONECOM_SP_PLUGIN_SLUG, $additional_info ) : '' ); oc_save_sp_options( $spam_logs, 'onecom_sp_spam_logs' ); } /** * @param $start_date * @param $end_date * @param $unsorted_arr * @param $case * @return array * * generates a sorted array based on start & end dates. */ public function oc_get_sorted_list( $start_date, $end_date, $unsorted_arr, $case ) { $sorted = array(); if ( is_array( $unsorted_arr ) ) { if ( $case == 'clearLog' ) { foreach ( $unsorted_arr as $date => $value ) { if ( strtotime( $date ) <= $start_date ) { $sorted[ $date ] = $value; } elseif ( strtotime( $date ) > $end_date ) { break; } } } elseif ( $case == 'summary' ) { foreach ( $unsorted_arr as $date => $value ) { if ( strtotime( $date ) >= $start_date ) { $sorted[ $date ] = $value; } elseif ( strtotime( $date ) > $end_date ) { break; } } } } return $sorted; } /** * @param $check * @return string * generates the description which appears before table on spam diagnostics page. */ public function oc_get_table_description( $check ) { $desc = ''; $desc .= "" . __( 'The diagnostics table consists of:', OC_SP_TEXTDOMAIN ) . '
'; $desc .= '' . __( 'No logs found!', OC_SP_TEXTDOMAIN ) . '
' ); return false; } wp_send_json_error(); } }