nodebb-plugin-ezoic-infinite 1.6.88 → 1.6.90
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 +97 -39
- package/package.json +1 -1
- package/public/client.js +46 -30
- package/public/style.css +17 -12
package/library.js
CHANGED
|
@@ -7,59 +7,117 @@ 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
|
+
*/
|
|
10
13
|
async function getSettings() {
|
|
11
|
-
|
|
14
|
+
return await meta.settings.get(SETTINGS_KEY);
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Vérifie si l'utilisateur actuel fait partie d'un groupe exclu
|
|
19
|
+
*/
|
|
14
20
|
async function isUserExcluded(uid, excludedGroups) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
if (!uid || uid <= 0) return false;
|
|
22
|
+
if (!excludedGroups || !excludedGroups.length) return false;
|
|
23
|
+
|
|
24
|
+
// S'assurer que excludedGroups est un tableau
|
|
25
|
+
const excludedList = Array.isArray(excludedGroups) ? excludedGroups : [excludedGroups];
|
|
26
|
+
|
|
27
|
+
// Récupérer les groupes de l'utilisateur
|
|
28
|
+
const userGroups = await groups.getUserGroupsNames([uid]);
|
|
29
|
+
|
|
30
|
+
// Vérifier s'il y a une intersection entre les groupes de l'utilisateur et les exclus
|
|
31
|
+
return excludedList.some(g => userGroups[0].includes(g));
|
|
18
32
|
}
|
|
19
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Récupère la liste de tous les groupes pour l'affichage dans l'admin
|
|
36
|
+
*/
|
|
20
37
|
async function getAllGroups() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
let names = await db.getSortedSetRange('groups:createtime', 0, -1);
|
|
39
|
+
if (!names || !names.length) {
|
|
40
|
+
names = await db.getSortedSetRange('groups:visible:createtime', 0, -1);
|
|
41
|
+
}
|
|
42
|
+
const filtered = names.filter(name => !groups.isPrivilegeGroup(name));
|
|
43
|
+
const data = await groups.getGroupsData(filtered);
|
|
44
|
+
const valid = data.filter(g => g && g.name);
|
|
45
|
+
valid.sort((a, b) => String(a.name).localeCompare(String(b.name), undefined, { sensitivity: 'base' }));
|
|
46
|
+
return valid;
|
|
24
47
|
}
|
|
25
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Initialisation du plugin (Routes et API)
|
|
51
|
+
*/
|
|
26
52
|
plugin.init = async ({ router, middleware }) => {
|
|
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
|
-
|
|
53
|
+
async function render(req, res) {
|
|
54
|
+
const settings = await getSettings();
|
|
55
|
+
const allGroups = await getAllGroups();
|
|
56
|
+
|
|
57
|
+
res.render('admin/plugins/ezoic-infinite', {
|
|
58
|
+
title: 'Ezoic Infinite Ads',
|
|
59
|
+
...settings,
|
|
60
|
+
// On force les booléens pour les cases à cocher dans le template
|
|
61
|
+
enableCategoryAds_checked: settings.enableCategoryAds === 'on' || settings.enableCategoryAds === true ? 'checked' : '',
|
|
62
|
+
enableBetweenAds_checked: settings.enableBetweenAds === 'on' || settings.enableBetweenAds === true ? 'checked' : '',
|
|
63
|
+
enableMessageAds_checked: settings.enableMessageAds === 'on' || settings.enableMessageAds === true ? 'checked' : '',
|
|
64
|
+
allGroups,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
router.get('/admin/plugins/ezoic-infinite', middleware.admin.buildHeader, render);
|
|
69
|
+
router.get('/api/admin/plugins/ezoic-infinite', render);
|
|
70
|
+
|
|
71
|
+
// API de configuration appelée par client.js
|
|
72
|
+
router.get('/api/plugins/ezoic-infinite/config', async (req, res) => {
|
|
73
|
+
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);
|
|
78
|
+
|
|
79
|
+
res.json({
|
|
80
|
+
excluded,
|
|
81
|
+
// 1. Accueil (Catégories)
|
|
82
|
+
enableCategoryAds: settings.enableCategoryAds === 'on' || settings.enableCategoryAds === true,
|
|
83
|
+
showFirstCategoryAd: settings.showFirstCategoryAd === 'on' || settings.showFirstCategoryAd === true,
|
|
84
|
+
categoryPlaceholderIds: settings.categoryPlaceholderIds || "",
|
|
85
|
+
intervalCategories: parseInt(settings.intervalCategories, 10) || 5,
|
|
86
|
+
|
|
87
|
+
// 2. Liste des Topics (Page catégorie)
|
|
88
|
+
enableBetweenAds: settings.enableBetweenAds === 'on' || settings.enableBetweenAds === true,
|
|
89
|
+
showFirstTopicAd: settings.showFirstTopicAd === 'on' || settings.showFirstTopicAd === true,
|
|
90
|
+
placeholderIds: settings.placeholderIds || "",
|
|
91
|
+
intervalPosts: parseInt(settings.intervalPosts, 10) || 10,
|
|
92
|
+
|
|
93
|
+
// 3. Messages (Dans un post)
|
|
94
|
+
enableMessageAds: settings.enableMessageAds === 'on' || settings.enableMessageAds === true,
|
|
95
|
+
showFirstMessageAd: settings.showFirstMessageAd === 'on' || settings.showFirstMessageAd === true,
|
|
96
|
+
messagePlaceholderIds: settings.messagePlaceholderIds || "",
|
|
97
|
+
messageIntervalPosts: parseInt(settings.messageIntervalPosts, 10) || 10,
|
|
98
|
+
});
|
|
52
99
|
});
|
|
53
|
-
});
|
|
54
100
|
};
|
|
55
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Ajoute le lien dans le menu de navigation de l'administration
|
|
104
|
+
*/
|
|
56
105
|
plugin.addAdminNavigation = async (header) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
106
|
+
header.plugins.push({
|
|
107
|
+
route: '/plugins/ezoic-infinite',
|
|
108
|
+
icon: 'fa-ad',
|
|
109
|
+
name: 'Ezoic Infinite'
|
|
110
|
+
});
|
|
111
|
+
return header;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Gère la sauvegarde des paramètres
|
|
116
|
+
*/
|
|
117
|
+
plugin.onSettingsSet = async (data) => {
|
|
118
|
+
if (data.plugin === 'ezoic-infinite') {
|
|
119
|
+
// Logique optionnelle à l'enregistrement
|
|
120
|
+
}
|
|
63
121
|
};
|
|
64
122
|
|
|
65
123
|
module.exports = plugin;
|
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
let config = null;
|
|
11
11
|
let isInternalChange = false;
|
|
12
12
|
let definedIds = new Set();
|
|
13
|
-
let
|
|
13
|
+
let pendingIds = new Set();
|
|
14
|
+
let refreshTimer = null;
|
|
15
|
+
|
|
16
|
+
if (typeof window.ezoicFirstEnableDone === 'undefined') {
|
|
17
|
+
window.ezoicFirstEnableDone = false;
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
function getPool() {
|
|
16
21
|
let p = document.getElementById(POOL_ID);
|
|
@@ -23,53 +28,68 @@
|
|
|
23
28
|
return p;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
function
|
|
27
|
-
if (typeof window.ezstandalone === 'undefined') return;
|
|
28
|
-
const pid = parseInt(id, 10);
|
|
29
|
-
if (isNaN(pid)) return;
|
|
31
|
+
function triggerEzoic() {
|
|
32
|
+
if (typeof window.ezstandalone === 'undefined' || pendingIds.size === 0) return;
|
|
30
33
|
|
|
31
34
|
window.ezstandalone.cmd.push(function() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
window.ezstandalone.define(pid);
|
|
35
|
-
definedIds.add(pid);
|
|
36
|
-
}
|
|
35
|
+
const idsToProcess = Array.from(pendingIds);
|
|
36
|
+
pendingIds.clear();
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
window.ezstandalone.define(idsToProcess);
|
|
39
|
+
|
|
40
|
+
if (!window.ezstandalone.enabled && !window.ezoicFirstEnableDone) {
|
|
40
41
|
window.ezstandalone.enable();
|
|
41
42
|
window.ezstandalone.display();
|
|
42
|
-
|
|
43
|
+
window.ezoicFirstEnableDone = true;
|
|
43
44
|
} else {
|
|
44
|
-
// Délai de sécurité
|
|
45
|
+
// Délai de sécurité pour éviter le conflit "same page enable"
|
|
45
46
|
setTimeout(function() {
|
|
46
47
|
try {
|
|
47
48
|
window.ezstandalone.refresh();
|
|
48
49
|
} catch (e) {
|
|
49
50
|
console.debug('[Ezoic] Refresh deferred');
|
|
50
51
|
}
|
|
51
|
-
},
|
|
52
|
+
}, 1000);
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
function callEzoic(id) {
|
|
58
|
+
const pid = parseInt(id, 10);
|
|
59
|
+
if (isNaN(pid)) return;
|
|
60
|
+
pendingIds.add(pid);
|
|
61
|
+
definedIds.add(pid);
|
|
62
|
+
|
|
63
|
+
clearTimeout(refreshTimer);
|
|
64
|
+
refreshTimer = setTimeout(triggerEzoic, 300);
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
function redistribute() {
|
|
57
68
|
if (!config || config.excluded) return;
|
|
58
69
|
|
|
59
|
-
//
|
|
70
|
+
// 1. PAGE D'ACCUEIL (Liste des catégories)
|
|
71
|
+
const categoryItems = document.querySelectorAll('.category-item, [component="categories/category"]');
|
|
72
|
+
|
|
73
|
+
// 2. PAGE CATEGORIE (Liste des topics)
|
|
60
74
|
const topicItems = document.querySelectorAll('li[component="category/topic"]');
|
|
75
|
+
|
|
76
|
+
// 3. PAGE TOPIC (Messages / Posts)
|
|
61
77
|
const postItems = document.querySelectorAll('[component="post"]');
|
|
62
78
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
79
|
+
if (categoryItems.length > 0 && config.enableCategoryAds) {
|
|
80
|
+
process(Array.from(categoryItems), 'home', config.intervalCategories, config.showFirstCategoryAd);
|
|
65
81
|
}
|
|
66
82
|
|
|
83
|
+
if (topicItems.length > 0 && config.enableBetweenAds) {
|
|
84
|
+
process(Array.from(topicItems), 'topic-list', config.intervalPosts, config.showFirstTopicAd);
|
|
85
|
+
}
|
|
86
|
+
|
|
67
87
|
if (postItems.length > 0 && config.enableMessageAds) {
|
|
68
|
-
|
|
88
|
+
process(Array.from(postItems), 'message', config.messageIntervalPosts, config.showFirstMessageAd);
|
|
69
89
|
}
|
|
70
90
|
}
|
|
71
91
|
|
|
72
|
-
function
|
|
92
|
+
function process(items, kind, interval, showFirst) {
|
|
73
93
|
const int = parseInt(interval, 10) || 10;
|
|
74
94
|
items.forEach((item, index) => {
|
|
75
95
|
const pos = index + 1;
|
|
@@ -95,6 +115,7 @@
|
|
|
95
115
|
.then(data => {
|
|
96
116
|
config = data;
|
|
97
117
|
const pool = getPool();
|
|
118
|
+
|
|
98
119
|
const setup = (raw, kind) => {
|
|
99
120
|
if (!raw) return;
|
|
100
121
|
raw.split(/[\s,]+/).filter(Boolean).forEach(id => {
|
|
@@ -108,7 +129,10 @@
|
|
|
108
129
|
}
|
|
109
130
|
});
|
|
110
131
|
};
|
|
111
|
-
|
|
132
|
+
|
|
133
|
+
// On initialise les 3 pools séparés
|
|
134
|
+
setup(config.categoryPlaceholderIds, 'home');
|
|
135
|
+
setup(config.placeholderIds, 'topic-list');
|
|
112
136
|
setup(config.messagePlaceholderIds, 'message');
|
|
113
137
|
|
|
114
138
|
redistribute();
|
|
@@ -120,15 +144,7 @@
|
|
|
120
144
|
});
|
|
121
145
|
}
|
|
122
146
|
|
|
123
|
-
|
|
124
|
-
window.addEventListener('action:ajaxify.start', function() {
|
|
125
|
-
ezoicEnabledOnThisPage = false;
|
|
126
|
-
definedIds.clear();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
window.addEventListener('action:ajaxify.end', function() {
|
|
130
|
-
setTimeout(redistribute, 600);
|
|
131
|
-
});
|
|
147
|
+
window.addEventListener('action:ajaxify.end', () => setTimeout(redistribute, 800));
|
|
132
148
|
|
|
133
149
|
if (document.readyState === 'loading') {
|
|
134
150
|
document.addEventListener('DOMContentLoaded', init);
|
package/public/style.css
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
/* Container global */
|
|
1
|
+
/* Container global de pub */
|
|
2
2
|
.nodebb-ezoic-wrap {
|
|
3
3
|
display: block !important;
|
|
4
4
|
width: 100% !important;
|
|
5
|
-
min-width: 100% !important;
|
|
6
5
|
margin: 20px 0 !important;
|
|
7
6
|
min-height: 250px;
|
|
8
7
|
clear: both;
|
|
9
8
|
text-align: center;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
/*
|
|
11
|
+
/* Accueil (Catégories) */
|
|
12
|
+
[component="categories/category"] + .nodebb-ezoic-wrap,
|
|
13
|
+
.category-item + .nodebb-ezoic-wrap {
|
|
14
|
+
margin: 40px 0 !important;
|
|
15
|
+
border-top: 1px solid rgba(0,0,0,0.05);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Liste des Topics (Page catégorie) */
|
|
13
19
|
li[component="category/topic"] + .nodebb-ezoic-wrap {
|
|
14
20
|
list-style: none !important;
|
|
15
|
-
margin-left: 0 !important;
|
|
16
21
|
padding: 15px 0;
|
|
17
22
|
border-bottom: 1px solid rgba(0,0,0,0.05);
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
/*
|
|
21
|
-
.nodebb-ezoic-wrap
|
|
22
|
-
|
|
25
|
+
/* Messages (Dans un post) */
|
|
26
|
+
[component="post"] + .nodebb-ezoic-wrap {
|
|
27
|
+
margin: 40px 0 !important;
|
|
28
|
+
padding: 20px;
|
|
29
|
+
background: rgba(0,0,0,0.01);
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
/*
|
|
26
|
-
.ezoic-
|
|
27
|
-
|
|
28
|
-
display: inline-block !important;
|
|
29
|
-
}
|
|
32
|
+
/* Masquage des blocs vides */
|
|
33
|
+
.nodebb-ezoic-wrap:empty { min-height: 1px; }
|
|
34
|
+
.ezoic-ad { margin: 0 auto !important; }
|