You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. <?php
  2. // Two Guys an Guy
  3. // This one looked like it might have died for a while but is updating again!
  4. // It's built on ComicControl (http://comicctrl.com), Hiveworks' CMS.
  5. $html = file_get_contents('http://twogag.com/');
  6. preg_match('@/comics/(.+\\.(jpg|png|gif))@', $html, $matches);
  7. if (empty($matches[1])) {
  8. echo "No comic found on home page! :(\n";
  9. return;
  10. }
  11. if (!is_dir('twogag')) {
  12. mkdir('twogag');
  13. }
  14. // Download current page's comic, load previous comic webpage, repeat
  15. while (true) {
  16. if (is_file('twogag/' . $matches[1])) {
  17. return;
  18. }
  19. echo "Downloading {$matches[1]}\n";
  20. $url = "http://twogag.com/comics/{$matches[1]}";
  21. $data = @file_get_contents($url);
  22. if ($data) {
  23. file_put_contents("twogag/{$matches[1]}", $data);
  24. }
  25. // Find previous page link
  26. $regex = '@rel="prev" href="(http://twogag.com/archives/[0-9a-zA-Z-]+)"@';
  27. preg_match($regex, $html, $prevMatch);
  28. if (empty($prevMatch[1])) {
  29. echo "No previous URL found!\n";
  30. return;
  31. }
  32. $html = @file_get_contents($prevMatch[1]);
  33. if (!$html) {
  34. echo "Failed to load previous page!\n";
  35. return;
  36. }
  37. preg_match('@/comics/(.+\\.(jpg|png|gif))@', $html, $matches);
  38. if (empty($matches[1])) {
  39. echo "No image found on page!\n";
  40. return;
  41. }
  42. usleep(5e5);
  43. }