function wpr_get_unsubscription_url($sid) { $baseURL = get_bloginfo("home"); $subscriber = _wpr_subscriber_get($sid); $newsletter = _wpr_newsletter_get($subscriber->nid); $nid = $newsletter->id; $string = $sid . "%\$%" . $nid . "%\$%" . $subscriber->hash; $codedString = base64_encode($string); $unsubscriptionUrl = $baseURL . "/?wpr-manage={$codedString}"; return $unsubscriptionUrl; }
$hash = addslashes($hash); } $subscribers_table = $wpdb->prefix . "wpr_subscribers"; $query = $wpdb->prepare("SELECT * FROM {$subscribers_table} WHERE id=%d AND hash='%s' AND active=1 AND confirmed=0", $id, $hash); $subs = $wpdb->get_results($query); if (count($subs) == 0) { ?> <div align="center"><h2>Your subscription does not exist or you are already subscribed. </h2></div> <?php exit; } $subs = $subs[0]; $query = $wpdb->prepare("UPDATE {$subscribers_table} set confirmed=1, active=1 where id=%d and hash='%s';", $id, $hash); $wpdb->query($query); $redirectionUrl = home_url("/?wpr-confirm=2"); $subscriber = _wpr_subscriber_get($id); _wpr_move_subscriber($subscriber->nid, $subscriber->email); //This subscriber's follow up subscriptions' time of creation should be updated to the time of confirmation. $currentTime = time(); $followup_subscriptions_table = $wpdb->prefix . "wpr_followup_subscriptions"; $query = $wpdb->prepare("UPDATE {$followup_subscriptions_table} SET doc='%s', last_date='%s' WHERE sid=%d;", $currentTime, $currentTime, $id); $wpdb->query($query); do_action("_wpr_subscriber_confirmed", $id); sendConfirmedEmail($id); ?> <script> window.location='<?php echo $redirectionUrl; ?> '; </script>
function _wpr_subscriber_profile($subscriber) { global $wpdb; $sid = $subscriber->id; if (isset($_POST['followupunsub'])) { $aid = (int) $_POST['aid']; $query = "DELETE FROM " . $wpdb->prefix . "wpr_followup_subscriptions where id={$aid}"; $wpdb->query($query); ?> <script>window.location='admin.php?page=wpresponder/subscribers.php&action=profile&sid=<?php echo $subscriber->id; ?> ';</script> <?php exit; } if (isset($_POST['customfielddata'])) { //Asume that all the custom fields are in the post data. $nid = $_POST['custom_field_newsletter']; $query = "SELECT * FROM " . $wpdb->prefix . "wpr_custom_fields where nid = {$nid};"; $results = $wpdb->get_results($query); $theSubscriberId = $_POST['custom_field_sid']; $formData = array(); foreach ($_POST as $name => $value) { $formData[trim($name)] = trim($value); } foreach ($results as $cfield) { $fieldName = trim('newsletter-' . $nid . '-cfield-' . $cfield->id); $value = $_POST[$fieldName]; $cid = $cfield->id; $query = "DELETE FROM " . $wpdb->prefix . "wpr_custom_fields_values where sid = {$theSubscriberId} and cid={$cid};"; $wpdb->query($query); if (empty($value)) { continue; } $query = "INSERT INTO " . $wpdb->prefix . "wpr_custom_fields_values (nid,sid,cid,value) VALUES ('{$nid}','{$theSubscriberId}','{$cid}','{$value}')"; $wpdb->query($query); $wpdb->print_error(); } ?> <script> window.location='admin.php?page=wpresponder/subscribers.php&action=profile&sid=<?php echo $sid; ?> '; </script> <?php exit; } if (isset($_POST['unsubscription_form'])) { $sid = $_POST['sid']; $query = "UPDATE " . $wpdb->prefix . "wpr_subscribers set active=0 where id={$sid}"; $wpdb->query($query); $query = "DELETE FROM " . $wpdb->prefix . "wpr_followup_subscriptions where sid={$sid}"; $wpdb->query($query); $query = "DELETE FROM " . $wpdb->prefix . "wpr_custom_fields_values where sid={$sid}"; $wpdb->query($query); } if (isset($_POST['subs_action'])) { switch ($_POST['subs_action']) { case 'delete': $sid = $_POST['sid']; $subscriber = _wpr_subscriber_get($sid); $theEmail = $subscriber->email; $query = "SELECT id from " . $wpdb->prefix . "wpr_subscribers where email='{$theEmail}';"; $subscriptions = $wpdb->get_results($query); foreach ($subscriptions as $theSubscription) { $currentSid = $theSubscription->id; $deleteBlogSubscriptions = "DELETE FROM " . $wpdb->prefix . "wpr_blog_subscription where sid={$currentSid}"; $wpdb->query($deleteBlogSubscriptions); $deleteFollowupSubscriptions = "DELETE FROM " . $wpdb->prefix . "wpr_followup_subscriptions where sid={$currentSid}"; $wpdb->query($deleteFollowupSubscriptions); $deleteCustomFieldValues = "DELETE FROM " . $wpdb->prefix . "wpr_custom_field_values where sid={$currentSid}"; $wpdb->query($deleteCustomFieldValues); $deleteSubscriber = "DELETE FROM " . $wpdb->prefix . "wpr_subscribers where id={$currentSid}"; $wpdb->query($deleteSubscriber); } ?> <script> window.location='admin.php?page=wpresponder/subscribers.php';</script><?php return; break; case 'unsubscribe': $newsletters = $_POST['newsletters']; foreach ($newsletters as $newsletter) { $query = "update " . $wpdb->prefix . "wpr_subscribers set active=0 where nid=" . $newsletter . " and email='" . $subscriber->email . "'"; $wpdb->query($query); } ?> <script>window.history.go(-2);</script> <?php return; break; } } ?> <div class="wrap"><h2>Profile</h2></div> <table> <tr> <td width="300">Name: </td> <td><?php $query = "select DISTINCT name from " . $wpdb->prefix . "wpr_subscribers where email='" . $subscriber->email . "' order by active desc"; $results = $wpdb->get_results($query); $names = array(); foreach ($results as $name) { array_push($names, $name->name); } $theName = implode(", ", $names); echo $theName; ?> </td> </tr> <tr> <td>E-Mail Address: </td> <td><?php echo $subscriber->email; ?> </td> </tr> </table> <p></p> <form action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input type="hidden" name="subs_action" value="delete" /> <input type="hidden" name="sid" value="<?php echo $subscriber->id; ?> " /> <input type="submit" onclick="return window.confirm('Are you sure you want to delete this subscriber?'); " value="Delete This Subscriber" class="button-primary" /> </form> <div style="clear:both"></div> <h3>Current Newsletter Subscriptions:</h3> <?php $query = "select distinct a.id id, a.name name from " . $wpdb->prefix . "wpr_newsletters a, " . $wpdb->prefix . "wpr_subscribers b where a.id=b.nid and b.email='" . $subscriber->email . "' and b.active in(1,2)"; $subscribedNewsletters = $wpdb->get_results($query); foreach ($subscribedNewsletters as $newsletter) { $nid = $newsletter->id; $email = $subscriber->email; $query = "SELECT * FROM " . $wpdb->prefix . "wpr_subscribers where nid='" . $newsletter->id . "' and email='" . $subscriber->email . "';"; $results = $wpdb->get_results($query); $theSubscriberObject = $results[0]; $sid = $theSubscriberObject->id; ?> <fieldset style="border: 1px solid #000; width:1000px; padding: 15px; margin-bottom: 10px;"><legend><span style="font-family: Arial;font-size: 15px; margin: 10px; font-weight:bold"><?php echo $newsletter->name; ?> </span></legend> <table width="300" style="margin: 10px;"> <tr> <td>Name: </td> <td><?php echo $theSubscriberObject->name; ?> </td> </tr> <tr> <td>Subscribed on:</td> <td><?php echo date("g:ia d F Y", $theSubscriberObject->date); ?> </td> </tr> </table><br /> <?php $query = "SELECT * FROM " . $wpdb->prefix . "wpr_followup_subscriptions where sid={$sid} and type='autoresponder';"; $autoresponderSubscriptions = $wpdb->get_results($query); ?> <?php if (count($autoresponderSubscriptions)) { ?> <h3>Follow-up Autoresponders Subscriptions</h3> <table class="widefat"> <tr> <th>Name Of Autoresponder</th> <th width="150">Currently Receiving?</th> <th>Progress in Autoresponder</th> <th>Date Of Subscription</th> <th>Stop</th> </tr> <?php foreach ($autoresponderSubscriptions as $followup) { ?> <tr id="autores-<?php echo $followup->eid; ?> -row"> <td><?php $query = "SELECT * FROM " . $wpdb->prefix . "wpr_autoresponders where id=" . $followup->eid . ";"; $theAutoresponder = $wpdb->get_results($query); echo $theAutoresponder[0]->name; ?> </td> <td> <?php if (isAutoresponderSeriesActive($followup->eid)) { echo "Receiving Follow-up Message."; } else { echo "Has Received All Messages."; } ?> </td> <td>Has Received <?php echo $followup->sequence + 1; ?> Messages.</td> <td> <?php echo date("g:ia d F Y", $followup->doc); ?> </td> <td> <?php if (isAutoresponderSeriesActive($followup->eid)) { ?> <form action="admin.php?page=wpresponder/subscribers.php&action=profile&sid=<?php echo $sid; ?> &aresid=<?php echo $followup->eid; ?> &subaction=delete" method="post"> <input type="hidden" name="aid" value="<?php echo $followup->id; ?> " /> <input type="submit" class="button-primary" name="followupunsub" value="Stop" onclick="return confirm('Are you sure you want to stop this autoresponder sequence for this subscriber?');" /> </form> <?php } else { ?> <center>Finished</center> <?php } ?> </td> </tr> <?php } ?> </table> <?php } ?> <h3>Custom Field Values</h3> <?php //fetch the custom fields of this newsletter $query = "SELECT * FROM " . $wpdb->prefix . "wpr_custom_fields where nid={$nid}"; $customFieldList = $wpdb->get_results($query); if (count($customFieldList)) { ?> <form name="newsletter-<?php echo $nid; ?> -customfields" method="post"> <input type="hidden" name="customfielddata" value="1" /> <input type="hidden" name="custom_field_sid" value="<?php echo $theSubscriberObject->id; ?> "> <input type="hidden" name="custom_field_newsletter" value="<?php echo $nid; ?> " /> <table width="800"> <?php foreach ($customFieldList as $formfield) { $cid = $formfield->id; ?> <tr> <td><?php echo $formfield->label; ?> </td> <td><?php $query = "SELECT value from " . $wpdb->prefix . "wpr_custom_fields_values where sid={$sid} and cid={$cid}"; $valueSet = $wpdb->get_results($query); $value = $valueSet[0]->value; if ($formfield->type != "hidden") { echo getCustomField($formfield->id, "newsletter-{$nid}-cfield-" . $formfield->id, $value); } else { ?> <input type="text" name="<?php echo "newsletter-{$nid}-cfield-" . $formfield->id; ?> " value="<?php echo $value; ?> " />(hidden type)<?php } ?> </td> </tr> <?php } ?> </table> <input type="submit" class="button" value="Save Custom Field Information" style="display:block" /><br /> </form> <?php } else { ?> No custom fields defined for this newsletter. <?php } ?> <br /> <?php if ($theSubscriberObject->active == 1) { ?> <strong>Subscription Status: </strong> Subscribed<p></p> <form action="admin.php?page=wpresponder/subscribers.php&action=profile&sid=<?php echo $sid; ?> " method="post"> <input type="hidden" name="sid" value="<?php echo $sid; ?> " /> <input type="hidden" name="unsubscription_form" value="1" /> <input type="submit" name="submit" onclick="return window.confirm('Are you sure you want to unsusbcribe this reader from this newsletter?');" value="Unsubscribe from this newsletter" class="button-primary" /> </form> <?php } else { if ($theSubscriberObject->active == 2) { ?> <strong>Subscription Status:</strong> Transfered. The subscriber's subscription to this newsletter was deactivated in accordance with a <a href="admin.php?page=wpresponder/actions.php">transfer rule</a>. <?php } else { ?> User has Unsubscribed<?php } } ?> </fieldset> <?php } ?> </form><br /> <a href="admin.php?page=wpresponder/subscribers.php" class="button">« Back</a> <?php }
function _wpr_postseries_process() { global $wpdb; $last_cron_status = get_option("_wpr_postseries_process_status"); $currentTime = time(); set_time_limit(3600); /* When the cron is running the _wpr_postseries_process_status is set to the timestamp at which the cron processing was started. Before shutting down the _wpr_postseries_process_status is set to 'stopped'. This cron will run only if the _wpr_postseries_process_status option is set to "stopped" or is empty. */ $timeOfStart = time(); $timeMaximumExecutionTimeAgo = $timeOfStart - WPR_MAX_POSTSERIES_PROCESS_EXECUTION_TIME; if (!empty($last_cron_status) && $last_cron_status != "stopped") { $last_cron_status = intval($last_cron_status); if ($last_cron_status != 0 && $last_cron_status > $timeMaximumExecutionTimeAgo) { return; } } update_option("_wpr_postseries_process_status", $timeOfStart); $prefix = $wpdb->prefix; $getActiveFollowupSubscriptionsQuery = "SELECT a.*, b.id sid, FLOOR(({$currentTime} - a.doc)/86400) daysSinceSubscribing FROM `" . $prefix . "wpr_followup_subscriptions` a, `" . $prefix . "wpr_subscribers` b WHERE a.type='postseries' AND a.sequence < FLOOR(({$currentTime} - a.doc)/86400) AND a.sequence <> -2 AND a.sid=b.id AND b.active=1 AND b.confirmed=1 LIMIT 1000;"; $postseriesSubscriptionList = $wpdb->get_results($getActiveFollowupSubscriptionsQuery); foreach ($postseriesSubscriptionList as $psubscription) { $sid = $psubscription->sid; $query = "SELECT nid from " . $wpdb->prefix . "wpr_subscribers where id=" . $sid; $results = $wpdb->get_results($query); if (count($results) != 1) { //where's the newsletter?!! continue; } $nid = $results[0]->nid; $subscriber = _wpr_subscriber_get($psubscription->sid); //how many days since subscribing? $daysSinceSubscribing = floor((time() - $psubscription->doc) / 86400); //get the post series as an object $postseries = _wpr_postseries_get($psubscription->eid); //get the posts in the post series $posts = get_postseries_posts($postseries->catid, $nid); $numberOfPosts = count($posts); if ($numberOfPosts == 0) { _wpr_expire_followup($psubscription->id); continue; } $timeBetweenPosts = $postseries->frequency; $last_post = $psubscription->sequence; $currentIndex = floor($daysSinceSubscribing / $timeBetweenPosts); if ($currentIndex == $last_post) { continue; } //all posts have been sent. expire the post series subscription if ($last_post >= count($posts) - 1) { _wpr_expire_followup($psubscription->id); continue; } $indexToDeliver = $last_post + 1; $category = $psubscription->eid; $postToSend = $posts[$indexToDeliver]; $sitename = get_bloginfo("name"); $meta_key = sprintf("PS-%s-%s-%s", $psubscription->eid, $psubscription->sid, $postToSend->ID); $additionalParams = array('meta_key' => $meta_key); deliverBlogPost($sid, $postToSend->ID, "You are receiving this blog post as a part of a post series at {$name}.", true, true, $additionalParams); $query = "UPDATE " . $prefix . "wpr_followup_subscriptions set sequence={$indexToDeliver} , last_date='" . time() . "' where id='" . $psubscription->id . "';"; $wpdb->query($query); $timeThisInstant = time(); $timeSinceStart = $timeThisInstant - $timeOfStart; if ($timeSinceStart > WPR_MAX_POSTSERIES_PROCESS_EXECUTION_TIME) { return; } } update_option("_wpr_postseries_process_status", "stopped"); }
function confirm_unsubscription($nid, $sid, $hash) { global $wpdb; $query = "SELECT * FROM " . $wpdb->prefix . "wpr_subscribers where id='{$sid}' and hash='{$hash}' and active=1 and confirmed=1;"; $subscriber = $wpdb->get_results($query); if (count($subscriber) > 0) { $newsletter = _wpr_newsletter_get($nid); $subscriber = _wpr_subscriber_get($sid); $query = "SELECT b.* FROM `" . $wpdb->prefix . "wpr_subscribers` `a`, `" . $wpdb->prefix . "wpr_newsletters` `b` WHERE `b`.`id`=`a`.`nid` and `a`.`email`='" . $subscriber->email . "' and `a`.`active`=1 and `a`.`confirmed`=1;"; $newsletters = $wpdb->get_results($query); ?> <div style="font-family:Verdana, Geneva, sans-serif; font-size:12px; padding:20px; margin-left: auto; margin-right: auto; width:300px; background-color:#f0f0f0; border: 1px solid #c0c0c0;"><form action="<?php print $_SERVER['REQUEST_URI']; ?> " method="post"> <input type="hidden" name="confirmed" value="true"> You are about to unsubscribe from:<br><br /> <input type="hidden" name="email" value="<?php echo $subscriber->email; ?> " /> <?php foreach ($newsletters as $newsletter) { ?> <div class="newsletter"><input type="checkbox" name="newsletter[]" checked="checked" value="<?php echo $newsletter->id; ?> " id="nl_<?php echo $newsletter->id; ?> " /> <label for="nl_<?php echo $newsletter->id; ?> "><?php echo $newsletter->name; ?> Newsletter<br /> <blockquote> <?php //get blog subscriptions $query = sprintf("SELECT * FROM {$wpdb->prefix}wpr_blog_subscription WHERE `type`='cat' AND `sid`=%d", $sid); $bsubs = $wpdb->get_results($query); foreach ($bsubs as $sub) { $cat = get_category($sub->eid); ?> You will stop receiving posts from the <?php echo $cat->name; ?> category.<br /> <?php } $query = "select * from " . $wpdb->prefix . "wpr_blog_subscription where type='all' AND sid='{$sid}'"; $bsubs = $wpdb->get_results($query); if (count($bsubs) > 0) { ?> New articles posted on the blog will not be delivered.<br /> <?php } //get post series $query = "SELECT b.* FROM " . $wpdb->prefix . "wpr_followup_subscriptions a, wpr_post_series b where type='postseries' and sid='{$sid}' and b.id=a.eid;"; $pssubs = $wpdb->get_results($query); if (count($pssubs) > 0) { } foreach ($pssubs as $sub) { "You will stop receiving " . $sub->name . " post series<br>"; } ?> </blockquote> </label><br> <?php } ?> Are you sure you want to unsubscribe from the above newsletter(s)? <br /> <br /> <div align="center"> <input type="submit" value="Unsubscribe"> <input type="button" onclick="window.location='/'" value="Cancel"></div> </form></div> <?php } else { header("HTTP/1.0 404 Not Found"); exit; } }