Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Helpers/
?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app
<?php
namespace KS_PAC_DCFH\Helpers;
if (!defined('ABSPATH')) {
exit;
}
class General_Helpers
{
private static $_instance;
public static function instance(): self
{
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function dd($data = '', $exit = true): void
{
// phpcs:disable
echo "<pre>";
print_r($data);
echo "</pre>";
if ($exit) {
exit;
}
// phpcs:enable
}
public static function log($data, $delete = false, $filename = ''): void
{
// phpcs:disable
if (empty($data)) {
return;
}
if (empty($filename)) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$filename = isset($trace[1]['function']) ? $trace[1]['function'] : time();
}
$filename = sanitize_file_name($filename).'.log';
$filepath = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$filename;
if ($delete && file_exists($filepath)) {
wp_delete_file($filepath);
}
ini_set('error_log', $filepath);
if (is_array($data) || is_object($data)) {
error_log(print_r($data, true));
} else {
error_log($data);
}
// phpcs:enable
}
public static function current_page(): string
{
return isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- No need to use nonce.
}
public static function sanitize_string($string, $case = 'ucwords')
{
// Remove Accents
$string = remove_accents($string);
// Replace Underscore and Hyphen
$string = preg_replace('/[\-_]/', ' ', $string);
// Removes special chars with space
$string = preg_replace('/\W/', ' ', $string);
// Replacing multiple spaces with a single space
$string = preg_replace('!\s+!', ' ', $string);
// Trim Spaces
$string = trim($string);
if (empty($case) || ' ' === $case) {
$case = 'strtolower';
}
return call_user_func($case, $string);
}
public static function sanitize_key($string, $replace_with = '_'): string
{
$string = remove_accents($string);
// Removes special chars with space
$string = preg_replace('/\W/', ' ', $string);
// Replacing multiple spaces with a single space
$string = preg_replace('!\s+!', ' ', $string);
// Trim Spaces
$string = trim($string);
// Replace space
$string = str_replace(' ', $replace_with, $string);
return strtolower($string);
}
public static function encrypt_decrypt($string = '', $encrypt_decrypt = 'e')
{
$output = null;
$secret_key = 'wbtZKk}rohV^Uw7V?+pgtNG++R2@hT3La.A)u*8+MK]-l?pM&,lfs{79SvXu/';
$secret_iv = 'w}W<<gj~+$S.TzRZ,=n*P@B{Ma{MnR(0baJ<zU|V7wCvl)&gC@4%+pth_-=|jRJo';
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if ($encrypt_decrypt === 'e') {
$output = base64_encode(openssl_encrypt($string, "AES-256-CBC", $key, 0, $iv)); // phpcs:ignore
} elseif ($encrypt_decrypt === 'd') {
$output = openssl_decrypt(base64_decode($string), "AES-256-CBC", $key, 0, $iv); // phpcs:ignore
}
return $output;
}
public static function is_robot()
{
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field($_SERVER['HTTP_USER_AGENT']) : '';
if (!empty($user_agent)) {
return preg_match('/abacho|accona|AddThis|AdsBot|ahoy|AhrefsBot|AISearchBot|alexa|altavista|anthill|appie|applebot|arale|araneo|AraybOt|ariadne|arks|aspseek|ATN_Worldwide|Atomz|baiduspider|baidu|bbot|bingbot|bing|Bjaaland|BlackWidow|BotLink|bot|boxseabot|bspider|calif|CCBot|ChinaClaw|christcrawler|CMC\/0\.01|combine|confuzzledbot|contaxe|CoolBot|cosmos|crawler|crawlpaper|crawl|curl|cusco|cyberspyder|cydralspider|dataprovider|digger|DIIbot|DotBot|downloadexpress|DragonBot|DuckDuckBot|dwcp|EasouSpider|ebiness|ecollector|elfinbot|esculapio|ESI|esther|eStyle|Ezooms|facebookexternalhit|facebook|facebot|fastcrawler|FatBot|FDSE|FELIX IDE|fetch|fido|find|Firefly|fouineur|Freecrawl|froogle|gammaSpider|gazz|gcreep|geona|Getterrobo-Plus|get|girafabot|golem|googlebot|-google|grabber|GrabNet|griffon|Gromit|gulliver|gulper|hambot|havIndex|hotwired|htdig|HTTrack|ia_archiver|iajabot|IDBot|Informant|InfoSeek|InfoSpiders|INGRID\/0\.1|inktomi|inspectorwww|Internet Cruiser Robot|irobot|Iron33|JBot|jcrawler|Jeeves|jobo|KDD-Explorer|KIT-Fireball|ko_yappo_robot|label-grabber|larbin|legs|libwww-perl|linkedin|Linkidator|linkwalker|Lockon|logo_gif_crawler|Lycos|m2e|majesticsEO|marvin|mattie|mediafox|mediapartners|MerzScope|MindCrawler|MJ12bot|mod_pagespeed|moget|Motor|msnbot|muncher|muninn|MuscatFerret|MwdSearch|NationalDirectory|naverbot|NEC-MeshExplorer|NetcraftSurveyAgent|NetScoop|NetSeer|newscan-online|nil|none|Nutch|ObjectsSearch|Occam|openstat.ru\/Bot|packrat|pageboy|ParaSite|patric|pegasus|perlcrawler|phpdig|piltdownman|Pimptrain|pingdom|pinterest|pjspider|PlumtreeWebAccessor|PortalBSpider|psbot|rambler|Raven|RHCS|RixBot|roadrunner|Robbie|robi|RoboCrawl|robofox|Scooter|Scrubby|Search-AU|searchprocess|search|SemrushBot|Senrigan|seznambot|Shagseeker|sharp-info-agent|sift|SimBot|Site Valet|SiteSucker|skymob|SLCrawler\/2\.0|slurp|snooper|solbot|speedy|spider_monkey|SpiderBot\/1\.0|spiderline|spider|suke|tach_bw|TechBOT|TechnoratiSnoop|templeton|teoma|titin|topiclink|twitterbot|twitter|UdmSearch|Ukonline|UnwindFetchor|URL_Spider_SQL|urlck|urlresolver|Valkyrie libwww-perl|verticrawl|Victoria|void-bot|Voyager|VWbot_K|wapspider|WebBandit\/1\.0|webcatcher|WebCopier|WebFindBot|WebLeacher|WebMechanic|WebMoose|webquest|webreaper|webspider|webs|WebWalker|WebZip|wget|whowhere|winona|wlm|WOLP|woriobot|WWWC|XGET|xing|yahoo|YandexBot|YandexMobileBot|yandex|yeti|Zeus/i', $user_agent);
}
return false;
}
public static function get_ip_address(): string
{
// Array of potential IP headers in the order of priority
$headers = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
];
foreach ($headers as $header) {
if (isset($_SERVER[$header])) {
return sanitize_text_field($_SERVER[$header]);
}
}
return __('IP not found', 'divi-contact-form-helper');
}
public static function get_user_agent($agent = '')
{
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field($_SERVER['HTTP_USER_AGENT']) : null;
if (empty($user_agent)) {
return null;
}
$browser = __('Browser not found', 'divi-contact-form-helper');
$platform = __('Platforn not found', 'divi-contact-form-helper');
$user_browser = "";
if (false !== stripos($user_agent, "linux")) {
$platform = esc_html('linux');
} elseif (preg_match('/macintosh|mac os x/i', $user_agent)) {
$platform = esc_html('mac');
} elseif (preg_match('/windows|win32/i', $user_agent)) {
$platform = esc_html('windows');
}
if (false !== stripos($user_agent, "MSIE") && false === stripos($user_agent, "Opera")) {
$browser = esc_html('Internet Explorer');
$user_browser = esc_html('MSIE');
} elseif (false !== stripos($user_agent, "Firefox")) {
$browser = esc_html('Mozilla Firefox');
$user_browser = esc_html('Firefox');
} elseif (false !== stripos($user_agent, "Chrome")) {
$browser = esc_html('Google Chrome');
$user_browser = esc_html('Chrome');
} elseif (false !== stripos($user_agent, "Safari")) {
$browser = esc_html('Apple Safari');
$user_browser = esc_html('Safari');
} elseif (false !== stripos($user_agent, "Opera")) {
$browser = esc_html('Opera');
$user_browser = esc_html('Opera');
} elseif (false !== stripos($user_agent, "Netscape")) {
$browser = esc_html('Netscape');
$user_browser = esc_html('Netscape');
}
$known = ['Version', $user_browser, 'other'];
$pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (preg_match_all($pattern, $user_agent, $matches)) {
$i = count($matches['browser']);
if ($i !== 1) {
if (strripos($user_agent, 'Version') < strripos($user_agent, $user_browser)) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
$version = $matches['version'][0];
}
if ($version === null || $version === '') {
$version = '';
}
$data = [
'agent' => $user_agent,
'browser' => $browser,
'version' => $version,
'platform' => $platform,
];
if (!empty($agent) && isset($data[$agent])) {
return $data[$agent];
}
return $data;
}
return null;
}
public static function get_field_index($string): int
{
preg_match("|\d+|", $string, $match);
return $match[0] ?? '';
}
public static function maybe_unserialize($string)
{
$string = wp_specialchars_decode($string);
$unserialize_data = maybe_unserialize($string);
if (false === $unserialize_data) {
$string = preg_replace_callback('/s:(\d+):\"(.*?)\";/', static function ($matches) use ($string) {
if (isset($matches[2])) {
return "s:".strlen($matches[2]).':"'.$matches[2].'";';
}
return $string;
}, $string);
$unserialize_data = maybe_unserialize($string);
}
return $unserialize_data;
}
}