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-2013 |
---|
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 | // securite : en ligne de commande c tout |
---|
28 | if (isset($_SERVER['SERVER_NAME'])) { |
---|
29 | die('en ligne de commande svp'); |
---|
30 | } |
---|
31 | |
---|
32 | // modules demandes en ligne de commande |
---|
33 | //$GLOBALS['modules'] = $_SERVER['argv']; |
---|
34 | //array_shift($GLOBALS['modules']); |
---|
35 | |
---|
36 | ini_set('memory_limit', '50M'); |
---|
37 | |
---|
38 | define('_DEBUG_TRAD_LANG', 1); // undef si on ne veut pas de messages |
---|
39 | define('_SALVATORE', './'); |
---|
40 | define('_SALVATORE_TRADUCTION', './traductions/'); |
---|
41 | if (!defined('_DIR_RESTREINT_ABS')) { |
---|
42 | define('_DIR_RESTREINT_ABS', '../ecrire/'); |
---|
43 | } |
---|
44 | define('_DIR_RACINE', '../'); |
---|
45 | |
---|
46 | // eviter les notice inutiles si les erreurs sont a un niveau (E_ALL) |
---|
47 | // lors de l'inclusion des modules SPIP |
---|
48 | $GLOBALS['HTTP_USER_AGENT']='shell'; |
---|
49 | $_SERVER['QUERY_STRING'] = ''; |
---|
50 | $_SERVER['HTTP_HOST'] = ''; |
---|
51 | $_SERVER['REQUEST_METHOD'] = ''; |
---|
52 | $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr_fr'; |
---|
53 | $GLOBALS['ip'] = getHostByName(getHostName()); |
---|
54 | $GLOBALS['SERVER_SOFTWARE'] = $_SERVER['SERVER_SOFTWARE'] = 'system'; |
---|
55 | $GLOBALS['REQUEST_METHOD']='$'; |
---|
56 | $GLOBALS['idx_lang']=0; |
---|
57 | |
---|
58 | /* Prepare l'inclusion des modules SPIP */ |
---|
59 | require_once(_DIR_RESTREINT_ABS.'inc_version.php'); |
---|
60 | |
---|
61 | |
---|
62 | /* fin inclusion */ |
---|
63 | |
---|
64 | define('_SALVATORE_TMP', _SALVATORE.'tmp/'); |
---|
65 | if (!is_dir(_SALVATORE_TMP)) { |
---|
66 | die("\nErreur : le répertoire "._SALVATORE_TMP." n'existe pas\n\n"); |
---|
67 | } |
---|
68 | |
---|
69 | // |
---|
70 | // chargement du fichier traductions.txt |
---|
71 | // Construit une liste de modules avec pour chacun un tableau compose de : 0 chemin, 1 nom, 2 langue principale |
---|
72 | // |
---|
73 | function charger_fichier_traductions($chemin = _SALVATORE_TRADUCTION, $trad_list = 'traductions.txt') { |
---|
74 | |
---|
75 | if (!is_dir(_SALVATORE_TRADUCTION)) { |
---|
76 | die('Le répertoire ' . _SALVATORE_TRADUCTION . " n'existe pas !!!\n\n"); |
---|
77 | } |
---|
78 | |
---|
79 | if (!file_exists(_SALVATORE_TRADUCTION. $trad_list)) { |
---|
80 | die('Le fichier ' . _SALVATORE_TRADUCTION . "$trad_list n'existe pas !!!\n\n"); |
---|
81 | } |
---|
82 | |
---|
83 | $contenu=file_get_contents($chemin.$trad_list); |
---|
84 | |
---|
85 | $contenu=preg_replace('/#.*/', '', $contenu); // supprimer les commentaires |
---|
86 | |
---|
87 | $tab=preg_split("/\r\n|\n\r|\n|\r/", $contenu); |
---|
88 | |
---|
89 | $liste_trad=array(); |
---|
90 | |
---|
91 | foreach ($tab as $ligne) { |
---|
92 | $liste = explode(';', trim($ligne)); |
---|
93 | if (!empty($liste[0])) { |
---|
94 | if (!isset($liste[1]) or empty($liste[1])) { |
---|
95 | $liste[1] = preg_replace('#.*/(.*)$#', '$1', $liste[0]); |
---|
96 | } |
---|
97 | if (!isset($liste[2]) or empty($liste[2])) { |
---|
98 | $liste[2] = 'fr'; |
---|
99 | } |
---|
100 | if (!count($GLOBALS['modules']) or in_array($liste[1], $GLOBALS['modules'])) { |
---|
101 | $liste_trad[]=$liste; |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | reset($liste_trad); |
---|
106 | return $liste_trad; |
---|
107 | } // liste_traductions |
---|
108 | |
---|
109 | // |
---|
110 | // Gere les logs |
---|
111 | // |
---|
112 | function trad_log($msg = '') { |
---|
113 | static $cnt; |
---|
114 | if (defined('_DEBUG_TRAD_LANG')) { |
---|
115 | echo $msg; |
---|
116 | $cnt++; |
---|
117 | } |
---|
118 | if ($cnt>10) { |
---|
119 | $cnt=0; |
---|
120 | flush(); |
---|
121 | } |
---|
122 | } // trad_log |
---|
123 | |
---|
124 | function trad_sendmail($sujet = 'Erreur', $corps = '') { |
---|
125 | if (defined('_EMAIL_ERREURS') and defined('_EMAIL_SALVATORE')) { |
---|
126 | $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
---|
127 | $destinataire = _EMAIL_ERREURS; |
---|
128 | $from = _EMAIL_SALVATORE; |
---|
129 | $envoyer_mail($destinataire, $sujet, $corps, $from); |
---|
130 | trad_log("Un email a été envoyé à l'adresse : "._EMAIL_ERREURS."\n"); |
---|
131 | } |
---|
132 | } |
---|