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