Index: audio.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v
retrieving revision 1.51
diff -u -r1.51 audio.module
--- audio.module	21 Apr 2006 21:46:10 -0000	1.51
+++ audio.module	10 May 2006 23:48:44 -0000
@@ -130,7 +130,7 @@
  * Implementation of hook_perm
  */
 function audio_perm() {
-  return array('administer audio', 'create audio');
+  return array('administer audio', 'create audio', 'play audio', 'download audio');
 }
 
 /**
@@ -154,6 +154,41 @@
 }
 
 /**
+ * Is the current user allowed to download an audio node?
+ */
+function audio_allow_download($node) {
+  if (isset($node->url_download)) {
+    $result = module_invoke_all('audio', 'access', $node, 'download');
+    if (in_array(TRUE, $result)) {
+      return TRUE;
+    }
+    if (in_array(FALSE, $result)) {
+      return FALSE;
+    }
+    return user_access('download audio');
+  }
+  return FALSE;
+}
+
+/**
+ * Is the current user allowed to play an audio node?
+ */
+function audio_allow_play($node) {
+  if (isset($node->url_play)) {
+    $result = module_invoke_all('audio', 'access', $node, 'play');
+    if (in_array(TRUE, $result)) {
+      return TRUE;
+    }
+    if (in_array(FALSE, $result)) {
+      return FALSE;
+    }
+    return user_access('play audio');
+  }
+  return FALSE;
+}
+
+
+/**
  * Build a title for the node.
  */
 function audio_set_title($node) {
@@ -201,7 +236,7 @@
 
       case 'rss item':
         $ret = array();
-        if ($node->audio_file && $node->url_download) {
+        if (audio_allow_download($node)) {
           // NOTE: we'll try to reset the node's body to remove theming, this only
           // works with this patch: http://drupal.org/node/41703
           $body = db_result(db_query("SELECT r.body FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid WHERE n.vid=%d", $node->vid));
@@ -342,6 +377,9 @@
 
   // add the tags records
   _audio_save_tags_to_db($node);
+
+  // notify other modules
+  module_invoke_all('audio', 'insert', $node);
 }
 
 /**
@@ -385,6 +423,9 @@
 
   // add the tags records
   _audio_save_tags_to_db($node);
+
+  // notify other modules
+  module_invoke_all('audio', 'insert', $node);
 }
 
 /**
@@ -437,13 +478,18 @@
 
   // add the tags records
   _audio_save_tags_to_db($node);
+
+  // notify other modules
+  module_invoke_all('audio', 'update', $node);
 }
 
 /**
  * Implementation of hook_delete.
  */
 function audio_delete($node) {
-  $vids = array();
+  // notify other modules
+  module_invoke_all('audio', 'delete', $node);
+
   $result = db_query('SELECT vid FROM {audio} WHERE nid = %d', $node->nid);
   while ($o = db_fetch_object($result)) {
     if ($filepath = db_result(db_query('SELECT filepath FROM {audio_file} WHERE vid = %d', $o->vid))) {
@@ -459,6 +505,9 @@
  * Delete a single revision.
  */
 function audio_delete_revision($node) {
+  // notify other modules
+  module_invoke_all('audio', 'delete', $node);
+
   if ($filepath = db_result(db_query('SELECT filepath FROM {audio_file} WHERE vid = %d', $node->vid))) {
     file_delete($filepath);
   }
@@ -1126,7 +1175,7 @@
  */
 function audio_get_player($node) {
   // if we've got a URL, setup a player
-  if (isset($node->url_play)) {
+  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)) {
@@ -1192,7 +1241,7 @@
  */
 function audio_download($nid = false) {
   if ($node = node_load($nid)) {
-    if (db_result(db_query('SELECT downloadable FROM {audio} a WHERE a.vid=%d', $node->vid))) {
+    if (db_result(db_query('SELECT downloadable FROM {audio} a WHERE a.vid=%d', $node->vid)) && audio_allow_download($node)) {
       // increment the play count
       db_query('UPDATE {audio} a SET a.download_count = a.download_count + 1 WHERE a.vid = %d', $node->vid);
 
@@ -1522,4 +1571,4 @@
   }
   // the smallest value will be the limiting factor so retun it.
   return min($limits);
-}
+}
\ No newline at end of file

