Example #1
0
function guilro_petitions_settings_page()
{
    // security check
    if (!current_user_can('manage_options')) {
        wp_die('Insufficient privileges: You need to be an administrator to do that.');
    }
    include_once 'class.speakout.php';
    include_once 'class.settings.php';
    include_once 'class.wpml.php';
    $the_settings = new guilro_petitions_Settings();
    $wpml = new guilro_petitions_WPML();
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'guilro-petitions-tab-01';
    switch ($action) {
        case 'update':
            // security check
            check_admin_referer('guilro_petitions-update_settings');
            $the_settings->update();
            $the_settings->retrieve();
            // attempt to resgister strings for translation in WPML
            // TODO FIX WPML and option
            //$options = $guilro_petitions_settings->getAll();
            //$wpml->register_options($options);
            $message_update = __('Settings updated.', 'guilro_petitions');
            break;
        default:
            $the_settings->retrieve();
            $message_update = '';
    }
    $nonce = 'guilro_petitions-update_settings';
    $action = 'update';
    include_once __DIR__ . '/settings.view.php';
}
Example #2
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;
}