function dk_speakout_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_speakout_Signature(); $the_petition = new dk_speakout_Petition(); $wpml = new dk_speakout_WPML(); $options = get_option('dk_speakout_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_speakout_Mail::send_confirmation($the_petition, $the_signature, $options); } else { if ($the_petition->sends_email) { dk_speakout_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; }
function dk_speakout_signatures_csv() { // check security: ensure user has authority and intention if (!current_user_can('publish_posts')) { wp_die(__('Insufficient privileges: You need to be an editor to do that.', 'dk_speakout')); } check_admin_referer('dk_speakout-download_signatures'); include_once 'class.signature.php'; $signatures = new dk_speakout_Signature(); $petition_id = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : ''; // petition id // retrieve signatures from the database $csv_data = $signatures->all($petition_id, 0, 0, 'csv'); // display error message if query returns no results if (count($csv_data) < 1) { echo '<h1>' . __("No signatures found.", "dk_speakout") . '</h1>'; die; } // construct CSV filename $counter = 0; foreach ($csv_data as $file) { if ($counter < 1) { $filename_title = stripslashes(str_replace(' ', '-', $file->title)); $filename_date = date('Y-m-d', strtotime(current_time('mysql', 0))); $filename = $filename_title . '_' . $filename_date . '.csv'; } $counter++; } // set up CSV file headers header('Content-Type: text/octet-stream; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Pragma: public'); // supposed to make stuff work over https // get the column headers translated $firstname = __('First Name', 'dk_speakout'); $lastname = __('Last Name', 'dk_speakout'); $email = __('Email Address', 'dk_speakout'); $street = __('Street Address', 'dk_speakout'); $city = __('City', 'dk_speakout'); $state = __('State', 'dk_speakout'); $postcode = __('Post Code', 'dk_speakout'); $country = __('Country', 'dk_speakout'); $date = __('Date Signed', 'dk_speakout'); $confirmed = __('Confirmed', 'dk_speakout'); $petition_title = __('Petition Title', 'dk_speakout'); $petitions_id = __('Petition ID', 'dk_speakout'); $email_optin = __('Email Opt-in', 'dk_speakout'); $custom_message = __('Custom Message', 'dk_speakout'); $language = __('Language', 'dk_speakout'); // If set, use the custom field label as column header instead of "Custom Field" $counter = 0; foreach ($csv_data as $label) { if ($counter < 1) { if ($label->custom_field_label != '') { $custom_field_label = stripslashes($label->custom_field_label); } else { $custom_field_label = __('Custom Field', 'dk_speakout'); } } $counter++; } // construct CSV file header row // must use double quotes and separate with tabs $csv = "{$firstname}\t{$lastname}\t{$email}\t{$street}\t{$city}\t{$state}\t{$postcode}\t{$country}\t{$custom_field_label}\t{$date}\t{$confirmed}\t{$petition_title}\t{$petitions_id}\t{$email_optin}\t{$custom_message}\t{$language}"; $csv .= "\n"; // construct CSV file data rows foreach ($csv_data as $signature) { // convert the 1, 0, or '' values of confirmed to readable format $confirm = $signature->is_confirmed; if ($confirm == 1) { $confirm = __('confirmed', 'dk_speakout'); } elseif ($confirm == 0) { $confirm = __('unconfirmed', 'dk_speakout'); } else { $confirm = '...'; } // convert the 1, 0, or '' values of optin to readable format $optin = $signature->optin; if ($optin == 1) { $optin = __('yes', 'dk_speakout'); } elseif ($optin == 0) { $optin = __('no', 'dk_speakout'); } else { $optin = '...'; } $csv .= stripslashes('"' . $signature->first_name . '" "' . $signature->last_name . '" "' . $signature->email . '" "' . $signature->street_address . '" "' . $signature->city . '" "' . $signature->state . '" "' . $signature->postcode . '" "' . $signature->country . '" "' . $signature->custom_field . '" "' . $signature->date . '" "' . $confirm . '" "' . $signature->title . '" "' . $signature->petitions_id . '" "' . $optin . '" "' . $signature->custom_message . '" "' . $signature->language . '"'); $csv .= "\n"; } // output CSV file in a UTF-8 format that Excel can understand echo chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8'); exit; }
/** * generates HTML table of signatures for a single petition * * @param int $id the ID petition for which we are displaying signatures * @param int $start the first signature to be retrieved * @param int $limit number of signatures to be retrieved * @param string $context either 'shortcode' or 'ajax' to distinguish between calls from the initia page load (shortcode) and calls from pagination buttons (ajax) * @param string $dateformat PHP date format provided by shortcode attribute - also relayed in ajax requests * @param string $nextbuttontext provided by shortcode attribute * @param string $prevtbuttontext provided by shortcode attribute * * @return string HTML table containing signatures (or just the table rows if context is ajax) */ public static function table($id, $start, $limit, $context = 'shortcode', $dateformat = 'M d, Y', $nextbuttontext = '>', $prevbuttontext = '<') { include_once 'class.signature.php'; $the_signatures = new dk_speakout_Signature(); $options = get_option('dk_speakout_options'); // get list of columns to display - as defined in settings $columns = unserialize($options['signaturelist_columns']); // get the signatures $signatures = $the_signatures->all($id, $start, $limit, 'signaturelist'); $total = $the_signatures->count($id, 'signaturelist'); $current_signature_number = $total - $start; $signatures_list = ''; // only show signature lists if there are signatures if ($total > 0) { // determine which columns to display $display_city = in_array('sig_city', $columns) ? 1 : 0; $display_state = in_array('sig_state', $columns) ? 1 : 0; $display_postcode = in_array('sig_postcode', $columns) ? 1 : 0; $display_country = in_array('sig_country', $columns) ? 1 : 0; $display_custom = in_array('sig_custom', $columns) ? 1 : 0; $display_date = in_array('sig_date', $columns) ? 1 : 0; if ($context !== 'ajax') { // only include on initial page load (not when paging) $signatures_list = ' <!-- signaturelist --> <table class="dk-speakout-signaturelist dk-speakout-signaturelist-' . $id . '"> <caption>' . $options['signaturelist_header'] . '</caption>'; } $row_count = 0; foreach ($signatures as $signature) { if ($row_count % 2) { $signatures_list .= '<tr class="dk-speakout-even">'; } else { $signatures_list .= '<tr class="dk-speakout-odd">'; } $signatures_list .= '<td class="dk-speakout-signaturelist-count">' . number_format($current_signature_number, 0, '.', ',') . '</td>'; $display_lastname = $signature->last_name; // if we have enabled privacy, only show forst letter of surname if ($options['signaturelist_privacy'] == 'enabled') { $display_lastname = substr($signature->last_name, 0, 1) . "."; } $signatures_list .= '<td class="dk-speakout-signaturelist-name">' . stripslashes($signature->first_name . ' ' . $display_lastname) . '</td>'; // if we display both city and state, combine them into one column $city = $display_city ? $signature->city : ''; $state = $display_state ? $signature->state : ''; if ($display_city && $display_state) { // should we separate with a comma? $delimiter = $city != '' && $state != '' ? ', ' : ''; $signatures_list .= '<td class="dk-speakout-signaturelist-city">' . stripslashes($city . $delimiter . $state) . '</td>'; } else { if ($display_city) { $signatures_list .= '<td class="dk-speakout-signaturelist-city">' . stripslashes($city) . '</td>'; } if ($display_state) { $signatures_list .= '<td class="dk-speakout-signaturelist-state">' . stripslashes($state) . '</td>'; } } if ($display_postcode) { $signatures_list .= '<td class="dk-speakout-signaturelist-postcode">' . stripslashes($signature->postcode) . '</td>'; } if ($display_country) { $signatures_list .= '<td class="dk-speakout-signaturelist-country">' . stripslashes($signature->country) . '</td>'; } if ($display_custom) { $signatures_list .= '<td class="dk-speakout-signaturelist-custom">' . stripslashes($signature->custom_field) . '</td>'; } if ($display_date) { $signatures_list .= '<td class="dk-speakout-signaturelist-date">' . date_i18n($dateformat, strtotime($signature->date)) . '</td>'; } $signatures_list .= '</tr>'; $current_signature_number--; $row_count++; } if ($context !== 'ajax') { // only include on initial page load if ($limit != 0 && $start + $limit < $total) { $colspan = count($columns) + 2; $signatures_list .= ' <tr class="dk-speakout-signaturelist-pagelinks"> <td colspan="' . $colspan . '"> <a class="dk-speakout-signaturelist-prev dk-speakout-signaturelist-disabled" rel="' . $id . ',' . $total . ',' . $limit . ',' . $total . ',0">' . $prevbuttontext . '</a> <a class="dk-speakout-signaturelist-next" rel="' . $id . ',' . ($start + $limit) . ',' . $limit . ',' . $total . ',1">' . $nextbuttontext . '</a> </td> </tr> '; } $signatures_list .= '</table>'; } } return $signatures_list; }
/** * Displays the confirmation page */ function dk_speakout_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_speakout_Signature(); $the_petition = new dk_speakout_Petition(); $wpml = new dk_speakout_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) { dk_speakout_Mail::send_petition($the_petition, $the_signature); } // set up the status message $message = __('Thank you. Your signature has been added to the petition.', 'dk_speakout'); } else { // has the signature already been confirmed? if ($the_signature->check_confirmation($confirmation_code)) { $message = __('Your signature has already been confirmed.', 'dk_speakout'); } else { // the confirmation code is fubar or an admin has already deleted the signature $message = __('The confirmation code you provided is invalid.', 'dk_speakout'); } } // 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("speakout/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("speakout/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_speakout") . '</h2> <p>' . $message . '</p> <p>' . __("You will be redirected momentarily.", "dk_speakout") . '</p> <p><a href="' . home_url() . '">' . get_bloginfo("name") . ' »</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; }