| 1 |
// $Id$
|
| 2 |
|
| 3 |
Please note that extended (and possibly more recent) developer and API
|
| 4 |
documentation is available in the Drupal Handbook at:
|
| 5 |
|
| 6 |
http://drupal.org/node/227210
|
| 7 |
|
| 8 |
HOOKS
|
| 9 |
-----
|
| 10 |
The Bitcache module exposes the following Drupal hook that third-party
|
| 11 |
extension modules can implement to provide extended functionality:
|
| 12 |
|
| 13 |
hook_bitcache()
|
| 14 |
~~~~~~~~~~~~~~~
|
| 15 |
|
| 16 |
Allows modules to take action when bitstreams are created or deleted, to
|
| 17 |
determine fine-grained bitstream download access rights for individual
|
| 18 |
users, and to define additional HTTP headers for bitstream downloads.
|
| 19 |
|
| 20 |
This is essentially an extended analog of the hook_file_download() core
|
| 21 |
hook.
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Implementation of hook_bitcache().
|
| 25 |
*/
|
| 26 |
function mymodule_bitcache($op, $id, $stream = NULL) {
|
| 27 |
switch ($op) {
|
| 28 |
case 'insert':
|
| 29 |
// A new bitstream was uploaded
|
| 30 |
break;
|
| 31 |
|
| 32 |
case 'delete':
|
| 33 |
// An existing bitstream was deleted
|
| 34 |
break;
|
| 35 |
|
| 36 |
case 'access':
|
| 37 |
// Should the current user be allowed to access the given bitstream?
|
| 38 |
return node_access('view', node_load($_GET['nid']));
|
| 39 |
|
| 40 |
case 'download':
|
| 41 |
// Determine additional HTTP headers for the bitstream download
|
| 42 |
$node = node_load($_GET['nid']);
|
| 43 |
return array(
|
| 44 |
'Content-Disposition' => 'attachment; filename='. $node->title,
|
| 45 |
'Last-Modified' => gmdate('D, d M Y H:i:s', $node->changed) .' GMT',
|
| 46 |
);
|
| 47 |
}
|
| 48 |
}
|