split a bunch of plugins into separate repos

This commit is contained in:
Andrew Dolgov 2021-03-04 15:09:56 +03:00
parent b74e313844
commit 2f6ea8b387
9 changed files with 0 additions and 782 deletions

View File

@ -1,44 +0,0 @@
<?php
class Af_Fsckportal extends Plugin {
private $host;
function about() {
return array(null,
"Remove feedsportal spamlinks from article content",
"fox");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
}
function hook_article_filter($article) {
$doc = new DOMDocument();
if (@$doc->loadHTML('<?xml encoding="UTF-8">' . $article["content"])) {
$xpath = new DOMXPath($doc);
$entries = $xpath->query('(//img[@src]|//a[@href])');
foreach ($entries as $entry) {
if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
$entry->parentNode->removeChild($entry);
} else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
$entry->parentNode->removeChild($entry);
}
}
$article["content"] = $doc->saveHTML();
}
return $article;
}
function api_version() {
return 2;
}
}

View File

@ -1,252 +0,0 @@
<?php
class Af_Proxy_Http extends Plugin {
/* @var PluginHost $host */
private $host;
/* @var DiskCache $cache */
private $cache;
function about() {
return array(null,
"Loads media served over plain HTTP via built-in secure proxy",
"fox");
}
private $ssl_known_whitelist = "imgur.com gfycat.com i.reddituploads.com pbs.twimg.com i.redd.it i.sli.mg media.tumblr.com";
function is_public_method($method) {
return $method === "imgproxy";
}
function init($host) {
$this->host = $host;
$this->cache = new DiskCache("images");
$host->add_hook($host::HOOK_RENDER_ARTICLE, $this, 150);
$host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this, 150);
$host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
if (empty($_SESSION['af_proxy_http_token']))
$_SESSION['af_proxy_http_token'] = bin2hex(get_random_bytes(16));
}
function hook_enclosure_entry($enc) {
if (preg_match("/image/", $enc["content_type"])) {
$proxy_all = $this->host->get($this, "proxy_all");
$enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], $proxy_all);
}
return $enc;
}
function hook_render_article($article) {
return $this->hook_render_article_cdm($article);
}
public function imgproxy() {
$url = UrlHelper::validate(clean($_REQUEST["url"]));
// immediately redirect to original URL if:
// - url points back to ourselves
// - called without user context
// - session-spefific token is invalid
if (
strpos($url, get_self_url_prefix()) === 0 ||
empty($_SESSION["uid"]) ||
$_REQUEST['af_proxy_http_token'] != $_SESSION['af_proxy_http_token']) {
header("Location: $url");
return;
}
$local_filename = sha1($url);
if ($this->cache->exists($local_filename)) {
header("Location: " . $this->cache->get_url($local_filename));
return;
} else {
$data = UrlHelper::fetch(["url" => $url, "max_size" => Config::get(Config::MAX_CACHE_FILE_SIZE)]);
if ($data) {
if ($this->cache->put($local_filename, $data)) {
header("Location: " . $this->cache->get_url($local_filename));
return;
}
} else {
if (function_exists("imagecreate") && !isset($_REQUEST["text"])) {
$img = imagecreate(450, 75);
/*$bg =*/ imagecolorallocate($img, 255, 255, 255);
$textcolor = imagecolorallocate($img, 255, 0, 0);
imagerectangle($img, 0, 0, 450-1, 75-1, $textcolor);
imagestring($img, 5, 5, 5, "Proxy request failed", $textcolor);
imagestring($img, 5, 5, 30, truncate_middle($url, 46, "..."), $textcolor);
imagestring($img, 5, 5, 55, "HTTP Code: ".UrlHelper::$fetch_last_error_code, $textcolor);
header("Content-type: image/png");
print imagepng($img);
imagedestroy($img);
} else {
header("Content-type: text/plain");
http_response_code(400);
print "Proxy request failed.\n".
"Fetch error ".UrlHelper::$fetch_last_error." (".UrlHelper::$fetch_last_error_code.")\n".
"Requested URL: $url";
}
}
}
}
private function rewrite_url_if_needed($url, $all_remote = false) {
/* don't rewrite urls pointing to ourselves */
if (strpos($url, get_self_url_prefix()) === 0)
return $url;
/* we don't need to handle URLs where local cache already exists, tt-rss rewrites those automatically */
if (!$this->cache->exists(sha1($url))) {
$scheme = parse_url($url, PHP_URL_SCHEME);
if ($all_remote) {
$host = parse_url($url, PHP_URL_HOST);
$self_host = parse_url(get_self_url_prefix(), PHP_URL_HOST);
$is_remote = $host != $self_host;
} else {
$is_remote = false;
}
if (($scheme != 'https' && $scheme != "") || $is_remote) {
if (strpos($url, "data:") !== 0) {
$parts = parse_url($url);
foreach (explode(" " , $this->ssl_known_whitelist) as $host) {
if (substr(strtolower($parts['host']), -strlen($host)) === strtolower($host)) {
$parts['scheme'] = 'https';
$url = UrlHelper::build_url($parts);
if ($all_remote && $is_remote) {
break;
} else {
return $url;
}
}
}
return $this->host->get_public_method_url($this, "imgproxy",
["url" => $url, "af_proxy_http_token" => $_SESSION["af_proxy_http_token"]]);
}
}
}
return $url;
}
function hook_render_article_cdm($article, $api_mode = false) {
$need_saving = false;
$proxy_all = $this->host->get($this, "proxy_all");
$doc = new DOMDocument();
if (@$doc->loadHTML('<?xml encoding="UTF-8">' . $article["content"])) {
$xpath = new DOMXPath($doc);
$imgs = $xpath->query("//img[@src]");
foreach ($imgs as $img) {
$new_src = $this->rewrite_url_if_needed($img->getAttribute("src"), $proxy_all);
if ($new_src != $img->getAttribute("src")) {
$img->setAttribute("src", $new_src);
$img->removeAttribute("srcset");
$need_saving = true;
}
}
$vids = $xpath->query("(//video|//picture)");
foreach ($vids as $vid) {
if ($vid->hasAttribute("poster")) {
$new_src = $this->rewrite_url_if_needed($vid->getAttribute("poster"), $proxy_all);
if ($new_src != $vid->getAttribute("poster")) {
$vid->setAttribute("poster", $new_src);
$need_saving = true;
}
}
$vsrcs = $xpath->query("source", $vid);
foreach ($vsrcs as $vsrc) {
$new_src = $this->rewrite_url_if_needed($vsrc->getAttribute("src"), $proxy_all);
if ($new_src != $vsrc->getAttribute("src")) {
$vid->setAttribute("src", $new_src);
$need_saving = true;
}
}
}
}
if ($need_saving) $article["content"] = $doc->saveHTML();
return $article;
}
function hook_prefs_tab($args) {
if ($args != "prefFeeds") return;
?>
<div dojoType="dijit.layout.AccordionPane"
title="<i class='material-icons'>extension</i> <?= __('Image proxy settings (af_proxy_http)') ?>">
<form dojoType="dijit.form.Form">
<?= \Controls\pluginhandler_tags($this, "save") ?>
<script type="dojo/method" event="onSubmit" args="evt">
evt.preventDefault();
if (this.validate()) {
xhr.post("backend.php", this.getValues(), (reply) => {
Notify.info(reply);
})
}
</script>
<fieldset>
<label class="checkbox">
<?= \Controls\checkbox_tag("proxy_all", $this->host->get($this, "proxy_all")) ?>
<?= __("Enable proxy for all remote images.") ?>
</label>
</fieldset>
<hr/>
<?= \Controls\submit_tag(__("Save")) ?>
</form>
</div>
<?php
}
function save() {
$proxy_all = checkbox_to_sql_bool($_POST["proxy_all"] ?? "");
$this->host->set($this, "proxy_all", $proxy_all);
echo __("Configuration saved");
}
function api_version() {
return 2;
}
}

View File

@ -1,33 +0,0 @@
<?php
class Close_Button extends Plugin {
private $host;
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
}
function about() {
return array(null,
"Adds a button to close article panel",
"fox");
}
function get_css() {
return ".post .header .buttons i.material-icons.icon-close-article { color : red; }";
}
function hook_article_button($line) {
if (!get_pref(Prefs::COMBINED_DISPLAY_MODE)) {
return "<i class='material-icons icon-close-article'
style='cursor : pointer' onclick='Article.close()'
title='".__('Close article')."'>close</i>";
}
}
function api_version() {
return 2;
}
}

View File

@ -1,235 +0,0 @@
<?php
class Mail extends Plugin {
/* @var PluginHost $host */
private $host;
function about() {
return array(null,
"Share article via email",
"fox");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
$host->add_hook($host::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, $this);
}
function get_js() {
return file_get_contents(__DIR__ . "/mail.js");
}
function hook_headline_toolbar_select_menu_item($feed_id, $is_cat) {
return "<div dojoType='dijit.MenuItem' onclick='Plugins.Mail.send()'>".__('Forward by email')."</div>";
}
function save() {
$addresslist = $_POST["addresslist"];
$this->host->set($this, "addresslist", $addresslist);
echo __("Mail addresses saved.");
}
function hook_prefs_tab($args) {
if ($args != "prefPrefs") return;
$addresslist = $this->host->get($this, "addresslist");
?>
<div dojoType="dijit.layout.AccordionPane"
title="<i class='material-icons'>mail</i> <?= __('Mail plugin') ?>">
<form dojoType="dijit.form.Form">
<?= \Controls\pluginhandler_tags($this, "save") ?>
<script type="dojo/method" event="onSubmit" args="evt">
evt.preventDefault();
if (this.validate()) {
Notify.progress('Saving data...', true);
xhr.post("backend.php", this.getValues(), (reply) => {
Notify.info(reply);
})
}
</script>
<header><?= __("You can set predefined email addressed here (comma-separated list):") ?></header>
<textarea dojoType="dijit.form.SimpleTextarea" style='font-size : 12px; width : 50%' rows="3"
name='addresslist'><?= $addresslist ?></textarea>
<hr/>
<?= \Controls\submit_tag(__("Save")) ?>
</form>
</div>
<?php
}
function hook_article_button($line) {
return "<i class='material-icons' style=\"cursor : pointer\"
onclick=\"Plugins.Mail.send(".$line["id"].")\"
title='".__('Forward by email')."'>mail</i>";
}
function emailArticle() {
$ids = explode(",", clean($_REQUEST['ids']));
$ids_qmarks = arr_qmarks($ids);
$sth = $this->pdo->prepare("SELECT email, full_name FROM ttrss_users WHERE
id = ?");
$sth->execute([$_SESSION['uid']]);
if ($row = $sth->fetch()) {
$user_email = htmlspecialchars($row['email']);
$user_name = htmlspecialchars($row['full_name']);
} else {
$user_name = "";
$user_email = "";
}
if (!$user_name)
$user_name = $_SESSION['name'];
$tpl = new Templator();
$tpl->readTemplateFromFile("email_article_template.txt");
$tpl->setVariable('USER_NAME', $_SESSION["name"], true);
$tpl->setVariable('USER_EMAIL', $user_email, true);
$tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
$sth = $this->pdo->prepare("SELECT DISTINCT link, content, title, note
FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
id IN ($ids_qmarks) AND owner_uid = ?");
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
if (count($ids) > 1) {
$subject = __("[Forwarded]") . " " . __("Multiple articles");
} else {
$subject = "";
}
while ($line = $sth->fetch()) {
if (!$subject)
$subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
$tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
$tnote = strip_tags($line["note"]);
if( $tnote != ''){
$tpl->setVariable('ARTICLE_NOTE', $tnote, true);
$tpl->addBlock('note');
}
$tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
$tpl->addBlock('article');
}
$tpl->addBlock('email');
$content = "";
$tpl->generateOutputToString($content);
$addresslist = explode(",", $this->host->get($this, "addresslist"));
?>
<form dojoType='dijit.form.Form'>
<?= \Controls\pluginhandler_tags($this, "sendemail") ?>
<?= \Controls\hidden_tag("from_email", $user_email) ?>
<?= \Controls\hidden_tag("from_name", $user_name) ?>
<script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault();
if (this.validate()) {
xhr.json("backend.php", this.getValues(), (reply) => {
if (reply && reply.error)
Notify.error(reply.error);
else
this.hide();
});
}
</script>
<section>
<fieldset class='narrow'>
<label><?= __('To:') ?></label>
<?= \Controls\select_tag("destination", "", $addresslist,
["style" => "width: 380px", "required" => 1, "dojoType" => "dijit.form.ComboBox"]) ?>
</fieldset>
</section>
<section>
<fieldset class='narrow'>
<label><?= __('Subject:') ?></label>
<input dojoType='dijit.form.ValidationTextBox' required='true'
style='width : 380px' name='subject' value="<?= htmlspecialchars($subject) ?>" id='subject'>
</fieldset>
</section>
<textarea dojoType='dijit.form.SimpleTextarea'
style='height : 200px; font-size : 12px; width : 98%' rows="20"
name='content'><?= $content ?></textarea>
<footer>
<?= \Controls\submit_tag(__('Send email')) ?>
<?= \Controls\cancel_dialog_tag(__('Cancel')) ?>
</footer>
</form>
<?php
}
function sendEmail() {
$reply = array();
/*$mail->AddReplyTo(strip_tags($_REQUEST['from_email']),
strip_tags($_REQUEST['from_name']));
//$mail->AddAddress($_REQUEST['destination']);
$addresses = explode(';', $_REQUEST['destination']);
foreach($addresses as $nextaddr)
$mail->AddAddress($nextaddr);
$mail->IsHTML(false);
$mail->Subject = $_REQUEST['subject'];
$mail->Body = $_REQUEST['content'];
$rc = $mail->Send(); */
$to = $_REQUEST["destination"];
$subject = strip_tags($_REQUEST["subject"]);
$message = strip_tags($_REQUEST["content"]);
$from = strip_tags($_REQUEST["from_email"]);
$mailer = new Mailer();
$rc = $mailer->mail(["to_address" => $to,
"headers" => ["Reply-To: $from"],
"subject" => $subject,
"message" => $message]);
if (!$rc) {
$reply['error'] = $mailer->error();
} else {
//save_email_address($destination);
$reply['message'] = "UPDATE_COUNTERS";
}
print json_encode($reply);
}
function api_version() {
return 2;
}
}

View File

@ -1,51 +0,0 @@
/* global Plugins, Headlines, dojo, App, xhr, Notify, fox, __ */
Plugins.Mail = {
send: function(id) {
if (!id) {
const ids = Headlines.getSelected();
if (ids.length == 0) {
alert(__("No articles selected."));
return;
}
id = ids.toString();
}
const dialog = new fox.SingleUseDialog({
title: __("Forward article by email"),
execute: function () {
if (this.validate()) {
xhr.json("backend.php", this.attr('value'), (reply) => {
if (reply) {
const error = reply['error'];
if (error) {
alert(__('Error sending email:') + ' ' + error);
} else {
Notify.info('Your message has been sent.');
dialog.hide();
}
}
});
}
},
content: __("Loading, please wait...")
});
const tmph = dojo.connect(dialog, 'onShow', function () {
dojo.disconnect(tmph);
xhr.post("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (reply) => {
dialog.attr('content', reply);
});
});
dialog.show();
},
onHotkey: function(id) {
Plugins.Mail.send(id);
}
};

View File

@ -1,39 +0,0 @@
/* global Plugins, Headlines, xhr, dojo, fox, __ */
Plugins.Mailto = {
send: function (id) {
if (!id) {
const ids = Headlines.getSelected();
if (ids.length == 0) {
alert(__("No articles selected."));
return;
}
id = ids.toString();
}
const dialog = new fox.SingleUseDialog({
title: __("Forward article by email (mailto:)"),
content: __("Loading, please wait...")
});
const tmph = dojo.connect(dialog, 'onShow', function () {
dojo.disconnect(tmph);
xhr.post("backend.php", App.getPhArgs("mailto", "emailArticle", {ids: id}), (reply) => {
dialog.attr('content', reply);
});
});
dialog.show();
}
};
// override default hotkey action if enabled
Plugins.Mail = Plugins.Mail || {};
Plugins.Mail.onHotkey = function(id) {
Plugins.Mailto.send(id);
};

View File

@ -1,95 +0,0 @@
<?php
class MailTo extends Plugin {
private $host;
function about() {
return array(null,
"Share article via email (using mailto: links, invoking your mail client)",
"fox");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
$host->add_hook($host::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, $this);
}
function hook_headline_toolbar_select_menu_item($feed_id, $is_cat) {
return "<div dojoType='dijit.MenuItem' onclick='Plugins.Mailto.send()'>".__('Forward by email (mailto:)')."</div>";
}
function get_js() {
return file_get_contents(__DIR__ . "/init.js");
}
function hook_article_button($line) {
return "<i class='material-icons' style=\"cursor : pointer\"
onclick=\"Plugins.Mailto.send(".$line["id"].")\"
title='".__('Forward by email (mailto:)')."'>mail_outline</i>";
}
function emailArticle() {
$ids = explode(",", clean($_REQUEST['ids']));
$ids_qmarks = arr_qmarks($ids);
$tpl = new Templator();
$tpl->readTemplateFromFile("email_article_template.txt");
$tpl->setVariable('USER_NAME', $_SESSION["name"], true);
//$tpl->setVariable('USER_EMAIL', $user_email, true);
$tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
$sth = $this->pdo->prepare("SELECT DISTINCT link, content, title
FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
id IN ($ids_qmarks) AND owner_uid = ?");
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
if (count($ids) > 1) {
$subject = __("[Forwarded]") . " " . __("Multiple articles");
} else {
$subject = "";
}
while ($line = $sth->fetch()) {
if (!$subject)
$subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
$tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
$tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
$tpl->addBlock('article');
}
$tpl->addBlock('email');
$content = "";
$tpl->generateOutputToString($content);
$mailto_link = "mailto:?subject=".rawurlencode($subject)."&body=".rawurlencode($content);
?>
<section>
<div class='panel text-center'>
<a target="_blank" href="<?= htmlspecialchars($mailto_link) ?>">
<?= __("Click to open your mail client") ?>
</a>
</div>
</section>
<footer class='text-center'>
<?= \Controls\submit_tag(__('Close this dialog')) ?>
</footer>
<?php
}
function api_version() {
return 2;
}
}

View File

@ -1,9 +0,0 @@
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
ready(function () {
PluginHost.register(PluginHost.HOOK_INIT_COMPLETE, () => {
App.updateTitle = function () {
document.title = "Tiny Tiny RSS";
};
});
});
});

View File

@ -1,24 +0,0 @@
<?php
class No_Title_Counters extends Plugin {
private $host;
function about() {
return array(null,
"Remove counters from window title (prevents tab flashing on new articles)",
"fox");
}
function init($host) {
$this->host = $host;
}
function get_js() {
return file_get_contents(__DIR__ . "/init.js");
}
function api_version() {
return 2;
}
}