| @@ -8,11 +8,11 @@ | ||
| 8 | 8 | { |
| 9 | 9 | public static function ip_address() |
| 10 | 10 | { |
| 11 | 11 | $ip = null; |
| 12 | - if ( ! empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| 12 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| 13 | 13 | $ip = $_SERVER['HTTP_CLIENT_IP']; |
| 14 | - } elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| 14 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| 15 | 15 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 16 | 16 | } else { |
| 17 | 17 | $ip = $_SERVER['REMOTE_ADDR']; |
| 18 | 18 | } |
| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | * @return boolean |
| 41 | 41 | */ |
| 42 | 42 | public static function isWcActive() |
| 43 | 43 | { |
| 44 | - if ( ! is_admin()) { | |
| 44 | + if (!is_admin()) { | |
| 45 | 45 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return is_plugin_active('woocommerce/woocommerce.php'); |
| @@ -54,9 +54,9 @@ | ||
| 54 | 54 | * @return boolean |
| 55 | 55 | */ |
| 56 | 56 | public static function isPluginInstalled() |
| 57 | 57 | { |
| 58 | - if ( ! is_admin()) { | |
| 58 | + if (!is_admin()) { | |
| 59 | 59 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | return is_plugin_active('hurrytimer/hurrytimer.php'); |
| @@ -68,9 +68,9 @@ | ||
| 68 | 68 | * @return boolean |
| 69 | 69 | */ |
| 70 | 70 | public static function isPluginProInstalled() |
| 71 | 71 | { |
| 72 | - if ( ! is_admin()) { | |
| 72 | + if (!is_admin()) { | |
| 73 | 73 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return is_plugin_active('hurrytimer-pro/hurrytimer.php'); |
| @@ -82,21 +82,22 @@ | ||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public static function timezone_string() |
| 85 | 85 | { |
| 86 | - if (($timezone = get_option('timezone_string'))) { | |
| 87 | - return $timezone; | |
| 86 | + $timezone_string = get_option('timezone_string'); | |
| 87 | + if (!empty($timezone_string)) { | |
| 88 | + return $timezone_string; | |
| 88 | 89 | } |
| 89 | - if (0 === ($utc_offset = get_option('gmt_offset', 0))) { | |
| 90 | - return 'UTC'; | |
| 91 | - } | |
| 92 | - | |
| 93 | - return self::get_timezone_by_offset($utc_offset); | |
| 90 | + $offset = get_option('gmt_offset'); | |
| 91 | + $hours = (int) $offset; | |
| 92 | + $minutes = abs(($offset - (int) $offset) * 60); | |
| 93 | + $offset = sprintf('%+03d:%02d', $hours, $minutes); | |
| 94 | + return $offset; | |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | 97 | public static function get_timezone_by_offset($offset) |
| 97 | 98 | { |
| 98 | - list($hours, $minutes) = explode(':', $offset); | |
| 99 | + list($hours, $minutes) = wp_parse_args([0, 0], explode(':', $offset)); | |
| 99 | 100 | $seconds = $hours * 60 * 60 + $minutes * 60; |
| 100 | 101 | |
| 101 | 102 | return timezone_name_from_abbr(null, $seconds, true); |
| 102 | 103 | } |
| @@ -115,9 +116,9 @@ | ||
| 115 | 116 | |
| 116 | 117 | public static function isPostActive($post_id) |
| 117 | 118 | { |
| 118 | 119 | return get_post_status($post_id) === "publish" |
| 119 | - || get_post_status($post_id) === "future"; | |
| 120 | + || get_post_status($post_id) === "future"; | |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | public static function activateUrl($post_id) |
| 123 | 124 | { |
| @@ -124,11 +125,11 @@ | ||
| 124 | 125 | return wp_nonce_url( |
| 125 | 126 | add_query_arg( |
| 126 | 127 | array( |
| 127 | 128 | 'hurrytimer_action' => 'activate-compaign', |
| 128 | - 'postid' => $post_id, | |
| 129 | - 'post' => $post_id, | |
| 130 | - 'action' => 'edit', | |
| 129 | + 'postid' => $post_id, | |
| 130 | + 'post' => $post_id, | |
| 131 | + 'action' => 'edit', | |
| 131 | 132 | ), |
| 132 | 133 | network_admin_url('post.php') |
| 133 | 134 | ), |
| 134 | 135 | 'activate-compaign' |
| @@ -140,11 +141,11 @@ | ||
| 140 | 141 | return wp_nonce_url( |
| 141 | 142 | add_query_arg( |
| 142 | 143 | array( |
| 143 | 144 | 'hurrytimer_action' => 'deactivate-compaign', |
| 144 | - 'postid' => $post_id, | |
| 145 | - 'post' => $post_id, | |
| 146 | - 'action' => 'edit', | |
| 145 | + 'postid' => $post_id, | |
| 146 | + 'post' => $post_id, | |
| 147 | + 'action' => 'edit', | |
| 147 | 148 | ), |
| 148 | 149 | network_admin_url('post.php') |
| 149 | 150 | ), |
| 150 | 151 | 'deactivate-compaign' |
| @@ -169,15 +170,89 @@ | ||
| 169 | 170 | |
| 170 | 171 | return implode('', $arr); |
| 171 | 172 | } |
| 172 | 173 | |
| 173 | - | |
| 174 | 174 | public static function getCampaigns($args = []) |
| 175 | 175 | { |
| 176 | 176 | return get_posts(array_merge( |
| 177 | 177 | [ |
| 178 | - 'post_type' => HURRYT_POST_TYPE, | |
| 178 | + 'post_type' => HURRYT_POST_TYPE, | |
| 179 | 179 | 'numberposts' => -1, |
| 180 | 180 | ], |
| 181 | 181 | $args)); |
| 182 | 182 | } |
| 183 | + | |
| 184 | + public static function isUsingDashboard() | |
| 185 | + { | |
| 186 | + return is_admin() | |
| 187 | + || is_preview() | |
| 188 | + || is_customize_preview() | |
| 189 | + || (strpos($_SERVER['REQUEST_URI'], 'preview=true') !== false | |
| 190 | + && strpos($_SERVER['REQUEST_URI'], 'preview_nonce=') !== false) | |
| 191 | + || (strpos($_SERVER['REQUEST_URI'], 'fl_builder') !== false); | |
| 192 | + } | |
| 193 | + | |
| 194 | + public static function getSiteTimezone() | |
| 195 | + { | |
| 196 | + $current_offset = get_option('gmt_offset'); | |
| 197 | + $tzstring = get_option('timezone_string'); | |
| 198 | + | |
| 199 | + $check_zone_info = true; | |
| 200 | + | |
| 201 | + // Remove old Etc mappings. Fallback to gmt_offset. | |
| 202 | + if (false !== strpos($tzstring, 'Etc/GMT')) { | |
| 203 | + $tzstring = ''; | |
| 204 | + } | |
| 205 | + | |
| 206 | + if (empty($tzstring)) { // Create a UTC+- zone if no timezone string exists | |
| 207 | + $check_zone_info = false; | |
| 208 | + if (0 == $current_offset) { | |
| 209 | + $tzstring = 'UTC+0'; | |
| 210 | + } elseif ($current_offset < 0) { | |
| 211 | + $tzstring = 'UTC' . $current_offset; | |
| 212 | + } else { | |
| 213 | + $tzstring = 'UTC+' . $current_offset; | |
| 214 | + } | |
| 215 | + } | |
| 216 | + | |
| 217 | + return $tzstring; | |
| 218 | + } | |
| 219 | + | |
| 220 | + public static function tzOffsetToName($tz) | |
| 221 | + { | |
| 222 | + $tz_name = $tz; | |
| 223 | + if (strpos($tz, 'UTC') !== false && $tz !== 'UTC') { | |
| 224 | + $tz_name = str_replace(array('.25', '.5', '.75', 'UTC'), array(':15', ':30', ':45', ''), | |
| 225 | + $tz); | |
| 226 | + } | |
| 227 | + | |
| 228 | + return $tz_name; | |
| 229 | + } | |
| 230 | + | |
| 231 | + public static function wpWeekDayToRRuleDay($days = []) | |
| 232 | + { | |
| 233 | + $rruleDays = ['SA', 'MO', 'TU', 'WE', 'TH', 'FR', 'SU']; | |
| 234 | + | |
| 235 | + return array_map(function ($i) use ($rruleDays) { | |
| 236 | + return $rruleDays[$i]; | |
| 237 | + }, $days); | |
| 238 | + | |
| 239 | + } | |
| 240 | + | |
| 241 | + public static function createResetAllEvergreenCampaignsUrl($scope = 'admin') | |
| 242 | + { | |
| 243 | + return wp_nonce_url( | |
| 244 | + add_query_arg( | |
| 245 | + array( | |
| 246 | + 'hurryt-action' => 'reset-all-evergreen-compaigns', | |
| 247 | + 'hurryt-scope' => $scope, | |
| 248 | + 'hurryt-page' => 'hurrytimer_settings', | |
| 249 | + ), | |
| 250 | + network_admin_url('admin.php?page=hurrytimer_settings') | |
| 251 | + ), | |
| 252 | + 'reset-all-evergreen-compaigns' | |
| 253 | + ); | |
| 254 | + } | |
| 255 | + | |
| 256 | + | |
| 183 | 257 | } |
| 258 | + | |