80012975d53ba4484f7a767cace821d4e592033a
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/actions'); // *action_auteur et determine_upload
16 include_spip('base/abstract_sql');
19 // Construire un formulaire pour telecharger un fichier an Ajax
22 // http://doc.spip.org/@inc_joindre_dist
23 function inc_joindre_dist($v) {
25 // calculer le formulaire de base
27 $res = joindre_formulaire($v);
29 if (!empty($v['cadre'])) {
30 $debut_cadre = 'debut_cadre_'.$v['cadre'];
31 $fin_cadre = 'fin_cadre_'.$v['cadre'];
32 $res = $debut_cadre($v['icone'], true, $v['fonction'], $v['titre'])
37 $res = "\n<div class='joindre'>".$res."</div>\n";
38 $att = " enctype='multipart/form-data' class='form_upload'";
39 $args = (intval($v['id']) .'/' .intval($v['id_document']) . "/".$v['mode'].'/'.$v['type']);
40 $script = $v['script'];
42 // si espace prive, $v a une signification speciale (pas clair)
43 if (test_espace_prive())
44 return redirige_action_post('joindre', $args, $script, $v['args'], $res, $att);
45 else return generer_action_auteur('joindre', $args, $script, $res, "$att method='post'");
48 // http://doc.spip.org/@joindre_formulaire
49 function joindre_formulaire(&$v) {
50 global $spip_lang_right;
54 $vignette_de_doc = ($mode == 'vignette' AND $v['id_document']>0);
55 $distant = (($mode == 'document' OR $mode == 'choix') AND $v['type']);
57 # indiquer un choix d'upload FTP
59 if (test_espace_prive()
60 AND ($mode == 'document' OR $mode == 'choix') # si c'est pour un document
61 AND !$vignette_de_doc # pas pour une vignette (NB: la ligne precedente suffit, mais si on la supprime il faut conserver ce test-ci)
62 AND $GLOBALS['flag_upload']) {
63 if ($dir = determine_upload('documents')) {
64 // quels sont les docs accessibles en ftp ?
65 $l = texte_upload_manuel($dir, $mode);
66 // s'il n'y en a pas, on affiche un message d'aide
67 // en mode document, mais pas en mode image
68 if ($l OR ($mode == 'document' OR $mode=='choix'))
69 $dir_ftp = afficher_transferer_upload($l, $dir);
73 // Add the redirect url when uploading via iframe
76 if($v['iframe_script'])
77 $iframe = "<input type='hidden' name='iframe_redirect' value='".rawurlencode($v['iframe_script'])."' />\n";
79 // Un menu depliant si on a une possibilite supplementaire
81 if ($dir_ftp OR $distant OR $vignette_de_doc) {
82 $bloc = "ftp_". $mode .'_'. intval($v['id_document']);
85 $debut = bouton_block_depliable($v['intitule'],false,$bloc);
87 $debut = $v['intitule'];
89 $milieu = debut_block_depliable(false,$bloc);
90 $fin = "\n\t" . fin_block();
91 $v['titre'] = bouton_block_depliable($v['titre'],false,$bloc);
94 $debut = $milieu = $fin = '';
96 // Lien document distant, jamais en mode image
98 $distant = "<br />\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
99 "\n\t<img src='". chemin_image('attachment.gif') .
100 "' style='float: $spip_lang_right;' alt=\"\" />\n" .
101 "<label for='url'>" .
102 _T('info_referencer_doc_distant') .
103 "</label><br />\n\t<input name='url' id='url' value='http://' />" .
104 "\n\t<div style='text-align: $spip_lang_right'><input name='sousaction2' type='submit' value='".
105 _T('bouton_choisir').
110 $res = "<input name='fichier' id='fichier_$mode" .'_'. strval($v['id_document']) . "' type='file' class='forml spip_xx-small' size='15' />"
112 ?
"\n\t\t<input type='hidden' name='ancre' value='".$v['ancre']."' />"
115 . "\n\t\t<div style='text-align: $spip_lang_right'><input name='sousaction1' type='submit' value='"
116 . _T('bouton_telecharger')
119 if ($vignette_de_doc)
120 $res = $milieu . $res;
122 $res = $res . $milieu;
124 return "$iframe$debut$res$dir_ftp$distant$fin";
129 // Retourner le code HTML d'utilisation de fichiers envoyes
132 // http://doc.spip.org/@texte_upload_manuel
133 function texte_upload_manuel($dir, $mode = 'document') {
134 $fichiers = preg_files($dir);
137 $texte_upload = array();
139 // en mode "charger une image", ne proposer que les inclus
140 $inclus = ($mode == 'document' OR $mode =='choix')
142 : " AND inclus='image'";
144 foreach ($fichiers as $f) {
145 $f = preg_replace(",^$dir,",'',$f);
146 if (preg_match(",\.([^.]+)$,", $f, $match)) {
147 $ext = strtolower($match[1]);
148 if (!isset($exts[$ext])) {
149 include_spip('inc/ajouter_documents');
150 $ext = corriger_extension($ext);
151 if (sql_fetsel('extension', 'spip_types_documents', $a = "extension='$ext'" . $inclus))
153 else $exts[$ext] = 'non';
156 $k = 2*substr_count($f,'/');
157 $n = strrpos($f, "/");
161 $lefichier = substr($f, $n+
1, strlen($f));
162 $ledossier = substr($f, 0, $n);
163 if (!in_array($ledossier, $dirs)) {
164 $texte_upload[] = "\n<option value=\"$ledossier\">"
165 . str_repeat(" ",$k)
166 ._T('tout_dossier_upload', array('upload' => $ledossier))
172 if ($exts[$ext] == 'oui')
173 $texte_upload[] = "\n<option value=\"$f\">" .
174 str_repeat(" ",$k+
2) .
180 $texte = join('', $texte_upload);
181 if (count($texte_upload)>1) {
182 $texte = "\n<option value=\"/\" style='font-weight: bold;'>"
183 ._T('info_installer_tous_documents')
184 ."</option>" . $texte;
191 // http://doc.spip.org/@afficher_transferer_upload
192 function afficher_transferer_upload($texte_upload, $dir)
194 $doc = array('upload' => '<b>' . joli_repertoire($dir) . '</b>');
195 if (!$texte_upload) {
196 return "\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
197 _T('info_installer_ftp', $doc) .
202 "\n<div style='color: #505050;'>"
203 ."<label for='cheminupload'>" . _T('info_selectionner_fichier', $doc)
204 ."</label> :<br />\n" .
205 "\n<select name='chemin' id='cheminupload' size='1' style='width:100%;overflow:hidden;'>"
206 . "<option value=''>>></option>"
209 "\n<div style='text-align: ".
210 $GLOBALS['spip_lang_right'] .
211 "'><input name='sousaction3' type='submit' value='" .
212 _T('bouton_choisir').