PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.2
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.2
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / classes / utils.php

utils.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.2, at inc/classes/utils.php

284 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Classes;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 class Utils
10 {
11 public static function get_options($key, $network_override = true)
12 {
13 if (is_network_admin()) {
14 $value = get_site_option($key);
15 } elseif (!$network_override && is_multisite()) {
16 $value = get_site_option($key);
17 } elseif ($network_override && is_multisite()) {
18 $value = get_option($key);
19 $value = (false === $value || (is_array($value) && in_array('disabled', $value))) ? get_site_option($key) : $value;
20 } else {
21 $value = get_option($key);
22 }
23
24 return $value;
25 }
26
27 public static function check_options($option_name)
28 {
29 return isset($option_name) ? esc_attr($option_name) : false;
30 }
31
32 public static function update_options($option_name, $option_value)
33 {
34 if (JLTMA_NETWORK_ACTIVATED == true) {
35 return update_site_option($option_name, $option_value);
36 } else {
37 return update_option($option_name, $option_value);
38 }
39 }
40
41 public static function is_plugin_active($plugin_basename)
42 {
43 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
44 return \is_plugin_active($plugin_basename);
45 }
46
47 public static function is_woocommerce_active()
48 {
49 return self::is_plugin_active('woocommerce/woocommerce.php');
50 }
51
52 public static function is_site_wide($plugin)
53 {
54 if (!is_multisite()) {
55 return false;
56 }
57
58 $plugins = get_site_option('active_sitewide_plugins');
59 if (isset($plugins[$plugin])) {
60 return true;
61 }
62
63 return false;
64 }
65
66 public static function pretty_number($x = 0)
67 {
68 $x = (int) $x;
69
70 if ($x > 1000000) {
71 return floor($x / 1000000) . 'M';
72 }
73
74 if ($x > 10000) {
75 return floor($x / 1000) . 'k';
76 }
77 return $x;
78 }
79
80 public static function get_site_domain()
81 {
82 return str_ireplace('www.', '', (string) wp_parse_url(home_url() ?? '', PHP_URL_HOST));
83 }
84
85 public static function human_readable_num($size)
86 {
87 $l = substr($size, -1);
88 $ret = substr($size, 0, -1);
89
90 switch (strtoupper($l)) {
91 case 'P':
92 $ret *= 1024;
93 case 'T':
94 $ret *= 1024;
95 case 'G':
96 $ret *= 1024;
97 case 'M':
98 $ret *= 1024;
99 case 'K':
100 $ret *= 1024;
101 }
102 return $ret;
103 }
104
105 public static function array_flatten($array)
106 {
107 if (!is_array($array)) {
108 return false;
109 }
110 $result = array();
111 foreach ($array as $key => $value) {
112 if (is_array($value)) {
113 $result[$key] = $value[0];
114 } else {
115 $result[$key] = $value;
116 }
117 }
118 return $result;
119 }
120
121 public static function hex2rgb_array($hex)
122 {
123 $hex = str_replace('#', '', $hex);
124 if (strlen($hex) == 3) {
125 $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
126 $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
127 $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
128 } else {
129 $r = hexdec(substr($hex, 0, 2));
130 $g = hexdec(substr($hex, 2, 2));
131 $b = hexdec(substr($hex, 4, 2));
132 }
133 $rgb = array($r, $g, $b);
134 return $rgb;
135 }
136
137 public static function hex2Rgb($hex, $alpha = false)
138 {
139 $hex = str_replace('#', '', $hex);
140 $length = strlen($hex);
141 $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
142 $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
143 $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
144 if ($alpha) {
145 $rgb['a'] = $alpha;
146 }
147 return $rgb;
148 }
149
150 public static function image_filter_gallery_categories($gallery_items)
151 {
152 if (!is_array($gallery_items)) {
153 return false;
154 }
155
156 $gallery_category_names = array();
157 $gallery_category_names_final = array();
158
159 foreach ($gallery_items as $gallery_item) {
160 $gallery_category_names[] = $gallery_item['gallery_category_name'];
161 }
162
163 if (is_array($gallery_category_names) && !empty($gallery_category_names)) {
164 foreach ($gallery_category_names as $gallery_category_name) {
165 $gallery_category_names_final[] = explode(',', $gallery_category_name);
166 }
167 }
168
169 if (is_array($gallery_category_names_final) && !empty($gallery_category_names_final)) {
170 $gallery_category_names_final = self::image_filter_gallery_array_flatten($gallery_category_names_final);
171 return array_unique(array_filter($gallery_category_names_final));
172 }
173 }
174
175 public static function image_filter_gallery_category_classes($gallery_classes, $id)
176 {
177 if (!($gallery_classes)) {
178 return false;
179 }
180
181 $gallery_cat_classes = array();
182 $gallery_classes = explode(',', $gallery_classes);
183
184 if (is_array($gallery_classes) && !empty($gallery_classes)) {
185 foreach ($gallery_classes as $gallery_class) {
186 $gallery_cat_classes[] = sanitize_title($gallery_class) . '-' . $id;
187 }
188 }
189
190 return implode(' ', $gallery_cat_classes);
191 }
192
193 public static function image_filter_gallery_categories_parts($gallery_classes)
194 {
195 if (!($gallery_classes)) {
196 return false;
197 }
198
199 $gallery_cat_classes = array();
200 $gallery_classes = explode(',', $gallery_classes);
201
202 if (is_array($gallery_classes) && !empty($gallery_classes)) {
203 foreach ($gallery_classes as $gallery_class) {
204 $gallery_cat_classes[] = '<div class="ma-el-label ma-el-added ma-el-image-filter-cat">' . sanitize_title($gallery_class) . '</div>';
205 }
206 }
207
208 return implode(' ', $gallery_cat_classes);
209 }
210
211 public static function image_filter_gallery_array_flatten($array)
212 {
213 if (!is_array($array)) {
214 return false;
215 }
216
217 $result = array();
218
219 foreach ($array as $key => $value) {
220 if (is_array($value)) {
221 $result = array_merge($result, self::image_filter_gallery_array_flatten($value));
222 } else {
223 $result[$key] = $value;
224 }
225 }
226
227 return $result;
228 }
229
230 public static function multi_dimension_flatten($array, $prefix = '')
231 {
232 $result = array();
233 foreach ($array as $key => $value) {
234 if (is_array($value)) {
235 $result = $result + self::multi_dimension_flatten($value, $prefix . $key . '.');
236 } else {
237 $result[$key] = $value;
238 }
239 }
240 return $result;
241 }
242
243 public static function get_environment_info()
244 {
245 $curl_version = '';
246 if (function_exists('curl_version')) {
247 $curl_version = curl_version();
248 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
249 }
250
251 $wp_memory_limit = self::human_readable_num(WP_MEMORY_LIMIT);
252 if (function_exists('memory_get_usage')) {
253 $wp_memory_limit = max($wp_memory_limit, self::human_readable_num(@ini_get('memory_limit')));
254 }
255
256 return array(
257 'home_url' => get_option('home'),
258 'site_url' => get_option('siteurl'),
259 'version' => defined('JLTMA_VER') ? JLTMA_VER : '',
260 'wp_version' => get_bloginfo('version'),
261 'wp_multisite' => is_multisite(),
262 'wp_memory_limit' => $wp_memory_limit,
263 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG),
264 'wp_cron' => !(defined('DISABLE_WP_CRON') && DISABLE_WP_CRON),
265 'language' => get_locale(),
266 'external_object_cache' => wp_using_ext_object_cache(),
267 'server_info' => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field( wp_unslash($_SERVER['SERVER_SOFTWARE']) ) : '',
268 'php_version' => phpversion(),
269 'php_post_max_size' => self::human_readable_num(ini_get('post_max_size')),
270 'php_max_execution_time' => ini_get('max_execution_time'),
271 'php_max_input_vars' => ini_get('max_input_vars'),
272 'curl_version' => $curl_version,
273 'suhosin_installed' => extension_loaded('suhosin'),
274 'max_upload_size' => wp_max_upload_size(),
275 'default_timezone' => date_default_timezone_get(),
276 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')),
277 'soapclient_enabled' => class_exists('SoapClient'),
278 'domdocument_enabled' => class_exists('DOMDocument'),
279 'gzip_enabled' => is_callable('gzopen'),
280 'mbstring_enabled' => extension_loaded('mbstring'),
281 );
282 }
283 }
284