feat: #8821, allow guest topic views

v1.18.x
Barış Soner Uşaklı 4 years ago
parent f68bce86a9
commit 9e3eb5d41a

@ -114,6 +114,8 @@
"hideFullname": 0,
"hideEmail": 0,
"allowGuestHandles": 0,
"guestsIncrementTopicViews": 1,
"incrementTopicViewsInterval": 60,
"recentMaxTopics": 200,
"disableRecentCategoryFilter": 0,
"maximumRelatedTopics": 0,

@ -1,5 +1,7 @@
{
"handles": "Guest Handles",
"handles.enabled": "Allow guest handles",
"handles.enabled-help": "This option exposes a new field that allows guests to pick a name to associate with each post they make. If disabled, they will simply be called \"Guest\""
"handles.enabled-help": "This option exposes a new field that allows guests to pick a name to associate with each post they make. If disabled, they will simply be called \"Guest\"",
"topic-views": "Topic views",
"topic-views.enabled": "Allow guests to increase topic view counts"
}

@ -34,6 +34,8 @@
"timestamp.cut-off-help": "Dates &amp; times will be shown in a relative manner (e.g. \"3 hours ago\" / \"5 days ago\"), and localised into various\n\t\t\t\t\tlanguages. After a certain point, this text can be switched to display the localised date itself\n\t\t\t\t\t(e.g. 5 Nov 2016 15:30).<br /><em>(Default: <code>30</code>, or one month). Set to 0 to always display dates, leave blank to always display relative times.</em>",
"timestamp.necro-threshold": "Necro Threshold (in days)",
"timestamp.necro-threshold-help": "A message will be shown between posts if the time between them is longer than the necro threshold. (Default: <code>7</code>, or one week). Set to 0 to disable.</em>",
"timestamp.topic-views-interval": "Increment topic views interval (in minutes)",
"timestamp.topic-views-interval-help": "Topic views will only increment once every X minutes as defined by this setting.",
"teaser": "Teaser Post",
"teaser.last-post": "Last &ndash; Show the latest post, including the original post, if no replies",
"teaser.last-reply": "Last &ndash; Show the latest reply, or a \"No replies\" placeholder if no replies",

@ -127,11 +127,14 @@ function calculateStartStop(page, postIndex, settings) {
}
async function incrementViewCount(req, tid) {
if (req.uid >= 1) {
const allow = req.uid > 0 || (meta.config.guestsIncrementTopicViews && req.uid === 0);
if (allow) {
req.session.tids_viewed = req.session.tids_viewed || {};
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) {
const now = Date.now();
const interval = meta.config.incrementTopicViewsInterval * 60000;
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < now - interval) {
await topics.increaseViewCount(tid);
req.session.tids_viewed[tid] = Date.now();
req.session.tids_viewed[tid] = now;
}
}
}

@ -15,6 +15,17 @@
</p>
</form>
</div>
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/guest:topic-views]]</div>
<div class="col-sm-10 col-xs-12">
<form role="form">
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input class="mdl-switch__input" type="checkbox" data-field="guestsIncrementTopicViews">
<span class="mdl-switch__label"><strong>[[admin/settings/guest:topic-views.enabled]]</strong></span>
</label>
</div>
</form>
</div>
</div>
<!-- IMPORT admin/partials/settings/footer.tpl -->

@ -170,6 +170,13 @@
[[admin/settings/post:timestamp.necro-threshold-help]]
</p>
</div>
<div class="form-group">
<label for="incrementTopicViewsInterval">[[admin/settings/post:timestamp.topic-views-interval]]</label>
<input type="number" class="form-control" id="incrementTopicViewsInterval" data-field="incrementTopicViewsInterval" />
<p class="help-block">
[[admin/settings/post:timestamp.topic-views-interval-help]]
</p>
</div>
</form>
</div>
</div>

Loading…
Cancel
Save