View source
<?php
function theme_dir_listing_icon_view($node) {
$files =& $node->file_listing;
$directory_empty = TRUE;
$output = "<div class='dir-listing-icon-view'>";
foreach ($files as $file_name => $data) {
if ($file_name == ".") {
continue;
}
$directory_empty = FALSE;
if ($file_name != ".." && $data['kind'] == 0 && $node->folder_presentation->hide_extension) {
$pos = strrpos($data['name'], ".");
$data[FILEBROWSER_DATA_NAME_DISPLAY_NAME] = substr($data['name'], 0, $pos);
}
$thumbnail = _filebrowser_thumbnails_generate($node, $data);
$href = $data['url'];
$title = $data['display-name'] == '..' ? t('Go up') : $data['display-name'];
$new = theme('mark', $data['status']);
$description = $data['description'];
$output .= theme('dir_listing_icon', $data, $thumbnail, $title, $description, $href, $new);
}
$output .= "</div>";
return $output;
}
function theme_dir_listing_statistics($statistics) {
$output = "<div class='dir-listing-status'>";
if ($statistics['empty']) {
$output .= $statistics['empty'];
}
else {
$output .= implode(" - ", $statistics);
}
$output .= "</div>";
return $output;
}
function theme_dir_listing_list_view($node) {
$output = '';
$files =& $node->file_listing;
$unsorted_rows = array();
$node->folder_presentation->visible_columns['description'] = TRUE;
$visible_columns = array();
$column_names = _filebrowser_externals('metadata_info');
$directory_empty = TRUE;
$actions = module_invoke_all('filebrowser_actions_info', $node);
$has_actions = count($actions) > 0;
$header = array();
if ($has_actions) {
$header[] = array(
'',
);
}
foreach ($files as $file_name => $data) {
if ($file_name == ".") {
continue;
}
$directory_empty = FALSE;
if ($file_name != ".." && $data['kind'] == 0 && $node->folder_presentation->hide_extension) {
$pos = strrpos($data[FILEBROWSER_DATA_NAME_DISPLAY_NAME], ".");
$data[FILEBROWSER_DATA_NAME_DISPLAY_NAME] = substr($data[FILEBROWSER_DATA_NAME_DISPLAY_NAME], 0, $pos);
}
if ($has_actions) {
$unsorted_rows[$file_name]['checkbox'] = $data['mime-type'] != 'folder/parent' ? "<input type='checkbox' name='select_{$data['fid']}'/>" : '';
}
foreach ($column_names as $column_name => $column_spec) {
if (isset($node->folder_presentation->visible_columns[$column_name]) && $node->folder_presentation->visible_columns[$column_name]) {
switch ($column_name) {
case FILEBROWSER_DATA_NAME_ICON:
$visible_columns[$column_name] = TRUE;
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_ICON] = array(
'data' => _filebrowser_thumbnails_generate($node, $data),
'style' => 'width:1%;',
);
break;
case FILEBROWSER_DATA_NAME_DISPLAY_NAME:
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_DISPLAY_NAME] = '<a href="' . $data['url'] . '">' . ($data['display-name'] == '..' ? t('Go up') : $data['display-name']) . '</a>' . theme('mark', $data['status']);
$visible_columns[$column_name] = TRUE;
break;
case FILEBROWSER_DATA_NAME_SIZE:
$used = $data['size'] != 0 && $data['kind'] == 0;
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_SIZE] = $used ? format_size($data['size']) : "";
if ($used) {
$visible_columns[$column_name] = TRUE;
}
break;
case FILEBROWSER_DATA_NAME_CREATED:
if ($data['created'] != 0) {
$visible_columns[$column_name] = TRUE;
}
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_CREATED] = format_date($data['created'], "small");
break;
case FILEBROWSER_DATA_NAME_MODIFIED:
if ($data['modified'] != 0) {
$visible_columns[$column_name] = TRUE;
}
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_MODIFIED] = format_date($data['modified'], "small");
break;
case FILEBROWSER_DATA_NAME_TYPE:
$used = $data['mime-type'] != 'folder' && $data['mime-type'] != 'folder/parent';
if ($used) {
$visible_columns[$column_name] = TRUE;
}
$unsorted_rows[$file_name][FILEBROWSER_DATA_NAME_TYPE] = $used ? t($data['mime-type']) : "";
break;
case FILEBROWSER_DATA_NAME_DESCRIPTION:
if (!empty($data['description'])) {
$visible_columns[$column_name] = TRUE;
}
$unsorted_rows[$file_name]['description'] = str_replace("\n", "<br/>", $data['description']);
break;
default:
$visible_columns[$column_name] = isset($data[$column_name]);
if ($visible_columns[$column_name]) {
$unsorted_rows[$file_name][$column_name] = $data[$column_name];
}
break;
}
}
}
}
if (!$directory_empty) {
foreach ($column_names as $column_name => $column_spec) {
if (isset($visible_columns[$column_name]) && $visible_columns[$column_name]) {
if ($column_name == FILEBROWSER_DATA_NAME_ICON) {
$header[$column_name] = array();
}
else {
$header[$column_name] = array(
'data' => $column_spec['title'],
'field' => $column_name,
);
}
}
else {
foreach ($unsorted_rows as &$row) {
unset($row[$column_name]);
}
}
}
$header[$node->folder_presentation->default_sort]['sort'] = $node->folder_presentation->default_sort_order;
$table_sort = tablesort_init($header);
$just_folders = array();
$just_files = array();
foreach ($files as $name => $data) {
if ($name != '.') {
if ($data['kind'] == 0) {
$just_files[] = $data;
}
else {
$just_folders[] = $data;
}
}
}
if (isset($table_sort['sql'])) {
$field = $table_sort['sql'];
$columns = _filebrowser_externals('metadata_info');
if (isset($columns[$table_sort['sql']]) && isset($columns[$table_sort['sql']]['sortable']) && $columns[$table_sort['sql']]['sortable']) {
switch ($columns[$table_sort['sql']]['type']) {
case 'integer':
$code = '$a=isset($a["' . $field . '"])?$a["' . $field . '"]:0;';
$code .= '$b=isset($b["' . $field . '"])?$b["' . $field . '"]:0;';
$code .= 'return $a-$b;';
break;
case 'string':
$code = '$a=isset($a["' . $field . '"])?$a["' . $field . '"]:"";';
$code .= '$b=isset($b["' . $field . '"])?$b["' . $field . '"]:"";';
$code .= 'return -strcmp(strtolower($a),strtolower($b));';
break;
}
$sorter = create_function('$a,$b', $code);
usort($just_folders, $sorter);
if ($table_sort['sort'] == 'asc') {
$just_folders = array_reverse($just_folders, TRUE);
}
usort($just_files, create_function('$a,$b', $code));
if ($table_sort['sort'] == 'asc') {
$just_files = array_reverse($just_files, TRUE);
}
}
}
$rows = array();
foreach ($just_folders as $data) {
$rows[] = $unsorted_rows[$data['display-name']];
}
foreach ($just_files as $data) {
$rows[] = $unsorted_rows[$data['display-name']];
}
$output .= theme('table', $header, $rows);
if ($has_actions) {
module_load_include("form.actions.inc", "filebrowser");
$output = drupal_get_form('filebrowser_form_actions', $output, $actions, $node);
}
return $output;
}
}
function theme_dir_listing_metadata_group($form) {
$thumbnail = drupal_render($form['thumbnail']);
$output = "<table>";
foreach (element_children($form) as $key) {
if ($key != 'thumbnail') {
$output .= "<tr><td>{$thumbnail}</td><td>" . drupal_render($form[$key]) . "</td></tr>";
$thumbnail = '';
}
}
$output .= "</table>";
return $output;
}