From 6af83e3881b3f38104027275913f7fc55251d020 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 12 Feb 2021 21:43:38 +0300 Subject: drop ENABLE_GZIP_OUTPUT; system prefs: load php info only if needed --- api/index.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'api') diff --git a/api/index.php b/api/index.php index 77552af46..9e998df84 100644 --- a/api/index.php +++ b/api/index.php @@ -22,13 +22,7 @@ ini_set('session.use_cookies', 0); ini_set("session.gc_maxlifetime", 86400); - if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT && - function_exists("ob_gzhandler")) { - - ob_start("ob_gzhandler"); - } else { - ob_start(); - } + ob_start(); $input = file_get_contents("php://input"); -- cgit v1.2.3-54-g00ecf From 9f55454f63b11ad8d2b2e0a8264a0f0dae919f6b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 16:51:35 +0300 Subject: remove the rest of db.php; rename some leftover methods in feeds --- api/index.php | 1 - backend.php | 1 - classes/feeds.php | 12 ++++++------ include/db-prefs.php | 2 -- include/sessions.php | 1 - js/App.js | 3 +-- js/FeedTree.js | 2 +- opml.php | 1 - public.php | 1 - update.php | 1 - update_daemon2.php | 1 - 11 files changed, 8 insertions(+), 18 deletions(-) (limited to 'api') diff --git a/api/index.php b/api/index.php index 9e998df84..664e92abe 100644 --- a/api/index.php +++ b/api/index.php @@ -14,7 +14,6 @@ define('NO_SESSION_AUTOSTART', true); require_once "autoload.php"; - require_once "db.php"; require_once "db-prefs.php"; require_once "functions.php"; require_once "sessions.php"; diff --git a/backend.php b/backend.php index e72d97ca4..89b06b7eb 100644 --- a/backend.php +++ b/backend.php @@ -27,7 +27,6 @@ require_once "sessions.php"; require_once "functions.php"; require_once "config.php"; - require_once "db.php"; require_once "db-prefs.php"; $op = (string)clean($op); diff --git a/classes/feeds.php b/classes/feeds.php index 07e3aa455..2a3efdb92 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -438,7 +438,7 @@ class Feeds extends Handler_Protected { * when there's nothing to load - e.g. no stuff in fresh feed */ if ($feed == -5) { - print json_encode($this->generate_dashboard_feed()); + print json_encode($this->_generate_dashboard_feed()); return; } @@ -466,7 +466,7 @@ class Feeds extends Handler_Protected { } if ($sth && !$sth->fetch()) { - print json_encode($this->generate_error_feed(__("Feed not found."))); + print json_encode($this->_generate_error_feed(__("Feed not found."))); return; } @@ -523,7 +523,7 @@ class Feeds extends Handler_Protected { } - private function generate_dashboard_feed() { + private function _generate_dashboard_feed() { $reply = array(); $reply['headlines']['id'] = -5; @@ -565,7 +565,7 @@ class Feeds extends Handler_Protected { return $reply; } - private function generate_error_feed($error) { + private function _generate_error_feed($error) { $reply = array(); $reply['headlines']['id'] = -7; @@ -630,7 +630,7 @@ class Feeds extends Handler_Protected { print ""; } - function update_debugger() { + function updatedebugger() { header("Content-type: text/html"); $xdebug = isset($_REQUEST["xdebug"]) ? (int)$_REQUEST["xdebug"] : 1; @@ -690,7 +690,7 @@ class Feeds extends Handler_Protected {
- + diff --git a/include/db-prefs.php b/include/db-prefs.php index 91235b479..ce5753638 100644 --- a/include/db-prefs.php +++ b/include/db-prefs.php @@ -1,6 +1,4 @@ read($pref_name, $user_id, $die_on_error); } diff --git a/include/sessions.php b/include/sessions.php index 3119a4e07..4de894c95 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -2,7 +2,6 @@ // Original from http://www.daniweb.com/code/snippet43.html require_once "config.php"; - require_once "classes/db.php"; require_once "autoload.php"; require_once "errorhandler.php"; require_once "lib/gettext/gettext.inc.php"; diff --git a/js/App.js b/js/App.js index 5c2d7726c..4b2adc388 100644 --- a/js/App.js +++ b/js/App.js @@ -998,10 +998,9 @@ const App = { }; this.hotkey_actions["feed_debug_update"] = () => { if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) { - //window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActive()); /* global __csrf_token */ - App.postOpenWindow("backend.php", {op: "feeds", method: "update_debugger", + App.postOpenWindow("backend.php", {op: "feeds", method: "updatedebugger", feed_id: Feeds.getActive(), csrf_token: __csrf_token}); } else { diff --git a/js/FeedTree.js b/js/FeedTree.js index 26c1c916c..694cf8332 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -102,7 +102,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co label: __("Debug feed"), onClick: function() { /* global __csrf_token */ - App.postOpenWindow("backend.php", {op: "feeds", method: "update_debugger", + App.postOpenWindow("backend.php", {op: "feeds", method: "updatedebugger", feed_id: this.getParent().row_id, csrf_token: __csrf_token}); }})); } diff --git a/opml.php b/opml.php index 9b7809e0e..6f13a6f3c 100644 --- a/opml.php +++ b/opml.php @@ -7,7 +7,6 @@ require_once "sessions.php"; require_once "sanity_check.php"; require_once "config.php"; - require_once "db.php"; require_once "db-prefs.php"; if (!init_plugins()) return; diff --git a/public.php b/public.php index dcfc4056e..59b5a499c 100644 --- a/public.php +++ b/public.php @@ -7,7 +7,6 @@ require_once "functions.php"; require_once "sanity_check.php"; require_once "config.php"; - require_once "db.php"; require_once "db-prefs.php"; startup_gettext(); diff --git a/update.php b/update.php index cb927e49a..1f79dccf0 100755 --- a/update.php +++ b/update.php @@ -11,7 +11,6 @@ require_once "functions.php"; require_once "config.php"; require_once "sanity_check.php"; - require_once "db.php"; require_once "db-prefs.php"; function make_stampfile($filename) { diff --git a/update_daemon2.php b/update_daemon2.php index 61cc85617..2a016df48 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -19,7 +19,6 @@ define_default('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL); // seconds require_once "sanity_check.php"; - require_once "db.php"; require_once "db-prefs.php"; if (!function_exists('pcntl_fork')) { -- cgit v1.2.3-54-g00ecf From 9d7ba773ec97bfb44601348c07e818f1a1d2c841 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 17:13:16 +0300 Subject: move session-related functions to their own namespace --- api/index.php | 2 +- backend.php | 2 +- classes/userhelper.php | 2 +- include/sessions.php | 27 +++++++++++++++------------ 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'api') diff --git a/api/index.php b/api/index.php index 664e92abe..eb79422f9 100644 --- a/api/index.php +++ b/api/index.php @@ -50,7 +50,7 @@ if (!init_plugins()) return; if (!empty($_SESSION["uid"])) { - if (!validate_session()) { + if (!\Sessions\validate_session()) { header("Content-Type: text/json"); print json_encode(array("seq" => -1, diff --git a/backend.php b/backend.php index 89b06b7eb..9ecc22914 100644 --- a/backend.php +++ b/backend.php @@ -45,7 +45,7 @@ } if (!empty($_SESSION["uid"])) { - if (!validate_session()) { + if (!\Sessions\validate_session()) { header("Content-Type: text/json"); print error_json(6); return; diff --git a/classes/userhelper.php b/classes/userhelper.php index 8e9b9a01b..42d50a0f4 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -94,7 +94,7 @@ class UserHelper { startup_gettext(); self::load_user_plugins($_SESSION["uid"]); } else { - if (!validate_session()) $_SESSION["uid"] = false; + if (!\Sessions\validate_session()) $_SESSION["uid"] = false; if (empty($_SESSION["uid"])) { diff --git a/include/sessions.php b/include/sessions.php index 4de894c95..16de53ab2 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -1,4 +1,6 @@ query("SELECT schema_version FROM ttrss_version")->fetch(); + $row = \Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch(); $version = $row["schema_version"]; @@ -42,7 +44,7 @@ __("Session failed to validate (schema version changed)"); return false; } - $pdo = Db::pdo(); + $pdo = \Db::pdo(); if (!empty($_SESSION["uid"])) { @@ -85,7 +87,7 @@ function ttrss_read ($id){ global $session_expire; - $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); + $sth = \Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); $sth->execute([$id]); if ($row = $sth->fetch()) { @@ -94,7 +96,7 @@ } else { $expire = time() + $session_expire; - $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) + $sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, '', ?)"); $sth->execute([$id, $expire]); @@ -110,14 +112,14 @@ $data = base64_encode($data); $expire = time() + $session_expire; - $sth = Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?"); + $sth = \Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?"); $sth->execute([$id]); if ($row = $sth->fetch()) { - $sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?"); + $sth = \Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?"); $sth->execute([$data, $expire, $id]); } else { - $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) + $sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, ?, ?)"); $sth->execute([$id, $data, $expire]); } @@ -130,22 +132,23 @@ } function ttrss_destroy($id) { - $sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?"); + $sth = \Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?"); $sth->execute([$id]); return true; } function ttrss_gc ($expire) { - Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); + \Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); return true; } if (!SINGLE_USER_MODE /* && DB_TYPE == "pgsql" */) { - session_set_save_handler("ttrss_open", - "ttrss_close", "ttrss_read", "ttrss_write", - "ttrss_destroy", "ttrss_gc"); + session_set_save_handler('\Sessions\ttrss_open', + '\Sessions\ttrss_close', '\Sessions\ttrss_read', + '\Sessions\ttrss_write', '\Sessions\ttrss_destroy', + '\Sessions\ttrss_gc'); register_shutdown_function('session_write_close'); } -- cgit v1.2.3-54-g00ecf From be4e7b13403666fc477d4b563ea8c075d0fd2022 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 14:41:09 +0300 Subject: fix several issues reported by phpstan --- api/index.php | 4 ++-- classes/api.php | 2 +- classes/digest.php | 9 --------- classes/feeds.php | 6 ------ classes/handler/public.php | 10 +++++----- classes/pluginhost.php | 3 ++- classes/pref/prefs.php | 7 ------- include/functions.php | 8 ++++---- include/sanity_check.php | 6 +++--- include/sanity_config.php | 4 ++-- include/sessions.php | 8 ++++---- phpstan.neon | 4 +++- plugins/af_fsckportal/init.php | 5 +---- plugins/af_redditimgur/init.php | 5 ++++- update.php | 4 ++-- utils/regen_config_checks.sh | 4 ++-- 16 files changed, 35 insertions(+), 54 deletions(-) (limited to 'api') diff --git a/api/index.php b/api/index.php index eb79422f9..1b713d561 100644 --- a/api/index.php +++ b/api/index.php @@ -18,8 +18,8 @@ require_once "functions.php"; require_once "sessions.php"; - ini_set('session.use_cookies', 0); - ini_set("session.gc_maxlifetime", 86400); + ini_set('session.use_cookies', "0"); + ini_set("session.gc_maxlifetime", "86400"); ob_start(); diff --git a/classes/api.php b/classes/api.php index 03eea1927..5677cb908 100755 --- a/classes/api.php +++ b/classes/api.php @@ -292,7 +292,7 @@ class API extends Handler { $sanitize_content = !isset($_REQUEST["sanitize"]) || self::_param_to_bool($_REQUEST["sanitize"]); - if ($article_ids) { + if (count($article_ids) > 0) { $article_qmarks = arr_qmarks($article_ids); diff --git a/classes/digest.php b/classes/digest.php index 77eb92c54..e0c23d705 100644 --- a/classes/digest.php +++ b/classes/digest.php @@ -1,12 +1,6 @@ addBlock('enclosure'); } } else { - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', "", true); + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', "", true); + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', "", true); } list ($og_image, $og_stream) = Article::_get_image($enclosures, $line['content'], $feed_site_url); @@ -207,8 +207,8 @@ class Handler_Public extends Handler { $article['content'] = Sanitizer::sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); $article['updated'] = date('c', strtotime($line["updated"])); - if ($line['note']) $article['note'] = $line['note']; - if ($article['author']) $article['author'] = $line['author']; + if (!empty($line['note'])) $article['note'] = $line['note']; + if (!empty($line['author'])) $article['author'] = $line['author']; if (count($line["tags"]) > 0) { $article['tags'] = array(); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index a05938111..5121c8491 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -108,8 +108,9 @@ class PluginHost { return false; } + // needed for compatibility with API 2 (?) function get_dbh() { - return Db::get(); + return false; } function get_pdo(): PDO { diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index a26281fee..adb249dac 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -311,13 +311,6 @@ class Pref_Prefs extends Handler_Protected { - -
- - -
- -