summaryrefslogtreecommitdiff
path: root/classes/handler/public.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/handler/public.php')
-rwxr-xr-xclasses/handler/public.php184
1 files changed, 102 insertions, 82 deletions
diff --git a/classes/handler/public.php b/classes/handler/public.php
index e4572382e..2de073cc2 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -1,9 +1,10 @@
<?php
class Handler_Public extends Handler {
- private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
- $limit, $offset, $search,
- $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) {
+ // $feed may be a tag
+ private function generate_syndicated_feed(int $owner_uid, string $feed, bool $is_cat,
+ int $limit, int $offset, string $search, string $view_mode = "",
+ string $format = 'atom', string $order = "", string $orig_guid = "", string $start_ts = "") {
$note_style = "background-color : #fff7d5;
border-width : 1px; ".
@@ -48,10 +49,10 @@ class Handler_Public extends Handler {
//$tmppluginhost->load_data();
$handler = $tmppluginhost->get_feed_handler(
- PluginHost::feed_to_pfeed_id($feed));
+ PluginHost::feed_to_pfeed_id((int)$feed));
if ($handler) {
- $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params);
+ $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id((int)$feed), $params);
}
} else {
@@ -63,7 +64,7 @@ class Handler_Public extends Handler {
$feed_site_url = $qfh_ret[2];
/* $last_error = $qfh_ret[3]; */
- $feed_self_url = get_self_url_prefix() .
+ $feed_self_url = Config::get_self_url() .
"/public.php?op=rss&id=$feed&key=" .
Feeds::_get_access_key($feed, false, $owner_uid);
@@ -75,7 +76,7 @@ class Handler_Public extends Handler {
$tpl->readTemplateFromFile("generated_feed.txt");
$tpl->setVariable('FEED_TITLE', $feed_title, true);
- $tpl->setVariable('VERSION', get_version(), true);
+ $tpl->setVariable('VERSION', Config::get_version(), true);
$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
$tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
@@ -151,7 +152,7 @@ class Handler_Public extends Handler {
$tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', "", true);
}
- list ($og_image, $og_stream) = Article::_get_image($enclosures, $line['content'], $feed_site_url);
+ list ($og_image, $og_stream) = Article::_get_image($enclosures, $line['content'], $feed_site_url, $line);
$tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true);
@@ -176,10 +177,8 @@ class Handler_Public extends Handler {
$feed['title'] = $feed_title;
$feed['feed_url'] = $feed_self_url;
-
- $feed['self_url'] = get_self_url_prefix();
-
- $feed['articles'] = array();
+ $feed['self_url'] = Config::get_self_url();
+ $feed['articles'] = [];
while ($line = $result->fetch()) {
@@ -304,7 +303,7 @@ class Handler_Public extends Handler {
$search = clean($_REQUEST["q"] ?? "");
$view_mode = clean($_REQUEST["view-mode"] ?? "");
$order = clean($_REQUEST["order"] ?? "");
- $start_ts = (int)clean($_REQUEST["ts"] ?? 0);
+ $start_ts = clean($_REQUEST["ts"] ?? "");
$format = clean($_REQUEST['format'] ?? "atom");
$orig_guid = clean($_REQUEST["orig_guid"] ?? false);
@@ -402,7 +401,7 @@ class Handler_Public extends Handler {
if ($_REQUEST['return'] && mb_strpos($return, Config::get(Config::SELF_URL_PATH)) === 0) {
header("Location: " . clean($_REQUEST['return']));
} else {
- header("Location: " . get_self_url_prefix());
+ header("Location: " . Config::get_self_url());
}
}
}
@@ -624,33 +623,57 @@ class Handler_Public extends Handler {
<!DOCTYPE html>
<html>
<head>
- <title>Database Updater</title>
+ <title>Tiny Tiny RSS: Database Updater</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <?= stylesheet_tag("themes/light.css") ?>
- <link rel="shortcut icon" type="image/png" href="images/favicon.png">
<link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png">
+ <link rel="shortcut icon" type="image/png" href="images/favicon.png">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
- echo stylesheet_tag("themes/light.css");
- echo javascript_tag("lib/dojo/dojo.js");
- echo javascript_tag("lib/dojo/tt-rss-layer.js");
- ?>
+ foreach (["lib/dojo/dojo.js",
+ "lib/dojo/tt-rss-layer.js",
+ "js/common.js",
+ "js/utility.js"] as $jsfile) {
+
+ echo javascript_tag($jsfile);
+
+ } ?>
+
+ <?php if (theme_exists(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET))) {
+ echo stylesheet_tag(get_theme_path(Config::get(Config::LOCAL_OVERRIDE_STYLESHEET)));
+ } ?>
+
<style type="text/css">
- span.ok { color : #009000; font-weight : bold; }
- span.err { color : #ff0000; font-weight : bold; }
+ @media (prefers-color-scheme: dark) {
+ body {
+ background : #303030;
+ }
+ }
+
+ body.css_loading * {
+ display : none;
+ }
</style>
+
+ <script type="text/javascript">
+ require({cache:{}});
+ </script>
</head>
- <body class="flat ttrss_utility">
+ <body class="flat ttrss_utility css_loading">
<script type="text/javascript">
- require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox', 'dijit/form/Form',
- 'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser, ready){
- ready(function() {
- parser.parse();
- });
- });
-
- function confirmOP() {
- return confirm("Update the database?");
+ const UtilityApp = {
+ init: function() {
+ require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox', 'dijit/form/Form',
+ 'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser, ready){
+ ready(function() {
+ parser.parse();
+ });
+ });
+ }
+ }
+
+ function confirmDbUpdate() {
+ return confirm(__("Proceed with update?"));
}
</script>
@@ -661,72 +684,66 @@ class Handler_Public extends Handler {
<?php
@$op = clean($_REQUEST["subop"] ?? "");
- $updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION);
-
- if ($op == "performupdate") {
- if ($updater->is_update_required()) {
- print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>";
+ $migrations = Config::get_migrations();
- for ($i = $updater->get_schema_version() + 1; $i <= SCHEMA_VERSION; $i++) {
- print "<ul>";
-
- print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>";
+ if ($op == "performupdate") {
+ if ($migrations->is_migration_needed()) {
+ ?>
- print "<li>";
- $result = $updater->update_to($i, true);
- print "</li>";
+ <h2><?= T_sprintf("Performing updates to version %d", Config::SCHEMA_VERSION) ?></h2>
- if (!$result) {
- print "</ul>";
+ <code><pre class="small pre-wrap"><?php
+ Debug::set_enabled(true);
+ Debug::set_loglevel(Debug::LOG_VERBOSE);
+ $result = $migrations->migrate();
+ Debug::set_loglevel(Debug::LOG_NORMAL);
+ Debug::set_enabled(false);
+ ?></pre></code>
- print_error("One of the updates failed. Either retry the process or perform updates manually.");
+ <?php if (!$result) { ?>
+ <?= format_error("One of migrations failed. Either retry the process or perform updates manually.") ?>
- print "<form method='POST'>
- <input type='hidden' name='subop' value='performupdate'>
- <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button>
- <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>
- </form>";
+ <form method="post">
+ <?= \Controls\hidden_tag('subop', 'performupdate') ?>
+ <?= \Controls\submit_tag(__("Update"), ["onclick" => "return confirmDbUpdate()"]) ?>
+ </form>
+ <?php } else { ?>
+ <?= format_notice("Update successful.") ?>
- return;
- } else {
- print "<li class='text-success'>" . __("Completed.") . "</li>";
- print "</ul>";
- }
- }
+ <a href="index.php"><?= __("Return to Tiny Tiny RSS") ?></a>
+ <?php }
- print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
+ } else { ?>
- print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
+ <?= format_notice("Database is already up to date.") ?>
- } else {
- print_notice("Tiny Tiny RSS database is up to date.");
+ <a href="index.php"><?= __("Return to Tiny Tiny RSS") ?></a>
- print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
+ <?php
}
} else {
- if ($updater->is_update_required()) {
+ if ($migrations->is_migration_needed()) {
- print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
- $updater->get_schema_version(), SCHEMA_VERSION)."</h2>";
+ ?>
+ <h2><?= T_sprintf("Database schema needs update to the latest version (%d to %d).",
+ Config::get_schema_version(), Config::SCHEMA_VERSION) ?></h2>
- if (Config::get(Config::DB_TYPE) == "mysql") {
- print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ".
- "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>");
- } else {
- print_warning("Please backup your database before proceeding.");
- }
+ <?= format_warning("Please backup your database before proceeding.") ?>
- print "<form method='POST'>
- <input type='hidden' name='subop' value='performupdate'>
- <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button>
- </form>";
+ <form method="post">
+ <?= \Controls\hidden_tag('subop', 'performupdate') ?>
+ <?= \Controls\submit_tag(__("Update"), ["onclick" => "return confirmDbUpdate()"]) ?>
+ </form>
- } else {
+ <?php
+ } else { ?>
+
+ <?= format_notice("Database is already up to date.") ?>
- print_notice("Tiny Tiny RSS database is up to date.");
+ <a href="index.php"><?= __("Return to Tiny Tiny RSS") ?></a>
- print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>";
+ <?php
}
}
?>
@@ -779,7 +796,7 @@ class Handler_Public extends Handler {
$timestamp = date("Y-m-d", strtotime($timestamp));
- return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id";
+ return "tag:" . parse_url(Config::get_self_url(), PHP_URL_HOST) . ",$timestamp:/$id";
}
// this should be used very carefully because this endpoint is exposed to unauthenticated users
@@ -817,9 +834,12 @@ class Handler_Public extends Handler {
}
}
- static function _render_login_form() {
+ static function _render_login_form(string $return_to = "") {
header('Cache-Control: public');
+ if ($return_to)
+ $_REQUEST['return'] = $return_to;
+
require_once "login_form.php";
exit;
}