function confirmnewsletterunsubscribe($lang, $arglist)
{
    head('title', translate('newsletter:title', $lang));
    head('description', false);
    head('keywords', false);
    head('robots', 'noindex, nofollow');
    $banner = build('banner', $lang);
    list($timestamp, $mail) = $arglist;
    $bad_mail = false;
    $bad_time = false;
    if (!newsletter_get_user($mail)) {
        $bad_mail = true;
    }
    if (time() - $timestamp > 3600) {
        $bad_time = true;
    }
    $subscribe_page = $unsubscribe_page = false;
    $internal_error = false;
    $contact_page = false;
    if ($bad_mail or $bad_time) {
        $unsubscribe_page = url('newsletterunsubscribe', $lang);
    } else {
        $r = newsletter_delete_user($mail);
        if (!$r) {
            $internal_error = true;
        } else {
            require_once 'serveripaddress.php';
            require_once 'emailme.php';
            global $sitename;
            $ip = server_ip_address();
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
            $subject = 'unsubscribe' . '@' . $sitename;
            $msg = $ip . ' ' . $timestamp . ' ' . $lang . ' ' . $mail;
            @emailme($subject, $msg);
            $subscribe_page = url('newslettersubscribe', $lang);
        }
    }
    if ($internal_error) {
        $contact_page = url('contact', $lang);
    }
    $errors = compact('bad_mail', 'bad_time', 'internal_error', 'contact_page');
    $content = view('confirmnewsletterunsubscribe', $lang, compact('mail', 'subscribe_page', 'unsubscribe_page', 'errors'));
    $output = layout('standard', compact('banner', 'content'));
    return $output;
}
示例#2
0
function unsubscribe($lang)
{
    $with_captcha = true;
    $action = 'init';
    if (isset($_POST['unsubscribe_send'])) {
        $action = 'unsubscribe';
    }
    $confirmed = $code = $token = false;
    $user_mail = user_profile('mail');
    $subscribe_page = false;
    switch ($action) {
        case 'init':
            $subscribe_page = url('newslettersubscribe', $lang);
            break;
        case 'unsubscribe':
            if (isset($_POST['unsubscribe_mail'])) {
                $user_mail = strtolower(strflat(readarg($_POST['unsubscribe_mail'])));
            }
            if (isset($_POST['unsubscribe_confirmed'])) {
                $confirmed = readarg($_POST['unsubscribe_confirmed']) == 'on' ? true : false;
            }
            if (isset($_POST['unsubscribe_code'])) {
                $code = readarg($_POST['unsubscribe_code']);
            }
            if (isset($_POST['unsubscribe_token'])) {
                $token = readarg($_POST['unsubscribe_token']);
            }
            break;
        default:
            break;
    }
    $missing_code = false;
    $bad_code = false;
    $bad_token = false;
    $missing_mail = false;
    $bad_mail = false;
    $unknown_mail = false;
    $missing_confirmation = false;
    $mail_unsubscribed = false;
    $internal_error = false;
    $contact_page = false;
    switch ($action) {
        case 'unsubscribe':
            if (!isset($_SESSION['unsubscribe_token']) or $token != $_SESSION['unsubscribe_token']) {
                $bad_token = true;
            }
            if ($with_captcha) {
                if (!$code) {
                    $missing_code = true;
                    break;
                }
                $captcha = isset($_SESSION['captcha']['unsubscribe']) ? $_SESSION['captcha']['unsubscribe'] : false;
                if (!$captcha or $captcha != strtoupper($code)) {
                    $bad_code = true;
                    break;
                }
            }
            if (!$user_mail) {
                $missing_mail = true;
            } else {
                if (!validate_mail($user_mail) or !is_mail_allowed($user_mail)) {
                    $bad_mail = true;
                } else {
                    if (!newsletter_get_user($user_mail)) {
                        $unknown_mail = true;
                    }
                }
            }
            if (!$confirmed) {
                $missing_confirmation = true;
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'unsubscribe':
            if ($bad_token or $missing_code or $bad_code or $missing_mail or $bad_mail or $unknown_mail or $missing_confirmation) {
                break;
            }
            require_once 'urlencodeaction.php';
            $id = 1;
            // confirmnewsletterunsubscribe, see saction
            $param = $user_mail;
            $s64 = urlencodeaction($id, $param);
            if (!$s64) {
                $internal_error = true;
                break;
            }
            $saction_page = url('saction', $lang);
            if (!$saction_page) {
                $internal_error = true;
                break;
            }
            global $base_url;
            $url = $base_url . $saction_page . '/' . $s64;
            require_once 'emailtext.php';
            $to = $user_mail;
            $subject = translate('newsletter:unregister_subject', $lang);
            $f = translate('newsletter:unregister_text', $lang);
            $s = sprintf($f, $url);
            $msg = $s . "\n\n" . translate('email:salutations', $lang);
            emailtext($msg, $to, $subject, false);
            $mail_unsubscribed = $user_mail;
            $confirmed = false;
            break;
        default:
            break;
    }
    if ($internal_error) {
        $contact_page = url('contact', $lang);
    }
    $_SESSION['unsubscribe_token'] = $token = token_id();
    $errors = compact('missing_mail', 'bad_mail', 'unknown_mail', 'missing_confirmation', 'missing_code', 'bad_code', 'internal_error', 'contact_page');
    $infos = compact('mail_unsubscribed');
    $output = view('unsubscribe', $lang, compact('token', 'with_captcha', 'user_mail', 'confirmed', 'subscribe_page', 'errors', 'infos'));
    return $output;
}
示例#3
0
function subscribe($lang)
{
    global $sitekey, $system_languages;
    $with_locale = count($system_languages) > 1;
    // true, false
    $with_captcha = true;
    $action = 'init';
    if (isset($_POST['subscribe_send'])) {
        $action = 'subscribe';
    }
    $confirmed = $code = $token = false;
    $user_mail = user_profile('mail');
    $user_locale = user_profile('locale');
    if (!$user_locale) {
        $user_locale = $lang;
    }
    $unsubscribe_page = false;
    switch ($action) {
        case 'init':
            if ($sitekey) {
                $unsubscribe_page = url('newsletterunsubscribe', $lang);
            }
            break;
        case 'subscribe':
            if (isset($_POST['subscribe_mail'])) {
                $user_mail = strtolower(strflat(readarg($_POST['subscribe_mail'])));
            }
            if ($with_locale) {
                if (isset($_POST['subscribe_locale'])) {
                    $user_locale = readarg($_POST['subscribe_locale']);
                }
            }
            if (isset($_POST['subscribe_confirmed'])) {
                $confirmed = readarg($_POST['subscribe_confirmed']) == 'on' ? true : false;
            }
            if (isset($_POST['subscribe_code'])) {
                $code = readarg($_POST['subscribe_code']);
            }
            if (isset($_POST['subscribe_token'])) {
                $token = readarg($_POST['subscribe_token']);
            }
            break;
        default:
            break;
    }
    $missing_code = false;
    $bad_code = false;
    $bad_token = false;
    $missing_mail = false;
    $bad_mail = false;
    $duplicated_mail = false;
    $missing_locale = false;
    $bad_locale = false;
    $missing_confirmation = false;
    $email_registered = false;
    $internal_error = false;
    $contact_page = false;
    switch ($action) {
        case 'subscribe':
            if (!isset($_SESSION['subscribe_token']) or $token != $_SESSION['subscribe_token']) {
                $bad_token = true;
            }
            if ($with_captcha) {
                if (!$code) {
                    $missing_code = true;
                    break;
                }
                $captcha = isset($_SESSION['captcha']['subscribe']) ? $_SESSION['captcha']['subscribe'] : false;
                if (!$captcha or $captcha != strtoupper($code)) {
                    $bad_code = true;
                    break;
                }
            }
            if (!$user_mail) {
                $missing_mail = true;
            } else {
                if (!validate_mail($user_mail) or !is_mail_allowed($user_mail)) {
                    $bad_mail = true;
                } else {
                    if (newsletter_get_user($user_mail)) {
                        $duplicated_mail = true;
                    }
                }
            }
            if ($with_locale) {
                if (!$user_locale) {
                    $missing_locale = true;
                } else {
                    if (!validate_locale($user_locale)) {
                        $bad_locale = true;
                    }
                }
            }
            if (!$confirmed) {
                $missing_confirmation = true;
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'subscribe':
            if ($bad_token or $missing_code or $bad_code or $missing_mail or $bad_mail or $duplicated_mail or $missing_locale or $bad_locale or $missing_confirmation) {
                break;
            }
            $r = newsletter_create_user($user_mail, $user_locale);
            if (!$r) {
                $internal_error = true;
                break;
            }
            require_once 'serveripaddress.php';
            require_once 'emailme.php';
            global $sitename;
            $ip = server_ip_address();
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', time());
            $subject = 'subscribe' . '@' . $sitename;
            $msg = $ip . ' ' . $timestamp . ' ' . $lang . ' ' . $user_mail;
            @emailme($subject, $msg);
            $email_registered = true;
            $confirmed = false;
            break;
        default:
            break;
    }
    if ($internal_error) {
        $contact_page = url('contact', $lang);
    }
    $_SESSION['subscribe_token'] = $token = token_id();
    $errors = compact('missing_mail', 'bad_mail', 'missing_locale', 'bad_locale', 'duplicated_mail', 'missing_confirmation', 'missing_code', 'bad_code', 'internal_error', 'contact_page');
    $infos = compact('email_registered');
    $output = view('subscribe', $lang, compact('token', 'with_captcha', 'user_mail', 'with_locale', 'user_locale', 'confirmed', 'unsubscribe_page', 'errors', 'infos'));
    return $output;
}
示例#4
0
 * @link       http://www.izend.org
 */
require_once 'pdo.php';
$db_url = $scheme . '://test:test@localhost/test';
$db_prefix = 'test_';
$db_debug = true;
db_connect($db_url);
require_once 'models/newsletter.inc';
$msecs = microtime(true);
$mail = '*****@*****.**';
$locale = 'fr';
$r = newsletter_create_user($mail, $locale);
dump($r);
$locale = 'en';
$r = newsletter_create_user($mail, $locale);
dump($r);
$r = newsletter_get_user($mail);
dump($r);
$r = newsletter_count_users('en');
dump($r);
$r = newsletter_count_users();
dump($r);
$r = newsletter_mailinglist('fr');
dump($r);
//$r=newsletter_schedule_post($newsletter_id, $page_id, $locale, $scheduled);
//dump($r);
$r = newsletter_post();
dump($r);
$r = newsletter_delete_user($mail);
dump($r);
echo sprintf('%.4f', microtime(true) - $msecs), PHP_EOL;