/**
  * Generates custom content for preview tab.
  */
 protected function generate_preview()
 {
     wp_enqueue_style('ch_css_base');
     wp_enqueue_script('jquery-ui-resizable');
     echo '<h3>' . __('Before submit preview:', 'contesthopper') . '</h3>';
     echo '<div id="preview_before" class="ch_widget_preview"><p>' . __('Resize this block to preview various widget sizes.', 'contesthopper') . '</p>';
     $url = add_query_arg('contesthopper_preview', $this->contest->ID, get_site_url());
     echo CH_Widget::html(array('contest' => $this->contest->ID, 'preview' => 'before_submit'));
     echo '</div>';
     $widget = CH_Widget::current_widget();
     $widget_id_before = $widget->widget_id;
     echo '<h3>' . __('After submit preview:', 'contesthopper') . '</h3>';
     echo '<div id="preview_after" class="ch_widget_preview"><p>' . __('Resize this block to preview various widget sizes.', 'contesthopper') . '</p>';
     $url = add_query_arg('contesthopper_preview', $this->contest->ID, get_site_url());
     echo CH_Widget::html(array('contest' => $this->contest->ID, 'preview' => 'after_submit'));
     echo '</div>';
     $widget = CH_Widget::current_widget();
     $widget_id_after = $widget->widget_id;
     if ($this->contest->ch_double_optin == '1') {
         echo '<div id="preview_doubleoptin" class="ch_widget_preview"><p>' . __('Resize this block to preview various widget sizes.', 'contesthopper') . '</p>';
         $url = add_query_arg('contesthopper_preview', $this->contest->ID, get_site_url());
         echo CH_Widget::html(array('contest' => $this->contest->ID, 'preview' => 'doubleoptin'));
         echo '</div>';
         $widget = CH_Widget::current_widget();
         $widget_id_doubleoptin = $widget->widget_id;
     }
     echo '<script type="text/javascript">jQuery(document).ready(function() { 
     jQuery(\'#preview_before\').resizable({ resize: function(event, ui) { ui.size.height = jQuery(\'#' . $widget_id_before . '\').height()+50; } }); 
     jQuery(\'#preview_after\').resizable({ resize: function(event, ui) { ui.size.height = jQuery(\'#' . $widget_id_after . '\').height()+50; } });';
     if ($this->contest->ch_double_optin == '1') {
         echo 'jQuery(\'#preview_doubleoptin\').resizable({ resize: function(event, ui) { ui.size.height = jQuery(\'#' . $widget_id_doubleoptin . '\').height()+50; } });';
     }
     echo '});</script>';
 }
<?php

/**
* Default actions after form submit template called by main widget.php template.
* @package CHTemplate
*/
$widget = CH_Widget::current_widget();
$contest = $widget->contest;
$participant = $widget->participant;
$url = $widget->url;
$widget_id = $widget->widget_id;
$url_enc = urldecode($url);
$ref_url = $url;
$out_actions_submit = '';
if ($contest->ch_referral_field == '1') {
    $short_ref = '';
    if (isset($participant->short_ref)) {
        $short_ref = $participant->short_ref;
    }
    if (!empty($short_ref)) {
        $ref_url = $short_ref;
    } else {
        $ref_url = add_query_arg('ref', $participant->code, $ref_url);
    }
    echo '<div class="social_title">' . __('Earn Extra Entries!', 'contesthopper') . '</div><div class="social_message">' . sprintf(_n('Share the link below and earn %d Entry for each person who enters with your custom link.', 'Share the link below and earn %d Entries for each person who enters with your custom link.', $contest->ch_referral_entries), $contest->ch_referral_entries) . '</div>';
}
$social = $contest->ch_social;
if (is_array($social)) {
    echo '<div class="social">';
    foreach ($social as $s) {
        // TODO
Beispiel #3
0
    echo $media . $description;
}
echo '<div class="ch_actions ch_clear" style="border-top-color: ' . $border_color . '">
    <div class="ch_actions_inner">';
if (!$contest->is_expired() && $contest->is_started()) {
    if (!empty($participant) && $participant->status != 'not_confirmed') {
        echo CH_Widget::get_template('actions_submit');
    } else {
        if (!empty($participant) && $participant->status == 'not_confirmed') {
            echo CH_Widget::get_template('double_optin');
        } else {
            echo CH_Widget::get_template('actions');
        }
    }
    if ($contest->ch_countdown_field == '1') {
        echo CH_Widget::get_template('countdown');
    }
    if (!empty($participant) && $participant->status != 'not_confirmed') {
        echo '<div class="ch_contact_message">' . __('Winner(s) will be contacted by email.', 'contesthopper') . '</div>';
    }
} else {
    if (!$contest->is_started()) {
        echo '<div class="ch_error">' . __('Contest has not yet started.', 'contesthopper') . '</div>';
    } else {
        echo '<div class="ch_error">' . __('This contest expired.', 'contesthopper') . '</div>';
    }
}
echo '</div></div>
<div class="ch_footer">
        <span class="ch_rules_disclaimer">';
if ($contest->ch_disclaimer_rules_type != 'none') {
 /**
  * Initialize method, called on <i>init</i> action.
  * <ul>
  * <li>setting up all ajax hooks</li>
  * <li>adding shortcodes</li>
  * <li>registering post types</li>
  * <li>registering textdomain for i18n</li>
  * <li>registering and enqueueing styles and scripts</li>
  * <li>catching and processing contest double-optin based on $_GET parameters</li>
  * </ul>
  */
 function init()
 {
     // ajax hooks
     add_action('wp_ajax_contesthopper_process', array('CH_Widget', 'process'));
     add_action('wp_ajax_nopriv_contesthopper_process', array('CH_Widget', 'process'));
     add_action('wp_ajax_ch_mailchimp_list', array('CH_Page_Contest', 'field_mailchimp_list_ajax'));
     add_action('wp_ajax_ch_campaignmonitor_client', array('CH_Page_Contest', 'field_campaignmonitor_client_ajax'));
     add_action('wp_ajax_ch_campaignmonitor_list', array('CH_Page_Contest', 'field_campaignmonitor_list_ajax'));
     add_action('wp_ajax_ch_aweber_code', array('CH_Page_Contest', 'field_aweber_code_ajax'));
     add_action('wp_ajax_ch_aweber_list', array('CH_Page_Contest', 'field_aweber_list_ajax'));
     add_action('wp_ajax_ch_getresponse_list', array('CH_Page_Contest', 'field_getresponse_list_ajax'));
     // register shortcode
     add_shortcode('contesthopper', array('CH_Widget', 'html'));
     // register post type
     $array = array('public' => false, 'exclude_from_search' => true);
     register_post_type(self::post_type, $array);
     // register i18n domain
     load_plugin_textdomain('contesthopper', false, dirname(plugin_basename(__FILE__)) . '/languages/');
     // register styles & scripts
     wp_enqueue_script('jquery');
     wp_register_style('ch_css_base', self::$plugin_url . '/css/ch_base.css');
     wp_enqueue_style('ch_css_base');
     wp_register_style('ch_css_jquery_ui', self::$plugin_url . '/css/jquery-ui-1.9.1.custom.min.css');
     wp_register_script('ch_js_widget', self::$plugin_url . '/js/ch_widget.js', array('jquery'));
     wp_register_script('ch_js_datetimepicker', self::$plugin_url . '/js/jquery-ui-timepicker-addon.min.js', array('jquery', 'jquery-ui-core', 'jquery-ui-slider', 'jquery-ui-datepicker'));
     // catch and process double optin
     if (isset($_GET['contesthopper_confirm'])) {
         CH_Widget::process_optin($_GET['contesthopper_confirm']);
         $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
         $url = remove_query_arg('contesthopper_confirm', $url);
         wp_safe_redirect($url);
         die;
     }
 }
 /**
  * Main contest widget process method.
  * Called by AJAX script on contest registration form submit.
  */
 public static function process()
 {
     global $wpdb;
     // check for valid contest
     $contest = new CH_Contest(intval($_POST['contest_id']));
     if ($contest->_valid == false) {
         echo '<div class="error">' . __('Invalid contest', 'contesthopper') . '</div>';
         die;
     }
     // get POST data
     $widget_id = esc_attr($_POST['div_id']);
     $url = urldecode($_POST['url']);
     $email = esc_sql($_POST['email']);
     $first_name = '';
     if (!empty($_POST['first_name'])) {
         $first_name = esc_sql($_POST['first_name']);
     }
     $last_name = '';
     if (!empty($_POST['last_name'])) {
         $last_name = esc_sql($_POST['last_name']);
     }
     $ref = '';
     if (!empty($_POST['ch_ref'])) {
         $ref = esc_sql($_POST['ch_ref']);
     }
     $do_process = true;
     // flag to indicate invalid input ~ do not process any data, just print the widget
     // init widget data
     $data = array();
     $data['contest'] =& $contest;
     $data['widget_id'] = $widget_id;
     $data['url'] = $url;
     $data['ref'] = $ref;
     $data['participant'] = '';
     $data['error'] = array();
     $data['status'] = '';
     // if the contest did not start yet or has already ended, just echo the original widget (started/expired error messages are handled in the template)
     if (!$contest->is_started() || $contest->is_expired()) {
         self::$current_widget = new CH_Widget($data);
         echo self::get_template('widget');
         die;
     }
     // validate email
     $pattern = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$/';
     if (preg_match($pattern, $email) != 1) {
         $data['error']['email'] = 1;
         $do_process = false;
     }
     // validate names
     if ($contest->ch_name_field == '1' && $contest->ch_name_field_req == '1') {
         if (empty($first_name)) {
             $data['error']['first_name'] = 1;
             $do_process = false;
         }
         if (empty($last_name)) {
             $data['error']['last_name'] = 1;
             $do_process = false;
         }
     }
     if ($do_process) {
         $double_optin = false;
         if ($contest->ch_double_optin == '1') {
             $double_optin = true;
         }
         // prepare participant data
         $participant_data = array('ip' => $_SERVER['REMOTE_ADDR'], 'date_gmt' => current_time('mysql', 1), 'contest_id' => $contest->ID, 'code' => CH_Participant::generate_code(), 'email' => $email, 'status' => '');
         if ($double_optin) {
             $participant_data['status'] = 'not_confirmed';
         }
         $participant = new CH_Participant($participant_data);
         $participant_id = $participant->exists();
         if ($participant_id === false) {
             $participant_id = $participant->add();
             if ($contest->ch_name_field == '1') {
                 $participant->add_meta('first_name', $first_name);
                 $participant->add_meta('last_name', $last_name);
             }
             if ($contest->ch_referral_field == '1') {
                 $ref_url = add_query_arg($contest->ref_variable, $participant->code, $url);
                 $ref_url_short = self::process_shorten_url($contest, $participant, $ref_url);
                 if (!empty($ref_url_short)) {
                     $participant->add_meta('short_ref', $ref_url_short);
                 }
             }
             if (!empty($ref) && $contest->ch_referral_field == '1') {
                 if (!$double_optin) {
                     $referral = new CH_Participant($ref, true);
                     if ($referral->_valid && !empty($participant_id)) {
                         $referral->add_meta('referral_to', $participant_id);
                     }
                     // store that participant was referred by $referral
                 } else {
                     // if is double-optin, can't store referral until participant confirms his email
                     $participant->add_meta('tmp_referral', $ref);
                 }
             }
             if (!$double_optin) {
                 // process stuff
                 self::process_email($contest, $participant);
                 self::process_integration($contest, $participant);
                 self::process_cookie($contest, $participant);
             } else {
                 // if double_optin, process different stuff
                 self::process_optin_email($contest, $participant, $url);
             }
         } else {
             $participant = new CH_Participant($participant_id);
             if ($participant->status != 'not_confirmed') {
                 self::process_cookie($contest, $participant);
                 // reset his cookie
             } else {
                 // if existing participant is not_confirmed (did not confirm the double_optin)
                 self::process_optin_email($contest, $participant, $url);
                 // resend the confirmation email
             }
         }
     }
     $data['participant'] = $participant;
     self::$current_widget = new CH_Widget($data);
     echo self::get_template('widget');
     die;
 }