summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/af_comics/filter_base.php14
-rw-r--r--plugins/af_comics/filters/af_comics_gocomics.php96
-rw-r--r--plugins/af_comics/filters/af_comics_gocomics_farside.php95
-rwxr-xr-xplugins/af_comics/init.php97
-rw-r--r--plugins/af_readability/init.js33
-rwxr-xr-xplugins/af_readability/init.php25
-rwxr-xr-xplugins/af_redditimgur/init.php50
-rw-r--r--plugins/auth_internal/init.php2
8 files changed, 305 insertions, 107 deletions
diff --git a/plugins/af_comics/filter_base.php b/plugins/af_comics/filter_base.php
index bfa077776..d6a697bb4 100644
--- a/plugins/af_comics/filter_base.php
+++ b/plugins/af_comics/filter_base.php
@@ -2,4 +2,16 @@
abstract class Af_ComicFilter {
public abstract function supported();
public abstract function process(&$article);
-} \ No newline at end of file
+
+ public function on_subscribe($url) {
+ return false;
+ }
+
+ public function on_basic_info($url) {
+ return false;
+ }
+
+ public function on_fetch($url) {
+ 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..791dc07d3
--- /dev/null
+++ b/plugins/af_comics/filters/af_comics_gocomics.php
@@ -0,0 +1,96 @@
+<?php
+class Af_Comics_Gocomics extends Af_ComicFilter {
+
+ function supported() {
+ return ["GoComics (see note below)"];
+ }
+
+ function process(&$article) {
+ return false;
+ }
+
+ public function on_subscribe($url) {
+ 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.
+ else
+ return false;
+ }
+
+ public function on_basic_info($url) {
+ if (preg_match('#^https?://www\.gocomics\.com/([-a-z0-9]+)$#i', $url, $matches))
+ return ['title' => ucfirst($matches[1]), 'site_url' => $matches[0]];
+ else
+ return false;
+ }
+
+ public function on_fetch($url) {
+ if (preg_match('#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i', $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', get_version(), true);
+ $tpl->setVariable('FEED_URL', htmlspecialchars($url), true);
+ $tpl->setVariable('SELF_URL', $site_url, 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) {
+ $title = $xpath->query('//h1')->item(0);
+
+ if ($title) {
+ $title = clean(trim($title->nodeValue));
+ } else {
+ $title = date('l, F d, Y');
+ }
+
+ foreach (['srcset', 'sizes', 'data-srcset', 'width'] as $attr ) {
+ $node->removeAttribute($attr);
+ }
+
+ $tpl->setVariable('ARTICLE_ID', $article_link, true);
+ $tpl->setVariable('ARTICLE_LINK', $article_link, true);
+ $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', mktime(11, 0, 0)), true);
+ $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($title), 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');
+
+ if ($tpl->generateOutputToString($tmp_data))
+ return $tmp_data;
+
+ }
+
+ return false;
+ }
+
+}
diff --git a/plugins/af_comics/filters/af_comics_gocomics_farside.php b/plugins/af_comics/filters/af_comics_gocomics_farside.php
new file mode 100644
index 000000000..783907e17
--- /dev/null
+++ b/plugins/af_comics/filters/af_comics_gocomics_farside.php
@@ -0,0 +1,95 @@
+<?php
+class Af_Comics_Gocomics_FarSide extends Af_ComicFilter {
+
+ function supported() {
+ return ["The Far Side (needs cache media)"];
+ }
+
+ function process(&$article) {
+ return false;
+ }
+
+ public function on_subscribe($url) {
+ if (preg_match("#^https?://www\.thefarside\.com#", $url))
+ return '<?xml version="1.0" encoding="utf-8"?>'; // Get is_html() to return false.
+ else
+ return false;
+ }
+
+ public function on_basic_info($url) {
+ if (preg_match("#^https?://www.thefarside.com/#", $url))
+ return ['title' => "The Far Side", 'site_url' => 'https://www.thefarside.com'];
+ else
+ return false;
+ }
+
+ public function on_fetch($url) {
+ if (preg_match("#^https?://www\.thefarside\.com#", $url)) {
+ require_once 'lib/MiniTemplator.class.php';
+
+ $article_link = htmlspecialchars("https://www.thefarside.com" . date('/Y/m/d'));
+
+ $tpl = new MiniTemplator();
+
+ $tpl->readTemplateFromFile('templates/generated_feed.txt');
+
+ $tpl->setVariable('FEED_TITLE', "The Far Side", true);
+ $tpl->setVariable('VERSION', get_version(), true);
+ $tpl->setVariable('FEED_URL', htmlspecialchars($url), true);
+ $tpl->setVariable('SELF_URL', htmlspecialchars($url), true);
+
+ $body = fetch_file_contents(['url' => $article_link, 'type' => 'text/html', 'followlocation' => false]);
+
+ if ($body) {
+ $doc = new DOMDocument();
+
+ if (@$doc->loadHTML($body)) {
+ $xpath = new DOMXPath($doc);
+
+ $content_node = $xpath->query('//*[contains(@class,"js-daily-dose")]')->item(0);
+
+ if ($content_node) {
+ $imgs = $xpath->query('//img[@data-src]', $content_node);
+
+ foreach ($imgs as $img) {
+ $img->setAttribute('src', $img->getAttribute('data-src'));
+ }
+
+ $junk_elems = $xpath->query("//*[@data-shareable-popover]");
+
+ foreach ($junk_elems as $junk)
+ $junk->parentNode->removeChild($junk);
+
+ $title = $xpath->query('//h3')->item(0);
+
+ if ($title) {
+ $title = clean(trim($title->nodeValue));
+ } else {
+ $title = date('l, F d, Y');
+ }
+
+ $tpl->setVariable('ARTICLE_ID', htmlspecialchars($article_link), true);
+ $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($article_link), true);
+ $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', mktime(11, 0, 0)), true);
+ $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($title), true);
+ $tpl->setVariable('ARTICLE_EXCERPT', '', true);
+ $tpl->setVariable('ARTICLE_CONTENT', "<p> " . $doc->saveHTML($content_node) . "</p>", true);
+
+ $tpl->setVariable('ARTICLE_AUTHOR', '', true);
+ $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($article_link), true);
+ $tpl->setVariable('ARTICLE_SOURCE_TITLE', "The Far Side", true);
+
+ $tpl->addBlock('entry');
+ }
+ }
+ }
+
+ $tpl->addBlock('feed');
+
+ if ($tpl->generateOutputToString($tmp_data))
+ return $tmp_data;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/af_comics/init.php b/plugins/af_comics/init.php
index 47e5894a7..d07220894 100755
--- a/plugins/af_comics/init.php
+++ b/plugins/af_comics/init.php
@@ -52,7 +52,7 @@ class Af_Comics extends Plugin {
print "<p>" . __("The following comics are currently supported:") . "</p>";
- $comics = array("GoComics");
+ $comics = [];
foreach ($this->filters as $f) {
foreach ($f->supported() as $comic) {
@@ -68,9 +68,9 @@ class Af_Comics extends Plugin {
}
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_notice("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>).");
- print "<p>".__('Drop any updated filters into <code>filters.local</code> in plugin directory.')."</p>";
+ print_notice('Drop any updated filters into <code>filters.local</code> in plugin directory.');
print "</div>";
}
@@ -84,98 +84,35 @@ class Af_Comics extends Plugin {
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', get_version(), true);
- $tpl->setVariable('FEED_URL', htmlspecialchars($fetch_url), true);
- $tpl->setVariable('SELF_URL', $site_url, 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) {
- $title = $xpath->query('//h1')->item(0);
-
- if ($title) {
- $title = clean(trim($title->nodeValue));
- } else {
- $title = date('l, F d, Y');
- }
-
- foreach (['srcset', 'sizes', 'data-srcset', 'width'] as $attr ) {
- $node->removeAttribute($attr);
- }
-
- $tpl->setVariable('ARTICLE_ID', $article_link, true);
- $tpl->setVariable('ARTICLE_LINK', $article_link, true);
- $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', mktime(11, 0, 0)), true);
- $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($title), 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');
+ foreach ($this->filters as $f) {
+ $res = $f->on_fetch($fetch_url);
- if ($tpl->generateOutputToString($tmp_data))
- $feed_data = $tmp_data;
+ if ($res)
+ return $res;
}
return $feed_data;
}
function hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) {
- if ($auth_login || $auth_pass)
- return $contents;
+ foreach ($this->filters as $f) {
+ $res = $f->on_subscribe($url);
- 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.
+ if ($res)
+ return $res;
+ }
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;
+ foreach ($this->filters as $f) {
+ $res = $f->on_basic_info($fetch_url);
- 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]);
+ if ($res)
+ return $res;
+ }
return $basic_info;
}
diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js
new file mode 100644
index 000000000..644dff9fe
--- /dev/null
+++ b/plugins/af_readability/init.js
@@ -0,0 +1,33 @@
+Plugins.Af_Readability = {
+ orig_attr_name: 'data-readability-orig-content',
+ self: this,
+ embed: function(id) {
+ const content = $$(App.isCombinedMode() ? ".cdm[data-article-id=" + id + "] .content-inner" :
+ ".post[data-article-id=" + id + "] .content")[0];
+
+ if (content.hasAttribute(self.orig_attr_name)) {
+ content.innerHTML = content.getAttribute(self.orig_attr_name);
+ content.removeAttribute(self.orig_attr_name);
+
+ if (App.isCombinedMode()) Article.cdmScrollToId(id);
+
+ return;
+ }
+
+ Notify.progress("Loading, please wait...");
+
+ xhrJson("backend.php",{ op: "pluginhandler", plugin: "af_readability", method: "embed", param: id }, (reply) => {
+
+ if (content && reply.content) {
+ content.setAttribute(self.orig_attr_name, content.innerHTML);
+ content.innerHTML = reply.content;
+ Notify.close();
+
+ if (App.isCombinedMode()) Article.cdmScrollToId(id);
+
+ } else {
+ Notify.error("Unable to fetch full text for this article");
+ }
+ });
+ }
+};
diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php
index a487707c8..9c62a4772 100755
--- a/plugins/af_readability/init.php
+++ b/plugins/af_readability/init.php
@@ -38,6 +38,7 @@ class Af_Readability extends Plugin {
$host->add_hook($host::HOOK_PREFS_TAB, $this);
$host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this);
$host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this);
+ $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
// Note: we have to install the hook even if disabled because init() is being run before plugin data has loaded
// so we can't check for our storage-set options here
@@ -46,6 +47,15 @@ class Af_Readability extends Plugin {
$host->add_filter_action($this, "action_inline", __("Inline content"));
}
+ function get_js() {
+ return file_get_contents(__DIR__ . "/init.js");
+ }
+
+ function hook_article_button($line) {
+ return "<i class='material-icons' onclick=\"Plugins.Af_Readability.embed(".$line["id"].")\"
+ style='cursor : pointer' title='".__('Toggle full article text')."'>description</i>";
+ }
+
function hook_prefs_tab($args) {
if ($args != "prefFeeds") return;
@@ -284,4 +294,19 @@ class Af_Readability extends Plugin {
return $tmp;
}
+ function embed() {
+ $article_id = (int) $_REQUEST["param"];
+
+ $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries WHERE id = ?");
+ $sth->execute([$article_id]);
+
+ $ret = [];
+
+ if ($row = $sth->fetch()) {
+ $ret["content"] = sanitize($this->extract_content($row["link"]));
+ }
+
+ print json_encode($ret);
+ }
+
}
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php
index c8ba4a1b2..d28e072f4 100755
--- a/plugins/af_redditimgur/init.php
+++ b/plugins/af_redditimgur/init.php
@@ -239,10 +239,10 @@ class Af_RedditImgur extends Plugin {
}
$matches = array();
- if (!$found && preg_match("/youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) ||
+ if (!$found && (preg_match("/youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) ||
preg_match("/youtube\.com\/.*?[\&\?]v=([\w-]+)/", $entry->getAttribute("href"), $matches) ||
preg_match("/youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) ||
- preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) {
+ preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches))) {
$vid_id = $matches[1];
@@ -264,9 +264,9 @@ class Af_RedditImgur extends Plugin {
$found = true;
}
- if (!$found && preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) ||
+ if (!$found && (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?[$\?]/i", $entry->getAttribute("href")) ||
mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE ||
- mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) {
+ mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE)) {
Debug::log("Handling as a picture", Debug::$LOG_VERBOSE);
@@ -280,36 +280,36 @@ class Af_RedditImgur extends Plugin {
$found = true;
}
- // imgur via link rel="image_src" href="..."
- if (!$found && preg_match("/imgur/", $entry->getAttribute("href"))) {
+ // imgur via link rel="image_src" href="..."
+ if (!$found && preg_match("/imgur/", $entry->getAttribute("href"))) {
- Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE);
+ Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE);
- $content = fetch_file_contents(["url" => $entry->getAttribute("href"),
- "http_accept" => "text/*"]);
+ $content = fetch_file_contents(["url" => $entry->getAttribute("href"),
+ "http_accept" => "text/*"]);
- if ($content) {
- $cdoc = new DOMDocument();
+ if ($content) {
+ $cdoc = new DOMDocument();
- if (@$cdoc->loadHTML($content)) {
- $cxpath = new DOMXPath($cdoc);
+ if (@$cdoc->loadHTML($content)) {
+ $cxpath = new DOMXPath($cdoc);
- $rel_image = $cxpath->query("//link[@rel='image_src']")->item(0);
+ $rel_image = $cxpath->query("//link[@rel='image_src']")->item(0);
- if ($rel_image) {
+ if ($rel_image) {
- $img = $doc->createElement('img');
- $img->setAttribute("src", $rel_image->getAttribute("href"));
+ $img = $doc->createElement('img');
+ $img->setAttribute("src", $rel_image->getAttribute("href"));
- $br = $doc->createElement('br');
- $entry->parentNode->insertBefore($img, $entry);
- $entry->parentNode->insertBefore($br, $entry);
+ $br = $doc->createElement('br');
+ $entry->parentNode->insertBefore($img, $entry);
+ $entry->parentNode->insertBefore($br, $entry);
- $found = true;
- }
- }
- }
- }
+ $found = true;
+ }
+ }
+ }
+ }
// wtf is this even
if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
diff --git a/plugins/auth_internal/init.php b/plugins/auth_internal/init.php
index bcba7970a..8dbc37fb3 100644
--- a/plugins/auth_internal/init.php
+++ b/plugins/auth_internal/init.php
@@ -64,7 +64,7 @@ class Auth_Internal extends Plugin implements IAuthModule {
<title>Tiny Tiny RSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
- <?php echo stylesheet_tag("css/default.css") ?>
+ <?php echo stylesheet_tag("themes/light.css") ?>
<body class="ttrss_utility otp">
<h1><?php echo __("Authentication") ?></h1>
<div class="content">