SEO Tools
All rights reserved.
You can find me at:
https://www.youtube.com/c/NetgrowsES
*/
/********************************************************************************/
/*
debugSearchDisplay can be true or false. If true, it will allow you to see search results in your screen (not recommended, only for debugging).
debugSearchDisplay puede ser true o false. En true, te mostrará los resultados de Google directamente en pantalla (no recomendado, solo para debug).
*/
$debugSearchDisplay=false;
/********************************************************************************/
/*
WARNING – AVISO
ENGLISH: DO NOT TOUCH ANYTHING BELOW THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING!
SPANISH: ¡NO TOQUES NADA DEBAJO DE ESTA ZONA A MENOS QUE SEPAS LO QUE ESTÁS HACIENDO!
*/
/************************************************************************************/
$phpseoVersion=”2.0″;
if (isset($_POST[‘query’])) $query = $_POST[‘query’];
else $query =””;
if (isset($_POST[‘pagina’])) $pagina = $_POST[‘pagina’];
else $pagina =”1″;
if (isset($_POST[‘optionz’])) $optionz = $_POST[‘optionz’];
else $optionz =””;
if (isset($_POST[‘googleRegion’])) $googleRegion = $_POST[‘googleRegion’];
else $googleRegion =””;
if (isset($_POST[‘webproxy’])) $webproxy = $_POST[‘webproxy’];
else $webproxy =”noproxy”;
if (isset($_GET[‘module’])) $module = $_GET[‘module’];
else $module =””;
if (isset($_POST[‘lang’])) $lang = $_POST[‘lang’];
else $lang =””;
if (isset($_POST[‘mainkwsuggest’])) $mainkwsuggest = $_POST[‘mainkwsuggest’];
else $mainkwsuggest =””;
if (isset($_POST[‘kwsugPlatform’])) $kwsugPlatform = $_POST[‘kwsugPlatform’];
else $kwsugPlatform =””;
if (isset($_POST[‘kwAtTheEnd’])) $kwAtTheEnd = $_POST[‘kwAtTheEnd’];
else $kwAtTheEnd =””;
if (isset($_POST[‘imagequery’])) $imagequery = $_POST[‘imagequery’];
else $imagequery =””;
if (isset($_POST[‘imagesToDownload’])) $imagesToDownload = $_POST[‘imagesToDownload’];
else $imagesToDownload =””;
if (isset($_POST[‘plagichecktext’])) $plagichecktext = $_POST[‘plagichecktext’];
else $plagichecktext =””;
if (isset($_POST[‘indexedcheckURLs’])) $indexedcheckURLs = $_POST[‘indexedcheckURLs’];
else $indexedcheckURLs =””;
if ($module==”lastnews”){
$totalNotificaciones = file_get_contents(‘https://netgrows.com/notifications/total.php’, true);
setcookie( “seenNotifications”, $totalNotificaciones, time() + (10 * 365 * 24 * 60 * 60) );
}
/*Initialize*/
if (!file_exists(“content-extractor-templates.txt”)) file_put_contents(‘content-extractor-templates.txt’, ‘Template Woo Product@@@product_title######@@@product_description######
‘.”n”.’Template Yahoo News@@@news_title###
###
@@@news_body######
@@@news_date######‘.”n”.’Template Reddit@@@post_title######@@@post_description###RichTextJSON-root”>###
‘.”n”.’Template Amazon.com@@@product_title######@@@product_description######
‘);
if (!file_exists(“web-proxy-list.txt”)) file_put_contents(‘web-proxy-list.txt’, ‘Sample 1@@@https://mydomain2.com/test/phpseo-proxy.php?password=YOURPASSWORDHERE’.”n”.’Sample 2@@@https://mydomain3.com/phpseo-proxy.php?password=YOURPASSWORDHERE’);
if (!file_exists(“footprints.txt”)) file_put_contents(‘footprints.txt’, ‘Site@@@site:yourdomain.com’.”n”.’Intext@@@intext:yourkeyword’.”n”.’Allintext@@@allintext:yourkeyword’.”n”.’Allintitle@@@allintitle:yourkeyword’.”n”.’Inurl@@@inurl:yourkeyword’.”n”.’Allinurl@@@allinurl:yourkeyword’.”n”.’Filetype@@@filetype:pdf’.”n”.’OR@@@OR keyword’.”n”.’AND@@@AND keyword’.”n”.’AROUND(X)@@@AROUND(12) youkeyword’.”n”.’FB pages@@@site:facebook.com+inurl:about’.”n”.’FB groups@@@site:facebook.com/groups’.”n”.’FB photos@@@site:facebook.com+inurl:photos’.”n”.’TW tweets@@@site:twitter.com+inurl:status’.”n”.’IG posts@@@site:instagram.com/p’.”n”.’YT videos@@@site:youtube.com+inurl:watch’.”n”.’Yahoo news@@@site:news.yahoo.com inurl:html’.”n”.’Amazon products@@@site:amazon.com inurl:/dp/’.”n”.’Web forums@@@inurl:forums+OR+intitle:forums+OR+intitle:foro’.”n”.’Disqus comments@@@%22Powered+by+Disqus%22′.”n”.’Facebook comments@@@%22facebook+comments+plugin%22′.”n”.’Blogspot comments@@@site:blogspot.com+inurl:html’.”n”.’Wordpress comments@@@%22powered+by+wordpress%22+AND+%22leave+a+reply%22′.”n”.’Wordpress.com comments@@@site:wordpress.com+%22introduce+tu+comentario%22+OR+%22enter+your+comment%22′);
/*Initialize extension, saves path if exist*/
$file = “phpseo_chrome_extension/content.js”;
if (file_exists($file)){
$lines = file($file);
$actual_link = “http://$_SERVER[HTTP_HOST]/”; //.strtok($_SERVER[“REQUEST_URI”], ‘?’)
$add_info = “var phpSeoPath=’$actual_link’; var phpSeoPathComplete=’http://$_SERVER[HTTP_HOST]”.dirname($_SERVER[‘PHP_SELF’]).”/’; n”;
if ($lines[0] != $add_info) {
$lines[0] = $add_info;
file_put_contents($file, $lines);
}
}
if (!file_exists(‘data-extractor’)) {
mkdir(‘data-extractor’, 0777, true);
}
if (!file_exists(“config.txt”)) {
$langConfig = substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 2);
if ($langConfig==”es”) $langToSave=”es”;
else $langToSave=”en”;
$howManyURLPerStep=3;
$batchDelaySeconds=20;
$searchDelaySeconds=15;
$customUserAgent=”Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36″;
file_put_contents(‘config.txt’, “lang=$langToSave”.”n”.”howManyURLPerStep=$howManyURLPerStep”.”n”.”batchDelaySeconds=$batchDelaySeconds”.”n”.”searchDelaySeconds=$searchDelaySeconds”.”n”.”customUserAgent=$customUserAgent”);
$langSelected=$langConfig;
} else {
/*Read config*/
$configVars = file_get_contents(‘config.txt’, true);
$arrayVars = explode(“n”,$configVars);
foreach ($arrayVars as $varconfig){
$partesVar = explode(“=”,$varconfig);
if (trim($partesVar[0])==”lang”) $langSelected=trim($partesVar[1]);
if (trim($partesVar[0])==”howManyURLPerStep”) $howManyURLPerStep=trim($partesVar[1]);
if (trim($partesVar[0])==”batchDelaySeconds”) $batchDelaySeconds=trim($partesVar[1]);
if (trim($partesVar[0])==”searchDelaySeconds”) $searchDelaySeconds=trim($partesVar[1]);
if (trim($partesVar[0])==”customUserAgent”) $customUserAgent=trim($partesVar[1]);
}
}
if (!file_exists(“search.json”)) file_put_contents(‘search.json’, “”);
//LOCAL API FOR TIMEOUT
/*
$domainFromURL = $_GET[‘domainFromURL’];
if ($domainFromURL) {
echo gethostbyname($domainFromURL);
exit;
}
*/
/******************/
/*PROXY GENERATOR*/
/****************/
if ($module==”proxygenerator”) {
if (isset($_GET[‘passNewProxy’])) $passNewProxy = $_GET[‘passNewProxy’];
else echo “ERROR, NO PASSWORD”;
$output=’
your php.”);
$w = “http://suggestqueries.google.com/complete/search?output=toolbar&hl=$lang&lr=lang_$lang&pws=0&gl=us&gws_rd=cr&q=”.$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$aux=utf8_encode(curl_exec($ch));
$xml = @simplexml_load_string($aux);
curl_close($ch);
if ($xml){
$result = $xml->xpath(“//@data”);
$ar = array();
foreach($result as $key => $value) {
$ar[] = (string)$value;
}
return $ar;
} else return false;
}
function youtubeSuggestKeywords2($k, $lang) {
if (!function_exists(“curl_init”)) die(“youtubeSuggestKeywords needs CURL module, please install CURL on your php.”);
$w = “https://clients1.google.com/complete/search?client=youtube&output=toolbar&gs_ri=youtube&ds=yt&hl=$lang&lr=lang_$lang&q=”.$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=utf8_encode(curl_exec($ch));
$arr_items = preg_split( ‘/(],[|”,[[“)/’, $content ); //Split and put it in arrary
foreach($arr_items as $items)
{ $arr_item=explode(“,”,$items);
$key=$arr_item[0]; //Get the keyword, the arrary will have other details such as no.of resutls also.
$key=trim($key,”””); //Use to remove quotes
if (strpos($key, “window.google.ac.h”) === false) {
if( strpos( $key, “<" ) === false ) {
echo $key;
echo "n";
}
}
}
curl_close($ch);
}
function amzSuggestKeywords2($k, $lang) {
if (!function_exists("curl_init")) die("amzSuggestKeywords needs CURL module, please install CURL on your php.");
$k=urlencode($k);
$w = "https://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=".$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=utf8_encode(curl_exec($ch));
$contentArray=explode(",",$content);
//delete last and first array elements (trash)
unset($contentArray[count($contentArray)-1]);
unset($contentArray[0]);
foreach ($contentArray as $element){
$elementClean = str_replace(array(']','[','}','{','"',':'), "", $element);
if ((!empty($elementClean))&&(strlen($elementClean)>=4)) echo utf8_decode($elementClean).”n”;
}
curl_close($ch);
}
$query=$searchPageStarts=$googleRegion=””;
if (isset($_GET[“query”])) $query=urlencode($_GET[“query”]);
if (isset($_GET[“searchPageStarts”])) $searchPageStarts=$_GET[“searchPageStarts”];
if (isset($_GET[“googleRegion”])) $googleRegion=$_GET[“googleRegion”];
if ((isset($querysug))&&($querysug!=””)) {
foreach(range(“a”,”z”) as $i){
if ($kwAtTheEnd==”kwatend”) {
$keyCombo=urlencode(“$i $querysug”).”&cp=1″;
} else $keyCombo=urlencode(“$querysug $i”);
$arraysug = googleSuggestKeywords2(“$keyCombo”, $lang);
if (is_array($arraysug) || is_object($arraysug)) {
foreach ($arraysug as &$value) {
if (!empty($value)) {
echo $value;
if(end($arraysug)!=$value) echo “n”;
}
}
}
}
}
if ((isset($querysugYT))&&($querysugYT!=””)) {
foreach(range(“a”,”z”) as $i){
if ($kwAtTheEnd==”kwatend”) {
$keyCombo=urlencode(“$i $querysugYT”).”&cp=1″;
} else $keyCombo=urlencode(“$querysugYT $i”);
$arraysug = youtubeSuggestKeywords2(“$keyCombo”, $lang);
if (is_array($arraysug) || is_object($arraysug)) {
foreach ($arraysug as &$value) {
if (!empty($value)) {
echo $value;
if(end($arraysug)!=$value) echo “n”;
}
}
}
}
}
if ((isset($querysugAZ))&&($querysugAZ!=””)) {
foreach(range(“a”,”z”) as $i){
$arraysug = amzSuggestKeywords2(“$querysugAZ $i”, $lang);
if (is_array($arraysug) || is_object($arraysug)) {
foreach ($arraysug as &$value) {
if (!empty($value)) {
echo $value;
if(end($arraysug)!=$value) echo “n”;
}
}
}
}
}
if ((($query!=””)&&($searchPageStarts!=””)&&($googleRegion!=””))||($tbm!=””)) {
if ($tbm==”isch”) { //image search
$getcontents=”https://$googleRegion/search?q=$query&tbm=isch”;
} else $getcontents=”https://$googleRegion/search?q=$query&ion=0&num=100&start=$searchPageStarts”;
$results = getPageGoogle2(“”,$getcontents, “”, “‘.$customUserAgent.'”, 1, 25);
echo $arraydatos=$results[“EXE”];
}
if ($getPage!=””) {
$results = getPageGoogle2(“”,$getPage, “”, “‘.$customUserAgent.'”, 1, 25);
echo $arraydatos=$results[“EXE”];
}
/*END PROXY CODE*/
?>
‘;
$file = “phpseo-proxy.php”;
$txt = fopen($file, “w”) or die(“Unable to open file!”);
fwrite($txt, $output);
fclose($txt);
header(‘Content-Description: File Transfer’);
header(‘Content-Disposition: attachment; filename=’.basename($file));
header(‘Expires: 0’);
header(‘Cache-Control: must-revalidate’);
header(‘Pragma: public’);
header(‘Content-Length: ‘ . filesize($file));
header(“Content-Type: text/plain”);
readfile($file);
exit;
}
session_start();
function getPageGoogle($proxy, $url, $referer, $agent, $header, $timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, “/tmp/cookie.txt”);
curl_setopt($ch, CURLOPT_REFERER, “https://twitter.com/”);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, “”);
//$fp = fopen(dirname(__FILE__).’/curllogs.txt’, ‘a’);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_STDERR, $fp);
$result[‘EXE’] = curl_exec($ch);
$result[‘INF’] = curl_getinfo($ch);
$result[‘ERR’] = curl_error($ch);
curl_close($ch);
return $result;
}
function googleSuggestKeywords($k, $lang) {
if (!function_exists(“curl_init”)) die(“googleSuggestKeywords needs CURL module, please install CURL on your php.”);
$w = “http://suggestqueries.google.com/complete/search?output=toolbar&hl=$lang&lr=lang_$lang&pws=0&gl=us&gws_rd=cr&q=”.$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$aux=utf8_encode(curl_exec($ch));
$xml = @simplexml_load_string($aux);
curl_close($ch);
if ($xml){
// Parse the keywords
$result = $xml->xpath(‘//@data’);
$ar = array();
foreach($result as $key => $value) {
$ar[] = (string)$value;
}
return $ar;
} else return false;
}
function youtubeSuggestKeywords($k, $lang) {
if (!function_exists(“curl_init”)) die(“youtubeSuggestKeywords needs CURL module, please install CURL on your php.”);
$w = “https://clients1.google.com/complete/search?client=youtube&output=toolbar&gs_ri=youtube&ds=yt&hl=$lang&lr=lang_$lang&q=”.$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=utf8_encode(curl_exec($ch));
$arr_items = preg_split( ‘/(],[|”,[[“)/’, $content ); //Split and put it in arrary
foreach($arr_items as $items)
{ $arr_item=explode(“,”,$items);
$key=$arr_item[0]; //Get the keyword, the arrary will have other details such as no.of resutls also.
$key=trim($key,”””); //Use to remove quotes
if (strpos($key, ‘window.google.ac.h’) === false) {
if( strpos( $key, “<" ) === false ) {
echo $key;
echo "n";
}
}
}
curl_close($ch);
}
function amzSuggestKeywords($k, $lang) {
if (!function_exists("curl_init")) die("amzSuggestKeywords needs CURL module, please install CURL on your php.");
$k=urlencode($k);
$w = "https://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=".$k;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $w);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=utf8_encode(curl_exec($ch));
$contentArray=explode(",",$content);
//delete last and first array elements (trash)
unset($contentArray[count($contentArray)-1]);
unset($contentArray[0]);
foreach ($contentArray as $element){
$elementClean = str_replace(array(']','[','}','{','"',':'), "", $element);
if ((!empty($elementClean))&&(strlen($elementClean)>=4)) echo utf8_decode($elementClean).”n”;
}
curl_close($ch);
}
function get_subscriber($channel,$use = “user”) {
(int) $subs = 0;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,”https://www.youtube.com/”.$use.”/”.$channel.”/about?disable_polymer=1″);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 0 );
curl_setopt($ch, CURLOPT_REFERER, ‘https://www.youtube.com/’);
curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0’);
$result = curl_exec($ch);
$R = curl_getinfo($ch);
if($R[“http_code”] == 200) {
$pattern = ‘/”subscriberCountText”:{“simpleText”:”(.*?)}/’;
preg_match($pattern, $result, $matches, PREG_OFFSET_CAPTURE);
$subs = intval(str_replace(‘,’,”,$matches[1][0]));
}
if($subs == 0 && $use == “user”) return get_subscriber($channel,”channel”);
return $subs;
}
function strip_HTML_tags($text)
{
//Delete all between curly braces or parenthesis
$pattern = ‘~(?:(()|([)|({))(?(1)(?>[^()]++|(?R))*))(?(2)(?>[^][]++|(?R))*])(?(3)(?>[^{}]++|(?R))*})~’;
$text= preg_replace($pattern , ”, $text);
//Strips HTML 4.01 start and end tags. Preserves contents.
$text= preg_replace(‘%
# Match an opening or closing HTML 4.01 tag.
? # Tag opening "<" delimiter.
(?: # Group for HTML 4.01 tags.
ABBR|ACRONYM|ADDRESS|APPLET|AREA|ARTICLE|A|BASE|BASEFONT|BDO|BIG|
BLOCKQUOTE|BODY|BR|BUTTON|B|CAPTION|CENTER|CITE|CODE|COL|
COLGROUP|DD|DEL|DFN|DIR|DIV|DL|DT|EM|FIELDSET|FIGURE|FIGCAPTION|FONT|FORM|
FRAME|FRAMESET|Hd|HEAD|HR|HTML|IFRAME|IMG|INPUT|INS|
ISINDEX|I|KBD|LABEL|LEGEND|LI|LINK|MAP|MENU|META|NOFRAMES|
NOSCRIPT|OBJECT|OL|OPTGROUP|OPTION|PARAM|PRE|PATH|P|Q|SAMP|
SCRIPT|SELECT|SMALL|SPAN|STRIKE|STRONG|STYLE|SUB|SUP|SVG|S|
TABLE|TD|TBODY|TEXTAREA|TFOOT|TH|THEAD|TITLE|TR|TT|U|UL|VAR
)b # End group of tag name alternative.
(?: # Non-capture group for optional attribute(s).
s+ # Attributes must be separated by whitespace.
[w-.:]+ # Attribute name is required for attr=value pair.
(?: # Non-capture group for optional attribute value.
s*=s* # Name and value separated by “=” and optional ws.
(?: # Non-capture group for attrib value alternatives.
“[^”]*” # Double quoted string.
| ‘[^’]*’ # Single quoted string.
| [w-.:]+ # Non-quoted attrib value can be A-Z0-9-._:
) # End of attribute value alternatives.
)? # Attribute value is optional.
)* # Allow zero or more attribute=value pairs
s* # Whitespace is allowed before closing delimiter.
/? # Tag may be empty (with self-closing “/>” sequence.
> # Opening tag closing “>” delimiter.
| # Or a (non-SGML compliant) HTML comment.
| ]*> # Or a DOCTYPE.
%six’, ”, $text);
return $text;
}
function validate_email($email) {
// Check email syntax
if(preg_match(‘/^([a-zA-Z0-9._+-]+)@(([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,7}|[0-9]{1,3})(]?))$/’, $email, $matches)) {
$user = $matches[1];
$domain = $matches[2];
// Check availability of DNS MX records
if(getmxrr($domain, $mxhosts, $mxweight)) {
for($i=0;$i $value) {
foreach ($value as $k => $val) {
for ($i = 0; $i < count($val); $i++) {
$result[$i][$k] = $val[$i];
}
}
}
return $result;
}
function hexColorAllocate($im,$hex){
$hex = ltrim($hex,'#');
$a = hexdec(substr($hex,0,2));
$b = hexdec(substr($hex,2,2));
$c = hexdec(substr($hex,4,2));
return imagecolorallocate($im, $a, $b, $c);
}
function replace_extension($filename, $new_extension) {
$info = pathinfo($filename);
return $info['filename'] . '.' . $new_extension;
}
function transform_image($src, $dist, $dis_width = 100,$quality,$flipImageSelector, $textImageSelector, $addTextoImage, $coordinateX, $coordinateY, $coordinateXwatermark, $coordinateYwatermark,$imageFontSize, $imageFontColor, $textWatermarkSelector,$convertFormat){
$img = '';
$extension = strtolower(strrchr($src, '.'));
$angle=0;
switch($extension)
{
case '.jpg':
case '.jpeg':
$img = @imagecreatefromjpeg($src);
break;
case '.gif':
$img = @imagecreatefromgif($src);
break;
case '.png':
$img = @imagecreatefrompng($src);
break;
}
if ($img != ''){
$width = imagesx($img);
$height = imagesy($img);
} else return false;
if (($width>=1)&&($height>=1)){
$dis_height = $dis_width * ($height / $width);
$new_image = imagecreatetruecolor($dis_width, $dis_height);
//Download initial font, watermark and imagetext.txt creation
if (!file_exists(__DIR__ . “/font.ttf”)) {
$font = file_get_contents(“http://themes.googleusercontent.com/static/fonts/abel/v3/RpUKfqNxoyNe_ka23bzQ2A.ttf”);
file_put_contents(__DIR__ . “/font.ttf”, $font);
}
if (!file_exists(“watermark.png”)) {
$font = file_get_contents(“https://netgrows.com/phpseo/minilogo.png”);
file_put_contents(“watermark.png”, $font);
}
if (!file_exists(“imagetext.txt”)) {
$content=”Line 1 from imagetext.txtnLine 2 from imagetext.txtnLine 3 from imagetext.txtnLine 4 from imagetext.txtnLine 5 from imagetext.txt”;
file_put_contents(“imagetext.txt”, $content);
}
imagecopyresampled($new_image, $img, 0, 0, 0, 0, $dis_width, $dis_height, $width, $height);
if ($flipImageSelector==”fliphorizontal”) imageflip($new_image, IMG_FLIP_HORIZONTAL);
if ($flipImageSelector==”flipvertical”) imageflip($new_image, IMG_FLIP_VERTICAL);
if ($flipImageSelector==”flipboth”) imageflip($new_image, IMG_FLIP_BOTH);
$hexColorAllocate = hexColorAllocate($new_image,$imageFontColor);
if ($textImageSelector==”addaphrase”) imagettftext($new_image, $imageFontSize, $angle, $coordinateX, $coordinateY, $hexColorAllocate, __DIR__ . “/font.ttf”, $addTextoImage);
elseif ($textImageSelector==”addrandomlines”) {
$f_contents = file(“imagetext.txt”);
$line = $f_contents[rand(0, count($f_contents) – 1)];
imagettftext($new_image, $imageFontSize, $angle, $coordinateX, $coordinateY, $hexColorAllocate, __DIR__ . “/font.ttf”, $line);
}
elseif ($textImageSelector==”addsecuenciallines”) {
$contents = file(“imagetextaux.txt”, FILE_IGNORE_NEW_LINES);
$line = array_shift($contents);
file_put_contents(“imagetextaux.txt”, implode(“rn”, $contents));
imagettftext($new_image, $imageFontSize, $angle, $coordinateX, $coordinateY, $hexColorAllocate, __DIR__ . “/font.ttf”, $line);
}
if ($textWatermarkSelector==”addwatermark”) {
$stamp = imagecreatefrompng(‘watermark.png’);
$marge_right = $coordinateXwatermark;
$marge_bottom = $coordinateYwatermark;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($new_image, $stamp, imagesx($new_image) – $sx – $marge_right, imagesy($new_image) – $sy – $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
}
switch($extension)
{
case ‘.jpg’:
case ‘.jpeg’:
if (imagetypes() & IMG_JPG) {
imagejpeg($new_image, $dist, $quality);
}
break;
case ‘.gif’:
if (imagetypes() & IMG_GIF) {
imagegif($new_image, $dist);
}
break;
case ‘.png’:
$scaleQuality = round(($quality/100) * 9);
$invertScaleQuality = 9 – $scaleQuality;
if (imagetypes() & IMG_PNG) {
imagepng($new_image, $dist, $invertScaleQuality);
}
break;
}
if ($convertFormat==”converttoWEBP”) {
$newReplacedFileName=replace_extension($dist,”webp”);
imagewebp($new_image, “images/”.$newReplacedFileName, $quality);
}
if ($convertFormat==”converttoJPG”) {
$newReplacedFileName=replace_extension($dist,”jpg”);
imagejpeg($new_image, “images/”.$newReplacedFileName, $quality);
}
if ($convertFormat==”converttoPNG”) {
$scaleQuality = round(($quality/100) * 9);
$invertScaleQuality = 9 – $scaleQuality;
$newReplacedFileName=replace_extension($dist,”png”);
imagepng($new_image, “images/”.$newReplacedFileName, $invertScaleQuality);
}
if ($convertFormat==”converttoGIF”) {
$newReplacedFileName=replace_extension($dist,”gif”);
imagegif($new_image, “images/”.$newReplacedFileName);
}
imagedestroy($new_image);
} else return false;
}
if ($module==”imagedownload”) {
if (file_exists(“phpseofiles.zip”)) unlink(“phpseofiles.zip”);
$files=explode(“|”,$_POST[‘data’]);
$tmpFile = tempnam(‘/tmp’, ”);
$zip = new ZipArchive;
$zip->open($tmpFile, ZipArchive::CREATE);
foreach ($files as $file) {
$file=str_replace(“””,””,$file);
if ((strlen($file))>=5){
$fileContent = file_get_contents($file);
$zip->addFromString(basename($file), $fileContent);
}
}
$zip->close();
header(‘Content-Type: application/zip’);
header(‘Content-disposition: attachment; filename=file.zip’);
header(‘Content-Length: ‘ . filesize($tmpFile));
readfile($tmpFile);
rename($tmpFile,”phpseofiles.zip”);
exit;
}
if ($module==”checkindexedsubmit”) {
$webproxy=$_POST[‘webproxy’];
$allurls=explode(“|”,$_POST[‘data’]);
$pausePerStepPHP=$_POST[‘pausePerStepPHP’];
$allurls=array_filter($allurls);//cleans empty lines
foreach ($allurls as $url){
$url=str_replace(‘”‘,”,$url);
$urlencoded=urlencode($url);
if (!empty($url)){
$urltoCheck=”https://google.com/search?q=$urlencoded”;
if ($webproxy==”noproxy”) {
$results = getPageGoogle(”,$urltoCheck, ”, $customUserAgent, 1, 25);
} else {
$urlDefinitiva=$webproxy.”&getPage=”.$urltoCheck;
$results = getPageGoogle(”,$urlDefinitiva, ”, $customUserAgent, 1, 25);
}
$arraydatos=$results[‘EXE’];
//Check if banned
if (preg_match(“/unusual traffic/i”, $arraydatos)) {
$bannedProxy=true;
} else {
if (preg_match(“/href/i”, $arraydatos)) {
$bannedProxy=false;
} else $bannedProxy=true;
}
if ($bannedProxy==true){
echo “Your current IP address -“.$_SERVER[‘SERVER_ADDR’].”- has been banned by Google. Stop during some hours or use a web proxy.n”;
} else {
$url=strtolower($url);
$url=trim( $url, “/” );
$arraydatos=strtolower($arraydatos);
if (strpos($arraydatos,”href=”$url”) !== false) { //se ha encontrado la URL
echo “YES $urln”;
} else {
echo “NO $urln”;
}
}
}
}
sleep ($pausePerStepPHP);
exit;
}
if ($module==”gmbchecksubmit”) {
$webproxy=$_POST[‘webproxy’];
$allurls=explode(“|”,$_POST[‘data’]);
$allurls=array_filter($allurls);//cleans empty lines
foreach ($allurls as $url){
$url=str_replace(‘”‘,”,$url);
$urlencoded=urlencode($url);
if (!empty($url)){
$urltoCheck=”https://google.com/search?q=$urlencoded”;
if ($webproxy==”noproxy”) {
$results = getPageGoogle(”,$urltoCheck, ”, $customUserAgent, 1, 25);
} else {
$urlDefinitiva=$webproxy.”&getPage=”.$urltoCheck;
$results = getPageGoogle(”,$urlDefinitiva, ”, $customUserAgent, 1, 25);
}
$arraydatos=$results[‘EXE’];
//Check if banned
if (preg_match(“/unusual traffic/i”, $arraydatos)) {
$bannedProxy=true;
} else {
if (preg_match(“/href/i”, $arraydatos)) {
$bannedProxy=false;
} else $bannedProxy=true;
}
if ($bannedProxy==true){
echo “Your current IP address -“.$_SERVER[‘SERVER_ADDR’].”- has been banned by Google. Stop during some hours or use a web proxy.n”;
} else {
$url=strtolower($url);
$url=trim( $url, “/” );
$arraydatos=strtolower($arraydatos);
if (strpos($arraydatos,”href=”$url”) !== false) { //se ha encontrado la URL
echo “YES $urln”;
} else {
echo “NO $urln”;
}
}
}
}
sleep ($batchDelaySeconds);
exit;
}
class WHOISClient
{
private $servers = array(
‘app’ => ‘whois.nic.google’,
‘live’ => ‘whois.nic.live’,
‘vip’ => ‘whois.nic.vip’,
‘shop’ => ‘whois.nic.shop’,
‘life’ => ‘whois.nic.life’,
‘club’ => ‘whois.nic.club’,
‘online’ => ‘whois.nic.online’,
‘site’ => ‘whois.nic.site’,
‘store’ => ‘whois.nic.store’,
‘xyz’ => ‘whois.nic.xyz’,
‘ac’ => ‘whois.nic.ac’,
‘ae’ => ‘whois.aeda.net.ae’,
‘aero’ => ‘whois.aero’,
‘af’ => ‘whois.nic.af’,
‘ag’ => ‘whois.nic.ag’,
‘al’ => ‘whois.ripe.net’,
‘am’ => ‘whois.amnic.net’,
‘as’ => ‘whois.nic.as’,
‘asia’ => ‘whois.nic.asia’,
‘at’ => ‘whois.nic.at’,
‘au’ => ‘whois.aunic.net’,
‘ax’ => ‘whois.ax’,
‘az’ => ‘whois.ripe.net’,
‘ba’ => ‘whois.ripe.net’,
‘be’ => ‘whois.dns.be’,
‘bg’ => ‘whois.register.bg’,
‘bi’ => ‘whois.nic.bi’,
‘biz’ => ‘whois.neulevel.biz’,
‘bj’ => ‘www.nic.bj’,
‘br’ => ‘whois.nic.br’,
‘br.com’ => ‘whois.centralnic.com’,
‘bt’ => ‘whois.netnames.net’,
‘by’ => ‘whois.ripe.net’,
‘bz’ => ‘whois.belizenic.bz’,
‘ca’ => ‘whois.cira.ca’,
‘cat’ => ‘whois.nic.cat’,
‘cc’ => ‘whois.nic.cc’,
‘cd’ => ‘whois.nic.cd’,
‘ch’ => ‘whois.nic.ch’,
‘ck’ => ‘whois.nic.ck’,
‘cl’ => ‘nic.cl’,
‘cn’ => ‘whois.cnnic.net.cn’,
‘cn.com’ => ‘whois.centralnic.com’,
‘co’ => ‘whois.nic.co’,
‘co.nl’ => ‘whois.co.nl’,
‘com’ => ‘whois.crsnic.net’, //whois.verisign-grs.com //whois.godaddy.com //whois.tucows.com
‘coop’ => ‘whois.nic.coop’,
‘cx’ => ‘whois.nic.cx’,
‘cy’ => ‘whois.ripe.net’,
‘cz’ => ‘whois.nic.cz’,
‘de’ => ‘whois.denic.de’,
‘dk’ => ‘whois.dk-hostmaster.dk’,
‘dm’ => ‘whois.nic.cx’,
‘dz’ => ‘whois.nic.dz’,
‘edu’ => ‘whois.educause.net’,
‘ee’ => ‘whois.tld.ee’,
‘eg’ => ‘whois.ripe.net’,
‘es’ => ‘whois.nic.es’,
‘eu’ => ‘whois.eu’,
‘eu.com’ => ‘whois.centralnic.com’,
‘fi’ => ‘whois.ficora.fi’,
‘fo’ => ‘whois.nic.fo’,
‘fr’ => ‘whois.nic.fr’,
‘gb’ => ‘whois.ripe.net’,
‘gb.com’ => ‘whois.centralnic.com’,
‘gb.net’ => ‘whois.centralnic.com’,
‘qc.com’ => ‘whois.centralnic.com’,
‘ge’ => ‘whois.ripe.net’,
‘gl’ => ‘whois.nic.gl’,
‘gm’ => ‘whois.ripe.net’,
‘gov’ => ‘whois.nic.gov’,
‘gr’ => ‘whois.ripe.net’,
‘gs’ => ‘whois.nic.gs’,
‘hk’ => ‘whois.hknic.net.hk’,
‘hm’ => ‘whois.registry.hm’,
‘hn’ => ‘whois2.afilias-grs.net’,
‘hr’ => ‘whois.ripe.net’,
‘hu’ => ‘whois.nic.hu’,
‘hu.com’ => ‘whois.centralnic.com’,
‘ie’ => ‘whois.domainregistry.ie’,
‘il’ => ‘whois.isoc.org.il’,
‘info’ => ‘whois.afilias.info’,
‘int’ => ‘whois.isi.edu’,
‘io’ => ‘whois.nic.io’,
‘iq’ => ‘vrx.net’,
‘ir’ => ‘whois.nic.ir’,
‘is’ => ‘whois.isnic.is’,
‘it’ => ‘whois.nic.it’,
‘je’ => ‘whois.je’,
‘jobs’ => ‘jobswhois.verisign-grs.com’,
‘jp’ => ‘whois.jprs.jp’,
‘ke’ => ‘whois.kenic.or.ke’,
‘kg’ => ‘whois.domain.kg’,
‘kr’ => ‘whois.nic.or.kr’,
‘la’ => ‘whois2.afilias-grs.net’,
‘li’ => ‘whois.nic.li’,
‘lt’ => ‘whois.domreg.lt’,
‘lu’ => ‘whois.restena.lu’,
‘lv’ => ‘whois.nic.lv’,
‘ly’ => ‘whois.lydomains.com’,
‘ma’ => ‘whois.iam.net.ma’,
‘mc’ => ‘whois.ripe.net’,
‘md’ => ‘whois.nic.md’,
‘me’ => ‘whois.nic.me’,
‘mil’ => ‘whois.nic.mil’,
‘mk’ => ‘whois.ripe.net’,
‘mobi’ => ‘whois.dotmobiregistry.net’,
‘ms’ => ‘whois.nic.ms’,
‘mt’ => ‘whois.ripe.net’,
‘mu’ => ‘whois.nic.mu’,
‘mx’ => ‘whois.nic.mx’,
‘my’ => ‘whois.mynic.net.my’,
‘name’ => ‘whois.nic.name’,
net‘ => ‘whois.crsnic.net’, //whois.verisign-grs.com //whois.godaddy.com //whois.tucows.com
‘nf’ => ‘whois.nic.cx’,
‘ng’ => ‘whois.nic.net.ng’,
‘nl’ => ‘whois.domain-registry.nl’,
‘no’ => ‘whois.norid.no’,
‘no.com’ => ‘whois.centralnic.com’,
‘nu’ => ‘whois.nic.nu’,
‘nz’ => ‘whois.srs.net.nz’,
‘org’ => ‘whois.tucows.com’, //whois.pir.org
‘pl’ => ‘whois.dns.pl’,
‘pr’ => ‘whois.nic.pr’,
‘pro’ => ‘whois.registrypro.pro’,
‘pt’ => ‘whois.dns.pt’,
‘pw’ => ‘whois.nic.pw’,
‘ro’ => ‘whois.rotld.ro’,
‘ru’ => ‘whois.tcinet.ru’,
‘sa’ => ‘saudinic.net.sa’,
‘sa.com’ => ‘whois.centralnic.com’,
‘sb’ => ‘whois.nic.net.sb’,
‘sc’ => ‘whois2.afilias-grs.net’,
‘se’ => ‘whois.nic-se.se’,
‘se.com’ => ‘whois.centralnic.com’,
‘se.net’ => ‘whois.centralnic.com’,
‘sg’ => ‘whois.nic.net.sg’,
‘sh’ => ‘whois.nic.sh’,
‘si’ => ‘whois.arnes.si’,
‘sk’ => ‘whois.sk-nic.sk’,
‘sm’ => ‘whois.nic.sm’,
‘st’ => ‘whois.nic.st’,
‘so’ => ‘whois.nic.so’,
‘su’ => ‘whois.tcinet.ru’,
‘tc’ => ‘whois.adamsnames.tc’,
‘tel’ => ‘whois.nic.tel’,
‘tf’ => ‘whois.nic.tf’,
‘th’ => ‘whois.thnic.net’,
‘tj’ => ‘whois.nic.tj’,
‘tk’ => ‘whois.nic.tk’,
‘tl’ => ‘whois.domains.tl’,
‘tm’ => ‘whois.nic.tm’,
‘tn’ => ‘whois.ripe.net’,
‘to’ => ‘whois.tonic.to’,
‘tp’ => ‘whois.domains.tl’,
‘tr’ => ‘whois.nic.tr’,
‘travel’ => ‘whois.nic.travel’,
‘tw’ => ‘whois.twnic.net.tw’,
‘tv’ => ‘whois.nic.tv’,
‘tz’ => ‘whois.tznic.or.tz’,
‘ua’ => ‘whois.ua’,
‘uk’ => ‘whois.nic.uk’,
‘uk.com’ => ‘whois.centralnic.com’,
‘uk.net’ => ‘whois.centralnic.com’,
‘gov.uk’ => ‘whois.ja.net’,
‘us’ => ‘whois.nic.us’,
‘us.com’ => ‘whois.centralnic.com’,
‘uy’ => ‘nic.uy’,
‘uy.com’ => ‘whois.centralnic.com’,
‘uz’ => ‘whois.cctld.uz’,
‘va’ => ‘whois.ripe.net’,
‘vc’ => ‘whois2.afilias-grs.net’,
‘ve’ => ‘whois.nic.ve’,
‘vg’ => ‘whois.adamsnames.tc’,
‘ws’ => ‘whois.website.ws’,
‘xxx’ => ‘whois.nic.xxx’,
‘yu’ => ‘whois.ripe.net’,
‘za.com’ => ‘whois.centralnic.com’
);
private function locateServer($domain)
{
$parts = explode(‘.’, $domain);
for ($i = 0, $l = count($parts); $i < $l; $i++) {
$root = implode('.', $parts);
if (isset($this->servers[$root])) {
return $this->servers[$root];
}
array_shift($parts);
}
//throw new UnexpectedValueException(‘Unknown TLD in domain ‘ . $domain);
//error_log(“Unknown TLD in domain $domain n”, 3, “whois_errors.log”);
}
private function makeRequest($server, $domain)
{
$sock = @stream_socket_client(“tcp://$server:43”, $errNo, $errStr, 3);
if (!$sock) {
//throw new RuntimeException(‘Unable to connect to WHOIS server at ‘ . $server . ‘:43’);
//error_log(“Unable to connect to WHOIS server at $server n”, 3, “whois_errors.log”);
}
if ($server == $this->servers[‘com’]) {
// .com domains are a special case, there may be others as well
$domain = “$domain”;
}
if (is_resource($sock)){
if (!@fwrite($sock, “$domainrn”)) {
//throw new RuntimeException(‘Error sending request to server at ‘ . $server . ‘:43’);
//error_log(“Error sending request to server at $server n”, 3, “whois_errors.log”);
}
} else return false;
return @stream_get_contents($sock);
}
private function findRegistrar($raw)
{
if (preg_match(‘/registrars*[:-=][^a-z0-9]*([^rn]+)/i’, $raw, $matches)) {
return trim($matches[1]);
}
return false;
}
public function queryRegistrar($domain)
{
$server = $this->locateServer($domain);
$raw = $this->makeRequest($server, $domain);
return $this->findRegistrar($raw);
}
}
if ($module==”getPageGoogle”) {
$urltoget=urldecode($_GET[‘urltoget’]);
$results = getPageGoogle(”,$urltoget, ”, $customUserAgent, 1, 5);
//file_put_contents(‘arraydatosexe.log’, “n”. print_r($results[‘EXE’], true),FILE_APPEND | LOCK_EX);
echo $arraydatos=$results[‘EXE’];
exit;
}
if ($module==”checkadomauthority”) {
$webproxy=$_POST[‘webproxy’];
$pausePerStepPHP=$_POST[‘pausePerStepPHP’];
$allurls=explode(“|”,$_POST[‘data’]);
$allurls=array_filter($allurls);//cleans empty lines
$savecode = ““;
file_put_contents(‘temp-stop.php’, $savecode);
if (file_exists(“savedlinks/stop”)) exit;
foreach ($allurls as $url){
$url=str_replace(‘”‘,”,$url);
$urlencoded=urlencode($url);
if (file_exists(“savedlinks/stop”)) exit;
if (!empty($url)){
$domainFromURL=get_domain($url);
$urltoCheck=”http://web.archive.org/cdx/search/cdx?url=$domainFromURL”;
$protocol_host = ‘http’ . isSecure() . ‘://’ . filter_input(INPUT_SERVER, ‘HTTP_HOST’, FILTER_SANITIZE_URL);
$context = stream_context_create(array(
‘http’ => array(
‘timeout’ => 5,// 400 ms //0.4
)
));
$urltoCheck=urlencode($urltoCheck);
$host = “”;
$host = @file_get_contents($protocol_host . $_SERVER[‘PHP_SELF’]. ‘?module=getPageGoogle&urltoget=’ . $urltoCheck, false, $context);
$numResultadosWayback=substr_count($host, “n”);
$url=strtolower($url);
$url=trim( $url, “/” );
if(preg_match(‘/(.cat|.eus|.br|.ir)b/’, $domainFromURL) === 1){
$baseDomainCheck=”https://search.nominalia.com/search?domain=”;
$iconDomainRegistrar=”https://www.google.com/s2/favicons?domain=nominalia.com”;
} elseif (preg_match(‘/(.hk|.fi)b/’, $domainFromURL) === 1){
$baseDomainCheck=”https://www.onlydomains.com/domain/frontSearch?domain=”;
$iconDomainRegistrar=”https://www.google.com/s2/favicons?domain=onlydomains.com”;
} else {
$baseDomainCheck=”https://godaddy.com/domainsearch/find?checkAvail=1&domainToCheck=”;
$iconDomainRegistrar=”https://img6.wsimg.com/ux/favicon/favicon-32×32.png”;
}
//echo $domainFromURL.” YES “.$numResultadosWayback.” “.”n”;
//$url
echo “$url $numResultadosWayback CHECK CHECKn”;
//echo “$url $numResultadosWayback CHECK CHECKn”;
}
}
sleep ($pausePerStepPHP);
exit;
}
function URLIsValid(&$url) {
$file_headers = get_headers($url);
if ($file_headers === false) return false; // when server not found
foreach($file_headers as $header) { // parse all headers:
// corrects $url when 301/302 redirect(s) lead(s) to 200:
if(preg_match(“/^Location: (http.+)$/”,$header,$m)) $url=$m[1];
// grabs the last $header $code, in case of redirect(s):
if(preg_match(“/^HTTP.+s(ddd)s/”,$header,$m)) $code=$m[1];
} // End foreach…
if($code==200) return true; // $code 200 == all OK
else return false; // All else has failed, so this must be a bad link
} // End function url_exists
/**
Get the whois content of an ip by selecting the correct server
*/
function get_whois($ip)
{
$w = get_whois_from_server(‘whois.iana.org’ , $ip);
//print “Response: ” . PHP_EOL;
//print $w;
//print PHP_EOL;
preg_match(“#whois:s*([w.]*)#si” , $w , $data);
$whois_server = $data[1];
//print “Whois Server: $whois_server ” . PHP_EOL;
// now get actual whois data
$whois_data = get_whois_from_server($whois_server , $ip);
return $whois_data;
}
/**
Get the whois result from a whois server
return text
*/
function get_whois_from_server($server , $ip)
{
$data = ”;
// Before connecting lets check whether server alive or not
$server = trim($server);
if(!strlen($server))
{
print “Blank string provided for server” . PHP_EOL;
die();
}
// Create the socket and connect
//print “Connecting to server $server …”;
$f = @fsockopen($server, 43, $errno, $errstr, 3); //Open a new connection
if(!$f)
{
print “Failed”;
return false;
}
//print “Done” . PHP_EOL;
// Set the timeout limit for read
if(!stream_set_timeout($f , 6))
{
die(‘Unable to set set_timeout’); #Did this solve the problem ?
}
// Send the IP to the whois server
if($f)
{
//print “Sending request for ip: $ip” . PHP_EOL;
$message = $ip . “rn”;
fputs($f, $message);
}
/*
Theory : stream_set_timeout must be set after a write and before a read for it to take effect on the read operation
If it is set before the write then it will have no effect : http://in.php.net/stream_set_timeout
*/
// Set the timeout limit for read
if( !stream_set_timeout($f , 3) )
{
die(‘Unable to stream_set_timeout’); #Did this solve the problem ?
}
// Set socket in non-blocking mode
stream_set_blocking ($f, 0 );
// If connection still valid
if($f)
{
//print “Starting to read socket”.PHP_EOL;
while (!feof($f))
{
//print “Read attempt…”.PHP_EOL;
$data .= fread($f , 128);
}
}
// Now return the data
return $data;
}
function get_domain($domain, $debug = false)
{
$original = $domain = strtolower($domain);
if (filter_var($domain, FILTER_VALIDATE_IP)) { return $domain; }
$debug ? print(‘» Parsing: ‘.$original) : false;
$arr = array_slice(array_filter(explode(‘.’, $domain, 4), function($value){
return $value !== ‘www’;
}), 0); //rebuild array indexes
if (count($arr) > 2)
{
$count = count($arr);
$_sub = explode(‘.’, $count === 4 ? $arr[3] : $arr[2]);
$debug ? print(” (parts count: {$count})”) : false;
if (count($_sub) === 2) // two level TLD
{
$removed = array_shift($arr);
if ($count === 4) // got a subdomain acting as a domain
{
$removed = array_shift($arr);
}
$debug ? print(“
n” . ‘[*] Two level TLD: ‘ . join(‘.’, $_sub) . ‘ ‘) : false;
}
elseif (count($_sub) === 1) // one level TLD
{
$removed = array_shift($arr); //remove the subdomain
if (strlen($_sub[0]) === 2 && $count === 3) // TLD domain must be 2 letters
{
array_unshift($arr, $removed);
}
else
{
// non country TLD according to IANA
$tlds = array(
‘aero’,
‘arpa’,
‘asia’,
‘biz’,
‘cat’,
‘com’,
‘coop’,
‘edu’,
‘gov’,
‘info’,
‘jobs’,
‘mil’,
‘mobi’,
‘museum’,
‘name’,
‘net’,
‘org’,
‘post’,
‘pro’,
‘tel’,
‘travel’,
‘xxx’,
);
if (count($arr) > 2 && in_array($_sub[0], $tlds) !== false) //special TLD don’t have a country
{
array_shift($arr);
}
}
$debug ? print(“
n” .'[*] One level TLD: ‘.join(‘.’, $_sub).’ ‘) : false;
}
else // more than 3 levels, something is wrong
{
for ($i = count($_sub); $i > 1; $i–)
{
$removed = array_shift($arr);
}
$debug ? print(“
n” . ‘[*] Three level TLD: ‘ . join(‘.’, $_sub) . ‘ ‘) : false;
}
}
elseif (count($arr) === 2)
{
$arr0 = array_shift($arr);
if (strpos(join(‘.’, $arr), ‘.’) === false
&& in_array($arr[0], array(‘localhost’,’test’,’invalid’)) === false) // not a reserved domain
{
$debug ? print(“
n” .’Seems invalid domain: ‘.join(‘.’, $arr).’ re-adding: ‘.$arr0.’ ‘) : false;
// seems invalid domain, restore it
array_unshift($arr, $arr0);
}
}
$debug ? print(“
n”.’« Done parsing: ‘ . $original . ‘ as ‘. join(‘.’, $arr) .”
n”) : false;
return join(‘.’, $arr);
}
function isSecure() { // prepare host url
return ((isset($_SERVER[‘HTTPS’]) && !empty($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’) || $_SERVER[‘SERVER_PORT’] == 443) ? ‘s’ : ”;
}
if ($module==”getnotifications”) {
$totalNotificaciones = file_get_contents(‘https://netgrows.com/notifications/total.php’, true);
$data = array(
‘unseen_notification’ => $totalNotificaciones
);
echo json_encode($data);
exit;
}
class SimpleXLSXGen {
public $curSheet;
protected $sheets;
protected $template;
protected $SI, $SI_KEYS;
public function __construct() {
$this->curSheet = -1;
$this->sheets = [ [‘name’ => ‘Sheet1’, ‘rows’ => [] ] ];
$this->SI = []; // sharedStrings index
$this->SI_KEYS = []; // & keys
$this->template = [
‘[Content_Types].xml’ => ‘
{SHEETS}
‘,
‘_rels/.rels’ => ‘
‘,
‘docProps/app.xml’ => ‘
0
‘.__CLASS__.’‘,
‘docProps/core.xml’ => ‘
{DATE}
en-US
{DATE}
1
‘,
‘xl/_rels/workbook.xml.rels’ => ‘
{SHEETS}’,
‘xl/worksheets/sheet1.xml’ => ‘
{COLS}{ROWS}‘,
‘xl/sharedStrings.xml’ => ‘
{STRINGS}‘,
‘xl/styles.xml’ => ‘
‘,
‘xl/workbook.xml’ => ‘
{SHEETS}
‘
];
}
public static function fromArray( array $rows, $sheetName = null ) {
$xlsx = new static();
return $xlsx->addSheet( $rows, $sheetName );
}
public function addSheet( array $rows, $name = null ) {
$this->curSheet++;
$this->sheets[$this->curSheet] = [‘name’ => $name ?: ‘Sheet’.($this->curSheet+1)];
if ( is_array( $rows ) && isset( $rows[0] ) && is_array($rows[0]) ) {
$this->sheets[$this->curSheet][‘rows’] = $rows;
} else {
$this->sheets[$this->curSheet][‘rows’] = [];
}
return $this;
}
public function __toString() {
$fh = fopen( ‘php://memory’, ‘wb’ );
if ( ! $fh ) {
return ”;
}
if ( ! $this->_write( $fh ) ) {
fclose( $fh );
return ”;
}
$size = ftell( $fh );
fseek( $fh, 0);
return (string) fread( $fh, $size );
}
public function saveAs( $filename ) {
$fh = fopen( $filename, ‘wb’ );
if (!$fh) {
return false;
}
if ( !$this->_write($fh) ) {
fclose($fh);
return false;
}
fclose($fh);
return true;
}
public function download() {
return $this->downloadAs( gmdate(‘YmdHi’) . ‘.xlsx’ );
}
public function downloadAs( $filename ) {
$fh = fopen(‘php://memory’,’wb’);
if (!$fh) {
return false;
}
if ( !$this->_write( $fh )) {
fclose( $fh );
return false;
}
$size = ftell($fh);
header(‘Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);
header(‘Content-Disposition: attachment; filename=”‘.$filename.'”‘);
header(‘Last-Modified: ‘ . gmdate(‘D, d M Y H:i:s GMT’ , time() ));
header(‘Content-Length: ‘.$size);
while( ob_get_level() ) {
ob_end_clean();
}
fseek($fh,0);
fpassthru( $fh );
fclose($fh);
return true;
}
protected function _write( $fh ) {
$dirSignatureE= “x50x4bx05x06″; // end of central dir signature
$zipComments = ‘Generated by ‘.__CLASS__.’ PHP class, thanks sergey.shuchkin@gmail.com’;
if (!$fh) {
return false;
}
$cdrec = ”; // central directory content
$entries= 0; // number of zipped files
$cnt_sheets = count( $this->sheets );
foreach ($this->template as $cfilename => $template ) {
if ( $cfilename === ‘[Content_Types].xml’ ) {
$s = ”;
for ( $i = 0; $i < $cnt_sheets; $i++) {
$s .= '‘;
}
$template = str_replace(‘{SHEETS}’, $s, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
}
elseif ( $cfilename === ‘xl/_rels/workbook.xml.rels’ ) {
$s = ”;
for ( $i = 0; $i < $cnt_sheets; $i++) {
$s .= 'n”;
}
$s .= ‘‘;
$template = str_replace(‘{SHEETS}’, $s, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
}
elseif ( $cfilename === ‘xl/workbook.xml’ ) {
$s = ”;
foreach ( $this->sheets as $k => $v ) {
$s .= ‘‘;
}
$template = str_replace(‘{SHEETS}’, $s, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
}
elseif ( $cfilename === ‘docProps/core.xml’ ) {
$template = str_replace(‘{DATE}’, gmdate(‘Y-m-dTH:i:sZ’), $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
} elseif ( $cfilename === ‘xl/sharedStrings.xml’ ) {
if (!count($this->SI)) {
$this->SI[] = ‘No Data’;
}
$si_cnt = count($this->SI);
$this->SI = ‘‘.implode(“rn“, $this->SI).’‘;
$template = str_replace([‘{CNT}’, ‘{STRINGS}’], [ $si_cnt, $this->SI ], $template );
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
} elseif ( $cfilename === ‘xl/worksheets/sheet1.xml’ ) {
foreach ( $this->sheets as $k => $v ) {
$filename = ‘xl/worksheets/sheet’.($k+1).’.xml’;
$xml = $this->_sheetToXML($this->sheets[$k], $template);
$this->_writeEntry($fh, $cdrec, $filename, $xml );
$entries++;
}
$xml = null;
}
else {
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
}
}
$before_cd = ftell($fh);
fwrite($fh, $cdrec);
// end of central dir
fwrite($fh, $dirSignatureE);
fwrite($fh, pack(‘v’, 0)); // number of this disk
fwrite($fh, pack(‘v’, 0)); // number of the disk with the start of the central directory
fwrite($fh, pack(‘v’, $entries)); // total # of entries “on this disk”
fwrite($fh, pack(‘v’, $entries)); // total # of entries overall
fwrite($fh, pack(‘V’, mb_strlen($cdrec,’8bit’))); // size of central dir
fwrite($fh, pack(‘V’, $before_cd)); // offset to start of central dir
fwrite($fh, pack(‘v’, mb_strlen($zipComments,’8bit’))); // .zip file comment length
fwrite($fh, $zipComments);
return true;
}
protected function _writeEntry($fh, &$cdrec, $cfilename, $data) {
$zipSignature = “x50x4bx03x04”; // local file header signature
$dirSignature = “x50x4bx01x02”; // central dir header signature
$e = [];
$e[‘uncsize’] = mb_strlen($data, ‘8bit’);
// if data to compress is too small, just store it
if($e[‘uncsize’] < 256){
$e['comsize'] = $e['uncsize'];
$e['vneeded'] = 10;
$e['cmethod'] = 0;
$zdata = $data;
} else{ // otherwise, compress it
$zdata = gzcompress($data);
$zdata = substr(substr($zdata, 0, - 4 ), 2); // fix crc bug (thanks to Eric Mueller)
$e['comsize'] = mb_strlen($zdata, '8bit');
$e['vneeded'] = 10;
$e['cmethod'] = 8;
}
$e['bitflag'] = 0;
$e['crc_32'] = crc32($data);
// Convert date and time to DOS Format, and set then
$lastmod_timeS = str_pad(decbin(date('s')>=32?date(‘s’)-32:date(‘s’)), 5, ‘0’, STR_PAD_LEFT);
$lastmod_timeM = str_pad(decbin(date(‘i’)), 6, ‘0’, STR_PAD_LEFT);
$lastmod_timeH = str_pad(decbin(date(‘H’)), 5, ‘0’, STR_PAD_LEFT);
$lastmod_dateD = str_pad(decbin(date(‘d’)), 5, ‘0’, STR_PAD_LEFT);
$lastmod_dateM = str_pad(decbin(date(‘m’)), 4, ‘0’, STR_PAD_LEFT);
$lastmod_dateY = str_pad(decbin(date(‘Y’)-1980), 7, ‘0’, STR_PAD_LEFT);
# echo “ModTime: $lastmod_timeS-$lastmod_timeM-$lastmod_timeH (“.date(“s H H”).”)n”;
# echo “ModDate: $lastmod_dateD-$lastmod_dateM-$lastmod_dateY (“.date(“d m Y”).”)n”;
$e[‘modtime’] = bindec(“$lastmod_timeH$lastmod_timeM$lastmod_timeS”);
$e[‘moddate’] = bindec(“$lastmod_dateY$lastmod_dateM$lastmod_dateD”);
$e[‘offset’] = ftell($fh);
fwrite($fh, $zipSignature);
fwrite($fh, pack(‘s’, $e[‘vneeded’])); // version_needed
fwrite($fh, pack(‘s’, $e[‘bitflag’])); // general_bit_flag
fwrite($fh, pack(‘s’, $e[‘cmethod’])); // compression_method
fwrite($fh, pack(‘s’, $e[‘modtime’])); // lastmod_time
fwrite($fh, pack(‘s’, $e[‘moddate’])); // lastmod_date
fwrite($fh, pack(‘V’, $e[‘crc_32’])); // crc-32
fwrite($fh, pack(‘I’, $e[‘comsize’])); // compressed_size
fwrite($fh, pack(‘I’, $e[‘uncsize’])); // uncompressed_size
fwrite($fh, pack(‘s’, mb_strlen($cfilename, ‘8bit’))); // file_name_length
fwrite($fh, pack(‘s’, 0)); // extra_field_length
fwrite($fh, $cfilename); // file_name
// ignoring extra_field
fwrite($fh, $zdata);
// Append it to central dir
$e[‘external_attributes’] = (substr($cfilename, -1) === ‘/’&&!$zdata)?16:32; // Directory or file name
$e[‘comments’] = ”;
$cdrec .= $dirSignature;
$cdrec .= “x0x0”; // version made by
$cdrec .= pack(‘v’, $e[‘vneeded’]); // version needed to extract
$cdrec .= “x0x0”; // general bit flag
$cdrec .= pack(‘v’, $e[‘cmethod’]); // compression method
$cdrec .= pack(‘v’, $e[‘modtime’]); // lastmod time
$cdrec .= pack(‘v’, $e[‘moddate’]); // lastmod date
$cdrec .= pack(‘V’, $e[‘crc_32’]); // crc32
$cdrec .= pack(‘V’, $e[‘comsize’]); // compressed filesize
$cdrec .= pack(‘V’, $e[‘uncsize’]); // uncompressed filesize
$cdrec .= pack(‘v’, mb_strlen($cfilename,’8bit’)); // file name length
$cdrec .= pack(‘v’, 0); // extra field length
$cdrec .= pack(‘v’, mb_strlen($e[‘comments’],’8bit’)); // file comment length
$cdrec .= pack(‘v’, 0); // disk number start
$cdrec .= pack(‘v’, 0); // internal file attributes
$cdrec .= pack(‘V’, $e[‘external_attributes’]); // internal file attributes
$cdrec .= pack(‘V’, $e[‘offset’]); // relative offset of local header
$cdrec .= $cfilename;
$cdrec .= $e[‘comments’];
}
protected function _sheetToXML(&$sheet, $template) {
$COLS = [];
$ROWS = [];
if ( count($sheet[‘rows’]) ) {
$CUR_ROW = 0;
$COL = [];
foreach( $sheet[‘rows’] as $r ) {
$CUR_ROW++;
$row = ‘‘;
$CUR_COL = 0;
foreach( $r as $v ) {
$CUR_COL++;
if ( !isset($COL[ $CUR_COL ])) {
$COL[ $CUR_COL ] = 0;
}
if ( $v === null || $v === ” ) {
continue;
}
$vl = mb_strlen( (string) $v );
$COL[ $CUR_COL ] = max( $vl, $COL[ $CUR_COL ] );
$cname = $this->num2name($CUR_COL) . $CUR_ROW;
$ct = $cs = null;
if ( is_string($v) ) {
if ( $v === ‘0’ || preg_match( ‘/^[-+]?[1-9]d{0,14}$/’, $v ) ) { // Integer as General
$cv = ltrim( $v, ‘+’ );
if ( $vl > 10 ) {
$cs = 1; // [1] 0
}
} elseif ( preg_match(‘/^[-+]?(0|[1-9]d*).d+$/’, $v ) ) {
$cv = ltrim($v,’+’);
} elseif ( preg_match(‘/^([-+]?d+)%$/’, $v, $m) ) {
$cv = round( $m[1] / 100, 2);
$cs = 2; // [9] 0%
} elseif ( preg_match(‘/^([-+]d+.d+)%$/’, $v, $m) ) {
$cv = round( $m[1] / 100, 4 );
$cs = 3; // [10] 0.00%
} elseif ( preg_match(‘/^(dddd)-(dd)-(dd)$/’, $v, $m ) ){
$cv = $this->date2excel($m[1],$m[2],$m[3]);
$cs = 4; // [14] mm-dd-yy
} elseif ( preg_match(‘/^(dd)/(dd)/(dddd)$/’, $v, $m ) ){
$cv = $this->date2excel($m[3],$m[2],$m[1]);
$cs = 4; // [14] mm-dd-yy
} elseif ( preg_match(‘/^(dd):(dd):(dd)$/’, $v, $m ) ){
$cv = $this->date2excel(0,0,0,$m[1],$m[2],$m[3]);
$cs = 5; // [14] mm-dd-yy
} elseif ( preg_match(‘/^(dddd)-(dd)-(dd) (dd):(dd):(dd)$/’, $v, $m ) ) {
$cv = $this->date2excel( $m[1], $m[2], $m[3], $m[4], $m[5], $m[6] );
$cs = 6; // [22] m/d/yy h:mm
} elseif ( preg_match(‘/^(dd)/(dd)/(dddd) (dd):(dd):(dd)$/’, $v, $m ) ) {
$cv = $this->date2excel( $m[3], $m[2], $m[1], $m[4], $m[5], $m[6] );
$cs = 6; // [22] m/d/yy h:mm
} elseif ( mb_strlen( $v ) > 160 ) {
$ct = ‘inlineStr’;
$cv = str_replace([‘&’,’<','>‘,”x03″],[‘&’,'<‘,’>’,”], $v);
} else {
if ( preg_match(‘/^[0-9+-.]+$/’, $v ) ) { // Long ?
$cs = 7; // Align Right
}
$v = ltrim($v,”