Hello, i'm trying to develop a module similar to private_download, but with multiple directories:
http://drupal.org/project/private_download
The module has been written based on this post:
http://www.drupalcoder.com/blog/mixing-private-and-public-downloads-in-drupa...
I managed to create the hook_menu implementation, but i am running into issues with the access callback function.
My drupal install seems to completely skip the access argument check and i can't figure out why, since the same access arguments variable present in the hook_menu implementation in the original module is working flawlessly.
I'd really like some ideas on why the files are downloadable by everyone and the permission check does not have any effect.
This is the code of my custom module:
/** * Implementation of hook_perm(). */
function custom_private_download_perm() { return array('access role A files', 'access role B files'); }
/** * Implementation of hook_menu(). */
function custom_private_download_name_menu() { $items = array(); $items['system/files/kb/role/a/%'] = array( 'access arguments' => array('access role A files'), 'type' => MENU_CALLBACK, 'page callback' => 'file_download', 'page arguments' => array('kb/role/a'), );
$items['system/files/kb/role/b/%'] = array( 'access arguments' => array('access role B files'), 'type' => MENU_CALLBACK, 'page callback' => 'file_download', 'page arguments' => array('kb/role/b'), ); return $items; }
/** * Implementation of hook_file_download(). */
function custom_private_download_file_download($filepath) { // define default file header attributes $header = array( 'Content-Type: '. file_get_mimetype($filepath), 'Content-Length: '. filesize(file_create_path($filepath)), 'Content-Disposition: attachment; filename="'. mime_header_encode(basename($filepath)) .'"' ); // additional user-defined file header attributes (if any) return array_merge($header, explode("\n", variable_get('private_download_header', "Content-Transfer-Encoding: binary\nCache-Control: max-age=60, must-revalidate"))); }
I don't think you are using the 'page arguments' parameter correctly. Check out the documentation on hook_menu http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_me... peruse other modules' implementations.
I would also suggest that your effort be posted as an issue to the Private Download issue queue and you post a patch such that you may contribute to the existing body of work. http://drupal.org/project/issues/search/private_download
On Fri, Apr 29, 2011 at 3:15 AM, Davide Mirtillo davide@ser-tec.org wrote:
Hello, i'm trying to develop a module similar to private_download, but with multiple directories:
http://drupal.org/project/private_download
The module has been written based on this post:
http://www.drupalcoder.com/blog/mixing-private-and-public-downloads-in-drupa...
I managed to create the hook_menu implementation, but i am running into issues with the access callback function.
My drupal install seems to completely skip the access argument check and i can't figure out why, since the same access arguments variable present in the hook_menu implementation in the original module is working flawlessly.
I'd really like some ideas on why the files are downloadable by everyone and the permission check does not have any effect.
This is the code of my custom module:
/**
- Implementation of hook_perm().
*/
function custom_private_download_perm() { return array('access role A files', 'access role B files'); }
/**
- Implementation of hook_menu().
*/
function custom_private_download_name_menu() { $items = array();
$items['system/files/kb/role/a/%'] = array( 'access arguments' => array('access role A files'), 'type' => MENU_CALLBACK, 'page callback' => 'file_download', 'page arguments' => array('kb/role/a'), );
$items['system/files/kb/role/b/%'] = array( 'access arguments' => array('access role B files'), 'type' => MENU_CALLBACK, 'page callback' => 'file_download', 'page arguments' => array('kb/role/b'), ); return $items; }
/**
- Implementation of hook_file_download().
*/
function custom_private_download_file_download($filepath) { // define default file header attributes $header = array( 'Content-Type: '. file_get_mimetype($filepath), 'Content-Length: '. filesize(file_create_path($filepath)), 'Content-Disposition: attachment; filename="'. mime_header_encode(basename($filepath)) .'"' ); // additional user-defined file header attributes (if any) return array_merge($header, explode("\n", variable_get('private_download_header', "Content-Transfer-Encoding: binary\nCache-Control: max-age=60, must-revalidate"))); } -- [ Drupal support list | http://lists.drupal.org/ ]
Il 29/04/2011 17:45, Carl Wiedemann ha scritto:
I don't think you are using the 'page arguments' parameter correctly. Check out the documentation on hook_menu http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_me... or peruse other modules' implementations.
I would also suggest that your effort be posted as an issue to the Private Download issue queue and you post a patch such that you may contribute to the existing body of work. http://drupal.org/project/issues/search/private_download
The page arguments were fine :)
Turns out there was something weird going on with the system/files url path. Once i changed that, the module started working as intended.
I will post a feature request asking for multiple private directories support (with multiple permissions), but i had to hack something up in the meantime.
Have a nice weekend!