예제 #1
0
function guilro_petitions_sendmail()
{
    // set WPML language
    global $sitepress;
    $lang = isset($_POST['lang']) ? $_POST['lang'] : '';
    if (isset($sitepress)) {
        $sitepress->switch_lang($lang, true);
    }
    include_once 'class.signature.php';
    include_once 'class.petition.php';
    include_once 'class.mail.php';
    include_once 'class.wpml.php';
    $the_signature = new guilro_petitions_Signature();
    $the_petition = new guilro_petitions_Petition();
    $the_settings = new guilro_petitions_Settings();
    $the_settings->retrieve();
    $wpml = new guilro_petitions_WPML();
    $options = get_object_vars($the_settings);
    // clean posted signature fields
    $the_signature->poppulate_from_post();
    // get petition data
    $the_petition->retrieve($the_signature->petitions_id);
    $wpml->translate_petition($the_petition);
    $options = $wpml->translate_options($options);
    // check if submitted email address is already in use for this petition
    if ($the_signature->has_unique_email($the_signature->email, $the_signature->petitions_id)) {
        // handle custom petition messages
        $original_message = str_replace("\r", '', $the_petition->petition_message);
        if ($the_petition->is_editable && $the_signature->submitted_message != $original_message) {
            $the_signature->custom_message = trim($the_signature->submitted_message);
        }
        // does petition require email confirmation?
        if ($the_petition->requires_confirmation) {
            $the_signature->is_confirmed = 0;
            $the_signature->create_confirmation_code();
            guilro_petitions_Mail::send_confirmation($the_petition, $the_signature, $options);
        } else {
            if ($the_petition->sends_email) {
                guilro_petitions_Mail::send_petition($the_petition, $the_signature);
            }
        }
        // add signature to database
        $the_signature->create($the_signature->petitions_id);
        // display success message
        $success_message = $options['success_message'];
        $success_message = str_replace('%first_name%', $the_signature->first_name, $success_message);
        $success_message = str_replace('%last_name%', $the_signature->last_name, $success_message);
        $json_response = array('status' => 'success', 'message' => $success_message);
        $json_response = json_encode($json_response);
        echo $json_response;
    } else {
        $json_response = array('status' => 'error', 'message' => $options['already_signed_message']);
        $json_response = json_encode($json_response);
        echo $json_response;
    }
    // end AJAX processing
    die;
}
예제 #2
0
/**
 * Displays the confirmation page.
 */
function guilro_petitions_confirm_email()
{
    // set WPML language
    global $sitepress;
    $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : '';
    if (isset($sitepress)) {
        $sitepress->switch_lang($lang, true);
    }
    include_once 'class.signature.php';
    include_once 'class.petition.php';
    include_once 'class.mail.php';
    include_once 'class.wpml.php';
    $the_signature = new guilro_petitions_Signature();
    $the_petition = new guilro_petitions_Petition();
    $wpml = new guilro_petitions_WPML();
    // get the confirmation code from url
    $confirmation_code = $_REQUEST['dkspeakoutconfirm'];
    // try to confirm the signature
    $try_confirm = $the_signature->confirm($confirmation_code);
    // if our attempt to confirm the signature was successful
    if ($try_confirm) {
        // retrieve the signature data
        $the_signature->retrieve_confirmed($confirmation_code);
        // retrieve the petition data
        $the_petition->retrieve($the_signature->petitions_id);
        $wpml->translate_petition($the_petition);
        // send the petition email
        if ($the_petition->sends_email) {
            guilro_petitions_Mail::send_petition($the_petition, $the_signature);
        }
        // redirect to page
        wp_redirect($the_petition->return_url);
        exit;
    } else {
        // has the signature already been confirmed?
        if ($the_signature->check_confirmation($confirmation_code)) {
            $message = __('Your signature has already been confirmed.', 'guilro_petitions');
        } else {
            // the confirmation code is fubar or an admin has already deleted the signature
            $message = __('The confirmation code you provided is invalid.', 'guilro_petitions');
        }
    }
    // display the confirmation page
    $confirmation_page = '
		<!doctype html>
		<html>
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=' . get_bloginfo('charset') . '" />
			<meta http-equiv="refresh" content="10;' . $the_petition->return_url . '">
			<title>' . get_bloginfo('name') . '</title>
			<style type="text/css">
				body {
					background: #666;
					font-family: arial, sans-serif;
					font-size: 14px;
				}
				#confirmation {
					background: #fff url(' . plugins_url('guilro-petitions/images/mail-stripes.png') . ') repeat top left;
					border: 1px solid #fff;
					width: 515px;
					margin: 200px auto 0 auto;
					box-shadow: 0px 3px 5px #333;
				}
				#confirmation-content {
					background: #fff url(' . plugins_url('guilro-petitions/images/postmark.png') . ') no-repeat top right;
					margin: 10px;
					padding: 40px 0 20px 100px;
				}
			</style>
		</head>
		<body>
			<div id="confirmation">
				<div id="confirmation-content">
					<h2>' . __('Email Confirmation', 'guilro_petitions') . '</h2>
					<p>' . $message . '</p>
					<p>' . __('You will be redirected momentarily.', 'guilro_petitions') . '</p>
					<p><a href="' . home_url() . '">' . get_bloginfo('name') . '  &raquo;</a></p>
				</div>
			</div>
		</body>
		</html>
	';
    echo $confirmation_page;
    // stop page rendering here
    // without this, the home page will display below the confirmation message
    die;
}