[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/audio/contrib/attach/ -> audio_attach.module (source)

   1  <?php
   2  // $Id: audio_attach.module,v 1.11 2009/11/25 19:30:45 drewish Exp $
   3  
   4  /**
   5   * @file audio_attach.module
   6   */
   7  
   8  /**
   9   * Implementation of hook_help().
  10   */
  11  function audio_attach_help($section, $args) {
  12    switch ($section) {
  13      case 'admin/help#audio_attach':
  14        return t('<p>Allows audio files to be attached to any content type.  You can configure which content types by going to admin/content/types.</p>');
  15        break;
  16    }
  17  }
  18  
  19  /**
  20   * Implementation of hook_perm().
  21   */
  22  function audio_attach_perm() {
  23    // FIXME: this isn't used at this point. Need to think about adding a default
  24    // view that's used to limit the attachable nodes and using it to control
  25    // some access.
  26    return array(
  27      'attach any existing audio file'
  28    );
  29  }
  30  
  31  /**
  32   * Implementation of hook_field_formatter_info().
  33   */
  34  function audio_attach_field_formatter_info() {
  35    return array(
  36      'audio_attach' => array(
  37        'label' => t('Attached audio'),
  38        'field types' => array('nodereference'),
  39        'multiple values' => CONTENT_HANDLE_MODULE,
  40      ),
  41    );
  42  }
  43  
  44  /**
  45   * Implementation of hook_theme
  46   */
  47  function audio_attach_theme() {
  48    return array(
  49      'audio_attach_formatter_audio_attach' => array(
  50        'arguments' => array('element' => NULL, 'teaser' => FALSE),
  51      ),
  52    );
  53  }
  54  
  55  
  56  /**
  57   * Theme function for 'attached_audio' nodereference field formatter.
  58   */
  59  function theme_audio_attach_formatter_audio_attach($element, $teaser = FALSE) {
  60    $items = array();
  61  
  62    foreach (element_children($element) as $item) {
  63      if (!empty($element[$item]['#item']['nid'])) {
  64        $audio = node_load($element[$item]['#item']['nid']);
  65        if ($audio->nid) {
  66          $audio = node_prepare($audio, $teaser);
  67          $title = $audio->status ? l($audio->title, 'node/'. $audio->nid, array('html' => TRUE)) : check_plain($audio->title);
  68          $items[] = '<div class="title">'. $title .'</div>'. theme('audio_teaser', $audio);
  69        }
  70      }
  71    }
  72  
  73    if (count($items)) {
  74      drupal_add_css(drupal_get_path('module', 'audio_attach') .'/audio_attach.css');
  75      return theme('item_list', $items, null, 'ol', array('class' => 'audio-attach-list'));
  76    }
  77  
  78    return '';
  79  }
  80  
  81  /**
  82   * Implementation of hook_form_alter()
  83   */
  84  function audio_attach_form_alter(&$form, &$form_state, $form_id) {
  85    switch ($form_id) {
  86      // FIXME: This is broken; I'm not sure what $form['type']['#value'] is
  87      // expected to be, but it certainly doesn't always exist.
  88      // if enabled adjust the form
  89      //case $form['type']['#value'] .'_node_form':
  90      case 'TYPE_node_form':
  91        if (variable_get('audio_attach_'. $form['type']['#value'], 0)) {
  92          $node = $form['#node'];
  93          $form['#attributes'] = array("enctype" => "multipart/form-data");
  94          $form['audio_attach'] = array('#type' => 'fieldset', '#title' => t('Attached audio files'), '#collapsible' => TRUE);
  95  
  96          // Display currently attached files, if any.
  97          if (isset($node->nid)) {
  98            if ($audio_list = _audio_attach_current_list($node->nid)) {
  99              $form['audio_attach']['audio_list'] = array(
 100                '#type' => 'item',
 101                '#prefix' => '<div id="audio-attach-items-table-wrapper">',
 102                '#value' => $audio_list,
 103                '#suffix' => '</div>',
 104              );
 105            }
 106          }
 107  
 108          if ($node->audio_aid) {
 109            $form['audio_attach']['audio_aid'] = array('#type' => 'hidden', '#value' => $node->audio_aid);
 110          }
 111  
 112          // allow existing audio file to be attached
 113          $form['audio_attach']['audio_existing_aid'] = array(
 114            '#type' => 'select',
 115            '#title' => t('Existing audio file'),
 116            '#options' => audio_attach_get_audio_nodes(),
 117            '#description' => t('Choose an audio file already existing on the server if you do not upload a new one.')
 118            );
 119  
 120          $form['audio_attach']['audio_upload'] = array(
 121            '#type' => 'file',
 122            '#title' => t('Upload new audio file'),
 123            '#description' => t('Click "Browse..." to select an audio file to upload. <strong>NOTE:</strong> the current PHP configuration limits uploads to %maxsize. ', array('%maxsize' => format_size(file_upload_max_size()))),
 124          );
 125          $form['audio_attach']['audio_title'] = array(
 126            '#type' => 'textfield',
 127            '#title' => t('Title'),
 128            '#default_value' => variable_get('audio_default_title_format', '[audio-tag-title] by [audio-tag-artist]')
 129          );
 130          $form['audio_attach']['audio_publish'] = array(
 131            '#type' => 'checkbox',
 132            '#title' => t('Published'),
 133            '#return_value' => 1,
 134            '#default_value' => 1,
 135            '#description' => t('If checked, this audio file will be published to the rest of the site.')
 136          );
 137        }
 138        break;
 139    }
 140  }
 141  
 142  /**
 143   * Implementation of hook_nodeapi().
 144   */
 145  function audio_attach_nodeapi(&$node, $op, $teaser, $page) {
 146    global $user;
 147  
 148    if ($node->type == 'audio' || !variable_get("audio_attach_$node->type", 0)) {
 149      return;
 150    }
 151    switch ($op) {
 152      case 'prepare':
 153        // FIXME: just holding onto this until it gets moved.
 154        break;
 155        $audio->title_format = check_plain($_POST['audio_title']);
 156        $audio->status = check_plain($_POST['audio_publish']) ? 1 : 0;
 157        $audio->uid = $user->uid;
 158        $audio->name = $user->name;
 159        $audio->type = 'audio';
 160        audio_prepare($audio);
 161        if ($audio->audio_file) {
 162          // Node validate is throwing errors...
 163          // node_validate($audio);
 164          if (!form_get_errors()) {
 165            $audio = node_submit($audio);
 166            node_save($audio);
 167            $node->audio_aid = $audio->nid;
 168          }
 169        }
 170        break;
 171    }
 172  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7