attachments as $attachment) { if ($attachment['working']) { $file = module_invoke('filemanager', 'get_file_info', $attachment['fid']); $workingurl = str_replace('&', '&', module_invoke('filemanager', 'url', $file, TRUE)); $activeurl = str_replace('&', '&', module_invoke('filemanager', 'url', $file, FALSE)); $node->body = str_replace($activeurl, $workingurl, $node->body); $node->teaser = str_replace($activeurl, $workingurl, $node->teaser); } } // If this is not a teaser add our attachment list to the end of the body if (_attachment_countvisible($node)>0) { if (!$arg) { $node->content['attachments']['#value'] .= '
' . theme('attachments', $node); } // if (variable_get('attachment_display_teaser', 0)) { // $node->content['attachments']['#value'] .= '
' . theme('attachments', $node); // } } break; case 'insert': case 'update': break; case 'delete': foreach ((array)$node->attachments as $attachment) { module_invoke('filemanager', 'delete', $attachment['fid']); if ($attachment['aid']) { db_query("DELETE FROM {attachment} WHERE aid=%d",$attachment['aid']); } } break; case 'prepare': break; } } /** * Implementation of hook_menu() */ function attachment_menu($may_cache) { $items[] = array( 'path' => 'admin/settings/attachment', 'title' => t('Attachment'), 'description' => t('Change attachment settings'), 'callback' => 'drupal_get_form', 'callback arguments' => array('attachment_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, // optional ); return $items; } function attachment_admin_settings() { $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display settings') ); $form['security'] = array( '#type' => 'fieldset', '#title' => t('Security settings') ); $form['security']['attachment_private_files'] = array( '#type' => 'checkbox', '#title' => t('Private files'), '#default_value' => variable_get('attachment_private_files', 0), '#return_value' => 1, '#description' => t('If checked attachments will be streamed through the private directory and node access security will be enforced. When unchecked public URLs can be accessed by anyone with the URL regardless if they are logged in or have access to that node. There is a server load impact to using private files. Changes to this setting only affect new attachments it will not update any existing attachments.') ); $form['security']['attachment_text_rename_whitelist'] = array( '#type' => 'textarea', '#title' => t('File extension whitelist'), '#default_value' => ATTACHMENT_EXTENSION_WHITELIST, '#description' => t('List of extensions that are allowed to be uploaded without modification. All other extensions can still be uploaded, but they will be renamed to have a .txt file extension to protect your server from attackers.') ); return system_settings_form($form); } /** * Implementation of hook_file_areas() */ function attachment_filemanager_areas() { return array(array('area'=>'attachments','name'=>t('Attachments'),'description'=>t('Area where all node attachments are stored.'))); } /** * Implementation of hook_help() */ function attachment_help($section) { switch ($section) { case 'admin/build/modules#description': return t('Adds support for attaching files to nodes and downloading them.'); case 'admin/help#attachment': return t('

Attachments are files uploaded while creating nodes. These files can be used to add images to stories, blogs, etc as well as just adding documents for download.

There are two factors used to determine whether a user can add attachments to the node they are creating. First the user is checked to make sure they have add attachments permission. These permissions can be set on the permissions page. Second attachments must be enabled for that particular node type. You can enable nodes on the default workfow page.

', array('%permissionurl' => url('admin/user/configure/permission'), '%nodeconfigurl' => url('admin/node/configure/defaults'))); } } /** * Implementation of hook_link(). */ function attachment_link($type, $node = NULL, $teaser = FALSE) { $links = array(); switch($type) { case 'node': if ($main == 1 && !variable_get('attachment_display_teaser', 0)) { $count = _attachment_countvisible($node); if ($count > 0) { $links['attachment_link_all'] = array(format_plural($count, 'attachment', '@count attachments'), "node/$node->nid", array('title' => t('View attachment list')), NULL, "Attachments"); } } break; } return $links; } /** * Counts the number of visible attachments */ function _attachment_countvisible($node) { $count = 0; foreach((array)$node->attachments as $attachment) { if (!$attachment['hidden'] && !$attachment['deleted']) { $count++; } } return $count; } function theme_attachment_form($form) { $output = ''; $header = array( t('Delete'), t('Hidden'), t('Title'), t('Description'), ); $rows = array(); foreach (element_children($form) as $key) { if ($key{0} != 'c') { $row = array(); $row[0]['data'] = drupal_render($form[$key]['display']); $row[0]['colspan'] = '4'; $rows[] = $row; $row = array( drupal_render($form[$key]['deleted']), drupal_render($form[$key]['hidden']), drupal_render($form[$key]['title']), drupal_render($form[$key]['description']), ); $rows[] = $row; } } if (count($rows) > 0) { $output .= theme('table', $header, $rows); } $output .= drupal_render($form); return $output; } /** * Load the attachments for the given node */ function attachment_load($node) { $result = db_query("SELECT aid, title, description, fid, filename, size, hidden FROM {attachment} WHERE nid = %d", $node->nid); while ($attachment = db_fetch_array($result)) { $attachment['deleted'] = FALSE; $attachment['working'] = FALSE; $attachments[] = $attachment; } $fields['attachments'] = $attachments; return $fields; } function attachment_filemanager_download($file) { if ($file->area == 'attachments') { // check if current user has right to view the node this file is attached to. $nid = db_result(db_query("SELECT nid FROM {attachment} WHERE {attachment}.fid = %d", $file->fid)); $node = node_load(array('nid'=>$nid)); if (node_access('view', $node)) { return TRUE; } else { return FALSE; } } } /** * @addtogroup themeable * @{ */ /** * Formats a list of attachments for a given node. */ function theme_attachments($node) { $output = "
\n"; $attributes['class'] = 'attachment-list'; $header[0]['data'] = t('Filename/Title'); $header[0]['class'] = 'filename'; $header[1]['data'] = t('Size'); $header[1]['class'] = 'size'; foreach ((array)$node->attachments as $attachment) { if (!$attachment['hidden'] && !$attachment['deleted']) { $text = empty($attachment['title']) ? $attachment['filename'] : ($attachment['title'] . ' (' . $attachment['filename'] . ')'); $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']); $row[0]['data'] = l($text, module_invoke('filemanager', 'url', $attachment['fid']), $attrib); $row[0]['data'] = module_invoke('filemanager', 'l', $text, $attachment['fid'], FALSE, $attrib, TRUE); $row[0]['class'] = 'filename'; $row[1]['data'] = format_size($attachment['size']); $row[1]['class'] = 'size'; $rows[] = $row; } } if (count($rows) > 0) { $output .= theme('table', $header, $rows, $attributes); } $output .= "
\n"; return $output; } /** * @} end of addtogroup themeable */