eensyweensy.php (1077B)
1 <?php 2 if (!isset($_POST["data"])) { 3 echo "<pre>You need to feed me some DATA.\nDada Dada Dada.</pre>"; 4 exit; 5 } 6 7 $data = json_decode(stripslashes($_REQUEST["data"]), true); 8 $results = array(); 9 10 if (is_null($data["href"]) || is_null($data["on_last_page"]) 11 || !is_array($data["urls"])) { 12 $results["error"] = "validation error: missing on_last_page or urls"; 13 } 14 else { 15 // http://www.tizag.com/phpT/fileappend.php 16 $file_name = "output.txt"; 17 $file_handle = fopen($file_name, "a+"); 18 foreach ($data["urls"] as $url) { 19 fwrite($file_handle, "$url\n"); 20 } 21 fclose($file_handle); 22 23 if ($data["on_last_page"] == "true") { 24 $results["url"] = "http://hampsterdance.com"; 25 } 26 else { 27 function next_url ($matches) { 28 if (count($matches) == 2) { 29 return $matches[1] . "?page=2"; 30 } 31 $page = (int) $matches[3]; 32 $page++; 33 return $matches[1] . "?page=$page"; 34 }; 35 $results["url"] = preg_replace_callback( 36 "/^([^\?]+)(\?page=(\d*))?$/", 37 "next_url", 38 $data["href"] 39 ); 40 } 41 } 42 43 echo json_encode($results); 44 ?>