Ejemplo n.º 1
0
            // load up the receipt template.
            $template = module_template::get_template_by_key('newsletter_unsubscribe');
            $data = $member;
            $data['email'] = htmlspecialchars($data['email']);
            // to be sure to be sure
            $template->page_title = htmlspecialchars(_l('Unsubscribe'));
            $template->assign_values($data);
            echo $template->render('pretty_html');
            exit;
        }
    }
} else {
    // show normal unsubscribe form. asking for their email address.
    if (isset($_REQUEST['email']) && trim($_REQUEST['email'])) {
        $email = htmlspecialchars(strtolower(trim($_REQUEST['email'])));
        if (!module_newsletter::unsubscribe_member_via_email($email)) {
            echo 'Unsubscribe failed... Please enter a valid email address.';
            exit;
        }
        // is the newsletter module giving us a subscription redirection?
        if (module_config::c('newsletter_unsubscribe_redirect', '')) {
            redirect_browser(module_config::c('newsletter_unsubscribe_redirect', ''));
        }
        // or display a message.
        $template = module_template::get_template_by_key('newsletter_unsubscribe_done');
        $data['email'] = $email;
        $template->page_title = htmlspecialchars(_l('Unsubscribe'));
        $template->assign_values($data);
        echo $template->render('pretty_html');
        exit;
    }
Ejemplo n.º 2
0
 public static function subscribe_member($email_address, $newsletter_member_id = false)
 {
     // we're subscribing this email address.
     // check they're not already subscribed.
     $already_subscribed = false;
     if ($newsletter_member_id) {
         $newsletter_member = get_single('newsletter_member', 'newsletter_member_id', $newsletter_member_id);
         if ($newsletter_member && $newsletter_member['join_date'] && $newsletter_member['join_date'] != '0000-00-00') {
             // they're already subscribed.
             $already_subscribed = true;
         }
     }
     // send double opt in?
     if (!$already_subscribed && module_config::c('newsletter_double_opt_in', 1)) {
         // add this new member to the blacklist, this will be removed when they confirm.
         module_newsletter::unsubscribe_member_via_email($email_address, 'doubleoptin');
         $template = module_template::get_template_by_key('member_subscription_double_optin');
         $template->assign_values(array('email' => $email_address, 'link' => self::double_optin_confirmation_link($email_address)));
         $html = $template->render('html');
         $email = module_email::new_email();
         $email->replace_values = array('email' => $email_address, 'link' => self::double_optin_confirmation_link($email_address));
         $email->set_to_manual($email_address);
         $email->set_from_manual(module_config::c('newsletter_default_from_email', module_config::c('admin_email_address')), module_config::c('newsletter_default_from_name', module_config::c('admin_system_name')));
         $email->set_subject(module_config::c('newsletter_double_opt_in_subject', 'Please confirm your newsletter subscription'));
         // do we send images inline?
         $email->set_html($html);
         if ($email->send()) {
             // it worked successfully!!
             return true;
         } else {
             return false;
         }
     } else {
         // remove them from a blacklist and remove any bounce counters that could prevent us sending them emails.
         module_newsletter::unsubscribe_member_via_email($email_address, 'new_subscribe', true);
         if ($newsletter_member_id) {
             $sql = "UPDATE `" . _DB_PREFIX . "newsletter_member` SET bounce_count = 0, receive_email = 1, unsubscribe_send_id = 0 WHERE newsletter_member_id = " . (int) $newsletter_member_id . " LIMIT 1";
             query($sql);
             if (!$already_subscribed) {
                 $sql = "UPDATE `" . _DB_PREFIX . "newsletter_member` SET join_date = NOW() WHERE newsletter_member_id = " . (int) $newsletter_member_id . " LIMIT 1";
                 query($sql);
             }
         }
         return true;
         // dont need to do anything.
     }
 }