1 | <?php |
---|
2 | |
---|
3 | function jqueryui_jquery_plugins($plugins){ |
---|
4 | $config = @unserialize($GLOBALS['meta']['jqueryui']); |
---|
5 | |
---|
6 | if (!is_array($config) OR !is_array($config['plugins'])) { |
---|
7 | $config['plugins'] = array(); |
---|
8 | $ecrire_meta = 'oui'; |
---|
9 | } |
---|
10 | |
---|
11 | $config['plugins'] = array_unique(array_merge(sinon(pipeline('jqueryui_forcer'),array()),$config['plugins'])); |
---|
12 | |
---|
13 | /** |
---|
14 | * Gestion des dépendances inter plugins |
---|
15 | */ |
---|
16 | $dependance_core = array( |
---|
17 | 'jquery.ui.mouse', |
---|
18 | 'jquery.ui.widget', |
---|
19 | 'jquery.ui.datepicker' |
---|
20 | ); |
---|
21 | |
---|
22 | /** |
---|
23 | * Dépendances à widget |
---|
24 | * Si un autre plugin est dépendant d'un de ceux là, on ne les ajoute pas |
---|
25 | */ |
---|
26 | $dependance_widget = array( |
---|
27 | 'jquery.ui.mouse', |
---|
28 | 'jquery.ui.accordion', |
---|
29 | 'jquery.ui.autocomplete', |
---|
30 | 'jquery.ui.button', |
---|
31 | 'jquery.ui.dialog', |
---|
32 | 'jquery.ui.tabs', |
---|
33 | 'jquery.ui.progressbar' |
---|
34 | ); |
---|
35 | |
---|
36 | $dependance_mouse = array( |
---|
37 | 'jquery.ui.draggable', |
---|
38 | 'jquery.ui.droppable', |
---|
39 | 'jquery.ui.resizable', |
---|
40 | 'jquery.ui.selectable', |
---|
41 | 'jquery.ui.sortable', |
---|
42 | 'jquery.ui.slider' |
---|
43 | ); |
---|
44 | |
---|
45 | $dependance_position = array( |
---|
46 | 'jquery.ui.autocomplete', |
---|
47 | 'jquery.ui.dialog', |
---|
48 | ); |
---|
49 | |
---|
50 | $dependance_draggable = array( |
---|
51 | 'jquery.ui.droppable' |
---|
52 | ); |
---|
53 | |
---|
54 | $dependance_effects = array( |
---|
55 | 'jquery.effects.blind', |
---|
56 | 'jquery.effects.bounce', |
---|
57 | 'jquery.effects.clip', |
---|
58 | 'jquery.effects.drop', |
---|
59 | 'jquery.effects.explode', |
---|
60 | 'jquery.effects.fold', |
---|
61 | 'jquery.effects.highlight', |
---|
62 | 'jquery.effects.pulsate', |
---|
63 | 'jquery.effects.scale', |
---|
64 | 'jquery.effects.shake', |
---|
65 | 'jquery.effects.slide', |
---|
66 | 'jquery.effects.transfer' |
---|
67 | ); |
---|
68 | |
---|
69 | /** |
---|
70 | * Vérification des dépendances |
---|
71 | * Ici on ajoute quand même le plugin en question et on supprime les doublons via array_unique |
---|
72 | * Pour éviter le cas où un pipeline demanderait un plugin dans le mauvais sens de la dépendance par exemple |
---|
73 | * |
---|
74 | * On commence par le bas de l'échelle : |
---|
75 | * - draggable |
---|
76 | * - position |
---|
77 | * - mouse |
---|
78 | * - widget |
---|
79 | * - core |
---|
80 | * - effects |
---|
81 | */ |
---|
82 | if(count($intersect = array_intersect($config['plugins'],$dependance_draggable)) > 0){ |
---|
83 | $keys = array_keys($intersect); |
---|
84 | array_splice($config['plugins'],$keys[0], 0, "jquery.ui.draggable"); |
---|
85 | } |
---|
86 | if(count($intersect = array_intersect($config['plugins'],$dependance_position)) > 0){ |
---|
87 | $keys = array_keys($intersect); |
---|
88 | array_splice($config['plugins'],$keys[0], 0, "jquery.ui.position"); |
---|
89 | } |
---|
90 | if(count($intersect = array_intersect($config['plugins'],$dependance_mouse)) > 0){ |
---|
91 | $keys = array_keys($intersect); |
---|
92 | array_splice($config['plugins'],$keys[0], 0, "jquery.ui.mouse"); |
---|
93 | } |
---|
94 | if(count($intersect = array_intersect($config['plugins'],$dependance_widget)) > 0){ |
---|
95 | $keys = array_keys($intersect); |
---|
96 | array_splice($config['plugins'],$keys[0], 0, "jquery.ui.widget"); |
---|
97 | } |
---|
98 | if(count($intersect = array_intersect($config['plugins'],$dependance_core)) > 0){ |
---|
99 | $keys = array_keys($intersect); |
---|
100 | array_splice($config['plugins'],$keys[0], 0, "jquery.ui.core"); |
---|
101 | } |
---|
102 | if(count($intersect = array_intersect($config['plugins'],$dependance_effects)) > 0){ |
---|
103 | $keys = array_keys($intersect); |
---|
104 | array_splice($config['plugins'],$keys[0], 0, "jquery.effects.core"); |
---|
105 | } |
---|
106 | $config['plugins'] = array_unique($config['plugins']); |
---|
107 | foreach ($config['plugins'] as $val) { |
---|
108 | $plugins[] = _DIR_JQUERYUI_JS.$val.".js"; |
---|
109 | } |
---|
110 | |
---|
111 | // si pas de config en base, on enregistre les scripts issu du pipeline jqueryui_forcer + leurs dépendances |
---|
112 | if ($ecrire_meta == 'oui') { |
---|
113 | include_spip('inc/meta'); |
---|
114 | ecrire_meta('jqueryui',serialize($config)); |
---|
115 | } |
---|
116 | |
---|
117 | return $plugins; |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * jqueryui_insert_head : ajout des CSS de jQuery-UI pour les pages publiques et privées |
---|
122 | * avec gestion du theme et des UI utilises |
---|
123 | * |
---|
124 | * @param: $flux |
---|
125 | * @return: $flux |
---|
126 | */ |
---|
127 | function jqueryui_insert_head($flux) { |
---|
128 | $config = @unserialize($GLOBALS['meta']['jqueryui']); |
---|
129 | |
---|
130 | // recuperer le repertoire du theme |
---|
131 | $theme = 'base/'; |
---|
132 | if (isset($config['theme']) AND $config['theme'] != '') |
---|
133 | $theme = $config['theme'].'/'; |
---|
134 | if ($theme == 'no_css/' && !defined('_JQUERYUI_FORCER_CSS')) |
---|
135 | return $flux; |
---|
136 | |
---|
137 | // ajouter core tout le temps et en debut de tableau, array_unique supprimera les occurrences suivantes |
---|
138 | array_unshift($config['plugins'],'jquery.ui.core'); |
---|
139 | |
---|
140 | // recuperer la liste des plugins jquery actives ou issus du pipeline jqueryui_forcer |
---|
141 | // Attention, l'ordre du merge est important, le css du core doit est charge avant le reste |
---|
142 | $config['plugins'] = array_unique(array_merge($config['plugins'],sinon(pipeline('jqueryui_forcer'),array()))); |
---|
143 | |
---|
144 | // ajouter theme si necessaire |
---|
145 | if (!in_array('jquery.ui.theme', $config['plugins'])) |
---|
146 | $config['plugins'][] = 'jquery.ui.theme'; |
---|
147 | |
---|
148 | // les CSS correspondantes aux plugins |
---|
149 | $Tjquery_css = array( |
---|
150 | 'jquery.ui.accordion', |
---|
151 | 'jquery.ui.autocomplete', |
---|
152 | 'jquery.ui.button', |
---|
153 | 'jquery.ui.core', |
---|
154 | 'jquery.ui.datepicker', |
---|
155 | 'jquery.ui.dialog', |
---|
156 | 'jquery.ui.progressbar', |
---|
157 | 'jquery.ui.resizable', |
---|
158 | 'jquery.ui.selectable', |
---|
159 | 'jquery.ui.slider', |
---|
160 | 'jquery.ui.tabs', |
---|
161 | 'jquery.ui.theme' |
---|
162 | ); |
---|
163 | |
---|
164 | // appeler les CSS necessaires |
---|
165 | foreach ($config['plugins'] as $plug) { |
---|
166 | if (in_array($plug, $Tjquery_css)) { |
---|
167 | $flux .= "<link rel='stylesheet' type='text/css' media='all' href='".find_in_path(_DIR_JQUERYUI_CSS.$theme.$plug.'.css')."' />\n"; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | return $flux; |
---|
172 | } |
---|
173 | |
---|
174 | ?> |
---|