Example #1
0
 function widget_newsletter($args)
 {
     $options = get_option('newsletter');
     // $args is an array of strings that help widgets to conform to
     // the active theme: before_widget, before_title, after_widget,
     // and after_title are the array keys. Default tags: li and h2.
     extract($args);
     // Each widget can store its own options. We keep strings here.
     $optionsw = get_option('newsletter_widget');
     $title = $optionsw['title'];
     $text = $optionsw['text'];
     $form = $optionsw['form'];
     // These lines generate our output. Widgets can be very complex
     // but as you can see here, they can also be very, very simple.
     echo $before_widget . $before_title . $title . $after_title;
     if (newsletter_has_extras('1.0.2') && $form != '') {
         $buffer .= str_replace('{newsletter_url}', $options['url'], newsletter_extras_get_form($form));
     } else {
         if (isset($options['noname'])) {
             $buffer = str_replace('{newsletter_url}', $options['url'], newsletter_label('widget_form_noname'));
         } else {
             $buffer = str_replace('{newsletter_url}', $options['url'], newsletter_label('widget_form'));
         }
     }
     $buffer = str_replace('{text}', $optionsw['text'], $buffer);
     $buffer = str_replace('{count}', newsletter_subscribers_count(), $buffer);
     //if (defined('NEWSLETTER_EXTRAS')) echo $buffer;
     //else echo $buffer . '<div style="text-align:right;padding:0 10px;margin:0;"><a style="font-size:9px;color:#bbb;text-decoration:none" href="http://www.satollo.net">by satollo.net</a></div>';
     echo $buffer;
     echo $after_widget;
 }
Example #2
0
/**
 * Intercept the request parameters which drive the subscription and unsubscription
 * process.
 */
function newsletter_init()
{
    global $newsletter_step, $wpdb, $newsletter_subscriber;
    global $hyper_cache_stop;
    // "na" always is the action to be performed - stands for "newsletter action"
    $action = $_REQUEST['na'];
    if (!$action) {
        return;
    }
    $hyper_cache_stop = true;
    if (defined('NEWSLETTER_EXTRAS')) {
        newsletter_extra_init($action);
    }
    $options = get_option('newsletter');
    // Subscription request from a subscription form (in page or widget), can be
    // a direct subscription with no confirmation
    if ($action == 's') {
        if (!newsletter_is_email($_REQUEST['ne'])) {
            die(newsletter_label('error_email'));
        }
        // If not set, the subscription form is not requesting the name, so we do not
        // raise errors.
        if (isset($_REQUEST['nn'])) {
            if (trim($_REQUEST['nn']) == '') {
                die(newsletter_label('error_name'));
            }
        } else {
            $_REQUEST['nn'] = '';
        }
        $profile1 = $_REQUEST['np'];
        if (!isset($profile1) || !is_array($profile1)) {
            $profile1 = array();
        }
        // keys starting with "_" are removed because used internally
        $profile = array();
        foreach ($profile1 as $k => $v) {
            if ($k[0] == '_') {
                continue;
            }
            $profile[$k] = $v;
        }
        $profile['_ip'] = $_SERVER['REMOTE_ADDR'];
        $profile['_referrer'] = $_SERVER['HTTP_REFERER'];
        // Check if the group is good
        newsletter_subscribe($_REQUEST['ne'], $_REQUEST['nn'], $profile);
        if (isset($options['noconfirmation'])) {
            $newsletter_step = 'confirmed';
        } else {
            $newsletter_step = 'subscribed';
        }
        return;
    }
    // A request to confirm a subscription
    if ($action == 'c') {
        $id = $_REQUEST['ni'];
        newsletter_confirm($id, $_REQUEST['nt']);
        header('Location: ' . newsletter_add_qs($options['url'], 'na=cs&ni=' . $id . '&nt=' . $_REQUEST['nt'], false));
        die;
    }
    // Show the confirmed message after a redirection (to avoid mutiple email sending).
    // Redirect is sent by action "c".
    if ($action == 'cs') {
        $newsletter_subscriber = newsletter_get_subscriber($_REQUEST['ni']);
        if ($newsletter_subscriber->token != $_REQUEST['nt']) {
            die('Ivalid token');
        }
        $newsletter_step = 'confirmed';
    }
    // Unsubscription process has 2 options: if email and token are specified the user
    // will only be asked to confirm. If there is no infos of who remove (when
    // mass mail mode is used) the user will be asked to type the emailto be removed.
    if ($action == 'u') {
        $newsletter_step = 'unsubscription';
    }
    // User confirmed he want to unsubscribe clicking the link on unsubscription
    // page
    if ($action == 'uc') {
        newsletter_unsubscribe($_REQUEST['ni'], $_REQUEST['nt']);
        $newsletter_step = 'unsubscribed';
    }
}