nodebb-plugin-ezoic-infinite 1.6.97 → 1.6.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +109 -45
- package/package.json +1 -1
- package/public/client.js +1664 -105
- package/public/style.css +78 -27
- package/public/test.txt +1 -0
package/library.js
CHANGED
|
@@ -7,60 +7,124 @@ const db = require.main.require('./src/database');
|
|
|
7
7
|
const SETTINGS_KEY = 'ezoic-infinite';
|
|
8
8
|
const plugin = {};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
function normalizeExcludedGroups(value) {
|
|
11
|
+
if (!value) return [];
|
|
12
|
+
if (Array.isArray(value)) return value;
|
|
13
|
+
return String(value).split(',').map(s => s.trim()).filter(Boolean);
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function parseBool(v, def = false) {
|
|
17
|
+
if (v === undefined || v === null || v === '') return def;
|
|
18
|
+
if (typeof v === 'boolean') return v;
|
|
19
|
+
const s = String(v).toLowerCase();
|
|
20
|
+
return s === '1' || s === 'true' || s === 'on' || s === 'yes';
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
async function getAllGroups() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
let names = await db.getSortedSetRange('groups:createtime', 0, -1);
|
|
25
|
+
if (!names || !names.length) {
|
|
26
|
+
names = await db.getSortedSetRange('groups:visible:createtime', 0, -1);
|
|
27
|
+
}
|
|
28
|
+
const filtered = names.filter(name => !groups.isPrivilegeGroup(name));
|
|
29
|
+
const data = await groups.getGroupsData(filtered);
|
|
30
|
+
// Filter out nulls (groups deleted between the sorted-set read and getGroupsData)
|
|
31
|
+
const valid = data.filter(g => g && g.name);
|
|
32
|
+
valid.sort((a, b) => String(a.name).localeCompare(String(b.name), undefined, { sensitivity: 'base' }));
|
|
33
|
+
return valid;
|
|
25
34
|
}
|
|
35
|
+
let _settingsCache = null;
|
|
36
|
+
let _settingsCacheAt = 0;
|
|
37
|
+
const SETTINGS_TTL = 30000; // 30s
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
39
|
+
async function getSettings() {
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
if (_settingsCache && (now - _settingsCacheAt) < SETTINGS_TTL) return _settingsCache;
|
|
42
|
+
const s = await meta.settings.get(SETTINGS_KEY);
|
|
43
|
+
_settingsCacheAt = Date.now();
|
|
44
|
+
_settingsCache = {
|
|
45
|
+
// Between-post ads (simple blocks) in category topic list
|
|
46
|
+
enableBetweenAds: parseBool(s.enableBetweenAds, true),
|
|
47
|
+
showFirstTopicAd: parseBool(s.showFirstTopicAd, false),
|
|
48
|
+
placeholderIds: (s.placeholderIds || '').trim(),
|
|
49
|
+
intervalPosts: Math.max(1, parseInt(s.intervalPosts, 10) || 6),
|
|
50
|
+
|
|
51
|
+
// Home/categories list ads (between categories on / or /categories)
|
|
52
|
+
enableCategoryAds: parseBool(s.enableCategoryAds, false),
|
|
53
|
+
showFirstCategoryAd: parseBool(s.showFirstCategoryAd, false),
|
|
54
|
+
categoryPlaceholderIds: (s.categoryPlaceholderIds || '').trim(),
|
|
55
|
+
intervalCategories: Math.max(1, parseInt(s.intervalCategories, 10) || 4),
|
|
56
|
+
|
|
57
|
+
// "Ad message" between replies (looks like a post)
|
|
58
|
+
enableMessageAds: parseBool(s.enableMessageAds, false),
|
|
59
|
+
showFirstMessageAd: parseBool(s.showFirstMessageAd, false),
|
|
60
|
+
messagePlaceholderIds: (s.messagePlaceholderIds || '').trim(),
|
|
61
|
+
messageIntervalPosts: Math.max(1, parseInt(s.messageIntervalPosts, 10) || 3),
|
|
62
|
+
|
|
63
|
+
excludedGroups: normalizeExcludedGroups(s.excludedGroups),
|
|
64
|
+
};
|
|
65
|
+
return _settingsCache;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function isUserExcluded(uid, excludedGroups) {
|
|
69
|
+
if (!uid || !excludedGroups.length) return false;
|
|
70
|
+
const userGroups = await groups.getUserGroups([uid]);
|
|
71
|
+
return (userGroups[0] || []).some(g => excludedGroups.includes(g.name));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
plugin.onSettingsSet = function (data) {
|
|
75
|
+
// Invalider le cache dès que les settings de ce plugin sont sauvegardés via l'ACP
|
|
76
|
+
if (data && data.hash === SETTINGS_KEY) {
|
|
77
|
+
_settingsCache = null;
|
|
78
|
+
}
|
|
59
79
|
};
|
|
60
80
|
|
|
61
81
|
plugin.addAdminNavigation = async (header) => {
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
header.plugins = header.plugins || [];
|
|
83
|
+
header.plugins.push({
|
|
84
|
+
route: '/plugins/ezoic-infinite',
|
|
85
|
+
icon: 'fa-ad',
|
|
86
|
+
name: 'Ezoic Infinite Ads'
|
|
87
|
+
});
|
|
88
|
+
return header;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
plugin.init = async ({ router, middleware }) => {
|
|
92
|
+
async function render(req, res) {
|
|
93
|
+
const settings = await getSettings();
|
|
94
|
+
const allGroups = await getAllGroups();
|
|
95
|
+
|
|
96
|
+
res.render('admin/plugins/ezoic-infinite', {
|
|
97
|
+
title: 'Ezoic Infinite Ads',
|
|
98
|
+
...settings,
|
|
99
|
+
enableBetweenAds_checked: settings.enableBetweenAds ? 'checked' : '',
|
|
100
|
+
enableMessageAds_checked: settings.enableMessageAds ? 'checked' : '',
|
|
101
|
+
allGroups,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
router.get('/admin/plugins/ezoic-infinite', middleware.admin.buildHeader, render);
|
|
106
|
+
router.get('/api/admin/plugins/ezoic-infinite', render);
|
|
107
|
+
|
|
108
|
+
router.get('/api/plugins/ezoic-infinite/config', async (req, res) => {
|
|
109
|
+
const settings = await getSettings();
|
|
110
|
+
const excluded = await isUserExcluded(req.uid, settings.excludedGroups);
|
|
111
|
+
|
|
112
|
+
res.json({
|
|
113
|
+
excluded,
|
|
114
|
+
enableBetweenAds: settings.enableBetweenAds,
|
|
115
|
+
showFirstTopicAd: settings.showFirstTopicAd,
|
|
116
|
+
placeholderIds: settings.placeholderIds,
|
|
117
|
+
intervalPosts: settings.intervalPosts,
|
|
118
|
+
enableCategoryAds: settings.enableCategoryAds,
|
|
119
|
+
showFirstCategoryAd: settings.showFirstCategoryAd,
|
|
120
|
+
categoryPlaceholderIds: settings.categoryPlaceholderIds,
|
|
121
|
+
intervalCategories: settings.intervalCategories,
|
|
122
|
+
enableMessageAds: settings.enableMessageAds,
|
|
123
|
+
showFirstMessageAd: settings.showFirstMessageAd,
|
|
124
|
+
messagePlaceholderIds: settings.messagePlaceholderIds,
|
|
125
|
+
messageIntervalPosts: settings.messageIntervalPosts,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
64
128
|
};
|
|
65
129
|
|
|
66
|
-
module.exports = plugin;
|
|
130
|
+
module.exports = plugin;
|