function post_notification_admin_sub() { global $wpdb; $t_emails = $wpdb->prefix . 'post_notification_emails'; $t_cats = $wpdb->prefix . 'post_notification_cats'; if ($_GET['action'] == 'remove_email') { $remove = true; } else { $remove = false; } echo '<h3>' . __('List of addresses:', 'post_notification') . '</h3>'; if (isset($_POST['removeEmailChecked'])) { if ($_POST['removeEmail'] == "") { echo '<div class = "error">' . __('No address checked!', 'post_notification') . '</div>'; } else { echo __('The following addresses were deleted:', 'post_notification') . '<br /><br />'; foreach ($_POST['removeEmail'] as $removeAddress) { //Multiple table delete only works with mysql 4.0 or 4.1 $wpdb->query("DELETE {$t_cats}, {$t_emails} \r\n\t\t\t\t\tFROM {$t_emails} LEFT JOIN {$t_cats} USING (id) \r\n\t\t\t\t\tWHERE email_addr = '{$removeAddress}'"); echo "{$removeAddress}<br />"; } } } else { if (isset($_POST['email'])) { $email = $_POST['email']; } else { $email = '*'; } if (isset($_POST['cats'])) { $sel_cats = $_POST['cats']; } else { $sel_cats = ''; } if (!is_array($sel_cats)) { $sel_cats = array(); } if (isset($_POST['limit'])) { $limit = $_POST['limit']; } else { $limit = 50; } if (!is_numeric($limit)) { $limit = 50; } if ($limit < 1) { $limit = 1; } if (isset($_POST['start'])) { $start = $_POST['start']; } else { $start = ''; } if (!is_numeric($start)) { $start = 0; } if (isset($_POST['next'])) { $start += $limit; } if (isset($_POST['perv'])) { $start -= $limit; } if ($start < 0) { $start = 0; } if (isset($_POST['sortby'])) { $sortby = $_POST['sortby']; } else { $sortby = 'id'; } if (isset($_POST['sortorder'])) { $sortorder = $_POST['sortorder']; } else { $sortorder = 'ASC'; } $sortsrt = " {$sortby} {$sortorder} "; $show_id = isset($_POST['show_id']); $show_list = isset($_POST['show_list']); $show_unconf = isset($_POST['show_unconf']); echo '<form method="post" action="admin.php?page=post_notification/admin.php&action=' . $_GET['action'] . '"> '; echo __('Email:', 'post_notification') . ' <input name="email" type="text" size="30" value="' . $email . '"> '; echo __('Cats:', 'post_notification') . ' <select name="cats[]" multiple="multiple" style="height:auto"> '; $cats = get_categories(); $walker = new Walker_pn_CategoryDropdown(); echo call_user_func_array(array(&$walker, 'walk'), array($cats, 0, array('sel_cat' => $sel_cats))); echo '</select> '; echo __('Limit:', 'post_notification') . ' <input name="limit" type="text" size="4" value="' . $limit . '" /> '; echo __('Start at:', 'post_notification') . ' <input name="start" type="text" size="4" value="' . $start . '" /> '; echo __('Sort by:', 'post_notification') . ' <select name="sortby" size = "1" > ' . '<option value="id" ' . ($sortby == 'id' ? 'selected="selected"' : '') . '>' . __('ID', 'post_notification') . '</option>' . '<option value="email_addr" ' . ($sortby == 'email_addr' ? 'selected="selected"' : '') . '>' . __('Address', 'post_notification') . '</option>' . '<option value="date_subscribed" ' . ($sortby == 'date_subscribed' ? 'selected="selected"' : '') . '>' . __('Date accepted', 'post_notification') . '</option>' . '<option value="subscribe_ip" ' . ($sortby == 'subscribe_ip' ? 'selected="selected"' : '') . '>' . __('IP', 'post_notification') . '</option>' . '</select>'; echo ' <select name="sortorder" size = "1" > ' . '<option value="ASC" ' . ($sortorder == 'ASC' ? 'selected="selected"' : '') . '>' . __('Ascending', 'post_notification') . '</option>' . '<option value="DESC" ' . ($sortorder == 'DESC' ? 'selected="selected"' : '') . '>' . __('Descending', 'post_notification') . '</option>' . '</select>'; echo '<BR /> '; echo __('Show unconfirmed mails:', 'post_notification') . ' <input name="show_unconf" type="checkbox" '; if ($show_unconf) { echo ' checked = "checked" '; } echo '/><br /> '; echo __('Only show cat ids:', 'post_notification') . ' <input name="show_id" type="checkbox" '; if ($show_id) { echo ' checked = "checked" '; } echo '/><br/> '; echo __('Show as list:', 'post_notification') . ' <input name="show_list" type="checkbox" '; if ($show_list) { echo ' checked = "checked" '; } echo '/> '; ?> </select><br /> <input type="submit" name="submit" value="<?php _e('Update', 'post_notification'); ?> " /><input type="submit" name="perv" value="<<--" /><input type="submit" name="next" value="-->>" /> <form> <?php ///Ok, now let's do some work. if ($remove) { echo '<form method="post" action="admin.php?page=post_notification/admin.php&action=remove_email">'; } $email = str_replace('*', '%', $email); $sel_cats = implode(',', $sel_cats); $show_unconf ? $wadd = ' AND gets_mail IS NULL ' : ($wadd = ' AND gets_mail = 1 '); if ($sel_cats == '') { $emails = $wpdb->get_results("SELECT email_addr, gets_mail, last_modified, date_subscribed, id, act_code, subscribe_ip FROM {$t_emails} WHERE email_addr LIKE '{$email}' {$wadd} ORDER BY {$sortsrt} LIMIT {$start}, {$limit} "); $total = $wpdb->get_var("SELECT COUNT(*) FROM {$t_emails} WHERE email_addr LIKE '{$email}' {$wadd}"); } else { $emails = $wpdb->get_results("SELECT email_addr, gets_mail, last_modified, date_subscribed, e.id AS id, act_code, subscribe_ip FROM {$t_emails} e, {$t_cats} c WHERE email_addr LIKE '{$email}' {$wadd} AND e.id = c.id AND c.cat_id IN ({$sel_cats}) GROUP BY e.id ORDER BY {$sortsrt} LIMIT {$start}, {$limit} "); $total = $wpdb->get_var("SELECT COUNT(e.id) FROM {$t_emails} e, {$t_cats} c WHERE email_addr LIKE '{$email}' {$wadd} AND e.id = c.id AND c.cat_id IN ({$sel_cats})"); } if (!$emails) { echo '<p class="error">' . __('No entries found!', 'post_notification') . '</p>'; echo '</div>'; return; } echo '<p>'; echo str_replace(array('@@start', '@@end', '@@total'), array($start, $start + count($emails) - 1, $total), __('Showing entry @@start to @@end of @@total entries.', 'post_notification')); echo '</p>'; if (!$show_list) { echo '<table><tr>'; if ($remove) { echo '<td width="20"><b> </b></td>'; } echo '<td width="200"><b>' . __('Address', 'post_notification') . '</b></td> <td width="125"><b>' . __('Accepted', 'post_notification') . '</b></td> <td width="255"><b>' . __('Date accepted', 'post_notification') . '</b></td> <td><b>' . __('Subscribed categories', 'post_notification') . '</b></td> <td><b>' . __('IP', 'post_notification') . '</b></td> </tr>'; } else { echo '<br /><br />'; } foreach ($emails as $email) { $email_addr = $email->email_addr; $gets_mail = $email->gets_mail; $last_modified = $email->last_modified; $datestr = get_settings('date_format') . ' ' . get_settings('time_format'); $date_subscribed = post_notification_date_i18n_tz($datestr, post_notification_mysql2gmdate($email->date_subscribed)); $id = $email->id; $ip = long2ip($email->subscribe_ip); if ($gets_mail == "1") { $gets_mail = __('Yes', 'post_notification'); } else { $gets_mail = __('No', 'post_notification'); } $modlink = post_notification_get_mailurl($email->email_addr, $email->act_code); $subcats_db = $wpdb->get_results("SELECT cat_id FROM {$t_cats} WHERE id = " . $id . " ORDER BY cat_id ASC"); $catnames = ''; if (isset($subcats_db)) { foreach ($subcats_db as $subcat) { $cat = $subcat->cat_id; if ($cat == 0) { if ($show_id) { $catnames .= '<abbr title="' . __('All', 'post_notification') . '">0</abbr>, '; } else { $catnames .= __('All', 'post_notification') . ', '; } } else { $cat = get_category($cat); //ID -> Object if ($show_id) { $catnames .= '<abbr title="' . $cat->cat_name . '">' . $subcat->cat_id . '</abbr>, '; } else { $catnames .= $cat->cat_name . ', '; } } } $catnames = substr($catnames, 0, -2); } if (!$show_list) { echo "<tr>"; if ($remove) { echo "<td><input type=\"checkbox\" name=\"removeEmail[]\" value=\"{$email_addr}\" /></td>"; } echo "<td><a href=\"{$modlink}\" target=\"_blank\">{$email_addr}<a></td>"; echo "<td>{$gets_mail}</td>"; echo "<td>{$date_subscribed}</td>"; echo "<td>{$catnames}</td>"; echo "<td>{$ip}</td>"; echo "</tr>"; } else { echo $email_addr . '<br/>'; } } echo "</table>"; if ($remove) { ?> <script type="text/javascript"> function post_notification_checkall(value){ boxes = document.getElementsByName("removeEmail[]"); for(i = 0; i < boxes.length; i++){ boxes[i].checked = value; } } </script> <?php echo '<br />' . '<input type="button" onclick="post_notification_checkall(true)" value="' . __('Check all', 'post_notification') . '" />' . '<input type="button" onclick="post_notification_checkall(false)" value="' . __('Uncheck all', 'post_notification') . '" />' . '<br /> <input type="submit" name="removeEmailChecked" value="' . __('Delete', 'post_notification') . '"></form>'; } } }
function post_notification_sendmail($maildata, $addr, $code = '', $send = true) { $maildata['body'] = str_replace('@@addr', $email->email_addr, $maildata['body']); $conf_url = post_notification_get_mailurl($addr, $code); $maildata['body'] = str_replace('@@unsub', $conf_url, $maildata['body']); $maildata['body'] = str_replace('@@conf_url', $conf_url, $maildata['body']); //User replacements if (function_exists('post_notificataion_uf_perEmail')) { $maildata['body'] = post_notification_arrayreplace($maildata['body'], post_notificataion_uf_perEmail($maildata['id'], $addr)); } if ($send) { //for debugging $maildata['sent'] = wp_mail($addr, $maildata['subject'], $maildata['body'], $maildata['header']); } else { $maildata['sent'] = false; } return $maildata; }
/** * 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; }