nodebb-plugin-ezoic-infinite 1.6.95 → 1.6.96
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 +19 -40
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -7,33 +7,24 @@ const db = require.main.require('./src/database');
|
|
|
7
7
|
const SETTINGS_KEY = 'ezoic-infinite';
|
|
8
8
|
const plugin = {};
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Récupère les paramètres du plugin
|
|
12
|
-
*/
|
|
13
10
|
async function getSettings() {
|
|
14
11
|
return await meta.settings.get(SETTINGS_KEY);
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
|
-
* Vérifie
|
|
15
|
+
* Vérifie l'exclusion par groupe avec gestion du format NodeBB
|
|
19
16
|
*/
|
|
20
17
|
async function isUserExcluded(uid, excludedGroups) {
|
|
21
18
|
if (!uid || uid <= 0) return false;
|
|
22
|
-
if (!excludedGroups ||
|
|
19
|
+
if (!excludedGroups || (Array.isArray(excludedGroups) && excludedGroups.length === 0)) return false;
|
|
23
20
|
|
|
24
|
-
// S'assurer que excludedGroups est un tableau
|
|
25
21
|
const excludedList = Array.isArray(excludedGroups) ? excludedGroups : [excludedGroups];
|
|
26
|
-
|
|
27
|
-
// Récupérer les groupes de l'utilisateur
|
|
28
22
|
const userGroups = await groups.getUserGroupsNames([uid]);
|
|
29
23
|
|
|
30
|
-
//
|
|
24
|
+
// userGroups[0] contient le tableau des noms de groupes de l'utilisateur
|
|
31
25
|
return excludedList.some(g => userGroups[0].includes(g));
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
/**
|
|
35
|
-
* Récupère la liste de tous les groupes pour l'affichage dans l'admin
|
|
36
|
-
*/
|
|
37
28
|
async function getAllGroups() {
|
|
38
29
|
let names = await db.getSortedSetRange('groups:createtime', 0, -1);
|
|
39
30
|
if (!names || !names.length) {
|
|
@@ -46,9 +37,6 @@ async function getAllGroups() {
|
|
|
46
37
|
return valid;
|
|
47
38
|
}
|
|
48
39
|
|
|
49
|
-
/**
|
|
50
|
-
* Initialisation du plugin (Routes et API)
|
|
51
|
-
*/
|
|
52
40
|
plugin.init = async ({ router, middleware }) => {
|
|
53
41
|
async function render(req, res) {
|
|
54
42
|
const settings = await getSettings();
|
|
@@ -57,10 +45,10 @@ plugin.init = async ({ router, middleware }) => {
|
|
|
57
45
|
res.render('admin/plugins/ezoic-infinite', {
|
|
58
46
|
title: 'Ezoic Infinite Ads',
|
|
59
47
|
...settings,
|
|
60
|
-
// On
|
|
61
|
-
enableCategoryAds_checked: settings.enableCategoryAds === 'on'
|
|
62
|
-
enableBetweenAds_checked: settings.enableBetweenAds === 'on'
|
|
63
|
-
enableMessageAds_checked: settings.enableMessageAds === 'on'
|
|
48
|
+
// On s'assure que les checkbox sont bien cochées dans l'admin
|
|
49
|
+
enableCategoryAds_checked: settings.enableCategoryAds === 'on' ? 'checked' : '',
|
|
50
|
+
enableBetweenAds_checked: settings.enableBetweenAds === 'on' ? 'checked' : '',
|
|
51
|
+
enableMessageAds_checked: settings.enableMessageAds === 'on' ? 'checked' : '',
|
|
64
52
|
allGroups,
|
|
65
53
|
});
|
|
66
54
|
}
|
|
@@ -68,40 +56,34 @@ plugin.init = async ({ router, middleware }) => {
|
|
|
68
56
|
router.get('/admin/plugins/ezoic-infinite', middleware.admin.buildHeader, render);
|
|
69
57
|
router.get('/api/admin/plugins/ezoic-infinite', render);
|
|
70
58
|
|
|
71
|
-
// API
|
|
59
|
+
// API consommée par le client.js
|
|
72
60
|
router.get('/api/plugins/ezoic-infinite/config', async (req, res) => {
|
|
73
61
|
const settings = await getSettings();
|
|
74
|
-
|
|
75
|
-
// Vérification de l'exclusion
|
|
76
|
-
const excludedGroups = settings.excludedGroups ? (Array.isArray(settings.excludedGroups) ? settings.excludedGroups : [settings.excludedGroups]) : [];
|
|
77
|
-
const excluded = await isUserExcluded(req.uid, excludedGroups);
|
|
62
|
+
const excluded = await isUserExcluded(req.uid, settings.excludedGroups);
|
|
78
63
|
|
|
79
64
|
res.json({
|
|
80
65
|
excluded,
|
|
81
|
-
//
|
|
82
|
-
enableCategoryAds: settings.enableCategoryAds === 'on'
|
|
83
|
-
showFirstCategoryAd: settings.showFirstCategoryAd === 'on'
|
|
66
|
+
// Pool Accueil
|
|
67
|
+
enableCategoryAds: settings.enableCategoryAds === 'on',
|
|
68
|
+
showFirstCategoryAd: settings.showFirstCategoryAd === 'on',
|
|
84
69
|
categoryPlaceholderIds: settings.categoryPlaceholderIds || "",
|
|
85
70
|
intervalCategories: parseInt(settings.intervalCategories, 10) || 5,
|
|
86
71
|
|
|
87
|
-
//
|
|
88
|
-
enableBetweenAds: settings.enableBetweenAds === 'on'
|
|
89
|
-
showFirstTopicAd: settings.showFirstTopicAd === 'on'
|
|
72
|
+
// Pool Topics (Catégories)
|
|
73
|
+
enableBetweenAds: settings.enableBetweenAds === 'on',
|
|
74
|
+
showFirstTopicAd: settings.showFirstTopicAd === 'on',
|
|
90
75
|
placeholderIds: settings.placeholderIds || "",
|
|
91
76
|
intervalPosts: parseInt(settings.intervalPosts, 10) || 10,
|
|
92
77
|
|
|
93
|
-
//
|
|
94
|
-
enableMessageAds: settings.enableMessageAds === 'on'
|
|
95
|
-
showFirstMessageAd: settings.showFirstMessageAd === 'on'
|
|
78
|
+
// Pool Messages (Topics)
|
|
79
|
+
enableMessageAds: settings.enableMessageAds === 'on',
|
|
80
|
+
showFirstMessageAd: settings.showFirstMessageAd === 'on',
|
|
96
81
|
messagePlaceholderIds: settings.messagePlaceholderIds || "",
|
|
97
82
|
messageIntervalPosts: parseInt(settings.messageIntervalPosts, 10) || 10,
|
|
98
83
|
});
|
|
99
84
|
});
|
|
100
85
|
};
|
|
101
86
|
|
|
102
|
-
/**
|
|
103
|
-
* Ajoute le lien dans le menu de navigation de l'administration
|
|
104
|
-
*/
|
|
105
87
|
plugin.addAdminNavigation = async (header) => {
|
|
106
88
|
header.plugins.push({
|
|
107
89
|
route: '/plugins/ezoic-infinite',
|
|
@@ -111,12 +93,9 @@ plugin.addAdminNavigation = async (header) => {
|
|
|
111
93
|
return header;
|
|
112
94
|
};
|
|
113
95
|
|
|
114
|
-
/**
|
|
115
|
-
* Gère la sauvegarde des paramètres
|
|
116
|
-
*/
|
|
117
96
|
plugin.onSettingsSet = async (data) => {
|
|
118
97
|
if (data.plugin === 'ezoic-infinite') {
|
|
119
|
-
//
|
|
98
|
+
// Optionnel : purger un cache si nécessaire
|
|
120
99
|
}
|
|
121
100
|
};
|
|
122
101
|
|