{{TITLE}}
{$title}
{$value}
"; } /** * Gives the markup of broken links email part. * * @return string */ public function broken_links_list_markup() { $broken_links_list = Model::get_scan_results( 'broken_links_list' ); $markup = ''; if ( empty( $broken_links_list ) || ! is_array( $broken_links_list ) ) { return $markup; } foreach ( $broken_links_list as $broken_link ) { if ( is_object( $broken_link ) ) { $broken_link = (array) $broken_link; } if ( ! is_array( $broken_link ) || empty( $broken_link['url'] ) ) { Utilities::log( 'BLC_SCAN_REPORT_EMAIL - Skipped a broken link entry because it holds no url.' ); continue; } if ( ! empty( $broken_link['is_ignored'] ) ) { continue; } $status_code = isset( $broken_link['status_code'] ) ? trim( (string) $broken_link['status_code'] ) : ''; $status_ref = isset( $broken_link['status_ref'] ) ? trim( (string) $broken_link['status_ref'] ) : ''; $origin_cell = $this->origin_markup( $broken_link ); ob_start(); ?>
{$markup}
" . esc_html__( 'Broken Links', 'broken-link-checker' ) . " " . esc_html__( 'Status', 'broken-link-checker' ) . " " . esc_html__( 'Source URL', 'broken-link-checker' ) . "
"; } /** * Gives the markup of the Source URL cell of a broken link row. * * A broken link is never dropped from the report because we could not tie its * origin back to a local post. We link to the best target we can resolve and * fall back to naming the origin as plain text. * * @param array $broken_link A single broken link record of the scan results. * * @return string */ protected function origin_markup( array $broken_link = array() ) { $origin_source = $this->first_origin( $broken_link ); if ( empty( $origin_source ) ) { Utilities::log( sprintf( 'BLC_SCAN_REPORT_EMAIL - Broken link %s holds no origin. Reporting it without a source.', $broken_link['url'] ?? '' ) ); return $this->origin_label_markup( __( 'Unknown', 'broken-link-checker' ) ); } $origin_source_id = intval( url_to_postid( $origin_source ) ); if ( ! empty( $origin_source_id ) ) { $edit_url = $this->post_edit_url( $origin_source_id ); if ( ! empty( $edit_url ) ) { $origin_post_title = get_the_title( $origin_source_id ); if ( '' === trim( (string) $origin_post_title ) ) { $origin_post_title = $origin_source; } return $this->origin_link_markup( $edit_url, $origin_post_title ); } } // Author archives never resolve through url_to_postid(). $author = Utilities::is_author_url( $origin_source ); if ( $author instanceof WP_User ) { return $this->origin_link_markup( $origin_source, $author->display_name ); } /* * Home page, term or date archives, and permalinks we cannot map to a post. * The origin is still worth reporting, so we point at the page itself. */ Utilities::log( sprintf( 'BLC_SCAN_REPORT_EMAIL - Origin %s did not resolve to a post. Reporting it as a plain url.', $origin_source ) ); return $this->origin_link_markup( $origin_source, $origin_source ); } /** * Returns the first usable origin url of a broken link. * * Origins reach us from the Hub API, so we accept a list of urls, a list of * objects or arrays holding a url, and a bare url string. * * @param array $broken_link A single broken link record of the scan results. * * @return string */ protected function first_origin( array $broken_link = array() ) { $origins = $broken_link['origins'] ?? array(); if ( is_string( $origins ) ) { $origins = array( $origins ); } if ( is_object( $origins ) ) { $origins = (array) $origins; } if ( ! is_array( $origins ) ) { return ''; } foreach ( $origins as $origin ) { if ( is_object( $origin ) ) { $origin = (array) $origin; } if ( is_array( $origin ) ) { $origin = $origin['url'] ?? ''; } if ( is_string( $origin ) && '' !== trim( $origin ) ) { return trim( $origin ); } } return ''; } /** * Returns the edit link of a post. * * The get_edit_post_link() function returns null whenever the current user * cannot edit the post, and a scheduled report is always sent without a user * in context. So we build the link ourselves in that case. * * @param int $post_id The post to build the edit link of. * * @return string */ protected function post_edit_url( int $post_id = 0 ) { if ( empty( $post_id ) ) { return ''; } $edit_url = get_edit_post_link( $post_id ); if ( ! empty( $edit_url ) ) { return $edit_url; } $post = get_post( $post_id ); if ( ! $post instanceof WP_Post ) { return ''; } $post_type_object = get_post_type_object( $post->post_type ); if ( ! $post_type_object || empty( $post_type_object->_edit_link ) ) { return ''; } return admin_url( sprintf( $post_type_object->_edit_link . '&action=edit', $post->ID ) ); } /** * Wraps an origin in a link. * * @param string $url The link target. * @param string $label The text to show. * * @return string */ protected function origin_link_markup( string $url = '', string $label = '' ) { return sprintf( '%2$s', esc_url( $url ), esc_html( $label ) ); } /** * Wraps an origin in plain text, for when there is nothing to link to. * * @param string $label The text to show. * * @return string */ protected function origin_label_markup( string $label = '' ) { return sprintf( '%s', esc_html( $label ) ); } /** * Return the footer content. * * @return string */ public function get_footer_content() { $footer_slogan_img_url = WPMUDEV_BLC_ASSETS_URL . 'images/footer-slogan.png'; ob_start(); ?>
'; $output .= '' . esc_html__( 'Follow us', 'broken-link-checker' ) . ''; foreach ( $social_data as $key => $data ) { $url = $data['url']; $icon = $data['icon']; $output .= " "; } $output .= ''; } return "{$output}
"; } public function review_box_markup( string $review_content = null ) { return '
'; } public function review_box_icon() { $icon_src = WPMUDEV_BLC_ASSETS_URL . 'images/email-review-prompt-icon.png'; return ''; } }