From 0f9158b37ba4368392d62fd8ee917be6577ea669 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 May 2024 14:38:41 +0200 Subject: [PATCH] allow disabling comment date display using `discussiondatedisplay` configuration option --- CHANGELOG.md | 2 +- cfg/conf.sample.php | 9 +++++++-- js/privatebin.js | 8 +++++--- lib/Configuration.php | 1 + lib/Model/Paste.php | 21 +++++++++++++++------ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3305cbd..eaa56b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * ADDED: Input sanitation to some not yet filtered query and server parameters * CHANGED: "Send" button now labeled "Create" (#946) * CHANGED: drop some PHP < 5.6 fallbacks, minimum version is PHP 7.3 as of release 1.6.0 -* CHANGED: `create` attribute is no longer returned in API for pastes (#1290) +* CHANGED: `create` attribute is no longer returned in API for pastes & can be disabled for comments using `discussiondatedisplay` as well (#1290) * FIXED: Add cache control headers also to API calls (#1263) * FIXED: Shortened paste URL does not appear in email (#606) diff --git a/cfg/conf.sample.php b/cfg/conf.sample.php index 141888f2..16a82dae 100644 --- a/cfg/conf.sample.php +++ b/cfg/conf.sample.php @@ -18,6 +18,11 @@ discussion = true ; preselect the discussion feature, defaults to false opendiscussion = false +; enable or disable the diplay of dates & times in the comments, defaults to true +; note that internally the creation time will still get tracked in order to sort +; the comments by creation time, but you can choose not to display them +; discussiondatedisplay = false + ; enable or disable the password feature, defaults to true password = true @@ -242,7 +247,7 @@ dir = PATH "data" ; - AWS_ACCESS_KEY_ID ; - AWS_SECRET_ACCESS_KEY ; - AWS_SESSION_TOKEN (if needed) -; for more details, see https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain +; for more details, see https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain ;class = S3Storage ;[model_options] ;region = "eu-central-1" @@ -264,4 +269,4 @@ dir = PATH "data" ; (optional) the "signature" (access key) issued by YOURLS for the using account ; signature = "" ; (optional) the URL of the YOURLS API, called to shorten a PrivateBin URL -; apiurl = "https://yourls.example.com/yourls-api.php" \ No newline at end of file +; apiurl = "https://yourls.example.com/yourls-api.php" diff --git a/js/privatebin.js b/js/privatebin.js index 0a3271c8..474fcde9 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -196,7 +196,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ this.getCreated = function() { - return this.meta[this.v === 1 ? 'postdate' : 'created']; + return this.meta[this.v === 1 ? 'postdate' : 'created'] || 0; } /** @@ -3484,9 +3484,11 @@ jQuery.PrivateBin = (function($, RawDeflate) { } // set date + const created = comment.getCreated(); + const commentDate = created == 0 ? '' : ' (' + (new Date(created * 1000).toLocaleString()) + ')'; $commentEntry.find('span.commentdate') - .text(' (' + (new Date(comment.getCreated() * 1000).toLocaleString()) + ')') - .attr('title', 'CommentID: ' + comment.id); + .text(commentDate) + .attr('title', 'CommentID: ' + comment.id); // if an avatar is available, display it const icon = comment.getIcon(); diff --git a/lib/Configuration.php b/lib/Configuration.php index dac6eec3..86c96a89 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -40,6 +40,7 @@ class Configuration 'basepath' => '', 'discussion' => true, 'opendiscussion' => false, + 'discussiondatedisplay' => true, 'password' => true, 'fileupload' => false, 'burnafterreadingselected' => false, diff --git a/lib/Model/Paste.php b/lib/Model/Paste.php index a63d6688..0847e1ce 100644 --- a/lib/Model/Paste.php +++ b/lib/Model/Paste.php @@ -47,11 +47,10 @@ class Paste extends AbstractModel $data['meta']['time_to_live'] = $data['meta']['expire_date'] - time(); unset($data['meta']['expire_date']); } - if (array_key_exists('created', $data['meta'])) { - unset($data['meta']['created']); - } - if (array_key_exists('postdate', $data['meta'])) { - unset($data['meta']['postdate']); + foreach (array('created', 'postdate') as $key) { + if (array_key_exists($key, $data['meta'])) { + unset($data['meta'][$key]); + } } // check if non-expired burn after reading paste needs to be deleted @@ -164,7 +163,17 @@ class Paste extends AbstractModel */ public function getComments() { - return $this->_store->readComments($this->getId()); + if ($this->_conf->getKey('discussiondatedisplay')) { + return $this->_store->readComments($this->getId()); + } + return array_map(function($comment) { + foreach (array('created', 'postdate') as $key) { + if (array_key_exists($key, $comment['meta'])) { + unset($comment['meta'][$key]); + } + } + return $comment; + }, $this->_store->readComments($this->getId())); } /** diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 6b08037f..5637c515 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -73,7 +73,7 @@ endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index c79c3e33..a4736e06 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -51,7 +51,7 @@ endif; ?> - +