[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / multilang / multilang_pipelines.php
1 <?php
2
3 if (!defined('_ECRIRE_INC_VERSION')) {
4 return;
5 }
6
7 /**
8 * Insertion dans le pipeline insert_head_css (SPIP)
9 * si on a configuré multilang pour s'insérer dans l'espace public
10 *
11 * @param string $flux Le contenu du head CSS
12 * @return string $flux Le contenu du head CSS modifié
13 */
14 function multilang_insert_head_css($flux) {
15 if (!function_exists('lire_config')) {
16 include_spip('inc/config');
17 }
18
19 $multilang_public = lire_config('multilang/multilang_public', 'off');
20 if ($multilang_public == 'on') {
21 static $done = false;
22 if (!$done) {
23 $done = true;
24 $css = url_absolue(generer_url_public('multilang.css'));
25 $flux .= '<link rel="stylesheet" href="'.$css.'" type="text/css" media="all" />';
26 }
27 }
28 return $flux;
29 }
30
31 /**
32 * Insertion dans le pipeline insert_head_prive (SPIP)
33 * Ajoute css et javascript dans le <head> privé
34 *
35 * @param string $flux
36 * Le contenu du head
37 * @return string $flux
38 * Le contenu du head modifié
39 */
40 function multilang_insert_head_prive($flux) {
41 if (!function_exists('lire_config')) {
42 include_spip('inc/config');
43 }
44 $config = lire_config('multilang', array());
45
46 $flux .= multilang_inserer_head($config);
47
48 return $flux;
49 }
50
51 /**
52 * Insertion dans le pipeline insert_head (SPIP)
53 * si on a configuré multilang pour s'insérer dans l'espace public
54 *
55 * @param string $flux
56 * Le contenu du head
57 * @return string $flux
58 * Le contenu du head modifié
59 */
60 function multilang_insert_head($flux) {
61 if (!function_exists('lire_config')) {
62 include_spip('inc/config');
63 }
64 $config = lire_config('multilang', array());
65
66 if (isset($config['multilang_public']) and ($config['multilang_public'] == 'on')) {
67 $flux .= multilang_insert_head_css(''); // au cas ou il n'est pas implemente
68 $flux .= multilang_inserer_head($config);
69 }
70 return $flux;
71 }
72
73 /**
74 * La fonction de modification du $flux pour l'insertion dans le head qu'il
75 * soit privé ou public
76 *
77 * @param array $config La configuration du plugin
78 * @return string $data Le contenu textuel qui sera inséré dans le head
79 */
80 function multilang_inserer_head($config = array()) {
81 /**
82 * N'activer multilang que si plus d'une langue dans le site
83 */
84 if (count(explode(',', $GLOBALS['meta']['langues_multilingue'])) > 1) {
85 $data = '
86 <script type="text/javascript" src="'.generer_url_public('multilang.js', 'lang='.$GLOBALS['spip_lang']).'"></script>
87 ';
88 }
89 return $data;
90 }
91
92 /**
93 * Insertion dans le pipeline formulaire_traiter (SPIP)
94 * On purge le cache js à chaque changement de la config de langue
95 *
96 * @param $flux array
97 * Le contexte du pipeline
98 * @return $flux array
99 * Le contexte du pipeline modifié
100 */
101 function multilang_formulaire_traiter($flux) {
102 if ($flux['args']['form'] == 'configurer_multilinguisme') {
103 include_spip('inc/invalideur');
104 $rep_js = _DIR_VAR.'cache-js/';
105 $rep_css = _DIR_VAR.'cache-css/';
106 purger_repertoire($rep_js);
107 purger_repertoire($rep_css);
108 suivre_invalideur('1');
109 }
110 return $flux;
111 }
112
113 /**
114 * Insertion dans le pipeline affichage_final (SPIP)
115 *
116 * Sur la page crayons.js, on insère également notre javascript pour être utilisable
117 * dans les crayons
118 *
119 * @param string $flux Le contenu de la page
120 * @return string $flux Le contenu de la page modifiée
121 */
122 function multilang_affichage_final($flux) {
123 if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'crayons.js'
124 and (count(explode(',', $GLOBALS['meta']['langues_multilingue'])) > 1)) {
125 if (!function_exists('lire_config')) {
126 include_spip('inc/config');
127 }
128 $config = lire_config('multilang', array());
129
130 /**
131 * On n'utilise multilang que si l'espace public est activé ainsi que les crayons
132 */
133 if (($config['multilang_public'] == 'on') && ($config['multilang_crayons'] == 'on')) {
134 unset($config['multilang_public']);
135 unset($config['multilang_crayons']);
136 $root = array();
137
138 if (isset($config['siteconfig']) && $config['siteconfig']) {
139 $root[] = 'input[type=hidden][name*=name_][value|=meta-valeur]';
140 unset($config['siteconfig']);
141 }
142
143 foreach ($config as $conf => $val) {
144 if ($conf == 'gis') {
145 // Les points gis sont traités bizarrement dans les crayons qui enlèvent
146 // purement et simplement leur 's'
147 $conf = 'gi';
148 }
149 if ($val == 'on') {
150 $root[] = 'input[type=hidden][name*=name_][value|='.$conf.']:not(input[value|='.$conf.'-logo]):not(input[value|='.$conf.'-vignette]):not(input[value|='.$conf.'-fichier])';
151 unset($config[$conf]);
152 }
153 }
154 $texte = '
155 var crayons_multilang_init = function(){
156 if(typeof(multilang_init_lang) == "function"){
157 var crayons_root = ".formulaire_spip:has('.implode(',', $root).')",
158 fields_selector = "textarea,input:text:not(input.date,input.heure,*.nomulti)",
159 forms_selector = "form[class!=\'form_upload\'][class!=\'form_upload_icon\']",
160 root_opt = "form:has(.multilang)",
161 fields_selector_opt = ".multilang";
162 multilang_init_lang({fields:fields_selector,fields_opt:fields_selector_opt,root:crayons_root,root_opt:root_opt,forms:forms_selector,init_done:false});
163 }
164 }
165
166 cQuery(document).ready(function(){
167 if(typeof onAjaxLoad == "function") onAjaxLoad(crayons_multilang_init);
168 crayons_multilang_init();
169 });';
170 $flux .= $texte;
171 }
172 }
173 return $flux;
174 }