You are here

function itweak_upload_upload_attachments in iTweak Upload 6.2

Implementation of theme_upload_attachments(). Theme the attachments output.

Parameters

$files: Array of file objects (descriptors from node).

1 call to itweak_upload_upload_attachments()
itweak_upload_comment_upload_attachments in ./itweak_upload.module
Implementation of theme_comment_upload_attachments(). We are adding two more arguments.
1 string reference to 'itweak_upload_upload_attachments'
itweak_upload_theme in ./itweak_upload.module
Implementation of hook_theme().

File

./itweak_upload.module, line 873
iTweakUpload - Tweak attachments display and file upload forms.

Code

function itweak_upload_upload_attachments($files) {
  $stats = function_exists('_download_count_stats');
  $header = $stats ? array(
    array(
      'data' => t('Preview'),
      'class' => 'preview',
    ),
    array(
      'data' => t('Attachment'),
      'class' => 'file',
    ),
    //        array('data' => t('Hits'), 'class' => 'download_count', ), array('data' => t('Last download'), 'class' => 'download_last'),
    array(
      'data' => t('Count / Last Download'),
      'class' => 'download_stats',
      'colspan' => 2,
    ),
    array(
      'data' => t('Size'),
      'class' => 'size',
    ),
  ) : array(
    array(
      'data' => t('Preview'),
      'class' => 'preview',
    ),
    array(
      'data' => t('Attachment'),
      'class' => 'file',
    ),
    array(
      'data' => t('Size'),
      'class' => 'size',
    ),
  );
  $rows = array();
  foreach ($files as $file) {
    $file = (object) $file;
    if ($file->list && empty($file->remove) && empty($file->hidden)) {
      $extension = strtolower(substr(strrchr($file->filename, '.'), 1));
      $href = _itweak_upload_file_create_url($file);
      $text = $file->description ? $file->description : $file->filename;
      $row = array();
      $options = isset($file->preview_options) ? $file->preview_options : array();
      if (!$file->access || !(isset($file->preview) || _itweak_upload_isimage($file) || isset($options['custom']))) {
        $options = array();
      }

      // [#1253692] by smokris: Add a hook for other modules to alter attachment links
      $data = compact('file', 'text', 'href', 'options');
      drupal_alter('itweak_upload_prerender', $data);
      extract($data);
      if (isset($file->preview)) {
        $row[] = array(
          'data' => drupal_render($file->preview),
          'class' => 'mime mime-' . $extension,
        );
      }
      else {
        $row[] = array(
          'data' => '',
          'class' => 'mime mime-' . $extension,
        );
      }
      $row[] = array(
        'data' => l($text, $href, $options),
        'class' => 'file',
      );
      if ($stats) {
        _download_count_stats($file);
        $row[] = array(
          'data' => $file->download_count,
          'class' => 'download_count',
        );
        $row[] = array(
          'data' => $file->download_last,
          'class' => 'download_last',
        );
      }
      $row[] = array(
        'data' => format_size($file->filesize),
        'class' => 'size',
      );
      $rows[] = $row;
    }
  }
  if (count($rows)) {
    return '<div class="itu-attachments">' . theme('table', $header, $rows, array(
      'class' => 'itu-attachment-list' . ($stats ? ' withstats' : ' withoutstats'),
      'id' => 'attachments',
    )) . '</div>';
  }
}