You are here

function demo_get_dumps in Demonstration site (Sandbox / Snapshot) 7

Same name and namespace in other branches
  1. 8 demo.module \demo_get_dumps()
  2. 5 demo.admin.inc \demo_get_dumps()
  3. 6 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 459
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);'));
  $element = array(
    '#type' => 'radios',
    '#title' => t('Snapshot'),
    '#required' => TRUE,
    '#parents' => array(
      'filename',
    ),
    '#options' => array(),
    '#attributes' => array(
      'class' => array(
        'demo-snapshots-widget',
      ),
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'demo') . '/demo.admin.js',
      ),
    ),
  );
  foreach ($files as $filename => $file) {
    $info = demo_get_info($filename);

    // Prepare snapshot title.
    $title = t('@snapshot <small>(!date, !size)</small>', array(
      '@snapshot' => $info['filename'],
      '!date' => format_date($file->filemtime, 'small'),
      '!size' => format_size($file->filesize),
    ));

    // Prepare snapshot description.
    $description = '';
    if (!empty($info['description'])) {
      $description .= '<p>' . $info['description'] . '</p>';
    }

    // Add download links.
    $description .= '<p>' . t('Download: <a href="@info-file-url">.info file</a>, <a href="@sql-file-url">.sql file</a>', array(
      '@info-file-url' => url('demo/download/' . $file->name . '/info'),
      '@sql-file-url' => url('demo/download/' . $file->name . '/sql'),
    )) . '</p>';

    // Add module list.
    if (count($info['modules']) > 1) {

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

      // Sort module list alphabetically.
      sort($modules);
      $description .= t('Modules: @modules', array(
        '@modules' => implode(', ', $modules),
      ));
    }

    // Add the radio option element.
    $element['#options'][$info['filename']] = $title;
    $element[$info['filename']] = array(
      '#description' => $description,
      '#file' => $file,
      '#info' => $info,
    );
  }
  return $element;
}