/[drupal]/contributions/modules/input_format_permissions/input_format_permissions.install
ViewVC logotype

Contents of /contributions/modules/input_format_permissions/input_format_permissions.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Jan 5 22:33:49 2009 UTC (10 months, 3 weeks ago) by mannkind
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, DRUPAL-6--1-1-BETA1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial commit of input_format_permissions. The module allows for the control of Input Format Permissions via the standard Drupal Permissions screen
1 <?php
2
3 /**
4 * Implementation of hook_install
5 */
6 function input_format_permissions_install() {
7 $role_perms = array();
8
9 // Get current permissions
10 $perm_result = db_query('SELECT rid, perm FROM {permission}');
11 while ($row = db_fetch_array($perm_result)) {
12 $role_perms[$row['rid']] = $row['perm'];
13 }
14
15
16 $filter_result = db_query('SELECT name, roles FROM {filter_formats}');
17 while ($row = db_fetch_array($filter_result)) {
18 $filter = check_plain(strtolower($row['name']));
19 $roles = array_filter(explode(',', $row['roles']));
20 foreach ($roles as $role) {
21 $role_perms[$role] .= ', ' . input_format_permissions_install_formatname_to_permission($filter);
22 }
23 }
24
25 if (count($role_perms) == 0) { return; }
26
27 foreach ($role_perms as $rid => $perm) {
28 db_query('UPDATE {permission} SET perm = "%s" WHERE rid = "%d"',
29 $perm, $rid);
30 }
31 }
32
33 /**
34 * This is needed so that default permissions can be set correctly
35 */
36 function input_format_permissions_install_formatname_to_permission($name) {
37 return 'use the ' . check_plain(strtolower($name)) . ' input format';
38 }

  ViewVC Help
Powered by ViewVC 1.1.2