-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagOptions.php
More file actions
455 lines (352 loc) · 13.1 KB
/
tagOptions.php
File metadata and controls
455 lines (352 loc) · 13.1 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<?php if(!defined('PLX_ROOT')) exit;
/**
* Plugin tagOptions
*
* @CMS required PluXml
*
* @version 1.0
* @date 2024-01-12
* @author G.Cyrille
**/
class tagOptions extends plxPlugin {
const BEGIN_CODE = '<?php' . PHP_EOL;
const END_CODE = PHP_EOL . '?>';
const XML_TAGS_OPTIONS = PLX_ROOT . PLX_CONFIG_PATH . 'tagsOptions.xml';
public $tagList = array();
public $tagListCheck = array();
public $lang = '';
public $pageTagTitle ='Mot clé';
public function __construct($default_lang) {
# appel du constructeur de la classe plxPlugin (obligatoire)
parent::__construct($default_lang);
# droits pour accèder à la page admin.php du plugin
$this->setAdminProfil(PROFIL_ADMIN, PROFIL_MANAGER);
# Personnalisation du menu admin
$this->setAdminMenu('Mots clés', 3, 'Descriptions et metadonnées des étiquettes');
# Declaration des hooks
$this->addHook('AdminTopBottom', 'AdminTopBottom');
$this->addHook('plxShowConstruct', 'plxShowConstruct');
$this->addHook('plxShowPageTitle', 'plxShowPageTitle');
$this->addHook('tagDescription', 'tagOptionswidget');
$this->addHook('wizard', 'wizard');
$this->addHook('MyHsitemapTags', 'MyHsitemapTags');
$this->addHook('plxShowMeta', 'plxShowMeta');
$this->addHook('plxShowArtTags', 'plxShowArtTags');
$this->addHook('plxShowTagList', 'plxShowTagList');
$this->addHook('plxShowTagFeed', 'plxShowTagFeed');
}
# Activation / desactivation
public function OnActivate() {
# code à executer à l’activation du plugin
if(!file_exists(self::XML_TAGS_OPTIONS)){
if (touch(self::XML_TAGS_OPTIONS)) {
$this->editXMLtagsOptions('init',self::XML_TAGS_OPTIONS );
}
}
# activation du wizard
$_SESSION['justactivated'.basename(__DIR__)] = true;
}
public function OnDeactivate() {
# code à executer à la désactivation du plugin
}
/**
* Méthode qui affiche un message si le plugin n'a pas la langue du site dans sa traduction
* Ajout gestion du wizard si inclus au plugin
* @return stdio
* @author Stephane F
**/
public function AdminTopBottom() {
echo '<?php
$file = PLX_PLUGINS."'.$this->plug['name'].'/lang/".$plxAdmin->aConf["default_lang"].".php";
if(!file_exists($file)) {
echo "<p class=\\"warning\\">'.basename(__DIR__).'<br />".sprintf("'.$this->getLang('L_LANG_UNAVAILABLE').'", $file)."</p>";
plxMsg::Display();
}
?>';
# affichage du wizard à la demande
if(isset($_GET['wizard'])) {$_SESSION['justactivated'.basename(__DIR__)] = true;}
# fermeture session wizard
if (isset($_SESSION['justactivated'.basename(__DIR__)])) {
unset($_SESSION['justactivated'.basename(__DIR__)]);
$this->wizard();
}
}
/**
* Méthode statique qui affiche le widget
*
**/
public static function tagOptionswidget($widget=false) {
# récupération d'une instance de plxMotor
$plxShow = plxShow::getInstance();
$plxMotor = plxMotor::getInstance();
$plxPlug = $plxMotor->plxPlugins->getInstance(basename(__DIR__));
include(PLX_PLUGINS.basename(__DIR__).'/widget.'.basename(__DIR__).'.php');
}
/**
* Méthode wizard
*
* Descrition :
* @author : '.$_POST['title'].'
*
**/
# insertion du wizard
public function wizard() {
# uniquement dans les page d'administration du plugin.
if(basename(
$_SERVER['SCRIPT_FILENAME']) =='parametres_plugins.php' ||
basename($_SERVER['SCRIPT_FILENAME']) =='parametres_plugin.php' ||
basename($_SERVER['SCRIPT_FILENAME']) =='plugin.php'
) {
include(PLX_PLUGINS.__CLASS__.'/lang/'.$this->default_lang.'-wizard.php');
}
}
/**
* Méthode de traitement du hook plxShowConstruct
*
* @return stdio
* @author Stephane F
**/
public function plxShowConstruct() {
$this->readTagList(self::XML_TAGS_OPTIONS);
}
/**
* Méthode qui renseigne le titre de la page dans la balise html <title>
*
* @return stdio
* @author Stephane F
**/
public function plxShowPageTitle() {
echo self::BEGIN_CODE;
?>
# maj balise title pour les tags
if(preg_match('#^tag/([\w-]+)#',$this->plxMotor->get,$capture)) {
$key = array_search($capture[1], array_column($this->plxMotor->plxPlugins->aPlugins["<?= basename(__DIR__)?>"]->tagList, 'url'));
echo $this->plxMotor->plxPlugins->aPlugins["<?= basename(__DIR__)?>"]->tagList[$key+1]['name'];
return true;
}
<?php
echo self::END_CODE;
}
/**
* Méthode MyHsitemapTags
*
* Descrition :
* @author : TheCrok
*
**/
public function MyHsitemapTags() {
# code à executer
}
/**
* Méthode plxShowMeta
*
* Descrition :
* @author : TheCrok
*
**/
public function plxShowMeta() {
# code à executer
echo self::BEGIN_CODE;
?>
$meta = strtolower($meta);
if($meta == 'author') return true;
# maj balise title pour les tags
if(preg_match('#^tag/([\w-]+)#',$this->plxMotor->get,$capture)) {
$key = array_search($capture[1], array_column($this->plxMotor->plxPlugins->aPlugins["<?= basename(__DIR__)?>"]->tagList, 'url'));
$datas = $this->plxMotor->plxPlugins->aPlugins["<?= basename(__DIR__)?>"]->tagList[$key+1]['meta_'.$meta];
}
if($this->plxMotor->mode == 'tags') {
if($meta == 'description') echo ' <meta name="description" content="'.$datas.'" />'.PHP_EOL;
if($meta == 'keywords') echo ' <meta name="keywords" content="'.$datas.'" />'.PHP_EOL;
return true;
}
<?php
echo self::END_CODE;
}
/**
* Méthode plxShowArtTags
*
* Descrition :
* @author : TheCrok
*
**/
public function plxShowArtTags() {
# code à executer
echo self::BEGIN_CODE;
?>
// here the code to inject into native function at hook's position
// return true; // use if needed : stops native function at this point
<?php
echo self::END_CODE;
}
/**
* Méthode plxShowTagList
*
* Descrition :
* @author : TheCrok
*
**/
public function plxShowTagList() {
# code à executer
echo self::BEGIN_CODE;
?>
// here the code to inject into native function at hook's position
// return true; // use if needed : stops native function at this point
<?php
echo self::END_CODE;
}
/**
* Méthode plxShowTagFeed
*
* Descrition :
* @author : TheCrok
*
**/
public function plxShowTagFeed() {
# code à executer
echo self::BEGIN_CODE;
?>
// here the code to inject into native function at hook's position
// return true; // use if needed : stops native function at this point
<?php
echo self::END_CODE;
}
# fonctions spécifique au plugin
/* edition du fichier "Options" des étiquettes."
*/
public function editXMLtagsOptions($setup='',$filetag=self::XML_TAGS_OPTIONS) {
$tagArray=array();
$i=000;
# create file on Install first time
if($setup == 'init') {
$this->getTagsFromConfig();
$tagArray=$this->tagListCheck;
}
if($setup=='update') {
$tagArray=$this->tagList;
}
if($setup=="regenerate") {
$this->getTagsFromConfig();
$i= count($this->tagList);
foreach($this->tagListCheck as $k => $v) {
$look='';
$lookFor = array_search($k, array_column($this->tagList, 'name'));
if($lookFor !='') continue;
$i++;
$this->tagList[$i]['number']=''.$i.'';
$this->tagList[$i]['name']=$k;
$this->tagList[$i]['url']=$this->tagListCheck[$k]['url'];
$this->tagList[$i]['description']=$this->tagListCheck[$k]['description'];
$this->tagList[$i]['meta_description']=$this->tagListCheck[$k]['meta_description'];
$this->tagList[$i]['meta_keywords']=$this->tagListCheck[$k]['meta_keywords'];
$this->tagList[$i]['title_htmltag']=$this->tagListCheck[$k]['title_htmltag'];
$this->tagList[$i]['thumbnail']=$this->tagListCheck[$k]['thumbnail'];
$this->tagList[$i]['thumbnail_alt']=$this->tagListCheck[$k]['thumbnail_alt'];
$this->tagList[$i]['thumbnail_title']=$this->tagListCheck[$k]['thumbnail_title'];
echo $this->tagListCheck[$k]['url'];
}
$tagArray=$this->tagList;
$i=0;
}
# On génére le fichier XML
$xml = "<?xml version=\"1.0\" encoding=\"".PLX_CHARSET."\"?>\n";
$xml .= "<document>\n";
foreach($tagArray as $tag_id => $tag) {
$i++;
if($setup=='update') {$i=$tag_id;}
$xml .= "\t<tag number=\"".$i."\" url=\"".$tag['url']."\" >";
$xml .= "<name><![CDATA[".$tag['name']."]]></name>";
$xml .= "<description><![CDATA[".$tag['description']."]]></description>";
$xml .= "<meta_description><![CDATA[".plxUtils::cdataCheck($tag['meta_description'])."]]></meta_description>";
$xml .= "<meta_keywords><![CDATA[".plxUtils::cdataCheck($tag['meta_keywords'])."]]></meta_keywords>";
$xml .= "<title_htmltag><![CDATA[".plxUtils::cdataCheck($tag['title_htmltag'])."]]></title_htmltag>";
$xml .= "<thumbnail><![CDATA[".plxUtils::cdataCheck($tag['thumbnail'])."]]></thumbnail>";
$xml .= "<thumbnail_alt><![CDATA[".plxUtils::cdataCheck($tag['thumbnail_alt'])."]]></thumbnail_alt>";
$xml .= "<thumbnail_title><![CDATA[".plxUtils::cdataCheck($tag['thumbnail_title'])."]]></thumbnail_title>";
# Hook plugins
// just for infos because there's one for categories
$xml .= "</tag>\n";
}
$xml .= "</document>";
# On écrit le fichier
if(plxUtils::write($xml, $filetag))
return plxMsg::Info(L_SAVE_SUCCESSFUL);
else
return plxMsg::Error(L_SAVE_ERR.' '.path($filetag));
}
/*
* Methode qui extrait les tags dans un tableau
*
*/
public function getTagsFromConfig() {
global $plxAdmin;
# On verifie qu'il y a des tags
if ($plxAdmin->aTags) {
$now = date('YmdHi');
foreach ($plxAdmin->aTags as $idart => $tag) {
if (isset($plxAdmin->activeArts[$idart]) and $tag['tags'] !='' and $tag['date'] <= $now and $tag['active']) {
if ($tags = array_map('trim', explode(',', $tag['tags']))) {
foreach ($tags as $tag) {
if (!empty($tag)) {
if (!array_key_exists($tag, $this->tagListCheck)) {
$this->tagListCheck[$tag] = array();
$this->tagListCheck[$tag]['name']= $tag;
$this->tagListCheck[$tag]['description']= '';
$this->tagListCheck[$tag]['meta_description']= '';
$this->tagListCheck[$tag]['meta_keywords']= $tag ;
$this->tagListCheck[$tag]['thumbnail']= '';
$this->tagListCheck[$tag]['thumbnail_title']= '';
$this->tagListCheck[$tag]['thumbnail_alt']= '';
$this->tagListCheck[$tag]['title_htmltag']= L_ARTICLE_TAGS_FIELD.' '.$tag;
$this->tagListCheck[$tag]['url']= plxUtils::title2url($tag);
}
}
}
}
}
}
}
ksort($this->tagListCheck);
$this->tagListCheck = $this->tagListCheck;
}
public function readTagList($filetag) {
# a t-on un fichier à lire ?
if(!is_file($filetag)) return;
# Mise en place du parseur XML
$data = implode('',file($filetag));
$parser = xml_parser_create(PLX_CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_parse_into_struct($parser,$data,$values,$iTags);
xml_parser_free($parser);
if(isset($iTags['tag']) AND isset($iTags['name'])) {
$nb = sizeof($iTags['name']);
$size=ceil(sizeof($iTags['tag'])/$nb);
for($i=0;$i<$nb;$i++) {
$attributes = $values[$iTags['tag'][$i*$size]]['attributes'];
$number = $attributes['number'];
# Recuperation du nom du tag
$this->tagList[$number]['number']=$number;
# Recuperation du nom du tag
// plxUtils::getValue($values[$iTags['meta_description'][$i]]['value']);
$this->tagList[$number]['name']=plxUtils::getValue($values[$iTags['name'][$i]]['value']);
# Recuperation du nom de la description
$this->tagList[$number]['description']=plxUtils::getValue($values[$iTags['description'][$i]]['value']);
# Recuperation de la balise title
$this->tagList[$number]['title_htmltag']=plxUtils::getValue($values[$iTags['title_htmltag'][$i]]['value']);
# Recuperation du meta description
$this->tagList[$number]['meta_description']=plxUtils::getValue($values[$iTags['meta_description'][$i]]['value']);
# Recuperation du meta keywords
$this->tagList[$number]['meta_keywords']=plxUtils::getValue($values[$iTags['meta_keywords'][$i]]['value']);
# Recuperation de l'url de la categorie
$this->tagList[$number]['url']=strtolower($attributes['url']);
# Récupération des informations de l'image représentant le tag
$this->tagList[$number]['thumbnail']=plxUtils::getValue($values[$iTags['thumbnail'][$i]]['value']);
$this->tagList[$number]['thumbnail_title']=plxUtils::getValue($values[$iTags['thumbnail_title'][$i]]['value']);
$this->tagList[$number]['thumbnail_alt']=plxUtils::getValue($values[$iTags['thumbnail_alt'][$i]]['value']);
}
# Hook plugins
// because similar categorie function got one about here
}
}
}