diff options
author | YoungMin Park <[email protected]> | 2014-11-04 11:49:43 +0900 |
---|---|---|
committer | YoungMin Park <[email protected]> | 2014-11-04 11:49:43 +0900 |
commit | a5bbb2bec133bdee08b361628f32430ae3884107 (patch) | |
tree | b203105149ec234ebe155d5718d2cbb6390b4a45 /plugins/af_comics | |
parent | 12727ad17d125eb2f3f243231ccca1cb0a5a7b4b (diff) | |
parent | 2f43089de1ead3f164b8b31967d1abbb784319fa (diff) |
Merge pull request #1 from gothfox/master
Update from original
Diffstat (limited to 'plugins/af_comics')
-rw-r--r-- | plugins/af_comics/af_comics_template.php | 14 | ||||
-rw-r--r-- | plugins/af_comics/filter_base.php | 6 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_cad.php | 36 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_comicpress.php | 46 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_darklegacy.php | 43 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_dilbert.php | 47 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_explosm.php | 44 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_gocomics.php | 53 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_pa.php | 77 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_tfd.php | 32 | ||||
-rw-r--r-- | plugins/af_comics/filters/af_comics_twp.php | 33 | ||||
-rw-r--r-- | plugins/af_comics/init.php | 79 |
12 files changed, 510 insertions, 0 deletions
diff --git a/plugins/af_comics/af_comics_template.php b/plugins/af_comics/af_comics_template.php new file mode 100644 index 000000000..117d69280 --- /dev/null +++ b/plugins/af_comics/af_comics_template.php @@ -0,0 +1,14 @@ +<?php +class Af_Comics_Template extends Af_ComicFilter { + + function supported() { + return array("Example"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + return false; + } +} +?> diff --git a/plugins/af_comics/filter_base.php b/plugins/af_comics/filter_base.php new file mode 100644 index 000000000..a53430645 --- /dev/null +++ b/plugins/af_comics/filter_base.php @@ -0,0 +1,6 @@ +<?php +abstract class Af_ComicFilter { + public abstract function supported(); + public abstract function process(&$article); +} +?> diff --git a/plugins/af_comics/filters/af_comics_cad.php b/plugins/af_comics/filters/af_comics_cad.php new file mode 100644 index 000000000..43836724f --- /dev/null +++ b/plugins/af_comics/filters/af_comics_cad.php @@ -0,0 +1,36 @@ +<?php +class Af_Comics_Cad extends Af_ComicFilter { + + function supported() { + return array("Ctrl+Alt+Del"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["link"], "cad-comic.com/cad/") !== FALSE) { + if (strpos($article["title"], "News:") === FALSE) { + + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('(//img[contains(@src, "/comics/cad-")])')->item(0); + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_comicpress.php b/plugins/af_comics/filters/af_comics_comicpress.php new file mode 100644 index 000000000..ec4b7ac57 --- /dev/null +++ b/plugins/af_comics/filters/af_comics_comicpress.php @@ -0,0 +1,46 @@ +<?php +class Af_Comics_ComicPress extends Af_ComicFilter { + + function supported() { + return array("Buni", "Buttersafe", "Whomp!", "Happy Jar", "CSection", + "Extra Fabulous Comics"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["guid"], "bunicomic.com") !== FALSE || + strpos($article["guid"], "buttersafe.com") !== FALSE || + strpos($article["guid"], "whompcomic.com") !== FALSE || + strpos($article["guid"], "extrafabulouscomics.com") !== FALSE || + strpos($article["guid"], "happyjar.com") !== FALSE || + strpos($article["guid"], "csectioncomics.com") !== FALSE) { + + // lol at people who block clients by user agent + // oh noes my ad revenue Q_Q + + $res = fetch_file_contents($article["link"], false, false, false, + false, false, 0, + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); + + $doc = new DOMDocument(); + @$doc->loadHTML($res); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('//div[@id="comic"]')->item(0); + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_darklegacy.php b/plugins/af_comics/filters/af_comics_darklegacy.php new file mode 100644 index 000000000..c03919b1d --- /dev/null +++ b/plugins/af_comics/filters/af_comics_darklegacy.php @@ -0,0 +1,43 @@ +<?php +class Af_Comics_DarkLegacy extends Af_ComicFilter { + + function supported() { + return array("Dark Legacy Comics"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["guid"], "darklegacycomics.com") !== FALSE) { + + $res = fetch_file_contents($article["link"], false, false, false, + false, false, 0, + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); + + global $fetch_last_error_content; + + if (!$res && $fetch_last_error_content) + $res = $fetch_last_error_content; + + $doc = new DOMDocument(); + @$doc->loadHTML($res); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('//div[@class="comic"]')->item(0); + + if ($basenode) { + + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_dilbert.php b/plugins/af_comics/filters/af_comics_dilbert.php new file mode 100644 index 000000000..f0e31cf88 --- /dev/null +++ b/plugins/af_comics/filters/af_comics_dilbert.php @@ -0,0 +1,47 @@ +<?php +class Af_Comics_Dilbert extends Af_ComicFilter { + + function supported() { + return array("Dilbert"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["guid"], "dilbert.com") !== FALSE) { + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... + + $matches = array(); + + foreach ($entries as $entry) { + + if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) { + + $entry->setAttribute("src", + rewrite_relative_url("http://dilbert.com/", + $matches[0])); + + $basenode = $entry; + break; + } + } + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_explosm.php b/plugins/af_comics/filters/af_comics_explosm.php new file mode 100644 index 000000000..cba7ad0ad --- /dev/null +++ b/plugins/af_comics/filters/af_comics_explosm.php @@ -0,0 +1,44 @@ +<?php +class Af_Comics_Explosm extends Af_ComicFilter { + + function supported() { + return array("Cyanide and Happiness"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["link"], "explosm.net/comics") !== FALSE) { + + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess... + + $matches = array(); + + foreach ($entries as $entry) { + + if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) { + + $basenode = $entry; + break; + } + } + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_gocomics.php b/plugins/af_comics/filters/af_comics_gocomics.php new file mode 100644 index 000000000..9b3c787de --- /dev/null +++ b/plugins/af_comics/filters/af_comics_gocomics.php @@ -0,0 +1,53 @@ +<?php +class Af_Comics_GoComics extends Af_ComicFilter { + + function supported() { + return array("GoComics"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["guid"], "gocomics.com") !== FALSE) { + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query("(//img[@class='strip'])"); + + $matches = array(); + + if ($entries->length > 1) { // if we have more than one match, then get the zoomed one, which is the second for gocomics + $entry = $entries->item(1); // get the second element (items start at 0) + if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) { + $entry->setAttribute("src", $matches[0]); + $basenode = $entry; + } + } + + if (!$basenode) { + // fallback on the smaller version + foreach ($entries as $entry) { + if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) { + $entry->setAttribute("src", $matches[0]); + $basenode = $entry; + break; + } + } + } + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_pa.php b/plugins/af_comics/filters/af_comics_pa.php new file mode 100644 index 000000000..a13857cc1 --- /dev/null +++ b/plugins/af_comics/filters/af_comics_pa.php @@ -0,0 +1,77 @@ +<?php +class Af_Comics_Pa extends Af_ComicFilter { + + function supported() { + return array("Penny Arcade"); + } + + function process(&$article) { + if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { + + if ($debug_enabled) { + _debug("af_pennyarcade: Processing comic"); + } + + $doc = new DOMDocument(); + $doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { + if ($debug_enabled) { + _debug("af_pennyarcade: Processing news post"); + } + $doc = new DOMDocument(); + $doc->loadHTML(fetch_file_contents($article["link"])); + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query('(//div[@class="post"])'); + + $basenode = false; + + foreach ($entries as $entry) { + $basenode = $entry; + } + + $meta = $xpath->query('(//div[@class="meta"])')->item(0); + if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } + + $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); + if ($header->parentNode) { $header->parentNode->removeChild($header); } + + $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); + if ($header->parentNode) { $header->parentNode->removeChild($header); } + + $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); + $basenode->insertBefore($avatar, $basenode->firstChild); + + $uninteresting = $xpath->query('(//div[@class="avatar"])'); + foreach ($uninteresting as $i) { + $i->parentNode->removeChild($i); + } + + if ($basenode){ + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_tfd.php b/plugins/af_comics/filters/af_comics_tfd.php new file mode 100644 index 000000000..c4e594551 --- /dev/null +++ b/plugins/af_comics/filters/af_comics_tfd.php @@ -0,0 +1,32 @@ +<?php +class Af_Comics_Tfd extends Af_ComicFilter { + + function supported() { + return array("Toothpaste For Dinner"); + } + + function process(&$article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["link"], "toothpastefordinner.com") !== FALSE) { + $doc = new DOMDocument(); + + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('//img[@class="comic"]')->item(0); + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + return true; + } + } + } + + return false; + } +} +?> diff --git a/plugins/af_comics/filters/af_comics_twp.php b/plugins/af_comics/filters/af_comics_twp.php new file mode 100644 index 000000000..ec43c1379 --- /dev/null +++ b/plugins/af_comics/filters/af_comics_twp.php @@ -0,0 +1,33 @@ +<?php +class Af_Comics_Twp extends Af_ComicFilter { + + function supported() { + return array("Three Word Phrase"); + } + + function process(&$article) { + + if (strpos($article["link"], "threewordphrase.com") !== FALSE) { + + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXpath($doc); + + $basenode = $xpath->query("//td/center/img")->item(0); + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode); + } + } + + return true; + } + + return false; + } +} +?> diff --git a/plugins/af_comics/init.php b/plugins/af_comics/init.php new file mode 100644 index 000000000..efc51d187 --- /dev/null +++ b/plugins/af_comics/init.php @@ -0,0 +1,79 @@ +<?php +class Af_Comics extends Plugin { + + private $host; + private $filters = array(); + + function about() { + return array(1.0, + "Fixes RSS feeds of assorted comic strips", + "fox"); + } + + function init($host) { + $this->host = $host; + + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); + $host->add_hook($host::HOOK_PREFS_TAB, $this); + + require_once __DIR__ . "/filter_base.php"; + + $filters = glob(__DIR__ . "/filters/*.php"); + + foreach ($filters as $file) { + require_once $file; + $filter_name = preg_replace("/\..*$/", "", basename($file)); + + $filter = new $filter_name(); + + if (is_subclass_of($filter, "Af_ComicFilter")) { + array_push($this->filters, $filter); + } + } + + } + + function hook_prefs_tab($args) { + if ($args != "prefPrefs") return; + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds supported by af_comics')."\">"; + + print "<p>" . __("The following comics are currently supported:") . "</p>"; + + $comics = array(); + + foreach ($this->filters as $f) { + foreach ($f->supported() as $comic) { + array_push($comics, $comic); + } + } + + asort($comics); + + print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">"; + foreach ($comics as $comic) { + print "<li>$comic</li>"; + } + print "</ul>"; + + print "</div>"; + } + + function hook_article_filter($article) { + $owner_uid = $article["owner_uid"]; + + foreach ($this->filters as $f) { + if ($f->process($article)) + break; + } + + return $article; + + } + + function api_version() { + return 2; + } + +} +?> |