function build_instance_list_for_email($instances, $max_displayed_links = 5) { $result = ''; if (count($instances) > $max_displayed_links) { $line = sprintf(_n("Here's a list of the first %d broken links:", "Here's a list of the first %d broken links:", $max_displayed_links, 'broken-link-checker'), $max_displayed_links); } else { $line = __("Here's a list of the new broken links: ", 'broken-link-checker'); } $result .= "<p>{$line}</p>"; //Show up to $max_displayed_links broken link instances right in the email. $displayed = 0; foreach ($instances as $instance) { /* @var blcLinkInstance $instance */ $pieces = array(sprintf(__('Link text : %s', 'broken-link-checker'), $instance->ui_get_link_text('email')), sprintf(__('Link URL : <a href="%s">%s</a>', 'broken-link-checker'), htmlentities($instance->get_url()), blcUtility::truncate($instance->get_url(), 70, '')), sprintf(__('Source : %s', 'broken-link-checker'), $instance->ui_get_source('email'))); $link_entry = implode("<br>", $pieces); $result .= "{$link_entry}<br><br>"; $displayed++; if ($displayed >= $max_displayed_links) { break; } } //Add a link to the "Broken Links" tab. $result .= __("You can see all broken links here:", 'broken-link-checker') . "<br>"; $result .= sprintf('<a href="%1$s">%1$s</a>', admin_url('tools.php?page=view-broken-links')); return $result; }
function ui_get_source_comment($container, $container_field = '') { //Display a comment icon. if ($container_field == 'comment_author_url') { $image = 'font-awesome/font-awesome-user.png'; } else { $image = 'font-awesome/font-awesome-comment-alt.png'; } $comment = $container->get_wrapped_object(); //Display a small text sample from the comment $text_sample = strip_tags($comment->comment_content); $text_sample = blcUtility::truncate($text_sample, 65); return array('image' => $image, 'text_sample' => $text_sample, 'comment_author' => esc_attr($comment->comment_author), 'comment_id' => esc_attr($comment->comment_ID), 'comment_status' => wp_get_comment_status($comment->comment_ID), 'container_post_title' => get_the_title($comment->comment_post_ID), 'container_post_status' => get_post_status($comment->comment_post_ID), 'container_post_ID' => $comment->comment_post_ID); }
function ui_get_source($container_field = '', $context = 'display') { //Display a comment icon. if ($container_field == 'comment_author_url') { $image = 'font-awesome/font-awesome-user.png'; } else { $image = 'font-awesome/font-awesome-comment-alt.png'; } $image = sprintf('<img src="%s/broken-link-checker/images/%s" class="blc-small-image" title="%3$s" alt="%3$s"> ', WP_PLUGIN_URL, $image, __('Comment', 'broken-link-checker')); $comment = $this->get_wrapped_object(); //Display a small text sample from the comment $text_sample = strip_tags($comment->comment_content); $text_sample = blcUtility::truncate($text_sample, 65); $html = sprintf('<a href="%s" title="%s"><b>%s</b> — %s</a>', $this->get_edit_url(), esc_attr__('Edit comment'), esc_attr($comment->comment_author), $text_sample); //Don't show the image in email notifications. if ($context != 'email') { $html = $image . $html; } return $html; }
function send_email_notifications() { global $wpdb; //Find links that have been detected as broken since the last sent notification. $last_notification = date('Y-m-d H:i:s', $this->conf->options['last_notification_sent']); $where = $wpdb->prepare('( first_failure >= %s )', $last_notification); $links = blc_get_links(array('s_filter' => 'broken', 'where_expr' => $where, 'load_instances' => true, 'max_results' => 0)); if (empty($links)) { return; } $cnt = count($links); //Prepare email message $subject = sprintf(__("[%s] Broken links detected", 'broken-link-checker'), html_entity_decode(get_option('blogname'), ENT_QUOTES)); $body = sprintf(_n("Broken Link Checker has detected %d new broken link on your site.", "Broken Link Checker has detected %d new broken links on your site.", $cnt, 'broken-link-checker'), $cnt); $body .= "<br>"; $max_displayed_links = 5; if ($cnt > $max_displayed_links) { $line = sprintf(_n("Here's a list of the first %d broken links:", "Here's a list of the first %d broken links:", $max_displayed_links, 'broken-link-checker'), $max_displayed_links); } else { $line = __("Here's a list of the new broken links: ", 'broken-link-checker'); } $body .= "<p>{$line}</p>"; //Show up to $max_displayed_links broken link instances right in the email. $displayed = 0; foreach ($links as $link) { $instances = $link->get_instances(); foreach ($instances as $instance) { $pieces = array(sprintf(__('Link text : %s', 'broken-link-checker'), $instance->ui_get_link_text('email')), sprintf(__('Link URL : <a href="%s">%s</a>', 'broken-link-checker'), htmlentities($link->url), blcUtility::truncate($link->url, 70, '')), sprintf(__('Source : %s', 'broken-link-checker'), $instance->ui_get_source('email'))); $link_entry = implode("<br>", $pieces); $body .= "{$link_entry}<br><br>"; $displayed++; if ($displayed >= $max_displayed_links) { break 2; //Exit both foreach loops } } } //Add a link to the "Broken Links" tab. $body .= __("You can see all broken links here:", 'broken-link-checker') . "<br>"; $link_page = admin_url('tools.php?page=view-broken-links'); $body .= sprintf('<a href="%1$s">%1$s</a>', $link_page); //Need to override the default 'text/plain' content type to send a HTML email. add_filter('wp_mail_content_type', array(&$this, 'override_mail_content_type')); //Send the notification $rez = wp_mail(get_option('admin_email'), $subject, $body); if ($rez) { $this->conf->options['last_notification_sent'] = time(); $this->conf->save_options(); } //Remove the override so that it doesn't interfere with other plugins that might //want to send normal plaintext emails. remove_filter('wp_mail_content_type', array(&$this, 'override_mail_content_type')); }