true,
'strategy' => 'defer',
)
);
wp_localize_script(
'cpradar',
'cpradarText',
array(
'copied' => __( 'Copied ✓', 'syncnet-patch-radar' ),
'copy' => __( 'Copy address:', 'syncnet-patch-radar' ),
)
);
}
add_action( 'wp_enqueue_scripts', 'cpradar_register_assets' );
/**
* Enqueue assets when a shortcode renders.
*/
function cpradar_enqueue() {
wp_enqueue_style( 'cpradar' );
$accent = sanitize_hex_color( cpradar_settings()['accent'] );
if ( $accent ) {
wp_add_inline_style( 'cpradar', '.cpr{--cpr-accent:' . $accent . ';}' );
}
wp_enqueue_script( 'cpradar' );
}
/**
* Shorten text at a word boundary.
*
* @param string $text Text.
* @param int $max Characters.
* @return string
*/
function cpradar_short( $text, $max = 200 ) {
$text = trim( preg_replace( '/\s+/u', ' ', (string) $text ) );
if ( mb_strlen( $text ) <= $max ) {
return $text;
}
$cut = mb_substr( $text, 0, $max - 1 );
$pos = mb_strrpos( $cut, ' ' );
if ( $pos > $max * 0.6 ) {
$cut = mb_substr( $cut, 0, $pos );
}
return rtrim( $cut, ' ,;:–-' ) . ' …';
}
/**
* Formatted date.
*
* @param int $ts Timestamp.
* @return string
*/
function cpradar_date( $ts ) {
return wp_date( get_option( 'date_format' ), $ts );
}
/**
* Badges for an alert.
*
* @param array $a Alert.
* @return string HTML.
*/
function cpradar_badges( $a ) {
$h = '';
if ( 'group' === $a['source'] && 'cisa' === ( $a['type'] ?? '' ) ) {
$h = '' . esc_html__( 'actively exploited', 'syncnet-patch-radar' ) . ' ';
/* translators: %d: number of vulnerabilities */
$h .= '' . esc_html( sprintf( _n( '%d vulnerability', '%d vulnerabilities', $a['count'], 'syncnet-patch-radar' ), $a['count'] ) ) . ' ';
if ( ! empty( $a['ransom'] ) ) {
$h .= ' ' . esc_html__( 'Ransomware', 'syncnet-patch-radar' ) . ' ';
}
return $h;
}
switch ( $a['source'] ) {
case 'group':
/* translators: %s: CVSS score */
$h = '' . esc_html( sprintf( __( 'CVSS up to %s', 'syncnet-patch-radar' ), cpradar_score( $a['cvss'] ) ) ) . ' ';
/* translators: %d: number of vulnerabilities */
$h .= '' . esc_html( sprintf( _n( '%d vulnerability', '%d vulnerabilities', $a['count'], 'syncnet-patch-radar' ), $a['count'] ) ) . ' ';
break;
case 'nvd':
$h = 'CVSS ' . esc_html( cpradar_score( $a['cvss'] ) ) . ' ';
break;
case 'cisa':
$h = '' . esc_html__( 'actively exploited', 'syncnet-patch-radar' ) . ' ';
if ( ! empty( $a['ransom'] ) ) {
$h .= ' ' . esc_html__( 'Ransomware', 'syncnet-patch-radar' ) . ' ';
}
if ( ! empty( $a['cvss'] ) ) {
$h .= ' CVSS ' . esc_html( cpradar_score( $a['cvss'] ) ) . ' ';
}
break;
default:
$h = '' . esc_html__( 'critical (BSI)', 'syncnet-patch-radar' ) . ' ';
if ( 'UPDATE' === $a['kind'] ) {
$h .= ' ' . esc_html__( 'updated', 'syncnet-patch-radar' ) . ' ';
}
}
return $h;
}
/**
* Source line with link to the original record.
*
* @param array $a Alert.
* @return string HTML.
*/
function cpradar_source_line( $a ) {
$names = array(
'bsi' => __( 'BSI / CERT-Bund (Germany)', 'syncnet-patch-radar' ),
'cisa' => __( 'CISA (USA), Known Exploited Vulnerabilities', 'syncnet-patch-radar' ),
'nvd' => __( 'NVD (USA)', 'syncnet-patch-radar' ),
);
$cisa_group = 'group' === $a['source'] && 'cisa' === ( $a['type'] ?? '' );
$link = 'group' === $a['source'] && ! $cisa_group ? 'https://nvd.nist.gov/' : $a['link'];
$name = $cisa_group ? $names['cisa'] : ( 'group' === $a['source'] ? $names['nvd'] : ( $names[ $a['source'] ] ?? $names['bsi'] ) );
/* translators: %s: name of the source, linked */
$h = sprintf( esc_html__( 'Source: %s', 'syncnet-patch-radar' ), '' . esc_html( $name ) . ' ' );
if ( in_array( $a['source'], array( 'nvd', 'group' ), true ) && ! empty( $a['cna'] ) ) {
/* translators: %s: vendor name */
$h .= ', ' . esc_html( sprintf( __( 'reported by %s', 'syncnet-patch-radar' ), $a['cna'] ) );
}
return $h;
}
/**
* List of CVEs in a group.
*
* @param array $g Group.
* @return string HTML.
*/
function cpradar_group_list( $g ) {
if ( 'cisa' === ( $g['type'] ?? '' ) ) {
$h = '
';
foreach ( $g['items'] as $a ) {
$h .= sprintf(
'%2$s %3$s · %4$s ',
esc_url( cpradar_alert_url( $a['id'] ) ),
esc_html( cpradar_short_name( $a, $g ) ),
esc_html( $a['id'] ),
esc_html( wp_date( 'j M', $a['date'] ) )
);
}
return $h . ' ';
}
$h = '';
foreach ( $g['items'] as $a ) {
$h .= sprintf(
'%2$s CVSS %3$s %4$s ',
esc_url( cpradar_alert_url( $a['id'] ) ),
esc_html( $a['id'] ),
esc_html( cpradar_score( $a['cvss'] ) ),
esc_html( wp_date( 'j M', $a['date'] ) )
);
}
return $h . ' ';
}
/**
* One card.
*
* @param array $a Alert or group.
* @param bool $full With text, source and links (list) or compact (box).
* @return string HTML.
*/
function cpradar_card( $a, $full = true ) {
$url = cpradar_alert_url( $a['id'] );
$attr = '';
if ( $full ) {
$search = mb_strtolower( $a['title'] . ' ' . $a['text'] . ' ' . $a['id'] . ' ' . ( $a['product'] ?? '' ) . ' ' . cpradar_vendor( $a ) );
if ( 'group' === $a['source'] ) {
$search .= ' ' . mb_strtolower( implode( ' ', array_column( $a['items'], 'id' ) ) );
}
$attr = ' data-search="' . esc_attr( $search ) . '" data-vendor="' . esc_attr( cpradar_vendor( $a ) ) . '"';
}
$h = '';
$h .= '' . cpradar_badges( $a ) . ' ' . esc_html( cpradar_date( $a['date'] ) ) . '
';
$h .= '';
if ( $full ) {
if ( '' !== $a['text'] ) {
$h .= '' . esc_html( cpradar_short( $a['text'] ) ) . '
';
}
$h .= '' . cpradar_source_line( $a ) . '
';
if ( 'group' === $a['source'] ) {
/* translators: %d: number of vulnerabilities */
$h .= '' . esc_html( sprintf( __( 'Show all %d vulnerabilities', 'syncnet-patch-radar' ), $a['count'] ) ) . ' ' . cpradar_group_list( $a ) . ' ';
}
$h .= '' . esc_html__( 'Details and sharing →', 'syncnet-patch-radar' ) . '
';
}
return $h . ' ';
}
/**
* Share buttons (plain links – nothing is loaded from third parties until a visitor clicks).
*
* @param array $a Alert.
* @param bool $compact Buttons only, without the note.
* @return string HTML.
*/
function cpradar_share( $a, $compact = false ) {
$url = cpradar_alert_url( $a['id'] );
/* translators: %s: alert title */
$text = sprintf( __( 'Security alert: %s', 'syncnet-patch-radar' ), $a['title'] );
$mail = 'mailto:?subject=' . rawurlencode( $text ) . '&body=' . rawurlencode( $text . "\n\n" . $url );
$h = '';
if ( ! $compact ) {
$h .= '' . esc_html__( 'LinkedIn, WhatsApp and Teams only open when you click them.', 'syncnet-patch-radar' ) . '
';
}
return $h;
}
/**
* Subscription box with main feed and vendor feeds.
*
* @param array $entries Cards.
* @param bool $compact One line with the main feed only.
* @return string HTML.
*/
function cpradar_subscribe( $entries, $compact = false ) {
$feed = cpradar_feed_url();
$vendors = array();
foreach ( $entries as $a ) {
$v = cpradar_vendor( $a );
if ( '' !== $v ) {
$vendors[ $v ] = true;
}
}
ksort( $vendors, SORT_NATURAL | SORT_FLAG_CASE );
$h = '';
if ( $compact ) {
$h = '
' . esc_html__( 'Subscribe via RSS:', 'syncnet-patch-radar' ) . ' ' . esc_html( $feed ) . ' ' . esc_html__( 'Copy address', 'syncnet-patch-radar' ) . '
';
return $h;
}
$h .= '
' . esc_html__( 'Subscribe to new alerts', 'syncnet-patch-radar' ) . '
';
$h .= '
' . esc_html__( 'With the RSS feed you see new alerts automatically – in Outlook, Thunderbird or any feed reader. No sign-up, no email address.', 'syncnet-patch-radar' ) . '
';
$h .= '
' . esc_html( $feed ) . ' ' . esc_html__( 'Copy address', 'syncnet-patch-radar' ) . '
';
$h .= '
';
/* translators: %s: vendor name (filled in by script) */
$h .= sprintf( esc_html__( 'Only %s', 'syncnet-patch-radar' ), ' ' );
$h .= '
' . esc_html__( 'Copy address', 'syncnet-patch-radar' ) . '
';
if ( count( $vendors ) > 1 ) {
$h .= '
' . esc_html__( 'Subscribe to single vendors only', 'syncnet-patch-radar' ) . ' ' . esc_html__( 'Copy the feed address and paste it into your feed reader or Outlook. Clicking a name shows that vendor\'s alerts on this page.', 'syncnet-patch-radar' ) . '
';
foreach ( array_keys( $vendors ) as $v ) {
$h .= '' . esc_html( $v ) . ' ' . esc_html__( 'copy feed address', 'syncnet-patch-radar' ) . ' ';
}
$h .= ' ';
}
$h .= '
' . esc_html__( 'How to subscribe in Outlook', 'syncnet-patch-radar' ) . ' ' . esc_html__( 'Classic Outlook: right-click "RSS Feeds" in the folder pane → "Add a New RSS Feed…" → paste the address → "Add".', 'syncnet-patch-radar' ) . '
';
return $h . '
';
}
/**
* Optional credit line (off by default, enabled in the settings).
*
* @return string HTML.
*/
function cpradar_credit() {
if ( empty( cpradar_settings()['credit'] ) ) {
return '';
}
/* translators: %s: linked author name */
return '' . sprintf( esc_html__( 'SyncNet Patch Radar by %s', 'syncnet-patch-radar' ), 'SyncNet | Oliver Giesbert ' ) . '
';
}
/**
* Optional call-to-action box (e.g. "Need help? Contact us").
*
* @return string HTML.
*/
function cpradar_cta() {
$s = cpradar_settings();
if ( '' === trim( (string) $s['cta_text'] ) ) {
return '';
}
$h = '';
}
/**
* Search field and vendor filters.
*
* @param array $entries Cards.
* @return string HTML.
*/
function cpradar_search( $entries ) {
$count = array();
foreach ( $entries as $a ) {
$v = cpradar_vendor( $a );
if ( '' !== $v ) {
$count[ $v ] = ( $count[ $v ] ?? 0 ) + 1;
}
}
arsort( $count );
$count = array_slice( $count, 0, 12, true );
$total = count( $entries );
$h = '';
$h .= '
' . esc_html__( 'Am I affected?', 'syncnet-patch-radar' ) . ' ';
$h .= '
';
if ( count( $count ) > 1 ) {
$h .= '
';
foreach ( $count as $name => $n ) {
$h .= '' . esc_html( $name ) . ' ' . (int) $n . ' ';
}
$h .= '
';
}
/* translators: 1: number shown (filled in by script), 2: total number */
$h .= '
' . sprintf( esc_html__( '%1$s of %2$s alerts', 'syncnet-patch-radar' ), '' . (int) $total . ' ', (int) $total );
$h .= ' ' . esc_html__( 'Reset filter', 'syncnet-patch-radar' ) . '
';
return $h . '
';
}
/**
* [syncnet_patch_radar] – list, or a single alert on /…/alert//.
*
* @return string HTML.
*/
function cpradar_shortcode_list() {
cpradar_enqueue();
$id = get_query_var( 'cpradar_alert' );
if ( $id ) {
return '' . cpradar_single( $id ) . '
';
}
$s = cpradar_settings();
$entries = cpradar_entries();
$status = (array) get_option( 'cpradar_status', array() );
$intro = trim( (string) $s['intro'] );
if ( '' === $intro ) {
$intro = __( 'Collected automatically: vulnerabilities in widely used products that are rated critical by the German BSI, are known to be actively exploited, or are rated CVSS 9 or higher by the vendor. Check whether you are affected and install updates promptly.', 'syncnet-patch-radar' );
}
$h = '' . esc_html( $intro ) . '
';
$pos = $s['subscribe_pos'];
if ( 'top' === $pos || 'both' === $pos ) {
$h .= cpradar_subscribe( $entries, 'both' === $pos );
}
if ( ! $entries ) {
$h .= '
' . esc_html__( 'There are currently no critical alerts.', 'syncnet-patch-radar' ) . '
';
} else {
$h .= cpradar_search( $entries );
$h .= '
' . esc_html__( 'Several critical vulnerabilities in the same product are combined into one card – usually one update fixes them all.', 'syncnet-patch-radar' ) . '
';
$h .= '
';
foreach ( $entries as $a ) {
$h .= cpradar_card( $a );
}
$h .= '
' . esc_html__( 'No alert matches your search.', 'syncnet-patch-radar' ) . ' ' . esc_html__( 'Show all', 'syncnet-patch-radar' ) . '
';
}
$h .= cpradar_cta();
if ( 'bottom' === $pos || 'both' === $pos ) {
$h .= cpradar_subscribe( $entries );
}
$h .= '' . cpradar_credit() . '
';
return $h;
}
add_shortcode( 'syncnet_patch_radar', 'cpradar_shortcode_list' );
/**
* Single alert or product group.
*
* @param string $id ID.
* @return string HTML.
*/
function cpradar_single( $id ) {
$a = cpradar_alert( $id );
$back = '' . esc_html__( '← All alerts', 'syncnet-patch-radar' ) . '
';
if ( ! $a ) {
return $back . '' . esc_html__( 'Alert no longer available', 'syncnet-patch-radar' ) . ' ' . esc_html__( 'This alert is older than the display period or has been withdrawn.', 'syncnet-patch-radar' ) . '
';
}
$h = $back . '' . cpradar_badges( $a ) . ' ' . esc_html( cpradar_date( $a['date'] ) ) . '
';
$h .= '' . esc_html( $a['title'] ) . ' ';
$share = cpradar_settings()['share_pos'];
if ( 'top' === $share || 'both' === $share ) {
$h .= '' . cpradar_share( $a, 'both' === $share ) . '
';
}
$h .= '';
switch ( $a['source'] ) {
case 'group':
$h .= '
' . esc_html( $a['text'] ) . '
' . cpradar_group_list( $a );
break;
case 'cisa':
$h .= '
' . esc_html( ! empty( $a['ransom'] ) ? __( 'According to the US agency CISA this vulnerability is already being exploited in attacks, also by ransomware groups. Affected systems should be updated immediately.', 'syncnet-patch-radar' ) : __( 'According to the US agency CISA this vulnerability is already being exploited in attacks. Affected systems should be updated immediately.', 'syncnet-patch-radar' ) ) . '
';
$h .= '' !== $a['text'] ? '
' . esc_html( $a['text'] ) . '
' : '';
break;
case 'nvd':
/* translators: %s: CVSS score */
$h .= '
' . esc_html( sprintf( __( 'This vulnerability is rated CVSS %s out of 10 and can be exploited over the network without authentication. It is currently not on the CISA list of actively exploited vulnerabilities – updates should still be installed promptly.', 'syncnet-patch-radar' ), cpradar_score( $a['cvss'] ) ) ) . '
';
$h .= '' !== $a['text'] ? '
' . esc_html( $a['text'] ) . '
' : '';
break;
default:
$h .= '' !== $a['text'] ? '
' . esc_html( $a['text'] ) . '
' : '';
$h .= '
' . esc_html__( 'The German Federal Office for Information Security (BSI) rates this advisory as critical, the highest level.', 'syncnet-patch-radar' ) . '
';
}
if ( 'group' !== $a['source'] ) {
/* translators: %s: alert ID */
$h .= '
' . sprintf( esc_html__( 'ID: %s', 'syncnet-patch-radar' ), '' . esc_html( $a['id'] ) . ' ' ) . '
';
}
$h .= '
' . cpradar_source_line( $a ) . '
';
if ( 'bottom' === $share || 'both' === $share ) {
$h .= cpradar_share( $a );
}
$h .= cpradar_cta() . '
' . cpradar_credit();
return $h;
}
/**
* [syncnet_patch_radar_latest] – one discreet line with the newest alert (e.g. for the front page).
*
* @param array $atts days: hide if older (default: setting).
* @return string HTML.
*/
function cpradar_shortcode_latest( $atts ) {
$atts = shortcode_atts( array( 'days' => cpradar_settings()['fresh'] ), $atts );
$all = cpradar_alerts();
$a = reset( $all );
if ( ! $a || (int) $atts['days'] < 1 || $a['date'] < time() - DAY_IN_SECONDS * (int) $atts['days'] ) {
return '';
}
cpradar_enqueue();
$url = cpradar_page_url() . '#alert-' . strtolower( cpradar_card_id( $a ) );
return sprintf(
'%2$s %3$s · %4$s →
',
esc_url( $url ),
esc_html( 'cisa' === $a['source'] ? __( 'Actively exploited:', 'syncnet-patch-radar' ) : __( 'Critical now:', 'syncnet-patch-radar' ) ),
esc_html( cpradar_short( $a['title'], 90 ) ),
esc_html( cpradar_date( $a['date'] ) )
);
}
add_shortcode( 'syncnet_patch_radar_latest', 'cpradar_shortcode_latest' );
/**
* [syncnet_patch_radar_box count="3"] – compact cards for other pages.
*
* @param array $atts count.
* @return string HTML.
*/
function cpradar_shortcode_box( $atts ) {
cpradar_enqueue();
$atts = shortcode_atts( array( 'count' => 3 ), $atts );
$list = array_slice( cpradar_entries(), 0, max( 1, min( 12, (int) $atts['count'] ) ) );
$h = '';
return $h;
}
add_shortcode( 'syncnet_patch_radar_box', 'cpradar_shortcode_box' );
// Red dot on the menu item of the alerts page while a fresh, actively exploited vulnerability is listed.
/**
* Whether an actively exploited vulnerability is newer than the configured hours.
*
* @return bool
*/
function cpradar_urgent() {
static $urgent = null;
if ( null === $urgent ) {
$hours = (int) cpradar_settings()['menu_dot'];
$limit = time() - HOUR_IN_SECONDS * $hours;
$urgent = false;
if ( $hours > 0 ) {
foreach ( cpradar_alerts() as $a ) {
if ( 'cisa' === $a['source'] && $a['date'] >= $limit ) {
$urgent = true;
break;
}
}
}
}
return $urgent;
}
/**
* Markup of the dot.
*
* @return string
*/
function cpradar_dot() {
return ' ' . esc_html__( '(new urgent alert)', 'syncnet-patch-radar' ) . ' ';
}
/**
* Whether a URL points to the alerts page.
*
* @param string $url URL.
* @return bool
*/
function cpradar_is_page_url( $url ) {
$page = untrailingslashit( (string) wp_parse_url( cpradar_page_url(), PHP_URL_PATH ) );
$path = untrailingslashit( (string) wp_parse_url( (string) $url, PHP_URL_PATH ) );
return '' !== $page && $page === $path;
}
add_filter(
'render_block_core/navigation-link',
function ( $html, $block ) {
$hit = (int) ( $block['attrs']['id'] ?? 0 ) === (int) cpradar_settings()['page_id'] || cpradar_is_page_url( $block['attrs']['url'] ?? '' );
if ( ! $hit || ! cpradar_urgent() ) {
return $html;
}
cpradar_enqueue();
return (string) preg_replace( '#(.*? )#s', '$1' . cpradar_dot(), $html, 1 );
},
10,
2
);
add_filter(
'render_block_core/page-list',
function ( $html ) {
if ( ! cpradar_urgent() ) {
return $html;
}
$url = preg_quote( untrailingslashit( cpradar_page_url() ), '#' );
$new = (string) preg_replace( '#(]+href="' . $url . '/?"[^>]*>)(.*?)( )#s', '$1$2' . cpradar_dot() . '$3', $html, 1 );
if ( $new !== $html ) {
cpradar_enqueue();
}
return $new;
}
);
add_filter(
'render_block',
function ( $html, $block ) {
if ( 'core/navigation' !== ( $block['blockName'] ?? '' ) || ! cpradar_urgent() || false === strpos( $html, 'cpr-menu-dot' ) ) {
return $html;
}
$p = new WP_HTML_Tag_Processor( $html );
if ( $p->next_tag( 'nav' ) ) {
$p->add_class( 'cpr-urgent' );
return $p->get_updated_html();
}
return $html;
},
20,
2
);
add_filter(
'nav_menu_item_title',
function ( $title, $item ) {
$page_id = (int) cpradar_settings()['page_id'];
$hit = ( 'page' === ( $item->object ?? '' ) && (int) $item->object_id === $page_id ) || cpradar_is_page_url( $item->url ?? '' );
if ( $hit && cpradar_urgent() ) {
wp_enqueue_style( 'cpradar' );
return $title . cpradar_dot();
}
return $title;
},
10,
2
);
// Title, description, robots for single alerts (core, Yoast SEO).
/**
* Alert of the current request, if any.
*
* @return array|null
*/
function cpradar_current() {
static $a = false;
if ( false === $a ) {
$id = get_query_var( 'cpradar_alert' );
$a = $id ? cpradar_alert( $id ) : null;
}
return $a;
}
/**
* Meta description for an alert.
*
* @param array $a Alert.
* @return string
*/
function cpradar_description( $a ) {
switch ( $a['source'] ) {
case 'cisa':
return __( 'Actively exploited. Update affected systems immediately.', 'syncnet-patch-radar' );
case 'group':
if ( 'cisa' === ( $a['type'] ?? '' ) ) {
/* translators: %d: number of vulnerabilities */
return sprintf( _n( '%d vulnerability is being actively exploited. Update affected systems immediately.', '%d vulnerabilities are being actively exploited. Update affected systems immediately.', $a['count'], 'syncnet-patch-radar' ), $a['count'] );
}
/* translators: 1: number, 2: CVSS score */
return sprintf( _n( '%1$d critical vulnerability (up to CVSS %2$s). Install updates.', '%1$d critical vulnerabilities (up to CVSS %2$s). Install updates.', $a['count'], 'syncnet-patch-radar' ), $a['count'], cpradar_score( $a['cvss'] ) );
case 'nvd':
/* translators: %s: CVSS score */
return sprintf( __( 'Critical vulnerability (CVSS %s), exploitable over the network without authentication. Install updates promptly.', 'syncnet-patch-radar' ), cpradar_score( $a['cvss'] ) );
default:
return cpradar_short( __( 'BSI rating: critical.', 'syncnet-patch-radar' ) . ' ' . $a['text'], 155 );
}
}
add_filter(
'document_title_parts',
function ( $parts ) {
$a = cpradar_current();
if ( $a ) {
/* translators: %s: alert title */
$parts['title'] = sprintf( __( 'Security alert: %s', 'syncnet-patch-radar' ), $a['title'] );
}
return $parts;
}
);
foreach ( array( 'wpseo_title', 'wpseo_opengraph_title', 'wpseo_twitter_title' ) as $cpradar_filter ) {
add_filter(
$cpradar_filter,
function ( $value ) {
$a = cpradar_current();
/* translators: %s: alert title */
return $a ? sprintf( __( 'Security alert: %s', 'syncnet-patch-radar' ), $a['title'] ) : $value;
}
);
}
foreach ( array( 'wpseo_metadesc', 'wpseo_opengraph_desc', 'wpseo_twitter_description' ) as $cpradar_filter ) {
add_filter(
$cpradar_filter,
function ( $value ) {
$a = cpradar_current();
return $a ? cpradar_description( $a ) : $value;
}
);
}
foreach ( array( 'wpseo_canonical', 'wpseo_opengraph_url' ) as $cpradar_filter ) {
add_filter(
$cpradar_filter,
function ( $value ) {
$a = cpradar_current();
return $a ? cpradar_alert_url( $a['id'] ) : $value;
}
);
}
add_filter(
'wpseo_robots',
function ( $value ) {
return cpradar_current() ? 'noindex, follow' : $value;
}
);
add_filter(
'wp_robots',
function ( $robots ) {
if ( cpradar_current() && ! defined( 'WPSEO_VERSION' ) ) {
$robots['noindex'] = true;
$robots['follow'] = true;
}
return $robots;
}
);
add_action(
'wp_head',
function () {
$a = cpradar_current();
if ( $a && ! defined( 'WPSEO_VERSION' ) ) {
printf( ' ' . "\n", esc_attr( cpradar_description( $a ) ) );
printf( ' ' . "\n", esc_attr( wp_get_document_title() ) );
printf( ' ' . "\n", esc_attr( cpradar_description( $a ) ) );
printf( ' ' . "\n", esc_url( cpradar_alert_url( $a['id'] ) ) );
}
printf( ' ' . "\n", esc_attr( get_bloginfo( 'name' ) . ' – ' . __( 'Security alerts', 'syncnet-patch-radar' ) ), esc_url( cpradar_feed_url() ) );
}
);
add_action(
'template_redirect',
function () {
if ( get_query_var( 'cpradar_alert' ) && ! cpradar_current() ) {
status_header( 404 );
nocache_headers();
}
}
);
// RSS feed: /feed/patch-radar/ and /feed/patch-radar/?vendor=Microsoft.
/**
* Output the feed.
*/
function cpradar_render_feed() {
$list = cpradar_entries();
$vendor = isset( $_GET['vendor'] ) ? sanitize_text_field( wp_unslash( $_GET['vendor'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- public, read-only feed.
if ( '' !== $vendor ) {
$list = array_values( array_filter( $list, fn( $a ) => 0 === strcasecmp( cpradar_vendor( $a ), $vendor ) ) );
}
usort( $list, fn( $a, $b ) => $b['date'] <=> $a['date'] );
$list = array_slice( $list, 0, 50 );
$updated = $list ? max( array_column( $list, 'date' ) ) : time();
$title = get_bloginfo( 'name' ) . ' – ' . __( 'Security alerts', 'syncnet-patch-radar' ) . ( '' !== $vendor ? ': ' . $vendor : '' );
header( 'Content-Type: application/rss+xml; charset=UTF-8' );
echo '' . "\n";
echo '' . "\n";
echo '' . esc_html( $title ) . ' ' . "\n";
echo ' ' . esc_url( cpradar_page_url() ) . '' . "\n";
echo ' ' . "\n";
echo '' . esc_html__( 'Critical vulnerabilities in widely used products, compiled automatically from BSI, CISA and NVD data.', 'syncnet-patch-radar' ) . ' ' . "\n";
echo '' . esc_html( get_bloginfo( 'language' ) ) . ' ' . "\n";
echo '' . esc_html( gmdate( 'r', $updated ) ) . ' 60 ' . "\n";
foreach ( $list as $a ) {
$url = cpradar_alert_url( $a['id'] );
$prefix = cpradar_is_exploited( $a ) ? '[' . __( 'actively exploited', 'syncnet-patch-radar' ) . '] ' : ( 'bsi' === $a['source'] ? '[' . __( 'critical (BSI)', 'syncnet-patch-radar' ) . '] ' : '' );
echo "- \n";
echo '
' . esc_html( $prefix . $a['title'] ) . ' ' . "\n";
echo ' ' . esc_url( $url ) . '' . "\n";
echo '' . esc_html( $url . ( 'group' === $a['source'] ? '#' . $a['count'] . '-' . $a['date'] : '' ) ) . ' ' . "\n";
echo '' . esc_html( gmdate( 'r', $a['date'] ) ) . ' ' . "\n";
echo '' . esc_html( cpradar_description( $a ) ) . ' ' . "\n";
echo " \n";
}
echo ' ';
exit;
}