... like it's in the comment module - theme_comment_post_forbidden() (not post comment, but play/download audio)

Comments

drewish’s picture

i'm not sure i follow... could you provide some sample code of how you'd like to use it? screen shot maybe?

alippai’s picture

function audio_link($type, $node, $main = 0) {
	global $user;
  $links = array();
  $link_access = user_access('view download stats');

  if ($type == 'node' && $node->type == 'audio') {
    if (_audio_allow_download($node)) {
      $links['audio_download_link'] = array(
        'title' => t('Download audio file'),
        'href' => $node->url_download,
      );
      if($link_access){
        $links['audio_download_count'] = array(
          'title' => t('@download_count downloads', array('@download_count' => $node->audio_fileinfo['download_count'])),
        );
      }
    } else {
		if($user->uid) {
		  $links['audio_download_link'] = array(
			'title' => t('You don\'t have enoght points to download music - please upload'),
		  );
		} else {
                            /*
                               without userpoints this is enought
                            */
		  $links['audio_download_link'] = array(
			'title' => t('Login or registrate to download music'),
			'href' => url('user/login', $destination),
		  );
		}
	}
    if (_audio_allow_play($node) && $link_access) {
      $links['audio_play_count'] = array(
        'title' => t('@play_count plays', array('@play_count' => $node->audio_fileinfo['play_count'])),
      );
    }
  }

  return $links;
}

On my site I'm using uerpoints too and downloading depends on their points....

function _audio_allow_download($node) {
	global $user;
  if (isset($node->url_download) && $node->audio_fileinfo['downloadable'] and userpoints_get_current_points($user->uid)>4) {
    // let other modules affect the download permissions
    $result = audio_invoke_audioapi('access', $node, 'download');
    if (in_array(TRUE, $result)) {
      return TRUE;
    }
    if (in_array(FALSE, $result)) {
      return FALSE;
    }
    return user_access('download audio');
  }
  return FALSE;
}

function audio_download($nid = false) {
  if ($nid && $node = node_load($nid)) {
    if (_audio_allow_download($node)) {
	global $user;
	  userpoints_userpointsapi('points', -5, $user->uid, 'zeneletoltes');
      // increment the play count
      db_query('UPDATE {audio} SET download_count = download_count + 1 WHERE vid = %d', $node->vid);

      // downloading counts as "viewing" the node
      node_tag_new($node->nid);

      // notify other modules
      audio_invoke_audioapi('download', $node);

      // The mime_header_encode function does not (yet) support
      // quoted-string encoding of ASCII strings with special
      // characters.  See discussion at http://drupal.org/node/82614
      $filename = $node->audio_file->origname;
      // If the string contains non-ASCII characters, process it through
      // the mime_header_encode function.
      if (preg_match('/[^\x20-\x7E]/', $filename)) {
        $filename = mime_header_encode($filename);
      }
      // Otherwise, if the string contains special characters (like
      // space), perform quoted-string encoding.
      elseif (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $filename)) {
        $filename = '"'. str_replace('"', '\"', $filename) .'"';
      }
      $headers = array(
        'Content-Type: '. mime_header_encode($node->audio_file->filemime),
        'Content-Length: '. $node->audio_file->filesize,
        'Content-Disposition: attachment; filename='. $filename,
      );
      audio_file_transfer($node->audio_file->filepath, $headers);
    }
    drupal_access_denied();
  }
  else {
    drupal_not_found();
  }
}

This could be a feature request too :) (downloading audio depending on userpoints)

drewish’s picture

Status: Active » Closed (won't fix)

okay, i see what you're trying to do. there's already ways to do this. take a look at hook_link_alter as well as the audio modules' hook_audio function. it lets other modules impose their own criteria for play and download access.

alippai’s picture

Thx :)