[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/action/ -> joindre.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   7   *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
   8   *                                                                         *
   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  \***************************************************************************/
  12  
  13  if (!defined("_ECRIRE_INC_VERSION")) return;
  14  
  15  include_spip('inc/charsets');    # pour le nom de fichier
  16  include_spip('base/abstract_sql');
  17  include_spip('inc/actions');
  18  
  19  // http://doc.spip.org/@action_joindre_dist
  20  function action_joindre_dist()
  21  {
  22      global $hash, $url, $chemin, $ancre,
  23        $sousaction1,
  24        $sousaction2,
  25        $sousaction3,
  26        $sousaction4,
  27        $sousaction5,
  28        $_FILES,  $HTTP_POST_FILES;
  29  
  30      $securiser_action = charger_fonction('securiser_action', 'inc');
  31      $arg = $securiser_action();
  32  
  33      $redirect = _request('redirect');
  34      $iframe_redirect = _request('iframe_redirect');
  35      if (!preg_match(',^(-?\d+)\D(\d+)\D(\w+)/(\w+)$,',$arg,$r)) {
  36        spip_log("action_joindre_dist incompris: " . $arg);
  37        redirige_par_entete(urldecode($redirect));
  38      }
  39      list($arg, $id, $id_document, $mode, $type) = $r;
  40  
  41       // pas terrible, mais c'est le pb du bouton Submit qui retourne son texte,
  42       // et son transcodage est couteux et perilleux
  43       $sousaction = 'spip_action_joindre' .
  44         ($sousaction1 ? 1 :
  45      ($sousaction2 ? 2 :
  46       ($sousaction3 ? 3 : 
  47        ($sousaction4 ? 4 :
  48         $sousaction5 ))));
  49  
  50       $path = ($sousaction1 ? ($_FILES ? $_FILES : $HTTP_POST_FILES) :
  51           ($sousaction2 ? $url : $chemin));
  52  
  53       $documents_actifs = array();
  54  
  55       if (function_exists($sousaction))
  56         $type_image = $sousaction($path, $mode, $type, $id, $id_document, 
  57                   $hash, $redirect, $documents_actifs, $iframe_redirect);
  58  
  59       else spip_log("spip_action: sousaction inconnue $sousaction");
  60  
  61       $redirect = urldecode($redirect);
  62       if ($documents_actifs) {
  63      $redirect = parametre_url($redirect,'show_docs',join(',',$documents_actifs),'&');
  64       }
  65       
  66      if (!$ancre) {
  67  
  68          if ($mode=='vignette')
  69              $ancre = 'images';
  70          else if ($type_image)
  71              $ancre = 'portfolio';
  72          else
  73              $ancre = 'documents';
  74       }
  75  
  76      $redirect .= '#' . $ancre;
  77      if ($type == 'rubrique') {
  78      include_spip('inc/rubriques');
  79      calculer_rubriques();
  80       }
  81  
  82      if(_request("iframe") == 'iframe') {
  83          $redirect = parametre_url(urldecode($iframe_redirect),"show_docs",join(',',$documents_actifs),'&')."&iframe=iframe";
  84      }
  85  
  86      redirige_par_entete($redirect);
  87       ## redirection a supprimer si on veut poster dans l'espace prive directement (UPLOAD_DIRECT)
  88  }
  89  
  90  
  91  // Cas d'un document distant reference sur internet
  92  
  93  // http://doc.spip.org/@spip_action_joindre2
  94  function spip_action_joindre2($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
  95  {
  96      return joindre_documents(array(
  97                     array('name' => basename($path),
  98                       'tmp_name' => $path)
  99                     ), 'distant', $type, $id, $id_document,
 100                   $hash, $redirect, $actifs, $iframe_redirect);
 101  }
 102  
 103  // Cas d'un fichier transmis
 104  
 105  // http://doc.spip.org/@spip_action_joindre1
 106  function spip_action_joindre1($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
 107  {
 108      $files = array();
 109      if (is_array($path))
 110        foreach ($path as $file) {
 111          if (!($file['error'] == 4) /* UPLOAD_ERR_NO_FILE */)
 112              $files[]=$file;
 113      }
 114  
 115      return joindre_documents($files, $mode, $type, $id, $id_document,
 116                   $hash, $redirect, $actifs, $iframe_redirect);
 117  } 
 118  
 119  // copie de tout ou partie du repertoire upload
 120  
 121  // http://doc.spip.org/@spip_action_joindre3
 122  function spip_action_joindre3($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
 123  {
 124      if (!$path || strstr($path, '..')) return;
 125          
 126      $upload = determine_upload();
 127      if ($path != '/' AND $path != './') $upload .= $path;
 128  
 129      if (!is_dir($upload))
 130        // seul un fichier est demande
 131        $files = array(array ('name' => basename($upload),
 132                  'tmp_name' => $upload)
 133               );
 134      else {
 135        include_spip('inc/documents');
 136        $files = array();
 137        foreach (preg_files($upload) as $fichier) {
 138              $files[]= array (
 139                      'name' => basename($fichier),
 140                      'tmp_name' => $fichier
 141                      );
 142        }
 143      }
 144  
 145      return joindre_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, $actifs, $iframe_redirect);
 146  }
 147  
 148  //
 149  // Charger la fonction surchargeable receptionnant un fichier
 150  // et l'appliquer sur celui ou ceux indiques.
 151  
 152  // http://doc.spip.org/@joindre_documents
 153  function joindre_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, &$actifs, $iframe_redirect)
 154  {
 155      $ajouter_documents = charger_fonction('ajouter_documents', 'inc');
 156  
 157      if (function_exists('gzopen') 
 158      AND !($mode == 'distant')
 159      AND (count($files) == 1)) {
 160  
 161          $desc = $files[0];
 162          if (preg_match('/\.zip$/i', $desc['name'])
 163              OR ($desc['type'] == 'application/zip')) {
 164      
 165        // on pose le fichier dans le repertoire zip 
 166        // (nota : copier_document n'ecrase pas un fichier avec lui-meme
 167        // ca autorise a boucler)
 168              $zip = copier_document("zip",
 169                      $desc['name'],
 170                      $desc['tmp_name']
 171                  );
 172              if (!$zip)
 173                {include_spip('minipres'); echo minipres('Erreur upload zip'); exit;} # pathologique
 174              // Est-ce qu'on sait le lire ?
 175              include_spip('inc/pclzip');
 176              $archive = new PclZip($zip);
 177              if ($archive) {
 178                $valables = verifier_compactes($archive);
 179                if ($valables) {
 180                  echo liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash, $redirect, $zip, $iframe_redirect);
 181      // a tout de suite en joindre4, joindre5, ou joindre6
 182                  exit;
 183                }
 184              }
 185          }
 186      }
 187      foreach ($files as $arg) {
 188          check_upload_error($arg['error']);
 189          $x = $ajouter_documents($arg['tmp_name'], $arg['name'], 
 190                      $type, $id, $mode, $id_document, $actifs);
 191      }
 192      // un invalideur a la hussarde qui doit marcher au moins pour article, breve, rubrique
 193      include_spip('inc/invalideur');
 194      suivre_invalideur("id='id_$type/$id'");
 195      return $x;
 196  }
 197  
 198  #-----------------------------------------------------------------------
 199  
 200  // sous-actions suite a l'envoi d'un Zip:
 201  // la fonction joindre_documents ci-dessus a construit un formulaire 
 202  // qui renvoie sur une des 3 sous-actions qui suivent. 
 203  
 204  //  Zip avec confirmation "tel quel"
 205  
 206  // http://doc.spip.org/@spip_action_joindre5
 207  function spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs)
 208  {
 209      $ajouter_documents = charger_fonction('ajouter_documents', 'inc');
 210      $pos = strpos($path, '/zip/');
 211      if (!$pos) {
 212          $pos = strpos($path, '/zip_');
 213      }
 214      return $ajouter_documents($path, substr($path, $pos+5), $type, $id, $mode, $id_document, $actifs);
 215  }
 216  
 217  // Zip a deballer. 
 218  
 219  // http://doc.spip.org/@spip_action_joindre6
 220  function spip_action_joindre6($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
 221  {
 222      $x = joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
 223      //  suppression de l'archive en zip
 224      @unlink($path);
 225      return $x;
 226  }
 227  
 228  // Zip avec les 2 options a la fois
 229  
 230  // http://doc.spip.org/@spip_action_joindre4
 231  function spip_action_joindre4($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
 232  {
 233      joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
 234      return spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
 235  }
 236  
 237  // http://doc.spip.org/@joindre_deballes
 238  function joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs)
 239  {
 240          $ajouter_documents = charger_fonction('ajouter_documents', 'inc');
 241          define('_tmp_dir', creer_repertoire_documents($hash));
 242  
 243          if (_tmp_dir == _DIR_DOC)
 244            {include_spip('minipres');
 245          echo minipres(_T('avis_operation_impossible'));
 246          exit;
 247            }
 248          include_spip('inc/pclzip');
 249          $archive = new PclZip($path);
 250          $archive->extract(
 251                    PCLZIP_OPT_PATH, _tmp_dir,
 252                    PCLZIP_CB_PRE_EXTRACT, 'callback_deballe_fichier'
 253                    );
 254          $contenu = verifier_compactes($archive);
 255  
 256          foreach ($contenu as $fichier) {
 257          $f = basename($fichier);
 258          $x = $ajouter_documents(_tmp_dir. $f, $f,
 259                      $type, $id, $mode, $id_document, $actifs);
 260          }
 261          effacer_repertoire_temporaire(_tmp_dir);
 262          return $x;
 263  }
 264  
 265  
 266  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics