function secure_permissions_export in Secure Permissions 6
Same name and namespace in other branches
- 7.2 secure_permissions.module \secure_permissions_export()
- 7 secure_permissions.module \secure_permissions_export()
Page callback to generate roles and permissions in code.
1 string reference to 'secure_permissions_export'
- secure_permissions_menu in ./
secure_permissions.module - Implement hook_menu().
File
- ./
secure_permissions.module, line 308 - Secure Permissions module file.
Code
function secure_permissions_export(&$form_state) {
$form = array();
$form['help'] = array(
'#value' => t('The Secure permissions module stores the permissions in a module (file) that is inaccessible through
the user interface.<br />You now need to create and enable that module in 4 easy steps.<ol><li>Create directory.
cd to /sites/all/modules and issue the command: mkdir secure_permissions_data<li>Create 2 empty files. cd to
/sites/all/modules/secure_permissions_data and issue the command: touch secure_permissions_data.info
secure_permissions_data.module<li>Copy data. Copy the text from the fields below into the respective files you just
created using the tools of your choice.<li>Enable the module. Navigate to admin/build/modules/list and enable your
new module.</ol>To change permissions with the module enabled, you must now edit your
/sites/all/modules/secure_permissions_data/secure_permissions_data.module file. After editing the file navigate to
/admin/user/secure_permissions/view select \'Load permissions from code\' and click \'Save configuration\' to update
the permissions. You may rename the module; remember to rename all the functions.'),
);
$output = '';
$output .= "name = Secure Permissions Data\n";
$output .= "description = Role and permission settings for the site.\n";
$output .= "core = 6.x\n";
$output .= "dependencies[] = secure_permissions\n";
$lines = explode("\n", $output);
$form['info'] = array(
'#title' => t('Permissions output -- secure_permissions_data.info'),
'#type' => 'textarea',
'#cols' => 40,
'#rows' => count($lines),
'#default_value' => $output,
'#description' => t('Module .info file for storing secure permissions.'),
);
$output = '';
// Get roles.
$roles = user_roles();
$output .= <<<EOT
<?php
/**
* @file Secure Permissions Data
* Module file for secure permissions in code.
*/
/**
* Define site roles in code.
*
* Create a secure_permissions_data module directory and place this function
* in secure_permissions_data.module.
*
* @return
* An array defining all the roles for the site.
*/
EOT;
$output .= 'function secure_permissions_data_secure_permissions_roles() {';
$output .= "\n return array(\n";
foreach ($roles as $role) {
$output .= " '" . $role . "',\n";
}
$output .= " );";
$output .= "\n}\n\n";
// Now get permissions.
$output .= <<<EOT
/**
* Define site permissions in code.
*
* Create a secure_permissions_data module directory and place this function
* in secure_permissions_data.module.
*
* @param \$role
* The role for which the permissions are being requested.
*
* @return
* An array defining all the permissions for the site.
*/
EOT;
$output .= 'function secure_permissions_data_secure_permissions($role) {';
$output .= "\n \$permissions = array(\n";
foreach ($roles as $rid => $role) {
$output .= " '{$role}' => array(\n";
$permissions = permissions_get_permissions_for_role($role);
foreach ($permissions as $key => $permission) {
$output .= " '{$permission}',\n";
}
$output .= " ),\n";
}
$output .= " );\n";
$output .= " if (isset(\$permissions[\$role])) {";
$output .= "\n return \$permissions[\$role];\n";
$output .= " }\n";
$output .= "}";
$lines = explode("\n", $output);
$form['export'] = array(
'#title' => t('Permissions output -- secure_permissions_data.module'),
'#type' => 'textarea',
'#cols' => 40,
'#rows' => count($lines),
'#default_value' => $output,
'#description' => t('Module .module file for storing secure permissions.'),
);
return $form;
}