[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / textwheel / wheels / spip / spip-listes.php
1 <?php
2
3 if (!defined('_ECRIRE_INC_VERSION')) {
4 return;
5 }
6 # not useful as this file is included by the engine itself
7 # require_once 'engine/textwheel.php';
8
9 function tw_liste_init($t) {
10 charger_fonction('dummy', 'inc', true); // ne sert a rien mais evite un segmentation fault PHP, on dirait
11 return tw_liste_item($t, 'init');
12 }
13
14 function tw_liste_close($t) {
15 return tw_liste_item($t, 'close');
16 }
17
18 function tw_liste_item($t, $quoi = 'item') {
19 global $class_spip, $class_spip_plus;
20 static $niveau;
21 static $pile_li;
22 static $pile_type;
23 static $type;
24
25 switch ($quoi) {
26 case 'init':
27 $niveau = 0;
28 $pile_li = array();
29 $pile_type = array();
30 $type = '';
31 break;
32 case 'close':
33 // retour sur terre
34 $ajout = '';
35 while ($niveau > 0) {
36 $ajout .= $pile_li[$niveau];
37 $ajout .= $pile_type[$niveau];
38 $niveau--;
39 }
40 $t .= $ajout;
41 break;
42
43 case 'ul':
44 case 'ol':
45 $nouv_type = $quoi;
46 break;
47
48 case 'item':
49 default:
50 $profond = 0;
51 if ($l = strlen($t[2])) {
52 $profond = $l;
53 $nouv_type = 'ul';
54 if (strncmp($t[2], '#', 1) == 0) {
55 $nouv_type = 'ol';
56 }
57 }
58
59 if ($profond > 0) {
60 $ajout = '';
61
62 // changement de type de liste au meme niveau : il faut
63 // descendre un niveau plus bas, fermer ce niveau, et
64 // remonter
65 $change_type = ($type and ($type <> $nouv_type) and ($profond == $niveau)) ? 1 : 0;
66 $type = $nouv_type;
67
68 // d'abord traiter les descentes
69 while ($niveau > $profond - $change_type) {
70 $ajout .= $pile_li[$niveau];
71 $ajout .= $pile_type[$niveau];
72 if (!$change_type) {
73 unset($pile_li[$niveau]);
74 }
75 $niveau--;
76 }
77
78 // puis les identites (y compris en fin de descente)
79 if ($niveau == $profond && !$change_type) {
80 $ajout .= $pile_li[$niveau];
81 }
82
83 // puis les montees (y compris apres une descente un cran trop bas)
84 while ($niveau < $profond) {
85 if ($niveau == 0) {
86 $ajout .= "\n\n";
87 } elseif (!isset($pile_li[$niveau])) {
88 $ajout .= "<li$class_spip>";
89 $pile_li[$niveau] = "</li>";
90 }
91 $niveau++;
92 $ajout .= "<$type$class_spip_plus>";
93 $pile_type[$niveau] = "</$type>";
94 }
95
96 $ajout .= "<li$class_spip>";
97 $pile_li[$profond] = "</li>";
98 } else {
99 $ajout = $t[1]; // puce normale ou <hr>
100 }
101
102 if (!isset($t[3]) or (trim($t[3]) === '')) {
103 // Permet de gerer la previsualisation grand ecran en temps reel en affichant correctement la derniere puce n'ayant pas encore de texte
104 $t[3] = '&nbsp;';
105 }
106 $t = $ajout . $t[3];
107 break;
108 }
109
110 return $t;
111 }
112
113 function tw_def_wrap($t) {
114 global $class_spip_plus;
115
116 return "<dl$class_spip_plus>\n$t</dl>\n";
117 }