3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2007 *
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
22 // http://doc.spip.org/@inc_joindre_dist
23 function inc_joindre_dist($script, $args, $id=0, $intitule='', $mode='', $type='', $ancre='', $id_document=0,$iframe_script='') {
24 global $spip_lang_right;
25 $vignette_de_doc = ($mode == 'vignette' AND $id_document>0);
26 $distant = ($mode == 'document' AND $type);
27 if ($intitule) $intitule = "<span>$intitule</span><br />";
30 if (!_DIR_RESTREINT
AND !$vignette_de_doc AND $GLOBALS['flag_upload']) {
31 if($dir = determine_upload()) {
32 // quels sont les docs accessibles en ftp ?
33 $l = texte_upload_manuel($dir, '', $mode);
34 // s'il n'y en a pas, on affiche un message d'aide
35 // en mode document, mais pas en mode vignette
36 if ($l OR ($mode == 'document'))
37 $dir_ftp = afficher_transferer_upload($l, $dir);
41 // Add the redirect url when uploading via iframe
45 $iframe = "<input type='hidden' name='iframe_redirect' value='".rawurlencode($iframe_script)."' />\n";
47 // Un menu depliant si on a une possibilite supplementaire
49 if ($dir_ftp OR $distant OR $vignette_de_doc) {
50 $bloc = "ftp_$mode" .'_'. intval($id_document);
51 $debut = "\n\t<div style='float:".$GLOBALS['spip_lang_left'].";position:relative'>"
52 . bouton_block_invisible($bloc) ."</div>\n";
53 $milieu = debut_block_invisible($bloc);
54 $fin = "\n\t" . fin_block();
56 } else $debut = $milieu = $fin = '';
58 // Lien document distant, jamais en mode image
60 $distant = "<br />\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
61 "\n\t<img src='"._DIR_IMG_PACK
.'attachment.gif' .
62 "' style='float: $spip_lang_right;' alt=\"\" />\n" .
63 _T('info_referencer_doc_distant') .
64 "<br />\n\t<input name='url' class='fondo' value='http://' />" .
65 "\n\t<div align='$spip_lang_right'><input name='sousaction2' type='submit' value='".
67 "' class='fondo' /></div>" .
71 $res = "<input name='fichier' type='file' class='forml spip_xx-small' size='15' />"
72 . "\n\t\t<input type='hidden' name='ancre' value='$ancre' />"
73 . "\n\t\t<div align='$spip_lang_right'><input name='sousaction1' type='submit' value='"
74 . _T('bouton_telecharger')
75 . "' class='fondo' /></div>";
78 $res = $milieu . $res;
80 $res = $res . $milieu;
82 return generer_action_auteur('joindre',
83 (intval($id) .'/' .intval($id_document) . "/$mode/$type"),
84 (_DIR_RESTREINT
)?
$script:generer_url_ecrire($script, $args, true
),
85 "$iframe$debut$intitule$res$dir_ftp$distant$fin",
86 " method='post' enctype='multipart/form-data' class='form_upload'");
91 // Retourner le code HTML d'utilisation de fichiers envoyes
94 // http://doc.spip.org/@texte_upload_manuel
95 function texte_upload_manuel($dir, $inclus = '', $mode = 'document') {
96 $fichiers = preg_files($dir);
99 $texte_upload = array();
100 foreach ($fichiers as $f) {
101 $f = preg_replace(",^$dir,",'',$f);
102 if (ereg("\.([^.]+)$", $f, $match)) {
103 $ext = strtolower($match[1]);
104 if (!isset($exts[$ext])) {
105 if ($ext == 'jpeg') $ext = 'jpg'; # cf. corriger_extension dans inc/getdocument
106 if (spip_abstract_fetsel('extension', 'spip_types_documents', "extension='$ext'" . (!$inclus ?
'': " AND inclus='$inclus'")))
108 else $exts[$ext] = 'non';
111 $k = 2*substr_count($f,'/');
112 $n = strrpos($f, "/");
116 $lefichier = substr($f, $n+
1, strlen($f));
117 $ledossier = substr($f, 0, $n);
118 if (!in_array($ledossier, $dirs)) {
119 $texte_upload[] = "\n<option value=\"$ledossier\">"
120 . str_repeat(" ",$k)
121 ._T('tout_dossier_upload', array('upload' => $ledossier))
127 if ($exts[$ext] == 'oui')
128 $texte_upload[] = "\n<option value=\"$f\">" .
129 str_repeat(" ",$k+
2) .
135 $texte = join('', $texte_upload);
137 if ($mode == "document" AND count($texte_upload)>1) {
138 $texte = "\n<option value=\"/\" style='font-weight: bold;'>"
139 ._T('info_installer_tous_documents')
140 ."</option>" . $texte;
147 // http://doc.spip.org/@afficher_transferer_upload
148 function afficher_transferer_upload($texte_upload, $dir)
150 $doc = array('upload' => '<b>' . joli_repertoire($dir) . '</b>');
151 if (!$texte_upload) {
152 return "\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
153 _T('info_installer_ftp', $doc) .
158 "\n<div style='color: #505050;'>"
159 ._T('info_selectionner_fichier', $doc)
161 "\n<select name='chemin' size='1' class='fondl'>" .
165 $GLOBALS['spip_lang_right'] .
166 "'><input name='sousaction3' type='submit' value='" .
167 _T('bouton_choisir').
168 "' class='fondo' /></div>" .