Projet

Général

Profil

Révision 8e7483ab

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/file_entity/file_entity.pages.inc
1208 1208
  if ($archive = file_load($form_state['values']['upload'])) {
1209 1209
    if ($archiver = archiver_get_archiver($archive->uri)) {
1210 1210
      $files = $archiver->listContents();
1211
      $destination = pathinfo($archive->filename, PATHINFO_FILENAME);
1212

  
1213
      // Prepare a temporary directory to extract the archive to before saving
1214
      // it is content.
1215
      $extract_location = 'temporary://' . $destination;
1216
      $extract_location = file_destination($extract_location, FILE_EXISTS_RENAME);
1217
      if (!file_prepare_directory($extract_location, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) {
1218
        throw new Exception(t('Unable to prepar, a temporary directory %dir for extraction.', array('%dir' => $extract_location)));
1219
      }
1211 1220

  
1212
      $extract_dir = file_default_scheme() . '://' . pathinfo($archive->filename, PATHINFO_FILENAME);
1213
      $extract_dir = file_destination($extract_dir, FILE_EXISTS_RENAME);
1214
      if (!file_prepare_directory($extract_dir, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) {
1215
        throw new Exception(t('Unable to prepare directory %dir for extraction.', array('%dir' => $extract_dir)));
1221
      // Prepare target directory where files are going to be saved.
1222
      $target_dir = file_default_scheme() . '://' . $destination;
1223
      $target_dir = file_destination($target_dir, FILE_EXISTS_RENAME);
1224
      if (!file_prepare_directory($target_dir, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) {
1225
        throw new Exception(t('Unable to prepar, a directory %dir for extraction.', array('%dir' => $target_dir)));
1216 1226
      }
1217 1227

  
1218
      $archiver->extract($extract_dir);
1228
      $archiver->extract($extract_location);
1219 1229
      $pattern = '/' . $form_state['values']['pattern'] . '/';
1220
      if ($files = file_scan_directory($extract_dir, $pattern)) {
1221
        foreach ($files as $file) {
1230
      if ($extracted_files = file_scan_directory($extract_location, $pattern)) {
1231
        foreach ($extracted_files as $extracted_file) {
1232
          $file = new stdClass();
1233
          $file->fid = NULL;
1234
           $file->uid = $archive->uid;
1235
          $file->filename = $extracted_file->filename;
1236
          $file->origname = $extracted_file->filename;
1222 1237
          $file->status = FILE_STATUS_PERMANENT;
1223
          $file->uid = $archive->uid;
1238
          $file->filemime = file_get_mimetype($extracted_file->filename);
1239

  
1240
          // destination uri should match the current file directory hierarchy.
1241
          $file->uri = $target_dir . str_replace($extract_location, '', $extracted_file->uri);
1242

  
1243
          // Rename potentially executable files, to help prevent exploits (i.e. will
1244
          // rename filename.php.foo and filename.php to filename.php.foo.txt and
1245
          // filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads'
1246
          // evaluates to TRUE.
1247
          if (!variable_get('allow_insecure_uploads', 0) && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
1248
            $file->filemime = 'text/plain';
1249
            $file->uri .= '.txt';
1250
            $file->filename .= '.txt';
1251
          }
1252

  
1253
          // prepare destination path for the extracted file while keeping the
1254
          // directory hierarchy of the file.
1255
          $destination = pathinfo($file->uri, PATHINFO_DIRNAME);
1256
          if (!file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) {
1257
            throw new Exception(t('Unable to prepar, a directory %dir for extraction.', array('%dir' => $destination)));
1258
          }
1259

  
1260
          if (!file_unmanaged_move($extracted_file->uri, $file->uri)) {
1261
            throw new Exception(t('Could not move uploaded file %file to destination %destination.', array('%file' => $extracted_file->filename, '%destination' => $file->uri)));
1262
            return FALSE;
1263
          }
1264

  
1224 1265
          file_save($file);
1225 1266
          $form_state['files'][$file->fid] = $file;
1226 1267
        }
1227 1268
      }
1269
      // Delete extract location
1270
      file_unmanaged_delete_recursive($extract_location);
1228 1271
      drupal_set_message(t('Extracted %file and added @count new files.', array('%file' => $archive->filename, '@count' => count($files))));
1229 1272
    }
1230 1273
    else {

Formats disponibles : Unified diff