You are here

function _install_all_from_zip in Bibliography Module 7

File

modules/CiteProc/biblio_citeproc.admin.inc, line 531

Code

function _install_all_from_zip(&$context = NULL) {
  $zipname = $context['results']['zipname'];
  if (!empty($zipname)) {

    // variable_del('github_zip');.
    $zip = zip_open($zipname);
    $za = new ZipArchive();
    if ($za
      ->open($zipname) !== TRUE) {
      $message = t('Could not open zip file containing styles: @file', array(
        '@file' => realpath($zipname),
      ));
      $message = check_plain($message);
      drupal_set_message($message, 'error');
      return;
    }
    if (empty($context['sandbox'])) {
      $context['sandbox']['progress'] = 0;
      $context['results']['install_count'] = 0;
    }
    $num_files = $za->numFiles;
    $start = $context['sandbox']['progress'];
    $end = min($start + 50, $num_files);
    for ($i = $start; $i < $end; $i++) {
      $name = $za
        ->getNameIndex($i);
      $name = basename($name);
      if (strstr($name, '.csl')) {
        $csl = $za
          ->getFromIndex($i);
        _install_csl($name, $csl, NULL, TRUE);
        $context['results']['install_count']++;
      }
      $context['sandbox']['progress']++;
    }
    $za
      ->close();
    if ($context['sandbox']['progress'] != $num_files) {
      $context['finished'] = $context['sandbox']['progress'] / $num_files;
    }
  }
}