You are here

function demo_get_dumps in Demonstration site (Sandbox / Snapshot) 6

Same name and namespace in other branches
  1. 8 demo.module \demo_get_dumps()
  2. 5 demo.admin.inc \demo_get_dumps()
  3. 7 demo.admin.inc \demo_get_dumps()
2 calls to demo_get_dumps()
demo_manage_form in ./demo.admin.inc
Form builder to manage snapshots.
demo_reset_confirm in ./demo.admin.inc
Form builder to reset site to a snapshot.

File

./demo.admin.inc, line 385
Demonstration Site administrative pages

Code

function demo_get_dumps() {
  $fileconfig = demo_get_fileconfig();

  // Fetch list of available info files
  $files = file_scan_directory($fileconfig['dumppath'], '.info$');
  foreach ($files as $file => $object) {
    $files[$file]->filemtime = filemtime($file);
    $files[$file]->filesize = filesize(substr($file, 0, -4) . 'sql');
  }

  // Sort snapshots by date (ascending file modification time)
  uasort($files, create_function('$a, $b', 'return ($a->filemtime < $b->filemtime);'));
  $options = array();

  // Forms API does not pass selected value of individual radio buttons,
  // so we manually insert an internal form value here.
  $options['filename'] = array(
    '#type' => 'value',
    '#required' => TRUE,
    '#title' => t('Snapshot'),
  );
  foreach ($files as $filename => $file) {

    // Build basic file info
    $files[$filename] = (array) $file;
    $info = demo_get_info($filename);

    // Convert file info for Forms API
    $option = array(
      '#type' => 'radio',
      '#name' => 'filename',
      '#title' => check_plain($info['filename']) . ' (' . format_date($file->filemtime, 'small') . ', ' . format_size($file->filesize) . ')',
      '#description' => '',
      '#return_value' => $info['filename'],
      '#file' => $file,
      '#info' => $info,
      '#attributes' => array(
        'onclick' => "jQuery('.description', this.parentNode.parentNode).slideToggle();",
      ),
    );
    if (!empty($info['description'])) {
      $option['#description'] .= '<p>' . $info['description'] . '</p>';
    }
    $targs = array(
      '@info-file-url' => url('demo/download/' . $file->name . '/info'),
      '@sql-file-url' => url('demo/download/' . $file->name . '/sql'),
    );
    $option['#description'] .= '<p>' . t('Download: <a href="@info-file-url">.info file</a>, <a href="@sql-file-url">.sql file</a>', $targs) . '</p>';
    if (count($info['modules']) > 1) {

      // Remove required core modules and obvious modules from module list.
      $info['modules'] = array_diff($info['modules'], array(
        'block',
        'filter',
        'node',
        'system',
        'user',
        'demo',
      ));

      // Sort module list alphabetically.
      sort($info['modules']);
      $option['#description'] .= t('Modules: ') . implode(', ', $info['modules']);
    }
    $options[$info['filename']] = $option;
  }

  // Attach stylesheet to initially hide descriptions
  drupal_add_js("\$('div.form-item div.description', \$('form')).hide();", 'inline', 'footer');
  return $options;
}