Beispiel #1
0
 function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     $title = $instance['title'] ? esc_attr($instance['title']) : __yop_poll('Yop Poll Widget');
     $poll_id = $instance['poll_id'] ? intval($instance['poll_id']) : -1;
     $tr_id = $instance['tr_id'] ? $instance['tr_id'] : '';
     $poll_unique_id = uniqid('_yp');
     wp_enqueue_script('yop-poll-supercookie-js', YOP_POLL_URL . "js/yop-poll-supercookie.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('superCookie-min-js', YOP_POLL_URL . "js/super-cookie/superCookie-min.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('swfobject-js', YOP_POLL_URL . "js/super-cookie/swfobject/swfobject.js", array('jquery'), YOP_POLL_VERSION, true);
     if (-99 == $poll_id) {
         return '';
     }
     $pro_options = get_option('yop_poll_pro_options');
     require_once YOP_POLL_MODELS . 'poll_model.php';
     $yop_poll_model = new YOP_POLL_Poll_Model($poll_id);
     $yop_poll_model->unique_id = $poll_unique_id;
     $poll_id = $yop_poll_model->ID;
     $template = $yop_poll_model->return_poll_html(array('tr_id' => $tr_id, 'location' => 'widget', 'load_css' => true, 'load_js' => true));
     if ('yes' == $yop_poll_model->use_default_loading_image) {
         $loading_image_src = YOP_POLL_URL . 'images/loading36x36.gif';
     } else {
         $loading_image_src = $yop_poll_model->loading_image_url;
     }
     wp_enqueue_script('jquery');
     wp_enqueue_script('yop-poll-jquery-popup-windows', YOP_POLL_URL . "js/jquery.popupWindow.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_style('yop-poll-public', YOP_POLL_URL . "css/yop-poll-public.css", array(), YOP_POLL_VERSION);
     wp_enqueue_script('yop-poll-widget-user-defined_' . $poll_id . $poll_unique_id, add_query_arg(array('id' => $poll_id, 'location' => 'widget', 'unique_id' => $poll_unique_id), admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http') . '?action=yop_poll_load_js'), array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-public-js', YOP_POLL_URL . 'js/yop-poll-public.js', array(), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-json-2', YOP_POLL_URL . "js/yop-poll-json2.js", array(), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-jquery-base64', YOP_POLL_URL . "js/yop-poll-jquery.base64.min.js", array(), YOP_POLL_VERSION, true);
     $yop_poll_public_config_general = array('ajax' => array('url' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'vote_action' => 'yop_poll_do_vote', 'yop_poll_show_vote_options' => 'yop_poll_show_vote_options', 'captcha_action' => 'yop_poll_show_captcha', 'view_results_action' => 'yop_poll_view_results', 'back_to_vote_action' => 'yop_poll_back_to_vote', 'is_wordpress_user_action' => 'yop_poll_is_wordpress_user', 'is_facebook_user_action' => 'yop_poll_is_facebook_user'), 'pro' => array(), 'yop_poll_version' => YOP_POLL_VERSION, 'vote_with_wordpress_login_url' => wp_login_url(admin_url('admin-ajax.php?action=yop_poll_set_wordpress_vote', is_ssl() ? 'https' : 'http')), 'vote_with_facebook_ajax_url' => admin_url('admin-ajax.php?action=yop_poll_set_facebook_vote', is_ssl() ? 'https' : 'http'));
     $vote_permisions_types = 0;
     if ('guest-only' != $yop_poll_model->vote_permisions) {
         if ('yes' == $yop_poll_model->vote_permisions_wordpress) {
             $vote_permisions_types += 1;
         }
         if ('yes' == $yop_poll_model->vote_permisions_anonymous) {
             $vote_permisions_types += 2;
         }
         if ('yes' == $yop_poll_model->vote_permisions_facebook) {
             $vote_permisions_types += 4;
         }
     }
     $yop_poll_public_config = array('poll_options' => array('vote_permisions' => $yop_poll_model->vote_permisions, 'vote_permisions_facebook_label' => $yop_poll_model->vote_permisions_facebook_label, 'vote_permisions_wordpress_label' => $yop_poll_model->vote_permisions_wordpress_label, 'vote_permisions_anonymous_label' => $yop_poll_model->vote_permisions_anonymous_label, 'vote_permisions_types' => $vote_permisions_types, 'share_after_vote' => $yop_poll_model->share_after_vote, 'share_name' => $yop_poll_model->share_name, 'share_caption' => $yop_poll_model->share_caption, 'share_description' => $yop_poll_model->share_description, 'share_picture' => $yop_poll_model->share_picture, 'share_link' => $yop_poll_model->poll_page_url == '' ? site_url() : $yop_poll_model->poll_options['poll_page_url'], 'redirect_after_vote' => $yop_poll_model->redirect_after_vote, 'redirect_after_vote_url' => $yop_poll_model->redirect_after_vote_url), 'loading_image_src' => $loading_image_src, 'loading_image_alt' => __('Loading', 'yop_poll'));
     wp_localize_script('yop-poll-public-js', 'yop_poll_public_config_general', $yop_poll_public_config_general);
     wp_localize_script('yop-poll-public-js', 'yop_poll_public_config_' . $poll_id . $poll_unique_id, $yop_poll_public_config);
     echo $before_widget;
     echo $before_title . $title . $after_title;
     echo do_shortcode($template);
     echo $after_widget;
 }
Beispiel #2
0
 public static function save_poll($preview = false)
 {
     $new_poll = new YOP_POLL_Poll_Model($_POST['poll_id']);
     $new_poll->poll_title = stripslashes(trim($_POST['poll_title']));
     $new_poll->poll_name = sanitize_title($new_poll->poll_title);
     $new_poll->poll_author = $GLOBALS['current_user']->ID;
     $new_poll->poll_date = current_time('mysql');
     $new_poll->poll_status = 'active';
     $new_poll->poll_modified = current_time('mysql');
     $new_poll->poll_start_date = $_POST['poll_start_date'];
     $new_poll->poll_end_date = isset($_POST['poll_never_expire']) && 'yes' == $_POST['poll_never_expire'] ? '01-01-2038 23:59:59' : $_POST['poll_end_date'];
     $new_poll->poll_total_votes = 0;
     //poll options area
     if (isset($_POST['yop_poll_options']) && is_array($_POST['yop_poll_options']) && count($_POST['yop_poll_options']) > 0) {
         foreach ($_POST['yop_poll_options'] as $poll_option_field => $poll_option_value) {
             $new_poll->{$poll_option_field} = $poll_option_value;
         }
     }
     if (isset($_POST['yop_poll_options']['use_the_same_template_for_widget'])) {
         $new_poll->use_the_same_template_for_widget = 'yes';
         $new_poll->widget_template_width = $new_poll->template_width;
         $new_poll->widget_template = $new_poll->template;
     } else {
         $new_poll->use_the_same_template_for_widget = 'no';
     }
     $questions = array();
     if (isset($_POST['yop_poll_question']) && is_array($_POST['yop_poll_question']) && count($_POST['yop_poll_question']) > 0) {
         foreach ($_POST['yop_poll_question'] as $question_args) {
             $new_question = new YOP_POLL_Question_Model($question_args['question_id']);
             $new_question->question = trim($question_args['question']);
             $new_question->type = trim($question_args['type']);
             $new_question->question_modified = current_time('mysql');
             $new_question->poll_order = intval($question_args['poll_order']);
             if (!$new_question->exists()) {
                 //for insert
                 $new_question->question_author = $GLOBALS['current_user']->ID;
                 $new_question->question_date = current_time('mysql');
                 $new_question->question_status = 'active';
             }
             //question options area
             if (isset($question_args['options']) && is_array($question_args['options']) && count($question_args['options']) > 0) {
                 foreach ($question_args['options'] as $question_option_field => $question_option_value) {
                     $new_question->{$question_option_field} = $question_option_value;
                 }
             }
             $custom_fields = array();
             //question custom fields area
             if (isset($question_args['custom_fields']) && is_array($question_args['custom_fields']) && count($question_args['custom_fields']) > 0) {
                 foreach ($question_args['custom_fields'] as $question_custom_field) {
                     $cf_id = isset($question_custom_field['id']) ? trim($question_custom_field['id']) : 0;
                     $new_custom_field = new YOP_POLL_Custom_Field_Model($cf_id);
                     $new_custom_field->custom_field = trim($question_custom_field['custom_field']);
                     $new_custom_field->required = isset($question_custom_field['required']) ? trim($question_custom_field['required']) : 'no';
                     $new_custom_field->status = "active";
                     if ($new_custom_field->custom_field == "") {
                         $response['success'] = 0;
                         $response['id'] = -1;
                         $response['error'] = 1;
                         $response['message'] = __yop_poll('Custom Field') . ' ' . $question_custom_field['order'] . ' ' . __yop_poll('from Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                         wp_die(json_encode($response));
                     }
                     $custom_fields[] = $new_custom_field;
                 }
             }
             $new_question->custom_fields = $custom_fields;
             $answers = array();
             if (isset($_POST['yop_poll_answer'][$question_args['question_id']]) && is_array($_POST['yop_poll_answer'][$question_args['question_id']]) && count($_POST['yop_poll_answer'][$question_args['question_id']]) > 0) {
                 foreach ($_POST['yop_poll_answer'][$question_args['question_id']] as $answer_args) {
                     $new_answer = new YOP_POLL_Answer_Model($answer_args['answer_id']);
                     $new_answer->answer = trim($answer_args['answer']);
                     $new_answer->type = trim($answer_args['type']);
                     if (isset($answer_args['is_default_answer'])) {
                         $new_answer->is_default_answer = 'yes';
                     } else {
                         $new_answer->is_default_answer = 'no';
                     }
                     $new_answer->description = "";
                     if ($new_answer->type == 'video') {
                         $new_answer->description = trim($answer_args['description_video']);
                     } else {
                         if ($new_answer->type == 'image') {
                             $new_answer->description = trim($answer_args['description_image']);
                         }
                     }
                     $new_answer->question_order = trim($answer_args['question_order']);
                     $new_answer->answer_modified = current_time('mysql');
                     if (!$new_answer->exists()) {
                         //for insert
                         $new_answer->answer_author = $GLOBALS['current_user']->ID;
                         $new_answer->answer_date = current_time('mysql');
                         $new_answer->answer_status = 'active';
                     }
                     if ($new_answer->answer == '') {
                         $response['success'] = 0;
                         $response['id'] = -1;
                         $response['error'] = 1;
                         $response['message'] = __yop_poll('Answer') . ' ' . $new_answer->question_order . ' ' . __yop_poll('from Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                         wp_die(json_encode($response));
                     }
                     $answers[] = $new_answer;
                 }
             }
             $new_question->answers = $answers;
             if ($new_question->question == '') {
                 $response['success'] = 0;
                 $response['id'] = -1;
                 $response['error'] = 1;
                 $response['message'] = __yop_poll('Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                 wp_die(json_encode($response));
             }
             $questions[] = $new_question;
         }
     }
     $new_poll->questions = $questions;
     if ($preview) {
         $new_poll->ID = 'preview';
         return $new_poll->return_poll_html(array('tr_id' => '', 'location' => 'page', 'load_css' => true, 'load_js' => false));
     } else {
         if (!$new_poll->exists() && YOP_POLL_Poll_Model::get_data_by('name', $new_poll->poll_name)) {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('This poll already exists! Please choose another name!');
             wp_die(json_encode($response));
         }
         if ($new_poll->exists() && YOP_POLL_Poll_Model::get_other_model_data_by('name', $new_poll->poll_name, $new_poll->id)) {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('This poll already exists! Please choose another name!');
             wp_die(json_encode($response));
         }
         if ($new_poll->save()) {
             self::save_poll_order($new_poll->get('ID'), $_POST['poll_archive_order']);
             $response['success'] = 1;
             $response['id'] = $new_poll->ID;
             $response['error'] = 0;
             $response['message'] = __yop_poll('Poll successfully saved!');
             wp_die(json_encode($response));
         } else {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('Poll couldn`t be saved!');
             wp_die(json_encode($response));
         }
     }
 }
Beispiel #3
0
 public function return_yop_poll($id, $results, $tr_id = '', $show_results = "", $offset = 0)
 {
     //$pro_options = get_option( 'yop_poll_pro_options' );
     $options = get_option('yop_poll_options');
     require_once YOP_POLL_MODELS . "poll_model.php";
     $poll_unique_id = uniqid('_yp');
     $yop_poll_model = new YOP_POLL_Poll_Model($id);
     $yop_poll_model->unique_id = $poll_unique_id;
     if (!$yop_poll_model->ID) {
         return '';
     }
     $yop_poll_public_config_general = array('ajax' => array('url' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'vote_action' => 'yop_poll_do_vote', 'yop_poll_show_vote_options' => 'yop_poll_show_vote_options', 'captcha_action' => 'yop_poll_show_captcha', 'view_results_action' => 'yop_poll_view_results', 'back_to_vote_action' => 'yop_poll_back_to_vote', 'is_wordpress_user_action' => 'yop_poll_is_wordpress_user', 'is_facebook_user_action' => 'yop_poll_is_facebook_user'), 'pro' => array(), 'yop_poll_version' => YOP_POLL_VERSION, 'vote_with_wordpress_login_url' => wp_login_url(admin_url('admin-ajax.php?action=yop_poll_set_wordpress_vote', is_ssl() ? 'https' : 'http')), 'vote_with_facebook_ajax_url' => admin_url('admin-ajax.php?action=yop_poll_set_facebook_vote', is_ssl() ? 'https' : 'http'));
     $vote_permisions_types = 0;
     if (in_array('registered', $yop_poll_model->vote_permisions)) {
         if ('yes' == $yop_poll_model->vote_permisions_wordpress) {
             $vote_permisions_types += 1;
         }
         if ('yes' == $yop_poll_model->vote_permisions_anonymous && in_array('guest', $yop_poll_model->vote_permisions) || 'yes' == $yop_poll_model->vote_permisions_anonymous && in_array('registered', $yop_poll_model->vote_permisions)) {
             $vote_permisions_types += 2;
         }
     } else {
         if (in_array('guest', $yop_poll_model->vote_permisions)) {
             if ('yes' == $yop_poll_model->vote_permisions_anonymous && in_array('guest', $yop_poll_model->vote_permisions)) {
                 $vote_permisions_types += 2;
             }
         }
     }
     if ('yes' == $options["use_default_loading_image"]) {
         $loading_image_src = YOP_POLL_URL . 'images/loading36x36.gif';
     } else {
         $loading_image_src = $options["loading_image_url"];
     }
     if ($results) {
         $yop_poll_model->vote = true;
     }
     $template = $yop_poll_model->return_poll_html(array('tr_id' => $tr_id, 'location' => 'page', 'load_css' => true, 'load_js' => true, 'show_results' => $show_results));
     $yop_poll_public_config = array('poll_options' => array('vote_permisions' => $yop_poll_model->vote_permisions, 'vote_permisions_facebook_label' => $yop_poll_model->vote_permisions_facebook_label, 'vote_permisions_wordpress_label' => $yop_poll_model->vote_permisions_wordpress_label, 'vote_permisions_anonymous_label' => $yop_poll_model->vote_permisions_anonymous_label, 'vote_permisions_google_label' => $yop_poll_model->vote_permisions_google_label, 'vote_permisions_types' => $vote_permisions_types, 'share_after_vote' => $yop_poll_model->share_after_vote, 'share_name' => $yop_poll_model->share_name, 'share_caption' => $yop_poll_model->share_caption, 'share_description' => $yop_poll_model->share_description, 'share_picture' => $yop_poll_model->share_picture, 'share_poll_name' => $yop_poll_model->poll['name'], 'share_link' => $yop_poll_model->poll_page_url == '' ? site_url() : $yop_poll_model->poll_page_url, 'redirect_after_vote' => $yop_poll_model->redirect_after_vote, 'redirect_after_vote_url' => $yop_poll_model->redirect_after_vote_url, 'facebook_share_after_vote' => $yop_poll_model->facebook_share_after_vote), 'loading_image_src' => $loading_image_src, 'loading_image_alt' => __yop_poll('Loading'));
     $tabulate['results'] = false;
     $tabulate['answers'] = false;
     $tabulate['orizontal_answers'] = 0;
     $tabulate['orizontal_results'] = 0;
     wp_enqueue_script('yop-poll-public-js', YOP_POLL_URL . "js/yop-poll-public.js", array('jquery'), YOP_POLL_VERSION, true);
     foreach ($yop_poll_model->questions as $question) {
         $answers_tabulated_cols = 1;
         //vertical display
         $results_tabulated_cols = 1;
         $include_others = false;
         $display_answers = array('text', 'image', 'video');
         if (isset($question->allow_other_answers) && 'yes' == $question->allow_other_answers) {
             if (isset($question->display_other_answers_values) && 'yes' == $question->display_other_answers_values) {
                 $include_others = true;
                 $display_answers = array('text', 'image', 'video', 'other');
             }
         }
         if ('orizontal' == $question->display_answers) {
             $ans_no = $question->countanswers($display_answers, $include_others);
             if ($ans_no > 0) {
                 $tabulate['orizontal_answers'] = $ans_no;
             }
             if (isset($question->allow_other_answers) && 'yes' == $question->allow_other_answers) {
                 $tabulate['orizontal_answers']++;
             }
         }
         if ('orizontal' == $question->display_results) {
             $ans_no = $question->countanswers($display_answers, $include_others);
             if ($ans_no > 0) {
                 $tabulate['orizontal_results'] = $ans_no;
             }
         }
         if ('tabulated' == $question->display_answers) {
             $tabulate['answers'] = true;
         }
         if ('tabulated' == $question->display_results) {
             $tabulate['results'] = true;
         }
     }
     wp_enqueue_script('yop-poll-public-js', YOP_POLL_URL . "js/yop-poll-public.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_localize_script('yop-poll-public-js', 'tabulate', $tabulate);
     wp_enqueue_script('yop-poll-supercookie-js', YOP_POLL_URL . "js/yop-poll-supercookie.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('superCookie-min-js', YOP_POLL_URL . "js/super-cookie/superCookie-min.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('swfobject-js', YOP_POLL_URL . "js/super-cookie/swfobject/swfobject.js", array('jquery'), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-jquery-popup-windows', YOP_POLL_URL . "js/jquery.popupWindow.js", array(), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-jquery-base64', YOP_POLL_URL . "js/yop-poll-jquery.base64.min.js", array(), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-json-2', YOP_POLL_URL . "js/yop-poll-json2.js", array(), YOP_POLL_VERSION, true);
     wp_enqueue_script('yop-poll-user-defined_' . $yop_poll_model->ID . $poll_unique_id, add_query_arg(array('id' => $id, 'location' => 'page', 'unique_id' => $poll_unique_id), admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http') . '?action=yop_poll_load_js'), array('jquery'), YOP_POLL_VERSION, true);
     wp_localize_script('yop-poll-public-js', 'yop_poll_public_config_general', $yop_poll_public_config_general);
     wp_localize_script('yop-poll-public-js', 'yop_poll_public_config_' . $yop_poll_model->ID . $poll_unique_id, $yop_poll_public_config);
     // wp_enqueue_style( 'yop-poll-public-css', "{$this->_config->plugin_url}css/yop-poll-admin.css", array(), YOP_POLL_VERSION );
     /*wp_enqueue_style( 'yop-poll-public-css', "{$this->_config->plugin_url}/css/yop-poll-public.css", array(), $this->_config->version );
       wp_enqueue_script( 'jquery' );
       wp_enqueue_script( 'yop-poll-jquery-popup-windows', "{$this->_config->plugin_url}/js/jquery.popupWindow.js", array(), $this->_config->version, true );
       wp_enqueue_script( 'yop-poll-user-defined_' . $id . $poll_unique_id, add_query_arg( array( 'id' => $id, 'location' => 'page', 'unique_id' => $poll_unique_id ), admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ) . '?action=yop_poll_load_js' ), array( 'jquery' ), $this->_config->version, true );
       wp_enqueue_script( 'yop-poll-public-js', "{$this->_config->plugin_url}js/yop-poll-public.js", array(), $this->_config->version, true );
       wp_enqueue_script( 'yop-poll-json2', "{$this->_config->plugin_url}/js/yop-poll-json2.js", array(), $this->_config->version, true );
       wp_enqueue_script( 'yop-poll-jquery-base64', "{$this->_config->plugin_url}/js/yop-poll-jquery.base64.min.js", array(), $this->_config->version, true );
       */
     return $template;
 }
Beispiel #4
0
 public function yop_poll_back_to_vote()
 {
     $error = '';
     $success = '';
     $message = '';
     if (!isset($_POST) || empty($_POST)) {
         $error = __('Bad Request! Try later!', 'yop_poll');
         print '[ajax-response]' . json_encode(array('error' => $error, 'success' => $success)) . '[/ajax-response]';
         die;
     }
     if (is_admin()) {
         $poll_id = isset($_REQUEST['poll_id']) ? $_REQUEST['poll_id'] : 0;
         $unique_id = isset($_REQUEST['unique_id']) ? $_REQUEST['unique_id'] : '';
         $location = isset($_REQUEST['location']) ? $_REQUEST['location'] : 'page';
         $tr_id = isset($_REQUEST['tr_id']) ? $_REQUEST['tr_id'] : '';
         $unique_id = strip_tags(xss_clean($unique_id));
         $location = strip_tags(xss_clean($location));
         $tr_id = strip_tags(xss_clean($tr_id));
         if (wp_verify_nonce($_REQUEST['nonce'], 'yop_poll-' . $poll_id . $unique_id . '-user-actions')) {
             if ($poll_id) {
                 require_once YOP_POLL_MODELS . 'poll_model.php';
                 $yop_poll_model = new YOP_POLL_Poll_Model($poll_id);
                 $yop_poll_model->unique_id = $unique_id;
                 $poll_html = do_shortcode($yop_poll_model->return_poll_html(array('tr_id' => $tr_id, 'location' => $location)));
                 if ($poll_html) {
                     $message = $poll_html;
                     $success = $yop_poll_model->success;
                 } else {
                     $error = $yop_poll_model->error;
                 }
                 unset($yop_poll_model);
             } else {
                 $error = __('Invalid Request! Try later!', 'yop_poll');
             }
         } else {
             $error = __('Bad Request!Try again later', 'yop_poll');
         }
     }
     print '[ajax-response]' . json_encode(array('error' => $error, 'success' => $success, 'message' => $message)) . '[/ajax-response]';
     die;
 }