diff -urpN ../private_upload_org/private_upload.module ./private_upload.module --- ../private_upload_org/private_upload.module 2008-07-25 19:49:36.000000000 -0500 +++ ./private_upload.module 2010-10-29 22:46:05.000000000 -0500 @@ -796,6 +796,30 @@ function _private_upload_is_url_protecte return TRUE; // good } +/** +* Implementation of hook_views_api(). +* @return Array with Views API version. +*/ +function private_upload_views_api() { + return array('api' => 2.0); +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function private_upload_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'private_upload'), + ), + 'handlers' => array( + 'views_handler_field_upload_fid' => array( + 'parent' => 'views_handler_field_prerender_list', + ), + ), + ); +} // ***************************************************************************** // Views 1.x Integration ***************************************************** diff -urpN ../private_upload_org/views_handler_field_upload_fid.inc ./views_handler_field_upload_fid.inc --- ../private_upload_org/views_handler_field_upload_fid.inc 1969-12-31 18:00:00.000000000 -0600 +++ ./views_handler_field_upload_fid.inc 2010-10-30 03:32:57.000000000 -0500 @@ -0,0 +1,92 @@ + FALSE); + $options['only_listed'] = array('default' => FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_file'] = array( + '#title' => t('Link this field to download the file'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_file']), + ); + + $form['only_listed'] = array( + '#title' => t('Only show "listed" file attachments'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['only_listed']), + ); + } + + function pre_render($values) { + $vids = array(); + $this->items = array(); + + foreach ($values as $result) { + $vids[] = $result->{$this->field_alias}; + } + + if ($vids) { + // Support "only listed files" option. + $where = ''; + if (!empty($this->options['only_listed'])) { + $where = " AND u.list <> 0"; + } + $result = db_query("SELECT u.vid, u.fid, f.filename, f.filepath, f.filesize, f.filemime, u.description FROM {upload} u LEFT JOIN {files} f ON f.fid = u.fid WHERE u.vid IN (" . implode(', ', $vids) . ")$where ORDER BY u.weight"); + while ($file = db_fetch_array($result)) { + $file['filename'] = check_plain($file['filename']); + $file['filemime'] = check_plain($file['filemime']); + $file['description'] = check_plain($file['description']); + $file['filesize'] = format_size($file['filesize']); + if ($file['description']) { + //_private_upload_create_url() needs object as param, so convert necessary array elements + $values = new stdClass(); + $values->vid = $file['vid']; + $values->fid = $file['fid']; + $values->filepath = $file['filepath']; + $values->description = $file['description']; + $file['filepath'] = _private_upload_create_url($values); + } + if (!empty($this->options['link_to_file']) ) { + $file['make_link'] = TRUE; + $file['path'] = $file['filepath']; + } + $this->items[$file['vid']][$file['fid']] = $file; + } + } + } + + function render_item($count, $item) { + return $item['description']; + } + + function document_self_tokens(&$tokens) { + $tokens['[' . $this->options['id'] . '-fid' . ']'] = t('The file ID for the file.'); + $tokens['[' . $this->options['id'] . '-name' . ']'] = t('The name of the attached file.'); + $tokens['[' . $this->options['id'] . '-type' . ']'] = t('The MIME type of the attached file.'); + $tokens['[' . $this->options['id'] . '-description' . ']'] = t('The name of the attached file.'); + $tokens['[' . $this->options['id'] . '-path' . ']'] = t('The path of the attached file.'); + $tokens['[' . $this->options['id'] . '-size' . ']'] = t('The size of the attached file.'); + } + + function add_self_tokens(&$tokens, $item) { + $tokens['[' . $this->options['id'] . '-fid' . ']'] = $item['fid']; + $tokens['[' . $this->options['id'] . '-name' . ']'] = $item['filename']; + $tokens['[' . $this->options['id'] . '-type' . ']'] = $item['filemime']; + $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description']; + $tokens['[' . $this->options['id'] . '-path' . ']'] = $item['filepath']; + $tokens['[' . $this->options['id'] . '-size' . ']'] = $item['filesize']; + } +}