Created
March 22, 2024 07:27
-
-
Save EscApp2/bbbbf8ce668f50c17afadc78b992de00 to your computer and use it in GitHub Desktop.
is Url remove Refresh get Image Data explode by array normalize Text From HTML tld list get domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate_url($url) { | |
return (bool)preg_match(" | |
/^ # Start at the beginning of the text | |
(?:ftp|https?|feed):\/\/ # Look for ftp, http, https or feed schemes | |
(?: # Userinfo (optional) which is typically | |
(?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)* # a username or a username and password | |
(?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@ # combination | |
)? | |
(?: | |
(?:[a-z0-9\-\.]|%[0-9a-f]{2})+ # A domain name or a IPv4 address | |
|(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]) # or a well formed IPv6 address | |
) | |
(?::[0-9]+)? # Server port number (optional) | |
(?:[\/|\?] | |
(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2}) # The path and query (optional) | |
*)? | |
$/xi", $url); | |
} | |
function isUrl( $text ) | |
{ | |
//not working this "https://discorhttps://discord.gg/9z8zX5j" | |
//return filter_var($text, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) !== false; | |
return validate_url($text); | |
} | |
function removeRefresh($feed){ | |
//http://php.net/manual/en/function.get-meta-tags.php | |
//<meta http-equiv="\"refresh\"" content="\"1;url=https:\/\/MasterNodes.Pro\/\"" \=""> | |
//preg_match_all('/<[\s]*meta[\s]*(name|property)="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match); | |
//$clear_sting = preg_replace_callback('/<[\s]*meta[\s]*http-equiv="?([^>"]*)"?' . '[\s]*content="([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', function($matches){ | |
// pre($matches); | |
//}, $feed); | |
//$clear_sting = preg_replace_callback('/<[\s]*meta[\s]*http-equiv="?([^>"]*)"?' . '[\s]*content="([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', function($matches){ | |
// pre($matches); | |
//}, $feed); | |
//$clear_sting = preg_replace_callback('/<[\s]*meta[\s]*http-equiv="?REFRESH"?[\s]*content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', function($matches){ | |
//pre($matches); | |
//}, $feed); | |
//pre($clear_sting); | |
//$feed = $clear_sting; | |
$clear_sting = preg_replace('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', "", $feed); | |
return $clear_sting; | |
} | |
if(!function_exists('getImageData')){ | |
function getImageData($path){ | |
if( | |
isUrl($path) | |
|| | |
(is_file($path) && is_readable($path)) | |
){ | |
$ImageData = array(); | |
if(function_exists('getimagesize')){ | |
$size = getimagesize($path); | |
$ImageData['width'] = $size[0]; | |
$ImageData['height'] = $size[1]; | |
$ImageData['mime_type'] = image_type_to_mime_type($size[2]); | |
$ImageData['extension'] = image_type_to_extension($size[2], false); | |
}elseif(class_exists('Imagick')){ | |
$res_im = new imagick($path); | |
$geo = $res_im->getImageGeometry(); | |
$ImageData['width'] = $geo['width']; | |
$ImageData['height'] = $geo['height']; | |
$ImageData['file_size'] = $res_im->getImageLength(); | |
$ImageData['mime_type'] = $res_im->getImageMimeType(); | |
}elseif(function_exists('finfo_open')){ | |
$buffer = file_get_contents($path); | |
$f = finfo_open(); | |
$ImageData['buffer'] = finfo_buffer($f, $buffer); | |
$ImageData['mime_type'] = finfo_buffer($f, $buffer,FILEINFO_MIME_TYPE); | |
finfo_close($f); | |
} | |
if(empty($ImageData['file_size'])){ | |
if(isUrl($path)){ | |
$h = array_change_key_case(get_headers($path,true)); | |
$size = $h['content-length']; | |
$ImageData['file_size'] = $size; | |
}else{ | |
$ImageData['file_size'] = filesize($path); | |
} | |
} | |
return $ImageData; | |
} | |
return false; | |
} | |
} | |
function explode_by_array($delim, $input) { | |
$unidelim = $delim[0]; | |
$step_01 = str_replace($delim, $unidelim, $input); //Extra step to create a uniform value | |
return explode($unidelim, $step_01); | |
} | |
function normalizeTextFromHTML($TEXT){ | |
//\bitrix\php_interface\parser\classes\bithostlive_com\bithostlive_com-api.php | |
//\bitrix\php_interface\parser\classes\ stakinglab_io-api.php | |
//\bitrix\php_interface\parser\classes\masternodes_biz\masternodes_biz-api.php | |
$TEXT = preg_replace('/\s\s+/', ' ', $TEXT); | |
$TEXT = htmlentities($TEXT); | |
$TEXT = str_replace(" ", "", $TEXT); | |
$TEXT = str_replace(array("\n", "\r"), '', $TEXT); | |
$TEXT = trim($TEXT); | |
return $TEXT; | |
} | |
function tld_list($cache_dir=null) { | |
// we use "/tmp" if $cache_dir is not set | |
$cache_dir = isset($cache_dir) ? $cache_dir : sys_get_temp_dir(); | |
$lock_dir = $cache_dir . '/public_suffix_list_lock/'; | |
$list_dir = $cache_dir . '/public_suffix_list/'; | |
// refresh list all 30 days | |
if (file_exists($list_dir) && @filemtime($list_dir) + 2592000 > time()) { | |
return $list_dir; | |
} | |
// use exclusive lock to avoid race conditions | |
if (!file_exists($lock_dir) && @mkdir($lock_dir)) { | |
// read from source | |
$list = @fopen('https://publicsuffix.org/list/public_suffix_list.dat', 'r'); | |
if ($list) { | |
// the list is older than 30 days so delete everything first | |
if (file_exists($list_dir)) { | |
foreach (glob($list_dir . '*') as $filename) { | |
unlink($filename); | |
} | |
rmdir($list_dir); | |
} | |
// now set list directory with new timestamp | |
mkdir($list_dir); | |
// read line-by-line to avoid high memory usage | |
while ($line = fgets($list)) { | |
// skip comments and empty lines | |
if ($line[0] == '/' || !$line) { | |
continue; | |
} | |
// remove wildcard | |
if ($line[0] . $line[1] == '*.') { | |
$line = substr($line, 2); | |
} | |
// remove exclamation mark | |
if ($line[0] == '!') { | |
$line = substr($line, 1); | |
} | |
// reverse TLD and remove linebreak | |
$line = implode('.', array_reverse(explode('.', (trim($line))))); | |
// we split the TLD list to reduce memory usage | |
touch($list_dir . $line); | |
} | |
fclose($list); | |
} | |
@rmdir($lock_dir); | |
} | |
// repair locks (should never happen) | |
if (file_exists($lock_dir) && mt_rand(0, 100) == 0 && @filemtime($lock_dir) + 86400 < time()) { | |
@rmdir($lock_dir); | |
} | |
return $list_dir; | |
} | |
function get_domain($url=null) { | |
// obtain location of public suffix list | |
$tld_dir = tld_list(__DIR__); | |
// no url = our own host | |
$url = isset($url) ? $url : $_SERVER['SERVER_NAME']; | |
// add missing scheme ftp:// http:// ftps:// https:// | |
$url = !isset($url[5]) || ($url[3] != ':' && $url[4] != ':' && $url[5] != ':') ? 'http://' . $url : $url; | |
// remove "/path/file.html", "/:80", etc. | |
$url = parse_url($url, PHP_URL_HOST); | |
// replace absolute domain name by relative (http://www.dns-sd.org/TrailingDotsInDomainNames.html) | |
$url = trim($url, '.'); | |
// check if TLD exists | |
$url = explode('.', $url); | |
$parts = array_reverse($url); | |
foreach ($parts as $key => $part) { | |
$tld = implode('.', $parts); | |
if (file_exists($tld_dir . $tld)) { | |
return !$key ? '' : implode('.', array_slice($url, $key - 1)); | |
} | |
// remove last part | |
array_pop($parts); | |
} | |
return ''; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment