if (!$connection) { $dbColumns = column_name($table, config_get("db_database")); } else { $dbColumns = column_name_extended($table, "", ["connection" => $connection]); } if (array_is_valid($dbColumns)) { $ins = array(); foreach ($dbColumns as $k => $v) { if (array_key_exists($v, $data)) { $ins[$v] = $data[$v]; } } if (array_is_valid($ins)) { $data = $ins; $sql = "insert into $table "; $sql_insert = array(); foreach ($data as $k => $v) { $sql_insert['key'][] = $k; $sql_insert['value'][] = \App\CRUD::valueEscape($v, ["value_escape_type" => $options['value_escape_type'], "connection" => $connection]); } if (array_is_valid($sql_insert)) { $sql_col_key = ""; $sql_col_value = ""; if (array_is_valid($sql_insert['key'])) { foreach ($sql_insert['key'] as $k => $v) { $sql_col_key .= "`" . $v . "`" . ","; $sql_col_value .= "'" . $sql_insert['value'][$k] . "'" . ","; } } $sql_col_key = trim(rtrim($sql_col_key, ",")); $sql_col_value = trim(rtrim($sql_col_value, ",")); if (!empty($sql_col_key) && !empty($sql_col_value)) { $sql = $sql . "(" . $sql_col_key . ")" . " VALUES " . "(" . $sql_col_value . ")"; if (!$connection) { query_update($sql); return query_insert_id(); } else { query_update($sql, ["connection" => $connection]); return query_insert_id(["connection" => $connection]); } } } } } } return FALSE; } function query_last_insert_id() { $__connection = $GLOBALS['link']; $id = mysql_insert_id($__connection); return $id; } function query_insert($sql, $options = array()) { $query_rsdummy = $sql; $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $rsdummy = mysql_query($query_rsdummy, $__connection); $rid = mysql_insert_id(); if (is_numeric($rid)) { return $rid; } break; case "mysqli": $rsdummy = mysqli_query($__connection, $query_rsdummy); $rid = mysqli_insert_id($__connection); if (is_numeric($rid)) { return $rid; } break; } return FALSE; } function query_affected_rows($options = array()) { $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $id = mysql_affected_rows($__connection); if (is_numeric($id)) { return $id; } break; case "mysqli": $id = mysqli_affected_rows($__connection); if (is_numeric($id)) { return $id; } break; } return FALSE; } function query_insert_id($options = array()) { $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $rid = mysql_insert_id(); if (is_numeric($rid)) { return $rid; } break; case "mysqli": $rid = mysqli_insert_id($__connection); if (is_numeric($rid)) { return $rid; } break; } return FALSE; } function query_update($sql, $options = array()) { $query_rsdummy = $sql; $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $rsdummy = mysql_query($query_rsdummy, $__connection); if ($rsdummy !== FALSE) { return TRUE; } break; case "mysqli": $rsdummy = mysqli_query($__connection, $query_rsdummy); if ($rsdummy !== FALSE) { return TRUE; } break; } return FALSE; } function query_count($sql, $options = array()) { $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $result = mysql_query($sql, $__connection); $data = mysql_fetch_assoc($result); return $data; break; case "mysqli": $result = mysqli_query($__connection, $sql); $data = mysqli_fetch_assoc($result); return $data; break; } return FALSE; } function querynumrows($sql, $options = array()) { $__connection = $GLOBALS['connection']; if (isset($options['connection'])) { $__connection = $options['connection']; } $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $r = mysql_query($sql, $__connection); $data = mysql_num_rows($r); return $data; break; case "mysqli": $r = mysqli_query($__connection, $sql); $data = mysqli_num_rows($r); return $data; break; } return FALSE; } function querytorowarray($sql, $options = array()) { $data = querytoarray($sql, $options); if (isset($data['0'])) { return $data['0']; } return FALSE; } function querytoarray($sql, $options = array()) { $returned = query($sql, $options); if ($returned[2] > 0) { $__mysql_driver = config_get("mysql_driver"); switch ($__mysql_driver) { default: case "mysql": $dummy = array(); do { array_push($dummy, $returned[0]); } while ($returned[0] = mysql_fetch_assoc($returned[1])); return $dummy; break; case "mysqli": $dummy = array(); do { array_push($dummy, $returned[0]); } while ($returned[0] = mysqli_fetch_assoc($returned[1])); return $dummy; break; } } } /** * rtrim similar behaviour * * @param $subject * @param $search * @param string $replace * * @return mixedS */ function string_last_replace($subject, $search, $replace = "") { $pos = strrpos($subject, $search); if ($pos !== FALSE) { $subject = substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; } // Get string between function get_string_between($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } function link_encode($str) { $dummy = str_replace(" ", "-", $str); $dummy = str_replace("/", "+", $dummy); $dummy = str_replace("&", "%26", $dummy); $dummy = str_replace("'", "%27", $dummy); // $dummy = str_replace("'","`",$dummy); $dummy = strtolower($dummy); return $dummy; } function link_encode2($str) { $dummy = str_replace("/", "+", $str); $dummy = str_replace("&", "", $dummy); $dummy = str_replace("'", "", $dummy); $dummy = str_replace(",", "", $dummy); $dummy = str_replace(" ", " ", $dummy); $dummy = str_replace(" ", " ", $dummy); $dummy = str_replace(" ", "-", $dummy); $dummy = str_replace("---", "-", $dummy); $dummy = str_replace("--", "-", $dummy); // $dummy = str_replace("'","`",$dummy); $dummy = strtolower($dummy); return $dummy; } function division($a, $b) { if ($b == 0) return NULL; return $a / $b; } function comment_fingerprint_generate($str = "") { $str = trim($str); $str = strtolower($str); $str = preg_replace("/[^a-zA-Z0-9]+/", "", $str); if (function_exists("sha1")) { $str = sha1($str); } return $str; } function link_decode($str) { $dummy = str_replace("-", " ", $str); $dummy = str_replace("-County", "", $dummy); //$dummy = str_replace("-","/",$dummy); $dummy = str_replace("%26", "&", $dummy); $dummy = str_replace("+", "/", $dummy); $dummy = str_replace("'", "%27", $dummy); //$dummy = str_replace("`","'",$dummy); $dummy = ucwords($dummy); //print "---$dummy---"; return $dummy; } function listing_viewdetail_request_store($data = array()) { if (array_is_valid($data)) { $ins = array(); $keys_valid = array("name", "first_name", "last_name", "email", "zipcode", "phone", "surl", "ip", "listing_id", "domain", "table", "type", "cat", "category", "city", "state"); foreach ($keys_valid as $k => $v) { if (isset($data[$v])) { $ins[$v] = $data[$v]; } } $keys_required = array("name", "first_name", "last_name", "email", "zipcode", "phone", "listing_id", "domain", "table"); if (array_is_valid($keys_required)) { foreach ($keys_required as $k => $v) { if (!isset($ins[$v])) { return FALSE; } } } $keys_not_empty = array("listing_id", "domain", "table"); if (array_is_valid($keys_not_empty)) { foreach ($keys_not_empty as $k => $v) { if (empty($ins[$v])) { return FALSE; } } } if (array_is_valid($ins)) { $skip_ids = session_get("lvd.skip_ids"); if (!array_is_valid($skip_ids)) { $skip_ids = array(); } if (!in_array($ins['listing_id'], $skip_ids)) { $sql = "insert into q_listing_viewdetail_request (`name`,first_name,last_name,email,zipcode,phone,surl,ip,listing_id,domain,`table`,`type`,cdate,cat,category,city,state) values ('{name}','{first_name}','{last_name}','{email}','{zipcode}','{phone}','{surl}','{ip}','{listing_id}','{domain}','{table}','{type}','{cdate}','{cat}','{category}','{city}','{state}')"; $sql = str_replace("{name}", $ins['name'], $sql); $sql = str_replace("{first_name}", $ins['first_name'], $sql); $sql = str_replace("{last_name}", $ins['last_name'], $sql); $sql = str_replace("{email}", $ins['email'], $sql); $sql = str_replace("{zipcode}", $ins['zipcode'], $sql); $sql = str_replace("{phone}", $ins['phone'], $sql); $sql = str_replace("{surl}", $ins['surl'], $sql); $sql = str_replace("{ip}", $ins['ip'], $sql); $sql = str_replace("{listing_id}", $ins['listing_id'], $sql); $sql = str_replace("{domain}", $ins['domain'], $sql); $sql = str_replace("{table}", $ins['table'], $sql); $sql = str_replace("{type}", $ins['type'], $sql); $sql = str_replace("{cat}", $ins['cat'], $sql); $sql = str_replace("{category}", $ins['category'], $sql); $sql = str_replace("{city}", $ins['city'], $sql); $sql = str_replace("{state}", $ins['state'], $sql); $sql = str_replace("{cdate}", mysql_now(), $sql); $rid = query_insert($sql); if (!empty($rid)) { $storeLocalData = array(); $storeLocalData['name'] = $ins['name']; $storeLocalData['first_name'] = $ins['first_name']; $storeLocalData['last_name'] = $ins['last_name']; $storeLocalData['email'] = $ins['email']; $storeLocalData['zipcode'] = $ins['zipcode']; $storeLocalData['phone'] = $ins['phone']; session_set("lvd.data", $storeLocalData); session_set("lvd.already", TRUE); $skip_ids[] = $ins['listing_id']; session_set("lvd.skip_ids", $skip_ids); return $rid; } } return TRUE; } } return FALSE; } function ValidateEmail($value) { $regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i'; if ($value == '') { return FALSE; } else { $string = preg_replace($regex, '', $value); } return empty($string) ? TRUE : FALSE; } function mysql_now() { return date('Y-m-d H:i:s'); } function url_is_amp($url = "") { if (!empty($url)) { $parts = parse_url($url); $path = rtrim($parts['path'], "/"); $path_array = explode("/", $path); $path_array = array_values($path_array); $path_last = end($path_array); $path_last = strtolower($path_last); $is_amp_request = ($path_last == "amp") ? TRUE : FALSE; return $is_amp_request; } return FALSE; } function url_is_absolute($url) { $pattern = "/^(?:ftp|https?|feed)?:?\/\/(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)* (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@)?(?: (?:[a-z0-9\-\.]|%[0-9a-f]{2})+|(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]))(?::[0-9]+)?(?:[\/|\?] (?:[\w#!:\.\?\+\|=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})*)?$/xi"; return (bool)preg_match($pattern, $url); } function url_certainly_absolute($url = "", $host = "") { if (!url_is_absolute($url)) { $host = rtrim($host, "/") . "/"; $url = ltrim($url, "/"); $url = $host . $url; } return $url; } function current_url_to_amp() { $url = current_url_extended(); if (!url_is_amp($url)) { $parts = parse_url($url); $path = rtrim($parts['path'], "/") . "/amp/"; $url = $parts['scheme'] . "://" . $parts['host'] . $path . $parts['query']; } return $url; } function current_url_to_noamp() { $url = current_url_extended(); if (url_is_amp($url)) { $parts = parse_url($url); $path = rtrim(rtrim($parts['path'], "/"), "/amp"); $url = $parts['scheme'] . "://" . $parts['host'] . $path . $parts['query']; } return $url; } function url_to_amp($url) { $parts = parse_url($url); $path = rtrim(rtrim($parts['path'], "/"), "/amp") . "/amp/"; $join_arr = array(); if (!empty($parts['scheme'])) { $join_arr[] = $parts['scheme'] . "://"; } if (!empty($parts['host'])) { $join_arr[] = $parts['host']; } if (!empty($path)) { $join_arr[] = $path; } if (!empty($parts['query'])) { $join_arr[] = $parts['query']; } $url = implode("", $join_arr); return $url; } function url_to_amp_none($url) { $parts = parse_url($url); $path = rtrim(rtrim($parts['path'], "/"), "/amp"); $join_arr = array(); if (!empty($parts['scheme'])) { $join_arr[] = $parts['scheme'] . "://"; } if (!empty($parts['host'])) { $join_arr[] = $parts['host']; } if (!empty($path)) { $join_arr[] = $path; } if (!empty($parts['query'])) { $join_arr[] = $parts['query']; } $url = implode("", $join_arr); return $url; } function adset_get_item($adset = "", $type = "") { if (!empty($type) && !empty($adset)) { $type = rtrim($type, ".php") . ".php"; $path = __DIR__ . "/template/common/adsets/" . $adset . "/" . $type; if (file_exists($path)) { include($path); } } return FALSE; } function is_valid_phone($str) { $str = preg_replace("/[^0-9]/", "", $str); $str = ltrim($str, "1"); if (strlen($str) != 10) { return FALSE; } return TRUE; } function ensure_storage_path_writable() { if (!is_storage_path_writable()) { $chmod = "0777"; mkdir(WEBROOTPATH . "/storage/", octdec($chmod), TRUE); chmod(WEBROOTPATH . "/storage/", octdec($chmod)); } return TRUE; } function is_storage_path_writable() { return is_directory_writable(WEBROOTPATH . "/storage/"); } function is_directory_writable_extended($dir) { if (empty($dir)) { return FALSE; } $dir = rtrim($dir, "/") . "/"; // try to create this directory if it doesn't exist $booExists = is_dir($dir) || (mkdir($dir, 0777, TRUE) && is_dir($dir)); $booIsWritable = FALSE; if ($booExists && is_writable($dir)) { $tempFile = tempnam($dir, 'tmp'); if ($tempFile !== FALSE) { $res = file_put_contents($tempFile, 'test'); $booIsWritable = $res !== FALSE; @unlink($tempFile); } } return $booIsWritable; } function is_directory_writable($dir = "") { if (empty($dir)) { return FALSE; } if (is_dir($dir) && is_writable($dir)) { return TRUE; } return FALSE; } function is_valid_date($date, $format = 'Y-m-d') { $f = DateTime::createFromFormat($format, $date); $valid = DateTime::getLastErrors(); return ($valid['warning_count'] == 0 and $valid['error_count'] == 0); } function is_valid_zipcode($str, $options = array()) { switch ($options['type']) { default: if (!empty($str)) { return TRUE; } break; case "us": $str = filter_var($str, FILTER_SANITIZE_NUMBER_INT); if (!empty($str)) { if (strlen($str) == 4 || strlen($str) == 5) { return TRUE; } } break; } return FALSE; } function is_valid_first_name($str) { if (!empty($str)) { return TRUE; } return FALSE; } function is_valid_last_name($str) { if (!empty($str)) { return TRUE; } return FALSE; } function is_spam_keyword($str = "") { $spam = ""; $str = strtolower($str); $spam_arr = querytoarray("select * from spam_keywords"); if (array_is_valid($spam_arr)) { foreach ($spam_arr as $ispam) { if (strlen(strstr($str, strtolower($ispam['keyword']))) > 0) { $spam .= "spam"; } } } if (!empty($spam)) { return FALSE; } return TRUE; } function is_valid_email($str) { if (!empty($str)) { return ValidateEmail($str); } return FALSE; } function is_valid_money($number) { if (is_null($number)) { return FALSE; } return preg_match("/^-?[0-9]+(?:\.[0-9]{1,2})?$/", $number); } function is_valid_percentage($number) { if (is_numeric($number)) { return FALSE; } if ($number >= 0 && $number <= 100) { return TRUE; } return FALSE; } function number_certainly($number) { $number = preg_replace("/[^0-9\.]/", "", $number); return $number; } function custom_include_get_item($type = "") { if (!empty($type)) { $data = config_site_get("", "template_include"); if (isset($data[$type])) { $file = ltrim($data[$type], "/"); $path = BOOTSTRAPPATH . "/" . $file; if (file_exists($path)) { include($path); } } } return FALSE; } function render_html_view($file = "", $data = array(), $options = []) { if (empty($file)) { return FALSE; } if (file_exists($file) && is_file($file)) { ob_start(); $__renderData = (array_is_valid($data)) ? $data : []; include($file); $html = ob_get_contents(); ob_end_clean(); return $html; } return FALSE; } function custom_domain_view_include($file = "", $options = array()) { if (!empty($file)) { $filePathData = pathinfo($file); if (empty($filePathData['extension'])) { $file = $file . ".php"; } $path = WEBROOTPATH . "/custom/" . domain_certainly(__domainCertainly()) . "/" . $file; $path_common = WEBROOTPATH . "/custom/" . "*" . "/" . $file; if (array_key_exists("template", $options)) { $path = WEBROOTPATH . "/custom/" . domain_certainly(__domainCertainly()) . "/" . $options['template'] . "/" . $file; } $data = $options['data']; if (file_exists($path)) { ob_start(); $__renderHtmlData = $data; include($path); $html = ob_get_contents(); ob_end_clean(); echo $html; return TRUE; } if (file_exists($path_common) && $options['skip_common'] !== TRUE) { ob_start(); $__renderHtmlData = $data; include($path_common); $html = ob_get_contents(); ob_end_clean(); echo $html; return TRUE; } if (!empty($options['default']) && file_exists($options['default'])) { ob_start(); $__renderHtmlData = $data; include($options['default']); $html = ob_get_contents(); ob_end_clean(); echo $html; return TRUE; } return FALSE; } } function href_to_amp($html) { $a = new SimpleXMLElement($html); $href = (string)$a['href']; $anchor = (string)$a[0]; $href = url_to_amp($href); $html = '' . $anchor . ''; return $html; } function current_url_extended() { $scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https'; $url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; return $url; } function current_host_extended() { $scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https'; $url = $scheme . '://' . $_SERVER['HTTP_HOST'] . "/"; return $url; } function validate_ip($ip) { if (strtolower($ip) === 'unknown') return FALSE; // generate ipv4 network address $ip = ip2long($ip); // if the ip is set and not equivalent to 255.255.255.255 if ($ip !== FALSE && $ip !== -1) { // make sure to get unsigned long representation of ip // due to discrepancies between 32 and 64 bit OSes and // signed numbers (ints default to signed in PHP) $ip = sprintf('%u', $ip); // do private network range checking if ($ip >= 0 && $ip <= 50331647) return FALSE; if ($ip >= 167772160 && $ip <= 184549375) return FALSE; if ($ip >= 2130706432 && $ip <= 2147483647) return FALSE; if ($ip >= 2851995648 && $ip <= 2852061183) return FALSE; if ($ip >= 2886729728 && $ip <= 2887778303) return FALSE; if ($ip >= 3221225984 && $ip <= 3221226239) return FALSE; if ($ip >= 3232235520 && $ip <= 3232301055) return FALSE; if ($ip >= 4294967040) return FALSE; } return TRUE; } function cookie_get_safe($name) { $key = $name; $value = array_key_exists($key, $_COOKIE) ? json_decode(base64_decode($_COOKIE[$key])) : NULL; if ($value == NULL) { return FALSE; } return $value; } function cookie_set_safe($name, $value, $expiration = 0, $domain = '') { $enc = base64_encode(json_encode($value)); return cookie_set($name, $enc, $expiration, '/', $domain); } function cookie_set($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE) { $_COOKIE[$name] = $value; if (!empty($expire)) { $expire = time() + $expire; } return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); } function cookie_delete($name, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE) { $value = time() - 1314000; $_COOKIE[$name] = $value; return setcookie($name, '', $value, $path, $domain, $secure, $httponly); } function session_init($id = "") { if (session_status() == PHP_SESSION_NONE) { if (!empty($id)) { session_id($id); } session_start(); } return TRUE; } function session_set($key = "", $value = "") { session_init(); if (empty($key)) { return FALSE; } $_SESSION[$key] = json_encode($value); return TRUE; } function session_id_get() { session_init(); return session_id(); } function session_get($key = "") { session_init(); if (empty($key)) { return FALSE; } $data = isset($_SESSION[$key]) ? json_decode($_SESSION[$key], TRUE) : NULL; return $data; } function session_delete($key = "") { session_init(); if (empty($key)) { return FALSE; } unset($_SESSION[$key]); return TRUE; } function get_ip_address() { // check cloudflare // Try to use Enable Pseudo IPv4 on CF. If client use IPv6 it will be in Cf-Connecting-IPv6 header. if (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) && validate_ip($_SERVER['HTTP_X_FORWARDED'])) { $ip = $_SERVER["HTTP_CF_CONNECTING_IP"]; $ip = \App\Helpers\IPHelper::ensureIPv4($ip); return $ip; } // check for shared internet/ISP IP if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; $ip = \App\Helpers\IPHelper::ensureIPv4($ip); return $ip; } // check for IPs passing through proxies if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // check if multiple ips exist in var if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== FALSE) { $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); foreach ($iplist as $ip) { if (validate_ip($ip)) return $ip; } } else { if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR'])) return $_SERVER['HTTP_X_FORWARDED_FOR']; } } if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED'])) return $_SERVER['HTTP_X_FORWARDED']; if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) return $_SERVER['HTTP_FORWARDED_FOR']; if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED'])) return $_SERVER['HTTP_FORWARDED']; // return unreliable ip since all else failed return $_SERVER['REMOTE_ADDR']; } function listing_get_detail($id = "", $options = array()) { if (empty($id)) { return FALSE; } $precheck = TRUE; if (!isset($options['x_table'])) { $precheck = FALSE; } if ($precheck) { $x_table = set_value_of($options['x_table'], $options['table']); $x_table_data = $x_table . "_data"; $data = querytorowarray("select * from `$x_table_data`" . " where id='$id' limit 1"); if (array_is_valid($data)) { $_options_format = array(); if (isset($options['cat'])) { $_options_format['cat'] = $options['cat']; } if (isset($options['category'])) { $_options_format['category'] = $options['category']; } if (isset($options['current_city'])) { $_options_format['current_city'] = $options['current_city']; } if (isset($options['current_state'])) { $_options_format['current_state'] = $options['current_state']; } if (isset($options['current_country'])) { $_options_format['current_country'] = $options['current_country']; } if (isset($options['current_longitude'])) { $_options_format['current_longitude'] = $options['current_longitude']; } if (isset($options['current_latitude'])) { $_options_format['current_latitude'] = $options['current_latitude']; } if (isset($options['address_formatter'])) { $_options_format['address_formatter'] = $options['address_formatter']; } $_options_format['table'] = $x_table; $data = __format_listing_item_data($data, $_options_format); return $data; } } return FALSE; } function url_title($str, $separator = 'dash', $lowercase = FALSE) { if ($separator == 'dash') { $search = '_'; $replace = '-'; } else { $search = '-'; $replace = '_'; } $trans = array( '&\#\d+?;' => '', '&\S+?;' => '', '\s+' => $replace, '\.' => $replace, '[^a-z0-9\-_]' => '', $replace . '+' => $replace, $replace . '$' => $replace, '^' . $replace => $replace, '\.+$' => '', ); $str = strip_tags($str); foreach ($trans as $key => $val) { $str = preg_replace("#" . $key . "#i", $val, $str); } if ($lowercase === TRUE) { $str = strtolower($str); } return trim(stripslashes($str), $replace); } function url_state_generate($options = array()) { $url_mapping = url_mapping_get(GeneralEnum::URL_MAPPING_TYPE_S); switch ($options['type']) { default: $href = "/" . $url_mapping . "/" . link_encode($options['state']) . "/" . link_encode($options['subcat_slug']); $text = $options['text']; break; case "301edback": $href = "/" . $url_mapping . "/" . link_encode($options['state']) . "/" . link_encode($options['subcat_slug']); $text = $options['text']; break; case "mainkeyword": $href = "/" . $url_mapping . "/" . link_encode($options['state']) . "/" . link_encode($options['main_keyword']) . "/" . link_encode($options['subcat_slug']); $text = $options['text']; break; case "sitemap": $href = "/" . $url_mapping . "/" . link_encode($options['state']) . "/" . $options['subcat_slug']; $text = $options['text']; break; case "sitemap_301": $href = "/" . $url_mapping . "/" . link_encode($options['state']) . "/" . $options['other']; $text = $options['text']; break; } if ($options['return_type'] == "href") { return $href; } if ($options['return_type'] == "text") { return $text; } $link = "" . $text . ""; return $link; } function url_cityorcounty_generate($options = array()) { return url_city_generate($options); } function url_categories_generate($options = array()) { return url_city_generate($options); } function url_geo_generate($options = array()) { return url_city_generate($options); } function url_tos_generate($options = array()) { $url_mapping = url_mapping_get(GeneralEnum::URL_MAPPING_TYPE_TOS); $href = "/" . $url_mapping; $text = "TOS"; if ($options['return_type'] == "href") { return $href; } if ($options['return_type'] == "text") { return $text; } $link = "" . $text . ""; return $link; } function url_privacypolicy_generate($options = array()) { $url_mapping = url_mapping_get(GeneralEnum::URL_MAPPING_TYPE_PRIVACY_POLICY); $href = "/" . $url_mapping; $text = "Privacy"; if ($options['return_type'] == "href") { return $href; } if ($options['return_type'] == "href_full") { $domain = (!empty($options['domain'])) ? $options['domain'] : __rm_step_thankyou_content_below'] = "settings_contact_form_step_thankyou_content_below"; $keys['enabled_fields']['settings_contact_form_above_contact_button'] = "settings_contact_form_above_contact_button"; $keys['enabled_fields']['settings_footer_below_content'] = "settings_footer_below_content"; $keys['enabled_fields']['listing_skip_claim'] = "listing_skip_claim"; $keys['enabled_fields']['listing_skip_delete'] = "listing_skip_delete"; $keys['enabled_fields']['category_only_mode'] = "category_only_mode"; $keys['enabled_fields']['phone_only_mode'] = "phone_only_mode"; $keys['enabled_fields']['single_category_mode'] = "single_category_mode"; $keys['enabled_fields']['single_category_geotarget_shortlink'] = "single_category_geotarget_shortlink"; $keys['enabled_fields']['locations_other_geopage'] = "locations_other_geopage"; $keys['enabled_fields']['location_finder'] = "location_finder"; $keys['enabled_fields']['skip_c_301_all_domains_listing'] = "skip_c_301_all_domains_listing"; $keys['enabled_fields']['skip_geo_content'] = "skip_geo_content"; $keys['enabled_fields']['c_301_all_domains_listing_type'] = "c_301_all_domains_listing_type"; $keys['enabled_fields']['geotable_simulated_content'] = "geotable_simulated_content"; $keys['enabled_fields']['geotable_simulated_content_skip_state'] = "geotable_simulated_content_skip_state"; $keys['enabled_fields']['phone_buyer_enabled'] = "phone_buyer_enabled"; $keys['enabled_fields']['phone_working_hours'] = "phone_working_hours"; $keys['enabled_fields']['url_mapping'] = "url_mapping"; $keys['enabled_fields']['homeadvisor_enabled'] = "homeadvisor_enabled"; $keys['enabled_fields']['contact_form_type'] = "contact_form_type"; $keys['enabled_fields']['contact_form_tcpa_location'] = "contact_form_tcpa_location"; $keys['enabled_fields']['contact_form_address_field_type'] = "contact_form_address_field_type"; $keys['enabled_fields']['contact_form_first_on_mobile'] = "contact_form_first_on_mobile"; $keys['enabled_fields']['trusted_form_enabled'] = "trusted_form_enabled"; $keys['enabled_fields']['donotsell_page_enabled'] = "donotsell_page_enabled"; $keys['enabled_fields']['facebook_pixel_id'] = "facebook_pixel_id"; $keys['enabled_fields']['gtag_id'] = "gtag_id"; $keys['enabled_fields']['image_upload_enabled'] = "image_upload_enabled"; $keys['enabled_fields']['skip_primary_navigation'] = "skip_primary_navigation"; $keys['enabled_fields']['angi_branding_type'] = "angi_branding_type"; $keys['forced_fields']['contact_form_type'] = "contact_form_type"; $__conf_data = array(); if (array_is_valid($domain_arr)) { $__options_skip = $options['skip']; if (array_is_valid($__options_skip)) { if (in_array("favicon", $__options_skip)) if (isset($domain_arr['settings_favicon_data'])) { unset($domain_arr['settings_favicon_data']); } if (in_array("logo", $__options_skip)) { if (isset($domain_arr['settings_logo_image_data'])) { unset($domain_arr['settings_logo_image_data']); } } if (in_array("color", $__options_skip)) { if (isset($domain_arr['color'])) { unset($domain_arr['color']); } } } if (isset($domain_arr['template'])) { $domain_arr['template'] = strtolower($domain_arr['template']); } $__enabled_fields = json_decode($domain_arr['enabled_fields'], TRUE); $__forced_fields = json_decode($domain_arr['forced_fields'], TRUE); unset($domain_arr['enabled_fields']); unset($domain_arr['forced_fields']); unset($domain_arr['cdate']); unset($domain_arr['udate']); foreach ($keys['forced_fields'] as $k => $v) { if ($__forced_fields[$k] == "1") { $__conf_data['site']['_forced_' . $k] = $domain_arr[$v]; } } foreach ($keys['enabled_fields'] as $k => $v) { if ($__enabled_fields[$k] != "1") { unset($domain_arr[$v]); } } if ($__enabled_fields['logo_url'] != "1") { unset($domain_arr['settings_logo_image_data']); unset($domain_arr['settings_logo_image_data_extension']); } if ($__enabled_fields['favicon_url'] != "1") { unset($domain_arr['settings_favicon_data']); } foreach ($keys['config_site'] as $k => $v) { if (isset($domain_arr[$v])) { $__conf_data['site'][$k] = $domain_arr[$v]; } } if (isset($__conf_data['site']['view'])) { $__conf_data['site']['view'] = json_decode($__conf_data['site']['view'], TRUE); if (!array_is_valid($__conf_data['site']['view'])) { $__conf_data['site']['view'] = array(); } } if (isset($__conf_data['site']['button_types'])) { $__conf_data['site']['button_types'] = json_decode($__conf_data['site']['button_types'], TRUE); if (!array_is_valid($__conf_data['site']['button_types'])) { $__conf_data['site']['button_types'] = array(); } } $__conf_data['site']['listing_skip_claim'] = (bool)$__conf_data['site']['listing_skip_claim']; $__conf_data['site']['listing_skip_delete'] = (bool)$__conf_data['site']['listing_skip_delete']; $__conf_data['site']['category_only_mode'] = (bool)$__conf_data['site']['category_only_mode']; $__conf_data['site']['phone_only_mode'] = (bool)$__conf_data['site']['phone_only_mode']; $__conf_data['site']['single_category_mode'] = (bool)$__conf_data['site']['single_category_mode']; $__conf_data['site']['single_category_geotarget_shortlink'] = (bool)$__conf_data['site']['single_category_geotarget_shortlink']; $__conf_data['site']['locations_other_geopage'] = (bool)$__conf_data['site']['locations_other_geopage']; $__conf_data['site']['location_finder'] = (bool)$__conf_data['site']['location_finder']; $__conf_data['site']['skip_c_301_all_domains_listing'] = (bool)$__conf_data['site']['skip_c_301_all_domains_listing']; $__conf_data['site']['skip_geo_content'] = (bool)$__conf_data['site']['skip_geo_content']; $__conf_data['site']['c_301_all_domains_listing_type'] = $__conf_data['site']['c_301_all_domains_listing_type']; $__conf_data['site']['c_301_all_domains_listing_type_data'] = json_decode($__conf_data['site']['c_301_all_domains_listing_type_data'], TRUE); $__conf_data['site']['geotable_simulated_content'] = (bool)$__conf_data['site']['geotable_simulated_content']; $__conf_data['site']['geotable_simulated_content_skip_state'] = (bool)$__conf_data['site']['geotable_simulated_content_skip_state']; $__conf_data['site']['phone_buyer_enabled'] = (bool)$__conf_data['site']['phone_buyer_enabled']; $__conf_data['site']['phone_working_hours'] = $__conf_data['site']['phone_working_hours']; $__conf_data['site']['homeadvisor_enabled'] = (bool)$__conf_data['site']['homeadvisor_enabled']; if (isset($__conf_data['site']['url_mapping'])) { $__conf_data['site']['url_mapping'] = json_decode($__conf_data['site']['url_mapping'], TRUE); if (!array_is_valid($__conf_data['site']['url_mapping'])) { $__conf_data['site']['url_mapping'] = array(); } } if (isset($__conf_data['site']['homeadvisor_task_mapping'])) { $__conf_data['site']['homeadvisor_task_mapping'] = json_decode($__conf_data['site']['homeadvisor_task_mapping'], TRUE); if (!array_is_valid($__conf_data['site']['homeadvisor_task_mapping'])) { $__conf_data['site']['homeadvisor_task_mapping'] = array(); } } if (isset($__conf_data['site']['content_groups_data'])) { $content_groups_data = json_decode($__conf_data['site']['content_groups_data'], TRUE); if (!array_is_valid($content_groups_data)) { $content_groups_data = array(); } $__enabled_fields_mapping = [ "cg_home_listing_type" => "home_listing_type", "cg_home_list_group_content_type" => "home_list_group_content_type", "cg_detail_list_group_content_type" => "detail_list_group_content_type", "cg_home_list_group_title" => "home_list_group_title", ]; foreach ($__enabled_fields_mapping as $k => $v) { if ($__enabled_fields[$k] != "1") { unset($content_groups_data[$v]); } } $__conf_data['site']['content_groups_data'] = $content_groups_data; } foreach ($keys['config_site_settings'] as $k => $v) { if (isset($domain_arr[$v])) { $__conf_data['site']['settings'][$k] = $domain_arr[$v]; } } if (isset($domain_arr['settings_favicon_data']) && !empty($domain_arr['settings_favicon_data'])) { $__conf_data['site']['settings']["favicon_data"] = $domain_arr['settings_favicon_data']; $__conf_data['site']['settings']["favicon_url"] = "/asset/favicon.ico"; } if (isset($domain_arr['settings_logo_image_data']) && !empty($domain_arr['settings_logo_image_data'])) { $__conf_data['site']['settings']["logo_image_data"] = $domain_arr['settings_logo_image_data']; $__conf_data['site']['settings']["logo_image_data_extension"] = $domain_arr['settings_logo_image_data_extension']; switch ($__conf_data['site']['settings']["logo_image_data_extension"]) { case "jpeg": case "jpg": default: $__conf_data['site']['settings']["logo_image_url"] = "/asset/logo.jpg"; break; case "gif": $__conf_data['site']['settings']["logo_image_url"] = "/asset/logo.gif"; break; case "png": $__conf_data['site']['settings']["logo_image_url"] = "/asset/logo.png"; break; } } if (isset($__conf_data['site']['listing_type'])) { if (!in_array($__conf_data['site']['listing_type'], array("normal", "viewbysubmit"))) { unset($__conf_data['site']['listing_type']); } } if (isset($__conf_data['site']['force_boot_type'])) { if (!in_array($__conf_data['site']['force_boot_type'], array("site", "master", "listing"))) { unset($__conf_data['site']['force_boot_type']); } } if (isset($__conf_data['site']['step_other_render_type'])) { if (!in_array($__conf_data['site']['step_other_render_type'], array("inline", "ajax", "standalone"))) { $__conf_data['site']['step_other_render_type'] = "standalone"; //unset($__conf_data['site']['step_other_render_type']); } } // We are overriding child lead render type to "standalone" as from 20200518 $__conf_data['site']['step_other_render_type'] = "standalone"; } if (array_is_valid($__conf_data)) { $data = $__conf_data; $instance[$instance_key] = $data; } } } return $instance[$instance_key]; } function remote_config_extend_for_301($domain = "") { if (empty($domain)) { return FALSE; } $options_extend = array(); $options_extend['skip'] = array("logo", "favicon", "color"); //dump_safe("Config Remote Extend For 301 :" . $domain); remote_config_extend($domain, $options_extend); } function remote_config_extend($domain = "", $options = array()) { if (SKIP_REMOTE_CONFIG !== TRUE) { //dump_safe("Config Remote Extend :" . $domain); $options_remote_config_get = array(); if (isset($options['skip'])) { $options_remote_config_get['skip'] = $options['skip']; } $data = remote_config_get($domain, $options_remote_config_get); if (array_is_valid($data)) { $_config_key = config_get_key(); $_config_site_key = config_site_get_key(); $__config = $GLOBALS['__config']; $__config_site = $GLOBALS['__config_site']; if (array_is_valid($data['site']) && !empty($__config_site)) { $__config_site[$_config_site_key] = array_merge_recursive_extended($__config_site[$_config_site_key], $data['site']); $GLOBALS['__config_site'] = $__config_site; } if (array_is_valid($data['env']) && !empty($_config_key)) { $__config[$_config_key] = array_merge_recursive_extended($__config[$_config_key], $data['env']); $GLOBALS['__config'] = $__config; } } } return TRUE; } function array_merge_recursive_extended(array &$array1, array &$array2) { $merged = $array1; foreach ($array2 as $key => &$value) { if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { $merged[$key] = array_merge_recursive_extended($merged[$key], $value); } else if (is_numeric($key)) { if (!in_array($value, $merged)) $merged[] = $value; } else $merged[$key] = $value; } return $merged; } function array_merge_certainly($array1 = array(), $array2 = array(), $type = "simple") { if (!is_array($array1)) { $array1 = array(); } if (!is_array($array2)) { $array2 = array(); } switch ($type) { case "simple" : default : $ret = array_merge($array1, $array2); break; case "extended" : $ret = array_merge_recursive_extended($array1, $array2); break; } return $ret; } function array_intersect_certainly($array1 = array(), $array2 = array()) { if (!is_array($array1)) { $array1 = array(); } if (!is_array($array2)) { $array2 = array(); } $ret = array_intersect($array1, $array2); return $ret; } function array_merge_certainly_with_keys($array1 = array(), $array2 = array()) { if (!is_array($array1)) { $array1 = array(); } if (!is_array($array2)) { $array2 = array(); } foreach ($array2 as $k => $v) { $array1[$k] = $v; } $ret = $array1; return $ret; } function sitemap_purge($domain = "") { if (empty($domain)) { return FALSE; } $cache_path = __DIR__ . "/storage/sitemap/"; $file_prefix = str_replace("-", "", url_title($domain)); $file_prefix_secure = "secure_" . $file_prefix; $files = directory_to_array_extendend($cache_path, FALSE); if (array_is_valid($files)) { $to_delete = array(); foreach ($files as $k => $v) { $__filename = $v; $__filepath = $cache_path . "/" . $v; if (is_file($__filepath) && str_starts_with($__filename, $file_prefix)) { $to_delete[] = $__filepath; } if (is_file($__filepath) && str_starts_with($__filename, $file_prefix_secure)) { $to_delete[] = $__filepath; } } } if (array_is_valid($to_delete)) { foreach ($to_delete as $k => $v) { @unlink($v); } } return TRUE; } function sitemap_purge_all() { $cache_path = __DIR__ . "/storage/sitemap/"; $files = directory_to_array_extendend($cache_path, FALSE); if (array_is_valid($files)) { $to_delete = array(); foreach ($files as $k => $v) { $__filename = $v; $__filepath = $cache_path . "/" . $v; if (is_file($__filepath) && !in_array($__filename, ['.keepme', 'index.html'])) { $to_delete[] = $__filepath; } } } if (array_is_valid($to_delete)) { foreach ($to_delete as $k => $v) { @unlink($v); } } return TRUE; } function domain_certainly($domain = "") { $domain = trim($domain); $arr = parse_url($domain); if (array_is_valid($arr) && isset($arr['host'])) { $data = trim($arr['host']); $data = strtolower($data); $data = str_replace("www.", "", $data); return $data; } else { $domain = strtolower($domain); $domain = str_replace("www.", "", $domain); return $domain; } } function sitemap_output_type() { /** * Valid values are "gz" or "" (empty); */ return "gz"; } function isGeoContentDisabled() { if (config_site_get("", "geotable_simulated_content") === TRUE) { return FALSE; } if (config_site_get("", "skip_geo_content") === TRUE) { return TRUE; } return FALSE; } function isShowcaseEnabled($type = "", $options = []) { $status = TRUE; switch ($type) { default: break; case "home": $status = TRUE; switch ($options['build_type']) { case GeneralEnum::BUILD_TYPE_CITY: $status = FALSE; break; } break; case "d": $status = FALSE; break; case "c": $status = FALSE; break; case "i": $status = FALSE; break; case "s": $status = FALSE; break; case "g": $status = TRUE; break; case "custom_page": $status = TRUE; break; } return $status; } function isReviewsEnabled($type = "") { // Reviews are enabled on levels - Requested on 20230116 return TRUE; $status = TRUE; switch ($type) { default: break; case "home": $status = TRUE; break; case "d": $status = FALSE; break; case "c": $status = FALSE; break; case "i": $status = FALSE; break; case "s": $status = FALSE; break; case "g": $status = TRUE; break; case "custom_page": $status = TRUE; break; } return $status; } /** * Do not refactor this since it might be used in /public_html/custom/ pages * @return bool|null * */ function isTcpaLogEnabled() { return \App\Support\ConfigRuntime::isTcpaLogEnabled(); } function isFaqEnabled($type = "") { // Reviews are enabled on levels - Requested on 2024052 return TRUE; $status = TRUE; switch ($type) { default: break; case "home": $status = TRUE; break; case "d": $status = FALSE; break; case "c": $status = FALSE; break; case "i": $status = FALSE; break; case "s": $status = FALSE; break; case "g": $status = TRUE; break; case "custom_page": $status = TRUE; break; } return $status; } function isProductsEnabled($type = "") { $status = TRUE; switch ($type) { default: $status = FALSE; break; case "home": $status = FALSE; break; case "d": $status = FALSE; break; case "c": $status = FALSE; break; case "i": $status = FALSE; break; case "s": $status = FALSE; break; case "g": $status = FALSE; break; case "custom_page": $status = TRUE; break; } return $status; } function isBotRateEnabled() { return TRUE; } function botRateLimitPurge() { // We are not checking if enabled cause we may disabled it but there can still be files on the system after disabled /* if (!isBotRateEnabled()) { return FALSE; } */ try { ob_start(); $path = WEBROOTPATH . "/storage/ratelimit"; $stashDriver = new \Stash\Driver\FileSystem(['path' => $path]); $stashDriver->purge(); ob_end_clean(); return TRUE; } catch (\Exception $e) { //dump($e->getMessage()); } return FALSE; } function redisServerConnect() { static $instance; try { $connect = FALSE; if (is_null($instance)) { $connect = TRUE; } else if ($instance instanceof \Predis\Client && $instance->isConnected() !== TRUE) { $connect = TRUE; } if ($connect) { $predis = new \Predis\Client(array( 'scheme' => 'tcp', 'host' => '108.62.123.155', 'port' => 6379, ), array( 'parameters' => [ 'password' => "ZmnrNMQM8tCjCCytZPPhypqk", 'database' => 2, ], )); $predis->connect(); $instance = $predis; } } catch (\Exception $e) { $instance = FALSE; } if ($instance) { return $instance; } return FALSE; } function botRateLimitGetAdapter($type = "") { try { switch ($type) { case "redis": $predis = redisServerConnect(); if ($predis) { $adapter = new \App\RateLimit\Adapter\Predis($predis); } break; case "filesystem": $path = WEBROOTPATH . "/storage/ratelimit"; $stashDriver = new \Stash\Driver\FileSystem(['path' => $path]); $stash = new \Stash\Pool($stashDriver); $adapter = new \App\RateLimit\Adapter\Stash($stash); break; } } catch (\Exception $e) { switch ($type) { case "redis": reportToDev("cannotConnectToRedis"); break; case "filesystem": if ($e->getMessage() == "Failed to create cache path.") { reportToDev("storageFolderNotWriteable"); } break; } } if ($adapter) { return $adapter; } return FALSE; } function botRateLimitCheck($options = []) { if (!isBotRateEnabled()) { return FALSE; } try { $maxRequestLimit = 20; // In seconds; $maxRequestTTL = 120; switch ($options['type']) { case "asset": case "photo": // Enable this if we need to rate limit image requests break; } $adapter = botRateLimitGetAdapter("redis"); if (!$adapter) { $adapter = botRateLimitGetAdapter("filesystem"); } if ($adapter) { $rateLimit = new \App\RateLimit\RateLimit("geoclientRateLimit", $maxRequestLimit, $maxRequestTTL, $adapter); $id = $ip = get_ip_address(); //$leftRate = $rateLimit->getAllowance($id); //$rate = $rateLimit->getCurrent($id); if ($rateLimit->check($id)) { // Rate passed } else { // Rate Limit Exceeded $conn = db_connect_origin(); if ($conn) { $agent = $_SERVER['HTTP_USER_AGENT']; $mysqlNow = $maxRequestDate = mysql_now(); $domain = domain_certainly(__domainCertainly()); $domainIP = $_SERVER['SERVER_ADDR']; $q = "insert into bots_rate_checker (`ip`,`agent`,`domain`,`maxrequest_date`,`maxrequest_limit`,`maxrequest_ttl`,`status`,`domain_ip`) values ('$ip','$agent','$domain','$maxRequestDate','$maxRequestLimit','$maxRequestTTL','idle','$domainIP') on duplicate key update `maxrequest_date`='$mysqlNow', `domain`='$domain', `domain_ip`='$domainIP' , cycle_count = cycle_count + 1 "; query_update($q, ['connection' => $conn]); $rateLimit->purge($id); // This may cause load when there are multiple checks need to be made. $checkImmediately = TRUE; if ($checkImmediately) { api_call(array("action" => "bots_check_immediately", "ip" => $ip)); } } } } } catch (\Exception $e) { } } function db_connect_origin() { static $instance; if (is_null($instance)) { $username = "refresh_meg"; $password = "cmaster13"; $database = "refresh_geo"; $hostname = "64.64.7.147"; $conn = db_connect($hostname, $username, $password, $database); if (!$conn) { //Unable to select database $conn = NULL; } $instance = $conn; } return $instance; } function db_connect_data01mail() { static $instance; if (is_null($instance)) { $conn = NULL; $instance = $conn; } return $instance; } function current_conn_id() { static $instance; if (is_null($instance)) { $instance = FALSE; $db_hostname = config_get("db_hostname"); $db_username = config_get("db_username"); $db_database = config_get("db_database"); $conn = db_connect_origin(); if ($conn) { // Exit on malicious bots $q = "select id from c_conn where database_user='$db_username' and database_ip='$db_hostname' and database_database='$db_database' limit 1"; $current = querytorowarray($q, ["connection" => $conn]); if (!empty($current['id'])) { $instance = $current['id']; } } } return $instance; } function header_503() { header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 300'); } function maintenance_output() { header_503(); echo "

Site is temporarily unavailable.

"; echo "

Scheduled maintenance is currently in progress. Please check back soon.

"; echo "

We apologize for any inconvenience.

"; exit(); } function maintenance_check_contact_form() { /* if (maintenance_is()) { return TRUE; } */ return FALSE; } function maintenance_check_site() { /* if (maintenance_is()) { maintenance_output(); } */ return FALSE; } function maintenance_is() { /* $config = config_get_all(); if (trim($config['db_hostname']) == "216.38.63.204") { return TRUE; } */ return FALSE; } function needLongProcess() { set_time_limit(0); ini_set('memory_limit', '-1'); ini_set('max_execution_time', 36000); } function badRequestDisable($category_arr) { // This check is moved to .htaccess return TRUE; if (!$category_arr || empty($category_arr[0])) { return TRUE; } $last = trim(end($category_arr)); if (!empty($last)) { $last = strtolower($last); $pool = ["wlwmanifest.xml", "administrator", "wp-login.php", "xmlrpc.php", "wp", "wordpress"]; if (in_array($last, $pool)) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit(); } } return TRUE; } function badReferrerDisable() { // Disabled on 2024-04-18 return TRUE; $spam_url = $_SERVER['HTTP_REFERER']; if (strlen(strstr($spam_url, "best-seo-offer.com")) > 0) { exit; } if (strlen(strstr($spam_url, "buttons-for-your-website.com")) > 0) { exit; } if (strlen(strstr($spam_url, "100dollars-seo.com")) > 0) { exit; } if (strlen(strstr($spam_url, "semaltmedia.com")) > 0) { exit; } if (strlen(strstr($spam_url, "videos-for-your-business.com")) > 0) { exit; } if (strlen(strstr($spam_url, "success-seo.com")) > 0) { exit; } if (strlen(strstr($spam_url, "video--production.com")) > 0) { exit; } if (strlen(strstr($spam_url, "rankings-analytics.com")) > 0) { exit; } return TRUE; } function badBotDisable() { $ip = get_ip_address(); if (empty($ip)) { return FALSE; } $ipWhitelist = ["64.64.18.65", "199.102.224.28", "199.102.224.35", "199.102.225.23", "192.168.10.1"]; //$ipWhitelist = ["64.64.18.65", "199.102.224.28", "199.102.224.35", "199.102.225.23"]; if (in_array($ip, $ipWhitelist)) { return FALSE; } //$ipDirectBan = ["41.36.77.144"]; $ipDirectBan = []; if ($ipDirectBan) { if (in_array($ip, $ipDirectBan)) { exit(); } } $skipCheckRedis = FALSE; $skipCheckDatabase = FALSE; if ($skipCheckRedis !== TRUE) { $predis = redisServerConnect(); if ($predis) { $key = "geoClientBadBots"; //$sMembers =$predis->smembers($key); if ($predis->scard($key) * 1 > 0) { $skipCheckDatabase = TRUE; $statusRedisExists = $predis->sismember($key, $ip); if ($statusRedisExists * 1 == "1") { exit(); } } } } if ($skipCheckDatabase !== TRUE) { $conn = db_connect_origin(); if ($conn) { // Exit on malicious bots $q = "select ip from bots where ip='$ip' and blocked='1' limit 1"; $current = querytorowarray($q, ["connection" => $conn]); if (!empty($current['ip'])) { exit(); } } } $agent = $_SERVER['HTTP_USER_AGENT']; $agent_lower = strtolower($agent); // mozilla/5.0 (linux; android 7.0; frd-al00 build/huaweifrd-al00; wv) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/53.0.2785.49 mobile mqqbrowser/6.2 tbs/043602 safari/537.36 micromessenger/6.5.16.1120 nettype/wifi language/zh_cn $checkLanguageOnAgent = [";zh-cn;", ";zh_cn;", "/zh_cn"]; foreach ($checkLanguageOnAgent as $k => $v) { if (strlen(strstr($agent_lower, $v)) > 0) { //reportToDev("ipData", ["data" => ["type" => "locale", "acceptLanguage" => httpAcceptLanguage(), "domain" => __domainCertainly(), "ip" => $ip, "agent" => $agent_lower]]); exit(); } } $blockAgents = [ "mqqbrowser" => ["blocked" => "1", "skipSave" => TRUE], "qqbrowser" => ["blocked" => "1", "skipSave" => TRUE], "liebaofast" => ["blocked" => "1", "skipSave" => TRUE], "mb2345browser" => ["blocked" => "1", "skipSave" => TRUE], "mj12bot" => ["blocked" => "1", "skipSave" => FALSE], "sogou.com" => ["blocked" => "1", "skipSa