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