Index: audio.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v
retrieving revision 1.89
diff -u -r1.89 audio.module
--- audio.module 12 Dec 2006 00:28:11 -0000 1.89
+++ audio.module 12 Dec 2006 21:30:29 -0000
@@ -4,6 +4,7 @@
include(drupal_get_path('module', 'audio') .'/audio_theme.inc');
if (module_exists('views')) {
include(drupal_get_path('module', 'audio') .'/views_audio.inc');
+ include(drupal_get_path('module', 'audio') .'/views_defaults.inc');
}
/**
@@ -82,7 +83,12 @@
'path' => 'admin/settings/audio/metadata', 'title' => t('Metadata tags'),
'callback' => 'drupal_get_form',
'callback arguments' => array('audio_admin_settings_metadata'),
- 'type' => MENU_LOCAL_TASK, 'weight' => '-1');
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/audio/players', 'title' => t('Players'),
+ 'callback' => 'drupal_get_form',
+ 'callback arguments' => array('audio_admin_settings_players'),
+ 'type' => MENU_LOCAL_TASK);
$items[] = array(
'path' => 'audio', 'title' => t('Audio'),
@@ -1107,6 +1113,83 @@
}
/**
+ * 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('autocomplete'), 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;
+}
+
+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['audio_player_'. $format] = array(
+ '#type' => 'radios',
+ '#title' => t('Player'),
+ '#default_value' => variable_get('audio_player_'. $format, 'xspf_button'),
+ '#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 .= '
'. t('%format files', array('%format' => $format)) .'
';
+ $rows = array();
+ foreach (element_children($form['players'][$format]) as $name) {
+ $rows[] = array(
+ drupal_render($form['audio_player_'. $format][$name]),
+ 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['audio_player_'. $format]);
+ $output .= theme('table', $header, $rows);
+ }
+ return $output . drupal_render($form);
+}
+
+/**
* Get an array of the allowed tags.
*
* @return
@@ -1330,7 +1413,6 @@
}
-
/**
* Fetch a random N audio files.
*/
@@ -1355,6 +1437,62 @@
return $output;
}
+function _audio_player_build_list() {
+ // invoke any modules that implement the hook
+ $players_name = module_invoke_all('audio_player');
+
+ // load all our module's player plugins
+ $path = drupal_get_path('module', 'audio') .'/players';
+ $files = drupal_system_listing('.inc$', $path, 'name', 0);
+ foreach ($files as $file) {
+ require_once('./' . $file->filename);
+ $function = 'audio_' . $file->name . '_audio_player';
+ if (function_exists($function)) {
+ $result = $function();
+ if (isset($result) && is_array($result)) {
+ $players_name = array_merge($players_name, $result);
+ }
+ }
+ }
+
+ // group them by format
+ $players_format = array();
+ foreach ($players_name as $name => $player) {
+ foreach ($player['formats'] as $format) {
+ $players_format[$format][$name] = $player;
+ }
+ }
+
+ return array($players_name, $players_format);
+}
+
+function audio_get_players($op = 'names', $name = '') {
+ static $_player_name, $_player_format;
+
+ if (!isset($_players_format)) {
+ list($_player_name, $_player_format) = _audio_player_build_list();
+ }
+
+ switch ($op) {
+ case 'formats':
+ return $_player_format;
+ case 'format':
+ if (isset($_player_format[$name])) {
+ return $_player_format[$name];
+ }
+ return FALSE;
+ case 'names':
+ return $_player_name;
+ case 'name':
+ if (isset($_player_name[$name])) {
+ return $_player_name[$name];
+ }
+ return FALSE;
+ default:
+ return FALSE;
+ }
+}
+
/**
* Build HTML to play an audio node.
*
@@ -1363,16 +1501,22 @@
*/
function audio_get_player($node) {
// if we've got a URL, setup a player
- if (_audio_allow_play($node)) {
- // try to find one that's type specific...
- $format = $node->audio_fileinfo['fileformat'];
- if (!$player = theme('audio_'. $format .'_player', $node)) {
- // ...if that doesn't work out, use the generic one
- $player = theme('audio_player', $node);
- }
- return $player;
+ if (!_audio_allow_play($node)) {
+ return NULL;
+ }
+
+ // try to find one that's type specific...
+ $format = $node->audio_fileinfo['fileformat'];
+ $default_player = variable_get('audio_player_'. $format, 'xspf_button');
+ $players = audio_get_players('format', $format);
+ $player = $players[$default_player];
+
+ $html = theme($player['theme'], $node);
+ if (!$html) {
+ // ...if that doesn't work out, use the generic one
+ $html = theme('audio_player', $node);
}
- return NULL;
+ return $html;
}
/**
@@ -1629,3 +1773,34 @@
}
}
+/**
+ * Generate a XSPF playlist
+ */
+function audio_views_xspf_playlist($title, $nodes) {
+ drupal_set_header('Content-Type: text/xml; charset=utf-8');
+ $output = "\n";
+ $output .= "\n";
+ $output .= " " . $title . "\n";
+ $output .= " \n";
+ foreach ($nodes as $n) {
+ $node = node_load($n->nid);
+ $output .= theme('audio_views_xspf_playlist_track', $node);
+ }
+ $output .= " \n";
+ $output .= "\n";
+ print $output;
+ exit;
+}
+
+function theme_audio_views_xspf_playlist_track($node) {
+ $output .= " \n";
+ return $output;
+}
\ No newline at end of file
Index: audio_theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio_theme.inc,v
retrieving revision 1.2
diff -u -r1.2 audio_theme.inc
--- audio_theme.inc 11 Oct 2006 15:52:12 -0000 1.2
+++ audio_theme.inc 12 Dec 2006 16:37:12 -0000
@@ -181,30 +181,3 @@
return $output;
}
-/**
- * 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('autocomplete'), 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;
-}