'Audio Field',
'description' => 'Configure Audiofield.',
'page callback' => 'drupal_get_form',
'page arguments' => array('audiofield_admin_settings_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function audiofield_perm() {
return array('download own audio files' , 'download all audio files');
}
/**
* Implementation of hook_filefield_sources_widgets().
*
* This returns a list of widgets that are compatible with FileField Sources.
*/
function audiofield_filefield_sources_widgets() {
return array('audiofield_widget');
}
function audiofield_admin_settings_form() {
global $base_path;
global $base_url;
$audio_players=audiofield_players();
$players=array();
foreach ($audio_players as $id => $player) {
if (file_exists($player['path'])) {
foreach ($player['filetypes'] as $filetype) {
$players[$filetype][$id] = $player['name'] . '
' . call_user_func($player['callback'], $base_path . $player['path'] , "");
}
}
else{
$download_players .= '
Download ' . l($player['name'], $player['download_link']) . '';
}
}
//MP3 Players list
if (!empty($players)) {
$form['audiofield_audioplayer'] = array(
'#type' => 'radios',
'#title' => t('MP3 Audio Players'),
'#options' => $players['mp3'],
'#default_value' => variable_get('audiofield_audioplayer', 0),
);
}
unset($players['mp3']);
//Other players list (wav, wma,...)
foreach ($players as $filetype => $type_player) {
$form['audiofield_audioplayer_' . $filetype] = array(
'#type' => 'radios',
'#title' => $filetype . t(' Audio Players'),
'#options' => $type_player,
'#default_value' => variable_get('audiofield_audioplayer_' . $filetype, 0),
);
}
$form['audiofield_players_dir'] = array(
'#type' => 'textfield',
'#title' => t('Audio Players Directory'),
'#description' => t('Download and extract audio players in this directory'),
'#default_value' => variable_get('audiofield_players_dir', 'sites/all/libraries/player'),
);
if (!empty($download_players)) {
$form['audiofield_downloadaudioplayer'] = array(
'#type' => 'item',
'#title' => t('Download and install audio players'),
'#value' => '' . $download_players . '
',
);
}
return system_settings_form($form);
}
/**
* Implementation of hook_elements().
*/
function audiofield_elements() {
$elements = array();
$filefield_elements = filefield_elements();
$elements['audiofield_widget'] = $filefield_elements['filefield_widget'];
$elements['audiofield_widget']['#value_callback'] = 'audiofield_widget_value';
return $elements;
}
/**
* Implementation of hook_theme().
*/
function audiofield_theme() {
$theme= array(
'audiofield_widget' => array(
'arguments' => array('element' => NULL),
'file' => 'audiofield_widget.inc',
),
// Themes for the formatters.
'audiofield_formatter_audiofield_embedded' => array(
'arguments' => array('element' => NULL),
'file' => 'audiofield_formatter.inc',
),
// Themes for the players.
'audiofield_players_wpaudioplayer' => array(
'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
),
'audiofield_players_xspf_slim' => array(
'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
),
'audiofield_players_premium_beat_single_track' => array(
'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
),
'audiofield_players_premium_beat_thin' => array(
'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
),
'audiofield_players_premium_beat_mini' => array(
'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
),
);
return $theme;
}
function audiofield_widget_info() {
return array(
'audiofield_widget' => array(
'label' => t('Audio Upload'),
'field types' => array('filefield'),
'multiple values' => CONTENT_HANDLE_CORE,
'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM),
'description' => t('Widget for uploading audios.'),
),
);
}
/**
* Implementation of CCK's hook_widget_settings().
*/
function audiofield_widget_settings($op, $widget) {
switch ($op) {
case 'form':
return audiofield_widget_settings_form($widget);
case 'save':
return audiofield_widget_settings_save($widget);
}
}
/**
* Implementation of CCK's hook_widget().
*
* Assign default properties to item and delegate to audiofield.
*/
function audiofield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
// Start with the audiofield widget as a basic start.
// Note that audiofield needs to modify $form by reference.
$element = filefield_widget($form, $form_state, $field, $items, $delta);
return $element;
}
//==========================================//
// DEFINING A FORMATTER
//==========================================//
/**
* Implementation of hook_field_formatter_info().
*
* All fields should have a 'default' formatter.
* Any number of other formatters can be defined as well.
* It's nice for there always to be a 'plain' option
* for the raw value, but that is not required.
*
*/
function audiofield_field_formatter_info() {
$formatters = array(
'audiofield_embedded' => array(
'label' => t('Audio'),
'field types' => array('filefield'),
'description' => t('Displays audio embedded in a web page.'),
),
);
return $formatters;
}
/**
* Implementation of CCK's hook_default_value().
*/
function audiofield_default_value(&$form, &$form_state, $field, $delta) {
return filefield_default_value($form, $form_state, $field, $delta);
}
/**
* Implementation of hook_form_[form_id]_alter().
*
* Modify the add new field form to change the default formatter.
*/
function audiofield_form_content_field_overview_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'audiofield_form_content_field_overview_submit';
}
/**
* Submit handler to set a new field's formatter to "audiofield_embedded".
*/
function audiofield_form_content_field_overview_submit(&$form, &$form_state) {
if (isset($form_state['fields_added']['_add_new_field']) && isset($form['#type_name'])) {
$new_field = $form_state['fields_added']['_add_new_field'];
$node_type = $form['#type_name'];
$field = content_fields($new_field, $node_type);
if ($field['widget']['module'] == 'audiofield') {
foreach ($field['display_settings'] as $display_type => $display_settings) {
if ($field['display_settings'][$display_type]['format'] == 'default') {
$field['display_settings'][$display_type]['format'] = 'audiofield_embedded';
}
}
content_field_instance_update($field);
}
}
}
/**
* Get the object for the suitable player for the parameter resource
*/
function audiofield_get_player($audio_url, $op) {
global $base_path;
$audio_players=audiofield_players();
$variable_name = 'audiofield_audioplayer' . ($op == 'mp3' ? '' : "_$op");
$player = $audio_players[variable_get($variable_name, '')];
if (empty($player)) {
return audiofield_embeddedplayer($audio_url);
}
return call_user_func($player['callback'], $base_path . $player['path'], $audio_url);
}
/**
* Implementation of hook_audiofield_players().
*/
function audiofield_players() {
$players=module_invoke_all('audiofield_players');
$players['wpaudioplayer']=array(
'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/audio-player/player.swf",
'name' => 'WordPress Audio Player',
'download_link' => 'http://wpaudioplayer.com/download',
'filetypes' => array('mp3'),
'callback' => 'audiofield_wpaudioplayer',
);
$players['xspf_slim']=array(
'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/xspf_player_slim.swf",
'name' => 'XSPF Slim Player',
'download_link' => 'http://sourceforge.net/projects/musicplayer/files/musicplayer/slim-player-0.2.3b/xspf_player_slim-correct-0.2.3.zip/download',
'filetypes' => array('mp3'),
'callback' => 'audiofield_xspf_slim',
);
$players['premium_beat_single_track']=array(
'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/playerSinglePackage/playerSingle.swf",
'name' => 'Premium Beat Single Player',
'download_link' => 'http://www.premiumbeat.com/flash_resources/free_flash_music_player/single_track_flash_mp3_player.php',
'filetypes' => array('mp3'),
'callback' => 'audiofield_premium_beat_single_track',
);
$players['premium_beat_thin']=array(
'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/OriginalThinMusicPlayer.swf",
'name' => 'Premium Beat Thin Player',
'download_link' => 'http://www.premiumbeat.com/flash_music_players/original/thin/',
'filetypes' => array('mp3'),
'callback' => 'audiofield_premium_beat_thin',
);
$players['premium_beat_mini']=array(
'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/LWMusicPlayer.swf",
'name' => 'Premium Beat Mini Player',
'download_link' => 'http://www.premiumbeat.com/flash_music_players/original/mini/',
'filetypes' => array('mp3'),
'callback' => 'audiofield_premium_beat_mini',
);
if (module_exists('flowplayer')) {
$players['flowplayer']=array(
'path' => drupal_get_path('module', 'flowplayer') . '/flowplayer/flowplayer.swf',
'name' => 'Flowplayer',
'download_link' => 'http://drupal.org/project/flowplayer',
'filetypes' => array('mp3'),
'callback' => 'audiofield_flowplayer',
);
}
return $players;
}
/* Audio Callback Functions */
function audiofield_embeddedplayer($audio_file) {
return '';
}
function audiofield_wpaudioplayer($player_path, $audio_file) {
return theme('audiofield_players_wpaudioplayer',$player_path, $audio_file);
}
function theme_audiofield_players_wpaudioplayer($player_path, $audio_file){
return '';
}
function audiofield_xspf_slim($player_path, $audio_file) {
return theme('audiofield_players_xspf_slim',$player_path, $audio_file);
}
function theme_audiofield_players_xspf_slim($player_path, $audio_file){
return '';
}
function audiofield_premium_beat_single_track($player_path, $audio_file) {
return theme('audiofield_players_premium_beat_single_track',$player_path, $audio_file);
}
function theme_audiofield_players_premium_beat_single_track($player_path, $audio_file){
return '';
}
function audiofield_premium_beat_thin($player_path, $audio_file) {
return theme('audiofield_players_premium_beat_thin',$player_path, $audio_file);
}
function theme_audiofield_players_premium_beat_thin($player_path, $audio_file){
return '';
}
function audiofield_premium_beat_mini($player_path, $audio_file) {
return theme('audiofield_players_premium_beat_mini',$player_path, $audio_file);
}
function theme_audiofield_players_premium_beat_mini($player_path, $audio_file){
return '';
}
if (module_exists('flowplayer')) {
function audiofield_flowplayer($player_path, $audio_file) {
return theme('flowplayer', $audio_file, 'audiofield', array('style' => 'height: 24px',));
}
}