예제 #1
0
function sendConfirmedEmail($id)
{
    global $wpdb;
    $query = "select * from " . $wpdb->prefix . "wpr_subscribers where id={$id}";
    $sub = $wpdb->get_results($query);
    $sub = $sub[0];
    //get the confirmation email and subject from newsletter
    $newsletter = _wpr_newsletter_get($sub->nid);
    $confirmed_subject = $newsletter->confirmed_subject;
    $confirmed_body = $newsletter->confirmed_body;
    //if a registered form was used to subscribe, then override the newsletter's confirmed email.
    $sid = $sub->id;
    //the susbcriber id
    $unsubscriptionURL = wpr_get_unsubscription_url($sid);
    $unsubscriptionInformation = "\n\nTo manage your email subscriptions or to unsubscribe click on the URL below:\n{$unsubscriptionURL}\n\nIf the above URL is not a clickable link simply copy it and paste it in your web browser.";
    $fid = $args[2];
    $query = "SELECT a.* from " . $wpdb->prefix . "wpr_subscription_form a, " . $wpdb->prefix . "wpr_subscribers b  where a.id=b.fid and b.id={$sid};";
    $form = $wpdb->get_results($query);
    if (count($form)) {
        $confirmed_subject = $form[0]->confirmed_subject;
        $confirmed_body = $form[0]->confirmed_body;
    }
    $confirmed_body .= $unsubscriptionInformation;
    $params = array($confirmed_subject, $confirmed_body);
    wpr_place_tags($sub->id, $params);
    $fromname = $newsletter->fromname;
    if (!$fromname) {
        $fromname = get_bloginfo('name');
    }
    $fromemail = $newsletter->fromemail;
    if (!$fromemail) {
        $fromemail = get_bloginfo('admin_email');
    }
    $email = $sub->email;
    $emailBody = $params[1];
    $emailSubject = $params[0];
    $mailToSend = array('to' => $email, 'fromname' => $fromname, 'from' => $fromemail, 'textbody' => $emailBody, 'subject' => $emailSubject);
    try {
        dispatchEmail($mailToSend);
    } catch (Swift_RfcComplianceException $exception) {
        //disable all subscribers with that email.
        $email = $mailToSend['to'];
        $query = "UPDATE " . $wpdb->prefix . "wpr_subscribers set active=3, confirmed=0 where email='{$email}'";
        $wpdb->query($query);
    }
}
예제 #2
0
function deliverBlogPost($sid, $post_id, $footerMessage = "", $checkCondition = false, $whetherPostSeries = false, $additionalParams = array())
{
    global $wpdb;
    //get the post meta
    $sid = (int) $sid;
    $post_id = (int) $post_id;
    if ($sid == 0 || $post_id == 0) {
        // neither of these can be zero or empty.
        return;
    }
    $post = get_post($post_id);
    //if plugin was activated after some posts were created
    //the options array will not exist. in that case, we just
    //deliver the blog post
    $optionsList = get_post_meta($post_id, "wpr-options", true);
    if (!empty($optionsList)) {
        $decoded = base64_decode($optionsList);
        $options = unserialize($decoded);
        $checkCondition = true;
        //if we have a valid options array, then we should
        //check the conditions of delivery.
    } else {
        $checkCondition = false;
    }
    $query = "SELECT nid from " . $wpdb->prefix . "wpr_subscribers where id=" . $sid;
    $results = $wpdb->get_results($query);
    $nid = $results[0]->nid;
    if (count($results) == 0) {
        //if there is no subscriber by that sid
        return;
    }
    $deliverFlag = true;
    // this flag is used to trigger the delivery
    if ($checkCondition == true) {
        //get the subscriber's newsletter id
        if (isset($options[$nid])) {
            if ($options[$nid]['disable'] == 1) {
                $deliverFlag = false;
            }
        } else {
            $deliverFlag = true;
        }
    } else {
        $deliverFlag = true;
    }
    if (isset($additionalParams['meta_key'])) {
        $meta_key = $additionalParams['meta_key'];
    } else {
        $meta_key = sprintf("BP-%s-%s", $sid, $post_id);
    }
    //deliver the email.
    if ($deliverFlag) {
        //are customizations disabled? then get the html body for the blog post
        //from the default layout format.
        //check if the subscriber is currently receiving any follow up series emails
        if (isset($options) && $options[$nid]['skipactivesubscribers'] == 1 && isReceivingFollowupPosts($sid)) {
            return;
        }
        /*
         * The conditions where the default layout is used are:
         * the customization has been disabled,
         * the customization has been disabled for post series
         * there is no customization information - the post was created when
         * wp responder was not installed/deactivated.
         */
        if (!isset($options[$nid]) || $options[$nid]['nocustomization'] == 1 || !isValidOptionsArray($options) || $whetherPostSeries == true && $options[$nid]['nopostseries'] == 1) {
            $htmlbody = getBlogContentInDefaultLayout($post_id);
            $post = get_post($post_id);
            $subject = $post->post_title;
            $params = array("subject" => $subject, "htmlbody" => $htmlbody, "textbody" => "", "htmlenabled" => 1, "attachimages" => true, 'meta_key' => $meta_key);
        } else {
            $htmlBody = $options[$nid]['htmlbody'] . nl2br($footerMessage);
            $htmlEnabled = $options[$nid]['htmlenable'] == 1 ? 1 : 0;
            if (!$htmlEnabled) {
                $htmlBody = "";
            }
            $params = array("subject" => $options[$nid]['subject'], "htmlbody" => $htmlBody, "textbody" => $options[$nid]['textbody'] . strip_tags("{$footerMessage}"), "attachimages" => $options[$nid]['attachimages'] ? 1 : 0, "htmlenabled" => $htmlEnabled, 'meta_key' => $meta_key);
        }
        $params['subject'] = substitutePostRelatedShortcodes($params['subject'], $post_id);
        $params['htmlbody'] = substitutePostRelatedShortcodes($params['htmlbody'], $post_id);
        $params['textbody'] = substitutePostRelatedShortcodes($params['textbody'], $post_id);
        //substitute newsletter related parameters.
        wpr_place_tags($sid, $params);
        sendmail($sid, $params);
        $insertDeliveryRecordQuery = sprintf("INSERT INTO `%swpr_delivery_record` (sid, type, eid, timestamp)\n                                            VALUES\n                                            (%d,'blog_post',%d,'%s')\n                                            ", $wpdb->prefix, $sid, $post_id, time());
        $wpdb->query($insertDeliveryRecordQuery);
    }
}
예제 #3
0
 $confirm_body = str_replace("[!date!]", $date, $confirm_body);
 $confirm_subject = str_replace("[!url!]", $url, $confirm_subject);
 $confirm_body = str_replace("[!url!]", $url, $confirm_body);
 $confirm_subject = str_replace("[!newslettername!]", $newslettername, $confirm_subject);
 $confirm_body = str_replace("[!newslettername!]", $newslettername, $confirm_body);
 $confirm_subject = str_replace("[!address!]", $address, $confirm_subject);
 $confirm_body = str_replace("[!address!]", $address, $confirm_body);
 $confirm_body = str_replace("[!confirm!]", $confirm, $confirm_body);
 $additional_parameters = array("ipaddress" => $_SERVER['REMOTE_ADDR'], "date" => date("g:i d F Y", time()), "url" => $_SERVER['HTTP_REFERER']);
 $params = array();
 date_default_timezone_set($zone);
 $params[0] = $confirm_subject;
 $params[1] = $confirm_body;
 wpr_create_temporary_tables($nid);
 wpr_make_subscriber_temptable($nid);
 wpr_place_tags($id, $params, $additional_parameters);
 $from_email = $newsletter->fromemail;
 if (!$from_email) {
     $from_email = get_bloginfo("admin_email");
 }
 $from_name = $newsletter->fromname;
 if (!$from_name) {
     $from_name = get_bloginfo("name");
 }
 $subject = $params[0];
 $body = $params[1];
 $verificationEmail = array('to' => $email, 'subject' => $subject, 'textbody' => $body, 'fromname' => $from_name, 'from' => $from_email);
 @dispatchEmail($verificationEmail);
 if (empty($return_url)) {
     if (isset($theForm)) {
         $return_url = $theForm->return_url;
예제 #4
0
function _wpr_process_broadcasts()
{
    global $wpdb;
    $prefix = $wpdb->prefix;
    $last_cron_status = get_option("_wpr_newsletter_process_status");
    set_time_limit(3600);
    /*
    
    
    When the cron is running the _wpr_newsletter_process_status
    is set to the timestamp at which the cron processing was started.
    
    Before shutting down the _wpr_newsletter_process_status is
    set to 'stopped'.
    
    This cron will run only if the _wpr_newsletter_process_status option
    is set to "stopped" or is empty.
    */
    $timeOfStart = time();
    $timeMaximumExecutionTimeAgo = $timeOfStart - WPR_MAX_NEWSLETTER_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;
        }
    }
    delete_option("_wpr_newsletter_process_status");
    add_option("_wpr_newsletter_process_status", $timeOfStart);
    $email_mailouts = wpr_get_mailouts();
    foreach ($email_mailouts as $broadcast) {
        $nid = $broadcast->nid;
        $subject = $broadcast->subject;
        $body = $broadcast->body;
        wpr_create_temporary_tables($nid);
        //this creates the tables based on which a bigger table will be created
        wpr_make_subscriber_temptable($nid);
        //this table will be used for getting the user list.
        $customFieldsConditions = trim(wpr_filter_query($nid, $broadcast->recipients));
        $customFields = $customFieldsConditions ? " AND " . $customFieldsConditions : "";
        $query = "SELECT * FROM " . $prefix . "wpr_subscribers_" . $nid . " where active=1 and confirmed=1 {$customFields};";
        $subscribersList = $wpdb->get_results($query);
        $subject = $broadcast->subject;
        $text_body = $broadcast->textbody;
        $html_body = $broadcast->htmlbody;
        $whetherToAttachImages = $broadcast->attachimages;
        $query = "SELECT fromname, fromemail from " . $wpdb->prefix . "wpr_newsletters where id=" . $nid;
        $results = $wpdb->get_results($query);
        $fromname = $results[0]->fromname;
        $fromemail = $results[0]->fromemail;
        if (count($subscribersList)) {
            $broadcastId = $broadcast->id;
            $newsletterId = $broadcast->nid;
            foreach ($subscribersList as $subscriber) {
                $sid = $subscriber->id;
                $email = $subscriber->email;
                $meta_key = sprintf("BR-%s-%s-%s", $sid, $broadcastId, $newsletterId);
                $emailParameters = array("subject" => $subject, "from" => $fromname, "fromemail" => $fromemail, "textbody" => $text_body, "htmlbody" => $html_body, "htmlenabled" => empty($html_body) ? 0 : 1, "attachimages" => $whetherToAttachImages, "meta_key" => $meta_key);
                wpr_place_tags($sid, $emailParameters);
                $emailParameters["to"] = $subscriber->email;
                sendmail($sid, $emailParameters);
            }
        }
        $timeThisInstant = time();
        $timeSinceStart = $timeThisInstant - $timeOfStart;
        if ($timeSinceStart > WPR_MAX_NEWSLETTER_PROCESS_EXECUTION_TIME) {
            return;
        }
        mailout_expire($broadcast->id);
    }
    delete_option("_wpr_newsletter_process_status");
    add_option("_wpr_newsletter_process_status", "stopped");
}