PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/spip/ecrire/inc/joindre.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 217 lines | 153 code | 35 blank | 29 comment | 30 complexity | 9c272e77218e295f16e95f8b1e397966 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. include_spip('inc/actions'); // *action_auteur et determine_upload
  13. include_spip('base/abstract_sql');
  14. //
  15. // Construire un formulaire pour telecharger un fichier an Ajax
  16. //
  17. // http://doc.spip.org/@inc_joindre_dist
  18. function inc_joindre_dist($v) {
  19. // calculer le formulaire de base
  20. $res = joindre_formulaire($v);
  21. if (!empty($v['cadre'])) {
  22. $debut_cadre = 'debut_cadre_'.$v['cadre'];
  23. $fin_cadre = 'fin_cadre_'.$v['cadre'];
  24. $res = $debut_cadre($v['icone'], true, $v['fonction'], $v['titre'])
  25. . $res
  26. . $fin_cadre(true);
  27. }
  28. $res = "\n<div class='joindre'>".$res."</div>\n";
  29. $att = " enctype='multipart/form-data' class='form_upload'";
  30. $args = (intval($v['id']) .'/' .intval($v['id_document']) . "/".$v['mode'].'/'.$v['type']);
  31. $script = $v['script'];
  32. // si espace prive, $v a une signification speciale (pas clair)
  33. if (test_espace_prive())
  34. return redirige_action_post('joindre', $args, $script, $v['args'], $res, $att);
  35. else return generer_action_auteur('joindre', $args, $script, $res, "$att method='post'");
  36. }
  37. // http://doc.spip.org/@joindre_formulaire
  38. function joindre_formulaire(&$v) {
  39. global $spip_lang_right;
  40. $depliable = false;
  41. $mode = $v['mode'];
  42. $vignette_de_doc = ($mode == 'vignette' AND $v['id_document']>0);
  43. $distant = (($mode == 'document' OR $mode == 'choix') AND $v['type']);
  44. # indiquer un choix d'upload FTP
  45. $dir_ftp = '';
  46. if (test_espace_prive()
  47. AND ($mode == 'document' OR $mode == 'choix') # si c'est pour un document
  48. AND !$vignette_de_doc # pas pour une vignette (NB: la ligne precedente suffit, mais si on la supprime il faut conserver ce test-ci)
  49. AND $GLOBALS['flag_upload']) {
  50. if ($dir = determine_upload('documents')) {
  51. // quels sont les docs accessibles en ftp ?
  52. $l = texte_upload_manuel($dir, $mode);
  53. // s'il n'y en a pas, on affiche un message d'aide
  54. // en mode document, mais pas en mode image
  55. if ($l OR ($mode == 'document' OR $mode=='choix'))
  56. $dir_ftp = afficher_transferer_upload($l, $dir);
  57. }
  58. }
  59. // Add the redirect url when uploading via iframe
  60. $iframe = "";
  61. if($v['iframe_script'])
  62. $iframe = "<input type='hidden' name='iframe_redirect' value='".rawurlencode($v['iframe_script'])."' />\n";
  63. // Un menu depliant si on a une possibilite supplementaire
  64. if ($dir_ftp OR $distant OR $vignette_de_doc) {
  65. $bloc = "ftp_". $mode .'_'. intval($v['id_document']);
  66. if ($vignette_de_doc)
  67. $debut = bouton_block_depliable($v['intitule'],false,$bloc);
  68. else
  69. $debut = $v['intitule'];
  70. $milieu = debut_block_depliable(false,$bloc);
  71. $fin = "\n\t" . fin_block();
  72. $v['titre'] = bouton_block_depliable($v['titre'],false,$bloc);
  73. } else
  74. $debut = $milieu = $fin = '';
  75. // Lien document distant, jamais en mode image
  76. if ($distant) {
  77. $distant = "<br />\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
  78. "\n\t<img src='". chemin_image('attachment.gif') .
  79. "' style='float: $spip_lang_right;' alt=\"\" />\n" .
  80. "<label for='url'>" .
  81. _T('info_referencer_doc_distant') .
  82. "</label><br />\n\t<input name='url' id='url' value='http://' />" .
  83. "\n\t<div style='text-align: $spip_lang_right'><input name='sousaction2' type='submit' value='".
  84. _T('bouton_choisir').
  85. "' /></div>" .
  86. "\n</div>";
  87. }
  88. $res = "<input name='fichier' id='fichier_$mode" .'_'. strval($v['id_document']) . "' type='file' class='forml spip_xx-small' size='15' />"
  89. . ($v['ancre']
  90. ? "\n\t\t<input type='hidden' name='ancre' value='".$v['ancre']."' />"
  91. : ''
  92. )
  93. . "\n\t\t<div style='text-align: $spip_lang_right'><input name='sousaction1' type='submit' value='"
  94. . _T('bouton_telecharger')
  95. . "' /></div>";
  96. if ($vignette_de_doc)
  97. $res = $milieu . $res;
  98. else
  99. $res = $res . $milieu;
  100. return "$iframe$debut$res$dir_ftp$distant$fin";
  101. }
  102. //
  103. // Retourner le code HTML d'utilisation de fichiers envoyes
  104. //
  105. // http://doc.spip.org/@texte_upload_manuel
  106. function texte_upload_manuel($dir, $mode = 'document') {
  107. $fichiers = preg_files($dir);
  108. $exts = array();
  109. $dirs = array();
  110. $texte_upload = array();
  111. // en mode "charger une image", ne proposer que les inclus
  112. $inclus = ($mode == 'document' OR $mode =='choix')
  113. ? ''
  114. : " AND inclus='image'";
  115. foreach ($fichiers as $f) {
  116. $f = preg_replace(",^$dir,",'',$f);
  117. if (preg_match(",\.([^.]+)$,", $f, $match)) {
  118. $ext = strtolower($match[1]);
  119. if (!isset($exts[$ext])) {
  120. include_spip('inc/ajouter_documents');
  121. $ext = corriger_extension($ext);
  122. if (sql_fetsel('extension', 'spip_types_documents', $a = "extension='$ext'" . $inclus))
  123. $exts[$ext] = 'oui';
  124. else $exts[$ext] = 'non';
  125. }
  126. $k = 2*substr_count($f,'/');
  127. $n = strrpos($f, "/");
  128. if ($n === false)
  129. $lefichier = $f;
  130. else {
  131. $lefichier = substr($f, $n+1, strlen($f));
  132. $ledossier = substr($f, 0, $n);
  133. if (!in_array($ledossier, $dirs)) {
  134. $texte_upload[] = "\n<option value=\"$ledossier\">"
  135. . str_repeat("&nbsp;",$k)
  136. ._T('tout_dossier_upload', array('upload' => $ledossier))
  137. ."</option>";
  138. $dirs[]= $ledossier;
  139. }
  140. }
  141. if ($exts[$ext] == 'oui')
  142. $texte_upload[] = "\n<option value=\"$f\">" .
  143. str_repeat("&nbsp;",$k+2) .
  144. $lefichier .
  145. "</option>";
  146. }
  147. }
  148. $texte = join('', $texte_upload);
  149. if (count($texte_upload)>1) {
  150. $texte = "\n<option value=\"/\" style='font-weight: bold;'>"
  151. ._T('info_installer_tous_documents')
  152. ."</option>" . $texte;
  153. }
  154. return $texte;
  155. }
  156. // http://doc.spip.org/@afficher_transferer_upload
  157. function afficher_transferer_upload($texte_upload, $dir)
  158. {
  159. $doc = array('upload' => '<b>' . joli_repertoire($dir) . '</b>');
  160. if (!$texte_upload) {
  161. return "\n<div style='border: 1px #303030 solid; padding: 4px; color: #505050;'>" .
  162. _T('info_installer_ftp', $doc) .
  163. aide("ins_upload") .
  164. "</div>";
  165. }
  166. else { return
  167. "\n<div style='color: #505050;'>"
  168. ."<label for='cheminupload'>" . _T('info_selectionner_fichier', $doc)
  169. ."</label>&nbsp;:<br />\n" .
  170. "\n<select name='chemin' id='cheminupload' size='1' style='width:100%;overflow:hidden;'>"
  171. . "<option value=''>&gt;&gt;</option>"
  172. . $texte_upload .
  173. "\n</select>" .
  174. "\n<div style='text-align: ".
  175. $GLOBALS['spip_lang_right'] .
  176. "'><input name='sousaction3' type='submit' value='" .
  177. _T('bouton_choisir').
  178. "' /></div>" .
  179. "</div>\n";
  180. }
  181. }
  182. ?>