function filebrowser_page in Filebrowser 5
Same name and namespace in other branches
- 6 filebrowser.module \filebrowser_page()
Prints a folder layout
1 string reference to 'filebrowser_page'
- filebrowser_menu in ./
filebrowser.module - Implementation of hook_menu().
File
- ./
filebrowser.module, line 84
Code
function filebrowser_page() {
// Build breadcrumb list for uplevel folders
$subfolder = preg_replace("!^filebrowser/*!", "", $_GET['q']);
$parts = explode("/", $subfolder);
$breadcrumb = array();
$dirname = t('root');
if ($subfolder) {
$dirname = array_pop($parts);
while (count($parts)) {
$breadcrumb[] = l($parts[count($parts) - 1], filebrowser_proper_path(join("/", $parts)));
array_pop($parts);
}
$breadcrumb[] = l(t('Filebrowser root'), 'filebrowser');
}
$breadcrumb[] = l(t('Home'), NULL);
drupal_set_breadcrumb(array_reverse($breadcrumb));
// Set page title
drupal_set_title(t('@dirname directory', array(
"@dirname" => $dirname,
)));
// No files to list, return with an empty page
if (!($files = filebrowser_get_list($subfolder))) {
drupal_set_message(t('Unable to get files for this directory.'));
return theme("filebrowser_page", '');
}
// Prepare headers for display
$headers = array_merge(array(
array(
'data' => t("Name"),
'field' => 1,
),
array(
'data' => t("Size"),
'field' => 2,
),
array(
'data' => t("Last modified"),
'field' => 3,
),
), filebrowser_get_fileinfo());
// Set sorting criteria eg. array(the 'field' key's associated value, asc/desc)
filebrowser_sort_table(array(
tablesort_get_order($headers),
tablesort_get_sort($headers),
));
// Protect folders from being resorted
$folders = array();
foreach ($files as $rnum => $filei) {
if ($filei[1]['data'] == '') {
$folders[] = $filei;
unset($files[$rnum]);
}
}
usort($files, 'filebrowser_sort_table');
$files = array_merge($folders, $files);
// Drop attributes only used for sorting, so
// these will not end up in the HTML output
foreach ($files as $rnum => $filei) {
foreach ($filei as $cnum => $cell) {
if (is_array($cell)) {
unset($filei[$cnum]['sv']);
}
}
$files[$rnum] = $filei;
}
// Allow modules to inject content above the table
$pre = join('', module_invoke_all('filebrowser_pre', $subfolder));
// Allow for themeing of the table
return theme('filebrowser_page', $files, $headers, $pre);
}