diff options
author | Andrew Dolgov <[email protected]> | 2021-02-06 10:10:54 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-06 10:10:54 +0300 |
commit | 10392ecc285871b3f0866370bea11c18693d6a2c (patch) | |
tree | e125369271fff6c4be0b6f672e28c55b03633d3b | |
parent | 9fdeb58fd39fb24aafebd67ad88f58be12b8ce7d (diff) |
event log: add pagination
-rw-r--r-- | classes/pref/system.php | 139 | ||||
-rw-r--r-- | classes/sanitizer.php | 4 | ||||
-rw-r--r-- | include/errorhandler.php | 6 | ||||
-rw-r--r-- | js/PrefHelpers.js | 42 |
4 files changed, 113 insertions, 78 deletions
diff --git a/classes/pref/system.php b/classes/pref/system.php index 89052c6e3..707869e3f 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -23,9 +23,75 @@ class Pref_System extends Handler_Protected { $this->pdo->query("DELETE FROM ttrss_error_log"); } + private function log_viewer(int $page, int $severity) { + print "<table width='100%' cellspacing='10' class='prefErrorLog'>"; + + print "<tr class='title'> + <td width='5%'>".__("Error")."</td> + <td>".__("Filename")."</td> + <td>".__("Message")."</td> + <td width='5%'>".__("User")."</td> + <td width='5%'>".__("Date")."</td> + </tr>"; + + $errno_values = []; + + switch ($severity) { + case E_USER_ERROR: + $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE ]; + break; + case E_USER_WARNING: + $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED ]; + break; + } + + if (count($errno_values) > 0) { + $errno_qmarks = arr_qmarks($errno_values); + $errno_filter_qpart = "errno IN ($errno_qmarks)"; + } else { + $errno_filter_qpart = "true"; + } + + $limit = 10; + $offset = $limit * $page; + + $sth = $this->pdo->prepare("SELECT + errno, errstr, filename, lineno, created_at, login, context + FROM + ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) + WHERE + $errno_filter_qpart + ORDER BY + ttrss_error_log.id DESC + LIMIT $limit OFFSET $offset"); + + $sth->execute($errno_values); + + while ($line = $sth->fetch()) { + print "<tr>"; + + foreach ($line as $k => $v) { + $line[$k] = htmlspecialchars($v); + } + + print "<td class='errno'>" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")</td>"; + print "<td class='filename'>" . $line["filename"] . ":" . $line["lineno"] . "</td>"; + print "<td class='errstr'>" . $line["errstr"] . "<hr/>" . nl2br($line["context"]) . "</td>"; + print "<td class='login'>" . $line["login"] . "</td>"; + + print "<td class='timestamp'>" . + TimeHelper::make_local_datetime($line["created_at"], false) . "</td>"; + + print "</tr>"; + } + + print "</table>"; + } + function index() { - $severity = isset($_REQUEST["severity"]) ? (int) clean($_REQUEST["severity"]) : E_USER_WARNING; + $severity = (int) ($_REQUEST["severity"] ?? E_USER_WARNING); + $page = (int) ($_REQUEST["page"] ?? 0); print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; print "<div dojoType='dijit.layout.AccordionPane' style='padding : 0' @@ -38,10 +104,18 @@ class Pref_System extends Handler_Protected { print "<div region='top' dojoType='fox.Toolbar'>"; print "<button dojoType='dijit.form.Button' - onclick='Helpers.updateEventLog()'>".__('Refresh')."</button>"; + onclick='Helpers.EventLog.refresh()'>".__('Refresh')."</button>"; print "<button dojoType='dijit.form.Button' - onclick='Helpers.clearEventLog()'>".__('Clear')."</button>"; + onclick='Helpers.EventLog.prevPage()'>".__('<<')."</button>"; + + print "<button dojoType='dijit.form.Button' disabled>".T_sprintf('Page %d', $page+1)."</button>"; + + print "<button dojoType='dijit.form.Button' + onclick='Helpers.EventLog.nextPage()'>".__('>>')."</button>"; + + print "<button dojoType='dijit.form.Button' + onclick='Helpers.EventLog.clear()'>".__('Clear')."</button>"; print "<div class='pull-right'>"; @@ -59,65 +133,8 @@ class Pref_System extends Handler_Protected { print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">'; - print "<table width='100%' cellspacing='10' class='prefErrorLog'>"; - - print "<tr class='title'> - <td width='5%'>".__("Error")."</td> - <td>".__("Filename")."</td> - <td>".__("Message")."</td> - <td width='5%'>".__("User")."</td> - <td width='5%'>".__("Date")."</td> - </tr>"; - - $errno_values = []; - - switch ($severity) { - case E_USER_ERROR: - $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE ]; - break; - case E_USER_WARNING: - $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED ]; - break; - } - - if (count($errno_values) > 0) { - $errno_qmarks = arr_qmarks($errno_values); - $errno_filter_qpart = "errno IN ($errno_qmarks)"; - } else { - $errno_filter_qpart = "true"; - } - - $sth = $this->pdo->prepare("SELECT - errno, errstr, filename, lineno, created_at, login, context - FROM - ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) - WHERE - $errno_filter_qpart - ORDER BY - ttrss_error_log.id DESC - LIMIT 100"); - - $sth->execute($errno_values); - - while ($line = $sth->fetch()) { - print "<tr>"; - - foreach ($line as $k => $v) { - $line[$k] = htmlspecialchars($v); - } - - print "<td class='errno'>" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")</td>"; - print "<td class='filename'>" . $line["filename"] . ":" . $line["lineno"] . "</td>"; - print "<td class='errstr'>" . $line["errstr"] . "<hr/>" . nl2br($line["context"]) . "</td>"; - print "<td class='login'>" . $line["login"] . "</td>"; - - print "<td class='timestamp'>" . - TimeHelper::make_local_datetime($line["created_at"], false) . "</td>"; - - print "</tr>"; - } + $this->log_viewer($page, $severity); - print "</table>"; } else { print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); } diff --git a/classes/sanitizer.php b/classes/sanitizer.php index 64b2edd36..9ca4200a5 100644 --- a/classes/sanitizer.php +++ b/classes/sanitizer.php @@ -54,7 +54,9 @@ class Sanitizer { } public static function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) { - if (!$owner) $owner = $_SESSION["uid"]; + + if (!$owner && isset($_SESSION["uid"])) + $owner = $_SESSION["uid"]; $res = trim($str); if (!$res) return ''; diff --git a/include/errorhandler.php b/include/errorhandler.php index 16afcabcf..3643db98a 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -11,11 +11,11 @@ function format_backtrace($trace) { if (is_array($e["args"])) { foreach ($e["args"] as $a) { if (is_object($a)) { - array_push($fmt_args, "[" . get_class($a) . "]"); + array_push($fmt_args, "{" . get_class($a) . "}"); } else if (is_array($a)) { - array_push($fmt_args, "[" . truncate_string(json_encode($a), 128, "...")) . "]"; + array_push($fmt_args, "[" . truncate_string(json_encode($a), 256, "...")) . "]"; } else { - array_push($fmt_args, $a); + array_push($fmt_args, truncate_string($a, 256, "...")); } } } diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 0780fb708..57dff2333 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -50,21 +50,37 @@ const Helpers = { return false; }, - updateEventLog: function() { - xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value') }, (transport) => { - dijit.byId('systemConfigTab').attr('content', transport.responseText); - Notify.close(); - }); - }, - clearEventLog: function() { - if (confirm(__("Clear event log?"))) { + EventLog: { + log_page: 0, + refresh: function() { + this.log_page = 0; + this.update(); + }, + update: function() { + xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value'), page: Helpers.EventLog.log_page }, (transport) => { + dijit.byId('systemConfigTab').attr('content', transport.responseText); + Notify.close(); + }); + }, + nextPage: function() { + this.log_page += 1; + this.update(); + }, + prevPage: function() { + if (this.log_page > 0) this.log_page -= 1; - Notify.progress("Loading, please wait..."); + this.update(); + }, + clear: function() { + if (confirm(__("Clear event log?"))) { - xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { - this.updateEventLog(); - }); - } + Notify.progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { + Helpers.EventLog.refresh(); + }); + } + }, }, editProfiles: function() { |