Recommended
3 years ago
Support
3 years ago
Cross.php
3 years ago
Fallback.php
3 years ago
Fields.php
3 years ago
Helper.php
3 years ago
I18n.php
3 years ago
Plugin.php
3 years ago
Popup.php
3 years ago
PostType.php
3 years ago
Review.php
3 years ago
Settings.php
3 years ago
Shortcode.php
3 years ago
Upgrade.php
3 years ago
Helper.php
129 lines
| 1 | <?php |
| 2 | namespace NTA_WhatsApp; |
| 3 | |
| 4 | defined('ABSPATH') || exit; |
| 5 | |
| 6 | class Helper |
| 7 | { |
| 8 | protected static $instance = null; |
| 9 | public static function getInstance() |
| 10 | { |
| 11 | if (null == self::$instance) { |
| 12 | self::$instance = new self; |
| 13 | } |
| 14 | return self::$instance; |
| 15 | } |
| 16 | |
| 17 | public function __construct() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | public static function printWorkingDays($array_data) |
| 22 | { |
| 23 | if ($array_data['isAlwaysAvailable'] === 'ON') { |
| 24 | return __('Always online','ninjateam-whatsapp'); |
| 25 | } |
| 26 | |
| 27 | $date_string = ""; |
| 28 | $daysOfWeek = array( |
| 29 | 'sunday' => __('Sunday', "ninjateam-whatsapp"), |
| 30 | 'monday' => __('Monday', "ninjateam-whatsapp"), |
| 31 | 'tuesday' => __('Tuesday', "ninjateam-whatsapp"), |
| 32 | 'wednesday' => __('Wednesday', "ninjateam-whatsapp"), |
| 33 | 'thursday' => __('Thursday', "ninjateam-whatsapp"), |
| 34 | 'friday' => __('Friday', "ninjateam-whatsapp"), |
| 35 | 'saturday' => __('Saturday', "ninjateam-whatsapp"), |
| 36 | ); |
| 37 | |
| 38 | foreach ($array_data['daysOfWeekWorking'] as $dayKey => $dayVal) { |
| 39 | if ($dayVal["isWorkingOnDay"] === 'ON') { |
| 40 | $date_string .= $daysOfWeek[$dayKey] . ', '; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | $date_string = trim($date_string, ', '); |
| 45 | return $date_string; |
| 46 | } |
| 47 | |
| 48 | public static function getValueOrDefault($object, $objectKey, $defaultValue = '') |
| 49 | { |
| 50 | return (isset($object[$objectKey]) ? $object[$objectKey] : $defaultValue); |
| 51 | } |
| 52 | |
| 53 | public static function buildTimeSelector($default = '08:00', $interval = '+30 minutes') |
| 54 | { |
| 55 | $output = ''; |
| 56 | |
| 57 | $current = strtotime('00:00'); |
| 58 | $end = strtotime('23:59'); |
| 59 | |
| 60 | while ($current <= $end) { |
| 61 | $time = date('H:i', $current); |
| 62 | $sel = ($time == $default) ? ' selected' : ''; |
| 63 | |
| 64 | $output .= "<option value=\"{$time}\"{$sel}>" . date('H:i', $current) . '</option>'; |
| 65 | $current = strtotime($interval, $current); |
| 66 | } |
| 67 | $sel = ($default === '23:59') ? ' selected' : ''; |
| 68 | $output .= "<option value=\"23:59\"{$sel}>" . '23:59' . '</option>'; |
| 69 | return $output; |
| 70 | } |
| 71 | |
| 72 | public static function sanitize_array($var) |
| 73 | { |
| 74 | if (is_array($var)) { |
| 75 | return array_map('self::sanitize_array', $var); |
| 76 | } else { |
| 77 | return is_scalar($var) ? sanitize_text_field($var) : $var; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public static function checkGDPR($option){ |
| 82 | if ($option['isShowGDPR'] === 'OFF') return false; |
| 83 | if (isset($_COOKIE["nta-wa-gdpr"]) && $_COOKIE["nta-wa-gdpr"] == 'accept') return false; |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | public static function isSaveNewPost($refererUrl){ |
| 88 | $add_new_action = strpos($refererUrl, 'post-new.php'); |
| 89 | if ($add_new_action !== false) return true; |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | public static function wp_timezone_string(){ |
| 94 | $timezone_string = get_option( 'timezone_string' ); |
| 95 | |
| 96 | if ( $timezone_string ) { |
| 97 | return $timezone_string; |
| 98 | } |
| 99 | |
| 100 | $offset = (float) get_option( 'gmt_offset' ); |
| 101 | $hours = (int) $offset; |
| 102 | $minutes = ( $offset - $hours ); |
| 103 | |
| 104 | $sign = ( $offset < 0 ) ? '-' : '+'; |
| 105 | $abs_hour = abs( $hours ); |
| 106 | $abs_mins = abs( $minutes * 60 ); |
| 107 | $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); |
| 108 | |
| 109 | return $tz_offset; |
| 110 | } |
| 111 | |
| 112 | public static function print_icon(){ |
| 113 | return '<svg width="48px" height="48px" class="nta-whatsapp-default-avatar" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" |
| 114 | viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"> |
| 115 | <path style="fill:#EDEDED;" d="M0,512l35.31-128C12.359,344.276,0,300.138,0,254.234C0,114.759,114.759,0,255.117,0 |
| 116 | S512,114.759,512,254.234S395.476,512,255.117,512c-44.138,0-86.51-14.124-124.469-35.31L0,512z"/> |
| 117 | <path style="fill:#55CD6C;" d="M137.71,430.786l7.945,4.414c32.662,20.303,70.621,32.662,110.345,32.662 |
| 118 | c115.641,0,211.862-96.221,211.862-213.628S371.641,44.138,255.117,44.138S44.138,137.71,44.138,254.234 |
| 119 | c0,40.607,11.476,80.331,32.662,113.876l5.297,7.945l-20.303,74.152L137.71,430.786z"/> |
| 120 | <path style="fill:#FEFEFE;" d="M187.145,135.945l-16.772-0.883c-5.297,0-10.593,1.766-14.124,5.297 |
| 121 | c-7.945,7.062-21.186,20.303-24.717,37.959c-6.179,26.483,3.531,58.262,26.483,90.041s67.09,82.979,144.772,105.048 |
| 122 | c24.717,7.062,44.138,2.648,60.028-7.062c12.359-7.945,20.303-20.303,22.952-33.545l2.648-12.359 |
| 123 | c0.883-3.531-0.883-7.945-4.414-9.71l-55.614-25.6c-3.531-1.766-7.945-0.883-10.593,2.648l-22.069,28.248 |
| 124 | c-1.766,1.766-4.414,2.648-7.062,1.766c-15.007-5.297-65.324-26.483-92.69-79.448c-0.883-2.648-0.883-5.297,0.883-7.062 |
| 125 | l21.186-23.834c1.766-2.648,2.648-6.179,1.766-8.828l-25.6-57.379C193.324,138.593,190.676,135.945,187.145,135.945"/> |
| 126 | </svg>'; |
| 127 | } |
| 128 | } |
| 129 |