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; }
/** * This creates the content */ function post_notification_page_content() { global $post_notification_page_content_glob, $wpdb; if ($post_notification_page_content_glob) { return $post_notification_page_content_glob; } //It doesn't matter where this goes: $content =& $post_notification_page_content_glob; $content = array(); $content['header'] = ''; $content['body'] = ''; // ******************************************************** // // GET VARIABLES FROM URL // ******************************************************** // $action = $_GET['action']; $addr = $wpdb->escape($_GET['addr']); $code = $wpdb->escape($_GET['code']); if ($_POST['addr'] != '') { $action = $_POST['action']; $addr = $wpdb->escape($_POST['addr']); $code = $wpdb->escape($_POST['code']); $pn_cats = $_POST['pn_cats']; //Security is handled in the function. } $msg =& $content['body']; // ******************************************************** // // DEFINE OTHER VARS NEEDED // ******************************************************** // require post_notification_get_profile_dir() . '/strings.php'; $t_emails = $wpdb->prefix . 'post_notification_emails'; $t_cats = $wpdb->prefix . 'post_notification_cats'; $from_email = get_option('post_notification_from_email'); $pnurl = post_notification_get_link(); if (get_option('post_notification_hdr_nl') == "rn") { $hdr_nl = "\r\n"; } else { $hdr_nl = "\n"; } $blogname = get_option('blogname'); // ******************************************************** // // Code Check // ******************************************************** // //This code is not very nice in performance, but I wanted to keep it as easy to understand as possible. It's not called that often. if ($code != '' && $wpdb->get_var("SELECT id FROM {$t_emails} WHERE email_addr = '{$addr}' AND act_code = '" . $code . "'")) { // ******************************************************** // // WITH AUTH // ******************************************************** // if (1 != $wpdb->get_var("SELECT gets_mail FROM {$t_emails} WHERE email_addr = '{$addr}'")) { //The user just subscribed, so let's set him up $now = post_notification_date2mysql(); $wpdb->query("UPDATE {$t_emails} SET gets_mail = 1, date_subscribed = '{$now}' WHERE email_addr = '{$addr}'"); $mailid = $wpdb->get_var("SELECT id FROM {$t_emails} WHERE email_addr = '{$addr}'"); $selected_cats = explode(',', get_option('post_notification_selected_cats')); $queryCats = ''; if (!empty($selected_cats)) { $queryCats = ""; foreach ($selected_cats as $category) { if (is_numeric($category)) { $queryCats .= ", ({$mailid}, {$category})"; } } if (strlen($queryCats) > 0) { $wpdb->query("INSERT INTO {$t_cats} (id, cat_id) VALUES" . substr($queryCats, 1)); } } if (isset($post_notification_strings['welcome'])) { $msg = '<h3>' . str_replace('@@blogname', get_option(blogname), $post_notification_strings['welcome']) . '</h3>'; } else { $msg = '<h3>' . $post_notification_strings['saved'] . '</h3>'; } } // ******************************************************** // // Select Cats // ******************************************************** // if ($action == "subscribe") { $wpdb->query("UPDATE {$t_emails} SET gets_mail = 1 WHERE email_addr = '{$addr}'"); $mid = $wpdb->get_var("SELECT id FROM {$t_emails} WHERE email_addr = '{$addr}'"); if (get_option('post_notification_show_cats') == 'yes') { //Delete all entries $wpdb->query("DELETE FROM {$t_cats} WHERE id = {$mid}"); if (!is_array($pn_cats)) { $pn_cats = array(); } //Just to make shure it doesn't crash //Let's see what cats we have $queryCats = ''; foreach ($pn_cats as $cat) { if (is_numeric($cat)) { $queryCats .= ", ({$mid}, {$cat})"; } //Security } if (strlen($queryCats) > 0) { $wpdb->query("INSERT INTO {$t_cats} (id, cat_id) VALUES" . substr($queryCats, 1)); } } $msg .= '<h3>' . $post_notification_strings['saved'] . '</h3>'; } // ******************************************************** // // UNSUBSCRIBE // ******************************************************** // if ($action == "unsubscribe" and is_email($addr)) { $mid = $wpdb->get_var("SELECT id FROM {$t_emails} WHERE email_addr = '{$addr}'"); if ($mid != '') { $wpdb->query("DELETE FROM {$t_emails} WHERE id = {$mid}"); $wpdb->query("DELETE FROM {$t_cats} WHERE id = {$mid}"); } $content['header'] = $post_notification_strings['deaktivated']; $msg = str_replace(array('@@addr', '@@blogname'), array($addr, $blogname), $post_notification_strings['no_longer_activated']); return $content; } // ********************************************************// // Subscribe-page // ********************************************************// $content['header'] = get_option('post_notification_page_name'); $id = $wpdb->get_var("SELECT id FROM {$t_emails} WHERE email_addr = '{$addr}'"); if (get_option('post_notification_show_cats') == 'yes') { $subcats_db = $wpdb->get_results("SELECT cat_id FROM {$t_cats} WHERE id = {$id}"); $subcats = array(); if (isset($subcats_db)) { foreach ($subcats_db as $subcat) { $subcats[] = $subcat->cat_id; } } // Get cats listing $cats_str = post_notification_get_catselect($post_notification_strings['all'], $subcats); } else { $cats_str = ''; } $vars = '<input type="hidden" name="code" value="' . $code . '" /><input type="hidden" name="addr" value="' . $addr . '" />'; if ($action == "subscribe" && get_option('post_notification_saved_tmpl') == 'yes') { $msg = post_notification_ldfile('saved.tmpl'); } else { $msg .= post_notification_ldfile('select.tmpl'); } $msg = str_replace('@@action', post_notification_get_link(), $msg); $msg = str_replace('@@addr', $addr, $msg); $msg = str_replace('@@cats', $cats_str, $msg); $msg = str_replace('@@vars', $vars, $msg); } else { // ******************************************************** // // WITHOUT AUTH // ******************************************************** // $code = ''; if (is_email($addr) && post_notification_check_captcha()) { // ******************************************************** // // SUBSCRIBE // ******************************************************** // if ($action == "subscribe" || $action == '') { $conf_url = post_notification_get_mailurl($addr); // Build mail $mailmsg = post_notification_ldfile('confirm.tmpl'); $mailmsg = str_replace('@@addr', $addr, $mailmsg); $mailmsg = str_replace('@@conf_url', $conf_url, $mailmsg); wp_mail($addr, "{$blogname} - " . get_option('post_notification_page_name'), $mailmsg, post_notification_header()); //Output Page $content['header'] = $post_notification_strings['registration_successful']; $msg = post_notification_ldfile('reg_success.tmpl'); return $content; //here it ends - We don't want to show the selection screen. } // ******************************************************** // // UNSUBSCRIBE // ******************************************************** // if ($action == "unsubscribe") { if ($wpdb->get_var("SELECT email_addr FROM {$t_emails} WHERE email_addr = '{$addr}'")) { //There is a mail in the db $conf_url = post_notification_get_mailurl($addr); $conf_url .= "action=unsubscribe"; $mailmsg = post_notification_ldfile('unsubscribe.tmpl'); $mailmsg = str_replace(array('@@addr', '@@conf_url'), array($addr, $conf_url), $mailmsg); wp_mail($addr, "{$blogname} - " . $post_notification_strings['deaktivated'], $mailmsg, post_notification_header()); } $content['header'] = $post_notification_strings['deaktivated']; $msg = str_replace(array('@@addr', '@@blogname'), array($addr, $blogname), $post_notification_strings['unsubscribe_mail']); return $content; //here it ends - We don't want to show the selection screen. } } if ($addr != '') { if (!is_email($addr)) { $msg .= '<p class="error">' . $post_notification_strings['check_email'] . '</p>'; } if (!post_notification_check_captcha() && action != '') { $msg .= '<p class="error">' . $post_notification_strings['wrong_captcha'] . '</p>'; } } //Try to get the email addr if ($addr == '') { $addr = post_notification_get_addr(); } $content['header'] = get_option('post_notification_page_name'); $msg .= post_notification_ldfile('subscribe.tmpl'); $msg = str_replace('@@action', post_notification_get_link($addr), $msg); $msg = str_replace('@@addr', $addr, $msg); $msg = str_replace('@@cats', '', $msg); $msg = str_replace('@@vars', $vars, $msg); //Do Captcha-Stuff if (get_option('post_notification_captcha') == 0) { $msg = preg_replace('/<!--capt-->(.*?)<!--cha-->/is', '', $msg); //remove captcha } else { require_once POST_NOTIFICATION_PATH . 'class.captcha.php'; $captcha_code = md5(round(rand(0, 40000))); $my_captcha = new captcha($captcha_code, POST_NOTIFICATION_PATH . '_temp'); $captchaimg = POST_NOTIFICATION_PATH_URL . '_temp/cap_' . $my_captcha->get_pic(get_option('post_notification_captcha')) . '.jpg'; $msg = str_replace('@@captchaimg', $captchaimg, $msg); $msg = str_replace('@@captchacode', $captcha_code, $msg); } } return $content; }