Automated build for v0.01

This commit is contained in:
Fmstrat
2019-03-22 10:17:29 -04:00
commit 791b998489
2771 changed files with 222096 additions and 0 deletions

1
plugins/af_comics/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
filters.local/*.php

View File

@ -0,0 +1,13 @@
<?php
class Af_Comics_Template extends Af_ComicFilter {
function supported() {
return array("Example");
}
function process(&$article) {
//$owner_uid = $article["owner_uid"];
return false;
}
}

View File

@ -0,0 +1,5 @@
<?php
abstract class Af_ComicFilter {
public abstract function supported();
public abstract function process(&$article);
}

View File

View File

@ -0,0 +1,39 @@
<?php
class Af_Comics_Cad extends Af_ComicFilter {
function supported() {
return array("Ctrl+Alt+Del");
}
function process(&$article) {
if (strpos($article["link"], "cad-comic.com") !== FALSE) {
if (strpos($article["title"], "News:") === FALSE) {
global $fetch_last_error_content;
$doc = new DOMDocument();
$res = fetch_file_contents($article["link"], false, false, false,
false, false, 0,
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
if (!$res && $fetch_last_error_content)
$res = $fetch_last_error_content;
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,34 @@
<?php
class Af_Comics_ComicClass extends Af_ComicFilter {
function supported() {
return array("Loading Artist");
}
function process(&$article) {
if (strpos($article["guid"], "loadingartist.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();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//div[@class="comic"]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,41 @@
<?php
class Af_Comics_ComicPress extends Af_ComicFilter {
function supported() {
return array("Buni", "Buttersafe", "Happy Jar", "CSection",
"Extra Fabulous Comics", "Nedroid", "Stonetoss");
}
function process(&$article) {
if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
strpos($article["guid"], "buttersafe.com") !== FALSE ||
strpos($article["guid"], "extrafabulouscomics.com") !== FALSE ||
strpos($article["guid"], "happyjar.com") !== FALSE ||
strpos($article["guid"], "nedroid.com") !== FALSE ||
strpos($article["guid"], "stonetoss.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();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//div[@id="comic"]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,38 @@
<?php
class Af_Comics_DarkLegacy extends Af_ComicFilter {
function supported() {
return array("Dark Legacy Comics");
}
function process(&$article) {
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();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//div[@class="comic"]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,73 @@
<?php
class Af_Comics_Dilbert extends Af_ComicFilter {
function supported() {
return array("Dilbert");
}
function process(&$article) {
if (strpos($article["link"], "dilbert.com") !== FALSE ||
strpos($article["link"], "/DilbertDailyStrip") !== FALSE) {
$res = fetch_file_contents($article["link"], false, false, false,
false, false, 0,
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
global $fetch_last_error_content;
if (!$res && $fetch_last_error_content)
$res = $fetch_last_error_content;
$doc = new DOMDocument();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
// Get the image container
$basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0);
// Get the comic title
$comic_title = $xpath->query('(//span[@class="comic-title-name"])')->item(0)->textContent;
// Get tags from the article
$matches = $xpath->query('(//p[contains(@class, "comic-tags")][1]//a)');
$tags = array();
foreach ($matches as $tag) {
// Only strings starting with a number sign are considered tags
if ( substr($tag->textContent, 0, 1) == '#' ) {
$tags[] = mb_strtolower(substr($tag->textContent, 1), 'utf-8');
}
}
// Get the current comics transcript and set it
// as the title so it will be visible on mousover
$transcript = $xpath->query('(//div[starts-with(@id, "js-toggle-transcript-")]//p)')->item(0);
if ($transcript) {
$basenode->setAttribute("title", $transcript->textContent);
}
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
// Add comic title to article type if not empty (mostly Sunday strips)
if ($comic_title) {
$article["title"] = $article["title"] . " - " . $comic_title;
}
if (!empty($tags)) {
// Ignore existing tags and just replace them all
$article["tags"] = array_unique($tags);
}
}
return true;
}
return false;
}
}
?>

View File

@ -0,0 +1,28 @@
<?php
class Af_Comics_Explosm extends Af_ComicFilter {
function supported() {
return array("Cyanide and Happiness");
}
function process(&$article) {
if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
$doc = new DOMDocument();
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('(//img[@id="main-comic"])')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,67 @@
<?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) {
$doc = new DOMDocument();
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
$doc = new DOMDocument();
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
$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);
if ($basenode)
$basenode->insertBefore($avatar, $basenode->firstChild);
$uninteresting = $xpath->query('(//div[@class="avatar"])');
foreach ($uninteresting as $i) {
$i->parentNode->removeChild($i);
}
if ($basenode){
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,31 @@
<?php
class Af_Comics_Pvp extends Af_ComicFilter {
function supported() {
return array("PvP Online");
}
function process(&$article) {
if (strpos($article["guid"], "pvponline.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)");
$doc = new DOMDocument();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//section[@class="comic-art"]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,32 @@
<?php
class Af_Comics_Tfd extends Af_ComicFilter {
function supported() {
return array("Toothpaste For Dinner", "Married to the Sea");
}
function process(&$article) {
if (strpos($article["link"], "toothpastefordinner.com") !== FALSE ||
strpos($article["link"], "marriedtothesea.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)");
if (!$res) return $article;
$doc = new DOMDocument();
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//img[contains(@src, ".gif")]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
return true;
}
}
}
return false;
}
}

View File

@ -0,0 +1,29 @@
<?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();
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
$xpath = new DOMXpath($doc);
$basenode = $xpath->query("//td/center/img")->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,36 @@
<?php
class Af_Comics_Whomp extends Af_ComicFilter {
function supported() {
return array("Whomp!");
}
function process(&$article) {
if (strpos($article["guid"], "whompcomic.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();
if (@$doc->loadHTML($res)) {
$xpath = new DOMXPath($doc);
$basenode = $xpath->query('//img[@id="cc-comic"]')->item(0);
if ($basenode) {
$article["content"] = $doc->saveHTML($basenode);
}
}
return true;
}
return false;
}
}

184
plugins/af_comics/init.php Executable file
View File

@ -0,0 +1,184 @@
<?php
class Af_Comics extends Plugin {
private $host;
private $filters = array();
function about() {
return array(2.0,
"Fixes RSS feeds of assorted comic strips",
"fox");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_FETCH_FEED, $this);
$host->add_hook($host::HOOK_FEED_BASIC_INFO, $this);
$host->add_hook($host::HOOK_SUBSCRIBE_FEED, $this);
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
require_once __DIR__ . "/filter_base.php";
$filters = array_merge(glob(__DIR__ . "/filters.local/*.php"), glob(__DIR__ . "/filters/*.php"));
$names = [];
foreach ($filters as $file) {
$filter_name = preg_replace("/\..*$/", "", basename($file));
if (array_search($filter_name, $names) === FALSE) {
if (!class_exists($filter_name)) {
require_once $file;
}
array_push($names, $filter_name);
$filter = new $filter_name();
if (is_subclass_of($filter, "Af_ComicFilter")) {
array_push($this->filters, $filter);
array_push($names, $filter_name);
}
}
}
}
function hook_prefs_tab($args) {
if ($args != "prefFeeds") return;
print "<div dojoType=\"dijit.layout.AccordionPane\"
title=\"<i class='material-icons'>photo</i> ".__('Feeds supported by af_comics')."\">";
print "<p>" . __("The following comics are currently supported:") . "</p>";
$comics = array("GoComics");
foreach ($this->filters as $f) {
foreach ($f->supported() as $comic) {
array_push($comics, $comic);
}
}
asort($comics);
print "<ul class='panel panel-scrollable list list-unstyled'>";
foreach ($comics as $comic) {
print "<li>$comic</li>";
}
print "</ul>";
print "<p>".__("To subscribe to GoComics use the comic's regular web page as the feed URL (e.g. for the <em>Garfield</em> comic use <code>http://www.gocomics.com/garfield</code>).")."</p>";
print "<p>".__('Drop any updated filters into <code>filters.local</code> in plugin directory.')."</p>";
print "</div>";
}
function hook_article_filter($article) {
foreach ($this->filters as $f) {
if ($f->process($article))
break;
}
return $article;
}
// GoComics dropped feed support so it needs to be handled when fetching the feed.
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass) {
if ($auth_login || $auth_pass)
return $feed_data;
if (preg_match('#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i', $fetch_url, $comic)) {
$site_url = 'https://www.gocomics.com/' . $comic[1];
$article_link = $site_url . date('/Y/m/d');
$body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false));
require_once 'lib/MiniTemplator.class.php';
$feed_title = htmlspecialchars($comic[1]);
$site_url = htmlspecialchars($site_url);
$article_link = htmlspecialchars($article_link);
$tpl = new MiniTemplator();
$tpl->readTemplateFromFile('templates/generated_feed.txt');
$tpl->setVariable('FEED_TITLE', $feed_title, true);
$tpl->setVariable('VERSION', VERSION, true);
$tpl->setVariable('FEED_URL', htmlspecialchars($fetch_url), true);
$tpl->setVariable('SELF_URL', $site_url, true);
$tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c'), true);
$tpl->setVariable('ARTICLE_UPDATED_RFC822', date(DATE_RFC822), true);
if ($body) {
$doc = new DOMDocument();
if (@$doc->loadHTML($body)) {
$xpath = new DOMXPath($doc);
$node = $xpath->query('//picture[contains(@class, "item-comic-image")]/img')->item(0);
if ($node) {
$node->removeAttribute("width");
$node->removeAttribute("data-srcset");
$node->removeAttribute("srcset");
$tpl->setVariable('ARTICLE_ID', $article_link, true);
$tpl->setVariable('ARTICLE_LINK', $article_link, true);
$tpl->setVariable('ARTICLE_TITLE', date('l, F d, Y'), true);
$tpl->setVariable('ARTICLE_EXCERPT', '', true);
$tpl->setVariable('ARTICLE_CONTENT', $doc->saveHTML($node), true);
$tpl->setVariable('ARTICLE_AUTHOR', '', true);
$tpl->setVariable('ARTICLE_SOURCE_LINK', $site_url, true);
$tpl->setVariable('ARTICLE_SOURCE_TITLE', $feed_title, true);
$tpl->addBlock('entry');
}
}
}
$tpl->addBlock('feed');
$tmp_data = '';
if ($tpl->generateOutputToString($tmp_data))
$feed_data = $tmp_data;
}
return $feed_data;
}
function hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) {
if ($auth_login || $auth_pass)
return $contents;
if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $url))
return '<?xml version="1.0" encoding="utf-8"?>'; // Get is_html() to return false.
return $contents;
}
function hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass) {
if ($auth_login || $auth_pass)
return $basic_info;
if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $fetch_url, $matches))
$basic_info = array('title' => ucfirst($matches[1]), 'site_url' => $matches[0]);
return $basic_info;
}
function api_version() {
return 2;
}
}