function dk_speakup_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 dk_speakup_Signature();
    $the_petition = new dk_speakup_Petition();
    $wpml = new dk_speakup_WPML();
    $options = get_option('dk_speakup_options');
    // 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();
            dk_speakup_Mail::send_confirmation($the_petition, $the_signature, $options);
        } else {
            if ($the_petition->sends_email) {
                dk_speakup_Mail::send_petition($the_petition, $the_signature);
            }
            if ($the_petition->user_send_email) {
                dk_speakup_Mail::send_subscriber($the_petition, $the_signature, $options);
            }
        }
        // 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);
        do_action('dk_speakup_petition_signed', $the_signature);
        $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;
}
/**
 * Displays the Email Petitions table page
 */
function dk_speakup_petitions_page()
{
    // check security: ensure user has authority
    if (!current_user_can('publish_posts')) {
        wp_die('Insufficient privileges: You need to be an editor to do that.');
    }
    include_once 'class.speakup.php';
    include_once 'class.petition.php';
    include_once 'class.wpml.php';
    $the_petitions = new dk_speakup_Petition();
    $wpml = new dk_speakup_WPML();
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
    $options = get_option('dk_speakup_options');
    // set variables for paged record display and limit values in db query
    // request values may be submitted either by html links (pagination.php) or by javascript (admin.js)
    $paged = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : '1';
    $total_pages = isset($_REQUEST['total_pages']) ? $_REQUEST['total_pages'] : '1';
    $current_page = dk_speakup_SpeakUp::current_paged($paged, $total_pages);
    $query_limit = $options['petitions_rows'];
    $query_start = $current_page * $query_limit - $query_limit;
    // link URL for "Add New" button in header
    $addnew_url = esc_url(site_url() . '/wp-admin/admin.php?page=dk_speakup_addnew');
    switch ($action) {
        case 'delete':
            // security: ensure user has intention
            check_admin_referer('dk_speakup-delete_petition' . $id);
            // delete the petition and its signatures
            $the_petitions->delete($id);
            $wpml->unregister_petition($id);
            // get petitions
            $petitions = $the_petitions->all($query_start, $query_limit);
            // set up page display variables
            $page_title = __('Email Petitions', 'dk_speakup');
            $count = $the_petitions->count();
            $message_update = __('Petition deleted.', 'dk_speakup');
            break;
        default:
            // get petitions
            $petitions = $the_petitions->all($query_start, $query_limit);
            // set up page display variables
            $page_title = __('Email Petitions', 'dk_speakup');
            $count = $the_petitions->count();
            $message_update = '';
    }
    // display the Petitions table
    include_once 'petitions.view.php';
}
function dk_speakup_signatures_page()
{
    // check security: ensure user has authority
    if (!current_user_can('publish_posts')) {
        wp_die(__('Insufficient privileges: You need to be an editor to do that.', 'dk_speakup'));
    }
    include_once 'class.speakup.php';
    include_once 'class.signature.php';
    include_once 'class.petition.php';
    $the_signatures = new dk_speakup_Signature();
    $the_petitions = new dk_speakup_Petition();
    $options = get_option('dk_speakup_options');
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : '';
    // petition id
    $sid = isset($_REQUEST['sid']) ? $_REQUEST['sid'] : '';
    // signature id
    // set variables for paged record display and for limit values in db query
    $paged = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : '1';
    $total_pages = isset($_REQUEST['total_pages']) ? $_REQUEST['total_pages'] : '1';
    $current_page = dk_speakup_SpeakUp::current_paged($paged, $total_pages);
    $query_limit = $options['signatures_rows'];
    $query_start = $current_page * $query_limit - $query_limit;
    switch ($action) {
        case 'delete':
            // security: ensure user has intention
            check_admin_referer('dk_speakup-delete_signature' . $sid);
            // delete signature from the database
            $the_signatures->delete($sid);
            // count number of signatures in database
            $count = $the_signatures->count($pid);
            // get all signatures for display
            $signatures = $the_signatures->all($pid, $query_start, $query_limit);
            // set up display strings
            // set up values for the table label ie: All Signatures (36)
            if ($count == 0) {
                $petition = '';
            } elseif ($pid != '') {
                $petition = $signatures[0]->title;
            } else {
                $petition = __('All Signatures', 'dk_speakup');
            }
            $table_label = esc_html($petition) . ' <span class="count">(' . $count . ')</span>';
            $base_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures&action=petition&pid=' . $pid);
            $message_update = __('Signature deleted.', 'dk_speakup');
            break;
        case 'petition':
            // count number of signatures in database
            $count = $the_signatures->count($pid);
            // get all signatures for display
            $signatures = $the_signatures->all($pid, $query_start, $query_limit);
            // TODO: Make this always show petition title (maybe use join in query)
            // set up display strings
            // if signatures exist, show petition title, else show petition id number
            if (count($signatures) > 0) {
                $table_label = esc_html($signatures[0]->title) . ' <span class="count">(' . $count . ')</span>';
            } else {
                $table_label = __('Petition', 'dk_speakup') . ' ' . $pid . ' <span class="count">(0)</span>';
            }
            $base_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures&action=petition&pid=' . $pid);
            $message_update = '';
            break;
        case 'reconfirm':
            check_admin_referer('dk_speakup-resend_confirmations' . $pid);
            include_once 'class.mail.php';
            $petition_to_confirm = new dk_speakup_Petition();
            // get unconfirmed signatures
            $unconfirmed = $the_signatures->unconfirmed($pid);
            foreach ($unconfirmed as $signature) {
                $unconfirmed_signature = new dk_speakup_signature();
                $unconfirmed_signature->first_name = $signature->first_name;
                $unconfirmed_signature->last_name = $signature->last_name;
                $unconfirmed_signature->email = $signature->email;
                $unconfirmed_signature->confirmation_code = $signature->confirmation_code;
                dk_speakup_Mail::send_confirmation($petition_to_confirm, $unconfirmed_signature, $options);
                // destroy temporary object so we can re-use the variable
                unset($unconfirmed_signature);
            }
            // count number of signatures in database
            $count = $the_signatures->count($pid);
            // get all signatures for display
            $signatures = $the_signatures->all($pid, $query_start, $query_limit);
            // set up display strings
            if (count($signatures) > 0) {
                $table_label = esc_html($signatures[0]->title) . ' <span class="count">(' . $count . ')</span>';
            } else {
                $table_label = __('Petition', 'dk_speakup') . ' ' . $pid . ' <span class="count">(0)</span>';
            }
            $base_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures&action=petition&pid=' . $pid);
            $message_update = __('Confirmation emails sent.', 'dk_speakup');
            break;
        default:
            // count number of signatures in database
            $count = $the_signatures->count($pid);
            // get all signatures for display
            $signatures = $the_signatures->all($pid, $query_start, $query_limit);
            // set up display strings
            $table_label = __('All Signatures', 'dk_speakup') . ' <span class="count">(' . $count . ')</span>';
            $base_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures');
            $message_update = '';
    }
    // get list of petitions to populate select box navigation
    $petitions_list = $the_petitions->quicklist();
    // Set up URLs for 'Download as CSV' and 'Resend confirmations' buttons
    // Show buttons only when we are viewing signatures from a single petition
    if (count($petitions_list) == 1 || $pid != '') {
        // if $pid (petition id) wasn't sent through the URL, then create it from the query
        if ($pid == '') {
            $pid = $petitions_list[0]->id;
        }
        $csv_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures&action=petition&pid=' . $pid);
        $reconfirm_url = site_url('wp-admin/admin.php?page=dk_speakup_signatures&action=reconfirm&pid=' . $pid);
    }
    // display the Signatures table
    include_once dirname(__FILE__) . '/signatures.view.php';
}
function dk_speakup_addnew_page()
{
    // check security: ensure user has authority
    if (!current_user_can('publish_posts')) {
        wp_die('Insufficient privileges: You need to be an editor to do that.');
    }
    include_once 'class.petition.php';
    include_once 'class.wpml.php';
    $petition = new dk_speakup_Petition();
    $wpml = new dk_speakup_WPML();
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $petition->id = isset($_REQUEST['id']) ? absint($_REQUEST['id']) : '';
    switch ($action) {
        // add a new petition to database
        // then display form for editing the new petition
        case 'create':
            // security: ensure user has intention
            check_admin_referer('dk_speakup-create_petition');
            $petition->poppulate_from_post();
            $petition->create();
            $wpml->register_petition($petition);
            // set up page display variables
            $page_title = __('Edit Email Petition', 'dk_speakup');
            $nonce = 'dk_speakup-update_petition' . $petition->id;
            $action = 'update';
            $x_date = $petition->get_expiration_date_components();
            $button_text = __('Update Petition', 'dk_speakup');
            // construct update message box content
            $emailpetition_shortcode = '[emailpetition id="' . $petition->id . '"]';
            $signaturelist_shortcode = '[signaturelist id="' . $petition->id . '"]';
            $start_tag = '<strong>';
            $end_tag = '</strong>';
            $message_text = __('Petition created. Use %1$s %2$s %3$s to display in a page or post. Use %1$s %4$s %3$s to display the signatures list.', 'dk_speakup');
            $message_update = sprintf($message_text, $start_tag, $emailpetition_shortcode, $end_tag, $signaturelist_shortcode);
            break;
            // 'edit' is only called from text links on the Email Petitions page
            // displays existing petition for alteration and submits with 'update' action
        // 'edit' is only called from text links on the Email Petitions page
        // displays existing petition for alteration and submits with 'update' action
        case 'edit':
            // security: ensure user has intention
            check_admin_referer('dk_speakup-edit_petition' . $petition->id);
            $petition->retrieve($petition->id);
            // set up page display variables
            $page_title = __('Edit Email Petition', 'dk_speakup');
            $nonce = 'dk_speakup-update_petition' . $petition->id;
            $action = 'update';
            $x_date = $petition->get_expiration_date_components();
            $button_text = __('Update Petition', 'dk_speakup');
            $message_update = '';
            break;
            // alter an existing petition
        // alter an existing petition
        case 'update':
            // security: ensure user has intention
            check_admin_referer('dk_speakup-update_petition' . $petition->id);
            $petition->poppulate_from_post();
            $petition->update($petition->id);
            $wpml->register_petition($petition);
            // set up page display variables
            $page_title = __('Edit New Email Petition', 'dk_speakup');
            $nonce = 'dk_speakup-update_petition' . $petition->id;
            $action = 'update';
            $x_date = $petition->get_expiration_date_components();
            $button_text = __('Update Petition', 'dk_speakup');
            $message_update = __('Petition updated.');
            break;
            // show blank form for adding a new petition
        // show blank form for adding a new petition
        default:
            // set up page display variables
            $page_title = __('Add New Email Petition', 'dk_speakup');
            $nonce = 'dk_speakup-create_petition';
            $action = 'create';
            $x_date = $petition->get_expiration_date_components();
            $button_text = __('Create Petition', 'dk_speakup');
            $message_update = '';
            $petition->optin_label = __('Add me to your mailing list', 'dk_speakup');
    }
    if ($petition->return_url == '') {
        $petition->return_url = home_url();
        error_log($petition->return_url);
    }
    // display the form
    include_once 'addnew.view.php';
}
/**
 * Displays the confirmation page
 */
function dk_speakup_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 dk_speakup_Signature();
    $the_petition = new dk_speakup_Petition();
    $wpml = new dk_speakup_WPML();
    // get the confirmation code from url
    $confirmation_code = $_REQUEST['dkspeakupconfirm'];
    // 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) {
            dk_speakup_Mail::send_petition($the_petition, $the_signature);
        }
        // set up the status message
        $message = __('Thank you. Your signature has been added to the petition.', 'dk_speakup');
    } else {
        // has the signature already been confirmed?
        if ($the_signature->check_confirmation($confirmation_code)) {
            $message = __('Your signature has already been confirmed.', 'dk_speakup');
        } else {
            // the confirmation code is fubar or an admin has already deleted the signature
            $message = __('The confirmation code you provided is invalid.', 'dk_speakup');
        }
    }
    // 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("speakup-email-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("speakup-email-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", "dk_speakup") . '</h2>
					<p>' . $message . '</p>
					<p>' . __("You will be redirected momentarily.", "dk_speakup") . '</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;
}
function dk_speakup_emailpetition_shortcode($attr)
{
    $petition_form = '';
    global $dk_speakup_version;
    include_once 'class.speakup.php';
    include_once 'class.petition.php';
    include_once 'class.wpml.php';
    $petition = new dk_speakup_Petition();
    $wpml = new dk_speakup_WPML();
    $options = get_option('dk_speakup_options');
    //If specific template exists for petition id, we load it
    if (isset($attr['id']) && is_numeric($attr['id']) and file_exists(get_stylesheet_directory('stylesheet_directory') . '/speakup-email-petitions/template-' . $attr['id'] . '.php')) {
        $petition_form = (include get_stylesheet_directory('stylesheet_directory') . '/speakup-email-petitions/template-' . $attr['id'] . '.php');
    } elseif (file_exists(get_stylesheet_directory('stylesheet_directory') . '/speakup-email-petitions/template.php')) {
        $petition_form = (include get_stylesheet_directory('stylesheet_directory') . '/speakup-email-petitions/template.php');
    } else {
        // only query a petition if the "id" attribute has been set
        if (isset($attr['id']) && is_numeric($attr['id'])) {
            // get petition data from database
            $id = absint($attr['id']);
            $petition_exists = $petition->retrieve($id);
            // attempt to translate with WPML
            $wpml->translate_petition($petition);
            $options = $wpml->translate_options($options);
            $wpml_lang = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : '';
            if ($petition_exists) {
                add_action('wp_head', function ($petition) use($petition) {
                    echo '<meta property="og:title" content="' . $petition->title . '" />' . "\n";
                    echo '<meta property="og:image" content="' . $petition->share_fb_img . '" />' . "\n";
                    echo '<meta property="og:description" content="' . $petition->share_fb_desc . '" />' . "\n";
                    echo '<meta property="og:url" content="' . get_permalink() . '" />' . "\n";
                    echo '<meta name="twitter:title" content="' . $petition->title . '" >' . "\n";
                    echo '<meta name="twitter:description" content="' . $petition->share_twitter . '" />' . "\n";
                    echo '<meta name="twitter:url" content="' . get_permalink() . '" />' . "\n";
                });
                $expired = $petition->expires == 1 && current_time('timestamp') >= strtotime($petition->expiration_date) ? 1 : 0;
                // shortcode attributes
                $width = isset($attr['width']) ? 'style="width: ' . $attr['width'] . ';"' : '';
                $height = isset($attr['height']) ? 'style="height: ' . $attr['height'] . ' !important;"' : '';
                $css_classes = isset($attr['class']) ? $css_classes = $attr['class'] : '';
                $progress_width = $options['petition_theme'] == 'basic' ? 300 : 200;
                // defaults
                $progress_width = isset($attr['progresswidth']) ? $attr['progresswidth'] : $progress_width;
                if (!$expired) {
                    $userdata = dk_speakup_SpeakUp::userinfo();
                    // compose the petition form
                    $petition_form = '
						<!-- SpeakUp! Email Petitions ' . $dk_speakup_version . ' -->
						<div id="dk-speakup-windowshade"></div>
						<div class="dk-speakup-petition-wrap ' . $css_classes . '" id="dk-speakup-petition-' . $petition->id . '" ' . $width . '>
							<h3>' . stripslashes(esc_html($petition->title)) . '</h3>
							<a id="dk-speakup-readme-' . $petition->id . '" class="dk-speakup-readme" rel="' . $petition->id . '" style="display: none;"><span>' . __('Read the petition', 'dk_speakup') . '</span></a>
							<div class="dk-speakup-response"></div>
							<form class="dk-speakup-petition">
								<input type="hidden" id="dk-speakup-posttitle-' . $petition->id . '" value="' . esc_attr(urlencode(stripslashes($petition->title))) . '" />
								<input type="hidden" id="dk-speakup-tweet-' . $petition->id . '" value="' . dk_speakup_SpeakUp::twitter_encode($petition->twitter_message) . '" />
								<input type="hidden" id="dk-speakup-lang-' . $petition->id . '" value="' . $wpml_lang . '" />
								<input type="hidden" id="dk-speakup-textval-' . $petition->id . '" value="val" />
								<div class="dk-speakup-full">
									<label for="dk-speakup-first-name-' . $petition->id . '" class="required">' . __('First Name', 'dk_speakup') . '</label>
									<input name="dk-speakup-first-name" id="dk-speakup-first-name-' . $petition->id . '" value="' . $userdata['firstname'] . '" type="text" />
								</div>
								<div class="dk-speakup-full">
									<label for="dk-speakup-last-name-' . $petition->id . '" class="required">' . __('Last Name', 'dk_speakup') . '</label>
									<input name="dk-speakup-last-name" id="dk-speakup-last-name-' . $petition->id . '" value="' . $userdata['lastname'] . '" type="text" />
								</div>
								<div class="dk-speakup-full">
									<label for="dk-speakup-email-' . $petition->id . '" class="required">' . __('Email', 'dk_speakup') . '</label>
									<input name="dk-speakup-email" id="dk-speakup-email-' . $petition->id . '" value="' . $userdata['email'] . '" type="text" />
								</div>';
                    if ($petition->requires_confirmation) {
                        $petition_form .= '
								<div class="dk-speakup-full">
									<label for="dk-speakup-email-confirm-' . $petition->id . '" class="required">' . __('Confirm Email', 'dk_speakup') . '</label>
									<input name="dk-speakup-email-confirm" id="dk-speakup-email-confirm-' . $petition->id . '" value="" type="text" />
								</div>';
                    }
                    if (in_array('street', $petition->address_fields)) {
                        $petition_form .= '
								<div class="dk-speakup-full">
									<label for="dk-speakup-street-' . $petition->id . '">' . __('Street', 'dk_speakup') . '</label>
									<input name="dk-speakup-street" id="dk-speakup-street-' . $petition->id . '" maxlength="200" type="text" />
								</div>';
                    }
                    $petition_form .= '<div>';
                    // need this div to give half-width fields a new parent - so we can style their margins differently by :nth-child
                    if (in_array('city', $petition->address_fields)) {
                        $petition_form .= '
								<div class="dk-speakup-half">
									<label for="dk-speakup-city-' . $petition->id . '">' . __('City', 'dk_speakup') . '</label>
									<input name="dk-speakup-city" id="dk-speakup-city-' . $petition->id . '" maxlength="200" type="text" />
								</div>';
                    }
                    if (in_array('state', $petition->address_fields)) {
                        $petition_form .= '
								<div class="dk-speakup-half">
									<label for="dk-speakup-state-' . $petition->id . '">' . __('State / Province', 'dk_speakup') . '</label>
									<input name="dk-speakup-state" id="dk-speakup-state-' . $petition->id . '" maxlength="200" type="text" list="dk-speakup-states" />
									<datalist id="dk-speakup-states">
										<option value="Alabama"><option value="Alaska"><option value="Alberta"><option value="Arizona"><option value="Arkansas"><option value="British Columbia"><option value="California"><option value="Colorado"><option value="Connecticut"><option value="Washington DC"><option value="Delaware"><option value="Florida"><option value="Georgia"><option value="Hawaii"><option value="Idaho"><option value="Illinois"><option value="Indiana"><option value="Iowa"><option value="Kansas"><option value="Kentucky"><option value="Labrador"><option value="Louisiana"><option value="Maine"><option value="Manitoba"><option value="Maryland"><option value="Massachusetts"><option value="Michigan"><option value="Minnesota"><option value="Mississippi"><option value="Missouri"><option value="Montana"><option value="Nebraska"><option value="Nevada"><option value="New Brunswick"><option value="Newfoundland"><option value="New Hampshire"><option value="New Jersey"><option value="New Mexico"><option value="New York"><option value="North Carolina"><option value="North Dakota"><option value="North West Territory"><option value="Nova Scotia"><option value="Nunavut"><option value="Ohio"><option value="Oklahoma"><option value="Ontario"><option value="Oregon"><option value="Pennsylvania"><option value="Prince Edward Island"><option value="Quebec"><option value="Rhode Island"><option value="Saskatchewan"><option value="South Carolina"><option value="South Dakota"><option value="Tennessee"><option value="Texas"><option value="Utah"><option value="Vermont"><option value="Virginia"><option value="Washington"><option value="West Virginia"><option value="Wisconsin"><option value="Wyoming"><option value="Yukon">
									</datalist>
								</div>';
                    }
                    if (in_array('postcode', $petition->address_fields)) {
                        $petition_form .= '
								<div class="dk-speakup-half">
									<label for="dk-speakup-postcode-' . $petition->id . '">' . __('Post Code', 'dk_speakup') . '</label>
									<input name="dk-speakup-postcode" id="dk-speakup-postcode-' . $petition->id . '" maxlength="200" type="text" />
								</div>';
                    }
                    if (in_array('country', $petition->address_fields)) {
                        $petition_form .= '
								<div class="dk-speakup-half">
									<label for="dk-speakup-country-' . $petition->id . '">' . __('Country', 'dk_speakup') . '</label>
									<input name="dk-speakup-country" id="dk-speakup-country-' . $petition->id . '" maxlength="200" type="text" list="dk-speakup-countries" />
									<datalist id="dk-speakup-countries">
										<option value="Afghanistan"><option value="Albania"><option value="Algeria"><option value="American Samoa"><option value="Andorra"><option value="Angola"><option value="Anguilla"><option value="Antarctica"><option value="Antigua and Barbuda"><option value="Argentina"><option value="Armenia"><option value="Aruba"><option value="Australia"><option value="Austria"><option value="Azerbaijan"><option value="Bahrain"><option value="Bangladesh"><option value="Barbados"><option value="Belarus"><option value="Belgium"><option value="Belize"><option value="Benin"><option value="Bermuda"><option value="Bhutan"><option value="Bolivia"><option value="Bosnia and Herzegovina"><option value="Botswana"><option value="Bouvet Island"><option value="Brazil"><option value="British Indian Ocean Territory"><option value="British Virgin Islands"><option value="Brunei"><option value="Bulgaria"><option value="Burkina Faso"><option value="Burundi"><option value="Côte d\'Ivoire"><option value="Cambodia"><option value="Cameroon"><option value="Canada"><option value="Cape Verde"><option value="Cayman Islands"><option value="Central African Republic"><option value="Chad"><option value="Chile"><option value="China"><option value="Christmas Island"><option value="Cocos (Keeling) Islands"><option value="Colombia"><option value="Comoros"><option value="Congo"><option value="Cook Islands"><option value="Costa Rica"><option value="Croatia"><option value="Cuba"><option value="Cyprus"><option value="Czech Republic"><option value="Democratic Republic of the Congo"><option value="Denmark"><option value="Djibouti"><option value="Dominica"><option value="Dominican Republic"><option value="East Timor"><option value="Ecuador"><option value="Egypt"><option value="El Salvador"><option value="Equatorial Guinea"><option value="Eritrea"><option value="Estonia"><option value="Ethiopia"><option value="Faeroe Islands"><option value="Falkland Islands"><option value="Fiji"><option value="Finland"><option value="Former Yugoslav Republic of Macedonia"><option value="France"><option value="French Guiana"><option value="French Polynesia"><option value="French Southern Territories"><option value="Gabon"><option value="Georgia"><option value="Germany"><option value="Ghana"><option value="Gibraltar"><option value="Greece"><option value="Greenland"><option value="Grenada"><option value="Guadeloupe"><option value="Guam"><option value="Guatemala"><option value="Guinea"><option value="Guinea-Bissau"><option value="Guyana"><option value="Haiti"><option value="Heard Island and McDonald Islands"><option value="Honduras"><option value="Hong Kong"><option value="Hungary"><option value="Iceland"><option value="India"><option value="Indonesia"><option value="Iran"><option value="Iraq"><option value="Ireland"><option value="Israel"><option value="Italy"><option value="Jamaica"><option value="Japan"><option value="Jordan"><option value="Kazakhstan"><option value="Kenya"><option value="Kiribati"><option value="Kuwait"><option value="Kyrgyzstan"><option value="Laos"><option value="Latvia"><option value="Lebanon"><option value="Lesotho"><option value="Liberia"><option value="Libya"><option value="Liechtenstein"><option value="Lithuania"><option value="Luxembourg"><option value="Macau"><option value="Madagascar"><option value="Malawi"><option value="Malaysia"><option value="Maldives"><option value="Mali"><option value="Malta"><option value="Marshall Islands"><option value="Martinique"><option value="Mauritania"><option value="Mauritius"><option value="Mayotte"><option value="Mexico"><option value="Micronesia"><option value="Moldova"><option value="Monaco"><option value="Mongolia"><option value="Montserrat"><option value="Morocco"><option value="Mozambique"><option value="Myanmar"><option value="Namibia"><option value="Nauru"><option value="Nepal"><option value="Netherlands"><option value="Netherlands Antilles"><option value="New Caledonia"><option value="New Zealand"><option value="Nicaragua"><option value="Niger"><option value="Nigeria"><option value="Niue"><option value="Norfolk Island"><option value="North Korea"><option value="Northern Marianas"><option value="Norway"><option value="Oman"><option value="Pakistan"><option value="Palau"><option value="Panama"><option value="Papua New Guinea"><option value="Paraguay"><option value="Peru"><option value="Philippines"><option value="Pitcairn Islands"><option value="Poland"><option value="Portugal"><option value="Puerto Rico"><option value="Qatar"><option value="Réunion"><option value="Romania"><option value="Russia"><option value="Rwanda"><option value="São Tomé and Príncipe"><option value="Saint Helena"><option value="Saint Kitts and Nevis"><option value="Saint Lucia"><option value="Saint Pierre and Miquelon"><option value="Saint Vincent and the Grenadines"><option value="Samoa"><option value="San Marino"><option value="Saudi Arabia"><option value="Senegal"><option value="Seychelles"><option value="Sierra Leone"><option value="Singapore"><option value="Slovakia"><option value="Slovenia"><option value="Solomon Islands"><option value="Somalia"><option value="South Africa"><option value="South Georgia and the South Sandwich Islands"><option value="South Korea"><option value="Spain"><option value="Sri Lanka"><option value="Sudan"><option value="Suriname"><option value="Svalbard and Jan Mayen"><option value="Swaziland"><option value="Sweden"><option value="Switzerland"><option value="Syria"><option value="Taiwan"><option value="Tajikistan"><option value="Tanzania"><option value="Thailand"><option value="The Bahamas"><option value="The Gambia"><option value="Togo"><option value="Tokelau"><option value="Tonga"><option value="Trinidad and Tobago"><option value="Tunisia"><option value="Turkey"><option value="Turkmenistan"><option value="Turks and Caicos Islands"><option value="Tuvalu"><option value="US Virgin Islands"><option value="Uganda"><option value="Ukraine"><option value="United Arab Emirates"><option value="United Kingdom"><option value="United States"><option value="United States Minor Outlying Islands"><option value="Uruguay"><option value="Uzbekistan"><option value="Vanuatu"><option value="Vatican City"><option value="Venezuela"><option value="Vietnam"><option value="Wallis and Futuna"><option value="Western Sahara"><option value="Yemen"><option value="Yugoslavia"><option value="Zambia"><option value="Zimbabwe">
									</datalist>
								</div>';
                    }
                    $petition_form .= '</div>';
                    if ($petition->displays_custom_field == 1) {
                        $petition_form .= '
								<div class="dk-speakup-full">
									<label for="dk-speakup-custom-field-' . $petition->id . '">' . stripslashes(esc_html($petition->custom_field_label)) . '</label>
									<input name="dk-speakup-custom-field" id="dk-speakup-custom-field-' . $petition->id . '" maxlength="400" type="text" />
								</div>';
                    }
                    if ($petition->is_editable == 1) {
                        $petition_form .= '
								<div class="dk-speakup-full dk-speakup-message-editable" id="dk-speakup-message-editable-' . $petition->id . '">
									<p class="dk-speakup-greeting">' . $petition->greeting . '</p>
									<textarea name="dk-speakup-message" class="dk-speakup-message-' . $petition->id . '" ' . $height . ' rows="8">' . stripslashes(esc_textarea($petition->petition_message)) . '</textarea>
									<p class="dk-speakup-caps">[' . __('signature', 'dk-speakup') . ']</p>
								</div>';
                    } else {
                        $petition_form .= '
								<div class="dk-speakup-full dk-speakup-message" ' . $height . ' id="dk-speakup-message-' . $petition->id . '">
									<p class="dk-speakup-greeting">' . $petition->greeting . '</p>
									' . stripslashes(wpautop($petition->petition_message)) . '
									<p class="dk-speakup-caps">[' . __('signature', 'dk-speakup') . ']</p>
								</div>';
                    }
                    if ($petition->displays_optin == 1) {
                        $optin_default = $options['optin_default'] == 'checked' ? ' checked="checked"' : '';
                        $petition_form .= '
								<div class="dk-speakup-optin-wrap">
									<input type="checkbox" name="dk-speakup-optin" id="dk-speakup-optin-' . $petition->id . '"' . $optin_default . ' />
									<label for="dk-speakup-optin-' . $petition->id . '">' . stripslashes(esc_html($petition->optin_label)) . '</label>
								</div>';
                    }
                    $petition_form .= '
								<div class="dk-speakup-submit-wrap">
									<div id="dk-speakup-ajaxloader-' . $petition->id . '" class="dk-speakup-ajaxloader" style="visibility: hidden;">&nbsp;</div>
									<a name="' . $petition->id . '" class="dk-speakup-submit"><span>' . stripslashes(esc_html($options['button_text'])) . '</span></a>
								</div>
							</form>';
                    if ($options['display_count'] == 1) {
                        $petition_form .= '
							<div class="dk-speakup-progress-wrap">
								<div class="dk-speakup-signature-count">
									<span>' . number_format($petition->signatures) . '</span> ' . _n('signature', 'signatures', $petition->signatures, 'dk_speakup') . '
								</div>
								' . dk_speakup_SpeakUp::progress_bar($petition->goal, $petition->signatures, $progress_width) . '
							</div>';
                    }
                    $petition_form .= '
							<div class="dk-speakup-share">
								<div><p>' . stripslashes(esc_html($options['share_message'])) . '</p>
								<p>
									<a class="dk-speakup-facebook" href="#" title="Facebook" rel="' . $petition->id . '"><span>&nbsp;</span></a>
									<a class="dk-speakup-twitter" href="#" title="Twitter" rel="' . $petition->id . '"><span>&nbsp;</span></a>
								</p>
							</div>
								<div class="dk-speakup-clear"></div>
							</div>
						</div>';
                } else {
                    $goal_text = $petition->goal != 0 ? '<p><strong>' . __('Signature goal', 'dk_speakup') . ':</strong> ' . $petition->goal . '</p>' : '';
                    $petition_form = '
						<div class="dk-speakup-petition-wrap dk-speakup-expired" id="dk-speakup-petition-' . $petition->id . '">
							<h3>' . stripslashes(esc_html($petition->title)) . '</h3>
							<p>' . stripslashes(esc_html($options['expiration_message'])) . '</p>
							<p><strong>' . __('End date', 'dk_speakup') . ':</strong> ' . date('M d, Y', strtotime($petition->expiration_date)) . '</p>
							<p><strong>' . __('Signatures collected', 'dk_speakup') . ':</strong> ' . $petition->signatures . '</p>
							' . $goal_text . '
							<div class="dk-speakup-progress-wrap">
								<div class="dk-speakup-signature-count">
									<span>' . number_format($petition->signatures) . '</span> ' . _n('signature', 'signatures', $petition->signatures, 'dk_speakup') . '
								</div>
								' . dk_speakup_SpeakUp::progress_bar($petition->goal, $petition->signatures, $progress_width) . '
							</div>
						</div>';
                }
            } else {
                $petition_form = '';
            }
        } else {
            $petition_form = '
				<div class="dk-speakup-petition-wrap dk-speakup-expired">
					<h3>' . __('Petition', 'dk_speakup') . '</h3>
					<div class="dk-speakup-notice">
						<p>' . __('Error: You must include a valid id.', 'dk_speakup') . '</p>
					</div>
				</div>';
        }
    }
    return $petition_form;
}
    function widget($args, $instance)
    {
        global $dk_speakup_version;
        include_once 'class.speakup.php';
        include_once 'class.petition.php';
        include_once 'class.wpml.php';
        $options = get_option('dk_speakup_options');
        $petition = new dk_speakup_Petition();
        $wpml = new dk_speakup_WPML();
        extract($args);
        // get widget data
        $instance = $wpml->translate_widget($instance);
        $title = apply_filters('widget_title', $instance['title']);
        $call_to_action = empty($instance['call_to_action']) ? '&nbsp;' : $instance['call_to_action'];
        $petition->id = empty($instance['petition_id']) ? 1 : absint($instance['petition_id']);
        $get_petition = $petition->retrieve($petition->id);
        $wpml->translate_petition($petition);
        $options = $wpml->translate_options($options);
        // set up variables for widget display
        $userdata = dk_speakup_SpeakUp::userinfo();
        $expired = $petition->expires == '1' && current_time('timestamp') >= strtotime($petition->expiration_date) ? 1 : 0;
        $greeting = $petition->greeting != '' && $petition->sends_email == 1 ? '<p><span class="dk-speakup-widget-greeting">' . $petition->greeting . '</span></p>' : '';
        $optin_default = $options['optin_default'] == 'checked' ? 'checked' : '';
        // get language value from URL if available (for WPML)
        $wpml_lang = '';
        if (defined('ICL_LANGUAGE_CODE')) {
            $wpml_lang = ICL_LANGUAGE_CODE;
        }
        // check if petition exists...
        // if a petition has been deleted, but its widget still exists, don't try to display the form
        if ($get_petition) {
            // compose the petition widget and pop-up form
            $petition_widget = '
				<!-- SpeakUp! Email Petitions ' . $dk_speakup_version . ' -->
				<div class="dk-speakup-widget-wrap">
					<h3>' . stripslashes(esc_html($title)) . '</h3>
					<p>' . stripslashes(esc_html($call_to_action)) . '</p>
					<div class="dk-speakup-widget-button-wrap">
						<a rel="dk-speakup-widget-popup-wrap-' . $petition->id . '" class="dk-speakup-widget-button"><span>' . $options['button_text'] . '</span></a>
					</div>';
            if ($options['display_count'] == 1) {
                $petition_widget .= '
					<div class="dk-speakup-widget-progress-wrap">
						<div class="dk-speakup-widget-signature-count">
							<span>' . number_format($petition->signatures) . '</span> ' . _n('signature', 'signatures', $petition->signatures, 'dk_speakup') . '
						</div>
						' . dk_speakup_SpeakUp::progress_bar($petition->goal, $petition->signatures, 150) . '
					</div>';
            }
            $petition_widget .= '
				</div>

				<div id="dk-speakup-widget-windowshade"></div>
				<div id="dk-speakup-widget-popup-wrap-' . $petition->id . '" class="dk-speakup-widget-popup-wrap">
					<h3>' . stripslashes(esc_html($petition->title)) . '</h3>
					<div class="dk-speakup-widget-close"></div>';
            if ($petition->is_editable == 1) {
                $petition_widget .= '
					<div class="dk-speakup-widget-message-wrap">
						<p class="dk-speakup-greeting">' . $petition->greeting . '</p>
						<textarea name="dk-speakup-widget-message" id="dk-speakup-widget-message-' . $petition->id . '" class="dk-speakup-widget-message">' . stripslashes(esc_textarea($petition->petition_message)) . '</textarea>
						<p class="dk-speakup-caps">[' . __('signature', 'dk-speakup') . ']</p>
					</div>';
            } else {
                $petition_widget .= '
					<div class="dk-speakup-widget-message-wrap">
						<div class="dk-speakup-widget-message">
							<p class="dk-speakup-greeting">' . $petition->greeting . '</p>
							' . stripslashes(wpautop($petition->petition_message)) . '
							<p class="dk-speakup-caps">[' . __('signature', 'dk-speakup') . ']</p>
						</div>
					</div>';
            }
            $petition_widget .= '
					<div class="dk-speakup-widget-form-wrap">
						<div class="dk-speakup-widget-response"></div>
						<form class="dk-speakup-widget-form">
							<input type="hidden" id="dk-speakup-widget-posttitle-' . $petition->id . '" value="' . esc_attr(urlencode(stripslashes($petition->title))) . '" />
							<input type="hidden" id="dk-speakup-widget-shareurl-' . $petition->id . '" value="' . esc_attr(urlencode(stripslashes($instance['sharing_url']))) . '" />
							<input type="hidden" id="dk-speakup-widget-tweet-' . $petition->id . '" value="' . dk_speakup_SpeakUp::twitter_encode($petition->twitter_message) . '" />
							<input type="hidden" id="dk-speakup-widget-lang-' . $petition->id . '" value="' . $wpml_lang . '" />';
            if ($expired) {
                $petition_widget .= '
							<p><strong>' . $options['expiration_message'] . '</strong></p>
							<p>' . __('End date', 'dk_speakup') . ': ' . date('M d, Y', strtotime($petition->expiration_date)) . '</p>
							<p>' . __('Signatures collected', 'dk_speakup') . ': ' . $petition->signatures . '</p>';
                if ($petition->goal != 0) {
                    $petition_widget .= '
							<p><div class="dk-speakup-expired-goal"><span>' . __('Signature goal', 'dk_speakup') . ':</span> ' . $petition->goal . '</div></p>';
                }
            } else {
                $petition_widget .= '
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-first-name-' . $petition->id . '" class="required">' . __('First Name', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-first-name" id="dk-speakup-widget-first-name-' . $petition->id . '" value="' . $userdata['firstname'] . '" type="text" />
							</div>
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-last-name-' . $petition->id . '" class="required">' . __('Last Name', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-last-name" id="dk-speakup-widget-last-name-' . $petition->id . '" value="' . $userdata['lastname'] . '" type="text" />
							</div>
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-email-' . $petition->id . '" class="required">' . __('Email', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-email" id="dk-speakup-widget-email-' . $petition->id . '" value="' . $userdata['email'] . '" type="text" />
							</div>';
                if ($petition->requires_confirmation) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-email-confirm-' . $petition->id . '" class="required">' . __('Confirm Email', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-email-confirm" id="dk-speakup-widget-email-confirm-' . $petition->id . '" value="" type="text" />
							</div>';
                }
                if (in_array('street', $petition->address_fields)) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-street-' . $petition->id . '">' . __('Street', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-street" id="dk-speakup-widget-street-' . $petition->id . '" maxlength="200" type="text" />
							</div>';
                }
                if (in_array('city', $petition->address_fields)) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-half">
								<label for="dk-speakup-widget-city-' . $petition->id . '">' . __('City', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-city" id="dk-speakup-widget-city-' . $petition->id . '" maxlength="200" type="text">
							</div>';
                }
                if (in_array('state', $petition->address_fields)) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-half">
								<label for="dk-speakup-widget-state-' . $petition->id . '">' . __('State / Province', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-state" id="dk-speakup-widget-state-' . $petition->id . '" maxlength="200" type="text" list="dk-speakup-states" />
								<datalist id="dk-speakup-states">
									<option value="Alabama"><option value="Alaska"><option value="Alberta"><option value="Arizona"><option value="Arkansas"><option value="British Columbia"><option value="California"><option value="Colorado"><option value="Connecticut"><option value="Washington DC"><option value="Delaware"><option value="Florida"><option value="Georgia"><option value="Hawaii"><option value="Idaho"><option value="Illinois"><option value="Indiana"><option value="Iowa"><option value="Kansas"><option value="Kentucky"><option value="Labrador"><option value="Louisiana"><option value="Maine"><option value="Manitoba"><option value="Maryland"><option value="Massachusetts"><option value="Michigan"><option value="Minnesota"><option value="Mississippi"><option value="Missouri"><option value="Montana"><option value="Nebraska"><option value="Nevada"><option value="New Brunswick"><option value="Newfoundland"><option value="New Hampshire"><option value="New Jersey"><option value="New Mexico"><option value="New York"><option value="North Carolina"><option value="North Dakota"><option value="North West Territory"><option value="Nova Scotia"><option value="Nunavut"><option value="Ohio"><option value="Oklahoma"><option value="Ontario"><option value="Oregon"><option value="Pennsylvania"><option value="Prince Edward Island"><option value="Quebec"><option value="Rhode Island"><option value="Saskatchewan"><option value="South Carolina"><option value="South Dakota"><option value="Tennessee"><option value="Texas"><option value="Utah"><option value="Vermont"><option value="Virginia"><option value="Washington"><option value="West Virginia"><option value="Wisconsin"><option value="Wyoming"><option value="Yukon">
								</datalist>
							</div>';
                }
                if (in_array('postcode', $petition->address_fields)) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-half">
								<label for="dk-speakup-widget-postcode-' . $petition->id . '">' . __('Post Code', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-postcode" id="dk-speakup-widget-postcode-' . $petition->id . '" maxlength="200" type="text">
							</div>';
                }
                if (in_array('country', $petition->address_fields)) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-half">
								<label for="dk-speakup-widget-country-' . $petition->id . '">' . __('Country', 'dk_speakup') . '</label>
								<input name="dk-speakup-widget-country" id="dk-speakup-widget-country-' . $petition->id . '" maxlength="200" type="text" list="dk-speakup-widget-countries" />
								<datalist id="dk-speakup-widget-countries">
									<option value="Afghanistan"><option value="Albania"><option value="Algeria"><option value="American Samoa"><option value="Andorra"><option value="Angola"><option value="Anguilla"><option value="Antarctica"><option value="Antigua and Barbuda"><option value="Argentina"><option value="Armenia"><option value="Aruba"><option value="Australia"><option value="Austria"><option value="Azerbaijan"><option value="Bahrain"><option value="Bangladesh"><option value="Barbados"><option value="Belarus"><option value="Belgium"><option value="Belize"><option value="Benin"><option value="Bermuda"><option value="Bhutan"><option value="Bolivia"><option value="Bosnia and Herzegovina"><option value="Botswana"><option value="Bouvet Island"><option value="Brazil"><option value="British Indian Ocean Territory"><option value="British Virgin Islands"><option value="Brunei"><option value="Bulgaria"><option value="Burkina Faso"><option value="Burundi"><option value="Côte d\'Ivoire"><option value="Cambodia"><option value="Cameroon"><option value="Canada"><option value="Cape Verde"><option value="Cayman Islands"><option value="Central African Republic"><option value="Chad"><option value="Chile"><option value="China"><option value="Christmas Island"><option value="Cocos (Keeling) Islands"><option value="Colombia"><option value="Comoros"><option value="Congo"><option value="Cook Islands"><option value="Costa Rica"><option value="Croatia"><option value="Cuba"><option value="Cyprus"><option value="Czech Republic"><option value="Democratic Republic of the Congo"><option value="Denmark"><option value="Djibouti"><option value="Dominica"><option value="Dominican Republic"><option value="East Timor"><option value="Ecuador"><option value="Egypt"><option value="El Salvador"><option value="Equatorial Guinea"><option value="Eritrea"><option value="Estonia"><option value="Ethiopia"><option value="Faeroe Islands"><option value="Falkland Islands"><option value="Fiji"><option value="Finland"><option value="Former Yugoslav Republic of Macedonia"><option value="France"><option value="French Guiana"><option value="French Polynesia"><option value="French Southern Territories"><option value="Gabon"><option value="Georgia"><option value="Germany"><option value="Ghana"><option value="Gibraltar"><option value="Greece"><option value="Greenland"><option value="Grenada"><option value="Guadeloupe"><option value="Guam"><option value="Guatemala"><option value="Guinea"><option value="Guinea-Bissau"><option value="Guyana"><option value="Haiti"><option value="Heard Island and McDonald Islands"><option value="Honduras"><option value="Hong Kong"><option value="Hungary"><option value="Iceland"><option value="India"><option value="Indonesia"><option value="Iran"><option value="Iraq"><option value="Ireland"><option value="Israel"><option value="Italy"><option value="Jamaica"><option value="Japan"><option value="Jordan"><option value="Kazakhstan"><option value="Kenya"><option value="Kiribati"><option value="Kuwait"><option value="Kyrgyzstan"><option value="Laos"><option value="Latvia"><option value="Lebanon"><option value="Lesotho"><option value="Liberia"><option value="Libya"><option value="Liechtenstein"><option value="Lithuania"><option value="Luxembourg"><option value="Macau"><option value="Madagascar"><option value="Malawi"><option value="Malaysia"><option value="Maldives"><option value="Mali"><option value="Malta"><option value="Marshall Islands"><option value="Martinique"><option value="Mauritania"><option value="Mauritius"><option value="Mayotte"><option value="Mexico"><option value="Micronesia"><option value="Moldova"><option value="Monaco"><option value="Mongolia"><option value="Montserrat"><option value="Morocco"><option value="Mozambique"><option value="Myanmar"><option value="Namibia"><option value="Nauru"><option value="Nepal"><option value="Netherlands"><option value="Netherlands Antilles"><option value="New Caledonia"><option value="New Zealand"><option value="Nicaragua"><option value="Niger"><option value="Nigeria"><option value="Niue"><option value="Norfolk Island"><option value="North Korea"><option value="Northern Marianas"><option value="Norway"><option value="Oman"><option value="Pakistan"><option value="Palau"><option value="Panama"><option value="Papua New Guinea"><option value="Paraguay"><option value="Peru"><option value="Philippines"><option value="Pitcairn Islands"><option value="Poland"><option value="Portugal"><option value="Puerto Rico"><option value="Qatar"><option value="Réunion"><option value="Romania"><option value="Russia"><option value="Rwanda"><option value="São Tomé and Príncipe"><option value="Saint Helena"><option value="Saint Kitts and Nevis"><option value="Saint Lucia"><option value="Saint Pierre and Miquelon"><option value="Saint Vincent and the Grenadines"><option value="Samoa"><option value="San Marino"><option value="Saudi Arabia"><option value="Senegal"><option value="Seychelles"><option value="Sierra Leone"><option value="Singapore"><option value="Slovakia"><option value="Slovenia"><option value="Solomon Islands"><option value="Somalia"><option value="South Africa"><option value="South Georgia and the South Sandwich Islands"><option value="South Korea"><option value="Spain"><option value="Sri Lanka"><option value="Sudan"><option value="Suriname"><option value="Svalbard and Jan Mayen"><option value="Swaziland"><option value="Sweden"><option value="Switzerland"><option value="Syria"><option value="Taiwan"><option value="Tajikistan"><option value="Tanzania"><option value="Thailand"><option value="The Bahamas"><option value="The Gambia"><option value="Togo"><option value="Tokelau"><option value="Tonga"><option value="Trinidad and Tobago"><option value="Tunisia"><option value="Turkey"><option value="Turkmenistan"><option value="Turks and Caicos Islands"><option value="Tuvalu"><option value="US Virgin Islands"><option value="Uganda"><option value="Ukraine"><option value="United Arab Emirates"><option value="United Kingdom"><option value="United States"><option value="United States Minor Outlying Islands"><option value="Uruguay"><option value="Uzbekistan"><option value="Vanuatu"><option value="Vatican City"><option value="Venezuela"><option value="Vietnam"><option value="Wallis and Futuna"><option value="Western Sahara"><option value="Yemen"><option value="Yugoslavia"><option value="Zambia"><option value="Zimbabwe">
								</datalist>
							</div>';
                }
                if ($petition->displays_custom_field == 1) {
                    $petition_widget .= '
							<div class="dk-speakup-widget-full">
								<label for="dk-speakup-widget-custom-field-' . $petition->id . '">' . stripslashes(esc_html($petition->custom_field_label)) . '</label>
								<input name="dk-speakup-widget-custom-field" id="dk-speakup-widget-custom-field-' . $petition->id . '" maxlength="400" type="text">
							</div>';
                }
                if ($petition->displays_optin == 1) {
                    $optin_default = $options['optin_default'] == 'checked' ? ' checked="checked"' : '';
                    $petition_widget .= '
							<div class="dk-speakup-widget-optin-wrap">
								<input type="checkbox" name="dk-speakup-widget-optin" id="dk-speakup-widget-optin-' . $petition->id . '"' . $optin_default . ' />
								<label for="dk-speakup-widget-optin-' . $petition->id . '">' . stripslashes(esc_html($petition->optin_label)) . '</label>
							</div>';
                }
                $petition_widget .= '
							<div class="dk-speakup-widget-submit-wrap">
								<div id="dk-speakup-widget-ajaxloader-' . $petition->id . '" class="dk-speakup-widget-ajaxloader" style="visibility: hidden;">&nbsp;</div>
								<a name="' . $petition->id . '" class="dk-speakup-widget-submit"><span>' . stripslashes(esc_html($options['button_text'])) . '</span></a>
							</div>
						</form>
						<div class="dk-speakup-widget-share">
							<p><strong>' . stripslashes(esc_html($options['share_message'])) . '</strong></p>
							<p>
							<a class="dk-speakup-widget-facebook" href="#" title="Facebook"><span></span></a>
							<a class="dk-speakup-widget-twitter" href="#" title="Twitter"><span></span></a>
							</p>
							<div class="dk-speakup-clear"></div>
						</div>
					</div>
				</div>';
            }
            echo $petition_widget;
        }
    }