@@ -4,25 +4,25 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function user_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'user_role' => array( |
9 | - 'name' => t('Roles'), |
|
10 | - 'feature_source' => TRUE, |
|
11 | - 'default_hook' => 'user_default_roles', |
|
12 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
9 | + 'name' => t('Roles'), |
|
10 | + 'feature_source' => TRUE, |
|
11 | + 'default_hook' => 'user_default_roles', |
|
12 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
13 | 13 | ), |
14 | 14 | 'user_permission' => array( |
15 | - 'name' => t('Permissions'), |
|
16 | - 'feature_source' => TRUE, |
|
17 | - 'default_hook' => 'user_default_permissions', |
|
18 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
15 | + 'name' => t('Permissions'), |
|
16 | + 'feature_source' => TRUE, |
|
17 | + 'default_hook' => 'user_default_permissions', |
|
18 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
19 | 19 | ), |
20 | 20 | // DEPRECATED |
21 | 21 | 'user' => array( |
22 | - 'name' => t('Permissions'), |
|
23 | - 'feature_source' => FALSE, |
|
22 | + 'name' => t('Permissions'), |
|
23 | + 'feature_source' => FALSE, |
|
24 | 24 | ) |
25 | - ); |
|
25 | + ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -31,86 +31,86 @@ discard block |
||
31 | 31 | * to the `user_permission` type. |
32 | 32 | */ |
33 | 33 | function user_features_export($data, &$export, $module_name = '') { |
34 | - $pipe = array(); |
|
35 | - foreach ($data as $perm) { |
|
34 | + $pipe = array(); |
|
35 | + foreach ($data as $perm) { |
|
36 | 36 | $pipe['user_permission'][] = $perm; |
37 | - } |
|
38 | - return $pipe; |
|
37 | + } |
|
38 | + return $pipe; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implementation of hook_features_export(). |
43 | 43 | */ |
44 | 44 | function user_permission_features_export($data, &$export, $module_name = '') { |
45 | - $export['dependencies']['features'] = 'features'; |
|
45 | + $export['dependencies']['features'] = 'features'; |
|
46 | 46 | |
47 | - // Ensure the modules that provide the given permissions are included as dependencies. |
|
48 | - $map = _user_features_permission_map(); |
|
49 | - foreach ($data as $perm) { |
|
47 | + // Ensure the modules that provide the given permissions are included as dependencies. |
|
48 | + $map = _user_features_permission_map(); |
|
49 | + foreach ($data as $perm) { |
|
50 | 50 | if (isset($map[$perm])) { |
51 | - $perm_module = $map[$perm]; |
|
52 | - $export['dependencies'][$perm_module] = $perm_module; |
|
53 | - $export['features']['user_permission'][$perm] = $perm; |
|
51 | + $perm_module = $map[$perm]; |
|
52 | + $export['dependencies'][$perm_module] = $perm_module; |
|
53 | + $export['features']['user_permission'][$perm] = $perm; |
|
54 | + } |
|
54 | 55 | } |
55 | - } |
|
56 | 56 | |
57 | - return array(); |
|
57 | + return array(); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Implementation of hook_features_export_options(). |
62 | 62 | */ |
63 | 63 | function user_permission_features_export_options() { |
64 | - $options = array(); |
|
65 | - foreach (module_list() as $module) { |
|
64 | + $options = array(); |
|
65 | + foreach (module_list() as $module) { |
|
66 | 66 | $prefix = check_plain($module) .': '; |
67 | 67 | if ($permissions = module_invoke($module, 'perm')) { |
68 | - foreach ($permissions as $permission) { |
|
68 | + foreach ($permissions as $permission) { |
|
69 | 69 | $options[$permission] = $prefix . check_plain($permission); |
70 | - } |
|
70 | + } |
|
71 | + } |
|
71 | 72 | } |
72 | - } |
|
73 | - asort($options); |
|
74 | - return $options; |
|
73 | + asort($options); |
|
74 | + return $options; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Implementation of hook_features_export_render(). |
79 | 79 | */ |
80 | 80 | function user_permission_features_export_render($module, $data) { |
81 | - $code = array(); |
|
82 | - $code[] = ' $permissions = array();'; |
|
83 | - $code[] = ''; |
|
81 | + $code = array(); |
|
82 | + $code[] = ' $permissions = array();'; |
|
83 | + $code[] = ''; |
|
84 | 84 | |
85 | - $permissions = _user_features_get_permissions(); |
|
85 | + $permissions = _user_features_get_permissions(); |
|
86 | 86 | |
87 | - foreach ($data as $perm_name) { |
|
87 | + foreach ($data as $perm_name) { |
|
88 | 88 | $permission = array(); |
89 | 89 | $permission['name'] = $perm_name; |
90 | 90 | if (isset($permissions[$perm_name])) { |
91 | - sort($permissions[$perm_name]); |
|
92 | - $permission['roles'] = $permissions[$perm_name]; |
|
91 | + sort($permissions[$perm_name]); |
|
92 | + $permission['roles'] = $permissions[$perm_name]; |
|
93 | 93 | } |
94 | 94 | else { |
95 | - $permission['roles'] = array(); |
|
95 | + $permission['roles'] = array(); |
|
96 | 96 | } |
97 | 97 | $perm_identifier = features_var_export($perm_name); |
98 | 98 | $perm_export = features_var_export($permission, ' '); |
99 | 99 | $code[] = " // Exported permission: {$perm_name}"; |
100 | 100 | $code[] = " \$permissions[{$perm_identifier}] = {$perm_export};"; |
101 | 101 | $code[] = ""; |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - $code[] = ' return $permissions;'; |
|
105 | - $code = implode("\n", $code); |
|
106 | - return array('user_default_permissions' => $code); |
|
104 | + $code[] = ' return $permissions;'; |
|
105 | + $code = implode("\n", $code); |
|
106 | + return array('user_default_permissions' => $code); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Implementation of hook_features_revert(). |
111 | 111 | */ |
112 | 112 | function user_permission_features_revert($module) { |
113 | - user_permission_features_rebuild($module); |
|
113 | + user_permission_features_rebuild($module); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -121,152 +121,152 @@ discard block |
||
121 | 121 | * The module whose default user permissions should be rebuilt. |
122 | 122 | */ |
123 | 123 | function user_permission_features_rebuild($module) { |
124 | - if ($defaults = features_get_default('user_permission', $module)) { |
|
124 | + if ($defaults = features_get_default('user_permission', $module)) { |
|
125 | 125 | $roles = _features_get_roles(); |
126 | 126 | foreach ($defaults as $permission) { |
127 | - $perm = $permission['name']; |
|
127 | + $perm = $permission['name']; |
|
128 | 128 | |
129 | - // Add permissions for any roles that should have them. |
|
130 | - foreach ($permission['roles'] as $role) { |
|
129 | + // Add permissions for any roles that should have them. |
|
130 | + foreach ($permission['roles'] as $role) { |
|
131 | 131 | if (isset($roles[$role]) && !in_array($perm, $roles[$role]['perm'])) { |
132 | - $roles[$role]['perm'][] = $perm; |
|
132 | + $roles[$role]['perm'][] = $perm; |
|
133 | + } |
|
133 | 134 | } |
134 | - } |
|
135 | 135 | |
136 | - // Remove permissions for any roles that shouldn't have them. |
|
137 | - foreach (array_keys($roles) as $role) { |
|
136 | + // Remove permissions for any roles that shouldn't have them. |
|
137 | + foreach (array_keys($roles) as $role) { |
|
138 | 138 | if (in_array($perm, $roles[$role]['perm']) && !in_array($role, $permission['roles'])) { |
139 | - $position = array_search($perm, $roles[$role]['perm']); |
|
140 | - unset($roles[$role]['perm'][$position]); |
|
139 | + $position = array_search($perm, $roles[$role]['perm']); |
|
140 | + unset($roles[$role]['perm'][$position]); |
|
141 | + } |
|
141 | 142 | } |
142 | - } |
|
143 | 143 | } |
144 | 144 | // Write the updated permissions. |
145 | 145 | _user_features_save_roles($roles); |
146 | - } |
|
146 | + } |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | 150 | * Implementation of hook_features_export(). |
151 | 151 | */ |
152 | 152 | function user_role_features_export($data, &$export, $module_name = '') { |
153 | - $export['dependencies']['features'] = 'features'; |
|
154 | - $map = features_get_default_map('user_role', 'name'); |
|
155 | - foreach ($data as $role) { |
|
153 | + $export['dependencies']['features'] = 'features'; |
|
154 | + $map = features_get_default_map('user_role', 'name'); |
|
155 | + foreach ($data as $role) { |
|
156 | 156 | // Role is provided by another module. Add dependency. |
157 | 157 | if (isset($map[$role]) && $map[$role] != $module_name) { |
158 | - $export['dependencies'][$map[$role]] = $map[$role]; |
|
158 | + $export['dependencies'][$map[$role]] = $map[$role]; |
|
159 | 159 | } |
160 | 160 | // Export. |
161 | 161 | else { |
162 | - $export['features']['user_role'][$role] = $role; |
|
162 | + $export['features']['user_role'][$role] = $role; |
|
163 | 163 | } |
164 | - } |
|
165 | - return array(); |
|
164 | + } |
|
165 | + return array(); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * Implementation of hook_features_export_options(). |
170 | 170 | */ |
171 | 171 | function user_role_features_export_options() { |
172 | - $options = drupal_map_assoc(array_keys(_features_get_roles())); |
|
173 | - asort($options); |
|
174 | - return $options; |
|
172 | + $options = drupal_map_assoc(array_keys(_features_get_roles())); |
|
173 | + asort($options); |
|
174 | + return $options; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | 178 | * Implementation of hook_features_export_render(). |
179 | 179 | */ |
180 | 180 | function user_role_features_export_render($module, $data) { |
181 | - $code = array(); |
|
182 | - $code[] = ' $roles = array();'; |
|
183 | - $code[] = ''; |
|
181 | + $code = array(); |
|
182 | + $code[] = ' $roles = array();'; |
|
183 | + $code[] = ''; |
|
184 | 184 | |
185 | - $roles = _features_get_roles(); |
|
186 | - foreach ($data as $role) { |
|
185 | + $roles = _features_get_roles(); |
|
186 | + foreach ($data as $role) { |
|
187 | 187 | if (isset($roles[$role])) { |
188 | - $object = array('name' => $role); |
|
189 | - $role_identifier = features_var_export($role); |
|
190 | - $role_export = features_var_export($object , ' '); |
|
191 | - $code[] = " // Exported role: {$role}"; |
|
192 | - $code[] = " \$roles[{$role_identifier}] = {$role_export};"; |
|
193 | - $code[] = ""; |
|
188 | + $object = array('name' => $role); |
|
189 | + $role_identifier = features_var_export($role); |
|
190 | + $role_export = features_var_export($object , ' '); |
|
191 | + $code[] = " // Exported role: {$role}"; |
|
192 | + $code[] = " \$roles[{$role_identifier}] = {$role_export};"; |
|
193 | + $code[] = ""; |
|
194 | + } |
|
194 | 195 | } |
195 | - } |
|
196 | 196 | |
197 | - $code[] = ' return $roles;'; |
|
198 | - $code = implode("\n", $code); |
|
199 | - return array('user_default_roles' => $code); |
|
197 | + $code[] = ' return $roles;'; |
|
198 | + $code = implode("\n", $code); |
|
199 | + return array('user_default_roles' => $code); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Implementation of hook_features_revert(). |
204 | 204 | */ |
205 | 205 | function user_role_features_revert($module) { |
206 | - user_role_features_rebuild($module); |
|
206 | + user_role_features_rebuild($module); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * Implementation of hook_features_rebuild(). |
211 | 211 | */ |
212 | 212 | function user_role_features_rebuild($module) { |
213 | - if ($defaults = features_get_default('user_role', $module)) { |
|
213 | + if ($defaults = features_get_default('user_role', $module)) { |
|
214 | 214 | $roles = _features_get_roles(); |
215 | 215 | foreach ($defaults as $role) { |
216 | - if (!isset($roles[$role['name']])) { |
|
216 | + if (!isset($roles[$role['name']])) { |
|
217 | 217 | drupal_write_record('role', $role); |
218 | - } |
|
218 | + } |
|
219 | + } |
|
219 | 220 | } |
220 | - } |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Generate a perm to module mapping. |
225 | 225 | */ |
226 | 226 | function _user_features_permission_map($reset = FALSE) { |
227 | - static $map; |
|
228 | - if (!isset($map) || $reset) { |
|
227 | + static $map; |
|
228 | + if (!isset($map) || $reset) { |
|
229 | 229 | $map = array(); |
230 | 230 | foreach (module_implements('perm') as $module) { |
231 | - if ($permissions = module_invoke($module, 'perm')) { |
|
231 | + if ($permissions = module_invoke($module, 'perm')) { |
|
232 | 232 | foreach ($permissions as $permission) { |
233 | - $map[$permission] = $module; |
|
233 | + $map[$permission] = $module; |
|
234 | 234 | } |
235 | - } |
|
235 | + } |
|
236 | + } |
|
236 | 237 | } |
237 | - } |
|
238 | - return $map; |
|
238 | + return $map; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Represent the current state of permissions as a perm to role name array map. |
243 | 243 | */ |
244 | 244 | function _user_features_get_permissions() { |
245 | - $result = db_query("SELECT p.perm, r.name FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid ORDER BY r.rid ASC, p.perm ASC"); |
|
246 | - $permissions = array(); |
|
247 | - while ($row = db_fetch_object($result)) { |
|
245 | + $result = db_query("SELECT p.perm, r.name FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid ORDER BY r.rid ASC, p.perm ASC"); |
|
246 | + $permissions = array(); |
|
247 | + while ($row = db_fetch_object($result)) { |
|
248 | 248 | $role = $row->name; |
249 | 249 | $role_perms = explode(', ', $row->perm); |
250 | 250 | foreach ($role_perms as $perm) { |
251 | - if (!isset($permissions[$perm])) { |
|
251 | + if (!isset($permissions[$perm])) { |
|
252 | 252 | $permissions[$perm] = array(); |
253 | - } |
|
254 | - if(!in_array($role, $permissions[$perm])) { |
|
253 | + } |
|
254 | + if(!in_array($role, $permissions[$perm])) { |
|
255 | 255 | $permissions[$perm][] = $role; |
256 | - } |
|
256 | + } |
|
257 | + } |
|
257 | 258 | } |
258 | - } |
|
259 | - return $permissions; |
|
259 | + return $permissions; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Save/update an array of roles to the database. |
264 | 264 | */ |
265 | 265 | function _user_features_save_roles($roles) { |
266 | - // Write the updated permissions. |
|
267 | - foreach ($roles as $role) { |
|
266 | + // Write the updated permissions. |
|
267 | + foreach ($roles as $role) { |
|
268 | 268 | db_query("DELETE FROM {permission} WHERE rid = %d", $role['rid']); |
269 | 269 | $role['perm'] = implode(', ', $role['perm']); |
270 | 270 | drupal_write_record('permission', $role); |
271 | - } |
|
271 | + } |
|
272 | 272 | } |
@@ -4,142 +4,142 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function filter_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'filter' => array( |
9 | - 'name' => t('Filter formats'), |
|
10 | - 'default_hook' => 'filter_default_formats', |
|
11 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
9 | + 'name' => t('Filter formats'), |
|
10 | + 'default_hook' => 'filter_default_formats', |
|
11 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
12 | 12 | ), |
13 | - ); |
|
13 | + ); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Implementation of hook_features_export(). |
18 | 18 | */ |
19 | 19 | function filter_features_export($data, &$export, $module_name = '') { |
20 | - // The filter_default_formats() hook integration is provided by the |
|
21 | - // features module so we need to add it as a dependency. |
|
22 | - $export['dependencies']['features'] = 'features'; |
|
20 | + // The filter_default_formats() hook integration is provided by the |
|
21 | + // features module so we need to add it as a dependency. |
|
22 | + $export['dependencies']['features'] = 'features'; |
|
23 | 23 | |
24 | - $formats = _filter_get_formats(); |
|
25 | - foreach ($formats as $format) { |
|
24 | + $formats = _filter_get_formats(); |
|
25 | + foreach ($formats as $format) { |
|
26 | 26 | if (in_array($format['name'], $data)) { |
27 | - // Add format to exports |
|
28 | - $export['features']['filter'][$format['name']] = $format['name']; |
|
27 | + // Add format to exports |
|
28 | + $export['features']['filter'][$format['name']] = $format['name']; |
|
29 | 29 | |
30 | - // Iterate through filters and ensure each filter's module is included as a dependency |
|
31 | - foreach ($format['filters'] as $filter) { |
|
30 | + // Iterate through filters and ensure each filter's module is included as a dependency |
|
31 | + foreach ($format['filters'] as $filter) { |
|
32 | 32 | $export['dependencies'][$filter['module']] = $filter['module']; |
33 | - } |
|
33 | + } |
|
34 | + } |
|
34 | 35 | } |
35 | - } |
|
36 | 36 | |
37 | - $pipe = array(); |
|
38 | - return $pipe; |
|
37 | + $pipe = array(); |
|
38 | + return $pipe; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implementation of hook_features_export_render(). |
43 | 43 | */ |
44 | 44 | function filter_features_export_render($module, $data) { |
45 | - $code = array(); |
|
46 | - $code[] = ' $formats = array();'; |
|
47 | - $code[] = ''; |
|
45 | + $code = array(); |
|
46 | + $code[] = ' $formats = array();'; |
|
47 | + $code[] = ''; |
|
48 | 48 | |
49 | - $formats = _filter_get_formats(); |
|
50 | - foreach ($formats as $format) { |
|
49 | + $formats = _filter_get_formats(); |
|
50 | + foreach ($formats as $format) { |
|
51 | 51 | if (in_array($format['name'], $data)) { |
52 | - $format_export = features_var_export($format, ' '); |
|
53 | - $format_identifier = features_var_export($format['name']); |
|
54 | - $code[] = " // Exported format: {$format['name']}"; |
|
55 | - $code[] = " \$formats[{$format_identifier}] = {$format_export};"; |
|
56 | - $code[] = ""; |
|
52 | + $format_export = features_var_export($format, ' '); |
|
53 | + $format_identifier = features_var_export($format['name']); |
|
54 | + $code[] = " // Exported format: {$format['name']}"; |
|
55 | + $code[] = " \$formats[{$format_identifier}] = {$format_export};"; |
|
56 | + $code[] = ""; |
|
57 | + } |
|
57 | 58 | } |
58 | - } |
|
59 | 59 | |
60 | - $code[] = ' return $formats;'; |
|
61 | - $code = implode("\n", $code); |
|
62 | - return array('filter_default_formats' => $code); |
|
60 | + $code[] = ' return $formats;'; |
|
61 | + $code = implode("\n", $code); |
|
62 | + return array('filter_default_formats' => $code); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * Implementation of hook_features_revert(). |
67 | 67 | */ |
68 | 68 | function filter_features_revert($module) { |
69 | - return filter_features_rebuild($module); |
|
69 | + return filter_features_rebuild($module); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Implementation of hook_features_rebuild(). |
74 | 74 | */ |
75 | 75 | function filter_features_rebuild($module) { |
76 | - if ($defaults = features_get_default('filter', $module)) { |
|
76 | + if ($defaults = features_get_default('filter', $module)) { |
|
77 | 77 | foreach ($defaults as $format) { |
78 | - _filter_features_update($format); |
|
78 | + _filter_features_update($format); |
|
79 | + } |
|
79 | 80 | } |
80 | - } |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Retrieve all input formats with their respective filters loaded. |
85 | 85 | */ |
86 | 86 | function _filter_get_formats() { |
87 | - $formats = array(); |
|
87 | + $formats = array(); |
|
88 | 88 | |
89 | - // We cannot use user_roles() here because it has the names translated. |
|
90 | - $roles = _features_get_roles(); |
|
91 | - $result = db_query("SELECT * FROM {filter_formats}"); |
|
92 | - while ($row = db_fetch_object($result)) { |
|
89 | + // We cannot use user_roles() here because it has the names translated. |
|
90 | + $roles = _features_get_roles(); |
|
91 | + $result = db_query("SELECT * FROM {filter_formats}"); |
|
92 | + while ($row = db_fetch_object($result)) { |
|
93 | 93 | $format_roles = array(); |
94 | 94 | // Prepare a roles array with roles that may access the filter. |
95 | 95 | foreach ($roles as $name => $role) { |
96 | - if (strstr($row->roles, ','. $role['rid'] .',')) { |
|
96 | + if (strstr($row->roles, ','. $role['rid'] .',')) { |
|
97 | 97 | $format_roles[] = $name; |
98 | - } |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | $formats[$row->format] = array( |
101 | - 'name' => $row->name, |
|
102 | - 'roles' => $format_roles, |
|
103 | - 'filters' => array(), |
|
101 | + 'name' => $row->name, |
|
102 | + 'roles' => $format_roles, |
|
103 | + 'filters' => array(), |
|
104 | 104 | ); |
105 | 105 | foreach (_filter_list_format($row->format, TRUE) as $filter) { |
106 | - $formats[$row->format]['filters'][] = array( |
|
106 | + $formats[$row->format]['filters'][] = array( |
|
107 | 107 | 'module' => $filter->module, |
108 | 108 | 'delta' => $filter->delta, |
109 | 109 | 'weight' => $filter->weight, |
110 | - ); |
|
110 | + ); |
|
111 | + } |
|
111 | 112 | } |
112 | - } |
|
113 | 113 | |
114 | - return $formats; |
|
114 | + return $formats; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * Direct copy of filter_list_format() but with a way to clear the static. |
119 | 119 | */ |
120 | 120 | function _filter_list_format($format, $reset = FALSE) { |
121 | - static $filters = array(); |
|
121 | + static $filters = array(); |
|
122 | 122 | |
123 | - if (!isset($filters[$format]) || $reset) { |
|
123 | + if (!isset($filters[$format]) || $reset) { |
|
124 | 124 | $result = db_query("SELECT * FROM {filters} WHERE format = %d ORDER BY weight, module, delta", $format); |
125 | 125 | if (db_affected_rows($result) == 0 && !db_result(db_query("SELECT 1 FROM {filter_formats} WHERE format = %d", $format))) { |
126 | - // The format has no filters and does not exist, use the default input |
|
127 | - // format. |
|
128 | - $filters[$format] = filter_list_format(variable_get('filter_default_format', 1)); |
|
126 | + // The format has no filters and does not exist, use the default input |
|
127 | + // format. |
|
128 | + $filters[$format] = filter_list_format(variable_get('filter_default_format', 1)); |
|
129 | 129 | } |
130 | 130 | else { |
131 | - $filters[$format] = array(); |
|
132 | - while ($filter = db_fetch_object($result)) { |
|
131 | + $filters[$format] = array(); |
|
132 | + while ($filter = db_fetch_object($result)) { |
|
133 | 133 | $list = module_invoke($filter->module, 'filter', 'list'); |
134 | 134 | if (isset($list) && is_array($list) && isset($list[$filter->delta])) { |
135 | - $filter->name = $list[$filter->delta]; |
|
136 | - $filters[$format][$filter->module .'/'. $filter->delta] = $filter; |
|
135 | + $filter->name = $list[$filter->delta]; |
|
136 | + $filters[$format][$filter->module .'/'. $filter->delta] = $filter; |
|
137 | 137 | } |
138 | - } |
|
138 | + } |
|
139 | + } |
|
139 | 140 | } |
140 | - } |
|
141 | 141 | |
142 | - return $filters[$format]; |
|
142 | + return $filters[$format]; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -147,48 +147,48 @@ discard block |
||
147 | 147 | * Helper function for updating/inserting formats. |
148 | 148 | */ |
149 | 149 | function _filter_features_update($format) { |
150 | - $format_id = db_result(db_query("SELECT format FROM {filter_formats} WHERE name = '%s'", $format['name'])); |
|
151 | - |
|
152 | - // Format the role IDs into something that can be inserted into the database. |
|
153 | - // This is so painful. See filter.admin.inc line 218. : ( |
|
154 | - // We cannot use user_roles() here because it has the names translated. |
|
155 | - $roles = _features_get_roles(); |
|
156 | - $format_rids = array(); |
|
157 | - foreach ($format['roles'] as $role_name) { |
|
150 | + $format_id = db_result(db_query("SELECT format FROM {filter_formats} WHERE name = '%s'", $format['name'])); |
|
151 | + |
|
152 | + // Format the role IDs into something that can be inserted into the database. |
|
153 | + // This is so painful. See filter.admin.inc line 218. : ( |
|
154 | + // We cannot use user_roles() here because it has the names translated. |
|
155 | + $roles = _features_get_roles(); |
|
156 | + $format_rids = array(); |
|
157 | + foreach ($format['roles'] as $role_name) { |
|
158 | 158 | // Ensure that each role exists. If it does not, create it and store the rid. |
159 | 159 | if (!isset($roles[$role_name])) { |
160 | - $record = array('name' => $role_name); |
|
161 | - drupal_write_record('role', $record); |
|
162 | - $roles[$role_name]['rid'] = $record['rid']; |
|
163 | - $roles[$role_name]['perm'] = array(); |
|
160 | + $record = array('name' => $role_name); |
|
161 | + drupal_write_record('role', $record); |
|
162 | + $roles[$role_name]['rid'] = $record['rid']; |
|
163 | + $roles[$role_name]['perm'] = array(); |
|
164 | 164 | } |
165 | 165 | // Retrieve the rid corresponding to each role and add it to the format's rids |
166 | 166 | if (isset($roles[$role_name])) { |
167 | - $format_rids[] = $roles[$role_name]['rid']; |
|
167 | + $format_rids[] = $roles[$role_name]['rid']; |
|
168 | 168 | } |
169 | - } |
|
170 | - if ($format_id && $format_id == variable_get('filter_default_format', 1)) { |
|
169 | + } |
|
170 | + if ($format_id && $format_id == variable_get('filter_default_format', 1)) { |
|
171 | 171 | $format['roles'] = ','. implode(',', array_keys(user_roles())) .','; |
172 | - } |
|
173 | - else { |
|
172 | + } |
|
173 | + else { |
|
174 | 174 | $format['roles'] = ','. implode(',', $format_rids) .','; |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - // Update or insert the format |
|
178 | - if ($format_id) { |
|
177 | + // Update or insert the format |
|
178 | + if ($format_id) { |
|
179 | 179 | $format['format'] = $format_id; |
180 | 180 | drupal_write_record('filter_formats', $format, 'format'); |
181 | - } |
|
182 | - else { |
|
181 | + } |
|
182 | + else { |
|
183 | 183 | drupal_write_record('filter_formats', $format); |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - // Update the filters for the format |
|
187 | - if ($format['format']) { |
|
186 | + // Update the filters for the format |
|
187 | + if ($format['format']) { |
|
188 | 188 | db_query("DELETE FROM {filters} WHERE format = %d", $format['format']); |
189 | 189 | foreach ($format['filters'] as $filter) { |
190 | - $filter['format'] = $format['format']; |
|
191 | - drupal_write_record('filters', $filter); |
|
190 | + $filter['format'] = $format['format']; |
|
191 | + drupal_write_record('filters', $filter); |
|
192 | + } |
|
192 | 193 | } |
193 | - } |
|
194 | 194 | } |
@@ -4,63 +4,63 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function content_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'content' => array( |
9 | - 'name' => t('CCK'), |
|
10 | - 'default_hook' => 'content_default_fields', |
|
11 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
12 | - 'feature_source' => TRUE, |
|
9 | + 'name' => t('CCK'), |
|
10 | + 'default_hook' => 'content_default_fields', |
|
11 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
12 | + 'feature_source' => TRUE, |
|
13 | 13 | ), |
14 | - ); |
|
14 | + ); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Implementation of hook_features_export_options(). |
19 | 19 | */ |
20 | 20 | function content_features_export_options() { |
21 | - $options = array(); |
|
22 | - foreach (node_get_types('names') as $type => $type_name) { |
|
21 | + $options = array(); |
|
22 | + foreach (node_get_types('names') as $type => $type_name) { |
|
23 | 23 | $content_info = content_types($type); |
24 | 24 | if (!empty($content_info['fields'])) { |
25 | - foreach ($content_info['fields'] as $field) { |
|
25 | + foreach ($content_info['fields'] as $field) { |
|
26 | 26 | $field_name = isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; |
27 | 27 | $options[content_features_identifier($field)] = "{$type_name}: {$field_name}"; |
28 | - } |
|
28 | + } |
|
29 | + } |
|
29 | 30 | } |
30 | - } |
|
31 | - return $options; |
|
31 | + return $options; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Implementation of hook_features_export(). |
36 | 36 | */ |
37 | 37 | function content_features_export($data, &$export, $module_name = '') { |
38 | - features_include_defaults('content'); |
|
39 | - $pipe = array(); |
|
38 | + features_include_defaults('content'); |
|
39 | + $pipe = array(); |
|
40 | 40 | |
41 | - // The content_default_fields() hook integration is provided by the |
|
42 | - // features module so we need to add it as a dependency. |
|
43 | - $export['dependencies']['features'] = 'features'; |
|
41 | + // The content_default_fields() hook integration is provided by the |
|
42 | + // features module so we need to add it as a dependency. |
|
43 | + $export['dependencies']['features'] = 'features'; |
|
44 | 44 | |
45 | - // Collect a field to module map |
|
46 | - $map = features_get_default_map('content', NULL, 'content_features_identifier'); |
|
47 | - foreach ($data as $instance) { |
|
45 | + // Collect a field to module map |
|
46 | + $map = features_get_default_map('content', NULL, 'content_features_identifier'); |
|
47 | + foreach ($data as $instance) { |
|
48 | 48 | // If this field is already provided by another module remove the field. |
49 | 49 | // We do not add the other module as a dependency as the field-providing |
50 | 50 | // module may be extending the content type in question. |
51 | 51 | if (isset($map[$instance]) && $map[$instance] != $module_name) { |
52 | - if (isset($export['features']['content'][$instance])) { |
|
52 | + if (isset($export['features']['content'][$instance])) { |
|
53 | 53 | unset($export['features']['content'][$instance]); |
54 | - } |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | // If the field has not yet been exported, add it |
57 | 57 | else { |
58 | - $split = explode('-', $instance); |
|
59 | - $type_name = $split[0]; |
|
60 | - $field_name = $split[1]; |
|
61 | - $field = content_fields($field_name, $type_name); |
|
58 | + $split = explode('-', $instance); |
|
59 | + $type_name = $split[0]; |
|
60 | + $field_name = $split[1]; |
|
61 | + $field = content_fields($field_name, $type_name); |
|
62 | 62 | |
63 | - if (!empty($field)) { |
|
63 | + if (!empty($field)) { |
|
64 | 64 | // Add field item instance for later export. |
65 | 65 | $export['features']['content'][$instance] = $instance; |
66 | 66 | |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | |
73 | 73 | // Add modules which provide display. |
74 | 74 | foreach (array('teaser', 'full') as $display) { |
75 | - $formatter = _content_get_formatter($field['display_settings'][$display]['format'], $field['type']); |
|
76 | - $export['dependencies'][$formatter['module']] = $formatter['module']; |
|
75 | + $formatter = _content_get_formatter($field['display_settings'][$display]['format'], $field['type']); |
|
76 | + $export['dependencies'][$formatter['module']] = $formatter['module']; |
|
77 | 77 | |
78 | - // TODO make this logic more generic, for now though we just handle |
|
79 | - // the imagecache presets. |
|
80 | - if ($formatter['module'] == 'imagecache') { |
|
78 | + // TODO make this logic more generic, for now though we just handle |
|
79 | + // the imagecache presets. |
|
80 | + if ($formatter['module'] == 'imagecache') { |
|
81 | 81 | $format = $field['display_settings'][$display]['format']; |
82 | 82 | |
83 | 83 | $parts = explode('_', $format); |
@@ -85,57 +85,57 @@ discard block |
||
85 | 85 | $presetname = implode('_', $parts); |
86 | 86 | |
87 | 87 | $pipe[$formatter['module']][] = $presetname; |
88 | - } |
|
88 | + } |
|
89 | + } |
|
89 | 90 | } |
90 | - } |
|
91 | 91 | } |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - return $pipe; |
|
94 | + return $pipe; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Implementation of hook_features_export_render(). |
99 | 99 | */ |
100 | 100 | function content_features_export_render($module, $data) { |
101 | - $translatables = $code = array(); |
|
101 | + $translatables = $code = array(); |
|
102 | 102 | |
103 | - $code[] = ' $fields = array();'; |
|
104 | - $code[] = ''; |
|
105 | - foreach ($data as $instance) { |
|
103 | + $code[] = ' $fields = array();'; |
|
104 | + $code[] = ''; |
|
105 | + foreach ($data as $instance) { |
|
106 | 106 | $instance = explode('-', $instance); |
107 | 107 | $type_name = $instance[0]; |
108 | 108 | $field_name = $instance[1]; |
109 | 109 | if ($field = content_fields($field_name, $type_name)) { |
110 | - unset($field['columns']); |
|
111 | - unset($field['locked']); |
|
112 | - unset($field['db_storage']); |
|
113 | - $field_identifier = features_var_export(content_features_identifier($field)); |
|
114 | - $field_export = features_var_export($field, ' '); |
|
115 | - |
|
116 | - $code[] = " // Exported field: {$field_name}"; |
|
117 | - $code[] = " \$fields[{$field_identifier}] = {$field_export};"; |
|
118 | - $code[] = ""; |
|
119 | - |
|
120 | - // Add any labels to translatables array. |
|
121 | - if (!empty($field['widget']['label'])) { |
|
110 | + unset($field['columns']); |
|
111 | + unset($field['locked']); |
|
112 | + unset($field['db_storage']); |
|
113 | + $field_identifier = features_var_export(content_features_identifier($field)); |
|
114 | + $field_export = features_var_export($field, ' '); |
|
115 | + |
|
116 | + $code[] = " // Exported field: {$field_name}"; |
|
117 | + $code[] = " \$fields[{$field_identifier}] = {$field_export};"; |
|
118 | + $code[] = ""; |
|
119 | + |
|
120 | + // Add any labels to translatables array. |
|
121 | + if (!empty($field['widget']['label'])) { |
|
122 | 122 | $translatables[] = $field['widget']['label']; |
123 | - } |
|
123 | + } |
|
124 | + } |
|
124 | 125 | } |
125 | - } |
|
126 | - if (!empty($translatables)) { |
|
126 | + if (!empty($translatables)) { |
|
127 | 127 | $code[] = features_translatables_export($translatables, ' '); |
128 | - } |
|
129 | - $code[] = ' return $fields;'; |
|
130 | - $code = implode("\n", $code); |
|
131 | - return array('content_default_fields' => $code); |
|
128 | + } |
|
129 | + $code[] = ' return $fields;'; |
|
130 | + $code = implode("\n", $code); |
|
131 | + return array('content_default_fields' => $code); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Implementation of hook_features_revert(). |
136 | 136 | */ |
137 | 137 | function content_features_revert($module) { |
138 | - content_features_rebuild($module); |
|
138 | + content_features_rebuild($module); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,29 +143,29 @@ discard block |
||
143 | 143 | * Rebuilds CCK field definitions from code defaults. |
144 | 144 | */ |
145 | 145 | function content_features_rebuild($module) { |
146 | - if ($fields = features_get_default('content', $module)) { |
|
146 | + if ($fields = features_get_default('content', $module)) { |
|
147 | 147 | module_load_include('inc', 'content', 'includes/content.crud'); |
148 | 148 | content_clear_type_cache(TRUE); |
149 | 149 | |
150 | 150 | foreach ($fields as $field) { |
151 | - // We use content_field_instance_read() here so that we can get inactive |
|
152 | - // fields too. We can't just pass $field to it as the fnc will add every |
|
153 | - // item of the array to the WHERE clause. |
|
154 | - $param = array('field_name' => $field['field_name'], 'type_name' => $field['type_name']); |
|
155 | - $existing_instance = array_shift(content_field_instance_read($param, TRUE)); |
|
151 | + // We use content_field_instance_read() here so that we can get inactive |
|
152 | + // fields too. We can't just pass $field to it as the fnc will add every |
|
153 | + // item of the array to the WHERE clause. |
|
154 | + $param = array('field_name' => $field['field_name'], 'type_name' => $field['type_name']); |
|
155 | + $existing_instance = array_shift(content_field_instance_read($param, TRUE)); |
|
156 | 156 | |
157 | - if (!empty($existing_instance)) { |
|
157 | + if (!empty($existing_instance)) { |
|
158 | 158 | // If this existing instance is inactive, we need to activate it before |
159 | 159 | // running content_field_instance_update(). |
160 | 160 | if (empty($existing_instance['widget_active'])) { |
161 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active = 1 WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
162 | - // We need to clear the type cache again, unfortunately. |
|
163 | - content_clear_type_cache(TRUE); |
|
161 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_active = 1 WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']); |
|
162 | + // We need to clear the type cache again, unfortunately. |
|
163 | + content_clear_type_cache(TRUE); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | content_field_instance_update($field, FALSE); |
167 | - } |
|
168 | - else { |
|
167 | + } |
|
168 | + else { |
|
169 | 169 | // Summary: content_field_instance_create() will fall back to prior |
170 | 170 | // instance values for weight, label, desc if not set. |
171 | 171 | // See http://drupal.org/node/686240#comment-2786162 |
@@ -173,40 +173,40 @@ discard block |
||
173 | 173 | $field['label'] = $field['widget']['label']; |
174 | 174 | $field['description'] = $field['widget']['description']; |
175 | 175 | content_field_instance_create($field, FALSE); |
176 | - } |
|
177 | - variable_set('menu_rebuild_needed', TRUE); |
|
176 | + } |
|
177 | + variable_set('menu_rebuild_needed', TRUE); |
|
178 | + } |
|
178 | 179 | } |
179 | - } |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * Callback for generating the field exportable identifier for a field. |
184 | 184 | */ |
185 | 185 | function content_features_identifier($field) { |
186 | - return isset($field['type_name'], $field['field_name']) ? "{$field['type_name']}-{$field['field_name']}" : FALSE; |
|
186 | + return isset($field['type_name'], $field['field_name']) ? "{$field['type_name']}-{$field['field_name']}" : FALSE; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Helper function: retrieve default fields by node type. |
191 | 191 | */ |
192 | 192 | function content_features_fields_default($node_type, $reset = FALSE) { |
193 | - static $content_default_fields; |
|
194 | - if (!isset($content_default_fields) || $reset) { |
|
193 | + static $content_default_fields; |
|
194 | + if (!isset($content_default_fields) || $reset) { |
|
195 | 195 | foreach (features_get_default('content') as $field) { |
196 | - $content_default_fields[$field['type_name']][] = $field['field_name']; |
|
196 | + $content_default_fields[$field['type_name']][] = $field['field_name']; |
|
197 | 197 | } |
198 | - } |
|
199 | - return isset($content_default_fields[$node_type]) ? $content_default_fields[$node_type] : array(); |
|
198 | + } |
|
199 | + return isset($content_default_fields[$node_type]) ? $content_default_fields[$node_type] : array(); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Helper function: retrieve normal fields by node type. |
204 | 204 | */ |
205 | 205 | function content_features_fields_normal($node_type) { |
206 | - $normal_fields = array(); |
|
207 | - $content_info = content_types($node_type); |
|
208 | - if (!empty($content_info['fields'])) { |
|
206 | + $normal_fields = array(); |
|
207 | + $content_info = content_types($node_type); |
|
208 | + if (!empty($content_info['fields'])) { |
|
209 | 209 | $normal_fields = array_keys($content_info['fields']); |
210 | - } |
|
211 | - return $normal_fields; |
|
210 | + } |
|
211 | + return $normal_fields; |
|
212 | 212 | } |
@@ -5,39 +5,39 @@ discard block |
||
5 | 5 | * Dynamically declare functions under a ctools component's namespace if they are not already declared. |
6 | 6 | */ |
7 | 7 | foreach (_ctools_features_get_info() as $component => $info) { |
8 | - $code = ''; |
|
9 | - if (!function_exists("{$info['module']}_features_api")) { |
|
8 | + $code = ''; |
|
9 | + if (!function_exists("{$info['module']}_features_api")) { |
|
10 | 10 | $code .= 'function '. $info['module'] .'_features_api() { return ctools_component_features_api("'. $info['module'] .'"); }'; |
11 | - } |
|
12 | - if (!function_exists("{$component}_features_export")) { |
|
11 | + } |
|
12 | + if (!function_exists("{$component}_features_export")) { |
|
13 | 13 | $code .= 'function '. $component .'_features_export($data, &$export, $module_name = "") { return ctools_component_features_export("'. $component .'", $data, $export, $module_name); }'; |
14 | - } |
|
15 | - if (!function_exists("{$component}_features_export_options")) { |
|
14 | + } |
|
15 | + if (!function_exists("{$component}_features_export_options")) { |
|
16 | 16 | $code .= 'function '. $component .'_features_export_options() { return ctools_component_features_export_options("'. $component .'"); }'; |
17 | - } |
|
18 | - if (!function_exists("{$component}_features_export_render")) { |
|
17 | + } |
|
18 | + if (!function_exists("{$component}_features_export_render")) { |
|
19 | 19 | $code .= 'function '. $component .'_features_export_render($module, $data) { return ctools_component_features_export_render("'. $component .'", $module, $data); }'; |
20 | - } |
|
21 | - if (!function_exists("{$component}_features_revert")) { |
|
20 | + } |
|
21 | + if (!function_exists("{$component}_features_revert")) { |
|
22 | 22 | $code .= 'function '. $component .'_features_revert($module) { return ctools_component_features_revert("'. $component .'", $module); }'; |
23 | - } |
|
24 | - eval($code); |
|
23 | + } |
|
24 | + eval($code); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Implementation of hook_features_api(). |
29 | 29 | */ |
30 | 30 | function ctools_features_api() { |
31 | - return array( |
|
31 | + return array( |
|
32 | 32 | 'ctools' => array( |
33 | - 'name' => 'CTools export API', |
|
34 | - 'feature_source' => TRUE, |
|
35 | - 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
36 | - // CTools API integration does not include a default hook declaration as |
|
37 | - // it is not a proper default hook. |
|
38 | - // 'default_hook' => 'ctools_plugin_api', |
|
33 | + 'name' => 'CTools export API', |
|
34 | + 'feature_source' => TRUE, |
|
35 | + 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
36 | + // CTools API integration does not include a default hook declaration as |
|
37 | + // it is not a proper default hook. |
|
38 | + // 'default_hook' => 'ctools_plugin_api', |
|
39 | 39 | ), |
40 | - ); |
|
40 | + ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,20 +45,20 @@ discard block |
||
45 | 45 | * Adds references to the ctools mothership hook, ctools_plugin_api(). |
46 | 46 | */ |
47 | 47 | function ctools_features_export($data, &$export, $module_name = '') { |
48 | - // Add ctools dependency |
|
49 | - $export['dependencies']['ctools'] = 'ctools'; |
|
48 | + // Add ctools dependency |
|
49 | + $export['dependencies']['ctools'] = 'ctools'; |
|
50 | 50 | |
51 | - // Add the actual ctools components which will need to be accounted for in |
|
52 | - // hook_ctools_plugin_api(). The components are actually identified by a |
|
53 | - // delimited list of values: `module_name:api:current_version` |
|
54 | - foreach ($data as $component) { |
|
51 | + // Add the actual ctools components which will need to be accounted for in |
|
52 | + // hook_ctools_plugin_api(). The components are actually identified by a |
|
53 | + // delimited list of values: `module_name:api:current_version` |
|
54 | + foreach ($data as $component) { |
|
55 | 55 | if ($info = _ctools_features_get_info($component)) { |
56 | - $identifier = "{$info['module']}:{$info['api']}:{$info['current_version']}"; |
|
57 | - $export['features']['ctools'][$identifier] = $identifier; |
|
56 | + $identifier = "{$info['module']}:{$info['api']}:{$info['current_version']}"; |
|
57 | + $export['features']['ctools'][$identifier] = $identifier; |
|
58 | + } |
|
58 | 59 | } |
59 | - } |
|
60 | 60 | |
61 | - return array(); |
|
61 | + return array(); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,21 +66,21 @@ discard block |
||
66 | 66 | * Adds the ctools mothership hook, ctools_plugin_api(). |
67 | 67 | */ |
68 | 68 | function ctools_features_export_render($module, $data) { |
69 | - $code = array(); |
|
70 | - $code[] = ' list($module, $api) = func_get_args();'; |
|
69 | + $code = array(); |
|
70 | + $code[] = ' list($module, $api) = func_get_args();'; |
|
71 | 71 | |
72 | - $first = TRUE; |
|
73 | - foreach ($data as $component) { |
|
72 | + $first = TRUE; |
|
73 | + foreach ($data as $component) { |
|
74 | 74 | if ($info = _ctools_features_get_info($component)) { |
75 | - $if = $first ? 'if' : 'elseif'; |
|
76 | - $code[] = ' '. $if .' ($module == "'. $info['module'] .'" && $api == "'. $info['api'] .'") {'; |
|
77 | - $code[] = ' return array("version" => '. $info['current_version'] .');'; |
|
78 | - $code[] = ' }'; |
|
75 | + $if = $first ? 'if' : 'elseif'; |
|
76 | + $code[] = ' '. $if .' ($module == "'. $info['module'] .'" && $api == "'. $info['api'] .'") {'; |
|
77 | + $code[] = ' return array("version" => '. $info['current_version'] .');'; |
|
78 | + $code[] = ' }'; |
|
79 | 79 | |
80 | - $first = FALSE; |
|
80 | + $first = FALSE; |
|
81 | + } |
|
81 | 82 | } |
82 | - } |
|
83 | - return array('ctools_plugin_api' => implode("\n", $code)); |
|
83 | + return array('ctools_plugin_api' => implode("\n", $code)); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -90,231 +90,231 @@ discard block |
||
90 | 90 | * component module's namespace instead. |
91 | 91 | */ |
92 | 92 | function ctools_component_features_api($module_name) { |
93 | - $api = array(); |
|
94 | - foreach (_ctools_features_get_info() as $component => $info) { |
|
93 | + $api = array(); |
|
94 | + foreach (_ctools_features_get_info() as $component => $info) { |
|
95 | 95 | if ($info['module'] === $module_name) { |
96 | - $api[$component] = $info; |
|
96 | + $api[$component] = $info; |
|
97 | 97 | } |
98 | - } |
|
99 | - return $api; |
|
98 | + } |
|
99 | + return $api; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Master implementation of hook_features_export_options() for all ctools components. |
104 | 104 | */ |
105 | 105 | function ctools_component_features_export_options($component) { |
106 | - $options = array(); |
|
106 | + $options = array(); |
|
107 | 107 | |
108 | - ctools_include('export'); |
|
109 | - $schema = ctools_export_get_schema($component); |
|
110 | - if ($schema && $schema['export']['bulk export']) { |
|
108 | + ctools_include('export'); |
|
109 | + $schema = ctools_export_get_schema($component); |
|
110 | + if ($schema && $schema['export']['bulk export']) { |
|
111 | 111 | if (!empty($schema['export']['list callback']) && function_exists($schema['export']['list callback'])) { |
112 | - $options = $schema['export']['list callback'](); |
|
112 | + $options = $schema['export']['list callback'](); |
|
113 | 113 | } |
114 | 114 | else { |
115 | - $options = _ctools_features_export_default_list($component, $schema); |
|
115 | + $options = _ctools_features_export_default_list($component, $schema); |
|
116 | 116 | } |
117 | - } |
|
118 | - asort($options); |
|
119 | - return $options; |
|
117 | + } |
|
118 | + asort($options); |
|
119 | + return $options; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Master implementation of hook_features_export() for all ctools components. |
124 | 124 | */ |
125 | 125 | function ctools_component_features_export($component, $data, &$export, $module_name = '') { |
126 | - // Add the actual implementing module as a dependency |
|
127 | - $info = _ctools_features_get_info(); |
|
128 | - if ($module_name !== $info[$component]['module']) { |
|
126 | + // Add the actual implementing module as a dependency |
|
127 | + $info = _ctools_features_get_info(); |
|
128 | + if ($module_name !== $info[$component]['module']) { |
|
129 | 129 | $export['dependencies'][$info[$component]['module']] = $info[$component]['module']; |
130 | - } |
|
130 | + } |
|
131 | 131 | |
132 | - // Add the components |
|
133 | - foreach ($data as $object_name) { |
|
132 | + // Add the components |
|
133 | + foreach ($data as $object_name) { |
|
134 | 134 | if ($object = _ctools_features_export_crud_load($component, $object_name)) { |
135 | - // If this object is provided as a default by a different module, don't |
|
136 | - // export and add that module as a dependency instead. |
|
137 | - if (!empty($object->export_module) && $object->export_module !== $module_name) { |
|
135 | + // If this object is provided as a default by a different module, don't |
|
136 | + // export and add that module as a dependency instead. |
|
137 | + if (!empty($object->export_module) && $object->export_module !== $module_name) { |
|
138 | 138 | $export['dependencies'][$object->export_module] = $object->export_module; |
139 | 139 | if (isset($export['features'][$component][$object_name])) { |
140 | - unset($export['features'][$component][$object_name]); |
|
140 | + unset($export['features'][$component][$object_name]); |
|
141 | 141 | } |
142 | - } |
|
143 | - // Otherwise, add the component. |
|
144 | - else { |
|
142 | + } |
|
143 | + // Otherwise, add the component. |
|
144 | + else { |
|
145 | 145 | $export['features'][$component][$object_name] = $object_name; |
146 | - } |
|
146 | + } |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | |
150 | - // Let CTools handle API integration for this component. |
|
151 | - return array('ctools' => array($component)); |
|
150 | + // Let CTools handle API integration for this component. |
|
151 | + return array('ctools' => array($component)); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Master implementation of hook_features_export_render() for all ctools components. |
156 | 156 | */ |
157 | 157 | function ctools_component_features_export_render($component, $module, $data) { |
158 | - ctools_include('export'); |
|
159 | - $schema = ctools_export_get_schema($component); |
|
158 | + ctools_include('export'); |
|
159 | + $schema = ctools_export_get_schema($component); |
|
160 | 160 | |
161 | - if (function_exists($schema['export']['to hook code callback'])) { |
|
161 | + if (function_exists($schema['export']['to hook code callback'])) { |
|
162 | 162 | $export = $schema['export']['to hook code callback']($data, $module); |
163 | 163 | $code = explode("{\n", $export); |
164 | 164 | array_shift($code); |
165 | 165 | $code = explode('}', implode($code, "{\n")); |
166 | 166 | array_pop($code); |
167 | 167 | $code = implode('}', $code); |
168 | - } |
|
169 | - else { |
|
168 | + } |
|
169 | + else { |
|
170 | 170 | $code = ' $export = array();'."\n\n"; |
171 | 171 | foreach ($data as $object_name) { |
172 | - if ($object = _ctools_features_export_crud_load($component, $object_name)) { |
|
172 | + if ($object = _ctools_features_export_crud_load($component, $object_name)) { |
|
173 | 173 | $identifier = $schema['export']['identifier']; |
174 | 174 | $code .= _ctools_features_export_crud_export($component, $object, ' '); |
175 | 175 | $code .= " \$export[" . ctools_var_export($object_name) . "] = \${$identifier};\n\n"; |
176 | - } |
|
176 | + } |
|
177 | 177 | } |
178 | 178 | $code .= ' return $export;'; |
179 | - } |
|
179 | + } |
|
180 | 180 | |
181 | - return array($schema['export']['default hook'] => $code); |
|
181 | + return array($schema['export']['default hook'] => $code); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * Master implementation of hook_features_revert() for all ctools components. |
186 | 186 | */ |
187 | 187 | function ctools_component_features_revert($component, $module) { |
188 | - if ($objects = features_get_default($component, $module)) { |
|
188 | + if ($objects = features_get_default($component, $module)) { |
|
189 | 189 | foreach ($objects as $object) { |
190 | - _ctools_features_export_crud_delete($component, $object); |
|
190 | + _ctools_features_export_crud_delete($component, $object); |
|
191 | + } |
|
191 | 192 | } |
192 | - } |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Helper function to return various ctools information for components. |
197 | 197 | */ |
198 | 198 | function _ctools_features_get_info($identifier = NULL, $reset = FALSE) { |
199 | - static $components; |
|
200 | - if (!isset($components) || $reset) { |
|
199 | + static $components; |
|
200 | + if (!isset($components) || $reset) { |
|
201 | 201 | $components = array(); |
202 | 202 | $modules = features_get_info(); |
203 | 203 | ctools_include('export'); |
204 | 204 | foreach (ctools_export_get_schemas_by_module() as $module => $schemas) { |
205 | - foreach ($schemas as $table => $schema) { |
|
205 | + foreach ($schemas as $table => $schema) { |
|
206 | 206 | if ($schema['export']['bulk export']) { |
207 | - // Let the API owner take precedence as the owning module. |
|
208 | - $api_module = isset($schema['export']['api']['owner']) ? $schema['export']['api']['owner'] : $module; |
|
209 | - $components[$table] = array( |
|
207 | + // Let the API owner take precedence as the owning module. |
|
208 | + $api_module = isset($schema['export']['api']['owner']) ? $schema['export']['api']['owner'] : $module; |
|
209 | + $components[$table] = array( |
|
210 | 210 | 'name' => isset($modules[$api_module]->info['name']) ? $modules[$api_module]->info['name'] : $api_module, |
211 | 211 | 'default_hook' => $schema['export']['default hook'], |
212 | 212 | 'default_file' => FEATURES_DEFAULTS_CUSTOM, |
213 | 213 | 'module' => $api_module, |
214 | 214 | 'feature_source' => TRUE, |
215 | - ); |
|
216 | - if (isset($schema['export']['api'])) { |
|
215 | + ); |
|
216 | + if (isset($schema['export']['api'])) { |
|
217 | 217 | $components[$table] += array( |
218 | - 'api' => $schema['export']['api']['api'], |
|
219 | - 'default_filename' => $schema['export']['api']['api'], |
|
220 | - 'current_version' => $schema['export']['api']['current_version'], |
|
218 | + 'api' => $schema['export']['api']['api'], |
|
219 | + 'default_filename' => $schema['export']['api']['api'], |
|
220 | + 'current_version' => $schema['export']['api']['current_version'], |
|
221 | 221 | ); |
222 | - } |
|
222 | + } |
|
223 | + } |
|
223 | 224 | } |
224 | - } |
|
225 | 225 | } |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Return information specific to a particular component. |
|
229 | - if (isset($identifier)) { |
|
228 | + // Return information specific to a particular component. |
|
229 | + if (isset($identifier)) { |
|
230 | 230 | // Identified by the table name. |
231 | 231 | if (isset($components[$identifier])) { |
232 | - return $components[$identifier]; |
|
232 | + return $components[$identifier]; |
|
233 | 233 | } |
234 | 234 | // New API identifier. Allows non-exportables related CTools APIs to be |
235 | 235 | // supported by an explicit `module:api:current_version` key. |
236 | 236 | else if (substr_count($identifier, ':') === 2) { |
237 | - list($module, $api, $current_version) = explode(':', $identifier); |
|
238 | - // If a schema component matches the provided identifier, provide that |
|
239 | - // information. This also ensures that the version number is up to date. |
|
240 | - foreach ($components as $table => $info) { |
|
237 | + list($module, $api, $current_version) = explode(':', $identifier); |
|
238 | + // If a schema component matches the provided identifier, provide that |
|
239 | + // information. This also ensures that the version number is up to date. |
|
240 | + foreach ($components as $table => $info) { |
|
241 | 241 | if ($info['module'] == $module && $info['api'] == $api && $info['current_version'] >= $current_version) { |
242 | - return $info; |
|
242 | + return $info; |
|
243 | + } |
|
243 | 244 | } |
244 | - } |
|
245 | - // Fallback to just giving back what was provided to us. |
|
246 | - return array('module' => $module, 'api' => $api, 'current_version' => $current_version); |
|
245 | + // Fallback to just giving back what was provided to us. |
|
246 | + return array('module' => $module, 'api' => $api, 'current_version' => $current_version); |
|
247 | 247 | } |
248 | 248 | return FALSE; |
249 | - } |
|
249 | + } |
|
250 | 250 | |
251 | - return $components; |
|
251 | + return $components; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
255 | 255 | * Wrapper around ctools_export_crud_export() for < 1.7 compatibility. |
256 | 256 | */ |
257 | 257 | function _ctools_features_export_crud_export($table, $object, $indent = '') { |
258 | - return ctools_api_version('1.7') ? ctools_export_crud_export($table, $object, $indent) : ctools_export_object($table, $object, $indent); |
|
258 | + return ctools_api_version('1.7') ? ctools_export_crud_export($table, $object, $indent) : ctools_export_object($table, $object, $indent); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
262 | 262 | * Wrapper around ctools_export_crud_load() for < 1.7 compatibility. |
263 | 263 | */ |
264 | 264 | function _ctools_features_export_crud_load($table, $name) { |
265 | - if (ctools_api_version('1.7')) { |
|
265 | + if (ctools_api_version('1.7')) { |
|
266 | 266 | return ctools_export_crud_load($table, $name); |
267 | - } |
|
268 | - elseif ($objects = ctools_export_load_object($table, 'names', array($name))) { |
|
267 | + } |
|
268 | + elseif ($objects = ctools_export_load_object($table, 'names', array($name))) { |
|
269 | 269 | return array_shift($objects); |
270 | - } |
|
271 | - return FALSE; |
|
270 | + } |
|
271 | + return FALSE; |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * Wrapper around ctools_export_default_list() for < 1.7 compatibility. |
276 | 276 | */ |
277 | 277 | function _ctools_features_export_default_list($table, $schema) { |
278 | - if (ctools_api_version('1.7')) { |
|
278 | + if (ctools_api_version('1.7')) { |
|
279 | 279 | return ctools_export_default_list($table, $schema); |
280 | - } |
|
281 | - elseif ($objects = ctools_export_load_object($table, 'all')) { |
|
280 | + } |
|
281 | + elseif ($objects = ctools_export_load_object($table, 'all')) { |
|
282 | 282 | return drupal_map_assoc(array_keys($objects)); |
283 | - } |
|
284 | - return array(); |
|
283 | + } |
|
284 | + return array(); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Wrapper around ctools_export_crud_delete() for < 1.7 compatibility. |
289 | 289 | */ |
290 | 290 | function _ctools_features_export_crud_delete($table, $object) { |
291 | - if (ctools_api_version('1.7')) { |
|
291 | + if (ctools_api_version('1.7')) { |
|
292 | 292 | ctools_export_crud_delete($table, $object); |
293 | - } |
|
294 | - else { |
|
293 | + } |
|
294 | + else { |
|
295 | 295 | $schema = ctools_export_get_schema($table); |
296 | 296 | $export = $schema['export']; |
297 | 297 | db_query("DELETE FROM {{$table}} WHERE {$export['key']} = '%s'", $object->{$export['key']}); |
298 | - } |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
302 | 302 | * Implementation of hook_features_export_render() for page_manager. |
303 | 303 | */ |
304 | 304 | function page_manager_pages_features_export_render($module, $data) { |
305 | - // Ensure that handlers have their code included before exporting. |
|
306 | - page_manager_get_tasks(); |
|
307 | - return ctools_component_features_export_render('page_manager_pages', $module, $data); |
|
305 | + // Ensure that handlers have their code included before exporting. |
|
306 | + page_manager_get_tasks(); |
|
307 | + return ctools_component_features_export_render('page_manager_pages', $module, $data); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | 311 | * Implementation of hook_features_revert() for page_manager. |
312 | 312 | */ |
313 | 313 | function page_manager_pages_features_revert($module) { |
314 | - if ($pages = features_get_default('page_manager_pages', $module)) { |
|
314 | + if ($pages = features_get_default('page_manager_pages', $module)) { |
|
315 | 315 | require_once drupal_get_path('module','ctools').'/page_manager/plugins/tasks/page.inc'; |
316 | 316 | foreach ($pages as $page) { |
317 | - page_manager_page_delete($page); |
|
317 | + page_manager_page_delete($page); |
|
318 | + } |
|
318 | 319 | } |
319 | - } |
|
320 | 320 | } |
@@ -4,50 +4,50 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function features_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'dependencies' => array( |
9 | - 'name' => 'Dependencies', |
|
10 | - 'feature_source' => TRUE, |
|
11 | - 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
9 | + 'name' => 'Dependencies', |
|
10 | + 'feature_source' => TRUE, |
|
11 | + 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
12 | 12 | ), |
13 | - ); |
|
13 | + ); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Implementation of hook_features_export_options(). |
18 | 18 | */ |
19 | 19 | function dependencies_features_export_options() { |
20 | - // Excluded modules. |
|
21 | - $excluded = drupal_required_modules(); |
|
22 | - $options = array(); |
|
23 | - foreach (features_get_modules() as $module_name => $info) { |
|
20 | + // Excluded modules. |
|
21 | + $excluded = drupal_required_modules(); |
|
22 | + $options = array(); |
|
23 | + foreach (features_get_modules() as $module_name => $info) { |
|
24 | 24 | if (!in_array($module_name, $excluded) && $info->status && !empty($info->info)) { |
25 | - $options[$module_name] = $info->info['name']; |
|
25 | + $options[$module_name] = $info->info['name']; |
|
26 | 26 | } |
27 | - } |
|
28 | - return $options; |
|
27 | + } |
|
28 | + return $options; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Implementation of hook_features_export(). |
33 | 33 | */ |
34 | 34 | function dependencies_features_export($data, &$export, $module_name = '') { |
35 | - // Don't allow a module to depend upon itself. |
|
36 | - if (!empty($data[$module_name])) { |
|
35 | + // Don't allow a module to depend upon itself. |
|
36 | + if (!empty($data[$module_name])) { |
|
37 | 37 | unset($data[$module_name]); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - // Clean up existing dependencies and merge. |
|
41 | - $export['dependencies'] = _features_export_minimize_dependencies($export['dependencies'], $module_name); |
|
42 | - $export['dependencies'] = array_merge($data, $export['dependencies']); |
|
43 | - $export['dependencies'] = array_unique($export['dependencies']); |
|
40 | + // Clean up existing dependencies and merge. |
|
41 | + $export['dependencies'] = _features_export_minimize_dependencies($export['dependencies'], $module_name); |
|
42 | + $export['dependencies'] = array_merge($data, $export['dependencies']); |
|
43 | + $export['dependencies'] = array_unique($export['dependencies']); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Implementation of hook_features_revert(). |
48 | 48 | */ |
49 | 49 | function dependencies_features_revert($module) { |
50 | - dependencies_features_rebuild($module); |
|
50 | + dependencies_features_rebuild($module); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * Ensure that all of a feature's dependencies are enabled. |
56 | 56 | */ |
57 | 57 | function dependencies_features_rebuild($module) { |
58 | - $feature = features_get_features($module); |
|
59 | - if (!empty($feature->info['dependencies'])) { |
|
58 | + $feature = features_get_features($module); |
|
59 | + if (!empty($feature->info['dependencies'])) { |
|
60 | 60 | $install = array(); |
61 | 61 | foreach ($feature->info['dependencies'] as $dependency) { |
62 | - if (!module_exists($dependency)) { |
|
62 | + if (!module_exists($dependency)) { |
|
63 | 63 | $install[] = $dependency; |
64 | - } |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | if (!empty($install)) { |
67 | - features_install_modules($install); |
|
67 | + features_install_modules($install); |
|
68 | + } |
|
68 | 69 | } |
69 | - } |
|
70 | 70 | } |
@@ -4,27 +4,27 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function menu_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'menu_custom' => array( |
9 | - 'name' => t('Menus'), |
|
10 | - 'default_hook' => 'menu_default_menu_custom', |
|
11 | - 'feature_source' => TRUE, |
|
12 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
9 | + 'name' => t('Menus'), |
|
10 | + 'default_hook' => 'menu_default_menu_custom', |
|
11 | + 'feature_source' => TRUE, |
|
12 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
13 | 13 | ), |
14 | 14 | 'menu_links' => array( |
15 | - 'name' => t('Menu links'), |
|
16 | - 'default_hook' => 'menu_default_menu_links', |
|
17 | - 'feature_source' => TRUE, |
|
18 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
15 | + 'name' => t('Menu links'), |
|
16 | + 'default_hook' => 'menu_default_menu_links', |
|
17 | + 'feature_source' => TRUE, |
|
18 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
19 | 19 | ), |
20 | 20 | // DEPRECATED |
21 | 21 | 'menu' => array( |
22 | - 'name' => t('Menu items'), |
|
23 | - 'default_hook' => 'menu_default_items', |
|
24 | - 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
25 | - 'feature_source' => FALSE, |
|
22 | + 'name' => t('Menu items'), |
|
23 | + 'default_hook' => 'menu_default_items', |
|
24 | + 'default_file' => FEATURES_DEFAULTS_INCLUDED, |
|
25 | + 'feature_source' => FALSE, |
|
26 | 26 | ), |
27 | - ); |
|
27 | + ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,134 +33,134 @@ discard block |
||
33 | 33 | * to the `menu_links` type. |
34 | 34 | */ |
35 | 35 | function menu_features_export($data, &$export, $module_name = '') { |
36 | - $pipe = array(); |
|
37 | - foreach ($data as $path) { |
|
36 | + $pipe = array(); |
|
37 | + foreach ($data as $path) { |
|
38 | 38 | $pipe['menu_links'][] = "features:{$path}"; |
39 | - } |
|
40 | - return $pipe; |
|
39 | + } |
|
40 | + return $pipe; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Implementation of hook_features_export_options(). |
45 | 45 | */ |
46 | 46 | function menu_custom_features_export_options() { |
47 | - $options = array(); |
|
48 | - $result = db_query("SELECT * FROM {menu_custom}"); |
|
49 | - while ($row = db_fetch_array($result)) { |
|
47 | + $options = array(); |
|
48 | + $result = db_query("SELECT * FROM {menu_custom}"); |
|
49 | + while ($row = db_fetch_array($result)) { |
|
50 | 50 | $options[$row['menu_name']] = $row['title']; |
51 | - } |
|
52 | - return $options; |
|
51 | + } |
|
52 | + return $options; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Implementation of hook_features_export(). |
57 | 57 | */ |
58 | 58 | function menu_custom_features_export($data, &$export, $module_name = '') { |
59 | - // Default hooks are provided by the feature module so we need to add |
|
60 | - // it as a dependency. |
|
61 | - $export['dependencies']['features'] = 'features'; |
|
62 | - $export['dependencies']['menu'] = 'menu'; |
|
59 | + // Default hooks are provided by the feature module so we need to add |
|
60 | + // it as a dependency. |
|
61 | + $export['dependencies']['features'] = 'features'; |
|
62 | + $export['dependencies']['menu'] = 'menu'; |
|
63 | 63 | |
64 | - // Collect a menu to module map |
|
65 | - $pipe = array(); |
|
66 | - $map = features_get_default_map('menu_custom', 'menu_name'); |
|
67 | - foreach ($data as $menu_name) { |
|
64 | + // Collect a menu to module map |
|
65 | + $pipe = array(); |
|
66 | + $map = features_get_default_map('menu_custom', 'menu_name'); |
|
67 | + foreach ($data as $menu_name) { |
|
68 | 68 | // If this menu is provided by a different module, add it as a dependency. |
69 | 69 | if (isset($map[$menu_name]) && $map[$menu_name] != $module_name) { |
70 | - $export['dependencies'][$map[$menu_name]] = $map[$menu_name]; |
|
70 | + $export['dependencies'][$map[$menu_name]] = $map[$menu_name]; |
|
71 | 71 | } |
72 | 72 | else { |
73 | - $export['features']['menu_custom'][$menu_name] = $menu_name; |
|
73 | + $export['features']['menu_custom'][$menu_name] = $menu_name; |
|
74 | + } |
|
74 | 75 | } |
75 | - } |
|
76 | - return $pipe; |
|
76 | + return $pipe; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Implementation of hook_features_export_render() |
81 | 81 | */ |
82 | 82 | function menu_custom_features_export_render($module, $data) { |
83 | - $code = array(); |
|
84 | - $code[] = ' $menus = array();'; |
|
85 | - $code[] = ''; |
|
83 | + $code = array(); |
|
84 | + $code[] = ' $menus = array();'; |
|
85 | + $code[] = ''; |
|
86 | 86 | |
87 | - $translatables = array(); |
|
88 | - foreach ($data as $menu_name) { |
|
87 | + $translatables = array(); |
|
88 | + foreach ($data as $menu_name) { |
|
89 | 89 | $result = db_query("SELECT menu_name, title, description FROM {menu_custom} WHERE menu_name = '%s'", $menu_name); |
90 | 90 | while ($row = db_fetch_array($result)) { |
91 | - $export = features_var_export($row, ' '); |
|
92 | - $code[] = " // Exported menu: {$menu_name}"; |
|
93 | - $code[] = " \$menus['{$menu_name}'] = {$export};"; |
|
94 | - $translatables[] = $row['title']; |
|
95 | - $translatables[] = $row['description']; |
|
91 | + $export = features_var_export($row, ' '); |
|
92 | + $code[] = " // Exported menu: {$menu_name}"; |
|
93 | + $code[] = " \$menus['{$menu_name}'] = {$export};"; |
|
94 | + $translatables[] = $row['title']; |
|
95 | + $translatables[] = $row['description']; |
|
96 | 96 | } |
97 | - } |
|
98 | - if (!empty($translatables)) { |
|
97 | + } |
|
98 | + if (!empty($translatables)) { |
|
99 | 99 | $code[] = features_translatables_export($translatables, ' '); |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - $code[] = ''; |
|
103 | - $code[] = ' return $menus;'; |
|
104 | - $code = implode("\n", $code); |
|
105 | - return array('menu_default_menu_custom' => $code); |
|
102 | + $code[] = ''; |
|
103 | + $code[] = ' return $menus;'; |
|
104 | + $code = implode("\n", $code); |
|
105 | + return array('menu_default_menu_custom' => $code); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Implementation of hook_features_revert(). |
110 | 110 | */ |
111 | 111 | function menu_custom_features_revert($module) { |
112 | - menu_custom_features_rebuild($module); |
|
112 | + menu_custom_features_rebuild($module); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Implementation of hook_features_rebuild(). |
117 | 117 | */ |
118 | 118 | function menu_custom_features_rebuild($module) { |
119 | - if ($defaults = features_get_default('menu_custom', $module)) { |
|
119 | + if ($defaults = features_get_default('menu_custom', $module)) { |
|
120 | 120 | foreach ($defaults as $menu) { |
121 | - $existing = db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = '%s'", $menu['menu_name'])); |
|
122 | - drupal_write_record('menu_custom', $menu, $existing ? array('menu_name') : array()); |
|
121 | + $existing = db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = '%s'", $menu['menu_name'])); |
|
122 | + drupal_write_record('menu_custom', $menu, $existing ? array('menu_name') : array()); |
|
123 | + } |
|
123 | 124 | } |
124 | - } |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Implementation of hook_features_export_options(). |
129 | 129 | */ |
130 | 130 | function menu_links_features_export_options() { |
131 | - // We can't use the menu_tree_all_data function as it statically caches it's menu items |
|
132 | - // so if something calls the function before now without $menu_admin set to true we |
|
133 | - // won't see all the links. Instead we reproduce the essential parts of the |
|
134 | - // function here. |
|
131 | + // We can't use the menu_tree_all_data function as it statically caches it's menu items |
|
132 | + // so if something calls the function before now without $menu_admin set to true we |
|
133 | + // won't see all the links. Instead we reproduce the essential parts of the |
|
134 | + // function here. |
|
135 | 135 | |
136 | - $menu_links = array(); |
|
137 | - foreach (array_reverse(menu_get_menus()) as $menu_name => $menu_title) { |
|
136 | + $menu_links = array(); |
|
137 | + foreach (array_reverse(menu_get_menus()) as $menu_name => $menu_title) { |
|
138 | 138 | $data = array(); |
139 | 139 | $cid = 'links:' . $menu_name . ':all-cid:0'; |
140 | 140 | $cache = cache_get($cid, 'cache_menu'); |
141 | 141 | if ($cache && isset($cache->data)) { |
142 | - // If the cache entry exists, it will just be the cid for the actual data. |
|
143 | - // This avoids duplication of large amounts of data. |
|
144 | - $cache = cache_get($cache->data, 'cache_menu'); |
|
145 | - if ($cache && isset($cache->data)) { |
|
142 | + // If the cache entry exists, it will just be the cid for the actual data. |
|
143 | + // This avoids duplication of large amounts of data. |
|
144 | + $cache = cache_get($cache->data, 'cache_menu'); |
|
145 | + if ($cache && isset($cache->data)) { |
|
146 | 146 | $data = $cache->data; |
147 | - } |
|
147 | + } |
|
148 | 148 | } else { |
149 | - $data['tree'] = menu_tree_data(db_query(" |
|
149 | + $data['tree'] = menu_tree_data(db_query(" |
|
150 | 150 | SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* |
151 | 151 | FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path |
152 | 152 | WHERE ml.menu_name = '%s' |
153 | 153 | ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $menu_name)); |
154 | 154 | |
155 | - $data['node_links'] = array(); |
|
156 | - menu_tree_collect_node_links($data['tree'], $data['node_links']); |
|
157 | - // May as well cache the data, if it is not already in the cache. |
|
158 | - $tree_cid = _menu_tree_cid($menu_name, $data); |
|
159 | - if (!cache_get($tree_cid, 'cache_menu')) { |
|
155 | + $data['node_links'] = array(); |
|
156 | + menu_tree_collect_node_links($data['tree'], $data['node_links']); |
|
157 | + // May as well cache the data, if it is not already in the cache. |
|
158 | + $tree_cid = _menu_tree_cid($menu_name, $data); |
|
159 | + if (!cache_get($tree_cid, 'cache_menu')) { |
|
160 | 160 | cache_set($tree_cid, $data, 'cache_menu'); |
161 | - } |
|
162 | - // Cache the cid of the (shared) data using the menu and item-specific cid. |
|
163 | - cache_set($cid, $tree_cid, 'cache_menu'); |
|
161 | + } |
|
162 | + // Cache the cid of the (shared) data using the menu and item-specific cid. |
|
163 | + cache_set($cid, $tree_cid, 'cache_menu'); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $GLOBALS['menu_admin'] = TRUE; |
@@ -168,180 +168,180 @@ discard block |
||
168 | 168 | $GLOBALS['menu_admin'] = FALSE; |
169 | 169 | |
170 | 170 | _menu_links_features_export_options_recurse($data['tree'], $menu_name, '--', $menu_links); |
171 | - } |
|
172 | - return $menu_links; |
|
171 | + } |
|
172 | + return $menu_links; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | function _menu_links_features_export_options_recurse($tree, $menu_name, $indent, &$menu_links) { |
176 | - // We don't want to use _menu_parents_recurse as that could potentially cut out some |
|
177 | - // options as not being suitable for parents which we still want to export. Also we can |
|
178 | - // save on additional calls to the database. |
|
176 | + // We don't want to use _menu_parents_recurse as that could potentially cut out some |
|
177 | + // options as not being suitable for parents which we still want to export. Also we can |
|
178 | + // save on additional calls to the database. |
|
179 | 179 | |
180 | - foreach ($tree as $data) { |
|
180 | + foreach ($tree as $data) { |
|
181 | 181 | if ($data['link']['hidden'] >= 0) { |
182 | - $title = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, FALSE); |
|
183 | - if ($data['link']['hidden']) { |
|
182 | + $title = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, FALSE); |
|
183 | + if ($data['link']['hidden']) { |
|
184 | 184 | $title .= ' (' . t('disabled') . ')'; |
185 | - } |
|
186 | - $menu_links[menu_links_features_identifier($data['link'])] = "{$menu_name}: {$title}"; |
|
187 | - if ($data['below']) { |
|
185 | + } |
|
186 | + $menu_links[menu_links_features_identifier($data['link'])] = "{$menu_name}: {$title}"; |
|
187 | + if ($data['below']) { |
|
188 | 188 | _menu_links_features_export_options_recurse($data['below'], $menu_name, $indent . '--', $menu_links); |
189 | - } |
|
189 | + } |
|
190 | 190 | } |
191 | - } |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Callback for generating the menu link exportable identifier. |
196 | 196 | */ |
197 | 197 | function menu_links_features_identifier($link) { |
198 | - return isset($link['menu_name'], $link['link_path']) ? "{$link['menu_name']}:{$link['link_path']}" : FALSE; |
|
198 | + return isset($link['menu_name'], $link['link_path']) ? "{$link['menu_name']}:{$link['link_path']}" : FALSE; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * Implementation of hook_features_export(). |
203 | 203 | */ |
204 | 204 | function menu_links_features_export($data, &$export, $module_name = '') { |
205 | - // Default hooks are provided by the feature module so we need to add |
|
206 | - // it as a dependency. |
|
207 | - $export['dependencies']['features'] = 'features'; |
|
208 | - $export['dependencies']['menu'] = 'menu'; |
|
205 | + // Default hooks are provided by the feature module so we need to add |
|
206 | + // it as a dependency. |
|
207 | + $export['dependencies']['features'] = 'features'; |
|
208 | + $export['dependencies']['menu'] = 'menu'; |
|
209 | 209 | |
210 | - // Collect a link to module map |
|
211 | - $pipe = array(); |
|
212 | - $map = features_get_default_map('menu_links', 'menu_links_features_identifier'); |
|
213 | - foreach ($data as $identifier) { |
|
210 | + // Collect a link to module map |
|
211 | + $pipe = array(); |
|
212 | + $map = features_get_default_map('menu_links', 'menu_links_features_identifier'); |
|
213 | + foreach ($data as $identifier) { |
|
214 | 214 | if ($link = features_menu_link_load($identifier)) { |
215 | - // If this link is provided by a different module, add it as a dependency. |
|
216 | - if (isset($map[$identifier]) && $map[$identifier] != $module_name) { |
|
215 | + // If this link is provided by a different module, add it as a dependency. |
|
216 | + if (isset($map[$identifier]) && $map[$identifier] != $module_name) { |
|
217 | 217 | $export['dependencies'][$map[$identifier]] = $map[$identifier]; |
218 | - } |
|
219 | - else { |
|
218 | + } |
|
219 | + else { |
|
220 | 220 | $export['features']['menu_links'][$identifier] = $identifier; |
221 | - } |
|
222 | - // For now, exclude a variety of common menus from automatic export. |
|
223 | - // They may still be explicitly included in a Feature if the builder |
|
224 | - // chooses to do so. |
|
225 | - if (!in_array($link['menu_name'], array('features', 'primary-links', 'secondary-links', 'navigation', 'admin', 'devel'))) { |
|
221 | + } |
|
222 | + // For now, exclude a variety of common menus from automatic export. |
|
223 | + // They may still be explicitly included in a Feature if the builder |
|
224 | + // chooses to do so. |
|
225 | + if (!in_array($link['menu_name'], array('features', 'primary-links', 'secondary-links', 'navigation', 'admin', 'devel'))) { |
|
226 | 226 | $pipe['menu_custom'][] = $link['menu_name']; |
227 | - } |
|
227 | + } |
|
228 | 228 | } |
229 | - } |
|
230 | - return $pipe; |
|
229 | + } |
|
230 | + return $pipe; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Implementation of hook_features_export_render() |
235 | 235 | */ |
236 | 236 | function menu_links_features_export_render($module, $data) { |
237 | - $code = array(); |
|
238 | - $code[] = ' $menu_links = array();'; |
|
239 | - $code[] = ''; |
|
237 | + $code = array(); |
|
238 | + $code[] = ' $menu_links = array();'; |
|
239 | + $code[] = ''; |
|
240 | 240 | |
241 | - $translatables = array(); |
|
242 | - foreach ($data as $identifier) { |
|
241 | + $translatables = array(); |
|
242 | + foreach ($data as $identifier) { |
|
243 | 243 | if ($link = features_menu_link_load($identifier)) { |
244 | - // Replace plid with a parent path. |
|
245 | - if (!empty($link['plid']) && $parent = menu_link_load($link['plid'])) { |
|
244 | + // Replace plid with a parent path. |
|
245 | + if (!empty($link['plid']) && $parent = menu_link_load($link['plid'])) { |
|
246 | 246 | $link['parent_path'] = $parent['link_path']; |
247 | - } |
|
248 | - unset($link['plid']); |
|
249 | - unset($link['mlid']); |
|
247 | + } |
|
248 | + unset($link['plid']); |
|
249 | + unset($link['mlid']); |
|
250 | 250 | |
251 | - $code[] = " // Exported menu link: {$identifier}"; |
|
252 | - $code[] = " \$menu_links['{$identifier}'] = ". features_var_export($link, ' ') .";"; |
|
253 | - $translatables[] = $link['link_title']; |
|
251 | + $code[] = " // Exported menu link: {$identifier}"; |
|
252 | + $code[] = " \$menu_links['{$identifier}'] = ". features_var_export($link, ' ') .";"; |
|
253 | + $translatables[] = $link['link_title']; |
|
254 | 254 | } |
255 | - } |
|
256 | - if (!empty($translatables)) { |
|
255 | + } |
|
256 | + if (!empty($translatables)) { |
|
257 | 257 | $code[] = features_translatables_export($translatables, ' '); |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - $code[] = ''; |
|
261 | - $code[] = ' return $menu_links;'; |
|
262 | - $code = implode("\n", $code); |
|
263 | - return array('menu_default_menu_links' => $code); |
|
260 | + $code[] = ''; |
|
261 | + $code[] = ' return $menu_links;'; |
|
262 | + $code = implode("\n", $code); |
|
263 | + return array('menu_default_menu_links' => $code); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | 267 | * Implementation of hook_features_revert(). |
268 | 268 | */ |
269 | 269 | function menu_links_features_revert($module) { |
270 | - menu_links_features_rebuild($module); |
|
270 | + menu_links_features_rebuild($module); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | 274 | * Implementation of hook_features_rebuild(). |
275 | 275 | */ |
276 | 276 | function menu_links_features_rebuild($module) { |
277 | - if ($menu_links = features_get_default('menu_links', $module)) { |
|
277 | + if ($menu_links = features_get_default('menu_links', $module)) { |
|
278 | 278 | menu_links_features_rebuild_ordered($menu_links); |
279 | - } |
|
279 | + } |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
283 | 283 | * Generate a depth tree of all menu links. |
284 | 284 | */ |
285 | 285 | function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) { |
286 | - static $ordered; |
|
287 | - static $all_links; |
|
288 | - if (!isset($ordered) || $reset) { |
|
286 | + static $ordered; |
|
287 | + static $all_links; |
|
288 | + if (!isset($ordered) || $reset) { |
|
289 | 289 | $ordered = array(); |
290 | 290 | $unordered = features_get_default('menu_links'); |
291 | 291 | |
292 | 292 | // Order all links by depth. |
293 | 293 | if ($unordered) { |
294 | - do { |
|
294 | + do { |
|
295 | 295 | $current = count($unordered); |
296 | 296 | foreach ($unordered as $key => $link) { |
297 | - $identifier = menu_links_features_identifier($link); |
|
298 | - $parent = isset($link['parent_path']) ? "{$link['menu_name']}:{$link['parent_path']}" : ''; |
|
299 | - if (empty($parent) || (!empty($parent) && !isset($unordered[$parent]) && !isset($ordered[$parent]))) { |
|
297 | + $identifier = menu_links_features_identifier($link); |
|
298 | + $parent = isset($link['parent_path']) ? "{$link['menu_name']}:{$link['parent_path']}" : ''; |
|
299 | + if (empty($parent) || (!empty($parent) && !isset($unordered[$parent]) && !isset($ordered[$parent]))) { |
|
300 | 300 | $ordered[$identifier] = 0; |
301 | 301 | $all_links[$identifier] = $link; |
302 | 302 | unset($unordered[$key]); |
303 | - } |
|
304 | - elseif (isset($ordered[$parent])) { |
|
303 | + } |
|
304 | + elseif (isset($ordered[$parent])) { |
|
305 | 305 | $ordered[$identifier] = $ordered[$parent] + 1; |
306 | 306 | $all_links[$identifier] = $link; |
307 | 307 | unset($unordered[$key]); |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | - } while (count($unordered) < $current); |
|
310 | + } while (count($unordered) < $current); |
|
311 | 311 | } |
312 | 312 | asort($ordered); |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - // Ensure any default menu items that do not exist are created. |
|
316 | - foreach (array_keys($ordered) as $identifier) { |
|
315 | + // Ensure any default menu items that do not exist are created. |
|
316 | + foreach (array_keys($ordered) as $identifier) { |
|
317 | 317 | $link = $all_links[$identifier]; |
318 | 318 | $existing = features_menu_link_load($identifier); |
319 | 319 | if (!$existing || in_array($link, $menu_links)) { |
320 | - // Retrieve the mlid if this is an existing item. |
|
321 | - if ($existing) { |
|
320 | + // Retrieve the mlid if this is an existing item. |
|
321 | + if ($existing) { |
|
322 | 322 | $link['mlid'] = $existing['mlid']; |
323 | - } |
|
324 | - // Retrieve the plid for a parent link. |
|
325 | - if (!empty($link['parent_path']) && $parent = features_menu_link_load("{$link['menu_name']}:{$link['parent_path']}")) { |
|
323 | + } |
|
324 | + // Retrieve the plid for a parent link. |
|
325 | + if (!empty($link['parent_path']) && $parent = features_menu_link_load("{$link['menu_name']}:{$link['parent_path']}")) { |
|
326 | 326 | $link['plid'] = $parent['mlid']; |
327 | - } |
|
328 | - else { |
|
327 | + } |
|
328 | + else { |
|
329 | 329 | $link['plid'] = 0; |
330 | - } |
|
331 | - menu_link_save($link); |
|
330 | + } |
|
331 | + menu_link_save($link); |
|
332 | + } |
|
332 | 333 | } |
333 | - } |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
337 | 337 | * Load a menu link by its menu_name:link_path identifier. |
338 | 338 | */ |
339 | 339 | function features_menu_link_load($identifier) { |
340 | - list($menu_name, $link_path) = explode(':', $identifier, 2); |
|
341 | - $result = db_query("SELECT menu_name, mlid, plid, link_path, router_path, link_title, options, module, hidden, external, has_children, expanded, weight FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $link_path); |
|
342 | - while ($link = db_fetch_array($result)) { |
|
340 | + list($menu_name, $link_path) = explode(':', $identifier, 2); |
|
341 | + $result = db_query("SELECT menu_name, mlid, plid, link_path, router_path, link_title, options, module, hidden, external, has_children, expanded, weight FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $link_path); |
|
342 | + while ($link = db_fetch_array($result)) { |
|
343 | 343 | $link['options'] = unserialize($link['options']); |
344 | 344 | return $link; |
345 | - } |
|
346 | - return FALSE; |
|
345 | + } |
|
346 | + return FALSE; |
|
347 | 347 | } |
@@ -4,88 +4,88 @@ |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function imagecache_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'imagecache' => array( |
9 | - 'name' => t('Imagecache presets'), |
|
10 | - 'default_hook' => 'imagecache_default_presets', |
|
9 | + 'name' => t('Imagecache presets'), |
|
10 | + 'default_hook' => 'imagecache_default_presets', |
|
11 | 11 | ) |
12 | - ); |
|
12 | + ); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Implementation of hook_features_export_options(). |
17 | 17 | */ |
18 | 18 | function imagecache_features_export_options() { |
19 | - $options = array(); |
|
20 | - foreach (imagecache_presets() as $preset) { |
|
19 | + $options = array(); |
|
20 | + foreach (imagecache_presets() as $preset) { |
|
21 | 21 | $options[$preset['presetname']] = $preset['presetname']; |
22 | - } |
|
23 | - return $options; |
|
22 | + } |
|
23 | + return $options; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Implementation of hook_features_export(). |
28 | 28 | */ |
29 | 29 | function imagecache_features_export($data, &$export, $module_name = '') { |
30 | - // Collect a module to preset map |
|
31 | - $map = features_get_default_map('imagecache', 'presetname'); |
|
32 | - foreach ($data as $preset) { |
|
30 | + // Collect a module to preset map |
|
31 | + $map = features_get_default_map('imagecache', 'presetname'); |
|
32 | + foreach ($data as $preset) { |
|
33 | 33 | // If another module provides this preset, add it as a dependency |
34 | 34 | if (isset($map[$preset]) && $map[$preset] != $module_name) { |
35 | - $module = $map[$preset]; |
|
36 | - $export['dependencies'][$module] = $module; |
|
35 | + $module = $map[$preset]; |
|
36 | + $export['dependencies'][$module] = $module; |
|
37 | 37 | } |
38 | 38 | // Otherwise, export the preset |
39 | 39 | else { |
40 | - $export['features']['imagecache'][$preset] = $preset; |
|
40 | + $export['features']['imagecache'][$preset] = $preset; |
|
41 | + } |
|
41 | 42 | } |
42 | - } |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Implementation of hook_features_export_render(). |
47 | 47 | */ |
48 | 48 | function imagecache_features_export_render($module_name, $data) { |
49 | - $items = array(); |
|
50 | - foreach ($data as $key) { |
|
49 | + $items = array(); |
|
50 | + foreach ($data as $key) { |
|
51 | 51 | // This second argument to clear the static cache relies on patch in |
52 | 52 | // http://drupal.org/node/665284. |
53 | 53 | $preset = imagecache_preset_by_name($key, TRUE); |
54 | 54 | _imagecache_features_preset_sanitize($preset); |
55 | 55 | $items[$key] = $preset; |
56 | - } |
|
57 | - $code = " \$items = ". features_var_export($items, ' ') .";\n"; |
|
58 | - $code .= ' return $items;'; |
|
59 | - return array('imagecache_default_presets' => $code); |
|
56 | + } |
|
57 | + $code = " \$items = ". features_var_export($items, ' ') .";\n"; |
|
58 | + $code .= ' return $items;'; |
|
59 | + return array('imagecache_default_presets' => $code); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Implementation of hook_features_revert(). |
64 | 64 | */ |
65 | 65 | function imagecache_features_revert($module) { |
66 | - if ($default_presets = features_get_default('imagecache', $module)) { |
|
66 | + if ($default_presets = features_get_default('imagecache', $module)) { |
|
67 | 67 | foreach (array_keys($default_presets) as $default_preset) { |
68 | - $preset = imagecache_preset_by_name($default_preset); |
|
69 | - if ($preset) { |
|
68 | + $preset = imagecache_preset_by_name($default_preset); |
|
69 | + if ($preset) { |
|
70 | 70 | imagecache_preset_delete($preset); |
71 | - } |
|
71 | + } |
|
72 | + } |
|
72 | 73 | } |
73 | - } |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Remove unnecessary keys for export. |
78 | 78 | */ |
79 | 79 | function _imagecache_features_preset_sanitize(&$preset) { |
80 | - $omit = array('presetid', 'storage', 'actionid'); |
|
81 | - if (is_array($preset)) { |
|
80 | + $omit = array('presetid', 'storage', 'actionid'); |
|
81 | + if (is_array($preset)) { |
|
82 | 82 | foreach ($preset as $k => $v) { |
83 | - if (in_array($k, $omit, TRUE)) { |
|
83 | + if (in_array($k, $omit, TRUE)) { |
|
84 | 84 | unset($preset[$k]); |
85 | - } |
|
86 | - else if (is_array($v)) { |
|
85 | + } |
|
86 | + else if (is_array($v)) { |
|
87 | 87 | _imagecache_features_preset_sanitize($preset[$k]); |
88 | - } |
|
88 | + } |
|
89 | + } |
|
89 | 90 | } |
90 | - } |
|
91 | 91 | } |
@@ -4,21 +4,21 @@ discard block |
||
4 | 4 | * Implementation of hook_features_export(). |
5 | 5 | */ |
6 | 6 | function views_api_features_export($data, &$export, $module_name = '') { |
7 | - // Add views dependency |
|
8 | - $export['dependencies']['views'] = 'views'; |
|
7 | + // Add views dependency |
|
8 | + $export['dependencies']['views'] = 'views'; |
|
9 | 9 | |
10 | - // Add the actual views API hook entries to be accounted for in |
|
11 | - // hook_views_api(). The components are actually identified by a delimited |
|
12 | - // list of values: `key:value`. Currently only the 'api' key is supported |
|
13 | - // as Features does not yet know how to write to subdirectories. |
|
14 | - foreach ($data as $component) { |
|
10 | + // Add the actual views API hook entries to be accounted for in |
|
11 | + // hook_views_api(). The components are actually identified by a delimited |
|
12 | + // list of values: `key:value`. Currently only the 'api' key is supported |
|
13 | + // as Features does not yet know how to write to subdirectories. |
|
14 | + foreach ($data as $component) { |
|
15 | 15 | if (is_numeric($component)) { |
16 | - $version = "api:{$component}"; |
|
17 | - $export['features']['views_api'][$version] = $version; |
|
16 | + $version = "api:{$component}"; |
|
17 | + $export['features']['views_api'][$version] = $version; |
|
18 | + } |
|
18 | 19 | } |
19 | - } |
|
20 | 20 | |
21 | - return array(); |
|
21 | + return array(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -26,241 +26,241 @@ discard block |
||
26 | 26 | * Adds the views mothership hook, views_api(). |
27 | 27 | */ |
28 | 28 | function views_api_features_export_render($module, $data) { |
29 | - $values = array(); |
|
30 | - foreach ($data as $component) { |
|
29 | + $values = array(); |
|
30 | + foreach ($data as $component) { |
|
31 | 31 | $split = explode(':', $component); |
32 | 32 | if (count($split) === 2) { |
33 | - list($key, $value) = $split; |
|
34 | - $values[$key] = $value; |
|
33 | + list($key, $value) = $split; |
|
34 | + $values[$key] = $value; |
|
35 | 35 | } |
36 | - } |
|
37 | - $code = ' return ' . features_var_export($values, ' ') . ';'; |
|
38 | - return array('views_api' => $code); |
|
36 | + } |
|
37 | + $code = ' return ' . features_var_export($values, ' ') . ';'; |
|
38 | + return array('views_api' => $code); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implementation of hook_features_api(). |
43 | 43 | */ |
44 | 44 | function views_features_api() { |
45 | - return array( |
|
45 | + return array( |
|
46 | 46 | 'views' => array( |
47 | - 'name' => t('Views'), |
|
48 | - 'feature_source' => TRUE, |
|
49 | - 'default_hook' => 'views_default_views', |
|
50 | - 'default_file' => FEATURES_DEFAULTS_CUSTOM, |
|
51 | - 'default_filename' => 'views_default', |
|
47 | + 'name' => t('Views'), |
|
48 | + 'feature_source' => TRUE, |
|
49 | + 'default_hook' => 'views_default_views', |
|
50 | + 'default_file' => FEATURES_DEFAULTS_CUSTOM, |
|
51 | + 'default_filename' => 'views_default', |
|
52 | 52 | ), |
53 | 53 | 'views_api' => array( |
54 | - 'name' => t('Views API'), |
|
55 | - 'feature_source' => FALSE, |
|
56 | - 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
57 | - // Views API integration does not include a default hook declaration as |
|
58 | - // it is not a proper default hook. |
|
59 | - // 'default_hook' => 'views_api', |
|
54 | + 'name' => t('Views API'), |
|
55 | + 'feature_source' => FALSE, |
|
56 | + 'duplicates' => FEATURES_DUPLICATES_ALLOWED, |
|
57 | + // Views API integration does not include a default hook declaration as |
|
58 | + // it is not a proper default hook. |
|
59 | + // 'default_hook' => 'views_api', |
|
60 | 60 | ) |
61 | - ); |
|
61 | + ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Implementation of hook_features_export_options(). |
66 | 66 | */ |
67 | 67 | function views_features_export_options() { |
68 | - $enabled_views = array(); |
|
69 | - $views = views_get_all_views(); |
|
70 | - foreach ($views as $view) { |
|
68 | + $enabled_views = array(); |
|
69 | + $views = views_get_all_views(); |
|
70 | + foreach ($views as $view) { |
|
71 | 71 | if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) { |
72 | - $enabled_views[$view->name] = $view->name; |
|
72 | + $enabled_views[$view->name] = $view->name; |
|
73 | + } |
|
73 | 74 | } |
74 | - } |
|
75 | - ksort($enabled_views); |
|
76 | - return $enabled_views; |
|
75 | + ksort($enabled_views); |
|
76 | + return $enabled_views; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Implementation of hook_features_export_render(). |
81 | 81 | */ |
82 | 82 | function views_features_export_render($module, $data) { |
83 | - $code = array(); |
|
84 | - $code[] = ' $views = array();'; |
|
85 | - $code[] = ''; |
|
83 | + $code = array(); |
|
84 | + $code[] = ' $views = array();'; |
|
85 | + $code[] = ''; |
|
86 | 86 | |
87 | - // Build views & add to export array |
|
88 | - foreach ($data as $view_name) { |
|
87 | + // Build views & add to export array |
|
88 | + foreach ($data as $view_name) { |
|
89 | 89 | // Build the view |
90 | 90 | $view = views_get_view($view_name, TRUE); |
91 | 91 | if ($view) { |
92 | - $code[] = ' // Exported view: '. $view_name; |
|
93 | - $code[] = $view->export(' '); |
|
94 | - $code[] = ' $views[$view->name] = $view;'; |
|
95 | - $code[] = ''; |
|
92 | + $code[] = ' // Exported view: '. $view_name; |
|
93 | + $code[] = $view->export(' '); |
|
94 | + $code[] = ' $views[$view->name] = $view;'; |
|
95 | + $code[] = ''; |
|
96 | 96 | } |
97 | - } |
|
98 | - $code[] = ' return $views;'; |
|
99 | - $code = implode("\n", $code); |
|
100 | - return array('views_default_views' => $code); |
|
97 | + } |
|
98 | + $code[] = ' return $views;'; |
|
99 | + $code = implode("\n", $code); |
|
100 | + return array('views_default_views' => $code); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Implementation of hook_features_export(). |
105 | 105 | */ |
106 | 106 | function views_features_export($data, &$export, $module_name = '') { |
107 | - // Build views & add to export array |
|
108 | - $map = features_get_default_map('views', 'name'); |
|
109 | - $views = array(); |
|
110 | - $conflicts = array(); |
|
111 | - foreach ($data as $view_name) { |
|
107 | + // Build views & add to export array |
|
108 | + $map = features_get_default_map('views', 'name'); |
|
109 | + $views = array(); |
|
110 | + $conflicts = array(); |
|
111 | + foreach ($data as $view_name) { |
|
112 | 112 | if ($view = views_get_view($view_name, TRUE)) { |
113 | - // This view is provided by another module. Add it as a dependency or |
|
114 | - // display a conflict message if the View is overridden. |
|
115 | - if (isset($map[$view_name]) && $map[$view_name] !== $module_name) { |
|
113 | + // This view is provided by another module. Add it as a dependency or |
|
114 | + // display a conflict message if the View is overridden. |
|
115 | + if (isset($map[$view_name]) && $map[$view_name] !== $module_name) { |
|
116 | 116 | if ($v = views_get_view($view_name)) { |
117 | - if ($v->type === 'Overridden') { |
|
117 | + if ($v->type === 'Overridden') { |
|
118 | 118 | $conflicts[$map[$view_name]] = $view_name; |
119 | - } |
|
120 | - elseif ($v->type === 'Default') { |
|
119 | + } |
|
120 | + elseif ($v->type === 'Default') { |
|
121 | 121 | $export['dependencies'][$map[$view_name]] = $map[$view_name]; |
122 | - } |
|
122 | + } |
|
123 | 123 | } |
124 | - } |
|
125 | - // Otherwise just add to exports |
|
126 | - else { |
|
124 | + } |
|
125 | + // Otherwise just add to exports |
|
126 | + else { |
|
127 | 127 | $export['features']['views'][$view_name] = $view_name; |
128 | 128 | $views[$view_name] = $view; |
129 | - } |
|
129 | + } |
|
130 | + } |
|
130 | 131 | } |
131 | - } |
|
132 | - if (!empty($conflicts)) { |
|
132 | + if (!empty($conflicts)) { |
|
133 | 133 | $message = 'The following overridden view(s) are provided by other modules: !views. To resolve this problem either revert each view or clone each view so that modified versions can be exported with your feature.'; |
134 | 134 | $tokens = array('!views' => implode(', ', $conflicts)); |
135 | 135 | features_log(t($message, $tokens), 'warning'); |
136 | - } |
|
136 | + } |
|
137 | 137 | |
138 | - // Only add Views API hook if there are actually views to export. |
|
139 | - if (!empty($export['features']['views'])) { |
|
138 | + // Only add Views API hook if there are actually views to export. |
|
139 | + if (!empty($export['features']['views'])) { |
|
140 | 140 | $export['features']['views_api']['api:'. views_api_version()] = 'api:'. views_api_version(); |
141 | 141 | $export['dependencies']['views'] = 'views'; |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - // Discover module dependencies |
|
145 | - // We need to find dependencies based on: |
|
146 | - // 1. handlers |
|
147 | - // 2. plugins (style plugins, display plugins) |
|
148 | - // 3. other... (e.g. imagecache display option for CCK imagefields) : ( |
|
144 | + // Discover module dependencies |
|
145 | + // We need to find dependencies based on: |
|
146 | + // 1. handlers |
|
147 | + // 2. plugins (style plugins, display plugins) |
|
148 | + // 3. other... (e.g. imagecache display option for CCK imagefields) : ( |
|
149 | 149 | |
150 | - // Handlers |
|
151 | - $handlers = array('fields', 'filters', 'arguments', 'sort', 'relationships'); |
|
152 | - $handler_dependencies = views_handler_dependencies(); |
|
150 | + // Handlers |
|
151 | + $handlers = array('fields', 'filters', 'arguments', 'sort', 'relationships'); |
|
152 | + $handler_dependencies = views_handler_dependencies(); |
|
153 | 153 | |
154 | - // Plugins |
|
155 | - // For now we only support dependency detection for a subset of all views plugins |
|
156 | - $plugins = array('display', 'style', 'row', 'access'); |
|
157 | - $plugin_dependencies = views_plugin_dependencies(); |
|
154 | + // Plugins |
|
155 | + // For now we only support dependency detection for a subset of all views plugins |
|
156 | + $plugins = array('display', 'style', 'row', 'access'); |
|
157 | + $plugin_dependencies = views_plugin_dependencies(); |
|
158 | 158 | |
159 | - foreach ($views as $view) { |
|
159 | + foreach ($views as $view) { |
|
160 | 160 | foreach ($view->display as $display) { |
161 | - // Handlers |
|
162 | - foreach ($handlers as $handler) { |
|
161 | + // Handlers |
|
162 | + foreach ($handlers as $handler) { |
|
163 | 163 | if (isset($display->display_options[$handler])) { |
164 | - foreach ($display->display_options[$handler] as $item) { |
|
164 | + foreach ($display->display_options[$handler] as $item) { |
|
165 | 165 | if ($item['table'] && isset($handler_dependencies[$item['table']])) { |
166 | - $module = $handler_dependencies[$item['table']]; |
|
167 | - $export['dependencies'][$module] = $module; |
|
166 | + $module = $handler_dependencies[$item['table']]; |
|
167 | + $export['dependencies'][$module] = $module; |
|
168 | + } |
|
168 | 169 | } |
169 | - } |
|
170 | 170 | } |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | - // Plugins |
|
174 | - foreach ($plugins as $plugin_type) { |
|
173 | + // Plugins |
|
174 | + foreach ($plugins as $plugin_type) { |
|
175 | 175 | $plugin_name = ''; |
176 | 176 | switch ($plugin_type) { |
177 | - case 'display': |
|
177 | + case 'display': |
|
178 | 178 | if (isset($display->display_plugin)) { |
179 | - $plugin_name = $display->display_plugin; |
|
179 | + $plugin_name = $display->display_plugin; |
|
180 | 180 | } |
181 | 181 | break; |
182 | - case 'access': |
|
182 | + case 'access': |
|
183 | 183 | if (isset($display->display_options['access'], $display->display_options['access']['type']) && $display->display_options['access']['type'] != 'none') { |
184 | - $plugin_name = $display->display_options['access']['type']; |
|
184 | + $plugin_name = $display->display_options['access']['type']; |
|
185 | 185 | } |
186 | 186 | break; |
187 | - default: |
|
187 | + default: |
|
188 | 188 | if (isset($display->display_options["{$plugin_type}_plugin"])) { |
189 | - $plugin_name = $display->display_options["{$plugin_type}_plugin"]; |
|
189 | + $plugin_name = $display->display_options["{$plugin_type}_plugin"]; |
|
190 | 190 | } |
191 | 191 | break; |
192 | 192 | } |
193 | 193 | if (!empty($plugin_name) && isset($plugin_dependencies[$plugin_type][$plugin_name])) { |
194 | - $module = $plugin_dependencies[$plugin_type][$plugin_name]; |
|
195 | - $export['dependencies'][$module] = $module; |
|
194 | + $module = $plugin_dependencies[$plugin_type][$plugin_name]; |
|
195 | + $export['dependencies'][$module] = $module; |
|
196 | + } |
|
196 | 197 | } |
197 | - } |
|
198 | 198 | } |
199 | - } |
|
199 | + } |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Provides an array that maps hook_views_data() tables to modules. |
204 | 204 | */ |
205 | 205 | function views_handler_dependencies() { |
206 | - views_include_handlers(); |
|
206 | + views_include_handlers(); |
|
207 | 207 | |
208 | - static $map; |
|
209 | - if (!isset($map)) { |
|
208 | + static $map; |
|
209 | + if (!isset($map)) { |
|
210 | 210 | $map = array(); |
211 | 211 | foreach (module_implements('views_data') as $module) { |
212 | - if ($tables = module_invoke($module, 'views_data')) { |
|
212 | + if ($tables = module_invoke($module, 'views_data')) { |
|
213 | 213 | foreach ($tables as $table => $info) { |
214 | - if (isset($info['table']) && (!isset($map[$table]) || $info['table']['group'])) { |
|
214 | + if (isset($info['table']) && (!isset($map[$table]) || $info['table']['group'])) { |
|
215 | 215 | $map[$table] = $module; |
216 | - } |
|
217 | - else if (!isset($map[$table])) { |
|
216 | + } |
|
217 | + else if (!isset($map[$table])) { |
|
218 | 218 | $map[$table] = $module; |
219 | - } |
|
219 | + } |
|
220 | + } |
|
220 | 221 | } |
221 | - } |
|
222 | 222 | } |
223 | - } |
|
224 | - return $map; |
|
223 | + } |
|
224 | + return $map; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
228 | 228 | * Provides an array that maps hook_views_plugins() to modules. |
229 | 229 | */ |
230 | 230 | function views_plugin_dependencies() { |
231 | - views_include_handlers(); |
|
231 | + views_include_handlers(); |
|
232 | 232 | |
233 | - static $map; |
|
234 | - if (!isset($map)) { |
|
233 | + static $map; |
|
234 | + if (!isset($map)) { |
|
235 | 235 | $map = array(); |
236 | 236 | foreach (module_implements('views_plugins') as $module) { |
237 | - $plugins = module_invoke($module, 'views_plugins'); |
|
238 | - if (!empty($plugins)) { |
|
237 | + $plugins = module_invoke($module, 'views_plugins'); |
|
238 | + if (!empty($plugins)) { |
|
239 | 239 | foreach ($plugins as $type => $items) { |
240 | - if (is_array($items)) { |
|
240 | + if (is_array($items)) { |
|
241 | 241 | foreach (array_keys($items) as $plugin_name) { |
242 | - $map[$type][$plugin_name] = $module; |
|
242 | + $map[$type][$plugin_name] = $module; |
|
243 | + } |
|
243 | 244 | } |
244 | - } |
|
245 | 245 | } |
246 | - } |
|
246 | + } |
|
247 | 247 | } |
248 | - } |
|
249 | - return $map; |
|
248 | + } |
|
249 | + return $map; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * Implementation of hook_features_revert(). |
254 | 254 | */ |
255 | 255 | function views_features_revert($module) { |
256 | - if ($default_views = features_get_default('views', $module)) { |
|
256 | + if ($default_views = features_get_default('views', $module)) { |
|
257 | 257 | foreach ($default_views as $default_view) { |
258 | - if ($current_view = views_get_view($default_view->name)) { |
|
258 | + if ($current_view = views_get_view($default_view->name)) { |
|
259 | 259 | $current_view->delete(FALSE); |
260 | - } |
|
260 | + } |
|
261 | 261 | } |
262 | 262 | // Flush caches. |
263 | 263 | cache_clear_all(); |
264 | 264 | menu_rebuild(); |
265 | - } |
|
265 | + } |
|
266 | 266 | } |
@@ -4,76 +4,76 @@ discard block |
||
4 | 4 | * Implementation of hook_features_api(). |
5 | 5 | */ |
6 | 6 | function node_features_api() { |
7 | - return array( |
|
7 | + return array( |
|
8 | 8 | 'node' => array( |
9 | - 'name' => t('Content types'), |
|
10 | - 'feature_source' => TRUE, |
|
11 | - 'default_hook' => 'node_info', |
|
9 | + 'name' => t('Content types'), |
|
10 | + 'feature_source' => TRUE, |
|
11 | + 'default_hook' => 'node_info', |
|
12 | 12 | ), |
13 | - ); |
|
13 | + ); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Implementation of hook_features_export_options(). |
18 | 18 | */ |
19 | 19 | function node_features_export_options() { |
20 | - return node_get_types('names'); |
|
20 | + return node_get_types('names'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Implementation of hook_features_export. |
25 | 25 | */ |
26 | 26 | function node_features_export($data, &$export, $module_name = '') { |
27 | - $pipe = array(); |
|
28 | - $map = features_get_default_map('node'); |
|
27 | + $pipe = array(); |
|
28 | + $map = features_get_default_map('node'); |
|
29 | 29 | |
30 | - foreach ($data as $type) { |
|
30 | + foreach ($data as $type) { |
|
31 | 31 | // Poll node module to determine who provides the node type. |
32 | 32 | if ($info = node_get_types('module', $type)) { |
33 | - if ($module_name != $info && module_exists($info)) { |
|
33 | + if ($module_name != $info && module_exists($info)) { |
|
34 | 34 | $export['dependencies'][$info] = $info; |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - // If this node type is provided by a different module, add it as a dependency |
|
38 | - if (isset($map[$type]) && $map[$type] != $module_name) { |
|
37 | + // If this node type is provided by a different module, add it as a dependency |
|
38 | + if (isset($map[$type]) && $map[$type] != $module_name) { |
|
39 | 39 | $export['dependencies'][$map[$type]] = $map[$type]; |
40 | - } |
|
41 | - // Otherwise export the node type. |
|
42 | - elseif (in_array($info, array('node', 'features')) || isset($map[$type])) { |
|
40 | + } |
|
41 | + // Otherwise export the node type. |
|
42 | + elseif (in_array($info, array('node', 'features')) || isset($map[$type])) { |
|
43 | 43 | $export['features']['node'][$type] = $type; |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - // Create a pipe for CCK fields |
|
47 | - if (module_exists('content')) { |
|
46 | + // Create a pipe for CCK fields |
|
47 | + if (module_exists('content')) { |
|
48 | 48 | $content_info = content_types($type); |
49 | 49 | if (!empty($content_info['fields'])) { |
50 | - foreach ($content_info['fields'] as $key => $field) { |
|
50 | + foreach ($content_info['fields'] as $key => $field) { |
|
51 | 51 | $pipe['content'][] = "{$type}-{$field['field_name']}"; |
52 | - } |
|
53 | - // If strongarm is present, create a pipe for the extra field weights |
|
54 | - // variable to be exported. |
|
55 | - if (module_exists('strongarm')) { |
|
52 | + } |
|
53 | + // If strongarm is present, create a pipe for the extra field weights |
|
54 | + // variable to be exported. |
|
55 | + if (module_exists('strongarm')) { |
|
56 | 56 | $pipe['variable'][] = "content_extra_weights_{$type}"; |
57 | - } |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | // Create a pipe for Fieldgroups |
60 | 60 | if (function_exists('fieldgroup_groups') && $groups = fieldgroup_groups($type)) { |
61 | - foreach ($groups as $group) { |
|
61 | + foreach ($groups as $group) { |
|
62 | 62 | $pipe['fieldgroup'][] = "{$type}-{$group['group_name']}"; |
63 | - } |
|
63 | + } |
|
64 | 64 | } |
65 | - } |
|
65 | + } |
|
66 | + } |
|
66 | 67 | } |
67 | - } |
|
68 | 68 | |
69 | - return $pipe; |
|
69 | + return $pipe; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Implementation of hook_features_export_render(). |
74 | 74 | */ |
75 | 75 | function node_features_export_render($module, $data, $export = NULL) { |
76 | - $elements = array( |
|
76 | + $elements = array( |
|
77 | 77 | 'name' => TRUE, |
78 | 78 | 'module' => FALSE, |
79 | 79 | 'description' => TRUE, |
@@ -83,47 +83,47 @@ discard block |
||
83 | 83 | 'body_label' => TRUE, |
84 | 84 | 'min_word_count' => FALSE, |
85 | 85 | 'help' => TRUE, |
86 | - ); |
|
87 | - $output = array(); |
|
88 | - $output[] = ' $items = array('; |
|
89 | - foreach ($data as $type) { |
|
86 | + ); |
|
87 | + $output = array(); |
|
88 | + $output[] = ' $items = array('; |
|
89 | + foreach ($data as $type) { |
|
90 | 90 | if ($info = node_get_types('type', $type)) { |
91 | - // Force module name to be 'features' if set to 'node. If we leave as |
|
92 | - // 'node' the content type will be assumed to be database-stored by |
|
93 | - // the node module. |
|
94 | - $info->module = ($info->module === 'node') ? 'features' : $info->module; |
|
95 | - $output[] = " '{$type}' => array("; |
|
96 | - foreach ($elements as $key => $t) { |
|
91 | + // Force module name to be 'features' if set to 'node. If we leave as |
|
92 | + // 'node' the content type will be assumed to be database-stored by |
|
93 | + // the node module. |
|
94 | + $info->module = ($info->module === 'node') ? 'features' : $info->module; |
|
95 | + $output[] = " '{$type}' => array("; |
|
96 | + foreach ($elements as $key => $t) { |
|
97 | 97 | if ($t) { |
98 | - $text = str_replace("'", "\'", $info->$key); |
|
99 | - $text = !empty($text) ? "t('{$text}')" : "''"; |
|
100 | - $output[] = " '{$key}' => {$text},"; |
|
98 | + $text = str_replace("'", "\'", $info->$key); |
|
99 | + $text = !empty($text) ? "t('{$text}')" : "''"; |
|
100 | + $output[] = " '{$key}' => {$text},"; |
|
101 | 101 | } |
102 | 102 | else { |
103 | - $output[] = " '{$key}' => '{$info->$key}',"; |
|
103 | + $output[] = " '{$key}' => '{$info->$key}',"; |
|
104 | 104 | } |
105 | - } |
|
106 | - // Detect whether there are extra fields on this content type than have |
|
107 | - // been described in defaults. If so, add an additional key to the node |
|
108 | - // type info allowing it to be detected by Features as a component that can |
|
109 | - // be reverted (delete those extra fields) or updated (export those extra |
|
110 | - // fields to code). |
|
111 | - // Note that this key is only added if $export is not set - ie. we never |
|
112 | - // *actually* write this key to code. |
|
113 | - if (!isset($export) && module_exists('content') && module_exists($module)) { |
|
105 | + } |
|
106 | + // Detect whether there are extra fields on this content type than have |
|
107 | + // been described in defaults. If so, add an additional key to the node |
|
108 | + // type info allowing it to be detected by Features as a component that can |
|
109 | + // be reverted (delete those extra fields) or updated (export those extra |
|
110 | + // fields to code). |
|
111 | + // Note that this key is only added if $export is not set - ie. we never |
|
112 | + // *actually* write this key to code. |
|
113 | + if (!isset($export) && module_exists('content') && module_exists($module)) { |
|
114 | 114 | // If there are deleted fields, mark the content type as such |
115 | 115 | $deleted_fields = array_diff(content_features_fields_normal($type), content_features_fields_default($type)); |
116 | 116 | if (!empty($deleted_fields)) { |
117 | - $output[] = " 'content_has_extra_fields' => TRUE,"; |
|
117 | + $output[] = " 'content_has_extra_fields' => TRUE,"; |
|
118 | + } |
|
118 | 119 | } |
119 | - } |
|
120 | - $output[] = " ),"; |
|
120 | + $output[] = " ),"; |
|
121 | + } |
|
121 | 122 | } |
122 | - } |
|
123 | - $output[] = ' );'; |
|
124 | - $output[] = ' return $items;'; |
|
125 | - $output = implode("\n", $output); |
|
126 | - return array('node_info' => $output); |
|
123 | + $output[] = ' );'; |
|
124 | + $output[] = ' return $items;'; |
|
125 | + $output = implode("\n", $output); |
|
126 | + return array('node_info' => $output); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -133,29 +133,29 @@ discard block |
||
133 | 133 | * name of module to revert content for |
134 | 134 | */ |
135 | 135 | function node_features_revert($module = NULL) { |
136 | - if ($default_types = features_get_default('node', $module)) { |
|
136 | + if ($default_types = features_get_default('node', $module)) { |
|
137 | 137 | foreach ($default_types as $type_name => $type_info) { |
138 | - // We need to de-activate any missing fields. De-activating allows us to |
|
139 | - // preserve data. We de-activate by setting the widget_active flag to 0; |
|
140 | - // widget_active is incorrectly named, and really should be |
|
141 | - // instance_active |
|
142 | - if (module_exists('content')) { |
|
138 | + // We need to de-activate any missing fields. De-activating allows us to |
|
139 | + // preserve data. We de-activate by setting the widget_active flag to 0; |
|
140 | + // widget_active is incorrectly named, and really should be |
|
141 | + // instance_active |
|
142 | + if (module_exists('content')) { |
|
143 | 143 | // Our existing fields ($fields) needs to be the first argument here, |
144 | 144 | // so only fields that don't exist in code can be de-activated. |
145 | 145 | if ($deleted_fields = array_diff(content_features_fields_normal($type_name), content_features_fields_default($type_name))) { |
146 | - foreach($deleted_fields as $field_name) { |
|
146 | + foreach($deleted_fields as $field_name) { |
|
147 | 147 | db_query("UPDATE {". content_instance_tablename() ."} SET widget_active = 0 WHERE field_name = '%s' AND type_name = '%s'", $field_name, $type_name); |
148 | - } |
|
148 | + } |
|
149 | 149 | } |
150 | - } |
|
151 | - // Delete node types |
|
152 | - // We don't use node_type_delete() because we do not actually |
|
153 | - // want to delete the node type (and invoke hook_node_type()). |
|
154 | - // This can lead to bad consequences like CCK deleting field |
|
155 | - // storage in the DB. |
|
156 | - db_query("DELETE FROM {node_type} WHERE type = '%s'", $type_name); |
|
150 | + } |
|
151 | + // Delete node types |
|
152 | + // We don't use node_type_delete() because we do not actually |
|
153 | + // want to delete the node type (and invoke hook_node_type()). |
|
154 | + // This can lead to bad consequences like CCK deleting field |
|
155 | + // storage in the DB. |
|
156 | + db_query("DELETE FROM {node_type} WHERE type = '%s'", $type_name); |
|
157 | 157 | } |
158 | 158 | node_types_rebuild(); |
159 | 159 | menu_rebuild(); |
160 | - } |
|
160 | + } |
|
161 | 161 | } |