1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | This file is part of Salvatore, the translation robot of Trad-lang (SPIP) |
---|
5 | |
---|
6 | Salvatore is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | Trad-Lang is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with Trad-Lang; if not, write to the Free Software |
---|
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | |
---|
20 | Copyright 2003-2015 |
---|
21 | Florent Jugla <florent.jugla@eledo.com>, |
---|
22 | Philippe Riviere <fil@rezo.net>, |
---|
23 | Chryjs <chryjs!@!free!.!fr>, |
---|
24 | kent1 <kent1@arscenic.info> |
---|
25 | */ |
---|
26 | |
---|
27 | |
---|
28 | require_once(dirname(__FILE__).'/inc_tradlang.php'); |
---|
29 | $tmp=_SALVATORE_TMP; |
---|
30 | $invalider = $die_message = false; |
---|
31 | |
---|
32 | /* modules de SPIP requis - il y a surement plus propre... */ |
---|
33 | include_spip('base/abstract_sql'); |
---|
34 | include_spip('inc/tradlang_verifier_langue_base'); |
---|
35 | include_spip('inc/tradlang_verifier_bilans'); |
---|
36 | include_spip('inc/charsets'); |
---|
37 | include_spip('inc/filtres'); |
---|
38 | include_spip('inc/texte'); |
---|
39 | include_spip('inc/xml'); |
---|
40 | include_spip('inc/lang_liste'); |
---|
41 | include_spip('inc/session'); |
---|
42 | |
---|
43 | if (defined('_ID_AUTEUR_SALVATORE') and is_numeric(_ID_AUTEUR_SALVATORE)) { |
---|
44 | $GLOBALS['visiteur_session']['id_auteur'] = _ID_AUTEUR_SALVATORE; |
---|
45 | } |
---|
46 | |
---|
47 | $url_site = $GLOBALS['meta']['adresse_site']; |
---|
48 | |
---|
49 | /* MAIN ***********************************************************************/ |
---|
50 | |
---|
51 | trad_log("\n=======================================\nLECTEUR\nPrend les fichiers de reference dans sa copie locale et met a jour la base de donnees\n=======================================\n"); |
---|
52 | |
---|
53 | $liste_sources=charger_fichier_traductions(); // chargement du fichier traductions.txt |
---|
54 | |
---|
55 | foreach ($liste_sources as $source) { |
---|
56 | trad_log('==== Module '.$source[1]." =======================================\n"); |
---|
57 | $liste_fic_lang= glob($tmp.$source[1] . '/' . $source[1] . '_*.php'); |
---|
58 | $import = true; |
---|
59 | /** |
---|
60 | * On test ici si le fichier est géré par un autre salvatore |
---|
61 | * Si oui on empeche son import en le signifiant |
---|
62 | */ |
---|
63 | if (file_exists($xml = $tmp.$source[1] . '/'.$source[1] . '.xml')) { |
---|
64 | $xml_content = spip_xml_load($xml); |
---|
65 | if (is_array($xml_content)) { |
---|
66 | spip_xml_match_nodes('/^traduction/', $xml_content, $matches); |
---|
67 | $test = '<'.key($matches).'>'; |
---|
68 | $url = extraire_attribut($test, 'url'); |
---|
69 | if ($url && (str_replace(array('http://','https://'),'',$url) != str_replace(array('http://','https://'),'',$url_site))) { |
---|
70 | $import = false; |
---|
71 | $sujet = 'Lecteur : Erreur sur '.$source[1]; |
---|
72 | $corps = "\nErreur : import impossible, le fichier est traduit autre part : $url\n\n"; |
---|
73 | trad_sendmail($sujet, $corps); |
---|
74 | trad_log("\nErreur : import impossible, le fichier est traduit autre part : $url\n\n"); |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | if ($import) { |
---|
79 | /** |
---|
80 | * on doit absolument charger la langue principale en premier (a cause des MD5) |
---|
81 | */ |
---|
82 | $fic_lang_principal=$tmp.$source[1].'/'.$source[1].'_'.$source[2].'.php'; |
---|
83 | |
---|
84 | /** |
---|
85 | * On regarde quelle est la date de dernière modification du fichier de langue principale |
---|
86 | */ |
---|
87 | $last_update = filemtime($fic_lang_principal); |
---|
88 | if ($last_update > strtotime('-1 day')) { |
---|
89 | $priorite = ''; |
---|
90 | $modifs = 0; |
---|
91 | if (defined('_TRAD_PRIORITE_DEFAUT')) { |
---|
92 | $priorite = _TRAD_PRIORITE_DEFAUT; |
---|
93 | } |
---|
94 | if (in_array($fic_lang_principal, $liste_fic_lang)) { |
---|
95 | $module = sql_fetsel('id_tradlang_module,lang_mere', 'spip_tradlang_modules', 'module = '.sql_quote($source[1])); |
---|
96 | $id_module = $module['id_tradlang_module']; |
---|
97 | /** |
---|
98 | * Si le module n'existe pas... on le crée |
---|
99 | */ |
---|
100 | if (!intval($id_module)) { |
---|
101 | $id_module = sql_insertq('spip_tradlang_modules', array('module' => $source[1], 'nom_mod' => $source[1], 'lang_prefix' => $source[1], 'lang_mere' => $source[2], 'priorite' => $priorite)); |
---|
102 | } elseif ($module['lang_mere'] != $source[2]) { |
---|
103 | /** |
---|
104 | * Si la langue mere a changée, on la modifie |
---|
105 | */ |
---|
106 | sql_updateq('spip_tradlang_modules', array('lang_mere' => $source[2]), 'id_tradlang_module = ' . intval($id_module)); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * Si $id_module n'est pas un entier => on tue le script |
---|
111 | */ |
---|
112 | if (!intval($id_module)) { |
---|
113 | $sujet = 'Lecteur : Erreur sur ' . $source[1]; |
---|
114 | $corps = "Le module n'est pas un entier"; |
---|
115 | trad_sendmail($sujet, $corps); |
---|
116 | $die_message = "Le module n'est pas un entier"; |
---|
117 | break; |
---|
118 | } |
---|
119 | $liste_id_orig = array(); |
---|
120 | $modifs = import_module_spip($source, $fic_lang_principal, $liste_id_orig, 1, $id_module); |
---|
121 | $langues_a_jour = array(); |
---|
122 | foreach ($liste_fic_lang as $f) { |
---|
123 | if ($f != $fic_lang_principal) { |
---|
124 | import_module_spip($source, $f, $liste_id_orig, 0, $id_module); |
---|
125 | $fich = str_replace($source[1], '', basename($f, '.php')); |
---|
126 | list(,$lang) = explode('_', $fich, 2); |
---|
127 | if (($modifs > 0) and function_exists('inc_tradlang_verifier_langue_base_dist')) { |
---|
128 | inc_tradlang_verifier_langue_base_dist($source[1], $lang); |
---|
129 | trad_log('|-- Synchro de la langue ' . $lang . ' pour le module ' . $source[1]."\n"); |
---|
130 | } elseif (!function_exists('inc_tradlang_verifier_langue_base_dist')) { |
---|
131 | trad_log("|-- Fonction de synchro inexistante\n"); |
---|
132 | } |
---|
133 | $langues_a_jour[] = $lang; |
---|
134 | } |
---|
135 | } |
---|
136 | /** |
---|
137 | * On s'occupe des langues en base sans fichier |
---|
138 | * s'il y a eu au moins une modif et que l'on peut faire la synchro |
---|
139 | */ |
---|
140 | if (($modifs > 0) and function_exists('inc_tradlang_verifier_langue_base_dist')) { |
---|
141 | $langues_pas_a_jour = sql_allfetsel('lang', 'spip_tradlangs', 'id_tradlang_module = ' . intval($id_module) . ' AND ' . sql_in('lang', $langues_a_jour, 'NOT'), 'lang'); |
---|
142 | foreach ($langues_pas_a_jour as $langue_a_jour) { |
---|
143 | inc_tradlang_verifier_langue_base_dist($source[1], $langue_a_jour['lang']); |
---|
144 | trad_log('|-- Synchro de la langue non exportée en fichier '. $langue_a_jour['lang'] . ' pour le module ' . $source[1]."\n"); |
---|
145 | } |
---|
146 | } |
---|
147 | $invalider = true; |
---|
148 | trad_log("|\n"); |
---|
149 | unset($langues_a_jour,$langues_pas_a_jour); |
---|
150 | } else { |
---|
151 | $sujet = 'Lecteur : Erreur sur '.$source[1]; |
---|
152 | $corps = '|-- Pas de fichier lang ' . $source[2] . ' pour le module ' . $source[1] . " : import impossible pour ce module\n"; |
---|
153 | trad_sendmail($sujet, $corps); |
---|
154 | $die_message = '|-- Pas de fichier lang '.$source[2] . ' pour le module ' . $source[1] . " : import impossible pour ce module\n"; |
---|
155 | break; |
---|
156 | } |
---|
157 | } else { |
---|
158 | trad_log("On ne modifie rien car l'original a été modifié il y a longtemps\n"); |
---|
159 | /** |
---|
160 | * Le fichier d'origine n'a pas été modifié |
---|
161 | * Mais on a peut être de nouvelles langues |
---|
162 | */ |
---|
163 | $langues = $langues_a_ajouter = array(); |
---|
164 | $langues_en_base = sql_allfetsel('lang', 'spip_tradlangs', 'module = ' . sql_quote($source[1]), 'lang'); |
---|
165 | foreach ($langues_en_base as $langue) { |
---|
166 | $langues[] = $langue['lang']; |
---|
167 | } |
---|
168 | foreach ($liste_fic_lang as $f) { |
---|
169 | $fich = str_replace($source[1], '', basename($f, '.php')); |
---|
170 | list(,$lang) = explode('_', $fich, 2); |
---|
171 | |
---|
172 | if (!in_array($lang, $langues)) { |
---|
173 | $langues_a_ajouter[] = array('lang' => $lang, 'fichier' => $f); |
---|
174 | } |
---|
175 | } |
---|
176 | if (count($langues_a_ajouter) > 0) { |
---|
177 | trad_log('On a ' . count($langues_a_ajouter) . " nouvelle(s) langue(s) à insérer \n"); |
---|
178 | $module = sql_fetsel('*', 'spip_tradlang_modules', 'module = ' . sql_quote($source[1])); |
---|
179 | $id_module = $module['id_tradlang_module']; |
---|
180 | $liste_id_orig = array(); |
---|
181 | $modifs = import_module_spip($source, $fic_lang_principal, $liste_id_orig, 1, $id_module); |
---|
182 | foreach ($langues_a_ajouter as $fichier) { |
---|
183 | import_module_spip($source, $fichier['fichier'], $liste_id_orig, 0, $id_module); |
---|
184 | if (($modifs > 0) && function_exists('inc_tradlang_verifier_langue_base_dist')) { |
---|
185 | inc_tradlang_verifier_langue_base_dist($source[1], $lang); |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | trad_log("\n"); |
---|
190 | } |
---|
191 | // Mise à jour des bilans |
---|
192 | if (function_exists('inc_tradlang_verifier_bilans_dist')) { |
---|
193 | trad_log('Création ou MAJ des bilans de ' . $source[1] . "\n\n"); |
---|
194 | inc_tradlang_verifier_bilans_dist($source[1], $source[2], false); |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | if ($invalider) { |
---|
200 | include_spip('inc/invalideur'); |
---|
201 | suivre_invalideur('1'); |
---|
202 | } |
---|
203 | |
---|
204 | if ($die_message) { |
---|
205 | die("$die_message"); |
---|
206 | } |
---|
207 | return 0; |
---|
208 | |
---|
209 | /** |
---|
210 | * Import d'un fichier de langue dans la base |
---|
211 | * |
---|
212 | * @param array $source |
---|
213 | * @param string $module |
---|
214 | * @param array $liste_id_orig |
---|
215 | * @param int $orig 1 signifie que c'est la langue originale |
---|
216 | * @param int $id_module |
---|
217 | * @return string |
---|
218 | */ |
---|
219 | function import_module_spip($source = array(), $module = '', &$liste_id_orig, $orig = null, $id_module) { |
---|
220 | trad_log("!\n+ Import de $module\n"); |
---|
221 | $memtrad = $GLOBALS['idx_lang'] = 'i18n_'.crc32($module).'_tmp'; |
---|
222 | $GLOBALS[$GLOBALS['idx_lang']] = null; |
---|
223 | $comm_fic_lang = charger_comm_fichier_langue($module); |
---|
224 | include $module; |
---|
225 | |
---|
226 | $str_lang = $GLOBALS[$memtrad]; // on a vu certains fichiers faire des betises et modifier idx_lang |
---|
227 | |
---|
228 | if (is_null($str_lang)) { |
---|
229 | trad_log("Erreur, fichier $module mal forme\n"); |
---|
230 | $sujet = 'Lecteur : Erreur sur '.$module; |
---|
231 | $corps = "Erreur, fichier $module mal forme\n"; |
---|
232 | trad_sendmail($sujet, $corps); |
---|
233 | return false; |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * Nettoyer le contenu de ses <MODIF>,<NEW> et <PLUS_UTILISE> |
---|
238 | * Ces chaines sont utilisées comme statut |
---|
239 | */ |
---|
240 | $status = array(); |
---|
241 | |
---|
242 | foreach ($str_lang as $id => $v) { |
---|
243 | if (1 == $orig) { |
---|
244 | $status[$id] = 'OK'; |
---|
245 | } else if (preg_match(',^<(MODIF|NEW|PLUS_UTILISE)>,US', $v, $r)) { |
---|
246 | $str_lang[$id] = preg_replace(',^(<(MODIF|NEW|PLUS_UTILISE)>)+,US', '', $v); |
---|
247 | $status[$id] = $r[1]; |
---|
248 | } else { |
---|
249 | $status[$id] = 'OK'; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | $fich = str_replace($source[1], '', basename($module, '.php')); |
---|
254 | $mod = $source[1]; |
---|
255 | list(,$lang) = explode('_', $fich, 2); |
---|
256 | |
---|
257 | if (!array_key_exists($lang, $GLOBALS['codes_langues'])) { |
---|
258 | trad_log("!-- Attention : La langue $lang n'existe pas dans les langues possibles - $mod \n"); |
---|
259 | } else { |
---|
260 | if (1==$orig) { |
---|
261 | $res = spip_query("SELECT id, str, md5 FROM spip_tradlangs WHERE module='".$source[1]."' and lang='".$lang."' AND statut != 'attic' "); |
---|
262 | } else { |
---|
263 | $res = spip_query("SELECT id, str, md5 FROM spip_tradlangs WHERE module='".$source[1]."' and lang='".$lang."' and statut!='MODIF' "); |
---|
264 | } |
---|
265 | $nb = sql_count($res); |
---|
266 | if ($nb > 0) { |
---|
267 | trad_log("!-- Fichier de langue $lang du module $mod deja inclus dans la base\n"); |
---|
268 | } |
---|
269 | |
---|
270 | $ajoutees = $inchangees = $supprimees = $modifiees = $ignorees = $recuperees = 0; |
---|
271 | |
---|
272 | /** |
---|
273 | * Si la langue est deja dans la base, on ne l'ecrase que s'il s'agit |
---|
274 | * de la langue source |
---|
275 | */ |
---|
276 | if ($nb == 0 or $orig == 1) { |
---|
277 | $typo = (in_array($lang, array('eo','fr','cpf')) || strncmp($lang, 'fr_', 3) == 0) ? 'fr' : 'en'; |
---|
278 | $typographie = charger_fonction($typo, 'typographie'); |
---|
279 | // La liste de ce qui existe deja |
---|
280 | $existant = $str_existant = array(); |
---|
281 | while ($t = spip_fetch_array($res)) { |
---|
282 | $existant[$t['id']] = $t['md5']; |
---|
283 | $str_existant[$t['id']] = $t['str']; |
---|
284 | } |
---|
285 | |
---|
286 | $bigwhere = 'module = ' . sql_quote($source[1]) . ' AND lang = '.sql_quote($lang); |
---|
287 | |
---|
288 | include_spip('action/editer_tradlang'); |
---|
289 | // Dans ce qui arrive, il y a 4 cas : |
---|
290 | foreach (array_unique(array_merge(array_keys($existant), array_keys($str_lang))) as $id) { |
---|
291 | $comm=(isset($comm_fic_lang[$id])) ? $comm_fic_lang[$id] : ''; |
---|
292 | // * chaine neuve |
---|
293 | if (isset($str_lang[$id]) and !isset($existant[$id])) { |
---|
294 | if ($orig) { |
---|
295 | $md5 = md5($str_lang[$id]); |
---|
296 | } else if (!isset($liste_id_orig[$id])) { |
---|
297 | trad_log("!-- Chaine $id inconnue dans la langue principale\n"); |
---|
298 | $ignorees++; |
---|
299 | } else { |
---|
300 | $md5 = $liste_id_orig[$id]; |
---|
301 | } |
---|
302 | |
---|
303 | if (isset($md5)) { |
---|
304 | /** |
---|
305 | * On enlève les sauts de lignes windows pour des sauts de ligne linux |
---|
306 | */ |
---|
307 | |
---|
308 | $str_lang[$id] = str_replace("\r\n", "\n", $str_lang[$id]); |
---|
309 | |
---|
310 | /** |
---|
311 | * protection dans les balises genre <a href="..." ou <img src="..." |
---|
312 | * cf inc/filtres |
---|
313 | */ |
---|
314 | if (preg_match_all(_TYPO_BALISE, $str_lang[$id], $regs, PREG_SET_ORDER)) { |
---|
315 | foreach ($regs as $reg) { |
---|
316 | $insert = $reg[0]; |
---|
317 | // hack: on transforme les caracteres a proteger en les remplacant |
---|
318 | // par des caracteres "illegaux". (cf corriger_caracteres()) |
---|
319 | $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
---|
320 | $str_lang[$id] = str_replace($reg[0], $insert, $str_lang[$id]); |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * Protéger le contenu des balises <html> <code> <cadre> <frame> <tt> <pre> |
---|
326 | */ |
---|
327 | define('_PROTEGE_BLOCS_HTML', ',<(html|code|cadre|pre|tt)(\s[^>]*)?>(.*)</\1>,UimsS'); |
---|
328 | if ((strpos($str_lang[$id], '<') !== false) and preg_match_all(_PROTEGE_BLOCS_HTML, $str_lang[$id], $matches, PREG_SET_ORDER)) { |
---|
329 | foreach ($matches as $reg) { |
---|
330 | $insert = $reg[0]; |
---|
331 | // hack: on transforme les caracteres a proteger en les remplacant |
---|
332 | // par des caracteres "illegaux". (cf corriger_caracteres()) |
---|
333 | $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
---|
334 | $str_lang[$id] = str_replace($reg[0], $insert, $str_lang[$id]); |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | /** |
---|
339 | * On applique la typographie de la langue |
---|
340 | */ |
---|
341 | $str_lang[$id] = $typographie($str_lang[$id]); |
---|
342 | |
---|
343 | /** |
---|
344 | * On remet les caractères normaux sur les caractères illégaux |
---|
345 | */ |
---|
346 | $str_lang[$id] = strtr($str_lang[$id], _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
---|
347 | |
---|
348 | $str_lang[$id] = unicode_to_utf_8(html_entity_decode(preg_replace('/&([lg]t;)/S', '&\1', $str_lang[$id]), ENT_NOQUOTES, 'utf-8')); |
---|
349 | |
---|
350 | /** |
---|
351 | * Calcul du nouveau md5 |
---|
352 | */ |
---|
353 | $md5 = md5($str_lang[$id]); |
---|
354 | |
---|
355 | /** |
---|
356 | * Si le commentaire est un statut et que l'on ne traite pas le fichier de langue mère |
---|
357 | * On vire le commentaire et met son contenu comme statut |
---|
358 | */ |
---|
359 | if (in_array($comm, array('NEW','OK','MODIF','MODI')) && $orig != 1) { |
---|
360 | if ($comm == 'MODI') { |
---|
361 | $comm = 'MODIF'; |
---|
362 | } |
---|
363 | $status[$id] = $comm; |
---|
364 | $comm = ''; |
---|
365 | } else if ((strlen($comm) > 1) && preg_match('/(.*?)(NEW|OK|MODIF)(.*?)/', $comm, $matches)) { |
---|
366 | if ($orig != 1) { |
---|
367 | $status[$id] = $matches[2]; |
---|
368 | } |
---|
369 | $comm = preg_replace('/(NEW|OK|MODIF)/', '', $comm); |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | * On génère un titre |
---|
374 | */ |
---|
375 | $titre = $id.' : '.$source[1].' - '.$lang; |
---|
376 | |
---|
377 | $data = array('id_tradlang_module' => $id_module,'titre' => $titre,'module' =>$source[1],'lang' =>$lang,'id'=>$id,'str'=>$str_lang[$id],'comm' => $comm,'md5'=>$md5,'statut'=>$status[$id]); |
---|
378 | $id_tradlang = sql_insertq('spip_tradlangs', $data); |
---|
379 | |
---|
380 | /** |
---|
381 | * L'identifiant de la chaîne de langue a peut être déjà été utilisé puis mis au grenier |
---|
382 | * On le récupère donc |
---|
383 | */ |
---|
384 | if (!$id_tradlang) { |
---|
385 | $tradlang = sql_fetsel('*', 'spip_tradlangs', 'id = ' . sql_quote($id) . ' AND module = ' . sql_quote($source[1]) . 'AND lang = ' . sql_quote($lang) . ' AND statut = ' . sql_quote('attic')); |
---|
386 | if (is_array($tradlang)) { |
---|
387 | $id_tradlang = intval($tradlang['id_tradlang']); |
---|
388 | trad_log("\n Recuperation d'une chaine de statut ATTIC \n"); |
---|
389 | sql_updateq('spip_tradlangs', $data, 'id_tradlang='.$id_tradlang); |
---|
390 | $trads = sql_allfetsel('id_tradlang', 'spip_tradlangs', 'id = ' . sql_quote($id) . ' AND module = ' . sql_quote($source[1]) . 'AND lang != ' . sql_quote($lang).' AND statut = ' . sql_quote('attic')); |
---|
391 | $maj = array('statut' => 'MODIF'); |
---|
392 | foreach ($trads as $trad) { |
---|
393 | trad_log("\n Changement d'une trad dans ATTIC \n"); |
---|
394 | sql_updateq('spip_tradlangs', $maj, 'id_tradlang = ' . intval($trad['id_tradlang'])); |
---|
395 | } |
---|
396 | $recuperees++; |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | /** |
---|
401 | * Vérifier si une autre chaîne de langue était identique (str == str) |
---|
402 | * |
---|
403 | * Si oui, on sélectionne toutes les occurences existantes dans les autres langues et on les duplique |
---|
404 | */ |
---|
405 | $identique_module = sql_getfetsel('id', 'spip_tradlangs', 'module = ' . sql_quote($source[1]) . ' AND lang = ' . sql_quote($lang) . ' AND str = '.sql_quote($str_lang[$id])); |
---|
406 | if ($identique_module) { |
---|
407 | trad_log('La nouvelle chaine est une chaine dupliquée : '.$identique_module."\n"); |
---|
408 | $chaines_a_dupliquer = sql_allfetsel('*', 'spip_tradlangs', 'id = '.sql_quote($identique_module) . ' AND id_tradlang_module = ' . intval($id_module) . ' AND lang != '.sql_quote($lang)); |
---|
409 | foreach ($chaines_a_dupliquer as $chaine) { |
---|
410 | unset($chaine['id_tradlang']); |
---|
411 | unset($chaine['maj']); |
---|
412 | $chaine['id'] = $id; |
---|
413 | $chaine['titre'] = $id.' : '.$source[1].' - '.$chaine['lang']; |
---|
414 | $chaine['md5'] = md5($chaine['str']); |
---|
415 | $chaine['date_modif'] = date('Y-m-d H:i:s'); |
---|
416 | if ($chaine['statut'] == 'attic') { |
---|
417 | $chaine['statut'] = 'NEW'; |
---|
418 | } |
---|
419 | $nouvelle_chaine = sql_insertq('spip_tradlangs', $chaine); |
---|
420 | trad_log('Ajout de la version ' . $chaine['lang'] . ' - ' . $nouvelle_chaine . "\n"); |
---|
421 | } |
---|
422 | } |
---|
423 | $ajoutees++; |
---|
424 | } |
---|
425 | } elseif (isset($str_lang[$id]) and isset($existant[$id])) { |
---|
426 | // * chaine existante |
---|
427 | // * identique ? => NOOP |
---|
428 | /** |
---|
429 | * On enlève les sauts de lignes windows pour des sauts de ligne linux |
---|
430 | */ |
---|
431 | $str_lang[$id] = str_replace("\r\n", "\n", $str_lang[$id]); |
---|
432 | |
---|
433 | /** |
---|
434 | * protection dans les balises genre <a href="..." ou <img src="..." |
---|
435 | * cf inc/filtres |
---|
436 | */ |
---|
437 | if (preg_match_all(_TYPO_BALISE, $str_lang[$id], $regs, PREG_SET_ORDER)) { |
---|
438 | foreach ($regs as $reg) { |
---|
439 | $insert = $reg[0]; |
---|
440 | // hack: on transforme les caracteres a proteger en les remplacant |
---|
441 | // par des caracteres "illegaux". (cf corriger_caracteres()) |
---|
442 | $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
---|
443 | $str_lang[$id] = str_replace($reg[0], $insert, $str_lang[$id]); |
---|
444 | } |
---|
445 | } |
---|
446 | |
---|
447 | /** |
---|
448 | * Protéger le contenu des balises <html> <code> <cadre> <frame> <tt> <pre> |
---|
449 | */ |
---|
450 | define('_PROTEGE_BLOCS_HTML', ',<(html|code|cadre|pre|tt)(\s[^>]*)?>(.*)</\1>,UimsS'); |
---|
451 | if ((strpos($str_lang[$id], '<') !== false) and preg_match_all(_PROTEGE_BLOCS_HTML, $str_lang[$id], $matches, PREG_SET_ORDER)) { |
---|
452 | foreach ($matches as $reg) { |
---|
453 | $insert = $reg[0]; |
---|
454 | // hack: on transforme les caracteres a proteger en les remplacant |
---|
455 | // par des caracteres "illegaux". (cf corriger_caracteres()) |
---|
456 | $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
---|
457 | $str_lang[$id] = str_replace($reg[0], $insert, $str_lang[$id]); |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | /** |
---|
462 | * On applique la typographie de la langue |
---|
463 | */ |
---|
464 | $str_lang[$id] = $typographie($str_lang[$id]); |
---|
465 | |
---|
466 | /** |
---|
467 | * On remet les caractères normaux sur les caractères illégaux |
---|
468 | */ |
---|
469 | $str_lang[$id] = strtr($str_lang[$id], _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
---|
470 | |
---|
471 | $str_lang[$id] = unicode_to_utf_8(html_entity_decode(preg_replace('/&([lg]t;)/S', '&\1', $str_lang[$id]), ENT_NOQUOTES, 'utf-8')); |
---|
472 | |
---|
473 | /** |
---|
474 | * Calcul du nouveau md5 |
---|
475 | */ |
---|
476 | $md5 = md5($str_lang[$id]); |
---|
477 | if ($md5 == $existant[$id]) { |
---|
478 | $inchangees++; |
---|
479 | } else { |
---|
480 | // * modifiee ? => UPDATE |
---|
481 | trad_log(md5($str_lang[$id]) . ' !- ' . md5($str_existant[$id])."\n"); |
---|
482 | // modifier la chaine |
---|
483 | $modifs = array( |
---|
484 | 'str' => $str_lang[$id], |
---|
485 | 'md5' => ($orig ? $md5 : $existant[$id]), |
---|
486 | 'statut' => ($orig ? 'OK' : ''), |
---|
487 | 'comm' => $comm, |
---|
488 | ); |
---|
489 | $id_tradlang = sql_getfetsel('id_tradlang', 'spip_tradlangs', "$bigwhere AND id = " . sql_quote($id)); |
---|
490 | $test = tradlang_set($id_tradlang, $modifs); |
---|
491 | |
---|
492 | /** |
---|
493 | * signaler le statut MODIF de ses traductions OK |
---|
494 | * update des str de ses traductions NEW |
---|
495 | */ |
---|
496 | if ($orig and ($orig != 0)) { |
---|
497 | spip_query( |
---|
498 | "UPDATE spip_tradlangs SET statut='MODIF' WHERE module='".$source[1] |
---|
499 | ."' AND id="._q($id) |
---|
500 | .' AND md5 != ' . _q($md5) |
---|
501 | .' AND lang != ' . _q($lang) |
---|
502 | ." AND statut!='NEW'" |
---|
503 | ); |
---|
504 | } |
---|
505 | spip_query( |
---|
506 | 'UPDATE spip_tradlangs SET str = ' .sql_quote($str_lang[$id])." |
---|
507 | WHERE module='".$source[1] |
---|
508 | ."' AND id="._q($id) |
---|
509 | .' AND md5 != '._q($md5) |
---|
510 | .' AND lang != '._q($lang) |
---|
511 | ." AND statut = 'NEW'" |
---|
512 | ); |
---|
513 | $modifiees++; |
---|
514 | } |
---|
515 | } elseif (!isset($str_lang[$id]) and isset($existant[$id])) { |
---|
516 | // * chaine supprimee |
---|
517 | // mettre au grenier |
---|
518 | spip_query("UPDATE spip_tradlangs SET statut='attic' WHERE id="._q($id).' AND module = ' . _q($source[1])); |
---|
519 | $supprimees++; |
---|
520 | } |
---|
521 | |
---|
522 | if ($orig and isset($str_lang[$id])) { |
---|
523 | $liste_id_orig[$id] = md5($str_lang[$id]); |
---|
524 | } |
---|
525 | } |
---|
526 | trad_log('!-- module ' . $source[1] . ", $lang : $modifiees modifiees, $ajoutees ajoutees, $supprimees supprimees, $recuperees recuperees, $ignorees ignorees, $inchangees inchangees\n"); |
---|
527 | } |
---|
528 | } |
---|
529 | unset($liste_id_orig,$str_lang,$GLOBALS[$GLOBALS['idx_lang']]); |
---|
530 | return $ajoutees + $supprimees + $modifiees; |
---|
531 | } |
---|
532 | |
---|
533 | /** |
---|
534 | * Chargement des commentaires de fichier de langue |
---|
535 | * Le fichier est chargé en mode texte pour récupérer les commentaires dans lesquels sont situés les statuts |
---|
536 | * |
---|
537 | * @param string $f Le chemin du fichier de langue |
---|
538 | * @return array $liste_trad Un tableau id/chaine |
---|
539 | */ |
---|
540 | function charger_comm_fichier_langue($f) { |
---|
541 | |
---|
542 | $contenu=file_get_contents($f); |
---|
543 | |
---|
544 | $tab=preg_split("/\r\n|\n\r|;\n|\n\/\/|\(\n|\n\);\n|\'\,\n|\n[\s\t]*(\')|\/\/[\s\t][0-9A-Z]\n[\s\t](\')/", $contenu, '-1', PREG_SPLIT_NO_EMPTY); |
---|
545 | |
---|
546 | $liste_trad=array(); |
---|
547 | reset($tab); |
---|
548 | |
---|
549 | while (list(,$ligne) = each($tab)) { |
---|
550 | $ligne = str_replace("\'", '', $ligne); |
---|
551 | if (strlen($ligne)>0) { |
---|
552 | if (preg_match("/(.*?)\'[\s\t]*=>[\s\t]*\'(.*?)\'[\s\t]*,{0,1}[\s\t]*(#.*)?/ms", $ligne, $matches)) { |
---|
553 | if (isset($matches[1]) and isset($matches[3]) and strlen(trim($matches[3])) > 0) { |
---|
554 | list(,$comm) = explode('#', $matches[3]); |
---|
555 | $liste_trad[$matches[1]] = trim($comm); |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | } |
---|
560 | reset($liste_trad); |
---|
561 | return $liste_trad; |
---|
562 | } |
---|