filefieldmp3player.module in MP3 Player 6.2
File
filefieldmp3player/filefieldmp3player.module
View source
<?php
function filefieldmp3player_field_formatter_info() {
$formatters = array();
$players = mp3player_players();
foreach ($players as $player) {
$formatters['mp3player_' . $player['name']] = array(
'label' => t('MP3 Player (' . $player['name'] . ')'),
'field types' => array(
'filefield',
),
);
}
return $formatters;
}
function filefieldmp3player_theme() {
$path = drupal_get_path('module', 'filefieldmp3player') . '/theme';
$theme = array();
$players = mp3player_players();
foreach ($players as $player) {
$theme['filefieldmp3player_formatter_mp3player_' . $player['name']] = array(
'arguments' => array(
'element' => NULL,
),
'function' => 'theme_filefieldmp3player_formatter_mp3player',
);
}
$theme['filefieldmp3player_description'] = array(
'template' => 'description',
'arguments' => array(
'id3' => array(),
),
'path' => $path,
);
return $theme;
}
function theme_filefieldmp3player_formatter_mp3player($element) {
$item = $element['#item'];
if (empty($item['filepath']) || $item['list'] == "0") {
return FALSE;
}
$description = $item['filename'];
$title = $artist = NULL;
if (variable_get('mp3player_description', 'description') == 'id3' && module_exists('getid3') && getid3_load() == TRUE) {
$id3 = getid3_analyze($item['filepath']);
$title = $id3['tags']['id3v2']['title'][0];
$artist = $id3['tags']['id3v2']['artist'][0];
$description = theme('filefieldmp3player_description', $id3);
}
else {
if (isset($item['data']['description'])) {
$description = $item['data']['description'];
}
else {
if (gettype($item['data']) == 'string' && is_array(unserialize($item['data']))) {
$bits = unserialize($item['data']);
$description = $bits['description'];
}
}
}
$parts = explode('_', $element['#formatter']);
unset($parts[0]);
$player = implode('_', $parts);
if ($item['filemime'] == 'audio/mpeg' || $item['filemime'] == 'audio/x-mpeg' || $item['filemime'] == 'audio/mp3' || $item['filemime'] == 'audio/x-mp3' || $item['filemime'] == 'audio/mpeg3' || $item['filemime'] == 'audio/x-mpeg3' || $item['filemime'] == 'audio/mpg' || $item['filemime'] == 'audio/x-mpg' || $item['filemime'] == 'audio/mpegaudi') {
$out = theme('mp3player', $player, file_create_url($item['filepath']), $title, $artist, $description);
}
else {
$out = theme('filefield_formatter_default', $element);
}
return $out;
}
function filefieldmp3player_preprocess_filefieldmp3player_description(&$vars) {
$vars['title'] = $vars['id3']['tags']['id3v2']['title'][0];
$vars['artist'] = $vars['id3']['tags']['id3v2']['artist'][0];
$vars['album'] = $vars['id3']['tags']['id3v2']['album'][0];
$vars['year'] = $vars['id3']['tags']['id3v2']['year'][0];
$vars['track'] = $vars['id3']['tags']['id3v2']['track'][0];
$vars['genre'] = $vars['id3']['tags']['id3v2']['genre'][0];
}