PluginProbe
Survey Maker by AYS / 5.2.1.8
Survey Maker by AYS v5.2.1.8
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / includes / class-survey-maker-data.php

class-survey-maker-data.php in Survey Maker by AYS 5.2.1.8, at includes/class-survey-maker-data.php

2,712 lines 159.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The public-facing functionality of the plugin.
4 *
5 * @link http://ays-pro.com/
6 * @since 1.0.0
7 *
8 * @package Survey_Maker
9 * @subpackage Survey_Maker/includes
10 */
11
12 /**
13 * The public-facing functionality of the plugin.
14 *
15 * Defines the plugin name, version, and two examples hooks for how to
16 * enqueue the public-facing stylesheet and JavaScript.
17 *
18 * @package Survey_Maker
19 * @subpackage Survey_Maker/includes
20 * @author AYS Pro LLC <[email protected]>
21 */
22 class Survey_Maker_Data {
23
24 public static function get_survey_validated_data_from_array( $survey, $attr ){
25 global $wpdb;
26
27 // Array for survey validated options
28 $settings = array();
29 $name_prefix = 'survey_';
30
31 // ID
32 $id = ( isset($attr['id']) ) ? absint( intval( $attr['id'] ) ) : null;
33 $settings['id'] = $id;
34
35 // Survey options
36 $options = array();
37 if( isset( $survey->options ) && $survey->options != '' ){
38 $options = json_decode( $survey->options, true );
39 }
40
41 $settings[ 'options' ] = $options;
42
43 $survey_answers_alignment_grid_types = array(
44 "space_around",
45 "space_between",
46 );
47
48 // ======================= // ======================= // ======================= // ======================= // ======================= //
49
50
51 // =============================================================
52 // ====================== Styles Tab =====================
53 // ======================== START ========================
54
55
56 // Survey Theme
57 $settings[ $name_prefix . 'theme' ] = (isset($options[ $name_prefix . 'theme' ]) && $options[ $name_prefix . 'theme' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'theme' ] ) ) : 'classic_light';
58 $settings[ $name_prefix . 'is_minimal' ] = $settings[ $name_prefix . 'theme' ] == 'minimal' ? true : false;
59 $settings[ $name_prefix . 'is_modern' ] = $settings[ $name_prefix . 'theme' ] == 'modern' ? true : false;
60
61 // Survey Color
62 $settings[ $name_prefix . 'color' ] = (isset($options[ $name_prefix . 'color' ]) && $options[ $name_prefix . 'color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'color' ] ) ) : '#ff5722'; // '#673ab7'
63
64 // Background color
65 $settings[ $name_prefix . 'background_color' ] = (isset($options[ $name_prefix . 'background_color' ]) && $options[ $name_prefix . 'background_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'background_color' ] ) ) : '#fff';
66
67 // Text Color
68 $settings[ $name_prefix . 'text_color' ] = (isset($options[ $name_prefix . 'text_color' ]) && $options[ $name_prefix . 'text_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'text_color' ] ) ) : '#333';
69
70 // Loader Color
71 $settings[ $name_prefix . 'loader_color' ] = (isset($options[ $name_prefix . 'loader_color' ]) && $options[ $name_prefix . 'loader_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'loader_color' ] ) ) : $settings[ $name_prefix . 'text_color' ];
72
73 // Buttons text Color
74 $settings[ $name_prefix . 'buttons_text_color' ] = (isset($options[ $name_prefix . 'buttons_text_color' ]) && $options[ $name_prefix . 'buttons_text_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'buttons_text_color' ] ) ) : $settings[ $name_prefix . 'text_color' ];
75
76 // Width
77 $settings[ $name_prefix . 'width' ] = (isset($options[ $name_prefix . 'width' ]) && $options[ $name_prefix . 'width' ] != '') ? absint ( intval( $options[ $name_prefix . 'width' ] ) ) : '';
78
79 // Survey Width by percentage or pixels
80 $settings[ $name_prefix . 'width_by_percentage_px' ] = (isset($options[ $name_prefix . 'width_by_percentage_px' ]) && $options[ $name_prefix . 'width_by_percentage_px' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'width_by_percentage_px' ] ) ) : 'pixels';
81
82 // Mobile width
83 $settings[ $name_prefix . 'mobile_width' ] = (isset($options[ $name_prefix . 'mobile_width' ]) && $options[ $name_prefix . 'mobile_width' ] != '') ? absint ( intval( $options[ $name_prefix . 'mobile_width' ] ) ) : '';
84
85 // Survey mobile width by percentage or pixels
86 $settings[ $name_prefix . 'mobile_width_by_percent_px' ] = (isset($options[ $name_prefix . 'mobile_width_by_percent_px' ]) && $options[ $name_prefix . 'mobile_width_by_percent_px' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'mobile_width_by_percent_px' ] ) ) : 'pixels';
87
88 // Survey container max width
89 $settings[ $name_prefix . 'mobile_max_width' ] = (isset($options[ $name_prefix . 'mobile_max_width' ]) && $options[ $name_prefix . 'mobile_max_width' ] != '') ? absint ( intval( $options[ $name_prefix . 'mobile_max_width' ] ) ) : '';
90
91 // Custom class for survey container
92 $settings[ $name_prefix . 'custom_class' ] = (isset($options[ $name_prefix . 'custom_class' ]) && $options[ $name_prefix . 'custom_class' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'custom_class' ] ) ) : '';
93
94 // Custom CSS
95 $settings[ $name_prefix . 'custom_css' ] = (isset($options[ $name_prefix . 'custom_css' ]) && $options[ $name_prefix . 'custom_css' ] != '') ? stripslashes ( html_entity_decode( $options[ $name_prefix . 'custom_css' ] ) ) : '';
96
97 // Survey logo
98 $settings[ $name_prefix . 'logo' ] = (isset($options[ $name_prefix . 'logo' ]) && $options[ $name_prefix . 'logo' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'logo' ] ) ) : '';
99
100 // Survey logo position
101 $settings[ $name_prefix . 'logo_image_position' ] = (isset($options[ $name_prefix . 'logo_image_position' ]) && $options[ $name_prefix . 'logo_image_position' ] != '') ? esc_attr( $options[ $name_prefix . 'logo_image_position' ] ) : 'right';
102 // Survey logo position mobile
103 $options[ $name_prefix . 'logo_image_position_mobile' ] = isset($options[ $name_prefix . 'logo_image_position_mobile' ]) ? $options[ $name_prefix . 'logo_image_position_mobile' ] : $settings[ $name_prefix . 'logo_image_position' ];
104 $settings[ $name_prefix . 'logo_image_position_mobile' ] = (isset($options[ $name_prefix . 'logo_image_position_mobile' ]) && $options[ $name_prefix . 'logo_image_position_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'logo_image_position_mobile' ] ) : 'right';
105
106 // Survey logo title
107 $settings[ $name_prefix . 'logo_title' ] = (isset($options[ $name_prefix . 'logo_title' ]) && $options[ $name_prefix . 'logo_title' ] != '') ? esc_attr( $options[ $name_prefix . 'logo_title' ] ) : '';
108
109 // Survey cover photo
110 $settings[ $name_prefix . 'cover_photo' ] = (isset($options[ $name_prefix . 'cover_photo' ]) && $options[ $name_prefix . 'cover_photo' ] != '') ? stripslashes( esc_attr( $options[ $name_prefix . 'cover_photo' ] ) ) : '';
111
112 // Survey cover photo height
113 $settings[ $name_prefix . 'cover_photo_height' ] = (isset($options[ $name_prefix . 'cover_photo_height' ]) && $options[ $name_prefix . 'cover_photo_height' ] != '') ? esc_attr( $options[ $name_prefix . 'cover_photo_height' ] ) : 150;
114
115 // Survey cover photo mobile height
116 $settings[ $name_prefix . 'cover_photo_mobile_height' ] = (isset($options[ $name_prefix . 'cover_photo_mobile_height' ]) && $options[ $name_prefix . 'cover_photo_mobile_height' ] != '') ? esc_attr( $options[ $name_prefix . 'cover_photo_mobile_height' ] ) : $settings[ $name_prefix . 'cover_photo_height' ];
117
118 // Survey cover photo position
119 $settings[ $name_prefix . 'cover_photo_position' ] = (isset($options[ $name_prefix . 'cover_photo_position' ]) && $options[ $name_prefix . 'cover_photo_position' ] != '') ? esc_attr( $options[ $name_prefix . 'cover_photo_position' ] ) : "center_center";
120
121 // Survey cover photo object fit
122 $settings[ $name_prefix . 'cover_photo_object_fit' ] = (isset($options[ $name_prefix . 'cover_photo_object_fit' ]) && $options[ $name_prefix . 'cover_photo_object_fit' ] != '') ? esc_attr( $options[ $name_prefix . 'cover_photo_object_fit' ] ) : "cover";
123
124 // Survey cover only first section
125 $settings[ $name_prefix . 'cover_only_first_section' ] = (isset($options[ $name_prefix . 'cover_only_first_section' ]) && $options[ $name_prefix . 'cover_only_first_section' ] == 'on') ? true : false;
126
127 // Survey title alignment
128 $settings[ $name_prefix . 'title_alignment' ] = (isset( $options[ $name_prefix . 'title_alignment' ] ) && $options[ $name_prefix . 'title_alignment' ] != '') ? esc_attr( $options[ $name_prefix . 'title_alignment' ] ) : 'left';
129
130 // Survey title alignment mobile
131 $options[ $name_prefix . 'title_alignment_mobile' ] = isset( $options[ $name_prefix . 'title_alignment_mobile' ] ) ? $options[ $name_prefix . 'title_alignment_mobile' ] : $settings[ $name_prefix . 'title_alignment' ];
132 $settings[ $name_prefix . 'title_alignment_mobile' ] = (isset( $options[ $name_prefix . 'title_alignment_mobile' ] ) && $options[ $name_prefix . 'title_alignment_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'title_alignment_mobile' ] ) : 'left';
133
134 // Survey title font size
135 $settings[ $name_prefix . 'title_font_size' ] = (isset( $options[ $name_prefix . 'title_font_size' ] ) && $options[ $name_prefix . 'title_font_size' ] != '' && $options[ $name_prefix . 'title_font_size' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'title_font_size' ] ) : 30;
136
137 // Survey title letter spacing
138 $settings[ $name_prefix . 'title_letter_spacing' ] = (isset( $options[ $name_prefix . 'title_letter_spacing' ] ) && $options[ $name_prefix . 'title_letter_spacing' ] != '' && $options[ $name_prefix . 'title_letter_spacing' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'title_letter_spacing' ] ) : 0;
139
140 // Survey title letter spacing mobile
141 $settings[ $name_prefix . 'title_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'title_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'title_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'title_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'title_letter_spacing_mobile' ] ) : $settings[ $name_prefix . 'title_letter_spacing' ];
142
143 // Survey title font size mobile
144 $settings[ $name_prefix . 'title_font_size_for_mobile' ] = (isset( $options[ $name_prefix . 'title_font_size_for_mobile' ] ) && $options[ $name_prefix . 'title_font_size_for_mobile' ] != '' && $options[ $name_prefix . 'title_font_size_for_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'title_font_size_for_mobile' ] ) : 30;
145
146 // Survey title box shadow
147 $settings[ $name_prefix . 'title_box_shadow_enable' ] = (isset( $options[ $name_prefix . 'title_box_shadow_enable' ] ) && $options[ $name_prefix . 'title_box_shadow_enable' ] == 'on' ) ? true : false;
148
149 // === Survey title box shadow offsets start ===
150 // Survey title box shadow offset x
151 $settings[ $name_prefix . 'title_text_shadow_x_offset' ] = ( isset($options[ $name_prefix . 'title_text_shadow_x_offset' ] ) && $options[ $name_prefix . 'title_text_shadow_x_offset' ] != "") ? esc_attr($options[ $name_prefix . 'title_text_shadow_x_offset' ]) : 0;
152 // Survey title box shadow offset y
153 $settings[ $name_prefix . 'title_text_shadow_y_offset' ] = ( isset($options[ $name_prefix . 'title_text_shadow_y_offset' ] ) && $options[ $name_prefix . 'title_text_shadow_y_offset' ] != "") ? esc_attr($options[ $name_prefix . 'title_text_shadow_y_offset' ]) : 0;
154 // Survey title box shadow offset z
155 $settings[ $name_prefix . 'title_text_shadow_z_offset' ] = ( isset($options[ $name_prefix . 'title_text_shadow_z_offset' ] ) && $options[ $name_prefix . 'title_text_shadow_z_offset' ] != "") ? esc_attr($options[ $name_prefix . 'title_text_shadow_z_offset' ]) : 10;
156 // === Survey title box shadow offsets end ===
157
158 // Survey title box shadow color
159 $settings[ $name_prefix . 'title_box_shadow_color' ] = (isset( $options[ $name_prefix . 'title_box_shadow_color' ] ) && $options[ $name_prefix . 'title_box_shadow_color' ] != '' ) ? esc_attr( $options[ $name_prefix . 'title_box_shadow_color' ] ) : '#333';
160
161 // Survey section title font size PC
162 $settings[ $name_prefix . 'section_title_font_size' ] = (isset( $options[ $name_prefix . 'section_title_font_size' ] ) && $options[ $name_prefix . 'section_title_font_size' ] != '' && $options[ $name_prefix . 'section_title_font_size' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_title_font_size' ] ) : 32;
163 // Survey section title font size Mobile
164 $settings[ $name_prefix . 'section_title_font_size_mobile' ] = (isset( $options[ $name_prefix . 'section_title_font_size_mobile' ] ) && $options[ $name_prefix . 'section_title_font_size_mobile' ] != '' && $options[ $name_prefix . 'section_title_font_size_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_title_font_size_mobile' ] ) : 32;
165
166 // Survey section title alignment
167 $settings[ $name_prefix . 'section_title_alignment' ] = (isset( $options[ $name_prefix . 'section_title_alignment' ] ) && $options[ $name_prefix . 'section_title_alignment' ] != '') ? esc_attr( $options[ $name_prefix . 'section_title_alignment' ] ) : 'left';
168
169 // Survey section title alignment mobile
170 $options[ $name_prefix . 'section_title_alignment_mobile' ] = isset($options[ $name_prefix . 'section_title_alignment_mobile' ]) ? $options[ $name_prefix . 'section_title_alignment_mobile' ] : $settings[ $name_prefix . 'section_title_alignment' ];
171 $settings[ $name_prefix . 'section_title_alignment_mobile' ] = (isset( $options[ $name_prefix . 'section_title_alignment_mobile' ] ) && $options[ $name_prefix . 'section_title_alignment_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'section_title_alignment_mobile' ] ) : 'left';
172
173 // Survey section title letter spacing
174 $settings[ $name_prefix . 'section_title_letter_spacing' ] = (isset( $options[ $name_prefix . 'section_title_letter_spacing' ] ) && $options[ $name_prefix . 'section_title_letter_spacing' ] != '' && $options[ $name_prefix . 'section_title_letter_spacing' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_title_letter_spacing' ] ) : 0;
175
176 // Survey section title letter spacing mobile
177 $settings[ $name_prefix . 'section_title_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'section_title_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'section_title_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'section_title_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_title_letter_spacing_mobile' ] ) : $settings[ $name_prefix . 'section_title_letter_spacing' ];
178
179 // Survey section description alignment
180 $settings[ $name_prefix . 'section_description_alignment' ] = (isset( $options[ $name_prefix . 'section_description_alignment' ] ) && $options[ $name_prefix . 'section_description_alignment' ] != '') ? esc_attr( $options[ $name_prefix . 'section_description_alignment' ] ) : 'left';
181 // Survey section description alignment mobile
182 $options[ $name_prefix . 'section_description_alignment_mobile' ] = isset($options[ $name_prefix . 'section_description_alignment_mobile' ]) ? $options[ $name_prefix . 'section_description_alignment_mobile' ] : $settings[ $name_prefix . 'section_description_alignment' ];
183 $settings[ $name_prefix . 'section_description_alignment_mobile' ] = (isset( $options[ $name_prefix . 'section_description_alignment_mobile' ] ) && $options[ $name_prefix . 'section_description_alignment_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'section_description_alignment_mobile' ] ) : 'left';
184
185 // Survey section description font size
186 $settings[ $name_prefix . 'section_description_font_size' ] = (isset( $options[ $name_prefix . 'section_description_font_size' ] ) && $options[ $name_prefix . 'section_description_font_size' ] != '' && $options[ $name_prefix . 'section_description_font_size' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_description_font_size' ] ) : 14;
187
188 // Survey section description font size mobile
189 $settings[ $name_prefix . 'section_description_font_size_mobile' ] = (isset( $options[ $name_prefix . 'section_description_font_size_mobile' ] ) && $options[ $name_prefix . 'section_description_font_size_mobile' ] != '' && $options[ $name_prefix . 'section_description_font_size_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_description_font_size_mobile' ] ) : 14;
190
191 // Survey section description letter spacing
192 $settings[ $name_prefix . 'section_description_letter_spacing' ] = (isset( $options[ $name_prefix . 'section_description_letter_spacing' ] ) && $options[ $name_prefix . 'section_description_letter_spacing' ] != '' && $options[ $name_prefix . 'section_description_letter_spacing' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_description_letter_spacing' ] ) : 0;
193
194 // Survey section description letter spacing mobile
195 $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] = isset($options[ $name_prefix . 'section_description_letter_spacing_mobile' ]) ? $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] : $settings[ $name_prefix . 'section_description_letter_spacing' ];
196 $settings[ $name_prefix . 'section_description_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'section_description_letter_spacing_mobile' ] ) : 0;
197
198 // =========== Questions Styles Start ===========
199
200 // Question font size
201 $settings[ $name_prefix . 'question_font_size' ] = (isset($options[ $name_prefix . 'question_font_size' ]) && $options[ $name_prefix . 'question_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_font_size' ] ) ) : 16;
202
203 // Question font size mobile
204 $settings[ $name_prefix . 'question_font_size_mobile' ] = (isset($options[ $name_prefix . 'question_font_size_mobile' ]) && $options[ $name_prefix . 'question_font_size_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_font_size_mobile' ] ) ) : 16;
205
206 // Question title alignment
207 $settings[ $name_prefix . 'question_title_alignment' ] = (isset($options[ $name_prefix . 'question_title_alignment' ]) && $options[ $name_prefix . 'question_title_alignment' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_title_alignment' ] ) ) : 'left';
208
209 // Question Image Width
210 $settings[ $name_prefix . 'question_image_width' ] = (isset($options[ $name_prefix . 'question_image_width' ]) && $options[ $name_prefix . 'question_image_width' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_image_width' ] ) ) : '';
211 // Question Image Width mobile
212 $options[ $name_prefix . 'question_image_width_mobile' ] = isset($options[ $name_prefix . 'question_image_width_mobile' ]) ? $options[ $name_prefix . 'question_image_width_mobile' ] : $settings[ $name_prefix . 'question_image_width' ];
213 $settings[ $name_prefix . 'question_image_width_mobile' ] = (isset($options[ $name_prefix . 'question_image_width_mobile' ]) && $options[ $name_prefix . 'question_image_width_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_image_width_mobile' ] ) ) : '';
214
215 // Question Image Height
216 $settings[ $name_prefix . 'question_image_height' ] = (isset($options[ $name_prefix . 'question_image_height' ]) && $options[ $name_prefix . 'question_image_height' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_image_height' ] ) ) : '';
217 // Question Image Height mobile
218 $options[ $name_prefix . 'question_image_height_mobile' ] = isset($options[ $name_prefix . 'question_image_height_mobile' ]) ? $options[ $name_prefix . 'question_image_height_mobile' ] : $settings[ $name_prefix . 'question_image_height' ];
219 $settings[ $name_prefix . 'question_image_height_mobile' ] = (isset($options[ $name_prefix . 'question_image_height_mobile' ]) && $options[ $name_prefix . 'question_image_height_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_image_height_mobile' ] ) ) : '';
220
221 // Question Image sizing
222 $settings[ $name_prefix . 'question_image_sizing' ] = (isset($options[ $name_prefix . 'question_image_sizing' ]) && $options[ $name_prefix . 'question_image_sizing' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_image_sizing' ] ) ) : 'cover';
223 // Question Image sizing mobile
224 $options[ $name_prefix . 'question_image_sizing_mobile' ] = isset($options[ $name_prefix . 'question_image_sizing_mobile' ]) ? $options[ $name_prefix . 'question_image_sizing_mobile' ] : $settings[ $name_prefix . 'question_image_sizing' ];
225 $settings[ $name_prefix . 'question_image_sizing_mobile' ] = (isset($options[ $name_prefix . 'question_image_sizing_mobile' ]) && $options[ $name_prefix . 'question_image_sizing_mobile' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_image_sizing_mobile' ] ) ) : 'cover';
226
227 // Question padding
228 $settings[ $name_prefix . 'question_padding' ] = (isset($options[ $name_prefix . 'question_padding' ]) && $options[ $name_prefix . 'question_padding' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_padding' ] ) ) : 24;
229
230 // Question padding mobile
231 $options[ $name_prefix . 'question_padding_mobile' ] = isset($options[ $name_prefix . 'question_padding_mobile' ]) ? $options[ $name_prefix . 'question_padding_mobile' ] : $settings[ $name_prefix . 'question_padding' ];
232 $settings[ $name_prefix . 'question_padding_mobile' ] = (isset($options[ $name_prefix . 'question_padding_mobile' ]) && $options[ $name_prefix . 'question_padding_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_padding_mobile' ] ) ) : 24;
233
234 // Question border radius
235 $settings[ $name_prefix . 'question_border_radius' ] = (isset($options[ $name_prefix . 'question_border_radius' ]) && $options[ $name_prefix . 'question_border_radius' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_border_radius' ] ) ) : 8;
236
237 // Question border radius mobile
238 $options[ $name_prefix . 'question_border_radius_mobile' ] = isset($options[ $name_prefix . 'question_border_radius_mobile' ]) ? $options[ $name_prefix . 'question_border_radius_mobile' ] : $settings[ $name_prefix . 'question_border_radius' ];
239 $settings[ $name_prefix . 'question_border_radius_mobile' ] = (isset($options[ $name_prefix . 'question_border_radius_mobile' ]) && $options[ $name_prefix . 'question_border_radius_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_border_radius_mobile' ] ) ) : 8;
240
241 // Question caption text color
242 $settings[ $name_prefix . 'question_caption_text_color' ] = (isset($options[ $name_prefix . 'question_caption_text_color' ]) && $options[ $name_prefix . 'question_caption_text_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_caption_text_color' ] ) ) : $settings[ $name_prefix . 'text_color' ];
243 // Question caption text color mobile
244 $options[ $name_prefix . 'question_caption_text_color_mobile' ] = (isset($options[ $name_prefix . 'question_caption_text_color_mobile' ])) ? $options[ $name_prefix . 'question_caption_text_color_mobile' ] : $settings[ $name_prefix . 'question_caption_text_color' ];
245 $settings[ $name_prefix . 'question_caption_text_color_mobile' ] = (isset($options[ $name_prefix . 'question_caption_text_color_mobile' ]) && $options[ $name_prefix . 'question_caption_text_color_mobile' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_caption_text_color_mobile' ] ) ) : $settings[ $name_prefix . 'text_color' ];
246
247 // Question caption text alignment
248 $settings[ $name_prefix . 'question_caption_text_alignment' ] = (isset($options[ $name_prefix . 'question_caption_text_alignment' ]) && $options[ $name_prefix . 'question_caption_text_alignment' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_caption_text_alignment' ] ) ) : 'center';
249
250 // Question caption text alignment on mobile
251 $options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ] = isset($options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ]) ? $options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ] : $settings[ $name_prefix . 'question_caption_text_alignment' ];
252 $settings[ $name_prefix . 'question_caption_text_alignment_on_mobile' ] = (isset($options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ]) && $options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'question_caption_text_alignment_on_mobile' ] ) ) : 'center';
253
254 // Question caption font size
255 $settings[ $name_prefix . 'question_caption_font_size' ] = (isset($options[ $name_prefix . 'question_caption_font_size' ]) && $options[ $name_prefix . 'question_caption_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_caption_font_size' ] ) ) : 16;
256
257 // Question caption font size on mobile
258 $options[ $name_prefix . 'question_caption_font_size_on_mobile' ] = isset($options[ $name_prefix . 'question_caption_font_size_on_mobile' ]) ? $options[ $name_prefix . 'question_caption_font_size_on_mobile' ] : $settings[ $name_prefix . 'question_caption_font_size' ];
259 $settings[ $name_prefix . 'question_caption_font_size_on_mobile' ] = (isset($options[ $name_prefix . 'question_caption_font_size_on_mobile' ]) && $options[ $name_prefix . 'question_caption_font_size_on_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_caption_font_size_on_mobile' ] ) ) : 16;
260
261 // Question caption text transform
262 $settings[ $name_prefix . 'question_caption_text_transform' ] = (isset($options[ $name_prefix . 'question_caption_text_transform' ]) && $options[ $name_prefix . 'question_caption_text_transform' ] != '') ? esc_attr ( $options[ $name_prefix . 'question_caption_text_transform' ] ) : 'none';
263 // Question caption text transform mobile
264 $options[ $name_prefix . 'question_caption_text_transform_mobile' ] = isset($options[ $name_prefix . 'question_caption_text_transform_mobile' ]) ? $options[ $name_prefix . 'question_caption_text_transform_mobile' ] : $settings[ $name_prefix . 'question_caption_text_transform' ];
265 $settings[ $name_prefix . 'question_caption_text_transform_mobile' ] = (isset($options[ $name_prefix . 'question_caption_text_transform_mobile' ]) && $options[ $name_prefix . 'question_caption_text_transform_mobile' ] != '') ? esc_attr ( $options[ $name_prefix . 'question_caption_text_transform_mobile' ] ) : 'none';
266
267 // Question caption letter spacing
268 $settings[ $name_prefix . 'question_caption_letter_spacing' ] = (isset($options[ $name_prefix . 'question_caption_letter_spacing' ]) && $options[ $name_prefix . 'question_caption_letter_spacing' ] != '') ? absint ( intval( $options[ $name_prefix . 'question_caption_letter_spacing' ] ) ) : 0;
269
270 // Question caption letter spacing mobile
271 $settings[ $name_prefix . 'question_caption_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'question_caption_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'question_caption_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'question_caption_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'question_caption_letter_spacing_mobile' ] ) : $settings[ $name_prefix . 'question_caption_letter_spacing' ];
272
273 // Question caption hide on mobile
274 $settings[ $name_prefix . 'question_caption_hide_on_mobile' ] = (isset($options[ $name_prefix . 'question_caption_hide_on_mobile' ]) && $options[ $name_prefix . 'question_caption_hide_on_mobile' ] == 'on') ? true : false;
275
276 // =========== Questions Styles End ===========
277
278
279 // =========== Answers Styles Start ===========
280
281 // Answer font size
282 $settings[ $name_prefix . 'answer_font_size' ] = (isset($options[ $name_prefix . 'answer_font_size' ]) && $options[ $name_prefix . 'answer_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'answer_font_size' ] ) ) : 15;
283
284 // Answer font size mobile
285 $settings[ $name_prefix . 'answer_font_size_on_mobile' ] = (isset($options[ $name_prefix . 'answer_font_size_on_mobile' ]) && $options[ $name_prefix . 'answer_font_size_on_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'answer_font_size_on_mobile' ] ) ) : 15;
286
287 // Answer letter spacing
288 $settings[ $name_prefix . 'answer_letter_spacing' ] = (isset($options[ $name_prefix . 'answer_letter_spacing' ]) && $options[ $name_prefix . 'answer_letter_spacing' ] != '') ? absint ( intval( $options[ $name_prefix . 'answer_letter_spacing' ] ) ) : 0;
289
290 // Answer letter spacing mobile
291 $options[ $name_prefix . 'answer_letter_spacing_mobile' ] = isset($options[ $name_prefix . 'answer_letter_spacing_mobile' ]) ? $options[ $name_prefix . 'answer_letter_spacing_mobile' ] : $settings[ $name_prefix . 'answer_letter_spacing' ];
292 $settings[ $name_prefix . 'answer_letter_spacing_mobile' ] = (isset($options[ $name_prefix . 'answer_letter_spacing_mobile' ]) && $options[ $name_prefix . 'answer_letter_spacing_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'answer_letter_spacing_mobile' ] ) ) : 0;
293
294 // Answer view
295 $settings[ $name_prefix . 'answers_view' ] = (isset($options[ $name_prefix . 'answers_view' ]) && $options[ $name_prefix . 'answers_view' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'answers_view' ] ) ) : 'list';
296
297 // Answer view alignment
298 $settings[ $name_prefix . 'answers_view_alignment' ] = (isset($options[ $name_prefix . 'answers_view_alignment' ]) && $options[ $name_prefix . 'answers_view_alignment' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'answers_view_alignment' ] ) ) : 'space-around';
299 $settings[ $name_prefix . 'answers_view_alignment' ] = ($settings[ $name_prefix . 'answers_view' ] == 'list' && in_array($settings[ $name_prefix . 'answers_view_alignment' ] , $survey_answers_alignment_grid_types)) ? 'flex-start' : $settings[ $name_prefix . 'answers_view_alignment' ];
300
301 // Answer object-fit
302 $settings[ $name_prefix . 'answers_object_fit' ] = (isset($options[ $name_prefix . 'answers_object_fit' ]) && $options[ $name_prefix . 'answers_object_fit' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'answers_object_fit' ] ) ) : 'cover';
303 // Answer object-fit
304 $settings[ $name_prefix . 'answers_object_fit_mobile' ] = (isset($options[ $name_prefix . 'answers_object_fit_mobile' ]) && $options[ $name_prefix . 'answers_object_fit_mobile' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'answers_object_fit_mobile' ] ) ) : 'cover';
305
306 // Answer padding
307 $settings[ $name_prefix . 'answers_padding' ] = (isset($options[ $name_prefix . 'answers_padding' ]) && $options[ $name_prefix . 'answers_padding' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_padding' ] ) ) : 8;
308
309 // Answer padding mobile
310 $options[ $name_prefix . 'answers_padding_mobile' ] = isset($options[ $name_prefix . 'answers_padding_mobile' ]) ? $options[ $name_prefix . 'answers_padding_mobile' ] : $settings[ $name_prefix . 'answers_padding' ];
311 $settings[ $name_prefix . 'answers_padding_mobile' ] = (isset($options[ $name_prefix . 'answers_padding_mobile' ]) && $options[ $name_prefix . 'answers_padding_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_padding_mobile' ] ) ) : 8;
312
313 // Answer Gap
314 $settings[ $name_prefix . 'answers_gap' ] = (isset($options[ $name_prefix . 'answers_gap' ]) && $options[ $name_prefix . 'answers_gap' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_gap' ] ) ) : 0;
315
316 // Answer Gap mobile
317 $options[ $name_prefix . 'answers_gap_mobile' ] = isset($options[ $name_prefix . 'answers_gap_mobile' ]) ? $options[ $name_prefix . 'answers_gap_mobile' ] : $options[ $name_prefix . 'answers_gap' ];
318 $settings[ $name_prefix . 'answers_gap_mobile' ] = (isset($options[ $name_prefix . 'answers_gap_mobile' ]) && $options[ $name_prefix . 'answers_gap_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_gap_mobile' ] ) ) : 0;
319
320 // Answer image size
321 $settings[ $name_prefix . 'answers_image_size' ] = (isset($options[ $name_prefix . 'answers_image_size' ]) && $options[ $name_prefix . 'answers_image_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_image_size' ] ) ) : 195;
322 // Answer image size mobile
323 $settings[ $name_prefix . 'answers_image_size_mobile' ] = (isset($options[ $name_prefix . 'answers_image_size_mobile' ]) && $options[ $name_prefix . 'answers_image_size_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'answers_image_size_mobile' ] ) ) : 195;
324
325
326 // =========== Answers Styles End ===========
327
328
329 // =========== Buttons Styles Start ===========
330
331 // Buttons background color
332 $settings[ $name_prefix . 'buttons_bg_color' ] = (isset($options[ $name_prefix . 'buttons_bg_color' ]) && $options[ $name_prefix . 'buttons_bg_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'buttons_bg_color' ] ) ) : '#fff';
333
334 // Buttons size
335 $settings[ $name_prefix . 'buttons_size' ] = (isset($options[ $name_prefix . 'buttons_size' ]) && $options[ $name_prefix . 'buttons_size' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'buttons_size' ] ) ) : 'medium';
336
337 // Buttons font size
338 $settings[ $name_prefix . 'buttons_font_size' ] = (isset($options[ $name_prefix . 'buttons_font_size' ]) && $options[ $name_prefix . 'buttons_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_font_size' ] ) ) : 14;
339
340 // Buttons mobile font size
341 $settings[ $name_prefix . 'buttons_mobile_font_size' ] = (isset($options[ $name_prefix . 'buttons_mobile_font_size' ]) && $options[ $name_prefix . 'buttons_mobile_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_mobile_font_size' ] ) ) : $settings[ $name_prefix . 'buttons_font_size' ];
342
343 // Buttons Left / Right padding
344 $settings[ $name_prefix . 'buttons_left_right_padding' ] = (isset($options[ $name_prefix . 'buttons_left_right_padding' ]) && $options[ $name_prefix . 'buttons_left_right_padding' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_left_right_padding' ] ) ) : 24;
345
346 // Buttons Top / Bottom padding
347 $settings[ $name_prefix . 'buttons_top_bottom_padding' ] = (isset($options[ $name_prefix . 'buttons_top_bottom_padding' ]) && $options[ $name_prefix . 'buttons_top_bottom_padding' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_top_bottom_padding' ] ) ) : 0;
348
349 // Buttons border radius
350 $settings[ $name_prefix . 'buttons_border_radius' ] = (isset($options[ $name_prefix . 'buttons_border_radius' ]) && $options[ $name_prefix . 'buttons_border_radius' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_border_radius' ] ) ) : 4;
351 // Buttons border radius mobile
352 $options[ $name_prefix . 'buttons_border_radius_mobile' ] = isset($options[ $name_prefix . 'buttons_border_radius_mobile' ]) ? $options[ $name_prefix . 'buttons_border_radius_mobile' ] : $settings[ $name_prefix . 'buttons_border_radius' ];
353 $settings[ $name_prefix . 'buttons_border_radius_mobile' ] = (isset($options[ $name_prefix . 'buttons_border_radius_mobile' ]) && $options[ $name_prefix . 'buttons_border_radius_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_border_radius_mobile' ] ) ) : 4;
354
355 // Buttons alignment
356 $settings[ $name_prefix . 'buttons_alignment' ] = (isset($options[ $name_prefix . 'buttons_alignment' ]) && $options[ $name_prefix . 'buttons_alignment' ] != '') ? esc_attr( $options[ $name_prefix . 'buttons_alignment' ] ) : 'left';
357 // Buttons alignment mobile
358 $options[ $name_prefix . 'buttons_alignment_mobile' ] = isset($options[ $name_prefix . 'buttons_alignment_mobile' ]) ? $options[ $name_prefix . 'buttons_alignment_mobile' ] : $settings[ $name_prefix . 'buttons_alignment' ];
359 $settings[ $name_prefix . 'buttons_alignment_mobile' ] = (isset($options[ $name_prefix . 'buttons_alignment_mobile' ]) && $options[ $name_prefix . 'buttons_alignment_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'buttons_alignment_mobile' ] ) : 'left';
360
361 // Buttons top distance
362 $settings[ $name_prefix . 'buttons_top_distance' ] = (isset($options[ $name_prefix . 'buttons_top_distance' ]) && $options[ $name_prefix . 'buttons_top_distance' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_top_distance' ] ) ) : 10;
363 // Buttons top distance mobile
364 $options[ $name_prefix . 'buttons_top_distance_mobile' ] = isset($options[ $name_prefix . 'buttons_top_distance_mobile' ]) ? $options[ $name_prefix . 'buttons_top_distance_mobile' ] : $settings[ $name_prefix . 'buttons_top_distance' ];
365 $settings[ $name_prefix . 'buttons_top_distance_mobile' ] = (isset($options[ $name_prefix . 'buttons_top_distance_mobile' ]) && $options[ $name_prefix . 'buttons_top_distance_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'buttons_top_distance_mobile' ] ) ) : 10;
366
367 // Buttons text letter spacing
368 $settings[ $name_prefix . 'buttons_text_letter_spacing' ] = (isset( $options[ $name_prefix . 'buttons_text_letter_spacing' ] ) && $options[ $name_prefix . 'buttons_text_letter_spacing' ] != '' && $options[ $name_prefix . 'buttons_text_letter_spacing' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'buttons_text_letter_spacing' ] ) : 0;
369
370 // Buttons text letter spacing mobile
371 $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] = isset( $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] ) ? $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] : $settings[ $name_prefix . 'buttons_text_letter_spacing' ];
372 $settings[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'buttons_text_letter_spacing_mobile' ] ) : 0;
373
374 // =========== Buttons Styles End ===========
375
376
377 // =============================================================
378 // ====================== Styles Tab =====================
379 // ======================== END ========================
380
381
382 // ======================= // ======================= // ======================= // ======================= // ======================= //
383
384 // =============================================================
385 // ===================== Start page Tab ======================
386 // ======================== START =========================
387
388
389 // Enable start page
390 $options[ $name_prefix . 'enable_start_page' ] = isset($options[ $name_prefix . 'enable_start_page' ]) ? $options[ $name_prefix . 'enable_start_page' ] : 'off';
391 $settings[ $name_prefix . 'enable_start_page' ] = (isset($options[ $name_prefix . 'enable_start_page' ]) && $options[ $name_prefix . 'enable_start_page' ] == 'on') ? true : false;
392
393 // Start page title
394 $settings[ $name_prefix . 'start_page_title' ] = (isset($options[ $name_prefix . 'start_page_title' ]) && $options[ $name_prefix . 'start_page_title' ] != '') ? stripslashes( $options[ $name_prefix . 'start_page_title' ] ) : '';
395
396 // Start page title position
397 $settings[ $name_prefix . 'start_page_title_pos' ] = (isset($options[ $name_prefix . 'start_page_title_pos' ]) && $options[ $name_prefix . 'start_page_title_pos' ] != '') ? stripslashes( $options[ $name_prefix . 'start_page_title_pos' ] ) : 'center';
398 // Start button position mobile
399 $options[ $name_prefix . 'start_page_title_pos_mobile' ] = isset($options[ $name_prefix . 'start_page_title_pos_mobile' ]) ? $options[ $name_prefix . 'start_page_title_pos_mobile' ] : $settings[ $name_prefix . 'start_page_title_pos' ];
400 $settings[ $name_prefix . 'start_page_title_pos_mobile' ] = (isset($options[ $name_prefix . 'start_page_title_pos_mobile' ]) && $options[ $name_prefix . 'start_page_title_pos_mobile' ] != '') ? stripslashes( $options[ $name_prefix . 'start_page_title_pos_mobile' ] ) : 'center';
401
402 // Start page description
403 $settings[ $name_prefix . 'start_page_description' ] = (isset($options[ $name_prefix . 'start_page_description' ]) && $options[ $name_prefix . 'start_page_description' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'start_page_description' ] ) ) : '';
404
405 // Start button position
406 $settings[ $name_prefix . 'start_page_button_pos' ] = (isset($options[ $name_prefix . 'start_page_button_pos' ]) && $options[ $name_prefix . 'start_page_button_pos' ] != '') ? stripslashes( $options[ $name_prefix . 'start_page_button_pos' ] ) : 'left';
407 // Start button position mobile
408 $options[ $name_prefix . 'start_page_button_pos_mobile' ] = isset($options[ $name_prefix . 'start_page_button_pos_mobile' ]) ? $options[ $name_prefix . 'start_page_button_pos_mobile' ] : $settings[ $name_prefix . 'start_page_button_pos' ];
409 $settings[ $name_prefix . 'start_page_button_pos_mobile' ] = (isset($options[ $name_prefix . 'start_page_button_pos_mobile' ]) && $options[ $name_prefix . 'start_page_button_pos_mobile' ] != '') ? stripslashes( $options[ $name_prefix . 'start_page_button_pos_mobile' ] ) : 'left';
410
411 // Start page Background color
412 $settings[ $name_prefix . 'start_page_background_color' ] = (isset($options[ $name_prefix . 'start_page_background_color' ]) && $options[ $name_prefix . 'start_page_background_color' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'start_page_background_color' ] ) ) : '#fff';
413
414 // Start page Text Color
415 $settings[ $name_prefix . 'start_page_text_color' ] = (isset($options[ $name_prefix . 'start_page_text_color' ]) && $options[ $name_prefix . 'start_page_text_color' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'start_page_text_color' ] ) ) : '#333';
416
417 // Custom class for Start page container
418 $settings[ $name_prefix . 'start_page_custom_class' ] = (isset($options[ $name_prefix . 'start_page_custom_class' ]) && $options[ $name_prefix . 'start_page_custom_class' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'start_page_custom_class' ] ) ) : '';
419
420
421 // =============================================================
422 // ===================== Start page Tab ======================
423 // ======================== END ========================
424
425
426 // =============================================================
427 // ====================== Settings Tab =======================
428 // ======================== START =========================
429
430 // Show survey title
431 $options[ $name_prefix . 'show_title' ] = isset($options[ $name_prefix . 'show_title' ]) ? $options[ $name_prefix . 'show_title' ] : 'on';
432 $settings[ $name_prefix . 'show_title' ] = (isset($options[ $name_prefix . 'show_title' ]) && $options[ $name_prefix . 'show_title' ] == 'on') ? true : false;
433
434 // Show survey section header
435 $options[ $name_prefix . 'show_section_header' ] = isset($options[ $name_prefix . 'show_section_header' ]) ? $options[ $name_prefix . 'show_section_header' ] : 'on';
436 $settings[ $name_prefix . 'show_section_header' ] = (isset($options[ $name_prefix . 'show_section_header' ]) && $options[ $name_prefix . 'show_section_header' ] == 'on') ? true : false;
437
438 // Enable randomize answers
439 $options[ $name_prefix . 'enable_randomize_answers' ] = isset($options[ $name_prefix . 'enable_randomize_answers' ]) ? $options[ $name_prefix . 'enable_randomize_answers' ] : 'off';
440 $settings[ $name_prefix . 'enable_randomize_answers' ] = (isset($options[ $name_prefix . 'enable_randomize_answers' ]) && $options[ $name_prefix . 'enable_randomize_answers' ] == 'on') ? true : false;
441
442 // Enable randomize questions
443 $options[ $name_prefix . 'enable_randomize_questions' ] = isset($options[ $name_prefix . 'enable_randomize_questions' ]) ? $options[ $name_prefix . 'enable_randomize_questions' ] : 'off';
444 $settings[ $name_prefix . 'enable_randomize_questions' ] = (isset($options[ $name_prefix . 'enable_randomize_questions' ]) && $options[ $name_prefix . 'enable_randomize_questions' ] == 'on') ? true : false;
445
446 // Enable rtl direction
447 $options[ $name_prefix . 'enable_rtl_direction' ] = isset($options[ $name_prefix . 'enable_rtl_direction' ]) ? $options[ $name_prefix . 'enable_rtl_direction' ] : 'off';
448 $settings[ $name_prefix . 'enable_rtl_direction' ] = (isset($options[ $name_prefix . 'enable_rtl_direction' ]) && $options[ $name_prefix . 'enable_rtl_direction' ] == 'on') ? true : false;
449
450 // Enable clear answer button
451 $options[ $name_prefix . 'enable_clear_answer' ] = isset($options[ $name_prefix . 'enable_clear_answer' ]) ? $options[ $name_prefix . 'enable_clear_answer' ] : 'off';
452 $settings[ $name_prefix . 'enable_clear_answer' ] = (isset($options[ $name_prefix . 'enable_clear_answer' ]) && $options[ $name_prefix . 'enable_clear_answer' ] == 'on') ? true : false;
453
454 // Enable previous button
455 $options[ $name_prefix . 'enable_previous_button' ] = isset($options[ $name_prefix . 'enable_previous_button' ]) ? $options[ $name_prefix . 'enable_previous_button' ] : 'off';
456 $settings[ $name_prefix . 'enable_previous_button' ] = (isset($options[ $name_prefix . 'enable_previous_button' ]) && $options[ $name_prefix . 'enable_previous_button' ] == 'on') ? true : false;
457
458 // Disable next button
459 $options[ $name_prefix . 'disable_next_button' ] = isset($options[ $name_prefix . 'disable_next_button' ]) ? $options[ $name_prefix . 'disable_next_button' ] : 'off';
460 $settings[ $name_prefix . 'disable_next_button' ] = (isset($options[ $name_prefix . 'disable_next_button' ]) && $options[ $name_prefix . 'disable_next_button' ] == 'on') ? true : false;
461
462 // Enable Survey Start loader
463 $options[ $name_prefix . 'enable_survey_start_loader' ] = isset($options[ $name_prefix . 'enable_survey_start_loader' ]) ? $options[ $name_prefix . 'enable_survey_start_loader' ] : 'on';
464 $settings[ $name_prefix . 'enable_survey_start_loader' ] = (isset($options[ $name_prefix . 'enable_survey_start_loader' ]) && $options[ $name_prefix . 'enable_survey_start_loader' ] == 'on') ? true : false;
465 $settings[ $name_prefix . 'before_start_loader' ] = (isset($options[ $name_prefix . 'before_start_loader' ]) && $options[ $name_prefix . 'before_start_loader' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'before_start_loader' ] ) ) : 'default';
466
467 // Allow HTML in answers
468 $options[ $name_prefix . 'allow_html_in_answers' ] = isset($options[ $name_prefix . 'allow_html_in_answers' ]) ? $options[ $name_prefix . 'allow_html_in_answers' ] : 'off';
469 $settings[ $name_prefix . 'allow_html_in_answers' ] = (isset($options[ $name_prefix . 'allow_html_in_answers' ]) && $options[ $name_prefix . 'allow_html_in_answers' ] == 'on') ? true : false;
470
471 //---- Schedule Start ---- //
472
473 // Schedule the Survey
474 $options[ $name_prefix . 'enable_schedule' ] = isset($options[ $name_prefix . 'enable_schedule' ]) ? $options[ $name_prefix . 'enable_schedule' ] : 'off';
475 $settings[ $name_prefix . 'enable_schedule' ] = (isset($options[ $name_prefix . 'enable_schedule' ]) && $options[ $name_prefix . 'enable_schedule' ] == 'on') ? true : false;
476
477 if ( $settings[ $name_prefix . 'enable_schedule' ] ) {
478 $activateTimeVal = (isset($options[ $name_prefix . 'schedule_active' ]) && $options[ $name_prefix . 'schedule_active' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'schedule_active' ] ) ) : current_time( 'mysql' );
479 $deactivateTimeVal = (isset($options[ $name_prefix . 'schedule_deactive' ]) && $options[ $name_prefix . 'schedule_deactive' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'schedule_deactive' ] ) ) : current_time( 'mysql' );
480
481 $activateTime = strtotime($activateTimeVal);
482 $settings[ $name_prefix . 'schedule_active' ] = date('Y-m-d H:i:s', $activateTime);
483
484 $deactivateTime = strtotime($deactivateTimeVal);
485 $settings[ $name_prefix . 'schedule_deactive' ] = date('Y-m-d H:i:s', $deactivateTime);
486 } else {
487 $settings[ $name_prefix . 'schedule_active' ] = current_time( 'mysql' );
488 $settings[ $name_prefix . 'schedule_deactive' ] = current_time( 'mysql' );
489 }
490
491 // Show timer
492 $options[ $name_prefix . 'schedule_show_timer' ] = isset($options[ $name_prefix . 'schedule_show_timer' ]) ? $options[ $name_prefix . 'schedule_show_timer' ] : 'off';
493 $settings[ $name_prefix . 'schedule_show_timer' ] = (isset($options[ $name_prefix . 'schedule_show_timer' ]) && $options[ $name_prefix . 'schedule_show_timer' ] == 'on') ? true : false;
494
495 // Show countdown / start date
496 $settings[ $name_prefix . 'show_timer_type' ] = (isset($options[ $name_prefix . 'show_timer_type' ]) && $options[ $name_prefix . 'show_timer_type' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'show_timer_type' ] ) ) : 'countdown';
497
498 // Pre start message
499 $settings[ $name_prefix . 'schedule_pre_start_message' ] = (isset($options[ $name_prefix . 'schedule_pre_start_message' ]) && $options[ $name_prefix . 'schedule_pre_start_message' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'schedule_pre_start_message' ] ) ) : __("The survey will be available soon!", "survey-maker");
500
501 // Expiration message
502 $settings[ $name_prefix . 'schedule_expiration_message' ] = (isset($options[ $name_prefix . 'schedule_expiration_message' ]) && $options[ $name_prefix . 'schedule_expiration_message' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'schedule_expiration_message' ] ) ) : __("This survey has expired!", "survey-maker");
503
504 // Expiration message
505 $settings[ $name_prefix . 'dont_show_survey_container' ] = (isset($options[ $name_prefix . 'dont_show_survey_container' ]) && $options[ $name_prefix . 'dont_show_survey_container' ] == 'on') ? true : false;
506 //---- Schedule End ---- //
507
508 // ---- Buttons settings Start ---- //
509 // Finish button text
510 $settings[ $name_prefix . 'finish_button_each_text' ] = (isset($options[ $name_prefix . 'finish_button_each_text' ]) && $options[ $name_prefix . 'finish_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'finish_button_each_text' ]) ) : '';
511 // Next button text
512 $settings[ $name_prefix . 'next_button_each_text' ] = (isset($options[ $name_prefix . 'next_button_each_text' ]) && $options[ $name_prefix . 'next_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'next_button_each_text' ]) ) : '';
513 // Previous button text
514 $settings[ $name_prefix . 'previous_button_each_text' ] = (isset($options[ $name_prefix . 'previous_button_each_text' ]) && $options[ $name_prefix . 'previous_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'previous_button_each_text' ]) ) : '';
515 // Restart button text
516 $settings[ $name_prefix . 'restart_button_each_text' ] = (isset($options[ $name_prefix . 'restart_button_each_text' ]) && $options[ $name_prefix . 'restart_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'restart_button_each_text' ]) ) : '';
517 // Exit button text
518 $settings[ $name_prefix . 'exit_button_each_text' ] = (isset($options[ $name_prefix . 'exit_button_each_text' ]) && $options[ $name_prefix . 'exit_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'exit_button_each_text' ]) ) : '';
519 // Clear selection button text
520 $settings[ $name_prefix . 'clear_selection_button_each_text' ] = (isset($options[ $name_prefix . 'clear_selection_button_each_text' ]) && $options[ $name_prefix . 'clear_selection_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'clear_selection_button_each_text' ]) ) : '';
521 // Start button text
522 $settings[ $name_prefix . 'start_button_each_text' ] = (isset($options[ $name_prefix . 'start_button_each_text' ]) && $options[ $name_prefix . 'start_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'start_button_each_text' ]) ) : '';
523 // Login button text
524 $settings[ $name_prefix . 'login_button_each_text' ] = (isset($options[ $name_prefix . 'login_button_each_text' ]) && $options[ $name_prefix . 'login_button_each_text' ] != '') ? stripslashes( esc_attr($options[ $name_prefix . 'login_button_each_text' ]) ) : '';
525 // ---- Buttons settings End ---- //
526
527 // Allow HTML in section description
528 $options[ $name_prefix . 'allow_html_in_section_description' ] = isset($options[ $name_prefix . 'allow_html_in_section_description' ]) ? $options[ $name_prefix . 'allow_html_in_section_description' ] : 'off';
529 $settings[ $name_prefix . 'allow_html_in_section_description' ] = (isset($options[ $name_prefix . 'allow_html_in_section_description' ]) && $options[ $name_prefix . 'allow_html_in_section_description' ] == 'on') ? true : false;
530
531 // Enable confirmation box for leaving the page
532 $options[ $name_prefix . 'enable_leave_page' ] = isset($options[ $name_prefix . 'enable_leave_page' ]) ? $options[ $name_prefix . 'enable_leave_page' ] : 'on';
533 $settings[ $name_prefix . 'enable_leave_page' ] = (isset($options[ $name_prefix . 'enable_leave_page' ]) && $options[ $name_prefix . 'enable_leave_page' ] == 'on') ? true : false;
534
535 // Full screen mode
536 $settings[ $name_prefix . 'full_screen_mode' ] = ( isset( $options[ $name_prefix . 'full_screen_mode' ] ) && $options[ $name_prefix . 'full_screen_mode' ] == "on" ) ? true : false;
537 $options[ $name_prefix . 'full_screen_button_color' ] = isset($options[ $name_prefix . 'full_screen_button_color' ]) ? $options[ $name_prefix . 'full_screen_button_color' ] : $options[ $name_prefix . 'text_color' ];
538 $settings[ $name_prefix . 'full_screen_button_color' ] = (isset($options[ $name_prefix . 'full_screen_button_color' ]) && $options[ $name_prefix . 'full_screen_button_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'full_screen_button_color' ] ) ) : '#fff';
539
540 // Survey progress bar
541 $settings[ $name_prefix . 'enable_progress_bar' ] = ( isset( $options[ $name_prefix . 'enable_progress_bar' ] ) && $options[ $name_prefix . 'enable_progress_bar' ] == "on" ) ? "on" : "off";
542 $settings[ $name_prefix . 'hide_section_pagination_text' ] = ( isset( $options[ $name_prefix . 'hide_section_pagination_text' ] ) && $options[ $name_prefix . 'hide_section_pagination_text' ] == "on" ) ? true : false;
543 $settings[ $name_prefix . 'pagination_positioning' ] = ( isset( $options[ $name_prefix . 'pagination_positioning' ] ) && $options[ $name_prefix . 'pagination_positioning' ] != "" ) ? esc_attr($options[ $name_prefix . 'pagination_positioning' ]) : "none";
544 $options[ $name_prefix . 'pagination_positioning_mobile' ] = isset($options[ $name_prefix . 'pagination_positioning_mobile' ]) ? $options[ $name_prefix . 'pagination_positioning_mobile' ] : $settings[ $name_prefix . 'pagination_positioning' ];
545 $settings[ $name_prefix . 'pagination_positioning_mobile' ] = ( isset( $options[ $name_prefix . 'pagination_positioning_mobile' ] ) && $options[ $name_prefix . 'pagination_positioning_mobile' ] != "" ) ? esc_attr($options[ $name_prefix . 'pagination_positioning_mobile' ]) : "none";
546 $settings[ $name_prefix . 'hide_section_bar' ] = ( isset( $options[ $name_prefix . 'hide_section_bar' ] ) && $options[ $name_prefix . 'hide_section_bar' ] == "on" ) ? true : false;
547 $settings[ $name_prefix . 'progress_bar_text' ] = ( isset( $options[ $name_prefix . 'progress_bar_text' ] ) && $options[ $name_prefix . 'progress_bar_text' ] != "" ) ? stripslashes(esc_attr($options[ $name_prefix . 'progress_bar_text' ])) : 'Page';
548 $settings[ $name_prefix . 'progress_bar_text_letter_spacing' ] = (isset( $options[ $name_prefix . 'progress_bar_text_letter_spacing' ] ) && $options[ $name_prefix . 'progress_bar_text_letter_spacing' ] != '' && $options[ $name_prefix . 'progress_bar_text_letter_spacing' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'progress_bar_text_letter_spacing' ] ) : 0;
549
550 $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] = !isset( $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] ) ? $settings[ $name_prefix . 'progress_bar_text_letter_spacing' ] : $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ];
551 $settings[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] = (isset( $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] ) && $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] != '' && $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] != '0' ) ? esc_attr( $options[ $name_prefix . 'progress_bar_text_letter_spacing_mobile' ] ) : 0;
552
553 $options[ $name_prefix . 'pagination_text_color' ] = isset($options[ $name_prefix . 'pagination_text_color' ]) ? $options[ $name_prefix . 'pagination_text_color' ] : $options[ $name_prefix . 'text_color' ];
554 $settings[ $name_prefix . 'pagination_text_color' ] = (isset($options[ $name_prefix . 'pagination_text_color' ]) && $options[ $name_prefix . 'pagination_text_color' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'pagination_text_color' ] ) ) : '#fff';
555 $options[ $name_prefix . 'pagination_text_color_mobile' ] = isset($options[ $name_prefix . 'pagination_text_color_mobile' ]) ? $options[ $name_prefix . 'pagination_text_color_mobile' ] : $settings[ $name_prefix . 'pagination_text_color' ];
556 $settings[ $name_prefix . 'pagination_text_color_mobile' ] = (isset($options[ $name_prefix . 'pagination_text_color_mobile' ]) && $options[ $name_prefix . 'pagination_text_color_mobile' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'pagination_text_color_mobile' ] ) ) : '#fff';
557 $options[ $name_prefix . 'progress_bar_text_font_size' ] = isset($options[ $name_prefix . 'progress_bar_text_font_size' ]) ? $options[ $name_prefix . 'progress_bar_text_font_size' ] : $options[ $name_prefix . 'answer_font_size' ];
558 $settings[ $name_prefix . 'progress_bar_text_font_size' ] = (isset($options[ $name_prefix . 'progress_bar_text_font_size' ]) && $options[ $name_prefix . 'progress_bar_text_font_size' ] != '') ? absint ( intval( $options[ $name_prefix . 'progress_bar_text_font_size' ] ) ) : 15;
559 $options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ] = isset($options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ]) ? $options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ] : $settings[ $name_prefix . 'progress_bar_text_font_size' ];
560 $settings[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ] = (isset($options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ]) && $options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ] != '') ? absint ( intval( $options[ $name_prefix . 'progress_bar_text_font_size_on_mobile' ] ) ) : 15;
561 $settings[ $name_prefix . 'progress_bar_text_transform' ] = (isset($options[ $name_prefix . 'progress_bar_text_transform' ]) && $options[ $name_prefix . 'progress_bar_text_transform' ] != '') ? esc_attr( $options[ $name_prefix . 'progress_bar_text_transform' ] ) : 'none';
562 $options[ $name_prefix . 'progress_bar_text_transform_mobile' ] = isset($options[ $name_prefix . 'progress_bar_text_transform_mobile' ]) ? $options[ $name_prefix . 'progress_bar_text_transform_mobile' ] : $settings[ $name_prefix . 'progress_bar_text_transform' ];
563 $settings[ $name_prefix . 'progress_bar_text_transform_mobile' ] = (isset($options[ $name_prefix . 'progress_bar_text_transform_mobile' ]) && $options[ $name_prefix . 'progress_bar_text_transform_mobile' ] != '') ? esc_attr( $options[ $name_prefix . 'progress_bar_text_transform_mobile' ] ) : 'none';
564
565 // Survey show sections questions count
566 $options[ $name_prefix . 'show_sections_questions_count' ] = ( isset( $options[ $name_prefix . 'show_sections_questions_count' ] ) ) ? $options[ $name_prefix . 'show_sections_questions_count' ] : "off";
567 $settings[ $name_prefix . 'show_sections_questions_count' ] = ( isset( $options[ $name_prefix . 'show_sections_questions_count' ] ) && $options[ $name_prefix . 'show_sections_questions_count' ] == "on" ) ? true : false;
568
569 // Survey required questions message
570 $options[ $name_prefix . 'required_questions_message' ] = ( isset( $options[ $name_prefix . 'required_questions_message' ] ) ) ? $options[ $name_prefix . 'required_questions_message' ] : "This is a required question";
571 $settings[ $name_prefix . 'required_questions_message' ] = ( isset( $options[ $name_prefix . 'required_questions_message' ] ) && $options[ $name_prefix . 'required_questions_message' ] != "" ) ? stripslashes(esc_attr($options[ $name_prefix . 'required_questions_message' ])) : '';
572
573 // Auto numbering questions
574 $settings[ $name_prefix . 'auto_numbering_questions' ] = (isset($options[ $name_prefix . 'auto_numbering_questions' ]) && $options[ $name_prefix . 'auto_numbering_questions' ] != '') ? stripslashes( $options[ $name_prefix . 'auto_numbering_questions' ] ) : 'none';
575
576 // =============================================================
577 // =================== Results Settings Tab ===================
578 // ======================== START =========================
579
580
581 // Redirect after submit
582 $options[ $name_prefix . 'redirect_after_submit' ] = isset($options[ $name_prefix . 'redirect_after_submit' ]) ? $options[ $name_prefix . 'redirect_after_submit' ] : 'off';
583 $settings[ $name_prefix . 'redirect_after_submit' ] = (isset($options[ $name_prefix . 'redirect_after_submit' ]) && $options[ $name_prefix . 'redirect_after_submit' ] == 'on') ? true : false;
584
585 // Redirect URL
586 $settings[ $name_prefix . 'submit_redirect_url' ] = (isset($options[ $name_prefix . 'submit_redirect_url' ]) && $options[ $name_prefix . 'submit_redirect_url' ] != '') ? stripslashes ( esc_url( $options[ $name_prefix . 'submit_redirect_url' ] ) ) : '';
587
588 // Redirect delay (sec)
589 $settings[ $name_prefix . 'submit_redirect_delay' ] = (isset($options[ $name_prefix . 'submit_redirect_delay' ]) && $options[ $name_prefix . 'submit_redirect_delay' ] != '') ? absint ( intval( $options[ $name_prefix . 'submit_redirect_delay' ] ) ) : '';
590
591 // Redirect in new tab
592 $settings[ $name_prefix . 'submit_redirect_new_tab' ] = (isset($options[ $name_prefix . 'submit_redirect_new_tab' ]) && $options[ $name_prefix . 'submit_redirect_new_tab' ] == 'on') ? true : false;
593
594 // Enable EXIT button
595 $options[ $name_prefix . 'enable_exit_button' ] = isset($options[ $name_prefix . 'enable_exit_button' ]) ? $options[ $name_prefix . 'enable_exit_button' ] : 'off';
596 $settings[ $name_prefix . 'enable_exit_button' ] = (isset($options[ $name_prefix . 'enable_exit_button' ]) && $options[ $name_prefix . 'enable_exit_button' ] == 'on') ? true : false;
597
598 // Redirect URL
599 $settings[ $name_prefix . 'exit_redirect_url' ] = (isset($options[ $name_prefix . 'exit_redirect_url' ]) && $options[ $name_prefix . 'exit_redirect_url' ] != '') ? stripslashes ( esc_url( $options[ $name_prefix . 'exit_redirect_url' ] ) ) : '';
600
601 // Enable EXIT button
602 $options[ $name_prefix . 'enable_restart_button' ] = isset($options[ $name_prefix . 'enable_restart_button' ]) ? $options[ $name_prefix . 'enable_restart_button' ] : 'off';
603 $settings[ $name_prefix . 'enable_restart_button' ] = (isset($options[ $name_prefix . 'enable_restart_button' ]) && $options[ $name_prefix . 'enable_restart_button' ] == 'on') ? true : false;
604
605 // Thank you message
606 $settings[ $name_prefix . 'final_result_text' ] = (isset($options[ $name_prefix . 'final_result_text' ]) && $options[ $name_prefix . 'final_result_text' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'final_result_text' ] ) ) : '';
607
608 // Select survey loader
609 $settings[ $name_prefix . 'loader' ] = (isset($options[ $name_prefix . 'loader' ]) && $options[ $name_prefix . 'loader' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'loader' ] ) ) : 'default';
610
611 // Social share buttons
612 $options[ $name_prefix . 'social_buttons' ] = ( isset( $options[ $name_prefix . 'social_buttons' ] ) && $options[ $name_prefix . 'social_buttons' ] == 'on' ) ? true : false;
613 $settings[ $name_prefix . 'social_buttons' ] = ( isset( $options[ $name_prefix . 'social_buttons' ] ) && $options[ $name_prefix . 'social_buttons' ] ) ? true : false;
614 // Social share buttons heading message
615 $settings[ $name_prefix . 'social_buttons_heading' ] = ( isset( $options[ $name_prefix . 'social_buttons_heading' ] ) && $options[ $name_prefix . 'social_buttons_heading' ] != '' ) ? stripslashes( wpautop( $options[ $name_prefix . 'social_buttons_heading' ] ) ) : '';
616 // Linkedin
617 $options[ $name_prefix . 'social_button_ln' ] = ( isset( $options[ $name_prefix . 'social_button_ln' ] ) && $options[ $name_prefix . 'social_button_ln' ] == 'on' ) ? true : false;
618 $settings[ $name_prefix . 'social_button_ln' ] = ( isset( $options[ $name_prefix . 'social_button_ln' ] ) && $options[ $name_prefix . 'social_button_ln' ] == 'on' ) ? true : false;
619 // Facebook
620 $options[ $name_prefix . 'social_button_fb' ] = ( isset( $options[ $name_prefix . 'social_button_fb' ] ) && $options[ $name_prefix . 'social_button_fb' ] == 'on' ) ? true : false;
621 $settings[ $name_prefix . 'social_button_fb' ] = ( isset( $options[ $name_prefix . 'social_button_fb' ] ) && $options[ $name_prefix . 'social_button_fb' ] ) ? true : false;
622 // Twitter
623 $options[ $name_prefix . 'social_button_tr' ] = ( isset( $options[ $name_prefix . 'social_button_tr' ] ) && $options[ $name_prefix . 'social_button_tr' ] == 'on' ) ? true : false;
624 $settings[ $name_prefix . 'social_button_tr' ] = ( isset( $options[ $name_prefix . 'social_button_tr' ] ) && $options[ $name_prefix . 'social_button_tr' ] ) ? true : false;
625 // Vk
626 $options[ $name_prefix . 'social_button_vk' ] = ( isset( $options[ $name_prefix . 'social_button_vk' ] ) && $options[ $name_prefix . 'social_button_vk' ] == 'on' ) ? true : false;
627 $settings[ $name_prefix . 'social_button_vk' ] = ( isset( $options[ $name_prefix . 'social_button_vk' ] ) && $options[ $name_prefix . 'social_button_vk' ] ) ? true : false;
628
629 // =============================================================
630 // =================== Results Settings Tab ===================
631 // ======================== END ==========================
632
633
634
635 // ======================= // ======================= // ======================= // ======================= // ======================= //
636
637
638
639 // =============================================================
640 // =================== Limitation Tab ===================
641 // ======================== START =========================
642
643 // Maximum number of attempts per user
644 $options[ $name_prefix . 'limit_users' ] = isset($options[ $name_prefix . 'limit_users' ]) ? $options[ $name_prefix . 'limit_users' ] : 'off';
645 $settings[ $name_prefix . 'limit_users' ] = (isset($options[ $name_prefix . 'limit_users' ]) && $options[ $name_prefix . 'limit_users' ] == 'on') ? true : false;
646
647 // Detects users by IP / ID
648 $settings[ $name_prefix . 'limit_users_by' ] = (isset($options[ $name_prefix . 'limit_users_by' ]) && $options[ $name_prefix . 'limit_users_by' ] != '') ? stripslashes ( sanitize_text_field( $options[ $name_prefix . 'limit_users_by' ] ) ) : 'ip';
649
650 // Attempts count
651 $settings[ $name_prefix . 'max_pass_count' ] = (isset($options[ $name_prefix . 'max_pass_count' ]) && $options[ $name_prefix . 'max_pass_count' ] != '') ? absint ( intval( $options[ $name_prefix . 'max_pass_count' ] ) ) : 1;
652
653 // Limitation Message
654 $settings[ $name_prefix . 'limitation_message' ] = (isset($options[ $name_prefix . 'limitation_message' ]) && $options[ $name_prefix . 'limitation_message' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'limitation_message' ] ) ) : '';
655
656 // Redirect Url
657 $settings[ $name_prefix . 'redirect_url' ] = (isset($options[ $name_prefix . 'redirect_url' ]) && $options[ $name_prefix . 'redirect_url' ] != '') ? $options[ $name_prefix . 'redirect_url' ] : '';
658
659 // Redirect delay
660 $settings[ $name_prefix . 'redirect_delay' ] = (isset($options[ $name_prefix . 'redirect_delay' ]) && $options[ $name_prefix . 'redirect_delay' ] != '') ? absint ( intval( $options[ $name_prefix . 'redirect_delay' ] ) ) : 1;
661
662 // Only for logged in users
663 $options[ $name_prefix . 'enable_logged_users' ] = isset($options[ $name_prefix . 'enable_logged_users' ]) ? $options[ $name_prefix . 'enable_logged_users' ] : 'off';
664 $settings[ $name_prefix . 'enable_logged_users' ] = (isset($options[ $name_prefix . 'enable_logged_users' ]) && $options[ $name_prefix . 'enable_logged_users' ] == 'on') ? true : false;
665
666 // Message - Only for logged in users
667 $settings[ $name_prefix . 'logged_in_message' ] = (isset($options[ $name_prefix . 'logged_in_message' ]) && $options[ $name_prefix . 'logged_in_message' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'logged_in_message' ] ) ) : '';
668
669 // Show login form
670 $options[ $name_prefix . 'show_login_form' ] = isset($options[ $name_prefix . 'show_login_form' ]) ? $options[ $name_prefix . 'show_login_form' ] : 'off';
671 $settings[ $name_prefix . 'show_login_form' ] = (isset($options[ $name_prefix . 'show_login_form' ]) && $options[ $name_prefix . 'show_login_form' ] == 'on') ? true : false;
672
673 // =============================================================
674 // =================== Limitation Tab ===================
675 // ======================== END ==========================
676
677
678
679 // ======================= // ======================= // ======================= // ======================= // ======================= //
680
681
682
683 // =============================================================
684 // ===================== E-Mail Tab =====================
685 // ======================== START =========================
686
687
688 // Send Mail To User
689 $options[ $name_prefix . 'enable_mail_user' ] = isset($options[ $name_prefix . 'enable_mail_user' ]) ? $options[ $name_prefix . 'enable_mail_user' ] : 'off';
690 $settings[ $name_prefix . 'enable_mail_user' ] = (isset($options[ $name_prefix . 'enable_mail_user' ]) && $options[ $name_prefix . 'enable_mail_user' ] == 'on') ? true : false;
691
692 // Email message
693 $settings[ $name_prefix . 'mail_message' ] = (isset($options[ $name_prefix . 'mail_message' ]) && $options[ $name_prefix . 'mail_message' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'mail_message' ] ) ) : '';
694
695 // Send email to admin
696 $options[ $name_prefix . 'enable_mail_admin' ] = isset($options[ $name_prefix . 'enable_mail_admin' ]) ? $options[ $name_prefix . 'enable_mail_admin' ] : 'off';
697 $settings[ $name_prefix . 'enable_mail_admin' ] = (isset($options[ $name_prefix . 'enable_mail_admin' ]) && $options[ $name_prefix . 'enable_mail_admin' ] == 'on') ? true : false;
698
699 // Send email to site admin ( SuperAdmin )
700 $options[ $name_prefix . 'send_mail_to_site_admin' ] = isset($options[ $name_prefix . 'send_mail_to_site_admin' ]) ? $options[ $name_prefix . 'send_mail_to_site_admin' ] : 'on';
701 $settings[ $name_prefix . 'send_mail_to_site_admin' ] = (isset($options[ $name_prefix . 'send_mail_to_site_admin' ]) && $options[ $name_prefix . 'send_mail_to_site_admin' ] == 'on') ? true : false;
702
703 // Additional emails
704 $settings[ $name_prefix . 'additional_emails' ] = (isset($options[ $name_prefix . 'additional_emails' ]) && $options[ $name_prefix . 'additional_emails' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'additional_emails' ] ) ) : '';
705
706 // Email message
707 $settings[ $name_prefix . 'mail_message_admin' ] = (isset($options[ $name_prefix . 'mail_message_admin' ]) && $options[ $name_prefix . 'mail_message_admin' ] != '') ? stripslashes( wpautop( $options[ $name_prefix . 'mail_message_admin' ] ) ) : '';
708
709 //---- Email configuration Start ---- //
710
711 // From email
712 $settings[ $name_prefix . 'email_configuration_from_email' ] = (isset($options[ $name_prefix . 'email_configuration_from_email' ]) && $options[ $name_prefix . 'email_configuration_from_email' ] != '') ? stripslashes( sanitize_email( $options[ $name_prefix . 'email_configuration_from_email' ] ) ) : '';
713
714 // From name
715 $settings[ $name_prefix . 'email_configuration_from_name' ] = (isset($options[ $name_prefix . 'email_configuration_from_name' ]) && $options[ $name_prefix . 'email_configuration_from_name' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'email_configuration_from_name' ] ) ) : '';
716
717 // Subject
718 $settings[ $name_prefix . 'email_configuration_from_subject' ] = (isset($options[ $name_prefix . 'email_configuration_from_subject' ]) && $options[ $name_prefix . 'email_configuration_from_subject' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'email_configuration_from_subject' ] ) ) : '';
719
720 // Reply to email
721 $settings[ $name_prefix . 'email_configuration_replyto_email' ] = (isset($options[ $name_prefix . 'email_configuration_replyto_email' ]) && $options[ $name_prefix . 'email_configuration_replyto_email' ] != '') ? stripslashes( sanitize_email( $options[ $name_prefix . 'email_configuration_replyto_email' ] ) ) : '';
722
723 // Reply to name
724 $settings[ $name_prefix . 'email_configuration_replyto_name' ] = (isset($options[ $name_prefix . 'email_configuration_replyto_name' ]) && $options[ $name_prefix . 'email_configuration_replyto_name' ] != '') ? stripslashes ( esc_attr( $options[ $name_prefix . 'email_configuration_replyto_name' ] ) ) : '';
725
726 //---- Email configuration End ---- //
727
728
729 // =============================================================
730 // ===================== E-Mail Tab =====================
731 // ======================== END ==========================
732
733 //limitation takers count
734 $options[ $name_prefix . 'enable_takers_count' ] = (isset( $options[ $name_prefix . 'enable_takers_count' ] ) && $options[ $name_prefix . 'enable_takers_count' ] == 'on') ? stripslashes ( $options[ $name_prefix . 'enable_takers_count' ] ) : 'off';
735 $settings[ $name_prefix . 'enable_takers_count' ] = (isset($options[ $name_prefix . 'enable_takers_count' ]) && $options[ $name_prefix . 'enable_takers_count' ] == 'on') ? true : false;
736
737 //Takers Count
738 $settings[ $name_prefix . 'takers_count' ] = (isset($options[ $name_prefix . 'takers_count' ]) && $options[ $name_prefix . 'takers_count' ] != '') ? absint ( intval( $options[ $name_prefix . 'takers_count' ] ) ) : 1;
739
740 // Auto numbering
741 $settings[ $name_prefix . 'auto_numbering' ] = (isset($options[ $name_prefix . 'auto_numbering' ]) && $options[ $name_prefix . 'auto_numbering' ] != '') ? stripslashes( $options[ $name_prefix . 'auto_numbering' ] ) : 'none';
742
743 // Loader custom gif
744 $settings[ $name_prefix . 'loader_gif' ] = (isset($options[ $name_prefix . 'loader_gif' ]) && $options[ $name_prefix . 'loader_gif' ] != '') ? esc_url( $options[ $name_prefix . 'loader_gif' ] ) : '';
745 $settings[ $name_prefix . 'loader_gif_width' ] = (isset($options[ $name_prefix . 'loader_gif_width' ]) && $options[ $name_prefix . 'loader_gif_width' ] != '') ? esc_attr( $options[ $name_prefix . 'loader_gif_width' ] ) : '100';
746
747
748 return $settings;
749 }
750
751 public static function get_surveys($ordering = ''){
752 global $wpdb;
753 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
754
755 $sql = "SELECT id,title
756 FROM {$surveys_table} WHERE `status` = 'published'";
757
758
759 if($ordering != ''){
760 $sql .= ' ORDER BY id '.$ordering;
761 }
762
763 $surveys = $wpdb->get_results( $sql , "ARRAY_A" );
764
765 return $surveys;
766 }
767
768 public static function get_survey_current_column( $survey_id , $column, $status = 'published'){
769 global $wpdb;
770 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
771
772 $sql = "SELECT ".sanitize_text_field($column)."
773 FROM {$surveys_table} WHERE `id`= ".sanitize_text_field($survey_id)." AND `status` = '".sanitize_text_field($status)."' ";
774 $current_column = $wpdb->get_var( $sql );
775
776 return $current_column;
777 }
778
779 public static function get_survey_by_id( $id ){
780 global $wpdb;
781 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
782
783 $sql = "SELECT *
784 FROM {$surveys_table}
785 WHERE id=" . esc_sql( absint( $id ) );
786
787 $survey = $wpdb->get_row( $sql );
788
789 return $survey;
790 }
791
792 public static function get_survey_category_by_id( $id ){
793 global $wpdb;
794 $survey_cat_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "survey_categories";
795
796 $sql = "SELECT *
797 FROM {$survey_cat_table}
798 WHERE id=" . esc_sql( absint( $id ) );
799
800 $category = $wpdb->get_row( $sql );
801
802 return $category;
803 }
804
805 public static function get_question_category_by_id( $id ){
806 global $wpdb;
807 $question_cat_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "question_categories";
808
809 $sql = "SELECT *
810 FROM {$question_cat_table}
811 WHERE id=" . esc_sql( absint( $id ) );
812
813 $category = $wpdb->get_row( $sql );
814
815 return $category;
816 }
817
818 public static function get_question_by_id( $id ){
819 global $wpdb;
820 $questions_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "questions";
821 $answers_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "answers";
822
823 $sql = "SELECT *
824 FROM {$questions_table}
825 WHERE id=" . esc_sql( absint( $id ) );
826
827 $question = $wpdb->get_row( $sql );
828
829 $sql = "SELECT *
830 FROM {$answers_table}
831 WHERE question_id=" . esc_sql( absint( $id ) );
832
833 $answers = $wpdb->get_results( $sql );
834
835 $question->answers = $answers;
836
837 return $question;
838 }
839
840 public static function get_question_by_ids( $ids ){
841 global $wpdb;
842 $questions_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "questions";
843 $answers_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "answers";
844
845 $qids = esc_sql( implode( ',', $ids ) );
846
847 $sql = "SELECT *
848 FROM {$questions_table}
849 WHERE id IN (" . esc_sql( $qids ) . ")
850 ORDER BY ordering";
851
852 $questions = $wpdb->get_results( $sql );
853
854 foreach ( $questions as $key => &$question ) {
855
856 $sql = "SELECT *
857 FROM {$answers_table}
858 WHERE question_id=" . esc_sql( absint( $question->id ) ) ."
859 ORDER BY ordering";
860
861 $answers = $wpdb->get_results( $sql );
862
863 $question->answers = $answers;
864
865 }
866
867 return $questions;
868 }
869
870 public static function get_section_by_id($id){
871 global $wpdb;
872 $sections_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "sections";
873
874 $sid = esc_sql( absint( $id ) );
875
876 $sql = "SELECT *
877 FROM {$sections_table}
878 WHERE id={$sid}
879 ORDER BY ordering";
880
881 $section = $wpdb->get_row( $sql );
882
883 return $section;
884 }
885
886 public static function get_answer_by_id($id){
887 global $wpdb;
888 $answers_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "answers";
889
890 $sql = "SELECT *
891 FROM {$answers_table}
892 WHERE id=" . esc_sql( absint( $id ) );
893
894 $answer = $wpdb->get_row( $sql );
895
896 return $answer;
897 }
898
899 public static function get_answers_by_question_id($id){
900 global $wpdb;
901 $answers_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "answers";
902
903 $sql = "SELECT *
904 FROM {$answers_table}
905 WHERE question_id=" . esc_sql( absint( $id ) ) . "
906 ORDER BY ordering";
907
908 $answers = $wpdb->get_results( $sql, 'ARRAY_A' );
909
910 if(! empty($answers) ){
911 return $answers;
912 }
913
914 return array();
915 }
916
917 public static function get_survey_questions_count($id){
918 global $wpdb;
919 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
920
921 $sql = "SELECT `questions_count`
922 FROM {$surveys_table}
923 WHERE id=" . esc_sql( absint( $id ) );
924
925 $questions_str = $wpdb->get_var( $sql );
926 $count = intval( $questions_str );
927
928 return $count;
929 }
930
931 public static function get_survey_sections_count($id){
932 global $wpdb;
933 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
934
935 $sql = "SELECT `sections_count`
936 FROM {$surveys_table}
937 WHERE id=" . esc_sql( absint( $id ) );
938
939 $sections_str = $wpdb->get_var( $sql );
940 $count = intval( $sections_str );
941
942 return $count;
943 }
944
945 public static function get_sections_by_survey_id( $ids ) {
946 global $wpdb;
947 if (empty($ids)) {
948 return array();
949 }
950 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "sections";
951
952 $sql = "SELECT * FROM {$table} WHERE `id` IN (" . esc_sql( $ids ) .") ORDER BY `ordering`;";
953 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
954
955 if(! empty($result) ){
956 return $result;
957 }
958
959 return array();
960 }
961
962 public static function get_questions_by_section_id( $section_id, $question_ids ) {
963 global $wpdb;
964 if (empty($question_ids) || empty($section_id)) {
965 return array();
966 }
967 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions";
968
969 $sql = "SELECT * FROM {$table} WHERE `section_id` = ". absint( $section_id ) ." AND `id` IN (" . esc_sql( $question_ids ) .") ORDER BY ordering;";
970 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
971
972 if(! empty($result) ){
973 return $result;
974 }
975
976 return array();
977 }
978
979 public static function get_answers_by_question_id_aro( $question_id ) {
980 global $wpdb;
981 if (empty($question_id)) {
982 return false;
983 }
984 $table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "answers";
985
986 $sql = "SELECT * FROM {$table} WHERE `question_id` = ". absint( $question_id );
987 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
988
989 return $result;
990 }
991
992 public static function sort_array_keys_by_array($array, $orderArray) {
993 $ordered = array();
994 foreach ($orderArray as $key) {
995 if (array_key_exists('ays-question-'.$key, $array)) {
996 $ordered['ays-question-'.$key] = $array['ays-question-'.$key];
997 unset($array['ays-question-'.$key]);
998 }
999 }
1000 return $ordered + $array;
1001 }
1002
1003 public static function replace_message_variables($content, $data){
1004 foreach($data as $variable => $value){
1005 $content = str_replace("%%".$variable."%%", $value, $content);
1006 }
1007 return $content;
1008 }
1009
1010 public static function question_type_is($question_id){
1011 global $wpdb;
1012 $questions_table = $wpdb->prefix . "aysquiz_questions";
1013 $question_id = absint(intval($question_id));
1014 $custom_types = array("custom");
1015 $question_type = $wpdb->get_var("SELECT type FROM {$questions_table} WHERE id=". absint( $question_id ) .";");
1016 if($question_type == ''){
1017 $question_type = 'radio';
1018 }
1019
1020 if(in_array($question_type, $custom_types)){
1021 return true;
1022 }
1023 return false;
1024 }
1025
1026 public static function hex2rgba($color, $opacity = false){
1027
1028 $default = 'rgb(0,0,0)';
1029
1030 //Return default if no color provided
1031 if (empty($color))
1032 return $default;
1033
1034 //Sanitize $color if "#" is provided
1035 if ($color[0] == '#') {
1036 $color = substr($color, 1);
1037 }else{
1038 return $color;
1039 }
1040
1041 //Check if color has 6 or 3 characters and get values
1042 if (strlen($color) == 6) {
1043 $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
1044 } elseif (strlen($color) == 3) {
1045 $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
1046 } else {
1047 return $default;
1048 }
1049
1050 //Convert hexadec to rgb
1051 $rgb = array_map('hexdec', $hex);
1052
1053 //Check if opacity is set(rgba or rgb)
1054 if ($opacity) {
1055 if (abs($opacity) > 1)
1056 $opacity = 1.0;
1057 $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
1058 } else {
1059 $output = 'rgb(' . implode(",", $rgb) . ')';
1060 }
1061
1062 //Return rgb(a) color string
1063 return $output;
1064 }
1065
1066 public static function rgb2hex( $rgba ) {
1067 if ( strpos( $rgba, '#' ) === 0 ) {
1068 return $rgba;
1069 }
1070
1071 preg_match( '/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i', $rgba, $by_color );
1072 if(!empty($by_color)){
1073 return sprintf( '#%02x%02x%02x', $by_color[1], $by_color[2], $by_color[3] );
1074 }
1075 }
1076
1077 public static function secondsToWords($seconds){
1078 $ret = "";
1079
1080 $seconds = absint($seconds);
1081
1082 /*** get the days ***/
1083 $days = (int)($seconds / 86400);
1084 if ($days > 0) {
1085 $ret .= "$days " . __( 'days', "survey-maker" ) . ' ';
1086 }
1087
1088 /*** get the hours ***/
1089 $hours = (int)(($seconds - ($days * 86400)) / 3600);
1090 if ($hours > 0) {
1091 $ret .= "$hours " . __( 'hours', "survey-maker" ) . ' ';
1092 }
1093
1094 /*** get the minutes ***/
1095 $minutes = (int)(($seconds - $days * 86400 - $hours * 3600) / 60);
1096 if ($minutes > 0) {
1097 $ret .= "$minutes " . __( 'minutes', "survey-maker" ) . ' ';
1098 }
1099
1100 /*** get the seconds ***/
1101 $seconds = (int)($seconds - ($days * 86400) - ($hours * 3600) - ($minutes * 60));
1102 if ($seconds > 0) {
1103 $ret .= "$seconds " . __( 'seconds', "survey-maker" );
1104 }
1105
1106 return $ret;
1107 }
1108
1109 public static function get_limit_user_by_ip($id){
1110 global $wpdb;
1111 $table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions" );
1112 $user_ip = self::get_user_ip();
1113 $sql = "SELECT COUNT(*)
1114 FROM `{$table}`
1115 WHERE `user_ip` = '". esc_sql( $user_ip ) ."'
1116 AND `survey_id` = ". absint( $id );
1117 $result = intval($wpdb->get_var($sql));
1118 return $result;
1119 }
1120
1121 public static function get_limit_user_by_id($survey_id, $user_id){
1122 global $wpdb;
1123 $table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions" );
1124 $sql = "SELECT COUNT(*)
1125 FROM `{$table}`
1126 WHERE `user_id` = ". absint( $user_id ) ."
1127 AND `survey_id` = ". absint( $survey_id );
1128 $result = intval($wpdb->get_var($sql));
1129 return $result;
1130 }
1131
1132 public static function get_user_ip(){
1133 $ipaddress = '';
1134 if( !empty($_SERVER) && !empty($_SERVER['REMOTE_ADDR']) ){
1135 $ipaddress = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? sanitize_text_field($_SERVER['REMOTE_ADDR']) : 'UNKNOWN';
1136 } else {
1137 if (getenv('REMOTE_ADDR'))
1138 $ipaddress = getenv('REMOTE_ADDR');
1139 elseif (getenv('HTTP_CLIENT_IP'))
1140 $ipaddress = getenv('HTTP_CLIENT_IP');
1141 else if (getenv('HTTP_X_FORWARDED_FOR'))
1142 $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
1143 else if (getenv('HTTP_X_FORWARDED'))
1144 $ipaddress = getenv('HTTP_X_FORWARDED');
1145 else if (getenv('HTTP_FORWARDED_FOR'))
1146 $ipaddress = getenv('HTTP_FORWARDED_FOR');
1147 else if (getenv('HTTP_FORWARDED'))
1148 $ipaddress = getenv('HTTP_FORWARDED');
1149 else
1150 $ipaddress = 'UNKNOWN';
1151 }
1152 return $ipaddress;
1153 }
1154
1155 // OLD
1156 // public static function get_user_ip_validated(){
1157 // $ipaddress = '';
1158 // if (getenv('REMOTE_ADDR')){
1159 // $ipaddress = getenv('REMOTE_ADDR');
1160 // }
1161 // elseif (getenv('HTTP_CLIENT_IP')){
1162 // $ipaddress = getenv('HTTP_CLIENT_IP');
1163 // }
1164 // else if (getenv('HTTP_X_FORWARDED_FOR')){
1165 // $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
1166 // }
1167 // else if (getenv('HTTP_X_FORWARDED')){
1168 // $ipaddress = getenv('HTTP_X_FORWARDED');
1169 // }
1170 // else if (getenv('HTTP_FORWARDED_FOR')){
1171 // $ipaddress = getenv('HTTP_FORWARDED_FOR');
1172 // }
1173 // else if (getenv('HTTP_FORWARDED')){
1174 // $ipaddress = getenv('HTTP_FORWARDED');
1175 // }
1176 // else{
1177 // $ipaddress = 'UNKNOWN';
1178 // }
1179 // // Validate the IP address
1180 // if (filter_var($ipaddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) && $ipaddress !== '0.0.0.0') {
1181 // return $ipaddress;
1182 // }
1183 // return 'UNKNOWN';
1184
1185 // }
1186
1187 // FOR REVIEW
1188 public static function get_user_ip_validated(){
1189
1190 if( !empty($_SERVER) && !empty($_SERVER['REMOTE_ADDR']) ){
1191 $ipaddress = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? sanitize_text_field($_SERVER['REMOTE_ADDR']) : 'UNKNOWN';
1192
1193 if(!empty($ipaddress) && $ipaddress != 'UNKNOWN' ){
1194 return $ipaddress;
1195 }
1196 }
1197
1198 $headers_to_check = array(
1199 'HTTP_CLIENT_IP',
1200 'HTTP_X_FORWARDED_FOR',
1201 'HTTP_X_FORWARDED',
1202 'HTTP_FORWARDED_FOR',
1203 'HTTP_FORWARDED',
1204 'REMOTE_ADDR'
1205 );
1206
1207 foreach ($headers_to_check as $header) {
1208 if (!empty($_SERVER[$header])) {
1209 // In case of multiple IPs in HTTP_X_FORWARDED_FOR, take the last one
1210 if ($header === 'HTTP_X_FORWARDED_FOR') {
1211 $ips = explode(',', $_SERVER[$header]);
1212 $ip = trim(end($ips));
1213 } else {
1214 $ip = $_SERVER[$header];
1215 }
1216
1217 // Validate the IP address
1218 if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) && $ip !== '0.0.0.0') {
1219 return $ip;
1220 }
1221 }
1222 }
1223
1224 return 'UNKNOWN';
1225 }
1226
1227 public static function ays_autoembed( $content ) {
1228 global $wp_embed;
1229 $content = stripslashes( wpautop( $content ) );
1230 $content = $wp_embed->autoembed( $content );
1231 if ( strpos( $content, '[embed]' ) !== false ) {
1232 $content = $wp_embed->run_shortcode( $content );
1233 }
1234 $content = do_shortcode( $content );
1235 return $content;
1236 }
1237
1238 public static function get_questions_categories($q_ids){
1239 global $wpdb;
1240
1241 if($q_ids == ''){
1242 return array();
1243 }
1244 $sql = "SELECT DISTINCT c.id, c.title
1245 FROM {$wpdb->prefix}aysquiz_categories c
1246 JOIN {$wpdb->prefix}aysquiz_questions q
1247 ON c.id = q.category_id
1248 WHERE q.id IN (". esc_sql( $q_ids ) .")";
1249
1250 $result = $wpdb->get_results($sql, 'ARRAY_A');
1251 $cats = array();
1252
1253 foreach($result as $res){
1254 $cats[$res['id']] = $res['title'];
1255 }
1256
1257 return $cats;
1258 }
1259
1260 public static function get_suervey_sections_with_questions( $sections_ids, $question_ids ){
1261
1262 $sections = self::get_sections_by_survey_id($sections_ids);
1263 $sections_count = count( $sections );
1264
1265 foreach ($sections as $section_key => $section) {
1266 $sections[$section_key]['title'] = (isset($section['title']) && $section['title'] != '') ? stripslashes( htmlentities( $section['title'] ) ) : '';
1267 $sections[$section_key]['description'] = (isset($section['description']) && $section['description'] != '') ? stripslashes( htmlentities( $section['description'] ) ) : '';
1268
1269 $section_questions = self::get_questions_by_section_id( intval( $section['id'] ), $question_ids );
1270
1271 foreach ($section_questions as $question_key => $question) {
1272 $section_questions[$question_key]['question'] = (isset($question['question']) && $question['question'] != '') ? stripslashes( $question['question'] ) : '';
1273 $section_questions[$question_key]['image'] = (isset($question['image']) && $question['image'] != '') ? $question['image'] : '';
1274 $section_questions[$question_key]['type'] = (isset($question['type']) && $question['type'] != '') ? $question['type'] : 'radio';
1275 $section_questions[$question_key]['user_variant'] = (isset($question['user_variant']) && $question['user_variant'] == 'on') ? true : false;
1276
1277 $opts = json_decode( $question['options'], true );
1278 $opts['required'] = (isset($opts['required']) && $opts['required'] == 'on') ? true : false;
1279
1280 $q_answers = self::get_answers_by_question_id( intval( $question['id'] ) );
1281
1282 foreach ($q_answers as $answer_key => $answer) {
1283 $q_answers[$answer_key]['answer'] = (isset($answer['answer']) && $answer['answer'] != '') ? stripslashes( $answer['answer'] ) : '';
1284 $q_answers[$answer_key]['image'] = (isset($answer['image']) && $answer['image'] != '') ? $answer['image'] : '';
1285 $q_answers[$answer_key]['placeholder'] = (isset($answer['placeholder']) && $answer['placeholder'] != '') ? $answer['placeholder'] : '';
1286 }
1287
1288 $section_questions[$question_key]['answers'] = $q_answers;
1289
1290 $section_questions[$question_key]['options'] = $opts;
1291 }
1292
1293 $sections[$section_key]['questions'] = $section_questions;
1294 }
1295
1296 return $sections;
1297 }
1298
1299 /**
1300 * Recursive sanitation for an array
1301 *
1302 * @param $array
1303 *
1304 * @return mixed
1305 */
1306 public static function recursive_sanitize_text_field( $array, $textareas = array() ) {
1307 foreach ( $array as $key => &$value ) {
1308 if ( is_array( $value ) ) {
1309 $value = self::recursive_sanitize_text_field( $value, $textareas );
1310 } else {
1311 if( in_array( $key, $textareas ) ){
1312 if( function_exists( 'sanitize_textarea_field' ) ){
1313 $value = sanitize_textarea_field( $value );
1314 }else{
1315 $value = sanitize_text_field( $value );
1316 }
1317 }else{
1318 $value = sanitize_text_field( $value );
1319 }
1320 }
1321 }
1322
1323 return $array;
1324 }
1325
1326 public static function get_survey_takers_count( $id ){
1327 global $wpdb;
1328 $submission_table = $wpdb->prefix . "ayssurvey_submissions";
1329 $sql = "SELECT COUNT(id) AS count FROM {$submission_table} WHERE survey_id=". absint( $id ) ;
1330 $result = absint( $wpdb->get_var( $sql ) );
1331
1332 return $result;
1333 }
1334
1335 public static function get_setting_data( $meta_key = 'options' ){
1336 global $wpdb;
1337
1338 $name_prefix = 'survey_';
1339
1340 $settings_table = $wpdb->prefix . "ayssurvey_settings";
1341 $sql = "SELECT meta_value FROM " . $settings_table . " WHERE meta_key = '". esc_sql( $meta_key ) ."'";
1342 $result = $wpdb->get_var($sql);
1343
1344 $options = ($result == "") ? array() : json_decode($result, true);
1345
1346 return $options;
1347 }
1348
1349 public static function get_listtables_title_length( $listtable_name ) {
1350 global $wpdb;
1351
1352 $options = self::get_setting_data( 'options' );
1353
1354 $listtable_title_length = 5;
1355 if(! empty($options) ){
1356 switch ( $listtable_name ) {
1357 case 'surveys':
1358 $listtable_title_length = (isset($options['survey_title_length']) && intval($options['survey_title_length']) != 0) ? absint(intval($options['survey_title_length'])) : 5;
1359 break;
1360 case 'submissions':
1361 $listtable_title_length = (isset($options['survey_submissions_title_length']) && intval($options['survey_submissions_title_length']) != 0) ? absint(intval($options['survey_submissions_title_length'])) : 5;
1362 break;
1363 case 'survey_categories':
1364 $listtable_title_length = (isset($options['survey_categories_title_length']) && intval($options['survey_categories_title_length']) != 0) ? absint(intval($options['survey_categories_title_length'])) : 5;
1365 break;
1366 case 'popup_surveys':
1367 $listtable_title_length = (isset($options['survey_popups_title_length']) && intval($options['survey_popups_title_length']) != 0) ? absint(intval($options['survey_popups_title_length'])) : 5;
1368 break;
1369 default:
1370 $listtable_title_length = 5;
1371 break;
1372 }
1373 return $listtable_title_length;
1374 }
1375 return $listtable_title_length;
1376 }
1377
1378 /*
1379 * Get survey default texts from database
1380 */
1381 public static function ays_set_default_texts( $plugin_name, $settings = array() ) {
1382 global $wpdb;
1383
1384 $settings_table = $wpdb->prefix . "ayssurvey_settings";
1385 $sql = "SELECT meta_value FROM " . $settings_table . " WHERE meta_key = 'default_texts'";
1386 $result = $wpdb->get_var($sql);
1387 $settings_static_texts = ($result == "") ? array() : json_decode($result, true);
1388
1389 $wrong_shortcode_text = (isset($settings_static_texts['wrong_shortcode_text']) && $settings_static_texts['wrong_shortcode_text'] != '') ? stripslashes(esc_attr($settings_static_texts['wrong_shortcode_text'])) : 'Wrong shortcode initialized';
1390 $email_validation_error_text = (isset($settings_static_texts['email_validation_error_text']) && $settings_static_texts['email_validation_error_text'] != '') ? stripslashes(esc_html($settings_static_texts['email_validation_error_text'])) : 'Must be a valid email address';
1391 $redirecting_after_text = (isset($settings_static_texts['redirecting_after_text']) && $settings_static_texts['redirecting_after_text'] != '') ? stripslashes( esc_html( $settings_static_texts['redirecting_after_text'] ) ) : 'Redirecting after';
1392
1393 if ($wrong_shortcode_text === 'Wrong shortcode initialized') {
1394 $wrong_shortcode_text = __('Wrong shortcode initialized', "survey-maker");
1395 }
1396
1397 if ($email_validation_error_text === 'Must be a valid email address') {
1398 $email_validation_error_text = __('Must be a valid email address', "survey-maker");
1399 }
1400
1401 if ($redirecting_after_text === 'Redirecting after') {
1402 $redirecting_after_text = __('Redirecting after', "survey-maker");
1403 }
1404
1405 $texts = array(
1406 'wrongShortcode' => $wrong_shortcode_text,
1407 'emailValidationError' => $email_validation_error_text,
1408 'redirectingAfter' => $redirecting_after_text,
1409 );
1410
1411 return $texts;
1412 }
1413
1414 public static function ays_set_survey_texts( $plugin_name, $settings ){
1415
1416 /*
1417 * Get survey buttons texts from database
1418 */
1419 global $wpdb;
1420
1421 $name_prefix = 'survey_';
1422
1423 $settings_table = $wpdb->prefix . "ayssurvey_settings";
1424 $sql = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = 'buttons_texts'";
1425 $result = $wpdb->get_var($sql);
1426 $settings_buttons_texts = ($result == "") ? array() : json_decode($result, true);
1427
1428 $settings_buttons_texts['next_button'] = (isset($settings_buttons_texts['next_button']) && $settings_buttons_texts['next_button'] != '') ? esc_attr($settings_buttons_texts['next_button']) : 'Next';
1429 $ays_next_button = (isset($settings['survey_next_button_each_text']) && $settings['survey_next_button_each_text'] != '') ? esc_attr($settings['survey_next_button_each_text']) : $settings_buttons_texts['next_button'];
1430
1431 $settings_buttons_texts['prev_button'] = (isset($settings_buttons_texts['prev_button']) && $settings_buttons_texts['prev_button'] != '') ? esc_attr($settings_buttons_texts['prev_button']) : 'Prev';
1432 $ays_previous_button = (isset($settings['survey_previous_button_each_text']) && $settings['survey_previous_button_each_text'] != '') ? esc_attr($settings['survey_previous_button_each_text']) : $settings_buttons_texts['prev_button'];
1433
1434 $settings_buttons_texts['clear_button'] = (isset($settings_buttons_texts['clear_button']) && $settings_buttons_texts['clear_button'] != '') ? esc_attr($settings_buttons_texts['clear_button']) : 'Clear selection';
1435 $ays_clear_button = (isset($settings['survey_clear_selection_button_each_text']) && $settings['survey_clear_selection_button_each_text'] != '') ? esc_attr($settings['survey_clear_selection_button_each_text']) : $settings_buttons_texts['clear_button'];
1436
1437 $settings_buttons_texts['finish_button'] = (isset($settings_buttons_texts['finish_button']) && $settings_buttons_texts['finish_button'] != '') ? esc_attr($settings_buttons_texts['finish_button']) : 'Finish';
1438 $ays_finish_button = (isset($settings['survey_finish_button_each_text']) && $settings['survey_finish_button_each_text'] != '') ? esc_attr($settings['survey_finish_button_each_text']) : $settings_buttons_texts['finish_button'];
1439
1440 $settings_buttons_texts['restart_button'] = (isset($settings_buttons_texts['restart_button']) && $settings_buttons_texts['restart_button'] != '') ? esc_attr($settings_buttons_texts['restart_button']) : 'Restart';
1441 $ays_restart_survey_button = (isset($settings['survey_restart_button_each_text']) && $settings['survey_restart_button_each_text'] != '') ? esc_attr($settings['survey_restart_button_each_text']) : $settings_buttons_texts['restart_button'];
1442
1443 $settings_buttons_texts['exit_button'] = (isset($settings_buttons_texts['exit_button']) && $settings_buttons_texts['exit_button'] != '') ? esc_attr($settings_buttons_texts['exit_button']) : 'Exit';
1444 $ays_exit_button = (isset($settings['survey_exit_button_each_text']) && $settings['survey_exit_button_each_text'] != '') ? esc_attr($settings['survey_exit_button_each_text']) : $settings_buttons_texts['exit_button'];
1445 $ays_login_button = (isset($settings_buttons_texts['login_button']) && $settings_buttons_texts['login_button'] != '') ? stripslashes( esc_attr($settings_buttons_texts['login_button']) ) : 'Log In';
1446
1447 $settings_buttons_texts['start_button'] = (isset($settings_buttons_texts['start_button']) && $settings_buttons_texts['start_button'] != '') ? esc_attr($settings_buttons_texts['start_button']) : 'Start';
1448 $ays_start_button = (isset($settings['survey_start_button_each_text']) && $settings['survey_start_button_each_text'] != '') ? stripslashes( esc_attr( $settings['survey_start_button_each_text'] ) ) : $settings_buttons_texts['start_button'];
1449
1450 $settings_buttons_texts['login_button'] = (isset($settings_buttons_texts['login_button']) && $settings_buttons_texts['login_button'] != '') ? esc_attr($settings_buttons_texts['login_button']) : 'Log in';
1451 $ays_login_button = (isset($settings['survey_login_button_each_text']) && $settings['survey_login_button_each_text'] != '') ? stripslashes( esc_attr( $settings['survey_login_button_each_text'] ) ) : $settings_buttons_texts['login_button'];
1452
1453 $ays_next_button_text = ($ays_next_button === 'Next') ? __('Next', "survey-maker") : $ays_next_button;
1454 $ays_previous_button_text = ($ays_previous_button === 'Prev') ? __('Prev', "survey-maker") : $ays_previous_button;
1455 $ays_clear_button_text = ($ays_clear_button === 'Clear selection') ? __('Clear selection', "survey-maker") : $ays_clear_button;
1456 $ays_finish_button_text = ($ays_finish_button === 'Finish') ? __('Finish', "survey-maker") : $ays_finish_button;
1457 $ays_restart_button_text = ($ays_finish_button === 'Restart') ? __('Restart', "survey-maker") : $ays_restart_survey_button;
1458 $ays_exit_button_text = ($ays_exit_button === 'Exit') ? __('Exit', "survey-maker") : $ays_exit_button;
1459 $ays_login_button_text = ($ays_login_button === 'Log In') ? __('Log In', "survey-maker") : $ays_login_button;
1460
1461 if ($ays_start_button === 'Start') {
1462 $ays_start_button_text = __('Start', "survey-maker");
1463 }else{
1464 $ays_start_button_text = $ays_start_button;
1465 }
1466
1467 $texts = array(
1468 'nextButton' => $ays_next_button_text,
1469 'previousButton' => $ays_previous_button_text,
1470 'clearButton' => $ays_clear_button_text,
1471 'finishButton' => $ays_finish_button_text,
1472 'restartButton' => $ays_restart_button_text,
1473 'exitButton' => $ays_exit_button_text,
1474 'loginButton' => $ays_login_button_text,
1475 'startButton' => $ays_start_button_text,
1476 );
1477 return $texts;
1478 }
1479
1480 public static function ays_survey_numbering_all( $numbering ){
1481 $keyword_arr = array();
1482 switch ($numbering) {
1483 case '1.':
1484
1485 $char_min_val = '1';
1486 $char_max_val = '100';
1487 for($x = $char_min_val; $x <= $char_max_val; $x++){
1488 $keyword_arr[] = $x .".";
1489 }
1490
1491 break;
1492 case '1)':
1493
1494 $char_min_val = '1';
1495 $char_max_val = '100';
1496 for($x = $char_min_val; $x <= $char_max_val; $x++){
1497 $keyword_arr[] = $x .")";
1498 }
1499
1500 break;
1501 case 'A.':
1502
1503 $char_min_val = 'A';
1504 $char_max_val = 'Z';
1505 for($x = $char_min_val; $x <= $char_max_val; $x++){
1506 $keyword_arr[] = $x .".";
1507 }
1508
1509 break;
1510 case 'A)':
1511
1512 $char_min_val = 'A';
1513 $char_max_val = 'Z';
1514 for($x = $char_min_val; $x <= $char_max_val; $x++){
1515 $keyword_arr[] = $x .")";
1516 }
1517
1518 break;
1519 case 'a.':
1520 $char_min_val = 'a';
1521 $char_max_val = 'z';
1522 for($x = $char_min_val; $x <= $char_max_val; $x++){
1523 $keyword_arr[] = $x .".";
1524 }
1525
1526 break;
1527 case 'a)':
1528
1529 $char_min_val = 'a';
1530 $char_max_val = 'z';
1531 for($x = $char_min_val; $x <= $char_max_val; $x++){
1532 $keyword_arr[] = $x .")";
1533 }
1534
1535 break;
1536
1537 default:
1538
1539 break;
1540 }
1541
1542 return $keyword_arr;
1543 }
1544
1545 public static function ays_survey_question_results_for_summary( $survey_id, $submission_ids = null ){
1546 global $wpdb;
1547
1548 if($survey_id === null){
1549 return array(
1550 'total_count' => 0,
1551 'questions' => array()
1552 );
1553 }
1554
1555 $answer_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "answers";
1556 $question_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "questions";
1557 $submitions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
1558 $survey_section_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "sections";
1559 $surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
1560 $submitions_questiions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions_questions";
1561
1562 $question_ids = "SELECT question_ids FROM {$surveys_table} WHERE id =". absint( $survey_id );
1563 $question_ids_results = $wpdb->get_var( $question_ids );
1564 $ays_question_id = ($question_ids_results != '') ? $question_ids_results : null;
1565
1566 if($ays_question_id == null){
1567 return array(
1568 'total_count' => 0,
1569 'questions' => array()
1570 );
1571 }
1572
1573 $questions_ids_arr = explode(',',$ays_question_id);
1574 $answer_id = "SELECT a.id, a.answer, COUNT(s_q.answer_id) AS answer_count
1575 FROM {$answer_table} AS a
1576 LEFT JOIN {$submitions_questiions_table} AS s_q
1577 ON a.id = s_q.answer_id
1578 WHERE s_q.survey_id=". absint( $survey_id ) ."
1579 GROUP BY a.id";
1580
1581 $answer_id_result = $wpdb->get_results($answer_id,'ARRAY_A');
1582
1583 $for_checkbox = "SELECT a.id, a.answer, COUNT(s_q.answer_id) AS answer_count
1584 FROM {$answer_table} AS a
1585 LEFT JOIN {$submitions_questiions_table} AS s_q
1586 ON a.id = s_q.answer_id OR FIND_IN_SET( a.id, s_q.user_answer )
1587 WHERE s_q.type = 'checkbox'
1588 AND s_q.survey_id=". absint( $survey_id ) ."
1589 GROUP BY a.id";
1590
1591 $for_checkbox_result = $wpdb->get_results($for_checkbox,'ARRAY_A');
1592
1593 $answer_count = array();
1594 $question_type = '';
1595 foreach ($answer_id_result as $key => $answer_count_by_id) {
1596 $ays_survey_answer_count = (isset($answer_count_by_id['answer_count']) && $answer_count_by_id['answer_count'] !="") ? absint(intval($answer_count_by_id['answer_count'])) : '';
1597 $answer_count[$answer_count_by_id['id']] = $ays_survey_answer_count;
1598 }
1599
1600 foreach ($for_checkbox_result as $key => $answer_count_by_id) {
1601 $ays_survey_answer_count = (isset($answer_count_by_id['answer_count']) && $answer_count_by_id['answer_count'] !="") ? absint(intval($answer_count_by_id['answer_count'])) : '';
1602 $answer_count[$answer_count_by_id['id']] = $ays_survey_answer_count;
1603 }
1604
1605 $question_by_ids = Survey_Maker_Data::get_question_by_ids( $questions_ids_arr );
1606
1607 $select_answer_q_type = "SELECT type, user_answer, id, question_id
1608 FROM {$submitions_questiions_table}
1609 WHERE user_answer != ''
1610 AND type != 'checkbox'
1611 AND survey_id=". absint( $survey_id );
1612
1613 $submission_answer_other = "SELECT question_id, answer_id, user_variant
1614 FROM {$submitions_questiions_table}
1615 WHERE user_variant != ''
1616 AND survey_id=". absint( $survey_id );
1617
1618 if( $submission_ids !== null ){
1619 if( is_array( $submission_ids ) ){
1620 $select_answer_q_type .= " AND submission_id IN (" . esc_sql( implode( ',', $submission_ids ) ) . ") ";
1621 $submission_answer_other .= " AND submission_id IN (" . esc_sql( implode( ',', $submission_ids ) ) . ") ";
1622 }
1623 }
1624
1625 $result_answers_q_type = $wpdb->get_results($select_answer_q_type,'ARRAY_A');
1626 $result_answers_other = $wpdb->get_results($submission_answer_other,'ARRAY_A');
1627 $text_answer = array();
1628 foreach($result_answers_q_type as $key => $result_answer_q_type){
1629 $text_answer[$result_answer_q_type['type']][$result_answer_q_type['question_id']][] = $result_answer_q_type['user_answer'];
1630 }
1631
1632 $other_answers = array();
1633 $other_answers_all = array();
1634 foreach($result_answers_other as $key => $result_answer_other){
1635 if( intval( $result_answer_other['answer_id'] ) == 0 ){
1636 $other_answers[$result_answer_other['question_id']][] = $result_answer_other['user_variant'];
1637 }
1638 $other_answers_all[$result_answer_other['question_id']][] = $result_answer_other['user_variant'];
1639 }
1640
1641 $text_types = array(
1642 'text',
1643 'short_text',
1644 'number',
1645 'phone',
1646 'star',
1647 'name',
1648 'email',
1649 'linear_scale',
1650 'star',
1651 'date',
1652 'time',
1653 'date_time',
1654 );
1655
1656 //Question types different charts
1657 $ays_submissions_count = array();
1658 $question_results = array();
1659
1660 $total_count = 0;
1661 foreach ($question_by_ids as $key => $question) {
1662
1663 $answers = $question->answers;
1664 $question_id = $question->id;
1665 $question_title = $question->question;
1666
1667 //questions
1668 $question_results[$question_id]['question_id'] = $question_id;
1669 $question_results[$question_id]['question'] = $question_title;
1670 $ays_answer = array();
1671 $question_answer_ids = array();
1672 foreach ($answers as $key => $answer) {
1673 $answer_id = $answer->id;
1674 $answer_title = $answer->answer;
1675
1676 $ays_answer[$answer_id] = isset( $answer_count[$answer_id] ) ? $answer_count[$answer_id] : 0;
1677 $question_answer_ids[$answer_id] = $answer_title;
1678 }
1679
1680 //sum of submissions count per questions
1681 if($question->type == "checkbox"){
1682 $sub_checkbox_count = self::ays_survey_get_submission_count($question->id, $question->type, $survey_id);
1683 $sum_of_count = $sub_checkbox_count;
1684 }else{
1685 $sum_of_count = array_sum( array_values( $ays_answer ) );
1686 }
1687
1688 $question_results[$question_id]['otherAnswers'] = isset( $other_answers[$question->id] ) ? $other_answers[$question->id] : array();
1689
1690 if( in_array( $question->type, $text_types ) ){
1691 $question_ls_options = json_decode($question->options, true);
1692
1693 if($question->type == 'star'){
1694 $scale_from = isset($question_ls_options['star_1']) && $question_ls_options['star_1'] != "" ? stripslashes($question_ls_options['star_1']) : "";
1695 $scale_to = isset($question_ls_options['star_2']) && $question_ls_options['star_2'] != "" ? stripslashes($question_ls_options['star_2']) : "";
1696 $scale_length = isset($question_ls_options['star_scale_length']) && $question_ls_options['star_scale_length'] != "" ? $question_ls_options['star_scale_length'] : "";
1697 $question_results[$question_id]['labels'] = array(
1698 'from' => $scale_from,
1699 'to' => $scale_to,
1700 'length' => $scale_length
1701 );
1702 }
1703 $question_results[$question_id]['answers'] = isset( $text_answer[$question->type] ) ? $text_answer[$question->type] : '';
1704 $question_results[$question_id]['answerTitles'] = isset( $text_answer[$question->type] ) ? $text_answer[$question->type] : '';
1705 $question_results[$question_id]['sum_of_answers_count'] = isset( $text_answer[$question->type][$question->id] ) ? count( $text_answer[$question->type][$question->id] ) : 0;
1706 $question_results[$question_id]['sum_of_same_answers'] = isset( $text_answer[$question->type][$question->id] ) ? array_count_values( $text_answer[$question->type][$question->id] ) : 0;
1707 }else{
1708 $question_results[$question_id]['answers'] = $ays_answer;
1709 $question_results[$question_id]['answerTitles'] = $question_answer_ids;
1710 $question_results[$question_id]['sum_of_answers_count'] = $sum_of_count;
1711 if( $sum_of_count == 0 ){
1712 $question_results[$question_id]['answers'] = array();
1713 }
1714 }
1715
1716 // Answers for charts
1717 if( !empty( $question_results[$question_id]['otherAnswers'] ) ){
1718 $question_results[$question_id]['answers'][0] = count( $question_results[$question_id]['otherAnswers'] );
1719 $question_results[$question_id]['answerTitles'][0] = __( '"Other" answer(s)', "survey-maker" );
1720 $question_results[$question_id]['same_other_count'] = array_count_values( $question_results[$question_id]['otherAnswers'] );
1721
1722 if($question->type == "radio" || $question_type == "yesorno"){
1723 $question_results[$question_id]['sum_of_answers_count'] += count( $question_results[$question_id]['otherAnswers'] );
1724 }
1725 }
1726 //
1727
1728 $total_count += intval( $question_results[$question_id]['sum_of_answers_count'] );
1729
1730 $question_results[$question_id]['question_type'] = $question->type;
1731 }
1732
1733 return array(
1734 'total_count' => $total_count,
1735 'questions' => $question_results
1736 );
1737 }
1738
1739 public static function ays_survey_get_last_submission_id_for_summary( $survey_id ){
1740 global $wpdb;
1741
1742 if($survey_id === null){
1743 return array();
1744 }
1745
1746 $submitions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
1747
1748 //submission of each result
1749 $submission = "SELECT * FROM {$submitions_table} WHERE survey_id=". absint( $survey_id ) ." ORDER BY id DESC LIMIT 1 ";
1750 $last_submission = $wpdb->get_row( $submission, 'ARRAY_A' );
1751
1752 if( $last_submission == null ){
1753 return array();
1754 }
1755 return $last_submission;
1756 }
1757
1758 public static function ays_survey_individual_results_for_one_submission_for_summary( $submission, $survey ){
1759 global $wpdb;
1760 $survey_id = isset( $survey['id'] ) ? absint( intval( $survey['id'] ) ) : null;
1761
1762 if( is_null( $survey_id ) || empty( $submission )){
1763 return array(
1764 'sections' => array()
1765 );
1766 }
1767
1768 $submitions_questiions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions_questions";
1769
1770 $ays_individual_questions_for_one_submission = array();
1771 $question_answer_id = array();
1772 $submission_id = isset( $submission['id'] ) && $submission['id'] != '' ? $submission['id'] : null;
1773
1774 if( is_null( $submission_id ) ){
1775 return array(
1776 'sections' => array()
1777 );
1778 }
1779
1780 $checkbox_ids = '';
1781
1782 $individual_questions = "SELECT * FROM {$submitions_questiions_table} WHERE submission_id=" . absint( $submission_id );
1783 $individual_questions_results = $wpdb->get_results($individual_questions,'ARRAY_A');
1784
1785 // Survey questions IDs
1786 $question_ids = isset( $survey['question_ids'] ) && $survey['question_ids'] != '' ? $survey['question_ids'] : '';
1787
1788 // Section Ids
1789 $sections_ids = (isset( $survey['section_ids' ] ) && $survey['section_ids'] != '') ? $survey['section_ids'] : '';
1790
1791 $sections = Survey_Maker_Data::get_suervey_sections_with_questions( $sections_ids, $question_ids );
1792
1793 $text_types = array(
1794 'text',
1795 'short_text',
1796 'number',
1797 'phone',
1798 'star',
1799 'name',
1800 'email',
1801 'linear_scale',
1802 'star',
1803 'date',
1804 'time',
1805 );
1806
1807 foreach ($individual_questions_results as $key => $individual_questions_result) {
1808 if($individual_questions_result['type'] == 'checkbox'){
1809 $checkbox_ids = $individual_questions_result['user_answer'] != '' ? explode(',', $individual_questions_result['user_answer']) : array();
1810 $question_answer_id[ $individual_questions_result['question_id'] ]['answer'] = $checkbox_ids;
1811 $question_answer_id[ $individual_questions_result['question_id'] ]['otherAnswer'] = isset($individual_questions_result['user_variant']) && $individual_questions_result['user_variant'] != '' ? $individual_questions_result['user_variant'] : '';
1812 }elseif( in_array( $individual_questions_result['type'], $text_types ) ){
1813 $question_answer_id[ $individual_questions_result['question_id'] ] = $individual_questions_result['user_answer'];
1814 if( $individual_questions_result['type'] == 'date' ){
1815 if( $individual_questions_result['user_answer'] != '' ){
1816 $question_answer_id[ $individual_questions_result['question_id'] ] = date( 'd . m . Y', strtotime( $individual_questions_result['user_answer'] ) );
1817 }else{
1818 $question_answer_id[ $individual_questions_result['question_id'] ] = '';
1819 }
1820 }
1821 elseif( $individual_questions_result['type'] == 'time' ){
1822 if( $individual_questions_result['user_answer'] != '' ){
1823 $question_answer_id[ $individual_questions_result['question_id'] ] = implode(" : ", explode( ":", $individual_questions_result['user_answer'] ));
1824 }else{
1825 $question_answer_id[ $individual_questions_result['question_id'] ] = '';
1826 }
1827 }
1828 }elseif($individual_questions_result['type'] == 'radio'){
1829 $other_answer = isset($individual_questions_result['user_variant']) && $individual_questions_result['user_variant'] != '' ? $individual_questions_result['user_variant'] : '';
1830 $question_answer_id[ $individual_questions_result['question_id'] ]['otherAnswer'] = $other_answer;
1831 $question_answer_id[ $individual_questions_result['question_id'] ]['answer'] = $individual_questions_result['answer_id'];
1832 if( intval( $individual_questions_result['answer_id'] ) === 0 && $other_answer !== '' ){
1833 $question_answer_id[ $individual_questions_result['question_id'] ]['otherAnswer'] = $other_answer;
1834 $question_answer_id[ $individual_questions_result['question_id'] ]['answer'] = $individual_questions_result['answer_id'];
1835 }elseif( intval( $individual_questions_result['answer_id'] ) === 0 && $other_answer === '' ){
1836 $question_answer_id[ $individual_questions_result['question_id'] ]['otherAnswer'] = '';
1837 $question_answer_id[ $individual_questions_result['question_id'] ]['answer'] = '-1';
1838 }else{
1839 $question_answer_id[ $individual_questions_result['question_id'] ]['otherAnswer'] = '';
1840 $question_answer_id[ $individual_questions_result['question_id'] ]['answer'] = $individual_questions_result['answer_id'];
1841 }
1842 }else{
1843 $question_answer_id[ $individual_questions_result['question_id'] ] = $individual_questions_result['answer_id'];
1844 }
1845 }
1846
1847 $ays_individual_questions_for_one_submission['submission_id'] = $submission['id'];
1848 $ays_individual_questions_for_one_submission['questions'] = $question_answer_id;
1849 $ays_individual_questions_for_one_submission['sections'] = $sections;
1850
1851 return $ays_individual_questions_for_one_submission;
1852 }
1853
1854 public static function get_submission_count_and_ids_for_summary( $survey_id){
1855 global $wpdb;
1856
1857 if($survey_id === null){
1858 return false;
1859 }
1860 $submitions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
1861
1862 //submission of each result
1863 $submission_ids = "SELECT id,
1864 (SELECT COUNT(id) FROM {$submitions_table} i
1865 WHERE i.survey_id=j.survey_id) AS count_submission
1866 FROM {$submitions_table} j
1867 WHERE survey_id=". absint( $survey_id ) ."
1868 ORDER BY id";
1869 $submission_ids_result = $wpdb->get_results($submission_ids,'ARRAY_A');
1870 $submission_count = '';
1871 $submissions_id_arr = array();
1872 foreach ($submission_ids_result as $key => $submission_id_result) {
1873 $submission_id_count = $submission_id_result['count_submission'];
1874 $submission_count = intval($submission_id_count);
1875 $submissions_id_arr[] = $submission_id_result['id'];
1876 }
1877 $submissions_id_str = implode(',', $submissions_id_arr );
1878
1879 $submission_count_and_ids = array(
1880 'submission_count' => $submission_count,
1881 'submission_ids' => $submissions_id_str,
1882 'submission_ids_arr' => $submissions_id_arr,
1883 );
1884
1885 return $submission_count_and_ids;
1886 }
1887
1888 public static function ays_survey_get_submission_count($id , $type , $survey_id){
1889 global $wpdb;
1890 $submitions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
1891 $submitions_q_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions_questions";
1892 $results = array();
1893
1894 $sql = "SELECT submission_id AS sub_count
1895 FROM {$submitions_q_table}
1896 WHERE question_id = ". absint( $id ) ."
1897 AND survey_id = ". absint( $survey_id ) ."";
1898
1899 if( $type == 'checkbox' ){
1900 $sql .= " AND user_answer != '' ";
1901 }
1902
1903 $sql .= " GROUP BY submission_id ";
1904 $results = $wpdb->get_results( $sql, 'ARRAY_A' );
1905
1906 $submission_count = count( $results );
1907 return $submission_count;
1908 }
1909
1910 public static function ays_survey_copy_text_formater( $info_array ) {
1911 $return = "`\n";
1912 foreach ( $info_array as $section => $details ) {
1913 $return .= sprintf( "%s: %s", $section, $details );
1914 $return .= "\n";
1915 }
1916 $return .= '`';
1917 return $return;
1918 }
1919
1920 public static function ays_survey_detected_device_chart() {
1921 $device = 'desktop';
1922 $isMobile = preg_match("/(iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile)/i", $_SERVER["HTTP_USER_AGENT"]);
1923 $isTablet = preg_match("/(ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle)/i", $_SERVER["HTTP_USER_AGENT"]);
1924
1925 if($isMobile){
1926 $device = 'mobile';
1927 }else if($isTablet){
1928 $device = 'tablet';
1929 }else{
1930 $device = 'desktop';
1931 }
1932 return $device;
1933 }
1934
1935 public static function ays_survey_get_passed_users_count( $survey_id ) {
1936 global $wpdb;
1937 $submissions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
1938 // Get passed users
1939 $sql = "SELECT COUNT(id) AS users_count FROM ".$submissions_table."
1940 WHERE survey_id = ".$survey_id." AND user_id != 0
1941 GROUP BY user_id";
1942 $result = $wpdb->get_results($sql);
1943 // Get passed guests count
1944 $sql2 = "SELECT COUNT(id) FROM ".$submissions_table." WHERE `user_id` = 0 AND `survey_id` = ".$survey_id;
1945 $result2 = $wpdb->get_var($sql2);
1946 $all_count = intval(count($result)) + intval($result2);
1947 return $all_count;
1948 }
1949
1950 public static function get_template_part( $slug, $name = null, $args = array(), $path = 'admin' ) {
1951 /**
1952 * Fires before the specified template part file is loaded.
1953 *
1954 * The dynamic portion of the hook name, `$slug`, refers to the slug name
1955 * for the generic template part.
1956 *
1957 * @since 1.0.0
1958 * @since 1.0.0 The `$args` parameter was added.
1959 *
1960 * @param string $slug The slug name for the generic template.
1961 * @param string|null $name The name of the specialized template.
1962 * @param array $args Additional arguments passed to the template.
1963 */
1964
1965 $templates = array();
1966 $name = (string) $name;
1967 if ( '' !== $name ) {
1968 $templates[] = "{$slug}-{$name}.php";
1969 }
1970
1971 $templates[] = "{$slug}.php";
1972
1973 /**
1974 * Fires before an attempt is made to locate and load a template part.
1975 *
1976 * @since 1.0.0
1977 * @since 1.0.0 The `$args` parameter was added.
1978 *
1979 * @param string $slug The slug name for the generic template.
1980 * @param string $name The name of the specialized template.
1981 * @param string[] $templates Array of template files to search for, in order.
1982 * @param array $args Additional arguments passed to the template.
1983 */
1984 do_action( 'ays_sm_get_template_part', $slug, $name, $templates, $path, $args );
1985
1986 if ( ! self::locate_template( $templates, true, false, $path, $args ) ) {
1987 return false;
1988 }
1989 }
1990
1991 public static function locate_template( $template_names, $load = false, $require_once = true, $path = 'admin', $args = array() ) {
1992 $located = '';
1993 foreach ( (array) $template_names as $template_name ) {
1994 if ( ! $template_name ) {
1995 continue;
1996 }
1997
1998 $path = $path == 'public' ? SURVEY_MAKER_PUBLIC_PATH : SURVEY_MAKER_ADMIN_PATH;
1999
2000 if ( file_exists( $path . '/' . $template_name ) ) {
2001 $located = $path . '/' . $template_name;
2002 break;
2003 } elseif ( file_exists( $path . '/' . $template_name ) ) {
2004 $located = $path . '/' . $template_name;
2005 break;
2006 }
2007 }
2008 if ( $load && '' !== $located ) {
2009
2010 self::load_template( $located, $require_once, $args );
2011 }
2012
2013 return $located;
2014 }
2015
2016 public static function load_template( $_template_file, $require_once = true, $args = array() ) {
2017 if ( $require_once ) {
2018
2019 require_once $_template_file;
2020 } else {
2021 require $_template_file;
2022 }
2023 }
2024
2025
2026 public static function get_submission_count_and_ids( $survey_id, $filters = array() ){
2027 global $wpdb;
2028
2029 if($survey_id === null){
2030 return false;
2031 }
2032 $submitions_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "submissions";
2033
2034 $filters_where_condition = "";
2035 if (isset($filters['is_filter']) && $filters['is_filter']) {
2036 $filters_where_condition = self::get_filters_where_condition($filters);
2037 }
2038
2039 //submission of each result
2040 $submission_ids = "SELECT id
2041 FROM {$submitions_table} j
2042 WHERE survey_id=". absint( $survey_id ) . $filters_where_condition . "
2043 ORDER BY id";
2044 $submission_ids_result = $wpdb->get_results($submission_ids,'ARRAY_A');
2045
2046 $submission_count_sql = "SELECT COUNT(id) AS count_submission
2047 FROM {$submitions_table}
2048 WHERE survey_id=". absint( $survey_id ) . $filters_where_condition ." ";
2049 $submission_count_result = $wpdb->get_var($submission_count_sql);
2050 $submission_count = '';
2051 $submissions_id_arr = array();
2052
2053 foreach ($submission_ids_result as $key => $submission_id_result) {
2054 $submission_count = intval($submission_count_result);
2055 $submissions_id_arr[] = $submission_id_result['id'];
2056 }
2057 $submissions_id_str = implode(',', $submissions_id_arr );
2058
2059 $submission_count_and_ids = array(
2060 'submission_count' => $submission_count,
2061 'submission_ids' => $submissions_id_str,
2062 'submission_ids_arr' => $submissions_id_arr,
2063 );
2064
2065 return $submission_count_and_ids;
2066 }
2067
2068 // Check users cookie
2069 public static function ays_survey_set_cookie($attr){
2070 $cookie_name = $attr['name'].$attr['id'];
2071 $cookie_value = $attr['title'];
2072 $cookie_value = isset( $attr['attempts_count'] ) ? $attr['attempts_count'] : 1;
2073 self::ays_survey_remove_cookie( $attr );
2074 $cookie_expiration = current_time('timestamp') + (1 * 365 * 24 * 60 * 60);
2075 setcookie($cookie_name, $cookie_value, $cookie_expiration, '/');
2076 }
2077
2078 public static function ays_survey_remove_cookie($attr){
2079 $cookie_name = $attr['name'].$attr['id'];
2080 if(isset($_COOKIE[$cookie_name])){
2081 unset($_COOKIE[$cookie_name]);
2082 $cookie_expiration = current_time('timestamp') - 1;
2083 setcookie($cookie_name, null, $cookie_expiration, '/');
2084 }
2085 }
2086
2087 public static function ays_survey_check_cookie($attr){
2088 $cookie_name = $attr['name'].$attr['id'];
2089 if(isset($_COOKIE[$cookie_name])){
2090 if( isset( $attr['increase_count'] ) && $attr['increase_count'] == true ){
2091 $attr['attempts_count'] = intval( $_COOKIE[$cookie_name] ) + 1;
2092 self::ays_survey_set_cookie( $attr );
2093 }
2094 return true;
2095 }
2096 return false;
2097 }
2098
2099 public static function get_limit_cookie_count($attr){
2100 $cookie_name = $attr['name'].$attr['id'];
2101 if(isset($_COOKIE[$cookie_name])){
2102 return intval( $_COOKIE[ $cookie_name ] );
2103 }
2104 return false;
2105 }
2106
2107 public static function get_user_profile_data(){
2108
2109 $user_first_name = '';
2110 $user_last_name = '';
2111 $user_nickname = '';
2112
2113 $user_id = get_current_user_id();
2114 if($user_id != 0){
2115 $usermeta = get_user_meta( $user_id );
2116
2117 if($usermeta !== null){
2118 $user_first_name = (isset($usermeta['first_name'][0]) && $usermeta['first_name'][0] != '' ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
2119 $user_last_name = (isset($usermeta['last_name'][0]) && $usermeta['last_name'][0] != '' ) ? sanitize_text_field( $usermeta['last_name'][0] ) : '';
2120 $user_nickname = (isset($usermeta['nickname'][0]) && $usermeta['nickname'][0] != '' ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
2121 }
2122 }
2123
2124 $message_data = array(
2125 'user_first_name' => $user_first_name,
2126 'user_last_name' => $user_last_name,
2127 'user_nickname' => $user_nickname,
2128 );
2129
2130 $current_user_data = get_userdata( $user_id );
2131 $user_display_name = "";
2132 $user_wordpress_roles = '';
2133 $user_website_url = '';
2134 $user_email = '';
2135
2136 if ( ! is_null( $current_user_data ) && $current_user_data ) {
2137 $user_display_name = ( isset( $current_user_data->data->display_name ) && $current_user_data->data->display_name != '' ) ? sanitize_text_field( $current_user_data->data->display_name ) : "";
2138 $user_email = ( isset( $current_user_data->data->user_email ) && $current_user_data->data->user_email != '' ) ? sanitize_text_field( $current_user_data->data->user_email ) : "";
2139 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
2140 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
2141 if ( is_array( $user_wordpress_roles ) ) {
2142 $user_wordpress_roles = implode(",", $user_wordpress_roles);
2143 }
2144 }
2145 $user_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? $current_user_data->user_url : "";
2146 }
2147
2148 $message_data['user_display_name'] = $user_display_name;
2149 $message_data['user_wordpress_roles'] = $user_wordpress_roles;
2150 $message_data['user_website_url'] = $user_website_url;
2151 $message_data['user_wordpress_email'] = $user_email;
2152 $message_data['user_ip_address'] = self::get_user_ip();
2153
2154 return $message_data;
2155 }
2156
2157 public static function get_survey_results_count_by_id($id){
2158 global $wpdb;
2159
2160 $sql = "SELECT COUNT(*) AS res_count
2161 FROM {$wpdb->prefix}ayssurvey_submissions
2162 WHERE survey_id=". $id ." ";
2163
2164 $quiz = $wpdb->get_row($sql, 'ARRAY_A');
2165
2166 return $quiz;
2167 }
2168
2169 public static function ays_survey_is_elementor(){
2170 if( isset( $_GET['action'] ) && $_GET['action'] == 'elementor' ){
2171 $is_elementor = true;
2172 }elseif( isset( $_REQUEST['elementor-preview'] ) && $_REQUEST['elementor-preview'] != '' ){
2173 $is_elementor = true;
2174 }else{
2175 $is_elementor = false;
2176 }
2177
2178 if ( ! $is_elementor ) {
2179 $is_elementor = ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ? true : false;
2180 }
2181
2182 return $is_elementor;
2183 }
2184
2185 public static function ays_survey_is_editor(){
2186 $is_editor = false;
2187 if( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ){
2188 if ( isset( $_GET['post'] ) && absint( $_GET['post'] ) > 0 ) {
2189 $is_editor = true;
2190 }
2191 } elseif ( isset( $_GET['context'] ) && ( $_GET['context'] == 'add' || $_GET['context'] == 'edit' ) ) {
2192 if( isset( $_GET['post_id'] ) & absint( $_GET['post_id'] ) > 0 ){
2193 $is_editor = true;
2194 }
2195 }
2196
2197 return $is_editor;
2198 }
2199
2200 // Retrieves the attachment ID from the file URL
2201 public static function ays_survey_get_image_id_by_url( $image_url ) {
2202 global $wpdb;
2203
2204 $image_alt_text = "";
2205 if ( !empty( $image_url ) ) {
2206
2207 $re = '/-\d+[Xx]\d+\./';
2208 $subst = '.';
2209
2210 $image_url = preg_replace($re, $subst, $image_url, 1);
2211
2212 $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
2213 if ( !is_null( $attachment ) && !empty( $attachment ) ) {
2214
2215 $image_id = (isset( $attachment[0] ) && $attachment[0] != "") ? absint( $attachment[0] ) : "";
2216 if ( $image_id != "" ) {
2217 $image_alt_text = self::ays_survey_get_image_alt_text_by_id( $image_id );
2218 }
2219 }
2220 }
2221
2222 return $image_alt_text;
2223 }
2224
2225 public static function ays_survey_get_image_alt_text_by_id( $image_id ) {
2226
2227 $image_data = "";
2228 if ( $image_id != "" ) {
2229
2230 $result = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
2231 if ( $result && $result != "" ) {
2232 $image_data = esc_attr( $result );
2233 }
2234 }
2235
2236 return $image_data;
2237 }
2238
2239 public static function get_user_by_ip($id){
2240 global $wpdb;
2241 $user_ip = self::get_user_ip();
2242 $sql = "SELECT COUNT(*)
2243 FROM `{$wpdb->prefix}ayssurvey_submissions`
2244 WHERE `user_ip` = '$user_ip'
2245 AND `survey_id` = $id";
2246 $result = $wpdb->get_var($sql);
2247 return $result;
2248 }
2249
2250 public static function get_surveys_by_category( $id ){
2251 global $wpdb;
2252
2253 $id = ( isset( $id ) && $id != '' ) ? absint( intval( $id ) ) : null;
2254 $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "surveys";
2255 $categories_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "survey_categories";
2256
2257 $results = '';
2258
2259 if($id != null){
2260 $sql = "SELECT *, s.`title`, s.`id`, s.`options` FROM `{$surveys_table}` AS s LEFT JOIN `{$categories_table}` AS c ON FIND_IN_SET(c.`id`, s. `category_ids` ) AND c.`status` = 'published' AND s.`status` = 'published' WHERE c.`id` = " . esc_sql( $id );
2261 $results = $wpdb->get_results( $sql, 'ARRAY_A');
2262 }
2263
2264 return $results;
2265 }
2266
2267 public static function survey_lazy_loading_for_images( $toggle ){
2268 if($toggle){
2269 return "loading='lazy'";
2270 }
2271 return '';
2272 }
2273
2274 public static function survey_no_items_list_tables() {
2275 if( isset( $_GET['status'] ) && ($_GET['status'] == 'deleted' || $_GET['status'] == 'restored')){
2276 $url = remove_query_arg( array('fstatus', 'status', '_wpnonce') );
2277 $url = esc_url_raw( $url );
2278 wp_redirect( $url );
2279 }
2280 else{
2281 echo esc_html__( 'There are no surveys yet.', "survey-maker" );
2282 }
2283 }
2284
2285 public static function survey_get_loader($type , $loading = ''){
2286 switch( $type ){
2287 case 'default':
2288 $survey_loader_html = "<div data-class='lds-ellipsis' data-role='loader' class='lds-ellipsis ays-survey-wait-loading-loader'><div></div><div></div><div></div><div></div></div>";
2289 break;
2290 case 'circle':
2291 $survey_loader_html = "<div data-class='lds-circle' data-role='loader' class='lds-circle ays-survey-wait-loading-loader'></div>";
2292 break;
2293 case 'dual_ring':
2294 $survey_loader_html = "<div data-class='lds-dual-ring' data-role='loader' class='lds-dual-ring ays-survey-wait-loading-loader'></div>";
2295 break;
2296 case 'facebook':
2297 $survey_loader_html = "<div data-class='lds-facebook' data-role='loader' class='lds-facebook ays-survey-wait-loading-loader'><div></div><div></div><div></div></div>";
2298 break;
2299 case 'hourglass':
2300 $survey_loader_html = "<div data-class='lds-hourglass' data-role='loader' class='lds-hourglass ays-survey-wait-loading-loader'></div>";
2301 break;
2302 case 'ripple':
2303 $survey_loader_html = "<div data-class='lds-ripple' data-role='loader' class='lds-ripple ays-survey-wait-loading-loader'><div></div><div></div></div>";
2304 break;
2305 case 'snake':
2306 $survey_loader_html = '<div class="ays-survey-loader-snake ays-survey-wait-loading-loader" data-class="ays-survey-loader-snake" data-role="loader"><div></div><div></div><div></div><div></div><div></div><div></div></div>';
2307 break;
2308 // case 'text':
2309 // $survey_loader_html = '<div class="ays-survey-loader ays-survey-loader-with-text '.$custom_class.'" data-class="ays-survey-loader-text" data-role="loader">'.$text.'</div>';
2310 // break;
2311 // case 'custom_gif':
2312 // $survey_loader_html = '<div class="ays-survey-loader ays-survey-loader-with-custom-gif '.$custom_class.'" data-class="ays-survey-loader-cistom-gif" data-role="loader"><img src="'.$gif.'" '.$loading.' style="width: '.$gif_width.'px;object-fit:cover;"></div>';
2313 // break;
2314 default:
2315 $survey_loader_html = "<div data-class='lds-ellipsis' data-role='loader' class='lds-ellipsis ays-survey-wait-loading-loader'><div></div><div></div><div></div><div></div></div>";
2316 break;
2317 }
2318 return $survey_loader_html;
2319 }
2320
2321 public static function ays_set_survey_message_variables_data( $id, $survey, $settings_options ){
2322
2323 /*
2324 * Survey message variables for Start Page
2325 */
2326
2327 $survey = (array)$survey;
2328
2329 // Survey options
2330 $options = ( json_decode($survey['options'], true) != null ) ? json_decode($survey['options'], true) : array();
2331
2332 // General Setting's Options
2333
2334 // Do not store IP adressess
2335 $disable_user_ip = (isset($settings_options['disable_user_ip']) && $settings_options['disable_user_ip'] == 'on') ? true : false;
2336
2337 // Survey title
2338 $survey_title = (isset( $survey['title'] ) && $survey['title'] != "") ? stripslashes( sanitize_text_field($survey['title']) ) : "";
2339
2340 // Survey create date
2341 $survey_creation_date = (isset($survey['date_created']) && $survey['date_created'] != '') ? sanitize_text_field( $survey['date_created'] ) : "";
2342 if( $survey_creation_date != "" ){
2343 $survey_creation_date = date_i18n( get_option( 'date_format' ), strtotime( $survey_creation_date ) );
2344 }
2345
2346 // Survey modified date
2347 $survey_modified_date = (isset($survey['date_modified']) && $survey['date_modified'] != '') ? sanitize_text_field( $survey['date_modified'] ) : "";
2348 if( $survey_modified_date != "" ){
2349 $survey_modified_date = date_i18n( get_option( 'date_format' ), strtotime( $survey_modified_date ) );
2350 }
2351
2352 // Current time
2353 $survey_current_time = explode( ' ', current_time( 'mysql' ) );
2354 $survey_current_time_only = ($survey_current_time[1]) ? $survey_current_time[1] : '';
2355
2356 // Get survey author
2357 $current_survey_user_data = get_userdata( $survey['author_id'] );
2358 $current_survey_author = '';
2359 $current_survey_author_email = '';
2360 if ( isset( $current_survey_user_data ) && $current_survey_user_data ) {
2361 // Get survey author name
2362 $current_survey_author = ( isset( $current_survey_user_data->data->display_name ) && $current_survey_user_data->data->display_name != '' ) ? sanitize_text_field( $current_survey_user_data->data->display_name ) : "";
2363 // Get survey author email
2364 $current_survey_author_email = ( isset( $current_survey_user_data->data->user_email ) && $current_survey_user_data->data->user_email != '' ) ? sanitize_text_field( $current_survey_user_data->data->user_email ) : "";
2365 }
2366
2367 $questions_count = (isset( $survey['questions_count'] ) && $survey['questions_count'] != "") ? stripslashes( sanitize_text_field($survey['questions_count']) ) : 0;
2368
2369 $survey_question_count = self::get_survey_questions_count($id);
2370 $survey_sections_count = self::get_survey_sections_count($id);
2371 $survey_passed_users_count = self::ays_survey_get_passed_users_count($id);
2372
2373 // WP home page url
2374 $home_main_url = home_url();
2375 $wp_home_page_url = '<a href="'.$home_main_url.'" target="_blank">'.$home_main_url.'</a>';
2376
2377 $survey_user_information = self::get_user_profile_data();
2378 // Get user first name
2379 $user_first_name = (isset( $survey_user_information['user_first_name'] ) && $survey_user_information['user_first_name'] != "") ? $survey_user_information['user_first_name'] : '';
2380
2381 // Get user last name
2382 $user_last_name = (isset( $survey_user_information['user_last_name'] ) && $survey_user_information['user_last_name'] != "") ? $survey_user_information['user_last_name'] : '';
2383
2384 // Get user nick name
2385 $user_nick_name = (isset( $survey_user_information['user_nickname'] ) && $survey_user_information['user_nickname'] != "") ? $survey_user_information['user_nickname'] : '';
2386
2387 // Get display name
2388 $user_display_name = (isset( $survey_user_information['user_display_name'] ) && $survey_user_information['user_display_name'] != "") ? $survey_user_information['user_display_name'] : '';
2389
2390 // User Wordpress role
2391 $user_wordpress_roles = (isset( $survey_user_information['user_wordpress_roles'] ) && $survey_user_information['user_wordpress_roles'] != "") ? $survey_user_information['user_wordpress_roles'] : '';
2392
2393 // User ip address
2394 $user_ip_address = "";
2395 if($disable_user_ip){
2396 $user_ip_address = '';
2397 }else{
2398 $user_ip_address = self::get_user_ip();
2399 }
2400
2401 // User wordpress email
2402 $user_wordpress_email = (isset( $survey_user_information['user_wordpress_email'] ) && $survey_user_information['user_wordpress_email'] != "") ? esc_attr($survey_user_information['user_wordpress_email']) : '';
2403
2404 $super_admin_email = get_option('admin_email');
2405
2406 $message_data = array(
2407 'survey_title' => $survey_title,
2408 'survey_id' => $id,
2409 'questions_count' => $questions_count,
2410 'current_time' => $survey_current_time_only,
2411 'sections_count' => $survey_sections_count,
2412 'users_count' => $survey_passed_users_count,
2413 'users_first_name' => $user_first_name,
2414 'users_last_name' => $user_last_name,
2415 'users_nick_name' => $user_nick_name,
2416 'users_display_name' => $user_display_name,
2417 'users_ip_address' => $user_ip_address,
2418 'user_wordpress_roles' => $user_wordpress_roles,
2419 'creation_date' => $survey_creation_date,
2420 'modified_date' => $survey_modified_date,
2421 'current_survey_author' => $current_survey_author,
2422 'current_survey_author_email' => $current_survey_author_email,
2423 'current_survey_page_link' => $current_survey_author_email,
2424 'admin_email' => $super_admin_email,
2425 'home_page_url' => $wp_home_page_url,
2426 );
2427
2428 return $message_data;
2429 }
2430
2431 public static function survey_sanitize_specific_content($content) {
2432 // Pattern to match <script> tags, dangerous attributes, and potential SVG exploits
2433 $pattern = '/<script.*?>.*?<\/script>|<[^>]+(?:\bon\w+\s*=\s*|attributeName\s*=\s*[^>]*>)/is';
2434
2435 // Callback function to convert matched tags into text
2436 $callback = function($matches) {
2437 // Convert characters to their HTML entities to render them as text
2438 return htmlspecialchars($matches[0], ENT_QUOTES, 'UTF-8');
2439 };
2440
2441 // Replace the matched patterns with their sanitized text equivalent
2442 $sanitized_content = preg_replace_callback($pattern, $callback, $content);
2443
2444 return $sanitized_content;
2445 }
2446
2447 // Sanitize data by admin level
2448 public static function admin_level_sanitize($data) {
2449
2450 if (is_multisite() && is_super_admin()) {
2451 return stripslashes($data);
2452
2453 } elseif (!is_multisite() && current_user_can('unfiltered_html')) {
2454 return stripslashes($data);
2455
2456 }
2457 return wp_kses_post($data);
2458
2459
2460 }
2461
2462 public static function get_allowed_tags_for_loader() {
2463 return array(
2464 'span' => array('class' => array()),
2465 'img' => array('src' => array(), 'alt' => array()),
2466 );
2467 }
2468
2469 public static function ays_survey_allowed_html() {
2470 $additionalAllowedTags = wp_kses_allowed_html('post');
2471 return array_merge(
2472 $additionalAllowedTags,
2473 array(
2474 'div' => array(
2475 'class' => true,
2476 'id' => true,
2477 'style' => true,
2478 'data-*' => true,
2479 'aria-selected' => true,
2480 ),
2481 'svg' => array(
2482 'class' => true,
2483 'width' => true,
2484 'height' => true,
2485 'viewBox' => true,
2486 'viewbox' => true,
2487 'xmlns' => true,
2488 'fill' => true,
2489 ),
2490 'path' => array(
2491 'class' => true,
2492 'd' => true,
2493 'fill' => true,
2494 'fill-rule' => true,
2495 'clip-rule' => true,
2496 'stroke-width' => true,
2497 'stroke-linecap' => true,
2498 ),
2499 'circle' => array(
2500 'style' => true,
2501 'id' => true,
2502 'class' => true,
2503 'r' => true,
2504 'cx' => true,
2505 'cy' => true,
2506 ),
2507 'rect' => array(
2508 'class' => true,
2509 'x' => true,
2510 'y' => true,
2511 'width' => true,
2512 'height' => true,
2513 'rx' => true,
2514 'fill' => true,
2515 'stroke' => true,
2516 'style' => true,
2517 'transform' => true,
2518 ),
2519 'defs' => array(
2520 'class' => true,
2521 'width' => true,
2522 'height' => true,
2523 'fill' => true,
2524 'style' => true,
2525 ),
2526 'pattern' => array(
2527 'class' => true,
2528 'id' => true,
2529 'width' => true,
2530 'height' => true,
2531 'patternContentUnits' => true,
2532 'patterncontentunits' => true,
2533 'style' => true,
2534 ),
2535 'use' => array(
2536 'class' => true,
2537 'id' => true,
2538 'xlink' => true,
2539 'xlink:href' => true,
2540 'transform' => true,
2541 'style' => true,
2542 ),
2543 'image' => array(
2544 'class' => true,
2545 'id' => true,
2546 'xlink' => true,
2547 'xlink:href' => true,
2548 'width' => true,
2549 'height' => true,
2550 'style' => true,
2551 ),
2552 'video' => array(
2553 'class' => true,
2554 'id' => true,
2555 'controls' => true,
2556 'style' => true,
2557 ),
2558 'source' => array(
2559 'class' => true,
2560 'id' => true,
2561 'src' => true,
2562 'style' => true,
2563 ),
2564 'form' => array(
2565 'name' => true,
2566 'id' => true,
2567 'action' => true,
2568 'method' => true,
2569 'data-*' => true,
2570 'style' => true,
2571 ),
2572 'input' => array(
2573 'id' => true,
2574 'name' => true,
2575 'class' => true,
2576 'type' => true,
2577 'value' => true,
2578 'size' => true,
2579 'required' => true,
2580 'readonly' => true,
2581 'data-*' => true,
2582 'style' => true,
2583 ),
2584 'select' => array(
2585 'id' => true,
2586 'name' => true,
2587 'class' => true,
2588 'type' => true,
2589 'value' => true,
2590 'size' => true,
2591 'required' => true,
2592 'readonly' => true,
2593 'data-*' => true,
2594 'style' => true,
2595 ),
2596 'option' => array(
2597 'id' => true,
2598 'class' => true,
2599 'type' => true,
2600 'value' => true,
2601 'size' => true,
2602 'required' => true,
2603 'readonly' => true,
2604 'data-*' => true,
2605 'style' => true,
2606 ),
2607 'progress' => array(
2608 'id' => true,
2609 'class' => true,
2610 'max' => true,
2611 'value' => true,
2612 'data-*' => true,
2613 'style' => true,
2614 ),
2615 'img' => array(
2616 'id' => true,
2617 'class' => true,
2618 'loading' => true,
2619 'decoding' => true,
2620 'src' => true,
2621 'sizes' => true,
2622 'srcset' => true,
2623 'width' => true,
2624 'height' => true,
2625 ),
2626 'a' => array(
2627 'aria-selected' => true,
2628 'data-*' => true,
2629 'style' => true,
2630 'target' => true,
2631 ),
2632 ),
2633 $additionalAllowedTags
2634 );
2635 }
2636
2637 public static function ays_survey_custom_allowed_html() {
2638 $additionalAllowedTags = self::ays_survey_allowed_html();
2639 return array_merge(
2640 $additionalAllowedTags,
2641 array(
2642 'iframe' => array(
2643 'class' => true,
2644 'id' => true,
2645 'width' => true,
2646 'height' => true,
2647 'src' => true,
2648 'title' => true,
2649 'frameborder' => true,
2650 'allow' => true,
2651 'allowfullscreen' => true,
2652 'loading' => true,
2653 'referrerpolicy' => true,
2654 'style' => true,
2655 ),
2656 'audio' => array(
2657 'class' => true,
2658 'id' => true,
2659 'controls' => true,
2660 'autoplay' => true,
2661 'loop' => true,
2662 'muted' => true,
2663 'preload' => true,
2664 'src' => true,
2665 'style' => true,
2666 ),
2667 'source' => array(
2668 'src' => true,
2669 'type' => true,
2670 ),
2671 'track' => array(
2672 'kind' => true,
2673 'src' => true,
2674 'srclang' => true,
2675 'label' => true,
2676 'default' => true,
2677 ),
2678 'video' => array(
2679 'class' => true,
2680 'id' => true,
2681 'width' => true,
2682 'height' => true,
2683 'controls' => true,
2684 'autoplay' => true,
2685 'loop' => true,
2686 'muted' => true,
2687 'poster' => true,
2688 'preload' => true,
2689 'src' => true,
2690 'style' => true,
2691 ),
2692 'picture' => array(
2693 'class' => true,
2694 'id' => true,
2695 ),
2696 'figure' => array(
2697 'class' => true,
2698 'id' => true,
2699 'style' => true,
2700 ),
2701 'figcaption' => array(
2702 'class' => true,
2703 'id' => true,
2704 'style' => true,
2705 ),
2706 ),
2707 $additionalAllowedTags
2708 );
2709 }
2710
2711 }
2712