/[drupal]/contributions/modules/attachment/attachment.module
ViewVC logotype

Diff of /contributions/modules/attachment/attachment.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.17, Thu Sep 28 09:59:31 2006 UTC revision 1.18, Tue Jul 17 19:50:04 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: attachment.module,v 1.16 2006/09/27 18:31:25 robertDouglass Exp $  // $Id: attachment.module,v 1.15.2.2 2006/09/28 09:53:13 robertDouglass Exp $
3    
4  define(ATTACHMENT_EXTENSION_WHITELIST, variable_get('attachment_text_rename_whitelist', 'jpg jpeg gif png tiff txt html doc xls pdf ppt pps odt mp3 ogg wav wmv mpg'));  define(ATTACHMENT_EXTENSION_WHITELIST, variable_get('attachment_text_rename_whitelist', 'jpg jpeg gif png tiff txt html doc xls pdf ppt pps odt mp3 ogg wav wmv mpg'));
5    
6    /**
7     * Implementation of hook_menu()
8     */
9    function attachment_menu($may_cache) {
10      $items = array();
11    
12      if ($may_cache) {
13        $items[] = array(
14          'path' => 'admin/settings/attachment',
15          'title' => t('Attachment'),
16          'description' => t('Settings for Attachment module'),
17          'callback' => 'drupal_get_form',
18          'callback arguments' => array('attachment_admin_settings'),
19          'access' => user_access('administer site configuration'),
20          'type' => MENU_NORMAL_ITEM,
21        );
22      }
23    
24      return $items;
25    }
26    
27    /**
28     * Implementation of hook_form_alter()
29     */
30  function attachment_form_alter($form_id, &$form) {  function attachment_form_alter($form_id, &$form) {
31    $type = $form['type']['#value'];    $type = $form['type']['#value'];
32      $oldtype = $form['old_type']['#value'];
33    
34    switch ($form_id) {    switch ($form_id) {
35      // node edit form      // node edit form
# Line 16  function attachment_form_alter($form_id, Line 41  function attachment_form_alter($form_id,
41            $node->attachments = $ret['attachments'];            $node->attachments = $ret['attachments'];
42          }          }
43          $form['#attributes'] = array('enctype' => 'multipart/form-data');          $form['#attributes'] = array('enctype' => 'multipart/form-data');
44    
45          $form['attachments'] = array('#type'=>'fieldset', '#title'=>t('Attachments'), '#tree'=>true, '#collapsible'=>true, '#weight'=>1);          // If we have attachments, open the area, otherwise it will be collapsed.
46            $collapsed = !isset($node->attachments);
47    
48            $form['attachments'] = array('#type'=>'fieldset', '#title'=>t('Attachments'), '#tree'=>true, '#collapsible'=>true, '#collapsed'=>$collapsed, '#weight'=>1);
49          $form['attachments']['#theme'] = 'attachment_form';          $form['attachments']['#theme'] = 'attachment_form';
50    
51          foreach ((array)$node->attachments as $key=>$attachment) {          foreach ((array)$node->attachments as $key=>$attachment) {
# Line 39  function attachment_form_alter($form_id, Line 67  function attachment_form_alter($form_id,
67        break;        break;
68    
69      // node settings form      // node settings form
70      case $type .'_node_settings':      case 'node_type_form':
71        $form['workflow']['attachment_node_'. $type] = array(        $form['workflow']['attachment_settings'] = array(
72          '#type'=>'radios',          '#type'=>'radios',
73          '#title'=>t('Attachments'),          '#title'=>t('Attachments'),
74          '#default_value'=>variable_get('attachment_node_'. $type, 0),          '#default_value'=>variable_get('attachment_node_'. $oldtype, 0),
75          '#options'=>array(0=>t('Disabled'), 1=>t('Enabled')),          '#options'=>array(0=>t('Disabled'), 1=>t('Enabled')),
76        );        );
77        break;        break;
# Line 54  function attachment_form_alter($form_id, Line 82  function attachment_form_alter($form_id,
82   * Implementation of hook_nodeapi.   * Implementation of hook_nodeapi.
83   */   */
84  function attachment_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {  function attachment_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {
85    
86    switch ($op) {    switch ($op) {
87      case 'load':      case 'load':
88        return attachment_load($node);        return attachment_load($node);
89      case 'view':  
90        case 'alter':
91          // This used to be in $op==view.  Not sure about it, but looks like alter is a good place for
92          // it since it looks like it has to do str_replace.
93        foreach ((array)$node->attachments as $attachment) {        foreach ((array)$node->attachments as $attachment) {
94          if ($attachment['working']) {          if ($attachment['working']) {
95            $file = module_invoke('filemanager', 'get_file_info', $attachment['fid']);            $file = module_invoke('filemanager', 'get_file_info', $attachment['fid']);
# Line 67  function attachment_nodeapi(&$node, $op, Line 99  function attachment_nodeapi(&$node, $op,
99            $node->teaser = str_replace($activeurl, $workingurl, $node->teaser);            $node->teaser = str_replace($activeurl, $workingurl, $node->teaser);
100          }          }
101        }        }
102          return;
103    
104        case 'view':
105    
106        // If this is not a teaser add our attachment list to the end of the body        // If this is not a teaser add our attachment list to the end of the body
107        if (_attachment_countvisible($node)>0) {        if (_attachment_countvisible($node)>0) {
108          if (!$arg) {          if (!$arg) {
109            $node->body .= '<br /><a name="attachments"></a>' . theme('attachments', $node);            $node->content['attachment'] = array(
110                '#value' => '<br /><a name="attachments"></a>'. theme('attachments', $node),
111                '#weight' => 10,
112                );
113          }          }
114          if (variable_get('attachment_display_teaser', 0)) {          if (variable_get('attachment_display_teaser', 0)) {
115            $node->teaser .= '<br /><a name="attachments"></a>' . theme('attachments', $node);            $node->content['attachment'] = array(
116                '#value' => '<br /><a name="attachments"></a>'. theme('attachments', $node),
117                '#weight' => 10,
118                );
119          }          }
120        }        }
121        return;        return;
# Line 111  function attachment_nodeapi(&$node, $op, Line 152  function attachment_nodeapi(&$node, $op,
152        return;        return;
153    
154      case 'prepare':      case 'prepare':
155        if (isset($_POST['edit']['attachments'])) {        if (($_POST['op'] == t('Preview')) || ($_POST['op'] == t('Submit'))) {
156          $node->attachments = $_POST['edit']['attachments'];          $node->attachments = $_POST['attachments'];
157        }        }
158    
159        if ($_POST['fileop'] == t('Add')) {        if ($_POST['fileop'] == t('Add')) {
160          attachment_add($node);          attachment_add($node);
161        }        }
162    
163    
164        return;        return;
165    }    }
# Line 133  function attachment_perm() { Line 175  function attachment_perm() {
175  /**  /**
176   * Implementation of hook_settings()   * Implementation of hook_settings()
177   */   */
178  function attachment_settings() {  function attachment_admin_settings() {
179    $form['display'] = array(    $form['display'] = array(
180      '#type' => 'fieldset',      '#type' => 'fieldset',
181      '#title' => t('Display settings')      '#title' => t('Display settings')
# Line 163  function attachment_settings() { Line 205  function attachment_settings() {
205      '#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.')      '#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.')
206    );    );
207    
208    return $form;    return system_settings_form($form);
209  }  }
210    
211  /**  /**
# Line 178  function attachment_filemanager_areas() Line 220  function attachment_filemanager_areas()
220   */   */
221  function attachment_help($section) {  function attachment_help($section) {
222    switch ($section) {    switch ($section) {
     case 'admin/modules#description':  
       return t('Adds support for attaching files to nodes and downloading them.');  
223      case 'admin/help#attachment':      case 'admin/help#attachment':
224        return t('<p>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.</p>        return t('<p>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.</p>
225                  <p>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 <em>add attachments</em> permission.  These permissions can be set on the <a href="%permissionurl%">permissions</a> page.  Second attachments must be enabled for that particular node type.  You can enable nodes on the <a href="%nodeconfigurl%">default workfow</a> page.</p>', array('%permissionurl' => url('admin/user/configure/permission'), '%nodeconfigurl' => url('admin/node/configure/defaults')));                  <p>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 <em>add attachments</em> permission.  These permissions can be set on the <a href="@permissionurl">permissions</a> page.  Second, attachments must be enabled for that particular node type.  You can enable attachments to nodes in the workflow section of each <a href="@nodeconfigurl">node type</a>.</p>', array('@permissionurl' => url('admin/user/access', NULL, 'module-attachment'), '@nodeconfigurl' => url('admin/content/types')));
226     }     }
227  }  }
228    
# Line 197  function attachment_link($type, $node = Line 237  function attachment_link($type, $node =
237        if ($main == 1 && !variable_get('attachment_display_teaser', 0)) {        if ($main == 1 && !variable_get('attachment_display_teaser', 0)) {
238          $count = _attachment_countvisible($node);          $count = _attachment_countvisible($node);
239          if ($count > 0) {          if ($count > 0) {
240            $links[] = l(format_plural($count, 'attachment', '%count attachments'), "node/$node->nid", array('title' => t('View attachment list')), NULL, "attachments");            $links['attachment_tease_links'] = array(
241                'title' => format_plural($count, '1 attachment', '@count attachments'),
242                'href' => "node/$node->nid",
243                'attributes' => array('title' => t('View attachment list')),
244                'fragment' => "attachments",
245              );
246          }          }
247        }        }
248        break;        break;
# Line 220  function _attachment_countvisible($node) Line 265  function _attachment_countvisible($node)
265    return $count;    return $count;
266  }  }
267    
268    /**
269     * Theme the attachment form
270     */
271  function theme_attachment_form($form) {  function theme_attachment_form($form) {
272    $output = '';    $output = '';
273    $header = array(    $header = array(
# Line 233  function theme_attachment_form($form) { Line 281  function theme_attachment_form($form) {
281    foreach (element_children($form) as $key) {    foreach (element_children($form) as $key) {
282      if ($key{0} != 'c') {      if ($key{0} != 'c') {
283        $row = array();        $row = array();
284        $row[0]['data'] = form_render($form[$key]['display']);        $row[0]['data'] = drupal_render($form[$key]['display']);
285        $row[0]['colspan'] = '4';        $row[0]['colspan'] = '4';
286        $rows[] = $row;        $rows[] = $row;
287        $row = array(        $row = array(
288          form_render($form[$key]['deleted']),          drupal_render($form[$key]['deleted']),
289          form_render($form[$key]['hidden']),          drupal_render($form[$key]['hidden']),
290          form_render($form[$key]['title']),          drupal_render($form[$key]['title']),
291          form_render($form[$key]['description']),          drupal_render($form[$key]['description']),
292        );        );
293        $rows[] = $row;        $rows[] = $row;
294      }      }
# Line 250  function theme_attachment_form($form) { Line 298  function theme_attachment_form($form) {
298      $output .= theme('table', $header, $rows);      $output .= theme('table', $header, $rows);
299    }    }
300    
301    $output .= form_render($form);    $output .= drupal_render($form);
302    
303    return $output;    return $output;
304  }  }
# Line 377  function theme_attachments($node) { Line 425  function theme_attachments($node) {
425    
426    foreach ((array)$node->attachments as $attachment) {    foreach ((array)$node->attachments as $attachment) {
427      if (!$attachment['hidden'] && !$attachment['deleted']) {      if (!$attachment['hidden'] && !$attachment['deleted']) {
428        $text = empty($attachment['title']) ? $attachment['filename'] : ($attachment['title'] . ' (' . $attachment['filename'] . ')');        // By default, title is set to filename.  The strcmp below avoids showing "filename (filename)"
429          // which is ugly and redundant.
430          $text = (empty($attachment['title'])) || (strcmp($attachment['title'], $attachment['filename']) == 0)
431                  ? $attachment['filename']
432                  : ($attachment['title'] . ' (' . $attachment['filename'] . ')');
433        $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']);        $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']);
434        $row[0]['data'] = l($text, module_invoke('filemanager', 'url', $attachment['fid']), $attrib);        $row[0]['data'] = l($text, module_invoke('filemanager', 'url', $attachment['fid']), $attrib);
435        $row[0]['data'] = module_invoke('filemanager', 'l', $text, $attachment['fid'], FALSE, $attrib, TRUE);        $row[0]['data'] = module_invoke('filemanager', 'l', $text, $attachment['fid'], FALSE, $attrib, TRUE);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.2