5 * Installs the better_formats module.
7 * Creates a database for use of multi-layered default formats and sets
12 * Implementation of hook_enable().
14 function better_formats_enable() {
15 better_formats_check_roles();
19 * Implementation of hook_schema().
21 function better_formats_schema() {
22 $schema['better_formats_defaults'] = array(
41 'type_weight' => array(
56 'primary key' => array('rid', 'type'),
63 * Implementation of hook_install().
65 function better_formats_install() {
67 drupal_install_schema('better_formats');
69 // Increase module weight to prevent compatibility issues.
70 $sql = "UPDATE {system}
72 WHERE name = 'better_formats'";
75 // Insert format defaults.
76 $roles = user_roles();
77 $sql = "INSERT INTO {better_formats_defaults}
78 VALUES (%d, '%s', %d, %d, %d)";
79 foreach ($roles as
$rid => $role) {
80 db_query($sql, $rid, 'node', 0, 1, 0);
81 db_query($sql, $rid, 'comment', 0, 1, 0);
82 db_query($sql, $rid, 'block', 0, 1, 25);
85 // Set default perms to be like core defaults.
86 $default_perms = ', show format selection for nodes, show format selection for comments, show format selection for blocks, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default';
87 // Get current core perms.
91 $result = db_query($sql);
92 $role_perms = array();
93 while ($row = db_fetch_object($result)) {
94 $role_perms[$row->rid
] = $row;
96 // If a role has no permissions set it will not have a row in the database.
97 // Assume that roles do not need perms set for BF as well if none are set.
98 if (!empty($role_perms)) {
99 // Add perms to core roles (anonymous user, authenticated user).
100 foreach ($role_perms as
$perms) {
101 $sql = "UPDATE {permission}
104 db_query($sql, $perms->perm .
$default_perms, $perms->pid
);
112 * Implementation of hook_uninstall().
114 function better_formats_uninstall() {
116 drupal_uninstall_schema('better_formats');
118 // Delete settings from varible table.
119 $sql = "DELETE FROM {variable}
120 WHERE name LIKE 'better_formats%'";
125 * Update from 1.0 to 1.1.
127 function better_formats_update_6110() {
130 // Insert block format defaults.
131 $roles = user_roles();
132 $sql = "INSERT INTO {better_formats_defaults}
133 VALUES (%d, '%s', %d, %d, %d)";
134 foreach ($roles as
$rid => $role) {
135 $result = db_query($sql, $rid, 'block', 0, 1, 25);
136 $ret[] = array('success' => $result !== FALSE
, 'query' => check_plain($sql));
139 // Split show format selection permission.
140 // Get permissions by role.
143 $result = db_query($sql);
144 $row_perms = array();
145 while ($row = db_fetch_object($result)) {
146 $role_perms[$row->rid
] = $row;
148 if (!empty($role_perms)) {
149 // Add perms to core roles (anonymous user, authenticated user).
150 foreach ($role_perms as
$perms) {
151 // Only enable spit permissions if previous was enabled.
152 $replace = ', show format selection for nodes, show format selection for comments, show format selection for blocks,';
153 $perms->perm
= str_replace(', show format selection,', $replace, $perms->perm
);
154 $sql = "UPDATE {permission}
157 $result = db_query($sql, $perms->perm
, $perms->pid
);
158 $ret[] = array('success' => $result !== FALSE
, 'query' => check_plain($sql));