array(), 'themes' => array(), 'core' => array(), ); } public static function refresh_if_stale() { return false; } } class ADT_Shield_History { const OPT = 'adt_shield_lite_history'; const CAP = 10; private static function counts( $result ) { $n = array( 'high' => 0, 'medium' => 0, 'low' => 0, ); if ( is_array( $result ) && ! empty( $result['findings'] ) ) { foreach ( $result['findings'] as $f ) { if ( isset( $n[ $f['sev'] ] ) ) { $n[ $f['sev'] ]++; } } } return $n; } public static function score( array $n ) { return max( 0, min( 100, 100 - 18 * (int) $n['high'] - 6 * (int) $n['medium'] - 2 * (int) $n['low'] ) ); } /** * Keeps a short list of finished scans so the Reports page can draw a trend. */ public static function record( $result, $trigger = 'manual' ) { if ( ! is_array( $result ) ) { return; } $n = self::counts( $result ); $list = get_option( self::OPT, array() ); $list = is_array( $list ) ? $list : array(); array_unshift( $list, array( 'time' => (int) $result['time'], 'scanned' => (int) $result['scanned'], 'high' => $n['high'], 'medium' => $n['medium'], 'low' => $n['low'], 'score' => self::score( $n ), ) ); update_option( self::OPT, array_slice( $list, 0, self::CAP ), false ); } public static function mark_resolved( $path ) { return $path; } /** * After a repair or undo the newest scan shows the new counts. */ public static function refresh_latest( $result ) { $list = get_option( self::OPT, array() ); if ( ! is_array( $list ) || ! $list ) { return; } $n = self::counts( $result ); $list[0] = array_merge( $list[0], $n, array( 'score' => self::score( $n ) ) ); update_option( self::OPT, $list, false ); } public static function summaries() { $list = get_option( self::OPT, array() ); return is_array( $list ) ? $list : array(); } } class ADT_Shield_Triage { /** * Only the order of the results is needed here: serious items first. */ public static function decide( array $f ) { $rank = array( 'high' => 1, 'medium' => 2, 'low' => 3, ); return array( 'rank' => isset( $rank[ $f['sev'] ] ) ? $rank[ $f['sev'] ] : 3, ); } }