| 1 |
<?php |
| 2 |
ob_start(); |
| 3 |
|
| 4 |
class Polls_List_Table extends WP_List_Table { |
| 5 |
private $plugin_name; |
| 6 |
private $title_length; |
| 7 |
|
| 8 |
/** Class constructor */ |
| 9 |
public function __construct( $plugin_name ) { |
| 10 |
$this->plugin_name = $plugin_name; |
| 11 |
$this->title_length = Poll_Maker_Ays_Admin::get_listtables_title_length('polls'); |
| 12 |
parent::__construct(array( |
| 13 |
'singular' =>esc_html__('Poll', "poll-maker"), //singular name of the listed records |
| 14 |
'plural' =>esc_html__('Polls', "poll-maker"), //plural name of the listed records |
| 15 |
'ajax' => false, //does this table support ajax? |
| 16 |
)); |
| 17 |
add_action('admin_notices', array($this, 'poll_notices')); |
| 18 |
add_filter( 'default_hidden_columns', array( $this, 'get_hidden_columns'), 10, 2 ); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_categories() { |
| 22 |
global $wpdb; |
| 23 |
$cat_table = esc_sql($wpdb->prefix."ayspoll_categories"); |
| 24 |
$sql = "SELECT * FROM ".$cat_table; |
| 25 |
|
| 26 |
return $wpdb->get_results($sql, 'ARRAY_A'); |
| 27 |
} |
| 28 |
|
| 29 |
public function display_tablenav( $which ) { |
| 30 |
?> |
| 31 |
<div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 32 |
|
| 33 |
<div class="alignleft actions"> |
| 34 |
<?php $this->bulk_actions( $which ); ?> |
| 35 |
</div> |
| 36 |
<?php |
| 37 |
$this->extra_tablenav( $which ); |
| 38 |
$this->pagination( $which ); |
| 39 |
?> |
| 40 |
<br class="clear" /> |
| 41 |
</div> |
| 42 |
<?php |
| 43 |
} |
| 44 |
|
| 45 |
public function extra_tablenav($which) { |
| 46 |
global $wpdb; |
| 47 |
$category_table = $wpdb->prefix . 'ayspoll_categories'; |
| 48 |
$titles_sql = "SELECT ".$category_table.".title,".$category_table.".id FROM ".$category_table; |
| 49 |
$cat_titles = $wpdb->get_results($titles_sql); |
| 50 |
$cat_id = null; |
| 51 |
if( isset( $_GET['filterby'] )){ |
| 52 |
$cat_id = intval($_GET['filterby']); |
| 53 |
} |
| 54 |
|
| 55 |
if( isset( $_GET['filterbyauthor'] )){ |
| 56 |
$author_id_select = absint( sanitize_text_field( $_GET['filterbyauthor'] ) ); |
| 57 |
} |
| 58 |
|
| 59 |
if( isset( $_GET['filterbytype'] )){ |
| 60 |
$type_select = sanitize_text_field( $_GET['filterbytype'] ); |
| 61 |
} |
| 62 |
|
| 63 |
$categories_select = array(); |
| 64 |
foreach($cat_titles as $key => $cat_title){ |
| 65 |
$selected = ""; |
| 66 |
if($cat_id === intval($cat_title->id)){ |
| 67 |
$selected = "selected"; |
| 68 |
} |
| 69 |
$categories_select[$cat_title->id]['title'] = $cat_title->title; |
| 70 |
$categories_select[$cat_title->id]['selected'] = $selected; |
| 71 |
$categories_select[$cat_title->id]['id'] = $cat_title->id; |
| 72 |
} |
| 73 |
sort($categories_select); |
| 74 |
|
| 75 |
$cat_id = null; |
| 76 |
|
| 77 |
$authors = array(); |
| 78 |
$users_sql = "SELECT `styles` FROM " .$wpdb->prefix . "ayspoll_polls"; |
| 79 |
$users = $wpdb->get_results($users_sql, "ARRAY_A"); |
| 80 |
|
| 81 |
foreach ($users as $user_key => $user) { |
| 82 |
$options = (isset($user['styles']) && $user['styles'] != '') ? json_decode( $user['styles'], 'ARRAY_A' ) : ''; |
| 83 |
$author = (isset( $options['author'] ) && !empty($options['author'])) ? $options['author'] : array(); |
| 84 |
|
| 85 |
if (!is_array($author)) { |
| 86 |
$author = json_decode($author, 'ARRAY_A'); |
| 87 |
} |
| 88 |
|
| 89 |
if (!empty($author)) { |
| 90 |
$author_id = (isset($author['id']) && $author['id'] != '') ? intval($author['id']) : ''; |
| 91 |
$author_name = (isset($author['name']) && $author['name'] != '') ? sanitize_text_field($author['name']) : ''; |
| 92 |
$authors[$author_id] = $author_name; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
$types = array(); |
| 97 |
$type_sql = "SELECT DISTINCT `type` FROM " .$wpdb->prefix . "ayspoll_polls"; |
| 98 |
$existed_types = $wpdb->get_results( $type_sql, "ARRAY_A"); |
| 99 |
|
| 100 |
foreach( $existed_types as $type_key => $type){ |
| 101 |
$curent_type = ( isset( $type['type'] ) && $type['type'] != '') ? sanitize_text_field($type['type']) : ''; |
| 102 |
$types[$type_key] = $curent_type; |
| 103 |
} |
| 104 |
|
| 105 |
?> |
| 106 |
<div id="poll-filter-div-<?php echo esc_attr( $which ); ?>" class="alignleft actions bulkactions"> |
| 107 |
<select name="filterby-<?php echo esc_attr($which); ?>" id="bulk-action-selector-<?php echo esc_attr($which); ?>"> |
| 108 |
<option value=""><?php echo esc_html__('Select Category', "poll-maker")?></option> |
| 109 |
<?php |
| 110 |
foreach($categories_select as $key => $cat_title){ |
| 111 |
echo "<option ".$cat_title['selected']." value='".$cat_title['id']."'>".$cat_title['title']."</option>"; |
| 112 |
} |
| 113 |
?> |
| 114 |
</select> |
| 115 |
<select name="filterbyauthor-<?php echo esc_attr( $which ); ?>" id="bulk-action-selector-<?php echo esc_attr( $which ); ?>"> |
| 116 |
<option value=""><?php echo esc_html__('Select Author', "poll-maker")?></option> |
| 117 |
<?php |
| 118 |
foreach ($authors as $author_key => $author) { |
| 119 |
$user_selected = ( isset($author_id_select) && $author_key == $author_id_select ) ? "selected" : ""; |
| 120 |
|
| 121 |
echo "<option " . $user_selected . " value='" . $author_key . "'>" . $author . "</option>"; |
| 122 |
} |
| 123 |
?> |
| 124 |
</select> |
| 125 |
<select name="filterbytype-<?php echo esc_attr( $which ); ?>" id="bulk-action-selector-<?php echo esc_attr( $which ); ?>"> |
| 126 |
<option value=""><?php echo esc_html__('Select Type', "poll-maker"); ?></option> |
| 127 |
<?php |
| 128 |
foreach( $types as $type_key => $type){ |
| 129 |
$user_selected_type = ( isset($type_select) && $type == $type_select ) ? "selected" : ""; |
| 130 |
echo "<option ".$user_selected_type." value='".$type."'>".$type."</option>"; |
| 131 |
} |
| 132 |
?> |
| 133 |
</select> |
| 134 |
<input type="button" id="doaction-<?php echo esc_attr($which); ?>" class="ays-poll-question-tab-all-filter-button-<?php echo esc_attr($which); ?> button" value="<?php echo esc_attr__('Filter', "poll-maker"); ?>"> |
| 135 |
</div> |
| 136 |
<a href="?page=<?php echo esc_attr( $_REQUEST['page'] ); ?>" class="button actions_style"><?php echo esc_html__( "Clear filters", "poll-maker" ); ?></a> |
| 137 |
<?php |
| 138 |
} |
| 139 |
|
| 140 |
protected function get_views() { |
| 141 |
$published_count = $this->published_polls_count(); |
| 142 |
$unpublished_count = $this->unpublished_polls_count(); |
| 143 |
$all_count = $this->all_record_count(); |
| 144 |
$selected_all = ""; |
| 145 |
$selected_0 = ""; |
| 146 |
$selected_1 = ""; |
| 147 |
if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){ |
| 148 |
|
| 149 |
$fstatus = absint( $_REQUEST['fstatus'] ); |
| 150 |
|
| 151 |
switch( $fstatus ){ |
| 152 |
case 0: |
| 153 |
$selected_0 = " style='font-weight:bold;' "; |
| 154 |
break; |
| 155 |
case 1: |
| 156 |
$selected_1 = " style='font-weight:bold;' "; |
| 157 |
break; |
| 158 |
default: |
| 159 |
$selected_all = " style='font-weight:bold;' "; |
| 160 |
break; |
| 161 |
} |
| 162 |
}else{ |
| 163 |
$selected_all = " style='font-weight:bold;' "; |
| 164 |
} |
| 165 |
|
| 166 |
$admin_url = get_admin_url( null, 'admin.php' ); |
| 167 |
$get_properties = http_build_query($_GET); |
| 168 |
|
| 169 |
$status_links_url = $admin_url . "?" . $get_properties; |
| 170 |
$publish_url = esc_url( add_query_arg('fstatus', 1, $status_links_url) ); |
| 171 |
$unpublish_url = esc_url( add_query_arg('fstatus', 0, $status_links_url) ); |
| 172 |
|
| 173 |
$status_links = array( |
| 174 |
"all" => "<a ".$selected_all." href='?page=".esc_attr( $_REQUEST['page'] )."'>".esc_html__( 'All', "poll-maker" )." (".$all_count.")</a>", |
| 175 |
"published" => "<a ".$selected_1." href='". $publish_url ."'>".esc_html__( 'Published', "poll-maker" )." (".$published_count.")</a>", |
| 176 |
"unpublished" => "<a ".$selected_0." href='". $unpublish_url ."'>".esc_html__( 'Unpublished', "poll-maker" )." (".$unpublished_count.")</a>" |
| 177 |
); |
| 178 |
return $status_links; |
| 179 |
} |
| 180 |
|
| 181 |
public function add_or_edit_polls( $data, $id = null, $ays_change_type = "" ) { |
| 182 |
global $allowedtags; |
| 183 |
$old_allowedtags = $allowedtags; |
| 184 |
$default_attribs = array( |
| 185 |
'id' => array(), |
| 186 |
'class' => array(), |
| 187 |
'title' => array(), |
| 188 |
'style' => array(), |
| 189 |
); |
| 190 |
$allowedtags = array( |
| 191 |
'div' => $default_attribs, |
| 192 |
'span' => $default_attribs, |
| 193 |
'p' => $default_attribs, |
| 194 |
'a' => array_merge($default_attribs, array( |
| 195 |
'href' => array(), |
| 196 |
'target' => array('_blank', '_top'), |
| 197 |
)), |
| 198 |
'input' => array_merge($default_attribs, array( |
| 199 |
'type' => array(), |
| 200 |
'name' => array(), |
| 201 |
'value' => array(), |
| 202 |
)), |
| 203 |
'textarea' => array_merge($default_attribs, array( |
| 204 |
'type' => array(), |
| 205 |
'name' => array(), |
| 206 |
)), |
| 207 |
'u' => $default_attribs, |
| 208 |
'i' => $default_attribs, |
| 209 |
'q' => $default_attribs, |
| 210 |
'b' => $default_attribs, |
| 211 |
'ul' => $default_attribs, |
| 212 |
'dl' => $default_attribs, |
| 213 |
'ol' => $default_attribs, |
| 214 |
'li' => $default_attribs, |
| 215 |
'br' => $default_attribs, |
| 216 |
'hr' => $default_attribs, |
| 217 |
'strong' => $default_attribs, |
| 218 |
'blockquote' => $default_attribs, |
| 219 |
'del' => $default_attribs, |
| 220 |
'strike' => $default_attribs, |
| 221 |
'em' => $default_attribs, |
| 222 |
'code' => $default_attribs, |
| 223 |
); |
| 224 |
|
| 225 |
global $wpdb; |
| 226 |
$poll_table = esc_sql($wpdb->prefix . 'ayspoll_polls'); |
| 227 |
$answer_table = esc_sql($wpdb->prefix . 'ayspoll_answers'); |
| 228 |
if (isset($data["poll_action"]) && wp_verify_nonce($data["poll_action"], 'poll_action')) { |
| 229 |
|
| 230 |
$poll_allowed_html = Poll_Maker_Data::ays_poll_custom_allowed_html(); |
| 231 |
|
| 232 |
$title = isset($data['ays-poll-title']) && $data['ays-poll-title'] != "" ? sanitize_text_field($data['ays-poll-title']) : "Default title"; |
| 233 |
$show_title = isset($data['show_title']) && $data['show_title'] == 'show' ? 1 : 0; |
| 234 |
$limit_users = isset($data['apm_limit_users']) && $data['apm_limit_users'] == 'on' ? 1 : 0; |
| 235 |
$limit_users_method = isset($data['ays_limit_method']) ? sanitize_text_field($data['ays_limit_method']) : 'ip'; |
| 236 |
$limit_users_msg = isset($data['ays_limitation_message']) ? wp_kses( $data['ays_limitation_message'], $poll_allowed_html ) : ""; |
| 237 |
$limit_users_url = isset($data['ays_redirect_url']) ? wp_http_validate_url($data['ays_redirect_url']) : ""; |
| 238 |
$limit_users_delay = isset($data['ays_redirection_delay']) ? absint($data['ays_redirection_delay']) : 0; |
| 239 |
$limit_users_role_enable = isset($data['ays_enable_restriction_pass']) && $data['ays_enable_restriction_pass'] == 'on' ? 1 : 0; |
| 240 |
$limit_users_role = (isset($data["ays_users_roles"]) && !empty($data["ays_users_roles"])) ? $data["ays_users_roles"] : array(); |
| 241 |
$limit_users_role_msg = isset($data['restriction_pass_message']) ? wp_kses( $data['restriction_pass_message'], $poll_allowed_html ) : ""; |
| 242 |
|
| 243 |
$limit_users_logged_enable = (isset($data['ays_enable_logged_users']) && $data['ays_enable_logged_users'] == 'on') || $limit_users_role_enable ? 1 : 0; |
| 244 |
$limit_users_logged_msg = isset($data['ays_enable_logged_users_message']) ? wp_kses( $data['ays_enable_logged_users_message'], $poll_allowed_html ) : ""; |
| 245 |
|
| 246 |
$hide_results = isset($data['ays-poll-hide-results']) && 'hide' == $data['ays-poll-hide-results'] ? 1 : 0; |
| 247 |
$hide_result_message = isset($data['ays_poll_result_message']) && 'hide' == $data['ays_poll_result_message'] ? 1 : 0; |
| 248 |
|
| 249 |
$hide_results_text = isset( $data['ays-poll-hide-results-text'] ) && $data['ays-poll-hide-results-text'] != '' ? wp_kses( $data['ays-poll-hide-results-text'], $poll_allowed_html ) : ''; |
| 250 |
|
| 251 |
$ays_result_message = isset( $data['ays_result_message'] ) && $data['ays_result_message'] != '' ? wp_kses( $data['ays_result_message'], $poll_allowed_html ) : ''; |
| 252 |
|
| 253 |
$allow_not_vote = isset($data['ays-poll-allow-not-vote']) && 'allow' == $data['ays-poll-allow-not-vote'] ? 1 : 0; |
| 254 |
$show_social = isset($data['ays-poll-show-social']) && 'show' == $data['ays-poll-show-social'] ? 1 : 0; |
| 255 |
$poll_social_buttons_heading = ( isset( $data[ 'ays_poll_social_buttons_heading' ] ) && $data[ 'ays_poll_social_buttons_heading' ] != '' ) ? wp_kses( $data['ays_poll_social_buttons_heading'], $poll_allowed_html ) : ''; |
| 256 |
$poll_show_social_ln = isset($data['ays_poll_enable_linkedin_share_button']) && $data['ays_poll_enable_linkedin_share_button'] == "on" ? "on" : "off"; |
| 257 |
$poll_show_social_fb = isset($data['ays_poll_enable_facebook_share_button']) && $data['ays_poll_enable_facebook_share_button'] == "on" ? "on" : "off"; |
| 258 |
$poll_show_social_tr = isset($data['ays_poll_enable_twitter_share_button']) && $data['ays_poll_enable_twitter_share_button'] == "on" ? "on" : "off"; |
| 259 |
$poll_show_social_vk = isset($data['ays_poll_enable_vkontakte_share_button']) && $data['ays_poll_enable_vkontakte_share_button'] == "on" ? "on" : "off"; |
| 260 |
$categories = isset($data['ays-poll-categories']) ? ',' . implode(',', $data['ays-poll-categories']) . ',' : ',1,'; |
| 261 |
$description = isset($data['ays-poll-description']) && $data['ays-poll-description'] != '' ? sanitize_textarea_field($data['ays-poll-description']) : ""; |
| 262 |
$type = isset($data['ays-poll-type']) ? sanitize_text_field($data['ays-poll-type']) : ""; |
| 263 |
|
| 264 |
$question = isset( $data['ays_poll_question'] ) && $data['ays_poll_question'] != '' ? wp_kses( $data['ays_poll_question'], $poll_allowed_html ) : ''; |
| 265 |
|
| 266 |
$image = isset($data['ays_poll_image']) && $data['ays_poll_image'] != '' ? sanitize_url($data['ays_poll_image']): ''; |
| 267 |
|
| 268 |
if( $image != "" ){ |
| 269 |
$check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($image); |
| 270 |
|
| 271 |
if( !$check_if_current_image_exists ){ |
| 272 |
$image = ""; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
$theme_id = isset($data['ays_poll_theme']) ? absint($data['ays_poll_theme']) : 1; |
| 277 |
$main_color = isset($data['ays_poll_main_color']) ? sanitize_text_field($data['ays_poll_main_color']) : '#000000'; |
| 278 |
$text_color = isset($data['ays_poll_text_color']) ? sanitize_text_field($data['ays_poll_text_color']) : '#000000'; |
| 279 |
$button_text_color = isset($data['ays_poll_button_text_color']) ? sanitize_text_field($data['ays_poll_button_text_color']) : '#ffffff'; |
| 280 |
$button_bg_color = isset($data['ays_poll_button_bg_color']) ? sanitize_text_field($data['ays_poll_button_bg_color']) : '#000000'; |
| 281 |
$icon_color = isset($data['ays_poll_icon_color']) ? sanitize_text_field($data['ays_poll_icon_color']) : '#000000'; |
| 282 |
$bg_color = isset($data['ays_poll_bg_color']) ? sanitize_text_field($data['ays_poll_bg_color']) : '#ffffff'; |
| 283 |
$answer_bg_color = isset($data['ays_poll_answer_bg_color']) ? sanitize_text_field($data['ays_poll_answer_bg_color']) : '#FBFEF9'; |
| 284 |
$answer_hover_color = isset($data['ays_poll_answer_hover_color']) ? sanitize_text_field($data['ays_poll_answer_hover_color']) : $text_color; |
| 285 |
$answer_border_side = isset($data['ays_poll_border_side']) ? sanitize_text_field($data['ays_poll_border_side']) : 'all_sides'; |
| 286 |
$bg_image = isset($data['ays_poll_bg_image']) && $data['ays_poll_bg_image'] != '' ? sanitize_url($data['ays_poll_bg_image']): ''; |
| 287 |
// if ($bg_image != '') { |
| 288 |
// if ( !(filter_var($bg_image, FILTER_VALIDATE_URL) && wp_http_validate_url($bg_image)) ) { |
| 289 |
// // invalid URL, handle accordingly |
| 290 |
// $bg_image = ''; |
| 291 |
// } |
| 292 |
// } |
| 293 |
if( $bg_image != "" ){ |
| 294 |
$check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($bg_image); |
| 295 |
|
| 296 |
if( !$check_if_current_image_exists ){ |
| 297 |
$bg_image = ""; |
| 298 |
} |
| 299 |
} |
| 300 |
$randomize_answers = !isset($data['randomize_answers']) ? "off" : $data['randomize_answers']; |
| 301 |
$enable_asnwers_sound = !isset($data['ays_poll_enable_asnwers_sound']) ? "off" : $data['ays_poll_enable_asnwers_sound']; |
| 302 |
$icon_size = absint($data['ays_poll_icon_size']) >= 10 ? absint($data['ays_poll_icon_size']) : 24; |
| 303 |
$width = absint($data['ays_poll_width']); |
| 304 |
$width_for_mobile = ( isset( $data['ays_poll_width_for_mobile'] ) && $data['ays_poll_width_for_mobile'] != '' ) ? absint($data['ays_poll_width_for_mobile']) : 0; |
| 305 |
$btn_text = sanitize_text_field($data['ays_poll_btn_text']); |
| 306 |
$see_res_btn_text = sanitize_text_field($data['ays_poll_res_btn_text']); |
| 307 |
$border_style = sanitize_text_field($data['ays_poll_border_style']); |
| 308 |
$border_radius = sanitize_text_field($data['ays_poll_border_radius']); |
| 309 |
$border_width = sanitize_text_field($data['ays_poll_border_width']); |
| 310 |
$box_shadow_color = sanitize_text_field($data['ays_poll_box_shadow_color']); |
| 311 |
|
| 312 |
//Gradient |
| 313 |
$enable_background_gradient = isset($data['ays_enable_background_gradient']) && $data['ays_enable_background_gradient'] == "on" ? sanitize_text_field($data['ays_enable_background_gradient']) : "off"; |
| 314 |
$background_gradient_color_1 = sanitize_text_field($data['ays_background_gradient_color_1']); |
| 315 |
$background_gradient_color_2 = sanitize_text_field($data['ays_background_gradient_color_2']); |
| 316 |
$poll_gradient_direction = sanitize_text_field($data['ays_poll_gradient_direction']); |
| 317 |
/// |
| 318 |
|
| 319 |
// Redirect after submit |
| 320 |
$redirect_after_submit = ( isset( $data['ays_redirect_after_submit'] ) && $data['ays_redirect_after_submit'] == 'on' ) ? 1 : 0; |
| 321 |
|
| 322 |
$submit_redirect_url = !isset($data['ays_submit_redirect_url']) ? '' : $data['ays_submit_redirect_url']; |
| 323 |
// $submit_redirect_delay = !isset($data['ays_submit_redirect_delay']) ? '' : $data['ays_submit_redirect_delay']; |
| 324 |
/// |
| 325 |
|
| 326 |
$enable_box_shadow = isset($data['ays_poll_enable_box_shadow']) && $data['ays_poll_enable_box_shadow'] == "on" ? sanitize_text_field($data['ays_poll_enable_box_shadow']) : "off"; |
| 327 |
$enable_answer_style = isset($data['ays_poll_enable_answer_style']) && $data['ays_poll_enable_answer_style'] == "on" ? sanitize_text_field($data['ays_poll_enable_answer_style']) : "off"; |
| 328 |
$load_effect = sanitize_text_field($data['ays-poll-load-effect']); |
| 329 |
$load_gif = isset($data['ays-poll-load-gif']) ? sanitize_text_field($data['ays-poll-load-gif']) : 'plg_default'; |
| 330 |
$notify_on = isset($data['ays_notify_by_email_on']) && $data['ays_notify_by_email_on'] == 'on' ? 1 : 0; |
| 331 |
$notify_email = isset($data['ays_notify_email']) && !empty($data['ays_notify_email']) ? sanitize_email($data['ays_notify_email']) : get_option('admin_email'); |
| 332 |
$redirect_users = isset($data['ays_redirect_after_vote']) && $data['ays_redirect_after_vote'] == 'on' ? 1 : 0; |
| 333 |
$redirect_after_vote_url = isset($data['redirection_url']) ? wp_http_validate_url($data['redirection_url']) : ""; |
| 334 |
$redirect_after_vote_delay = isset($data['redirection_delay']) ? absint($data['redirection_delay']) : 0; |
| 335 |
$result_sort_type = sanitize_text_field($data['ays-poll-result-sort-type']); |
| 336 |
$poll_direction = sanitize_text_field($data['ays_poll_direction']); |
| 337 |
$published = absint(intval($data['ays_publish'])); |
| 338 |
$enable_pass_count = !isset($data['ays_enable_pass_count']) ? null : $data['ays_enable_pass_count']; |
| 339 |
|
| 340 |
$activeInterval_full = isset($data['ays-active']) ? $data['ays-active'] : ""; |
| 341 |
$activeInterval_fullArr = explode(" ",$activeInterval_full); |
| 342 |
$activeInterval = isset($activeInterval_fullArr[0]) ? $activeInterval_fullArr[0] : ""; |
| 343 |
$activeIntervalSec = isset($activeInterval_fullArr[1]) ? $activeInterval_fullArr[1] : ""; |
| 344 |
|
| 345 |
$deactiveInterval_full = isset($data['ays-deactive']) ? $data['ays-deactive'] : ""; |
| 346 |
$deactiveInterval_fullArr = explode(" ",$deactiveInterval_full); |
| 347 |
$deactiveInterval = isset($deactiveInterval_fullArr[0]) ? $deactiveInterval_fullArr[0] : ""; |
| 348 |
$deactiveIntervalSec = isset($deactiveInterval_fullArr[1]) ? $deactiveInterval_fullArr[1] : ""; |
| 349 |
|
| 350 |
$active_date_message = isset( $data['active_date_message'] ) && $data['active_date_message'] != '' ? wp_kses( $data['active_date_message'], $poll_allowed_html ) : ''; |
| 351 |
$active_date_message_soon = isset( $data['active_date_message_soon'] ) && $data['active_date_message_soon'] != '' ? wp_kses( $data['active_date_message_soon'], $poll_allowed_html ) : ''; |
| 352 |
|
| 353 |
$css = stripcslashes($data['ays_custom_css']); |
| 354 |
$active_date_check = isset($data['active_date_check']) && !empty($data['active_date_check']) ? $data['active_date_check'] : ''; |
| 355 |
$enable_restart_button = isset($data['ays_enable_restart_button']) && 'on' == $data['ays_enable_restart_button'] ? 1 : 0; |
| 356 |
$enable_vote_btn = isset($data['ays_enable_vote_button']) && 1 == $data['ays_enable_vote_button'] ? 1 : 0; |
| 357 |
$show_votes_count = isset($data['show_votes_count']) && 1 == $data['show_votes_count'] ? 1 : 0; |
| 358 |
$show_create_date = isset($data['show_poll_creation_date']) && 1 == $data['show_poll_creation_date'] ? 1 : 0; |
| 359 |
$show_author = isset($data['show_poll_author']) && 1 == $data['show_poll_author'] ? 1 : 0; |
| 360 |
$show_res_percent = isset($data['show_res_percent']) && 1 == $data['show_res_percent'] ? 1 : 0; |
| 361 |
$show_result_btn_schedule = isset($data['show_result_btn_schedule']) && 1 == $data['show_result_btn_schedule'] ? 1 : 0; |
| 362 |
$ays_poll_show_timer = isset($data['ays_poll_show_timer']) && 1 == $data['ays_poll_show_timer'] ? 1 : 0; |
| 363 |
$show_bottom_timer = isset($data['ays_show_bottom_timer']) && 1 == $data['ays_show_bottom_timer'] ? 1 : 0; |
| 364 |
$ays_show_timer_type = isset($data['ays_show_timer_type']) && !empty($data['ays_show_timer_type']) ? $data['ays_show_timer_type'] : 'countdown'; |
| 365 |
$ays_show_result_btn_see = isset($data['ays_poll_show_result_btn_see_schedule']) && !empty($data['ays_poll_show_result_btn_see_schedule']) ? $data['ays_poll_show_result_btn_see_schedule'] : 'with_see'; |
| 366 |
$info_form = isset($data['ays_poll_info_form']) && 'on' == $data['ays_poll_info_form'] ? 1 : 0; |
| 367 |
$form_fields = isset($data['ays-poll-form-fields']) ? sanitize_text_field(implode(',', $data['ays-poll-form-fields'])) : ""; |
| 368 |
$form_required_fields = isset($data['ays-poll-form-required-fields']) ? sanitize_text_field(implode(',', $data['ays-poll-form-required-fields'])) : ""; |
| 369 |
$info_form_title = isset($data['ays-poll-info-form-text']) ? wp_kses( $data['ays-poll-info-form-text'], $poll_allowed_html ) : ""; |
| 370 |
$title_bg_color = sanitize_text_field($data['ays_poll_title_bg_color']); |
| 371 |
|
| 372 |
// Poll main URL |
| 373 |
$poll_main_url = (isset( $_POST['ays_poll_main_url'] ) && $_POST['ays_poll_main_url'] != '') ? wp_kses_post( $_POST['ays_poll_main_url'] ) : ''; |
| 374 |
|
| 375 |
$changed_creation_date = (isset($data['ays_poll_change_creation_date']) && $data['ays_poll_change_creation_date'] != '') ? $data['ays_poll_change_creation_date'] : current_time( 'mysql' ) ; |
| 376 |
|
| 377 |
$author = ( isset( $data['ays_poll_author'] ) && $data['ays_poll_author'] != '' ) ? stripslashes($data['ays_poll_author']) : ''; |
| 378 |
|
| 379 |
// Change the author of the current poll |
| 380 |
$poll_create_author = ( isset($data['ays_poll_create_author']) && $data['ays_poll_create_author'] != "" ) ? absint( sanitize_text_field( $data['ays_poll_create_author'] ) ) : ''; |
| 381 |
|
| 382 |
if ( $poll_create_author != "" && $poll_create_author > 0 ) { |
| 383 |
$user = get_userdata($poll_create_author); |
| 384 |
if ( ! is_null( $user ) && $user ) { |
| 385 |
$poll_author = array( |
| 386 |
'id' => $user->ID."", |
| 387 |
'name' => $user->data->display_name |
| 388 |
); |
| 389 |
|
| 390 |
$author = json_encode($poll_author, JSON_UNESCAPED_SLASHES); |
| 391 |
} else { |
| 392 |
$author_data = json_decode($author, true); |
| 393 |
$poll_create_author = (isset( $author_data['id'] ) && $author_data['id'] != "") ? absint( sanitize_text_field( $author_data['id'] ) ) : get_current_user_id(); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
// MailChimp |
| 398 |
$enable_mailchimp = isset($data['ays_enable_mailchimp']) && $data['ays_enable_mailchimp'] == 'on' ? "on": "off"; |
| 399 |
$mailchimp_list = !isset($data['ays_mailchimp_list'])?"":$data['ays_mailchimp_list']; |
| 400 |
|
| 401 |
|
| 402 |
// Show login form for not logged in users |
| 403 |
$show_login_form = (isset($data['ays_show_login_form']) && $data['ays_show_login_form'] == "on" && $limit_users_logged_enable == 1) ? 'on' : 'off'; |
| 404 |
// Disable answer hover |
| 405 |
$disable_answer_hover = (isset($data['ays_disable_answer_hover']) && $data['ays_disable_answer_hover'] == 'on') ? 1 : 0; |
| 406 |
|
| 407 |
$custom_class = (isset($data['ays_poll_custom_class']) && $data['ays_poll_custom_class'] != '') ? $data['ays_poll_custom_class'] : ''; |
| 408 |
|
| 409 |
// Bg image positioning |
| 410 |
$poll_bg_image_position = (isset($data['ays_poll_bg_image_position']) && $data['ays_poll_bg_image_position'] != "") ? $data['ays_poll_bg_image_position'] : 'center center'; |
| 411 |
$poll_bg_img_in_finish_page = (isset($data['ays_poll_bg_img_in_finish_page']) && $data['ays_poll_bg_img_in_finish_page'] != "") ? $data['ays_poll_bg_img_in_finish_page'] : 'off'; |
| 412 |
|
| 413 |
// Results bar in RGBA |
| 414 |
$result_in_rgba = (isset($data['ays-poll-res-rgba']) && $data['ays-poll-res-rgba'] == 'on' ) ? 'on' : 'off'; |
| 415 |
|
| 416 |
// Enable View more button |
| 417 |
$enable_view_more_button = (isset($data['ays_enable_view_more_button']) && $data['ays_enable_view_more_button'] == 'on' ) ? 'on' : 'off'; |
| 418 |
$poll_view_more_button_count = (isset($data['ays_poll_view_more_button_count']) && $data['ays_poll_view_more_button_count'] != '' ) ? absint(intval($data['ays_poll_view_more_button_count'])) : 0; |
| 419 |
|
| 420 |
// Poll Min Height |
| 421 |
$poll_min_height = (isset($data['ays_poll_min_height']) && $data['ays_poll_min_height'] != '') ? absint(intval($data['ays_poll_min_height'])) : ''; |
| 422 |
|
| 423 |
// Poll answer ordering |
| 424 |
$poll_answer_ordering = (isset($data['ays_answers_sort_select']) && $data['ays_answers_sort_select'] != '') ? sanitize_text_field($data['ays_answers_sort_select']) : ''; |
| 425 |
|
| 426 |
// Poll answers font size |
| 427 |
$poll_answer_font_size = (isset($data['ays_answer_font_size']) && $data['ays_answer_font_size'] != '') ? sanitize_text_field($data['ays_answer_font_size']) : '16'; |
| 428 |
|
| 429 |
// Poll answers font size on mobile |
| 430 |
$poll_answer_font_size_mobile = (isset($data['ays_poll_answer_font_size_mobile']) && $data['ays_poll_answer_font_size_mobile'] != '') ? sanitize_text_field($data['ays_poll_answer_font_size_mobile']) : '16'; |
| 431 |
|
| 432 |
// Poll show passed users in result page |
| 433 |
$poll_show_passed_users = (isset($data['ays_poll_show_users']) && sanitize_text_field($data['ays_poll_show_users']) == 'on') ? 'on' : 'off'; |
| 434 |
$poll_show_passed_users_count = (isset($data['ays_poll_show_users_count']) && $data['ays_poll_show_users_count'] != '') ? intval(sanitize_text_field($data['ays_poll_show_users_count'])) : 3; |
| 435 |
|
| 436 |
// Poll Logo image |
| 437 |
$poll_logo_image = (isset($data['ays_poll_logo_image']) && $data['ays_poll_logo_image'] != '') ? sanitize_url($data['ays_poll_logo_image']) : ''; |
| 438 |
// if ($poll_logo_image != '') { |
| 439 |
// if ( !(filter_var($poll_logo_image, FILTER_VALIDATE_URL) && wp_http_validate_url($poll_logo_image)) ) { |
| 440 |
// // invalid URL, handle accordingly |
| 441 |
// $poll_logo_image = ''; |
| 442 |
// } |
| 443 |
// } |
| 444 |
if( $poll_logo_image != "" ){ |
| 445 |
$check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($poll_logo_image); |
| 446 |
|
| 447 |
if( !$check_if_current_image_exists ){ |
| 448 |
$poll_logo_image = ""; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
// Poll schedule container on/off |
| 453 |
$poll_show_container = (isset($data['ays_show_poll_container']) && $data['ays_show_poll_container'] == 'on') ? 'on' : 'off'; |
| 454 |
|
| 455 |
// Poll see results button in limitations |
| 456 |
$poll_see_result_button = (isset($data['ays_see_result_show']) && $data['ays_see_result_show'] == 'on') ? 'on' : 'off'; |
| 457 |
$poll_see_result_radio = (isset($data['ays_poll_see_result_show']) && $data['ays_poll_see_result_show'] != '') ? sanitize_text_field($data['ays_poll_see_result_show']) : ''; |
| 458 |
|
| 459 |
// loader font size |
| 460 |
$poll_loader_font_size = (isset($data['ays_loader_font_size']) && $data['ays_loader_font_size'] != '') ? sanitize_text_field($data['ays_loader_font_size']) : '64'; |
| 461 |
if(intval($poll_loader_font_size) <= 0){ |
| 462 |
$poll_loader_font_size = ''; |
| 463 |
} |
| 464 |
|
| 465 |
// Show answers numbering |
| 466 |
$show_answers_numbering = (isset($_POST['ays_poll_show_answers_numbering']) && sanitize_text_field( $_POST['ays_poll_show_answers_numbering']) != '') ? sanitize_text_field( $_POST['ays_poll_show_answers_numbering'] ) : 'none'; |
| 467 |
|
| 468 |
// Poll border color |
| 469 |
$poll_border_color = (isset($data['ays_poll_border_color']) && $data['ays_poll_border_color'] != '') ? sanitize_text_field($data['ays_poll_border_color']) : ''; |
| 470 |
|
| 471 |
// Poll load effect message |
| 472 |
$poll_effect_message = (isset($data['ays_poll_load_effect_message']) && $data['ays_poll_load_effect_message'] != '') ? sanitize_text_field($data['ays_poll_load_effect_message']) : ''; |
| 473 |
|
| 474 |
// Box Shadow X offset |
| 475 |
$poll_box_shadow_x_offset = (isset($data['ays_poll_box_shadow_x_offset']) && $data['ays_poll_box_shadow_x_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_x_offset'] ) ) : 0; |
| 476 |
|
| 477 |
// Box Shadow Y offset |
| 478 |
$poll_box_shadow_y_offset = (isset($data['ays_poll_box_shadow_y_offset']) && $data['ays_poll_box_shadow_y_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_y_offset'] ) ) : 0; |
| 479 |
|
| 480 |
// Box Shadow Z offset |
| 481 |
$poll_box_shadow_z_offset = (isset($data['ays_poll_box_shadow_z_offset']) && $data['ays_poll_box_shadow_z_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_z_offset'] ) ) : 15; |
| 482 |
|
| 483 |
// Vote Reason |
| 484 |
$poll_vote_reason = (isset($data['ays-poll-reason']) && $data['ays-poll-reason'] == 'on' ) ? "on" : "off"; |
| 485 |
|
| 486 |
// Allow multivote |
| 487 |
$poll_allow_multivote = isset($data['ays_poll_allow_multivote']) && $data['ays_poll_allow_multivote'] == 'on' ? "on" : "off"; |
| 488 |
$multivote_answer_min_count = (isset($data['ays_poll_multivote_min_count']) && $data['ays_poll_multivote_min_count'] != '') ? sanitize_text_field($data['ays_poll_multivote_min_count']) : ''; |
| 489 |
$poll_multivote_answer_count = (isset($data['ays_poll_multivote_count']) && $data['ays_poll_multivote_count'] != '') ? sanitize_text_field($data['ays_poll_multivote_count']) : ''; |
| 490 |
|
| 491 |
// Allow collect user info |
| 492 |
$poll_allow_collecting_users_data = (isset($data['ays_allow_collecting_logged_in_users_data']) && $data['ays_allow_collecting_logged_in_users_data'] == 'on') ? 'on' : 'off'; |
| 493 |
|
| 494 |
// Answer Icon |
| 495 |
$poll_answer_icon_check = isset($data['ays_poll_show_answers_icon']) && $data['ays_poll_show_answers_icon'] == "on" ? "on" : "off"; |
| 496 |
$poll_answer_icon = isset($data['ays_poll_answer_icon']) && $data['ays_poll_answer_icon'] != "" ? sanitize_text_field($data['ays_poll_answer_icon']) : "radio"; |
| 497 |
|
| 498 |
// Every Answer redirect delay |
| 499 |
$poll_every_answer_redirect_delay = isset($data['ays_poll_answer_redirect_delay']) && $data['ays_poll_answer_redirect_delay'] != "" ? sanitize_text_field($data['ays_poll_answer_redirect_delay']) : ""; |
| 500 |
$poll_enable_every_answer_redirect_delay = isset($data['ays_poll_enable_answer_redirect_delay']) && $data['ays_poll_enable_answer_redirect_delay'] == "on" ? "on" : "off"; |
| 501 |
|
| 502 |
// Show Answers image after voting |
| 503 |
if(isset($data['ays-poll-answers-images']) && empty(array_filter($data['ays-poll-answers-images']))){ |
| 504 |
$data['ays_poll_enable_answer_image_after_voting'] = 'off'; |
| 505 |
} |
| 506 |
$poll_enable_answer_image_after_voting = isset($data['ays_poll_enable_answer_image_after_voting']) && $data['ays_poll_enable_answer_image_after_voting'] == "on" ? "on" : "off"; |
| 507 |
|
| 508 |
// Poll logo image url |
| 509 |
$poll_logo_image_url = isset($data['ays_poll_logo_image_url']) && $data['ays_poll_logo_image_url'] != "" ? sanitize_text_field($data['ays_poll_logo_image_url']) : ""; |
| 510 |
$poll_logo_image_url_check = isset($data['ays_poll_logo_enable_image_url']) && $data['ays_poll_logo_enable_image_url'] == "on" ? "on" : "off"; |
| 511 |
|
| 512 |
// Poll Logo title |
| 513 |
$poll_logo_title = (isset( $data['ays_poll_logo_title'] ) && $data['ays_poll_logo_title'] != '') ? sanitize_text_field( $data['ays_poll_logo_title'] ) : ''; |
| 514 |
|
| 515 |
// Poll question font size |
| 516 |
$poll_question_font_size_pc = isset($data['ays_poll_answers_font_size_pc']) && $data['ays_poll_answers_font_size_pc'] != "" ? sanitize_text_field($data['ays_poll_answers_font_size_pc']) : "16"; |
| 517 |
$poll_question_font_size_mobile = isset($data['ays_poll_answers_font_size_mobile']) && $data['ays_poll_answers_font_size_mobile'] != "" ? sanitize_text_field($data['ays_poll_answers_font_size_mobile']) : "16"; |
| 518 |
|
| 519 |
// Poll question image height |
| 520 |
$poll_question_image_height = isset($data['ays_poll_question_image_height']) && $data['ays_poll_question_image_height'] != "" ? abs(sanitize_text_field($data['ays_poll_question_image_height'])) : ""; |
| 521 |
|
| 522 |
// Poll question object fit |
| 523 |
$poll_question_image_object_fit = isset($data['ays_poll_question_image_object_fit']) && $data['ays_poll_question_image_object_fit'] != "" ? sanitize_text_field($data['ays_poll_question_image_object_fit']) : "cover"; |
| 524 |
|
| 525 |
// Poll container max-width for mobile |
| 526 |
$poll_mobile_max_width = (isset($data['ays_poll_mobile_max_width']) && $data['ays_poll_mobile_max_width'] != "") ? abs(sanitize_text_field($data['ays_poll_mobile_max_width'])) : ''; |
| 527 |
|
| 528 |
// ==== Button Styles ===== |
| 529 |
// Buttons size |
| 530 |
$poll_buttons_size = (isset($data['ays_poll_buttons_size']) && $data['ays_poll_buttons_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_size']) : 'medium'; |
| 531 |
|
| 532 |
// Buttons font size |
| 533 |
$poll_buttons_font_size = (isset($data['ays_poll_buttons_font_size']) && $data['ays_poll_buttons_font_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_font_size']) : '17'; |
| 534 |
|
| 535 |
// Buttons mobile font size |
| 536 |
$poll_buttons_mobile_font_size = (isset($data['ays_poll_buttons_mobile_font_size']) && $data['ays_poll_buttons_mobile_font_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_mobile_font_size']) : '17'; |
| 537 |
|
| 538 |
// Buttons Left / Right padding |
| 539 |
$poll_buttons_left_right_padding = (isset($data['ays_poll_buttons_left_right_padding']) && $data['ays_poll_buttons_left_right_padding'] != "") ? sanitize_text_field($data['ays_poll_buttons_left_right_padding']) : '20'; |
| 540 |
|
| 541 |
// Buttons Top / Bottom padding |
| 542 |
$poll_buttons_top_bottom_padding = (isset($data['ays_poll_buttons_top_bottom_padding']) && $data['ays_poll_buttons_top_bottom_padding'] != "") ? sanitize_text_field($data['ays_poll_buttons_top_bottom_padding']) : '10'; |
| 543 |
|
| 544 |
// Buttons padding |
| 545 |
$poll_buttons_border_radius = (isset($data['ays_poll_buttons_border_radius']) && $data['ays_poll_buttons_border_radius'] != "") ? sanitize_text_field($data['ays_poll_buttons_border_radius']) : '3'; |
| 546 |
|
| 547 |
// Buttons width |
| 548 |
$poll_buttons_width = (isset($data['ays_poll_buttons_width']) && sanitize_text_field( $data['ays_poll_buttons_width'] ) != "") ? sanitize_text_field( $data['ays_poll_buttons_width'] ) : ''; |
| 549 |
|
| 550 |
// Buttons mobile width |
| 551 |
$poll_buttons_mobile_width = (isset($data['ays_poll_buttons_mobile_width']) && sanitize_text_field( $data['ays_poll_buttons_mobile_width'] ) != "") ? sanitize_text_field( $data['ays_poll_buttons_mobile_width'] ) : $poll_buttons_width; |
| 552 |
// ==== ==== |
| 553 |
|
| 554 |
// ==== Allow Answer options ==== |
| 555 |
// Allow custom answer |
| 556 |
$poll_allow_answer = (isset($data['ays_poll_allow_add_answers']) && $data['ays_poll_allow_add_answers'] == "on") ? "on" : "off"; |
| 557 |
// Require admin approval |
| 558 |
|
| 559 |
$poll_allow_answer_require = (isset($data['ays_poll_allow_answer_require']) && $data['ays_poll_allow_answer_require'] == "on") ? "on" : "off"; |
| 560 |
|
| 561 |
// ==== ==== |
| 562 |
|
| 563 |
// Poll answer view type |
| 564 |
$poll_answer_view_type = (isset($data['ays_poll_choose_answer_type']) && $data['ays_poll_choose_answer_type'] != "") ? sanitize_text_field($data['ays_poll_choose_answer_type']) : "list"; |
| 565 |
|
| 566 |
// Poll answer box shadow |
| 567 |
// Poll answer box shadow enable |
| 568 |
$poll_answer_enable_box_shadow = (isset($data['ays_poll_answers_box_shadow_enable']) && $data['ays_poll_answers_box_shadow_enable'] == "on") ? "on" : "off"; |
| 569 |
// Poll answer box shadow color |
| 570 |
$poll_answer_box_shadow_color = (isset($data['ays_poll_answers_box_shadow_color']) && $data['ays_poll_answers_box_shadow_color'] != "") ? sanitize_text_field($data['ays_poll_answers_box_shadow_color']) : "#000000"; |
| 571 |
|
| 572 |
$poll_answer_box_shadow_x_offset = (isset($data['ays_poll_answer_box_shadow_x_offset']) && $data['ays_poll_answer_box_shadow_x_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_x_offset']) : 0; |
| 573 |
|
| 574 |
$poll_answer_box_shadow_y_offset = (isset($data['ays_poll_answer_box_shadow_y_offset']) && $data['ays_poll_answer_box_shadow_y_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_y_offset']) : 0; |
| 575 |
|
| 576 |
$poll_answer_box_shadow_z_offset = (isset($data['ays_poll_answer_box_shadow_z_offset']) && $data['ays_poll_answer_box_shadow_z_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_z_offset']) : 10; |
| 577 |
// |
| 578 |
|
| 579 |
// Poll answer image height |
| 580 |
$poll_answer_image_height = (isset($data['ays_poll_answer_img_height']) && $data['ays_poll_answer_img_height'] != "") ? sanitize_text_field($data['ays_poll_answer_img_height']) : "150"; |
| 581 |
if($poll_answer_image_height == '0'){ |
| 582 |
$poll_answer_image_height = "150"; |
| 583 |
} |
| 584 |
|
| 585 |
// Poll answer image height for mobile |
| 586 |
$poll_answer_image_height_for_mobile = (isset($data['ays_poll_answer_image_height_for_mobile']) && $data['ays_poll_answer_image_height_for_mobile'] != "") ? sanitize_text_field($data['ays_poll_answer_image_height_for_mobile']) : "150"; |
| 587 |
if($poll_answer_image_height_for_mobile == '0'){ |
| 588 |
$poll_answer_image_height_for_mobile = "150"; |
| 589 |
} |
| 590 |
|
| 591 |
// Poll answer image border radius |
| 592 |
$poll_answer_image_border_radius = (isset($data['ays_poll_answer_image_border_radius']) && $data['ays_poll_answer_image_border_radius'] != "") ? sanitize_text_field($data['ays_poll_answer_image_border_radius']) : 0; |
| 593 |
|
| 594 |
// Poll answer image object fit |
| 595 |
$poll_answer_object_fit = (isset($data['ays_poll_image_background_size']) && $data['ays_poll_image_background_size'] != "") ? sanitize_text_field($data['ays_poll_image_background_size']) : "cover"; |
| 596 |
|
| 597 |
// Poll answer padding |
| 598 |
$poll_answer_padding = (isset($data['ays_poll_answers_padding']) && $data['ays_poll_answers_padding'] != "") ? sanitize_text_field($data['ays_poll_answers_padding']) : "10"; |
| 599 |
|
| 600 |
// Poll answer gap |
| 601 |
$poll_answer_margin = (isset($data['ays_poll_answers_margin']) && $data['ays_poll_answers_margin'] != "") ? sanitize_text_field($data['ays_poll_answers_margin']) : "10"; |
| 602 |
|
| 603 |
// Poll answer border radius |
| 604 |
$poll_answer_border_radius = (isset($data['ays_poll_answer_border_radius']) && $data['ays_poll_answer_border_radius'] != "") ? absint(intval($data['ays_poll_answer_border_radius'])) : 0; |
| 605 |
|
| 606 |
// Poll title font size |
| 607 |
$poll_title_font_size = (isset($data['ays_poll_title_font_size']) && $data['ays_poll_title_font_size'] != "" && $data['ays_poll_title_font_size'] > 0) ? sanitize_text_field($data['ays_poll_title_font_size']) : "20"; |
| 608 |
|
| 609 |
// Poll title font size for mobile |
| 610 |
$poll_title_font_size_mobile = (isset($data['ays_poll_title_font_size_mobile']) && $data['ays_poll_title_font_size_mobile'] != "" && $data['ays_poll_title_font_size_mobile'] > 0) ? sanitize_text_field($data['ays_poll_title_font_size_mobile']) : "20"; |
| 611 |
|
| 612 |
// Poll title alignment |
| 613 |
$poll_title_alignment = ( isset($data['ays_poll_title_alignment']) && $data['ays_poll_title_alignment'] != "" ) ? sanitize_text_field($data['ays_poll_title_alignment']) : "center"; |
| 614 |
|
| 615 |
// Poll title alignment mobile |
| 616 |
$poll_title_alignment_mobile = ( isset($data['ays_poll_title_alignment_mobile']) && $data['ays_poll_title_alignment_mobile'] != "" ) ? sanitize_text_field($data['ays_poll_title_alignment_mobile']) : "center"; |
| 617 |
|
| 618 |
// ===== Poll text type options start ===== |
| 619 |
$poll_text_type_length_enable = ( isset($data['ays_poll_enable_question_length']) && $data['ays_poll_enable_question_length'] != "" ) ? sanitize_text_field($data['ays_poll_enable_question_length']) : "off"; |
| 620 |
$poll_text_type_limit_type = ( isset($data['ays_poll_question_limit_text_type']) && $data['ays_poll_question_limit_text_type'] != "" ) ? sanitize_text_field($data['ays_poll_question_limit_text_type']) : "characters"; |
| 621 |
$poll_text_type_limit_length = ( isset($data['ays_poll_question_text_max_length']) && $data['ays_poll_question_text_max_length'] != "" ) ? sanitize_text_field($data['ays_poll_question_text_max_length']) : ""; |
| 622 |
$poll_text_type_limit_message = ( isset($data['ays_poll_question_enable_text_message']) && $data['ays_poll_question_enable_text_message'] != "" ) ? sanitize_text_field($data['ays_poll_question_enable_text_message']) : "off"; |
| 623 |
$poll_text_type_placeholder = ( isset($data['ays_poll_text_type_placeholder']) && $data['ays_poll_text_type_placeholder'] != "" ) ? sanitize_text_field($data['ays_poll_text_type_placeholder']) : ""; |
| 624 |
$poll_text_type_width = ( isset($data['ays_poll_text_type_width']) && $data['ays_poll_text_type_width'] != "" ) ? absint(intval(sanitize_text_field($data['ays_poll_text_type_width']))) : ""; |
| 625 |
$poll_text_type_width_type = ( isset($data['ays_poll_text_type_width_type']) && $data['ays_poll_text_type_width_type'] != "" ) ? sanitize_text_field($data['ays_poll_text_type_width_type']) : "percent"; |
| 626 |
// ===== Poll text type options end ===== |
| 627 |
|
| 628 |
$poll_enable_password = ( isset($data['ays_poll_enable_password']) && $data['ays_poll_enable_password'] == "on" ) ? "on" : "off"; |
| 629 |
$poll_password = ( isset($data['ays_poll_password']) && $data['ays_poll_password'] != "" ) ? sanitize_text_field($data['ays_poll_password']) : ""; |
| 630 |
// Enable toggle password visibility |
| 631 |
$poll_enable_password_visibility = (isset($data['ays_poll_enable_password_visibility']) && $data['ays_poll_enable_password_visibility'] == 'on') ? 'on' : 'off'; |
| 632 |
$poll_password_message = ( isset($data['ays_poll_password_message']) && $data['ays_poll_password_message'] != "" ) ? wp_kses( $data['ays_poll_password_message'], $poll_allowed_html ) : "Please enter password"; |
| 633 |
|
| 634 |
// Add post for poll |
| 635 |
$ays_add_post_for_poll = isset($data['ays_add_post_for_poll']) && $data['ays_add_post_for_poll'] == 'on' ? 'on' : 'off'; |
| 636 |
|
| 637 |
//Title Text Shadow |
| 638 |
$enable_poll_title_text_shadow = ( isset( $data['ays_poll_enable_title_text_shadow'] ) && $data['ays_poll_enable_title_text_shadow'] != '' ) ? 'on' : 'off'; |
| 639 |
|
| 640 |
// Enable/disable grid column layout for answers on mobile devices |
| 641 |
$answers_grid_column_mobile = (isset($data['ays_answers_grid_column_mobile']) && $data['ays_answers_grid_column_mobile'] == 'on') ? 'on' :'off'; |
| 642 |
|
| 643 |
|
| 644 |
$poll_title_text_shadow = ( isset($data['ays_poll_title_text_shadow_color'] ) && $data['ays_poll_title_text_shadow_color'] != '' ) ? sanitize_text_field( $data['ays_poll_title_text_shadow_color'] ) : 'rgba(255,255,255,0)'; |
| 645 |
$poll_title_text_shadow_x_offset = (isset($data['ays_poll_title_text_shadow_x_offset']) && $data['ays_poll_title_text_shadow_x_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_x_offset'] ) : 2; |
| 646 |
|
| 647 |
$poll_title_text_shadow_y_offset = (isset($data['ays_poll_title_text_shadow_y_offset']) && $data['ays_poll_title_text_shadow_y_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_y_offset'] ) : 2; |
| 648 |
|
| 649 |
$poll_title_text_shadow_z_offset = (isset($data['ays_poll_title_text_shadow_z_offset']) && $data['ays_poll_title_text_shadow_z_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_z_offset'] ) : 0; |
| 650 |
|
| 651 |
//Display form fields labels |
| 652 |
$display_fields_labels = ( isset($data['ays_poll_display_fields_labels']) && sanitize_text_field( $data['ays_poll_display_fields_labels'] ) == 'on' ) ? 'on' : 'off'; |
| 653 |
|
| 654 |
// Autofill users data |
| 655 |
$autofill_user_data = ( isset($data['ays_poll_autofill_user_data']) && sanitize_text_field( $data['ays_poll_autofill_user_data'] ) == 'on' ) ? 'on' : 'off'; |
| 656 |
|
| 657 |
//Open Logo Url in new tab |
| 658 |
$poll_logo_url_new_tab = (isset( $data[ 'ays_poll_logo_enable_image_url_new_tab' ] ) && $data[ 'ays_poll_logo_enable_image_url_new_tab' ] == 'on') ? "on" : 'off'; |
| 659 |
|
| 660 |
// Social Media links |
| 661 |
$enable_social_links = (isset($data['ays_poll_enable_social_links']) && sanitize_text_field( $data['ays_poll_enable_social_links'] ) == "on") ? 'on' : 'off'; |
| 662 |
$poll_social_links_heading = ( isset( $data[ 'ays_poll_social_links_heading' ] ) && $data[ 'ays_poll_social_links_heading' ] != '' ) ? wp_kses( $data['ays_poll_social_links_heading'], $poll_allowed_html ) : ''; |
| 663 |
$ays_social_links = (isset($data['ays_poll_social_links'])) ? array_map( 'sanitize_text_field', $data['ays_poll_social_links'] ) : array( |
| 664 |
'linkedin_link' => '', |
| 665 |
'facebook_link' => '', |
| 666 |
'twitter_link' => '', |
| 667 |
'vkontakte_link' => '', |
| 668 |
'youtube_link' => '', |
| 669 |
'tiktok_link' => '', |
| 670 |
); |
| 671 |
|
| 672 |
$linkedin_link = isset($ays_social_links['ays_linkedin_link']) && sanitize_text_field( $ays_social_links['ays_linkedin_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_linkedin_link'] ) : ''; |
| 673 |
$facebook_link = isset($ays_social_links['ays_facebook_link']) && sanitize_text_field( $ays_social_links['ays_facebook_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_facebook_link'] ) : ''; |
| 674 |
$twitter_link = isset($ays_social_links['ays_twitter_link']) && sanitize_text_field( $ays_social_links['ays_twitter_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_twitter_link'] ) : ''; |
| 675 |
$vkontakte_link = isset($ays_social_links['ays_vkontakte_link']) && sanitize_text_field( $ays_social_links['ays_vkontakte_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_vkontakte_link'] ) : ''; |
| 676 |
$youtube_link = isset($ays_social_links['ays_youtube_link']) && sanitize_text_field( $ays_social_links['ays_youtube_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_youtube_link'] ) : ''; |
| 677 |
$tiktok_link = isset($ays_social_links['ays_tiktok_link']) && sanitize_text_field( $ays_social_links['ays_tiktok_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_tiktok_link'] ) : ''; |
| 678 |
|
| 679 |
$social_links = array( |
| 680 |
'linkedin_link' => $linkedin_link, |
| 681 |
'facebook_link' => $facebook_link, |
| 682 |
'twitter_link' => $twitter_link, |
| 683 |
'vkontakte_link' => $vkontakte_link, |
| 684 |
'youtube_link' => $youtube_link, |
| 685 |
'tiktok_link' => $tiktok_link, |
| 686 |
); |
| 687 |
|
| 688 |
$show_chart_type = (isset($_POST['ays_poll_show_result_chart']) && sanitize_text_field( $_POST['ays_poll_show_result_chart'] ) != "") ? sanitize_text_field( $_POST['ays_poll_show_result_chart'] ) : 'default_bar_chart'; |
| 689 |
$show_chart_type_google_height = (isset($_POST['ays_poll_show_result_chart_google_height']) && $_POST['ays_poll_show_result_chart_google_height'] != "" && $_POST['ays_poll_show_result_chart_google_height'] != 0) ? absint( intval($_POST['ays_poll_show_result_chart_google_height']) ) : 400; |
| 690 |
|
| 691 |
$styles = json_encode(array( |
| 692 |
// Style tab start |
| 693 |
'main_color' => $main_color, |
| 694 |
'text_color' => $text_color, |
| 695 |
'button_text_color' => $button_text_color, |
| 696 |
'button_bg_color' => $button_bg_color, |
| 697 |
'icon_color' => $icon_color, |
| 698 |
'bg_color' => $bg_color, |
| 699 |
'bg_image' => $bg_image, |
| 700 |
'enable_answer_style' => $enable_answer_style, |
| 701 |
'answer_bg_color' => $answer_bg_color, |
| 702 |
'answer_hover_color' => $answer_hover_color, |
| 703 |
'answer_border_side' => $answer_border_side, |
| 704 |
"answer_font_size" => $poll_answer_font_size, |
| 705 |
"poll_answer_font_size_mobile" => $poll_answer_font_size_mobile, |
| 706 |
'poll_answer_object_fit' => $poll_answer_object_fit, |
| 707 |
'poll_answer_padding' => $poll_answer_padding, |
| 708 |
'poll_answer_margin' => $poll_answer_margin, |
| 709 |
'poll_answer_border_radius' => $poll_answer_border_radius, |
| 710 |
'poll_answer_icon_check' => $poll_answer_icon_check, |
| 711 |
'poll_answer_icon' => $poll_answer_icon, |
| 712 |
'poll_answer_view_type' => $poll_answer_view_type, |
| 713 |
'poll_answer_enable_box_shadow' => $poll_answer_enable_box_shadow, |
| 714 |
'poll_answer_box_shadow_color' => $poll_answer_box_shadow_color, |
| 715 |
'poll_answer_box_shadow_x_offset' => $poll_answer_box_shadow_x_offset, |
| 716 |
'poll_answer_box_shadow_y_offset' => $poll_answer_box_shadow_y_offset, |
| 717 |
'poll_answer_box_shadow_z_offset' => $poll_answer_box_shadow_z_offset, |
| 718 |
'title_bg_color' => $title_bg_color, //aray |
| 719 |
'poll_title_font_size' => $poll_title_font_size, |
| 720 |
'poll_title_font_size_mobile' => $poll_title_font_size_mobile, |
| 721 |
'icon_size' => $icon_size, |
| 722 |
'width' => $width, |
| 723 |
'width_for_mobile' => $width_for_mobile, |
| 724 |
"poll_min_height" => $poll_min_height, |
| 725 |
'border_style' => $border_style, |
| 726 |
'border_radius' => $border_radius, |
| 727 |
'border_width' => $border_width, |
| 728 |
"border_color" => $poll_border_color, |
| 729 |
'enable_box_shadow' => $enable_box_shadow, |
| 730 |
'box_shadow_color' => $box_shadow_color, |
| 731 |
"poll_box_shadow_x_offset" => $poll_box_shadow_x_offset, |
| 732 |
"poll_box_shadow_y_offset" => $poll_box_shadow_y_offset, |
| 733 |
"poll_box_shadow_z_offset" => $poll_box_shadow_z_offset, |
| 734 |
'enable_background_gradient' => $enable_background_gradient, |
| 735 |
'background_gradient_color_1' => $background_gradient_color_1, |
| 736 |
'background_gradient_color_2' => $background_gradient_color_2, |
| 737 |
'poll_gradient_direction' => $poll_gradient_direction, |
| 738 |
'poll_question_size_pc' => $poll_question_font_size_pc, |
| 739 |
'poll_question_size_mobile' => $poll_question_font_size_mobile, |
| 740 |
'poll_question_image_height' => $poll_question_image_height, |
| 741 |
'poll_question_image_object_fit' => $poll_question_image_object_fit, |
| 742 |
'poll_mobile_max_width' => $poll_mobile_max_width, |
| 743 |
'poll_buttons_size' => $poll_buttons_size, |
| 744 |
'poll_buttons_font_size' => $poll_buttons_font_size, |
| 745 |
'poll_buttons_mobile_font_size' => $poll_buttons_mobile_font_size, |
| 746 |
'poll_buttons_left_right_padding' => $poll_buttons_left_right_padding, |
| 747 |
'poll_buttons_top_bottom_padding' => $poll_buttons_top_bottom_padding, |
| 748 |
'poll_buttons_border_radius' => $poll_buttons_border_radius, |
| 749 |
'poll_buttons_width' => $poll_buttons_width, |
| 750 |
'poll_buttons_mobile_width' => $poll_buttons_mobile_width, |
| 751 |
"disable_answer_hover" => $disable_answer_hover, |
| 752 |
"logo_image" => $poll_logo_image, |
| 753 |
'poll_enable_logo_url' => $poll_logo_image_url_check, |
| 754 |
'poll_logo_title' => $poll_logo_title, |
| 755 |
'poll_logo_url' => $poll_logo_image_url, |
| 756 |
"custom_class" => $custom_class, |
| 757 |
"enable_poll_title_text_shadow" => $enable_poll_title_text_shadow, |
| 758 |
"poll_title_text_shadow" => $poll_title_text_shadow, |
| 759 |
"poll_title_text_shadow_x_offset" => $poll_title_text_shadow_x_offset, |
| 760 |
"poll_title_text_shadow_y_offset" => $poll_title_text_shadow_y_offset, |
| 761 |
"poll_title_text_shadow_z_offset" => $poll_title_text_shadow_z_offset, |
| 762 |
|
| 763 |
// Settings tab start |
| 764 |
"poll_allow_multivote" => $poll_allow_multivote, |
| 765 |
"multivote_answer_min_count" => $multivote_answer_min_count, |
| 766 |
"poll_allow_multivote_count" => $poll_multivote_answer_count, |
| 767 |
'poll_direction' => $poll_direction, |
| 768 |
'show_create_date' => $show_create_date, |
| 769 |
'show_author' => $show_author, |
| 770 |
'active_date_check' => $active_date_check, |
| 771 |
'activeInterval' => $activeInterval, |
| 772 |
'activeIntervalSec' => $activeIntervalSec, |
| 773 |
'deactiveInterval' => $deactiveInterval, |
| 774 |
'deactiveIntervalSec' => $deactiveIntervalSec, |
| 775 |
'ays_poll_show_timer' => $ays_poll_show_timer, |
| 776 |
'show_bottom_timer' => $show_bottom_timer, |
| 777 |
'ays_show_timer_type' => $ays_show_timer_type, |
| 778 |
'show_result_btn_see_schedule' => $ays_show_result_btn_see, |
| 779 |
'active_date_message_soon' => $active_date_message_soon, |
| 780 |
'active_date_message' => $active_date_message, |
| 781 |
'show_result_btn_schedule' => $show_result_btn_schedule, |
| 782 |
"dont_show_poll_cont" => $poll_show_container, |
| 783 |
'allow_not_vote' => $allow_not_vote, |
| 784 |
'see_res_btn_text' => $see_res_btn_text, |
| 785 |
'enable_pass_count' => $enable_pass_count, |
| 786 |
'redirect_users' => $redirect_users, |
| 787 |
'redirect_after_vote_url' => $redirect_after_vote_url, |
| 788 |
'redirection_delay' => $limit_users_delay, |
| 789 |
'randomize_answers' => $randomize_answers, |
| 790 |
'enable_asnwers_sound' => $enable_asnwers_sound, |
| 791 |
"poll_vote_reason" => $poll_vote_reason, |
| 792 |
'enable_vote_btn' => $enable_vote_btn, |
| 793 |
'btn_text' => $btn_text, |
| 794 |
"enable_view_more_button" => $enable_view_more_button, |
| 795 |
"poll_view_more_button_count" => $poll_view_more_button_count, |
| 796 |
"answer_sort_type" => $poll_answer_ordering, |
| 797 |
"show_answers_numbering" => $show_answers_numbering, |
| 798 |
// Settings tab end |
| 799 |
'hide_results' => $hide_results, |
| 800 |
'hide_result_message' => $hide_result_message, |
| 801 |
'hide_results_text' => $hide_results_text, |
| 802 |
'result_message' => $ays_result_message, |
| 803 |
'show_social' => $show_social, |
| 804 |
'poll_social_buttons_heading' => $poll_social_buttons_heading, |
| 805 |
'poll_show_social_ln' => $poll_show_social_ln, |
| 806 |
'poll_show_social_fb' => $poll_show_social_fb, |
| 807 |
'poll_show_social_tr' => $poll_show_social_tr, |
| 808 |
'poll_show_social_vk' => $poll_show_social_vk, |
| 809 |
'load_effect' => $load_effect, |
| 810 |
'load_gif' => $load_gif, |
| 811 |
'limit_users' => $limit_users, |
| 812 |
'limit_users_method' => $limit_users_method, |
| 813 |
'limitation_message' => $limit_users_msg, |
| 814 |
'redirect_url' => $limit_users_url, |
| 815 |
'user_role' => $limit_users_role, |
| 816 |
'enable_restriction_pass' => $limit_users_role_enable, |
| 817 |
'restriction_pass_message' => $limit_users_role_msg, |
| 818 |
'enable_logged_users' => $limit_users_logged_enable, |
| 819 |
'enable_logged_users_message' => $limit_users_logged_msg, |
| 820 |
'notify_email_on' => $notify_on, |
| 821 |
'notify_email' => $notify_email, |
| 822 |
'result_sort_type' => $result_sort_type, |
| 823 |
'create_date' => $changed_creation_date, |
| 824 |
'author' => $author, |
| 825 |
'poll_main_url' => $poll_main_url, |
| 826 |
'redirect_after_vote_delay' => $redirect_after_vote_delay, |
| 827 |
'published' => $published, |
| 828 |
'enable_restart_button' => $enable_restart_button, |
| 829 |
'show_votes_count' => $show_votes_count, |
| 830 |
'show_res_percent' => $show_res_percent, |
| 831 |
'show_login_form' => $show_login_form, |
| 832 |
'info_form' => $info_form, |
| 833 |
'fields' => $form_fields, |
| 834 |
"answers_grid_column_mobile" => $answers_grid_column_mobile, |
| 835 |
'required_fields' => $form_required_fields, |
| 836 |
'info_form_title' => $info_form_title, |
| 837 |
'enable_mailchimp' => $enable_mailchimp, |
| 838 |
'redirect_after_submit' => $redirect_after_submit, |
| 839 |
'mailchimp_list' => $mailchimp_list, |
| 840 |
"users_role" => json_encode($limit_users_role), |
| 841 |
"poll_bg_image_position" => $poll_bg_image_position, |
| 842 |
"poll_bg_img_in_finish_page" => $poll_bg_img_in_finish_page, |
| 843 |
'ays_add_post_for_poll' => $ays_add_post_for_poll, |
| 844 |
"result_in_rgba" => $result_in_rgba, |
| 845 |
"show_passed_users" => $poll_show_passed_users, |
| 846 |
"see_result_button" => $poll_see_result_button, |
| 847 |
"see_result_radio" => $poll_see_result_radio, |
| 848 |
"loader_font_size" => $poll_loader_font_size, |
| 849 |
"effect_message" => $poll_effect_message, |
| 850 |
|
| 851 |
"poll_allow_collecting_users_data" => $poll_allow_collecting_users_data, |
| 852 |
'poll_every_answer_redirect_delay' => $poll_every_answer_redirect_delay, |
| 853 |
'poll_enable_answer_image_after_voting' => $poll_enable_answer_image_after_voting, |
| 854 |
'poll_enable_answer_redirect_delay' => $poll_enable_every_answer_redirect_delay, |
| 855 |
'poll_show_passed_users_count' => $poll_show_passed_users_count, |
| 856 |
'poll_allow_answer' => $poll_allow_answer, |
| 857 |
'poll_allow_answer_require' => $poll_allow_answer_require, |
| 858 |
'poll_answer_image_height' => $poll_answer_image_height, |
| 859 |
'poll_answer_image_height_for_mobile' => $poll_answer_image_height_for_mobile, |
| 860 |
'poll_answer_image_border_radius' => $poll_answer_image_border_radius, |
| 861 |
'poll_title_alignment' => $poll_title_alignment, |
| 862 |
'poll_title_alignment_mobile' => $poll_title_alignment_mobile, |
| 863 |
// Text type options |
| 864 |
'poll_text_type_length_enable' => $poll_text_type_length_enable, |
| 865 |
'poll_text_type_limit_type' => $poll_text_type_limit_type, |
| 866 |
'poll_text_type_limit_length' => $poll_text_type_limit_length, |
| 867 |
'poll_text_type_limit_message' => $poll_text_type_limit_message, |
| 868 |
'poll_text_type_placeholder' => $poll_text_type_placeholder, |
| 869 |
'poll_text_type_width' => $poll_text_type_width, |
| 870 |
'poll_text_type_width_type' => $poll_text_type_width_type, |
| 871 |
|
| 872 |
'poll_enable_password' => $poll_enable_password, |
| 873 |
'poll_password' => $poll_password, |
| 874 |
'poll_enable_password_visibility' => $poll_enable_password_visibility, |
| 875 |
'poll_password_message' => $poll_password_message, |
| 876 |
'display_fields_labels' => $display_fields_labels, |
| 877 |
'autofill_user_data' => $autofill_user_data, |
| 878 |
'poll_create_author' => $poll_create_author, |
| 879 |
'poll_logo_url_new_tab' => $poll_logo_url_new_tab, |
| 880 |
'enable_social_links' => $enable_social_links, |
| 881 |
'poll_social_links_heading' => $poll_social_links_heading, |
| 882 |
'social_links' => $social_links, |
| 883 |
'show_chart_type' => $show_chart_type, |
| 884 |
'show_chart_type_google_height' => $show_chart_type_google_height, |
| 885 |
)); |
| 886 |
|
| 887 |
$poll_answers_img = array(); |
| 888 |
$answers = array(); |
| 889 |
switch ( $type ) { |
| 890 |
case 'choosing': |
| 891 |
$view_type = isset( $data['ays_poll_choose_answer_type'] ) ? sanitize_text_field($data['ays_poll_choose_answer_type'] ) : "list"; |
| 892 |
$poll_answers_img = isset($data['ays-poll-answers-images']) && !empty($data['ays-poll-answers-images']) ? $data['ays-poll-answers-images'] : $poll_answers_img; |
| 893 |
$answers = isset($data['ays-poll-answers']) && !empty($data['ays-poll-answers']) ? $data['ays-poll-answers'] : array(); |
| 894 |
$answers_ids = $data['ays-poll-answers-ids']; |
| 895 |
$answers_url = $data['ays_submit_redirect_url']; |
| 896 |
$answers_show_added = isset($data['ays_poll_show_user_added']) && !empty( $data['ays_poll_show_user_added']) ? $data['ays_poll_show_user_added'] : array(1,1); |
| 897 |
break; |
| 898 |
case 'voting': |
| 899 |
$view_type = isset($data['ays-poll-vote-type']) ? sanitize_text_field($data['ays-poll-vote-type']) : ""; |
| 900 |
$answers = array(1, -1); |
| 901 |
$answers_show_added = array(1,1); |
| 902 |
break; |
| 903 |
case 'rating': |
| 904 |
$view_type = isset($data['ays-poll-rate-type']) ? sanitize_text_field($data['ays-poll-rate-type']) : ""; |
| 905 |
$rate_value = $data['ays-poll-rate-value']; |
| 906 |
$answers = range(1, $rate_value); |
| 907 |
$answers_show_added = array(1,1); |
| 908 |
break; |
| 909 |
case 'text': |
| 910 |
$view_type = isset($data['ays_poll_text_type']) ? sanitize_text_field($data['ays_poll_text_type']) : ""; |
| 911 |
break; |
| 912 |
default: |
| 913 |
# code... |
| 914 |
break; |
| 915 |
} |
| 916 |
if (0 == $id) { |
| 917 |
$poll_result = $wpdb->insert( |
| 918 |
$poll_table, |
| 919 |
array( |
| 920 |
'title' => $title, |
| 921 |
'description' => $description, |
| 922 |
'type' => $type, |
| 923 |
'question' => $question, |
| 924 |
'view_type' => $view_type, |
| 925 |
'categories' => $categories, |
| 926 |
'image' => $image, |
| 927 |
'show_title' => $show_title, |
| 928 |
'styles' => $styles, |
| 929 |
'custom_css' => $css, |
| 930 |
'theme_id' => $theme_id, |
| 931 |
), |
| 932 |
array( |
| 933 |
'%s', |
| 934 |
'%s', |
| 935 |
'%s', |
| 936 |
'%s', |
| 937 |
'%s', |
| 938 |
'%s', |
| 939 |
'%s', |
| 940 |
'%d', |
| 941 |
'%s', |
| 942 |
'%s', |
| 943 |
'%d', |
| 944 |
) |
| 945 |
); |
| 946 |
$last_id = $wpdb->insert_id; |
| 947 |
$answer_count = isset($answers) && is_array($answers) ? count($answers) : 0; |
| 948 |
$empty_answers_count = 0; |
| 949 |
$not_empty_answers_count = 0; |
| 950 |
foreach ( $answers as $k => $answer ) { |
| 951 |
if (empty($answer)) { |
| 952 |
$empty_answers_count++; |
| 953 |
continue; |
| 954 |
} |
| 955 |
else{ |
| 956 |
$not_empty_answers_count++; |
| 957 |
} |
| 958 |
|
| 959 |
$wpdb->insert( |
| 960 |
$answer_table, |
| 961 |
array( |
| 962 |
'poll_id' => $last_id, |
| 963 |
'answer' => wp_filter_kses($answer), |
| 964 |
'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "", |
| 965 |
'ordering' => ($k + 1), |
| 966 |
'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1, |
| 967 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "", |
| 968 |
), |
| 969 |
array( |
| 970 |
'%d', // poll_id |
| 971 |
'%s', // answer |
| 972 |
'%s', // redirect |
| 973 |
'%d', // ordering |
| 974 |
'%d', // show_user_added |
| 975 |
'%s', // Answer Image |
| 976 |
) |
| 977 |
); |
| 978 |
} |
| 979 |
if($empty_answers_count == $answer_count && $type != "text"){ |
| 980 |
for($i = 0 ; $i < 2 ; $i++){ |
| 981 |
$wpdb->insert( |
| 982 |
$answer_table, |
| 983 |
array( |
| 984 |
'poll_id' => $last_id, |
| 985 |
'answer' => "Answer ".($i+1), |
| 986 |
'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "", |
| 987 |
'ordering' => ($i + 1), |
| 988 |
'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1, |
| 989 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "", |
| 990 |
), |
| 991 |
array( |
| 992 |
'%d', // poll_id |
| 993 |
'%s', // answer |
| 994 |
'%s', // redirect |
| 995 |
'%d', // ordering |
| 996 |
'%d', // show_user_added |
| 997 |
'%s', // Answer Image |
| 998 |
) |
| 999 |
); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
if($not_empty_answers_count == 1){ |
| 1003 |
$wpdb->insert( |
| 1004 |
$answer_table, |
| 1005 |
array( |
| 1006 |
'poll_id' => $last_id, |
| 1007 |
'answer' => "Answer 1", |
| 1008 |
'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "", |
| 1009 |
'ordering' => ($i + 1), |
| 1010 |
'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1, |
| 1011 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "", |
| 1012 |
), |
| 1013 |
array( |
| 1014 |
'%d', // poll_id |
| 1015 |
'%s', // answer |
| 1016 |
'%s', // redirect |
| 1017 |
'%d', // ordering |
| 1018 |
'%d', // show_user_added |
| 1019 |
'%s', // Answer Image |
| 1020 |
) |
| 1021 |
); |
| 1022 |
} |
| 1023 |
$message = 'created'; |
| 1024 |
|
| 1025 |
$post_type_args = array( |
| 1026 |
'poll_id' => $last_id, |
| 1027 |
'author_id' => !empty($poll_create_author) ? $poll_create_author : get_current_user_id(), |
| 1028 |
'poll_title' => $title, |
| 1029 |
); |
| 1030 |
|
| 1031 |
$custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args); |
| 1032 |
|
| 1033 |
} else { |
| 1034 |
$poll = $this->get_poll_by_id($id); |
| 1035 |
$poll_result = $wpdb->update( |
| 1036 |
$poll_table, |
| 1037 |
array( |
| 1038 |
'title' => $title, |
| 1039 |
'description' => $description, |
| 1040 |
'type' => $type, |
| 1041 |
'question' => $question, |
| 1042 |
'view_type' => $view_type, |
| 1043 |
'categories' => $categories, |
| 1044 |
'image' => $image, |
| 1045 |
'show_title' => $show_title, |
| 1046 |
'styles' => $styles, |
| 1047 |
'custom_css' => $css, |
| 1048 |
'theme_id' => $theme_id, |
| 1049 |
), |
| 1050 |
array('id' => $id), |
| 1051 |
array( |
| 1052 |
'%s', // title |
| 1053 |
'%s', // description |
| 1054 |
'%s', // type |
| 1055 |
'%s', // question |
| 1056 |
'%s', // view_type |
| 1057 |
'%s', // categories |
| 1058 |
'%s', // image |
| 1059 |
'%d', // show_title |
| 1060 |
'%s', // styles |
| 1061 |
'%s', // custom_css |
| 1062 |
'%d', // theme_id |
| 1063 |
), |
| 1064 |
array('%d') |
| 1065 |
); |
| 1066 |
if ($type != $poll['type']) { |
| 1067 |
$reports_table = esc_sql($wpdb->prefix."ayspoll_reports"); |
| 1068 |
$poll_id = absint(intval($id)); |
| 1069 |
$sql = "DELETE r FROM ".$reports_table." as r JOIN ".$answer_table." ON ".$answer_table.".id = r.answer_id JOIN ".$poll_table." ON ".$poll_table.".id = ".$answer_table.".poll_id WHERE ".$poll_table.".id = %d"; |
| 1070 |
|
| 1071 |
$wpdb->query( |
| 1072 |
$wpdb->prepare($sql,$poll_id) |
| 1073 |
); |
| 1074 |
|
| 1075 |
$wpdb->delete( |
| 1076 |
$answer_table, |
| 1077 |
array('poll_id' => $id), |
| 1078 |
array('%d') |
| 1079 |
); |
| 1080 |
|
| 1081 |
foreach ( $answers as $k => $answer ) { |
| 1082 |
if (empty($answer)) { |
| 1083 |
continue; |
| 1084 |
} |
| 1085 |
|
| 1086 |
$wpdb->insert( |
| 1087 |
$answer_table, |
| 1088 |
array( |
| 1089 |
'poll_id' => $id, |
| 1090 |
'answer' => wp_filter_kses($answer), |
| 1091 |
'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "", |
| 1092 |
'ordering' => ($k + 1), |
| 1093 |
'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1, |
| 1094 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "", |
| 1095 |
), |
| 1096 |
array( |
| 1097 |
'%d', // poll_id |
| 1098 |
'%s', // answer |
| 1099 |
'%s', // redirect |
| 1100 |
'%d', // ordering |
| 1101 |
'%d', // show_user_added |
| 1102 |
'%s', // Answer Image |
| 1103 |
) |
| 1104 |
); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
if ('choosing' == $type && $type == $poll['type']) { |
| 1108 |
foreach ( $poll['answers'] as $answer ) { |
| 1109 |
$old_id = $answer['id']; |
| 1110 |
$index = array_search($old_id, $answers_ids); |
| 1111 |
if ($index !== false && !empty($answers[$index])) { |
| 1112 |
$new_answer = isset($answers[$index]) && $answers[$index] != "" ? $answers[$index] : ""; |
| 1113 |
$new_url = sanitize_url($answers_url[$index]); |
| 1114 |
|
| 1115 |
if (empty($new_url)) { |
| 1116 |
$new_url = null; |
| 1117 |
} |
| 1118 |
|
| 1119 |
$wpdb->update( |
| 1120 |
$answer_table, |
| 1121 |
array( |
| 1122 |
'answer' => wp_filter_kses($new_answer), |
| 1123 |
'redirect' => $new_url, |
| 1124 |
'ordering' => ($index + 1), |
| 1125 |
'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1, |
| 1126 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "", |
| 1127 |
), |
| 1128 |
array('id' => $old_id), |
| 1129 |
array( |
| 1130 |
'%s', // answer |
| 1131 |
'%s', // redirect |
| 1132 |
'%d', // ordering |
| 1133 |
'%d', // show_user_added |
| 1134 |
'%s', // Answer Image |
| 1135 |
), |
| 1136 |
array('%d') |
| 1137 |
); |
| 1138 |
} else { |
| 1139 |
$report_table = esc_sql($wpdb->prefix."ayspoll_reports"); |
| 1140 |
$wpdb->delete( |
| 1141 |
$report_table, |
| 1142 |
array('answer_id' => $old_id), |
| 1143 |
array('%d') |
| 1144 |
); |
| 1145 |
$wpdb->delete( |
| 1146 |
$answer_table, |
| 1147 |
array('id' => $old_id), |
| 1148 |
array('%d') |
| 1149 |
); |
| 1150 |
} |
| 1151 |
} |
| 1152 |
$e_answer_count = 0; |
| 1153 |
$full_answer_count = 0; |
| 1154 |
$answer_ids_count = count($answers); |
| 1155 |
foreach ( $answers_ids as $index => $value ) { |
| 1156 |
if (empty($answers[$index])) { |
| 1157 |
$e_answer_count++; |
| 1158 |
} |
| 1159 |
else{ |
| 1160 |
$full_answer_count++; |
| 1161 |
} |
| 1162 |
if (0 == $value) { |
| 1163 |
if (empty($answers[$index])) { |
| 1164 |
continue; |
| 1165 |
} |
| 1166 |
|
| 1167 |
$wpdb->insert( |
| 1168 |
$answer_table, |
| 1169 |
array( |
| 1170 |
'poll_id' => $id, |
| 1171 |
'answer' => wp_filter_kses($answers[$index]), |
| 1172 |
'redirect' => isset($answers_url[$index]) && $answers_url[$index] != "" ? sanitize_url($answers_url[$index]) : null, |
| 1173 |
'ordering' => ($index + 1), |
| 1174 |
'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1, |
| 1175 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "", |
| 1176 |
), |
| 1177 |
array( |
| 1178 |
'%d', // poll_id |
| 1179 |
'%s', // answer |
| 1180 |
'%s', // redirect |
| 1181 |
'%d', // ordering |
| 1182 |
'%d', // show_user_added |
| 1183 |
'%s', // Answer Image |
| 1184 |
) |
| 1185 |
); |
| 1186 |
} |
| 1187 |
|
| 1188 |
} |
| 1189 |
if($e_answer_count == $answer_ids_count){ |
| 1190 |
for($j = 0 ; $j < 2 ; $j++){ |
| 1191 |
$wpdb->insert( |
| 1192 |
$answer_table, |
| 1193 |
array( |
| 1194 |
'poll_id' => $id, |
| 1195 |
'answer' => "Answer ".($j+1), |
| 1196 |
'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null, |
| 1197 |
'ordering' => ($j + 1), |
| 1198 |
'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1, |
| 1199 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "", |
| 1200 |
), |
| 1201 |
array( |
| 1202 |
'%d', // poll_id |
| 1203 |
'%s', // answer |
| 1204 |
'%s', // redirect |
| 1205 |
'%d', // ordering |
| 1206 |
'%d', // show_user_added |
| 1207 |
'%s', // Answer Image |
| 1208 |
) |
| 1209 |
); |
| 1210 |
} |
| 1211 |
} |
| 1212 |
if($full_answer_count == 1){ |
| 1213 |
$wpdb->insert( |
| 1214 |
$answer_table, |
| 1215 |
array( |
| 1216 |
'poll_id' => $id, |
| 1217 |
'answer' => "Answer 1", |
| 1218 |
'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null, |
| 1219 |
'ordering' => 1, |
| 1220 |
'show_user_added' => isset($answers_show_added[$j]) ? $answers_show_added[$j] : 1, |
| 1221 |
'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "", |
| 1222 |
), |
| 1223 |
array( |
| 1224 |
'%d', // poll_id |
| 1225 |
'%s', // answer |
| 1226 |
'%s', // redirect |
| 1227 |
'%d', // ordering |
| 1228 |
'%d', // show_user_added |
| 1229 |
'%s', // Answer Image |
| 1230 |
) |
| 1231 |
); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
if ($type == 'rating' && $poll['type'] == 'rating' && count($poll['answers']) != $rate_value) { |
| 1235 |
if (count($poll['answers']) > $rate_value) { |
| 1236 |
for ( $i = intval($rate_value); $i < count($poll['answers']); $i++ ) { |
| 1237 |
$wpdb->delete( |
| 1238 |
"{$wpdb->prefix}ayspoll_reports", |
| 1239 |
array('answer_id' => $poll['answers'][$i]['id']), |
| 1240 |
array('%d') |
| 1241 |
); |
| 1242 |
$wpdb->delete( |
| 1243 |
$answer_table, |
| 1244 |
array('id' => $poll['answers'][$i]['id']), |
| 1245 |
array('%d') |
| 1246 |
); |
| 1247 |
} |
| 1248 |
} else { |
| 1249 |
for ( $i = count($poll['answers']); $i < $rate_value; $i++ ) { |
| 1250 |
$wpdb->insert( |
| 1251 |
$answer_table, |
| 1252 |
array( |
| 1253 |
'poll_id' => $id, |
| 1254 |
'ordering'=> wp_filter_kses($answers[$i]), |
| 1255 |
'answer' => wp_filter_kses($answers[$i]), |
| 1256 |
), |
| 1257 |
array('%d', '%s') |
| 1258 |
); |
| 1259 |
} |
| 1260 |
} |
| 1261 |
} |
| 1262 |
$message = 'updated'; |
| 1263 |
} |
| 1264 |
|
| 1265 |
$add_post_for_poll = (isset($data['ays_add_post_for_poll']) && $data['ays_add_post_for_poll'] == 'on') ? 'on' : 'off'; |
| 1266 |
$add_postcat_for_poll = isset($data['ays_add_postcat_for_poll']) ? $data['ays_add_postcat_for_poll'] : array(); |
| 1267 |
$poll_post_id = ($id == 0) ? $last_id : $id; |
| 1268 |
|
| 1269 |
if($add_post_for_poll == "on"){ |
| 1270 |
global $user_ID; |
| 1271 |
$post_content = '[ays_poll id="'.$poll_post_id.'"]'; |
| 1272 |
|
| 1273 |
if ( Poll_Maker_Ays_Admin::is_active_gutenberg() ) { |
| 1274 |
$post_content = '<!-- wp:poll-maker/poll {"metaFieldValue":'.$poll_post_id.',"shortcode":"[ays_poll id='.$poll_post_id.']"} --> |
| 1275 |
<div class="wp-block-poll-maker-poll">[ays_poll id="'.$poll_post_id.'"]</div> |
| 1276 |
<!-- /wp:poll-maker/poll -->'; |
| 1277 |
} |
| 1278 |
|
| 1279 |
$new_post = array( |
| 1280 |
'post_title' => $title, |
| 1281 |
'post_content' => $post_content, |
| 1282 |
'post_status' => 'publish', |
| 1283 |
'post_date' => current_time( 'mysql' ), |
| 1284 |
'post_author' => $user_ID, |
| 1285 |
'post_type' => 'post', |
| 1286 |
'post_category' => $add_postcat_for_poll |
| 1287 |
); |
| 1288 |
$post_id = wp_insert_post($new_post); |
| 1289 |
if(! empty($image)){ |
| 1290 |
$sql = "SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND guid = '".$image."'"; |
| 1291 |
$attachment_id = intval($wpdb->get_var($sql)); |
| 1292 |
if($attachment_id !== 0){ |
| 1293 |
$featured_image = set_post_thumbnail($post_id, $attachment_id); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
$poll_post_result = $wpdb->update( |
| 1297 |
$poll_table, |
| 1298 |
array( 'post_id' => $post_id ), |
| 1299 |
array( 'id' => $poll_post_id ), |
| 1300 |
array( '%d' ), |
| 1301 |
array( '%d' ) |
| 1302 |
); |
| 1303 |
} |
| 1304 |
|
| 1305 |
$active_tabs = !empty($data['ays_poll_active_tab']) ? sanitize_text_field($data['ays_poll_active_tab']) : "General"; |
| 1306 |
$active_tab = urlencode($active_tabs); |
| 1307 |
|
| 1308 |
if ($poll_result >= 0) { |
| 1309 |
if($message == 'created'){ |
| 1310 |
setcookie('ays_poll_created_new', $last_id, time() + 3600, '/'); |
| 1311 |
if(!empty($custom_post_id)){ |
| 1312 |
$custom_post_url = array( |
| 1313 |
'post_type' => 'ays-poll-maker', |
| 1314 |
'p' => $custom_post_id, |
| 1315 |
'preview' => 'true', |
| 1316 |
); |
| 1317 |
$custom_post_url_ready = http_build_query($custom_post_url); |
| 1318 |
$ready_url = get_home_url(); |
| 1319 |
$ready_url .= '/?' . $custom_post_url_ready; |
| 1320 |
setcookie('ays_poll_created_new_'.$last_id.'_post_id', $ready_url, time() + 3600, '/'); |
| 1321 |
} |
| 1322 |
|
| 1323 |
} |
| 1324 |
} |
| 1325 |
|
| 1326 |
if ($poll_result >= 0) { |
| 1327 |
if ('' != $ays_change_type) { |
| 1328 |
if($id == 0){ |
| 1329 |
$url = esc_url_raw( add_query_arg( array( |
| 1330 |
"action" => "edit", |
| 1331 |
"poll" => $last_id, |
| 1332 |
"active-tab" => $active_tab, |
| 1333 |
"status" => $message |
| 1334 |
) ) ); |
| 1335 |
}else{ |
| 1336 |
$url = esc_url_raw( remove_query_arg(false) ) . '&active-tab='.$active_tab.'&status=' . $message; |
| 1337 |
} |
| 1338 |
wp_redirect($url); |
| 1339 |
} else { |
| 1340 |
$url = esc_url_raw(remove_query_arg(['action'])) . "&active-tab=".$active_tab."&status=" . $message; |
| 1341 |
wp_redirect($url); |
| 1342 |
} |
| 1343 |
} |
| 1344 |
} |
| 1345 |
$allowedtags = $old_allowedtags; |
| 1346 |
} |
| 1347 |
|
| 1348 |
public function duplicate_poll( $id ) { |
| 1349 |
global $wpdb; |
| 1350 |
|
| 1351 |
// Nonce verification for CSRF protection |
| 1352 |
if (!isset($_GET['_wpnonce']) && !wp_verify_nonce($_GET['_wpnonce'], $this->plugin_name . '-duplicate-poll')) { |
| 1353 |
wp_die( esc_html__('Security check error. Try again.', "poll-maker")); |
| 1354 |
} |
| 1355 |
|
| 1356 |
$poll_table = esc_sql($wpdb->prefix."ayspoll_polls"); |
| 1357 |
$answers_table = esc_sql($wpdb->prefix."ayspoll_answers"); |
| 1358 |
|
| 1359 |
$duplicate = $this->get_poll_by_id($id, false); |
| 1360 |
if (empty($duplicate)) { |
| 1361 |
$url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=failed'; |
| 1362 |
wp_redirect($url); |
| 1363 |
exit; |
| 1364 |
} |
| 1365 |
|
| 1366 |
$user_id = get_current_user_id(); |
| 1367 |
$user = get_userdata($user_id); |
| 1368 |
$author = array( |
| 1369 |
'id' => $user->ID, |
| 1370 |
'name' => $user->data->display_name |
| 1371 |
); |
| 1372 |
$options = json_decode($duplicate['styles'], true); |
| 1373 |
|
| 1374 |
$options['create_date'] = current_time( 'mysql' ); |
| 1375 |
$options['author'] = $author; |
| 1376 |
|
| 1377 |
$options['ays_add_post_for_poll'] = 'off'; |
| 1378 |
|
| 1379 |
$answers = $duplicate['answers']; |
| 1380 |
unset($duplicate['answers']); |
| 1381 |
unset($duplicate['id']); |
| 1382 |
$duplicate['title'] = "Copy - " . $duplicate['title']; |
| 1383 |
$duplicate['styles'] = json_encode($options); |
| 1384 |
$result = $wpdb->insert( |
| 1385 |
$poll_table, |
| 1386 |
$duplicate, |
| 1387 |
array( |
| 1388 |
'%d', // post_id |
| 1389 |
'%s', // title |
| 1390 |
'%s', // description |
| 1391 |
'%s', // question |
| 1392 |
'%s', // type |
| 1393 |
'%s', // view_type |
| 1394 |
'%s', // categories |
| 1395 |
'%s', // image |
| 1396 |
'%s', // show_title |
| 1397 |
'%s', // styles |
| 1398 |
'%s', // custom_css |
| 1399 |
'%d', // theme_id |
| 1400 |
) |
| 1401 |
); |
| 1402 |
|
| 1403 |
$poll_id = $wpdb->insert_id; |
| 1404 |
$answers_results = array(); |
| 1405 |
$flag = true; |
| 1406 |
|
| 1407 |
foreach ( $answers as $answer ) { |
| 1408 |
$answer['poll_id'] = $poll_id; |
| 1409 |
unset($answer['id']); |
| 1410 |
unset($answer['votes']); |
| 1411 |
$answers_results[] = $wpdb->insert( |
| 1412 |
$answers_table, |
| 1413 |
$answer, |
| 1414 |
array( |
| 1415 |
'%s', |
| 1416 |
'%s', |
| 1417 |
'%s', |
| 1418 |
) |
| 1419 |
); |
| 1420 |
} |
| 1421 |
|
| 1422 |
foreach ( $answers_results as $answers_result ) { |
| 1423 |
if ($answers_result >= 0) { |
| 1424 |
$flag = true; |
| 1425 |
} else { |
| 1426 |
$flag = false; |
| 1427 |
break; |
| 1428 |
} |
| 1429 |
} |
| 1430 |
$message = 'duplicated'; |
| 1431 |
if ($result >= 0 && $flag == true) { |
| 1432 |
|
| 1433 |
$post_type_args = array( |
| 1434 |
'poll_id' => $poll_id, |
| 1435 |
'author_id' => !empty($user->ID) ? $user->ID : $user_id, |
| 1436 |
'poll_title' => "Copy - ".$duplicate['title'], |
| 1437 |
); |
| 1438 |
|
| 1439 |
$custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args); |
| 1440 |
|
| 1441 |
$url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=' . $message; |
| 1442 |
wp_redirect($url); |
| 1443 |
exit; |
| 1444 |
} |
| 1445 |
|
| 1446 |
} |
| 1447 |
|
| 1448 |
public static function get_poll_pass_count($id) { |
| 1449 |
global $wpdb; |
| 1450 |
$poll_id = absint(sanitize_text_field($id)); |
| 1451 |
$args_id = esc_sql($poll_id); |
| 1452 |
$answ_table = esc_sql($wpdb->prefix."ayspoll_answers"); |
| 1453 |
$sql = "SELECT SUM(votes) FROM ".$answ_table." WHERE poll_id=%d"; |
| 1454 |
$result = $wpdb->get_var( |
| 1455 |
$wpdb->prepare( $sql, $args_id) |
| 1456 |
); |
| 1457 |
|
| 1458 |
return $result; |
| 1459 |
} |
| 1460 |
|
| 1461 |
public function get_poll_by_id( $id, $decode = true ) { |
| 1462 |
global $wpdb; |
| 1463 |
$poll_id = absint(sanitize_text_field($id)); |
| 1464 |
$poll_table = esc_sql($wpdb->prefix."ayspoll_polls"); |
| 1465 |
$answ_table = esc_sql($wpdb->prefix."ayspoll_answers"); |
| 1466 |
$sql = "SELECT * FROM ".$poll_table." WHERE id=%d"; |
| 1467 |
$poll = $wpdb->get_row( |
| 1468 |
$wpdb->prepare( $sql, $poll_id), |
| 1469 |
'ARRAY_A' |
| 1470 |
); |
| 1471 |
|
| 1472 |
if (empty($poll)) { |
| 1473 |
return array(); |
| 1474 |
} |
| 1475 |
|
| 1476 |
$sql_answ = "SELECT * FROM ".$answ_table." WHERE poll_id=%d ORDER BY ordering ASC, id ASC"; |
| 1477 |
$poll['answers'] = $wpdb->get_results( |
| 1478 |
$wpdb->prepare( $sql_answ, $poll_id), |
| 1479 |
'ARRAY_A' |
| 1480 |
); |
| 1481 |
|
| 1482 |
if ($decode) { |
| 1483 |
$cats = explode(',', $poll['categories']); |
| 1484 |
$poll['categories'] = !empty($cats) ? $cats : array(); |
| 1485 |
$json = $poll['styles']; |
| 1486 |
$poll['styles'] = json_decode($json, true); |
| 1487 |
} |
| 1488 |
|
| 1489 |
return $poll; |
| 1490 |
} |
| 1491 |
|
| 1492 |
/** Text displayed when no customer data is available */ |
| 1493 |
public function no_items() { |
| 1494 |
_e('There are no polls yet.', "poll-maker"); |
| 1495 |
} |
| 1496 |
|
| 1497 |
/** |
| 1498 |
* Render a column when no column specific method exist. |
| 1499 |
* |
| 1500 |
* @param array $item |
| 1501 |
* @param string $column_name |
| 1502 |
* |
| 1503 |
* @return mixed |
| 1504 |
*/ |
| 1505 |
public function column_default( $item, $column_name ) { |
| 1506 |
switch ( $column_name ) { |
| 1507 |
case 'title': |
| 1508 |
case 'poll_image': |
| 1509 |
case 'categories': |
| 1510 |
case 'type': |
| 1511 |
case 'shortcode': |
| 1512 |
case 'code_include': |
| 1513 |
case 'results': |
| 1514 |
case 'create_date': |
| 1515 |
case 'completed_count': |
| 1516 |
case 'id': |
| 1517 |
case 'publish': |
| 1518 |
return $item[$column_name]; |
| 1519 |
break; |
| 1520 |
default: |
| 1521 |
return print_r($item, true); //Show the whole array for troubleshooting purposes |
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
/** |
| 1526 |
* Render the bulk edit checkbox |
| 1527 |
* |
| 1528 |
* @param array $item |
| 1529 |
* |
| 1530 |
* @return string |
| 1531 |
*/ |
| 1532 |
function column_cb( $item ) { |
| 1533 |
return sprintf( |
| 1534 |
'<input type="checkbox" name="bulk-delete[]" value="%s" />', |
| 1535 |
$item['id'] |
| 1536 |
); |
| 1537 |
} |
| 1538 |
|
| 1539 |
/** |
| 1540 |
* Method for name column |
| 1541 |
* |
| 1542 |
* @param array $item an array of DB data |
| 1543 |
* |
| 1544 |
* @return string |
| 1545 |
*/ |
| 1546 |
function column_title( $item ) { |
| 1547 |
$delete_nonce = wp_create_nonce($this->plugin_name . '-delete-poll'); |
| 1548 |
$duplicate_nonce = wp_create_nonce($this->plugin_name . '-duplicate-poll'); |
| 1549 |
|
| 1550 |
$poll_title = stripcslashes($item['title']); |
| 1551 |
|
| 1552 |
$custom_post_id = isset($item['custom_post_id']) && $item['custom_post_id'] != 0 && $item['custom_post_id'] != '' ? esc_attr(intval($item['custom_post_id'])) : 0; |
| 1553 |
|
| 1554 |
$p = esc_attr($poll_title); |
| 1555 |
$polls_title_length = intval( $this->title_length ); |
| 1556 |
|
| 1557 |
$restitle = Poll_Maker_Ays_Admin::ays_restriction_string("word", $poll_title, $polls_title_length); |
| 1558 |
|
| 1559 |
$title = sprintf('<a href="?page=%s&action=%s&poll=%d" title="%s">%s</a>', esc_attr($_REQUEST['page']), 'edit', absint($item['id']), $p, $restitle); |
| 1560 |
|
| 1561 |
$actions['edit'] = sprintf( '<a href="?page=%s&action=%s&poll=%d">'. esc_html__('Edit', 'poll-maker') .'</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) ); |
| 1562 |
|
| 1563 |
$actions['duplicate'] = sprintf('<a href="?page=%s&action=%s&poll=%d&_wpnonce=%s">' .esc_html__('Duplicate', "poll-maker") . '</a>', esc_attr($_REQUEST['page']), 'duplicate', absint($item['id']),$duplicate_nonce); |
| 1564 |
|
| 1565 |
$actions['results'] = sprintf( '<a href="?page=%s&poll=%d&title=%s">'. esc_html__('View Results', 'poll-maker') .'</a>', esc_attr( $_REQUEST['page'] ) . '-results-each', absint( $item['id'] ), $poll_title ); |
| 1566 |
|
| 1567 |
if($custom_post_id > 0){ |
| 1568 |
$actions['custom_posts'] = sprintf( '<a href="%s" target="_blank">'. esc_html__('Preview', "poll-maker") .'</a>', esc_url( add_query_arg( 'preview', 'true', get_permalink($custom_post_id) ) )); |
| 1569 |
} |
| 1570 |
|
| 1571 |
$actions['delete'] = sprintf( '<a class="ays_confirm_del" data-message="%s" href="?page=%s&action=%s&poll=%d&_wpnonce=%s">'. esc_html__('Delete', 'poll-maker') .'</a>', $restitle, esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce ); |
| 1572 |
|
| 1573 |
|
| 1574 |
return $title . $this->row_actions($actions); |
| 1575 |
} |
| 1576 |
|
| 1577 |
function column_shortcode( $item ) { |
| 1578 |
$shortcode_content = '<div class="ays-poll-shortcode-container"> |
| 1579 |
<div class="ays-poll-copy-image" data-toggle="tooltip" aria-label="' . __( 'Click to copy', "poll-maker" ) . '" data-original-title="' . __( 'Click to copy', "poll-maker" ) . '"> |
| 1580 |
<img src="' . esc_url(POLL_MAKER_AYS_ADMIN_URL) . '/images/icons/edit-shortcode.svg"> |
| 1581 |
</div>'; |
| 1582 |
|
| 1583 |
$shortcode_input = sprintf('<input type="text" class="ays-poll-shortcode-input" onclick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id=%s]" />', $item["id"]); |
| 1584 |
|
| 1585 |
$shortcode_content .= $shortcode_input; |
| 1586 |
$shortcode_content .= '</div>'; |
| 1587 |
|
| 1588 |
return $shortcode_content; |
| 1589 |
} |
| 1590 |
|
| 1591 |
function column_code_include( $item ) { |
| 1592 |
return sprintf('<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="<?php echo do_shortcode(\'[ays_poll id=%s]\'); ?>" />', $item["id"]); |
| 1593 |
} |
| 1594 |
|
| 1595 |
function column_results($item) { |
| 1596 |
return sprintf('<a href="?page=%s&poll=%d&title=%s"><img src="'. esc_url(POLL_MAKER_AYS_ADMIN_URL) .'/images/icons/view-poll-results.svg"></a>', esc_attr( $_REQUEST['page'] ) . '-results-each', absint( $item['id']), $item['title']); |
| 1597 |
} |
| 1598 |
|
| 1599 |
function column_categories( $item ) { |
| 1600 |
if ($item['categories'] == '') { |
| 1601 |
return ''; |
| 1602 |
} |
| 1603 |
global $wpdb; |
| 1604 |
$cats_ids = explode(',', $item['categories']); |
| 1605 |
$cat_table = esc_sql($wpdb->prefix."ayspoll_categories"); |
| 1606 |
$category_location = "#"; |
| 1607 |
foreach ( $cats_ids as $id ) { |
| 1608 |
if (empty($id)) { |
| 1609 |
continue; |
| 1610 |
} |
| 1611 |
$args_id = absint( esc_sql($id) ); |
| 1612 |
$sql = "SELECT * FROM ".$cat_table." WHERE id=%d"; |
| 1613 |
|
| 1614 |
$result = $wpdb->get_row( |
| 1615 |
$wpdb->prepare( $sql, $args_id), |
| 1616 |
'ARRAY_A' |
| 1617 |
); |
| 1618 |
if (empty($result)) { |
| 1619 |
continue; |
| 1620 |
} |
| 1621 |
|
| 1622 |
if ( isset($result) && $result > 0 ) { |
| 1623 |
$category_location = sprintf( '<span>%s</span>', $result['title']); |
| 1624 |
} |
| 1625 |
|
| 1626 |
$cats_content = $category_location; |
| 1627 |
} |
| 1628 |
|
| 1629 |
return $cats_content; |
| 1630 |
} |
| 1631 |
|
| 1632 |
function column_create_date( $item ) { |
| 1633 |
$options = json_decode($item['styles'], true); |
| 1634 |
$date = isset($options['create_date']) && $options['create_date'] != '' ? sanitize_text_field($options['create_date']) : current_time( 'mysql' ); |
| 1635 |
if(isset($options['author'])){ |
| 1636 |
if(is_array($options['author'])){ |
| 1637 |
$author = $options['author']; |
| 1638 |
}else{ |
| 1639 |
$author = json_decode($options['author'], true); |
| 1640 |
} |
| 1641 |
}else{ |
| 1642 |
$author = array("name"=>"Unknown"); |
| 1643 |
} |
| 1644 |
$text = ""; |
| 1645 |
if(Poll_Maker_Ays_Admin::validateDate($date)){ |
| 1646 |
$text .= "<p><b>Date:</b> ".$date."</p>"; |
| 1647 |
} |
| 1648 |
if(isset($author['name']) && $author['name'] !== "Unknown"){ |
| 1649 |
$text .= "<p><b>Author:</b> ".$author['name']."</p>"; |
| 1650 |
} |
| 1651 |
return $text; |
| 1652 |
} |
| 1653 |
|
| 1654 |
function column_completed_count( $item ) { |
| 1655 |
$id = $item['id']; |
| 1656 |
$passed_count = $this->get_poll_pass_count($id); |
| 1657 |
$text = "<p style='text-align:center;font-size:14px;'>".$passed_count."</p>"; |
| 1658 |
return $text; |
| 1659 |
} |
| 1660 |
|
| 1661 |
function column_publish( $item ) { |
| 1662 |
global $wpdb; |
| 1663 |
$id = absint(sanitize_text_field($item['id'])); |
| 1664 |
$poll_table = esc_sql($wpdb->prefix."ayspoll_polls"); |
| 1665 |
$sql = "SELECT * FROM ".$poll_table." WHERE id=%d"; |
| 1666 |
|
| 1667 |
$res = $wpdb->get_row( |
| 1668 |
$wpdb->prepare( $sql, $id), |
| 1669 |
'ARRAY_A' |
| 1670 |
); |
| 1671 |
$options = json_decode($res['styles'], true); |
| 1672 |
$status = isset($options['published']) ? $options['published'] : 1; |
| 1673 |
|
| 1674 |
return $status ? "<i class=\"ays_poll_far ays_poll_fa-check-square\"></i> " .esc_html__("Published", "poll-maker") : "<i class=\"ays_poll_far ays_poll_fa-xmark-square\"></i> " .esc_html__("Unpublished", "poll-maker"); |
| 1675 |
} |
| 1676 |
|
| 1677 |
function column_poll_image( $item ) { |
| 1678 |
global $wpdb; |
| 1679 |
$poll_image = (isset( $item['image'] ) && $item['image'] != '') ? esc_url( $item['image'] ) : ''; |
| 1680 |
|
| 1681 |
$image_html = array(); |
| 1682 |
$edit_page_url = ''; |
| 1683 |
|
| 1684 |
if($poll_image != ''){ |
| 1685 |
|
| 1686 |
if ( isset( $item['id'] ) && absint( $item['id'] ) > 0 ) { |
| 1687 |
$edit_page_url = sprintf( 'href="?page=%s&action=%s&poll=%d"', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) ); |
| 1688 |
} |
| 1689 |
|
| 1690 |
$poll_image_url = $poll_image; |
| 1691 |
$this_site_path = trim( get_site_url(), "https:" ); |
| 1692 |
if( strpos( trim( $poll_image_url, "https:" ), $this_site_path ) !== false ){ |
| 1693 |
$query = "SELECT * FROM `" . $wpdb->prefix . "posts` WHERE `post_type` = 'attachment' AND `guid` = '" . $poll_image_url . "'"; |
| 1694 |
$result_img = $wpdb->get_results( $query, "ARRAY_A" ); |
| 1695 |
|
| 1696 |
if( ! empty( $result_img ) ){ |
| 1697 |
$url_img = wp_get_attachment_image_src( $result_img[0]['ID'], 'thumbnail' ); |
| 1698 |
if( $url_img !== false ){ |
| 1699 |
$poll_image_url = $url_img[0]; |
| 1700 |
} |
| 1701 |
} |
| 1702 |
} |
| 1703 |
|
| 1704 |
$image_html[] = '<div class="ays-poll-image-list-table-column">'; |
| 1705 |
$image_html[] = '<a '. $edit_page_url .' class="ays-poll-image-list-table-link-column">'; |
| 1706 |
$image_html[] = '<img src="'. $poll_image_url .'" class="ays-poll-image-list-table-img-column">'; |
| 1707 |
$image_html[] = '</a>'; |
| 1708 |
$image_html[] = '</div>'; |
| 1709 |
} |
| 1710 |
|
| 1711 |
$image_html = implode('', $image_html); |
| 1712 |
|
| 1713 |
return $image_html; |
| 1714 |
} |
| 1715 |
|
| 1716 |
/** |
| 1717 |
* Associative array of columns |
| 1718 |
* |
| 1719 |
* @return array |
| 1720 |
*/ |
| 1721 |
function get_columns() { |
| 1722 |
$columns = array( |
| 1723 |
'cb' => '<input type="checkbox" />', |
| 1724 |
'title' => esc_html__('Title', "poll-maker"), |
| 1725 |
'poll_image' => esc_html__('Question image', "poll-maker"), |
| 1726 |
'type' => esc_html__('Type', "poll-maker"), |
| 1727 |
'shortcode' => esc_html__('Shortcode', "poll-maker"), |
| 1728 |
'code_include' => esc_html__('Code Include', "poll-maker"), |
| 1729 |
'results' => esc_html__('Results', "poll-maker"), |
| 1730 |
'categories' => esc_html__('Categories', "poll-maker"), |
| 1731 |
'create_date' => esc_html__('Created', "poll-maker" ), |
| 1732 |
'completed_count' => esc_html__('Completed count', "poll-maker" ), |
| 1733 |
'publish' => esc_html__('Status', "poll-maker"), |
| 1734 |
'id' => esc_html__('ID', "poll-maker"), |
| 1735 |
); |
| 1736 |
|
| 1737 |
return $columns; |
| 1738 |
} |
| 1739 |
|
| 1740 |
/** |
| 1741 |
* Columns to make sortable. |
| 1742 |
* |
| 1743 |
* @return array |
| 1744 |
*/ |
| 1745 |
public function get_sortable_columns() { |
| 1746 |
$sortable_columns = array( |
| 1747 |
'title' => array('title', true), |
| 1748 |
'type' => array('type', true), |
| 1749 |
'id' => array('id', true), |
| 1750 |
); |
| 1751 |
|
| 1752 |
return $sortable_columns; |
| 1753 |
} |
| 1754 |
|
| 1755 |
/** |
| 1756 |
* Columns to make sortable. |
| 1757 |
* |
| 1758 |
* @return array |
| 1759 |
*/ |
| 1760 |
public function get_hidden_columns() { |
| 1761 |
$hidden_culumns = array( |
| 1762 |
'poll_image', |
| 1763 |
'code_include', |
| 1764 |
); |
| 1765 |
return $hidden_culumns; |
| 1766 |
} |
| 1767 |
|
| 1768 |
/** |
| 1769 |
* Returns an associative array containing the bulk action |
| 1770 |
* |
| 1771 |
* @return array |
| 1772 |
*/ |
| 1773 |
public function get_bulk_actions() { |
| 1774 |
$actions = array( |
| 1775 |
'bulk-delete' =>esc_html__('Delete', "poll-maker"), |
| 1776 |
); |
| 1777 |
|
| 1778 |
return $actions; |
| 1779 |
} |
| 1780 |
|
| 1781 |
/** |
| 1782 |
* Handles data query and filter, sorting, and pagination. |
| 1783 |
*/ |
| 1784 |
public function prepare_items() { |
| 1785 |
global $wpdb; |
| 1786 |
|
| 1787 |
$this->_column_headers = $this->get_column_info(); |
| 1788 |
|
| 1789 |
/** Process bulk action */ |
| 1790 |
$this->process_bulk_action(); |
| 1791 |
|
| 1792 |
$per_page = $this->get_items_per_page('polls_per_page', 20); |
| 1793 |
$current_page = $this->get_pagenum(); |
| 1794 |
$total_items = self::record_count(); |
| 1795 |
|
| 1796 |
$this->set_pagination_args(array( |
| 1797 |
'total_items' => $total_items, //WE have to calculate the total number of items |
| 1798 |
'per_page' => $per_page, //WE have to determine how many items to show on a page |
| 1799 |
)); |
| 1800 |
|
| 1801 |
$search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false; |
| 1802 |
$do_search = ( $search ) ? sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) ) : ''; |
| 1803 |
|
| 1804 |
$this->items = self::get_polls($per_page, $current_page, $do_search); |
| 1805 |
} |
| 1806 |
|
| 1807 |
public function process_bulk_action() { |
| 1808 |
//Detect when a bulk action is being triggered... |
| 1809 |
$message = 'deleted'; |
| 1810 |
if ('delete' === $this->current_action()) { |
| 1811 |
|
| 1812 |
// In our file that handles the request, verify the nonce. |
| 1813 |
$nonce = esc_attr($_REQUEST['_wpnonce']); |
| 1814 |
|
| 1815 |
if (!wp_verify_nonce($nonce, $this->plugin_name . '-delete-poll')) { |
| 1816 |
die('Go get a life script kiddies'); |
| 1817 |
} else { |
| 1818 |
self::delete_polls(absint($_GET['poll'])); |
| 1819 |
|
| 1820 |
// esc_url_raw() is used to prevent converting ampersand in url to "#038;" |
| 1821 |
// add_query_arg() return the current url |
| 1822 |
|
| 1823 |
$url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message; |
| 1824 |
wp_redirect($url); |
| 1825 |
} |
| 1826 |
} |
| 1827 |
|
| 1828 |
// If the delete bulk action is triggered |
| 1829 |
if ((isset($_POST['action']) && 'bulk-delete' == $_POST['action']) |
| 1830 |
|| (isset($_POST['action2']) && 'bulk-delete' == $_POST['action2']) |
| 1831 |
) { |
| 1832 |
|
| 1833 |
$delete_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array(); |
| 1834 |
|
| 1835 |
// loop over the array of record IDs and delete them |
| 1836 |
$deleted_polls_count = 0; |
| 1837 |
foreach ( $delete_ids as $id ) { |
| 1838 |
$deleted_polls_count++; |
| 1839 |
self::delete_polls($id); |
| 1840 |
} |
| 1841 |
|
| 1842 |
// esc_url_raw() is used to prevent converting ampersand in url to "#038;" |
| 1843 |
// add_query_arg() return the current url |
| 1844 |
|
| 1845 |
$url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message . '&d_count=' .$deleted_polls_count; |
| 1846 |
wp_redirect($url); |
| 1847 |
} |
| 1848 |
} |
| 1849 |
|
| 1850 |
/** |
| 1851 |
* Delete a customer record. |
| 1852 |
* |
| 1853 |
* @param int $id customer ID |
| 1854 |
*/ |
| 1855 |
public static function delete_polls( $id ) { |
| 1856 |
global $wpdb; |
| 1857 |
$poll_table = esc_sql($wpdb->prefix . "ayspoll_polls"); |
| 1858 |
$answ_table = esc_sql($wpdb->prefix . "ayspoll_answers"); |
| 1859 |
$reports_table = esc_sql($wpdb->prefix . "ayspoll_reports"); |
| 1860 |
$wpdb->delete( |
| 1861 |
$poll_table, |
| 1862 |
array('id' => $id), |
| 1863 |
array('%d') |
| 1864 |
); |
| 1865 |
$wpdb->delete( |
| 1866 |
$answ_table, |
| 1867 |
array('poll_id' => $id), |
| 1868 |
array('%d') |
| 1869 |
); |
| 1870 |
$sql = "DELETE FROM ".$reports_table." |
| 1871 |
WHERE answer_id NOT IN (SELECT id FROM ".$answ_table.")"; |
| 1872 |
$wpdb->query($sql); |
| 1873 |
} |
| 1874 |
|
| 1875 |
/** |
| 1876 |
* Returns the count of records in the database. |
| 1877 |
* |
| 1878 |
* @return null|string |
| 1879 |
*/ |
| 1880 |
public static function record_count() { |
| 1881 |
global $wpdb; |
| 1882 |
$poll_table = esc_sql($wpdb->prefix . "ayspoll_polls"); |
| 1883 |
$sql = "SELECT COUNT(*) FROM ".$poll_table; |
| 1884 |
$sql_count = self::get_where_condition(); |
| 1885 |
if(isset($sql_count) && !empty($sql_count)){ |
| 1886 |
$sql .= $sql_count; |
| 1887 |
} |
| 1888 |
return $wpdb->get_var($sql); |
| 1889 |
} |
| 1890 |
|
| 1891 |
public static function all_record_count() { |
| 1892 |
global $wpdb; |
| 1893 |
|
| 1894 |
$sql = "SELECT COUNT(*) FROM {$wpdb->prefix}ayspoll_polls"; |
| 1895 |
|
| 1896 |
if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) { |
| 1897 |
$cat_id = absint(intval($_GET['filterby'])); |
| 1898 |
if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") { |
| 1899 |
$sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'"; |
| 1900 |
} else { |
| 1901 |
$sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0"; |
| 1902 |
} |
| 1903 |
} |
| 1904 |
|
| 1905 |
return $wpdb->get_var( $sql ); |
| 1906 |
} |
| 1907 |
|
| 1908 |
public static function published_polls_count() { |
| 1909 |
global $wpdb; |
| 1910 |
|
| 1911 |
// Counters |
| 1912 |
$publishedCount = 0; |
| 1913 |
|
| 1914 |
$poll_table = esc_sql($wpdb->prefix . "ayspoll_polls"); |
| 1915 |
$sql = "SELECT * FROM " . $poll_table; |
| 1916 |
|
| 1917 |
if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) { |
| 1918 |
$cat_id = absint(intval($_GET['filterby'])); |
| 1919 |
if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") { |
| 1920 |
$sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'"; |
| 1921 |
} else { |
| 1922 |
$sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0"; |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
$results = $wpdb->get_results($sql, ARRAY_A); |
| 1927 |
|
| 1928 |
foreach ($results as $poll) { |
| 1929 |
$options = json_decode($poll['styles'], true); |
| 1930 |
$status = isset($options['published']) ? $options['published'] : 1; |
| 1931 |
|
| 1932 |
if ($status == 1) { |
| 1933 |
$publishedCount++; |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
return $publishedCount; |
| 1938 |
} |
| 1939 |
|
| 1940 |
public static function unpublished_polls_count() { |
| 1941 |
global $wpdb; |
| 1942 |
|
| 1943 |
// Counters |
| 1944 |
$unpublishedCount = 0; |
| 1945 |
|
| 1946 |
$poll_table = esc_sql($wpdb->prefix . "ayspoll_polls"); |
| 1947 |
$sql = "SELECT * FROM " . $poll_table; |
| 1948 |
|
| 1949 |
if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) { |
| 1950 |
$cat_id = absint(intval($_GET['filterby'])); |
| 1951 |
if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") { |
| 1952 |
$sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'"; |
| 1953 |
} else { |
| 1954 |
$sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0"; |
| 1955 |
} |
| 1956 |
} |
| 1957 |
|
| 1958 |
$results = $wpdb->get_results($sql, ARRAY_A); |
| 1959 |
|
| 1960 |
foreach ($results as $poll) { |
| 1961 |
$options = json_decode($poll['styles'], true); |
| 1962 |
$status = isset($options['published']) ? $options['published'] : 1; |
| 1963 |
|
| 1964 |
if ($status == 0) { |
| 1965 |
$unpublishedCount++; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
|
| 1969 |
return $unpublishedCount; |
| 1970 |
} |
| 1971 |
|
| 1972 |
public static function get_where_condition(){ |
| 1973 |
global $wpdb; |
| 1974 |
|
| 1975 |
$where = array(); |
| 1976 |
$sql = ''; |
| 1977 |
|
| 1978 |
$search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false; |
| 1979 |
if( $search ){ |
| 1980 |
$where[] = sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) ); |
| 1981 |
} |
| 1982 |
|
| 1983 |
if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){ |
| 1984 |
$cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) ); |
| 1985 |
|
| 1986 |
$where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) ); |
| 1987 |
} |
| 1988 |
|
| 1989 |
if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){ |
| 1990 |
if( esc_sql( $_REQUEST['fstatus'] ) != '' ){ |
| 1991 |
$fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) ); |
| 1992 |
$where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0'); |
| 1993 |
} |
| 1994 |
} |
| 1995 |
|
| 1996 |
if(isset( $_REQUEST['filterbyauthor'] ) && $_REQUEST['filterbyauthor'] > 0 ){ |
| 1997 |
$author_id = esc_sql( sanitize_text_field( $_REQUEST['filterbyauthor'] ) ); |
| 1998 |
|
| 1999 |
$where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $author_id ) ) ); |
| 2000 |
} |
| 2001 |
if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){ |
| 2002 |
$type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) ); |
| 2003 |
if (isset($type) && $type != '') { |
| 2004 |
$where[] = " type = '" . $type . "'"; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
|
| 2008 |
if( !empty($where) ){ |
| 2009 |
$sql = " WHERE " . implode( " AND ", $where ); |
| 2010 |
} |
| 2011 |
return $sql; |
| 2012 |
} |
| 2013 |
|
| 2014 |
/** |
| 2015 |
* Retrieve customers data from the database |
| 2016 |
* |
| 2017 |
* @param int $per_page |
| 2018 |
* @param int $page_number |
| 2019 |
* |
| 2020 |
* @return mixed |
| 2021 |
*/ |
| 2022 |
public static function get_polls( $per_page = 20, $page_number = 1 , $search = '') { |
| 2023 |
|
| 2024 |
global $wpdb; |
| 2025 |
$poll_table = esc_sql($wpdb->prefix . "ayspoll_polls"); |
| 2026 |
$sql = "SELECT * FROM ".$poll_table; |
| 2027 |
$args = array(); |
| 2028 |
|
| 2029 |
$where = array(); |
| 2030 |
|
| 2031 |
if( $search != '' ){ |
| 2032 |
$where[] = $search; |
| 2033 |
} |
| 2034 |
|
| 2035 |
if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){ |
| 2036 |
$cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) ); |
| 2037 |
|
| 2038 |
$where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) ); |
| 2039 |
} |
| 2040 |
|
| 2041 |
if ( isset( $_REQUEST['filterbyauthor'] ) && absint( $_REQUEST['filterbyauthor'] ) > 0 ) { |
| 2042 |
$poll_author = absint( $_REQUEST['filterbyauthor'] ); |
| 2043 |
$where[] = $wpdb->prepare( "JSON_EXTRACT(styles, '$.poll_create_author') = %d", $poll_author ); |
| 2044 |
} |
| 2045 |
|
| 2046 |
if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){ |
| 2047 |
$type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) ); |
| 2048 |
if (isset($type) && $type != '') { |
| 2049 |
$where[] = " type = '" . $type . "'"; |
| 2050 |
} |
| 2051 |
} |
| 2052 |
|
| 2053 |
if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){ |
| 2054 |
if( esc_sql( $_REQUEST['fstatus'] ) != '' ){ |
| 2055 |
$fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) ); |
| 2056 |
$where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0'); |
| 2057 |
} |
| 2058 |
} |
| 2059 |
|
| 2060 |
if( ! empty($where) ){ |
| 2061 |
$sql .= " WHERE " . implode( " AND ", $where ); |
| 2062 |
} |
| 2063 |
|
| 2064 |
if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 2065 |
|
| 2066 |
$order_by = ( isset( $_REQUEST['orderby'] ) && sanitize_text_field( $_REQUEST['orderby'] ) != '' ) ? sanitize_text_field( $_REQUEST['orderby'] ) : 'id'; |
| 2067 |
$order_by .= ( ! empty( $_REQUEST['order'] ) && strtolower( $_REQUEST['order'] ) == 'asc' ) ? ' ASC' : ' DESC'; |
| 2068 |
|
| 2069 |
$sql_orderby = sanitize_sql_orderby($order_by); |
| 2070 |
|
| 2071 |
if ( $sql_orderby ) { |
| 2072 |
$sql .= ' ORDER BY ' . $sql_orderby; |
| 2073 |
} else { |
| 2074 |
$sql .= ' ORDER BY id DESC'; |
| 2075 |
} |
| 2076 |
}else{ |
| 2077 |
$sql .= ' ORDER BY id DESC'; |
| 2078 |
} |
| 2079 |
|
| 2080 |
$sql .= " LIMIT %d"; |
| 2081 |
$args[] = $per_page; |
| 2082 |
$offset = ($page_number - 1) * $per_page; |
| 2083 |
$sql .= " OFFSET %d"; |
| 2084 |
$args[] = $offset; |
| 2085 |
$result = $wpdb->get_results( |
| 2086 |
$wpdb->prepare( $sql, $args), |
| 2087 |
'ARRAY_A' |
| 2088 |
); |
| 2089 |
|
| 2090 |
return $result; |
| 2091 |
} |
| 2092 |
|
| 2093 |
public function poll_notices() { |
| 2094 |
$status = (isset($_REQUEST['status'])) ? sanitize_text_field($_REQUEST['status']) : ''; |
| 2095 |
|
| 2096 |
if (empty($status)) { |
| 2097 |
return; |
| 2098 |
} |
| 2099 |
|
| 2100 |
if ('created' == $status) { |
| 2101 |
$updated_message = esc_html( esc_html__('Poll created.', "poll-maker")); |
| 2102 |
} elseif ('updated' == $status) { |
| 2103 |
$updated_message = esc_html( esc_html__('Poll saved.', "poll-maker")); |
| 2104 |
} elseif ('duplicated' == $status) { |
| 2105 |
$updated_message = esc_html( esc_html__('Poll duplicated.', "poll-maker")); |
| 2106 |
} elseif ('deleted' == $status) { |
| 2107 |
$deleted_count = isset($_GET['d_count']) && $_GET['d_count'] != "" ? intval(esc_attr($_GET['d_count'])) : 0; |
| 2108 |
$deleted_count_message =esc_html__('Poll deleted.', "poll-maker"); |
| 2109 |
if($deleted_count > 1){ |
| 2110 |
$deleted_count_message = $deleted_count .esc_html__(' Polls are deleted.', "poll-maker"); |
| 2111 |
} |
| 2112 |
$updated_message = $deleted_count_message; |
| 2113 |
} |
| 2114 |
|
| 2115 |
if (empty($updated_message)) { |
| 2116 |
return; |
| 2117 |
} |
| 2118 |
|
| 2119 |
?> |
| 2120 |
<div class="ays-poll-admin-notice notice notice-success is-dismissible"> |
| 2121 |
<p> |
| 2122 |
<?php echo $updated_message; ?> |
| 2123 |
</p> |
| 2124 |
</div> |
| 2125 |
<?php |
| 2126 |
} |
| 2127 |
} |
| 2128 |
|