Changeset 96995 in spip-zone
- Timestamp:
- May 5, 2016, 6:16:46 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/convertisseur/trunk/exec/convertisseur.php
r93490 r96995 1 1 <?php 2 2 3 if (!defined("_ECRIRE_INC_VERSION")) return; 3 if (!defined('_ECRIRE_INC_VERSION')) { 4 return; 5 } 4 6 5 7 // ------------------------------- 6 8 // Main 7 9 // ------------------------------ 8 function exec_convertisseur() {9 include_spip( "inc/presentation");10 function exec_convertisseur() { 11 include_spip('inc/presentation'); 10 12 include_spip('inc/convertisseur'); 11 13 12 14 global $spip_lang_right; 13 15 global $log; 14 global $spip_version_branche 16 global $spip_version_branche; 15 17 16 18 global $conv_formats; 17 19 global $conv_functions_pre; 18 20 19 $conv_in = ""; 20 $conv_out = "";21 21 $conv_in = ''; 22 $conv_out = ''; 23 22 24 // convertir le charset ? 23 25 $convert_charset = (_request('convert_charset') == 'true'); 24 $GLOBALS['auteur_session']['prefs']['convertisseur_cvcharset'] = ($convert_charset) ? "oui" : "non";25 26 27 28 26 $GLOBALS['auteur_session']['prefs']['convertisseur_cvcharset'] = ($convert_charset) ? 'oui' : 'non'; 27 28 29 // check rights (utile ?) 30 global $connect_statut; 29 31 global $connect_toutes_rubriques; 30 if ($connect_statut != '0minirezo') { 31 32 echo $commencer_page(_T( "convertisseur:convertir_titre"),_T("convertisseur:convertir_titre"),_T("convertisseur:convertir_titre"));32 if ($connect_statut != '0minirezo') { 33 $commencer_page = charger_fonction('commencer_page', 'inc'); 34 echo $commencer_page(_T('convertisseur:convertir_titre'), _T('convertisseur:convertir_titre'), _T('convertisseur:convertir_titre')); 33 35 echo _T('avis_non_acces_page'); 34 36 fin_page(); … … 41 43 // --------------------------------------------------------------------- 42 44 45 $out = array(); 46 $format = ''; 43 47 if (isset($_POST['conv_in'])) { 44 48 45 49 $conv_textes = array(); 46 50 47 51 // upload ? 48 52 if (count($_FILES)) { … … 50 54 include_spip('inc/pclzip'); 51 55 include_spip('inc/invalideur'); # pour purger_repertoire() 52 foreach ($_FILES as $file) 53 if ($file['size']) { 54 chdir('..'); ## dirty 55 $a = deplacer_fichier_upload($file['tmp_name'], 56 'tmp/convertisseur.tmp'); 57 chdir('ecrire/'); 58 if (!$a) next; 59 60 // traitement specifique des .zip : on les 61 // eclate en autant de sources 62 if ($file['type'] == 'application/x-zip-compressed' 63 OR preg_match(',\.zip$,', $file['name'])) { 64 $zip = new PclZip('../tmp/convertisseur.tmp'); 65 if (!$list = $zip->listContent()) { 66 $log = 'erreur zip'; 67 } else { 68 $tmp = sous_repertoire(_DIR_TMP,'convertisseur'); 69 if ($tmp == _DIR_TMP) die('erreur creation repertoire temporaire'); 70 define('_tmp_dir', $tmp); 71 purger_repertoire($tmp); 72 // extraire dans le temporaire 73 $zip->extract( 74 PCLZIP_OPT_PATH, _tmp_dir, 75 PCLZIP_CB_PRE_EXTRACT, 76 'callback_admissibles' 77 ); 78 // lire les fichiers temporaires 79 foreach (glob(_tmp_dir.'*') as $f) { 80 if (lire_fichier($f, $tmp) 81 AND strlen(trim($tmp))) 82 $conv_textes[$f] = $tmp; 56 foreach ($_FILES as $file) { 57 if ($file['size']) { 58 chdir('..'); ## dirty 59 $a = deplacer_fichier_upload($file['tmp_name'], 60 'tmp/convertisseur.tmp'); 61 chdir('ecrire/'); 62 if (!$a) { 63 next; 64 } 65 66 // traitement specifique des .zip : on les 67 // eclate en autant de sources 68 if ($file['type'] == 'application/x-zip-compressed' 69 or preg_match(',\.zip$,', $file['name']) 70 ) { 71 $zip = new PclZip('../tmp/convertisseur.tmp'); 72 if (!$list = $zip->listContent()) { 73 $log = 'erreur zip'; 74 } else { 75 $tmp = sous_repertoire(_DIR_TMP, 'convertisseur'); 76 if ($tmp == _DIR_TMP) { 77 die('erreur creation repertoire temporaire'); 78 } 79 define('_tmp_dir', $tmp); 80 purger_repertoire($tmp); 81 // extraire dans le temporaire 82 $zip->extract( 83 PCLZIP_OPT_PATH, _tmp_dir, 84 PCLZIP_CB_PRE_EXTRACT, 85 'callback_admissibles' 86 ); 87 // lire les fichiers temporaires 88 foreach (glob(_tmp_dir . '*') as $f) { 89 if (lire_fichier($f, $tmp) 90 and strlen(trim($tmp)) 91 ) { 92 $conv_textes[$f] = $tmp; 93 } 94 } 83 95 } 96 } // fichier simple 97 elseif (lire_fichier('../tmp/convertisseur.tmp', $tmp)) { 98 $conv_textes[$file['name']] = $tmp; 84 99 } 85 100 } 86 87 // fichier simple88 else89 if (lire_fichier('../tmp/convertisseur.tmp', $tmp))90 $conv_textes[$file['name']] = $tmp;91 101 } 92 102 } 93 103 94 104 // Pas de fichier : on regarde le POST 95 if (!count($conv_textes)) 105 if (!count($conv_textes)) { 96 106 $conv_textes[] = _request('conv_in'); 107 } 97 108 98 109 if ($convert_charset) { 99 110 include_spip('inc/charsets'); 100 foreach ($conv_textes as $i => $t) 111 foreach ($conv_textes as $i => $t) { 101 112 $conv_textes[$i] = importer_charset($t, $charset); 113 } 102 114 } 103 115 … … 111 123 112 124 // Traitement et conversion de chaque texte soumis, dans un tableau 113 $out = array();114 125 foreach ($conv_textes as $f => $conv_in) { 115 126 $tmp = conversion_format($conv_in, $format); 116 127 $out[$f] = nettoyer_format($tmp); 117 if ($id_rubrique = intval(_request('id_parent'))) 128 if ($id_rubrique = intval(_request('id_parent'))) { 118 129 $id_article = inserer_conversion($out[$f], $id_rubrique, $f); 119 $article[$f] = $id_article; 120 } 121 if (is_string($conv_formats[$format])) 122 $conv_in = ""; // sur les formats extract, ne pas retourner texte intro (fichier binaire) 130 } 131 $article[$f] = $id_article; 132 } 133 if (is_string($conv_formats[$format])) { 134 $conv_in = ''; 135 } // sur les formats extract, ne pas retourner texte intro (fichier binaire) 123 136 124 137 … … 128 141 // enregistrer les prefs de l'auteur 129 142 spip_query('UPDATE spip_auteurs SET prefs=' 130 ._q(serialize($GLOBALS['auteur_session']['prefs']))131 .' WHERE id_auteur='.intval($GLOBALS['auteur_session']['id_auteur'])143 . _q(serialize($GLOBALS['auteur_session']['prefs'])) 144 . ' WHERE id_auteur=' . intval($GLOBALS['auteur_session']['id_auteur']) 132 145 ); 133 146 … … 135 148 136 149 137 138 // HTML output 139 150 // --------------------------------------------------------------------------- 151 // HTML output 152 // --------------------------------------------------------------------------- 140 153 $commencer_page = charger_fonction('commencer_page', 'inc'); 141 echo $commencer_page(_T( "convertisseur:convertir_titre"),_T("convertisseur:convertir_titre"),_T("convertisseur:convertir_titre"));154 echo $commencer_page(_T('convertisseur:convertir_titre'), _T('convertisseur:convertir_titre'), _T('convertisseur:convertir_titre')); 142 155 echo debut_gauche('', true); 143 echo debut_boite_info(true) ._T("convertisseur:convertir_desc");156 echo debut_boite_info(true) . _T('convertisseur:convertir_desc'); 144 157 echo fin_boite_info(true); 145 158 146 159 echo debut_droite('', true); 147 160 148 161 149 162 echo $log; … … 151 164 152 165 if ($out) { 153 echo "<div style='background-color:#E6ECF9;padding:8px 3px;margin-bottom:5px'>"._T("convertisseur:convertir_en"); 154 if (isset($conv_formats[$format])) echo "<strong>"._T("convertisseur:$format")."</strong>\n"; 166 echo "<div style='background-color:#E6ECF9;padding:8px 3px;margin-bottom:5px'>" . _T('convertisseur:convertir_en'); 167 if (isset($conv_formats[$format])) { 168 echo '<strong>' . _T("convertisseur:$format") . "</strong>\n"; 169 } 155 170 156 171 foreach ($out as $f => $texte) { 157 if ($f) echo "<h2>".basename($f)."</h2>\n"; 158 echo "<textarea name='conv_out' cols='65' rows='12'>".entites_html($texte)."</textarea><br />\n"; 159 160 if (isset($article[$f])){ 161 // spip 3 162 if($spip_version_branche > "3") 163 echo "<div>article ".$article[$f].": <a href='".generer_url_ecrire('article_edit', 'id_article='.$article[$f])."'>éditer</a></div>\n"; 164 else 165 echo "<div>article ".$article[$f].": <a href='".generer_url_ecrire('articles_edit', 'id_article='.$article[$f])."'>éditer</a></div>\n"; 172 if ($f) { 173 echo '<h2>' . basename($f) . "</h2>\n"; 174 } 175 echo "<textarea name='conv_out' cols='65' rows='12'>" . entites_html($texte) . "</textarea><br />\n"; 176 177 if (isset($article[$f])) { 178 // spip 3 179 if ($spip_version_branche > '3') { 180 echo '<div>article ' . $article[$f] . ": <a href='" . generer_url_ecrire('article_edit', 'id_article=' . $article[$f]) . "'>éditer</a></div>\n"; 181 } else { 182 echo '<div>article ' . $article[$f] . ": <a href='" . generer_url_ecrire('articles_edit', 'id_article=' . $article[$f]) . "'>éditer</a></div>\n"; 183 } 166 184 } 167 185 } … … 170 188 } 171 189 172 echo "<h3>"._T("convertisseur:texte_a_convertir")."</h3>\n";190 echo '<h3>' . _T('convertisseur:texte_a_convertir') . "</h3>\n"; 173 191 174 192 // format memorise pour avoir le selected dans le menu 175 if (!$format) 176 $format = $GLOBALS['auteur_session']['prefs']['convertisseur_format']; 177 echo "<p>"; 178 echo _T("convertisseur:from"); 193 if (!$format) { 194 $format = isset($GLOBALS['auteur_session']['prefs']['convertisseur_format']) ? $GLOBALS['auteur_session']['prefs']['convertisseur_format'] : ''; 195 } 196 echo '<p>'; 197 echo _T('convertisseur:from'); 179 198 echo "<select name='format'>\n"; 180 foreach ($conv_formats as $k =>$val) {181 if ($format ==$k)199 foreach ($conv_formats as $k => $val) { 200 if ($format == $k) { 182 201 $selected = " selected='selected'"; 183 else 184 $selected = ""; 185 echo "<option value='$k'$selected>"._T("convertisseur:$k")."</option>\n"; 202 } else { 203 $selected = ''; 204 } 205 echo "<option value='$k'$selected>" . _T("convertisseur:$k") . "</option>\n"; 186 206 } 187 207 echo "</select></p>\n"; 188 208 189 209 190 echo _T( "convertisseur:texte_a_copier")."<br />\n";191 192 $conv_in = entites_html(substr($conv_in, 0,40000));210 echo _T('convertisseur:texte_a_copier') . "<br />\n"; 211 212 $conv_in = entites_html(substr($conv_in, 0, 40000)); 193 213 echo "<textarea name='conv_in' cols='65' rows='12'>$conv_in</textarea><br />\n"; 194 214 195 215 196 216 echo "<div style='float:$spip_lang_right;'>"; 197 echo _T( "convertisseur:texte_fichier")."<br />\n";217 echo _T('convertisseur:texte_fichier') . "<br />\n"; 198 218 echo "<input type='file' name='upload' />\n"; 199 219 echo "</div>\n"; … … 203 223 echo "<p align='right'><small>Il est possible de convertir plusieurs fichiers en une seule fois, en les regroupant dans une archive ZIP</small></p>\n"; 204 224 205 echo "<h5>"._T("convertisseur:options")."</h5>\n";206 207 $checked = ($GLOBALS['auteur_session']['prefs']['convertisseur_cvcharset'] == "oui")225 echo '<h5>' . _T('convertisseur:options') . "</h5>\n"; 226 227 $checked = ($GLOBALS['auteur_session']['prefs']['convertisseur_cvcharset'] == 'oui') 208 228 ? ' checked="checked"' 209 229 : ''; 210 230 echo "<label><input type='checkbox' value='true' name='convert_charset'$checked 211 />" ._T("convertisseur:convertir_utf")."\n";231 />" . _T('convertisseur:convertir_utf') . "\n"; 212 232 echo "</label>\n"; 213 233 … … 215 235 // Ajouter sous forme d'article dans la rubrique 216 236 if ( 217 function_exists('charger_fonction') 218 AND $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc', true)) { 219 echo "<p/><div><label>Choisissez une rubrique si vous voulez insérer le résultat de la conversion dans un nouvel article sur le site :"; 220 echo $chercher_rubrique(null,'rubrique',null); 237 function_exists('charger_fonction') 238 and $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc', true) 239 ) { 240 echo '<p/><div><label>Choisissez une rubrique si vous voulez insérer le résultat de la conversion dans un nouvel article sur le site :'; 241 echo $chercher_rubrique(null, 'rubrique', null); 221 242 echo "</label></div>\n"; 222 243 } 223 244 224 echo "<p style='float:right;'><input type='submit' value='". _T("convertisseur:convertir")."'></p>\n"; 225 echo "</form>\n"; 226 227 228 echo fin_gauche(),fin_page();245 echo "<p style='float:right;'><input type='submit' value='" . _T('convertisseur:convertir') . "'></p>\n"; 246 echo "</form>\n"; 247 248 249 echo fin_gauche(), fin_page(); 229 250 } 230 ?>
Note: See TracChangeset
for help on using the changeset viewer.