PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.4
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.4
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / util_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year ago whatsapp_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
util_helper.php
504 lines
1 <?php
2
3 class OsUtilHelper {
4
5 public static function add_auto_print_script(){
6 wp_register_script('latepoint-auto-print', false);
7 wp_enqueue_script('latepoint-auto-print');
8 wp_add_inline_script('latepoint-auto-print', '
9 window.onload = function() {
10 window.print();
11 }
12 ');
13 }
14
15 public static function generate_missing_addon_link($label){
16 $html = '<a target="_blank" href="'.esc_url(LATEPOINT_UPGRADE_URL).'" class="os-add-box" >
17 <div class="add-box-graphic-w"><div class="add-box-plus"><i class="latepoint-icon latepoint-icon-plus4"></i></div></div>
18 <div class="add-box-label">'.esc_html($label).'</div>
19 </a>';
20 $html = apply_filters('latepoint_missing_addon_link', $html, $label);
21 return $html;
22 }
23
24 public static function extract_plugin_name_from_path(string $plugin_path) : string{
25 preg_match('/latepoint-([^-\/]+(?:-[^-\/]+)*)\//', $plugin_path, $matches);
26 if (isset($matches[1])) {
27 // Convert hyphenated words to capitalized words
28 $name = ucwords(str_replace('-', ' ', $matches[1]));
29 }else{
30 $name = 'n/a';
31 }
32 return $name;
33 }
34
35 public static function first_value_if_array($value){
36 if(!empty($value) && is_array($value) && isset($value[0])) return $value[0];
37 else return $value;
38 }
39
40 public static function get_array_of_ids_from_array_of_models(array $models): array{
41 $ids = [];
42 if($models){
43 foreach($models as $model){
44 if(property_exists($model, 'id')) $ids[] = $model->id;
45 }
46 }
47 return $ids;
48 }
49
50 /**
51 * Cleans array of ids and makes sure they are integers
52 *
53 * @param array $ids
54 * @return array
55 */
56 public static function clean_numeric_ids(array $ids): array{
57 $clean_ids = [];
58 if(!$ids) return $clean_ids;
59 foreach($ids as $id){
60 if(filter_var($id, FILTER_VALIDATE_INT)) $clean_ids[] = $id;
61 }
62 return $clean_ids;
63 }
64
65 public static function explode_and_trim($string){
66 return preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $string, -1, PREG_SPLIT_NO_EMPTY);
67 }
68
69 public static function replace_single_curly_with_double(string $string): string{
70 $string = preg_replace("/(?<!{){(?!{)/", "{{", $string);
71 $string = preg_replace("/(?<!})}(?!})/", "}}", $string);
72 return $string;
73 }
74
75 public static function compare_model_data_vars($new_data_vars, $old_data_vars, $parent = false){
76 $level = $parent ? [$parent] : [];
77 $changes = [];
78 foreach($new_data_vars as $key => $var){
79 // check if both empty (could be null and '', that doesn't mean its changed)
80 if(empty($old_data_vars[$key]) && empty($var)) continue;
81 if(!isset($old_data_vars[$key]) || $var != $old_data_vars[$key]) $changes[$key] = ['before' => $old_data_vars[$key] ?? '', 'after' => $var];
82 }
83 foreach($old_data_vars as $key => $var){
84 // check if both empty (could be null and '', that doesn't mean its changed)
85 if(empty($new_data_vars[$key]) && empty($var)) continue;
86 if(!isset($changes[$key]) && !isset($new_data_vars[$key]) || $var != $new_data_vars[$key]) $changes[$key] = ['before' => $var ?? '', 'after' => $new_data_vars[$key] ?? ''];
87 }
88 return $changes;
89 }
90
91 public static function ordered_column_html($order_by, $column){
92 if($order_by['column'] == $column) return ' class="ordered-'.$order_by['direction'].'"';
93 }
94
95 public static function generate_uuid(){
96 $data = openssl_random_pseudo_bytes(16);
97
98 $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
99 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
100
101 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
102 }
103
104 public static function get_site_url(){
105 return network_home_url();
106 }
107
108 public static function is_off($value){
109 return ($value != 'on');
110 }
111
112 public static function is_on($value){
113 return ($value == 'on');
114 }
115
116 public static function template_variables_link_html(){
117 return '<a href="#" class="field-note-info-link open-template-variables-panel"><i class="latepoint-icon latepoint-icon-info"></i><span>'.esc_html__('Show Available Variables', 'latepoint').'</span></a>';
118 }
119
120 public static function hex2rgba($color, $opacity = false) {
121 $default = 'rgb(0,0,0)';
122 if(empty($color))
123 return $default;
124
125 //Sanitize $color if "#" is provided
126 if ($color[0] == '#' ) {
127 $color = substr( $color, 1 );
128 }
129
130 //Check if color has 6 or 3 characters and get values
131 if (strlen($color) == 6) {
132 $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
133 } elseif ( strlen( $color ) == 3 ) {
134 $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
135 } else {
136 return $default;
137 }
138
139 //Convert hexadec to rgb
140 $rgb = array_map('hexdec', $hex);
141
142 //Check if opacity is set(rgba or rgb)
143 if($opacity){
144 if(abs($opacity) > 1)
145 $opacity = 1.0;
146 $output = 'rgba('.implode(",",$rgb).','.$opacity.')';
147 } else {
148 $output = 'rgb('.implode(",",$rgb).')';
149 }
150
151 //Return rgb(a) color string
152 return $output;
153 }
154
155 public static function percent_diff($before, $now){
156 if($before == $now) return 0;
157 $sign = ($before > $now) ? '-' : '+';
158 if($before > 0 && $now > 0){
159 if($before > $now){
160 return $sign.round(($before - $now) / $before * 100);
161 }else{
162 return $sign.round(($now - $before) / $before * 100);
163 }
164 }else{
165 return $sign.'100';
166 }
167 }
168
169
170 public static function get_weekday_numbers(){
171 return array(1,2,3,4,5,6,7);
172 }
173
174 public static function is_valid_email($email){
175 return filter_var($email, FILTER_VALIDATE_EMAIL);
176 }
177
178 public static function merge_default_atts($defaults = [], $settings = []){
179 return array_merge($defaults, array_intersect_key($settings, $defaults));
180 }
181
182 public static function random_text( $type = 'nozero', $length = 6 ): string{
183 switch ( $type ) {
184 case 'nozero':
185 $pool = '123456789';
186 break;
187 case 'alnum':
188 $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
189 break;
190 case 'alpha':
191 $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
192 break;
193 case 'hexdec':
194 $pool = '0123456789abcdef';
195 break;
196 case 'numeric':
197 $pool = '0123456789';
198 break;
199 case 'distinct':
200 $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
201 break;
202 default:
203 $pool = (string) $type;
204 break;
205 }
206
207
208 $crypto_rand_secure = function ( $min, $max ) {
209 $range = $max - $min;
210 if ( $range < 0 ) return $min; // not so random...
211 $log = log( $range, 2 );
212 $bytes = (int) ( $log / 8 ) + 1; // length in bytes
213 $bits = (int) $log + 1; // length in bits
214 $filter = (int) ( 1 << $bits ) - 1; // set all lower bits to 1
215 do {
216 $rnd = hexdec( bin2hex( openssl_random_pseudo_bytes( $bytes ) ) );
217 $rnd = $rnd & $filter; // discard irrelevant bits
218 } while ( $rnd >= $range );
219 return $min + $rnd;
220 };
221
222 $token = "";
223 $max = strlen( $pool );
224 for ( $i = 0; $i < $length; $i++ ) {
225 $token .= $pool[$crypto_rand_secure( 0, $max )];
226 }
227 return $token;
228 }
229
230 public static function ellipse_string( $string, $length ): string {
231 return substr( $string, 0, $length ) . ( strlen( $string ) > $length ? '...' : '' );
232 }
233
234 public static function get_month_name_by_number($month_number, $short = false){
235 $full_names = [__('January', 'latepoint'),
236 __('February', 'latepoint'),
237 __('March', 'latepoint'),
238 __('April', 'latepoint'),
239 __('May', 'latepoint'),
240 __('June', 'latepoint'),
241 __('July', 'latepoint'),
242 __('August', 'latepoint'),
243 __('September', 'latepoint'),
244 __('October', 'latepoint'),
245 __('November', 'latepoint'),
246 __('December', 'latepoint')];
247 $short_names = [__('Jan', 'latepoint'),
248 __('Feb', 'latepoint'),
249 __('Mar', 'latepoint'),
250 __('Apr', 'latepoint'),
251 _x('May', 'short version of May month', 'latepoint'),
252 __('Jun', 'latepoint'),
253 __('Jul', 'latepoint'),
254 __('Aug', 'latepoint'),
255 __('Sep', 'latepoint'),
256 __('Oct', 'latepoint'),
257 __('Nov', 'latepoint'),
258 __('Dec', 'latepoint')];
259
260 if(empty($month_number)) return '';
261 if($short){
262 $month_name = isset($short_names[$month_number - 1]) ? $short_names[$month_number - 1] : 'n/a';
263 }else{
264 $month_name = isset($full_names[$month_number - 1]) ? $full_names[$month_number - 1] : 'n/a';
265 }
266 return $month_name;
267 }
268
269
270 public static function translated_months(){
271 return [ 'January' => __('January', 'latepoint'),
272 'February' => __('February', 'latepoint'),
273 'March' => __('March', 'latepoint'),
274 'April' => __('April', 'latepoint'),
275 'May' => __('May', 'latepoint'),
276 'June' => __('June', 'latepoint'),
277 'July' => __('July', 'latepoint'),
278 'August' => __('August', 'latepoint'),
279 'September' => __('September', 'latepoint'),
280 'October' => __('October', 'latepoint'),
281 'November' => __('November', 'latepoint'),
282 'December' => __('December', 'latepoint'),
283 'Jan' => __('Jan', 'latepoint'),
284 'Feb' => __('Feb', 'latepoint'),
285 'Mar' => __('Mar', 'latepoint'),
286 'Apr' => __('Apr', 'latepoint'),
287 'Jun' => __('Jun', 'latepoint'),
288 'Jul' => __('Jul', 'latepoint'),
289 'Aug' => __('Aug', 'latepoint'),
290 'Sep' => __('Sep', 'latepoint'),
291 'Oct' => __('Oct', 'latepoint'),
292 'Nov' => __('Nov', 'latepoint'),
293 'Dec' => __('Dec', 'latepoint')];
294 }
295
296 public static function translate_months($date_string){
297 $date_string = str_replace(array_keys(self::translated_months()), array_values(self::translated_months()), $date_string);
298 return $date_string;
299 }
300
301 public static function get_months_for_select(){
302 $months = [];
303 for($i = 1; $i<= 12; $i++){
304 $months[] = ['label' => self::get_month_name_by_number($i), 'value' => $i];
305 }
306 return $months;
307 }
308
309 public static function get_weekday_name_by_number($weekday_number, $short = false){
310 $weekday_names = [__('Monday', 'latepoint'),
311 __('Tuesday', 'latepoint'),
312 __('Wednesday', 'latepoint'),
313 __('Thursday', 'latepoint'),
314 __('Friday', 'latepoint'),
315 __('Saturday', 'latepoint'),
316 __('Sunday', 'latepoint')];
317 $weekday_name = isset($weekday_names[$weekday_number - 1]) ? $weekday_names[$weekday_number - 1] : 'n/a';
318 if($short) $weekday_name = mb_substr($weekday_name, 0, 3);
319 return $weekday_name;
320 }
321
322 // Checks if array is associative
323 public static function is_array_a($array){
324 return count(array_filter(array_keys($array), 'is_string')) > 0;
325 }
326
327
328 public static function models_to_select_options(array $models, string $value_key, string $label_key): array{
329 if(empty($models)) return [];
330 $options = [];
331 foreach($models as $model){
332 if(method_exists($model, $label_key)){
333 $label = call_user_func_array([$model, $label_key], []);
334 }elseif(property_exists($model, $label_key)){
335 $label = $model->$label_key;
336 }
337 if(method_exists($model, $value_key)){
338 $value = call_user_func_array([$model, $value_key], []);
339 }elseif(property_exists($model, $value_key)){
340 $value = $model->$value_key;
341 }
342 if(isset($label) && isset($value)){
343 $options[] = ['value' => $value, 'label' => $label];
344 }
345 unset($value);
346 unset($label);
347 }
348 return $options;
349 }
350
351
352 public static function array_to_select_options(array $array, string $value_key, string $label_key): array{
353 if(empty($array)) return [];
354 $options = [];
355 foreach($array as $item){
356 if(isset($item[$value_key]) && isset($item[$label_key])) $options[$item[$value_key]] = $item[$label_key];
357 }
358 return $options;
359 }
360
361 public static function transform_flat_list_for_multi_select( array $flat_list ): array {
362 $result_list = [];
363
364 foreach ( $flat_list as $key => $value ) {
365 $result_list[] = [
366 'value' => $key,
367 'label' => $value
368 ];
369 }
370
371 return $result_list;
372 }
373
374
375 /**
376 *
377 * Returns phone number in format +18888888888, strips all none plus characters and digits, prepends country code if provided
378 *
379 * @param string $number
380 * @param string $country_code
381 * @return string
382 */
383 public static function sanitize_phone_number(string $number, string $country_code = ''): string{
384 if(empty($number)) return '';
385 $add_country_code = (substr($number, 0, 1) == '+') ? '+' : $country_code; // figure out if country code is missing
386 if(stripos($number, 'x') !== false) $number = substr($number, 0, stripos($number, 'x')); // strip extension
387
388 $formatted_phone = preg_replace('/[^\d]/', '', $number);
389 if(!empty($formatted_phone)){
390 return $add_country_code.$formatted_phone;
391 }else{
392 return '';
393 }
394 }
395
396 public static function get_countries_list(): array {
397 return [ "us" => "United States", "af" => "Afghanistan", "al" => "Albania", "dz" => "Algeria", "as" => "American Samoa", "ad" => "Andorra", "ao" => "Angola", "ai" => "Anguilla", "ag" => "Antigua and Barbuda", "ar" => "Argentina", "am" => "Armenia (Հայաստան)", "aw" => "Aruba", "ac" => "Ascension Island", "au" => "Australia", "at" => "Austria (Österreich)", "az" => "Azerbaijan (Azərbaycan)", "bs" => "Bahamas", "bh" => "Bahrain (‫البحرين‬‎)", "bd" => "Bangladesh (বাংলাদেশ)", "bb" => "Barbados", "by" => "Belarus (Беларусь)", "be" => "Belgium (België)", "bz" => "Belize", "bj" => "Benin (Bénin)", "bm" => "Bermuda", "bt" => "Bhutan (འབྲུག)", "bo" => "Bolivia", "ba" => "Bosnia and Herzegovina (Босна и Херцеговина)", "bw" => "Botswana", "br" => "Brazil (Brasil)", "io" => "British Indian Ocean Territory", "vg" => "British Virgin Islands", "bn" => "Brunei", "bg" => "Bulgaria (България)", "bf" => "Burkina Faso", "bi" => "Burundi (Uburundi)", "kh" => "Cambodia (កម្ពុជា)", "cm" => "Cameroon (Cameroun)", "ca" => "Canada", "cv" => "Cape Verde (Kabu Verdi)", "bq" => "Caribbean Netherlands", "ky" => "Cayman Islands", "cf" => "Central African Republic (République centrafricaine)", "td" => "Chad (Tchad)", "cl" => "Chile", "cn" => "China (中国)", "cx" => "Christmas Island", "cc" => "Cocos (Keeling) Islands", "co" => "Colombia", "km" => "Comoros (‫جزر الق�
398 ر‬‎)", "cd" => "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cg" => "Congo (Republic) (Congo-Brazzaville)", "ck" => "Cook Islands", "cr" => "Costa Rica", "ci" => "Côte d’Ivoire", "hr" => "Croatia (Hrvatska)", "cu" => "Cuba", "cw" => "Curaçao", "cy" => "Cyprus (Κύπρος)", "cz" => "Czech Republic (Česká republika)", "dk" => "Denmark (Danmark)", "dj" => "Djibouti", "dm" => "Dominica", "do" => "Dominican Republic (República Dominicana)", "ec" => "Ecuador", "eg" => "Egypt (‫�
399 صر‬‎)", "sv" => "El Salvador", "gq" => "Equatorial Guinea (Guinea Ecuatorial)", "er" => "Eritrea", "ee" => "Estonia (Eesti)", "sz" => "Eswatini", "et" => "Ethiopia", "fk" => "Falkland Islands (Islas Malvinas)", "fo" => "Faroe Islands (Føroyar)", "fj" => "Fiji", "fi" => "Finland (Suomi)", "fr" => "France", "gf" => "French Guiana (Guyane française)", "pf" => "French Polynesia (Polynésie française)", "ga" => "Gabon", "gm" => "Gambia", "ge" => "Georgia (საქართველო)", "de" => "Germany (Deutschland)", "gh" => "Ghana (Gaana)", "gi" => "Gibraltar", "gr" => "Greece (Ελλάδα)", "gl" => "Greenland (Kalaallit Nunaat)", "gd" => "Grenada", "gp" => "Guadeloupe", "gu" => "Guam", "gt" => "Guatemala", "gg" => "Guernsey", "gn" => "Guinea (Guinée)", "gw" => "Guinea-Bissau (Guiné Bissau)", "gy" => "Guyana", "ht" => "Haiti", "hn" => "Honduras", "hk" => "Hong Kong (香港)", "hu" => "Hungary (Magyarország)", "is" => "Iceland (Ísland)", "in" => "India (भारत)", "id" => "Indonesia", "ir" => "Iran (‫ایران‬‎)", "iq" => "Iraq (‫العراق‬‎)", "ie" => "Ireland", "im" => "Isle of Man", "il" => "Israel (‫ישראל‬‎)", "it" => "Italy (Italia)", "jm" => "Jamaica", "jp" => "Japan (日本)", "je" => "Jersey", "jo" => "Jordan (‫الأردن‬‎)", "kz" => "Kazakhstan (Каза�
400 стан)", "ke" => "Kenya", "ki" => "Kiribati", "xk" => "Kosovo", "kw" => "Kuwait (‫الكويت‬‎)", "kg" => "Kyrgyzstan (Кыргызстан)", "la" => "Laos (ລາວ)", "lv" => "Latvia (Latvija)", "lb" => "Lebanon (‫لبنان‬‎)", "ls" => "Lesotho", "lr" => "Liberia", "ly" => "Libya (‫ليبيا‬‎)", "li" => "Liechtenstein", "lt" => "Lithuania (Lietuva)", "lu" => "Luxembourg", "mo" => "Macau (澳門)", "mk" => "North Macedonia (Македонија)", "mg" => "Madagascar (Madagasikara)", "mw" => "Malawi", "my" => "Malaysia", "mv" => "Maldives", "ml" => "Mali", "mt" => "Malta", "mh" => "Marshall Islands", "mq" => "Martinique", "mr" => "Mauritania (‫�
401 وريتانيا‬‎)", "mu" => "Mauritius (Moris)", "yt" => "Mayotte", "mx" => "Mexico (México)", "fm" => "Micronesia", "md" => "Moldova (Republica Moldova)", "mc" => "Monaco", "mn" => "Mongolia (Монгол)", "me" => "Montenegro (Crna Gora)", "ms" => "Montserrat", "ma" => "Morocco (‫ال�
402 غرب‬‎)", "mz" => "Mozambique (Moçambique)", "mm" => "Myanmar (Burma) (မြန်မာ)", "na" => "Namibia (Namibië)", "nr" => "Nauru", "np" => "Nepal (नेपाल)", "nl" => "Netherlands (Nederland)", "nc" => "New Caledonia (Nouvelle-Calédonie)", "nz" => "New Zealand", "ni" => "Nicaragua", "ne" => "Niger (Nijar)", "ng" => "Nigeria", "nu" => "Niue", "nf" => "Norfolk Island", "kp" => "North Korea (조선 민주주의 인민 공화국)", "mp" => "Northern Mariana Islands", "no" => "Norway (Norge)", "om" => "Oman (‫عُ�
403 ان‬‎)", "pk" => "Pakistan (‫پاکستان‬‎)", "pw" => "Palau", "ps" => "Palestine (‫فلسطين‬‎)", "pa" => "Panama (Panamá)", "pg" => "Papua New Guinea", "py" => "Paraguay", "pe" => "Peru (Perú)", "ph" => "Philippines", "pl" => "Poland (Polska)", "pt" => "Portugal", "pr" => "Puerto Rico", "qa" => "Qatar (‫قطر‬‎)", "re" => "Réunion (La Réunion)", "ro" => "Romania (România)", "ru" => "Russia (Россия)", "rw" => "Rwanda", "bl" => "Saint Barthélemy", "sh" => "Saint Helena", "kn" => "Saint Kitts and Nevis", "lc" => "Saint Lucia", "mf" => "Saint Martin (Saint-Martin (partie française))", "pm" => "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "vc" => "Saint Vincent and the Grenadines", "ws" => "Samoa", "sm" => "San Marino", "st" => "São Tomé and Príncipe (São Tomé e Príncipe)", "sa" => "Saudi Arabia (‫ال�
404
405 لكة العربية السعودية‬‎)", "sn" => "Senegal (Sénégal)", "rs" => "Serbia (Србија)", "sc" => "Seychelles", "sl" => "Sierra Leone", "sg" => "Singapore", "sx" => "Sint Maarten", "sk" => "Slovakia (Slovensko)", "si" => "Slovenia (Slovenija)", "sb" => "Solomon Islands", "so" => "Somalia (Soomaaliya)", "za" => "South Africa", "kr" => "South Korea (대한민국)", "ss" => "South Sudan (‫جنوب السودان‬‎)", "es" => "Spain (España)", "lk" => "Sri Lanka (ශ්‍රී ලංකාව)", "sd" => "Sudan (‫السودان‬‎)", "sr" => "Suriname", "sj" => "Svalbard and Jan Mayen", "se" => "Sweden (Sverige)", "ch" => "Switzerland (Schweiz)", "sy" => "Syria (‫سوريا‬‎)", "tw" => "Taiwan (台灣)", "tj" => "Tajikistan", "tz" => "Tanzania", "th" => "Thailand (ไทย)", "tl" => "Timor-Leste", "tg" => "Togo", "tk" => "Tokelau", "to" => "Tonga", "tt" => "Trinidad and Tobago", "tn" => "Tunisia (‫تونس‬‎)", "tr" => "Turkey (Türkiye)", "tm" => "Turkmenistan", "tc" => "Turks and Caicos Islands", "tv" => "Tuvalu", "vi" => "U.S. Virgin Islands", "ug" => "Uganda", "ua" => "Ukraine (Україна)", "ae" => "United Arab Emirates (‫الإ�
406 ارات العربية ال�
407 تحدة‬‎)", "gb" => "United Kingdom", "uy" => "Uruguay", "uz" => "Uzbekistan (Oʻzbekiston)", "vu" => "Vanuatu", "va" => "Vatican City (Città del Vaticano)", "ve" => "Venezuela", "vn" => "Vietnam (Việt Nam)", "wf" => "Wallis and Futuna (Wallis-et-Futuna)", "eh" => "Western Sahara (‫الصحراء الغربية‬‎)", "ye" => "Yemen (‫الي�
408 ن‬‎)", "zm" => "Zambia", "zw" => "Zimbabwe", "ax" => "�
409 land Islands", ];
410 }
411
412 public static function is_date_valid($date_string){
413 return (bool)strtotime($date_string);
414 }
415
416 public static function build_os_params($params = array(), string $nonce_action = ''){
417 if(!empty($nonce_action)){
418 $params['_wpnonce'] = wp_create_nonce($nonce_action);
419 }
420 return http_build_query($params);
421 }
422
423
424 public static function get_user_ip() : string{
425 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ){
426 $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP']));
427 }elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
428 $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR']));
429 }else{
430 $ip = sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'] ?? ''));
431 }
432
433 // Sanitize the IP address
434 $ip = filter_var( $ip, FILTER_VALIDATE_IP );
435
436 if ( $ip === false ) {
437 // Handle invalid IP case
438 $ip = 'n/a';
439 }
440
441 return $ip;
442 }
443
444 public static function create_nonce($string = ''){
445 return wp_create_nonce( 'latepoint_'.$string );
446 }
447
448 public static function verify_nonce($nonce, $string = ''){
449 return wp_verify_nonce( $nonce, 'latepoint_'.$string );
450 }
451
452 public static function obfuscate_license(string $license_key): string {
453 return preg_replace_callback('/-(.*)/', function($matches) {
454 return '-' . str_repeat('*', strlen($matches[1]));
455 }, $license_key);
456 }
457
458 public static function generate_form_id(): string {
459 return 'new_'.self::random_text();
460 }
461
462 public static function pro_feature_block(string $label = '', string $label_code = '') : string {
463 $label = !empty($label) ? $label : __('Requires upgrade to a premium version', 'latepoint');
464 $html = '<a href="'.esc_url(LATEPOINT_UPGRADE_URL).'" class="os-add-box" >
465 <div class="add-box-graphic-w"><div class="add-box-plus"><i class="latepoint-icon latepoint-icon-plus4"></i></div></div>
466 <div class="add-box-label">'.esc_html($label).'</div>
467 </a>';
468 /**
469 * PRO Features block
470 *
471 * @since 5.1.2
472 * @hook latepoint_pro_feature_block_html
473 *
474 * @param {string} $html html of a block
475 * @param {string} $label label that goes inside
476 * @param {string} $label_code code used to determine where the block is shown
477 * @returns {string} The filtered html of a block
478 */
479 return apply_filters('latepoint_pro_feature_block_html', $html, $label, $label_code);
480 }
481
482 public static function generate_key_to_manage() : string {
483 return bin2hex( random_bytes( 18 ) );
484 }
485
486 public static function get_color_for_variable_by_index($index) : string {
487 $colors = self::get_colors_for_variables();
488 return $colors[$index] ?? '#eee';
489 }
490
491 public static function get_colors_for_variables() : array {
492 $colors = [ '#b6ffc8', '#ffbbbb', '#cbc5ff', '#ffe2a3', '#ffbfe2', '#6dffe3', '#abe4ff', '#eee' ];
493 /**
494 * Generate colors to be used for variables
495 *
496 * @since 5.1.3
497 * @hook latepoint_get_colors_for_variables
498 *
499 * @param {array} $colors array of colors
500 * @returns {array} The filtered array of colors
501 */
502 return apply_filters('latepoint_get_colors_for_variables', $colors);
503 }
504 }