You are here

function theme_filehash_table in File Hash 7

Returns HTML for a file attachments table with hashes.

Parameters

array $variables: An associative array containing:

  • items: An array of file attachments.
  • settings: The field instance display settings.
1 theme call to theme_filehash_table()
filehash_field_formatter_view in ./filehash.module
Implements hook_field_formatter_view().

File

./filehash.module, line 270
Generate hashes for each uploaded file.

Code

function theme_filehash_table(array $variables) {
  $names = filehash_names();
  $header = array(
    t('Attachment'),
    t('Size'),
    t('@algo hash', array(
      '@algo' => $names[$variables['settings']['algo']],
    )),
  );
  $rows = array();
  foreach ($variables['items'] as $item) {

    // Media field items contain a file object.
    if (!isset($item['uri']) && isset($item['file'])) {
      $file = $item['file'];
    }
    else {
      $file = (object) $item;
    }
    $rows[] = array(
      theme('file_link', array(
        'file' => $file,
      )),
      format_size($file->filesize),
      substr(chunk_split($file->filehash[$variables['settings']['algo']], 1, '<wbr />'), 0, -7),
    );
  }
  return empty($rows) ? '' : theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}