pages ) { return $this->pages; } $ignored = Accesswell_Settings::ignored(); $skip = Accesswell_Settings::get()['skip_rules']; $this->pages = array(); foreach ( Accesswell_DB::all() as $row ) { $path = (string) Accesswell_Urls::path_of( $row['page_url'] ); $open = array(); $hidden = 0; foreach ( $row['issues'] as $issue ) { if ( in_array( $issue['rule'], $skip, true ) || ! Accesswell_Rules::get( $issue['rule'] ) ) { continue; } if ( Accesswell_Settings::is_ignored( $issue, $path, $ignored ) ) { ++$hidden; continue; } $open[] = $issue; } $counts = array( 'error' => 0, 'warning' => 0, 'notice' => 0, ); foreach ( $open as $issue ) { ++$counts[ $issue['impact'] ]; } $this->pages[] = array( 'url' => $row['page_url'], 'path' => $path, 'post_id' => (int) $row['post_id'], 'checked_at' => $row['checked_at'], 'issues' => $open, 'ignored' => $hidden, 'errors' => $counts['error'], 'warnings' => $counts['warning'], 'notices' => $counts['notice'], ); } usort( $this->pages, function ( $a, $b ) { return array( $b['errors'], $b['warnings'], $b['notices'] ) <=> array( $a['errors'], $a['warnings'], $a['notices'] ); } ); return $this->pages; } /** * Issues grouped by rule across the site, most serious first. * * @return array Rule ID => { rule, count, pages: [ path => count ] }. */ public function by_rule() { $out = array(); foreach ( $this->pages() as $page ) { foreach ( $page['issues'] as $issue ) { $id = $issue['rule']; if ( ! isset( $out[ $id ] ) ) { $out[ $id ] = array( 'rule' => Accesswell_Rules::get( $id ), 'count' => 0, 'pages' => array(), ); } ++$out[ $id ]['count']; $out[ $id ]['pages'][ $page['path'] ] = isset( $out[ $id ]['pages'][ $page['path'] ] ) ? $out[ $id ]['pages'][ $page['path'] ] + 1 : 1; } } $rank = array( 'error' => 0, 'warning' => 1, 'notice' => 2, ); uasort( $out, function ( $a, $b ) use ( $rank ) { return array( $rank[ $a['rule']['impact'] ], -count( $a['pages'] ), -$a['count'] ) <=> array( $rank[ $b['rule']['impact'] ], -count( $b['pages'] ), -$b['count'] ); } ); return $out; } /** * @return array */ public function totals() { $t = array( 'pages' => 0, 'with_errors' => 0, 'errors' => 0, 'warnings' => 0, 'notices' => 0, 'last' => '', ); foreach ( $this->pages() as $page ) { ++$t['pages']; $t['errors'] += $page['errors']; $t['warnings'] += $page['warnings']; $t['notices'] += $page['notices']; if ( $page['errors'] ) { ++$t['with_errors']; } if ( $page['checked_at'] > $t['last'] ) { $t['last'] = $page['checked_at']; } } return $t; } }