function main() { if (!isset($_GET['url']) || !preg_match('#^http.?://.+\\.tumblr\\.com.*#i', $_GET['url'])) { echo $_GET['url']; exit('Hello Visitor!'); } $strPageSource = getPageSource(encode_cjk_url($_GET['url'])); #get HTML page source code !$strPageSource && echoImageNotFoundTextFileAndExit($_GET['url']); $arrImagesUrls = parseImagesUrls($strPageSource); #parse urls of images $intCountOfImagesUrls = count($arrImagesUrls); $intCountOfImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); #no image url found, echo error message as txt file. $intCountOfImagesUrls === 1 && redirectAndExit(array_pop($arrImagesUrls)); #we got just one image url to be fetch, so no need for fetching, just redirect the browser to it. $arrContentAndUrlOfValidImages = fetchImages($arrImagesUrls); #not every url is available, so try every one. $intCountOfValidImagesUrls = count($arrContentAndUrlOfValidImages['validImagesUrls']); #check out the number of available urls $intCountOfValidImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); $intCountOfValidImagesUrls === 1 && redirectAndExit(array_pop($arrContentAndUrlOfValidImages['validImagesUrls'])); #if we got just one available url, no need to pack the image cause we could just redirect the browser. //when we got multiple images to deal with $strZipString = makeZipPack($arrContentAndUrlOfValidImages['imageStrings'], $arrContentAndUrlOfValidImages['validImagesUrls']); outputZipPackAsFileDownload($strZipString); }
function main() { (!isset($_GET['url']) || !filter_var($_GET['url'], FILTER_VALIDATE_URL)) && exit('Hello World!'); $strPageSource = getPageSource($_GET['url']); #get HTML page source code !$strPageSource && echoImageNotFoundTextFileAndExit($_GET['url']); $arrImagesUrls = parseImagesUrls($strPageSource); #parse urls of images $intCountOfImagesUrls = count($arrImagesUrls); $intCountOfImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); #no image url found, echo error message as txt file. $intCountOfImagesUrls === 1 && redirectAndExit(array_pop($arrImagesUrls)); #we got just one image url to be fetch, so no need for fetching, just redirect the browser to it. $arrContentAndUrlOfValidImages = fetchImages($arrImagesUrls); #not every url is available, so try every one. $intCountOfValidImagesUrls = count($arrContentAndUrlOfValidImages['validImagesUrls']); #check out the number of available urls $intCountOfValidImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); $intCountOfValidImagesUrls === 1 && redirectAndExit(array_pop($arrContentAndUrlOfValidImages['validImagesUrls'])); #if we got just one available url, no need to pack the image cause we could just redirect the browser. //when we got multiple images to deal with $strZipString = makeZipPack($arrContentAndUrlOfValidImages['imageStrings'], $arrContentAndUrlOfValidImages['validImagesUrls']); outputZipPackAsFileDownload($strZipString); }