summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/dbupdater.php65
-rw-r--r--classes/feeds.php15
-rw-r--r--classes/handler/public.php112
-rw-r--r--classes/pref/feeds.php4
-rw-r--r--classes/pref/prefs.php2
5 files changed, 190 insertions, 8 deletions
diff --git a/classes/dbupdater.php b/classes/dbupdater.php
new file mode 100644
index 000000000..a9a713273
--- /dev/null
+++ b/classes/dbupdater.php
@@ -0,0 +1,65 @@
+<?php
+class DbUpdater {
+
+ private $link;
+ private $db_type;
+ private $need_version;
+
+ function __construct($link, $db_type, $need_version) {
+ $this->link = $link;
+ $this->db_type = $db_type;
+ $this->need_version = (int) $need_version;
+ }
+
+ function getSchemaVersion() {
+ $result = db_query($this->link, "SELECT schema_version FROM ttrss_version");
+ return (int) db_fetch_result($result, 0, "schema_version");
+ }
+
+ function isUpdateRequired() {
+ return $this->getSchemaVersion() < $this->need_version;
+ }
+
+ function getSchemaLines($version) {
+ $filename = "schema/versions/".$this->db_type."/$version.sql";
+
+ if (file_exists($filename)) {
+ return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
+ } else {
+ return false;
+ }
+ }
+
+ function performUpdateTo($version) {
+ if ($this->getSchemaVersion() == $version - 1) {
+
+ $lines = $this->getSchemaLines($version);
+
+ if (is_array($lines)) {
+
+ db_query($this->link, "BEGIN");
+
+ foreach ($lines as $line) {
+ if (strpos($line, "--") !== 0 && $line) {
+ db_query($this->link, $line);
+ }
+ }
+
+ $db_version = $this->getSchemaVersion();
+
+ if ($db_version == $version) {
+ db_query($this->link, "COMMIT");
+ return true;
+ } else {
+ db_query($this->link, "ROLLBACK");
+ return false;
+ }
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+} ?>
diff --git a/classes/feeds.php b/classes/feeds.php
index 778850fc4..1d0bb5293 100644
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -866,12 +866,15 @@ class Feeds extends Handler_Protected {
$override_order = false;
switch ($order_by) {
- case "date_reverse":
- $override_order = "date_entered, updated";
- break;
- case "feed_dates":
- $override_order = "updated DESC";
- break;
+ case "title":
+ $override_order = "ttrss_entries.title";
+ break;
+ case "date_reverse":
+ $override_order = "date_entered, updated";
+ break;
+ case "feed_dates":
+ $override_order = "updated DESC";
+ break;
}
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
diff --git a/classes/handler/public.php b/classes/handler/public.php
index b8a32cd27..e95f118bb 100644
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -837,5 +837,117 @@ class Handler_Public extends Handler {
}
+ function dbupdate() {
+ if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
+ $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
+ render_login_form($link);
+ exit;
+ }
+
+ ?><html>
+ <head>
+ <title>Database Updater</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <link rel="stylesheet" type="text/css" href="utility.css"/>
+ </head>
+ <style type="text/css">
+ span.ok { color : #009000; font-weight : bold; }
+ span.err { color : #ff0000; font-weight : bold; }
+ </style>
+ <body>
+ <script type='text/javascript'>
+ function confirmOP() {
+ return confirm("Update the database?");
+ }
+ </script>
+
+ <div class="floatingLogo"><img src="images/logo_small.png"></div>
+
+ <h1><?php echo __("Database Updater") ?></h1>
+
+ <div class="content">
+
+ <?php
+ @$op = $_REQUEST["subop"];
+ $updater = new DbUpdater($this->link, DB_TYPE, SCHEMA_VERSION);
+
+ if ($op == "performupdate") {
+ if ($updater->isUpdateRequired()) {
+
+ print "<h2>Performing updates</h2>";
+
+ print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
+
+ print "<ul>";
+
+ for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
+ print "<li>Performing update up to version $i...";
+
+ $result = $updater->performUpdateTo($i);
+
+ if (!$result) {
+ print "<span class='err'>FAILED!</span></li></ul>";
+
+ print_warning("One of the updates failed. Either retry the process or perform updates manually.");
+ print "<p><form method=\"GET\" action=\"index.php\">
+ <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+ </form>";
+
+ break;
+ } else {
+ print "<span class='ok'>OK!</span></li>";
+ }
+ }
+
+ print "</ul>";
+
+ print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
+
+ print "<p><form method=\"GET\" action=\"index.php\">
+ <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+ </form>";
+
+ } else {
+ print "<h2>Your database is up to date.</h2>";
+
+ print "<p><form method=\"GET\" action=\"index.php\">
+ <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+ </form>";
+ }
+ } else {
+ if ($updater->isUpdateRequired()) {
+
+ print "<h2>Database update required</h2>";
+
+ print "<h3>";
+ printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
+ $updater->getSchemaVersion(), SCHEMA_VERSION);
+ print "</h3>";
+
+ print_warning("Please backup your database before proceeding.");
+
+ print "<form method='POST'>
+ <input type='hidden' name='subop' value='performupdate'>
+ <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
+ </form>";
+
+ } else {
+
+ print "<h2>" . "Tiny Tiny RSS database is up to date." . "</h2>";
+
+ print "<p><form method=\"GET\" action=\"index.php\">
+ <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+ </form>";
+
+ }
+ }
+ ?>
+
+ </div>
+ </body>
+ </html>
+ <?php
+ }
+
}
?>
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 7fb64623e..68535562f 100644
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1800,12 +1800,12 @@ class Pref_Feeds extends Handler_Protected {
function batchAddFeeds() {
$cat_id = db_escape_string($this->link, $_REQUEST['cat']);
- $feeds = explode("\n", db_escape_string($this->link, $_REQUEST['feeds']));
+ $feeds = explode("\n", $_REQUEST['feeds']);
$login = db_escape_string($this->link, $_REQUEST['login']);
$pass = db_escape_string($this->link, $_REQUEST['pass']);
foreach ($feeds as $feed) {
- $feed = trim($feed);
+ $feed = db_escape_string($this->link, trim($feed));
if (validate_feed_url($feed)) {
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index 730d556a5..445d0aadb 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -180,6 +180,8 @@ class Pref_Prefs extends Handler_Protected {
WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]);
initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]);
+
+ echo __("Your preferences are now set to default values.");
}
function index() {