af_comics_gocomics.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class Af_Comics_GoComics extends Af_ComicFilter {
  3. function supported() {
  4. return array("GoComics");
  5. }
  6. function process(&$article) {
  7. $owner_uid = $article["owner_uid"];
  8. if (strpos($article["guid"], "gocomics.com") !== FALSE) {
  9. $doc = new DOMDocument();
  10. @$doc->loadHTML(fetch_file_contents($article["link"]));
  11. $basenode = false;
  12. if ($doc) {
  13. $xpath = new DOMXPath($doc);
  14. $entries = $xpath->query("(//img[@class='strip'])");
  15. $matches = array();
  16. if ($entries->length > 1) { // if we have more than one match, then get the zoomed one, which is the second for gocomics
  17. $entry = $entries->item(1); // get the second element (items start at 0)
  18. if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
  19. $entry->setAttribute("src", $matches[0]);
  20. $basenode = $entry;
  21. }
  22. }
  23. if (!$basenode) {
  24. // fallback on the smaller version
  25. foreach ($entries as $entry) {
  26. if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
  27. $entry->setAttribute("src", $matches[0]);
  28. $basenode = $entry;
  29. break;
  30. }
  31. }
  32. }
  33. if ($basenode) {
  34. $article["content"] = $doc->saveXML($basenode);
  35. }
  36. }
  37. return true;
  38. }
  39. return false;
  40. }
  41. }
  42. ?>