| 1 |
<?php |
| 2 |
|
| 3 |
namespace PixelGallery; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 6 |
|
| 7 |
class Utils { |
| 8 |
|
| 9 |
/** |
| 10 |
* A list of safe tage for `get_valid_html_tag` method. |
| 11 |
*/ |
| 12 |
const ALLOWED_HTML_WRAPPER_TAGS = [ |
| 13 |
'article', |
| 14 |
'aside', |
| 15 |
'div', |
| 16 |
'footer', |
| 17 |
'h1', |
| 18 |
'h2', |
| 19 |
'h3', |
| 20 |
'h4', |
| 21 |
'h5', |
| 22 |
'h6', |
| 23 |
'header', |
| 24 |
'main', |
| 25 |
'nav', |
| 26 |
'p', |
| 27 |
'section', |
| 28 |
'span', |
| 29 |
]; |
| 30 |
|
| 31 |
|
| 32 |
public static function get_site_domain() { |
| 33 |
return str_ireplace('www.', '', wp_parse_url(home_url(), PHP_URL_HOST)); |
| 34 |
} |
| 35 |
|
| 36 |
public static function readable_num($size) { |
| 37 |
$l = substr($size, -1); |
| 38 |
$ret = substr($size, 0, -1); |
| 39 |
|
| 40 |
switch (strtoupper($l)) { |
| 41 |
case 'P': |
| 42 |
$ret *= 1024; |
| 43 |
break; |
| 44 |
case 'T': |
| 45 |
$ret *= 1024; |
| 46 |
break; |
| 47 |
case 'G': |
| 48 |
$ret *= 1024; |
| 49 |
break; |
| 50 |
case 'M': |
| 51 |
$ret *= 1024; |
| 52 |
break; |
| 53 |
case 'K': |
| 54 |
$ret *= 1024; |
| 55 |
} |
| 56 |
return $ret; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Validate an HTML tag against a safe allowed list. |
| 61 |
* @param string $tag |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
public static function get_valid_html_tag($tag) { |
| 65 |
return in_array(strtolower($tag), self::ALLOWED_HTML_WRAPPER_TAGS) ? $tag : 'div'; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Get placeholder image source. |
| 70 |
* Retrieve the source of the placeholder image. |
| 71 |
* @since 5.7.6 |
| 72 |
* @access public |
| 73 |
* @static |
| 74 |
* @return string The source of the default placeholder image used by Elementor. |
| 75 |
*/ |
| 76 |
public static function get_placeholder_image_src() { |
| 77 |
$placeholder_image = ELEMENTOR_ASSETS_URL . 'images/placeholder.png'; |
| 78 |
|
| 79 |
return $placeholder_image; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* For get wp environment for ultimate store kit |
| 84 |
* @return [type] [description] |
| 85 |
*/ |
| 86 |
public static function get_environment_info() { |
| 87 |
|
| 88 |
// Figure out cURL version, if installed. |
| 89 |
$curl_version = ''; |
| 90 |
if (function_exists('curl_version')) { |
| 91 |
$curl_version = curl_version(); |
| 92 |
$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
// WP memory limit. |
| 97 |
$wp_memory_limit = self::readable_num(WP_MEMORY_LIMIT); |
| 98 |
if (function_exists('memory_get_usage')) { |
| 99 |
$wp_memory_limit = max($wp_memory_limit, self::readable_num(@ini_get('memory_limit'))); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
return array( |
| 104 |
'home_url' => get_option('home'), |
| 105 |
'site_url' => get_option('siteurl'), |
| 106 |
'version' => BDTPG_VER, |
| 107 |
'wp_version' => get_bloginfo('version'), |
| 108 |
'wp_multisite' => is_multisite(), |
| 109 |
'wp_memory_limit' => $wp_memory_limit, |
| 110 |
'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), |
| 111 |
'wp_cron' => !(defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), |
| 112 |
'language' => get_locale(), |
| 113 |
'external_object_cache' => wp_using_ext_object_cache(), |
| 114 |
'php_version' => phpversion(), |
| 115 |
'php_post_max_size' => self::readable_num(ini_get('post_max_size')), |
| 116 |
'php_max_execution_time' => ini_get('max_execution_time'), |
| 117 |
'php_max_input_vars' => ini_get('max_input_vars'), |
| 118 |
'curl_version' => $curl_version, |
| 119 |
'suhosin_installed' => extension_loaded('suhosin'), |
| 120 |
'max_upload_size' => wp_max_upload_size(), |
| 121 |
'default_timezone' => date_default_timezone_get(), |
| 122 |
'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), |
| 123 |
'soapclient_enabled' => class_exists('SoapClient'), |
| 124 |
'domdocument_enabled' => class_exists('DOMDocument'), |
| 125 |
'gzip_enabled' => is_callable('gzopen'), |
| 126 |
'mbstring_enabled' => extension_loaded('mbstring'), |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Get timezone string. |
| 132 |
* |
| 133 |
* Retrieve timezone string from the WordPress database. |
| 134 |
* |
| 135 |
* @since 1.0.0 |
| 136 |
* @access public |
| 137 |
* @static |
| 138 |
* |
| 139 |
* @return string Timezone string. |
| 140 |
*/ |
| 141 |
public static function get_timezone_string() { |
| 142 |
$current_offset = (float) get_option('gmt_offset'); |
| 143 |
$timezone_string = get_option('timezone_string'); |
| 144 |
|
| 145 |
// Create a UTC+- zone if no timezone string exists. |
| 146 |
if (empty($timezone_string)) { |
| 147 |
if ($current_offset < 0) { |
| 148 |
$timezone_string = 'UTC' . $current_offset; |
| 149 |
} else { |
| 150 |
$timezone_string = 'UTC+' . $current_offset; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
return $timezone_string; |
| 155 |
} |
| 156 |
|
| 157 |
public static function print_html_attributes(array $attributes) |
| 158 |
{ |
| 159 |
// PHPCS - the method render_html_attributes is safe. |
| 160 |
echo self::render_html_attributes($attributes); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Render html attributes |
| 165 |
* |
| 166 |
* @access public |
| 167 |
* @static |
| 168 |
* @param array $attributes |
| 169 |
* |
| 170 |
* @return string |
| 171 |
*/ |
| 172 |
public static function render_html_attributes(array $attributes) |
| 173 |
{ |
| 174 |
$rendered_attributes = []; |
| 175 |
|
| 176 |
foreach ($attributes as $attribute_key => $attribute_values) { |
| 177 |
if (is_array($attribute_values)) { |
| 178 |
$attribute_values = implode(' ', $attribute_values); |
| 179 |
} |
| 180 |
|
| 181 |
$rendered_attributes[] = sprintf('%1$s="%2$s"', $attribute_key, esc_attr($attribute_values)); |
| 182 |
} |
| 183 |
|
| 184 |
return implode(' ', $rendered_attributes); |
| 185 |
} |
| 186 |
|
| 187 |
} |
| 188 |
|