settings; $report = $plugin->report; $scan = $plugin->scanner->last(); $open = $report->open(); $counts = array( 'critical' => 0, 'warning' => 0, 'info' => 0, ); $issues = array(); foreach ( $open as $i ) { ++$counts[ $i['severity'] ]; $i['wording'] = ( isset( $i['fix']['type'] ) && 'wording' === $i['fix']['type'] ) ? $report->wording->get( $i['id'] ) : null; $issues[] = $i; } $handled = array(); foreach ( $report->handled() as $id => $h ) { $handled[] = array( 'id' => $id, 'title' => $h['title'], 'how' => $h['how'], 'reason' => $h['reason'], 'user' => $h['user'], 'when' => sprintf( /* translators: %s: time difference, e.g. "5 mins". */ __( '%s ago', 'goconsent' ), human_time_diff( (int) $h['time'] ) ), ); } $over = (array) $s->get( 'overrides' ); $approvals = Approvals::all(); $items = array(); foreach ( $scan['items'] as $id => $it ) { $cat = isset( $over[ $id ] ) ? $over[ $id ] : $it['default']; $approved = null; if ( isset( $approvals[ $id ], $over[ $id ] ) ) { $a = $approvals[ $id ]; $user = get_userdata( (int) $a['user'] ); $approved = array( 'by' => $user ? $user->display_name : __( 'a former user', 'goconsent' ), 'when' => wp_date( get_option( 'date_format' ), (int) $a['time'] ), ); } $sources = array(); foreach ( isset( $it['sources'] ) ? (array) $it['sources'] : array() as $src ) { $sources[] = self::source_note( $src ); } $items[] = array( 'id' => $id, 'label' => $it['label'], 'match' => $it['match'], 'kind' => $it['kind'], 'pages' => array_slice( $it['pages'], 0, 5 ), 'more' => max( 0, count( $it['pages'] ) - 5 ), 'category' => $cat ? $cat : 'marketing', 'review' => empty( $it['known'] ) && ! isset( $over[ $id ] ), 'approved' => $approved, 'sources' => $sources, ); } $next = wp_next_scheduled( Cron::SCAN ); $loc = (string) $s->get( 'location' ); $rule = $loc ? Laws::rule_for( $loc ) : null; return array( 'rescan' => ! empty( $scan['items'] ) && ! self::has_sources( $scan['items'] ), 'score' => $report->score(), 'counts' => $counts, 'issues' => $issues, 'handled' => $handled, 'items' => $items, 'scan' => array( 'when' => $scan['time'] ? human_time_diff( $scan['time'] ) : '', 'pages' => count( $scan['pages'] ), 'next' => $next ? human_time_diff( $next ) : '', ), 'banner' => array( 'mode' => (string) $s->get( 'banner_mode' ), 'blockers' => \GoConsent\Frontend\BannerMode::blockers( $s ), ), 'enforcing' => $s->enforcing(), 'enforce_at' => wp_date( get_option( 'time_format' ) . ', ' . get_option( 'date_format' ), $s->enforce_at() ), 'version' => (int) $s->get( 'version' ), 'law' => $rule && $rule['law'] ? $rule['law'] : '', 'protecting' => $plugin->is_protecting(), 'policy' => self::policy_editor( (int) $s->privacy_page_id() ), 'laws' => self::laws( $s ), 'pages' => \GoConsent\Policies\Manager::all(), 'codes' => \GoConsent\Policies\Tags::report(), 'pro' => \GoConsent\Policies\Pages::pro(), ); } /** * Laws that apply now (ids) and soon (id => date), for the Laws tab and issue links. * * @param \GoConsent\Settings $s Settings. * @return array */ private static function laws( $s ) { $app = new \GoConsent\Rules\Applicability( $s ); $laws = $app->laws(); $soon = array(); foreach ( $laws['soon'] as $id => $l ) { $soon[ $id ] = wp_date( get_option( 'date_format' ), strtotime( $l['effective'] . ' 12:00:00' ) ); } $names = array(); foreach ( \GoConsent\Rules\Reference::all() as $id => $r ) { $names[ $id ] = $r['law']; } foreach ( $laws['now'] as $id => $l ) { $names[ $id ] = $l['short']; } return array( 'now' => array_keys( $laws['now'] ), 'soon' => $soon, 'names' => $names, ); } /** * Where the privacy page is edited, and with what. * * @param int $id Privacy page id. * @return array|null { edit: url, builder: blocks|classic|elementor|beaver } */ private static function policy_editor( $id ) { $post = $id ? get_post( $id ) : null; if ( ! $post || ! current_user_can( 'edit_post', $id ) ) { return null; } if ( 'builder' === get_post_meta( $id, '_elementor_edit_mode', true ) && defined( 'ELEMENTOR_VERSION' ) ) { return array( 'edit' => admin_url( 'post.php?post=' . $id . '&action=elementor' ), 'builder' => 'elementor', ); } if ( get_post_meta( $id, '_fl_builder_enabled', true ) && class_exists( 'FLBuilderModel' ) ) { return array( 'edit' => add_query_arg( 'fl_builder', '', get_permalink( $id ) ), 'builder' => 'beaver', ); } return array( 'edit' => (string) get_edit_post_link( $id, 'raw' ), 'builder' => has_blocks( $post ) || use_block_editor_for_post( $post ) ? 'blocks' : 'classic', ); } /** * Whether the last scan recorded sources (scans before 1.0.6 didn't). * * @param array $items Scan items. * @return bool */ private static function has_sources( array $items ) { foreach ( $items as $it ) { if ( array_key_exists( 'sources', $it ) ) { return true; } } return false; } /** * Plain-English note on what put a script on the page, plus an edit link where useful. * * @param array $src Source from the scanner. * @return array{text:string,link:string,link_label:string,known:bool} */ public static function source_note( array $src ) { $name = isset( $src['name'] ) ? (string) $src['name'] : ''; $detail = isset( $src['detail'] ) ? (string) $src['detail'] : ''; $out = array( 'text' => '', 'link' => '', 'link_label' => '', 'known' => true, ); switch ( isset( $src['type'] ) ? $src['type'] : '' ) { case 'plugin': /* translators: %s: plugin name. */ $out['text'] = sprintf( __( 'Added by the %s plugin', 'goconsent' ), $name ); if ( current_user_can( 'activate_plugins' ) ) { $out['link'] = admin_url( 'plugins.php' ); $out['link_label'] = __( 'Plugins', 'goconsent' ); } break; case 'theme': /* translators: %s: theme name. */ $out['text'] = sprintf( __( 'Added by the %s theme', 'goconsent' ), $name ); break; case 'content': $page = ! empty( $src['post'] ) ? get_the_title( (int) $src['post'] ) : ''; if ( '' !== $page && '' !== $detail ) { /* translators: 1: module name, 2: page title, 3: section name. */ $out['text'] = sprintf( __( 'Pasted into a %1$s on “%2$s”, section “%3$s”', 'goconsent' ), $name, $page, $detail ); } elseif ( '' !== $page ) { /* translators: 1: module name, 2: page title. */ $out['text'] = sprintf( __( 'Pasted into a %1$s on “%2$s”', 'goconsent' ), $name, $page ); } else { /* translators: %s: module name. */ $out['text'] = sprintf( __( 'Pasted into a %s in the page content', 'goconsent' ), $name ); } if ( ! empty( $src['post'] ) && current_user_can( 'edit_post', (int) $src['post'] ) ) { $out['link'] = false !== stripos( $name, 'Beaver' ) ? add_query_arg( 'fl_builder', '', get_permalink( (int) $src['post'] ) ) : (string) get_edit_post_link( (int) $src['post'], 'raw' ); $out['link_label'] = __( 'Edit page', 'goconsent' ); } break; case 'snippet': $out['text'] = 'head' === $detail /* translators: %s: plugin name. */ ? sprintf( __( 'Probably a header snippet in %s (no WordPress handle)', 'goconsent' ), $name ) /* translators: %s: plugin name. */ : sprintf( __( 'Probably a footer snippet in %s (no WordPress handle)', 'goconsent' ), $name ); break; case 'handle': /* translators: %s: script handle. */ $out['text'] = sprintf( __( 'Enqueued as “%s”, owner not identified', 'goconsent' ), $detail ); $out['known'] = false; break; default: $out['text'] = 'head' === $detail ? __( 'Source not identified: added to the page head without a WordPress handle (theme code or a custom snippet)', 'goconsent' ) : __( 'Source not identified: added to the page without a WordPress handle (theme code or a custom snippet)', 'goconsent' ); $out['known'] = false; } return $out; } }