? modules/audio/getid3 Index: modules/audio/audio.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v retrieving revision 1.51 diff -u -u -F^f -r1.51 audio.module --- modules/audio/audio.module 21 Apr 2006 21:46:10 -0000 1.51 +++ modules/audio/audio.module 10 May 2006 21:41:31 -0000 @@ -130,7 +130,8 @@ function audio_node_info() { * Implementation of hook_perm */ function audio_perm() { - return array('administer audio', 'create audio'); + return array('administer audio', 'create audio', + 'play audio files', 'download audio files'); } /** @@ -179,13 +180,14 @@ function audio_link($type, $node, $main $links = array(); if ($type == 'node' && $node->type == 'audio') { - if ($node->url_download) { + if ($node->url_download && + audio_file_access($node, 'download')) { $links[] = l(t('download audio file'), $node->url_download, NULL); $links[] = t('%download_count downloads', array('%download_count' => $node->audio_fileinfo['download_count'])); } $links[] = t('%play_count plays', array('%play_count' => $node->audio_fileinfo['play_count'])); } - + return $links; } @@ -342,6 +344,9 @@ function audio_insert(&$node) { // add the tags records _audio_save_tags_to_db($node); + + // notify other modules + audio_invoke_fileapi($node, 'insert', $f); } /** @@ -385,6 +390,9 @@ function audio_insert_revision($node) { // add the tags records _audio_save_tags_to_db($node); + + // notify other modules + audio_invoke_fileapi($node, 'insert', $f); } /** @@ -437,6 +445,9 @@ function audio_update(&$node) { // add the tags records _audio_save_tags_to_db($node); + + // notify other modules + audio_invoke_fileapi($node, 'update', $node->audio_file); } /** @@ -453,6 +464,9 @@ function audio_delete($node) { db_query('DELETE FROM {audio_file} WHERE vid = %d', $o->vid); } db_query('DELETE FROM {audio} WHERE nid = %d', $node->nid); + + // notify other modules + audio_invoke_fileapi($node, 'delete', $node->audio_file); } /** @@ -465,6 +479,9 @@ function audio_delete_revision($node) { db_query('DELETE FROM {audio_metadata} WHERE vid = %d', $node->vid); db_query('DELETE FROM {audio_file} WHERE vid = %d', $node->vid); db_query('DELETE FROM {audio} WHERE vid = %d', $node->vid); + + // notify other modules + audio_invoke_fileapi($node, 'delete', $node->audio_file); } /** @@ -1126,7 +1143,8 @@ function audio_get_latest($count = 1) { */ function audio_get_player($node) { // if we've got a URL, setup a player - if (isset($node->url_play)) { + if (isset($node->url_play) && + audio_file_access($node, 'view')) { // try to find one that's type specific... $format = $node->audio_fileinfo['fileformat']; if (!$player = theme('audio_'. $format .'_player', $node)) { @@ -1523,3 +1541,52 @@ function audio_get_max_upload_size() { // the smallest value will be the limiting factor so retun it. return min($limits); } + + + +/** + * Helper function to notify other module via fileapis. + */ +function audio_invoke_fileapi($node, $op, $info) { + // Invoke ecommerce fileapi. Allows audio nodes to be products. + module_invoke_all('ec_fileapi', + $node->vid, 'audio.module', $node, $op, $info); +} + +/** + * hook_ec_file_nodetypes + * + * Enables the ecommerce modules to treat audio nodes as file products. + * + * @return + * An array in which keys are nodetypes and values are configuration arrays. + */ +function audio_ec_file_nodetypes() { + return array('audio' => array('realm' => 'audio.module')); +} + +/** + * Is the current user allowed to see the audio file? + * + * @param $node + * @param $op + * operations include 'view' and 'download' (to audio, 'view' means 'play') + */ +function audio_file_access($node, $op) { + global $user; + $perms = array('view' => 'play audio files', + 'download' => 'download audio files'); + if ($perms[$op] && + user_access($perms[$op])) { + // explicit permission based on role + return TRUE; + } + + // Otherwise, let other modules determine whether file is downloadable. + $result = module_invoke_all('ec_file_access', // ecommerce hook + $node->vid, 'audio.module', $node, $op, + $node->audio_file, $user); + if (in_array(TRUE, $result)) { + return TRUE; + } +}