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']) && exit_script('Hello Tumblr!'); isImageUrl($_GET['url']) && redirect_location($_GET['url']) && exit_script(); $hosts_number = 4; $hash_no = str_hash($_GET['url'], $hosts_number); $redirect_url = "http://tumblr-images-{$hash_no}.appspot.com/fetch.php?url={$_GET['url']}"; $redirect_url = encode_cjk_url($redirect_url); redirect_location($redirect_url); }
function main() { $html = get_page(encode_cjk_url($_GET['url'])); $img_urls = parse_img_urls($html); switch (count($img_urls)) { case 0: exit_with_msg('Images not found'); break; case 1: redirect_location(array_pop($img_urls)); break; default: output_zip(make_zip(fetch_and_store_images($img_urls))); break; } }