-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvip_zone.php
More file actions
438 lines (403 loc) · 16.2 KB
/
vip_zone.php
File metadata and controls
438 lines (403 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?php
/*###################################################################################
# Plugin PluXml (Cette version est incompatible avec les versions 6 et + de PluXml)
# Auteur : Gcyrillus aka Gc-Nomade
# premiere version : Sept. 2021
# Version : 3.2 / Dec. 2024
# Maj : 24/04/2023 fin de script sur redirection
# Maj : 26/04/2022 (desactivation de l'option GZIP de PluXml)
# Maj : 06/07/2022 (ajout de PLX_ROOT dans la redirection, installationPluXml dans un sous-dossier )
# Dépot github : https://github.com/gcyrillus/PLX_VIP_ZONE
# Options de configurations de Zone privatisée dans votre PluXml.
# Aide Forum : https://forum.pluxml.org/discussion/7056/plugin-vip-zone-options-de-privatisation-de-votre-pluxml#latest
###################################################################################*/
if(!defined('PLX_ROOT')) {
die('oups!');
}
class vip_zone extends plxPlugin {
const HOOKS = array(
'IndexBegin',
'AdminPrepend',
'AdminAuthPrepend',
'AdminAuthTop',
'AdminTopEndHead',
'AdminUsersTop',
'ThemeEndHead',
'ThemeEndBody',
'plxShowStaticListEnd',
'plxMotorParseArticle',
'plxMotorParseCommentaire',
'plxShowLastComList'
);
const BEGIN_CODE = '<?php' . PHP_EOL;
const END_CODE = PHP_EOL . '?>';
public $links='';
public function __construct($default_lang) {
# appel du constructeur de la classe plxPlugin (obligatoire)
parent::__construct($default_lang);
# Ajoute des hooks
foreach(self::HOOKS as $hook) {
$this->addHook($hook, $hook);
}
# droits pour accéder à la page config.php et admin.php du plugin
$this->setConfigProfil(PROFIL_ADMIN);
$this->setAdminProfil( PROFIL_ADMIN);
}
#code à exécuter à la désactivation du plugin
public function OnDeactivate() {
#desactive les comptes visiteurs
$deactivateVisitors=simplexml_load_file(PLX_ROOT.PLX_CONFIG_PATH."users.xml") or die("Error: Cannot create object");
foreach($deactivateVisitors->children() as $users) {
if ( $users['profil'] =='5') {
$users->attributes()->delete = '1';
}
}
$deactivateVisitors->asXml(PLX_ROOT.PLX_CONFIG_PATH."users.xml");
#desactive les pages static VIP
$deactivateVipStatics=simplexml_load_file(PLX_ROOT.PLX_CONFIG_PATH."statiques.xml") or die("Error: Cannot create object");
foreach($deactivateVipStatics->children() as $vipStats) {
if ( (string) $vipStats->group =='V.I.P.') {
$vipStats->Attributes()->active='0';
}
}
$deactivateVipStatics->asXml(PLX_ROOT.PLX_CONFIG_PATH."statiques.xml");
}
#code à exécuter à l’activation du plugin
public function OnActivate() {
#réactive compte visiteur s'il y en a
$reactivateVisitors=simplexml_load_file(PLX_ROOT.PLX_CONFIG_PATH."users.xml") or die("Error: Cannot create object");
foreach($reactivateVisitors->children() as $users) {
if (( $users['profil'] =='5') and ( $users['delete'] =='1') ) {
$users->attributes()->delete = '0';
}
}
$reactivateVisitors->asXml(PLX_ROOT.PLX_CONFIG_PATH."users.xml");
#reactive pages static VIP
$reactivateVipStatics=simplexml_load_file(PLX_ROOT.PLX_CONFIG_PATH."statiques.xml") or die("Error: Cannot create object");
foreach($reactivateVipStatics->children() as $vipStats) {
if ( (string) $vipStats->group =='V.I.P.') {
$vipStats->Attributes()->active='1';
}
}
$reactivateVipStatics->asXml(PLX_ROOT.PLX_CONFIG_PATH."statiques.xml");
}
#HOOKS
// désactive la compression gzip
public function IndexBegin() {
echo self::BEGIN_CODE;
?>
$plxMotor->aConf['gzip'] ='0';
<?php echo self::END_CODE;
}
#ajout constante profil VIP
public function AdminPrepend() {
echo self::BEGIN_CODE;
?>
const PROFIL_VISITOR = 5;
if(isset($_SESSION['profil']) && $_SESSION['profil'] == 5 && empty($_GET['d']) ) {
if(isset($_SESSION['pageRequest'])) {
$loc= $_SESSION['pageRequest'];
unset($_SESSION['pageRequest']);
echo header("location: ".$loc);
die;
}
else {
echo header("location: /");
die;
}
}
<?php
echo self::END_CODE;
}
#renvoi VIP à la page d'acceuil à la deconnexion
public function AdminAuthPrepend() {
echo self::BEGIN_CODE;
?>
if (!empty($_GET['d']) and $_GET['d'] == 1) {
if(!empty($_SESSION['pageRequest'])) {
$_SESSION = array();
session_destroy();
header('Location:'.PLX_ROOT);
}
else {
$_SESSION = array();
session_destroy();
header('Location: auth.php');
}
exit;
}
<?php
echo self::END_CODE;
}
#personalise le titre du formulaire de connexion
public function AdminAuthTop() {
echo self::BEGIN_CODE;
?>
# pour accés fichier lang du plugin
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$newValue = $plugin->getLang("L_LOGIN_PAGE_VIP");
#pour accés fichier lang de l'admin
$plxAdmin = plxAdmin::getInstance();
$lang = $plxAdmin->aConf['default_lang'];
# Chargement du fichier de lang du theme
$langfile = PLX_CORE.'lang/'.$lang.'/admin.php';
if (is_file($langfile)) {
include $langfile;
$lang = $LANG;
}
$oldValue = $lang["L_LOGIN_PAGE"];
echo '
<script>
window.addEventListener("load", (event) => {
let h1s = document.querySelectorAll("form h1");
[...h1s].forEach((h1) => {
if (h1.textContent =="'. $oldValue.'") { h1.textContent ="'.$plxAdmin->aConf['title'].'\n\n'.$newValue.'";h1.style.whiteSpace="pre"; }
});
});
</script>';
<?php
echo self::END_CODE;
}
#On renvoi le VIP vers la page privée demandée aprés authentification
public function AdminTopEndHead() {
echo self::BEGIN_CODE;
?>
if(isset($_SESSION['profil']) && $_SESSION['profil'] == 5 && empty($_GET['d']) ) {
if(isset($_SESSION['pageRequest'])) {
$loc= $_SESSION['pageRequest'];
unset($_SESSION['pageRequest']);
echo header("location: ".$loc);
die;
}
else {
echo header("location: /");
die;
}
}
<?php
echo self::END_CODE;
}
#On ajoute un profil utilisateur
public function AdminUsersTop() {
echo self::BEGIN_CODE;
?>
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$VIP_Profil = $plugin->getLang('L_PROFIL_VISITOR');
# Tableau des profils
$aProfils = array(
PROFIL_ADMIN => L_PROFIL_ADMIN,
PROFIL_MANAGER => L_PROFIL_MANAGER,
PROFIL_MODERATOR => L_PROFIL_MODERATOR,
PROFIL_EDITOR => L_PROFIL_EDITOR,
PROFIL_WRITER => L_PROFIL_WRITER,
PROFIL_VISITOR => $VIP_Profil
);
<?php
echo self::END_CODE;
}
#Avant l'affichage de la page, on verifie si il y a besoin d'authenfication en comparant la configuration du plugin et le type de page demandée
public function ThemeEndHead() {
echo self::BEGIN_CODE;
?>
# On recupere le mode privatisé
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$parameter = $plugin->getParam('privatize');
#Selon le mode privatisé, on redirige vers la page d'authenfication si par encore logué
if($parameter =="catart") {
if (!isset($_SESSION['profil']) && (($plxMotor->mode === 'categorie' ) || ($plxMotor->mode === 'article' ))) {
$_SESSION['pageRequest']= $_SERVER['REQUEST_URI'];
header("Location: ".$plxMotor->urlRewrite(PLX_ROOT."core/admin/"));
exit;
}
}
else if ($parameter =="static") {
if (!isset($_SESSION['profil']) && ($plxMotor->mode === 'static' )) {
$_SESSION['pageRequest']= $_SERVER['REQUEST_URI'];
header("Location: ".$plxMotor->urlRewrite(PLX_ROOT."core/admin/"));
exit;
}
}
else if ($parameter =="blog") {
if (!isset($_SESSION['profil']) && (($plxMotor->mode === 'home' ))) {
$_SESSION['pageRequest']=$_SERVER['REQUEST_URI'];
header("Location: ".$plxMotor->urlRewrite(PLX_ROOT."core/admin/"));
exit;
}
}
<?php
echo self::END_CODE;
}
#Ajout class a body selon config du plugin
public function ThemeEndBody() {
echo self::BEGIN_CODE;
?>
if ((!isset($_SESSION['profil']))) {
echo'
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" media="screen"/>
<script>
let zoneMode = document.querySelector("body#top");
zoneMode.classList.add("vip-mode-'.$parameter.'");
</script>';
}
<?php
echo self::END_CODE;
}
#Ajout d'un bouton de deconnexion dans le menu principal si le visiteur est authentifier .
public function plxShowStaticListEnd() {
echo self::BEGIN_CODE;
?>
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$parameter = $plugin->getParam('privatize');
if ((isset($_SESSION['profil'])) && ($_SESSION['profil']=='5') ) { array_push($menus, '<li class="static menu noactive" id="vip_logout"><a href="'.PLX_ROOT.'core/admin/auth.php?d=1" title="'.$plugin->getLang("L_VIP_LOGOUT_TITLE").'">'.$plugin->getLang("L_VIP_LOGOUT").'</a></li>');}
if (!isset($_SESSION['profil'])) {
$menus = array();
$home = ((empty($this->plxMotor->get) or preg_match('/^page[0-9]*/', $this->plxMotor->get)) and basename($_SERVER['SCRIPT_NAME']) == "index.php");
# Si on a la variable extra, on affiche un lien vers la page d'accueil (avec $extra comme nom)
if ($extra != '') {
$stat = str_replace('#static_id', 'static-home', $format);
$stat = str_replace('#static_class', 'static menu', $stat);
$stat = str_replace('#static_url', $this->plxMotor->urlRewrite(), $stat);
$stat = str_replace('#static_name', plxUtils::strCheck($extra), $stat);
$stat = str_replace('#static_status', ($home == true ? "active" : "noactive"), $stat);
$menus[][] = $stat;
}
$group_active = "";
if ($this->plxMotor->aStats) {
foreach ($this->plxMotor->aStats as $k => $v) {
if ($v['active'] == 1 and $v['menu'] == 'oui') { # La page est bien active et dispo ds le menu
$stat = str_replace('#static_id', 'static-' . intval($k), $format);
$stat = str_replace('#static_class', 'static menu ', $stat);
if ($v['url'][0] == '?') # url interne commençant par ?
$stat = str_replace('#static_url', $this->plxMotor->urlRewrite($v['url']), $stat);
elseif (plxUtils::checkSite($v['url'], false)) # url externe en http ou autre
$stat = str_replace('#static_url', $v['url'], $stat);
else # url page statique
$stat = str_replace('#static_url', $this->plxMotor->urlRewrite('?static' . intval($k) . '/' . $v['url']), $stat);
$stat = str_replace('#static_name', plxUtils::strCheck($v['name']), $stat);
$stat = str_replace('#static_status', ($this->staticId() == intval($k) ? 'active' : 'noactive'), $stat);
if ($v['group'] == '')
$menus[][] = $stat;
else
$menus[$v['group']][] = $stat;
if ($group_active == "" and $home === false and $this->staticId() == intval($k) and $v['group'] != '')
$group_active = $v['group'];
}
}
}
if ($menublog) {
if ($this->plxMotor->aConf['homestatic'] != '' and isset($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']])) {
if ($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']]['active']) {
$menu = str_replace('#static_id', 'static-blog', $format);
if ($this->plxMotor->get and preg_match('/(blog|categorie|archives|tag|article)/', $_SERVER['QUERY_STRING'] . $this->plxMotor->mode)) {
$menu = str_replace('#static_status', 'active', $menu);
} else {
$menu = str_replace('#static_status', 'noactive', $menu);
}
$menu = str_replace('#static_url', $this->plxMotor->urlRewrite('?blog'), $menu);
$menu = str_replace('#static_name', L_PAGEBLOG_TITLE, $menu);
$menu = str_replace('#static_class', 'static menu', $menu);
array_splice($menus, (intval($menublog) - 1), 0, array($menu));
}
}
}
}
<?php
echo self::END_CODE;
}
#cache le contenu des article si en zone VIP non connecté.
public function plxMotorParseArticle() {
echo self::BEGIN_CODE;
?>
if (!isset($_SESSION['profil'])) {
# pour accéder au plugin
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$parameter = $plugin->getParam('privatize');
$artHidden = $plugin->getLang("L_HIDDEN_ARTICLE");
if($parameter =='blog') {$artHidden = $plugin->getLang("L_HIDDEN_ARTICLE_BLOG");}
if(($parameter =='catart') or ($parameter =='blog') ){
$art = array(
'filename' => $filename,
# Recuperation des valeurs de nos champs XML
'title' => plxUtils::getValue($values[$iTags['title'][0]]['value']),
'allow_com' => plxUtils::getValue($values[$iTags['allow_com'][0]]['value'], 0),
'template' => plxUtils::getValue($values[$iTags['template'][0]]['value'], 'article.php'),
'chapo' => $artHidden,
'content' => '',
'tags' => plxUtils::getValue($values[ $iTags['tags'][0] ]['value']),
'meta_description' => plxUtils::getValue($values[$meta_description]['value']),
'meta_keywords' => plxUtils::getValue($values[$meta_keywords]['value']),
'title_htmltag' => plxUtils::getValue($values[$iTags['title_htmltag'][0]]['value']),
'thumbnail' => '',
'thumbnail_title' => '',
'thumbnail_alt' => '',
'numero' => $tmp['artId'],
'author' => $tmp['usrId'],
'categorie' => $tmp['catId'],
'url' => $tmp['artUrl'],
'date' => $tmp['artDate'],
'nb_com' => $this->getNbCommentaires('#^' . $tmp['artId'] . '.\d{10}.\d+.xml$#'),
'date_creation' => plxUtils::getValue($values[$iTags['date_creation'][0]]['value'], $tmp['artDate']),
'date_update' => plxUtils::getValue($values[$iTags['date_update'][0]]['value'], $tmp['artDate']),
);
}
}
<?php
echo self::END_CODE;
}
# cache les commentaire en sidebar
public function plxShowLastComList() {
echo self::BEGIN_CODE;
?>
# pour accéder au plugin
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$parameter = $plugin->getParam('privatize');
if(!isset($_SESSION['profil']) and ($parameter =='catart' or $parameter =='blog' )) {
$this->plxMotor->plxGlob_coms->aFiles = array();
echo $plugin->getLang("L_HIDDEN_COMMENTS");
}
<?php
echo self::END_CODE;
}
#cache les commentaires si en zone VIP
public function plxMotorParseCommentaire() {
echo self::BEGIN_CODE;
?>
# pour accéder au plugin
$plxMotor = plxMotor::getInstance();
$plugin = $plxMotor->plxPlugins->aPlugins['vip_zone'];
$parameter = $plugin->getParam('privatize');
if( !isset($_SESSION['profil']) and ($parameter =='catart' or $parameter =='blog' )){
$com['author'] = $plugin->getLang("L_HIDDEN_AUTHOR");
$com['content'] = $plugin->getLang("L_HIDDEN_COMMENT");
}
<?php
echo self::END_CODE;
}
# pas hook
# repositionne le plugin en premiere position // utilise le formatage XML produit par PluXml
/* aprés maj du fichier plugins.xml, les tags
<plugin name="non du plugin" scope=""></plugin> sont réecris en
<plugin name="non du plugin" scope=""/> conformement à la syntaxe XML
sans provoquer de dysfonctionement de lecture dans PluXml .
*/
public function resetPluginsToTop() {
$xmlplug = file_get_contents(PLX_ROOT.PLX_CONFIG_PATH.'plugins.xml', true);
$topDoc ='<document>';
$topPlug= ' <plugin name="vip_zone" scope=""></plugin>';//recherche sur syntaxe produite par PluXml
$newxmlplug = str_replace($topPlug, '', $xmlplug);
$res = str_replace($topDoc, $topDoc.' '.$topPlug, $newxmlplug);
$doc = simplexml_load_string($res);
$endres = new DOMDocument ();
$endres->preserveWhiteSpace = false;
$endres->formatOutput = true;
$endres->loadXML ( $doc->asXML() );
$endres->save(PLX_ROOT.PLX_CONFIG_PATH.'plugins.xml');
}
#end class
}