PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.6
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
512 lines
1 <?php
2
3 class OsUtilHelper {
4
5 public static function get_referrer(){
6 if(!empty($_SERVER['HTTP_REFERER'])){
7 return $_SERVER['HTTP_REFERER'];
8 }else{
9 return wp_get_original_referer() || '';
10 }
11 }
12
13 public static function add_auto_print_script(){
14 wp_register_script('latepoint-auto-print', false);
15 wp_enqueue_script('latepoint-auto-print');
16 wp_add_inline_script('latepoint-auto-print', '
17 window.onload = function() {
18 window.print();
19 }
20 ');
21 }
22
23 public static function generate_missing_addon_link($label){
24 $html = '<a target="_blank" href="'.esc_url(LATEPOINT_UPGRADE_URL).'" class="os-add-box" >
25 <div class="add-box-graphic-w"><div class="add-box-plus"><i class="latepoint-icon latepoint-icon-plus4"></i></div></div>
26 <div class="add-box-label">'.esc_html($label).'</div>
27 </a>';
28 $html = apply_filters('latepoint_missing_addon_link', $html, $label);
29 return $html;
30 }
31
32 public static function extract_plugin_name_from_path(string $plugin_path) : string{
33 preg_match('/latepoint-([^-\/]+(?:-[^-\/]+)*)\//', $plugin_path, $matches);
34 if (isset($matches[1])) {
35 // Convert hyphenated words to capitalized words
36 $name = ucwords(str_replace('-', ' ', $matches[1]));
37 }else{
38 $name = 'n/a';
39 }
40 return $name;
41 }
42
43 public static function first_value_if_array($value){
44 if(!empty($value) && is_array($value) && isset($value[0])) return $value[0];
45 else return $value;
46 }
47
48 public static function get_array_of_ids_from_array_of_models(array $models): array{
49 $ids = [];
50 if($models){
51 foreach($models as $model){
52 if(property_exists($model, 'id')) $ids[] = $model->id;
53 }
54 }
55 return $ids;
56 }
57
58 /**
59 * Cleans array of ids and makes sure they are integers
60 *
61 * @param array $ids
62 * @return array
63 */
64 public static function clean_numeric_ids(array $ids): array{
65 $clean_ids = [];
66 if(!$ids) return $clean_ids;
67 foreach($ids as $id){
68 if(filter_var($id, FILTER_VALIDATE_INT)) $clean_ids[] = $id;
69 }
70 return $clean_ids;
71 }
72
73 public static function explode_and_trim($string){
74 return preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $string, -1, PREG_SPLIT_NO_EMPTY);
75 }
76
77 public static function replace_single_curly_with_double(string $string): string{
78 $string = preg_replace("/(?<!{){(?!{)/", "{{", $string);
79 $string = preg_replace("/(?<!})}(?!})/", "}}", $string);
80 return $string;
81 }
82
83 public static function compare_model_data_vars($new_data_vars, $old_data_vars, $parent = false){
84 $level = $parent ? [$parent] : [];
85 $changes = [];
86 foreach($new_data_vars as $key => $var){
87 // check if both empty (could be null and '', that doesn't mean its changed)
88 if(empty($old_data_vars[$key]) && empty($var)) continue;
89 if(!isset($old_data_vars[$key]) || $var != $old_data_vars[$key]) $changes[$key] = ['before' => $old_data_vars[$key] ?? '', 'after' => $var];
90 }
91 foreach($old_data_vars as $key => $var){
92 // check if both empty (could be null and '', that doesn't mean its changed)
93 if(empty($new_data_vars[$key]) && empty($var)) continue;
94 if(!isset($changes[$key]) && !isset($new_data_vars[$key]) || $var != $new_data_vars[$key]) $changes[$key] = ['before' => $var ?? '', 'after' => $new_data_vars[$key] ?? ''];
95 }
96 return $changes;
97 }
98
99 public static function ordered_column_html($order_by, $column){
100 if($order_by['column'] == $column) return ' class="ordered-'.$order_by['direction'].'"';
101 }
102
103 public static function generate_uuid(){
104 $data = openssl_random_pseudo_bytes(16);
105
106 $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
107 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
108
109 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
110 }
111
112 public static function get_site_url(){
113 return network_home_url();
114 }
115
116 public static function is_off($value){
117 return ($value != 'on');
118 }
119
120 public static function is_on($value){
121 return ($value == 'on');
122 }
123
124 public static function template_variables_link_html(){
125 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>';
126 }
127
128 public static function hex2rgba($color, $opacity = false) {
129 $default = 'rgb(0,0,0)';
130 if(empty($color))
131 return $default;
132
133 //Sanitize $color if "#" is provided
134 if ($color[0] == '#' ) {
135 $color = substr( $color, 1 );
136 }
137
138 //Check if color has 6 or 3 characters and get values
139 if (strlen($color) == 6) {
140 $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
141 } elseif ( strlen( $color ) == 3 ) {
142 $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
143 } else {
144 return $default;
145 }
146
147 //Convert hexadec to rgb
148 $rgb = array_map('hexdec', $hex);
149
150 //Check if opacity is set(rgba or rgb)
151 if($opacity){
152 if(abs($opacity) > 1)
153 $opacity = 1.0;
154 $output = 'rgba('.implode(",",$rgb).','.$opacity.')';
155 } else {
156 $output = 'rgb('.implode(",",$rgb).')';
157 }
158
159 //Return rgb(a) color string
160 return $output;
161 }
162
163 public static function percent_diff($before, $now){
164 if($before == $now) return 0;
165 $sign = ($before > $now) ? '-' : '+';
166 if($before > 0 && $now > 0){
167 if($before > $now){
168 return $sign.round(($before - $now) / $before * 100);
169 }else{
170 return $sign.round(($now - $before) / $before * 100);
171 }
172 }else{
173 return $sign.'100';
174 }
175 }
176
177
178 public static function get_weekday_numbers(){
179 return array(1,2,3,4,5,6,7);
180 }
181
182 public static function is_valid_email($email){
183 return filter_var($email, FILTER_VALIDATE_EMAIL);
184 }
185
186 public static function merge_default_atts($defaults = [], $settings = []){
187 return array_merge($defaults, array_intersect_key($settings, $defaults));
188 }
189
190 public static function random_text( $type = 'nozero', $length = 6 ): string{
191 switch ( $type ) {
192 case 'nozero':
193 $pool = '123456789';
194 break;
195 case 'alnum':
196 $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
197 break;
198 case 'alpha':
199 $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
200 break;
201 case 'hexdec':
202 $pool = '0123456789abcdef';
203 break;
204 case 'numeric':
205 $pool = '0123456789';
206 break;
207 case 'distinct':
208 $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
209 break;
210 default:
211 $pool = (string) $type;
212 break;
213 }
214
215
216 $crypto_rand_secure = function ( $min, $max ) {
217 $range = $max - $min;
218 if ( $range < 0 ) return $min; // not so random...
219 $log = log( $range, 2 );
220 $bytes = (int) ( $log / 8 ) + 1; // length in bytes
221 $bits = (int) $log + 1; // length in bits
222 $filter = (int) ( 1 << $bits ) - 1; // set all lower bits to 1
223 do {
224 $rnd = hexdec( bin2hex( openssl_random_pseudo_bytes( $bytes ) ) );
225 $rnd = $rnd & $filter; // discard irrelevant bits
226 } while ( $rnd >= $range );
227 return $min + $rnd;
228 };
229
230 $token = "";
231 $max = strlen( $pool );
232 for ( $i = 0; $i < $length; $i++ ) {
233 $token .= $pool[$crypto_rand_secure( 0, $max )];
234 }
235 return $token;
236 }
237
238 public static function ellipse_string( $string, $length ): string {
239 return substr( $string, 0, $length ) . ( strlen( $string ) > $length ? '...' : '' );
240 }
241
242 public static function get_month_name_by_number($month_number, $short = false){
243 $full_names = [__('January', 'latepoint'),
244 __('February', 'latepoint'),
245 __('March', 'latepoint'),
246 __('April', 'latepoint'),
247 __('May', 'latepoint'),
248 __('June', 'latepoint'),
249 __('July', 'latepoint'),
250 __('August', 'latepoint'),
251 __('September', 'latepoint'),
252 __('October', 'latepoint'),
253 __('November', 'latepoint'),
254 __('December', 'latepoint')];
255 $short_names = [__('Jan', 'latepoint'),
256 __('Feb', 'latepoint'),
257 __('Mar', 'latepoint'),
258 __('Apr', 'latepoint'),
259 _x('May', 'short version of May month', 'latepoint'),
260 __('Jun', 'latepoint'),
261 __('Jul', 'latepoint'),
262 __('Aug', 'latepoint'),
263 __('Sep', 'latepoint'),
264 __('Oct', 'latepoint'),
265 __('Nov', 'latepoint'),
266 __('Dec', 'latepoint')];
267
268 if(empty($month_number)) return '';
269 if($short){
270 $month_name = isset($short_names[$month_number - 1]) ? $short_names[$month_number - 1] : 'n/a';
271 }else{
272 $month_name = isset($full_names[$month_number - 1]) ? $full_names[$month_number - 1] : 'n/a';
273 }
274 return $month_name;
275 }
276
277
278 public static function translated_months(){
279 return [ 'January' => __('January', 'latepoint'),
280 'February' => __('February', 'latepoint'),
281 'March' => __('March', 'latepoint'),
282 'April' => __('April', 'latepoint'),
283 'May' => __('May', 'latepoint'),
284 'June' => __('June', 'latepoint'),
285 'July' => __('July', 'latepoint'),
286 'August' => __('August', 'latepoint'),
287 'September' => __('September', 'latepoint'),
288 'October' => __('October', 'latepoint'),
289 'November' => __('November', 'latepoint'),
290 'December' => __('December', 'latepoint'),
291 'Jan' => __('Jan', 'latepoint'),
292 'Feb' => __('Feb', 'latepoint'),
293 'Mar' => __('Mar', 'latepoint'),
294 'Apr' => __('Apr', 'latepoint'),
295 'Jun' => __('Jun', 'latepoint'),
296 'Jul' => __('Jul', 'latepoint'),
297 'Aug' => __('Aug', 'latepoint'),
298 'Sep' => __('Sep', 'latepoint'),
299 'Oct' => __('Oct', 'latepoint'),
300 'Nov' => __('Nov', 'latepoint'),
301 'Dec' => __('Dec', 'latepoint')];
302 }
303
304 public static function translate_months($date_string){
305 $date_string = str_replace(array_keys(self::translated_months()), array_values(self::translated_months()), $date_string);
306 return $date_string;
307 }
308
309 public static function get_months_for_select(){
310 $months = [];
311 for($i = 1; $i<= 12; $i++){
312 $months[] = ['label' => self::get_month_name_by_number($i), 'value' => $i];
313 }
314 return $months;
315 }
316
317 public static function get_weekday_name_by_number($weekday_number, $short = false){
318 $weekday_names = [__('Monday', 'latepoint'),
319 __('Tuesday', 'latepoint'),
320 __('Wednesday', 'latepoint'),
321 __('Thursday', 'latepoint'),
322 __('Friday', 'latepoint'),
323 __('Saturday', 'latepoint'),
324 __('Sunday', 'latepoint')];
325 $weekday_name = isset($weekday_names[$weekday_number - 1]) ? $weekday_names[$weekday_number - 1] : 'n/a';
326 if($short) $weekday_name = mb_substr($weekday_name, 0, 3);
327 return $weekday_name;
328 }
329
330 // Checks if array is associative
331 public static function is_array_a($array){
332 return count(array_filter(array_keys($array), 'is_string')) > 0;
333 }
334
335
336 public static function models_to_select_options(array $models, string $value_key, string $label_key): array{
337 if(empty($models)) return [];
338 $options = [];
339 foreach($models as $model){
340 if(method_exists($model, $label_key)){
341 $label = call_user_func_array([$model, $label_key], []);
342 }elseif(property_exists($model, $label_key)){
343 $label = $model->$label_key;
344 }
345 if(method_exists($model, $value_key)){
346 $value = call_user_func_array([$model, $value_key], []);
347 }elseif(property_exists($model, $value_key)){
348 $value = $model->$value_key;
349 }
350 if(isset($label) && isset($value)){
351 $options[] = ['value' => $value, 'label' => $label];
352 }
353 unset($value);
354 unset($label);
355 }
356 return $options;
357 }
358
359
360 public static function array_to_select_options(array $array, string $value_key, string $label_key): array{
361 if(empty($array)) return [];
362 $options = [];
363 foreach($array as $item){
364 if(isset($item[$value_key]) && isset($item[$label_key])) $options[$item[$value_key]] = $item[$label_key];
365 }
366 return $options;
367 }
368
369 public static function transform_flat_list_for_multi_select( array $flat_list ): array {
370 $result_list = [];
371
372 foreach ( $flat_list as $key => $value ) {
373 $result_list[] = [
374 'value' => $key,
375 'label' => $value
376 ];
377 }
378
379 return $result_list;
380 }
381
382
383 /**
384 *
385 * Returns phone number in format +18888888888, strips all none plus characters and digits, prepends country code if provided
386 *
387 * @param string $number
388 * @param string $country_code
389 * @return string
390 */
391 public static function sanitize_phone_number(string $number, string $country_code = ''): string{
392 if(empty($number)) return '';
393 $add_country_code = (substr($number, 0, 1) == '+') ? '+' : $country_code; // figure out if country code is missing
394 if(stripos($number, 'x') !== false) $number = substr($number, 0, stripos($number, 'x')); // strip extension
395
396 $formatted_phone = preg_replace('/[^\d]/', '', $number);
397 if(!empty($formatted_phone)){
398 return $add_country_code.$formatted_phone;
399 }else{
400 return '';
401 }
402 }
403
404 public static function get_countries_list(): array {
405 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 (‫جزر الق�
406 ر‬‎)", "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 (‫�
407 صر‬‎)", "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 (Каза�
408 стан)", "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 (‫�
409 وريتانيا‬‎)", "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 (‫ال�
410 غرب‬‎)", "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 (‫عُ�
411 ان‬‎)", "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 (‫ال�
412
413 لكة العربية السعودية‬‎)", "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 (‫الإ�
414 ارات العربية ال�
415 تحدة‬‎)", "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 (‫الي�
416 ن‬‎)", "zm" => "Zambia", "zw" => "Zimbabwe", "ax" => "�
417 land Islands", ];
418 }
419
420 public static function is_date_valid($date_string){
421 return (bool)strtotime($date_string);
422 }
423
424 public static function build_os_params($params = array(), string $nonce_action = ''){
425 if(!empty($nonce_action)){
426 $params['_wpnonce'] = wp_create_nonce($nonce_action);
427 }
428 return http_build_query($params);
429 }
430
431
432 public static function get_user_ip() : string{
433 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ){
434 $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP']));
435 }elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
436 $ip = sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR']));
437 }else{
438 $ip = sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'] ?? ''));
439 }
440
441 // Sanitize the IP address
442 $ip = filter_var( $ip, FILTER_VALIDATE_IP );
443
444 if ( $ip === false ) {
445 // Handle invalid IP case
446 $ip = 'n/a';
447 }
448
449 return $ip;
450 }
451
452 public static function create_nonce($string = ''){
453 return wp_create_nonce( 'latepoint_'.$string );
454 }
455
456 public static function verify_nonce($nonce, $string = ''){
457 return wp_verify_nonce( $nonce, 'latepoint_'.$string );
458 }
459
460 public static function obfuscate_license(string $license_key): string {
461 return preg_replace_callback('/-(.*)/', function($matches) {
462 return '-' . str_repeat('*', strlen($matches[1]));
463 }, $license_key);
464 }
465
466 public static function generate_form_id(): string {
467 return 'new_'.self::random_text();
468 }
469
470 public static function pro_feature_block(string $label = '', string $label_code = '') : string {
471 $label = !empty($label) ? $label : __('Requires upgrade to a premium version', 'latepoint');
472 $html = '<a href="'.esc_url(LATEPOINT_UPGRADE_URL).'" class="os-add-box" >
473 <div class="add-box-graphic-w"><div class="add-box-plus"><i class="latepoint-icon latepoint-icon-plus4"></i></div></div>
474 <div class="add-box-label">'.esc_html($label).'</div>
475 </a>';
476 /**
477 * PRO Features block
478 *
479 * @since 5.1.2
480 * @hook latepoint_pro_feature_block_html
481 *
482 * @param {string} $html html of a block
483 * @param {string} $label label that goes inside
484 * @param {string} $label_code code used to determine where the block is shown
485 * @returns {string} The filtered html of a block
486 */
487 return apply_filters('latepoint_pro_feature_block_html', $html, $label, $label_code);
488 }
489
490 public static function generate_key_to_manage() : string {
491 return bin2hex( random_bytes( 18 ) );
492 }
493
494 public static function get_color_for_variable_by_index($index) : string {
495 $colors = self::get_colors_for_variables();
496 return $colors[$index] ?? '#eee';
497 }
498
499 public static function get_colors_for_variables() : array {
500 $colors = [ '#b6ffc8', '#ffbbbb', '#cbc5ff', '#ffe2a3', '#ffbfe2', '#6dffe3', '#abe4ff', '#eee' ];
501 /**
502 * Generate colors to be used for variables
503 *
504 * @since 5.1.3
505 * @hook latepoint_get_colors_for_variables
506 *
507 * @param {array} $colors array of colors
508 * @returns {array} The filtered array of colors
509 */
510 return apply_filters('latepoint_get_colors_for_variables', $colors);
511 }
512 }