function post_notification_create_email($id, $template = '') { $blogname = get_option('blogname'); if (get_option('post_notification_hdr_nl') == 'rn') { $hdr_nl = "\r\n"; } else { $hdr_nl = "\n"; } if ($template == '') { $template = get_option('post_notification_template'); } if (substr($template, -5) == '.html') { $html_email = true; } else { $html_email = false; } //Get the post $post = get_post($id); $post_url = get_permalink($post->ID); $post_author = get_userdata($post->post_author); $post_author = $post_author->display_name; //cz $co_authors = get_coauthors($post->ID); $post_author = ''; //$post_author = coauthors_posts_links(); //$post_author = count($co_authors); foreach ($co_authors as $key => $co_author) { $post_author .= $co_author->display_name . ' '; if ($key + 1 < count($co_authors)) { $post_author .= '& '; } } $post_title = $post->post_title; if (get_option('post_notification_show_content') == 'yes') { $post_content = stripslashes($post->post_content); } else { if (get_option('post_notification_show_content') == 'more') { $post_content = stripslashes($post->post_content); list($post_content, $more_content) = split('<!--more', $post_content); if ($more_content) { $post_content .= '<a href="@@permalink" >' . get_option('post_notification_read_more') . '</a>'; } } else { if (get_option('post_notification_show_content') == 'excerpt') { if (strlen($post->post_excerpt)) { $post_content = stripslashes($post->post_excerpt); } else { $words = explode(' ', stripslashes($post->post_content)); $tag = false; $wcount = 0; foreach ($words as $word) { $stag = strrpos($word, '<'); $etag = strrpos($word, '>'); if (!is_bool($stag) || !is_bool($etag)) { if (is_bool($stag)) { $tag = false; } else { if (is_bool($etag)) { $tag = true; } else { if ($stag < $etag) { $tag = false; } else { $tag = true; } } } } if (!$tag) { $wcount++; } if ($wcount > 55) { break; } $post_content .= $word . " "; } $post_content = balanceTags($post_content, true); } $post_content .= '<br /><a href="@@permalink" >' . get_option('post_notification_read_more') . '</a>'; } } } // Run filters over the post if ($post_content) { //backup $filter_backup = $GLOBALS['wp_filter']; //Remove unwanted Filters $rem_filters = get_option('post_notification_the_content_exclude'); if (is_string($rem_filters) && strlen($rem_filters)) { $rem_filters = unserialize($rem_filters); } if (!is_array($rem_filters)) { $rem_filters = array(); } foreach ($rem_filters as $rem_filter) { remove_filter('the_content', $rem_filter); } if (!$html_email) { remove_filter('the_content', 'convert_smilies'); //We defenetly don't want smilie - Imgs in Text-Mails. } $post_content = apply_filters('the_content', $post_content); //recover for other plugins $GLOBALS['wp_filter'] = $filter_backup; } // Do some date stuff $post_date = mysql2date(get_settings('date_format'), $post->post_date); $post_time = mysql2date(get_settings('time_format'), $post->post_date); if (!$html_email) { if (get_option('post_notification_debug') == 'yes') { echo 'Date1: ' . htmlspecialchars($post_date) . '<br />'; } if (function_exists('iconv') && strpos(phpversion(), '4') == 0) { //html_entity_decode does not support UTF-8 in php < 5 $post_time = ($temp = iconv(get_settings('blog_charset'), 'ISO8859-1', $post_time)) != "" ? $temp : $post_time; $post_date = ($temp = iconv(get_settings('blog_charset'), 'ISO8859-1', $post_date)) != "" ? $temp : $post_date; } if (get_option('post_notification_debug') == 'yes') { echo 'Date2: ' . htmlspecialchars($post_date) . '<br />'; } $post_time = @html_entity_decode($post_time, ENT_QUOTES, get_settings('blog_charset')); $post_date = @html_entity_decode($post_date, ENT_QUOTES, get_settings('blog_charset')); if (get_option('post_notification_debug') == 'yes') { echo 'Date3: ' . htmlspecialchars($post_date) . '<br />'; } if (function_exists('iconv') && strpos(phpversion(), '4') == 0) { //html_entity_decode does not support UTF-8 in php < 5 $post_time = ($temp = iconv('ISO8859-1', get_settings('blog_charset'), $post_time)) != "" ? $temp : $post_time; $post_date = ($temp = iconv('ISO8859-1', get_settings('blog_charset'), $post_date)) != "" ? $temp : $post_date; } if (get_option('post_notification_debug') == 'yes') { echo 'Date4: ' . htmlspecialchars($post_date) . '<br />'; } } $post_title = strip_tags($post_title); //Convert from HTML to text. if (!$html_email && isset($post_content)) { require_once POST_NOTIFICATION_PATH . 'class.html2text.php'; $h2t =& new html2text($post_content); $post_content = $h2t->get_text(); } // Load template $body = post_notification_ldfile($template); if (get_option('post_notification_debug') == 'yes') { echo "Email variables: <br /><table>"; echo '<tr><td>Emailtype</td><td>' . ($html_email ? 'HTML' : 'TEXT') . '</td>'; echo '<tr><td>@@title</td><td>' . $post_title . '</td></tr>'; echo '<tr><td>@@permalink</td><td>' . $post_url . '</td></tr>'; echo '<tr><td>@@author</td><td>' . $post_author . '</td></tr>'; echo '<tr><td>@@time</td><td>' . $post_time . '</td></tr>'; echo '<tr><td>@@date</td><td>' . $post_date . '</td></tr>'; echo "</table>"; } // Replace variables $body = str_replace('@@content', $post_content, $body); //Insert the posting first. -> for Replacements $body = str_replace('@@title', $post_title, $body); $body = str_replace('@@permalink', $post_url, $body); $body = str_replace('@@author', $post_author, $body); $body = str_replace('@@time', $post_time, $body); $body = str_replace('@@date', $post_date, $body); //cb fix $body = str_replace('<img class="alignright', '<img align="right" class="alignright', $body); $body = str_replace('<img class="alignleft', '<img align="left" hspace="5" vspace="5" class="alignleft', $body); // User replacements if (function_exists('post_notificataion_uf_perPost')) { $body = post_notification_arrayreplace($body, post_notificataion_uf_perPost($id)); } // EMAIL HEADER $header = post_notification_header($html_email); // SUBJECT $subject = get_option('post_notification_subject'); $subject = str_replace('@@blogname', $blogname, $subject); if ($post_title != '') { $subject = str_replace('@@title', $post_title, $subject); } else { $subject = str_replace('@@title', __('New post', 'post_notification'), $subject); } $subject = post_notification_encode($subject, get_settings('blog_charset')); //cz fix dup spaces in subject: $subject = str_replace(' ', ' ', $subject); //cb fix $subject = htmlspecialchars_decode($subject, ENT_QUOTES); $header = htmlspecialchars_decode($header, ENT_QUOTES); $rv = array(); $rv['id'] = $id; $rv['subject'] = $subject; $rv['body'] = $body; $rv['header'] = $header; return $rv; }
function post_notification_header($html = false) { if (get_option('post_notification_hdr_nl') == 'rn') { $hdr_nl = "\r\n"; } else { $hdr_nl = "\n"; } $header = "MIME-Version: 1.0{$hdr_nl}"; if ($html) { $header .= 'Content-Type: text/html; charset="' . get_settings('blog_charset') . '"' . $hdr_nl; } else { $header .= 'Content-Type: text/plain; charset="' . get_settings('blog_charset') . '"' . $hdr_nl; } $from_name = str_replace('@@blogname', get_option('blogname'), get_option('post_notification_from_name')); $from_name = post_notification_encode($from_name, get_settings('blog_charset')); $from_email = get_option('post_notification_from_email'); //cb fix $from_name = htmlspecialchars_decode($from_name, ENT_QUOTES); $from_email = htmlspecialchars_decode($from_email, ENT_QUOTES); $header .= "From: \"{$from_name}\" <{$from_email}>{$hdr_nl}"; $header .= "Reply-To: {$from_email}{$hdr_nl}"; $header .= "Return-Path: {$from_email}{$hdr_nl}"; return $header; }