function demo_get_dumps in Demonstration site (Sandbox / Snapshot) 5
Same name and namespace in other branches
- 8 demo.module \demo_get_dumps()
- 6 demo.admin.inc \demo_get_dumps()
- 7 demo.admin.inc \demo_get_dumps()
2 calls to demo_get_dumps()
File
- ./
demo.admin.inc, line 336 - 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['dump']['filename'] = array(
'#type' => 'value',
'#required' => TRUE,
'#title' => t('Snapshot'),
);
foreach ($files as $filename => $file) {
// Build basic file info
$files[$filename] = (array) $files[$filename];
$info = demo_get_info($filename);
// Convert file info for Forms API
$option = array();
$option['#type'] = 'radio';
$option['#name'] = 'filename';
$option['#title'] = $info['filename'] . ' (' . format_date($file->filemtime, 'small') . ', ' . format_size($file->filesize) . ')';
$option['#return_value'] = $info['filename'];
if ($info['filename'] == variable_get('demo_dump_cron', 'demo_site')) {
$option['#value'] = $info['filename'];
}
$option['#description'] = '';
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',
'watchdog',
'demo',
));
// Sort module list alphabetically.
sort($info['modules']);
$option['#description'] .= t('Modules: ') . implode(', ', $info['modules']);
}
$option['#attributes'] = array(
'onclick' => "\$('.description', this.parentNode.parentNode).slideToggle();",
);
$options['dump'][] = $option;
}
// Attach stylesheet to initially hide descriptions
drupal_add_js("\$('div.form-item div.description', \$('form')).hide();", 'inline', 'footer');
return $options;
}