| @@ -1,81 +1,118 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace UltimateStoreKit\Classes; | |
| 4 | - | |
| 5 | -if (!defined('ABSPATH')) exit; // Exit if accessed directly | |
| 6 | - | |
| 7 | -class Utils { | |
| 8 | - | |
| 9 | - | |
| 10 | - public static function get_site_domain() { | |
| 11 | - return str_ireplace('www.', '', parse_url(home_url(), PHP_URL_HOST)); | |
| 12 | - } | |
| 13 | - | |
| 14 | - public static function readable_num($size) { | |
| 15 | - $l = substr($size, -1); | |
| 16 | - $ret = substr($size, 0, -1); | |
| 17 | - $byte = 1024; | |
| 18 | - | |
| 19 | - switch (strtoupper($l)) { | |
| 20 | - case 'P': | |
| 21 | - $ret *= 1024; | |
| 22 | - case 'T': | |
| 23 | - $ret *= 1024; | |
| 24 | - case 'G': | |
| 25 | - $ret *= 1024; | |
| 26 | - case 'M': | |
| 27 | - $ret *= 1024; | |
| 28 | - case 'K': | |
| 29 | - $ret *= 1024; | |
| 30 | - } | |
| 31 | - return $ret; | |
| 32 | - } | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * For get wp environment for ultimate store kit | |
| 36 | - * @return [type] [description] | |
| 37 | - */ | |
| 38 | - public static function get_environment_info() { | |
| 39 | - | |
| 40 | - // Figure out cURL version, if installed. | |
| 41 | - $curl_version = ''; | |
| 42 | - if (function_exists('curl_version')) { | |
| 43 | - $curl_version = curl_version(); | |
| 44 | - $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; | |
| 45 | - } | |
| 46 | - | |
| 47 | - | |
| 48 | - // WP memory limit. | |
| 49 | - $wp_memory_limit = self::readable_num(WP_MEMORY_LIMIT); | |
| 50 | - if (function_exists('memory_get_usage')) { | |
| 51 | - $wp_memory_limit = max($wp_memory_limit, self::readable_num(@ini_get('memory_limit'))); | |
| 52 | - } | |
| 53 | - | |
| 54 | - | |
| 55 | - return array( | |
| 56 | - 'home_url' => get_option('home'), | |
| 57 | - 'site_url' => get_option('siteurl'), | |
| 58 | - 'version' => BDTUSK_VER, | |
| 59 | - 'wp_version' => get_bloginfo('version'), | |
| 60 | - 'wp_multisite' => is_multisite(), | |
| 61 | - 'wp_memory_limit' => $wp_memory_limit, | |
| 62 | - 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), | |
| 63 | - 'wp_cron' => !(defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), | |
| 64 | - 'language' => get_locale(), | |
| 65 | - 'external_object_cache' => wp_using_ext_object_cache(), | |
| 66 | - 'php_version' => phpversion(), | |
| 67 | - 'php_post_max_size' => self::readable_num(ini_get('post_max_size')), | |
| 68 | - 'php_max_execution_time' => ini_get('max_execution_time'), | |
| 69 | - 'php_max_input_vars' => ini_get('max_input_vars'), | |
| 70 | - 'curl_version' => $curl_version, | |
| 71 | - 'suhosin_installed' => extension_loaded('suhosin'), | |
| 72 | - 'max_upload_size' => wp_max_upload_size(), | |
| 73 | - 'default_timezone' => date_default_timezone_get(), | |
| 74 | - 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), | |
| 75 | - 'soapclient_enabled' => class_exists('SoapClient'), | |
| 76 | - 'domdocument_enabled' => class_exists('DOMDocument'), | |
| 77 | - 'gzip_enabled' => is_callable('gzopen'), | |
| 78 | - 'mbstring_enabled' => extension_loaded('mbstring'), | |
| 79 | - ); | |
| 80 | - } | |
| 81 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UltimateStoreKit\Classes; | |
| 4 | + | |
| 5 | +if (!defined('ABSPATH')) | |
| 6 | + exit; // Exit if accessed directly | |
| 7 | + | |
| 8 | +class Utils | |
| 9 | +{ | |
| 10 | + | |
| 11 | + | |
| 12 | + public static function get_site_domain() | |
| 13 | + { | |
| 14 | + return str_ireplace('www.', '', wp_parse_url(home_url(), PHP_URL_HOST)); | |
| 15 | + } | |
| 16 | + | |
| 17 | + public static function readable_num($size) | |
| 18 | + { | |
| 19 | + $l = substr($size, -1); | |
| 20 | + $ret = substr($size, 0, -1); | |
| 21 | + $byte = 1024; | |
| 22 | + | |
| 23 | + switch (strtoupper($l)) { | |
| 24 | + case 'P': | |
| 25 | + $ret *= 1024; | |
| 26 | + case 'T': | |
| 27 | + $ret *= 1024; | |
| 28 | + case 'G': | |
| 29 | + $ret *= 1024; | |
| 30 | + case 'M': | |
| 31 | + $ret *= 1024; | |
| 32 | + case 'K': | |
| 33 | + $ret *= 1024; | |
| 34 | + } | |
| 35 | + return $ret; | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * For get wp environment for ultimate store kit | |
| 40 | + * @return [type] [description] | |
| 41 | + */ | |
| 42 | + public static function get_environment_info() | |
| 43 | + { | |
| 44 | + | |
| 45 | + // Figure out cURL version, if installed. | |
| 46 | + $curl_version = ''; | |
| 47 | + if (function_exists('curl_version')) { | |
| 48 | + $curl_version = curl_version(); | |
| 49 | + $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; | |
| 50 | + } | |
| 51 | + | |
| 52 | + | |
| 53 | + // WP memory limit. | |
| 54 | + $wp_memory_limit = self::readable_num(WP_MEMORY_LIMIT); | |
| 55 | + if (function_exists('memory_get_usage')) { | |
| 56 | + $wp_memory_limit = max($wp_memory_limit, self::readable_num(@ini_get('memory_limit'))); | |
| 57 | + } | |
| 58 | + | |
| 59 | + | |
| 60 | + return array( | |
| 61 | + 'home_url' => get_option('home'), | |
| 62 | + 'site_url' => get_option('siteurl'), | |
| 63 | + 'version' => BDTUSK_VER, | |
| 64 | + 'wp_version' => get_bloginfo('version'), | |
| 65 | + 'wp_multisite' => is_multisite(), | |
| 66 | + 'wp_memory_limit' => $wp_memory_limit, | |
| 67 | + 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), | |
| 68 | + 'wp_cron' => !(defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), | |
| 69 | + 'language' => get_locale(), | |
| 70 | + 'external_object_cache' => wp_using_ext_object_cache(), | |
| 71 | + 'php_version' => phpversion(), | |
| 72 | + 'php_post_max_size' => self::readable_num(ini_get('post_max_size')), | |
| 73 | + 'php_max_execution_time' => ini_get('max_execution_time'), | |
| 74 | + 'php_max_input_vars' => ini_get('max_input_vars'), | |
| 75 | + 'curl_version' => $curl_version, | |
| 76 | + 'suhosin_installed' => extension_loaded('suhosin'), | |
| 77 | + 'max_upload_size' => wp_max_upload_size(), | |
| 78 | + 'default_timezone' => date_default_timezone_get(), | |
| 79 | + 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), | |
| 80 | + 'soapclient_enabled' => class_exists('SoapClient'), | |
| 81 | + 'domdocument_enabled' => class_exists('DOMDocument'), | |
| 82 | + 'gzip_enabled' => is_callable('gzopen'), | |
| 83 | + 'mbstring_enabled' => extension_loaded('mbstring'), | |
| 84 | + ); | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * A list of safe tage for `get_valid_html_tag` method. | |
| 89 | + */ | |
| 90 | + const ALLOWED_HTML_WRAPPER_TAGS = [ | |
| 91 | + 'article', | |
| 92 | + 'aside', | |
| 93 | + 'div', | |
| 94 | + 'footer', | |
| 95 | + 'h1', | |
| 96 | + 'h2', | |
| 97 | + 'h3', | |
| 98 | + 'h4', | |
| 99 | + 'h5', | |
| 100 | + 'h6', | |
| 101 | + 'header', | |
| 102 | + 'main', | |
| 103 | + 'nav', | |
| 104 | + 'p', | |
| 105 | + 'section', | |
| 106 | + 'span', | |
| 107 | + ]; | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Validate an HTML tag against a safe allowed list. | |
| 111 | + * @param string $tag | |
| 112 | + * @return string | |
| 113 | + */ | |
| 114 | + public static function get_valid_html_tag($tag) | |
| 115 | + { | |
| 116 | + return in_array(strtolower($tag), self::ALLOWED_HTML_WRAPPER_TAGS) ? $tag : 'div'; | |
| 117 | + } | |
| 118 | +} | |