PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.5
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.5
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 5.6.6 5.6.7 All 152 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.5, at admin/partials/settings/poll-maker-settings-actions.php

298 lines 13.5 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 // Menu notifications
73 $poll_disable_poll_menu_notification = (isset( $data['ays_poll_disable_poll_menu_notification'] ) && sanitize_text_field( $data['ays_poll_disable_poll_menu_notification'] ) == 'on') ? 'on' : 'off';
74
75 // WP Editor height
76 $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;
77
78 $options = array(
79 "disable_ip_storing" => $disable_ip_storing,
80 "answer_default_count" => $answer_default_count,
81 "show_cat_title" => $show_cat_title,
82 "answers_sound" => $answers_sound,
83 "poll_title_length" => $poll_title_length,
84 "poll_category_title_length"=> $poll_category_title_length,
85 "poll_results_title_length" => $poll_results_title_length,
86 "default_category" => $ays_default_cat,
87 "default_type" => $ays_default_type,
88 "all_shortcode_message" => $all_shortcode_message,
89 "show_result_view" => $poll_show_result_view,
90 "poll_animation_top" => $poll_animation_top,
91 "poll_enable_animation_top" => $poll_enable_animation_top,
92 "poll_exclude_general_css" => $poll_exclude_general_css,
93 "poll_disable_poll_menu_notification" => $poll_disable_poll_menu_notification,
94 "poll_wp_editor_height" => $poll_wp_editor_height,
95 );
96
97 $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' ;
98 $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' ;
99 $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' ;
100
101 $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' ;
102 $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' ;
103 $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' ;
104
105 $fields_placeholders = array(
106 'poll_fields_placeholder_name' => $poll_fields_placeholder_name,
107 'poll_fields_placeholder_email' => $poll_fields_placeholder_email,
108 'poll_fields_placeholder_phone' => $poll_fields_placeholder_phone,
109
110 'poll_fields_label_name' => $poll_fields_label_name,
111 'poll_fields_label_email' => $poll_fields_label_email,
112 'poll_fields_label_phone' => $poll_fields_label_phone,
113
114
115 );
116
117 $del_stat = "";
118 $month_count = isset($data['ays_delete_results_by']) ? intval(sanitize_text_field($data['ays_delete_results_by'])) : null;
119 if($month_count !== null && $month_count > 0){
120 $year = intval( date( 'Y', current_time('timestamp') ) );
121 $dt = intval( date( 'n', current_time('timestamp') ) );
122 $month = $dt - $month_count;
123 if($month < 0){
124 $month = 12 - $month;
125 if($month > 12){
126 $mn = $month % 12;
127 $mnac = ($month - $mn) / 12;
128 $month = 12 - ($mn);
129 $year -= $mnac;
130 }
131 }elseif($month == 0){
132 $month = 12;
133 $year--;
134 }
135 $sql = "DELETE FROM " . esc_sql($wpdb->prefix) . "ayspoll_reports
136 WHERE YEAR(vote_date) = '".esc_sql($year)."'
137 AND MONTH(vote_date) <= '".esc_sql($month)."'";
138 $res = $wpdb->query($sql);
139 if($res >= 0){
140 $del_stat = "&del_stat=ok&mcount=".$month_count;
141 }
142 }
143
144 $result = $this->ays_update_setting('mailchimp', json_encode($mailchimp));
145 if ($result) {
146 $success++;
147 }
148
149 $result = $this->ays_update_setting('options', json_encode($options));
150 if($result){
151 $success++;
152 }
153
154 $result = $this->ays_update_setting('fields_placeholders', json_encode($fields_placeholders, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
155 if ($result) {
156 $success++;
157 }
158
159 $message = "saved";
160 if($success > 0){
161 $tab = "";
162 if(isset($data['ays_poll_tab'])){
163 $tab = "&ays_poll_tab=".sanitize_text_field($data['ays_poll_tab']);
164 }
165 $url = admin_url('admin.php') . "?page=poll-maker-ays-settings" . $tab . '&status=' . $message.$del_stat;
166 wp_redirect( esc_url_raw($url) );
167 }
168 }
169
170 }
171
172 public function get_db_data(){
173 global $wpdb;
174 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
175 $sql = "SELECT * FROM ".$settings_table;
176
177 $results = $wpdb->get_results($sql, 'ARRAY_A');
178 if(count($results) > 0){
179 return $results;
180 }else{
181 return array();
182 }
183 }
184
185 public function check_setting_mailchimp(){
186 global $wpdb;
187 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
188 $mailchimp = esc_sql('mailchimp');
189 $sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = %s";
190
191 $result = $wpdb->get_var(
192 $wpdb->prepare( $sql, $mailchimp)
193 );
194
195 if(intval($result) == 0){
196 $this->ays_add_setting("mailchimp", "", "", "");
197 }
198 return false;
199 }
200
201 public function ays_get_setting($meta_key){
202 global $wpdb;
203 $settings_table = esc_sql($wpdb->prefix . "ayspoll_settings");
204 $key_meta = esc_sql($meta_key);
205
206 $sql = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = %s";
207
208 $result = $wpdb->get_var(
209 $wpdb->prepare( $sql, $key_meta)
210 );
211
212 if($result != ""){
213 return $result;
214 }
215 return false;
216 }
217
218 public function ays_add_setting($meta_key, $meta_value, $note = "", $options = ""){
219 global $wpdb;
220 $settings_table = $wpdb->prefix . "ayspoll_settings";
221 $result = $wpdb->insert(
222 $settings_table,
223 array(
224 'meta_key' => $meta_key,
225 'meta_value' => $meta_value,
226 'note' => $note,
227 'options' => $options
228 ),
229 array( '%s', '%s', '%s', '%s' )
230 );
231 if($result >= 0){
232 return true;
233 }
234 return false;
235 }
236
237 public function ays_update_setting($meta_key, $meta_value, $note = null, $options = null){
238 global $wpdb;
239 $settings_table = $wpdb->prefix . "ayspoll_settings";
240 $value = array(
241 'meta_value' => $meta_value,
242 );
243 $value_s = array( '%s' );
244 if($note != null){
245 $value['note'] = $note;
246 $value_s[] = '%s';
247 }
248 if($options != null){
249 $value['options'] = $options;
250 $value_s[] = '%s';
251 }
252 $result = $wpdb->update(
253 $settings_table,
254 $value,
255 array( 'meta_key' => $meta_key, ),
256 $value_s,
257 array( '%s' )
258 );
259 if($result >= 0){
260 return true;
261 }
262 return false;
263 }
264
265 public function ays_delete_setting($meta_key){
266 global $wpdb;
267 $settings_table = $wpdb->prefix . "ayspoll_settings";
268 $wpdb->delete(
269 $settings_table,
270 array( 'meta_key' => $meta_key ),
271 array( '%s' )
272 );
273 }
274
275
276 public function poll_settings_notices($status){
277
278 if ( empty( $status ) )
279 return;
280
281 if ( 'saved' == $status )
282 $updated_message = esc_html(esc_html__( 'Changes saved.', "poll-maker" ) );
283 elseif ( 'updated' == $status )
284 $updated_message = esc_html(esc_html__( 'Poll attribute .', "poll-maker" ) );
285 elseif ( 'deleted' == $status )
286 $updated_message = esc_html(esc_html__( 'Poll attribute deleted.', "poll-maker" ) );
287
288 if ( empty( $updated_message ) )
289 return;
290
291 ?>
292 <div class="ays-poll-admin-notice notice notice-success is-dismissible">
293 <p> <?php echo $updated_message; ?> </p>
294 </div>
295 <?php
296 }
297
298 }