1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Insertion dans le pipeline insert_head_css |
---|
5 | * si on a configuré multilang pour s'insérer dans l'espace public |
---|
6 | * |
---|
7 | * @param $flux |
---|
8 | */ |
---|
9 | function multilang_insert_head_css($flux){ |
---|
10 | |
---|
11 | $config = lire_config('multilang',array()); |
---|
12 | if($config['multilang_public'] == 'on'){ |
---|
13 | |
---|
14 | static $done = false; |
---|
15 | |
---|
16 | if (!$done) { |
---|
17 | |
---|
18 | $done = true; |
---|
19 | $flux .= '<link rel="stylesheet" href="'.url_absolue(generer_url_public('multilang.css')).'" type="text/css" media="all" />'; |
---|
20 | } |
---|
21 | } |
---|
22 | return $flux; |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * Insertion dans le pipeline insert_head_prive |
---|
27 | * Ajoute css et javascript dans le <head> privé |
---|
28 | * |
---|
29 | * @param string $flux Le contenu du head privé |
---|
30 | */ |
---|
31 | function multilang_insert_head_prive($flux){ |
---|
32 | |
---|
33 | $config = lire_config('multilang',array()); |
---|
34 | |
---|
35 | $flux .= multilang_inserer_head($config); |
---|
36 | |
---|
37 | return $flux; |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * Insertion dans le pipeline insert_head |
---|
42 | * si on a configuré multilang pour s'insérer dans l'espace public |
---|
43 | * |
---|
44 | * @param $flux |
---|
45 | */ |
---|
46 | function multilang_insert_head($flux){ |
---|
47 | |
---|
48 | $config = lire_config('multilang',array()); |
---|
49 | |
---|
50 | if($config['multilang_public'] == 'on'){ |
---|
51 | $flux .= multilang_insert_head_css(''); // au cas ou il n'est pas implemente |
---|
52 | $flux .= multilang_inserer_head($config); |
---|
53 | } |
---|
54 | return $flux; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * La fonction de modification du $flux pour l'insertion dans le head qu'il |
---|
59 | * soit privé ou public |
---|
60 | * |
---|
61 | * @param string $flux Le head de la page où l'on se trouve |
---|
62 | * @param array $config La configuration du plugin |
---|
63 | */ |
---|
64 | function multilang_inserer_head($config=array()){ |
---|
65 | if(count(explode(',',$GLOBALS["meta"]["langues_multilingue"])) > 1){ |
---|
66 | |
---|
67 | $root = '' ; |
---|
68 | |
---|
69 | if($config['siteconfig']){ |
---|
70 | $root .= 'div#configurer-accueil,div.formulaire_configurer_identite' ; // Config Site |
---|
71 | } |
---|
72 | if($config['article']) { // Articles |
---|
73 | $root .= ',div.formulaire_editer_article'; |
---|
74 | } |
---|
75 | if($config['breve']) { // Breves |
---|
76 | $root .= ',div.formulaire_editer_breve'; |
---|
77 | } |
---|
78 | if($config['rubrique']) { // Rubriques |
---|
79 | $root .= ',div.formulaire_editer_rubrique'; |
---|
80 | } |
---|
81 | if($config['auteur']) { // Auteurs |
---|
82 | $root .= ',div.formulaire_editer_auteur'; |
---|
83 | } |
---|
84 | if($config['document']) { // Docs dans page de presentation rubrique ou article, |
---|
85 | $root .= ',div#portfolio_portfolio,div#portfolio_documents' ; |
---|
86 | } |
---|
87 | if($config['site']) { // Sites |
---|
88 | $root .= ',div.formulaire_editer_site'; |
---|
89 | } |
---|
90 | if($config['evenement']) { // Evenements |
---|
91 | $root .= ',div.formulaire_editer_evenement'; |
---|
92 | } |
---|
93 | if($config['motcle']) { // Mots |
---|
94 | $root .= ',div.formulaire_editer_mot,div.formulaire_editer_groupe_mot'; |
---|
95 | } |
---|
96 | if($config['gis']) { // GIS |
---|
97 | $root .= ',div.formulaire_editer_gis'; |
---|
98 | } |
---|
99 | |
---|
100 | // Docs traites a part dans pages d'edition d'articles et de rubriques |
---|
101 | if($config['document']){ |
---|
102 | $root .= ',div#liste_documents,div.formulaire_editer_document' ; // avec ou sans Mediatheque |
---|
103 | } |
---|
104 | |
---|
105 | // Appel de multilang_init_lang si |
---|
106 | // - document.ready |
---|
107 | // - onAjaxLoad (cas des docs et de la configuration du site) |
---|
108 | |
---|
109 | $data = ' |
---|
110 | <script type="text/javascript" src="'.generer_url_public("multilang_lang.js","lang=".$GLOBALS["spip_lang"]).'"></script> |
---|
111 | <script type="text/javascript" src="'.find_in_path("javascript/multilang.js").'"></script> |
---|
112 | <script type="text/javascript"> |
---|
113 | var multilang_avail_langs = "'.$GLOBALS["meta"]["langues_multilingue"].'".split(\',\'), |
---|
114 | multilang_def_lang = "'.$GLOBALS["meta"]["langue_site"].'", |
---|
115 | multilang_lang_courante = "'.$GLOBALS["spip_lang"].'", |
---|
116 | multilang_dir_plugin = "'._DIR_PLUGIN_MULTILANG.'"; |
---|
117 | |
---|
118 | // On trie les langues. Langue de l environnement en premier, |
---|
119 | // puis langue principale du site puis les autres en ordre alphabetique |
---|
120 | // Un utilisateur de langue anglaise souhaite logiquement traduire en anglais |
---|
121 | multilang_avail_langs = jQuery.grep(multilang_avail_langs, function(value) { |
---|
122 | return (value != multilang_def_lang && value != multilang_lang_courante); |
---|
123 | }); |
---|
124 | multilang_avail_langs.sort(); |
---|
125 | if(multilang_lang_courante!=multilang_def_lang) multilang_avail_langs.unshift(multilang_def_lang); |
---|
126 | multilang_avail_langs.unshift(multilang_lang_courante); |
---|
127 | |
---|
128 | jQuery(document).ready(function(){ |
---|
129 | function multilang_init(){ |
---|
130 | var root = "'.$root.'"; |
---|
131 | var fields_selector = "textarea:not(textarea#adresses_secondaires),input:text:not(input#new_login,input#email,#titreparent,input.date,input.heure,input#largeur,input#hauteur,.ac_input,#url_syndic,#url_auto,#champ_geocoder,#champ_lat,#champ_lon,#champ_zoom,*.nomulti),.multilang"; |
---|
132 | // on exclue aussi les form d upload (Pour les vignettes de docs, logos...) |
---|
133 | var forms_selector = "form[class!=\'form_upload\'][class!=\'form_upload_icon\']"; |
---|
134 | // Les div qui ont un formulaire de classe multilang (pour accélérer la recherche dans le DOM, |
---|
135 | // on passe le form et le parent sera trouvé dans lors de l\'init) |
---|
136 | var root_opt = "form:has(.multilang)"; |
---|
137 | var fields_selector_opt = ".multilang"; |
---|
138 | multilang_init_lang({fields:fields_selector,fields_opt:fields_selector_opt,root:root,root_opt:root_opt,forms:forms_selector}); |
---|
139 | } |
---|
140 | multilang_init(); |
---|
141 | if(typeof onAjaxLoad == "function") onAjaxLoad(multilang_init); |
---|
142 | }); |
---|
143 | </script> |
---|
144 | '; |
---|
145 | } |
---|
146 | return $data; |
---|
147 | } |
---|
148 | |
---|
149 | function multilang_affichage_final($flux){ |
---|
150 | if($_REQUEST['page'] == 'crayons.js'){ |
---|
151 | $root = '' ; |
---|
152 | $config = lire_config('multilang',array()); |
---|
153 | if(($config['multilang_public'] == 'on') && ($config['multilang_crayons'] == 'on')){ |
---|
154 | if($config['siteconfig']){ |
---|
155 | $root .= ',input[type=hidden][name*=name_][value|=meta-valeur]'; |
---|
156 | } |
---|
157 | if($config['article']) { // Articles |
---|
158 | $root .= ',input[type=hidden][name*=name_][value|=article]:not(input[value|=article-logo])'; |
---|
159 | } |
---|
160 | if($config['breve']) { // Breves |
---|
161 | $root .= ',input[type=hidden][name*=name_][value|=breve]:not(input[value|=breve-logo])'; |
---|
162 | } |
---|
163 | if($config['rubrique']) { // Rubriques |
---|
164 | $root .= ',input[type=hidden][name*=name_][value|=rubrique]:not(input[value|=rubrique-logo])'; |
---|
165 | } |
---|
166 | if($config['auteur']) { // Auteurs |
---|
167 | $root .= ',input[type=hidden][name*=name_][value|=auteur]:not(input[value|=auteur-logo])'; |
---|
168 | } |
---|
169 | if($config['document']) { // Docs dans page de presentation rubrique ou article, |
---|
170 | $root .= ',input[type=hidden][name*=name_][value|=document]:not(input[value|=document-vignette])' ; |
---|
171 | } |
---|
172 | if($config['site']) { // Sites |
---|
173 | $root .= ',input[type=hidden][name*=name_][value|=site]'; |
---|
174 | } |
---|
175 | if($config['evenement']) { // Evenements |
---|
176 | $root .= ',input[type=hidden][name*=name_][value|=evenement]'; |
---|
177 | } |
---|
178 | if($config['motcle']) { // Mots |
---|
179 | $root .= ',input[type=hidden][name*=name_][value|=mot]:not(input[value|=mot-logo])'; |
---|
180 | } |
---|
181 | if($config['gis']) { // GIS |
---|
182 | $root .= ',input[type=hidden][name*=name_][value|=gis]:not(input[value|=gis-logo])'; |
---|
183 | } |
---|
184 | $flux .= ' |
---|
185 | var crayons_multilang_init = function(){ |
---|
186 | var crayons_root = ".formulaire_spip:has('.$root.')"; |
---|
187 | var fields_selector = "textarea,input:text:not(input.date,input.heure,*.nomulti)"; |
---|
188 | var forms_selector = "form[class!=\'form_upload\'][class!=\'form_upload_icon\']"; |
---|
189 | var root_opt = "form:has(.multilang)"; |
---|
190 | var fields_selector_opt = ".multilang"; |
---|
191 | multilang_init_lang({fields:fields_selector,fields_opt:fields_selector_opt,root:crayons_root,root_opt:root_opt,forms:forms_selector,init_done:false}); |
---|
192 | } |
---|
193 | jQuery(document).ready(function(){ |
---|
194 | crayons_multilang_init(); |
---|
195 | if(typeof onAjaxLoad == "function") onAjaxLoad(crayons_multilang_init); |
---|
196 | });'; |
---|
197 | $flux = str_replace('jQuery', 'cQuery',$flux); |
---|
198 | } |
---|
199 | } |
---|
200 | return $flux; |
---|
201 | } |
---|
202 | ?> |
---|