PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.3
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.3
6.5.1 6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 All 154 releases
poll-maker / admin / partials / settings / poll-maker-settings-actions.php

poll-maker-settings-actions.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.3, at admin/partials/settings/poll-maker-settings-actions.php

294 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Poll_Maker_Settings_Actions {
3 private $plugin_name;
4
5 public function __construct($plugin_name) {
6 $this->plugin_name = $plugin_name;
7 // $this->check_setting_mailchimp();
8 }
9
10 public function store_data($data){
11 global $wpdb;
12 $settings_table = $wpdb->prefix . "ayspoll_settings";
13 if( isset($data["settings_action"]) && wp_verify_nonce( $data["settings_action"], 'settings_action' ) ){
14 $success = 0;
15 $roles = (isset($data['ays_user_roles']) && !empty($data['ays_user_roles'])) ? array_map( 'sanitize_text_field', $data['ays_user_roles'] ) : array('administrator');
16 $mailchimp_username = isset($data['ays_mailchimp_username']) ? stripslashes(sanitize_text_field($data['ays_mailchimp_username'])) : '';
17 $mailchimp_api_key = isset($data['ays_mailchimp_api_key']) ? (sanitize_text_field($data['ays_mailchimp_api_key'])) : '';
18
19 if (preg_match('/^[a-zA-Z0-9]+-[a-z]+\d+$/', $mailchimp_api_key)) {
20 $mailchimp_api_key = stripslashes($mailchimp_api_key);
21 } else {
22 $mailchimp_api_key = '';
23 }
24
25 $mailchimp = array(
26 'username' => $mailchimp_username,
27 'apiKey' => $mailchimp_api_key
28 );
29
30 $mailchimp = array(
31 'username' => $mailchimp_username,
32 'apiKey' => $mailchimp_api_key
33 );
34
35 $disable_ip_storing = (isset($data['ays_disable_ip_storing']) && $data['ays_disable_ip_storing'] == 'on') ? "on" : 'off';
36
37 $show_cat_title = isset($data['ays_poll_show_cat_title']) && $data['ays_poll_show_cat_title'] == 'on' ? $data['ays_poll_show_cat_title'] : 'off';
38
39
40 $answer_default_count = isset($data['ays_answer_default_count']) && !empty($data['ays_answer_default_count']) ? absint( sanitize_text_field($data['ays_answer_default_count']) ) : 2;
41
42 $answers_sound = isset($data['ays_poll_answers_sound']) ? sanitize_text_field($data['ays_poll_answers_sound']) : '';
43
44 // Poll title length
45 $poll_title_length = (isset($data['ays_poll_title_length']) && intval($data['ays_poll_title_length']) != 0) ? absint(intval($data['ays_poll_title_length'])) : 5;
46
47 // Poll Category Title length
48 $poll_category_title_length = (isset($data['ays_poll_category_title_length']) && intval($data['ays_poll_category_title_length']) != 0) ? absint(intval($data['ays_poll_category_title_length'])) : 5;
49
50 // Poll Results Title length
51 $poll_results_title_length = (isset($data['ays_poll_results_title_length']) && intval($data['ays_poll_results_title_length']) != 0) ? absint(intval($data['ays_poll_results_title_length'])) : 5;
52
53 // Default Category for poll
54 $ays_default_cat = (isset($data['ays_poll_default_cat']) && !empty($data['ays_poll_default_cat'])) ? sanitize_text_field(implode("," , $data['ays_poll_default_cat'])) : "1";
55
56 // Default Type for poll
57 $ays_default_type = (isset($data['ays_poll_default_type']) && $data['ays_poll_default_type'] != "") ? sanitize_text_field($data['ays_poll_default_type']) : "choosing";
58
59 // Poll expired and unpublished message
60 $all_shortcode_message = isset($data['ays_poll_all_polls_shortcodes']) && $data['ays_poll_all_polls_shortcodes'] != '' ? sanitize_text_field($data['ays_poll_all_polls_shortcodes']) : '';
61
62 // Show result view
63 $poll_show_result_view = isset($data['ays_poll_show_result_view']) ? sanitize_text_field($data['ays_poll_show_result_view']) : 'standart';
64
65 // Animation Top
66 $poll_animation_top = (isset($data['ays_poll_animation_top']) && $data['ays_poll_animation_top'] != '') ? absint(intval($data['ays_poll_animation_top'])) : 100;
67 $poll_enable_animation_top = (isset( $data['ays_poll_enable_animation_top'] ) && $data['ays_poll_enable_animation_top'] == 'on') ? 'on' : 'off';
68
69 // General CSS File
70 $poll_exclude_general_css = (isset( $data['ays_poll_exclude_general_css'] ) && sanitize_text_field( $data['ays_poll_exclude_general_css'] ) == 'on') ? 'on' : 'off';
71
72 // WP Editor height
73 $poll_wp_editor_height = (isset($data['ays_poll_wp_editor_height']) && $data['ays_poll_wp_editor_height'] != '' && $data['ays_poll_wp_editor_height'] != 0) ? absint( sanitize_text_field($data['ays_poll_wp_editor_height']) ) : 50;
74
75 $options = array(
76 "disable_ip_storing" => $disable_ip_storing,
77 "answer_default_count" => $answer_default_count,
78 "show_cat_title" => $show_cat_title,
79 "answers_sound" => $answers_sound,
80 "poll_title_length" => $poll_title_length,
81 "poll_category_title_length"=> $poll_category_title_length,
82 "poll_results_title_length" => $poll_results_title_length,
83 "default_category" => $ays_default_cat,
84 "default_type" => $ays_default_type,
85 "all_shortcode_message" => $all_shortcode_message,
86 "show_result_view" => $poll_show_result_view,
87 "poll_animation_top" => $poll_animation_top,
88 "poll_enable_animation_top" => $poll_enable_animation_top,
89 "poll_exclude_general_css" => $poll_exclude_general_css,
90 "poll_wp_editor_height" => $poll_wp_editor_height,
91 );
92
93 $poll_fields_placeholder_name = (isset($data['ays_poll_fields_placeholder_name']) && $data['ays_poll_fields_placeholder_name'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_placeholder_name'] )) : 'Name' ;
94 $poll_fields_placeholder_email = (isset($data['ays_poll_fields_placeholder_email']) && $data['ays_poll_fields_placeholder_email'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_placeholder_email'] )) : 'E-mail' ;
95 $poll_fields_placeholder_phone = (isset($data['ays_poll_fields_placeholder_phone']) && $data['ays_poll_fields_placeholder_phone'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_placeholder_phone'] )) : 'Phone' ;
96
97 $poll_fields_label_name = (isset($data['ays_poll_fields_label_name']) && $data['ays_poll_fields_label_name'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_label_name'] )) : 'Name' ;
98 $poll_fields_label_email = (isset($data['ays_poll_fields_label_email']) && $data['ays_poll_fields_label_email'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_label_email'] )) : 'E-mail' ;
99 $poll_fields_label_phone = (isset($data['ays_poll_fields_label_phone']) && $data['ays_poll_fields_label_phone'] != '') ? stripslashes(sanitize_text_field( $data['ays_poll_fields_label_phone'] )) : 'Phone' ;
100
101 $fields_placeholders = array(
102 'poll_fields_placeholder_name' => $poll_fields_placeholder_name,
103 'poll_fields_placeholder_email' => $poll_fields_placeholder_email,
104 'poll_fields_placeholder_phone' => $poll_fields_placeholder_phone,
105
106 'poll_fields_label_name' => $poll_fields_label_name,
107 'poll_fields_label_email' => $poll_fields_label_email,
108 'poll_fields_label_phone' => $poll_fields_label_phone,
109
110
111 );
112
113 $del_stat = "";
114 $month_count = isset($data['ays_delete_results_by']) ? intval(sanitize_text_field($data['ays_delete_results_by'])) : null;
115 if($month_count !== null && $month_count > 0){
116 $year = intval( date( 'Y', current_time('timestamp') ) );
117 $dt = intval( date( 'n', current_time('timestamp') ) );
118 $month = $dt - $month_count;
119 if($month < 0){
120 $month = 12 - $month;
121 if($month > 12){
122 $mn = $month % 12;
123 $mnac = ($month - $mn) / 12;
124 $month = 12 - ($mn);
125 $year -= $mnac;
126 }
127 }elseif($month == 0){
128 $month = 12;
129 $year--;
130 }
131 $sql = "DELETE FROM " . esc_sql($wpdb->prefix) . "ayspoll_reports
132 WHERE YEAR(vote_date) = '".esc_sql($year)."'
133 AND MONTH(vote_date) <= '".esc_sql($month)."'";
134 $res = $wpdb->query($sql);
135 if($res >= 0){
136 $del_stat = "&del_stat=ok&mcount=".$month_count;
137 }
138 }
139
140 $result = $this->ays_update_setting('mailchimp', json_encode($mailchimp));
141 if ($result) {
142 $success++;
143 }
144
145 $result = $this->ays_update_setting('options', json_encode($options));
146 if($result){
147 $success++;
148 }
149
150 $result = $this->ays_update_setting('fields_placeholders', json_encode($fields_placeholders, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
151 if ($result) {
152 $success++;
153 }
154
155 $message = "saved";
156 if($success > 0){
157 $tab = "";
158 if(isset($data['ays_poll_tab'])){
159 $tab = "&ays_poll_tab=".sanitize_text_field($data['ays_poll_tab']);
160 }
161 $url = admin_url('admin.php') . "?page=poll-maker-ays-settings" . $tab . '&status=' . $message.$del_stat;
162 wp_redirect( esc_url_raw($url) );
163 }
164 }
165
166 }
167
168 public function get_db_data(){
169 global $wpdb;
170 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
171 $sql = "SELECT * FROM ".$settings_table;
172
173 $results = $wpdb->get_results($sql, 'ARRAY_A');
174 if(count($results) > 0){
175 return $results;
176 }else{
177 return array();
178 }
179 }
180
181 public function check_setting_mailchimp(){
182 global $wpdb;
183 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
184 $mailchimp = esc_sql('mailchimp');
185 $sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = %s";
186
187 $result = $wpdb->get_var(
188 $wpdb->prepare( $sql, $mailchimp)
189 );
190
191 if(intval($result) == 0){
192 $this->ays_add_setting("mailchimp", "", "", "");
193 }
194 return false;
195 }
196
197 public function ays_get_setting($meta_key){
198 global $wpdb;
199 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
200 $key_meta = esc_sql($meta_key);
201
202 $sql = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = %s";
203
204 $result = $wpdb->get_var(
205 $wpdb->prepare( $sql, $key_meta)
206 );
207
208 if($result != ""){
209 return $result;
210 }
211 return false;
212 }
213
214 public function ays_add_setting($meta_key, $meta_value, $note = "", $options = ""){
215 global $wpdb;
216 $settings_table = $wpdb->prefix . "ayspoll_settings";
217 $result = $wpdb->insert(
218 $settings_table,
219 array(
220 'meta_key' => $meta_key,
221 'meta_value' => $meta_value,
222 'note' => $note,
223 'options' => $options
224 ),
225 array( '%s', '%s', '%s', '%s' )
226 );
227 if($result >= 0){
228 return true;
229 }
230 return false;
231 }
232
233 public function ays_update_setting($meta_key, $meta_value, $note = null, $options = null){
234 global $wpdb;
235 $settings_table = $wpdb->prefix . "ayspoll_settings";
236 $value = array(
237 'meta_value' => $meta_value,
238 );
239 $value_s = array( '%s' );
240 if($note != null){
241 $value['note'] = $note;
242 $value_s[] = '%s';
243 }
244 if($options != null){
245 $value['options'] = $options;
246 $value_s[] = '%s';
247 }
248 $result = $wpdb->update(
249 $settings_table,
250 $value,
251 array( 'meta_key' => $meta_key, ),
252 $value_s,
253 array( '%s' )
254 );
255 if($result >= 0){
256 return true;
257 }
258 return false;
259 }
260
261 public function ays_delete_setting($meta_key){
262 global $wpdb;
263 $settings_table = $wpdb->prefix . "ayspoll_settings";
264 $wpdb->delete(
265 $settings_table,
266 array( 'meta_key' => $meta_key ),
267 array( '%s' )
268 );
269 }
270
271
272 public function poll_settings_notices($status){
273
274 if ( empty( $status ) )
275 return;
276
277 if ( 'saved' == $status )
278 $updated_message = esc_html(esc_html__( 'Changes saved.', "poll-maker" ) );
279 elseif ( 'updated' == $status )
280 $updated_message = esc_html(esc_html__( 'Poll attribute .', "poll-maker" ) );
281 elseif ( 'deleted' == $status )
282 $updated_message = esc_html(esc_html__( 'Poll attribute deleted.', "poll-maker" ) );
283
284 if ( empty( $updated_message ) )
285 return;
286
287 ?>
288 <div class="ays-poll-admin-notice notice notice-success is-dismissible">
289 <p> <?php echo $updated_message; ?> </p>
290 </div>
291 <?php
292 }
293
294 }