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

Diff of /contributions/modules/audio/audio.module

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

revision 1.135 by drewish, Wed May 14 03:54:56 2008 UTC revision 1.136 by drewish, Sun May 25 17:21:26 2008 UTC
# Line 10  if (module_exists('views')) { Line 10  if (module_exists('views')) {
10  /**  /**
11   * Implementation of hook_help().   * Implementation of hook_help().
12   */   */
13  function audio_help($section) {  function audio_help($section, $arg) {
14    switch ($section) {    switch ($section) {
15      case 'audio/by':      case 'audio/by':
16        return t("You can browse for audio by any of the following fields.");        return t("You can browse for audio by any of the following fields.");
# Line 52  function audio_help($section) { Line 52  function audio_help($section) {
52  /**  /**
53   * Implementation of hook_menu().   * Implementation of hook_menu().
54   */   */
55  function audio_menu($may_cache) {  function audio_menu() {
56    $items = array();    $items = array();
57    
58    if ($may_cache) {    $items['admin/settings/audio'] = array(
59      $items[] = array(      'title' => 'Audio settings',
60        'path' => 'admin/settings/audio', 'title' => t('Audio settings'),      'description' => 'Change settings for the audio module.',
61        'callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
62        'callback arguments' => array('audio_admin_settings'),      'page arguments' => array('audio_admin_settings'),
63        'access' => user_access('administer site configuration'),      'access arguments' => array('administer site configuration'),
64        'type' => MENU_NORMAL_ITEM,      'file' => 'audio.admin.inc',
65        'description' => t('Change settings for the audio module.'),    );
66      );    $items['admin/settings/audio/main'] = array(
67      $items[] = array(      'title' => 'Audio',
68        'path' => 'admin/settings/audio/main', 'title' => t('Audio'),      'page callback' => 'drupal_get_form',
69        'callback' => 'drupal_get_form',      'page arguments' => array('audio_admin_settings'),
70        'callback arguments' => array('audio_admin_settings'),      'type' => MENU_DEFAULT_LOCAL_TASK,
71        'type' => MENU_DEFAULT_LOCAL_TASK,      'weight' => '-10',
72        'weight' => '-10',      'file' => 'audio.admin.inc',
73      );    );
74      $items[] = array(    $items['admin/settings/audio/metadata'] = array(
75        'path' => 'admin/settings/audio/metadata', 'title' => t('Metadata tags'),      'title' => 'Metadata tags',
76        'callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
77        'callback arguments' => array('audio_admin_settings_metadata'),      'page arguments' => array('audio_admin_settings_metadata'),
78        'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
79      );      'file' => 'audio.admin.inc',
80      $items[] = array(    );
81        'path' => 'admin/settings/audio/players', 'title' => t('Players'),    $items['admin/settings/audio/players'] = array(
82        'callback' => 'drupal_get_form',      'title' => 'Players',
83        'callback arguments' => array('audio_admin_settings_players'),      'page callback' => 'drupal_get_form',
84        'type' => MENU_LOCAL_TASK,      'page arguments' => array('audio_admin_settings_players'),
85      );      'type' => MENU_LOCAL_TASK,
86        'file' => 'audio.admin.inc',
87      $items[] = array(    );
88        'path' => 'audio/autocomplete',  
89        'callback' => 'audio_autocomplete',    $items['audio/autocomplete'] = array(
90        'access' => user_access('access content'),      'page callback' => 'audio_autocomplete',
91        'type' => MENU_CALLBACK,      'access arguments' => array('access content'),
92      );      'type' => MENU_CALLBACK,
93      $items[] = array(    );
94        'path' => 'audio/by', 'title' => t('Browse by...'),    $items['audio/by'] = array(
95        'access' => user_access('access content'),      'title' => 'Browse by...',
96        'type' => MENU_NORMAL_ITEM,      'page callback' => 'audio_page_browse_by',
97        'callback' => 'audio_page_browse_by',      'access arguments' => array('access content'),
98      );      'type' => MENU_NORMAL_ITEM,
99      );
100    
101      $items['audio/download'] = array(
102        'page callback' => 'audio_download',
103        'access arguments' => array('access content'),
104        'type' => MENU_CALLBACK,
105      );
106      $items['audio/play'] = array(
107        'page callback' => 'audio_play',
108        'access arguments' => array('access content'),
109        'type' => MENU_CALLBACK,
110      );
111    
     $items[] = array(  
       'path' => 'audio/download',  
       'access' => user_access('access content'),  
       'type' => MENU_CALLBACK,  
       'callback' => 'audio_download',  
     );  
     $items[] = array(  
       'path' => 'audio/play',  
       'access' => user_access('access content'),  
       'type' => MENU_CALLBACK,  
       'callback' => 'audio_play',  
     );  
   }  
112    return $items;    return $items;
113  }  }
114    
115  /**  /**
116     * Implementation of hook_theme
117     */
118    function audio_theme() {
119      return array(
120        'audio_file_form' => array(
121          'arguments' => array('form'),
122        ),
123        'audio_admin_settings_metadata' => array(
124          'arguments' => array('form_element'),
125          'file' => 'audio.admin.inc',
126        ),
127        'audio_admin_settings_players' => array(
128          'arguments' => array('form_element'),
129          'file' => 'audio.admin.inc',
130        ),
131        'audio_default_node_player' => array(
132          'arguments' => array('node'),
133        ),
134        'audio_teaser' => array(
135          'arguments' => array('node'),
136        ),
137        'audio_display' => array(
138          'arguments' => array('node'),
139        ),
140        'audio_format_tag' => array(
141          'arguments' => array('tag', 'value', 'setting'),
142        ),
143        'audio_format_filelength' => array(
144          'arguments' => array('fileinfo'),
145        ),
146        'audio_format_fileformat' => array(
147          'arguments' => array('fileinfo'),
148        ),
149      );
150    }
151    
152    /**
153   * Implementation of hook_node_info().   * Implementation of hook_node_info().
154   */   */
155  function audio_node_info() {  function audio_node_info() {
# Line 277  function audio_cron() { Line 313  function audio_cron() {
313    }    }
314  }  }
315    
   
   
316  /**  /**
317   * Implementation of hook_link().   * Implementation of hook_link().
318   */   */
# Line 396  function audio_validate(&$node, &$form) Line 430  function audio_validate(&$node, &$form)
430      $node->title_format = variable_get('audio_default_title_format', '[audio-tag-title-raw] by [audio-tag-artist-raw]');      $node->title_format = variable_get('audio_default_title_format', '[audio-tag-title-raw] by [audio-tag-artist-raw]');
431    }    }
432    $node->title = token_replace($node->title_format, 'node', $node);    $node->title = token_replace($node->title_format, 'node', $node);
433    form_set_value($form['title'], $node->title);    $form_state['values']['title'] = $node->title; // FIXME
434  }  }
435    
436  /**  /**
# Line 429  function audio_load($node) { Line 463  function audio_load($node) {
463    
464      if (file_exists($fields['file_path'])) {      if (file_exists($fields['file_path'])) {
465        // TODO: should these links be by vid?        // TODO: should these links be by vid?
466        $ret['url_play'] = url('audio/play/'. $node->nid, NULL, NULL, TRUE);        $ret['url_play'] = url('audio/play/'. $node->nid, array('absolution' => TRUE));
467        if ($ret['audio_file']['downloadable']) {        if ($ret['audio_file']['downloadable']) {
468          // iTunes and other podcasting programs check the url to determine the          // iTunes and other podcasting programs check the url to determine the
469          // file type. we'll add the original file name on to the end. see issues          // file type. we'll add the original file name on to the end. see issues
470          // #35398 and #68716 for more info.          // #35398 and #68716 for more info.
471          $url = 'audio/download/'. $node->nid .'/'. $fields['file_name'];          $url = 'audio/download/'. $node->nid .'/'. $fields['file_name'];
472          $ret['url_download'] = url($url , NULL, NULL, TRUE);          $ret['url_download'] = url($url, array('absolute' => TRUE));
473        }        }
474      }      }
475    
# Line 456  function audio_load($node) { Line 490  function audio_load($node) {
490   * Implementation of hook_insert().   * Implementation of hook_insert().
491   */   */
492  function audio_insert(&$node) {  function audio_insert(&$node) {
493      drupal_set_message('Hammy hoo...?');
494    file_move($node->audio_file['file_path'], audio_get_directory(), FILE_EXISTS_RENAME);    file_move($node->audio_file['file_path'], audio_get_directory(), FILE_EXISTS_RENAME);
495    
496    // Notify other modules.    // Notify other modules.
# Line 490  function audio_insert_revision($node) { Line 525  function audio_insert_revision($node) {
525    audio_invoke_audioapi('insert revision', $node);    audio_invoke_audioapi('insert revision', $node);
526    
527    $f = $node->audio_file;    $f = $node->audio_file;
528    db_query("INSERT INTO {audio} (vid, nid, title_format, play_count, download_count, downloadable, file_format, file_name, file_path, file_mime, file_size, bitrate, bitrate_mode, sample_rate, channel_mode, playtime)    db_query("INSERT INTO {audio} (vid, nid, title_format, downloadable, file_format, file_name, file_path, file_mime, file_size, bitrate, bitrate_mode, sample_rate, channel_mode, playtime)
529      VALUES (%d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', %d, %f, '%s', %d, '%s', '%s')",      VALUES (%d, %d, '%s', %d, '%s', '%s', '%s', '%s', %d, %f, '%s', %d, '%s', '%s')",
530      $node->vid, $node->nid, $node->title_format, $f['play_count'], $f['download_count'], $f['downloadable'], $f['file_format'], $f['file_name'], $f['file_path'], $f['file_mime'], filesize($f['file_path']), $f['bitrate'], $f['bitrate_mode'], $f['sample_rate'], $f['channel_mode'], $f['playtime']);      $node->vid, $node->nid, $node->title_format, $f['downloadable'], $f['file_format'], $f['file_name'], $f['file_path'], $f['file_mime'], filesize($f['file_path']), $f['bitrate'], $f['bitrate_mode'], $f['sample_rate'], $f['channel_mode'], $f['playtime']);
531    
532    _audio_save_tags_to_db($node);    _audio_save_tags_to_db($node);
533  }  }
# Line 575  function audio_prepare(&$node) { Line 610  function audio_prepare(&$node) {
610    // We need to be aware that a user may try to edit multiple audio nodes at    // We need to be aware that a user may try to edit multiple audio nodes at
611    // once. By using the $nid variable each node's files can be stored separately    // once. By using the $nid variable each node's files can be stored separately
612    // in the session.    // in the session.
613    $nid = ($node->nid) ? $node->nid : 'new_node';    $nid = empty($node->nid) ? 'new_node' : $node->nid;
614    // When you enter the edit view the first time we need to clear our files in    // When you enter the edit view the first time we need to clear our files in
615    // session for this node. This is so if you upload a file, then decide you    // session for this node. This is so if you upload a file, then decide you
616    // don't want it and reload the form (without posting), the files will be    // don't want it and reload the form (without posting), the files will be
# Line 585  function audio_prepare(&$node) { Line 620  function audio_prepare(&$node) {
620    }    }
621    
622    // Check for an upload.    // Check for an upload.
623    if ($file = file_check_upload('audio_upload')) {    $validators = array(
624      // Check for valid file extensions...      'file_validate_extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'),
625      $extensions = variable_get('audio_allowed_extensions', 'mp3 wav ogg');    );
626      $regex = '/\.('. ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';    if ($file = file_save_upload('audio_upload', $validators)) {
627      if (!preg_match($regex, $file->filename)) {      file_copy($file, 'files/audio/'. $file->filename, FILE_EXISTS_REPLACE);
628        //set an error message and delete the the file      $node->audio_file = array(
629        form_set_error('audio', t('The selected file %name can not be uploaded, because it is only possible to upload files with the following extensions: %files-allowed.', array('%name' => $file->filename, '%files-allowed' => $extensions)));        'newfile' => TRUE,
630        file_delete($file->filepath);        'play_count' => 0,
631      }        'download_count' => 0,
632      else {        'downloadable' => (bool) $_POST['audio_file']['downloadable'],
633        // Save the upload into Drupal's temp directory.        'file_name' => $file->filename,
634        $temppath = file_directory_temp() .'/audio/';        'file_path' => $file->filepath,
635        file_check_directory($temppath, TRUE);        'file_mime' => $file->filemime,
636          'file_size' => filesize($node->audio_file['file_path']),
637        $file = file_save_upload($file, $temppath .'/'. $file->filename, FILE_EXISTS_REPLACE);      );
638        $node->audio_file = array(  
639          'newfile' => TRUE,      // Allow other modules to modify the node.
640          'play_count' => $node->audio_file['play_count'],      audio_invoke_audioapi('upload', $node);
641          'download_count' => $node->audio_file['download_count'],  
642          'downloadable' => (bool) $_POST['audio_file']['downloadable'],      // ...save info to $_POST so that it shows up in both the preview and
643          'file_name' => $file->filename,      // form. Note that we do this after calling we called our api hook with
644          'file_path' => $file->filepath,      // the upload operation, it gives the audio_id3 module a chance to read
645          'file_mime' => $file->filemime,      // the tags.
646          'file_size' => filesize($node->audio_file['file_path']),      $_POST['audio_file'] = $node->audio_file;
647        );      $_POST['audio_tags'] = $node->audio_tags;
   
       // Allow other modules to modify the node.  
       audio_invoke_audioapi('upload', $node);  
   
       // ...save info to $_POST so that it shows up in both the preview and  
       // form. Note that we do this after calling we called our api hook with  
       // the upload operation, it gives the audio_id3 module a chance to read  
       // the tags.  
       $_POST['audio_file'] = $node->audio_file;  
       $_POST['audio_tags'] = $node->audio_tags;  
648    
649        $_SESSION['audio_new_file'][$nid] = $node->audio_file['file_path'];      $_SESSION['audio_new_file'][$nid] = $node->audio_file['file_path'];
     }  
650    }    }
651    // Assign a newly uploaded file that's being previewed.    // Assign a newly uploaded file that's being previewed.
652    else if (isset($_SESSION['audio_new_file'][$nid])) {    else if (isset($_SESSION['audio_new_file'][$nid])) {
# Line 670  function audio_form(&$node) { Line 694  function audio_form(&$node) {
694    }    }
695    
696    $form['#attributes'] = array('enctype' => 'multipart/form-data');    $form['#attributes'] = array('enctype' => 'multipart/form-data');
697    
698      if (empty($node->nid)) {
699        $node->audio_file = array(
700          'file_path' => '',
701          'file_name' => '',
702          'file_mime' => '',
703        );
704      }
705    
706    $form['audio_file'] = array(    $form['audio_file'] = array(
707      '#type' => 'fieldset',      '#type' => 'fieldset',
708      '#title' => t('Audio File Info'),      '#title' => t('Audio File Info'),
# Line 700  function audio_form(&$node) { Line 733  function audio_form(&$node) {
733    $form['audio_file']['display_file_path'] = array(    $form['audio_file']['display_file_path'] = array(
734      '#type' => 'item',      '#type' => 'item',
735      '#title' => t('Current File'),      '#title' => t('Current File'),
736      '#value' => isset($file_path) ? $file_path : t('No file is attached.'),      '#value' => !empty($file_path) ? $file_path : t('No file is attached.'),
737    );    );
738    
739    // If we've got a file, add the file information fields.    // If we've got a file, add the file information fields.
740    if (isset($node->audio_file)) {    if (!empty($node->audio_file['file_name'])) {
741      $form['audio_file']['#theme'] = 'audio_file_form';      $form['audio_file']['#theme'] = 'audio_file_form';
742      $form['audio_file']['file_format'] = array(      $form['audio_file']['file_format'] = array(
743        '#type' => 'select',        '#type' => 'select',
# Line 773  function audio_form(&$node) { Line 806  function audio_form(&$node) {
806    $form['audio_file']['audio_upload'] = array(    $form['audio_file']['audio_upload'] = array(
807      '#tree' => FALSE,      '#tree' => FALSE,
808      '#type' => 'file',      '#type' => 'file',
809      '#title' => !isset($node->audio_file) ? t('Add a new audio file') : t('Replace this with a new file'),      '#title' => empty($node->audio_file['file_name']) ? t('Add a new audio file') : t('Replace this with a new file'),
810      '#description' => t('Click "Browse..." to select an audio file to upload. Only files with the following extensions are allowed: %allowed-extensions.', array('%allowed-extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'))) .'<br />'      '#description' => t('Click "Browse..." to select an audio file to upload. Only files with the following extensions are allowed: %allowed-extensions.', array('%allowed-extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'))) .'<br />'
811        . t('<strong>NOTE:</strong> the current PHP configuration limits uploads to %maxsize.', array('%maxsize' => format_size(file_upload_max_size()))),        . t('<strong>NOTE:</strong> the current PHP configuration limits uploads to %maxsize.', array('%maxsize' => format_size(file_upload_max_size()))),
812    );    );
813    $form['audio_file']['downloadable'] = array(    $form['audio_file']['downloadable'] = array(
814      '#type' => 'checkbox',      '#type' => 'checkbox',
815      '#title' => t('Allow file downloads.'),      '#title' => t('Allow file downloads.'),
816      '#default_value' => isset($node->audio_file['downloadable']) ? $node->audio_file['downloadable'] : variable_get('audio_default_downloadable', 1),      '#default_value' => !empty($node->audio_file['downloadable']) ? $node->audio_file['downloadable'] : variable_get('audio_default_downloadable', 1),
817      '#description' => t('If checked, a link will be displayed allowing visitors to download this audio file on to their own computer.') .'<br />'      '#description' => t('If checked, a link will be displayed allowing visitors to download this audio file on to their own computer.') .'<br />'
818        . t('<strong>WARNING:</strong> even if you leave this unchecked, clever users will be able to find a way to download the file. This just makes them work a little harder to find the link.'),        . t('<strong>WARNING:</strong> even if you leave this unchecked, clever users will be able to find a way to download the file. This just makes them work a little harder to find the link.'),
819    );    );
820    
821    
822    // If we've got a file, add the fields for editing meta data.    // If we've got a file, add the fields for editing meta data.
823    if (isset($node->audio_file)) {    if (!empty($node->audio_file)) {
824      $form['audio_tags'] = array(      $form['audio_tags'] = array(
825        '#type' => 'fieldset',        '#type' => 'fieldset',
826        '#title' => t('Audio Metadata'),        '#title' => t('Audio Metadata'),
# Line 797  function audio_form(&$node) { Line 830  function audio_form(&$node) {
830      );      );
831      // Delegate out the dirty work of building form elements.      // Delegate out the dirty work of building form elements.
832      foreach (audio_get_tag_settings() as $tag => $tag_settings) {      foreach (audio_get_tag_settings() as $tag => $tag_settings) {
833        $form['audio_tags'][$tag] = _audio_build_tag_form($tag, $tag_settings, $node->audio_tags[$tag]);        $form['audio_tags'][$tag] = _audio_build_tag_form($tag, $tag_settings,
834            empty($node->audio_tags) ? '' : $node->audio_tags[$tag]);
835      }      }
836    }    }
837    
838      // Register the submit hander.
839      $form['#submit'][] = 'audio_node_submit';
840    return $form;    return $form;
841  }  }
842    
# Line 809  function audio_form(&$node) { Line 845  function audio_form(&$node) {
845   * the watchdog module.   * the watchdog module.
846   */   */
847  function theme_audio_file_form($form) {  function theme_audio_file_form($form) {
848    // List of elements to leave out of the table.    // List of elements to leave out of the table.
849    $skip_list = array('audio_upload' => 1, 'downloadable' => 1);    $skip_list = array('audio_upload' => 1, 'downloadable' => 1);
850    
851    $rows = array();    $rows = array();
# Line 871  function _audio_build_tag_form($tag, $ta Line 907  function _audio_build_tag_form($tag, $ta
907  }  }
908    
909  /**  /**
910   * Implementation of hook_submit().   * Node submit handler
911   */   */
912  function audio_submit(&$node) {  function audio_node_submit($form, &$form_state) {
913    // If a new file was stored in the session move it into the $node.    // If a new file was stored in the session move it into the $form_state.
914    $nid = ($node->nid) ? $node->nid : 'new_node';    $nid = ($form_state['values']['nid']) ? $form_state['values']['nid'] : 'new_node';
915    if (isset($_SESSION['audio_new_file'][$nid])) {    if (isset($_SESSION['audio_new_file'][$nid])) {
916      $node->audio_file['file_path'] = $_SESSION['audio_new_file'][$nid];      $form_state['values']['audio_file']['file_path'] = $_SESSION['audio_new_file'][$nid];
917      $node->audio_file['newfile'] = TRUE;      $form_state['values']['audio_file']['newfile'] = TRUE;
918      unset($_SESSION['audio_new_file'][$nid]);      unset($_SESSION['audio_new_file'][$nid]);
919    }    }
920    audio_invoke_audioapi('submit', $node);    audio_invoke_audioapi('submit', $node);
# Line 933  function audio_block($op = 'list', $delt Line 969  function audio_block($op = 'list', $delt
969    }    }
970  }  }
971    
   
 /**  
  * Settings form.  
  */  
 function audio_admin_settings() {  
   $form['audio_default_title_format'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Default node title format'),  
     '#maxlength' => 128,  
     '#default_value' => variable_get('audio_default_title_format', '[audio-tag-title-raw] by [audio-tag-artist-raw]'),  
     '#description' => t("The audio node's title can use the file's metadata as variables. This will be used as the default title for all new audio nodes. By using the tokens listed below, you can automatically create titles from things like a song's artist or title. <strong>Note:</strong> the node title is escaped so it is safe to use the -raw tokens."),  
   );  
   $form['audio_teaser_format'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Node teaser format'),  
     '#maxlength' => 128,  
     '#default_value' => variable_get('audio_teaser_format', '[audio-player]<br />[audio-length]'),  
     '#description' => t("Use this setting to customize the teasers for audio nodes. Using the tokens listed below you can select what information about the file will be displayed. <strong>Note: the teaser is not escaped so it is unsafe to use the -raw tokens.</strong>"),  
   );  
   $form['token_help'] = array(  
     '#title' => t('List of available tokens'),  
     '#type' => 'fieldset',  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
     '#description' => t('This is a list of the tokens that can be used in the titles and teasers of audio nodes.'),  
     'help' => array('#value' => theme('token_help', 'node')),  
   );  
   $form['audio_allowed_extensions'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Permitted audio file extensions'),  
     '#maxlength' => 128,  
     '#default_value' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'),  
     '#description' => t('Audio file extensions that users can upload. Separate extensions with a space and do not include a leading dot.'),  
   );  
   $form['audio_default_downloadable'] = array(  
     '#type' => 'checkbox',  
     '#title' => t("Downloadable by default"),  
     '#default_value' => variable_get('audio_default_downloadable', 1),  
     '#description' => t('Check this to make downloadable the default setting for new audio nodes. You should be aware that even when audio is not marked as downloadable, clever users can still download it, this just makes the work harder. '),  
   );  
   
   return system_settings_form($form);  
 }  
   
 function audio_admin_settings_validate($form_id, $form_values) {  
   // Ensure they don't try to slip raw tokens in.  
   if (preg_match("/\[.*?\-raw\s*?\]/i", $form_values['audio_teaser_format'])) {  
     form_set_error('audio_teaser_format', t('Raw tokens are not allowed.'));  
   }  
 }  
   
 /**  
  * The ID3 tag settings page.  
  */  
 function audio_admin_settings_metadata() {  
   $settings = audio_get_tag_settings();  
   $form['audio_tag_settings'] = array('#tree' => TRUE);  
   foreach ($settings as $tag => $setting) {  
     $form['audio_tag_settings'][$tag]['name'] = array(  
       '#type' => 'item',  
       '#value' => $tag  
     );  
     $form['audio_tag_settings'][$tag]['autocomplete'] = array(  
       '#type' => 'checkbox',  
       '#default_value' => $setting['autocomplete']  
     );  
     $form['audio_tag_settings'][$tag]['required'] = array(  
       '#type' => 'checkbox',  
       '#default_value' => $setting['required'],  
     );  
     $form['audio_tag_settings'][$tag]['hidden'] = array(  
       '#type' => 'checkbox',  
       '#default_value' => $setting['hidden'],  
     );  
     $form['audio_tag_settings'][$tag]['browsable'] = array(  
       '#type' => 'checkbox',  
       '#default_value' => $setting['browsable'],  
     );  
     $form['audio_tag_settings'][$tag]['writetofile'] = array(  
       '#type' => 'checkbox',  
       '#default_value' => $setting['writetofile'],  
     );  
     $form['audio_tag_settings'][$tag]['weight'] = array(  
       '#type' => 'weight',  
       '#default_value' => $setting['weight']  
     );  
   }  
   $delete_options = array();  
   foreach ($settings as $tag => $setting) {  
     $delete_options[$tag] = '';  
   }  
   $form['delete'] = array(  
     '#type' => 'checkboxes',  
     '#options' => $delete_options,  
   );  
   
   // Add in a row for a new tag.  
   $form['audio_tag_settings']['new']['name'] = array(  
     '#type' => 'textfield',  
     '#size' => 15,  
     '#maxlength' => 45,  
   );  
   $form['audio_tag_settings']['new']['autocomplete'] = array(  
     '#type' => 'checkbox',  
     '#default_value' => TRUE,  
   );  
   $form['audio_tag_settings']['new']['required'] = array(  
     '#type' => 'checkbox',  
     '#default_value' => FALSE,  
   );  
   $form['audio_tag_settings']['new']['hidden'] = array(  
     '#type' => 'checkbox',  
     '#default_value' => FALSE,  
   );  
   $form['audio_tag_settings']['new']['browsable'] = array(  
     '#type' => 'checkbox',  
     '#default_value' => TRUE,  
   );  
   $form['audio_tag_settings']['new']['writetofile'] = array(  
     '#type' => 'checkbox',  
     '#default_value' => FALSE,  
   );  
   $form['audio_tag_settings']['new']['weight'] = array(  
     '#type' => 'weight',  
     '#default_value' => 0,  
   );  
   
   return system_settings_form($form);  
 }  
   
 /**  
  * Save the ID3 tag settings, we can't use system_settings_form_submit() as the  
  * form callback because it wouldn't call theme_audio_settings().  
  */  
 function audio_admin_settings_metadata_submit($form_id, $form_values) {  
   $op = isset($_POST['op']) ? $_POST['op'] : '';  
   
   if ($op == t('Reset to defaults')) {  
     variable_del('audio_tag_settings');  
     drupal_set_message(t('The configuration options have been reset to their default values.'));  
   }  
   else {  
     // Remove any deleted tags.  
     foreach ($form_values['delete'] as $field) {  
       if ($field) {  
         unset($form_values['audio_tag_settings'][$field]);  
       }  
     }  
     // If there's a new tag, add it in.  
     if ($form_values['audio_tag_settings']['new']['name']) {  
       $name = $form_values['audio_tag_settings']['new']['name'];  
       $form_values['audio_tag_settings'][$name] = $form_values['audio_tag_settings']['new'];  
     }  
     unset($form_values['audio_tag_settings']['new']);  
   
     // Sort by the weight and then by name of the tag. I'm sure there's a  
     // better way to do this...  
     foreach ($form_values['audio_tag_settings'] as $tag => $settings) {  
       $weights[$tag] = $settings['weight'];  
       $names[$tag] = $tag;  
     }  
     array_multisort($weights, SORT_ASC, SORT_NUMERIC, $names, SORT_ASC, SORT_STRING);  
     $audio_tag_settings = array();  
     foreach ($names as $tag) {  
       $audio_tag_settings[$tag] = $form_values['audio_tag_settings'][$tag];  
     }  
   
     // ...and save it.  
     variable_set('audio_tag_settings', $audio_tag_settings);  
   
     drupal_set_message(t('The configuration options have been saved.'));  
   }  
 }  
   
 /**  
  * Format the id3tags settings form as a table.  
  */  
 function theme_audio_admin_settings_metadata($form) {  
   $rows = array();  
   foreach (element_children($form['audio_tag_settings']) as $key) {  
     $row = array();  
     if (is_array($form['audio_tag_settings'][$key]['name'])) {  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['name']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['autocomplete']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['required']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['hidden']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['browsable']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['writetofile']);  
       $row[] = drupal_render($form['audio_tag_settings'][$key]['weight']);  
   
       $row[] = drupal_render($form['delete'][$key]);  
     }  
     $rows[] = $row;  
   }  
   $header = array(t('Tag'), t('Autocompleted'), t('Required'), t('Hidden'), t('Browsable'),  
     t('Written to file'), t('Weight'), t('Delete'));  
   
   $output = theme('table', $header, $rows);  
   $output .= drupal_render($form);  
   return $output;  
 }  
   
 /**  
  * Form for player settings.  
  */  
 function audio_admin_settings_players() {  
   $form = array();  
   
   $options = array();  
   foreach (audio_get_players('formats') as $format => $players) {  
     foreach ($players as $id => $player) {  
       $options[$id] = $player['title'];  
       $form['players'][$format][$id]['description'] = array(  
         '#type' => 'item',  
         '#title' => t('Description'),  
         '#value' => $player['description'],  
       );  
       $form['players'][$format][$id]['url'] = array(  
         '#type' => 'item',  
         '#title' => t('URL'),  
         '#value' => $player['url'],  
       );  
       $form['players'][$format][$id]['preview'] = array(  
         '#type' => 'item',  
         '#title' => t('URL'),  
         '#value' => drupal_get_path('module', $player['module']) .'/'. $player['preview'],  
       );  
     }  
     $form['audio_player_'. $format] = array(  
       '#type' => 'radios',  
       '#title' => t('Player'),  
       '#default_value' => variable_get('audio_player_'. $format, '1pixelout'),  
       '#options' => $options,  
     );  
   }  
   return system_settings_form($form);  
 }  
   
 function theme_audio_admin_settings_players($form) {  
   $output = '';  
   $header = array(t('Player'), t('Description'), t('Homepage'));  
   foreach (element_children($form['players']) as $format) {  
     $output .= '<h2>'. t('%format files', array('%format' => $format)) .'</h2>';  
     $rows = array();  
     foreach (element_children($form['players'][$format]) as $name) {  
       $rows[] = array(  
         drupal_render($form['audio_player_'. $format][$name])  
           . theme('image', $form['players'][$format][$name]['preview']['#value'], 'preview', 'preview'),  
         check_plain($form['players'][$format][$name]['description']['#value']),  
         l(t('Link'), $form['players'][$format][$name]['url']['#value']),  
       );  
       unset($form['players'][$format][$name]['description']);  
       unset($form['players'][$format][$name]['url']);  
       unset($form['players'][$format][$name]['preview']);  
     }  
     unset($form['audio_player_'. $format]);  
     $output .= theme('table', $header, $rows);  
   }  
   return $output . drupal_render($form);  
 }  
   
972  /**  /**
973   * Get an array of the allowed tags.   * Get an array of the allowed tags.
974   *   *

Legend:
Removed from v.1.135  
changed lines
  Added in v.1.136

  ViewVC Help
Powered by ViewVC 1.1.3