@@ -289,6 +289,7 @@ |
||
289 | 289 | /** |
290 | 290 | * Returns the fields of a given field type only. |
291 | 291 | * Suitable for using it with #options. |
292 | + * @param string $type |
|
292 | 293 | */ |
293 | 294 | function content_rules_get_field_names_by_type($type = NULL) { |
294 | 295 | $fields = array(); |
@@ -10,34 +10,34 @@ discard block |
||
10 | 10 | * Implementation of hook_rules_action_info(). |
11 | 11 | */ |
12 | 12 | function content_rules_action_info() { |
13 | - $info = array(); |
|
14 | - $info['content_rules_action_populate_field'] = array( |
|
13 | + $info = array(); |
|
14 | + $info['content_rules_action_populate_field'] = array( |
|
15 | 15 | 'label' => t('Populate a field'), |
16 | 16 | 'arguments' => array( |
17 | - 'node' => array( |
|
17 | + 'node' => array( |
|
18 | 18 | 'type' => 'node', |
19 | 19 | 'label' => t('Content'), |
20 | - ), |
|
20 | + ), |
|
21 | 21 | ), |
22 | 22 | 'eval input' => array('code'), |
23 | 23 | 'help' => t('You should make sure that the used field exists in the given content type.'), |
24 | 24 | 'module' => 'CCK', |
25 | - ); |
|
26 | - return $info; |
|
25 | + ); |
|
26 | + return $info; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Action: populate a field. |
31 | 31 | */ |
32 | 32 | function content_rules_action_populate_field($node, $settings, $element, &$state) { |
33 | - // Get information about the field. |
|
34 | - $field = content_fields($settings['field_name'], $node->type); |
|
35 | - $value = _content_rules_get_field_value($settings, $state); |
|
33 | + // Get information about the field. |
|
34 | + $field = content_fields($settings['field_name'], $node->type); |
|
35 | + $value = _content_rules_get_field_value($settings, $state); |
|
36 | 36 | |
37 | - if (!empty($field) && is_array($value)) { |
|
37 | + if (!empty($field) && is_array($value)) { |
|
38 | 38 | $node->$settings['field_name'] = $value; |
39 | 39 | return array('node' => $node); |
40 | - } |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * This is a multistep form! |
47 | 47 | */ |
48 | 48 | function content_rules_action_populate_field_form($settings, &$form, &$form_state) { |
49 | - $settings += array('field_name' => '', 'code' => '', 'value' => NULL); |
|
50 | - if (empty($settings['field_name'])) { |
|
49 | + $settings += array('field_name' => '', 'code' => '', 'value' => NULL); |
|
50 | + if (empty($settings['field_name'])) { |
|
51 | 51 | $form['settings']['field_name'] = array( |
52 | - '#type' => 'select', |
|
53 | - '#title' => t('Field'), |
|
54 | - '#options' => content_rules_get_field_names_by_type(), |
|
55 | - '#default_value' => $settings['field_name'], |
|
56 | - '#description' => t('Select the machine-name of the field.'), |
|
57 | - '#required' => TRUE, |
|
52 | + '#type' => 'select', |
|
53 | + '#title' => t('Field'), |
|
54 | + '#options' => content_rules_get_field_names_by_type(), |
|
55 | + '#default_value' => $settings['field_name'], |
|
56 | + '#description' => t('Select the machine-name of the field.'), |
|
57 | + '#required' => TRUE, |
|
58 | 58 | ); |
59 | 59 | // Hide some form elements in the first step. |
60 | 60 | $form['negate']['#access'] = FALSE; |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | // Replace the usual submit handlers with a own handler. |
65 | 65 | $form['submit']['#submit'] = array('content_rules_action_populate_field_form_step_submit'); |
66 | 66 | $form['submit']['#value'] = t('Continue'); |
67 | - } |
|
68 | - else { |
|
67 | + } |
|
68 | + else { |
|
69 | 69 | // Show the fields form here. |
70 | 70 | module_load_include('inc', 'content', 'includes/content.node_form'); |
71 | 71 | $field = content_fields($settings['field_name']); |
@@ -78,111 +78,111 @@ discard block |
||
78 | 78 | |
79 | 79 | unset($form['#cache']); |
80 | 80 | |
81 | - // Advanced: PHP code. |
|
81 | + // Advanced: PHP code. |
|
82 | 82 | $form['advanced_options'] = array( |
83 | - '#type' => 'fieldset', |
|
84 | - '#title' => t('Advanced: Specify the fields value with PHP code'), |
|
85 | - '#collapsible' => TRUE, |
|
86 | - '#collapsed' => empty($settings['code']), |
|
87 | - '#weight' => 5, |
|
83 | + '#type' => 'fieldset', |
|
84 | + '#title' => t('Advanced: Specify the fields value with PHP code'), |
|
85 | + '#collapsible' => TRUE, |
|
86 | + '#collapsed' => empty($settings['code']), |
|
87 | + '#weight' => 5, |
|
88 | 88 | ); |
89 | 89 | |
90 | 90 | $db_info = content_database_info($field); |
91 | 91 | $columns = array_keys($db_info['columns']); |
92 | 92 | foreach ($columns as $key => $column) { |
93 | - $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
93 | + $columns[$key] = t("'@column' => value for @column", array('@column' => $column)); |
|
94 | 94 | } |
95 | 95 | $sample = t("return array(\n 0 => array(@columns),\n // You'll usually want to stop here. Provide more values\n // if you want your 'default value' to be multi-valued:\n 1 => array(@columns),\n 2 => ...\n);", array('@columns' => implode(', ', $columns))); |
96 | 96 | |
97 | 97 | $form['advanced_options']['code'] = array( |
98 | - '#type' => 'textarea', |
|
99 | - '#title' => t('Code'), |
|
100 | - '#default_value' => $settings['code'], |
|
101 | - '#rows' => 6, |
|
102 | - '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array( |
|
98 | + '#type' => 'textarea', |
|
99 | + '#title' => t('Code'), |
|
100 | + '#default_value' => $settings['code'], |
|
101 | + '#rows' => 6, |
|
102 | + '#description' => t('Advanced usage only: PHP code that returns the value to set. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format: <pre>!sample</pre>Using <a href="@link_devel">devel.module\'s</a> \'devel load\' tab on a content page might help you figure out the expected format.', array( |
|
103 | 103 | '!sample' => $sample, |
104 | 104 | '@link_devel' => 'http://www.drupal.org/project/devel', |
105 | - )), |
|
105 | + )), |
|
106 | 106 | ); |
107 | 107 | |
108 | 108 | // Add this file to be included when the form is built by rules |
109 | 109 | // as it's needed by CCKs add more button. |
110 | 110 | // See rules_after_build_include_files(). |
111 | 111 | $form['#includes'][] = './'. drupal_get_path('module', 'node') .'/node.pages.inc'; |
112 | - } |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | function content_rules_action_populate_field_form_step_submit($form, &$form_state) { |
116 | - $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name']; |
|
116 | + $form_state['element']['#settings']['field_name'] = $form_state['values']['settings']['field_name']; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Validate the chosen value or php code. |
121 | 121 | */ |
122 | 122 | function content_rules_action_populate_field_validate($form, &$form_state) { |
123 | - if (!isset($form_state['element']['#settings']['field_name'])) { |
|
123 | + if (!isset($form_state['element']['#settings']['field_name'])) { |
|
124 | 124 | //Just validate the last step. |
125 | 125 | return; |
126 | - } |
|
126 | + } |
|
127 | 127 | |
128 | - if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) { |
|
128 | + if (isset($form_state['values']['code']) && ($php = $form_state['values']['code'])) { |
|
129 | 129 | if (strpos($php, 'return') === FALSE) { |
130 | - form_set_error('code', t('You have to return the default value in the expected format.')); |
|
130 | + form_set_error('code', t('You have to return the default value in the expected format.')); |
|
131 | 131 | } |
132 | - } |
|
133 | - else { |
|
132 | + } |
|
133 | + else { |
|
134 | 134 | // Validate the field. |
135 | 135 | $settings = $form_state['element']['#settings']; |
136 | 136 | $field = content_fields($settings['field_name']); |
137 | 137 | $field_types = _content_field_types(); |
138 | 138 | $function = $field_types[$field['type']]['module'] .'_field'; |
139 | 139 | if (function_exists($function)) { |
140 | - $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]); |
|
141 | - $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array(); |
|
140 | + $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]); |
|
141 | + $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array(); |
|
142 | 142 | |
143 | - //Make sure AHAH 'add more' button isn't sent to the fields |
|
144 | - // for processing. |
|
145 | - unset($items[$field['field_name'] .'_add_more']); |
|
143 | + //Make sure AHAH 'add more' button isn't sent to the fields |
|
144 | + // for processing. |
|
145 | + unset($items[$field['field_name'] .'_add_more']); |
|
146 | 146 | |
147 | - $function('validate', $form['#node'], $field, $items, $form, NULL); |
|
148 | - content_field('validate', $form['#node'], $field, $items, $form, NULL); |
|
147 | + $function('validate', $form['#node'], $field, $items, $form, NULL); |
|
148 | + content_field('validate', $form['#node'], $field, $items, $form, NULL); |
|
149 | + } |
|
149 | 150 | } |
150 | - } |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function content_rules_action_populate_field_submit(&$settings, $form, &$form_state) { |
154 | - // Take over field values and filter out private properties added by CCK |
|
155 | - $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array'); |
|
154 | + // Take over field values and filter out private properties added by CCK |
|
155 | + $settings['value'] = array_filter($form_state['values'][$settings['field_name']], 'is_array'); |
|
156 | 156 | |
157 | - foreach ($settings['value'] as $key => $data) { |
|
157 | + foreach ($settings['value'] as $key => $data) { |
|
158 | 158 | foreach (array_filter(array_keys($data)) as $col) { |
159 | - if ($col[0] == '_') { |
|
159 | + if ($col[0] == '_') { |
|
160 | 160 | unset($settings['value'][$key][$col]); |
161 | - } |
|
161 | + } |
|
162 | 162 | } |
163 | 163 | if ($key && count(array_filter($settings['value'][$key])) == 0) { |
164 | - // For multi-valued fields don't check for any additional empty values. |
|
165 | - unset($settings['value'][$key]); |
|
164 | + // For multi-valued fields don't check for any additional empty values. |
|
165 | + unset($settings['value'][$key]); |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | 168 | |
169 | - $settings['code'] = $form_state['values']['code']; |
|
169 | + $settings['code'] = $form_state['values']['code']; |
|
170 | 170 | |
171 | - if (function_exists('rules_action_custom_php_submit')) { |
|
171 | + if (function_exists('rules_action_custom_php_submit')) { |
|
172 | 172 | // Support adding variables to the php code, if php module is present. |
173 | 173 | rules_action_custom_php_submit($settings, $form, $form_state); |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - // Add all values to the input evaluator, so that textfields / textares can |
|
177 | - // make use of it. |
|
178 | - $names = array('code'); |
|
176 | + // Add all values to the input evaluator, so that textfields / textares can |
|
177 | + // make use of it. |
|
178 | + $names = array('code'); |
|
179 | 179 | |
180 | - foreach ($settings['value'] as $key => $data) { |
|
180 | + foreach ($settings['value'] as $key => $data) { |
|
181 | 181 | foreach (array_filter($data, 'is_string') as $col => $value) { |
182 | - $names[] = "value|$key|$col"; |
|
182 | + $names[] = "value|$key|$col"; |
|
183 | + } |
|
183 | 184 | } |
184 | - } |
|
185 | - $form_state['element']['#info']['eval input'] = $names; |
|
185 | + $form_state['element']['#info']['eval input'] = $names; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | * Label callback: Improve the label of the action. |
191 | 191 | */ |
192 | 192 | function content_rules_action_populate_field_label($settings, $argument_labels) { |
193 | - return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels); |
|
193 | + return t("Populate @node's field '@field'", array('@field' => $settings['field_name']) + $argument_labels); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | function workflow_ng_action_populate_field_upgrade(&$element) { |
197 | - $element['#name'] = 'content_rules_action_populate_field'; |
|
198 | - $element['#settings']['code'] = $element['#settings']['default_value_php']; |
|
199 | - $element['#settings'][$element['#settings']['field_name']] = array(); |
|
200 | - unset($element['#settings']['default_value_php']); |
|
197 | + $element['#name'] = 'content_rules_action_populate_field'; |
|
198 | + $element['#settings']['code'] = $element['#settings']['default_value_php']; |
|
199 | + $element['#settings'][$element['#settings']['field_name']] = array(); |
|
200 | + unset($element['#settings']['default_value_php']); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -205,84 +205,84 @@ discard block |
||
205 | 205 | * Implementation of hook_rules_condition_info(). |
206 | 206 | */ |
207 | 207 | function content_rules_condition_info() { |
208 | - $info = array(); |
|
209 | - $info['content_rules_field_has_value'] = array( |
|
208 | + $info = array(); |
|
209 | + $info['content_rules_field_has_value'] = array( |
|
210 | 210 | 'label' => t('Field has value'), |
211 | 211 | 'arguments' => array( |
212 | - 'node' => array('type' => 'node', 'label' => t('Content')), |
|
212 | + 'node' => array('type' => 'node', 'label' => t('Content')), |
|
213 | 213 | ), |
214 | 214 | 'eval input' => array('code'), |
215 | 215 | 'help' => t('You should make sure that the used field exists in the given content type. The condition returns TRUE, if the selected field has the given value.'), |
216 | 216 | 'module' => 'CCK', |
217 | - ); |
|
218 | - $info['content_rules_field_changed'] = array( |
|
217 | + ); |
|
218 | + $info['content_rules_field_changed'] = array( |
|
219 | 219 | 'label' => t('Field has changed'), |
220 | 220 | 'arguments' => array( |
221 | - 'node' => array('type' => 'node', 'label' => t('Content containing changes')), |
|
222 | - 'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')), |
|
221 | + 'node' => array('type' => 'node', 'label' => t('Content containing changes')), |
|
222 | + 'node_unchanged' => array('type' => 'node', 'label' => t('Content not containing changes')), |
|
223 | 223 | ), |
224 | 224 | 'help' => t('You should make sure that the used field exists in the given content type.'), |
225 | 225 | 'module' => 'CCK', |
226 | - ); |
|
227 | - return $info; |
|
226 | + ); |
|
227 | + return $info; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Condition: Check the value of a field. |
232 | 232 | */ |
233 | 233 | function content_rules_field_has_value($node, $settings) { |
234 | - // Get information about the field. |
|
235 | - $field = content_fields($settings['field_name'], $node->type); |
|
236 | - $value = _content_rules_get_field_value($settings, $state); |
|
234 | + // Get information about the field. |
|
235 | + $field = content_fields($settings['field_name'], $node->type); |
|
236 | + $value = _content_rules_get_field_value($settings, $state); |
|
237 | 237 | |
238 | - if (empty($field) || !is_array($value)) { |
|
238 | + if (empty($field) || !is_array($value)) { |
|
239 | 239 | return FALSE; |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | - return _content_rules_field_has_value($node->$settings['field_name'], $value); |
|
242 | + return _content_rules_field_has_value($node->$settings['field_name'], $value); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Use the same configuration form as the "populate field" action. |
247 | 247 | */ |
248 | 248 | function content_rules_field_has_value_form($settings, &$form, &$form_state) { |
249 | - content_rules_action_populate_field_form($settings, $form, $form_state); |
|
249 | + content_rules_action_populate_field_form($settings, $form, $form_state); |
|
250 | 250 | } |
251 | 251 | function content_rules_field_has_value_validate($form, &$form_state) { |
252 | - content_rules_action_populate_field_validate($form, $form_state); |
|
252 | + content_rules_action_populate_field_validate($form, $form_state); |
|
253 | 253 | } |
254 | 254 | function content_rules_field_has_value_submit(&$settings, $form, &$form_state) { |
255 | - content_rules_action_populate_field_submit($settings, $form, $form_state); |
|
255 | + content_rules_action_populate_field_submit($settings, $form, $form_state); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | function content_rules_field_has_value_label($settings, $argument_labels) { |
259 | - return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels); |
|
259 | + return t("@node's field '@field' has value", array('@field' => $settings['field_name']) + $argument_labels); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Condition: Check if the field has changed. |
264 | 264 | */ |
265 | 265 | function content_rules_field_changed($node1, $node2, $settings) { |
266 | - // Get information about the field. |
|
267 | - $field = content_fields($settings['field_name'], $node1->type); |
|
266 | + // Get information about the field. |
|
267 | + $field = content_fields($settings['field_name'], $node1->type); |
|
268 | 268 | |
269 | - return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']); |
|
269 | + return !empty($field) && !_content_rules_field_has_value($node1->$settings['field_name'], $node2->$settings['field_name']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | function content_rules_field_changed_form($settings, &$form, &$form_state) { |
273 | - $settings += array('field_name' => ''); |
|
274 | - $form['settings']['field_name'] = array( |
|
273 | + $settings += array('field_name' => ''); |
|
274 | + $form['settings']['field_name'] = array( |
|
275 | 275 | '#type' => 'select', |
276 | 276 | '#title' => t('Field'), |
277 | 277 | '#options' => content_rules_get_field_names_by_type(), |
278 | 278 | '#default_value' => $settings['field_name'], |
279 | 279 | '#description' => t('Select the machine-name of the field to look at.'), |
280 | 280 | '#required' => TRUE, |
281 | - ); |
|
281 | + ); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | function content_rules_field_changed_label($settings, $argument_labels) { |
285 | - return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels); |
|
285 | + return t("@node's field '@field' has been changed", array('@field' => $settings['field_name']) + $argument_labels); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -291,32 +291,32 @@ discard block |
||
291 | 291 | * Suitable for using it with #options. |
292 | 292 | */ |
293 | 293 | function content_rules_get_field_names_by_type($type = NULL) { |
294 | - $fields = array(); |
|
295 | - foreach (content_fields() as $field) { |
|
294 | + $fields = array(); |
|
295 | + foreach (content_fields() as $field) { |
|
296 | 296 | if (!isset($type) || $field['type'] == $type) { |
297 | - $fields[$field['field_name']] = $field['field_name']; |
|
297 | + $fields[$field['field_name']] = $field['field_name']; |
|
298 | + } |
|
298 | 299 | } |
299 | - } |
|
300 | - asort($fields); |
|
301 | - return $fields; |
|
300 | + asort($fields); |
|
301 | + return $fields; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | function _content_rules_get_field_value($settings, &$state) { |
305 | - if ($settings['code']) { |
|
305 | + if ($settings['code']) { |
|
306 | 306 | if (function_exists('rules_input_evaluator_php_apply')) { |
307 | - // Support adding variables to the php code, if php module is present. |
|
308 | - $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE); |
|
307 | + // Support adding variables to the php code, if php module is present. |
|
308 | + $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE); |
|
309 | 309 | } |
310 | 310 | else { |
311 | - ob_start(); |
|
312 | - $value = eval($settings['code']); |
|
313 | - ob_end_clean(); |
|
311 | + ob_start(); |
|
312 | + $value = eval($settings['code']); |
|
313 | + ob_end_clean(); |
|
314 | 314 | } |
315 | - } |
|
316 | - else { |
|
315 | + } |
|
316 | + else { |
|
317 | 317 | $value = $settings['value']; |
318 | - } |
|
319 | - return $value; |
|
318 | + } |
|
319 | + return $value; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | * @param $value The value to check for. |
330 | 330 | */ |
331 | 331 | function _content_rules_field_has_value($node_value, $value) { |
332 | - if (count($value) != count($node_value)) { |
|
332 | + if (count($value) != count($node_value)) { |
|
333 | 333 | return FALSE; |
334 | - } |
|
335 | - // Loop over multiple fields |
|
336 | - foreach ($value as $delta => $sub_value) { |
|
334 | + } |
|
335 | + // Loop over multiple fields |
|
336 | + foreach ($value as $delta => $sub_value) { |
|
337 | 337 | // Check if all properties of the value are there in the node value too |
338 | 338 | if (is_array($sub_value) && is_array($node_value[$delta])) { |
339 | - if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) { |
|
339 | + if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) { |
|
340 | 340 | return FALSE; |
341 | - } |
|
341 | + } |
|
342 | 342 | } |
343 | 343 | elseif ($sub_value !== $node_value[$delta]) { |
344 | - return FALSE; |
|
344 | + return FALSE; |
|
345 | + } |
|
345 | 346 | } |
346 | - } |
|
347 | - return TRUE; |
|
347 | + return TRUE; |
|
348 | 348 | } |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $form['#node'] = (object)array('type' => '', $settings['field_name'] => $settings['value']); |
74 | 74 | $form['#field_info'][$field['field_name']] = $field; |
75 | 75 | // We can't put it into $form['settings'] as this would break AHAH callbacks |
76 | - $form += (array) content_field_form($form, $form_state, $field); |
|
77 | - $form[ $settings['field_name'] ]['#weight'] = 4; |
|
76 | + $form += (array)content_field_form($form, $form_state, $field); |
|
77 | + $form[$settings['field_name']]['#weight'] = 4; |
|
78 | 78 | |
79 | 79 | unset($form['#cache']); |
80 | 80 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | // Add this file to be included when the form is built by rules |
109 | 109 | // as it's needed by CCKs add more button. |
110 | 110 | // See rules_after_build_include_files(). |
111 | - $form['#includes'][] = './'. drupal_get_path('module', 'node') .'/node.pages.inc'; |
|
111 | + $form['#includes'][] = './'.drupal_get_path('module', 'node').'/node.pages.inc'; |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | $settings = $form_state['element']['#settings']; |
136 | 136 | $field = content_fields($settings['field_name']); |
137 | 137 | $field_types = _content_field_types(); |
138 | - $function = $field_types[$field['type']]['module'] .'_field'; |
|
138 | + $function = $field_types[$field['type']]['module'].'_field'; |
|
139 | 139 | if (function_exists($function)) { |
140 | 140 | $form['#node'] = (object)array('type' => '', $settings['field_name'] => $form_state['values'][$settings['field_name']]); |
141 | 141 | $items = isset($form['#node']->$field['field_name']) ? $form['#node']->$field['field_name'] : array(); |
142 | 142 | |
143 | 143 | //Make sure AHAH 'add more' button isn't sent to the fields |
144 | 144 | // for processing. |
145 | - unset($items[$field['field_name'] .'_add_more']); |
|
145 | + unset($items[$field['field_name'].'_add_more']); |
|
146 | 146 | |
147 | 147 | $function('validate', $form['#node'], $field, $items, $form, NULL); |
148 | 148 | content_field('validate', $form['#node'], $field, $items, $form, NULL); |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | // Replace the usual submit handlers with a own handler. |
65 | 65 | $form['submit']['#submit'] = array('content_rules_action_populate_field_form_step_submit'); |
66 | 66 | $form['submit']['#value'] = t('Continue'); |
67 | - } |
|
68 | - else { |
|
67 | + } else { |
|
69 | 68 | // Show the fields form here. |
70 | 69 | module_load_include('inc', 'content', 'includes/content.node_form'); |
71 | 70 | $field = content_fields($settings['field_name']); |
@@ -129,8 +128,7 @@ discard block |
||
129 | 128 | if (strpos($php, 'return') === FALSE) { |
130 | 129 | form_set_error('code', t('You have to return the default value in the expected format.')); |
131 | 130 | } |
132 | - } |
|
133 | - else { |
|
131 | + } else { |
|
134 | 132 | // Validate the field. |
135 | 133 | $settings = $form_state['element']['#settings']; |
136 | 134 | $field = content_fields($settings['field_name']); |
@@ -306,14 +304,12 @@ discard block |
||
306 | 304 | if (function_exists('rules_input_evaluator_php_apply')) { |
307 | 305 | // Support adding variables to the php code, if php module is present. |
308 | 306 | $value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE); |
309 | - } |
|
310 | - else { |
|
307 | + } else { |
|
311 | 308 | ob_start(); |
312 | 309 | $value = eval($settings['code']); |
313 | 310 | ob_end_clean(); |
314 | 311 | } |
315 | - } |
|
316 | - else { |
|
312 | + } else { |
|
317 | 313 | $value = $settings['value']; |
318 | 314 | } |
319 | 315 | return $value; |
@@ -339,8 +335,7 @@ discard block |
||
339 | 335 | if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) { |
340 | 336 | return FALSE; |
341 | 337 | } |
342 | - } |
|
343 | - elseif ($sub_value !== $node_value[$delta]) { |
|
338 | + } elseif ($sub_value !== $node_value[$delta]) { |
|
344 | 339 | return FALSE; |
345 | 340 | } |
346 | 341 | } |
@@ -607,7 +607,7 @@ |
||
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
610 | - * @return a code representation of the recorded macro. |
|
610 | + * @return string|null code representation of the recorded macro. |
|
611 | 611 | */ |
612 | 612 | function content_copy_get_macro() { |
613 | 613 | // Define the indexes for the evaluated code. |
@@ -32,174 +32,174 @@ discard block |
||
32 | 32 | * Implementation of hook_menu(). |
33 | 33 | */ |
34 | 34 | function content_copy_menu() { |
35 | - $items = array(); |
|
35 | + $items = array(); |
|
36 | 36 | |
37 | - $items['admin/content/types/export'] = array( |
|
37 | + $items['admin/content/types/export'] = array( |
|
38 | 38 | 'title' => 'Export', |
39 | 39 | 'page callback' => 'drupal_get_form', |
40 | 40 | 'page arguments' => array('content_copy_export_form'), |
41 | 41 | 'access arguments' => array('administer content types'), |
42 | 42 | 'type' => MENU_LOCAL_TASK, |
43 | 43 | 'weight' => 3, |
44 | - ); |
|
45 | - $items['admin/content/types/import'] = array( |
|
44 | + ); |
|
45 | + $items['admin/content/types/import'] = array( |
|
46 | 46 | 'title' => 'Import', |
47 | 47 | 'page callback' => 'drupal_get_form', |
48 | 48 | 'page arguments' => array('content_copy_import_form'), |
49 | 49 | 'access arguments' => array('administer content types'), |
50 | 50 | 'type' => MENU_LOCAL_TASK, |
51 | 51 | 'weight' => 4, |
52 | - ); |
|
53 | - return $items; |
|
52 | + ); |
|
53 | + return $items; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Implementation of hook_theme(). |
58 | 58 | */ |
59 | 59 | function content_copy_theme() { |
60 | - return array( |
|
60 | + return array( |
|
61 | 61 | 'content_copy_export_form' => array( |
62 | - 'template' => 'content_copy_export_form', |
|
63 | - 'arguments' => array('form' => NULL), |
|
62 | + 'template' => 'content_copy_export_form', |
|
63 | + 'arguments' => array('form' => NULL), |
|
64 | 64 | ), |
65 | - ); |
|
65 | + ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * A form to export field definitions. |
70 | 70 | */ |
71 | 71 | function content_copy_export_form(&$form_state) { |
72 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
73 | - include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
72 | + include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
73 | + include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
74 | 74 | |
75 | - $form_values = isset($form_state['values']) ? $form_state['values'] : array(); |
|
76 | - $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1; |
|
75 | + $form_values = isset($form_state['values']) ? $form_state['values'] : array(); |
|
76 | + $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1; |
|
77 | 77 | |
78 | - $exportable_fields = array(); |
|
79 | - $groups = array(); |
|
78 | + $exportable_fields = array(); |
|
79 | + $groups = array(); |
|
80 | 80 | |
81 | - $type_name = isset($form_values['type_name']) ? $form_values['type_name'] : ''; |
|
82 | - if ($type_name) { |
|
81 | + $type_name = isset($form_values['type_name']) ? $form_values['type_name'] : ''; |
|
82 | + if ($type_name) { |
|
83 | 83 | $type = content_types($type_name); |
84 | 84 | $exportable_fields = content_copy_fields($type_name); |
85 | 85 | if (module_exists('fieldgroup')) { |
86 | - $groups = fieldgroup_groups($type_name); |
|
86 | + $groups = fieldgroup_groups($type_name); |
|
87 | + } |
|
87 | 88 | } |
88 | - } |
|
89 | 89 | |
90 | - // If a content type has been selected and there are no fields or groups to select, |
|
91 | - // jump straight to export. |
|
92 | - if ($step == 2 && !($groups) && !($exportable_fields)) { |
|
90 | + // If a content type has been selected and there are no fields or groups to select, |
|
91 | + // jump straight to export. |
|
92 | + if ($step == 2 && !($groups) && !($exportable_fields)) { |
|
93 | 93 | $step = 3; |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - $form['#step'] = $step; |
|
97 | - $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.'); |
|
96 | + $form['#step'] = $step; |
|
97 | + $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.'); |
|
98 | 98 | |
99 | - switch ($step) { |
|
99 | + switch ($step) { |
|
100 | 100 | case 1: // Select a content type. |
101 | 101 | $types = content_copy_types(); |
102 | - $form['type_name'] = array( |
|
102 | + $form['type_name'] = array( |
|
103 | 103 | '#title' => t('Types'), |
104 | 104 | '#type' => 'radios', |
105 | 105 | '#options' => $types, |
106 | 106 | '#description' => t('Select the content type to export.'), |
107 | - ); |
|
108 | - break; |
|
107 | + ); |
|
108 | + break; |
|
109 | 109 | |
110 | 110 | case 2: // Select groups and fields. |
111 | 111 | $form['type_name'] = array( |
112 | 112 | '#type' => 'hidden', |
113 | 113 | '#value' => $type_name, |
114 | - ); |
|
114 | + ); |
|
115 | 115 | |
116 | - $form += array( |
|
116 | + $form += array( |
|
117 | 117 | '#fields' => $exportable_fields, |
118 | 118 | '#groups' => array_keys($groups), |
119 | - ); |
|
119 | + ); |
|
120 | 120 | |
121 | - $fields_options = $groups_options = array(); |
|
121 | + $fields_options = $groups_options = array(); |
|
122 | 122 | |
123 | - // Fields. |
|
124 | - foreach ($exportable_fields as $field_name) { |
|
123 | + // Fields. |
|
124 | + foreach ($exportable_fields as $field_name) { |
|
125 | 125 | $field = content_fields($field_name, $type_name); |
126 | 126 | $fields_options[$field_name] = ''; |
127 | 127 | $weight = $field['widget']['weight']; |
128 | 128 | $form[$field_name] = array( |
129 | - 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | - 'field_name' => array('#value' => $field['field_name']), |
|
131 | - 'type' => array('#value' => $field['type']), |
|
132 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | - 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | - '#row_type' => 'field', |
|
129 | + 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | + 'field_name' => array('#value' => $field['field_name']), |
|
131 | + 'type' => array('#value' => $field['type']), |
|
132 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | + 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | + '#row_type' => 'field', |
|
135 | 135 | ); |
136 | - } |
|
137 | - $form['fields'] = array( |
|
136 | + } |
|
137 | + $form['fields'] = array( |
|
138 | 138 | '#type' => 'checkboxes', |
139 | 139 | '#options' => $fields_options, |
140 | 140 | '#default_value' => array_keys($fields_options), |
141 | - ); |
|
141 | + ); |
|
142 | 142 | |
143 | - // Groups. |
|
144 | - foreach ($groups as $name => $group) { |
|
143 | + // Groups. |
|
144 | + foreach ($groups as $name => $group) { |
|
145 | 145 | $groups_options[$name] = ''; |
146 | 146 | $weight = $group['weight']; |
147 | 147 | $form[$name] = array( |
148 | - 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | - 'group_name' => array('#value' => $group['group_name']), |
|
150 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | - '#row_type' => 'group', |
|
148 | + 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | + 'group_name' => array('#value' => $group['group_name']), |
|
150 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | + '#row_type' => 'group', |
|
152 | 152 | ); |
153 | 153 | foreach ($group['fields'] as $field_name => $field) { |
154 | - // Do nothing for non-exportable (inactive) fields. |
|
155 | - if (isset($form[$field_name])) { |
|
154 | + // Do nothing for non-exportable (inactive) fields. |
|
155 | + if (isset($form[$field_name])) { |
|
156 | 156 | $form[$field_name]['parent']['#value'] = $name; |
157 | - } |
|
157 | + } |
|
158 | + } |
|
158 | 159 | } |
159 | - } |
|
160 | - if ($groups) { |
|
160 | + if ($groups) { |
|
161 | 161 | $form['groups'] = array( |
162 | - '#type' => 'checkboxes', |
|
163 | - '#options' => $groups_options, |
|
164 | - '#default_value' => array_keys($groups_options), |
|
162 | + '#type' => 'checkboxes', |
|
163 | + '#options' => $groups_options, |
|
164 | + '#default_value' => array_keys($groups_options), |
|
165 | 165 | ); |
166 | - } |
|
167 | - break; |
|
166 | + } |
|
167 | + break; |
|
168 | 168 | |
169 | 169 | case 3: // Display the export macro. |
170 | 170 | $GLOBALS['content_copy']['count'] = 0; |
171 | - $form['export'] = array( |
|
171 | + $form['export'] = array( |
|
172 | 172 | '#title' => t('Export data'), |
173 | 173 | '#type' => 'textarea', |
174 | 174 | '#cols' => 60, |
175 | 175 | '#value' => content_copy_export($form_values), |
176 | 176 | '#rows' => max(40, $GLOBALS['content_copy']['count']), |
177 | 177 | '#description' => t('Copy the export text and paste it into another content type using the import function.'), |
178 | - ); |
|
179 | - // The calls to drupal_execute('content_field_edit_form') in |
|
180 | - // content_copy_export() affect the page title, |
|
181 | - drupal_set_title(t('Content types')); |
|
182 | - break; |
|
183 | - } |
|
184 | - |
|
185 | - if ($step < 3) { // Omit submit button on the textarea block to display the export data. |
|
178 | + ); |
|
179 | + // The calls to drupal_execute('content_field_edit_form') in |
|
180 | + // content_copy_export() affect the page title, |
|
181 | + drupal_set_title(t('Content types')); |
|
182 | + break; |
|
183 | + } |
|
184 | + |
|
185 | + if ($step < 3) { // Omit submit button on the textarea block to display the export data. |
|
186 | 186 | $form['submit'] = array( |
187 | - '#type' => 'submit', |
|
188 | - '#value' => t('Export'), |
|
187 | + '#type' => 'submit', |
|
188 | + '#value' => t('Export'), |
|
189 | 189 | ); |
190 | - } |
|
190 | + } |
|
191 | 191 | |
192 | - $form['step'] = array( |
|
192 | + $form['step'] = array( |
|
193 | 193 | '#type' => 'value', |
194 | 194 | '#value' => $step, |
195 | - ); |
|
195 | + ); |
|
196 | 196 | |
197 | - return $form; |
|
197 | + return $form; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | function content_copy_export_form_submit($form, &$form_state) { |
201 | - $form_state['rebuild'] = TRUE; |
|
202 | - $form_state['storage']['step'] = $form_state['values']['step']; |
|
201 | + $form_state['rebuild'] = TRUE; |
|
202 | + $form_state['storage']['step'] = $form_state['values']['step']; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -208,66 +208,66 @@ discard block |
||
208 | 208 | * and save the form values as formatted text. |
209 | 209 | */ |
210 | 210 | function content_copy_export($form_values) { |
211 | - // Set a global variable to tell when to intervene with form_alter(). |
|
212 | - $GLOBALS['content_copy']['status'] = 'export'; |
|
211 | + // Set a global variable to tell when to intervene with form_alter(). |
|
212 | + $GLOBALS['content_copy']['status'] = 'export'; |
|
213 | 213 | |
214 | - // Get the content type info by submitting the content type form. |
|
215 | - $node_state = array('values' => array('type_name' => $form_values['type_name'])); |
|
216 | - module_load_include('inc', 'node', 'content_types'); |
|
217 | - drupal_execute('node_type_form', $node_state, node_get_types('type', $form_values['type_name'])); |
|
214 | + // Get the content type info by submitting the content type form. |
|
215 | + $node_state = array('values' => array('type_name' => $form_values['type_name'])); |
|
216 | + module_load_include('inc', 'node', 'content_types'); |
|
217 | + drupal_execute('node_type_form', $node_state, node_get_types('type', $form_values['type_name'])); |
|
218 | 218 | |
219 | - module_load_include('inc', 'content', 'includes/content.admin'); |
|
220 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
219 | + module_load_include('inc', 'content', 'includes/content.admin'); |
|
220 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
221 | 221 | |
222 | - // Get an array of groups to export. |
|
223 | - // Record a macro for each group by submitting the group edit form. |
|
224 | - $groups = array(); |
|
225 | - if (!empty($form_values['groups']) && module_exists('fieldgroup')) { |
|
222 | + // Get an array of groups to export. |
|
223 | + // Record a macro for each group by submitting the group edit form. |
|
224 | + $groups = array(); |
|
225 | + if (!empty($form_values['groups']) && module_exists('fieldgroup')) { |
|
226 | 226 | $groups = array_filter($form_values['groups']); |
227 | 227 | foreach ($groups as $group) { |
228 | - $group_state = array('values' => array('group_name' => $group)); |
|
229 | - drupal_execute('fieldgroup_group_edit_form', $group_state, $form_values['type_name'], $group, 'edit'); |
|
228 | + $group_state = array('values' => array('group_name' => $group)); |
|
229 | + drupal_execute('fieldgroup_group_edit_form', $group_state, $form_values['type_name'], $group, 'edit'); |
|
230 | + } |
|
230 | 231 | } |
231 | - } |
|
232 | 232 | |
233 | - // Get an array of fields to export |
|
234 | - // Record a macro for each field by submitting the field settings form. |
|
235 | - // Omit fields from the export if their module is not currently installed |
|
236 | - // otherwise the system will generate errors when the macro tries to execute their forms. |
|
237 | - if (!empty($form_values['fields'])) { |
|
233 | + // Get an array of fields to export |
|
234 | + // Record a macro for each field by submitting the field settings form. |
|
235 | + // Omit fields from the export if their module is not currently installed |
|
236 | + // otherwise the system will generate errors when the macro tries to execute their forms. |
|
237 | + if (!empty($form_values['fields'])) { |
|
238 | 238 | $type = content_types($form_values['type_name']); |
239 | 239 | $fields = array_filter($form_values['fields']); |
240 | 240 | foreach ($fields as $field_name) { |
241 | - $field = $type['fields'][$field_name]; |
|
242 | - $field_types = _content_field_types(); |
|
243 | - $field_module = $field_types[$field['type']]['module']; |
|
244 | - $widget_types = _content_widget_types(); |
|
245 | - $widget_module = $widget_types[$field['widget']['type']]['module']; |
|
246 | - if (!empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) { |
|
241 | + $field = $type['fields'][$field_name]; |
|
242 | + $field_types = _content_field_types(); |
|
243 | + $field_module = $field_types[$field['type']]['module']; |
|
244 | + $widget_types = _content_widget_types(); |
|
245 | + $widget_module = $widget_types[$field['widget']['type']]['module']; |
|
246 | + if (!empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) { |
|
247 | 247 | $field_state = array('values' => content_field_instance_collapse($field)); |
248 | 248 | $field_state['values']['op'] = t('Save field settings'); |
249 | 249 | if (module_exists('fieldgroup')) { |
250 | - // Avoid undefined index error by always creating this. |
|
251 | - $field_state['values']['group'] = ''; |
|
252 | - $group_name = fieldgroup_get_group($form_values['type_name'], $field_name); |
|
253 | - if (in_array($group_name, $groups)) { |
|
250 | + // Avoid undefined index error by always creating this. |
|
251 | + $field_state['values']['group'] = ''; |
|
252 | + $group_name = fieldgroup_get_group($form_values['type_name'], $field_name); |
|
253 | + if (in_array($group_name, $groups)) { |
|
254 | 254 | $field_state['values']['group'] = $group_name; |
255 | - } |
|
255 | + } |
|
256 | 256 | } |
257 | 257 | drupal_execute('content_field_edit_form', $field_state, $form_values['type_name'], $field_name); |
258 | - } |
|
258 | + } |
|
259 | + } |
|
259 | 260 | } |
260 | - } |
|
261 | 261 | |
262 | - // Convert the macro array into formatted text. |
|
263 | - $output = content_copy_get_macro(); |
|
262 | + // Convert the macro array into formatted text. |
|
263 | + $output = content_copy_get_macro(); |
|
264 | 264 | |
265 | - // Add weights of non-CCK fields. |
|
266 | - if ($extra = variable_get('content_extra_weights_'. $form_values['type_name'], array())) { |
|
265 | + // Add weights of non-CCK fields. |
|
266 | + if ($extra = variable_get('content_extra_weights_'. $form_values['type_name'], array())) { |
|
267 | 267 | $output .= "\$content['extra'] = ". var_export((array) $extra, TRUE) .";\n"; |
268 | - } |
|
268 | + } |
|
269 | 269 | |
270 | - return $output; |
|
270 | + return $output; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -294,37 +294,37 @@ discard block |
||
294 | 294 | * } |
295 | 295 | */ |
296 | 296 | function content_copy_import_form(&$form_state, $type_name = '') { |
297 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
298 | - include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
297 | + include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
298 | + include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
299 | 299 | |
300 | - $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.'); |
|
301 | - $form['type_name'] = array( |
|
300 | + $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.'); |
|
301 | + $form['type_name'] = array( |
|
302 | 302 | '#type' => 'select', |
303 | 303 | '#options' => array('<create>' => t('<Create>')) + content_copy_types(), |
304 | 304 | '#default_value' => $type_name, |
305 | 305 | '#title' => t('Content type'), |
306 | 306 | '#description' => t('Select the content type to import these fields into.<br/>Select <Create> to create a new content type to contain the fields.'), |
307 | - ); |
|
308 | - $form['macro'] = array( |
|
307 | + ); |
|
308 | + $form['macro'] = array( |
|
309 | 309 | '#type' => 'textarea', |
310 | 310 | '#rows' => 40, |
311 | 311 | '#title' => t('Import data'), |
312 | 312 | '#required' => TRUE, |
313 | 313 | '#description' => t('Paste the text created by a content export into this field.'), |
314 | - ); |
|
315 | - $form['submit'] = array( |
|
314 | + ); |
|
315 | + $form['submit'] = array( |
|
316 | 316 | '#type' => 'submit', |
317 | 317 | '#value' => t('Import'), |
318 | - ); |
|
319 | - // Read in a file if there is one and set it as the default macro value. |
|
320 | - if (isset($_REQUEST['macro_file']) && $file = file_get_contents($_REQUEST['macro_file'])) { |
|
318 | + ); |
|
319 | + // Read in a file if there is one and set it as the default macro value. |
|
320 | + if (isset($_REQUEST['macro_file']) && $file = file_get_contents($_REQUEST['macro_file'])) { |
|
321 | 321 | $form['macro']['#default_value'] = $file; |
322 | 322 | if (isset($_REQUEST['type_name'])) { |
323 | - $form['type_name']['#default_value'] = $_REQUEST['type_name']; |
|
323 | + $form['type_name']['#default_value'] = $_REQUEST['type_name']; |
|
324 | 324 | } |
325 | 325 | $form['#prefix'] .= '<p class="error">'. t('A file has been pre-loaded for import.') .'</p>'; |
326 | - } |
|
327 | - return $form; |
|
326 | + } |
|
327 | + return $form; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,90 +334,90 @@ discard block |
||
334 | 334 | * 2) execute the imported field macro to update the settings to the imported values |
335 | 335 | */ |
336 | 336 | function content_copy_import_form_submit($form, &$form_state) { |
337 | - $form_values = $form_state['values']; |
|
337 | + $form_values = $form_state['values']; |
|
338 | 338 | |
339 | - // Get the content type we are importing into. |
|
340 | - $type_name = $form_values['type_name']; |
|
341 | - $type_label = node_get_types('name', $type_name); |
|
339 | + // Get the content type we are importing into. |
|
340 | + $type_name = $form_values['type_name']; |
|
341 | + $type_label = node_get_types('name', $type_name); |
|
342 | 342 | |
343 | - $content = NULL; |
|
344 | - // Convert the import formatted text back into a $content array. |
|
345 | - // Return if errors generated or not an array. |
|
346 | - // Use '@' to suppress errors about undefined constants in the macro. |
|
347 | - @eval($form_values['macro']); |
|
343 | + $content = NULL; |
|
344 | + // Convert the import formatted text back into a $content array. |
|
345 | + // Return if errors generated or not an array. |
|
346 | + // Use '@' to suppress errors about undefined constants in the macro. |
|
347 | + @eval($form_values['macro']); |
|
348 | 348 | |
349 | - // Preliminary error trapping, must have valid arrays to work with. |
|
350 | - if (!isset($content) || !isset($content['type']) || !is_array($content) || !is_array($content['type'])) { |
|
349 | + // Preliminary error trapping, must have valid arrays to work with. |
|
350 | + if (!isset($content) || !isset($content['type']) || !is_array($content) || !is_array($content['type'])) { |
|
351 | 351 | form_set_error('macro', t('The import data is not valid import text.')); |
352 | 352 | return; |
353 | - } |
|
353 | + } |
|
354 | 354 | |
355 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
355 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
356 | 356 | |
357 | - // Get all type and field info for this database. |
|
358 | - $content_info = _content_type_info(); |
|
357 | + // Get all type and field info for this database. |
|
358 | + $content_info = _content_type_info(); |
|
359 | 359 | |
360 | - $imported_type = $content['type']; |
|
361 | - $imported_type_name = $imported_type['type']; |
|
362 | - $imported_type_label = $imported_type['name']; |
|
360 | + $imported_type = $content['type']; |
|
361 | + $imported_type_name = $imported_type['type']; |
|
362 | + $imported_type_label = $imported_type['name']; |
|
363 | 363 | |
364 | - // It is allowed to import a type with no fields, |
|
365 | - // so the fields array could be empty and must be cast as an array. |
|
366 | - $imported_fields = isset($content['fields']) ? $content['fields'] : array(); |
|
364 | + // It is allowed to import a type with no fields, |
|
365 | + // so the fields array could be empty and must be cast as an array. |
|
366 | + $imported_fields = isset($content['fields']) ? $content['fields'] : array(); |
|
367 | 367 | |
368 | - // Perform more pre-import error trapping. |
|
369 | - // If there are potential problems, exit without doing the import. |
|
370 | - $not_enabled = array(); |
|
368 | + // Perform more pre-import error trapping. |
|
369 | + // If there are potential problems, exit without doing the import. |
|
370 | + $not_enabled = array(); |
|
371 | 371 | |
372 | - // The groups array could be empty and still valid, make sure to cast it as an array. |
|
373 | - // If there are groups in the import, make sure the fieldgroup module is enabled. |
|
374 | - $imported_groups = array(); |
|
375 | - if (isset($content['groups']) && module_exists('fieldgroup')) { |
|
372 | + // The groups array could be empty and still valid, make sure to cast it as an array. |
|
373 | + // If there are groups in the import, make sure the fieldgroup module is enabled. |
|
374 | + $imported_groups = array(); |
|
375 | + if (isset($content['groups']) && module_exists('fieldgroup')) { |
|
376 | 376 | $imported_groups = (array) $content['groups']; |
377 | - } |
|
378 | - elseif (isset($content['groups']) && is_array($content['groups'])) { |
|
377 | + } |
|
378 | + elseif (isset($content['groups']) && is_array($content['groups'])) { |
|
379 | 379 | $not_enabled[] = 'fieldgroup'; |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - // Make sure that all the field and widget modules in the import are enabled in this database. |
|
383 | - foreach ($imported_fields as $import) { |
|
382 | + // Make sure that all the field and widget modules in the import are enabled in this database. |
|
383 | + foreach ($imported_fields as $import) { |
|
384 | 384 | $field = content_field_instance_collapse($import); |
385 | 385 | if (empty($field['module']) || empty($field['widget_module'])) { |
386 | - $not_enabled[] = $field['field_name']; |
|
386 | + $not_enabled[] = $field['field_name']; |
|
387 | 387 | } |
388 | 388 | else { |
389 | - if (!module_exists($field['module'])) { |
|
389 | + if (!module_exists($field['module'])) { |
|
390 | 390 | $not_enabled[] = $field['module']; |
391 | - } |
|
392 | - if (!module_exists($field['widget_module'])) { |
|
391 | + } |
|
392 | + if (!module_exists($field['widget_module'])) { |
|
393 | 393 | $not_enabled[] = $field['widget_module']; |
394 | - } |
|
394 | + } |
|
395 | + } |
|
395 | 396 | } |
396 | - } |
|
397 | 397 | |
398 | - // If any required module is not enabled, set an error message and exit. |
|
399 | - if ($not_enabled) { |
|
398 | + // If any required module is not enabled, set an error message and exit. |
|
399 | + if ($not_enabled) { |
|
400 | 400 | form_set_error('macro', t('The following modules must be enabled for this import to work: %modules.', array( |
401 | 401 | '%modules' => implode(', ', array_unique($not_enabled)) |
402 | 402 | ))); |
403 | - } |
|
403 | + } |
|
404 | 404 | |
405 | - // Make sure the imported content type doesn't already exist in the database. |
|
406 | - if ($form_values['type_name'] == '<create>') { |
|
405 | + // Make sure the imported content type doesn't already exist in the database. |
|
406 | + if ($form_values['type_name'] == '<create>') { |
|
407 | 407 | if (in_array($imported_type_name, array_keys($content_info['content types']))) { |
408 | - form_set_error('macro', t('The content type %type already exists in this database.', array( |
|
408 | + form_set_error('macro', t('The content type %type already exists in this database.', array( |
|
409 | 409 | '%type' => $imported_type_name |
410 | 410 | ))); |
411 | 411 | } |
412 | - } |
|
412 | + } |
|
413 | 413 | |
414 | - if (form_get_errors()) { |
|
414 | + if (form_get_errors()) { |
|
415 | 415 | drupal_set_message(t('Exiting. No import performed.'), 'error'); |
416 | 416 | return; |
417 | - } |
|
417 | + } |
|
418 | 418 | |
419 | - // Create the content type, if requested. |
|
420 | - if ($form_values['type_name'] == '<create>') { |
|
419 | + // Create the content type, if requested. |
|
420 | + if ($form_values['type_name'] == '<create>') { |
|
421 | 421 | |
422 | 422 | $type = (object) $imported_type; |
423 | 423 | $values = $imported_type; |
@@ -435,26 +435,26 @@ discard block |
||
435 | 435 | $content_info = _content_type_info(); |
436 | 436 | |
437 | 437 | if (form_get_errors() || !isset($content_info['content types']) || !is_array($content_info['content types'][$type_name])) { |
438 | - drupal_set_message(t('An error has occurred adding the content type %type.<br/>Please check the errors displayed for more details.', array( |
|
438 | + drupal_set_message(t('An error has occurred adding the content type %type.<br/>Please check the errors displayed for more details.', array( |
|
439 | 439 | '%type' => $imported_type_name |
440 | 440 | ))); |
441 | - return; |
|
441 | + return; |
|
442 | + } |
|
442 | 443 | } |
443 | - } |
|
444 | 444 | |
445 | - // Create the groups for this type, if they don't already exist. |
|
446 | - if (module_exists('fieldgroup') && $imported_groups) { |
|
445 | + // Create the groups for this type, if they don't already exist. |
|
446 | + if (module_exists('fieldgroup') && $imported_groups) { |
|
447 | 447 | foreach ($imported_groups as $group) { |
448 | - $group_name = $group['group_name']; |
|
449 | - fieldgroup_save_group($type_name, $group); |
|
448 | + $group_name = $group['group_name']; |
|
449 | + fieldgroup_save_group($type_name, $group); |
|
450 | 450 | } |
451 | 451 | // Reset the static variable in fieldgroup_groups() with new data. |
452 | 452 | fieldgroup_groups('', FALSE, TRUE); |
453 | - } |
|
453 | + } |
|
454 | 454 | |
455 | - // Iterate through the field forms in the import and execute each. |
|
456 | - $rebuild = FALSE; |
|
457 | - foreach ($imported_fields as $field) { |
|
455 | + // Iterate through the field forms in the import and execute each. |
|
456 | + $rebuild = FALSE; |
|
457 | + foreach ($imported_fields as $field) { |
|
458 | 458 | |
459 | 459 | // Make sure the field doesn't already exist in the type. |
460 | 460 | // If so, do nothing, fields can't be duplicated within a content type. |
@@ -464,13 +464,13 @@ discard block |
||
464 | 464 | $field['type_name'] = $type_name; |
465 | 465 | |
466 | 466 | if (!empty($field['field_name']) && isset($content_info['content types'][$type_name]['fields'][$field_name])) { |
467 | - drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array( |
|
467 | + drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array( |
|
468 | 468 | '%field_label' => $field['label'], '%field_name' => $field_name, '%type' => $type_label))); |
469 | 469 | } |
470 | 470 | else { |
471 | - $field = content_field_instance_create($field, FALSE); |
|
472 | - $rebuild = TRUE; |
|
473 | - drupal_set_message(t('The field %field_label (%field_name) was added to the content type %type.', array( |
|
471 | + $field = content_field_instance_create($field, FALSE); |
|
472 | + $rebuild = TRUE; |
|
473 | + drupal_set_message(t('The field %field_label (%field_name) was added to the content type %type.', array( |
|
474 | 474 | '%field_label' => $field['widget']['label'], '%field_name' => $field_name, '%type' => $type_label))); |
475 | 475 | } |
476 | 476 | |
@@ -480,20 +480,20 @@ discard block |
||
480 | 480 | // restored. Hence, we need to update field group data for newly imported |
481 | 481 | // field, but also for fields that already exist. |
482 | 482 | if (module_exists('fieldgroup') && isset($imported_groups)) { |
483 | - fieldgroup_update_fields($field); |
|
483 | + fieldgroup_update_fields($field); |
|
484 | + } |
|
484 | 485 | } |
485 | - } |
|
486 | 486 | |
487 | - // Clear caches and rebuild menu only if any field has been created. |
|
488 | - if ($rebuild) { |
|
487 | + // Clear caches and rebuild menu only if any field has been created. |
|
488 | + if ($rebuild) { |
|
489 | 489 | content_clear_type_cache(TRUE); |
490 | 490 | menu_rebuild(); |
491 | - } |
|
491 | + } |
|
492 | 492 | |
493 | - // Import weights of non-CCK fields. |
|
494 | - if (isset($content['extra'])) { |
|
493 | + // Import weights of non-CCK fields. |
|
494 | + if (isset($content['extra'])) { |
|
495 | 495 | variable_set('content_extra_weights_'. $type_name, $content['extra']); |
496 | - } |
|
496 | + } |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -501,22 +501,22 @@ discard block |
||
501 | 501 | * Intervene to run form through macro when doing export |
502 | 502 | */ |
503 | 503 | function content_copy_form_alter(&$form, $form_state, $form_id) { |
504 | - $alter_forms = array('node_type_form', 'content_field_edit_form', 'fieldgroup_group_edit_form'); |
|
505 | - if (isset($GLOBALS['content_copy']) && isset($GLOBALS['content_copy']['status']) && $GLOBALS['content_copy']['status'] == 'export' && in_array($form_id, $alter_forms)) { |
|
504 | + $alter_forms = array('node_type_form', 'content_field_edit_form', 'fieldgroup_group_edit_form'); |
|
505 | + if (isset($GLOBALS['content_copy']) && isset($GLOBALS['content_copy']['status']) && $GLOBALS['content_copy']['status'] == 'export' && in_array($form_id, $alter_forms)) { |
|
506 | 506 | $form['#submit'][] = 'content_copy_record_macro'; |
507 | - } |
|
507 | + } |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
511 | 511 | * Get all the *active* fields for a content type. |
512 | 512 | */ |
513 | 513 | function content_copy_fields($type_name) { |
514 | - $fields = array(); |
|
515 | - if (!$type_name) { |
|
514 | + $fields = array(); |
|
515 | + if (!$type_name) { |
|
516 | 516 | return $fields; |
517 | - } |
|
518 | - $content_info = _content_type_info(); |
|
519 | - foreach ($content_info['content types'][$type_name]['fields'] as $field_name => $field) { |
|
517 | + } |
|
518 | + $content_info = _content_type_info(); |
|
519 | + foreach ($content_info['content types'][$type_name]['fields'] as $field_name => $field) { |
|
520 | 520 | // Omit fields from the export if their module is not currently installed |
521 | 521 | // otherwise the system will generate errors when the macro tries to execute their forms. |
522 | 522 | $field_types = _content_field_types(); |
@@ -525,125 +525,125 @@ discard block |
||
525 | 525 | $widget_module = $widget_types[$field['widget']['type']]['module']; |
526 | 526 | |
527 | 527 | if (!$field['locked'] && !empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) { |
528 | - $fields[] = $field_name; |
|
528 | + $fields[] = $field_name; |
|
529 | 529 | } |
530 | - } |
|
531 | - return $fields; |
|
530 | + } |
|
531 | + return $fields; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
535 | 535 | * Get all content types. |
536 | 536 | */ |
537 | 537 | function content_copy_types() { |
538 | - $types = array(); |
|
539 | - $content_info = _content_type_info(); |
|
540 | - foreach ($content_info['content types'] as $type_name => $val) { |
|
538 | + $types = array(); |
|
539 | + $content_info = _content_type_info(); |
|
540 | + foreach ($content_info['content types'] as $type_name => $val) { |
|
541 | 541 | $types[$type_name] = check_plain($val['name']) .' ('. $type_name .')'; |
542 | - } |
|
543 | - return $types; |
|
542 | + } |
|
543 | + return $types; |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | 547 | * A handler that stores the form submissions into a $GLOBALS array |
548 | 548 | */ |
549 | 549 | function content_copy_record_macro($form, &$form_state) { |
550 | - $edit = $form_state['values']; |
|
551 | - $subs = isset($GLOBALS['content_copy']['submissions']) ? $GLOBALS['content_copy']['submissions'] : array(); |
|
550 | + $edit = $form_state['values']; |
|
551 | + $subs = isset($GLOBALS['content_copy']['submissions']) ? $GLOBALS['content_copy']['submissions'] : array(); |
|
552 | 552 | |
553 | - // Get the form values and store them in a $GLOBALS['content_copy']['submissions'] array. |
|
554 | - // Update $GLOBALS['content_copy']['count'] with an approximation of the number of rows in this item. |
|
555 | - // Count is used to approximate necessary size of textarea in form. |
|
553 | + // Get the form values and store them in a $GLOBALS['content_copy']['submissions'] array. |
|
554 | + // Update $GLOBALS['content_copy']['count'] with an approximation of the number of rows in this item. |
|
555 | + // Count is used to approximate necessary size of textarea in form. |
|
556 | 556 | |
557 | - $form_id = $form_state['values']['form_id']; |
|
558 | - if (isset($edit['type_name']) || isset($edit['submit']) || isset($edit['delete']) || isset($edit['form_id'])) { |
|
557 | + $form_id = $form_state['values']['form_id']; |
|
558 | + if (isset($edit['type_name']) || isset($edit['submit']) || isset($edit['delete']) || isset($edit['form_id'])) { |
|
559 | 559 | unset($edit['type_name'], $edit['submit'], $edit['delete'], $edit['form_id'], $edit['previous_field']); |
560 | - } |
|
561 | - switch ($form_id) { |
|
560 | + } |
|
561 | + switch ($form_id) { |
|
562 | 562 | case 'node_type_form': |
563 | 563 | $subs['type'] = $edit; |
564 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | - break; |
|
564 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | + break; |
|
566 | 566 | |
567 | 567 | case 'fieldgroup_group_edit_form': |
568 | 568 | $subs['groups'][] = $edit; |
569 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | - break; |
|
569 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | + break; |
|
571 | 571 | |
572 | 572 | default: |
573 | 573 | if (isset($edit['field_widget_type'])) { |
574 | 574 | $tmp = explode('-', $edit['field_widget_type']); |
575 | 575 | $field_name = $tmp[0]; |
576 | - } |
|
577 | - else { |
|
576 | + } |
|
577 | + else { |
|
578 | 578 | $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - // The display settings are being fetched directly from the DB. During import, |
|
582 | - // we'll re-insert the data directly as well. |
|
583 | - // |
|
584 | - $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | - $row_info = db_fetch_array(db_query($query, $field_name)); |
|
581 | + // The display settings are being fetched directly from the DB. During import, |
|
582 | + // we'll re-insert the data directly as well. |
|
583 | + // |
|
584 | + $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | + $row_info = db_fetch_array(db_query($query, $field_name)); |
|
586 | 586 | |
587 | - // If an error occurs, notify the user. |
|
588 | - if ($db_err = db_error()) { |
|
587 | + // If an error occurs, notify the user. |
|
588 | + if ($db_err = db_error()) { |
|
589 | 589 | drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array( |
590 | - '%field_name' => $field_name, |
|
591 | - '%db_err' => $db_err |
|
590 | + '%field_name' => $field_name, |
|
591 | + '%db_err' => $db_err |
|
592 | 592 | ))); |
593 | - } |
|
594 | - else { |
|
593 | + } |
|
594 | + else { |
|
595 | 595 | // The db fetch occurred successfully, unserialize the data blob and |
596 | 596 | // insert it into a new "display_settings" field of the data. |
597 | 597 | if ($display_settings = unserialize($row_info['display_settings'])) { |
598 | - $edit['display_settings'] = $display_settings; |
|
598 | + $edit['display_settings'] = $display_settings; |
|
599 | 599 | } |
600 | - } |
|
601 | - $subs['fields'][] = $edit; |
|
602 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | - break; |
|
604 | - } |
|
600 | + } |
|
601 | + $subs['fields'][] = $edit; |
|
602 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | + break; |
|
604 | + } |
|
605 | 605 | |
606 | - $GLOBALS['content_copy']['submissions'] = $subs; |
|
606 | + $GLOBALS['content_copy']['submissions'] = $subs; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
610 | 610 | * @return a code representation of the recorded macro. |
611 | 611 | */ |
612 | 612 | function content_copy_get_macro() { |
613 | - // Define the indexes for the evaluated code. |
|
614 | - $string = ""; |
|
615 | - if (array_key_exists('submissions', $GLOBALS['content_copy'])) { |
|
613 | + // Define the indexes for the evaluated code. |
|
614 | + $string = ""; |
|
615 | + if (array_key_exists('submissions', $GLOBALS['content_copy'])) { |
|
616 | 616 | foreach ($GLOBALS['content_copy']['submissions'] as $form_type => $form) { |
617 | - $string .= "\$content['$form_type'] = ". var_export((array) $form, TRUE) .";\n"; |
|
617 | + $string .= "\$content['$form_type'] = ". var_export((array) $form, TRUE) .";\n"; |
|
618 | 618 | } |
619 | 619 | return $string; |
620 | - } |
|
620 | + } |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | function template_preprocess_content_copy_export_form($vars) { |
624 | - $form = &$vars['form']; |
|
624 | + $form = &$vars['form']; |
|
625 | 625 | |
626 | - if ($form['#step'] == 2) { |
|
626 | + if ($form['#step'] == 2) { |
|
627 | 627 | $order = _content_overview_order($form, $form['#fields'], $form['#groups']); |
628 | 628 | |
629 | 629 | $rows = array(); |
630 | 630 | foreach ($order as $key) { |
631 | - $element = &$form[$key]; |
|
632 | - $row = new stdClass(); |
|
631 | + $element = &$form[$key]; |
|
632 | + $row = new stdClass(); |
|
633 | 633 | |
634 | - $row->row_type = $element['#row_type']; |
|
635 | - $checkbox_key = $element['#row_type'] == 'field' ? 'fields' : 'groups'; |
|
636 | - $row->checkbox = drupal_render($form[$checkbox_key][$key]); |
|
637 | - foreach (element_children($element) as $child) { |
|
634 | + $row->row_type = $element['#row_type']; |
|
635 | + $checkbox_key = $element['#row_type'] == 'field' ? 'fields' : 'groups'; |
|
636 | + $row->checkbox = drupal_render($form[$checkbox_key][$key]); |
|
637 | + foreach (element_children($element) as $child) { |
|
638 | 638 | $row->{$child} = drupal_render($element[$child]); |
639 | - } |
|
640 | - $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field'; |
|
641 | - $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
|
639 | + } |
|
640 | + $row->label_class = in_array($key, $form['#groups']) ? 'label-group' : 'label-field'; |
|
641 | + $row->indentation = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0); |
|
642 | 642 | |
643 | - $rows[] = $row; |
|
643 | + $rows[] = $row; |
|
644 | 644 | } |
645 | 645 | $vars['rows'] = $rows; |
646 | - } |
|
646 | + } |
|
647 | 647 | |
648 | - $vars['submit'] = drupal_render($form); |
|
648 | + $vars['submit'] = drupal_render($form); |
|
649 | 649 | } |
650 | 650 | \ No newline at end of file |
@@ -97,89 +97,89 @@ discard block |
||
97 | 97 | $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to an existing content type or create a new content type that includes the selected fields.'); |
98 | 98 | |
99 | 99 | switch ($step) { |
100 | - case 1: // Select a content type. |
|
101 | - $types = content_copy_types(); |
|
102 | - $form['type_name'] = array( |
|
103 | - '#title' => t('Types'), |
|
104 | - '#type' => 'radios', |
|
105 | - '#options' => $types, |
|
106 | - '#description' => t('Select the content type to export.'), |
|
107 | - ); |
|
108 | - break; |
|
100 | + case 1: // Select a content type. |
|
101 | + $types = content_copy_types(); |
|
102 | + $form['type_name'] = array( |
|
103 | + '#title' => t('Types'), |
|
104 | + '#type' => 'radios', |
|
105 | + '#options' => $types, |
|
106 | + '#description' => t('Select the content type to export.'), |
|
107 | + ); |
|
108 | + break; |
|
109 | 109 | |
110 | - case 2: // Select groups and fields. |
|
111 | - $form['type_name'] = array( |
|
112 | - '#type' => 'hidden', |
|
113 | - '#value' => $type_name, |
|
114 | - ); |
|
110 | + case 2: // Select groups and fields. |
|
111 | + $form['type_name'] = array( |
|
112 | + '#type' => 'hidden', |
|
113 | + '#value' => $type_name, |
|
114 | + ); |
|
115 | 115 | |
116 | - $form += array( |
|
117 | - '#fields' => $exportable_fields, |
|
118 | - '#groups' => array_keys($groups), |
|
119 | - ); |
|
116 | + $form += array( |
|
117 | + '#fields' => $exportable_fields, |
|
118 | + '#groups' => array_keys($groups), |
|
119 | + ); |
|
120 | 120 | |
121 | - $fields_options = $groups_options = array(); |
|
122 | - |
|
123 | - // Fields. |
|
124 | - foreach ($exportable_fields as $field_name) { |
|
125 | - $field = content_fields($field_name, $type_name); |
|
126 | - $fields_options[$field_name] = ''; |
|
127 | - $weight = $field['widget']['weight']; |
|
128 | - $form[$field_name] = array( |
|
129 | - 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | - 'field_name' => array('#value' => $field['field_name']), |
|
131 | - 'type' => array('#value' => $field['type']), |
|
132 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | - 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | - '#row_type' => 'field', |
|
135 | - ); |
|
136 | - } |
|
137 | - $form['fields'] = array( |
|
138 | - '#type' => 'checkboxes', |
|
139 | - '#options' => $fields_options, |
|
140 | - '#default_value' => array_keys($fields_options), |
|
121 | + $fields_options = $groups_options = array(); |
|
122 | + |
|
123 | + // Fields. |
|
124 | + foreach ($exportable_fields as $field_name) { |
|
125 | + $field = content_fields($field_name, $type_name); |
|
126 | + $fields_options[$field_name] = ''; |
|
127 | + $weight = $field['widget']['weight']; |
|
128 | + $form[$field_name] = array( |
|
129 | + 'human_name' => array('#value' => check_plain($field['widget']['label'])), |
|
130 | + 'field_name' => array('#value' => $field['field_name']), |
|
131 | + 'type' => array('#value' => $field['type']), |
|
132 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
133 | + 'parent' => array('#type' => 'value', '#value' => ''), |
|
134 | + '#row_type' => 'field', |
|
141 | 135 | ); |
136 | + } |
|
137 | + $form['fields'] = array( |
|
138 | + '#type' => 'checkboxes', |
|
139 | + '#options' => $fields_options, |
|
140 | + '#default_value' => array_keys($fields_options), |
|
141 | + ); |
|
142 | 142 | |
143 | - // Groups. |
|
144 | - foreach ($groups as $name => $group) { |
|
145 | - $groups_options[$name] = ''; |
|
146 | - $weight = $group['weight']; |
|
147 | - $form[$name] = array( |
|
148 | - 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | - 'group_name' => array('#value' => $group['group_name']), |
|
150 | - 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | - '#row_type' => 'group', |
|
152 | - ); |
|
153 | - foreach ($group['fields'] as $field_name => $field) { |
|
154 | - // Do nothing for non-exportable (inactive) fields. |
|
155 | - if (isset($form[$field_name])) { |
|
156 | - $form[$field_name]['parent']['#value'] = $name; |
|
157 | - } |
|
143 | + // Groups. |
|
144 | + foreach ($groups as $name => $group) { |
|
145 | + $groups_options[$name] = ''; |
|
146 | + $weight = $group['weight']; |
|
147 | + $form[$name] = array( |
|
148 | + 'human_name' => array('#value' => check_plain($group['label'])), |
|
149 | + 'group_name' => array('#value' => $group['group_name']), |
|
150 | + 'weight' => array('#type' => 'value', '#value' => $weight), |
|
151 | + '#row_type' => 'group', |
|
152 | + ); |
|
153 | + foreach ($group['fields'] as $field_name => $field) { |
|
154 | + // Do nothing for non-exportable (inactive) fields. |
|
155 | + if (isset($form[$field_name])) { |
|
156 | + $form[$field_name]['parent']['#value'] = $name; |
|
158 | 157 | } |
159 | 158 | } |
160 | - if ($groups) { |
|
161 | - $form['groups'] = array( |
|
162 | - '#type' => 'checkboxes', |
|
163 | - '#options' => $groups_options, |
|
164 | - '#default_value' => array_keys($groups_options), |
|
165 | - ); |
|
166 | - } |
|
167 | - break; |
|
168 | - |
|
169 | - case 3: // Display the export macro. |
|
170 | - $GLOBALS['content_copy']['count'] = 0; |
|
171 | - $form['export'] = array( |
|
172 | - '#title' => t('Export data'), |
|
173 | - '#type' => 'textarea', |
|
174 | - '#cols' => 60, |
|
175 | - '#value' => content_copy_export($form_values), |
|
176 | - '#rows' => max(40, $GLOBALS['content_copy']['count']), |
|
177 | - '#description' => t('Copy the export text and paste it into another content type using the import function.'), |
|
159 | + } |
|
160 | + if ($groups) { |
|
161 | + $form['groups'] = array( |
|
162 | + '#type' => 'checkboxes', |
|
163 | + '#options' => $groups_options, |
|
164 | + '#default_value' => array_keys($groups_options), |
|
178 | 165 | ); |
179 | - // The calls to drupal_execute('content_field_edit_form') in |
|
180 | - // content_copy_export() affect the page title, |
|
181 | - drupal_set_title(t('Content types')); |
|
182 | - break; |
|
166 | + } |
|
167 | + break; |
|
168 | + |
|
169 | + case 3: // Display the export macro. |
|
170 | + $GLOBALS['content_copy']['count'] = 0; |
|
171 | + $form['export'] = array( |
|
172 | + '#title' => t('Export data'), |
|
173 | + '#type' => 'textarea', |
|
174 | + '#cols' => 60, |
|
175 | + '#value' => content_copy_export($form_values), |
|
176 | + '#rows' => max(40, $GLOBALS['content_copy']['count']), |
|
177 | + '#description' => t('Copy the export text and paste it into another content type using the import function.'), |
|
178 | + ); |
|
179 | + // The calls to drupal_execute('content_field_edit_form') in |
|
180 | + // content_copy_export() affect the page title, |
|
181 | + drupal_set_title(t('Content types')); |
|
182 | + break; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | if ($step < 3) { // Omit submit button on the textarea block to display the export data. |
@@ -559,48 +559,48 @@ discard block |
||
559 | 559 | unset($edit['type_name'], $edit['submit'], $edit['delete'], $edit['form_id'], $edit['previous_field']); |
560 | 560 | } |
561 | 561 | switch ($form_id) { |
562 | - case 'node_type_form': |
|
563 | - $subs['type'] = $edit; |
|
564 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | - break; |
|
566 | - |
|
567 | - case 'fieldgroup_group_edit_form': |
|
568 | - $subs['groups'][] = $edit; |
|
569 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | - break; |
|
571 | - |
|
572 | - default: |
|
573 | - if (isset($edit['field_widget_type'])) { |
|
574 | - $tmp = explode('-', $edit['field_widget_type']); |
|
575 | - $field_name = $tmp[0]; |
|
576 | - } |
|
577 | - else { |
|
578 | - $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
|
579 | - } |
|
562 | + case 'node_type_form': |
|
563 | + $subs['type'] = $edit; |
|
564 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
565 | + break; |
|
566 | + |
|
567 | + case 'fieldgroup_group_edit_form': |
|
568 | + $subs['groups'][] = $edit; |
|
569 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
570 | + break; |
|
571 | + |
|
572 | + default: |
|
573 | + if (isset($edit['field_widget_type'])) { |
|
574 | + $tmp = explode('-', $edit['field_widget_type']); |
|
575 | + $field_name = $tmp[0]; |
|
576 | + } |
|
577 | + else { |
|
578 | + $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
|
579 | + } |
|
580 | 580 | |
581 | - // The display settings are being fetched directly from the DB. During import, |
|
582 | - // we'll re-insert the data directly as well. |
|
583 | - // |
|
584 | - $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | - $row_info = db_fetch_array(db_query($query, $field_name)); |
|
586 | - |
|
587 | - // If an error occurs, notify the user. |
|
588 | - if ($db_err = db_error()) { |
|
589 | - drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array( |
|
590 | - '%field_name' => $field_name, |
|
591 | - '%db_err' => $db_err |
|
592 | - ))); |
|
593 | - } |
|
594 | - else { |
|
595 | - // The db fetch occurred successfully, unserialize the data blob and |
|
596 | - // insert it into a new "display_settings" field of the data. |
|
597 | - if ($display_settings = unserialize($row_info['display_settings'])) { |
|
598 | - $edit['display_settings'] = $display_settings; |
|
599 | - } |
|
581 | + // The display settings are being fetched directly from the DB. During import, |
|
582 | + // we'll re-insert the data directly as well. |
|
583 | + // |
|
584 | + $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
585 | + $row_info = db_fetch_array(db_query($query, $field_name)); |
|
586 | + |
|
587 | + // If an error occurs, notify the user. |
|
588 | + if ($db_err = db_error()) { |
|
589 | + drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array( |
|
590 | + '%field_name' => $field_name, |
|
591 | + '%db_err' => $db_err |
|
592 | + ))); |
|
593 | + } |
|
594 | + else { |
|
595 | + // The db fetch occurred successfully, unserialize the data blob and |
|
596 | + // insert it into a new "display_settings" field of the data. |
|
597 | + if ($display_settings = unserialize($row_info['display_settings'])) { |
|
598 | + $edit['display_settings'] = $display_settings; |
|
600 | 599 | } |
601 | - $subs['fields'][] = $edit; |
|
602 | - $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | - break; |
|
600 | + } |
|
601 | + $subs['fields'][] = $edit; |
|
602 | + $GLOBALS['content_copy']['count'] += sizeof($edit) + 5; |
|
603 | + break; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | $GLOBALS['content_copy']['submissions'] = $subs; |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * A form to export field definitions. |
70 | 70 | */ |
71 | 71 | function content_copy_export_form(&$form_state) { |
72 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
73 | - include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
72 | + include_once('./'.drupal_get_path('module', 'content').'/includes/content.admin.inc'); |
|
73 | + include_once('./'.drupal_get_path('module', 'node').'/content_types.inc'); |
|
74 | 74 | |
75 | 75 | $form_values = isset($form_state['values']) ? $form_state['values'] : array(); |
76 | 76 | $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | switch ($step) { |
100 | 100 | case 1: // Select a content type. |
101 | - $types = content_copy_types(); |
|
101 | + $types = content_copy_types(); |
|
102 | 102 | $form['type_name'] = array( |
103 | 103 | '#title' => t('Types'), |
104 | 104 | '#type' => 'radios', |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | $output = content_copy_get_macro(); |
264 | 264 | |
265 | 265 | // Add weights of non-CCK fields. |
266 | - if ($extra = variable_get('content_extra_weights_'. $form_values['type_name'], array())) { |
|
267 | - $output .= "\$content['extra'] = ". var_export((array) $extra, TRUE) .";\n"; |
|
266 | + if ($extra = variable_get('content_extra_weights_'.$form_values['type_name'], array())) { |
|
267 | + $output .= "\$content['extra'] = ".var_export((array)$extra, TRUE).";\n"; |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | return $output; |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | * } |
295 | 295 | */ |
296 | 296 | function content_copy_import_form(&$form_state, $type_name = '') { |
297 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc'); |
|
298 | - include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc'); |
|
297 | + include_once('./'.drupal_get_path('module', 'content').'/includes/content.admin.inc'); |
|
298 | + include_once('./'.drupal_get_path('module', 'node').'/content_types.inc'); |
|
299 | 299 | |
300 | 300 | $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.'); |
301 | 301 | $form['type_name'] = array( |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | if (isset($_REQUEST['type_name'])) { |
323 | 323 | $form['type_name']['#default_value'] = $_REQUEST['type_name']; |
324 | 324 | } |
325 | - $form['#prefix'] .= '<p class="error">'. t('A file has been pre-loaded for import.') .'</p>'; |
|
325 | + $form['#prefix'] .= '<p class="error">'.t('A file has been pre-loaded for import.').'</p>'; |
|
326 | 326 | } |
327 | 327 | return $form; |
328 | 328 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | // If there are groups in the import, make sure the fieldgroup module is enabled. |
374 | 374 | $imported_groups = array(); |
375 | 375 | if (isset($content['groups']) && module_exists('fieldgroup')) { |
376 | - $imported_groups = (array) $content['groups']; |
|
376 | + $imported_groups = (array)$content['groups']; |
|
377 | 377 | } |
378 | 378 | elseif (isset($content['groups']) && is_array($content['groups'])) { |
379 | 379 | $not_enabled[] = 'fieldgroup'; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | // Create the content type, if requested. |
420 | 420 | if ($form_values['type_name'] == '<create>') { |
421 | 421 | |
422 | - $type = (object) $imported_type; |
|
422 | + $type = (object)$imported_type; |
|
423 | 423 | $values = $imported_type; |
424 | 424 | // Prevent a warning in node/content_types.inc |
425 | 425 | $type->has_title = TRUE; |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | |
459 | 459 | // Make sure the field doesn't already exist in the type. |
460 | 460 | // If so, do nothing, fields can't be duplicated within a content type. |
461 | - $field_name = $field['field_name']; |
|
461 | + $field_name = $field['field_name']; |
|
462 | 462 | |
463 | 463 | // Might need to overwrite the content type name if a new type was created. |
464 | 464 | $field['type_name'] = $type_name; |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | // Import weights of non-CCK fields. |
494 | 494 | if (isset($content['extra'])) { |
495 | - variable_set('content_extra_weights_'. $type_name, $content['extra']); |
|
495 | + variable_set('content_extra_weights_'.$type_name, $content['extra']); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | $types = array(); |
539 | 539 | $content_info = _content_type_info(); |
540 | 540 | foreach ($content_info['content types'] as $type_name => $val) { |
541 | - $types[$type_name] = check_plain($val['name']) .' ('. $type_name .')'; |
|
541 | + $types[$type_name] = check_plain($val['name']).' ('.$type_name.')'; |
|
542 | 542 | } |
543 | 543 | return $types; |
544 | 544 | } |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | // The display settings are being fetched directly from the DB. During import, |
582 | 582 | // we'll re-insert the data directly as well. |
583 | 583 | // |
584 | - $query = 'SELECT display_settings FROM {'. content_instance_tablename() .'} WHERE field_name = \'%s\''; |
|
584 | + $query = 'SELECT display_settings FROM {'.content_instance_tablename().'} WHERE field_name = \'%s\''; |
|
585 | 585 | $row_info = db_fetch_array(db_query($query, $field_name)); |
586 | 586 | |
587 | 587 | // If an error occurs, notify the user. |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | $string = ""; |
615 | 615 | if (array_key_exists('submissions', $GLOBALS['content_copy'])) { |
616 | 616 | foreach ($GLOBALS['content_copy']['submissions'] as $form_type => $form) { |
617 | - $string .= "\$content['$form_type'] = ". var_export((array) $form, TRUE) .";\n"; |
|
617 | + $string .= "\$content['$form_type'] = ".var_export((array)$form, TRUE).";\n"; |
|
618 | 618 | } |
619 | 619 | return $string; |
620 | 620 | } |
@@ -374,8 +374,7 @@ discard block |
||
374 | 374 | $imported_groups = array(); |
375 | 375 | if (isset($content['groups']) && module_exists('fieldgroup')) { |
376 | 376 | $imported_groups = (array) $content['groups']; |
377 | - } |
|
378 | - elseif (isset($content['groups']) && is_array($content['groups'])) { |
|
377 | + } elseif (isset($content['groups']) && is_array($content['groups'])) { |
|
379 | 378 | $not_enabled[] = 'fieldgroup'; |
380 | 379 | } |
381 | 380 | |
@@ -384,8 +383,7 @@ discard block |
||
384 | 383 | $field = content_field_instance_collapse($import); |
385 | 384 | if (empty($field['module']) || empty($field['widget_module'])) { |
386 | 385 | $not_enabled[] = $field['field_name']; |
387 | - } |
|
388 | - else { |
|
386 | + } else { |
|
389 | 387 | if (!module_exists($field['module'])) { |
390 | 388 | $not_enabled[] = $field['module']; |
391 | 389 | } |
@@ -466,8 +464,7 @@ discard block |
||
466 | 464 | if (!empty($field['field_name']) && isset($content_info['content types'][$type_name]['fields'][$field_name])) { |
467 | 465 | drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array( |
468 | 466 | '%field_label' => $field['label'], '%field_name' => $field_name, '%type' => $type_label))); |
469 | - } |
|
470 | - else { |
|
467 | + } else { |
|
471 | 468 | $field = content_field_instance_create($field, FALSE); |
472 | 469 | $rebuild = TRUE; |
473 | 470 | drupal_set_message(t('The field %field_label (%field_name) was added to the content type %type.', array( |
@@ -573,8 +570,7 @@ discard block |
||
573 | 570 | if (isset($edit['field_widget_type'])) { |
574 | 571 | $tmp = explode('-', $edit['field_widget_type']); |
575 | 572 | $field_name = $tmp[0]; |
576 | - } |
|
577 | - else { |
|
573 | + } else { |
|
578 | 574 | $field_name = isset($edit['field_name']) ? $edit['field_name'] : ''; |
579 | 575 | } |
580 | 576 | |
@@ -590,8 +586,7 @@ discard block |
||
590 | 586 | '%field_name' => $field_name, |
591 | 587 | '%db_err' => $db_err |
592 | 588 | ))); |
593 | - } |
|
594 | - else { |
|
589 | + } else { |
|
595 | 590 | // The db fetch occurred successfully, unserialize the data blob and |
596 | 591 | // insert it into a new "display_settings" field of the data. |
597 | 592 | if ($display_settings = unserialize($row_info['display_settings'])) { |
@@ -788,7 +788,7 @@ |
||
788 | 788 | * @param $ids |
789 | 789 | * Optional node ids to lookup (the $string and $match arguments will be |
790 | 790 | * ignored). |
791 | - * @param $limit |
|
791 | + * @param integer $limit |
|
792 | 792 | * If non-zero, limit the size of the result set. |
793 | 793 | * |
794 | 794 | * @return |
@@ -10,230 +10,230 @@ discard block |
||
10 | 10 | * Implementation of hook_menu(). |
11 | 11 | */ |
12 | 12 | function nodereference_menu() { |
13 | - $items = array(); |
|
14 | - $items['nodereference/autocomplete'] = array( |
|
13 | + $items = array(); |
|
14 | + $items['nodereference/autocomplete'] = array( |
|
15 | 15 | 'title' => 'Nodereference autocomplete', |
16 | 16 | 'page callback' => 'nodereference_autocomplete', |
17 | 17 | 'access callback' => 'nodereference_autocomplete_access', |
18 | 18 | 'access arguments' => array(2), |
19 | 19 | 'type' => MENU_CALLBACK |
20 | - ); |
|
21 | - return $items; |
|
20 | + ); |
|
21 | + return $items; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Implementation of hook_theme(). |
26 | 26 | */ |
27 | 27 | function nodereference_theme() { |
28 | - return array( |
|
28 | + return array( |
|
29 | 29 | 'nodereference_select' => array( |
30 | - 'arguments' => array('element' => NULL), |
|
30 | + 'arguments' => array('element' => NULL), |
|
31 | 31 | ), |
32 | 32 | 'nodereference_buttons' => array( |
33 | - 'arguments' => array('element' => NULL), |
|
33 | + 'arguments' => array('element' => NULL), |
|
34 | 34 | ), |
35 | 35 | 'nodereference_autocomplete' => array( |
36 | - 'arguments' => array('element' => NULL), |
|
36 | + 'arguments' => array('element' => NULL), |
|
37 | 37 | ), |
38 | 38 | 'nodereference_formatter_default' => array( |
39 | - 'arguments' => array('element'), |
|
39 | + 'arguments' => array('element'), |
|
40 | 40 | ), |
41 | 41 | 'nodereference_formatter_plain' => array( |
42 | - 'arguments' => array('element'), |
|
42 | + 'arguments' => array('element'), |
|
43 | 43 | ), |
44 | 44 | 'nodereference_formatter_full' => array( |
45 | - 'arguments' => array('element'), |
|
46 | - 'function' => 'theme_nodereference_formatter_full_teaser', |
|
45 | + 'arguments' => array('element'), |
|
46 | + 'function' => 'theme_nodereference_formatter_full_teaser', |
|
47 | 47 | ), |
48 | 48 | 'nodereference_formatter_teaser' => array( |
49 | - 'arguments' => array('element'), |
|
50 | - 'function' => 'theme_nodereference_formatter_full_teaser', |
|
49 | + 'arguments' => array('element'), |
|
50 | + 'function' => 'theme_nodereference_formatter_full_teaser', |
|
51 | 51 | ), |
52 | - ); |
|
52 | + ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Implementaion of hook_ctools_plugin_directory(). |
57 | 57 | */ |
58 | 58 | function nodereference_ctools_plugin_directory($module, $plugin) { |
59 | - if ($module == 'ctools' && $plugin == 'relationships') { |
|
59 | + if ($module == 'ctools' && $plugin == 'relationships') { |
|
60 | 60 | return 'panels/' . $plugin; |
61 | - } |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Implementation of hook_field_info(). |
66 | 66 | */ |
67 | 67 | function nodereference_field_info() { |
68 | - return array( |
|
68 | + return array( |
|
69 | 69 | 'nodereference' => array( |
70 | - 'label' => t('Node reference'), |
|
71 | - 'description' => t('Store the ID of a related node as an integer value.'), |
|
70 | + 'label' => t('Node reference'), |
|
71 | + 'description' => t('Store the ID of a related node as an integer value.'), |
|
72 | 72 | // 'content_icon' => 'icon_content_noderef.png', |
73 | 73 | ), |
74 | - ); |
|
74 | + ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Implementation of hook_field_settings(). |
79 | 79 | */ |
80 | 80 | function nodereference_field_settings($op, $field) { |
81 | - switch ($op) { |
|
81 | + switch ($op) { |
|
82 | 82 | case 'form': |
83 | 83 | $form = array(); |
84 | - $form['referenceable_types'] = array( |
|
84 | + $form['referenceable_types'] = array( |
|
85 | 85 | '#type' => 'checkboxes', |
86 | 86 | '#title' => t('Content types that can be referenced'), |
87 | 87 | '#multiple' => TRUE, |
88 | 88 | '#default_value' => is_array($field['referenceable_types']) ? $field['referenceable_types'] : array(), |
89 | 89 | '#options' => array_map('check_plain', node_get_types('names')), |
90 | - ); |
|
91 | - if (module_exists('views')) { |
|
90 | + ); |
|
91 | + if (module_exists('views')) { |
|
92 | 92 | $views = array('--' => '--'); |
93 | 93 | $all_views = views_get_all_views(); |
94 | 94 | foreach ($all_views as $view) { |
95 | - // Only 'node' views that have fields will work for our purpose. |
|
96 | - if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) { |
|
95 | + // Only 'node' views that have fields will work for our purpose. |
|
96 | + if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) { |
|
97 | 97 | if ($view->type == 'Default') { |
98 | - $views[t('Default Views')][$view->name] = $view->name; |
|
98 | + $views[t('Default Views')][$view->name] = $view->name; |
|
99 | 99 | } |
100 | 100 | else { |
101 | - $views[t('Existing Views')][$view->name] = $view->name; |
|
101 | + $views[t('Existing Views')][$view->name] = $view->name; |
|
102 | + } |
|
102 | 103 | } |
103 | - } |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $form['advanced'] = array( |
107 | - '#type' => 'fieldset', |
|
108 | - '#title' => t('Advanced - Nodes that can be referenced (View)'), |
|
109 | - '#collapsible' => TRUE, |
|
110 | - '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
111 | - ); |
|
107 | + '#type' => 'fieldset', |
|
108 | + '#title' => t('Advanced - Nodes that can be referenced (View)'), |
|
109 | + '#collapsible' => TRUE, |
|
110 | + '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
111 | + ); |
|
112 | 112 | if (count($views) > 1) { |
113 | - $form['advanced']['advanced_view'] = array( |
|
113 | + $form['advanced']['advanced_view'] = array( |
|
114 | 114 | '#type' => 'select', |
115 | 115 | '#title' => t('View used to select the nodes'), |
116 | 116 | '#options' => $views, |
117 | 117 | '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
118 | 118 | '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') . |
119 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
120 | - ); |
|
121 | - $form['advanced']['advanced_view_args'] = array( |
|
119 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
120 | + ); |
|
121 | + $form['advanced']['advanced_view_args'] = array( |
|
122 | 122 | '#type' => 'textfield', |
123 | 123 | '#title' => t('View arguments'), |
124 | 124 | '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
125 | 125 | '#required' => FALSE, |
126 | 126 | '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
127 | - ); |
|
127 | + ); |
|
128 | 128 | } |
129 | 129 | else { |
130 | - $form['advanced']['no_view_help'] = array( |
|
130 | + $form['advanced']['no_view_help'] = array( |
|
131 | 131 | '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
132 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
133 | - ); |
|
132 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
133 | + ); |
|
134 | 134 | } |
135 | - } |
|
136 | - return $form; |
|
135 | + } |
|
136 | + return $form; |
|
137 | 137 | |
138 | 138 | case 'save': |
139 | 139 | $settings = array('referenceable_types'); |
140 | - if (module_exists('views')) { |
|
140 | + if (module_exists('views')) { |
|
141 | 141 | $settings[] = 'advanced_view'; |
142 | 142 | $settings[] = 'advanced_view_args'; |
143 | - } |
|
144 | - return $settings; |
|
143 | + } |
|
144 | + return $settings; |
|
145 | 145 | |
146 | 146 | case 'database columns': |
147 | 147 | $columns = array( |
148 | 148 | 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
149 | - ); |
|
150 | - return $columns; |
|
149 | + ); |
|
150 | + return $columns; |
|
151 | 151 | |
152 | 152 | case 'views data': |
153 | 153 | $data = content_views_field_views_data($field); |
154 | - $db_info = content_database_info($field); |
|
155 | - $table_alias = content_views_tablename($field); |
|
154 | + $db_info = content_database_info($field); |
|
155 | + $table_alias = content_views_tablename($field); |
|
156 | 156 | |
157 | - // Filter: swap the handler to the 'in' operator. |
|
158 | - $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
159 | - // Argument: use node.title for summaries. |
|
160 | - $data["node_$table_alias"]['table']['join']['node'] = array( |
|
157 | + // Filter: swap the handler to the 'in' operator. |
|
158 | + $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
159 | + // Argument: use node.title for summaries. |
|
160 | + $data["node_$table_alias"]['table']['join']['node'] = array( |
|
161 | 161 | 'table' => 'node', |
162 | 162 | 'field' => 'nid', |
163 | 163 | 'left_table' => $table_alias, |
164 | 164 | 'left_field' => $field['field_name'] .'_nid', |
165 | - ); |
|
166 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title'; |
|
169 | - // Relationship: add a relationship for related node. |
|
170 | - $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array( |
|
165 | + ); |
|
166 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title'; |
|
169 | + // Relationship: add a relationship for related node. |
|
170 | + $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array( |
|
171 | 171 | 'base' => 'node', |
172 | 172 | 'field' => $db_info['columns']['nid']['column'], |
173 | 173 | 'handler' => 'content_handler_relationship', |
174 | 174 | 'label' => t($field['widget']['label']), |
175 | 175 | 'content_field_name' => $field['field_name'], |
176 | - ); |
|
177 | - return $data; |
|
178 | - } |
|
176 | + ); |
|
177 | + return $data; |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Implementation of hook_field(). |
183 | 183 | */ |
184 | 184 | function nodereference_field($op, &$node, $field, &$items, $teaser, $page) { |
185 | - static $sanitized_nodes = array(); |
|
185 | + static $sanitized_nodes = array(); |
|
186 | 186 | |
187 | - switch ($op) { |
|
187 | + switch ($op) { |
|
188 | 188 | // When preparing a translation, load any translations of existing references. |
189 | 189 | case 'prepare translation': |
190 | 190 | $addition = array(); |
191 | - $addition[$field['field_name']] = array(); |
|
192 | - if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) { |
|
191 | + $addition[$field['field_name']] = array(); |
|
192 | + if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) { |
|
193 | 193 | foreach ($node->translation_source->$field['field_name'] as $key => $reference) { |
194 | - $reference_node = node_load($reference['nid']); |
|
195 | - // Test if the referenced node type is translatable and, if so, |
|
196 | - // load translations if the reference is not for the current language. |
|
197 | - // We can assume the translation module is present because it invokes 'prepare translation'. |
|
198 | - if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) { |
|
194 | + $reference_node = node_load($reference['nid']); |
|
195 | + // Test if the referenced node type is translatable and, if so, |
|
196 | + // load translations if the reference is not for the current language. |
|
197 | + // We can assume the translation module is present because it invokes 'prepare translation'. |
|
198 | + if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) { |
|
199 | 199 | // If there is a translation for the current language, use it. |
200 | 200 | $addition[$field['field_name']][] = array( |
201 | - 'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'], |
|
201 | + 'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'], |
|
202 | 202 | ); |
203 | - } |
|
203 | + } |
|
204 | + } |
|
204 | 205 | } |
205 | - } |
|
206 | - return $addition; |
|
206 | + return $addition; |
|
207 | 207 | |
208 | 208 | case 'validate': |
209 | 209 | // Extract nids to check. |
210 | 210 | $ids = array(); |
211 | - foreach ($items as $delta => $item) { |
|
211 | + foreach ($items as $delta => $item) { |
|
212 | 212 | if (is_array($item) && !empty($item['nid'])) { |
213 | - if (is_numeric($item['nid'])) { |
|
213 | + if (is_numeric($item['nid'])) { |
|
214 | 214 | $ids[] = $item['nid']; |
215 | - } |
|
216 | - else { |
|
215 | + } |
|
216 | + else { |
|
217 | 217 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
218 | 218 | if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
219 | 219 | form_set_error($error_element, t("%name: invalid input.", array('%name' => t($field['widget']['label'])))); |
220 | - } |
|
220 | + } |
|
221 | + } |
|
221 | 222 | } |
222 | - } |
|
223 | - // Prevent performance hog if there are no ids to check. |
|
224 | - if ($ids) { |
|
223 | + // Prevent performance hog if there are no ids to check. |
|
224 | + if ($ids) { |
|
225 | 225 | $refs = _nodereference_potential_references($field, '', NULL, $ids); |
226 | 226 | foreach ($items as $delta => $item) { |
227 | - if (is_array($item)) { |
|
227 | + if (is_array($item)) { |
|
228 | 228 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
229 | 229 | if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
230 | 230 | if (!empty($item['nid']) && !isset($refs[$item['nid']])) { |
231 | - form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label'])))); |
|
231 | + form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label'])))); |
|
232 | 232 | } |
233 | - } |
|
233 | + } |
|
234 | + } |
|
234 | 235 | } |
235 | - } |
|
236 | - return $items; |
|
236 | + return $items; |
|
237 | 237 | |
238 | 238 | case 'sanitize': |
239 | 239 | // We can't just check the node is 'referenceable', because Views-mode |
@@ -241,133 +241,133 @@ discard block |
||
241 | 241 | |
242 | 242 | // Extract nids to check. |
243 | 243 | $ids = array(); |
244 | - foreach ($items as $delta => $item) { |
|
244 | + foreach ($items as $delta => $item) { |
|
245 | 245 | if (is_array($item)) { |
246 | - // Default to 'non accessible'. |
|
247 | - $items[$delta]['safe'] = array(); |
|
248 | - if (!empty($item['nid']) && is_numeric($item['nid'])) { |
|
246 | + // Default to 'non accessible'. |
|
247 | + $items[$delta]['safe'] = array(); |
|
248 | + if (!empty($item['nid']) && is_numeric($item['nid'])) { |
|
249 | 249 | $ids[] = $item['nid']; |
250 | - } |
|
250 | + } |
|
251 | + } |
|
251 | 252 | } |
252 | - } |
|
253 | - if ($ids) { |
|
253 | + if ($ids) { |
|
254 | 254 | // Load information about nids that we haven't already loaded during |
255 | 255 | // this page request. |
256 | 256 | $missing_ids = array_diff($ids, array_keys($sanitized_nodes)); |
257 | 257 | if (!empty($missing_ids)) { |
258 | - $where = array('n.nid in ('. db_placeholders($missing_ids) . ')'); |
|
259 | - if (!user_access('administer nodes')) { |
|
258 | + $where = array('n.nid in ('. db_placeholders($missing_ids) . ')'); |
|
259 | + if (!user_access('administer nodes')) { |
|
260 | 260 | $where[] = 'n.status = 1'; |
261 | - } |
|
262 | - $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids); |
|
263 | - while ($row = db_fetch_array($result)) { |
|
261 | + } |
|
262 | + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids); |
|
263 | + while ($row = db_fetch_array($result)) { |
|
264 | 264 | $sanitized_nodes[$row['nid']] = $row; |
265 | - } |
|
265 | + } |
|
266 | 266 | } |
267 | 267 | foreach ($items as $delta => $item) { |
268 | - if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) { |
|
268 | + if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) { |
|
269 | 269 | $items[$delta]['safe'] = $sanitized_nodes[$item['nid']]; |
270 | - } |
|
270 | + } |
|
271 | + } |
|
271 | 272 | } |
272 | - } |
|
273 | - return $items; |
|
274 | - } |
|
273 | + return $items; |
|
274 | + } |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Implementation of hook_content_is_empty(). |
279 | 279 | */ |
280 | 280 | function nodereference_content_is_empty($item, $field) { |
281 | - if (empty($item['nid'])) { |
|
281 | + if (empty($item['nid'])) { |
|
282 | 282 | return TRUE; |
283 | - } |
|
284 | - return FALSE; |
|
283 | + } |
|
284 | + return FALSE; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Implementation of hook_field_formatter_info(). |
289 | 289 | */ |
290 | 290 | function nodereference_field_formatter_info() { |
291 | - return array( |
|
291 | + return array( |
|
292 | 292 | 'default' => array( |
293 | - 'label' => t('Title (link)'), |
|
294 | - 'field types' => array('nodereference'), |
|
295 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
293 | + 'label' => t('Title (link)'), |
|
294 | + 'field types' => array('nodereference'), |
|
295 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
296 | 296 | ), |
297 | 297 | 'plain' => array( |
298 | - 'label' => t('Title (no link)'), |
|
299 | - 'field types' => array('nodereference'), |
|
300 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
298 | + 'label' => t('Title (no link)'), |
|
299 | + 'field types' => array('nodereference'), |
|
300 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
301 | 301 | ), |
302 | 302 | 'full' => array( |
303 | - 'label' => t('Full node'), |
|
304 | - 'field types' => array('nodereference'), |
|
305 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
303 | + 'label' => t('Full node'), |
|
304 | + 'field types' => array('nodereference'), |
|
305 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
306 | 306 | ), |
307 | 307 | 'teaser' => array( |
308 | - 'label' => t('Teaser'), |
|
309 | - 'field types' => array('nodereference'), |
|
310 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
308 | + 'label' => t('Teaser'), |
|
309 | + 'field types' => array('nodereference'), |
|
310 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
311 | 311 | ), |
312 | - ); |
|
312 | + ); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Theme function for 'default' nodereference field formatter. |
317 | 317 | */ |
318 | 318 | function theme_nodereference_formatter_default($element) { |
319 | - $output = ''; |
|
320 | - if (!empty($element['#item']['safe']['nid'])) { |
|
319 | + $output = ''; |
|
320 | + if (!empty($element['#item']['safe']['nid'])) { |
|
321 | 321 | $output = l($element['#item']['safe']['title'], 'node/'. $element['#item']['safe']['nid']); |
322 | 322 | if (!$element['#item']['safe']['status']) { |
323 | - $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
323 | + $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
324 | 324 | } |
325 | - } |
|
326 | - return $output; |
|
325 | + } |
|
326 | + return $output; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | 330 | * Theme function for 'plain' nodereference field formatter. |
331 | 331 | */ |
332 | 332 | function theme_nodereference_formatter_plain($element) { |
333 | - $output = ''; |
|
334 | - if (!empty($element['#item']['safe']['nid'])) { |
|
333 | + $output = ''; |
|
334 | + if (!empty($element['#item']['safe']['nid'])) { |
|
335 | 335 | $output = check_plain($element['#item']['safe']['title']); |
336 | 336 | if (!$element['#item']['safe']['status']) { |
337 | - $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
337 | + $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
338 | + } |
|
338 | 339 | } |
339 | - } |
|
340 | - return $output; |
|
340 | + return $output; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | 344 | * Proxy theme function for 'full' and 'teaser' nodereference field formatters. |
345 | 345 | */ |
346 | 346 | function theme_nodereference_formatter_full_teaser($element) { |
347 | - static $recursion_queue = array(); |
|
348 | - $output = ''; |
|
349 | - if (!empty($element['#item']['safe']['nid'])) { |
|
347 | + static $recursion_queue = array(); |
|
348 | + $output = ''; |
|
349 | + if (!empty($element['#item']['safe']['nid'])) { |
|
350 | 350 | $nid = $element['#item']['safe']['nid']; |
351 | 351 | $node = $element['#node']; |
352 | 352 | $field = content_fields($element['#field_name'], $element['#type_name']); |
353 | 353 | // If no 'referencing node' is set, we are starting a new 'reference thread' |
354 | 354 | if (!isset($node->referencing_node)) { |
355 | - $recursion_queue = array(); |
|
355 | + $recursion_queue = array(); |
|
356 | 356 | } |
357 | 357 | $recursion_queue[] = $node->nid; |
358 | 358 | if (in_array($nid, $recursion_queue)) { |
359 | - // Prevent infinite recursion caused by reference cycles: |
|
360 | - // if the node has already been rendered earlier in this 'thread', |
|
361 | - // we fall back to 'default' (node title) formatter. |
|
362 | - return theme('nodereference_formatter_default', $element); |
|
359 | + // Prevent infinite recursion caused by reference cycles: |
|
360 | + // if the node has already been rendered earlier in this 'thread', |
|
361 | + // we fall back to 'default' (node title) formatter. |
|
362 | + return theme('nodereference_formatter_default', $element); |
|
363 | 363 | } |
364 | 364 | if ($referenced_node = node_load($nid)) { |
365 | - $referenced_node->referencing_node = $node; |
|
366 | - $referenced_node->referencing_field = $field; |
|
367 | - $output = node_view($referenced_node, $element['#formatter'] == 'teaser'); |
|
365 | + $referenced_node->referencing_node = $node; |
|
366 | + $referenced_node->referencing_field = $field; |
|
367 | + $output = node_view($referenced_node, $element['#formatter'] == 'teaser'); |
|
368 | + } |
|
368 | 369 | } |
369 | - } |
|
370 | - return $output; |
|
370 | + return $output; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -376,12 +376,12 @@ discard block |
||
376 | 376 | * Store node titles collected in the curent request. |
377 | 377 | */ |
378 | 378 | function _nodereference_titles($nid, $known_title = NULL) { |
379 | - static $titles = array(); |
|
380 | - if (!isset($titles[$nid])) { |
|
379 | + static $titles = array(); |
|
380 | + if (!isset($titles[$nid])) { |
|
381 | 381 | $title = $known_title ? $known_title : db_result(db_query(db_rewrite_sql("SELECT n.title FROM {node} n WHERE n.nid=%d"), $nid)); |
382 | 382 | $titles[$nid] = $title ? $title : ''; |
383 | - } |
|
384 | - return $titles[$nid]; |
|
383 | + } |
|
384 | + return $titles[$nid]; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -399,32 +399,32 @@ discard block |
||
399 | 399 | * differently. |
400 | 400 | */ |
401 | 401 | function nodereference_widget_info() { |
402 | - return array( |
|
402 | + return array( |
|
403 | 403 | 'nodereference_select' => array( |
404 | - 'label' => t('Select list'), |
|
405 | - 'field types' => array('nodereference'), |
|
406 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
407 | - 'callbacks' => array( |
|
404 | + 'label' => t('Select list'), |
|
405 | + 'field types' => array('nodereference'), |
|
406 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
407 | + 'callbacks' => array( |
|
408 | 408 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
409 | - ), |
|
409 | + ), |
|
410 | 410 | ), |
411 | 411 | 'nodereference_buttons' => array( |
412 | - 'label' => t('Check boxes/radio buttons'), |
|
413 | - 'field types' => array('nodereference'), |
|
414 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
415 | - 'callbacks' => array( |
|
412 | + 'label' => t('Check boxes/radio buttons'), |
|
413 | + 'field types' => array('nodereference'), |
|
414 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
415 | + 'callbacks' => array( |
|
416 | 416 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
417 | - ), |
|
417 | + ), |
|
418 | 418 | ), |
419 | 419 | 'nodereference_autocomplete' => array( |
420 | - 'label' => t('Autocomplete text field'), |
|
421 | - 'field types' => array('nodereference'), |
|
422 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
423 | - 'callbacks' => array( |
|
420 | + 'label' => t('Autocomplete text field'), |
|
421 | + 'field types' => array('nodereference'), |
|
422 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
423 | + 'callbacks' => array( |
|
424 | 424 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
425 | - ), |
|
425 | + ), |
|
426 | 426 | ), |
427 | - ); |
|
427 | + ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -440,23 +440,23 @@ discard block |
||
440 | 440 | * (see nodereference and userreference). |
441 | 441 | */ |
442 | 442 | function nodereference_elements() { |
443 | - return array( |
|
443 | + return array( |
|
444 | 444 | 'nodereference_select' => array( |
445 | - '#input' => TRUE, |
|
446 | - '#columns' => array('uid'), '#delta' => 0, |
|
447 | - '#process' => array('nodereference_select_process'), |
|
445 | + '#input' => TRUE, |
|
446 | + '#columns' => array('uid'), '#delta' => 0, |
|
447 | + '#process' => array('nodereference_select_process'), |
|
448 | 448 | ), |
449 | 449 | 'nodereference_buttons' => array( |
450 | - '#input' => TRUE, |
|
451 | - '#columns' => array('uid'), '#delta' => 0, |
|
452 | - '#process' => array('nodereference_buttons_process'), |
|
450 | + '#input' => TRUE, |
|
451 | + '#columns' => array('uid'), '#delta' => 0, |
|
452 | + '#process' => array('nodereference_buttons_process'), |
|
453 | 453 | ), |
454 | 454 | 'nodereference_autocomplete' => array( |
455 | - '#input' => TRUE, |
|
456 | - '#columns' => array('name'), '#delta' => 0, |
|
457 | - '#process' => array('nodereference_autocomplete_process'), |
|
458 | - '#autocomplete_path' => FALSE, |
|
459 | - ), |
|
455 | + '#input' => TRUE, |
|
456 | + '#columns' => array('name'), '#delta' => 0, |
|
457 | + '#process' => array('nodereference_autocomplete_process'), |
|
458 | + '#autocomplete_path' => FALSE, |
|
459 | + ), |
|
460 | 460 | ); |
461 | 461 | } |
462 | 462 | |
@@ -464,39 +464,39 @@ discard block |
||
464 | 464 | * Implementation of hook_widget_settings(). |
465 | 465 | */ |
466 | 466 | function nodereference_widget_settings($op, $widget) { |
467 | - switch ($op) { |
|
467 | + switch ($op) { |
|
468 | 468 | case 'form': |
469 | 469 | $form = array(); |
470 | - $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
471 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
472 | - if ($widget['type'] == 'nodereference_autocomplete') { |
|
470 | + $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
471 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
472 | + if ($widget['type'] == 'nodereference_autocomplete') { |
|
473 | 473 | $form['autocomplete_match'] = array( |
474 | - '#type' => 'select', |
|
475 | - '#title' => t('Autocomplete matching'), |
|
476 | - '#default_value' => $match, |
|
477 | - '#options' => array( |
|
474 | + '#type' => 'select', |
|
475 | + '#title' => t('Autocomplete matching'), |
|
476 | + '#default_value' => $match, |
|
477 | + '#options' => array( |
|
478 | 478 | 'starts_with' => t('Starts with'), |
479 | 479 | 'contains' => t('Contains'), |
480 | - ), |
|
481 | - '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'), |
|
480 | + ), |
|
481 | + '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'), |
|
482 | 482 | ); |
483 | 483 | $form['size'] = array( |
484 | - '#type' => 'textfield', |
|
485 | - '#title' => t('Size of textfield'), |
|
486 | - '#default_value' => $size, |
|
487 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
488 | - '#required' => TRUE, |
|
484 | + '#type' => 'textfield', |
|
485 | + '#title' => t('Size of textfield'), |
|
486 | + '#default_value' => $size, |
|
487 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
488 | + '#required' => TRUE, |
|
489 | 489 | ); |
490 | - } |
|
491 | - else { |
|
490 | + } |
|
491 | + else { |
|
492 | 492 | $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
493 | 493 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
494 | - } |
|
495 | - return $form; |
|
494 | + } |
|
495 | + return $form; |
|
496 | 496 | |
497 | 497 | case 'save': |
498 | 498 | return array('autocomplete_match', 'size'); |
499 | - } |
|
499 | + } |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -531,30 +531,30 @@ discard block |
||
531 | 531 | * the form item for a single element for this field |
532 | 532 | */ |
533 | 533 | function nodereference_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
534 | - switch ($field['widget']['type']) { |
|
534 | + switch ($field['widget']['type']) { |
|
535 | 535 | case 'nodereference_select': |
536 | 536 | $element = array( |
537 | 537 | '#type' => 'nodereference_select', |
538 | 538 | '#default_value' => $items, |
539 | - ); |
|
540 | - break; |
|
539 | + ); |
|
540 | + break; |
|
541 | 541 | |
542 | 542 | case 'nodereference_buttons': |
543 | 543 | $element = array( |
544 | 544 | '#type' => 'nodereference_buttons', |
545 | 545 | '#default_value' => $items, |
546 | - ); |
|
547 | - break; |
|
546 | + ); |
|
547 | + break; |
|
548 | 548 | |
549 | 549 | case 'nodereference_autocomplete': |
550 | 550 | $element = array( |
551 | 551 | '#type' => 'nodereference_autocomplete', |
552 | 552 | '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
553 | 553 | '#value_callback' => 'nodereference_autocomplete_value', |
554 | - ); |
|
555 | - break; |
|
556 | - } |
|
557 | - return $element; |
|
554 | + ); |
|
555 | + break; |
|
556 | + } |
|
557 | + return $element; |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -563,14 +563,14 @@ discard block |
||
563 | 563 | * Substitute in the node title for the node nid. |
564 | 564 | */ |
565 | 565 | function nodereference_autocomplete_value($element, $edit = FALSE) { |
566 | - $field_key = $element['#columns'][0]; |
|
567 | - if (!empty($element['#default_value'][$field_key])) { |
|
566 | + $field_key = $element['#columns'][0]; |
|
567 | + if (!empty($element['#default_value'][$field_key])) { |
|
568 | 568 | $nid = $element['#default_value'][$field_key]; |
569 | 569 | $value = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $nid)); |
570 | 570 | $value .= ' [nid:'. $nid .']'; |
571 | 571 | return array($field_key => $value); |
572 | - } |
|
573 | - return array($field_key => NULL); |
|
572 | + } |
|
573 | + return array($field_key => NULL); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -582,12 +582,12 @@ discard block |
||
582 | 582 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
583 | 583 | */ |
584 | 584 | function nodereference_select_process($element, $edit, $form_state, $form) { |
585 | - // The nodereference_select widget doesn't need to create its own |
|
586 | - // element, it can wrap around the optionwidgets_select element. |
|
587 | - // This will create a new, nested instance of the field. |
|
588 | - // Add a validation step where the value can be unwrapped. |
|
589 | - $field_key = $element['#columns'][0]; |
|
590 | - $element[$field_key] = array( |
|
585 | + // The nodereference_select widget doesn't need to create its own |
|
586 | + // element, it can wrap around the optionwidgets_select element. |
|
587 | + // This will create a new, nested instance of the field. |
|
588 | + // Add a validation step where the value can be unwrapped. |
|
589 | + $field_key = $element['#columns'][0]; |
|
590 | + $element[$field_key] = array( |
|
591 | 591 | '#type' => 'optionwidgets_select', |
592 | 592 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
593 | 593 | // The following values were set by the content module and need |
@@ -599,12 +599,12 @@ discard block |
||
599 | 599 | '#type_name' => $element['#type_name'], |
600 | 600 | '#delta' => $element['#delta'], |
601 | 601 | '#columns' => $element['#columns'], |
602 | - ); |
|
603 | - if (empty($element[$field_key]['#element_validate'])) { |
|
602 | + ); |
|
603 | + if (empty($element[$field_key]['#element_validate'])) { |
|
604 | 604 | $element[$field_key]['#element_validate'] = array(); |
605 | - } |
|
606 | - array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate'); |
|
607 | - return $element; |
|
605 | + } |
|
606 | + array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate'); |
|
607 | + return $element; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -616,12 +616,12 @@ discard block |
||
616 | 616 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
617 | 617 | */ |
618 | 618 | function nodereference_buttons_process($element, $edit, $form_state, $form) { |
619 | - // The nodereference_select widget doesn't need to create its own |
|
620 | - // element, it can wrap around the optionwidgets_select element. |
|
621 | - // This will create a new, nested instance of the field. |
|
622 | - // Add a validation step where the value can be unwrapped. |
|
623 | - $field_key = $element['#columns'][0]; |
|
624 | - $element[$field_key] = array( |
|
619 | + // The nodereference_select widget doesn't need to create its own |
|
620 | + // element, it can wrap around the optionwidgets_select element. |
|
621 | + // This will create a new, nested instance of the field. |
|
622 | + // Add a validation step where the value can be unwrapped. |
|
623 | + $field_key = $element['#columns'][0]; |
|
624 | + $element[$field_key] = array( |
|
625 | 625 | '#type' => 'optionwidgets_buttons', |
626 | 626 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
627 | 627 | // The following values were set by the content module and need |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | '#type_name' => $element['#type_name'], |
634 | 634 | '#delta' => $element['#delta'], |
635 | 635 | '#columns' => $element['#columns'], |
636 | - ); |
|
637 | - if (empty($element[$field_key]['#element_validate'])) { |
|
636 | + ); |
|
637 | + if (empty($element[$field_key]['#element_validate'])) { |
|
638 | 638 | $element[$field_key]['#element_validate'] = array(); |
639 | - } |
|
640 | - array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate'); |
|
641 | - return $element; |
|
639 | + } |
|
640 | + array_unshift($element[$field_key]['#element_validate'], 'nodereference_optionwidgets_validate'); |
|
641 | + return $element; |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
@@ -650,13 +650,13 @@ discard block |
||
650 | 650 | */ |
651 | 651 | function nodereference_autocomplete_process($element, $edit, $form_state, $form) { |
652 | 652 | |
653 | - // The nodereference autocomplete widget doesn't need to create its own |
|
654 | - // element, it can wrap around the text_textfield element and add an autocomplete |
|
655 | - // path and some extra processing to it. |
|
656 | - // Add a validation step where the value can be unwrapped. |
|
657 | - $field_key = $element['#columns'][0]; |
|
653 | + // The nodereference autocomplete widget doesn't need to create its own |
|
654 | + // element, it can wrap around the text_textfield element and add an autocomplete |
|
655 | + // path and some extra processing to it. |
|
656 | + // Add a validation step where the value can be unwrapped. |
|
657 | + $field_key = $element['#columns'][0]; |
|
658 | 658 | |
659 | - $element[$field_key] = array( |
|
659 | + $element[$field_key] = array( |
|
660 | 660 | '#type' => 'text_textfield', |
661 | 661 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
662 | 662 | '#autocomplete_path' => 'nodereference/autocomplete/'. $element['#field_name'], |
@@ -669,20 +669,20 @@ discard block |
||
669 | 669 | '#type_name' => $element['#type_name'], |
670 | 670 | '#delta' => $element['#delta'], |
671 | 671 | '#columns' => $element['#columns'], |
672 | - ); |
|
673 | - if (empty($element[$field_key]['#element_validate'])) { |
|
672 | + ); |
|
673 | + if (empty($element[$field_key]['#element_validate'])) { |
|
674 | 674 | $element[$field_key]['#element_validate'] = array(); |
675 | - } |
|
676 | - array_unshift($element[$field_key]['#element_validate'], 'nodereference_autocomplete_validate'); |
|
675 | + } |
|
676 | + array_unshift($element[$field_key]['#element_validate'], 'nodereference_autocomplete_validate'); |
|
677 | 677 | |
678 | - // Used so that hook_field('validate') knows where to flag an error. |
|
679 | - $element['_error_element'] = array( |
|
678 | + // Used so that hook_field('validate') knows where to flag an error. |
|
679 | + $element['_error_element'] = array( |
|
680 | 680 | '#type' => 'value', |
681 | 681 | // Wrapping the element around a text_textfield element creates a |
682 | 682 | // nested element, so the final id will look like 'field-name-0-nid-nid'. |
683 | 683 | '#value' => implode('][', array_merge($element['#parents'], array($field_key, $field_key))), |
684 | - ); |
|
685 | - return $element; |
|
684 | + ); |
|
685 | + return $element; |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
@@ -697,20 +697,20 @@ discard block |
||
697 | 697 | * like optionwidgets are using #element_validate to alter the value. |
698 | 698 | */ |
699 | 699 | function nodereference_optionwidgets_validate($element, &$form_state) { |
700 | - $field_key = $element['#columns'][0]; |
|
700 | + $field_key = $element['#columns'][0]; |
|
701 | 701 | |
702 | - $value = $form_state['values']; |
|
703 | - $new_parents = array(); |
|
704 | - foreach ($element['#parents'] as $parent) { |
|
702 | + $value = $form_state['values']; |
|
703 | + $new_parents = array(); |
|
704 | + foreach ($element['#parents'] as $parent) { |
|
705 | 705 | $value = $value[$parent]; |
706 | 706 | // Use === to be sure we get right results if parent is a zero (delta) value. |
707 | 707 | if ($parent === $field_key) { |
708 | - $element['#parents'] = $new_parents; |
|
709 | - form_set_value($element, $value, $form_state); |
|
710 | - break; |
|
708 | + $element['#parents'] = $new_parents; |
|
709 | + form_set_value($element, $value, $form_state); |
|
710 | + break; |
|
711 | 711 | } |
712 | 712 | $new_parents[] = $parent; |
713 | - } |
|
713 | + } |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
@@ -721,52 +721,52 @@ discard block |
||
721 | 721 | * back to its original location, 'field-name-0-nid'. |
722 | 722 | */ |
723 | 723 | function nodereference_autocomplete_validate($element, &$form_state) { |
724 | - $field_name = $element['#field_name']; |
|
725 | - $type_name = $element['#type_name']; |
|
726 | - $field = content_fields($field_name, $type_name); |
|
727 | - $field_key = $element['#columns'][0]; |
|
728 | - $delta = $element['#delta']; |
|
729 | - $value = $element['#value'][$field_key]; |
|
730 | - $nid = NULL; |
|
731 | - if (!empty($value)) { |
|
724 | + $field_name = $element['#field_name']; |
|
725 | + $type_name = $element['#type_name']; |
|
726 | + $field = content_fields($field_name, $type_name); |
|
727 | + $field_key = $element['#columns'][0]; |
|
728 | + $delta = $element['#delta']; |
|
729 | + $value = $element['#value'][$field_key]; |
|
730 | + $nid = NULL; |
|
731 | + if (!empty($value)) { |
|
732 | 732 | preg_match('/^(?:\s*|(.*) )?\[\s*nid\s*:\s*(\d+)\s*\]$/', $value, $matches); |
733 | 733 | if (!empty($matches)) { |
734 | - // Explicit [nid:n]. |
|
735 | - list(, $title, $nid) = $matches; |
|
736 | - if (!empty($title) && ($n = node_load($nid)) && trim($title) != trim($n->title)) { |
|
734 | + // Explicit [nid:n]. |
|
735 | + list(, $title, $nid) = $matches; |
|
736 | + if (!empty($title) && ($n = node_load($nid)) && trim($title) != trim($n->title)) { |
|
737 | 737 | form_error($element[$field_key], t('%name: title mismatch. Please check your selection.', array('%name' => t($field['widget']['label'])))); |
738 | - } |
|
738 | + } |
|
739 | 739 | } |
740 | 740 | else { |
741 | - // No explicit nid. |
|
742 | - $reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1); |
|
743 | - if (empty($reference)) { |
|
741 | + // No explicit nid. |
|
742 | + $reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1); |
|
743 | + if (empty($reference)) { |
|
744 | 744 | form_error($element[$field_key], t('%name: found no valid post with that title.', array('%name' => t($field['widget']['label'])))); |
745 | - } |
|
746 | - else { |
|
745 | + } |
|
746 | + else { |
|
747 | 747 | // TODO: |
748 | 748 | // the best thing would be to present the user with an additional form, |
749 | 749 | // allowing the user to choose between valid candidates with the same title |
750 | 750 | // ATM, we pick the first matching candidate... |
751 | 751 | $nid = key($reference); |
752 | - } |
|
752 | + } |
|
753 | 753 | } |
754 | - } |
|
755 | - form_set_value($element, $nid, $form_state); |
|
754 | + } |
|
755 | + form_set_value($element, $nid, $form_state); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | /** |
759 | 759 | * Implementation of hook_allowed_values(). |
760 | 760 | */ |
761 | 761 | function nodereference_allowed_values($field) { |
762 | - $references = _nodereference_potential_references($field); |
|
762 | + $references = _nodereference_potential_references($field); |
|
763 | 763 | |
764 | - $options = array(); |
|
765 | - foreach ($references as $key => $value) { |
|
764 | + $options = array(); |
|
765 | + foreach ($references as $key => $value) { |
|
766 | 766 | $options[$key] = $value['rendered']; |
767 | - } |
|
767 | + } |
|
768 | 768 | |
769 | - return $options; |
|
769 | + return $options; |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | /** |
@@ -802,26 +802,26 @@ discard block |
||
802 | 802 | * ) |
803 | 803 | */ |
804 | 804 | function _nodereference_potential_references($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
805 | - static $results = array(); |
|
805 | + static $results = array(); |
|
806 | 806 | |
807 | - // Create unique id for static cache. |
|
808 | - $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
809 | - if (!isset($results[$cid])) { |
|
807 | + // Create unique id for static cache. |
|
808 | + $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
809 | + if (!isset($results[$cid])) { |
|
810 | 810 | $references = FALSE; |
811 | 811 | if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') { |
812 | - $references = _nodereference_potential_references_views($field, $string, $match, $ids, $limit); |
|
812 | + $references = _nodereference_potential_references_views($field, $string, $match, $ids, $limit); |
|
813 | 813 | } |
814 | 814 | // If the view doesn't exist, we got FALSE, and fallback to the regular 'standard mode'. |
815 | 815 | |
816 | 816 | if ($references === FALSE) { |
817 | - $references = _nodereference_potential_references_standard($field, $string, $match, $ids, $limit); |
|
817 | + $references = _nodereference_potential_references_standard($field, $string, $match, $ids, $limit); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | // Store the results. |
821 | 821 | $results[$cid] = !empty($references) ? $references : array(); |
822 | - } |
|
822 | + } |
|
823 | 823 | |
824 | - return $results[$cid]; |
|
824 | + return $results[$cid]; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -829,9 +829,9 @@ discard block |
||
829 | 829 | * case of Views-defined referenceable nodes. |
830 | 830 | */ |
831 | 831 | function _nodereference_potential_references_views($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
832 | - $view_name = $field['advanced_view']; |
|
832 | + $view_name = $field['advanced_view']; |
|
833 | 833 | |
834 | - if ($view = views_get_view($view_name)) { |
|
834 | + if ($view = views_get_view($view_name)) { |
|
835 | 835 | // We add a display, and let it derive from the 'default' display. |
836 | 836 | // TODO: We should let the user pick a display in the fields settings - sort of requires AHAH... |
837 | 837 | $display = $view->add_display('content_references'); |
@@ -848,12 +848,12 @@ discard block |
||
848 | 848 | // Additional options to let content_plugin_display_references::query() |
849 | 849 | // narrow the results. |
850 | 850 | $options = array( |
851 | - 'table' => 'node', |
|
852 | - 'field_string' => 'title', |
|
853 | - 'string' => $string, |
|
854 | - 'match' => $match, |
|
855 | - 'field_id' => 'nid', |
|
856 | - 'ids' => $ids, |
|
851 | + 'table' => 'node', |
|
852 | + 'field_string' => 'title', |
|
853 | + 'string' => $string, |
|
854 | + 'match' => $match, |
|
855 | + 'field_id' => 'nid', |
|
856 | + 'ids' => $ids, |
|
857 | 857 | ); |
858 | 858 | $view->display_handler->set_option('content_options', $options); |
859 | 859 | |
@@ -866,26 +866,26 @@ discard block |
||
866 | 866 | |
867 | 867 | // Get arguments for the view. |
868 | 868 | if (!empty($field['advanced_view_args'])) { |
869 | - // TODO: Support Tokens using token.module ? |
|
870 | - $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
|
869 | + // TODO: Support Tokens using token.module ? |
|
870 | + $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
|
871 | 871 | } |
872 | 872 | else { |
873 | - $view_args = array(); |
|
873 | + $view_args = array(); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | // We do need title field, so add it if not present (unlikely, but...) |
877 | 877 | $fields = $view->get_items('field', $display); |
878 | 878 | if (!isset($fields['title'])) { |
879 | - $view->add_item($display, 'field', 'node', 'title'); |
|
879 | + $view->add_item($display, 'field', 'node', 'title'); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | // If not set, make all fields inline and define a separator. |
883 | 883 | $options = $view->display_handler->get_option('row_options'); |
884 | 884 | if (empty($options['inline'])) { |
885 | - $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display))); |
|
885 | + $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display))); |
|
886 | 886 | } |
887 | 887 | if (empty($options['separator'])) { |
888 | - $options['separator'] = '-'; |
|
888 | + $options['separator'] = '-'; |
|
889 | 889 | } |
890 | 890 | $view->display_handler->set_option('row_options', $options); |
891 | 891 | |
@@ -894,12 +894,12 @@ discard block |
||
894 | 894 | |
895 | 895 | // Get the results. |
896 | 896 | $result = $view->execute_display($display, $view_args); |
897 | - } |
|
898 | - else { |
|
897 | + } |
|
898 | + else { |
|
899 | 899 | $result = FALSE; |
900 | - } |
|
900 | + } |
|
901 | 901 | |
902 | - return $result; |
|
902 | + return $result; |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
@@ -907,50 +907,50 @@ discard block |
||
907 | 907 | * referenceable nodes defined by content types. |
908 | 908 | */ |
909 | 909 | function _nodereference_potential_references_standard($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
910 | - $related_types = array(); |
|
911 | - $where = array(); |
|
912 | - $args = array(); |
|
910 | + $related_types = array(); |
|
911 | + $where = array(); |
|
912 | + $args = array(); |
|
913 | 913 | |
914 | - if (is_array($field['referenceable_types'])) { |
|
914 | + if (is_array($field['referenceable_types'])) { |
|
915 | 915 | foreach (array_filter($field['referenceable_types']) as $related_type) { |
916 | - $related_types[] = "n.type = '%s'"; |
|
917 | - $args[] = $related_type; |
|
916 | + $related_types[] = "n.type = '%s'"; |
|
917 | + $args[] = $related_type; |
|
918 | + } |
|
918 | 919 | } |
919 | - } |
|
920 | 920 | |
921 | - $where[] = implode(' OR ', $related_types); |
|
921 | + $where[] = implode(' OR ', $related_types); |
|
922 | 922 | |
923 | - if (!count($related_types)) { |
|
923 | + if (!count($related_types)) { |
|
924 | 924 | return array(); |
925 | - } |
|
925 | + } |
|
926 | 926 | |
927 | - if ($string !== '') { |
|
927 | + if ($string !== '') { |
|
928 | 928 | $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE"; |
929 | 929 | $match_clauses = array( |
930 | - 'contains' => "$like '%%%s%%'", |
|
931 | - 'equals' => "= '%s'", |
|
932 | - 'starts_with' => "$like '%s%%'", |
|
930 | + 'contains' => "$like '%%%s%%'", |
|
931 | + 'equals' => "= '%s'", |
|
932 | + 'starts_with' => "$like '%s%%'", |
|
933 | 933 | ); |
934 | 934 | $where[] = 'n.title '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
935 | 935 | $args[] = $string; |
936 | - } |
|
937 | - elseif ($ids) { |
|
936 | + } |
|
937 | + elseif ($ids) { |
|
938 | 938 | $where[] = 'n.nid IN (' . db_placeholders($ids) . ')'; |
939 | 939 | $args = array_merge($args, $ids); |
940 | - } |
|
940 | + } |
|
941 | 941 | |
942 | - $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
943 | - $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause ORDER BY n.title, n.type"); |
|
944 | - $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args); |
|
945 | - $references = array(); |
|
946 | - while ($node = db_fetch_object($result)) { |
|
942 | + $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
943 | + $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause ORDER BY n.title, n.type"); |
|
944 | + $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args); |
|
945 | + $references = array(); |
|
946 | + while ($node = db_fetch_object($result)) { |
|
947 | 947 | $references[$node->nid] = array( |
948 | - 'title' => $node->node_title, |
|
949 | - 'rendered' => check_plain($node->node_title), |
|
948 | + 'title' => $node->node_title, |
|
949 | + 'rendered' => check_plain($node->node_title), |
|
950 | 950 | ); |
951 | - } |
|
951 | + } |
|
952 | 952 | |
953 | - return $references; |
|
953 | + return $references; |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | /** |
@@ -960,31 +960,31 @@ discard block |
||
960 | 960 | * a user has edit but not view access. |
961 | 961 | */ |
962 | 962 | function nodereference_autocomplete_access($field_name) { |
963 | - return user_access('access content') && ($field = content_fields($field_name)) && isset($field['field_name']) && content_access('view', $field) && content_access('edit', $field); |
|
963 | + return user_access('access content') && ($field = content_fields($field_name)) && isset($field['field_name']) && content_access('view', $field) && content_access('edit', $field); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | /** |
967 | 967 | * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users |
968 | 968 | */ |
969 | 969 | function nodereference_autocomplete($field_name, $string = '') { |
970 | - $fields = content_fields(); |
|
971 | - $field = $fields[$field_name]; |
|
972 | - $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains'; |
|
973 | - $matches = array(); |
|
970 | + $fields = content_fields(); |
|
971 | + $field = $fields[$field_name]; |
|
972 | + $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains'; |
|
973 | + $matches = array(); |
|
974 | 974 | |
975 | - $references = _nodereference_potential_references($field, $string, $match, array(), 10); |
|
976 | - foreach ($references as $id => $row) { |
|
975 | + $references = _nodereference_potential_references($field, $string, $match, array(), 10); |
|
976 | + foreach ($references as $id => $row) { |
|
977 | 977 | // Add a class wrapper for a few required CSS overrides. |
978 | 978 | $matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>'; |
979 | - } |
|
980 | - drupal_json($matches); |
|
979 | + } |
|
980 | + drupal_json($matches); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
984 | 984 | * Implementation of hook_node_types. |
985 | 985 | */ |
986 | 986 | function nodereference_node_type($op, $info) { |
987 | - switch ($op) { |
|
987 | + switch ($op) { |
|
988 | 988 | case 'update': |
989 | 989 | // Reflect type name changes to the 'referenceable types' settings. |
990 | 990 | if (!empty($info->old_type) && $info->old_type != $info->type) { |
@@ -993,22 +993,22 @@ discard block |
||
993 | 993 | $fields = content_fields(); |
994 | 994 | $rebuild = FALSE; |
995 | 995 | foreach ($fields as $field_name => $field) { |
996 | - if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) { |
|
996 | + if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) { |
|
997 | 997 | $field['referenceable_types'][$info->type] = empty($field['referenceable_types'][$info->old_type]) ? 0 : $info->type; |
998 | 998 | unset($field['referenceable_types'][$info->old_type]); |
999 | 999 | content_field_instance_update($field, FALSE); |
1000 | 1000 | $rebuild = TRUE; |
1001 | - } |
|
1001 | + } |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | // Clear caches and rebuild menu only if any field has been updated. |
1005 | 1005 | if ($rebuild) { |
1006 | - content_clear_type_cache(TRUE); |
|
1007 | - menu_rebuild(); |
|
1006 | + content_clear_type_cache(TRUE); |
|
1007 | + menu_rebuild(); |
|
1008 | + } |
|
1008 | 1009 | } |
1009 | - } |
|
1010 | - break; |
|
1011 | - } |
|
1010 | + break; |
|
1011 | + } |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1018,16 +1018,16 @@ discard block |
||
1018 | 1018 | * nodereference field with the 'full node' / 'teaser' formatters. |
1019 | 1019 | */ |
1020 | 1020 | function nodereference_preprocess_node(&$vars) { |
1021 | - // The 'referencing_field' attribute of the node is added by the 'teaser' |
|
1022 | - // and 'full node' formatters. |
|
1023 | - if (!empty($vars['node']->referencing_field)) { |
|
1021 | + // The 'referencing_field' attribute of the node is added by the 'teaser' |
|
1022 | + // and 'full node' formatters. |
|
1023 | + if (!empty($vars['node']->referencing_field)) { |
|
1024 | 1024 | $node = $vars['node']; |
1025 | 1025 | $field = $node->referencing_field; |
1026 | 1026 | $vars['template_files'][] = 'node-nodereference'; |
1027 | 1027 | $vars['template_files'][] = 'node-nodereference-'. $field['field_name']; |
1028 | 1028 | $vars['template_files'][] = 'node-nodereference-'. $node->type; |
1029 | 1029 | $vars['template_files'][] = 'node-nodereference-'. $field['field_name'] .'-'. $node->type; |
1030 | - } |
|
1030 | + } |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
@@ -1042,13 +1042,13 @@ discard block |
||
1042 | 1042 | * $element['#delta] is the position of this element in the group |
1043 | 1043 | */ |
1044 | 1044 | function theme_nodereference_select($element) { |
1045 | - return $element['#children']; |
|
1045 | + return $element['#children']; |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | function theme_nodereference_buttons($element) { |
1049 | - return $element['#children']; |
|
1049 | + return $element['#children']; |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | function theme_nodereference_autocomplete($element) { |
1053 | - return $element['#children']; |
|
1053 | + return $element['#children']; |
|
1054 | 1054 | } |
@@ -79,102 +79,102 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function nodereference_field_settings($op, $field) { |
81 | 81 | switch ($op) { |
82 | - case 'form': |
|
83 | - $form = array(); |
|
84 | - $form['referenceable_types'] = array( |
|
85 | - '#type' => 'checkboxes', |
|
86 | - '#title' => t('Content types that can be referenced'), |
|
87 | - '#multiple' => TRUE, |
|
88 | - '#default_value' => is_array($field['referenceable_types']) ? $field['referenceable_types'] : array(), |
|
89 | - '#options' => array_map('check_plain', node_get_types('names')), |
|
90 | - ); |
|
91 | - if (module_exists('views')) { |
|
92 | - $views = array('--' => '--'); |
|
93 | - $all_views = views_get_all_views(); |
|
94 | - foreach ($all_views as $view) { |
|
95 | - // Only 'node' views that have fields will work for our purpose. |
|
96 | - if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) { |
|
97 | - if ($view->type == 'Default') { |
|
98 | - $views[t('Default Views')][$view->name] = $view->name; |
|
99 | - } |
|
100 | - else { |
|
101 | - $views[t('Existing Views')][$view->name] = $view->name; |
|
102 | - } |
|
82 | + case 'form': |
|
83 | + $form = array(); |
|
84 | + $form['referenceable_types'] = array( |
|
85 | + '#type' => 'checkboxes', |
|
86 | + '#title' => t('Content types that can be referenced'), |
|
87 | + '#multiple' => TRUE, |
|
88 | + '#default_value' => is_array($field['referenceable_types']) ? $field['referenceable_types'] : array(), |
|
89 | + '#options' => array_map('check_plain', node_get_types('names')), |
|
90 | + ); |
|
91 | + if (module_exists('views')) { |
|
92 | + $views = array('--' => '--'); |
|
93 | + $all_views = views_get_all_views(); |
|
94 | + foreach ($all_views as $view) { |
|
95 | + // Only 'node' views that have fields will work for our purpose. |
|
96 | + if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) { |
|
97 | + if ($view->type == 'Default') { |
|
98 | + $views[t('Default Views')][$view->name] = $view->name; |
|
99 | + } |
|
100 | + else { |
|
101 | + $views[t('Existing Views')][$view->name] = $view->name; |
|
103 | 102 | } |
104 | - } |
|
105 | - |
|
106 | - $form['advanced'] = array( |
|
107 | - '#type' => 'fieldset', |
|
108 | - '#title' => t('Advanced - Nodes that can be referenced (View)'), |
|
109 | - '#collapsible' => TRUE, |
|
110 | - '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
111 | - ); |
|
112 | - if (count($views) > 1) { |
|
113 | - $form['advanced']['advanced_view'] = array( |
|
114 | - '#type' => 'select', |
|
115 | - '#title' => t('View used to select the nodes'), |
|
116 | - '#options' => $views, |
|
117 | - '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
|
118 | - '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') . |
|
119 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
120 | - ); |
|
121 | - $form['advanced']['advanced_view_args'] = array( |
|
122 | - '#type' => 'textfield', |
|
123 | - '#title' => t('View arguments'), |
|
124 | - '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
|
125 | - '#required' => FALSE, |
|
126 | - '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
|
127 | - ); |
|
128 | - } |
|
129 | - else { |
|
130 | - $form['advanced']['no_view_help'] = array( |
|
131 | - '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
132 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
133 | - ); |
|
134 | 103 | } |
135 | 104 | } |
136 | - return $form; |
|
137 | 105 | |
138 | - case 'save': |
|
139 | - $settings = array('referenceable_types'); |
|
140 | - if (module_exists('views')) { |
|
141 | - $settings[] = 'advanced_view'; |
|
142 | - $settings[] = 'advanced_view_args'; |
|
106 | + $form['advanced'] = array( |
|
107 | + '#type' => 'fieldset', |
|
108 | + '#title' => t('Advanced - Nodes that can be referenced (View)'), |
|
109 | + '#collapsible' => TRUE, |
|
110 | + '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
111 | + ); |
|
112 | + if (count($views) > 1) { |
|
113 | + $form['advanced']['advanced_view'] = array( |
|
114 | + '#type' => 'select', |
|
115 | + '#title' => t('View used to select the nodes'), |
|
116 | + '#options' => $views, |
|
117 | + '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
|
118 | + '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') . |
|
119 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
120 | + ); |
|
121 | + $form['advanced']['advanced_view_args'] = array( |
|
122 | + '#type' => 'textfield', |
|
123 | + '#title' => t('View arguments'), |
|
124 | + '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
|
125 | + '#required' => FALSE, |
|
126 | + '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
|
127 | + ); |
|
128 | + } |
|
129 | + else { |
|
130 | + $form['advanced']['no_view_help'] = array( |
|
131 | + '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
132 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
|
133 | + ); |
|
143 | 134 | } |
144 | - return $settings; |
|
135 | + } |
|
136 | + return $form; |
|
145 | 137 | |
146 | - case 'database columns': |
|
147 | - $columns = array( |
|
148 | - 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
|
149 | - ); |
|
150 | - return $columns; |
|
151 | - |
|
152 | - case 'views data': |
|
153 | - $data = content_views_field_views_data($field); |
|
154 | - $db_info = content_database_info($field); |
|
155 | - $table_alias = content_views_tablename($field); |
|
156 | - |
|
157 | - // Filter: swap the handler to the 'in' operator. |
|
158 | - $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
159 | - // Argument: use node.title for summaries. |
|
160 | - $data["node_$table_alias"]['table']['join']['node'] = array( |
|
161 | - 'table' => 'node', |
|
162 | - 'field' => 'nid', |
|
163 | - 'left_table' => $table_alias, |
|
164 | - 'left_field' => $field['field_name'] .'_nid', |
|
165 | - ); |
|
166 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title'; |
|
169 | - // Relationship: add a relationship for related node. |
|
170 | - $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array( |
|
171 | - 'base' => 'node', |
|
172 | - 'field' => $db_info['columns']['nid']['column'], |
|
173 | - 'handler' => 'content_handler_relationship', |
|
174 | - 'label' => t($field['widget']['label']), |
|
175 | - 'content_field_name' => $field['field_name'], |
|
176 | - ); |
|
177 | - return $data; |
|
138 | + case 'save': |
|
139 | + $settings = array('referenceable_types'); |
|
140 | + if (module_exists('views')) { |
|
141 | + $settings[] = 'advanced_view'; |
|
142 | + $settings[] = 'advanced_view_args'; |
|
143 | + } |
|
144 | + return $settings; |
|
145 | + |
|
146 | + case 'database columns': |
|
147 | + $columns = array( |
|
148 | + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
|
149 | + ); |
|
150 | + return $columns; |
|
151 | + |
|
152 | + case 'views data': |
|
153 | + $data = content_views_field_views_data($field); |
|
154 | + $db_info = content_database_info($field); |
|
155 | + $table_alias = content_views_tablename($field); |
|
156 | + |
|
157 | + // Filter: swap the handler to the 'in' operator. |
|
158 | + $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
159 | + // Argument: use node.title for summaries. |
|
160 | + $data["node_$table_alias"]['table']['join']['node'] = array( |
|
161 | + 'table' => 'node', |
|
162 | + 'field' => 'nid', |
|
163 | + 'left_table' => $table_alias, |
|
164 | + 'left_field' => $field['field_name'] .'_nid', |
|
165 | + ); |
|
166 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | + $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title'; |
|
169 | + // Relationship: add a relationship for related node. |
|
170 | + $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array( |
|
171 | + 'base' => 'node', |
|
172 | + 'field' => $db_info['columns']['nid']['column'], |
|
173 | + 'handler' => 'content_handler_relationship', |
|
174 | + 'label' => t($field['widget']['label']), |
|
175 | + 'content_field_name' => $field['field_name'], |
|
176 | + ); |
|
177 | + return $data; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -186,91 +186,91 @@ discard block |
||
186 | 186 | |
187 | 187 | switch ($op) { |
188 | 188 | // When preparing a translation, load any translations of existing references. |
189 | - case 'prepare translation': |
|
190 | - $addition = array(); |
|
191 | - $addition[$field['field_name']] = array(); |
|
192 | - if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) { |
|
193 | - foreach ($node->translation_source->$field['field_name'] as $key => $reference) { |
|
194 | - $reference_node = node_load($reference['nid']); |
|
195 | - // Test if the referenced node type is translatable and, if so, |
|
196 | - // load translations if the reference is not for the current language. |
|
197 | - // We can assume the translation module is present because it invokes 'prepare translation'. |
|
198 | - if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) { |
|
199 | - // If there is a translation for the current language, use it. |
|
200 | - $addition[$field['field_name']][] = array( |
|
201 | - 'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'], |
|
202 | - ); |
|
203 | - } |
|
189 | + case 'prepare translation': |
|
190 | + $addition = array(); |
|
191 | + $addition[$field['field_name']] = array(); |
|
192 | + if (isset($node->translation_source->$field['field_name']) && is_array($node->translation_source->$field['field_name'])) { |
|
193 | + foreach ($node->translation_source->$field['field_name'] as $key => $reference) { |
|
194 | + $reference_node = node_load($reference['nid']); |
|
195 | + // Test if the referenced node type is translatable and, if so, |
|
196 | + // load translations if the reference is not for the current language. |
|
197 | + // We can assume the translation module is present because it invokes 'prepare translation'. |
|
198 | + if (translation_supported_type($reference_node->type) && !empty($reference_node->language) && $reference_node->language != $node->language && $translations = translation_node_get_translations($reference_node->tnid)) { |
|
199 | + // If there is a translation for the current language, use it. |
|
200 | + $addition[$field['field_name']][] = array( |
|
201 | + 'nid' => isset($translations[$node->language]) ? $translations[$node->language]->nid : $reference['nid'], |
|
202 | + ); |
|
204 | 203 | } |
205 | 204 | } |
206 | - return $addition; |
|
207 | - |
|
208 | - case 'validate': |
|
209 | - // Extract nids to check. |
|
210 | - $ids = array(); |
|
211 | - foreach ($items as $delta => $item) { |
|
212 | - if (is_array($item) && !empty($item['nid'])) { |
|
213 | - if (is_numeric($item['nid'])) { |
|
214 | - $ids[] = $item['nid']; |
|
215 | - } |
|
216 | - else { |
|
217 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
218 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
219 | - form_set_error($error_element, t("%name: invalid input.", array('%name' => t($field['widget']['label'])))); |
|
220 | - } |
|
205 | + } |
|
206 | + return $addition; |
|
207 | + |
|
208 | + case 'validate': |
|
209 | + // Extract nids to check. |
|
210 | + $ids = array(); |
|
211 | + foreach ($items as $delta => $item) { |
|
212 | + if (is_array($item) && !empty($item['nid'])) { |
|
213 | + if (is_numeric($item['nid'])) { |
|
214 | + $ids[] = $item['nid']; |
|
221 | 215 | } |
222 | - } |
|
223 | - // Prevent performance hog if there are no ids to check. |
|
224 | - if ($ids) { |
|
225 | - $refs = _nodereference_potential_references($field, '', NULL, $ids); |
|
226 | - foreach ($items as $delta => $item) { |
|
227 | - if (is_array($item)) { |
|
228 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
229 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
230 | - if (!empty($item['nid']) && !isset($refs[$item['nid']])) { |
|
231 | - form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label'])))); |
|
232 | - } |
|
233 | - } |
|
216 | + else { |
|
217 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
218 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
219 | + form_set_error($error_element, t("%name: invalid input.", array('%name' => t($field['widget']['label'])))); |
|
234 | 220 | } |
235 | 221 | } |
236 | - return $items; |
|
237 | - |
|
238 | - case 'sanitize': |
|
239 | - // We can't just check the node is 'referenceable', because Views-mode |
|
240 | - // could rely on 'current user' (at edit time). |
|
241 | - |
|
242 | - // Extract nids to check. |
|
243 | - $ids = array(); |
|
222 | + } |
|
223 | + // Prevent performance hog if there are no ids to check. |
|
224 | + if ($ids) { |
|
225 | + $refs = _nodereference_potential_references($field, '', NULL, $ids); |
|
244 | 226 | foreach ($items as $delta => $item) { |
245 | 227 | if (is_array($item)) { |
246 | - // Default to 'non accessible'. |
|
247 | - $items[$delta]['safe'] = array(); |
|
248 | - if (!empty($item['nid']) && is_numeric($item['nid'])) { |
|
249 | - $ids[] = $item['nid']; |
|
228 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
229 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
230 | + if (!empty($item['nid']) && !isset($refs[$item['nid']])) { |
|
231 | + form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label'])))); |
|
250 | 232 | } |
251 | 233 | } |
252 | 234 | } |
253 | - if ($ids) { |
|
254 | - // Load information about nids that we haven't already loaded during |
|
255 | - // this page request. |
|
256 | - $missing_ids = array_diff($ids, array_keys($sanitized_nodes)); |
|
257 | - if (!empty($missing_ids)) { |
|
258 | - $where = array('n.nid in ('. db_placeholders($missing_ids) . ')'); |
|
259 | - if (!user_access('administer nodes')) { |
|
260 | - $where[] = 'n.status = 1'; |
|
261 | - } |
|
262 | - $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids); |
|
263 | - while ($row = db_fetch_array($result)) { |
|
264 | - $sanitized_nodes[$row['nid']] = $row; |
|
265 | - } |
|
235 | + } |
|
236 | + return $items; |
|
237 | + |
|
238 | + case 'sanitize': |
|
239 | + // We can't just check the node is 'referenceable', because Views-mode |
|
240 | + // could rely on 'current user' (at edit time). |
|
241 | + |
|
242 | + // Extract nids to check. |
|
243 | + $ids = array(); |
|
244 | + foreach ($items as $delta => $item) { |
|
245 | + if (is_array($item)) { |
|
246 | + // Default to 'non accessible'. |
|
247 | + $items[$delta]['safe'] = array(); |
|
248 | + if (!empty($item['nid']) && is_numeric($item['nid'])) { |
|
249 | + $ids[] = $item['nid']; |
|
266 | 250 | } |
267 | - foreach ($items as $delta => $item) { |
|
268 | - if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) { |
|
269 | - $items[$delta]['safe'] = $sanitized_nodes[$item['nid']]; |
|
270 | - } |
|
251 | + } |
|
252 | + } |
|
253 | + if ($ids) { |
|
254 | + // Load information about nids that we haven't already loaded during |
|
255 | + // this page request. |
|
256 | + $missing_ids = array_diff($ids, array_keys($sanitized_nodes)); |
|
257 | + if (!empty($missing_ids)) { |
|
258 | + $where = array('n.nid in ('. db_placeholders($missing_ids) . ')'); |
|
259 | + if (!user_access('administer nodes')) { |
|
260 | + $where[] = 'n.status = 1'; |
|
261 | + } |
|
262 | + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids); |
|
263 | + while ($row = db_fetch_array($result)) { |
|
264 | + $sanitized_nodes[$row['nid']] = $row; |
|
271 | 265 | } |
272 | 266 | } |
273 | - return $items; |
|
267 | + foreach ($items as $delta => $item) { |
|
268 | + if (is_array($item) && !empty($item['nid']) && isset($sanitized_nodes[$item['nid']])) { |
|
269 | + $items[$delta]['safe'] = $sanitized_nodes[$item['nid']]; |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + return $items; |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -465,37 +465,37 @@ discard block |
||
465 | 465 | */ |
466 | 466 | function nodereference_widget_settings($op, $widget) { |
467 | 467 | switch ($op) { |
468 | - case 'form': |
|
469 | - $form = array(); |
|
470 | - $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
471 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
472 | - if ($widget['type'] == 'nodereference_autocomplete') { |
|
473 | - $form['autocomplete_match'] = array( |
|
474 | - '#type' => 'select', |
|
475 | - '#title' => t('Autocomplete matching'), |
|
476 | - '#default_value' => $match, |
|
477 | - '#options' => array( |
|
478 | - 'starts_with' => t('Starts with'), |
|
479 | - 'contains' => t('Contains'), |
|
480 | - ), |
|
481 | - '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'), |
|
482 | - ); |
|
483 | - $form['size'] = array( |
|
484 | - '#type' => 'textfield', |
|
485 | - '#title' => t('Size of textfield'), |
|
486 | - '#default_value' => $size, |
|
487 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
488 | - '#required' => TRUE, |
|
489 | - ); |
|
490 | - } |
|
491 | - else { |
|
492 | - $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
|
493 | - $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
494 | - } |
|
495 | - return $form; |
|
468 | + case 'form': |
|
469 | + $form = array(); |
|
470 | + $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
471 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
472 | + if ($widget['type'] == 'nodereference_autocomplete') { |
|
473 | + $form['autocomplete_match'] = array( |
|
474 | + '#type' => 'select', |
|
475 | + '#title' => t('Autocomplete matching'), |
|
476 | + '#default_value' => $match, |
|
477 | + '#options' => array( |
|
478 | + 'starts_with' => t('Starts with'), |
|
479 | + 'contains' => t('Contains'), |
|
480 | + ), |
|
481 | + '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'), |
|
482 | + ); |
|
483 | + $form['size'] = array( |
|
484 | + '#type' => 'textfield', |
|
485 | + '#title' => t('Size of textfield'), |
|
486 | + '#default_value' => $size, |
|
487 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
488 | + '#required' => TRUE, |
|
489 | + ); |
|
490 | + } |
|
491 | + else { |
|
492 | + $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
|
493 | + $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
494 | + } |
|
495 | + return $form; |
|
496 | 496 | |
497 | - case 'save': |
|
498 | - return array('autocomplete_match', 'size'); |
|
497 | + case 'save': |
|
498 | + return array('autocomplete_match', 'size'); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
@@ -532,27 +532,27 @@ discard block |
||
532 | 532 | */ |
533 | 533 | function nodereference_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
534 | 534 | switch ($field['widget']['type']) { |
535 | - case 'nodereference_select': |
|
536 | - $element = array( |
|
537 | - '#type' => 'nodereference_select', |
|
538 | - '#default_value' => $items, |
|
539 | - ); |
|
540 | - break; |
|
535 | + case 'nodereference_select': |
|
536 | + $element = array( |
|
537 | + '#type' => 'nodereference_select', |
|
538 | + '#default_value' => $items, |
|
539 | + ); |
|
540 | + break; |
|
541 | 541 | |
542 | - case 'nodereference_buttons': |
|
543 | - $element = array( |
|
544 | - '#type' => 'nodereference_buttons', |
|
545 | - '#default_value' => $items, |
|
546 | - ); |
|
547 | - break; |
|
542 | + case 'nodereference_buttons': |
|
543 | + $element = array( |
|
544 | + '#type' => 'nodereference_buttons', |
|
545 | + '#default_value' => $items, |
|
546 | + ); |
|
547 | + break; |
|
548 | 548 | |
549 | - case 'nodereference_autocomplete': |
|
550 | - $element = array( |
|
551 | - '#type' => 'nodereference_autocomplete', |
|
552 | - '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
553 | - '#value_callback' => 'nodereference_autocomplete_value', |
|
554 | - ); |
|
555 | - break; |
|
549 | + case 'nodereference_autocomplete': |
|
550 | + $element = array( |
|
551 | + '#type' => 'nodereference_autocomplete', |
|
552 | + '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
553 | + '#value_callback' => 'nodereference_autocomplete_value', |
|
554 | + ); |
|
555 | + break; |
|
556 | 556 | } |
557 | 557 | return $element; |
558 | 558 | } |
@@ -985,29 +985,29 @@ discard block |
||
985 | 985 | */ |
986 | 986 | function nodereference_node_type($op, $info) { |
987 | 987 | switch ($op) { |
988 | - case 'update': |
|
989 | - // Reflect type name changes to the 'referenceable types' settings. |
|
990 | - if (!empty($info->old_type) && $info->old_type != $info->type) { |
|
991 | - // content.module's implementaion of hook_node_type() has already |
|
992 | - // refreshed _content_type_info(). |
|
993 | - $fields = content_fields(); |
|
994 | - $rebuild = FALSE; |
|
995 | - foreach ($fields as $field_name => $field) { |
|
996 | - if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) { |
|
997 | - $field['referenceable_types'][$info->type] = empty($field['referenceable_types'][$info->old_type]) ? 0 : $info->type; |
|
998 | - unset($field['referenceable_types'][$info->old_type]); |
|
999 | - content_field_instance_update($field, FALSE); |
|
1000 | - $rebuild = TRUE; |
|
1001 | - } |
|
988 | + case 'update': |
|
989 | + // Reflect type name changes to the 'referenceable types' settings. |
|
990 | + if (!empty($info->old_type) && $info->old_type != $info->type) { |
|
991 | + // content.module's implementaion of hook_node_type() has already |
|
992 | + // refreshed _content_type_info(). |
|
993 | + $fields = content_fields(); |
|
994 | + $rebuild = FALSE; |
|
995 | + foreach ($fields as $field_name => $field) { |
|
996 | + if ($field['type'] == 'nodereference' && isset($field['referenceable_types'][$info->old_type])) { |
|
997 | + $field['referenceable_types'][$info->type] = empty($field['referenceable_types'][$info->old_type]) ? 0 : $info->type; |
|
998 | + unset($field['referenceable_types'][$info->old_type]); |
|
999 | + content_field_instance_update($field, FALSE); |
|
1000 | + $rebuild = TRUE; |
|
1002 | 1001 | } |
1002 | + } |
|
1003 | 1003 | |
1004 | - // Clear caches and rebuild menu only if any field has been updated. |
|
1005 | - if ($rebuild) { |
|
1006 | - content_clear_type_cache(TRUE); |
|
1007 | - menu_rebuild(); |
|
1008 | - } |
|
1004 | + // Clear caches and rebuild menu only if any field has been updated. |
|
1005 | + if ($rebuild) { |
|
1006 | + content_clear_type_cache(TRUE); |
|
1007 | + menu_rebuild(); |
|
1009 | 1008 | } |
1010 | - break; |
|
1009 | + } |
|
1010 | + break; |
|
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | function nodereference_ctools_plugin_directory($module, $plugin) { |
59 | 59 | if ($module == 'ctools' && $plugin == 'relationships') { |
60 | - return 'panels/' . $plugin; |
|
60 | + return 'panels/'.$plugin; |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | '#title' => t('View used to select the nodes'), |
116 | 116 | '#options' => $views, |
117 | 117 | '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
118 | - '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') . |
|
118 | + '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>'). |
|
119 | 119 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
120 | 120 | ); |
121 | 121 | $form['advanced']['advanced_view_args'] = array( |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | } |
129 | 129 | else { |
130 | 130 | $form['advanced']['no_view_help'] = array( |
131 | - '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
131 | + '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>'). |
|
132 | 132 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
133 | 133 | ); |
134 | 134 | } |
@@ -155,19 +155,19 @@ discard block |
||
155 | 155 | $table_alias = content_views_tablename($field); |
156 | 156 | |
157 | 157 | // Filter: swap the handler to the 'in' operator. |
158 | - $data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
158 | + $data[$table_alias][$field['field_name'].'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
159 | 159 | // Argument: use node.title for summaries. |
160 | 160 | $data["node_$table_alias"]['table']['join']['node'] = array( |
161 | 161 | 'table' => 'node', |
162 | 162 | 'field' => 'nid', |
163 | 163 | 'left_table' => $table_alias, |
164 | - 'left_field' => $field['field_name'] .'_nid', |
|
164 | + 'left_field' => $field['field_name'].'_nid', |
|
165 | 165 | ); |
166 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | - $data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title'; |
|
166 | + $data[$table_alias][$field['field_name'].'_nid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
167 | + $data[$table_alias][$field['field_name'].'_nid']['argument']['name table'] = "node_$table_alias"; |
|
168 | + $data[$table_alias][$field['field_name'].'_nid']['argument']['name field'] = 'title'; |
|
169 | 169 | // Relationship: add a relationship for related node. |
170 | - $data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array( |
|
170 | + $data[$table_alias][$field['field_name'].'_nid']['relationship'] = array( |
|
171 | 171 | 'base' => 'node', |
172 | 172 | 'field' => $db_info['columns']['nid']['column'], |
173 | 173 | 'handler' => 'content_handler_relationship', |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | // this page request. |
256 | 256 | $missing_ids = array_diff($ids, array_keys($sanitized_nodes)); |
257 | 257 | if (!empty($missing_ids)) { |
258 | - $where = array('n.nid in ('. db_placeholders($missing_ids) . ')'); |
|
258 | + $where = array('n.nid in ('.db_placeholders($missing_ids).')'); |
|
259 | 259 | if (!user_access('administer nodes')) { |
260 | 260 | $where[] = 'n.status = 1'; |
261 | 261 | } |
262 | - $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '. implode(' AND ', $where)), $missing_ids); |
|
262 | + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status FROM {node} n WHERE '.implode(' AND ', $where)), $missing_ids); |
|
263 | 263 | while ($row = db_fetch_array($result)) { |
264 | 264 | $sanitized_nodes[$row['nid']] = $row; |
265 | 265 | } |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | function theme_nodereference_formatter_default($element) { |
319 | 319 | $output = ''; |
320 | 320 | if (!empty($element['#item']['safe']['nid'])) { |
321 | - $output = l($element['#item']['safe']['title'], 'node/'. $element['#item']['safe']['nid']); |
|
321 | + $output = l($element['#item']['safe']['title'], 'node/'.$element['#item']['safe']['nid']); |
|
322 | 322 | if (!$element['#item']['safe']['status']) { |
323 | - $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
323 | + $output = '<span class="node-unpublished"> '.t('(Unpublished)')." $output</span>"; |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 | return $output; |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | if (!empty($element['#item']['safe']['nid'])) { |
335 | 335 | $output = check_plain($element['#item']['safe']['title']); |
336 | 336 | if (!$element['#item']['safe']['status']) { |
337 | - $output = '<span class="node-unpublished"> '. t('(Unpublished)') ." $output</span>"; |
|
337 | + $output = '<span class="node-unpublished"> '.t('(Unpublished)')." $output</span>"; |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | return $output; |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | * Substitute in the node title for the node nid. |
564 | 564 | */ |
565 | 565 | function nodereference_autocomplete_value($element, $edit = FALSE) { |
566 | - $field_key = $element['#columns'][0]; |
|
566 | + $field_key = $element['#columns'][0]; |
|
567 | 567 | if (!empty($element['#default_value'][$field_key])) { |
568 | 568 | $nid = $element['#default_value'][$field_key]; |
569 | 569 | $value = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $nid)); |
570 | - $value .= ' [nid:'. $nid .']'; |
|
570 | + $value .= ' [nid:'.$nid.']'; |
|
571 | 571 | return array($field_key => $value); |
572 | 572 | } |
573 | 573 | return array($field_key => NULL); |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | // element, it can wrap around the optionwidgets_select element. |
587 | 587 | // This will create a new, nested instance of the field. |
588 | 588 | // Add a validation step where the value can be unwrapped. |
589 | - $field_key = $element['#columns'][0]; |
|
589 | + $field_key = $element['#columns'][0]; |
|
590 | 590 | $element[$field_key] = array( |
591 | 591 | '#type' => 'optionwidgets_select', |
592 | 592 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | // element, it can wrap around the optionwidgets_select element. |
621 | 621 | // This will create a new, nested instance of the field. |
622 | 622 | // Add a validation step where the value can be unwrapped. |
623 | - $field_key = $element['#columns'][0]; |
|
623 | + $field_key = $element['#columns'][0]; |
|
624 | 624 | $element[$field_key] = array( |
625 | 625 | '#type' => 'optionwidgets_buttons', |
626 | 626 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
@@ -654,12 +654,12 @@ discard block |
||
654 | 654 | // element, it can wrap around the text_textfield element and add an autocomplete |
655 | 655 | // path and some extra processing to it. |
656 | 656 | // Add a validation step where the value can be unwrapped. |
657 | - $field_key = $element['#columns'][0]; |
|
657 | + $field_key = $element['#columns'][0]; |
|
658 | 658 | |
659 | 659 | $element[$field_key] = array( |
660 | 660 | '#type' => 'text_textfield', |
661 | 661 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
662 | - '#autocomplete_path' => 'nodereference/autocomplete/'. $element['#field_name'], |
|
662 | + '#autocomplete_path' => 'nodereference/autocomplete/'.$element['#field_name'], |
|
663 | 663 | // The following values were set by the content module and need |
664 | 664 | // to be passed down to the nested element. |
665 | 665 | '#title' => $element['#title'], |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * like optionwidgets are using #element_validate to alter the value. |
698 | 698 | */ |
699 | 699 | function nodereference_optionwidgets_validate($element, &$form_state) { |
700 | - $field_key = $element['#columns'][0]; |
|
700 | + $field_key = $element['#columns'][0]; |
|
701 | 701 | |
702 | 702 | $value = $form_state['values']; |
703 | 703 | $new_parents = array(); |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | static $results = array(); |
806 | 806 | |
807 | 807 | // Create unique id for static cache. |
808 | - $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
808 | + $cid = $field['field_name'].':'.$match.':'.($string !== '' ? $string : implode('-', $ids)).':'.$limit; |
|
809 | 809 | if (!isset($results[$cid])) { |
810 | 810 | $references = FALSE; |
811 | 811 | if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') { |
@@ -931,15 +931,15 @@ discard block |
||
931 | 931 | 'equals' => "= '%s'", |
932 | 932 | 'starts_with' => "$like '%s%%'", |
933 | 933 | ); |
934 | - $where[] = 'n.title '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
|
934 | + $where[] = 'n.title '.(isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
|
935 | 935 | $args[] = $string; |
936 | 936 | } |
937 | 937 | elseif ($ids) { |
938 | - $where[] = 'n.nid IN (' . db_placeholders($ids) . ')'; |
|
938 | + $where[] = 'n.nid IN ('.db_placeholders($ids).')'; |
|
939 | 939 | $args = array_merge($args, $ids); |
940 | 940 | } |
941 | 941 | |
942 | - $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
942 | + $where_clause = $where ? 'WHERE ('.implode(') AND (', $where).')' : ''; |
|
943 | 943 | $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause ORDER BY n.title, n.type"); |
944 | 944 | $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args); |
945 | 945 | $references = array(); |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | $references = _nodereference_potential_references($field, $string, $match, array(), 10); |
976 | 976 | foreach ($references as $id => $row) { |
977 | 977 | // Add a class wrapper for a few required CSS overrides. |
978 | - $matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>'; |
|
978 | + $matches[$row['title']." [nid:$id]"] = '<div class="reference-autocomplete">'.$row['rendered'].'</div>'; |
|
979 | 979 | } |
980 | 980 | drupal_json($matches); |
981 | 981 | } |
@@ -1024,9 +1024,9 @@ discard block |
||
1024 | 1024 | $node = $vars['node']; |
1025 | 1025 | $field = $node->referencing_field; |
1026 | 1026 | $vars['template_files'][] = 'node-nodereference'; |
1027 | - $vars['template_files'][] = 'node-nodereference-'. $field['field_name']; |
|
1028 | - $vars['template_files'][] = 'node-nodereference-'. $node->type; |
|
1029 | - $vars['template_files'][] = 'node-nodereference-'. $field['field_name'] .'-'. $node->type; |
|
1027 | + $vars['template_files'][] = 'node-nodereference-'.$field['field_name']; |
|
1028 | + $vars['template_files'][] = 'node-nodereference-'.$node->type; |
|
1029 | + $vars['template_files'][] = 'node-nodereference-'.$field['field_name'].'-'.$node->type; |
|
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 |
@@ -96,8 +96,7 @@ discard block |
||
96 | 96 | if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) { |
97 | 97 | if ($view->type == 'Default') { |
98 | 98 | $views[t('Default Views')][$view->name] = $view->name; |
99 | - } |
|
100 | - else { |
|
99 | + } else { |
|
101 | 100 | $views[t('Existing Views')][$view->name] = $view->name; |
102 | 101 | } |
103 | 102 | } |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | '#required' => FALSE, |
126 | 125 | '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
127 | 126 | ); |
128 | - } |
|
129 | - else { |
|
127 | + } else { |
|
130 | 128 | $form['advanced']['no_view_help'] = array( |
131 | 129 | '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
132 | 130 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'), |
@@ -212,10 +210,11 @@ discard block |
||
212 | 210 | if (is_array($item) && !empty($item['nid'])) { |
213 | 211 | if (is_numeric($item['nid'])) { |
214 | 212 | $ids[] = $item['nid']; |
215 | - } |
|
216 | - else { |
|
213 | + } else { |
|
217 | 214 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
218 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
215 | + if (is_array($item) && isset($item['_error_element'])) { |
|
216 | + unset($item['_error_element']); |
|
217 | + } |
|
219 | 218 | form_set_error($error_element, t("%name: invalid input.", array('%name' => t($field['widget']['label'])))); |
220 | 219 | } |
221 | 220 | } |
@@ -226,7 +225,9 @@ discard block |
||
226 | 225 | foreach ($items as $delta => $item) { |
227 | 226 | if (is_array($item)) { |
228 | 227 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
229 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
228 | + if (is_array($item) && isset($item['_error_element'])) { |
|
229 | + unset($item['_error_element']); |
|
230 | + } |
|
230 | 231 | if (!empty($item['nid']) && !isset($refs[$item['nid']])) { |
231 | 232 | form_set_error($error_element, t("%name: this post can't be referenced.", array('%name' => t($field['widget']['label'])))); |
232 | 233 | } |
@@ -487,8 +488,7 @@ discard block |
||
487 | 488 | '#element_validate' => array('_element_validate_integer_positive'), |
488 | 489 | '#required' => TRUE, |
489 | 490 | ); |
490 | - } |
|
491 | - else { |
|
491 | + } else { |
|
492 | 492 | $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
493 | 493 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
494 | 494 | } |
@@ -736,14 +736,12 @@ discard block |
||
736 | 736 | if (!empty($title) && ($n = node_load($nid)) && trim($title) != trim($n->title)) { |
737 | 737 | form_error($element[$field_key], t('%name: title mismatch. Please check your selection.', array('%name' => t($field['widget']['label'])))); |
738 | 738 | } |
739 | - } |
|
740 | - else { |
|
739 | + } else { |
|
741 | 740 | // No explicit nid. |
742 | 741 | $reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1); |
743 | 742 | if (empty($reference)) { |
744 | 743 | form_error($element[$field_key], t('%name: found no valid post with that title.', array('%name' => t($field['widget']['label'])))); |
745 | - } |
|
746 | - else { |
|
744 | + } else { |
|
747 | 745 | // TODO: |
748 | 746 | // the best thing would be to present the user with an additional form, |
749 | 747 | // allowing the user to choose between valid candidates with the same title |
@@ -868,8 +866,7 @@ discard block |
||
868 | 866 | if (!empty($field['advanced_view_args'])) { |
869 | 867 | // TODO: Support Tokens using token.module ? |
870 | 868 | $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
871 | - } |
|
872 | - else { |
|
869 | + } else { |
|
873 | 870 | $view_args = array(); |
874 | 871 | } |
875 | 872 | |
@@ -894,8 +891,7 @@ discard block |
||
894 | 891 | |
895 | 892 | // Get the results. |
896 | 893 | $result = $view->execute_display($display, $view_args); |
897 | - } |
|
898 | - else { |
|
894 | + } else { |
|
899 | 895 | $result = FALSE; |
900 | 896 | } |
901 | 897 | |
@@ -933,8 +929,7 @@ discard block |
||
933 | 929 | ); |
934 | 930 | $where[] = 'n.title '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
935 | 931 | $args[] = $string; |
936 | - } |
|
937 | - elseif ($ids) { |
|
932 | + } elseif ($ids) { |
|
938 | 933 | $where[] = 'n.nid IN (' . db_placeholders($ids) . ')'; |
939 | 934 | $args = array_merge($args, $ids); |
940 | 935 | } |
@@ -653,7 +653,7 @@ |
||
653 | 653 | * @param $ids |
654 | 654 | * Optional user ids to lookup (the $string and $match arguments will be |
655 | 655 | * ignored). |
656 | - * @param $limit |
|
656 | + * @param integer $limit |
|
657 | 657 | * If non-zero, limit the size of the result set. |
658 | 658 | * |
659 | 659 | * @return |
@@ -10,258 +10,258 @@ discard block |
||
10 | 10 | * Implementation of hook_menu(). |
11 | 11 | */ |
12 | 12 | function userreference_menu() { |
13 | - $items = array(); |
|
14 | - $items['userreference/autocomplete'] = array( |
|
13 | + $items = array(); |
|
14 | + $items['userreference/autocomplete'] = array( |
|
15 | 15 | 'title' => 'Userreference autocomplete', |
16 | 16 | 'page callback' => 'userreference_autocomplete', |
17 | 17 | 'access arguments' => array('access content'), |
18 | 18 | 'type' => MENU_CALLBACK |
19 | - ); |
|
20 | - return $items; |
|
19 | + ); |
|
20 | + return $items; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Implementation of hook_theme(). |
25 | 25 | */ |
26 | 26 | function userreference_theme() { |
27 | - return array( |
|
27 | + return array( |
|
28 | 28 | 'userreference_select' => array( |
29 | - 'arguments' => array('element' => NULL), |
|
29 | + 'arguments' => array('element' => NULL), |
|
30 | 30 | ), |
31 | 31 | 'userreference_buttons' => array( |
32 | - 'arguments' => array('element' => NULL), |
|
32 | + 'arguments' => array('element' => NULL), |
|
33 | 33 | ), |
34 | 34 | 'userreference_autocomplete' => array( |
35 | - 'arguments' => array('element' => NULL), |
|
35 | + 'arguments' => array('element' => NULL), |
|
36 | 36 | ), |
37 | 37 | 'userreference_formatter_default' => array( |
38 | - 'arguments' => array('element'), |
|
38 | + 'arguments' => array('element'), |
|
39 | 39 | ), |
40 | 40 | 'userreference_formatter_plain' => array( |
41 | - 'arguments' => array('element'), |
|
41 | + 'arguments' => array('element'), |
|
42 | 42 | ), |
43 | - ); |
|
43 | + ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Implementaion of hook_ctools_plugin_directory(). |
48 | 48 | */ |
49 | 49 | function userreference_ctools_plugin_directory($module, $plugin) { |
50 | - if ($module == 'ctools' && $plugin == 'relationships') { |
|
50 | + if ($module == 'ctools' && $plugin == 'relationships') { |
|
51 | 51 | return 'panels/' . $plugin; |
52 | - } |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Implementation of hook_field_info(). |
57 | 57 | */ |
58 | 58 | function userreference_field_info() { |
59 | - return array( |
|
59 | + return array( |
|
60 | 60 | 'userreference' => array( |
61 | - 'label' => t('User reference'), |
|
62 | - 'description' => t('Store the ID of a related user as an integer value.'), |
|
61 | + 'label' => t('User reference'), |
|
62 | + 'description' => t('Store the ID of a related user as an integer value.'), |
|
63 | 63 | // 'content_icon' => 'icon_content_noderef.png', |
64 | 64 | ), |
65 | - ); |
|
65 | + ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Implementation of hook_field_settings(). |
70 | 70 | */ |
71 | 71 | function userreference_field_settings($op, $field) { |
72 | - switch ($op) { |
|
72 | + switch ($op) { |
|
73 | 73 | case 'form': |
74 | 74 | $form = array(); |
75 | - $form['referenceable_roles'] = array( |
|
75 | + $form['referenceable_roles'] = array( |
|
76 | 76 | '#type' => 'checkboxes', |
77 | 77 | '#title' => t('User roles that can be referenced'), |
78 | 78 | '#default_value' => isset($field['referenceable_roles']) && is_array($field['referenceable_roles']) ? array_filter($field['referenceable_roles']) : array(), |
79 | 79 | '#options' => user_roles(1), |
80 | - ); |
|
81 | - $form['referenceable_status'] = array( |
|
80 | + ); |
|
81 | + $form['referenceable_status'] = array( |
|
82 | 82 | '#type' => 'radios', |
83 | 83 | '#title' => t('User status that can be referenced'), |
84 | 84 | '#default_value' => isset($field['referenceable_status']) ? $field['referenceable_status'] : '', |
85 | 85 | '#options' => array('' => t('All users'), 1 => t('Active users'), 0 => t('Blocked users')), |
86 | - ); |
|
87 | - if (module_exists('views')) { |
|
86 | + ); |
|
87 | + if (module_exists('views')) { |
|
88 | 88 | $views = array('--' => '--'); |
89 | 89 | $all_views = views_get_all_views(); |
90 | 90 | foreach ($all_views as $view) { |
91 | - // Only 'users' views that have fields will work for our purpose. |
|
92 | - if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) { |
|
91 | + // Only 'users' views that have fields will work for our purpose. |
|
92 | + if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) { |
|
93 | 93 | if ($view->type == 'Default') { |
94 | - $views[t('Default Views')][$view->name] = $view->name; |
|
94 | + $views[t('Default Views')][$view->name] = $view->name; |
|
95 | 95 | } |
96 | 96 | else { |
97 | - $views[t('Existing Views')][$view->name] = $view->name; |
|
97 | + $views[t('Existing Views')][$view->name] = $view->name; |
|
98 | + } |
|
98 | 99 | } |
99 | - } |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | $form['advanced'] = array( |
103 | - '#type' => 'fieldset', |
|
104 | - '#title' => t('Advanced - Users that can be referenced (View)'), |
|
105 | - '#collapsible' => TRUE, |
|
106 | - '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
107 | - ); |
|
103 | + '#type' => 'fieldset', |
|
104 | + '#title' => t('Advanced - Users that can be referenced (View)'), |
|
105 | + '#collapsible' => TRUE, |
|
106 | + '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
107 | + ); |
|
108 | 108 | if (count($views) > 1) { |
109 | - $form['advanced']['advanced_view'] = array( |
|
109 | + $form['advanced']['advanced_view'] = array( |
|
110 | 110 | '#type' => 'select', |
111 | 111 | '#title' => t('View used to select the users'), |
112 | 112 | '#options' => $views, |
113 | 113 | '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
114 | 114 | '#description' => t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>') . |
115 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
116 | - ); |
|
117 | - $form['advanced']['advanced_view_args'] = array( |
|
115 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
116 | + ); |
|
117 | + $form['advanced']['advanced_view_args'] = array( |
|
118 | 118 | '#type' => 'textfield', |
119 | 119 | '#title' => t('View arguments'), |
120 | 120 | '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
121 | 121 | '#required' => FALSE, |
122 | 122 | '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
123 | - ); |
|
123 | + ); |
|
124 | 124 | } |
125 | 125 | else { |
126 | - $form['advanced']['no_view_help'] = array( |
|
126 | + $form['advanced']['no_view_help'] = array( |
|
127 | 127 | '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
128 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
129 | - ); |
|
128 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
129 | + ); |
|
130 | + } |
|
130 | 131 | } |
131 | - } |
|
132 | - return $form; |
|
132 | + return $form; |
|
133 | 133 | |
134 | 134 | case 'save': |
135 | 135 | $settings = array('referenceable_roles', 'referenceable_status'); |
136 | - if (module_exists('views')) { |
|
136 | + if (module_exists('views')) { |
|
137 | 137 | $settings[] = 'advanced_view'; |
138 | 138 | $settings[] = 'advanced_view_args'; |
139 | - } |
|
140 | - return $settings; |
|
139 | + } |
|
140 | + return $settings; |
|
141 | 141 | |
142 | 142 | case 'database columns': |
143 | 143 | $columns = array( |
144 | 144 | 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
145 | - ); |
|
146 | - return $columns; |
|
145 | + ); |
|
146 | + return $columns; |
|
147 | 147 | |
148 | 148 | case 'views data': |
149 | 149 | $data = content_views_field_views_data($field); |
150 | - $db_info = content_database_info($field); |
|
151 | - $table_alias = content_views_tablename($field); |
|
152 | - |
|
153 | - // Filter : swap the handler to the 'in' operator. |
|
154 | - $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
155 | - // Argument: get the user name for summaries. |
|
156 | - // We need to join a new instance of the users table. |
|
157 | - $data["users_$table_alias"]['table']['join']['node'] = array( |
|
150 | + $db_info = content_database_info($field); |
|
151 | + $table_alias = content_views_tablename($field); |
|
152 | + |
|
153 | + // Filter : swap the handler to the 'in' operator. |
|
154 | + $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
155 | + // Argument: get the user name for summaries. |
|
156 | + // We need to join a new instance of the users table. |
|
157 | + $data["users_$table_alias"]['table']['join']['node'] = array( |
|
158 | 158 | 'table' => 'users', |
159 | 159 | 'field' => 'uid', |
160 | 160 | 'left_table' => $table_alias, |
161 | 161 | 'left_field' => $field['field_name'] .'_uid', |
162 | - ); |
|
163 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name'; |
|
166 | - // Relationship: Add a relationship for related user. |
|
167 | - $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array( |
|
162 | + ); |
|
163 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name'; |
|
166 | + // Relationship: Add a relationship for related user. |
|
167 | + $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array( |
|
168 | 168 | 'base' => 'users', |
169 | 169 | 'field' => $db_info['columns']['uid']['column'], |
170 | 170 | 'handler' => 'content_handler_relationship', |
171 | 171 | 'label' => t($field['widget']['label']), |
172 | 172 | 'content_field_name' => $field['field_name'], |
173 | - ); |
|
174 | - return $data; |
|
173 | + ); |
|
174 | + return $data; |
|
175 | 175 | |
176 | - } |
|
176 | + } |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Implementation of hook_field(). |
181 | 181 | */ |
182 | 182 | function userreference_field($op, &$node, $field, &$items, $teaser, $page) { |
183 | - switch ($op) { |
|
183 | + switch ($op) { |
|
184 | 184 | case 'validate': |
185 | 185 | // Extract uids to check. |
186 | 186 | $ids = array(); |
187 | - foreach ($items as $delta => $item) { |
|
187 | + foreach ($items as $delta => $item) { |
|
188 | 188 | if (is_array($item) && !empty($item['uid'])) { |
189 | - if (is_numeric($item['uid'])) { |
|
189 | + if (is_numeric($item['uid'])) { |
|
190 | 190 | $ids[] = $item['uid']; |
191 | - } |
|
192 | - else { |
|
191 | + } |
|
192 | + else { |
|
193 | 193 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
194 | 194 | if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
195 | 195 | form_set_error($error_element, t('%name: invalid input.', array('%name' => t($field['widget']['label'])))); |
196 | - } |
|
196 | + } |
|
197 | + } |
|
197 | 198 | } |
198 | - } |
|
199 | - // Prevent performance hog if there are no ids to check. |
|
200 | - if ($ids) { |
|
199 | + // Prevent performance hog if there are no ids to check. |
|
200 | + if ($ids) { |
|
201 | 201 | $refs = _userreference_potential_references($field, '', NULL, $ids); |
202 | 202 | foreach ($items as $delta => $item) { |
203 | - if (is_array($item)) { |
|
203 | + if (is_array($item)) { |
|
204 | 204 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
205 | 205 | if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
206 | 206 | if (!empty($item['uid']) && !isset($refs[$item['uid']])) { |
207 | - form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label'])))); |
|
207 | + form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label'])))); |
|
208 | + } |
|
208 | 209 | } |
209 | - } |
|
210 | 210 | } |
211 | - } |
|
212 | - return $items; |
|
213 | - } |
|
211 | + } |
|
212 | + return $items; |
|
213 | + } |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | 217 | * Implementation of hook_content_is_empty(). |
218 | 218 | */ |
219 | 219 | function userreference_content_is_empty($item, $field) { |
220 | - if (empty($item['uid'])) { |
|
220 | + if (empty($item['uid'])) { |
|
221 | 221 | return TRUE; |
222 | - } |
|
223 | - return FALSE; |
|
222 | + } |
|
223 | + return FALSE; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
227 | 227 | * Implementation of hook_field_formatter_info(). |
228 | 228 | */ |
229 | 229 | function userreference_field_formatter_info() { |
230 | - return array( |
|
230 | + return array( |
|
231 | 231 | 'default' => array( |
232 | - 'label' => t('Default'), |
|
233 | - 'field types' => array('userreference'), |
|
234 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
232 | + 'label' => t('Default'), |
|
233 | + 'field types' => array('userreference'), |
|
234 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
235 | 235 | ), |
236 | 236 | 'plain' => array( |
237 | - 'label' => t('Plain text'), |
|
238 | - 'field types' => array('userreference'), |
|
239 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
237 | + 'label' => t('Plain text'), |
|
238 | + 'field types' => array('userreference'), |
|
239 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
240 | 240 | ), |
241 | - ); |
|
241 | + ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | 245 | * Theme function for 'default' userreference field formatter. |
246 | 246 | */ |
247 | 247 | function theme_userreference_formatter_default($element) { |
248 | - $output = ''; |
|
248 | + $output = ''; |
|
249 | 249 | |
250 | - if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) { |
|
250 | + if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) { |
|
251 | 251 | $output = theme('username', $account); |
252 | - } |
|
253 | - return $output; |
|
252 | + } |
|
253 | + return $output; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
257 | 257 | * Theme function for 'plain' userreference field formatter. |
258 | 258 | */ |
259 | 259 | function theme_userreference_formatter_plain($element) { |
260 | - $output = ''; |
|
261 | - if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) { |
|
260 | + $output = ''; |
|
261 | + if (isset($element['#item']['uid']) && $account = user_load(array('uid' => $element['#item']['uid']))) { |
|
262 | 262 | $output = $account->name; |
263 | - } |
|
264 | - return $output; |
|
263 | + } |
|
264 | + return $output; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -279,32 +279,32 @@ discard block |
||
279 | 279 | * differently. |
280 | 280 | */ |
281 | 281 | function userreference_widget_info() { |
282 | - return array( |
|
282 | + return array( |
|
283 | 283 | 'userreference_select' => array( |
284 | - 'label' => t('Select list'), |
|
285 | - 'field types' => array('userreference'), |
|
286 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
287 | - 'callbacks' => array( |
|
284 | + 'label' => t('Select list'), |
|
285 | + 'field types' => array('userreference'), |
|
286 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
287 | + 'callbacks' => array( |
|
288 | 288 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
289 | - ), |
|
289 | + ), |
|
290 | 290 | ), |
291 | 291 | 'userreference_buttons' => array( |
292 | - 'label' => t('Check boxes/radio buttons'), |
|
293 | - 'field types' => array('userreference'), |
|
294 | - 'multiple values' => CONTENT_HANDLE_MODULE, |
|
295 | - 'callbacks' => array( |
|
292 | + 'label' => t('Check boxes/radio buttons'), |
|
293 | + 'field types' => array('userreference'), |
|
294 | + 'multiple values' => CONTENT_HANDLE_MODULE, |
|
295 | + 'callbacks' => array( |
|
296 | 296 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
297 | - ), |
|
297 | + ), |
|
298 | 298 | ), |
299 | 299 | 'userreference_autocomplete' => array( |
300 | - 'label' => t('Autocomplete text field'), |
|
301 | - 'field types' => array('userreference'), |
|
302 | - 'multiple values' => CONTENT_HANDLE_CORE, |
|
303 | - 'callbacks' => array( |
|
300 | + 'label' => t('Autocomplete text field'), |
|
301 | + 'field types' => array('userreference'), |
|
302 | + 'multiple values' => CONTENT_HANDLE_CORE, |
|
303 | + 'callbacks' => array( |
|
304 | 304 | 'default value' => CONTENT_CALLBACK_DEFAULT, |
305 | - ), |
|
305 | + ), |
|
306 | 306 | ), |
307 | - ); |
|
307 | + ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -320,23 +320,23 @@ discard block |
||
320 | 320 | * (see nodereference and userreference). |
321 | 321 | */ |
322 | 322 | function userreference_elements() { |
323 | - return array( |
|
323 | + return array( |
|
324 | 324 | 'userreference_select' => array( |
325 | - '#input' => TRUE, |
|
326 | - '#columns' => array('uid'), '#delta' => 0, |
|
327 | - '#process' => array('userreference_select_process'), |
|
325 | + '#input' => TRUE, |
|
326 | + '#columns' => array('uid'), '#delta' => 0, |
|
327 | + '#process' => array('userreference_select_process'), |
|
328 | 328 | ), |
329 | 329 | 'userreference_buttons' => array( |
330 | - '#input' => TRUE, |
|
331 | - '#columns' => array('uid'), '#delta' => 0, |
|
332 | - '#process' => array('userreference_buttons_process'), |
|
330 | + '#input' => TRUE, |
|
331 | + '#columns' => array('uid'), '#delta' => 0, |
|
332 | + '#process' => array('userreference_buttons_process'), |
|
333 | 333 | ), |
334 | 334 | 'userreference_autocomplete' => array( |
335 | - '#input' => TRUE, |
|
336 | - '#columns' => array('name'), '#delta' => 0, |
|
337 | - '#process' => array('userreference_autocomplete_process'), |
|
338 | - '#autocomplete_path' => FALSE, |
|
339 | - ), |
|
335 | + '#input' => TRUE, |
|
336 | + '#columns' => array('name'), '#delta' => 0, |
|
337 | + '#process' => array('userreference_autocomplete_process'), |
|
338 | + '#autocomplete_path' => FALSE, |
|
339 | + ), |
|
340 | 340 | ); |
341 | 341 | } |
342 | 342 | |
@@ -344,45 +344,45 @@ discard block |
||
344 | 344 | * Implementation of hook_widget_settings(). |
345 | 345 | */ |
346 | 346 | function userreference_widget_settings($op, $widget) { |
347 | - switch ($op) { |
|
347 | + switch ($op) { |
|
348 | 348 | case 'form': |
349 | 349 | $form = array(); |
350 | - $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
351 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
352 | - if ($widget['type'] == 'userreference_autocomplete') { |
|
350 | + $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
351 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
352 | + if ($widget['type'] == 'userreference_autocomplete') { |
|
353 | 353 | $form['autocomplete_match'] = array( |
354 | - '#type' => 'select', |
|
355 | - '#title' => t('Autocomplete matching'), |
|
356 | - '#default_value' => $match, |
|
357 | - '#options' => array( |
|
354 | + '#type' => 'select', |
|
355 | + '#title' => t('Autocomplete matching'), |
|
356 | + '#default_value' => $match, |
|
357 | + '#options' => array( |
|
358 | 358 | 'starts_with' => t('Starts with'), |
359 | 359 | 'contains' => t('Contains'), |
360 | - ), |
|
361 | - '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'), |
|
360 | + ), |
|
361 | + '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'), |
|
362 | 362 | ); |
363 | 363 | $form['size'] = array( |
364 | - '#type' => 'textfield', |
|
365 | - '#title' => t('Size of textfield'), |
|
366 | - '#default_value' => $size, |
|
367 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
368 | - '#required' => TRUE, |
|
364 | + '#type' => 'textfield', |
|
365 | + '#title' => t('Size of textfield'), |
|
366 | + '#default_value' => $size, |
|
367 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
368 | + '#required' => TRUE, |
|
369 | 369 | ); |
370 | - } |
|
371 | - else { |
|
370 | + } |
|
371 | + else { |
|
372 | 372 | $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
373 | 373 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
374 | - } |
|
375 | - $form['reverse_link'] = array( |
|
374 | + } |
|
375 | + $form['reverse_link'] = array( |
|
376 | 376 | '#type' => 'checkbox', |
377 | 377 | '#title' => t('Reverse link'), |
378 | 378 | '#default_value' => isset($widget['reverse_link']) ? $widget['reverse_link'] : 0, |
379 | 379 | '#description' => t('If selected, a reverse link back to the referencing node will displayed on the referenced user record.'), |
380 | - ); |
|
381 | - return $form; |
|
380 | + ); |
|
381 | + return $form; |
|
382 | 382 | |
383 | 383 | case 'save': |
384 | 384 | return array('autocomplete_match', 'size', 'reverse_link'); |
385 | - } |
|
385 | + } |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -417,30 +417,30 @@ discard block |
||
417 | 417 | * the form item for a single element for this field |
418 | 418 | */ |
419 | 419 | function userreference_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
420 | - switch ($field['widget']['type']) { |
|
420 | + switch ($field['widget']['type']) { |
|
421 | 421 | case 'userreference_select': |
422 | 422 | $element = array( |
423 | 423 | '#type' => 'userreference_select', |
424 | 424 | '#default_value' => $items, |
425 | - ); |
|
426 | - break; |
|
425 | + ); |
|
426 | + break; |
|
427 | 427 | |
428 | 428 | case 'userreference_buttons': |
429 | 429 | $element = array( |
430 | 430 | '#type' => 'userreference_buttons', |
431 | 431 | '#default_value' => $items, |
432 | - ); |
|
433 | - break; |
|
432 | + ); |
|
433 | + break; |
|
434 | 434 | |
435 | 435 | case 'userreference_autocomplete': |
436 | 436 | $element = array( |
437 | 437 | '#type' => 'userreference_autocomplete', |
438 | 438 | '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
439 | 439 | '#value_callback' => 'userreference_autocomplete_value', |
440 | - ); |
|
441 | - break; |
|
442 | - } |
|
443 | - return $element; |
|
440 | + ); |
|
441 | + break; |
|
442 | + } |
|
443 | + return $element; |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -449,12 +449,12 @@ discard block |
||
449 | 449 | * Substitute in the user name for the uid. |
450 | 450 | */ |
451 | 451 | function userreference_autocomplete_value($element, $edit = FALSE) { |
452 | - $field_key = $element['#columns'][0]; |
|
453 | - if (!empty($element['#default_value'][$field_key])) { |
|
452 | + $field_key = $element['#columns'][0]; |
|
453 | + if (!empty($element['#default_value'][$field_key])) { |
|
454 | 454 | $value = db_result(db_query("SELECT name FROM {users} WHERE uid = '%d'", $element['#default_value'][$field_key])); |
455 | 455 | return array($field_key => $value); |
456 | - } |
|
457 | - return array($field_key => NULL); |
|
456 | + } |
|
457 | + return array($field_key => NULL); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
467 | 467 | */ |
468 | 468 | function userreference_select_process($element, $edit, $form_state, $form) { |
469 | - // The userreference_select widget doesn't need to create its own |
|
470 | - // element, it can wrap around the optionwidgets_select element. |
|
471 | - // Add a validation step where the value can be unwrapped. |
|
472 | - $field_key = $element['#columns'][0]; |
|
473 | - $element[$field_key] = array( |
|
469 | + // The userreference_select widget doesn't need to create its own |
|
470 | + // element, it can wrap around the optionwidgets_select element. |
|
471 | + // Add a validation step where the value can be unwrapped. |
|
472 | + $field_key = $element['#columns'][0]; |
|
473 | + $element[$field_key] = array( |
|
474 | 474 | '#type' => 'optionwidgets_select', |
475 | 475 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
476 | 476 | // The following values were set by the content module and need |
@@ -482,12 +482,12 @@ discard block |
||
482 | 482 | '#type_name' => $element['#type_name'], |
483 | 483 | '#delta' => $element['#delta'], |
484 | 484 | '#columns' => $element['#columns'], |
485 | - ); |
|
486 | - if (empty($element[$field_key]['#element_validate'])) { |
|
485 | + ); |
|
486 | + if (empty($element[$field_key]['#element_validate'])) { |
|
487 | 487 | $element[$field_key]['#element_validate'] = array(); |
488 | - } |
|
489 | - array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate'); |
|
490 | - return $element; |
|
488 | + } |
|
489 | + array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate'); |
|
490 | + return $element; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -499,11 +499,11 @@ discard block |
||
499 | 499 | * The $fields array is in $form['#field_info'][$element['#field_name']]. |
500 | 500 | */ |
501 | 501 | function userreference_buttons_process($element, $edit, $form_state, $form) { |
502 | - // The userreference_select widget doesn't need to create its own |
|
503 | - // element, it can wrap around the optionwidgets_select element. |
|
504 | - // Add a validation step where the value can be unwrapped. |
|
505 | - $field_key = $element['#columns'][0]; |
|
506 | - $element[$field_key] = array( |
|
502 | + // The userreference_select widget doesn't need to create its own |
|
503 | + // element, it can wrap around the optionwidgets_select element. |
|
504 | + // Add a validation step where the value can be unwrapped. |
|
505 | + $field_key = $element['#columns'][0]; |
|
506 | + $element[$field_key] = array( |
|
507 | 507 | '#type' => 'optionwidgets_buttons', |
508 | 508 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
509 | 509 | // The following values were set by the content module and need |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | '#type_name' => $element['#type_name'], |
516 | 516 | '#delta' => $element['#delta'], |
517 | 517 | '#columns' => $element['#columns'], |
518 | - ); |
|
519 | - if (empty($element[$field_key]['#element_validate'])) { |
|
518 | + ); |
|
519 | + if (empty($element[$field_key]['#element_validate'])) { |
|
520 | 520 | $element[$field_key]['#element_validate'] = array(); |
521 | - } |
|
522 | - array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate'); |
|
523 | - return $element; |
|
521 | + } |
|
522 | + array_unshift($element[$field_key]['#element_validate'], 'userreference_optionwidgets_validate'); |
|
523 | + return $element; |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -531,13 +531,13 @@ discard block |
||
531 | 531 | * |
532 | 532 | */ |
533 | 533 | function userreference_autocomplete_process($element, $edit, $form_state, $form) { |
534 | - // The userreference autocomplete widget doesn't need to create its own |
|
535 | - // element, it can wrap around the text_textfield element and add an autocomplete |
|
536 | - // path and some extra processing to it. |
|
537 | - // Add a validation step where the value can be unwrapped. |
|
538 | - $field_key = $element['#columns'][0]; |
|
534 | + // The userreference autocomplete widget doesn't need to create its own |
|
535 | + // element, it can wrap around the text_textfield element and add an autocomplete |
|
536 | + // path and some extra processing to it. |
|
537 | + // Add a validation step where the value can be unwrapped. |
|
538 | + $field_key = $element['#columns'][0]; |
|
539 | 539 | |
540 | - $element[$field_key] = array( |
|
540 | + $element[$field_key] = array( |
|
541 | 541 | '#type' => 'text_textfield', |
542 | 542 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
543 | 543 | '#autocomplete_path' => 'userreference/autocomplete/'. $element['#field_name'], |
@@ -550,20 +550,20 @@ discard block |
||
550 | 550 | '#type_name' => $element['#type_name'], |
551 | 551 | '#delta' => $element['#delta'], |
552 | 552 | '#columns' => $element['#columns'], |
553 | - ); |
|
554 | - if (empty($element[$field_key]['#element_validate'])) { |
|
553 | + ); |
|
554 | + if (empty($element[$field_key]['#element_validate'])) { |
|
555 | 555 | $element[$field_key]['#element_validate'] = array(); |
556 | - } |
|
557 | - array_unshift($element[$field_key]['#element_validate'], 'userreference_autocomplete_validate'); |
|
556 | + } |
|
557 | + array_unshift($element[$field_key]['#element_validate'], 'userreference_autocomplete_validate'); |
|
558 | 558 | |
559 | - // Used so that hook_field('validate') knows where to flag an error. |
|
560 | - $element['_error_element'] = array( |
|
559 | + // Used so that hook_field('validate') knows where to flag an error. |
|
560 | + $element['_error_element'] = array( |
|
561 | 561 | '#type' => 'value', |
562 | 562 | // Wrapping the element around a text_textfield element creates a |
563 | 563 | // nested element, so the final id will look like 'field-name-0-uid-uid'. |
564 | 564 | '#value' => implode('][', array_merge($element['#parents'], array($field_key, $field_key))), |
565 | - ); |
|
566 | - return $element; |
|
565 | + ); |
|
566 | + return $element; |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -578,20 +578,20 @@ discard block |
||
578 | 578 | * like optionwidgets are using #element_validate to alter the value. |
579 | 579 | */ |
580 | 580 | function userreference_optionwidgets_validate($element, &$form_state) { |
581 | - $field_key = $element['#columns'][0]; |
|
581 | + $field_key = $element['#columns'][0]; |
|
582 | 582 | |
583 | - $value = $form_state['values']; |
|
584 | - $new_parents = array(); |
|
585 | - foreach ($element['#parents'] as $parent) { |
|
583 | + $value = $form_state['values']; |
|
584 | + $new_parents = array(); |
|
585 | + foreach ($element['#parents'] as $parent) { |
|
586 | 586 | $value = $value[$parent]; |
587 | 587 | // Use === to be sure we get right results if parent is a zero (delta) value. |
588 | 588 | if ($parent === $field_key) { |
589 | - $element['#parents'] = $new_parents; |
|
590 | - form_set_value($element, $value, $form_state); |
|
591 | - break; |
|
589 | + $element['#parents'] = $new_parents; |
|
590 | + form_set_value($element, $value, $form_state); |
|
591 | + break; |
|
592 | 592 | } |
593 | 593 | $new_parents[] = $parent; |
594 | - } |
|
594 | + } |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -602,36 +602,36 @@ discard block |
||
602 | 602 | * back to its original location, 'field-name-0-uid'. |
603 | 603 | */ |
604 | 604 | function userreference_autocomplete_validate($element, &$form_state) { |
605 | - $field_name = $element['#field_name']; |
|
606 | - $type_name = $element['#type_name']; |
|
607 | - $field = content_fields($field_name, $type_name); |
|
608 | - $field_key = $element['#columns'][0]; |
|
609 | - $value = $element['#value'][$field_key]; |
|
610 | - $uid = NULL; |
|
611 | - if (!empty($value)) { |
|
605 | + $field_name = $element['#field_name']; |
|
606 | + $type_name = $element['#type_name']; |
|
607 | + $field = content_fields($field_name, $type_name); |
|
608 | + $field_key = $element['#columns'][0]; |
|
609 | + $value = $element['#value'][$field_key]; |
|
610 | + $uid = NULL; |
|
611 | + if (!empty($value)) { |
|
612 | 612 | $reference = _userreference_potential_references($field, $value, 'equals', NULL, 1); |
613 | 613 | if (empty($reference)) { |
614 | - form_error($element[$field_key], t('%name: found no valid user with that name.', array('%name' => t($field['widget']['label'])))); |
|
614 | + form_error($element[$field_key], t('%name: found no valid user with that name.', array('%name' => t($field['widget']['label'])))); |
|
615 | 615 | } |
616 | 616 | else { |
617 | - $uid = key($reference); |
|
617 | + $uid = key($reference); |
|
618 | + } |
|
618 | 619 | } |
619 | - } |
|
620 | - form_set_value($element, $uid, $form_state); |
|
620 | + form_set_value($element, $uid, $form_state); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
624 | 624 | * Implementation of hook_allowed_values(). |
625 | 625 | */ |
626 | 626 | function userreference_allowed_values($field) { |
627 | - $references = _userreference_potential_references($field); |
|
627 | + $references = _userreference_potential_references($field); |
|
628 | 628 | |
629 | - $options = array(); |
|
630 | - foreach ($references as $key => $value) { |
|
629 | + $options = array(); |
|
630 | + foreach ($references as $key => $value) { |
|
631 | 631 | $options[$key] = $value['rendered']; |
632 | - } |
|
632 | + } |
|
633 | 633 | |
634 | - return $options; |
|
634 | + return $options; |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | /** |
@@ -667,26 +667,26 @@ discard block |
||
667 | 667 | * ) |
668 | 668 | */ |
669 | 669 | function _userreference_potential_references($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
670 | - static $results = array(); |
|
670 | + static $results = array(); |
|
671 | 671 | |
672 | - // Create unique id for static cache. |
|
673 | - $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
674 | - if (!isset($results[$cid])) { |
|
672 | + // Create unique id for static cache. |
|
673 | + $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
674 | + if (!isset($results[$cid])) { |
|
675 | 675 | $references = FALSE; |
676 | 676 | if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') { |
677 | - $references = _userreference_potential_references_views($field, $string, $match, $ids, $limit); |
|
677 | + $references = _userreference_potential_references_views($field, $string, $match, $ids, $limit); |
|
678 | 678 | } |
679 | 679 | // If the view doesn't exist, we got FALSE, and fallback to the regular 'standard mode'. |
680 | 680 | |
681 | 681 | if ($references === FALSE) { |
682 | - $references = _userreference_potential_references_standard($field, $string, $match, $ids, $limit); |
|
682 | + $references = _userreference_potential_references_standard($field, $string, $match, $ids, $limit); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // Store the results. |
686 | 686 | $results[$cid] = !empty($references) ? $references : array(); |
687 | - } |
|
687 | + } |
|
688 | 688 | |
689 | - return $results[$cid]; |
|
689 | + return $results[$cid]; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | * case of Views-defined referenceable users. |
695 | 695 | */ |
696 | 696 | function _userreference_potential_references_views($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
697 | - $view_name = $field['advanced_view']; |
|
697 | + $view_name = $field['advanced_view']; |
|
698 | 698 | |
699 | - if ($view = views_get_view($view_name)) { |
|
699 | + if ($view = views_get_view($view_name)) { |
|
700 | 700 | // We add a display, and let it derive from the 'default' display. |
701 | 701 | // TODO: We should let the user pick a display in the fields settings - sort of requires AHAH... |
702 | 702 | $display = $view->add_display('content_references'); |
@@ -713,12 +713,12 @@ discard block |
||
713 | 713 | // Additional options to let content_plugin_display_references::query() |
714 | 714 | // narrow the results. |
715 | 715 | $options = array( |
716 | - 'table' => 'users', |
|
717 | - 'field_string' => 'name', |
|
718 | - 'string' => $string, |
|
719 | - 'match' => $match, |
|
720 | - 'field_id' => 'uid', |
|
721 | - 'ids' => $ids, |
|
716 | + 'table' => 'users', |
|
717 | + 'field_string' => 'name', |
|
718 | + 'string' => $string, |
|
719 | + 'match' => $match, |
|
720 | + 'field_id' => 'uid', |
|
721 | + 'ids' => $ids, |
|
722 | 722 | ); |
723 | 723 | $view->display_handler->set_option('content_options', $options); |
724 | 724 | |
@@ -731,26 +731,26 @@ discard block |
||
731 | 731 | |
732 | 732 | // Get arguments for the view. |
733 | 733 | if (!empty($field['advanced_view_args'])) { |
734 | - // TODO: Support Tokens using token.module ? |
|
735 | - $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
|
734 | + // TODO: Support Tokens using token.module ? |
|
735 | + $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
|
736 | 736 | } |
737 | 737 | else { |
738 | - $view_args = array(); |
|
738 | + $view_args = array(); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | // We do need name field, so add it if not present (unlikely, but...) |
742 | 742 | $fields = $view->get_items('field', $display); |
743 | 743 | if (!isset($fields['name'])) { |
744 | - $view->add_item($display, 'field', 'users', 'name'); |
|
744 | + $view->add_item($display, 'field', 'users', 'name'); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | // If not set, make all fields inline and define a separator. |
748 | 748 | $options = $view->display_handler->get_option('row_options'); |
749 | 749 | if (empty($options['inline'])) { |
750 | - $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display))); |
|
750 | + $options['inline'] = drupal_map_assoc(array_keys($view->get_items('field', $display))); |
|
751 | 751 | } |
752 | 752 | if (empty($options['separator'])) { |
753 | - $options['separator'] = '-'; |
|
753 | + $options['separator'] = '-'; |
|
754 | 754 | } |
755 | 755 | $view->display_handler->set_option('row_options', $options); |
756 | 756 | |
@@ -759,12 +759,12 @@ discard block |
||
759 | 759 | |
760 | 760 | // Get the results. |
761 | 761 | $result = $view->execute_display($display, $view_args); |
762 | - } |
|
763 | - else { |
|
762 | + } |
|
763 | + else { |
|
764 | 764 | $result = FALSE; |
765 | - } |
|
765 | + } |
|
766 | 766 | |
767 | - return $result; |
|
767 | + return $result; |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -772,112 +772,112 @@ discard block |
||
772 | 772 | * referenceable users defined by user role and status |
773 | 773 | */ |
774 | 774 | function _userreference_potential_references_standard($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) { |
775 | - $where = array(); |
|
776 | - $args = array(); |
|
777 | - $join = array(); |
|
775 | + $where = array(); |
|
776 | + $args = array(); |
|
777 | + $join = array(); |
|
778 | 778 | |
779 | - if ($string !== '') { |
|
779 | + if ($string !== '') { |
|
780 | 780 | $like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE"; |
781 | 781 | $match_clauses = array( |
782 | - 'contains' => "$like '%%%s%%'", |
|
783 | - 'equals' => "= '%s'", |
|
784 | - 'starts_with' => "$like '%s%%'", |
|
782 | + 'contains' => "$like '%%%s%%'", |
|
783 | + 'equals' => "= '%s'", |
|
784 | + 'starts_with' => "$like '%s%%'", |
|
785 | 785 | ); |
786 | 786 | $where[] = 'u.name '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
787 | 787 | $args[] = $string; |
788 | - } |
|
789 | - elseif ($ids) { |
|
788 | + } |
|
789 | + elseif ($ids) { |
|
790 | 790 | $where[] = 'u.uid IN (' . db_placeholders($ids) . ')'; |
791 | 791 | $args = array_merge($args, $ids); |
792 | - } |
|
793 | - else { |
|
792 | + } |
|
793 | + else { |
|
794 | 794 | $where[] = "u.uid > 0"; |
795 | - } |
|
795 | + } |
|
796 | 796 | |
797 | - $roles = array(); |
|
798 | - if (isset($field['referenceable_roles']) && is_array($field['referenceable_roles'])) { |
|
797 | + $roles = array(); |
|
798 | + if (isset($field['referenceable_roles']) && is_array($field['referenceable_roles'])) { |
|
799 | 799 | // keep only selected checkboxes |
800 | 800 | $roles = array_filter($field['referenceable_roles']); |
801 | 801 | // filter invalid values that seems to get through sometimes ?? |
802 | 802 | $roles = array_intersect(array_keys(user_roles(1)), $roles); |
803 | - } |
|
804 | - if (!empty($roles) && !in_array(DRUPAL_AUTHENTICATED_RID, $roles)) { |
|
803 | + } |
|
804 | + if (!empty($roles) && !in_array(DRUPAL_AUTHENTICATED_RID, $roles)) { |
|
805 | 805 | $where[] = "r.rid IN (". implode($roles, ',') .")"; |
806 | 806 | $join[] = 'LEFT JOIN {users_roles} r ON u.uid = r.uid'; |
807 | - } |
|
807 | + } |
|
808 | 808 | |
809 | - if (isset($field['referenceable_status']) && is_numeric($field['referenceable_status'])) { |
|
809 | + if (isset($field['referenceable_status']) && is_numeric($field['referenceable_status'])) { |
|
810 | 810 | $where[] = 'u.status = %d'; |
811 | 811 | $args[] = $field['referenceable_status']; |
812 | - } |
|
812 | + } |
|
813 | 813 | |
814 | - $users = array(); |
|
815 | - $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
816 | - $result = db_query('SELECT u.name, u.uid FROM {users} u '. implode(' ', $join) ." $where_clause ORDER BY u.name ASC", $args); |
|
817 | - while ($user = db_fetch_object($result)) { |
|
814 | + $users = array(); |
|
815 | + $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
816 | + $result = db_query('SELECT u.name, u.uid FROM {users} u '. implode(' ', $join) ." $where_clause ORDER BY u.name ASC", $args); |
|
817 | + while ($user = db_fetch_object($result)) { |
|
818 | 818 | $users[$user->uid] = array( |
819 | - 'title' => $user->name, |
|
820 | - 'rendered' => check_plain($user->name), |
|
819 | + 'title' => $user->name, |
|
820 | + 'rendered' => check_plain($user->name), |
|
821 | 821 | ); |
822 | - } |
|
823 | - return $users; |
|
822 | + } |
|
823 | + return $users; |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
827 | 827 | * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users |
828 | 828 | */ |
829 | 829 | function userreference_autocomplete($field_name, $string = '') { |
830 | - $fields = content_fields(); |
|
831 | - $field = $fields[$field_name]; |
|
832 | - $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains'; |
|
833 | - $matches = array(); |
|
830 | + $fields = content_fields(); |
|
831 | + $field = $fields[$field_name]; |
|
832 | + $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains'; |
|
833 | + $matches = array(); |
|
834 | 834 | |
835 | - $references = _userreference_potential_references($field, $string, $match, array(), 10); |
|
836 | - foreach ($references as $id => $row) { |
|
835 | + $references = _userreference_potential_references($field, $string, $match, array(), 10); |
|
836 | + foreach ($references as $id => $row) { |
|
837 | 837 | // Add a class wrapper for a few required CSS overrides. |
838 | 838 | $matches[$row['title']] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>'; |
839 | - } |
|
840 | - drupal_json($matches); |
|
839 | + } |
|
840 | + drupal_json($matches); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
844 | 844 | * Implementation of hook_user(). |
845 | 845 | */ |
846 | 846 | function userreference_user($type, &$edit, &$account) { |
847 | - switch ($type) { |
|
847 | + switch ($type) { |
|
848 | 848 | case 'load': |
849 | 849 | // Only add links if we are on the user 'view' page. |
850 | 850 | if (arg(0) != 'user' || arg(2)) { |
851 | 851 | return; |
852 | - } |
|
853 | - // find CCK userreference field tables |
|
854 | - // search through them for matching user ids and load those nodes |
|
855 | - $additions = array(); |
|
856 | - $types = content_types(); |
|
857 | - |
|
858 | - // Find the table and columns to search through, if the same |
|
859 | - // table comes up in more than one content type, we only need |
|
860 | - // to search it once. |
|
861 | - $search_tables = array(); |
|
862 | - foreach ($types as $type_name => $type) { |
|
852 | + } |
|
853 | + // find CCK userreference field tables |
|
854 | + // search through them for matching user ids and load those nodes |
|
855 | + $additions = array(); |
|
856 | + $types = content_types(); |
|
857 | + |
|
858 | + // Find the table and columns to search through, if the same |
|
859 | + // table comes up in more than one content type, we only need |
|
860 | + // to search it once. |
|
861 | + $search_tables = array(); |
|
862 | + foreach ($types as $type_name => $type) { |
|
863 | 863 | foreach ($type['fields'] as $field) { |
864 | - // Only add tables when reverse link has been selected. |
|
865 | - if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) { |
|
864 | + // Only add tables when reverse link has been selected. |
|
865 | + if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) { |
|
866 | 866 | $db_info = content_database_info($field); |
867 | 867 | $search_tables[$db_info['table']][] = $db_info['columns']['uid']['column']; |
868 | - } |
|
868 | + } |
|
869 | + } |
|
869 | 870 | } |
870 | - } |
|
871 | - foreach ($search_tables as $table => $columns) { |
|
871 | + foreach ($search_tables as $table => $columns) { |
|
872 | 872 | foreach ($columns as $column) { |
873 | - $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); |
|
874 | - while ($data = db_fetch_object($ids)) { |
|
873 | + $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); |
|
874 | + while ($data = db_fetch_object($ids)) { |
|
875 | 875 | $additions[$data->type][$data->nid] = $data->title; |
876 | - } |
|
876 | + } |
|
877 | 877 | } |
878 | - } |
|
879 | - $account->userreference = $additions; |
|
880 | - break; |
|
878 | + } |
|
879 | + $account->userreference = $additions; |
|
880 | + break; |
|
881 | 881 | |
882 | 882 | case 'view': |
883 | 883 | if (!empty($account->userreference)) { |
@@ -885,28 +885,28 @@ discard block |
||
885 | 885 | $additions = array(); |
886 | 886 | $values = array(); |
887 | 887 | foreach ($account->userreference as $node_type => $nodes) { |
888 | - foreach ($nodes as $nid => $title) { |
|
888 | + foreach ($nodes as $nid => $title) { |
|
889 | 889 | $values[$node_type][] = l($title, 'node/'. $nid); |
890 | - } |
|
891 | - if (isset($values[$node_type])) { |
|
890 | + } |
|
891 | + if (isset($values[$node_type])) { |
|
892 | 892 | $additions[] = array( |
893 | - '#type' => 'user_profile_item', |
|
894 | - '#title' => check_plain($node_types[$node_type]['name']), |
|
895 | - '#value' => theme('item_list', $values[$node_type]), |
|
893 | + '#type' => 'user_profile_item', |
|
894 | + '#title' => check_plain($node_types[$node_type]['name']), |
|
895 | + '#value' => theme('item_list', $values[$node_type]), |
|
896 | 896 | ); |
897 | - } |
|
897 | + } |
|
898 | 898 | } |
899 | 899 | if ($additions) { |
900 | - $account->content['userreference'] = $additions + array( |
|
900 | + $account->content['userreference'] = $additions + array( |
|
901 | 901 | '#type' => 'user_profile_category', |
902 | 902 | '#attributes' => array('class' => 'user-member'), |
903 | 903 | '#title' => t('Related content'), |
904 | 904 | '#weight' => 10, |
905 | - ); |
|
905 | + ); |
|
906 | 906 | } |
907 | - } |
|
908 | - break; |
|
909 | - } |
|
907 | + } |
|
908 | + break; |
|
909 | + } |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | /** |
@@ -921,13 +921,13 @@ discard block |
||
921 | 921 | * $element['#delta] is the position of this element in the group |
922 | 922 | */ |
923 | 923 | function theme_userreference_select($element) { |
924 | - return $element['#children']; |
|
924 | + return $element['#children']; |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | function theme_userreference_buttons($element) { |
928 | - return $element['#children']; |
|
928 | + return $element['#children']; |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | function theme_userreference_autocomplete($element) { |
932 | - return $element['#children']; |
|
932 | + return $element['#children']; |
|
933 | 933 | } |
934 | 934 | \ No newline at end of file |
@@ -70,108 +70,108 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function userreference_field_settings($op, $field) { |
72 | 72 | switch ($op) { |
73 | - case 'form': |
|
74 | - $form = array(); |
|
75 | - $form['referenceable_roles'] = array( |
|
76 | - '#type' => 'checkboxes', |
|
77 | - '#title' => t('User roles that can be referenced'), |
|
78 | - '#default_value' => isset($field['referenceable_roles']) && is_array($field['referenceable_roles']) ? array_filter($field['referenceable_roles']) : array(), |
|
79 | - '#options' => user_roles(1), |
|
80 | - ); |
|
81 | - $form['referenceable_status'] = array( |
|
82 | - '#type' => 'radios', |
|
83 | - '#title' => t('User status that can be referenced'), |
|
84 | - '#default_value' => isset($field['referenceable_status']) ? $field['referenceable_status'] : '', |
|
85 | - '#options' => array('' => t('All users'), 1 => t('Active users'), 0 => t('Blocked users')), |
|
86 | - ); |
|
87 | - if (module_exists('views')) { |
|
88 | - $views = array('--' => '--'); |
|
89 | - $all_views = views_get_all_views(); |
|
90 | - foreach ($all_views as $view) { |
|
91 | - // Only 'users' views that have fields will work for our purpose. |
|
92 | - if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) { |
|
93 | - if ($view->type == 'Default') { |
|
94 | - $views[t('Default Views')][$view->name] = $view->name; |
|
95 | - } |
|
96 | - else { |
|
97 | - $views[t('Existing Views')][$view->name] = $view->name; |
|
98 | - } |
|
73 | + case 'form': |
|
74 | + $form = array(); |
|
75 | + $form['referenceable_roles'] = array( |
|
76 | + '#type' => 'checkboxes', |
|
77 | + '#title' => t('User roles that can be referenced'), |
|
78 | + '#default_value' => isset($field['referenceable_roles']) && is_array($field['referenceable_roles']) ? array_filter($field['referenceable_roles']) : array(), |
|
79 | + '#options' => user_roles(1), |
|
80 | + ); |
|
81 | + $form['referenceable_status'] = array( |
|
82 | + '#type' => 'radios', |
|
83 | + '#title' => t('User status that can be referenced'), |
|
84 | + '#default_value' => isset($field['referenceable_status']) ? $field['referenceable_status'] : '', |
|
85 | + '#options' => array('' => t('All users'), 1 => t('Active users'), 0 => t('Blocked users')), |
|
86 | + ); |
|
87 | + if (module_exists('views')) { |
|
88 | + $views = array('--' => '--'); |
|
89 | + $all_views = views_get_all_views(); |
|
90 | + foreach ($all_views as $view) { |
|
91 | + // Only 'users' views that have fields will work for our purpose. |
|
92 | + if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) { |
|
93 | + if ($view->type == 'Default') { |
|
94 | + $views[t('Default Views')][$view->name] = $view->name; |
|
95 | + } |
|
96 | + else { |
|
97 | + $views[t('Existing Views')][$view->name] = $view->name; |
|
99 | 98 | } |
100 | - } |
|
101 | - |
|
102 | - $form['advanced'] = array( |
|
103 | - '#type' => 'fieldset', |
|
104 | - '#title' => t('Advanced - Users that can be referenced (View)'), |
|
105 | - '#collapsible' => TRUE, |
|
106 | - '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
107 | - ); |
|
108 | - if (count($views) > 1) { |
|
109 | - $form['advanced']['advanced_view'] = array( |
|
110 | - '#type' => 'select', |
|
111 | - '#title' => t('View used to select the users'), |
|
112 | - '#options' => $views, |
|
113 | - '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
|
114 | - '#description' => t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>') . |
|
115 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
116 | - ); |
|
117 | - $form['advanced']['advanced_view_args'] = array( |
|
118 | - '#type' => 'textfield', |
|
119 | - '#title' => t('View arguments'), |
|
120 | - '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
|
121 | - '#required' => FALSE, |
|
122 | - '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
|
123 | - ); |
|
124 | - } |
|
125 | - else { |
|
126 | - $form['advanced']['no_view_help'] = array( |
|
127 | - '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
128 | - t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
129 | - ); |
|
130 | 99 | } |
131 | 100 | } |
132 | - return $form; |
|
133 | 101 | |
134 | - case 'save': |
|
135 | - $settings = array('referenceable_roles', 'referenceable_status'); |
|
136 | - if (module_exists('views')) { |
|
137 | - $settings[] = 'advanced_view'; |
|
138 | - $settings[] = 'advanced_view_args'; |
|
102 | + $form['advanced'] = array( |
|
103 | + '#type' => 'fieldset', |
|
104 | + '#title' => t('Advanced - Users that can be referenced (View)'), |
|
105 | + '#collapsible' => TRUE, |
|
106 | + '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--', |
|
107 | + ); |
|
108 | + if (count($views) > 1) { |
|
109 | + $form['advanced']['advanced_view'] = array( |
|
110 | + '#type' => 'select', |
|
111 | + '#title' => t('View used to select the users'), |
|
112 | + '#options' => $views, |
|
113 | + '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
|
114 | + '#description' => t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>') . |
|
115 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
116 | + ); |
|
117 | + $form['advanced']['advanced_view_args'] = array( |
|
118 | + '#type' => 'textfield', |
|
119 | + '#title' => t('View arguments'), |
|
120 | + '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '', |
|
121 | + '#required' => FALSE, |
|
122 | + '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
|
123 | + ); |
|
124 | + } |
|
125 | + else { |
|
126 | + $form['advanced']['no_view_help'] = array( |
|
127 | + '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
128 | + t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
|
129 | + ); |
|
139 | 130 | } |
140 | - return $settings; |
|
131 | + } |
|
132 | + return $form; |
|
141 | 133 | |
142 | - case 'database columns': |
|
143 | - $columns = array( |
|
144 | - 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
|
145 | - ); |
|
146 | - return $columns; |
|
147 | - |
|
148 | - case 'views data': |
|
149 | - $data = content_views_field_views_data($field); |
|
150 | - $db_info = content_database_info($field); |
|
151 | - $table_alias = content_views_tablename($field); |
|
152 | - |
|
153 | - // Filter : swap the handler to the 'in' operator. |
|
154 | - $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
155 | - // Argument: get the user name for summaries. |
|
156 | - // We need to join a new instance of the users table. |
|
157 | - $data["users_$table_alias"]['table']['join']['node'] = array( |
|
158 | - 'table' => 'users', |
|
159 | - 'field' => 'uid', |
|
160 | - 'left_table' => $table_alias, |
|
161 | - 'left_field' => $field['field_name'] .'_uid', |
|
162 | - ); |
|
163 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name'; |
|
166 | - // Relationship: Add a relationship for related user. |
|
167 | - $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array( |
|
168 | - 'base' => 'users', |
|
169 | - 'field' => $db_info['columns']['uid']['column'], |
|
170 | - 'handler' => 'content_handler_relationship', |
|
171 | - 'label' => t($field['widget']['label']), |
|
172 | - 'content_field_name' => $field['field_name'], |
|
173 | - ); |
|
174 | - return $data; |
|
134 | + case 'save': |
|
135 | + $settings = array('referenceable_roles', 'referenceable_status'); |
|
136 | + if (module_exists('views')) { |
|
137 | + $settings[] = 'advanced_view'; |
|
138 | + $settings[] = 'advanced_view_args'; |
|
139 | + } |
|
140 | + return $settings; |
|
141 | + |
|
142 | + case 'database columns': |
|
143 | + $columns = array( |
|
144 | + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'index' => TRUE), |
|
145 | + ); |
|
146 | + return $columns; |
|
147 | + |
|
148 | + case 'views data': |
|
149 | + $data = content_views_field_views_data($field); |
|
150 | + $db_info = content_database_info($field); |
|
151 | + $table_alias = content_views_tablename($field); |
|
152 | + |
|
153 | + // Filter : swap the handler to the 'in' operator. |
|
154 | + $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
155 | + // Argument: get the user name for summaries. |
|
156 | + // We need to join a new instance of the users table. |
|
157 | + $data["users_$table_alias"]['table']['join']['node'] = array( |
|
158 | + 'table' => 'users', |
|
159 | + 'field' => 'uid', |
|
160 | + 'left_table' => $table_alias, |
|
161 | + 'left_field' => $field['field_name'] .'_uid', |
|
162 | + ); |
|
163 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | + $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name'; |
|
166 | + // Relationship: Add a relationship for related user. |
|
167 | + $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array( |
|
168 | + 'base' => 'users', |
|
169 | + 'field' => $db_info['columns']['uid']['column'], |
|
170 | + 'handler' => 'content_handler_relationship', |
|
171 | + 'label' => t($field['widget']['label']), |
|
172 | + 'content_field_name' => $field['field_name'], |
|
173 | + ); |
|
174 | + return $data; |
|
175 | 175 | |
176 | 176 | } |
177 | 177 | } |
@@ -181,35 +181,35 @@ discard block |
||
181 | 181 | */ |
182 | 182 | function userreference_field($op, &$node, $field, &$items, $teaser, $page) { |
183 | 183 | switch ($op) { |
184 | - case 'validate': |
|
185 | - // Extract uids to check. |
|
186 | - $ids = array(); |
|
187 | - foreach ($items as $delta => $item) { |
|
188 | - if (is_array($item) && !empty($item['uid'])) { |
|
189 | - if (is_numeric($item['uid'])) { |
|
190 | - $ids[] = $item['uid']; |
|
191 | - } |
|
192 | - else { |
|
193 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
194 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
195 | - form_set_error($error_element, t('%name: invalid input.', array('%name' => t($field['widget']['label'])))); |
|
196 | - } |
|
184 | + case 'validate': |
|
185 | + // Extract uids to check. |
|
186 | + $ids = array(); |
|
187 | + foreach ($items as $delta => $item) { |
|
188 | + if (is_array($item) && !empty($item['uid'])) { |
|
189 | + if (is_numeric($item['uid'])) { |
|
190 | + $ids[] = $item['uid']; |
|
191 | + } |
|
192 | + else { |
|
193 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
194 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
195 | + form_set_error($error_element, t('%name: invalid input.', array('%name' => t($field['widget']['label'])))); |
|
197 | 196 | } |
198 | 197 | } |
199 | - // Prevent performance hog if there are no ids to check. |
|
200 | - if ($ids) { |
|
201 | - $refs = _userreference_potential_references($field, '', NULL, $ids); |
|
202 | - foreach ($items as $delta => $item) { |
|
203 | - if (is_array($item)) { |
|
204 | - $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
205 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
206 | - if (!empty($item['uid']) && !isset($refs[$item['uid']])) { |
|
207 | - form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label'])))); |
|
208 | - } |
|
198 | + } |
|
199 | + // Prevent performance hog if there are no ids to check. |
|
200 | + if ($ids) { |
|
201 | + $refs = _userreference_potential_references($field, '', NULL, $ids); |
|
202 | + foreach ($items as $delta => $item) { |
|
203 | + if (is_array($item)) { |
|
204 | + $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
|
205 | + if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
206 | + if (!empty($item['uid']) && !isset($refs[$item['uid']])) { |
|
207 | + form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label'])))); |
|
209 | 208 | } |
210 | 209 | } |
211 | 210 | } |
212 | - return $items; |
|
211 | + } |
|
212 | + return $items; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
@@ -345,43 +345,43 @@ discard block |
||
345 | 345 | */ |
346 | 346 | function userreference_widget_settings($op, $widget) { |
347 | 347 | switch ($op) { |
348 | - case 'form': |
|
349 | - $form = array(); |
|
350 | - $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
351 | - $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
352 | - if ($widget['type'] == 'userreference_autocomplete') { |
|
353 | - $form['autocomplete_match'] = array( |
|
354 | - '#type' => 'select', |
|
355 | - '#title' => t('Autocomplete matching'), |
|
356 | - '#default_value' => $match, |
|
357 | - '#options' => array( |
|
358 | - 'starts_with' => t('Starts with'), |
|
359 | - 'contains' => t('Contains'), |
|
360 | - ), |
|
361 | - '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'), |
|
362 | - ); |
|
363 | - $form['size'] = array( |
|
364 | - '#type' => 'textfield', |
|
365 | - '#title' => t('Size of textfield'), |
|
366 | - '#default_value' => $size, |
|
367 | - '#element_validate' => array('_element_validate_integer_positive'), |
|
368 | - '#required' => TRUE, |
|
369 | - ); |
|
370 | - } |
|
371 | - else { |
|
372 | - $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
|
373 | - $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
374 | - } |
|
375 | - $form['reverse_link'] = array( |
|
376 | - '#type' => 'checkbox', |
|
377 | - '#title' => t('Reverse link'), |
|
378 | - '#default_value' => isset($widget['reverse_link']) ? $widget['reverse_link'] : 0, |
|
379 | - '#description' => t('If selected, a reverse link back to the referencing node will displayed on the referenced user record.'), |
|
348 | + case 'form': |
|
349 | + $form = array(); |
|
350 | + $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains'; |
|
351 | + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
352 | + if ($widget['type'] == 'userreference_autocomplete') { |
|
353 | + $form['autocomplete_match'] = array( |
|
354 | + '#type' => 'select', |
|
355 | + '#title' => t('Autocomplete matching'), |
|
356 | + '#default_value' => $match, |
|
357 | + '#options' => array( |
|
358 | + 'starts_with' => t('Starts with'), |
|
359 | + 'contains' => t('Contains'), |
|
360 | + ), |
|
361 | + '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of users.'), |
|
380 | 362 | ); |
381 | - return $form; |
|
363 | + $form['size'] = array( |
|
364 | + '#type' => 'textfield', |
|
365 | + '#title' => t('Size of textfield'), |
|
366 | + '#default_value' => $size, |
|
367 | + '#element_validate' => array('_element_validate_integer_positive'), |
|
368 | + '#required' => TRUE, |
|
369 | + ); |
|
370 | + } |
|
371 | + else { |
|
372 | + $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
|
373 | + $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
374 | + } |
|
375 | + $form['reverse_link'] = array( |
|
376 | + '#type' => 'checkbox', |
|
377 | + '#title' => t('Reverse link'), |
|
378 | + '#default_value' => isset($widget['reverse_link']) ? $widget['reverse_link'] : 0, |
|
379 | + '#description' => t('If selected, a reverse link back to the referencing node will displayed on the referenced user record.'), |
|
380 | + ); |
|
381 | + return $form; |
|
382 | 382 | |
383 | - case 'save': |
|
384 | - return array('autocomplete_match', 'size', 'reverse_link'); |
|
383 | + case 'save': |
|
384 | + return array('autocomplete_match', 'size', 'reverse_link'); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | |
@@ -418,27 +418,27 @@ discard block |
||
418 | 418 | */ |
419 | 419 | function userreference_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
420 | 420 | switch ($field['widget']['type']) { |
421 | - case 'userreference_select': |
|
422 | - $element = array( |
|
423 | - '#type' => 'userreference_select', |
|
424 | - '#default_value' => $items, |
|
425 | - ); |
|
426 | - break; |
|
421 | + case 'userreference_select': |
|
422 | + $element = array( |
|
423 | + '#type' => 'userreference_select', |
|
424 | + '#default_value' => $items, |
|
425 | + ); |
|
426 | + break; |
|
427 | 427 | |
428 | - case 'userreference_buttons': |
|
429 | - $element = array( |
|
430 | - '#type' => 'userreference_buttons', |
|
431 | - '#default_value' => $items, |
|
432 | - ); |
|
433 | - break; |
|
428 | + case 'userreference_buttons': |
|
429 | + $element = array( |
|
430 | + '#type' => 'userreference_buttons', |
|
431 | + '#default_value' => $items, |
|
432 | + ); |
|
433 | + break; |
|
434 | 434 | |
435 | - case 'userreference_autocomplete': |
|
436 | - $element = array( |
|
437 | - '#type' => 'userreference_autocomplete', |
|
438 | - '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
439 | - '#value_callback' => 'userreference_autocomplete_value', |
|
440 | - ); |
|
441 | - break; |
|
435 | + case 'userreference_autocomplete': |
|
436 | + $element = array( |
|
437 | + '#type' => 'userreference_autocomplete', |
|
438 | + '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL, |
|
439 | + '#value_callback' => 'userreference_autocomplete_value', |
|
440 | + ); |
|
441 | + break; |
|
442 | 442 | } |
443 | 443 | return $element; |
444 | 444 | } |
@@ -845,67 +845,67 @@ discard block |
||
845 | 845 | */ |
846 | 846 | function userreference_user($type, &$edit, &$account) { |
847 | 847 | switch ($type) { |
848 | - case 'load': |
|
849 | - // Only add links if we are on the user 'view' page. |
|
850 | - if (arg(0) != 'user' || arg(2)) { |
|
851 | - return; |
|
852 | - } |
|
853 | - // find CCK userreference field tables |
|
854 | - // search through them for matching user ids and load those nodes |
|
855 | - $additions = array(); |
|
856 | - $types = content_types(); |
|
857 | - |
|
858 | - // Find the table and columns to search through, if the same |
|
859 | - // table comes up in more than one content type, we only need |
|
860 | - // to search it once. |
|
861 | - $search_tables = array(); |
|
862 | - foreach ($types as $type_name => $type) { |
|
863 | - foreach ($type['fields'] as $field) { |
|
864 | - // Only add tables when reverse link has been selected. |
|
865 | - if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) { |
|
866 | - $db_info = content_database_info($field); |
|
867 | - $search_tables[$db_info['table']][] = $db_info['columns']['uid']['column']; |
|
868 | - } |
|
848 | + case 'load': |
|
849 | + // Only add links if we are on the user 'view' page. |
|
850 | + if (arg(0) != 'user' || arg(2)) { |
|
851 | + return; |
|
852 | + } |
|
853 | + // find CCK userreference field tables |
|
854 | + // search through them for matching user ids and load those nodes |
|
855 | + $additions = array(); |
|
856 | + $types = content_types(); |
|
857 | + |
|
858 | + // Find the table and columns to search through, if the same |
|
859 | + // table comes up in more than one content type, we only need |
|
860 | + // to search it once. |
|
861 | + $search_tables = array(); |
|
862 | + foreach ($types as $type_name => $type) { |
|
863 | + foreach ($type['fields'] as $field) { |
|
864 | + // Only add tables when reverse link has been selected. |
|
865 | + if ($field['type'] == 'userreference' && !empty($field['widget']['reverse_link'])) { |
|
866 | + $db_info = content_database_info($field); |
|
867 | + $search_tables[$db_info['table']][] = $db_info['columns']['uid']['column']; |
|
869 | 868 | } |
870 | 869 | } |
871 | - foreach ($search_tables as $table => $columns) { |
|
872 | - foreach ($columns as $column) { |
|
873 | - $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); |
|
874 | - while ($data = db_fetch_object($ids)) { |
|
875 | - $additions[$data->type][$data->nid] = $data->title; |
|
876 | - } |
|
870 | + } |
|
871 | + foreach ($search_tables as $table => $columns) { |
|
872 | + foreach ($columns as $column) { |
|
873 | + $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); |
|
874 | + while ($data = db_fetch_object($ids)) { |
|
875 | + $additions[$data->type][$data->nid] = $data->title; |
|
877 | 876 | } |
878 | 877 | } |
879 | - $account->userreference = $additions; |
|
880 | - break; |
|
878 | + } |
|
879 | + $account->userreference = $additions; |
|
880 | + break; |
|
881 | 881 | |
882 | - case 'view': |
|
883 | - if (!empty($account->userreference)) { |
|
884 | - $node_types = content_types(); |
|
885 | - $additions = array(); |
|
886 | - $values = array(); |
|
887 | - foreach ($account->userreference as $node_type => $nodes) { |
|
888 | - foreach ($nodes as $nid => $title) { |
|
889 | - $values[$node_type][] = l($title, 'node/'. $nid); |
|
890 | - } |
|
891 | - if (isset($values[$node_type])) { |
|
892 | - $additions[] = array( |
|
893 | - '#type' => 'user_profile_item', |
|
894 | - '#title' => check_plain($node_types[$node_type]['name']), |
|
895 | - '#value' => theme('item_list', $values[$node_type]), |
|
896 | - ); |
|
897 | - } |
|
882 | + case 'view': |
|
883 | + if (!empty($account->userreference)) { |
|
884 | + $node_types = content_types(); |
|
885 | + $additions = array(); |
|
886 | + $values = array(); |
|
887 | + foreach ($account->userreference as $node_type => $nodes) { |
|
888 | + foreach ($nodes as $nid => $title) { |
|
889 | + $values[$node_type][] = l($title, 'node/'. $nid); |
|
898 | 890 | } |
899 | - if ($additions) { |
|
900 | - $account->content['userreference'] = $additions + array( |
|
901 | - '#type' => 'user_profile_category', |
|
902 | - '#attributes' => array('class' => 'user-member'), |
|
903 | - '#title' => t('Related content'), |
|
904 | - '#weight' => 10, |
|
891 | + if (isset($values[$node_type])) { |
|
892 | + $additions[] = array( |
|
893 | + '#type' => 'user_profile_item', |
|
894 | + '#title' => check_plain($node_types[$node_type]['name']), |
|
895 | + '#value' => theme('item_list', $values[$node_type]), |
|
905 | 896 | ); |
906 | 897 | } |
907 | 898 | } |
908 | - break; |
|
899 | + if ($additions) { |
|
900 | + $account->content['userreference'] = $additions + array( |
|
901 | + '#type' => 'user_profile_category', |
|
902 | + '#attributes' => array('class' => 'user-member'), |
|
903 | + '#title' => t('Related content'), |
|
904 | + '#weight' => 10, |
|
905 | + ); |
|
906 | + } |
|
907 | + } |
|
908 | + break; |
|
909 | 909 | } |
910 | 910 | } |
911 | 911 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function userreference_ctools_plugin_directory($module, $plugin) { |
50 | 50 | if ($module == 'ctools' && $plugin == 'relationships') { |
51 | - return 'panels/' . $plugin; |
|
51 | + return 'panels/'.$plugin; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | '#title' => t('View used to select the users'), |
112 | 112 | '#options' => $views, |
113 | 113 | '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--', |
114 | - '#description' => t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>') . |
|
114 | + '#description' => t('<p>Choose the "Views module" view that selects the users that can be referenced.<br />Note:</p>'). |
|
115 | 115 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
116 | 116 | ); |
117 | 117 | $form['advanced']['advanced_view_args'] = array( |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | else { |
126 | 126 | $form['advanced']['no_view_help'] = array( |
127 | - '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
|
127 | + '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>'). |
|
128 | 128 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
129 | 129 | ); |
130 | 130 | } |
@@ -151,20 +151,20 @@ discard block |
||
151 | 151 | $table_alias = content_views_tablename($field); |
152 | 152 | |
153 | 153 | // Filter : swap the handler to the 'in' operator. |
154 | - $data[$table_alias][$field['field_name'] .'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
154 | + $data[$table_alias][$field['field_name'].'_uid']['filter']['handler'] = 'content_handler_filter_many_to_one'; |
|
155 | 155 | // Argument: get the user name for summaries. |
156 | 156 | // We need to join a new instance of the users table. |
157 | 157 | $data["users_$table_alias"]['table']['join']['node'] = array( |
158 | 158 | 'table' => 'users', |
159 | 159 | 'field' => 'uid', |
160 | 160 | 'left_table' => $table_alias, |
161 | - 'left_field' => $field['field_name'] .'_uid', |
|
161 | + 'left_field' => $field['field_name'].'_uid', |
|
162 | 162 | ); |
163 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | - $data[$table_alias][$field['field_name'] .'_uid']['argument']['name field'] = 'name'; |
|
163 | + $data[$table_alias][$field['field_name'].'_uid']['argument']['handler'] = 'content_handler_argument_reference'; |
|
164 | + $data[$table_alias][$field['field_name'].'_uid']['argument']['name table'] = "users_$table_alias"; |
|
165 | + $data[$table_alias][$field['field_name'].'_uid']['argument']['name field'] = 'name'; |
|
166 | 166 | // Relationship: Add a relationship for related user. |
167 | - $data[$table_alias][$field['field_name'] .'_uid']['relationship'] = array( |
|
167 | + $data[$table_alias][$field['field_name'].'_uid']['relationship'] = array( |
|
168 | 168 | 'base' => 'users', |
169 | 169 | 'field' => $db_info['columns']['uid']['column'], |
170 | 170 | 'handler' => 'content_handler_relationship', |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | * Substitute in the user name for the uid. |
450 | 450 | */ |
451 | 451 | function userreference_autocomplete_value($element, $edit = FALSE) { |
452 | - $field_key = $element['#columns'][0]; |
|
452 | + $field_key = $element['#columns'][0]; |
|
453 | 453 | if (!empty($element['#default_value'][$field_key])) { |
454 | 454 | $value = db_result(db_query("SELECT name FROM {users} WHERE uid = '%d'", $element['#default_value'][$field_key])); |
455 | 455 | return array($field_key => $value); |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | // The userreference_select widget doesn't need to create its own |
470 | 470 | // element, it can wrap around the optionwidgets_select element. |
471 | 471 | // Add a validation step where the value can be unwrapped. |
472 | - $field_key = $element['#columns'][0]; |
|
472 | + $field_key = $element['#columns'][0]; |
|
473 | 473 | $element[$field_key] = array( |
474 | 474 | '#type' => 'optionwidgets_select', |
475 | 475 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | // The userreference_select widget doesn't need to create its own |
503 | 503 | // element, it can wrap around the optionwidgets_select element. |
504 | 504 | // Add a validation step where the value can be unwrapped. |
505 | - $field_key = $element['#columns'][0]; |
|
505 | + $field_key = $element['#columns'][0]; |
|
506 | 506 | $element[$field_key] = array( |
507 | 507 | '#type' => 'optionwidgets_buttons', |
508 | 508 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
@@ -535,12 +535,12 @@ discard block |
||
535 | 535 | // element, it can wrap around the text_textfield element and add an autocomplete |
536 | 536 | // path and some extra processing to it. |
537 | 537 | // Add a validation step where the value can be unwrapped. |
538 | - $field_key = $element['#columns'][0]; |
|
538 | + $field_key = $element['#columns'][0]; |
|
539 | 539 | |
540 | 540 | $element[$field_key] = array( |
541 | 541 | '#type' => 'text_textfield', |
542 | 542 | '#default_value' => isset($element['#value']) ? $element['#value'] : '', |
543 | - '#autocomplete_path' => 'userreference/autocomplete/'. $element['#field_name'], |
|
543 | + '#autocomplete_path' => 'userreference/autocomplete/'.$element['#field_name'], |
|
544 | 544 | // The following values were set by the content module and need |
545 | 545 | // to be passed down to the nested element. |
546 | 546 | '#title' => $element['#title'], |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * like optionwidgets are using #element_validate to alter the value. |
579 | 579 | */ |
580 | 580 | function userreference_optionwidgets_validate($element, &$form_state) { |
581 | - $field_key = $element['#columns'][0]; |
|
581 | + $field_key = $element['#columns'][0]; |
|
582 | 582 | |
583 | 583 | $value = $form_state['values']; |
584 | 584 | $new_parents = array(); |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | static $results = array(); |
671 | 671 | |
672 | 672 | // Create unique id for static cache. |
673 | - $cid = $field['field_name'] .':'. $match .':'. ($string !== '' ? $string : implode('-', $ids)) .':'. $limit; |
|
673 | + $cid = $field['field_name'].':'.$match.':'.($string !== '' ? $string : implode('-', $ids)).':'.$limit; |
|
674 | 674 | if (!isset($results[$cid])) { |
675 | 675 | $references = FALSE; |
676 | 676 | if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') { |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | 'equals' => "= '%s'", |
784 | 784 | 'starts_with' => "$like '%s%%'", |
785 | 785 | ); |
786 | - $where[] = 'u.name '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
|
786 | + $where[] = 'u.name '.(isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
|
787 | 787 | $args[] = $string; |
788 | 788 | } |
789 | 789 | elseif ($ids) { |
790 | - $where[] = 'u.uid IN (' . db_placeholders($ids) . ')'; |
|
790 | + $where[] = 'u.uid IN ('.db_placeholders($ids).')'; |
|
791 | 791 | $args = array_merge($args, $ids); |
792 | 792 | } |
793 | 793 | else { |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | $roles = array_intersect(array_keys(user_roles(1)), $roles); |
803 | 803 | } |
804 | 804 | if (!empty($roles) && !in_array(DRUPAL_AUTHENTICATED_RID, $roles)) { |
805 | - $where[] = "r.rid IN (". implode($roles, ',') .")"; |
|
805 | + $where[] = "r.rid IN (".implode($roles, ',').")"; |
|
806 | 806 | $join[] = 'LEFT JOIN {users_roles} r ON u.uid = r.uid'; |
807 | 807 | } |
808 | 808 | |
@@ -812,8 +812,8 @@ discard block |
||
812 | 812 | } |
813 | 813 | |
814 | 814 | $users = array(); |
815 | - $where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : ''; |
|
816 | - $result = db_query('SELECT u.name, u.uid FROM {users} u '. implode(' ', $join) ." $where_clause ORDER BY u.name ASC", $args); |
|
815 | + $where_clause = $where ? 'WHERE ('.implode(') AND (', $where).')' : ''; |
|
816 | + $result = db_query('SELECT u.name, u.uid FROM {users} u '.implode(' ', $join)." $where_clause ORDER BY u.name ASC", $args); |
|
817 | 817 | while ($user = db_fetch_object($result)) { |
818 | 818 | $users[$user->uid] = array( |
819 | 819 | 'title' => $user->name, |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $references = _userreference_potential_references($field, $string, $match, array(), 10); |
836 | 836 | foreach ($references as $id => $row) { |
837 | 837 | // Add a class wrapper for a few required CSS overrides. |
838 | - $matches[$row['title']] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>'; |
|
838 | + $matches[$row['title']] = '<div class="reference-autocomplete">'.$row['rendered'].'</div>'; |
|
839 | 839 | } |
840 | 840 | drupal_json($matches); |
841 | 841 | } |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | } |
871 | 871 | foreach ($search_tables as $table => $columns) { |
872 | 872 | foreach ($columns as $column) { |
873 | - $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {". $table ."} f ON n.vid = f.vid WHERE f.". $column ."=". $account->uid. " AND n.status = 1")); |
|
873 | + $ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.type FROM {node} n LEFT JOIN {".$table."} f ON n.vid = f.vid WHERE f.".$column."=".$account->uid." AND n.status = 1")); |
|
874 | 874 | while ($data = db_fetch_object($ids)) { |
875 | 875 | $additions[$data->type][$data->nid] = $data->title; |
876 | 876 | } |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | $values = array(); |
887 | 887 | foreach ($account->userreference as $node_type => $nodes) { |
888 | 888 | foreach ($nodes as $nid => $title) { |
889 | - $values[$node_type][] = l($title, 'node/'. $nid); |
|
889 | + $values[$node_type][] = l($title, 'node/'.$nid); |
|
890 | 890 | } |
891 | 891 | if (isset($values[$node_type])) { |
892 | 892 | $additions[] = array( |
@@ -92,8 +92,7 @@ discard block |
||
92 | 92 | if ($view->base_table == 'users' && !empty($view->display['default']->display_options['fields'])) { |
93 | 93 | if ($view->type == 'Default') { |
94 | 94 | $views[t('Default Views')][$view->name] = $view->name; |
95 | - } |
|
96 | - else { |
|
95 | + } else { |
|
97 | 96 | $views[t('Existing Views')][$view->name] = $view->name; |
98 | 97 | } |
99 | 98 | } |
@@ -121,8 +120,7 @@ discard block |
||
121 | 120 | '#required' => FALSE, |
122 | 121 | '#description' => t('Provide a comma separated list of arguments to pass to the view.'), |
123 | 122 | ); |
124 | - } |
|
125 | - else { |
|
123 | + } else { |
|
126 | 124 | $form['advanced']['no_view_help'] = array( |
127 | 125 | '#value' => t('<p>The list of user that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') . |
128 | 126 | t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'), |
@@ -188,10 +186,11 @@ discard block |
||
188 | 186 | if (is_array($item) && !empty($item['uid'])) { |
189 | 187 | if (is_numeric($item['uid'])) { |
190 | 188 | $ids[] = $item['uid']; |
191 | - } |
|
192 | - else { |
|
189 | + } else { |
|
193 | 190 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
194 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
191 | + if (is_array($item) && isset($item['_error_element'])) { |
|
192 | + unset($item['_error_element']); |
|
193 | + } |
|
195 | 194 | form_set_error($error_element, t('%name: invalid input.', array('%name' => t($field['widget']['label'])))); |
196 | 195 | } |
197 | 196 | } |
@@ -202,7 +201,9 @@ discard block |
||
202 | 201 | foreach ($items as $delta => $item) { |
203 | 202 | if (is_array($item)) { |
204 | 203 | $error_element = isset($item['_error_element']) ? $item['_error_element'] : ''; |
205 | - if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']); |
|
204 | + if (is_array($item) && isset($item['_error_element'])) { |
|
205 | + unset($item['_error_element']); |
|
206 | + } |
|
206 | 207 | if (!empty($item['uid']) && !isset($refs[$item['uid']])) { |
207 | 208 | form_set_error($error_element, t('%name: invalid user.', array('%name' => t($field['widget']['label'])))); |
208 | 209 | } |
@@ -367,8 +368,7 @@ discard block |
||
367 | 368 | '#element_validate' => array('_element_validate_integer_positive'), |
368 | 369 | '#required' => TRUE, |
369 | 370 | ); |
370 | - } |
|
371 | - else { |
|
371 | + } else { |
|
372 | 372 | $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match); |
373 | 373 | $form['size'] = array('#type' => 'hidden', '#value' => $size); |
374 | 374 | } |
@@ -612,8 +612,7 @@ discard block |
||
612 | 612 | $reference = _userreference_potential_references($field, $value, 'equals', NULL, 1); |
613 | 613 | if (empty($reference)) { |
614 | 614 | form_error($element[$field_key], t('%name: found no valid user with that name.', array('%name' => t($field['widget']['label'])))); |
615 | - } |
|
616 | - else { |
|
615 | + } else { |
|
617 | 616 | $uid = key($reference); |
618 | 617 | } |
619 | 618 | } |
@@ -733,8 +732,7 @@ discard block |
||
733 | 732 | if (!empty($field['advanced_view_args'])) { |
734 | 733 | // TODO: Support Tokens using token.module ? |
735 | 734 | $view_args = array_map('trim', explode(',', $field['advanced_view_args'])); |
736 | - } |
|
737 | - else { |
|
735 | + } else { |
|
738 | 736 | $view_args = array(); |
739 | 737 | } |
740 | 738 | |
@@ -759,8 +757,7 @@ discard block |
||
759 | 757 | |
760 | 758 | // Get the results. |
761 | 759 | $result = $view->execute_display($display, $view_args); |
762 | - } |
|
763 | - else { |
|
760 | + } else { |
|
764 | 761 | $result = FALSE; |
765 | 762 | } |
766 | 763 | |
@@ -785,12 +782,10 @@ discard block |
||
785 | 782 | ); |
786 | 783 | $where[] = 'u.name '. (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']); |
787 | 784 | $args[] = $string; |
788 | - } |
|
789 | - elseif ($ids) { |
|
785 | + } elseif ($ids) { |
|
790 | 786 | $where[] = 'u.uid IN (' . db_placeholders($ids) . ')'; |
791 | 787 | $args = array_merge($args, $ids); |
792 | - } |
|
793 | - else { |
|
788 | + } else { |
|
794 | 789 | $where[] = "u.uid > 0"; |
795 | 790 | } |
796 | 791 |
@@ -99,6 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Presents a node editing or adding form for the given content profile. |
102 | + * @param string $type |
|
102 | 103 | */ |
103 | 104 | function content_profile_page_edit($type, $account) { |
104 | 105 | drupal_set_title(check_plain($account->name)); |
@@ -211,7 +212,7 @@ discard block |
||
211 | 212 | * @param $op |
212 | 213 | * When set to 'types', content profile content types are returned |
213 | 214 | * as type objects. When set to 'names', only their type names are returned. |
214 | - * @param $setting |
|
215 | + * @param string $setting |
|
215 | 216 | * If set, only content types that have this setting activated are returned. |
216 | 217 | * Leave it NULL to get all content profile types. |
217 | 218 | * @param $value |
@@ -11,56 +11,56 @@ discard block |
||
11 | 11 | * Implementation of hook_init(). |
12 | 12 | */ |
13 | 13 | function content_profile_init() { |
14 | - module_load_include('inc', 'content_profile', 'content_profile.theme_vars'); |
|
14 | + module_load_include('inc', 'content_profile', 'content_profile.theme_vars'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Implementation of hook_ctools_plugin_directory(). |
19 | 19 | */ |
20 | 20 | function content_profile_ctools_plugin_directory($module, $plugin) { |
21 | - if ($module == 'ctools' && $plugin == 'relationships') { |
|
21 | + if ($module == 'ctools' && $plugin == 'relationships') { |
|
22 | 22 | return 'panels/' . $plugin; |
23 | - } |
|
23 | + } |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Implementation of hook_menu(). |
28 | 28 | */ |
29 | 29 | function content_profile_menu() { |
30 | - $items = array(); |
|
30 | + $items = array(); |
|
31 | 31 | |
32 | - //Register a path for each content profile type |
|
33 | - foreach (content_profile_get_types('names') as $type => $typename) { |
|
32 | + //Register a path for each content profile type |
|
33 | + foreach (content_profile_get_types('names') as $type => $typename) { |
|
34 | 34 | $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/edit'] = array( |
35 | - 'title' => 'Edit', |
|
36 | - 'type' => MENU_DEFAULT_LOCAL_TASK, |
|
35 | + 'title' => 'Edit', |
|
36 | + 'type' => MENU_DEFAULT_LOCAL_TASK, |
|
37 | 37 | ); |
38 | 38 | $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/profile'] = array( |
39 | - 'title' => 'Content profile', |
|
40 | - 'description' => 'Configure the display and management of this content profile.', |
|
41 | - 'page callback' => 'drupal_get_form', |
|
42 | - 'page arguments' => array('content_profile_admin_settings', $type), |
|
43 | - 'access callback' => 'user_access', |
|
44 | - 'access arguments' => array('administer nodes'), |
|
45 | - 'type' => MENU_LOCAL_TASK, |
|
46 | - 'weight' => 1, |
|
39 | + 'title' => 'Content profile', |
|
40 | + 'description' => 'Configure the display and management of this content profile.', |
|
41 | + 'page callback' => 'drupal_get_form', |
|
42 | + 'page arguments' => array('content_profile_admin_settings', $type), |
|
43 | + 'access callback' => 'user_access', |
|
44 | + 'access arguments' => array('administer nodes'), |
|
45 | + 'type' => MENU_LOCAL_TASK, |
|
46 | + 'weight' => 1, |
|
47 | 47 | ); |
48 | - } |
|
49 | - foreach (content_profile_get_types('names') as $type => $type_name) { |
|
48 | + } |
|
49 | + foreach (content_profile_get_types('names') as $type => $type_name) { |
|
50 | 50 | $items['user/%user/profile/'. $type] = array( |
51 | - 'title callback' => 'check_plain', |
|
52 | - 'title' => drupal_ucfirst($type_name), |
|
53 | - 'page callback' => 'content_profile_page_edit', |
|
54 | - 'page arguments' => array($type, 1), |
|
55 | - 'access callback' => 'content_profile_page_access', |
|
56 | - 'access arguments' => array($type, 1), |
|
57 | - 'weight' => content_profile_get_settings($type, 'weight'), |
|
58 | - 'file' => 'node.pages.inc', |
|
59 | - 'file path' => drupal_get_path('module', 'node'), |
|
60 | - 'type' => content_profile_get_settings($type, 'edit_tab') == 'top' ? MENU_LOCAL_TASK : MENU_CALLBACK, |
|
51 | + 'title callback' => 'check_plain', |
|
52 | + 'title' => drupal_ucfirst($type_name), |
|
53 | + 'page callback' => 'content_profile_page_edit', |
|
54 | + 'page arguments' => array($type, 1), |
|
55 | + 'access callback' => 'content_profile_page_access', |
|
56 | + 'access arguments' => array($type, 1), |
|
57 | + 'weight' => content_profile_get_settings($type, 'weight'), |
|
58 | + 'file' => 'node.pages.inc', |
|
59 | + 'file path' => drupal_get_path('module', 'node'), |
|
60 | + 'type' => content_profile_get_settings($type, 'edit_tab') == 'top' ? MENU_LOCAL_TASK : MENU_CALLBACK, |
|
61 | 61 | ); |
62 | - } |
|
63 | - return $items; |
|
62 | + } |
|
63 | + return $items; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,45 +68,45 @@ discard block |
||
68 | 68 | * Take over menu items generated by the user module for our categories. |
69 | 69 | */ |
70 | 70 | function content_profile_menu_alter(&$items) { |
71 | - foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
71 | + foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
72 | 72 | if (!empty($items['user/%user_category/edit/'. $type])) { |
73 | - $item = &$items['user/%user_category/edit/'. $type]; |
|
74 | - $item = array( |
|
73 | + $item = &$items['user/%user_category/edit/'. $type]; |
|
74 | + $item = array( |
|
75 | 75 | 'page callback' => 'content_profile_page_edit', |
76 | 76 | 'page arguments' => array($type, 1), |
77 | 77 | 'access callback' => 'content_profile_page_access', |
78 | 78 | 'access arguments' => array($type, 1), |
79 | 79 | 'file' => 'node.pages.inc', |
80 | 80 | 'file path' => drupal_get_path('module', 'node'), |
81 | - ) + $item; |
|
81 | + ) + $item; |
|
82 | + } |
|
82 | 83 | } |
83 | - } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | 87 | function content_profile_page_access($type, $account) { |
88 | - if ($node = content_profile_load($type, $account->uid)) { |
|
88 | + if ($node = content_profile_load($type, $account->uid)) { |
|
89 | 89 | return node_access('update', $node); |
90 | - } |
|
91 | - // Else user may view the page when they are going to create their own profile |
|
92 | - // or have permission to create it for others. |
|
93 | - global $user; |
|
94 | - if ($user->uid == $account->uid || user_access('administer nodes') ){ |
|
90 | + } |
|
91 | + // Else user may view the page when they are going to create their own profile |
|
92 | + // or have permission to create it for others. |
|
93 | + global $user; |
|
94 | + if ($user->uid == $account->uid || user_access('administer nodes') ){ |
|
95 | 95 | return node_access('create', $type); |
96 | - } |
|
97 | - return FALSE; |
|
96 | + } |
|
97 | + return FALSE; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Presents a node editing or adding form for the given content profile. |
102 | 102 | */ |
103 | 103 | function content_profile_page_edit($type, $account) { |
104 | - drupal_set_title(check_plain($account->name)); |
|
105 | - $node = content_profile_load($type, $account->uid); |
|
106 | - if (!$node) { |
|
104 | + drupal_set_title(check_plain($account->name)); |
|
105 | + $node = content_profile_load($type, $account->uid); |
|
106 | + if (!$node) { |
|
107 | 107 | $node = array('uid' => $account->uid, 'name' => (isset($account->name) ? $account->name : ''), 'type' => $type, 'language' => ''); |
108 | - } |
|
109 | - return drupal_get_form($type .'_node_form', $node); |
|
108 | + } |
|
109 | + return drupal_get_form($type .'_node_form', $node); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * Implementation of hook_views_api(). |
115 | 115 | */ |
116 | 116 | function content_profile_views_api() { |
117 | - return array( |
|
117 | + return array( |
|
118 | 118 | 'api' => 2, |
119 | 119 | 'path' => drupal_get_path('module', 'content_profile') .'/views', |
120 | - ); |
|
120 | + ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -125,71 +125,71 @@ discard block |
||
125 | 125 | * Menu callback; content profile settings. |
126 | 126 | */ |
127 | 127 | function content_profile_admin_settings(&$form_state, $type) { |
128 | - $form_state['type'] = $type; |
|
128 | + $form_state['type'] = $type; |
|
129 | 129 | |
130 | - $form['weight'] = array( |
|
130 | + $form['weight'] = array( |
|
131 | 131 | '#type' => 'weight', |
132 | 132 | '#title' => t("Weight"), |
133 | 133 | '#default_value' => content_profile_get_settings($type, 'weight'), |
134 | 134 | '#description' => t('The weight of content of this content type where ever they appear - this applies to the input form integration as well to the display integration.'), |
135 | 135 | '#weight' => 5, |
136 | - ); |
|
137 | - $form['display'] = array( |
|
136 | + ); |
|
137 | + $form['display'] = array( |
|
138 | 138 | '#type' => 'fieldset', |
139 | 139 | '#title' => t('Display settings'), |
140 | 140 | '#description' => t('Customize the display of this content profile.'), |
141 | 141 | '#collapsible' => TRUE, |
142 | - ); |
|
143 | - $form['display']['user_display'] = array( |
|
142 | + ); |
|
143 | + $form['display']['user_display'] = array( |
|
144 | 144 | '#type' => 'radios', |
145 | 145 | '#title' => t("User page display style"), |
146 | 146 | '#default_value' => content_profile_get_settings($type, 'user_display'), |
147 | 147 | '#options' => array( |
148 | - 0 => t("Don't display this content profile on the user account page"), |
|
149 | - 'link' => t('Display it as link to the profile content'), |
|
150 | - 'full' => t('Display the full content'), |
|
151 | - 'teaser' => t("Display the content's teaser"), |
|
148 | + 0 => t("Don't display this content profile on the user account page"), |
|
149 | + 'link' => t('Display it as link to the profile content'), |
|
150 | + 'full' => t('Display the full content'), |
|
151 | + 'teaser' => t("Display the content's teaser"), |
|
152 | 152 | ), |
153 | - ); |
|
154 | - $form['display']['edit_link'] = array( |
|
153 | + ); |
|
154 | + $form['display']['edit_link'] = array( |
|
155 | 155 | '#type' => 'checkbox', |
156 | 156 | '#title' => t("Include an edit link to the display"), |
157 | 157 | '#default_value' => content_profile_get_settings($type, 'edit_link'), |
158 | - ); |
|
159 | - $form['display']['add_link'] = array( |
|
158 | + ); |
|
159 | + $form['display']['add_link'] = array( |
|
160 | 160 | '#type' => 'checkbox', |
161 | 161 | '#title' => t("Show a link to the content profile creation page, if there is no profile."), |
162 | 162 | '#default_value' => content_profile_get_settings($type, 'add_link'), |
163 | 163 | '#description' => t("If selected and the user has no profile of this type yet, a link to add one is shown on the user page."), |
164 | - ); |
|
165 | - $form['display']['edit_tab'] = array( |
|
164 | + ); |
|
165 | + $form['display']['edit_tab'] = array( |
|
166 | 166 | '#type' => 'radios', |
167 | 167 | '#title' => t("Profile edit tab"), |
168 | 168 | '#default_value' => content_profile_get_settings($type, 'edit_tab'), |
169 | 169 | '#options' => array( |
170 | - 0 => t('None'), |
|
171 | - 'top' => t("Show a tab at the user's page"), |
|
172 | - 'sub' => t("Show a secondary tab below the user's edit tab"), |
|
170 | + 0 => t('None'), |
|
171 | + 'top' => t("Show a tab at the user's page"), |
|
172 | + 'sub' => t("Show a secondary tab below the user's edit tab"), |
|
173 | 173 | ), |
174 | - ); |
|
175 | - $form['submit'] = array( |
|
174 | + ); |
|
175 | + $form['submit'] = array( |
|
176 | 176 | '#type' => 'submit', |
177 | 177 | '#value' => t('Submit'), |
178 | 178 | '#weight' => 10, |
179 | - ); |
|
180 | - return $form; |
|
179 | + ); |
|
180 | + return $form; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | function content_profile_admin_settings_submit($form, &$form_state) { |
184 | - $settings = content_profile_get_settings($form_state['type']); |
|
185 | - foreach (content_profile_settings_info() as $setting => $default) { |
|
184 | + $settings = content_profile_get_settings($form_state['type']); |
|
185 | + foreach (content_profile_settings_info() as $setting => $default) { |
|
186 | 186 | if (isset($form_state['values'][$setting])) { |
187 | - $settings[$setting] = $form_state['values'][$setting]; |
|
187 | + $settings[$setting] = $form_state['values'][$setting]; |
|
188 | + } |
|
188 | 189 | } |
189 | - } |
|
190 | - content_profile_set_settings($form_state['type'], $settings); |
|
191 | - drupal_set_message('Your changes have been saved.'); |
|
192 | - menu_rebuild(); |
|
190 | + content_profile_set_settings($form_state['type'], $settings); |
|
191 | + drupal_set_message('Your changes have been saved.'); |
|
192 | + menu_rebuild(); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | * The node object or the node's type |
199 | 199 | */ |
200 | 200 | function is_content_profile($type) { |
201 | - if (is_object($type)) { |
|
201 | + if (is_object($type)) { |
|
202 | 202 | $type = $type->type; |
203 | - } |
|
204 | - return variable_get('content_profile_use_'. $type, FALSE); |
|
203 | + } |
|
204 | + return variable_get('content_profile_use_'. $type, FALSE); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | * The value to compare the given setting too. |
219 | 219 | */ |
220 | 220 | function content_profile_get_types($op = 'types', $setting = NULL , $value = TRUE) { |
221 | - $types = array(); |
|
221 | + $types = array(); |
|
222 | 222 | |
223 | - foreach (node_get_types($op) as $type => $info) { |
|
223 | + foreach (node_get_types($op) as $type => $info) { |
|
224 | 224 | if (is_content_profile($type) && (!isset($setting) || content_profile_get_settings($type, $setting) == $value)) { |
225 | - $types[$type] = $info; |
|
225 | + $types[$type] = $info; |
|
226 | 226 | } |
227 | - } |
|
228 | - return $types; |
|
227 | + } |
|
228 | + return $types; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -233,79 +233,79 @@ discard block |
||
233 | 233 | * Rename or delete the settings variable if a type changes. |
234 | 234 | */ |
235 | 235 | function content_profile_node_type($op, $info) { |
236 | - switch ($op) { |
|
236 | + switch ($op) { |
|
237 | 237 | case 'delete': |
238 | 238 | variable_del('content_profile_use_'. $info->type); |
239 | - variable_del('content_profile_'. $info->type); |
|
240 | - break; |
|
239 | + variable_del('content_profile_'. $info->type); |
|
240 | + break; |
|
241 | 241 | case 'update': |
242 | 242 | if (!empty($info->old_type) && $info->old_type != $info->type) { |
243 | 243 | if (is_content_profile($info->old_type)) { |
244 | - $settings = variable_get('content_profile_'. $info->old_type, array()); |
|
245 | - variable_del('content_profile_use_'. $info->old_type); |
|
246 | - variable_del('content_profile_'. $info->old_type); |
|
247 | - variable_set('content_profile_use_'. $info->type, 1); |
|
248 | - variable_set('content_profile_'. $info->type, $settings); |
|
244 | + $settings = variable_get('content_profile_'. $info->old_type, array()); |
|
245 | + variable_del('content_profile_use_'. $info->old_type); |
|
246 | + variable_del('content_profile_'. $info->old_type); |
|
247 | + variable_set('content_profile_use_'. $info->type, 1); |
|
248 | + variable_set('content_profile_'. $info->type, $settings); |
|
249 | + } |
|
249 | 250 | } |
250 | - } |
|
251 | - break; |
|
252 | - } |
|
251 | + break; |
|
252 | + } |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | 256 | * Implementation of hook_form_alter(). |
257 | 257 | */ |
258 | 258 | function content_profile_form_alter(&$form, $form_state, $form_id) { |
259 | - if ($form_id == 'node_type_form') { |
|
259 | + if ($form_id == 'node_type_form') { |
|
260 | 260 | $form['content_profile'] = array( |
261 | - '#type' => 'fieldset', |
|
262 | - '#title' => t('Content Profile'), |
|
263 | - '#group' => 'additional_settings', |
|
264 | - '#collapsible' => TRUE, |
|
265 | - '#collapsed' => TRUE, |
|
266 | - '#weight' => 32, |
|
261 | + '#type' => 'fieldset', |
|
262 | + '#title' => t('Content Profile'), |
|
263 | + '#group' => 'additional_settings', |
|
264 | + '#collapsible' => TRUE, |
|
265 | + '#collapsed' => TRUE, |
|
266 | + '#weight' => 32, |
|
267 | 267 | ); |
268 | 268 | $form['content_profile']['content_profile_use'] = array( |
269 | - '#type' => 'checkbox', |
|
270 | - '#title' => t('Use this content type as a content profile for users'), |
|
271 | - '#default_value' => variable_get('content_profile_use_'. $form['#node_type']->type, FALSE), |
|
269 | + '#type' => 'checkbox', |
|
270 | + '#title' => t('Use this content type as a content profile for users'), |
|
271 | + '#default_value' => variable_get('content_profile_use_'. $form['#node_type']->type, FALSE), |
|
272 | 272 | ); |
273 | - } |
|
274 | - elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
273 | + } |
|
274 | + elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
275 | 275 | // Customize the redirect target and buttons of our own node forms. |
276 | 276 | if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit' || arg(2) == 'profile') { |
277 | - $form['buttons']['preview']['#access'] = FALSE; |
|
278 | - $form['buttons']['delete']['#access'] = FALSE; |
|
279 | - $form['#redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q']; |
|
277 | + $form['buttons']['preview']['#access'] = FALSE; |
|
278 | + $form['buttons']['delete']['#access'] = FALSE; |
|
279 | + $form['#redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q']; |
|
280 | 280 | } |
281 | 281 | // Set the author value - note that this works only for admins. |
282 | 282 | if (!empty($_GET['uid']) && ($uid = intval($_GET['uid'])) && ($user = user_load($uid))) { |
283 | - $form['author']['name']['#default_value'] = $user->name; |
|
283 | + $form['author']['name']['#default_value'] = $user->name; |
|
284 | + } |
|
284 | 285 | } |
285 | - } |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | 289 | * Implementation of hook_user(). |
290 | 290 | */ |
291 | 291 | function content_profile_user($op, &$edit, &$account, $category = NULL) { |
292 | - global $user; |
|
292 | + global $user; |
|
293 | 293 | |
294 | - switch ($op) { |
|
294 | + switch ($op) { |
|
295 | 295 | case 'categories': |
296 | 296 | $data = array(); |
297 | - foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
297 | + foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
298 | 298 | $data[] = array( |
299 | - 'name' => $type, |
|
300 | - 'title' => drupal_ucfirst($type_name), |
|
301 | - 'weight' => content_profile_get_settings($type, 'weight') + 1, |
|
299 | + 'name' => $type, |
|
300 | + 'title' => drupal_ucfirst($type_name), |
|
301 | + 'weight' => content_profile_get_settings($type, 'weight') + 1, |
|
302 | 302 | ); |
303 | - } |
|
304 | - return $data; |
|
303 | + } |
|
304 | + return $data; |
|
305 | 305 | |
306 | 306 | case 'view': |
307 | 307 | $account->content['content_profile'] = content_profile_show_profiles($account->uid); |
308 | - break; |
|
308 | + break; |
|
309 | 309 | |
310 | 310 | case 'delete': |
311 | 311 | // Retrieve all profile nodes (in any language) for this user by issueing an SQL query. |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | |
316 | 316 | $result = db_query("SELECT * FROM {node} WHERE (". implode(' OR ', $condition) .") AND uid = %d", $arguments); |
317 | 317 | while ($node = db_fetch_object($result)) { |
318 | - _content_profile_node_delete($node); |
|
318 | + _content_profile_node_delete($node); |
|
319 | + } |
|
319 | 320 | } |
320 | - } |
|
321 | - break; |
|
322 | - } |
|
321 | + break; |
|
322 | + } |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -333,42 +333,42 @@ discard block |
||
333 | 333 | * "SELECT * FROM {node}" query) instead of just the $nid. |
334 | 334 | */ |
335 | 335 | function _content_profile_node_delete($node) { |
336 | - // Copied over from node_load(), so that node_invoke('delete') gets |
|
337 | - // the fully extended node object, like modules would expect: |
|
336 | + // Copied over from node_load(), so that node_invoke('delete') gets |
|
337 | + // the fully extended node object, like modules would expect: |
|
338 | 338 | |
339 | - if ($node->nid) { |
|
339 | + if ($node->nid) { |
|
340 | 340 | // Call the node specific callback (if any) and piggy-back the |
341 | 341 | // results to the node or overwrite some values. |
342 | 342 | if ($extra = node_invoke($node, 'load')) { |
343 | - foreach ($extra as $key => $value) { |
|
343 | + foreach ($extra as $key => $value) { |
|
344 | 344 | $node->$key = $value; |
345 | - } |
|
345 | + } |
|
346 | 346 | } |
347 | 347 | if ($extra = node_invoke_nodeapi($node, 'load')) { |
348 | - foreach ($extra as $key => $value) { |
|
348 | + foreach ($extra as $key => $value) { |
|
349 | 349 | $node->$key = $value; |
350 | - } |
|
350 | + } |
|
351 | + } |
|
351 | 352 | } |
352 | - } |
|
353 | 353 | |
354 | - // Copied over from node_delete(): |
|
354 | + // Copied over from node_delete(): |
|
355 | 355 | |
356 | - db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); |
|
357 | - db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); |
|
356 | + db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); |
|
357 | + db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid); |
|
358 | 358 | |
359 | - // Call the node-specific callback (if any): |
|
360 | - node_invoke($node, 'delete'); |
|
361 | - node_invoke_nodeapi($node, 'delete'); |
|
359 | + // Call the node-specific callback (if any): |
|
360 | + node_invoke($node, 'delete'); |
|
361 | + node_invoke_nodeapi($node, 'delete'); |
|
362 | 362 | |
363 | - // Clear the cache so an anonymous poster can see the node being deleted. |
|
364 | - cache_clear_all(); |
|
363 | + // Clear the cache so an anonymous poster can see the node being deleted. |
|
364 | + cache_clear_all(); |
|
365 | 365 | |
366 | - // Remove this node from the search index if needed. |
|
367 | - if (function_exists('search_wipe')) { |
|
366 | + // Remove this node from the search index if needed. |
|
367 | + if (function_exists('search_wipe')) { |
|
368 | 368 | search_wipe($node->nid, 'node'); |
369 | - } |
|
370 | - watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); |
|
371 | - drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title))); |
|
369 | + } |
|
370 | + watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); |
|
371 | + drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title))); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -376,30 +376,30 @@ discard block |
||
376 | 376 | */ |
377 | 377 | function content_profile_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
378 | 378 | |
379 | - if ($op == 'prepare' && is_content_profile($node) && !isset($node->nid) && $node->uid && !user_access('administer nodes') && arg(0) != 'admin') { |
|
379 | + if ($op == 'prepare' && is_content_profile($node) && !isset($node->nid) && $node->uid && !user_access('administer nodes') && arg(0) != 'admin') { |
|
380 | 380 | // Check if this nodetype already exists |
381 | 381 | if ($nid = content_profile_profile_exists($node, $node->uid)) { |
382 | - // This node already exists, redirect to edit page |
|
383 | - drupal_goto('node/'. $nid .'/edit', 'destination=user/'. $node->uid); |
|
382 | + // This node already exists, redirect to edit page |
|
383 | + drupal_goto('node/'. $nid .'/edit', 'destination=user/'. $node->uid); |
|
384 | 384 | } |
385 | - } |
|
386 | - elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) { |
|
385 | + } |
|
386 | + elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) { |
|
387 | 387 | $form = $a3; |
388 | 388 | // Only validate if the user-name changed or we add a new node |
389 | 389 | if (!empty($node->nid) && $form['author']['name']['#default_value'] == $node->name) { |
390 | - return; |
|
390 | + return; |
|
391 | 391 | } |
392 | 392 | //check whether the selected user has already a profile |
393 | 393 | $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $node->name)); |
394 | 394 | if ($uid && content_profile_profile_exists($node, $uid)) { |
395 | - form_set_error('name', t('This user already has a content profile of this type. You can only create one profile per user.')); |
|
395 | + form_set_error('name', t('This user already has a content profile of this type. You can only create one profile per user.')); |
|
396 | + } |
|
396 | 397 | } |
397 | - } |
|
398 | - elseif ($op == 'prepare translation' && is_content_profile($node->translation_source)) { |
|
398 | + elseif ($op == 'prepare translation' && is_content_profile($node->translation_source)) { |
|
399 | 399 | // Make sure the translated profile belongs to the same user. |
400 | 400 | $node->uid = $node->translation_source->uid; |
401 | 401 | $node->name = $node->translation_source->name; |
402 | - } |
|
402 | + } |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | * @return If a node exists, the node id, FALSE else. |
413 | 413 | */ |
414 | 414 | function content_profile_profile_exists($node, $uid) { |
415 | - $query = "SELECT n.nid AS nid FROM {node} n WHERE n.type = '%s' AND n.uid = %d "; |
|
416 | - if (module_exists('translation') && translation_supported_type($node->type)) { |
|
415 | + $query = "SELECT n.nid AS nid FROM {node} n WHERE n.type = '%s' AND n.uid = %d "; |
|
416 | + if (module_exists('translation') && translation_supported_type($node->type)) { |
|
417 | 417 | $query .= "AND n.language = '%s'"; |
418 | - } |
|
419 | - return db_result(db_query($query, $node->type, $uid, $node->language)); |
|
418 | + } |
|
419 | + return db_result(db_query($query, $node->type, $uid, $node->language)); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -428,19 +428,19 @@ discard block |
||
428 | 428 | * e.g. user_edit, register or weight. |
429 | 429 | */ |
430 | 430 | function content_profile_get_settings($type, $return = 'all') { |
431 | - $settings = variable_get('content_profile_'. $type, array()); |
|
432 | - $settings += content_profile_settings_info(); |
|
433 | - if ($return == 'all') { |
|
431 | + $settings = variable_get('content_profile_'. $type, array()); |
|
432 | + $settings += content_profile_settings_info(); |
|
433 | + if ($return == 'all') { |
|
434 | 434 | return $settings; |
435 | - } |
|
436 | - return $settings[$return]; |
|
435 | + } |
|
436 | + return $settings[$return]; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
440 | 440 | * Saves the content_profile settings of a content type. |
441 | 441 | */ |
442 | 442 | function content_profile_set_settings($type, $settings) { |
443 | - variable_set('content_profile_'. $type, $settings); |
|
443 | + variable_set('content_profile_'. $type, $settings); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * and their default value. |
449 | 449 | */ |
450 | 450 | function content_profile_settings_info() { |
451 | - return module_invoke_all('content_profile_settings'); |
|
451 | + return module_invoke_all('content_profile_settings'); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -457,13 +457,13 @@ discard block |
||
457 | 457 | * Defines content profile settings and their default value. |
458 | 458 | */ |
459 | 459 | function content_profile_content_profile_settings() { |
460 | - return array( |
|
460 | + return array( |
|
461 | 461 | 'weight' => 0, |
462 | 462 | 'user_display' => 'full', |
463 | 463 | 'edit_link' => 0, |
464 | 464 | 'edit_tab' => 'sub', |
465 | 465 | 'add_link' => 1, |
466 | - ); |
|
466 | + ); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -479,17 +479,17 @@ discard block |
||
479 | 479 | * Optional. If set, the cache is reset. |
480 | 480 | */ |
481 | 481 | function content_profile_load($type, $uid, $lang = '', $reset = NULL) { |
482 | - static $cache = array(); |
|
482 | + static $cache = array(); |
|
483 | 483 | |
484 | - if (!isset($cache[$type][$uid][$lang]) || $reset) { |
|
484 | + if (!isset($cache[$type][$uid][$lang]) || $reset) { |
|
485 | 485 | $cache[$type][$uid][$lang] = FALSE; |
486 | 486 | $params = array('type' => $type, 'uid' => $uid); |
487 | 487 | if ($node = node_load($lang ? $params + array('language' => $lang) : $params, NULL, $reset)) { |
488 | - $cache[$type][$uid][$lang] = $node->nid; |
|
488 | + $cache[$type][$uid][$lang] = $node->nid; |
|
489 | 489 | } |
490 | 490 | return $node; |
491 | - } |
|
492 | - return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE; |
|
491 | + } |
|
492 | + return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -498,19 +498,19 @@ discard block |
||
498 | 498 | * Show node submission guidelines for content profile node forms. |
499 | 499 | */ |
500 | 500 | function content_profile_help($path, $arg) { |
501 | - if (preg_match('/user\/\%\/(profile|edit)\/(.*)/', $path, $matches)) { |
|
501 | + if (preg_match('/user\/\%\/(profile|edit)\/(.*)/', $path, $matches)) { |
|
502 | 502 | foreach (content_profile_get_types('names') as $type => $typename) { |
503 | - if ($type == $matches[2]) { |
|
503 | + if ($type == $matches[2]) { |
|
504 | 504 | $node = content_profile_load($type, $arg[1]); |
505 | 505 | if ($node) { |
506 | - return node_help('node/%/edit', array(1 => $node->nid)); |
|
506 | + return node_help('node/%/edit', array(1 => $node->nid)); |
|
507 | 507 | } |
508 | 508 | else { |
509 | - return node_help('node/add/'. $type, array('node', 'add', $type)); |
|
509 | + return node_help('node/add/'. $type, array('node', 'add', $type)); |
|
510 | 510 | } |
511 | - } |
|
511 | + } |
|
512 | + } |
|
512 | 513 | } |
513 | - } |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -518,14 +518,14 @@ discard block |
||
518 | 518 | * that shows all content_profiles as configured by the admin. |
519 | 519 | */ |
520 | 520 | function content_profile_show_profiles($uid) { |
521 | - global $user; |
|
521 | + global $user; |
|
522 | 522 | |
523 | - $content = array(); |
|
524 | - foreach (content_profile_get_types('names') as $type => $type_name) { |
|
523 | + $content = array(); |
|
524 | + foreach (content_profile_get_types('names') as $type => $type_name) { |
|
525 | 525 | $node = content_profile_load($type, $uid); |
526 | 526 | |
527 | 527 | if (($style = content_profile_get_settings($type, 'user_display')) && $node && node_access('view', $node)) { |
528 | - $content['content_profile_'. $type] = array( |
|
528 | + $content['content_profile_'. $type] = array( |
|
529 | 529 | '#theme' => ($style == 'link') ? 'content_profile_display_link' : 'content_profile_display_view', |
530 | 530 | '#edit_link' => content_profile_get_settings($type, 'edit_link'), |
531 | 531 | '#uid' => $uid, |
@@ -533,59 +533,59 @@ discard block |
||
533 | 533 | '#content_type' => $type, |
534 | 534 | '#weight' => content_profile_get_settings($type, 'weight'), |
535 | 535 | '#suffix' => '<br />', |
536 | - ); |
|
536 | + ); |
|
537 | 537 | |
538 | - // Working around the bug described at http://drupal.org/node/302873 |
|
539 | - module_load_include('inc', 'content_profile', 'content_profile.theme'); |
|
538 | + // Working around the bug described at http://drupal.org/node/302873 |
|
539 | + module_load_include('inc', 'content_profile', 'content_profile.theme'); |
|
540 | 540 | } |
541 | 541 | elseif (user_access('create '. $type .' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) { |
542 | - $content['content_profile_'. $type] = array( |
|
542 | + $content['content_profile_'. $type] = array( |
|
543 | 543 | '#admin' => $uid != $user->uid, |
544 | 544 | '#theme' => 'content_profile_display_add_link', |
545 | 545 | '#uid' => $uid, |
546 | 546 | '#content_type' => $type, |
547 | 547 | '#weight' => content_profile_get_settings($type, 'weight'), |
548 | 548 | '#suffix' => '<br />', |
549 | - ); |
|
549 | + ); |
|
550 | + } |
|
550 | 551 | } |
551 | - } |
|
552 | - if ($content) { |
|
552 | + if ($content) { |
|
553 | 553 | $content['#prefix'] = '<p id="content-profile-view">'; |
554 | 554 | $content['#suffix'] = '</p>'; |
555 | - } |
|
556 | - return $content; |
|
555 | + } |
|
556 | + return $content; |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
560 | 560 | * Implementation of hook_theme(). |
561 | 561 | */ |
562 | 562 | function content_profile_theme() { |
563 | - $return = array( |
|
563 | + $return = array( |
|
564 | 564 | 'content_profile_display_view' => array( |
565 | - 'template' => 'content_profile-display-view', |
|
566 | - 'arguments' => array('element' => NULL), |
|
567 | - 'file' => 'content_profile.theme.inc', |
|
565 | + 'template' => 'content_profile-display-view', |
|
566 | + 'arguments' => array('element' => NULL), |
|
567 | + 'file' => 'content_profile.theme.inc', |
|
568 | 568 | ), |
569 | 569 | 'content_profile_display_add_link' => array( |
570 | - 'file' => 'content_profile.theme.inc', |
|
570 | + 'file' => 'content_profile.theme.inc', |
|
571 | 571 | ), |
572 | 572 | 'content_profile_display_link' => array( |
573 | - 'file' => 'content_profile.theme.inc', |
|
573 | + 'file' => 'content_profile.theme.inc', |
|
574 | 574 | ), |
575 | 575 | 'content_profile_display_tab_view' => array( |
576 | - 'file' => 'content_profile.theme.inc', |
|
576 | + 'file' => 'content_profile.theme.inc', |
|
577 | 577 | ), |
578 | 578 | 'content_profile_display_tab_edit' => array( |
579 | - 'file' => 'content_profile.theme.inc', |
|
579 | + 'file' => 'content_profile.theme.inc', |
|
580 | 580 | ), |
581 | - ); |
|
582 | - if (module_exists('pageroute')) { |
|
581 | + ); |
|
582 | + if (module_exists('pageroute')) { |
|
583 | 583 | $return['content_profile_pageroute_empty'] = array( |
584 | - 'arguments' => array('type_name' => NULL), |
|
585 | - 'file' => 'content_profile.pageroute.inc', |
|
584 | + 'arguments' => array('type_name' => NULL), |
|
585 | + 'file' => 'content_profile.pageroute.inc', |
|
586 | 586 | ); |
587 | - } |
|
588 | - return $return; |
|
587 | + } |
|
588 | + return $return; |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | * $conf['content_profile_extra_templates'] in settings.php. |
595 | 595 | */ |
596 | 596 | function content_profile_theme_registry_alter(&$items) { |
597 | - $templates = array_merge(array( |
|
597 | + $templates = array_merge(array( |
|
598 | 598 | 'author_pane', |
599 | 599 | 'comment', |
600 | 600 | 'node', |
@@ -603,47 +603,47 @@ discard block |
||
603 | 603 | 'username', |
604 | 604 | 'user_profile', |
605 | 605 | 'user_signature', |
606 | - ), variable_get('content_profile_extra_templates', array())); |
|
606 | + ), variable_get('content_profile_extra_templates', array())); |
|
607 | 607 | |
608 | - foreach ($templates as $key) { |
|
608 | + foreach ($templates as $key) { |
|
609 | 609 | if (isset($items[$key])) { |
610 | - $items[$key] += array('preprocess functions' => array()); |
|
611 | - $items[$key]['preprocess functions'][] = 'content_profile_template_preprocess'; |
|
610 | + $items[$key] += array('preprocess functions' => array()); |
|
611 | + $items[$key]['preprocess functions'][] = 'content_profile_template_preprocess'; |
|
612 | + } |
|
612 | 613 | } |
613 | - } |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Adds $content_profile variable if we can find a $uid. |
618 | 618 | */ |
619 | 619 | function content_profile_template_preprocess(&$variables, $hook) { |
620 | - // Search the uid |
|
621 | - foreach (array('account_id', 'uid', 'account', 'node', 'comment', 'user') as $name) { |
|
620 | + // Search the uid |
|
621 | + foreach (array('account_id', 'uid', 'account', 'node', 'comment', 'user') as $name) { |
|
622 | 622 | if (isset($variables[$name])) { |
623 | - $uid = is_object($variables[$name]) ? $variables[$name]->uid : $variables[$name]; |
|
624 | - $variables['content_profile'] = new content_profile_theme_variables($uid); |
|
625 | - break; |
|
623 | + $uid = is_object($variables[$name]) ? $variables[$name]->uid : $variables[$name]; |
|
624 | + $variables['content_profile'] = new content_profile_theme_variables($uid); |
|
625 | + break; |
|
626 | + } |
|
626 | 627 | } |
627 | - } |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
631 | 631 | * Implementation of hook_simpletest(). |
632 | 632 | */ |
633 | 633 | function content_profile_simpletest() { |
634 | - // Scan through content_profile/tests directory for any .test files to tell SimpleTest module. |
|
635 | - $tests = file_scan_directory(drupal_get_path('module', 'content_profile') .'/tests', '\.test'); |
|
636 | - return array_keys($tests); |
|
634 | + // Scan through content_profile/tests directory for any .test files to tell SimpleTest module. |
|
635 | + $tests = file_scan_directory(drupal_get_path('module', 'content_profile') .'/tests', '\.test'); |
|
636 | + return array_keys($tests); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
640 | 640 | * Implementation of hook_pageroute_info() for Pageroute integration. |
641 | 641 | */ |
642 | 642 | function content_profile_pageroute_info() { |
643 | - return array( |
|
643 | + return array( |
|
644 | 644 | 'content_profile' => array( |
645 | - 'viewprofile' => 'content_profile.pageroute', |
|
646 | - 'editprofile' => 'content_profile.pageroute', |
|
645 | + 'viewprofile' => 'content_profile.pageroute', |
|
646 | + 'editprofile' => 'content_profile.pageroute', |
|
647 | 647 | ) |
648 | - ); |
|
648 | + ); |
|
649 | 649 | } |
@@ -234,21 +234,21 @@ discard block |
||
234 | 234 | */ |
235 | 235 | function content_profile_node_type($op, $info) { |
236 | 236 | switch ($op) { |
237 | - case 'delete': |
|
238 | - variable_del('content_profile_use_'. $info->type); |
|
239 | - variable_del('content_profile_'. $info->type); |
|
240 | - break; |
|
241 | - case 'update': |
|
242 | - if (!empty($info->old_type) && $info->old_type != $info->type) { |
|
243 | - if (is_content_profile($info->old_type)) { |
|
244 | - $settings = variable_get('content_profile_'. $info->old_type, array()); |
|
245 | - variable_del('content_profile_use_'. $info->old_type); |
|
246 | - variable_del('content_profile_'. $info->old_type); |
|
247 | - variable_set('content_profile_use_'. $info->type, 1); |
|
248 | - variable_set('content_profile_'. $info->type, $settings); |
|
249 | - } |
|
237 | + case 'delete': |
|
238 | + variable_del('content_profile_use_'. $info->type); |
|
239 | + variable_del('content_profile_'. $info->type); |
|
240 | + break; |
|
241 | + case 'update': |
|
242 | + if (!empty($info->old_type) && $info->old_type != $info->type) { |
|
243 | + if (is_content_profile($info->old_type)) { |
|
244 | + $settings = variable_get('content_profile_'. $info->old_type, array()); |
|
245 | + variable_del('content_profile_use_'. $info->old_type); |
|
246 | + variable_del('content_profile_'. $info->old_type); |
|
247 | + variable_set('content_profile_use_'. $info->type, 1); |
|
248 | + variable_set('content_profile_'. $info->type, $settings); |
|
250 | 249 | } |
251 | - break; |
|
250 | + } |
|
251 | + break; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
@@ -292,33 +292,33 @@ discard block |
||
292 | 292 | global $user; |
293 | 293 | |
294 | 294 | switch ($op) { |
295 | - case 'categories': |
|
296 | - $data = array(); |
|
297 | - foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
298 | - $data[] = array( |
|
299 | - 'name' => $type, |
|
300 | - 'title' => drupal_ucfirst($type_name), |
|
301 | - 'weight' => content_profile_get_settings($type, 'weight') + 1, |
|
302 | - ); |
|
303 | - } |
|
304 | - return $data; |
|
295 | + case 'categories': |
|
296 | + $data = array(); |
|
297 | + foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
|
298 | + $data[] = array( |
|
299 | + 'name' => $type, |
|
300 | + 'title' => drupal_ucfirst($type_name), |
|
301 | + 'weight' => content_profile_get_settings($type, 'weight') + 1, |
|
302 | + ); |
|
303 | + } |
|
304 | + return $data; |
|
305 | 305 | |
306 | - case 'view': |
|
307 | - $account->content['content_profile'] = content_profile_show_profiles($account->uid); |
|
308 | - break; |
|
306 | + case 'view': |
|
307 | + $account->content['content_profile'] = content_profile_show_profiles($account->uid); |
|
308 | + break; |
|
309 | 309 | |
310 | - case 'delete': |
|
311 | - // Retrieve all profile nodes (in any language) for this user by issueing an SQL query. |
|
312 | - if ($types = content_profile_get_types()) { |
|
313 | - $condition = array_fill(0, count($types), "type = '%s'"); |
|
314 | - $arguments = array_merge(array_keys($types), array($account->uid)); |
|
310 | + case 'delete': |
|
311 | + // Retrieve all profile nodes (in any language) for this user by issueing an SQL query. |
|
312 | + if ($types = content_profile_get_types()) { |
|
313 | + $condition = array_fill(0, count($types), "type = '%s'"); |
|
314 | + $arguments = array_merge(array_keys($types), array($account->uid)); |
|
315 | 315 | |
316 | - $result = db_query("SELECT * FROM {node} WHERE (". implode(' OR ', $condition) .") AND uid = %d", $arguments); |
|
317 | - while ($node = db_fetch_object($result)) { |
|
318 | - _content_profile_node_delete($node); |
|
319 | - } |
|
316 | + $result = db_query("SELECT * FROM {node} WHERE (". implode(' OR ', $condition) .") AND uid = %d", $arguments); |
|
317 | + while ($node = db_fetch_object($result)) { |
|
318 | + _content_profile_node_delete($node); |
|
320 | 319 | } |
321 | - break; |
|
320 | + } |
|
321 | + break; |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function content_profile_ctools_plugin_directory($module, $plugin) { |
21 | 21 | if ($module == 'ctools' && $plugin == 'relationships') { |
22 | - return 'panels/' . $plugin; |
|
22 | + return 'panels/'.$plugin; |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | |
32 | 32 | //Register a path for each content profile type |
33 | 33 | foreach (content_profile_get_types('names') as $type => $typename) { |
34 | - $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/edit'] = array( |
|
34 | + $items['admin/content/node-type/'.str_replace('_', '-', $type).'/edit'] = array( |
|
35 | 35 | 'title' => 'Edit', |
36 | 36 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
37 | 37 | ); |
38 | - $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/profile'] = array( |
|
38 | + $items['admin/content/node-type/'.str_replace('_', '-', $type).'/profile'] = array( |
|
39 | 39 | 'title' => 'Content profile', |
40 | 40 | 'description' => 'Configure the display and management of this content profile.', |
41 | 41 | 'page callback' => 'drupal_get_form', |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | foreach (content_profile_get_types('names') as $type => $type_name) { |
50 | - $items['user/%user/profile/'. $type] = array( |
|
50 | + $items['user/%user/profile/'.$type] = array( |
|
51 | 51 | 'title callback' => 'check_plain', |
52 | 52 | 'title' => drupal_ucfirst($type_name), |
53 | 53 | 'page callback' => 'content_profile_page_edit', |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function content_profile_menu_alter(&$items) { |
71 | 71 | foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) { |
72 | - if (!empty($items['user/%user_category/edit/'. $type])) { |
|
73 | - $item = &$items['user/%user_category/edit/'. $type]; |
|
72 | + if (!empty($items['user/%user_category/edit/'.$type])) { |
|
73 | + $item = &$items['user/%user_category/edit/'.$type]; |
|
74 | 74 | $item = array( |
75 | 75 | 'page callback' => 'content_profile_page_edit', |
76 | 76 | 'page arguments' => array($type, 1), |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // Else user may view the page when they are going to create their own profile |
92 | 92 | // or have permission to create it for others. |
93 | 93 | global $user; |
94 | - if ($user->uid == $account->uid || user_access('administer nodes') ){ |
|
94 | + if ($user->uid == $account->uid || user_access('administer nodes')) { |
|
95 | 95 | return node_access('create', $type); |
96 | 96 | } |
97 | 97 | return FALSE; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | if (!$node) { |
107 | 107 | $node = array('uid' => $account->uid, 'name' => (isset($account->name) ? $account->name : ''), 'type' => $type, 'language' => ''); |
108 | 108 | } |
109 | - return drupal_get_form($type .'_node_form', $node); |
|
109 | + return drupal_get_form($type.'_node_form', $node); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | function content_profile_views_api() { |
117 | 117 | return array( |
118 | 118 | 'api' => 2, |
119 | - 'path' => drupal_get_path('module', 'content_profile') .'/views', |
|
119 | + 'path' => drupal_get_path('module', 'content_profile').'/views', |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | if (is_object($type)) { |
202 | 202 | $type = $type->type; |
203 | 203 | } |
204 | - return variable_get('content_profile_use_'. $type, FALSE); |
|
204 | + return variable_get('content_profile_use_'.$type, FALSE); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param $value |
218 | 218 | * The value to compare the given setting too. |
219 | 219 | */ |
220 | -function content_profile_get_types($op = 'types', $setting = NULL , $value = TRUE) { |
|
220 | +function content_profile_get_types($op = 'types', $setting = NULL, $value = TRUE) { |
|
221 | 221 | $types = array(); |
222 | 222 | |
223 | 223 | foreach (node_get_types($op) as $type => $info) { |
@@ -235,17 +235,17 @@ discard block |
||
235 | 235 | function content_profile_node_type($op, $info) { |
236 | 236 | switch ($op) { |
237 | 237 | case 'delete': |
238 | - variable_del('content_profile_use_'. $info->type); |
|
239 | - variable_del('content_profile_'. $info->type); |
|
238 | + variable_del('content_profile_use_'.$info->type); |
|
239 | + variable_del('content_profile_'.$info->type); |
|
240 | 240 | break; |
241 | 241 | case 'update': |
242 | 242 | if (!empty($info->old_type) && $info->old_type != $info->type) { |
243 | 243 | if (is_content_profile($info->old_type)) { |
244 | - $settings = variable_get('content_profile_'. $info->old_type, array()); |
|
245 | - variable_del('content_profile_use_'. $info->old_type); |
|
246 | - variable_del('content_profile_'. $info->old_type); |
|
247 | - variable_set('content_profile_use_'. $info->type, 1); |
|
248 | - variable_set('content_profile_'. $info->type, $settings); |
|
244 | + $settings = variable_get('content_profile_'.$info->old_type, array()); |
|
245 | + variable_del('content_profile_use_'.$info->old_type); |
|
246 | + variable_del('content_profile_'.$info->old_type); |
|
247 | + variable_set('content_profile_use_'.$info->type, 1); |
|
248 | + variable_set('content_profile_'.$info->type, $settings); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | break; |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | $form['content_profile']['content_profile_use'] = array( |
269 | 269 | '#type' => 'checkbox', |
270 | 270 | '#title' => t('Use this content type as a content profile for users'), |
271 | - '#default_value' => variable_get('content_profile_use_'. $form['#node_type']->type, FALSE), |
|
271 | + '#default_value' => variable_get('content_profile_use_'.$form['#node_type']->type, FALSE), |
|
272 | 272 | ); |
273 | 273 | } |
274 | - elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
274 | + elseif (isset($form['#node']) && $form['#node']->type.'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
275 | 275 | // Customize the redirect target and buttons of our own node forms. |
276 | 276 | if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit' || arg(2) == 'profile') { |
277 | 277 | $form['buttons']['preview']['#access'] = FALSE; |
278 | 278 | $form['buttons']['delete']['#access'] = FALSE; |
279 | - $form['#redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q']; |
|
279 | + $form['#redirect'] = arg(2) == 'profile' ? 'user/'.$form['#node']->uid : $_GET['q']; |
|
280 | 280 | } |
281 | 281 | // Set the author value - note that this works only for admins. |
282 | 282 | if (!empty($_GET['uid']) && ($uid = intval($_GET['uid'])) && ($user = user_load($uid))) { |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $condition = array_fill(0, count($types), "type = '%s'"); |
314 | 314 | $arguments = array_merge(array_keys($types), array($account->uid)); |
315 | 315 | |
316 | - $result = db_query("SELECT * FROM {node} WHERE (". implode(' OR ', $condition) .") AND uid = %d", $arguments); |
|
316 | + $result = db_query("SELECT * FROM {node} WHERE (".implode(' OR ', $condition).") AND uid = %d", $arguments); |
|
317 | 317 | while ($node = db_fetch_object($result)) { |
318 | 318 | _content_profile_node_delete($node); |
319 | 319 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | // Check if this nodetype already exists |
381 | 381 | if ($nid = content_profile_profile_exists($node, $node->uid)) { |
382 | 382 | // This node already exists, redirect to edit page |
383 | - drupal_goto('node/'. $nid .'/edit', 'destination=user/'. $node->uid); |
|
383 | + drupal_goto('node/'.$nid.'/edit', 'destination=user/'.$node->uid); |
|
384 | 384 | } |
385 | 385 | } |
386 | 386 | elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) { |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * e.g. user_edit, register or weight. |
429 | 429 | */ |
430 | 430 | function content_profile_get_settings($type, $return = 'all') { |
431 | - $settings = variable_get('content_profile_'. $type, array()); |
|
431 | + $settings = variable_get('content_profile_'.$type, array()); |
|
432 | 432 | $settings += content_profile_settings_info(); |
433 | 433 | if ($return == 'all') { |
434 | 434 | return $settings; |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * Saves the content_profile settings of a content type. |
441 | 441 | */ |
442 | 442 | function content_profile_set_settings($type, $settings) { |
443 | - variable_set('content_profile_'. $type, $settings); |
|
443 | + variable_set('content_profile_'.$type, $settings); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | return node_help('node/%/edit', array(1 => $node->nid)); |
507 | 507 | } |
508 | 508 | else { |
509 | - return node_help('node/add/'. $type, array('node', 'add', $type)); |
|
509 | + return node_help('node/add/'.$type, array('node', 'add', $type)); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | } |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | $node = content_profile_load($type, $uid); |
526 | 526 | |
527 | 527 | if (($style = content_profile_get_settings($type, 'user_display')) && $node && node_access('view', $node)) { |
528 | - $content['content_profile_'. $type] = array( |
|
528 | + $content['content_profile_'.$type] = array( |
|
529 | 529 | '#theme' => ($style == 'link') ? 'content_profile_display_link' : 'content_profile_display_view', |
530 | 530 | '#edit_link' => content_profile_get_settings($type, 'edit_link'), |
531 | 531 | '#uid' => $uid, |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | // Working around the bug described at http://drupal.org/node/302873 |
539 | 539 | module_load_include('inc', 'content_profile', 'content_profile.theme'); |
540 | 540 | } |
541 | - elseif (user_access('create '. $type .' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) { |
|
542 | - $content['content_profile_'. $type] = array( |
|
541 | + elseif (user_access('create '.$type.' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) { |
|
542 | + $content['content_profile_'.$type] = array( |
|
543 | 543 | '#admin' => $uid != $user->uid, |
544 | 544 | '#theme' => 'content_profile_display_add_link', |
545 | 545 | '#uid' => $uid, |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | ), |
581 | 581 | ); |
582 | 582 | if (module_exists('pageroute')) { |
583 | - $return['content_profile_pageroute_empty'] = array( |
|
583 | + $return['content_profile_pageroute_empty'] = array( |
|
584 | 584 | 'arguments' => array('type_name' => NULL), |
585 | 585 | 'file' => 'content_profile.pageroute.inc', |
586 | 586 | ); |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | */ |
633 | 633 | function content_profile_simpletest() { |
634 | 634 | // Scan through content_profile/tests directory for any .test files to tell SimpleTest module. |
635 | - $tests = file_scan_directory(drupal_get_path('module', 'content_profile') .'/tests', '\.test'); |
|
635 | + $tests = file_scan_directory(drupal_get_path('module', 'content_profile').'/tests', '\.test'); |
|
636 | 636 | return array_keys($tests); |
637 | 637 | } |
638 | 638 |
@@ -270,8 +270,7 @@ discard block |
||
270 | 270 | '#title' => t('Use this content type as a content profile for users'), |
271 | 271 | '#default_value' => variable_get('content_profile_use_'. $form['#node_type']->type, FALSE), |
272 | 272 | ); |
273 | - } |
|
274 | - elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
273 | + } elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { |
|
275 | 274 | // Customize the redirect target and buttons of our own node forms. |
276 | 275 | if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit' || arg(2) == 'profile') { |
277 | 276 | $form['buttons']['preview']['#access'] = FALSE; |
@@ -382,8 +381,7 @@ discard block |
||
382 | 381 | // This node already exists, redirect to edit page |
383 | 382 | drupal_goto('node/'. $nid .'/edit', 'destination=user/'. $node->uid); |
384 | 383 | } |
385 | - } |
|
386 | - elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) { |
|
384 | + } elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) { |
|
387 | 385 | $form = $a3; |
388 | 386 | // Only validate if the user-name changed or we add a new node |
389 | 387 | if (!empty($node->nid) && $form['author']['name']['#default_value'] == $node->name) { |
@@ -394,8 +392,7 @@ discard block |
||
394 | 392 | if ($uid && content_profile_profile_exists($node, $uid)) { |
395 | 393 | form_set_error('name', t('This user already has a content profile of this type. You can only create one profile per user.')); |
396 | 394 | } |
397 | - } |
|
398 | - elseif ($op == 'prepare translation' && is_content_profile($node->translation_source)) { |
|
395 | + } elseif ($op == 'prepare translation' && is_content_profile($node->translation_source)) { |
|
399 | 396 | // Make sure the translated profile belongs to the same user. |
400 | 397 | $node->uid = $node->translation_source->uid; |
401 | 398 | $node->name = $node->translation_source->name; |
@@ -504,8 +501,7 @@ discard block |
||
504 | 501 | $node = content_profile_load($type, $arg[1]); |
505 | 502 | if ($node) { |
506 | 503 | return node_help('node/%/edit', array(1 => $node->nid)); |
507 | - } |
|
508 | - else { |
|
504 | + } else { |
|
509 | 505 | return node_help('node/add/'. $type, array('node', 'add', $type)); |
510 | 506 | } |
511 | 507 | } |
@@ -537,8 +533,7 @@ discard block |
||
537 | 533 | |
538 | 534 | // Working around the bug described at http://drupal.org/node/302873 |
539 | 535 | module_load_include('inc', 'content_profile', 'content_profile.theme'); |
540 | - } |
|
541 | - elseif (user_access('create '. $type .' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) { |
|
536 | + } elseif (user_access('create '. $type .' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) { |
|
542 | 537 | $content['content_profile_'. $type] = array( |
543 | 538 | '#admin' => $uid != $user->uid, |
544 | 539 | '#theme' => 'content_profile_display_add_link', |
@@ -10,6 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Rewrite the forum administration page with our new access rules. |
13 | + * @param boolean $is_container |
|
13 | 14 | */ |
14 | 15 | function _forum_access_forum_form(&$form, &$form_state, $is_container) { |
15 | 16 | $tid = (isset($form['tid']['#value']) ? $form['tid']['#value'] : NULL); |
@@ -663,6 +664,8 @@ discard block |
||
663 | 664 | * This is a multistep operation : we go through all nodes by packs of 20. |
664 | 665 | * The batch processing engine interrupts processing and sends progress |
665 | 666 | * feedback after 1 second execution time. |
667 | + * @param integer $limit |
|
668 | + * @param integer $count |
|
666 | 669 | */ |
667 | 670 | function _forum_access_update_batch_operation($tid, $limit, $count, &$context) { |
668 | 671 | if (empty($context['sandbox'])) { |
@@ -693,6 +696,7 @@ discard block |
||
693 | 696 | |
694 | 697 | /** |
695 | 698 | * Post-processing for forum_access_form_submit(). |
699 | + * @param boolean $success |
|
696 | 700 | */ |
697 | 701 | function _forum_access_update_batch_finished($success, $results, $operations) { |
698 | 702 | if ($success) { |
@@ -12,33 +12,33 @@ discard block |
||
12 | 12 | * Rewrite the forum administration page with our new access rules. |
13 | 13 | */ |
14 | 14 | function _forum_access_forum_form(&$form, &$form_state, $is_container) { |
15 | - $tid = (isset($form['tid']['#value']) ? $form['tid']['#value'] : NULL); |
|
16 | - if (isset($tid) && !forum_access_access($tid, 'view', NULL, FALSE)) { |
|
15 | + $tid = (isset($form['tid']['#value']) ? $form['tid']['#value'] : NULL); |
|
16 | + if (isset($tid) && !forum_access_access($tid, 'view', NULL, FALSE)) { |
|
17 | 17 | drupal_access_denied(); // Deny access if the user doesn't have View access. |
18 | 18 | module_invoke_all('exit'); |
19 | 19 | exit; |
20 | - } |
|
20 | + } |
|
21 | 21 | |
22 | - $roles = user_roles(); |
|
23 | - if (isset($tid)) { // edit |
|
22 | + $roles = user_roles(); |
|
23 | + if (isset($tid)) { // edit |
|
24 | 24 | $template_tid = variable_get('forum_access_default_template_tid', 0); |
25 | 25 | $settings = _forum_access_get_settings($tid); |
26 | - } |
|
27 | - else { // create |
|
26 | + } |
|
27 | + else { // create |
|
28 | 28 | $template_tid = variable_get('forum_access_new_template_tid', NULL); |
29 | 29 | $settings = _forum_access_get_settings($template_tid); |
30 | - } |
|
31 | - $fa_priority = $settings['priority']; |
|
30 | + } |
|
31 | + $fa_priority = $settings['priority']; |
|
32 | 32 | |
33 | - $form['forum_access'] = array( |
|
33 | + $form['forum_access'] = array( |
|
34 | 34 | '#type' => 'fieldset', |
35 | 35 | '#title' => t('Access control'), |
36 | 36 | '#collapsible' => TRUE, |
37 | 37 | '#tree' => TRUE, |
38 | - ); |
|
38 | + ); |
|
39 | 39 | |
40 | - $tr = 't'; |
|
41 | - $variables = array( |
|
40 | + $tr = 't'; |
|
41 | + $variables = array( |
|
42 | 42 | '!access_content' => '<em>'. l($tr('access content'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)) .'</em>', |
43 | 43 | '!access_comments' => '<em>'. l($tr('access comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
44 | 44 | '!create_forum_topics' => '<em>'. l($tr('create forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
@@ -51,368 +51,368 @@ discard block |
||
51 | 51 | '!administer_comments' => '<em>'. l($tr('administer comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
52 | 52 | '!administer_forums' => '<em>'. l($tr('administer forums'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
53 | 53 | '!administer_nodes' => '<em>'. l($tr('administer nodes'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)) .'</em>', |
54 | - ); |
|
55 | - if (!$is_container) { |
|
54 | + ); |
|
55 | + if (!$is_container) { |
|
56 | 56 | $form['forum_access']['permissions'] = array( |
57 | - '#type' => 'fieldset', |
|
58 | - '#title' => $tr('Permissions information'), |
|
59 | - '#collapsible' => TRUE, |
|
60 | - '#collapsed' => TRUE, |
|
57 | + '#type' => 'fieldset', |
|
58 | + '#title' => $tr('Permissions information'), |
|
59 | + '#collapsible' => TRUE, |
|
60 | + '#collapsed' => TRUE, |
|
61 | 61 | ); |
62 | 62 | $form['forum_access']['permissions'][] = array( |
63 | - '#type' => 'markup', |
|
64 | - '#value' => '<div>'. t('Note that users need') .'<ul style="margin-top: 0"><li>'. |
|
65 | - t('the !access_content and !access_comments permissions <strong>AND <em>View</em></strong> to be able to see this forum and its content at all,', $variables) .'</li><li>'. |
|
66 | - t('the !create_forum_topics (and similar) permissions <strong>AND <em>Post</em></strong> to be able to create forum content, and', $variables) .'</li><li>'. |
|
67 | - t('the !post_comments and (probably) !post_comments_without_approval permission <!TAG>AND <em>Comment</em></!TAG> to be able to post comments/replies;', $variables + array('!TAG' => (variable_get('forum_access_D5_legacy_mode', FALSE) ? 'del title="'. t('Drupal 5 legacy mode') .'"' : 'strong'))) .'</li><li>'. |
|
68 | - t('the !edit_own_forum_topics or !edit_any_forum_topics (and similar) permissions <strong>AND (<em>Edit</em> AND <em>Comment</em></strong>) can be added if desired, <strong>plus</strong>', $variables) .'</li><li>'. |
|
69 | - t('the !delete_own_forum_topics or !delete_any_forum_topics (and similar) permissions (<strong>OR <em>Delete</em></strong>) if desired;', $variables) .'</li><li>'. |
|
70 | - t('the !administer_comments (global!) permission <strong>OR <em>Edit</em>/<em>Delete</em></strong> to be able to edit/delete comments;', $variables) .'</li><li>'. |
|
71 | - t('the !administer_forums permission <strong>AND <em>View</em></strong> to be able to administer forums (and change access!).', $variables) .'</li></ul>'. |
|
72 | - t('Furthermore note that content which is not published is treated in a different way by Drupal: it can be viewed only by its author or by users with the !administer_nodes permission. Unpublished comments and replies are accessible to users with <strong><em>Edit</em> OR <em>Delete</em></strong>, <strong>OR</strong> with the !administer_comments permission, but they are never counted on the forum page.', $variables) .'</div>', |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - // Load a template: |
|
77 | - $vid = _forum_access_get_vid(); |
|
78 | - $form['forum_access']['template'] = array( |
|
79 | - '#type' => 'fieldset', |
|
80 | - '#title' => $tr('Template'), |
|
81 | - '#collapsible' => TRUE, |
|
82 | - '#collapsed' => empty($template_tid), |
|
83 | - ); |
|
84 | - $form['forum_access']['template']['taxonomy'][$vid] = taxonomy_form($vid, array($template_tid), ''); |
|
85 | - $form['forum_access']['template']['taxonomy'][$vid]['#description'] = t("Select a forum and click !Load to retrieve that forum's settings as a starting point for this forum or container.", array('!Load' => '['. t('Load') .']')); |
|
86 | - $form['forum_access']['template']['load_button'] = array( |
|
63 | + '#type' => 'markup', |
|
64 | + '#value' => '<div>'. t('Note that users need') .'<ul style="margin-top: 0"><li>'. |
|
65 | + t('the !access_content and !access_comments permissions <strong>AND <em>View</em></strong> to be able to see this forum and its content at all,', $variables) .'</li><li>'. |
|
66 | + t('the !create_forum_topics (and similar) permissions <strong>AND <em>Post</em></strong> to be able to create forum content, and', $variables) .'</li><li>'. |
|
67 | + t('the !post_comments and (probably) !post_comments_without_approval permission <!TAG>AND <em>Comment</em></!TAG> to be able to post comments/replies;', $variables + array('!TAG' => (variable_get('forum_access_D5_legacy_mode', FALSE) ? 'del title="'. t('Drupal 5 legacy mode') .'"' : 'strong'))) .'</li><li>'. |
|
68 | + t('the !edit_own_forum_topics or !edit_any_forum_topics (and similar) permissions <strong>AND (<em>Edit</em> AND <em>Comment</em></strong>) can be added if desired, <strong>plus</strong>', $variables) .'</li><li>'. |
|
69 | + t('the !delete_own_forum_topics or !delete_any_forum_topics (and similar) permissions (<strong>OR <em>Delete</em></strong>) if desired;', $variables) .'</li><li>'. |
|
70 | + t('the !administer_comments (global!) permission <strong>OR <em>Edit</em>/<em>Delete</em></strong> to be able to edit/delete comments;', $variables) .'</li><li>'. |
|
71 | + t('the !administer_forums permission <strong>AND <em>View</em></strong> to be able to administer forums (and change access!).', $variables) .'</li></ul>'. |
|
72 | + t('Furthermore note that content which is not published is treated in a different way by Drupal: it can be viewed only by its author or by users with the !administer_nodes permission. Unpublished comments and replies are accessible to users with <strong><em>Edit</em> OR <em>Delete</em></strong>, <strong>OR</strong> with the !administer_comments permission, but they are never counted on the forum page.', $variables) .'</div>', |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + // Load a template: |
|
77 | + $vid = _forum_access_get_vid(); |
|
78 | + $form['forum_access']['template'] = array( |
|
79 | + '#type' => 'fieldset', |
|
80 | + '#title' => $tr('Template'), |
|
81 | + '#collapsible' => TRUE, |
|
82 | + '#collapsed' => empty($template_tid), |
|
83 | + ); |
|
84 | + $form['forum_access']['template']['taxonomy'][$vid] = taxonomy_form($vid, array($template_tid), ''); |
|
85 | + $form['forum_access']['template']['taxonomy'][$vid]['#description'] = t("Select a forum and click !Load to retrieve that forum's settings as a starting point for this forum or container.", array('!Load' => '['. t('Load') .']')); |
|
86 | + $form['forum_access']['template']['load_button'] = array( |
|
87 | 87 | '#type' => 'button', |
88 | 88 | '#name' => 'load_template', |
89 | 89 | '#value' => t('Load'), |
90 | 90 | '#submit' => FALSE, |
91 | - ); |
|
92 | - $form['forum_access']['template']['template_tid'] = array( |
|
91 | + ); |
|
92 | + $form['forum_access']['template']['template_tid'] = array( |
|
93 | 93 | '#type' => 'value', |
94 | 94 | '#value' => NULL, |
95 | - ); |
|
96 | - $form['forum_access']['template']['select_by_default'] = array( |
|
95 | + ); |
|
96 | + $form['forum_access']['template']['select_by_default'] = array( |
|
97 | 97 | '#type' => 'checkbox', |
98 | 98 | '#title' => t('Remember this selection.'), |
99 | 99 | '#default_value' => FALSE, |
100 | - ); |
|
101 | - $form['forum_access']['template']['load_for_new'] = array( |
|
100 | + ); |
|
101 | + $form['forum_access']['template']['load_for_new'] = array( |
|
102 | 102 | '#type' => 'checkbox', |
103 | 103 | '#title' => t("Use the selected forum's settings as defaults for new forums and containers."), |
104 | 104 | '#default_value' => FALSE, |
105 | - ); |
|
106 | - $form['forum_access']['#after_build'][] = '_forum_access_forum_form_after_build'; |
|
105 | + ); |
|
106 | + $form['forum_access']['#after_build'][] = '_forum_access_forum_form_after_build'; |
|
107 | 107 | |
108 | - // Column titles: |
|
109 | - $form['forum_access']['headers']['view'] = array( |
|
108 | + // Column titles: |
|
109 | + $form['forum_access']['headers']['view'] = array( |
|
110 | 110 | '#type' => 'item', |
111 | 111 | '#prefix' => '<div class="forum-access-div">', |
112 | 112 | '#title' => ($is_container ? t('View this container') : t('View this forum')), |
113 | 113 | '#suffix' => '</div>', |
114 | - ); |
|
115 | - $forum_vocabulary = taxonomy_vocabulary_load(_forum_access_get_vid()); |
|
116 | - $form['forum_access']['headers']['create'] = array( |
|
114 | + ); |
|
115 | + $forum_vocabulary = taxonomy_vocabulary_load(_forum_access_get_vid()); |
|
116 | + $form['forum_access']['headers']['create'] = array( |
|
117 | 117 | '#type' => 'item', |
118 | 118 | '#prefix' => '<div class="forum-access-div" id="forum-access-div-container">', |
119 | 119 | '#title' => t('See this container in the %Forums selection list', array('%Forums' => $forum_vocabulary->name)), |
120 | 120 | '#suffix' => '</div>', |
121 | - ); |
|
122 | - if (!$is_container) { |
|
121 | + ); |
|
122 | + if (!$is_container) { |
|
123 | 123 | $form['forum_access']['headers']['create'] = array( // overwrite! |
124 | - '#type' => 'item', |
|
125 | - '#prefix' => '<div class="forum-access-div">', |
|
126 | - '#title' => t('Post in this forum'), |
|
127 | - '#suffix' => '</div>', |
|
124 | + '#type' => 'item', |
|
125 | + '#prefix' => '<div class="forum-access-div">', |
|
126 | + '#title' => t('Post in this forum'), |
|
127 | + '#suffix' => '</div>', |
|
128 | 128 | ); |
129 | 129 | $form['forum_access']['headers']['comment_create'] = array( |
130 | - '#type' => 'item', |
|
131 | - '#prefix' => '<div class="forum-access-div">', |
|
132 | - '#title' => t('Comment on posts'), |
|
133 | - '#suffix' => '</div>', |
|
130 | + '#type' => 'item', |
|
131 | + '#prefix' => '<div class="forum-access-div">', |
|
132 | + '#title' => t('Comment on posts'), |
|
133 | + '#suffix' => '</div>', |
|
134 | 134 | ); |
135 | 135 | $form['forum_access']['headers']['update'] = array( |
136 | - '#type' => 'item', |
|
137 | - '#prefix' => '<div class="forum-access-div">', |
|
138 | - '#title' => t('Edit posts'), |
|
139 | - '#suffix' => '</div>', |
|
136 | + '#type' => 'item', |
|
137 | + '#prefix' => '<div class="forum-access-div">', |
|
138 | + '#title' => t('Edit posts'), |
|
139 | + '#suffix' => '</div>', |
|
140 | 140 | ); |
141 | 141 | $form['forum_access']['headers']['delete'] = array( |
142 | - '#type' => 'item', |
|
143 | - '#prefix' => '<div class="forum-access-div">', |
|
144 | - '#title' => t('Delete posts'), |
|
145 | - '#suffix' => '</div>', |
|
146 | - ); |
|
147 | - } |
|
148 | - $form['forum_access']['headers']['clearer'] = array( |
|
149 | - '#value' => '<div class="forum-access-clearer"></div>', |
|
150 | - ); |
|
142 | + '#type' => 'item', |
|
143 | + '#prefix' => '<div class="forum-access-div">', |
|
144 | + '#title' => t('Delete posts'), |
|
145 | + '#suffix' => '</div>', |
|
146 | + ); |
|
147 | + } |
|
148 | + $form['forum_access']['headers']['clearer'] = array( |
|
149 | + '#value' => '<div class="forum-access-clearer"></div>', |
|
150 | + ); |
|
151 | 151 | |
152 | - // Column content (checkboxes): |
|
153 | - $form['forum_access']['view'] = array( |
|
152 | + // Column content (checkboxes): |
|
153 | + $form['forum_access']['view'] = array( |
|
154 | 154 | '#type' => 'checkboxes', |
155 | 155 | '#prefix' => '<div class="forum-access-div">', |
156 | 156 | '#suffix' => '</div>', |
157 | 157 | '#options' => $roles, |
158 | 158 | '#default_value' => $settings['view'], |
159 | 159 | '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
160 | - ); |
|
161 | - $form['forum_access']['create'] = array( |
|
160 | + ); |
|
161 | + $form['forum_access']['create'] = array( |
|
162 | 162 | '#type' => 'checkboxes', |
163 | 163 | '#prefix' => '<div class="forum-access-div">', |
164 | 164 | '#suffix' => '</div>', |
165 | 165 | '#options' => $roles, |
166 | 166 | '#default_value' => $settings['create'], |
167 | 167 | '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
168 | - ); |
|
169 | - if (!$is_container) { |
|
168 | + ); |
|
169 | + if (!$is_container) { |
|
170 | 170 | $form['forum_access']['comment_create'] = array( |
171 | - '#type' => 'checkboxes', |
|
172 | - '#prefix' => '<div class="forum-access-div">', |
|
173 | - '#suffix' => '</div>', |
|
174 | - '#options' => $roles, |
|
175 | - '#default_value' => $settings['comment_create'], |
|
176 | - '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
171 | + '#type' => 'checkboxes', |
|
172 | + '#prefix' => '<div class="forum-access-div">', |
|
173 | + '#suffix' => '</div>', |
|
174 | + '#options' => $roles, |
|
175 | + '#default_value' => $settings['comment_create'], |
|
176 | + '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
177 | 177 | ); |
178 | 178 | $form['forum_access']['update'] = array( |
179 | - '#type' => 'checkboxes', |
|
180 | - '#prefix' => '<div class="forum-access-div">', |
|
181 | - '#suffix' => '</div>', |
|
182 | - '#options' => $roles, |
|
183 | - '#default_value' => $settings['update'], |
|
184 | - '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
179 | + '#type' => 'checkboxes', |
|
180 | + '#prefix' => '<div class="forum-access-div">', |
|
181 | + '#suffix' => '</div>', |
|
182 | + '#options' => $roles, |
|
183 | + '#default_value' => $settings['update'], |
|
184 | + '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
185 | 185 | ); |
186 | 186 | $form['forum_access']['delete'] = array( |
187 | - '#type' => 'checkboxes', |
|
188 | - '#prefix' => '<div class="forum-access-div">', |
|
189 | - '#suffix' => '</div>', |
|
190 | - '#options' => $roles, |
|
191 | - '#default_value' => $settings['delete'], |
|
192 | - '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
193 | - ); |
|
194 | - } |
|
195 | - $form['forum_access']['clearer'] = array( |
|
187 | + '#type' => 'checkboxes', |
|
188 | + '#prefix' => '<div class="forum-access-div">', |
|
189 | + '#suffix' => '</div>', |
|
190 | + '#options' => $roles, |
|
191 | + '#default_value' => $settings['delete'], |
|
192 | + '#process' => array('expand_checkboxes', '_forum_access_forum_form_disable_checkboxes'), |
|
193 | + ); |
|
194 | + } |
|
195 | + $form['forum_access']['clearer'] = array( |
|
196 | 196 | '#type' => 'item', |
197 | 197 | '#prefix' => '<div class="forum-access-clearer">', |
198 | 198 | '#suffix' => '</div>', |
199 | 199 | '#description' => t('For explanations of special cases, hover your mouse over role names.'), |
200 | - ); |
|
201 | - if ($is_container) { |
|
200 | + ); |
|
201 | + if ($is_container) { |
|
202 | 202 | $form['forum_access']['container_note'] = array( |
203 | - '#type' => 'item', |
|
204 | - '#description' => t('Users who can see any forum or container within this one should get the <strong><em>View</em></strong> grant. <br /> Users who can post to a forum within this container should get the <strong><em>See</em></strong> grant, so that this forum appears in the proper context in the selection list.', $variables), |
|
203 | + '#type' => 'item', |
|
204 | + '#description' => t('Users who can see any forum or container within this one should get the <strong><em>View</em></strong> grant. <br /> Users who can post to a forum within this container should get the <strong><em>See</em></strong> grant, so that this forum appears in the proper context in the selection list.', $variables), |
|
205 | 205 | ); |
206 | - } |
|
206 | + } |
|
207 | 207 | |
208 | - drupal_add_css(drupal_get_path('module', 'forum_access') .'/forum_access.css'); |
|
208 | + drupal_add_css(drupal_get_path('module', 'forum_access') .'/forum_access.css'); |
|
209 | 209 | |
210 | - // Find our moderator ACL: |
|
211 | - if (isset($tid)) { // edit, not new |
|
210 | + // Find our moderator ACL: |
|
211 | + if (isset($tid)) { // edit, not new |
|
212 | 212 | $acl_id = acl_get_id_by_number('forum_access', $tid); |
213 | 213 | if (!$acl_id) { // create one |
214 | - $acl_id = acl_create_new_acl('forum_access', NULL, $tid); |
|
215 | - // update every existing node in this forum to use this acl. |
|
216 | - $result = db_query("SELECT nid FROM {term_node} WHERE tid = %d", $tid); |
|
217 | - while ($node = db_fetch_object($result)) { |
|
214 | + $acl_id = acl_create_new_acl('forum_access', NULL, $tid); |
|
215 | + // update every existing node in this forum to use this acl. |
|
216 | + $result = db_query("SELECT nid FROM {term_node} WHERE tid = %d", $tid); |
|
217 | + while ($node = db_fetch_object($result)) { |
|
218 | 218 | // all privs to this ACL. |
219 | 219 | acl_node_add_acl($node->nid, $acl_id, 1, 1, 1); |
220 | - } |
|
220 | + } |
|
221 | 221 | } |
222 | 222 | $form['forum_access']['acl'] = acl_edit_form($acl_id, t('Moderators')); |
223 | 223 | $form['forum_access']['acl'][] = array( |
224 | - '#type' => 'markup', |
|
225 | - '#value' => '<div>'. t('Moderators receive all grants above.') .'</div>', |
|
226 | - '#weight' => -1, |
|
224 | + '#type' => 'markup', |
|
225 | + '#value' => '<div>'. t('Moderators receive all grants above.') .'</div>', |
|
226 | + '#weight' => -1, |
|
227 | 227 | ); |
228 | 228 | $form['forum_access']['acl']['note'] = array( |
229 | - '#type' => 'markup', |
|
230 | - '#value' => '<div>'. t('Note: Changes to moderators are not saved until you click [!Save] below.', array('!Save' => $tr('Save'))) .'</div>', |
|
229 | + '#type' => 'markup', |
|
230 | + '#value' => '<div>'. t('Note: Changes to moderators are not saved until you click [!Save] below.', array('!Save' => $tr('Save'))) .'</div>', |
|
231 | 231 | ); |
232 | 232 | $form['forum_access']['acl']['#after_build'][] = '_forum_access_forum_form_after_build_acl0'; |
233 | 233 | $form['forum_access']['acl']['#after_build'] = array_reverse($form['forum_access']['acl']['#after_build']); |
234 | 234 | $form['forum_access']['acl']['#after_build'][] = '_forum_access_forum_form_after_build_acl2'; |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | - foreach (module_implements('node_access_records') as $module) { |
|
237 | + foreach (module_implements('node_access_records') as $module) { |
|
238 | 238 | $na_modules[$module] = $module; |
239 | - } |
|
240 | - unset($na_modules['forum_access']); |
|
241 | - unset($na_modules['acl']); |
|
242 | - if (count($na_modules) && !$is_container) { |
|
239 | + } |
|
240 | + unset($na_modules['forum_access']); |
|
241 | + unset($na_modules['acl']); |
|
242 | + if (count($na_modules) && !$is_container) { |
|
243 | 243 | $form['forum_access']['interference'] = array( |
244 | - '#type' => 'fieldset', |
|
245 | - '#title' => t('Module interference'), |
|
246 | - '#collapsible' => TRUE, |
|
244 | + '#type' => 'fieldset', |
|
245 | + '#title' => t('Module interference'), |
|
246 | + '#collapsible' => TRUE, |
|
247 | 247 | ); |
248 | 248 | $variables = array( |
249 | - '%content_type' => node_get_types('name', 'forum'), |
|
250 | - '!Forum_Access' => 'Forum Access', |
|
251 | - '!Content_Access' => l('Content Access', 'http://drupal.org/project/content_access'), |
|
252 | - '@Content_Access' => 'Content Access', |
|
253 | - '!ACL' => 'ACL', |
|
254 | - '!module_list' => '<ul><li>'. implode($na_modules, '</li><li>') .'</li></ul>', |
|
249 | + '%content_type' => node_get_types('name', 'forum'), |
|
250 | + '!Forum_Access' => 'Forum Access', |
|
251 | + '!Content_Access' => l('Content Access', 'http://drupal.org/project/content_access'), |
|
252 | + '@Content_Access' => 'Content Access', |
|
253 | + '!ACL' => 'ACL', |
|
254 | + '!module_list' => '<ul><li>'. implode($na_modules, '</li><li>') .'</li></ul>', |
|
255 | 255 | ); |
256 | 256 | $form['forum_access']['interference'][] = array( |
257 | - '#type' => 'item', |
|
258 | - '#value' => '<p>'. t("Besides !Forum_Access (and !ACL) you have installed the following node access module(s): !module_list The grants of every module are combined for each node. Access can only be granted, not removed — if a certain module grants a permission, the other(s) cannot deny it.", $variables) .'</p>', |
|
259 | - '#description' => t('Forums can contain other content types besides %content_type; !Forum_Access will contribute the grants defined above to every node in this forum, but other node access control modules may also contribute their grants, especially to nodes of types other than %content_type.', $variables), |
|
257 | + '#type' => 'item', |
|
258 | + '#value' => '<p>'. t("Besides !Forum_Access (and !ACL) you have installed the following node access module(s): !module_list The grants of every module are combined for each node. Access can only be granted, not removed — if a certain module grants a permission, the other(s) cannot deny it.", $variables) .'</p>', |
|
259 | + '#description' => t('Forums can contain other content types besides %content_type; !Forum_Access will contribute the grants defined above to every node in this forum, but other node access control modules may also contribute their grants, especially to nodes of types other than %content_type.', $variables), |
|
260 | 260 | ); |
261 | 261 | |
262 | 262 | if (module_exists('content_access')) { |
263 | - $ca_settings = variable_get('content_access_settings', array()); |
|
264 | - foreach (array('view', 'update', 'delete', 'per_node') as $type) { |
|
263 | + $ca_settings = variable_get('content_access_settings', array()); |
|
264 | + foreach (array('view', 'update', 'delete', 'per_node') as $type) { |
|
265 | 265 | $value = content_access_get_settings($type, 'forum'); |
266 | 266 | if (!empty($value)) { |
267 | - $ca_interferes = TRUE; |
|
267 | + $ca_interferes = TRUE; |
|
268 | + } |
|
268 | 269 | } |
269 | - } |
|
270 | - $ca_priority = content_access_get_settings('priority', 'forum'); |
|
271 | - $is_conflict = $ca_priority >= $fa_priority && !empty($ca_interferes) || $ca_priority > $fa_priority; |
|
272 | - $variables += array( |
|
270 | + $ca_priority = content_access_get_settings('priority', 'forum'); |
|
271 | + $is_conflict = $ca_priority >= $fa_priority && !empty($ca_interferes) || $ca_priority > $fa_priority; |
|
272 | + $variables += array( |
|
273 | 273 | '!link' => l(t('@Content_Access configuration for the %content_type type', $variables), 'admin/content/node-type/forum/access', array('html' => TRUE)), |
274 | 274 | '%Advanced' => $tr('Advanced'), |
275 | - ); |
|
276 | - $specifically = ($ca_priority == $fa_priority ? t('Specifically, any grants given by !Content_Access cannot be taken back by !Forum_Access.', $variables) : ''); |
|
277 | - if ($is_conflict) { |
|
275 | + ); |
|
276 | + $specifically = ($ca_priority == $fa_priority ? t('Specifically, any grants given by !Content_Access cannot be taken back by !Forum_Access.', $variables) : ''); |
|
277 | + if ($is_conflict) { |
|
278 | 278 | $form['forum_access']['interference']['by_content_access'] = array( |
279 | - '#type' => 'fieldset', |
|
280 | - '#title' => 'Content Access', |
|
281 | - '#collapsible' => FALSE, |
|
282 | - '#attributes' => array('class' => 'error'), |
|
279 | + '#type' => 'fieldset', |
|
280 | + '#title' => 'Content Access', |
|
281 | + '#collapsible' => FALSE, |
|
282 | + '#attributes' => array('class' => 'error'), |
|
283 | 283 | ); |
284 | 284 | $form['forum_access']['interference']['by_content_access'][] = array( |
285 | - '#value' => '<div>'. t('You have set the !Content_Access module to control access to content of type %content_type—this can interfere with proper operation of !Forum_Access!', $variables) ." $specifically</div>", |
|
285 | + '#value' => '<div>'. t('You have set the !Content_Access module to control access to content of type %content_type—this can interfere with proper operation of !Forum_Access!', $variables) ." $specifically</div>", |
|
286 | 286 | ); |
287 | 287 | if ($ca_priority == $fa_priority) { |
288 | - $form['forum_access']['interference']['by_content_access'][] = array( |
|
288 | + $form['forum_access']['interference']['by_content_access'][] = array( |
|
289 | 289 | '#value' => '<div>'. t("Unless you really know what you're doing, we recommend that you go to the !link page and clear all checkboxes. This will instruct @Content_Access to leave the %content_type nodes alone. However, if you put nodes of other content types into forums as well, then these content types will continue to have this problem.", $variables) .'</div>', |
290 | - ); |
|
290 | + ); |
|
291 | 291 | } |
292 | 292 | else { |
293 | - $form['forum_access']['interference']['by_content_access'][] = array( |
|
293 | + $form['forum_access']['interference']['by_content_access'][] = array( |
|
294 | 294 | '#value' => '<div>'. t("The priority of @Content_Access ($ca_priority) is higher than the priority of !Forum_Access ($fa_priority), which means the latter is <strong>completely disabled</strong> for the %content_type type! Unless you really know what you're doing, we recommend that you go to the !link page, change the priority (under %Advanced) to 0, and clear all checkboxes.", $variables) .'</div>', |
295 | - ); |
|
295 | + ); |
|
296 | 296 | } |
297 | 297 | $form['forum_access']['interference']['by_content_access'][] = array( |
298 | - '#value' => '<div>'. t("Alternatively, you can give !Forum_Access priority over @Content_Access by either raising the priority of !Forum_Access in every forum above the priority of @Content_Access, or by lowering the priority of @Content_Access for the content types in question below the priority of !Forum_Access.", $variables) .'</div>', |
|
298 | + '#value' => '<div>'. t("Alternatively, you can give !Forum_Access priority over @Content_Access by either raising the priority of !Forum_Access in every forum above the priority of @Content_Access, or by lowering the priority of @Content_Access for the content types in question below the priority of !Forum_Access.", $variables) .'</div>', |
|
299 | 299 | ); |
300 | - } |
|
301 | - else { |
|
300 | + } |
|
301 | + else { |
|
302 | 302 | $form['forum_access']['interference'][] = array( |
303 | - '#value' => '<p>'. t('Note: You have installed the !Content_Access module, which has the capability to grant access to content that would otherwise be protected by !Forum_Access. Be careful when configuring @Content_Access!', $variables) .'</p>', |
|
303 | + '#value' => '<p>'. t('Note: You have installed the !Content_Access module, which has the capability to grant access to content that would otherwise be protected by !Forum_Access. Be careful when configuring @Content_Access!', $variables) .'</p>', |
|
304 | 304 | ); |
305 | - } |
|
305 | + } |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | $form['forum_access']['interference']['advanced'] = array( |
309 | - '#type' => 'fieldset', |
|
310 | - '#title' => t('Advanced'), |
|
311 | - '#collapsible' => TRUE, |
|
312 | - '#collapsed' => !($fa_priority != 0), |
|
309 | + '#type' => 'fieldset', |
|
310 | + '#title' => t('Advanced'), |
|
311 | + '#collapsible' => TRUE, |
|
312 | + '#collapsed' => !($fa_priority != 0), |
|
313 | 313 | ); |
314 | 314 | $form['forum_access']['interference']['advanced']['priority'] = array( |
315 | - '#type' => 'weight', |
|
316 | - '#title' => t('Priority of !Forum_Access node grants in this forum', $variables), |
|
317 | - '#default_value' => $fa_priority, |
|
318 | - '#description' => t("If you have no other node access control modules installed, you should leave this at the default 0. <br /> Otherwise you can raise or lower the priority of !Forum_Access' grants. Out of all the grants contributed to a node, only those with the highest priority are used, and all others are discarded.", $variables), |
|
315 | + '#type' => 'weight', |
|
316 | + '#title' => t('Priority of !Forum_Access node grants in this forum', $variables), |
|
317 | + '#default_value' => $fa_priority, |
|
318 | + '#description' => t("If you have no other node access control modules installed, you should leave this at the default 0. <br /> Otherwise you can raise or lower the priority of !Forum_Access' grants. Out of all the grants contributed to a node, only those with the highest priority are used, and all others are discarded.", $variables), |
|
319 | 319 | ); |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - if (!$is_container) { |
|
322 | + if (!$is_container) { |
|
323 | 323 | $variables = array( |
324 | - '!Forum_Access' => l('Forum Access', 'http://drupal.org/project/forum_access'), |
|
325 | - '!ACL' => l('ACL', 'http://drupal.org/project/acl'), |
|
326 | - '%Module_interference' => t('Module interference'), |
|
327 | - '!Forum_Access-dev' => l('Forum Access 6.x-1.x-dev', 'http://drupal.org/node/96795', array('html' => TRUE)), |
|
328 | - '!ACL-dev' => l('ACL 6.x-1.x-dev', 'http://drupal.org/node/96794', array('html' => TRUE)), |
|
329 | - '%devel_node_access' => 'devel_node_access', |
|
330 | - '!Devel' => l('Devel', 'http://drupal.org/project/devel'), |
|
331 | - '!DNA' => 'DNA', |
|
332 | - '!debug_mode' => l('debug mode', 'admin/settings/devel', array('fragment' => 'edit-devel-node-access-debug-mode')), |
|
333 | - '!dna_summary' => l('devel/node_access/summary', 'devel/node_access/summary'), |
|
334 | - '!Rebuild_permissions' => '['. $tr('Rebuild permissions') .']', |
|
335 | - '!Post_settings_link' => l('admin/content/node-settings', 'admin/content/node-settings'), |
|
336 | - '!Forum_Access_' => l('Forum Access', 'http://drupal.org/project/issues/forum_access'), |
|
337 | - '!ACL_' => l('ACL', 'http://drupal.org/project/issues/acl'), |
|
324 | + '!Forum_Access' => l('Forum Access', 'http://drupal.org/project/forum_access'), |
|
325 | + '!ACL' => l('ACL', 'http://drupal.org/project/acl'), |
|
326 | + '%Module_interference' => t('Module interference'), |
|
327 | + '!Forum_Access-dev' => l('Forum Access 6.x-1.x-dev', 'http://drupal.org/node/96795', array('html' => TRUE)), |
|
328 | + '!ACL-dev' => l('ACL 6.x-1.x-dev', 'http://drupal.org/node/96794', array('html' => TRUE)), |
|
329 | + '%devel_node_access' => 'devel_node_access', |
|
330 | + '!Devel' => l('Devel', 'http://drupal.org/project/devel'), |
|
331 | + '!DNA' => 'DNA', |
|
332 | + '!debug_mode' => l('debug mode', 'admin/settings/devel', array('fragment' => 'edit-devel-node-access-debug-mode')), |
|
333 | + '!dna_summary' => l('devel/node_access/summary', 'devel/node_access/summary'), |
|
334 | + '!Rebuild_permissions' => '['. $tr('Rebuild permissions') .']', |
|
335 | + '!Post_settings_link' => l('admin/content/node-settings', 'admin/content/node-settings'), |
|
336 | + '!Forum_Access_' => l('Forum Access', 'http://drupal.org/project/issues/forum_access'), |
|
337 | + '!ACL_' => l('ACL', 'http://drupal.org/project/issues/acl'), |
|
338 | 338 | ); |
339 | 339 | $form['forum_access']['troubleshooting'] = array( |
340 | - '#type' => 'fieldset', |
|
341 | - '#title' => t('Trouble-shooting node access'), |
|
342 | - '#collapsible' => TRUE, |
|
343 | - '#collapsed' => TRUE, |
|
340 | + '#type' => 'fieldset', |
|
341 | + '#title' => t('Trouble-shooting node access'), |
|
342 | + '#collapsible' => TRUE, |
|
343 | + '#collapsed' => TRUE, |
|
344 | 344 | ); |
345 | 345 | $form['forum_access']['troubleshooting'][] = array( |
346 | - '#type' => 'item', |
|
347 | - '#value' => '<div>'. t("In case of problems, follow these steps until you've got it worked out:") .'<ol style="margin-top: 0"><li>'. |
|
348 | - t("Update to the 'recommended' !Forum_Access and !ACL releases for your version of Drupal.", $variables) .'</li><li>'. |
|
346 | + '#type' => 'item', |
|
347 | + '#value' => '<div>'. t("In case of problems, follow these steps until you've got it worked out:") .'<ol style="margin-top: 0"><li>'. |
|
348 | + t("Update to the 'recommended' !Forum_Access and !ACL releases for your version of Drupal.", $variables) .'</li><li>'. |
|
349 | 349 | (count($na_modules) ? t("Read %Module_interference above and update your other node access modules.", $variables) .'</li><li>' : '') . |
350 | - t("Check the release notes of the development snapshots for issues that might have been fixed in !Forum_Access-dev or !ACL-dev since the latest release.", $variables) .'</li><li>'. |
|
351 | - t("Install the %devel_node_access module (!DNA, part of the !Devel module) and enable its !debug_mode: !DNA will show you all the grants that actually control your nodes in a footer block on each node's page.", $variables) .'</li><li>'. |
|
352 | - t("Additional insight can be gained from !dna_summary and by enabling the second !DNA block.", $variables) .'</li><li>'. |
|
353 | - t("Click !Rebuild_permissions on !Post_settings_link and check DNA for changes.", $variables) .'</li><li>'. |
|
354 | - t("Check the issues queues of !Forum_Access_ and !ACL_ for existing reports and possible solutions.", $variables) .'</li><li>'. |
|
355 | - t("If all of this hasn't helped, then pick ONE node that is misbehaving, look at it using an account that can see the node (and that should NOT have access if that's your problem!), create a new issue in the issues queue, describe the problem... <ul><li> what did you do? </li><li> what did you expect? </li><li> what happened instead? </li></ul> ... and <strong>attach a screenshot of all the DNA records</strong> for that one node. <br /> Be sure to indicate paths (URLs) for every page and module that you mention.") .'</li></ol></div>', |
|
350 | + t("Check the release notes of the development snapshots for issues that might have been fixed in !Forum_Access-dev or !ACL-dev since the latest release.", $variables) .'</li><li>'. |
|
351 | + t("Install the %devel_node_access module (!DNA, part of the !Devel module) and enable its !debug_mode: !DNA will show you all the grants that actually control your nodes in a footer block on each node's page.", $variables) .'</li><li>'. |
|
352 | + t("Additional insight can be gained from !dna_summary and by enabling the second !DNA block.", $variables) .'</li><li>'. |
|
353 | + t("Click !Rebuild_permissions on !Post_settings_link and check DNA for changes.", $variables) .'</li><li>'. |
|
354 | + t("Check the issues queues of !Forum_Access_ and !ACL_ for existing reports and possible solutions.", $variables) .'</li><li>'. |
|
355 | + t("If all of this hasn't helped, then pick ONE node that is misbehaving, look at it using an account that can see the node (and that should NOT have access if that's your problem!), create a new issue in the issues queue, describe the problem... <ul><li> what did you do? </li><li> what did you expect? </li><li> what happened instead? </li></ul> ... and <strong>attach a screenshot of all the DNA records</strong> for that one node. <br /> Be sure to indicate paths (URLs) for every page and module that you mention.") .'</li></ol></div>', |
|
356 | 356 | ); |
357 | 357 | $form['forum_access']['troubleshooting'][] = array( |
358 | - '#type' => 'item', |
|
359 | - '#value' => '<div>'. t("Note: You should not keep the !Devel module enabled on a production site.", $variables) .'</div>', |
|
358 | + '#type' => 'item', |
|
359 | + '#value' => '<div>'. t("Note: You should not keep the !Devel module enabled on a production site.", $variables) .'</div>', |
|
360 | 360 | ); |
361 | - } |
|
361 | + } |
|
362 | 362 | |
363 | - if (!$is_container && isset($tid) && !node_access_needs_rebuild()) { |
|
363 | + if (!$is_container && isset($tid) && !node_access_needs_rebuild()) { |
|
364 | 364 | $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
365 | 365 | $limit = 20; // from _node_access_rebuild_batch_operation() |
366 | 366 | $threshold = variable_get('forum_access_batch_threshold', $limit); // change the variable if you want |
367 | 367 | $form['forum_access']['update_limit'] = array( |
368 | - '#type' => 'value', |
|
369 | - '#value' => $limit, |
|
368 | + '#type' => 'value', |
|
369 | + '#value' => $limit, |
|
370 | 370 | ); |
371 | 371 | $form['forum_access']['update_choice'] = array( |
372 | - '#type' => 'radios', |
|
373 | - '#title' => 'Update the permissions', |
|
374 | - '#description' => t('<em>If</em> you make any node access changes, then each node in this forum needs to be updated. Hover over the radiobuttons for details.'), |
|
375 | - '#options' => NULL, |
|
376 | - 0 => array( |
|
372 | + '#type' => 'radios', |
|
373 | + '#title' => 'Update the permissions', |
|
374 | + '#description' => t('<em>If</em> you make any node access changes, then each node in this forum needs to be updated. Hover over the radiobuttons for details.'), |
|
375 | + '#options' => NULL, |
|
376 | + 0 => array( |
|
377 | 377 | '#type' => 'radio', |
378 | 378 | '#title' => t('for all %count nodes immediately', array('%count' => $count)), |
379 | 379 | '#attributes' => array('title' => t('This option is the fastest, but with many nodes it can still take considerable time and memory. If it fails, it will leave your !node_access table in an inconsistent state.', array('!node_access' => '{node_access}'))), |
380 | 380 | '#return_value' => 0, |
381 | 381 | '#default_value' => ($count <= $threshold ? 0 : 1), |
382 | 382 | '#parents' => array('forum_access', 'update_choice'), |
383 | - ), |
|
384 | - 1 => array( |
|
383 | + ), |
|
384 | + 1 => array( |
|
385 | 385 | '#type' => 'radio', |
386 | 386 | '#title' => t('in batches of !limit now', array('!limit' => $limit)), |
387 | 387 | '#attributes' => array('title' => t('The batch option will always work reliably, but it takes longer to complete.')), |
388 | 388 | '#return_value' => 1, |
389 | 389 | '#default_value' => ($count <= $threshold ? 0 : 1), |
390 | 390 | '#parents' => array('forum_access', 'update_choice'), |
391 | - ), |
|
392 | - 2 => array( |
|
391 | + ), |
|
392 | + 2 => array( |
|
393 | 393 | '#type' => 'radio', |
394 | 394 | '#title' => t('rebuild <strong>all</strong> permissions later'), |
395 | 395 | '#attributes' => array('title' => t("This option will only set a flag to remind you to rebuild all permissions later; this is useful if you want to make multiple changes to your node access settings quickly and delay the updating until you're done.")), |
396 | 396 | '#return_value' => 2, |
397 | 397 | '#default_value' => ($count <= $threshold ? 0 : 1), |
398 | 398 | '#parents' => array('forum_access', 'update_choice'), |
399 | - ), |
|
400 | - '#attributes' => array('class' => 'forum-access-flowed'), |
|
399 | + ), |
|
400 | + '#attributes' => array('class' => 'forum-access-flowed'), |
|
401 | 401 | ); |
402 | - } |
|
403 | - if (isset($tid)) { |
|
402 | + } |
|
403 | + if (isset($tid)) { |
|
404 | 404 | $form['forum_access']['force_update'] = array( |
405 | - '#type' => 'checkbox', |
|
406 | - '#title' => t('Update even if unchanged'), |
|
405 | + '#type' => 'checkbox', |
|
406 | + '#title' => t('Update even if unchanged'), |
|
407 | 407 | ); |
408 | - } |
|
408 | + } |
|
409 | 409 | |
410 | - // Move some stuff down so our block goes in a nice place. |
|
411 | - $form['submit']['#weight'] = 10; |
|
412 | - $form['delete']['#weight'] = 10; |
|
410 | + // Move some stuff down so our block goes in a nice place. |
|
411 | + $form['submit']['#weight'] = 10; |
|
412 | + $form['delete']['#weight'] = 10; |
|
413 | 413 | |
414 | - $form['#validate'][] = '_forum_access_form_validate'; |
|
415 | - $form['#submit'][] = '_forum_access_form_submit'; |
|
414 | + $form['#validate'][] = '_forum_access_form_validate'; |
|
415 | + $form['#submit'][] = '_forum_access_form_submit'; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | /** |
@@ -420,82 +420,82 @@ discard block |
||
420 | 420 | * are the permissions of the corresponding role. |
421 | 421 | */ |
422 | 422 | function _forum_access_get_role_permissions() { |
423 | - static $permissions; |
|
424 | - if (empty($permissions)) { |
|
423 | + static $permissions; |
|
424 | + if (empty($permissions)) { |
|
425 | 425 | $permissions[DRUPAL_AUTHENTICATED_RID] = array(); |
426 | 426 | $result = db_query('SELECT r.rid, p.perm FROM {role} r INNER JOIN {permission} p ON r.rid = p.rid ORDER BY r.rid'); |
427 | 427 | while ($role = db_fetch_object($result)) { |
428 | - $permissions[$role->rid] = ($role->rid == DRUPAL_ANONYMOUS_RID ? array() : $permissions[DRUPAL_AUTHENTICATED_RID]); |
|
429 | - $permissions[$role->rid] += array_flip(explode(', ', $role->perm)); |
|
428 | + $permissions[$role->rid] = ($role->rid == DRUPAL_ANONYMOUS_RID ? array() : $permissions[DRUPAL_AUTHENTICATED_RID]); |
|
429 | + $permissions[$role->rid] += array_flip(explode(', ', $role->perm)); |
|
430 | + } |
|
430 | 431 | } |
431 | - } |
|
432 | - return $permissions; |
|
432 | + return $permissions; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | function _forum_access_forum_form_disable_checkboxes($element) { |
436 | - global $user; |
|
437 | - $tr = 't'; |
|
438 | - $moderator_rid = forum_access_query_moderator_rid(); |
|
436 | + global $user; |
|
437 | + $tr = 't'; |
|
438 | + $moderator_rid = forum_access_query_moderator_rid(); |
|
439 | 439 | |
440 | - $permissions = _forum_access_get_role_permissions(); |
|
441 | - $element_children = element_children($element); |
|
442 | - foreach ($element_children as $rid) { |
|
440 | + $permissions = _forum_access_get_role_permissions(); |
|
441 | + $element_children = element_children($element); |
|
442 | + foreach ($element_children as $rid) { |
|
443 | 443 | if ($rid == $moderator_rid) { |
444 | - $element[$rid]['#prefix'] = '<span title="'. t("This is the (temporary) @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and is only used temporarily by @Forum_Access — do NOT give this role to any user!", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments'), '@Forum_Access' => 'Forum Access')) .'" class="forum-access-temporary-moderator">'; |
|
445 | - $element[$rid]['#suffix'] = "</span>"; |
|
446 | - $element[$rid]['#default_value'] = TRUE; |
|
447 | - $element[$rid]['#disabled'] = TRUE; |
|
444 | + $element[$rid]['#prefix'] = '<span title="'. t("This is the (temporary) @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and is only used temporarily by @Forum_Access — do NOT give this role to any user!", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments'), '@Forum_Access' => 'Forum Access')) .'" class="forum-access-temporary-moderator">'; |
|
445 | + $element[$rid]['#suffix'] = "</span>"; |
|
446 | + $element[$rid]['#default_value'] = TRUE; |
|
447 | + $element[$rid]['#disabled'] = TRUE; |
|
448 | 448 | } |
449 | 449 | elseif ($element['#parents'][1] == 'create') { |
450 | - // Do nothing (Post is always mutable). |
|
450 | + // Do nothing (Post is always mutable). |
|
451 | 451 | } |
452 | 452 | elseif ($element['#parents'][1] == 'comment_create') { |
453 | 453 | } |
454 | 454 | elseif ($element['#parents'][1] == 'view' && isset($permissions[$rid]['administer forums'])) { |
455 | - $element[$rid]['#title'] = '<em>'. $element[$rid]['#title'] .'</em>'; |
|
456 | - $element[$rid]['#prefix'] = '<span title="'. t("This role has the '@administer_forums' permission, and granting '@View' enables the role holders to change the settings on this page, including @Access_control!", array('@administer_forums' => $tr('administer forums'), '@View' => t('View'), '@Access_control' => t('Access control'))) .'">'; |
|
457 | - if (isset($permissions[$rid]['administer nodes'])) { |
|
455 | + $element[$rid]['#title'] = '<em>'. $element[$rid]['#title'] .'</em>'; |
|
456 | + $element[$rid]['#prefix'] = '<span title="'. t("This role has the '@administer_forums' permission, and granting '@View' enables the role holders to change the settings on this page, including @Access_control!", array('@administer_forums' => $tr('administer forums'), '@View' => t('View'), '@Access_control' => t('Access control'))) .'">'; |
|
457 | + if (isset($permissions[$rid]['administer nodes'])) { |
|
458 | 458 | $element[$rid]['#prefix'] = str_replace('">', ' '. t("Because the role also has the '@administer_nodes' permission, it has full access to all nodes either way.", array('@administer_nodes' => $tr('administer nodes'))) .'">', $element[$rid]['#prefix']); |
459 | - } |
|
460 | - $element[$rid]['#suffix'] = "</span>"; |
|
459 | + } |
|
460 | + $element[$rid]['#suffix'] = "</span>"; |
|
461 | 461 | } |
462 | 462 | elseif (isset($permissions[$rid]['administer nodes'])) { |
463 | - $element[$rid]['#disabled'] = TRUE; |
|
464 | - $element[$rid]['#default_value'] = TRUE; |
|
465 | - $element[$rid]['#prefix'] = '<span title="'. ($rid != $moderator_rid |
|
463 | + $element[$rid]['#disabled'] = TRUE; |
|
464 | + $element[$rid]['#default_value'] = TRUE; |
|
465 | + $element[$rid]['#prefix'] = '<span title="'. ($rid != $moderator_rid |
|
466 | 466 | ? t("This role has the '@administer_nodes' permission and thus full access to all nodes.", array('@administer_nodes' => $tr('administer nodes'))) |
467 | 467 | : t("This is the @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and thus full access to all nodes and comments.", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments')))) .'">'; |
468 | - $element[$rid]['#suffix'] = "</span>"; |
|
468 | + $element[$rid]['#suffix'] = "</span>"; |
|
469 | + } |
|
469 | 470 | } |
470 | - } |
|
471 | - return $element; |
|
471 | + return $element; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | function _forum_access_forum_form_after_build_acl0($form, $form_state) { |
475 | - if (isset($form['#post']['forum_access']['template']['taxonomy'])) { |
|
475 | + if (isset($form['#post']['forum_access']['template']['taxonomy'])) { |
|
476 | 476 | // Get ACL's user_list for the template and replace it before ACL's after_build function gets its shot at it. |
477 | 477 | $imv = array_values($form['#post']['forum_access']['template']['taxonomy']); |
478 | 478 | $template_tid = reset($imv); |
479 | 479 | if ($acl_id = acl_get_id_by_number('forum_access', $template_tid)) { |
480 | - $f = acl_edit_form($acl_id, 'DUMMY'); |
|
481 | - $form['user_list']['#value'] = $f['user_list']['#default_value']; |
|
480 | + $f = acl_edit_form($acl_id, 'DUMMY'); |
|
481 | + $form['user_list']['#value'] = $f['user_list']['#default_value']; |
|
482 | 482 | } |
483 | - } |
|
484 | - return $form; |
|
483 | + } |
|
484 | + return $form; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | function _forum_access_forum_form_after_build_acl2($form, $form_state) { |
488 | - if (!count(unserialize($form['user_list']['#default_value'])) && !count(unserialize($form['user_list']['#value']))) { |
|
488 | + if (!count(unserialize($form['user_list']['#default_value'])) && !count(unserialize($form['user_list']['#value']))) { |
|
489 | 489 | $form['#collapsed'] = TRUE; |
490 | - } |
|
491 | - if ($form['user_list']['#default_value'] != $form['user_list']['#value']) { |
|
490 | + } |
|
491 | + if ($form['user_list']['#default_value'] != $form['user_list']['#value']) { |
|
492 | 492 | $form['note']['#value'] = preg_replace('/<div>/', '<div class="warning">', $form['note']['#value']); |
493 | - } |
|
494 | - return $form; |
|
493 | + } |
|
494 | + return $form; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | function _forum_access_forum_form_after_build($form, &$form_state) { |
498 | - if (isset($form_state['clicked_button']['#name']) && $form_state['clicked_button']['#name'] == $form['template']['load_button']['#name']) { |
|
498 | + if (isset($form_state['clicked_button']['#name']) && $form_state['clicked_button']['#name'] == $form['template']['load_button']['#name']) { |
|
499 | 499 | // Load a setting from a template: |
500 | 500 | $template_tid = reset(array_values($form['#post']['forum_access']['template']['taxonomy'])); |
501 | 501 | $form_state['values']['forum_access']['template']['template_tid'] = $template_tid; |
@@ -503,158 +503,158 @@ discard block |
||
503 | 503 | |
504 | 504 | $settings = _forum_access_get_settings($template_tid); |
505 | 505 | foreach (array('view', 'create', 'comment_create', 'update', 'delete') as $grant_type) { |
506 | - if (empty($form[$grant_type])) { |
|
506 | + if (empty($form[$grant_type])) { |
|
507 | 507 | continue; |
508 | - } |
|
509 | - foreach (element_children($form[$grant_type]) as $tid) { |
|
508 | + } |
|
509 | + foreach (element_children($form[$grant_type]) as $tid) { |
|
510 | 510 | $checked = array_search($tid, $settings[$grant_type]) !== FALSE; |
511 | 511 | $form[$grant_type][$tid]['#value'] = ($checked ? $tid : 0); |
512 | - } |
|
512 | + } |
|
513 | 513 | } |
514 | 514 | $form['interference']['advanced']['priority']['#value'] = $settings['priority']; |
515 | 515 | if ($settings['priority'] != 0) { |
516 | - $form['interference']['advanced']['#collapsed'] = FALSE; |
|
516 | + $form['interference']['advanced']['#collapsed'] = FALSE; |
|
517 | 517 | } |
518 | - } |
|
519 | - elseif (is_array(reset($form_state['values']['forum_access']['template']['taxonomy']))) { |
|
520 | - $imv = reset($form_state['values']['forum_access']['template']['taxonomy']); |
|
518 | + } |
|
519 | + elseif (is_array(reset($form_state['values']['forum_access']['template']['taxonomy']))) { |
|
520 | + $imv = reset($form_state['values']['forum_access']['template']['taxonomy']); |
|
521 | 521 | $template_tid = reset($imv); |
522 | - } |
|
523 | - if (isset($template_tid)) { |
|
522 | + } |
|
523 | + if (isset($template_tid)) { |
|
524 | 524 | $form['template']['select_by_default']['#value'] = ($template_tid && $template_tid == variable_get('forum_access_default_template_tid', 0)); |
525 | 525 | $form['template']['load_for_new']['#value'] = ($template_tid && $template_tid == variable_get('forum_access_new_template_tid', 0)); |
526 | - } |
|
527 | - return $form; |
|
526 | + } |
|
527 | + return $form; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | function _forum_access_form_validate($form, &$form_state) { |
531 | - global $user; |
|
531 | + global $user; |
|
532 | 532 | |
533 | - if ($user->uid == 1) { |
|
533 | + if ($user->uid == 1) { |
|
534 | 534 | return; |
535 | - } |
|
536 | - $access = $form_state['values']['forum_access']; // shortcut |
|
537 | - foreach ($access['view'] as $rid => $checked) { |
|
535 | + } |
|
536 | + $access = $form_state['values']['forum_access']; // shortcut |
|
537 | + foreach ($access['view'] as $rid => $checked) { |
|
538 | 538 | if ($checked && isset($user->roles[$rid])) { |
539 | - return; |
|
539 | + return; |
|
540 | + } |
|
540 | 541 | } |
541 | - } |
|
542 | - form_set_error('forum_access][view', t('You must assign %View access to a role that you hold.', array('%View' => 'View'))); |
|
542 | + form_set_error('forum_access][view', t('You must assign %View access to a role that you hold.', array('%View' => 'View'))); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | function _forum_access_form_submit($form, &$form_state) { |
546 | - $access = $form_state['values']['forum_access']; // shortcut |
|
546 | + $access = $form_state['values']['forum_access']; // shortcut |
|
547 | 547 | |
548 | - // Save template choice: |
|
549 | - $template_tid = reset(array_values($access['template']['taxonomy'])); |
|
550 | - if ($access['template']['select_by_default']) { |
|
548 | + // Save template choice: |
|
549 | + $template_tid = reset(array_values($access['template']['taxonomy'])); |
|
550 | + if ($access['template']['select_by_default']) { |
|
551 | 551 | variable_set('forum_access_default_template_tid', $template_tid); |
552 | - } |
|
553 | - elseif (variable_get('forum_access_default_template_tid', 0) == $template_tid) { |
|
552 | + } |
|
553 | + elseif (variable_get('forum_access_default_template_tid', 0) == $template_tid) { |
|
554 | 554 | variable_del('forum_access_default_template_tid'); |
555 | - } |
|
556 | - if ($access['template']['load_for_new']) { |
|
555 | + } |
|
556 | + if ($access['template']['load_for_new']) { |
|
557 | 557 | variable_set('forum_access_new_template_tid', $template_tid); |
558 | - } |
|
559 | - elseif (variable_get('forum_access_new_template_tid', 0) == $template_tid) { |
|
558 | + } |
|
559 | + elseif (variable_get('forum_access_new_template_tid', 0) == $template_tid) { |
|
560 | 560 | variable_del('forum_access_new_template_tid'); |
561 | - } |
|
562 | - module_load_include('node.inc', 'forum_access'); |
|
563 | - $moderator_rid = _forum_access_get_moderator_rid(TRUE); // create the moderators role if it doesn't exist |
|
564 | - |
|
565 | - // check for changes |
|
566 | - $is_changed = $is_new = strpos($_GET['q'], 'admin/content/forum/add/') === 0; |
|
567 | - $is_changed = $is_changed || !empty($access['force_update']); |
|
568 | - $form_initial_values = $form; // avoid Coder warning |
|
569 | - $form_initial_values = $form_initial_values['forum_access']; |
|
570 | - foreach (array('view', 'create', 'comment_create', 'update', 'delete') as $grant_type) { |
|
561 | + } |
|
562 | + module_load_include('node.inc', 'forum_access'); |
|
563 | + $moderator_rid = _forum_access_get_moderator_rid(TRUE); // create the moderators role if it doesn't exist |
|
564 | + |
|
565 | + // check for changes |
|
566 | + $is_changed = $is_new = strpos($_GET['q'], 'admin/content/forum/add/') === 0; |
|
567 | + $is_changed = $is_changed || !empty($access['force_update']); |
|
568 | + $form_initial_values = $form; // avoid Coder warning |
|
569 | + $form_initial_values = $form_initial_values['forum_access']; |
|
570 | + foreach (array('view', 'create', 'comment_create', 'update', 'delete') as $grant_type) { |
|
571 | 571 | if (isset($form_initial_values[$grant_type])) { |
572 | - $defaults = $form_initial_values[$grant_type]['#default_value']; |
|
573 | - $defaults = array_flip($defaults); |
|
574 | - foreach ($access[$grant_type] as $rid => $checked) { |
|
572 | + $defaults = $form_initial_values[$grant_type]['#default_value']; |
|
573 | + $defaults = array_flip($defaults); |
|
574 | + foreach ($access[$grant_type] as $rid => $checked) { |
|
575 | 575 | $is_changed = $is_changed || (empty($form_initial_values[$grant_type][$rid]['#disabled']) && !empty($checked) != isset($defaults[$rid])); |
576 | - } |
|
576 | + } |
|
577 | + } |
|
577 | 578 | } |
578 | - } |
|
579 | - if (!$is_changed && $access['acl']['user_list'] == $form_initial_values['acl']['user_list']['#default_value'] && $access['interference']['advanced']['priority'] == $form_initial_values['interference']['advanced']['priority']['#default_value']) { |
|
579 | + if (!$is_changed && $access['acl']['user_list'] == $form_initial_values['acl']['user_list']['#default_value'] && $access['interference']['advanced']['priority'] == $form_initial_values['interference']['advanced']['priority']['#default_value']) { |
|
580 | 580 | drupal_set_message(t('The content access permissions are unchanged.')); |
581 | 581 | return; |
582 | - } |
|
582 | + } |
|
583 | 583 | |
584 | - $tid = $form_state['values']['tid']; |
|
585 | - db_query("DELETE FROM {forum_access} WHERE tid = %d", $tid); |
|
584 | + $tid = $form_state['values']['tid']; |
|
585 | + db_query("DELETE FROM {forum_access} WHERE tid = %d", $tid); |
|
586 | 586 | |
587 | - $fa_priority = isset($access['interference']['advanced']['priority']) ? $access['interference']['advanced']['priority'] : 0; |
|
588 | - if (array_key_exists('acl', $access)) { |
|
587 | + $fa_priority = isset($access['interference']['advanced']['priority']) ? $access['interference']['advanced']['priority'] : 0; |
|
588 | + if (array_key_exists('acl', $access)) { |
|
589 | 589 | $moderators = unserialize($access['acl']['user_list']); |
590 | 590 | acl_save_form($access['acl'], $fa_priority); |
591 | - } |
|
592 | - $permissions = _forum_access_get_role_permissions(); |
|
593 | - foreach ($access['view'] as $rid => $checked) { |
|
591 | + } |
|
592 | + $permissions = _forum_access_get_role_permissions(); |
|
593 | + foreach ($access['view'] as $rid => $checked) { |
|
594 | 594 | if ($rid == $moderator_rid) { |
595 | - continue; |
|
595 | + continue; |
|
596 | 596 | } |
597 | 597 | if (isset($permissions[$rid]['administer nodes'])) { |
598 | - // We prefer not to save records for node administrators, because these have access anyway. |
|
599 | - if (isset($permissions[$rid]['administer forums']) && $access['view'][$rid]) { |
|
598 | + // We prefer not to save records for node administrators, because these have access anyway. |
|
599 | + if (isset($permissions[$rid]['administer forums']) && $access['view'][$rid]) { |
|
600 | 600 | // For forum administrators, View needs to be saved, ... |
601 | - } |
|
602 | - else { |
|
601 | + } |
|
602 | + else { |
|
603 | 603 | // ... otherwise forget View. |
604 | 604 | $access['view'][$rid] = FALSE; |
605 | - } |
|
606 | - if ($access['view'][$rid] || $access['create'][$rid] || $access['comment_create'][$rid]) { |
|
605 | + } |
|
606 | + if ($access['view'][$rid] || $access['create'][$rid] || $access['comment_create'][$rid]) { |
|
607 | 607 | db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
608 | 608 | $tid, $rid, !empty($access['view'][$rid]), 0, 0, !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
609 | - } |
|
609 | + } |
|
610 | 610 | } |
611 | 611 | else { |
612 | - db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
|
613 | - $tid, $rid, (bool) $checked, !empty($access['update'][$rid]), !empty($access['delete'][$rid]), !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
|
612 | + db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
|
613 | + $tid, $rid, (bool) $checked, !empty($access['update'][$rid]), !empty($access['delete'][$rid]), !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
|
614 | 614 | } |
615 | - } |
|
616 | - $tr = 't'; |
|
617 | - $link = l($tr('edit'), 'admin/content/forum/edit/forum/'. $tid); |
|
618 | - watchdog('access', 'Changed grants for %forum forum.', array('%forum' => $form_state['values']['name']), WATCHDOG_NOTICE, $link); |
|
615 | + } |
|
616 | + $tr = 't'; |
|
617 | + $link = l($tr('edit'), 'admin/content/forum/edit/forum/'. $tid); |
|
618 | + watchdog('access', 'Changed grants for %forum forum.', array('%forum' => $form_state['values']['name']), WATCHDOG_NOTICE, $link); |
|
619 | 619 | |
620 | - if (!$is_new && $form_state['values']['form_id'] != 'forum_form_container') { |
|
620 | + if (!$is_new && $form_state['values']['form_id'] != 'forum_form_container') { |
|
621 | 621 | if (!isset($access['update_choice']) || $access['update_choice'] == 2) { |
622 | - node_access_needs_rebuild(TRUE); |
|
622 | + node_access_needs_rebuild(TRUE); |
|
623 | 623 | } |
624 | 624 | elseif ($access['update_choice'] == 0) { |
625 | - // update immediately (but use the batch functions anyway |
|
626 | - $save_redirect = $form_state['redirect']; |
|
627 | - $form_state['redirect'] = $_GET['q']; |
|
628 | - $context = array(); |
|
629 | - $pending_error_messages = drupal_get_messages('error', FALSE); |
|
630 | - $our_error_message_index = (isset($pending_error_messages['error']) ? count($pending_error_messages['error']) : 0); |
|
631 | - _forum_access_update_batch_finished(FALSE, array(), array()); // add our error message (in case we die underway) |
|
632 | - _forum_access_update_batch_operation($tid, 999999, 1, $context); |
|
633 | - $pending_error_messages = drupal_get_messages('error', TRUE); // still alive, get and clear all 'error' messages |
|
634 | - unset($pending_error_messages['error'][$our_error_message_index]); // remove our error message |
|
635 | - foreach ($pending_error_messages['error'] as $message) { // replay any others |
|
625 | + // update immediately (but use the batch functions anyway |
|
626 | + $save_redirect = $form_state['redirect']; |
|
627 | + $form_state['redirect'] = $_GET['q']; |
|
628 | + $context = array(); |
|
629 | + $pending_error_messages = drupal_get_messages('error', FALSE); |
|
630 | + $our_error_message_index = (isset($pending_error_messages['error']) ? count($pending_error_messages['error']) : 0); |
|
631 | + _forum_access_update_batch_finished(FALSE, array(), array()); // add our error message (in case we die underway) |
|
632 | + _forum_access_update_batch_operation($tid, 999999, 1, $context); |
|
633 | + $pending_error_messages = drupal_get_messages('error', TRUE); // still alive, get and clear all 'error' messages |
|
634 | + unset($pending_error_messages['error'][$our_error_message_index]); // remove our error message |
|
635 | + foreach ($pending_error_messages['error'] as $message) { // replay any others |
|
636 | 636 | drupal_set_message($message, 'error'); |
637 | - } |
|
638 | - _forum_access_update_batch_finished(TRUE, array(), array()); |
|
639 | - $form_state['redirect'] = $save_redirect; |
|
637 | + } |
|
638 | + _forum_access_update_batch_finished(TRUE, array(), array()); |
|
639 | + $form_state['redirect'] = $save_redirect; |
|
640 | 640 | } |
641 | 641 | else { |
642 | - // mass update in batch mode, modeled after node.module |
|
643 | - $limit = $access['update_limit']; |
|
644 | - $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
|
645 | - $batch = array( |
|
642 | + // mass update in batch mode, modeled after node.module |
|
643 | + $limit = $access['update_limit']; |
|
644 | + $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
|
645 | + $batch = array( |
|
646 | 646 | 'title' => t('Updating content access permissions'), |
647 | 647 | 'file' => drupal_get_path('module', 'forum_access') .'/forum_access.admin.inc', |
648 | 648 | 'operations' => array( |
649 | - array('_forum_access_update_batch_operation', array($tid, $limit, $count)), |
|
649 | + array('_forum_access_update_batch_operation', array($tid, $limit, $count)), |
|
650 | 650 | ), |
651 | 651 | 'finished' => '_forum_access_update_batch_finished' |
652 | - ); |
|
653 | - batch_set($batch); |
|
652 | + ); |
|
653 | + batch_set($batch); |
|
654 | + } |
|
654 | 655 | } |
655 | - } |
|
656 | 656 | |
657 | - variable_del('forum_access_rids'); // clear cache |
|
657 | + variable_del('forum_access_rids'); // clear cache |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -665,73 +665,73 @@ discard block |
||
665 | 665 | * feedback after 1 second execution time. |
666 | 666 | */ |
667 | 667 | function _forum_access_update_batch_operation($tid, $limit, $count, &$context) { |
668 | - if (empty($context['sandbox'])) { |
|
668 | + if (empty($context['sandbox'])) { |
|
669 | 669 | // Initiate multistep processing. |
670 | 670 | $context['sandbox']['progress'] = 0; |
671 | 671 | $context['sandbox']['current_node'] = 0; |
672 | 672 | $context['sandbox']['max'] = $count; |
673 | - } |
|
673 | + } |
|
674 | 674 | |
675 | - // Process the next 20 nodes. |
|
676 | - $result = db_query_range("SELECT DISTINCT n.nid FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE n.nid > %d AND tn.tid = %d ORDER BY n.nid ASC", $context['sandbox']['current_node'], $tid, 0, $limit); |
|
677 | - while ($row = db_fetch_array($result)) { |
|
675 | + // Process the next 20 nodes. |
|
676 | + $result = db_query_range("SELECT DISTINCT n.nid FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE n.nid > %d AND tn.tid = %d ORDER BY n.nid ASC", $context['sandbox']['current_node'], $tid, 0, $limit); |
|
677 | + while ($row = db_fetch_array($result)) { |
|
678 | 678 | $loaded_node = node_load($row['nid'], NULL, TRUE); |
679 | 679 | // To preserve database integrity, only aquire grants if the node |
680 | 680 | // loads successfully. |
681 | 681 | if (!empty($loaded_node)) { |
682 | - node_access_acquire_grants($loaded_node); |
|
682 | + node_access_acquire_grants($loaded_node); |
|
683 | 683 | } |
684 | 684 | $context['sandbox']['progress']++; |
685 | 685 | $context['sandbox']['current_node'] = $loaded_node->nid; |
686 | - } |
|
686 | + } |
|
687 | 687 | |
688 | - // Multistep processing : report progress. |
|
689 | - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
688 | + // Multistep processing : report progress. |
|
689 | + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
|
690 | 690 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
691 | - } |
|
691 | + } |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | /** |
695 | 695 | * Post-processing for forum_access_form_submit(). |
696 | 696 | */ |
697 | 697 | function _forum_access_update_batch_finished($success, $results, $operations) { |
698 | - if ($success) { |
|
698 | + if ($success) { |
|
699 | 699 | drupal_set_message(t('The content access permissions have been updated.')); |
700 | 700 | cache_clear_all(); |
701 | - } |
|
702 | - else { |
|
701 | + } |
|
702 | + else { |
|
703 | 703 | drupal_set_message(t('The content access permissions have not been properly updated.'), 'error'); |
704 | - } |
|
704 | + } |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /** |
708 | 708 | * Add our settings to the forum administration settings page. |
709 | 709 | */ |
710 | 710 | function _forum_access_forum_admin_settings_form(&$form, &$form_state) { |
711 | - $variables = array( |
|
711 | + $variables = array( |
|
712 | 712 | '!Forum_Access' => 'Forum Access', |
713 | 713 | '%View' => 'View', |
714 | 714 | '%Post' => 'Post', |
715 | 715 | '%post_comments' => 'post comments', |
716 | - ); |
|
717 | - $form['forum_access'] = array( |
|
716 | + ); |
|
717 | + $form['forum_access'] = array( |
|
718 | 718 | '#type' => 'fieldset', |
719 | 719 | '#title' => 'Forum Access', |
720 | 720 | '#attributes' => array('id' => 'edit-forum-admin-settings-forum-access'), |
721 | - ); |
|
722 | - $form['forum_access']['note'] = array( |
|
721 | + ); |
|
722 | + $form['forum_access']['note'] = array( |
|
723 | 723 | '#type' => 'item', |
724 | 724 | '#value' => t('Note: All other !Forum_Access controls are on the administration pages of the individual forums.', $variables), |
725 | - ); |
|
726 | - $form['forum_access']['forum_access_D5_legacy_mode'] = array( |
|
725 | + ); |
|
726 | + $form['forum_access']['forum_access_D5_legacy_mode'] = array( |
|
727 | 727 | '#type' => 'checkbox', |
728 | 728 | '#title' => t('Drupal 5 legacy mode', $variables), |
729 | 729 | '#default_value' => variable_get('forum_access_D5_legacy_mode', FALSE), |
730 | 730 | '#description' => t('In Drupal 5, comment posting was not restricted by !Forum_Access; users with %View access (and the %post_comments permission) were always allowed to post forum comments. Starting with Drupal 6, posting comments is now restricted to users with %Post access. Turn this option on to revert to the old behavior. The default is OFF.', $variables), |
731 | - ); |
|
732 | - $buttons = $form['buttons']; |
|
733 | - unset($form['buttons']); |
|
734 | - $form['buttons'] = $buttons; |
|
731 | + ); |
|
732 | + $buttons = $form['buttons']; |
|
733 | + unset($form['buttons']); |
|
734 | + $form['buttons'] = $buttons; |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
@@ -739,63 +739,63 @@ discard block |
||
739 | 739 | */ |
740 | 740 | function _forum_access_get_settings($tid = NULL) { |
741 | 741 | $return = array('view' => array(), 'create' => array(), 'comment_create' => array(), 'update' => array(), 'delete' => array(), 'priority' => 0); |
742 | - if (!isset($tid)) { |
|
742 | + if (!isset($tid)) { |
|
743 | 743 | // Default to all users can read; all logged in users can post and comment. |
744 | 744 | $return['view'] = array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID); |
745 | 745 | $return['create'] = array(DRUPAL_AUTHENTICATED_RID); |
746 | 746 | $return['comment_create'] = array(DRUPAL_AUTHENTICATED_RID); |
747 | - } |
|
748 | - else { |
|
747 | + } |
|
748 | + else { |
|
749 | 749 | $result = db_query("SELECT * FROM {forum_access} where tid = %d", $tid); |
750 | 750 | while ($access = db_fetch_object($result)) { |
751 | - if ($access->grant_view) { |
|
751 | + if ($access->grant_view) { |
|
752 | 752 | $return['view'][] = $access->rid; |
753 | - } |
|
754 | - if ($access->grant_update) { |
|
753 | + } |
|
754 | + if ($access->grant_update) { |
|
755 | 755 | $return['update'][] = $access->rid; |
756 | - } |
|
757 | - if ($access->grant_delete) { |
|
756 | + } |
|
757 | + if ($access->grant_delete) { |
|
758 | 758 | $return['delete'][] = $access->rid; |
759 | - } |
|
760 | - if ($access->grant_create) { |
|
759 | + } |
|
760 | + if ($access->grant_create) { |
|
761 | 761 | $return['create'][] = $access->rid; |
762 | - } |
|
763 | - if ($access->grant_comment_create) { |
|
762 | + } |
|
763 | + if ($access->grant_comment_create) { |
|
764 | 764 | $return['comment_create'][] = $access->rid; |
765 | - } |
|
766 | - if ($access->rid == DRUPAL_AUTHENTICATED_RID) { // this is our reference |
|
765 | + } |
|
766 | + if ($access->rid == DRUPAL_AUTHENTICATED_RID) { // this is our reference |
|
767 | 767 | $return['priority'] = $access->priority; |
768 | - } |
|
768 | + } |
|
769 | + } |
|
769 | 770 | } |
770 | - } |
|
771 | - return $return; |
|
771 | + return $return; |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
775 | 775 | * Remove unusable 'edit' links from overview form. |
776 | 776 | */ |
777 | 777 | function _forum_access_forum_overview(&$form, &$form_state) { |
778 | - global $user; |
|
779 | - if ($user->uid == 1) { |
|
778 | + global $user; |
|
779 | + if ($user->uid == 1) { |
|
780 | 780 | return; |
781 | - } |
|
782 | - foreach ($form as $key => $value) { |
|
781 | + } |
|
782 | + foreach ($form as $key => $value) { |
|
783 | 783 | if (preg_match('/^tid:(.*):0$/', $key, $matches)) { |
784 | - if (!forum_access_access($matches[1], 'view', NULL, FALSE)) { |
|
784 | + if (!forum_access_access($matches[1], 'view', NULL, FALSE)) { |
|
785 | 785 | $form[$key]['edit']['#access'] = FALSE; |
786 | 786 | if (preg_match('|<a [^>]*>([^<]*)</a>|', $form[$key]['view']['#value'], $matches)) { |
787 | - $form[$key]['view']['#value'] = $matches[1]; |
|
787 | + $form[$key]['view']['#value'] = $matches[1]; |
|
788 | + } |
|
788 | 789 | } |
789 | - } |
|
790 | 790 | } |
791 | - } |
|
791 | + } |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
795 | 795 | * We must know when a role is deleted. |
796 | 796 | */ |
797 | 797 | function _forum_access_user_admin_role_form(&$form, &$form_state) { |
798 | - $form['#submit'][] = '_forum_access_user_admin_role_submit'; |
|
798 | + $form['#submit'][] = '_forum_access_user_admin_role_submit'; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
@@ -803,14 +803,14 @@ discard block |
||
803 | 803 | * Also, we complain if the Forum Moderator role is deleted. |
804 | 804 | */ |
805 | 805 | function _forum_access_user_admin_role_submit($form, &$form_state) { |
806 | - if ($form_state['values']['op'] == $form_state['values']['delete']) { |
|
806 | + if ($form_state['values']['op'] == $form_state['values']['delete']) { |
|
807 | 807 | $rid = $form_state['values']['rid']; |
808 | 808 | db_query("DELETE FROM {forum_access} WHERE rid = %d", $rid); |
809 | 809 | db_query("DELETE FROM {node_access} WHERE gid = %d AND realm = 'forum_access'", $rid); |
810 | 810 | if ($rid === forum_access_query_moderator_rid()) { |
811 | - drupal_set_message(t('The role you have just deleted is required by !Forum_Access; it will be recreated automatically.', array('!Forum_Access' => 'Forum Access')), 'error'); |
|
811 | + drupal_set_message(t('The role you have just deleted is required by !Forum_Access; it will be recreated automatically.', array('!Forum_Access' => 'Forum Access')), 'error'); |
|
812 | + } |
|
812 | 813 | } |
813 | - } |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | /** |
@@ -818,27 +818,27 @@ discard block |
||
818 | 818 | * to control the same content types as we do. |
819 | 819 | */ |
820 | 820 | function _forum_access_content_access_admin_form() { |
821 | - $tr = 't'; |
|
822 | - $variables = array( |
|
821 | + $tr = 't'; |
|
822 | + $variables = array( |
|
823 | 823 | '!Content_Access' => 'Content Access', |
824 | 824 | '!Forum_Access' => 'Forum Access', |
825 | 825 | '!Forum_Access_link' => l('Forum Access', 'admin/content/forum'), |
826 | 826 | '%anonymous_user' => $tr('anonymous user'), |
827 | 827 | '%authenticated_user' => $tr('authenticated user'), |
828 | 828 | '%Advanced' => $tr('Advanced'), |
829 | - ); |
|
830 | - if (arg(3) == 'forum') { |
|
829 | + ); |
|
830 | + if (arg(3) == 'forum') { |
|
831 | 831 | drupal_set_message(t('Note: In Drupal, access can only be granted, not taken away. Whatever access you grant here will not be reflected in the !Forum_Access_link settings, but !Forum_Access can only allow <i>more</i> access, not less.', $variables) |
832 | - .'<br /><span class="error">'. t('Specifically, any rights granted to the %anonymous_user and/or the %authenticated_user will <b>override</b> the settings of !Forum_Access!', $variables) .'</span>' |
|
833 | - .'<br />'. t('To avoid conflicts with !Forum_Access settings, you may want to lower the priority of !Content_Access (under %Advanced below) below the priority of !Forum_Access for the content types that you want to be controlled by !Forum_Access.', $variables), 'warning'); |
|
834 | - } |
|
835 | - else { |
|
832 | + .'<br /><span class="error">'. t('Specifically, any rights granted to the %anonymous_user and/or the %authenticated_user will <b>override</b> the settings of !Forum_Access!', $variables) .'</span>' |
|
833 | + .'<br />'. t('To avoid conflicts with !Forum_Access settings, you may want to lower the priority of !Content_Access (under %Advanced below) below the priority of !Forum_Access for the content types that you want to be controlled by !Forum_Access.', $variables), 'warning'); |
|
834 | + } |
|
835 | + else { |
|
836 | 836 | $vid = _forum_access_get_vid(); |
837 | 837 | $vocabulary = taxonomy_vocabulary_load($vid); |
838 | 838 | if (isset($vocabulary->nodes[arg(3)])) { |
839 | - drupal_set_message(t('Note: Nodes of this content type can be put inside forums, where access to them will also be controlled by !Forum_Access.<br />In Drupal, access can only be granted, not taken away. Whatever access you grant here will not be reflected on the !Forum_Access_link settings, and vice versa, but any node access module can only allow <i>more</i> access, not less.', $variables), 'warning'); |
|
839 | + drupal_set_message(t('Note: Nodes of this content type can be put inside forums, where access to them will also be controlled by !Forum_Access.<br />In Drupal, access can only be granted, not taken away. Whatever access you grant here will not be reflected on the !Forum_Access_link settings, and vice versa, but any node access module can only allow <i>more</i> access, not less.', $variables), 'warning'); |
|
840 | + } |
|
840 | 841 | } |
841 | - } |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -848,12 +848,12 @@ discard block |
||
848 | 848 | * admin/user/permissions. |
849 | 849 | */ |
850 | 850 | function _forum_access_user_admin_perm_form(&$form, &$form_state) { |
851 | - $moderator_rid = forum_access_query_moderator_rid(); |
|
852 | - if (isset($moderator_rid) && array_key_exists($moderator_rid, $form['role_names'])) { |
|
851 | + $moderator_rid = forum_access_query_moderator_rid(); |
|
852 | + if (isset($moderator_rid) && array_key_exists($moderator_rid, $form['role_names'])) { |
|
853 | 853 | drupal_set_message(t('The %role role is used internally by the @Forum_Access module and must not be changed!', array('%role' => $form['role_names'][$moderator_rid]['#value'], '@Forum_Access' => 'Forum Access')), 'warning', FALSE); |
854 | 854 | $form['checkboxes'][$moderator_rid]['#disabled'] = TRUE; |
855 | - } |
|
856 | - array_unshift($form['#submit'], '_forum_access_user_admin_perm_form_submit'); |
|
855 | + } |
|
856 | + array_unshift($form['#submit'], '_forum_access_user_admin_perm_form_submit'); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -863,10 +863,10 @@ discard block |
||
863 | 863 | * before the real handler gets them. |
864 | 864 | */ |
865 | 865 | function _forum_access_user_admin_perm_form_submit($form, &$form_state) { |
866 | - $moderator_rid = forum_access_query_moderator_rid(); |
|
867 | - if (isset($moderator_rid)) { |
|
866 | + $moderator_rid = forum_access_query_moderator_rid(); |
|
867 | + if (isset($moderator_rid)) { |
|
868 | 868 | unset($form_state['values'][$moderator_rid]); |
869 | - } |
|
869 | + } |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
@@ -876,10 +876,10 @@ discard block |
||
876 | 876 | * admin/user/user. |
877 | 877 | */ |
878 | 878 | function _forum_access_user_admin_account_form(&$form, &$form_state) { |
879 | - $moderator_rid = forum_access_query_moderator_rid(); |
|
880 | - if (isset($moderator_rid)) { |
|
879 | + $moderator_rid = forum_access_query_moderator_rid(); |
|
880 | + if (isset($moderator_rid)) { |
|
881 | 881 | unset($form['options']['operation']['#options'][t('Add a role to the selected users')]["add_role-$moderator_rid"]); |
882 | - } |
|
882 | + } |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -888,54 +888,54 @@ discard block |
||
888 | 888 | * Disable the Forum Moderator checkbox on user/UID/edit. |
889 | 889 | */ |
890 | 890 | function _forum_access_user_profile_form(&$form, &$form_state) { |
891 | - //dpm($form, '_forum_access_user_profile_form()'); |
|
892 | - $moderator_rid = forum_access_query_moderator_rid(); |
|
893 | - if (isset($moderator_rid) && isset($form['account']['roles']['#options'][$moderator_rid])) { |
|
891 | + //dpm($form, '_forum_access_user_profile_form()'); |
|
892 | + $moderator_rid = forum_access_query_moderator_rid(); |
|
893 | + if (isset($moderator_rid) && isset($form['account']['roles']['#options'][$moderator_rid])) { |
|
894 | 894 | $form['account']['roles'][$moderator_rid] = array( |
895 | - '#type' => 'checkbox', |
|
896 | - '#title' => $form['account']['roles']['#options'][$moderator_rid] .' ('. t('reserved for internal use by the @Forum_Access module', array('@Forum_Access' => 'Forum Access')) .')', |
|
897 | - '#default_value' => in_array($moderator_rid, $form['account']['roles']['#default_value']), |
|
898 | - '#disabled' => TRUE, |
|
895 | + '#type' => 'checkbox', |
|
896 | + '#title' => $form['account']['roles']['#options'][$moderator_rid] .' ('. t('reserved for internal use by the @Forum_Access module', array('@Forum_Access' => 'Forum Access')) .')', |
|
897 | + '#default_value' => in_array($moderator_rid, $form['account']['roles']['#default_value']), |
|
898 | + '#disabled' => TRUE, |
|
899 | 899 | ); |
900 | 900 | unset($form['account']['roles']['#options'][$moderator_rid]); |
901 | - } |
|
901 | + } |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
905 | 905 | * Create the Forum Moderator role. |
906 | 906 | */ |
907 | 907 | function _forum_access_create_moderator_rid($verbose = FALSE) { |
908 | - $tr = 't'; |
|
909 | - $variables = array('!Forum_Access' => 'Forum Access', '%administer_comments' => $tr('administer comments'), '%administer_nodes' => $tr('administer nodes')); |
|
910 | - $role_name = t('Forum Moderator'); |
|
911 | - $role = new stdClass(); |
|
912 | - $role->name = $role_name; |
|
913 | - for ($i = 2; $i <= 12; ++$i) { |
|
908 | + $tr = 't'; |
|
909 | + $variables = array('!Forum_Access' => 'Forum Access', '%administer_comments' => $tr('administer comments'), '%administer_nodes' => $tr('administer nodes')); |
|
910 | + $role_name = t('Forum Moderator'); |
|
911 | + $role = new stdClass(); |
|
912 | + $role->name = $role_name; |
|
913 | + for ($i = 2; $i <= 12; ++$i) { |
|
914 | 914 | $variables['%role'] = $role->name; |
915 | 915 | if (!db_result(db_query("SELECT COUNT(rid) FROM {role} WHERE name = '%s'", $role->name)) && |
916 | 916 | drupal_write_record('role', $role)) { |
917 | - $rid = $role->rid; |
|
918 | - variable_set('forum_access_moderator_rid', $rid); |
|
919 | - $permission = new stdClass(); |
|
920 | - $permission->rid = $rid; |
|
921 | - $permission->perm = 'administer comments, administer nodes, post comments, post comments without approval'; |
|
922 | - drupal_write_record('permission', $permission); |
|
923 | - $msg = t('!Forum_Access has created a new role named %role and given it the %administer_nodes and %administer_comments permissions. This role is used internally by !Forum_Access. You can change the name of the role as you like, but you must keep it unmodified otherwise.', $variables); |
|
924 | - if ($verbose) { |
|
917 | + $rid = $role->rid; |
|
918 | + variable_set('forum_access_moderator_rid', $rid); |
|
919 | + $permission = new stdClass(); |
|
920 | + $permission->rid = $rid; |
|
921 | + $permission->perm = 'administer comments, administer nodes, post comments, post comments without approval'; |
|
922 | + drupal_write_record('permission', $permission); |
|
923 | + $msg = t('!Forum_Access has created a new role named %role and given it the %administer_nodes and %administer_comments permissions. This role is used internally by !Forum_Access. You can change the name of the role as you like, but you must keep it unmodified otherwise.', $variables); |
|
924 | + if ($verbose) { |
|
925 | 925 | drupal_set_message($msg, 'warning'); |
926 | - } |
|
927 | - watchdog('user', $msg, NULL, WATCHDOG_NOTICE); |
|
928 | - return $rid; |
|
926 | + } |
|
927 | + watchdog('user', $msg, NULL, WATCHDOG_NOTICE); |
|
928 | + return $rid; |
|
929 | 929 | } |
930 | 930 | else { |
931 | - $msg = t('!Forum_Access cannot create the %role role!', $variables); |
|
932 | - watchdog('user', $msg, NULL, WATCHDOG_WARNING); |
|
933 | - drupal_set_message($msg .' '. t('Is it already in use?'), 'error'); |
|
934 | - $role->name = $role_name .' '. $i; |
|
935 | - } |
|
936 | - } |
|
937 | - $msg = t('!Forum_Access has given up and will not work correctly! Rename one of the roles listed above, so that !Forum_Access can use its name.', $variables); |
|
938 | - drupal_set_message($msg, 'error'); |
|
939 | - watchdog('user', $msg, NULL, WATCHDOG_CRITICAL); |
|
931 | + $msg = t('!Forum_Access cannot create the %role role!', $variables); |
|
932 | + watchdog('user', $msg, NULL, WATCHDOG_WARNING); |
|
933 | + drupal_set_message($msg .' '. t('Is it already in use?'), 'error'); |
|
934 | + $role->name = $role_name .' '. $i; |
|
935 | + } |
|
936 | + } |
|
937 | + $msg = t('!Forum_Access has given up and will not work correctly! Rename one of the roles listed above, so that !Forum_Access can use its name.', $variables); |
|
938 | + drupal_set_message($msg, 'error'); |
|
939 | + watchdog('user', $msg, NULL, WATCHDOG_CRITICAL); |
|
940 | 940 | } |
941 | 941 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | function _forum_access_forum_form(&$form, &$form_state, $is_container) { |
15 | 15 | $tid = (isset($form['tid']['#value']) ? $form['tid']['#value'] : NULL); |
16 | 16 | if (isset($tid) && !forum_access_access($tid, 'view', NULL, FALSE)) { |
17 | - drupal_access_denied(); // Deny access if the user doesn't have View access. |
|
17 | + drupal_access_denied(); // Deny access if the user doesn't have View access. |
|
18 | 18 | module_invoke_all('exit'); |
19 | 19 | exit; |
20 | 20 | } |
@@ -39,18 +39,18 @@ discard block |
||
39 | 39 | |
40 | 40 | $tr = 't'; |
41 | 41 | $variables = array( |
42 | - '!access_content' => '<em>'. l($tr('access content'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)) .'</em>', |
|
43 | - '!access_comments' => '<em>'. l($tr('access comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
|
44 | - '!create_forum_topics' => '<em>'. l($tr('create forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
45 | - '!post_comments' => '<em>'. l($tr('post comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
|
46 | - '!post_comments_without_approval' => '<em>'. l($tr('post comments without approval'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
|
47 | - '!edit_own_forum_topics' => '<em>'. l($tr('edit own forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
48 | - '!edit_any_forum_topics' => '<em>'. l($tr('edit any forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
49 | - '!delete_own_forum_topics' => '<em>'. l($tr('delete own forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
50 | - '!delete_any_forum_topics' => '<em>'. l($tr('delete any forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
51 | - '!administer_comments' => '<em>'. l($tr('administer comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)) .'</em>', |
|
52 | - '!administer_forums' => '<em>'. l($tr('administer forums'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)) .'</em>', |
|
53 | - '!administer_nodes' => '<em>'. l($tr('administer nodes'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)) .'</em>', |
|
42 | + '!access_content' => '<em>'.l($tr('access content'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)).'</em>', |
|
43 | + '!access_comments' => '<em>'.l($tr('access comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)).'</em>', |
|
44 | + '!create_forum_topics' => '<em>'.l($tr('create forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
45 | + '!post_comments' => '<em>'.l($tr('post comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)).'</em>', |
|
46 | + '!post_comments_without_approval' => '<em>'.l($tr('post comments without approval'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)).'</em>', |
|
47 | + '!edit_own_forum_topics' => '<em>'.l($tr('edit own forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
48 | + '!edit_any_forum_topics' => '<em>'.l($tr('edit any forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
49 | + '!delete_own_forum_topics' => '<em>'.l($tr('delete own forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
50 | + '!delete_any_forum_topics' => '<em>'.l($tr('delete any forum topics'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
51 | + '!administer_comments' => '<em>'.l($tr('administer comments'), 'admin/user/permissions', array('fragment' => 'module-comment', 'html' => TRUE)).'</em>', |
|
52 | + '!administer_forums' => '<em>'.l($tr('administer forums'), 'admin/user/permissions', array('fragment' => 'module-forum', 'html' => TRUE)).'</em>', |
|
53 | + '!administer_nodes' => '<em>'.l($tr('administer nodes'), 'admin/user/permissions', array('fragment' => 'module-node', 'html' => TRUE)).'</em>', |
|
54 | 54 | ); |
55 | 55 | if (!$is_container) { |
56 | 56 | $form['forum_access']['permissions'] = array( |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | ); |
62 | 62 | $form['forum_access']['permissions'][] = array( |
63 | 63 | '#type' => 'markup', |
64 | - '#value' => '<div>'. t('Note that users need') .'<ul style="margin-top: 0"><li>'. |
|
65 | - t('the !access_content and !access_comments permissions <strong>AND <em>View</em></strong> to be able to see this forum and its content at all,', $variables) .'</li><li>'. |
|
66 | - t('the !create_forum_topics (and similar) permissions <strong>AND <em>Post</em></strong> to be able to create forum content, and', $variables) .'</li><li>'. |
|
67 | - t('the !post_comments and (probably) !post_comments_without_approval permission <!TAG>AND <em>Comment</em></!TAG> to be able to post comments/replies;', $variables + array('!TAG' => (variable_get('forum_access_D5_legacy_mode', FALSE) ? 'del title="'. t('Drupal 5 legacy mode') .'"' : 'strong'))) .'</li><li>'. |
|
68 | - t('the !edit_own_forum_topics or !edit_any_forum_topics (and similar) permissions <strong>AND (<em>Edit</em> AND <em>Comment</em></strong>) can be added if desired, <strong>plus</strong>', $variables) .'</li><li>'. |
|
69 | - t('the !delete_own_forum_topics or !delete_any_forum_topics (and similar) permissions (<strong>OR <em>Delete</em></strong>) if desired;', $variables) .'</li><li>'. |
|
70 | - t('the !administer_comments (global!) permission <strong>OR <em>Edit</em>/<em>Delete</em></strong> to be able to edit/delete comments;', $variables) .'</li><li>'. |
|
71 | - t('the !administer_forums permission <strong>AND <em>View</em></strong> to be able to administer forums (and change access!).', $variables) .'</li></ul>'. |
|
72 | - t('Furthermore note that content which is not published is treated in a different way by Drupal: it can be viewed only by its author or by users with the !administer_nodes permission. Unpublished comments and replies are accessible to users with <strong><em>Edit</em> OR <em>Delete</em></strong>, <strong>OR</strong> with the !administer_comments permission, but they are never counted on the forum page.', $variables) .'</div>', |
|
64 | + '#value' => '<div>'.t('Note that users need').'<ul style="margin-top: 0"><li>'. |
|
65 | + t('the !access_content and !access_comments permissions <strong>AND <em>View</em></strong> to be able to see this forum and its content at all,', $variables).'</li><li>'. |
|
66 | + t('the !create_forum_topics (and similar) permissions <strong>AND <em>Post</em></strong> to be able to create forum content, and', $variables).'</li><li>'. |
|
67 | + t('the !post_comments and (probably) !post_comments_without_approval permission <!TAG>AND <em>Comment</em></!TAG> to be able to post comments/replies;', $variables + array('!TAG' => (variable_get('forum_access_D5_legacy_mode', FALSE) ? 'del title="'.t('Drupal 5 legacy mode').'"' : 'strong'))).'</li><li>'. |
|
68 | + t('the !edit_own_forum_topics or !edit_any_forum_topics (and similar) permissions <strong>AND (<em>Edit</em> AND <em>Comment</em></strong>) can be added if desired, <strong>plus</strong>', $variables).'</li><li>'. |
|
69 | + t('the !delete_own_forum_topics or !delete_any_forum_topics (and similar) permissions (<strong>OR <em>Delete</em></strong>) if desired;', $variables).'</li><li>'. |
|
70 | + t('the !administer_comments (global!) permission <strong>OR <em>Edit</em>/<em>Delete</em></strong> to be able to edit/delete comments;', $variables).'</li><li>'. |
|
71 | + t('the !administer_forums permission <strong>AND <em>View</em></strong> to be able to administer forums (and change access!).', $variables).'</li></ul>'. |
|
72 | + t('Furthermore note that content which is not published is treated in a different way by Drupal: it can be viewed only by its author or by users with the !administer_nodes permission. Unpublished comments and replies are accessible to users with <strong><em>Edit</em> OR <em>Delete</em></strong>, <strong>OR</strong> with the !administer_comments permission, but they are never counted on the forum page.', $variables).'</div>', |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | '#collapsed' => empty($template_tid), |
83 | 83 | ); |
84 | 84 | $form['forum_access']['template']['taxonomy'][$vid] = taxonomy_form($vid, array($template_tid), ''); |
85 | - $form['forum_access']['template']['taxonomy'][$vid]['#description'] = t("Select a forum and click !Load to retrieve that forum's settings as a starting point for this forum or container.", array('!Load' => '['. t('Load') .']')); |
|
85 | + $form['forum_access']['template']['taxonomy'][$vid]['#description'] = t("Select a forum and click !Load to retrieve that forum's settings as a starting point for this forum or container.", array('!Load' => '['.t('Load').']')); |
|
86 | 86 | $form['forum_access']['template']['load_button'] = array( |
87 | 87 | '#type' => 'button', |
88 | 88 | '#name' => 'load_template', |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - drupal_add_css(drupal_get_path('module', 'forum_access') .'/forum_access.css'); |
|
208 | + drupal_add_css(drupal_get_path('module', 'forum_access').'/forum_access.css'); |
|
209 | 209 | |
210 | 210 | // Find our moderator ACL: |
211 | 211 | if (isset($tid)) { // edit, not new |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | $form['forum_access']['acl'] = acl_edit_form($acl_id, t('Moderators')); |
223 | 223 | $form['forum_access']['acl'][] = array( |
224 | 224 | '#type' => 'markup', |
225 | - '#value' => '<div>'. t('Moderators receive all grants above.') .'</div>', |
|
225 | + '#value' => '<div>'.t('Moderators receive all grants above.').'</div>', |
|
226 | 226 | '#weight' => -1, |
227 | 227 | ); |
228 | 228 | $form['forum_access']['acl']['note'] = array( |
229 | 229 | '#type' => 'markup', |
230 | - '#value' => '<div>'. t('Note: Changes to moderators are not saved until you click [!Save] below.', array('!Save' => $tr('Save'))) .'</div>', |
|
230 | + '#value' => '<div>'.t('Note: Changes to moderators are not saved until you click [!Save] below.', array('!Save' => $tr('Save'))).'</div>', |
|
231 | 231 | ); |
232 | 232 | $form['forum_access']['acl']['#after_build'][] = '_forum_access_forum_form_after_build_acl0'; |
233 | 233 | $form['forum_access']['acl']['#after_build'] = array_reverse($form['forum_access']['acl']['#after_build']); |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | '!Content_Access' => l('Content Access', 'http://drupal.org/project/content_access'), |
252 | 252 | '@Content_Access' => 'Content Access', |
253 | 253 | '!ACL' => 'ACL', |
254 | - '!module_list' => '<ul><li>'. implode($na_modules, '</li><li>') .'</li></ul>', |
|
254 | + '!module_list' => '<ul><li>'.implode($na_modules, '</li><li>').'</li></ul>', |
|
255 | 255 | ); |
256 | 256 | $form['forum_access']['interference'][] = array( |
257 | 257 | '#type' => 'item', |
258 | - '#value' => '<p>'. t("Besides !Forum_Access (and !ACL) you have installed the following node access module(s): !module_list The grants of every module are combined for each node. Access can only be granted, not removed — if a certain module grants a permission, the other(s) cannot deny it.", $variables) .'</p>', |
|
258 | + '#value' => '<p>'.t("Besides !Forum_Access (and !ACL) you have installed the following node access module(s): !module_list The grants of every module are combined for each node. Access can only be granted, not removed — if a certain module grants a permission, the other(s) cannot deny it.", $variables).'</p>', |
|
259 | 259 | '#description' => t('Forums can contain other content types besides %content_type; !Forum_Access will contribute the grants defined above to every node in this forum, but other node access control modules may also contribute their grants, especially to nodes of types other than %content_type.', $variables), |
260 | 260 | ); |
261 | 261 | |
@@ -282,25 +282,25 @@ discard block |
||
282 | 282 | '#attributes' => array('class' => 'error'), |
283 | 283 | ); |
284 | 284 | $form['forum_access']['interference']['by_content_access'][] = array( |
285 | - '#value' => '<div>'. t('You have set the !Content_Access module to control access to content of type %content_type—this can interfere with proper operation of !Forum_Access!', $variables) ." $specifically</div>", |
|
285 | + '#value' => '<div>'.t('You have set the !Content_Access module to control access to content of type %content_type—this can interfere with proper operation of !Forum_Access!', $variables)." $specifically</div>", |
|
286 | 286 | ); |
287 | 287 | if ($ca_priority == $fa_priority) { |
288 | 288 | $form['forum_access']['interference']['by_content_access'][] = array( |
289 | - '#value' => '<div>'. t("Unless you really know what you're doing, we recommend that you go to the !link page and clear all checkboxes. This will instruct @Content_Access to leave the %content_type nodes alone. However, if you put nodes of other content types into forums as well, then these content types will continue to have this problem.", $variables) .'</div>', |
|
289 | + '#value' => '<div>'.t("Unless you really know what you're doing, we recommend that you go to the !link page and clear all checkboxes. This will instruct @Content_Access to leave the %content_type nodes alone. However, if you put nodes of other content types into forums as well, then these content types will continue to have this problem.", $variables).'</div>', |
|
290 | 290 | ); |
291 | 291 | } |
292 | 292 | else { |
293 | 293 | $form['forum_access']['interference']['by_content_access'][] = array( |
294 | - '#value' => '<div>'. t("The priority of @Content_Access ($ca_priority) is higher than the priority of !Forum_Access ($fa_priority), which means the latter is <strong>completely disabled</strong> for the %content_type type! Unless you really know what you're doing, we recommend that you go to the !link page, change the priority (under %Advanced) to 0, and clear all checkboxes.", $variables) .'</div>', |
|
294 | + '#value' => '<div>'.t("The priority of @Content_Access ($ca_priority) is higher than the priority of !Forum_Access ($fa_priority), which means the latter is <strong>completely disabled</strong> for the %content_type type! Unless you really know what you're doing, we recommend that you go to the !link page, change the priority (under %Advanced) to 0, and clear all checkboxes.", $variables).'</div>', |
|
295 | 295 | ); |
296 | 296 | } |
297 | 297 | $form['forum_access']['interference']['by_content_access'][] = array( |
298 | - '#value' => '<div>'. t("Alternatively, you can give !Forum_Access priority over @Content_Access by either raising the priority of !Forum_Access in every forum above the priority of @Content_Access, or by lowering the priority of @Content_Access for the content types in question below the priority of !Forum_Access.", $variables) .'</div>', |
|
298 | + '#value' => '<div>'.t("Alternatively, you can give !Forum_Access priority over @Content_Access by either raising the priority of !Forum_Access in every forum above the priority of @Content_Access, or by lowering the priority of @Content_Access for the content types in question below the priority of !Forum_Access.", $variables).'</div>', |
|
299 | 299 | ); |
300 | 300 | } |
301 | 301 | else { |
302 | 302 | $form['forum_access']['interference'][] = array( |
303 | - '#value' => '<p>'. t('Note: You have installed the !Content_Access module, which has the capability to grant access to content that would otherwise be protected by !Forum_Access. Be careful when configuring @Content_Access!', $variables) .'</p>', |
|
303 | + '#value' => '<p>'.t('Note: You have installed the !Content_Access module, which has the capability to grant access to content that would otherwise be protected by !Forum_Access. Be careful when configuring @Content_Access!', $variables).'</p>', |
|
304 | 304 | ); |
305 | 305 | } |
306 | 306 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | '!DNA' => 'DNA', |
332 | 332 | '!debug_mode' => l('debug mode', 'admin/settings/devel', array('fragment' => 'edit-devel-node-access-debug-mode')), |
333 | 333 | '!dna_summary' => l('devel/node_access/summary', 'devel/node_access/summary'), |
334 | - '!Rebuild_permissions' => '['. $tr('Rebuild permissions') .']', |
|
334 | + '!Rebuild_permissions' => '['.$tr('Rebuild permissions').']', |
|
335 | 335 | '!Post_settings_link' => l('admin/content/node-settings', 'admin/content/node-settings'), |
336 | 336 | '!Forum_Access_' => l('Forum Access', 'http://drupal.org/project/issues/forum_access'), |
337 | 337 | '!ACL_' => l('ACL', 'http://drupal.org/project/issues/acl'), |
@@ -344,26 +344,26 @@ discard block |
||
344 | 344 | ); |
345 | 345 | $form['forum_access']['troubleshooting'][] = array( |
346 | 346 | '#type' => 'item', |
347 | - '#value' => '<div>'. t("In case of problems, follow these steps until you've got it worked out:") .'<ol style="margin-top: 0"><li>'. |
|
348 | - t("Update to the 'recommended' !Forum_Access and !ACL releases for your version of Drupal.", $variables) .'</li><li>'. |
|
349 | - (count($na_modules) ? t("Read %Module_interference above and update your other node access modules.", $variables) .'</li><li>' : '') . |
|
350 | - t("Check the release notes of the development snapshots for issues that might have been fixed in !Forum_Access-dev or !ACL-dev since the latest release.", $variables) .'</li><li>'. |
|
351 | - t("Install the %devel_node_access module (!DNA, part of the !Devel module) and enable its !debug_mode: !DNA will show you all the grants that actually control your nodes in a footer block on each node's page.", $variables) .'</li><li>'. |
|
352 | - t("Additional insight can be gained from !dna_summary and by enabling the second !DNA block.", $variables) .'</li><li>'. |
|
353 | - t("Click !Rebuild_permissions on !Post_settings_link and check DNA for changes.", $variables) .'</li><li>'. |
|
354 | - t("Check the issues queues of !Forum_Access_ and !ACL_ for existing reports and possible solutions.", $variables) .'</li><li>'. |
|
355 | - t("If all of this hasn't helped, then pick ONE node that is misbehaving, look at it using an account that can see the node (and that should NOT have access if that's your problem!), create a new issue in the issues queue, describe the problem... <ul><li> what did you do? </li><li> what did you expect? </li><li> what happened instead? </li></ul> ... and <strong>attach a screenshot of all the DNA records</strong> for that one node. <br /> Be sure to indicate paths (URLs) for every page and module that you mention.") .'</li></ol></div>', |
|
347 | + '#value' => '<div>'.t("In case of problems, follow these steps until you've got it worked out:").'<ol style="margin-top: 0"><li>'. |
|
348 | + t("Update to the 'recommended' !Forum_Access and !ACL releases for your version of Drupal.", $variables).'</li><li>'. |
|
349 | + (count($na_modules) ? t("Read %Module_interference above and update your other node access modules.", $variables).'</li><li>' : ''). |
|
350 | + t("Check the release notes of the development snapshots for issues that might have been fixed in !Forum_Access-dev or !ACL-dev since the latest release.", $variables).'</li><li>'. |
|
351 | + t("Install the %devel_node_access module (!DNA, part of the !Devel module) and enable its !debug_mode: !DNA will show you all the grants that actually control your nodes in a footer block on each node's page.", $variables).'</li><li>'. |
|
352 | + t("Additional insight can be gained from !dna_summary and by enabling the second !DNA block.", $variables).'</li><li>'. |
|
353 | + t("Click !Rebuild_permissions on !Post_settings_link and check DNA for changes.", $variables).'</li><li>'. |
|
354 | + t("Check the issues queues of !Forum_Access_ and !ACL_ for existing reports and possible solutions.", $variables).'</li><li>'. |
|
355 | + t("If all of this hasn't helped, then pick ONE node that is misbehaving, look at it using an account that can see the node (and that should NOT have access if that's your problem!), create a new issue in the issues queue, describe the problem... <ul><li> what did you do? </li><li> what did you expect? </li><li> what happened instead? </li></ul> ... and <strong>attach a screenshot of all the DNA records</strong> for that one node. <br /> Be sure to indicate paths (URLs) for every page and module that you mention.").'</li></ol></div>', |
|
356 | 356 | ); |
357 | 357 | $form['forum_access']['troubleshooting'][] = array( |
358 | 358 | '#type' => 'item', |
359 | - '#value' => '<div>'. t("Note: You should not keep the !Devel module enabled on a production site.", $variables) .'</div>', |
|
359 | + '#value' => '<div>'.t("Note: You should not keep the !Devel module enabled on a production site.", $variables).'</div>', |
|
360 | 360 | ); |
361 | 361 | } |
362 | 362 | |
363 | 363 | if (!$is_container && isset($tid) && !node_access_needs_rebuild()) { |
364 | 364 | $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
365 | - $limit = 20; // from _node_access_rebuild_batch_operation() |
|
366 | - $threshold = variable_get('forum_access_batch_threshold', $limit); // change the variable if you want |
|
365 | + $limit = 20; // from _node_access_rebuild_batch_operation() |
|
366 | + $threshold = variable_get('forum_access_batch_threshold', $limit); // change the variable if you want |
|
367 | 367 | $form['forum_access']['update_limit'] = array( |
368 | 368 | '#type' => 'value', |
369 | 369 | '#value' => $limit, |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | $element_children = element_children($element); |
442 | 442 | foreach ($element_children as $rid) { |
443 | 443 | if ($rid == $moderator_rid) { |
444 | - $element[$rid]['#prefix'] = '<span title="'. t("This is the (temporary) @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and is only used temporarily by @Forum_Access — do NOT give this role to any user!", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments'), '@Forum_Access' => 'Forum Access')) .'" class="forum-access-temporary-moderator">'; |
|
444 | + $element[$rid]['#prefix'] = '<span title="'.t("This is the (temporary) @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and is only used temporarily by @Forum_Access — do NOT give this role to any user!", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments'), '@Forum_Access' => 'Forum Access')).'" class="forum-access-temporary-moderator">'; |
|
445 | 445 | $element[$rid]['#suffix'] = "</span>"; |
446 | 446 | $element[$rid]['#default_value'] = TRUE; |
447 | 447 | $element[$rid]['#disabled'] = TRUE; |
@@ -452,19 +452,19 @@ discard block |
||
452 | 452 | elseif ($element['#parents'][1] == 'comment_create') { |
453 | 453 | } |
454 | 454 | elseif ($element['#parents'][1] == 'view' && isset($permissions[$rid]['administer forums'])) { |
455 | - $element[$rid]['#title'] = '<em>'. $element[$rid]['#title'] .'</em>'; |
|
456 | - $element[$rid]['#prefix'] = '<span title="'. t("This role has the '@administer_forums' permission, and granting '@View' enables the role holders to change the settings on this page, including @Access_control!", array('@administer_forums' => $tr('administer forums'), '@View' => t('View'), '@Access_control' => t('Access control'))) .'">'; |
|
455 | + $element[$rid]['#title'] = '<em>'.$element[$rid]['#title'].'</em>'; |
|
456 | + $element[$rid]['#prefix'] = '<span title="'.t("This role has the '@administer_forums' permission, and granting '@View' enables the role holders to change the settings on this page, including @Access_control!", array('@administer_forums' => $tr('administer forums'), '@View' => t('View'), '@Access_control' => t('Access control'))).'">'; |
|
457 | 457 | if (isset($permissions[$rid]['administer nodes'])) { |
458 | - $element[$rid]['#prefix'] = str_replace('">', ' '. t("Because the role also has the '@administer_nodes' permission, it has full access to all nodes either way.", array('@administer_nodes' => $tr('administer nodes'))) .'">', $element[$rid]['#prefix']); |
|
458 | + $element[$rid]['#prefix'] = str_replace('">', ' '.t("Because the role also has the '@administer_nodes' permission, it has full access to all nodes either way.", array('@administer_nodes' => $tr('administer nodes'))).'">', $element[$rid]['#prefix']); |
|
459 | 459 | } |
460 | 460 | $element[$rid]['#suffix'] = "</span>"; |
461 | 461 | } |
462 | 462 | elseif (isset($permissions[$rid]['administer nodes'])) { |
463 | 463 | $element[$rid]['#disabled'] = TRUE; |
464 | 464 | $element[$rid]['#default_value'] = TRUE; |
465 | - $element[$rid]['#prefix'] = '<span title="'. ($rid != $moderator_rid |
|
465 | + $element[$rid]['#prefix'] = '<span title="'.($rid != $moderator_rid |
|
466 | 466 | ? t("This role has the '@administer_nodes' permission and thus full access to all nodes.", array('@administer_nodes' => $tr('administer nodes'))) |
467 | - : t("This is the @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and thus full access to all nodes and comments.", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments')))) .'">'; |
|
467 | + : t("This is the @Forum_Moderator role; it has the '@administer_nodes' and '@administer_comments' permissions and thus full access to all nodes and comments.", array('@Forum_Moderator' => t('Forum Moderator'), '@administer_nodes' => $tr('administer nodes'), '@administer_comments' => $tr('administer comments')))).'">'; |
|
468 | 468 | $element[$rid]['#suffix'] = "</span>"; |
469 | 469 | } |
470 | 470 | } |
@@ -560,12 +560,12 @@ discard block |
||
560 | 560 | variable_del('forum_access_new_template_tid'); |
561 | 561 | } |
562 | 562 | module_load_include('node.inc', 'forum_access'); |
563 | - $moderator_rid = _forum_access_get_moderator_rid(TRUE); // create the moderators role if it doesn't exist |
|
563 | + $moderator_rid = _forum_access_get_moderator_rid(TRUE); // create the moderators role if it doesn't exist |
|
564 | 564 | |
565 | 565 | // check for changes |
566 | 566 | $is_changed = $is_new = strpos($_GET['q'], 'admin/content/forum/add/') === 0; |
567 | 567 | $is_changed = $is_changed || !empty($access['force_update']); |
568 | - $form_initial_values = $form; // avoid Coder warning |
|
568 | + $form_initial_values = $form; // avoid Coder warning |
|
569 | 569 | $form_initial_values = $form_initial_values['forum_access']; |
570 | 570 | foreach (array('view', 'create', 'comment_create', 'update', 'delete') as $grant_type) { |
571 | 571 | if (isset($form_initial_values[$grant_type])) { |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | } |
611 | 611 | else { |
612 | 612 | db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
613 | - $tid, $rid, (bool) $checked, !empty($access['update'][$rid]), !empty($access['delete'][$rid]), !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
|
613 | + $tid, $rid, (bool)$checked, !empty($access['update'][$rid]), !empty($access['delete'][$rid]), !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | $tr = 't'; |
617 | - $link = l($tr('edit'), 'admin/content/forum/edit/forum/'. $tid); |
|
617 | + $link = l($tr('edit'), 'admin/content/forum/edit/forum/'.$tid); |
|
618 | 618 | watchdog('access', 'Changed grants for %forum forum.', array('%forum' => $form_state['values']['name']), WATCHDOG_NOTICE, $link); |
619 | 619 | |
620 | 620 | if (!$is_new && $form_state['values']['form_id'] != 'forum_form_container') { |
@@ -628,10 +628,10 @@ discard block |
||
628 | 628 | $context = array(); |
629 | 629 | $pending_error_messages = drupal_get_messages('error', FALSE); |
630 | 630 | $our_error_message_index = (isset($pending_error_messages['error']) ? count($pending_error_messages['error']) : 0); |
631 | - _forum_access_update_batch_finished(FALSE, array(), array()); // add our error message (in case we die underway) |
|
631 | + _forum_access_update_batch_finished(FALSE, array(), array()); // add our error message (in case we die underway) |
|
632 | 632 | _forum_access_update_batch_operation($tid, 999999, 1, $context); |
633 | - $pending_error_messages = drupal_get_messages('error', TRUE); // still alive, get and clear all 'error' messages |
|
634 | - unset($pending_error_messages['error'][$our_error_message_index]); // remove our error message |
|
633 | + $pending_error_messages = drupal_get_messages('error', TRUE); // still alive, get and clear all 'error' messages |
|
634 | + unset($pending_error_messages['error'][$our_error_message_index]); // remove our error message |
|
635 | 635 | foreach ($pending_error_messages['error'] as $message) { // replay any others |
636 | 636 | drupal_set_message($message, 'error'); |
637 | 637 | } |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
645 | 645 | $batch = array( |
646 | 646 | 'title' => t('Updating content access permissions'), |
647 | - 'file' => drupal_get_path('module', 'forum_access') .'/forum_access.admin.inc', |
|
647 | + 'file' => drupal_get_path('module', 'forum_access').'/forum_access.admin.inc', |
|
648 | 648 | 'operations' => array( |
649 | 649 | array('_forum_access_update_batch_operation', array($tid, $limit, $count)), |
650 | 650 | ), |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - variable_del('forum_access_rids'); // clear cache |
|
657 | + variable_del('forum_access_rids'); // clear cache |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | |
688 | 688 | // Multistep processing : report progress. |
689 | 689 | if ($context['sandbox']['progress'] != $context['sandbox']['max']) { |
690 | - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
|
690 | + $context['finished'] = $context['sandbox']['progress']/$context['sandbox']['max']; |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
@@ -829,8 +829,8 @@ discard block |
||
829 | 829 | ); |
830 | 830 | if (arg(3) == 'forum') { |
831 | 831 | drupal_set_message(t('Note: In Drupal, access can only be granted, not taken away. Whatever access you grant here will not be reflected in the !Forum_Access_link settings, but !Forum_Access can only allow <i>more</i> access, not less.', $variables) |
832 | - .'<br /><span class="error">'. t('Specifically, any rights granted to the %anonymous_user and/or the %authenticated_user will <b>override</b> the settings of !Forum_Access!', $variables) .'</span>' |
|
833 | - .'<br />'. t('To avoid conflicts with !Forum_Access settings, you may want to lower the priority of !Content_Access (under %Advanced below) below the priority of !Forum_Access for the content types that you want to be controlled by !Forum_Access.', $variables), 'warning'); |
|
832 | + .'<br /><span class="error">'.t('Specifically, any rights granted to the %anonymous_user and/or the %authenticated_user will <b>override</b> the settings of !Forum_Access!', $variables).'</span>' |
|
833 | + .'<br />'.t('To avoid conflicts with !Forum_Access settings, you may want to lower the priority of !Content_Access (under %Advanced below) below the priority of !Forum_Access for the content types that you want to be controlled by !Forum_Access.', $variables), 'warning'); |
|
834 | 834 | } |
835 | 835 | else { |
836 | 836 | $vid = _forum_access_get_vid(); |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | if (isset($moderator_rid) && isset($form['account']['roles']['#options'][$moderator_rid])) { |
894 | 894 | $form['account']['roles'][$moderator_rid] = array( |
895 | 895 | '#type' => 'checkbox', |
896 | - '#title' => $form['account']['roles']['#options'][$moderator_rid] .' ('. t('reserved for internal use by the @Forum_Access module', array('@Forum_Access' => 'Forum Access')) .')', |
|
896 | + '#title' => $form['account']['roles']['#options'][$moderator_rid].' ('.t('reserved for internal use by the @Forum_Access module', array('@Forum_Access' => 'Forum Access')).')', |
|
897 | 897 | '#default_value' => in_array($moderator_rid, $form['account']['roles']['#default_value']), |
898 | 898 | '#disabled' => TRUE, |
899 | 899 | ); |
@@ -930,8 +930,8 @@ discard block |
||
930 | 930 | else { |
931 | 931 | $msg = t('!Forum_Access cannot create the %role role!', $variables); |
932 | 932 | watchdog('user', $msg, NULL, WATCHDOG_WARNING); |
933 | - drupal_set_message($msg .' '. t('Is it already in use?'), 'error'); |
|
934 | - $role->name = $role_name .' '. $i; |
|
933 | + drupal_set_message($msg.' '.t('Is it already in use?'), 'error'); |
|
934 | + $role->name = $role_name.' '.$i; |
|
935 | 935 | } |
936 | 936 | } |
937 | 937 | $msg = t('!Forum_Access has given up and will not work correctly! Rename one of the roles listed above, so that !Forum_Access can use its name.', $variables); |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | if (isset($tid)) { // edit |
24 | 24 | $template_tid = variable_get('forum_access_default_template_tid', 0); |
25 | 25 | $settings = _forum_access_get_settings($tid); |
26 | - } |
|
27 | - else { // create |
|
26 | + } else { // create |
|
28 | 27 | $template_tid = variable_get('forum_access_new_template_tid', NULL); |
29 | 28 | $settings = _forum_access_get_settings($template_tid); |
30 | 29 | } |
@@ -288,8 +287,7 @@ discard block |
||
288 | 287 | $form['forum_access']['interference']['by_content_access'][] = array( |
289 | 288 | '#value' => '<div>'. t("Unless you really know what you're doing, we recommend that you go to the !link page and clear all checkboxes. This will instruct @Content_Access to leave the %content_type nodes alone. However, if you put nodes of other content types into forums as well, then these content types will continue to have this problem.", $variables) .'</div>', |
290 | 289 | ); |
291 | - } |
|
292 | - else { |
|
290 | + } else { |
|
293 | 291 | $form['forum_access']['interference']['by_content_access'][] = array( |
294 | 292 | '#value' => '<div>'. t("The priority of @Content_Access ($ca_priority) is higher than the priority of !Forum_Access ($fa_priority), which means the latter is <strong>completely disabled</strong> for the %content_type type! Unless you really know what you're doing, we recommend that you go to the !link page, change the priority (under %Advanced) to 0, and clear all checkboxes.", $variables) .'</div>', |
295 | 293 | ); |
@@ -297,8 +295,7 @@ discard block |
||
297 | 295 | $form['forum_access']['interference']['by_content_access'][] = array( |
298 | 296 | '#value' => '<div>'. t("Alternatively, you can give !Forum_Access priority over @Content_Access by either raising the priority of !Forum_Access in every forum above the priority of @Content_Access, or by lowering the priority of @Content_Access for the content types in question below the priority of !Forum_Access.", $variables) .'</div>', |
299 | 297 | ); |
300 | - } |
|
301 | - else { |
|
298 | + } else { |
|
302 | 299 | $form['forum_access']['interference'][] = array( |
303 | 300 | '#value' => '<p>'. t('Note: You have installed the !Content_Access module, which has the capability to grant access to content that would otherwise be protected by !Forum_Access. Be careful when configuring @Content_Access!', $variables) .'</p>', |
304 | 301 | ); |
@@ -445,21 +442,17 @@ discard block |
||
445 | 442 | $element[$rid]['#suffix'] = "</span>"; |
446 | 443 | $element[$rid]['#default_value'] = TRUE; |
447 | 444 | $element[$rid]['#disabled'] = TRUE; |
448 | - } |
|
449 | - elseif ($element['#parents'][1] == 'create') { |
|
445 | + } elseif ($element['#parents'][1] == 'create') { |
|
450 | 446 | // Do nothing (Post is always mutable). |
451 | - } |
|
452 | - elseif ($element['#parents'][1] == 'comment_create') { |
|
453 | - } |
|
454 | - elseif ($element['#parents'][1] == 'view' && isset($permissions[$rid]['administer forums'])) { |
|
447 | + } elseif ($element['#parents'][1] == 'comment_create') { |
|
448 | + } elseif ($element['#parents'][1] == 'view' && isset($permissions[$rid]['administer forums'])) { |
|
455 | 449 | $element[$rid]['#title'] = '<em>'. $element[$rid]['#title'] .'</em>'; |
456 | 450 | $element[$rid]['#prefix'] = '<span title="'. t("This role has the '@administer_forums' permission, and granting '@View' enables the role holders to change the settings on this page, including @Access_control!", array('@administer_forums' => $tr('administer forums'), '@View' => t('View'), '@Access_control' => t('Access control'))) .'">'; |
457 | 451 | if (isset($permissions[$rid]['administer nodes'])) { |
458 | 452 | $element[$rid]['#prefix'] = str_replace('">', ' '. t("Because the role also has the '@administer_nodes' permission, it has full access to all nodes either way.", array('@administer_nodes' => $tr('administer nodes'))) .'">', $element[$rid]['#prefix']); |
459 | 453 | } |
460 | 454 | $element[$rid]['#suffix'] = "</span>"; |
461 | - } |
|
462 | - elseif (isset($permissions[$rid]['administer nodes'])) { |
|
455 | + } elseif (isset($permissions[$rid]['administer nodes'])) { |
|
463 | 456 | $element[$rid]['#disabled'] = TRUE; |
464 | 457 | $element[$rid]['#default_value'] = TRUE; |
465 | 458 | $element[$rid]['#prefix'] = '<span title="'. ($rid != $moderator_rid |
@@ -515,8 +508,7 @@ discard block |
||
515 | 508 | if ($settings['priority'] != 0) { |
516 | 509 | $form['interference']['advanced']['#collapsed'] = FALSE; |
517 | 510 | } |
518 | - } |
|
519 | - elseif (is_array(reset($form_state['values']['forum_access']['template']['taxonomy']))) { |
|
511 | + } elseif (is_array(reset($form_state['values']['forum_access']['template']['taxonomy']))) { |
|
520 | 512 | $imv = reset($form_state['values']['forum_access']['template']['taxonomy']); |
521 | 513 | $template_tid = reset($imv); |
522 | 514 | } |
@@ -549,14 +541,12 @@ discard block |
||
549 | 541 | $template_tid = reset(array_values($access['template']['taxonomy'])); |
550 | 542 | if ($access['template']['select_by_default']) { |
551 | 543 | variable_set('forum_access_default_template_tid', $template_tid); |
552 | - } |
|
553 | - elseif (variable_get('forum_access_default_template_tid', 0) == $template_tid) { |
|
544 | + } elseif (variable_get('forum_access_default_template_tid', 0) == $template_tid) { |
|
554 | 545 | variable_del('forum_access_default_template_tid'); |
555 | 546 | } |
556 | 547 | if ($access['template']['load_for_new']) { |
557 | 548 | variable_set('forum_access_new_template_tid', $template_tid); |
558 | - } |
|
559 | - elseif (variable_get('forum_access_new_template_tid', 0) == $template_tid) { |
|
549 | + } elseif (variable_get('forum_access_new_template_tid', 0) == $template_tid) { |
|
560 | 550 | variable_del('forum_access_new_template_tid'); |
561 | 551 | } |
562 | 552 | module_load_include('node.inc', 'forum_access'); |
@@ -598,8 +588,7 @@ discard block |
||
598 | 588 | // We prefer not to save records for node administrators, because these have access anyway. |
599 | 589 | if (isset($permissions[$rid]['administer forums']) && $access['view'][$rid]) { |
600 | 590 | // For forum administrators, View needs to be saved, ... |
601 | - } |
|
602 | - else { |
|
591 | + } else { |
|
603 | 592 | // ... otherwise forget View. |
604 | 593 | $access['view'][$rid] = FALSE; |
605 | 594 | } |
@@ -607,8 +596,7 @@ discard block |
||
607 | 596 | db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
608 | 597 | $tid, $rid, !empty($access['view'][$rid]), 0, 0, !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
609 | 598 | } |
610 | - } |
|
611 | - else { |
|
599 | + } else { |
|
612 | 600 | db_query("INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, grant_comment_create, priority) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", |
613 | 601 | $tid, $rid, (bool) $checked, !empty($access['update'][$rid]), !empty($access['delete'][$rid]), !empty($access['create'][$rid]), !empty($access['comment_create'][$rid]), $fa_priority); |
614 | 602 | } |
@@ -620,8 +608,7 @@ discard block |
||
620 | 608 | if (!$is_new && $form_state['values']['form_id'] != 'forum_form_container') { |
621 | 609 | if (!isset($access['update_choice']) || $access['update_choice'] == 2) { |
622 | 610 | node_access_needs_rebuild(TRUE); |
623 | - } |
|
624 | - elseif ($access['update_choice'] == 0) { |
|
611 | + } elseif ($access['update_choice'] == 0) { |
|
625 | 612 | // update immediately (but use the batch functions anyway |
626 | 613 | $save_redirect = $form_state['redirect']; |
627 | 614 | $form_state['redirect'] = $_GET['q']; |
@@ -637,8 +624,7 @@ discard block |
||
637 | 624 | } |
638 | 625 | _forum_access_update_batch_finished(TRUE, array(), array()); |
639 | 626 | $form_state['redirect'] = $save_redirect; |
640 | - } |
|
641 | - else { |
|
627 | + } else { |
|
642 | 628 | // mass update in batch mode, modeled after node.module |
643 | 629 | $limit = $access['update_limit']; |
644 | 630 | $count = db_result(db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid WHERE tn.tid = %d", $tid)); |
@@ -698,8 +684,7 @@ discard block |
||
698 | 684 | if ($success) { |
699 | 685 | drupal_set_message(t('The content access permissions have been updated.')); |
700 | 686 | cache_clear_all(); |
701 | - } |
|
702 | - else { |
|
687 | + } else { |
|
703 | 688 | drupal_set_message(t('The content access permissions have not been properly updated.'), 'error'); |
704 | 689 | } |
705 | 690 | } |
@@ -744,8 +729,7 @@ discard block |
||
744 | 729 | $return['view'] = array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID); |
745 | 730 | $return['create'] = array(DRUPAL_AUTHENTICATED_RID); |
746 | 731 | $return['comment_create'] = array(DRUPAL_AUTHENTICATED_RID); |
747 | - } |
|
748 | - else { |
|
732 | + } else { |
|
749 | 733 | $result = db_query("SELECT * FROM {forum_access} where tid = %d", $tid); |
750 | 734 | while ($access = db_fetch_object($result)) { |
751 | 735 | if ($access->grant_view) { |
@@ -831,8 +815,7 @@ discard block |
||
831 | 815 | drupal_set_message(t('Note: In Drupal, access can only be granted, not taken away. Whatever access you grant here will not be reflected in the !Forum_Access_link settings, but !Forum_Access can only allow <i>more</i> access, not less.', $variables) |
832 | 816 | .'<br /><span class="error">'. t('Specifically, any rights granted to the %anonymous_user and/or the %authenticated_user will <b>override</b> the settings of !Forum_Access!', $variables) .'</span>' |
833 | 817 | .'<br />'. t('To avoid conflicts with !Forum_Access settings, you may want to lower the priority of !Content_Access (under %Advanced below) below the priority of !Forum_Access for the content types that you want to be controlled by !Forum_Access.', $variables), 'warning'); |
834 | - } |
|
835 | - else { |
|
818 | + } else { |
|
836 | 819 | $vid = _forum_access_get_vid(); |
837 | 820 | $vocabulary = taxonomy_vocabulary_load($vid); |
838 | 821 | if (isset($vocabulary->nodes[arg(3)])) { |
@@ -926,8 +909,7 @@ discard block |
||
926 | 909 | } |
927 | 910 | watchdog('user', $msg, NULL, WATCHDOG_NOTICE); |
928 | 911 | return $rid; |
929 | - } |
|
930 | - else { |
|
912 | + } else { |
|
931 | 913 | $msg = t('!Forum_Access cannot create the %role role!', $variables); |
932 | 914 | watchdog('user', $msg, NULL, WATCHDOG_WARNING); |
933 | 915 | drupal_set_message($msg .' '. t('Is it already in use?'), 'error'); |
@@ -143,7 +143,7 @@ |
||
143 | 143 | * Return the Views fields that should be translated. |
144 | 144 | * |
145 | 145 | * @return |
146 | - * Array of field names. |
|
146 | + string[] Array of field names. |
|
147 | 147 | */ |
148 | 148 | function _i18nviews_display_fields() { |
149 | 149 | return array('title', 'header', 'footer', 'empty'); |
@@ -14,44 +14,44 @@ discard block |
||
14 | 14 | * Implementation of hook_help(). |
15 | 15 | */ |
16 | 16 | function i18nviews_help($path, $arg) { |
17 | - switch ($path) { |
|
17 | + switch ($path) { |
|
18 | 18 | case 'admin/modules#description' : |
19 | 19 | $output = '<p>'. t('Supports translation for views strings: title, header, footer...') .'</p>'; |
20 | - $output .= '<p>'. t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))) .'</p>'; |
|
21 | - return $output; |
|
22 | - } |
|
20 | + $output .= '<p>'. t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))) .'</p>'; |
|
21 | + return $output; |
|
22 | + } |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Implementation of hook_locale(). |
27 | 27 | */ |
28 | 28 | function i18nviews_locale($op = 'groups') { |
29 | - switch ($op) { |
|
29 | + switch ($op) { |
|
30 | 30 | case 'groups': |
31 | 31 | return array('views' => t('Views')); |
32 | 32 | case 'info': |
33 | 33 | $info['views']['refresh callback'] = 'i18nviews_locale_refresh'; |
34 | - $info['views']['format'] = TRUE; |
|
35 | - return $info; |
|
36 | - } |
|
34 | + $info['views']['format'] = TRUE; |
|
35 | + return $info; |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Refresh views locales, 2.x version |
41 | 41 | */ |
42 | 42 | function i18nviews_locale_refresh() { |
43 | - $views = views_get_all_views(); |
|
44 | - foreach ($views as $view) { |
|
43 | + $views = views_get_all_views(); |
|
44 | + foreach ($views as $view) { |
|
45 | 45 | if (!$view->disabled) { |
46 | - $fields = _i18nviews_display_fields(); |
|
47 | - if (!empty($view->display) && is_array($view->display)) { |
|
46 | + $fields = _i18nviews_display_fields(); |
|
47 | + if (!empty($view->display) && is_array($view->display)) { |
|
48 | 48 | foreach (array_keys($view->display) as $display_id) { |
49 | - _i18nviews_localize_array($view->name, $display_id, $view->display[$display_id]->display_options, $fields, TRUE); |
|
49 | + _i18nviews_localize_array($view->name, $display_id, $view->display[$display_id]->display_options, $fields, TRUE); |
|
50 | + } |
|
50 | 51 | } |
51 | - } |
|
52 | 52 | } |
53 | - } |
|
54 | - return TRUE; // Completed successfully |
|
53 | + } |
|
54 | + return TRUE; // Completed successfully |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -60,37 +60,37 @@ discard block |
||
60 | 60 | * Remake of views_handler_field_allterms with term name translation. |
61 | 61 | */ |
62 | 62 | function i18nviews_views_handler_field_allterms($fieldinfo, $fielddata, $value, $data) { |
63 | - if ($fieldinfo['vocabulary']) { |
|
63 | + if ($fieldinfo['vocabulary']) { |
|
64 | 64 | $terms = taxonomy_node_get_terms_by_vocabulary($data->nid, $fieldinfo['vocabulary']); |
65 | - } |
|
66 | - else { |
|
65 | + } |
|
66 | + else { |
|
67 | 67 | $terms = taxonomy_node_get_terms($data->nid); |
68 | - } |
|
69 | - // Translate all these terms. |
|
70 | - _i18ntaxonomy_translate_terms($terms); |
|
68 | + } |
|
69 | + // Translate all these terms. |
|
70 | + _i18ntaxonomy_translate_terms($terms); |
|
71 | 71 | |
72 | - if ($fielddata['options'] == 'nolink') { |
|
72 | + if ($fielddata['options'] == 'nolink') { |
|
73 | 73 | foreach ($terms as $term) { |
74 | - $links[] = check_plain($term->name); |
|
74 | + $links[] = check_plain($term->name); |
|
75 | 75 | } |
76 | 76 | $links = !empty($links) ? implode(' | ', $links) : ''; |
77 | - } |
|
78 | - else { |
|
77 | + } |
|
78 | + else { |
|
79 | 79 | $node = new stdClass(); |
80 | 80 | $node->taxonomy = $terms; |
81 | 81 | $links = theme('links', taxonomy_link('taxonomy terms', $node)); |
82 | - } |
|
83 | - return $links; |
|
82 | + } |
|
83 | + return $links; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Implementation of hook_views_api(). |
88 | 88 | */ |
89 | 89 | function i18nviews_views_api() { |
90 | - return array( |
|
90 | + return array( |
|
91 | 91 | 'api' => '2.0', |
92 | 92 | 'path' => drupal_get_path('module', 'i18nviews') . '/includes', |
93 | - ); |
|
93 | + ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -105,38 +105,38 @@ discard block |
||
105 | 105 | * This is just for views 2.x, next version (3.x) will use a different one |
106 | 106 | */ |
107 | 107 | function i18nviews_views_pre_view(&$view, &$display_id, &$args) { |
108 | - global $language; |
|
109 | - if (views_api_version() == '2.0' && $language->language != language_default('language')) { |
|
108 | + global $language; |
|
109 | + if (views_api_version() == '2.0' && $language->language != language_default('language')) { |
|
110 | 110 | // Also checking weird values for $display_id, see 277711 |
111 | 111 | if (!empty($view->display) && is_array($view->display) && is_string($display_id)) { |
112 | - $fields = _i18nviews_display_fields(); |
|
113 | - if(!empty($view->display[$display_id])) { |
|
112 | + $fields = _i18nviews_display_fields(); |
|
113 | + if(!empty($view->display[$display_id])) { |
|
114 | 114 | $fields = _i18nviews_localize_array($view->name, $display_id, $view->display[$display_id]->handler->options, $fields); |
115 | - } |
|
116 | - if($fields && !empty($view->display['default'])) { |
|
115 | + } |
|
116 | + if($fields && !empty($view->display['default'])) { |
|
117 | 117 | _i18nviews_localize_array($view->name, 'default', $view->display['default']->handler->options, $fields); |
118 | - } |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | // Translate taxonomy fields. |
121 | 121 | // @todo I don think this works at all. |
122 | 122 | if (module_exists('i18ntaxonomy') && isset($view->field) && is_array($view->field)) { |
123 | - $translate = variable_get('i18ntaxonomy_vocabularies', array()); |
|
124 | - foreach ($view->field as $index => $data) { |
|
123 | + $translate = variable_get('i18ntaxonomy_vocabularies', array()); |
|
124 | + foreach ($view->field as $index => $data) { |
|
125 | 125 | $matches = array(); |
126 | 126 | if ($data['id'] == 'term_node.name') { |
127 | - // That's a full taxonomy box. |
|
128 | - $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; |
|
127 | + // That's a full taxonomy box. |
|
128 | + $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; |
|
129 | 129 | } |
130 | 130 | elseif (preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { |
131 | - $vid = $matches[1]; |
|
132 | - if ($translate[$vid]) { |
|
131 | + $vid = $matches[1]; |
|
132 | + if ($translate[$vid]) { |
|
133 | 133 | // Set new handler for this field. |
134 | 134 | $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; |
135 | - } |
|
135 | + } |
|
136 | + } |
|
136 | 137 | } |
137 | - } |
|
138 | 138 | } |
139 | - } |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * Array of field names. |
147 | 147 | */ |
148 | 148 | function _i18nviews_display_fields() { |
149 | - return array('title', 'header', 'footer', 'empty'); |
|
149 | + return array('title', 'header', 'footer', 'empty'); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,21 +155,21 @@ discard block |
||
155 | 155 | * We get the translated fields out of the array so they are not translated again. |
156 | 156 | */ |
157 | 157 | function _i18nviews_localize_array($name, $group, &$data, $field_names, $update = FALSE) { |
158 | - $translated = array(); |
|
159 | - foreach ($field_names as $field) { |
|
158 | + $translated = array(); |
|
159 | + foreach ($field_names as $field) { |
|
160 | 160 | if (!empty($data[$field])) { |
161 | - if ($update) { |
|
161 | + if ($update) { |
|
162 | 162 | $format = isset($data[$field . '_format']) ? $data[$field . '_format'] : NULL; |
163 | 163 | i18nstrings_update("views:$name:$group:$field", $data[$field], $format); |
164 | - } |
|
165 | - else { |
|
164 | + } |
|
165 | + else { |
|
166 | 166 | $data[$field] = i18nstrings("views:$name:$group:$field", $data[$field]); |
167 | 167 | $translated[] = $field; |
168 | - } |
|
168 | + } |
|
169 | 169 | } |
170 | - } |
|
171 | - // Return remaining field names |
|
172 | - return array_diff($field_names, $translated); |
|
170 | + } |
|
171 | + // Return remaining field names |
|
172 | + return array_diff($field_names, $translated); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | * We cannot play with object 2 array conversion because some are real typed objects. |
179 | 179 | */ |
180 | 180 | function _i18nviews_localize_object($name, $group, &$data, &$field_names, $trim = FALSE) { |
181 | - $translated = array(); |
|
182 | - foreach ($field_names as $field) { |
|
181 | + $translated = array(); |
|
182 | + foreach ($field_names as $field) { |
|
183 | 183 | if (!empty($data->$field)) { |
184 | - $data->$field = i18nstrings("views:$name:$group:$field", $data->$field); |
|
184 | + $data->$field = i18nstrings("views:$name:$group:$field", $data->$field); |
|
185 | + } |
|
185 | 186 | } |
186 | - } |
|
187 | - if ($trim && $translated) { |
|
187 | + if ($trim && $translated) { |
|
188 | 188 | $field_names = array_diff($field_names, $translated); |
189 | - } |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * Add a submit handler to the submit button on views_ui_edit_display_form. |
196 | 196 | */ |
197 | 197 | function i18nviews_form_views_ui_edit_display_form_alter(&$form, $form_state) { |
198 | - $form['buttons']['submit']['#submit'][] = 'i18nviews_views_ui_edit_display_submit'; |
|
198 | + $form['buttons']['submit']['#submit'][] = 'i18nviews_views_ui_edit_display_submit'; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | * Creates or updates translation source records for specified Views fields. |
205 | 205 | */ |
206 | 206 | function i18nviews_views_ui_edit_display_submit($form, &$form_state) { |
207 | - $fields = _i18nviews_display_fields(); |
|
208 | - foreach ($fields as $field) { |
|
207 | + $fields = _i18nviews_display_fields(); |
|
208 | + foreach ($fields as $field) { |
|
209 | 209 | if (isset($form_state['values'][$field])) { |
210 | - $name = $form_state['view']->name; |
|
211 | - $group = $form_state['display_id']; |
|
212 | - $format = isset($form_state['values'][$field . '_format']) ? $form_state['values'][$field . '_format'] : NULL; |
|
213 | - i18nstrings_update("views:$name:$group:$field", $form_state['values'][$field], $format); |
|
210 | + $name = $form_state['view']->name; |
|
211 | + $group = $form_state['display_id']; |
|
212 | + $format = isset($form_state['values'][$field . '_format']) ? $form_state['values'][$field . '_format'] : NULL; |
|
213 | + i18nstrings_update("views:$name:$group:$field", $form_state['values'][$field], $format); |
|
214 | + } |
|
214 | 215 | } |
215 | - } |
|
216 | 216 | } |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | */ |
16 | 16 | function i18nviews_help($path, $arg) { |
17 | 17 | switch ($path) { |
18 | - case 'admin/modules#description' : |
|
19 | - $output = '<p>'. t('Supports translation for views strings: title, header, footer...') .'</p>'; |
|
20 | - $output .= '<p>'. t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))) .'</p>'; |
|
21 | - return $output; |
|
18 | + case 'admin/modules#description' : |
|
19 | + $output = '<p>'. t('Supports translation for views strings: title, header, footer...') .'</p>'; |
|
20 | + $output .= '<p>'. t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))) .'</p>'; |
|
21 | + return $output; |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | */ |
28 | 28 | function i18nviews_locale($op = 'groups') { |
29 | 29 | switch ($op) { |
30 | - case 'groups': |
|
31 | - return array('views' => t('Views')); |
|
32 | - case 'info': |
|
33 | - $info['views']['refresh callback'] = 'i18nviews_locale_refresh'; |
|
34 | - $info['views']['format'] = TRUE; |
|
35 | - return $info; |
|
30 | + case 'groups': |
|
31 | + return array('views' => t('Views')); |
|
32 | + case 'info': |
|
33 | + $info['views']['refresh callback'] = 'i18nviews_locale_refresh'; |
|
34 | + $info['views']['format'] = TRUE; |
|
35 | + return $info; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | function i18nviews_help($path, $arg) { |
17 | 17 | switch ($path) { |
18 | 18 | case 'admin/modules#description' : |
19 | - $output = '<p>'. t('Supports translation for views strings: title, header, footer...') .'</p>'; |
|
20 | - $output .= '<p>'. t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))) .'</p>'; |
|
19 | + $output = '<p>'.t('Supports translation for views strings: title, header, footer...').'</p>'; |
|
20 | + $output .= '<p>'.t('To search and translate strings, use the <a href="@translate-interface">translation interface</a> pages.', array('@translate-interface' => url('admin/build/translate'))).'</p>'; |
|
21 | 21 | return $output; |
22 | 22 | } |
23 | 23 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | function i18nviews_views_api() { |
90 | 90 | return array( |
91 | 91 | 'api' => '2.0', |
92 | - 'path' => drupal_get_path('module', 'i18nviews') . '/includes', |
|
92 | + 'path' => drupal_get_path('module', 'i18nviews').'/includes', |
|
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | // Also checking weird values for $display_id, see 277711 |
111 | 111 | if (!empty($view->display) && is_array($view->display) && is_string($display_id)) { |
112 | 112 | $fields = _i18nviews_display_fields(); |
113 | - if(!empty($view->display[$display_id])) { |
|
113 | + if (!empty($view->display[$display_id])) { |
|
114 | 114 | $fields = _i18nviews_localize_array($view->name, $display_id, $view->display[$display_id]->handler->options, $fields); |
115 | 115 | } |
116 | - if($fields && !empty($view->display['default'])) { |
|
116 | + if ($fields && !empty($view->display['default'])) { |
|
117 | 117 | _i18nviews_localize_array($view->name, 'default', $view->display['default']->handler->options, $fields); |
118 | 118 | } |
119 | 119 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | foreach ($field_names as $field) { |
160 | 160 | if (!empty($data[$field])) { |
161 | 161 | if ($update) { |
162 | - $format = isset($data[$field . '_format']) ? $data[$field . '_format'] : NULL; |
|
162 | + $format = isset($data[$field.'_format']) ? $data[$field.'_format'] : NULL; |
|
163 | 163 | i18nstrings_update("views:$name:$group:$field", $data[$field], $format); |
164 | 164 | } |
165 | 165 | else { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if (isset($form_state['values'][$field])) { |
210 | 210 | $name = $form_state['view']->name; |
211 | 211 | $group = $form_state['display_id']; |
212 | - $format = isset($form_state['values'][$field . '_format']) ? $form_state['values'][$field . '_format'] : NULL; |
|
212 | + $format = isset($form_state['values'][$field.'_format']) ? $form_state['values'][$field.'_format'] : NULL; |
|
213 | 213 | i18nstrings_update("views:$name:$group:$field", $form_state['values'][$field], $format); |
214 | 214 | } |
215 | 215 | } |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | function i18nviews_views_handler_field_allterms($fieldinfo, $fielddata, $value, $data) { |
63 | 63 | if ($fieldinfo['vocabulary']) { |
64 | 64 | $terms = taxonomy_node_get_terms_by_vocabulary($data->nid, $fieldinfo['vocabulary']); |
65 | - } |
|
66 | - else { |
|
65 | + } else { |
|
67 | 66 | $terms = taxonomy_node_get_terms($data->nid); |
68 | 67 | } |
69 | 68 | // Translate all these terms. |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | $links[] = check_plain($term->name); |
75 | 74 | } |
76 | 75 | $links = !empty($links) ? implode(' | ', $links) : ''; |
77 | - } |
|
78 | - else { |
|
76 | + } else { |
|
79 | 77 | $node = new stdClass(); |
80 | 78 | $node->taxonomy = $terms; |
81 | 79 | $links = theme('links', taxonomy_link('taxonomy terms', $node)); |
@@ -126,8 +124,7 @@ discard block |
||
126 | 124 | if ($data['id'] == 'term_node.name') { |
127 | 125 | // That's a full taxonomy box. |
128 | 126 | $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; |
129 | - } |
|
130 | - elseif (preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { |
|
127 | + } elseif (preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { |
|
131 | 128 | $vid = $matches[1]; |
132 | 129 | if ($translate[$vid]) { |
133 | 130 | // Set new handler for this field. |
@@ -161,8 +158,7 @@ discard block |
||
161 | 158 | if ($update) { |
162 | 159 | $format = isset($data[$field . '_format']) ? $data[$field . '_format'] : NULL; |
163 | 160 | i18nstrings_update("views:$name:$group:$field", $data[$field], $format); |
164 | - } |
|
165 | - else { |
|
161 | + } else { |
|
166 | 162 | $data[$field] = i18nstrings("views:$name:$group:$field", $data[$field]); |
167 | 163 | $translated[] = $field; |
168 | 164 | } |
@@ -161,7 +161,6 @@ |
||
161 | 161 | * |
162 | 162 | * @param array $form_state |
163 | 163 | * @param array $options |
164 | - * @param integer $active |
|
165 | 164 | * @return array |
166 | 165 | */ |
167 | 166 | function jump_quickly_form(&$form_state, $options, $menu_state) { |
@@ -12,16 +12,16 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | */ |
14 | 14 | function jump_menu() { |
15 | - $items = array(); |
|
16 | - $items['admin/settings/jump'] = array( |
|
15 | + $items = array(); |
|
16 | + $items['admin/settings/jump'] = array( |
|
17 | 17 | 'title' => 'Jump Settings', |
18 | 18 | 'description' => 'Configure Jump module settings.', |
19 | 19 | 'page callback' => 'drupal_get_form', |
20 | 20 | 'page arguments' => array('jump_settings'), |
21 | 21 | 'access callback' => 'user_access', |
22 | 22 | 'access arguments' => array('administer menu'), |
23 | - ); |
|
24 | - return $items; |
|
23 | + ); |
|
24 | + return $items; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * @return string |
31 | 31 | */ |
32 | 32 | function jump_settings() { |
33 | - $form['jump_activepageinmenu'] = array( |
|
33 | + $form['jump_activepageinmenu'] = array( |
|
34 | 34 | '#type' => 'checkbox', |
35 | 35 | '#title' => t('Show active page in menu.'), |
36 | 36 | '#default_value' => variable_get('jump_activepageinmenu', 1), |
37 | 37 | '#description' => t('This setting will force the jump menu to show the current page as the default selection in the jump menu when checked. If you have a menu option that you would always like displayed at the top of the menu, like <em>Select a menu item</em>, you will want to uncheck this. This setting controls this behavior for all jump menus sitewide. You can override this setting on a block-by-block basis.'), |
38 | - ); |
|
39 | - return system_settings_form($form); |
|
38 | + ); |
|
39 | + return system_settings_form($form); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,64 +48,64 @@ discard block |
||
48 | 48 | * @return array |
49 | 49 | */ |
50 | 50 | function jump_block($op = 'list', $delta = 0, $edit = array()) { |
51 | - switch ($op) { |
|
51 | + switch ($op) { |
|
52 | 52 | case 'list': |
53 | 53 | $blocks = array(); |
54 | - foreach (menu_get_menus() as $name => $title) { |
|
54 | + foreach (menu_get_menus() as $name => $title) { |
|
55 | 55 | $blocks['menu-' . $name] = array( |
56 | - 'info' => t('Jump menu: !menu', array('!menu' => $name)) |
|
56 | + 'info' => t('Jump menu: !menu', array('!menu' => $name)) |
|
57 | 57 | ); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - $vocs = taxonomy_get_vocabularies(); |
|
61 | - foreach ($vocs as $vid => $vocabulary) { |
|
60 | + $vocs = taxonomy_get_vocabularies(); |
|
61 | + foreach ($vocs as $vid => $vocabulary) { |
|
62 | 62 | $blocks['taxo-' . $vid] = array( |
63 | - 'info' => t('Jump menu: !voc', array('!voc' => $vocabulary->name)) |
|
63 | + 'info' => t('Jump menu: !voc', array('!voc' => $vocabulary->name)) |
|
64 | 64 | ); |
65 | - } |
|
66 | - return $blocks; |
|
65 | + } |
|
66 | + return $blocks; |
|
67 | 67 | case 'configure': |
68 | 68 | $form = array(); |
69 | - $form['block_settings']['jump_activepageinmenu_' . $delta] = array( |
|
69 | + $form['block_settings']['jump_activepageinmenu_' . $delta] = array( |
|
70 | 70 | '#type' => 'checkbox', |
71 | 71 | '#title' => t('Show active page in jump menu.'), |
72 | 72 | '#default_value' => variable_get('jump_activepageinmenu_' . $delta, 1), |
73 | 73 | '#description' => t('This setting will force the jump menu to show the current page as the default selection in this block\'s jump menu.'), |
74 | - ); |
|
75 | - // Do the rest of the form additions in hook_form_alter() since we can't do ahah here. |
|
76 | - return $form; |
|
74 | + ); |
|
75 | + // Do the rest of the form additions in hook_form_alter() since we can't do ahah here. |
|
76 | + return $form; |
|
77 | 77 | case 'save': |
78 | 78 | variable_set('jump_activepageinmenu_' . $delta, $edit['jump_activepageinmenu_' . $delta]); |
79 | - variable_set('jump_use_js_' . $delta, $edit['jump_use_js_' . $delta]); |
|
80 | - variable_set('jump_add_select_' . $delta, $edit['jump_add_select_' . $delta]); |
|
81 | - variable_set('jump_add_select_text_' . $delta, $edit['jump_add_select_text_' . $delta]); |
|
82 | - break; |
|
79 | + variable_set('jump_use_js_' . $delta, $edit['jump_use_js_' . $delta]); |
|
80 | + variable_set('jump_add_select_' . $delta, $edit['jump_add_select_' . $delta]); |
|
81 | + variable_set('jump_add_select_text_' . $delta, $edit['jump_add_select_text_' . $delta]); |
|
82 | + break; |
|
83 | 83 | case 'view': |
84 | 84 | // The first 5 characters of $delta should be one of: |
85 | 85 | // menu- |
86 | 86 | // taxo- |
87 | 87 | $subject = ''; |
88 | - $jumpmenu_type = substr($delta, 0, 4); |
|
89 | - $jumpmenu_name = substr($delta, 5); |
|
90 | - $active = jump_get_active_setting($delta); |
|
91 | - if ($jumpmenu_type == 'menu') { |
|
88 | + $jumpmenu_type = substr($delta, 0, 4); |
|
89 | + $jumpmenu_name = substr($delta, 5); |
|
90 | + $active = jump_get_active_setting($delta); |
|
91 | + if ($jumpmenu_type == 'menu') { |
|
92 | 92 | $form = jump_quickly($jumpmenu_name, 'menu', $active); |
93 | 93 | |
94 | 94 | // Use the menu label as the default block subject |
95 | 95 | $menus = menu_get_menus(); |
96 | 96 | $subject = $menus[$jumpmenu_name]; |
97 | - } |
|
98 | - else if ($jumpmenu_type == 'taxo') { |
|
97 | + } |
|
98 | + else if ($jumpmenu_type == 'taxo') { |
|
99 | 99 | $form = jump_quickly($jumpmenu_name, 'taxo', $active); |
100 | 100 | |
101 | 101 | // Use the vocabulary name as the default block subject |
102 | 102 | $vocab = taxonomy_vocabulary_load($jumpmenu_name); |
103 | 103 | $subject = $vocab->name; |
104 | - } |
|
105 | - if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
106 | - return array('subject' => $subject, 'content' => $form); |
|
107 | - break; |
|
108 | - } |
|
104 | + } |
|
105 | + if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
106 | + return array('subject' => $subject, 'content' => $form); |
|
107 | + break; |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -124,36 +124,36 @@ discard block |
||
124 | 124 | * @return array |
125 | 125 | */ |
126 | 126 | function jump_quickly($name = 'navigation', $type = 'menu', $active = -1, $override = '') { |
127 | - // Reconstruct the $delta |
|
128 | - $delta = $type . '-' . $name; |
|
129 | - if ($active === -1) { |
|
127 | + // Reconstruct the $delta |
|
128 | + $delta = $type . '-' . $name; |
|
129 | + if ($active === -1) { |
|
130 | 130 | $active = variable_get('jump_activepageinmenu', 1); |
131 | - } |
|
132 | - $menu_state = array( |
|
131 | + } |
|
132 | + $menu_state = array( |
|
133 | 133 | 'delta' => $delta, |
134 | 134 | 'active' => $active, |
135 | 135 | 'override' => $override |
136 | - ); |
|
136 | + ); |
|
137 | 137 | |
138 | - if (is_array($name)) { |
|
138 | + if (is_array($name)) { |
|
139 | 139 | $options = $name; |
140 | - } |
|
141 | - else { |
|
140 | + } |
|
141 | + else { |
|
142 | 142 | $options = array(); |
143 | 143 | if ($type == 'menu') { |
144 | - jump_menu_get_menu_options($options, $name); |
|
144 | + jump_menu_get_menu_options($options, $name); |
|
145 | 145 | } |
146 | 146 | elseif ($type == 'taxo') { |
147 | - jump_menu_get_taxo_options($options, $name); |
|
147 | + jump_menu_get_taxo_options($options, $name); |
|
148 | + } |
|
148 | 149 | } |
149 | - } |
|
150 | 150 | |
151 | - // Give each form on the page a unique id so we can handle multiple |
|
152 | - // jump forms... |
|
153 | - static $num_jump_forms = 0; |
|
154 | - $num_jump_forms++; |
|
151 | + // Give each form on the page a unique id so we can handle multiple |
|
152 | + // jump forms... |
|
153 | + static $num_jump_forms = 0; |
|
154 | + $num_jump_forms++; |
|
155 | 155 | |
156 | - return drupal_get_form('jump_quickly_form_' . $num_jump_forms, $options, $menu_state); |
|
156 | + return drupal_get_form('jump_quickly_form_' . $num_jump_forms, $options, $menu_state); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -165,43 +165,43 @@ discard block |
||
165 | 165 | * @return array |
166 | 166 | */ |
167 | 167 | function jump_quickly_form(&$form_state, $options, $menu_state) { |
168 | - $default = ''; |
|
169 | - if ($menu_state['active'] === 1) { |
|
168 | + $default = ''; |
|
169 | + if ($menu_state['active'] === 1) { |
|
170 | 170 | if (isset($options[$_GET['q']])) { |
171 | - $default = $_GET['q']; |
|
171 | + $default = $_GET['q']; |
|
172 | + } |
|
172 | 173 | } |
173 | - } |
|
174 | - if ($menu_state['override']) { |
|
174 | + if ($menu_state['override']) { |
|
175 | 175 | $default = $menu_state['override']; |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - $form = array(); |
|
179 | - $form['#submit'][] = 'jump_quickly_form_submit'; |
|
180 | - $form['#theme'] = 'jump_quickly_form'; |
|
181 | - $form['#attributes']['class'] = 'jump-quickly'; |
|
182 | - $form['jump_goto'] = array( |
|
178 | + $form = array(); |
|
179 | + $form['#submit'][] = 'jump_quickly_form_submit'; |
|
180 | + $form['#theme'] = 'jump_quickly_form'; |
|
181 | + $form['#attributes']['class'] = 'jump-quickly'; |
|
182 | + $form['jump_goto'] = array( |
|
183 | 183 | '#type' => 'select', |
184 | 184 | '#default_value' => $default, |
185 | 185 | '#options' => $options |
186 | - ); |
|
187 | - $form['submit'] = array( |
|
186 | + ); |
|
187 | + $form['submit'] = array( |
|
188 | 188 | '#type' => 'submit', |
189 | 189 | '#value' => t('Go') |
190 | - ); |
|
191 | - if (variable_get('jump_use_js_' . $menu_state['delta'], 0) === 1) { |
|
190 | + ); |
|
191 | + if (variable_get('jump_use_js_' . $menu_state['delta'], 0) === 1) { |
|
192 | 192 | // Give each menu a unique name. |
193 | 193 | $form['#attributes']['name'] = 'jumpquickly' . $menu_state['delta']; |
194 | 194 | $form['#attributes']['class'] .= ' js-enabled'; |
195 | 195 | // unset($form['submit']); |
196 | 196 | if (variable_get('jump_add_select_' . $menu_state['delta'], 0) === 1) { |
197 | - $form['jump_goto']['#attributes']['class'] = 'first-no-jump'; |
|
198 | - // Add the extra empty select option to the top of the array. |
|
199 | - $form['jump_goto']['#options'] = array('' => variable_get('jump_add_select_text_' . $menu_state['delta'], t('Select Option'))) + $options; |
|
200 | - $form['jump_goto']['#default_value'] = (array_key_exists($default, $options)) ? $default : ''; |
|
197 | + $form['jump_goto']['#attributes']['class'] = 'first-no-jump'; |
|
198 | + // Add the extra empty select option to the top of the array. |
|
199 | + $form['jump_goto']['#options'] = array('' => variable_get('jump_add_select_text_' . $menu_state['delta'], t('Select Option'))) + $options; |
|
200 | + $form['jump_goto']['#default_value'] = (array_key_exists($default, $options)) ? $default : ''; |
|
201 | + } |
|
201 | 202 | } |
202 | - } |
|
203 | 203 | |
204 | - return $form; |
|
204 | + return $form; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -211,15 +211,15 @@ discard block |
||
211 | 211 | * @param array $form_state |
212 | 212 | */ |
213 | 213 | function jump_quickly_form_submit($form, &$form_state) { |
214 | - if (!empty($form_state['values']['jump_goto'])) { |
|
214 | + if (!empty($form_state['values']['jump_goto'])) { |
|
215 | 215 | $fragment = explode('#', $form_state['values']['jump_goto']); |
216 | 216 | if (isset($fragment[1])) { |
217 | - drupal_goto($fragment[0], NULL, $fragment[1]); |
|
217 | + drupal_goto($fragment[0], NULL, $fragment[1]); |
|
218 | 218 | } |
219 | 219 | else { |
220 | - drupal_goto($form_state['values']['jump_goto']); |
|
220 | + drupal_goto($form_state['values']['jump_goto']); |
|
221 | + } |
|
221 | 222 | } |
222 | - } |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -229,12 +229,12 @@ discard block |
||
229 | 229 | * @return string |
230 | 230 | */ |
231 | 231 | function theme_jump_quickly_form($form) { |
232 | - $output = '<div class="container-inline">'; |
|
233 | - $output .= drupal_render($form['jump_goto']); |
|
234 | - $output .= drupal_render($form['submit']); |
|
235 | - $output .= '</div>'; |
|
236 | - $output .= drupal_render($form); |
|
237 | - return $output; |
|
232 | + $output = '<div class="container-inline">'; |
|
233 | + $output .= drupal_render($form['jump_goto']); |
|
234 | + $output .= drupal_render($form['submit']); |
|
235 | + $output .= '</div>'; |
|
236 | + $output .= drupal_render($form); |
|
237 | + return $output; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | * @param string $name |
245 | 245 | */ |
246 | 246 | function jump_menu_get_menu_options(&$options, $name) { |
247 | - $tree = menu_tree_page_data($name); |
|
248 | - $front = variable_get('site_frontpage', 'node'); |
|
249 | - foreach ($tree as $data) { |
|
247 | + $tree = menu_tree_page_data($name); |
|
248 | + $front = variable_get('site_frontpage', 'node'); |
|
249 | + foreach ($tree as $data) { |
|
250 | 250 | if (!$data['link']['hidden']) { |
251 | - $href = ($data['link']['href'] == '<front>') ? $front : $data['link']['href']; |
|
252 | - $href = (isset($data['link']['options']['fragment'])) ? $href . '#' . $data['link']['options']['fragment'] : $href; |
|
253 | - $options[$href] = $data['link']['title']; |
|
251 | + $href = ($data['link']['href'] == '<front>') ? $front : $data['link']['href']; |
|
252 | + $href = (isset($data['link']['options']['fragment'])) ? $href . '#' . $data['link']['options']['fragment'] : $href; |
|
253 | + $options[$href] = $data['link']['title']; |
|
254 | + } |
|
254 | 255 | } |
255 | - } |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | * @param integer $vid |
263 | 263 | */ |
264 | 264 | function jump_menu_get_taxo_options(&$options, $vid) { |
265 | - $tree = taxonomy_get_tree($vid); |
|
266 | - foreach ($tree as $term) { |
|
265 | + $tree = taxonomy_get_tree($vid); |
|
266 | + foreach ($tree as $term) { |
|
267 | 267 | $options[taxonomy_term_path($term)] = $term->name; |
268 | - } |
|
268 | + } |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,14 +276,14 @@ discard block |
||
276 | 276 | * @return array |
277 | 277 | */ |
278 | 278 | function jump_forms($form_id) { |
279 | - // Ensure we map a callback for our form and not something else |
|
280 | - $forms = array(); |
|
281 | - if (strpos($form_id, 'jump_quickly_form') === 0) { |
|
279 | + // Ensure we map a callback for our form and not something else |
|
280 | + $forms = array(); |
|
281 | + if (strpos($form_id, 'jump_quickly_form') === 0) { |
|
282 | 282 | // Let the forms API know where to get the form data corresponding |
283 | 283 | // to this form id. |
284 | 284 | $forms[$form_id] = array('callback' => 'jump_quickly_form'); |
285 | - } |
|
286 | - return $forms; |
|
285 | + } |
|
286 | + return $forms; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | function jump_theme() { |
295 | - return array( |
|
295 | + return array( |
|
296 | 296 | 'jump_quickly_form' => array( |
297 | - 'arguments' => array('form') |
|
297 | + 'arguments' => array('form') |
|
298 | 298 | ) |
299 | - ); |
|
299 | + ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @param string $form_id |
309 | 309 | */ |
310 | 310 | function jump_form_alter(&$form, $form_state, $form_id) { |
311 | - switch ($form_id) { |
|
311 | + switch ($form_id) { |
|
312 | 312 | case 'block_admin_configure': |
313 | 313 | if ($form['module']['#value'] === 'jump' && function_exists('ahah_helper_register')) { |
314 | 314 | $delta = $form['delta']['#value']; |
@@ -317,45 +317,45 @@ discard block |
||
317 | 317 | $default_jump_add_select = (!isset($form_state['storage']['jump_add_select_' . $delta])) ? variable_get('jump_add_select_' . $delta, 0) : $form_state['storage']['jump_add_select_' . $delta]; |
318 | 318 | |
319 | 319 | $form['block_settings']['jump_wrapper'] = array( |
320 | - '#prefix' => '<div id="jump-wrapper">', |
|
321 | - '#suffix' => '</div>', |
|
322 | - '#type' => 'markup' |
|
320 | + '#prefix' => '<div id="jump-wrapper">', |
|
321 | + '#suffix' => '</div>', |
|
322 | + '#type' => 'markup' |
|
323 | 323 | ); |
324 | 324 | $form['block_settings']['jump_wrapper']['jump_use_js_' . $delta] = array( |
325 | - '#type' => 'checkbox', |
|
326 | - '#title' => t('Hide the submit button and use Javascript to automatically jump to the selected menu item'), |
|
327 | - '#default_value' => $default_jump_use_js, |
|
328 | - '#disabled' => ($default_jump_add_select === 1) ? TRUE : FALSE, |
|
329 | - '#ahah' => array( |
|
325 | + '#type' => 'checkbox', |
|
326 | + '#title' => t('Hide the submit button and use Javascript to automatically jump to the selected menu item'), |
|
327 | + '#default_value' => $default_jump_use_js, |
|
328 | + '#disabled' => ($default_jump_add_select === 1) ? TRUE : FALSE, |
|
329 | + '#ahah' => array( |
|
330 | 330 | 'event' => 'change', |
331 | 331 | 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
332 | 332 | 'wrapper' => 'jump-wrapper', |
333 | - ), |
|
333 | + ), |
|
334 | 334 | ); |
335 | 335 | if ($default_jump_use_js === 1) { |
336 | - $form['block_settings']['jump_wrapper']['jump_add_select_' . $delta] = array( |
|
336 | + $form['block_settings']['jump_wrapper']['jump_add_select_' . $delta] = array( |
|
337 | 337 | '#type' => 'checkbox', |
338 | 338 | '#title' => t('Add an empty select option into the list of options'), |
339 | 339 | '#default_value' => $default_jump_add_select, |
340 | 340 | '#weight' => 1, |
341 | 341 | '#ahah' => array( |
342 | - 'event' => 'change', |
|
343 | - 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
|
344 | - 'wrapper' => 'jump-wrapper', |
|
342 | + 'event' => 'change', |
|
343 | + 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
|
344 | + 'wrapper' => 'jump-wrapper', |
|
345 | 345 | ), |
346 | - ); |
|
347 | - if ($default_jump_add_select === 1) { |
|
346 | + ); |
|
347 | + if ($default_jump_add_select === 1) { |
|
348 | 348 | $form['block_settings']['jump_wrapper']['jump_add_select_text_' . $delta] = array( |
349 | - '#type' => 'textfield', |
|
350 | - '#title' => t('Text to use for the empty select option'), |
|
351 | - '#default_value' => variable_get('jump_add_select_text_' . $delta, t('Select Option')), |
|
352 | - '#weight' => 2 |
|
349 | + '#type' => 'textfield', |
|
350 | + '#title' => t('Text to use for the empty select option'), |
|
351 | + '#default_value' => variable_get('jump_add_select_text_' . $delta, t('Select Option')), |
|
352 | + '#weight' => 2 |
|
353 | 353 | ); |
354 | - } |
|
354 | + } |
|
355 | 355 | } |
356 | - } |
|
357 | - break; |
|
358 | - } |
|
356 | + } |
|
357 | + break; |
|
358 | + } |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -365,16 +365,16 @@ discard block |
||
365 | 365 | * @return integer |
366 | 366 | */ |
367 | 367 | function jump_get_active_setting($delta) { |
368 | - $active_site_default = variable_get('jump_activepageinmenu', 1); |
|
369 | - $active = variable_get('jump_activepageinmenu_' . $delta, $active_site_default); |
|
370 | - return $active; |
|
368 | + $active_site_default = variable_get('jump_activepageinmenu', 1); |
|
369 | + $active = variable_get('jump_activepageinmenu_' . $delta, $active_site_default); |
|
370 | + return $active; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
374 | 374 | * Implementation of hook_views_api(). |
375 | 375 | */ |
376 | 376 | function jump_views_api() { |
377 | - return array( |
|
377 | + return array( |
|
378 | 378 | 'api' => 2, |
379 | - ); |
|
379 | + ); |
|
380 | 380 | } |
@@ -49,62 +49,62 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function jump_block($op = 'list', $delta = 0, $edit = array()) { |
51 | 51 | switch ($op) { |
52 | - case 'list': |
|
53 | - $blocks = array(); |
|
54 | - foreach (menu_get_menus() as $name => $title) { |
|
55 | - $blocks['menu-' . $name] = array( |
|
56 | - 'info' => t('Jump menu: !menu', array('!menu' => $name)) |
|
57 | - ); |
|
58 | - } |
|
52 | + case 'list': |
|
53 | + $blocks = array(); |
|
54 | + foreach (menu_get_menus() as $name => $title) { |
|
55 | + $blocks['menu-' . $name] = array( |
|
56 | + 'info' => t('Jump menu: !menu', array('!menu' => $name)) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - $vocs = taxonomy_get_vocabularies(); |
|
61 | - foreach ($vocs as $vid => $vocabulary) { |
|
62 | - $blocks['taxo-' . $vid] = array( |
|
63 | - 'info' => t('Jump menu: !voc', array('!voc' => $vocabulary->name)) |
|
64 | - ); |
|
65 | - } |
|
66 | - return $blocks; |
|
67 | - case 'configure': |
|
68 | - $form = array(); |
|
69 | - $form['block_settings']['jump_activepageinmenu_' . $delta] = array( |
|
70 | - '#type' => 'checkbox', |
|
71 | - '#title' => t('Show active page in jump menu.'), |
|
72 | - '#default_value' => variable_get('jump_activepageinmenu_' . $delta, 1), |
|
73 | - '#description' => t('This setting will force the jump menu to show the current page as the default selection in this block\'s jump menu.'), |
|
60 | + $vocs = taxonomy_get_vocabularies(); |
|
61 | + foreach ($vocs as $vid => $vocabulary) { |
|
62 | + $blocks['taxo-' . $vid] = array( |
|
63 | + 'info' => t('Jump menu: !voc', array('!voc' => $vocabulary->name)) |
|
74 | 64 | ); |
75 | - // Do the rest of the form additions in hook_form_alter() since we can't do ahah here. |
|
76 | - return $form; |
|
77 | - case 'save': |
|
78 | - variable_set('jump_activepageinmenu_' . $delta, $edit['jump_activepageinmenu_' . $delta]); |
|
79 | - variable_set('jump_use_js_' . $delta, $edit['jump_use_js_' . $delta]); |
|
80 | - variable_set('jump_add_select_' . $delta, $edit['jump_add_select_' . $delta]); |
|
81 | - variable_set('jump_add_select_text_' . $delta, $edit['jump_add_select_text_' . $delta]); |
|
82 | - break; |
|
83 | - case 'view': |
|
84 | - // The first 5 characters of $delta should be one of: |
|
85 | - // menu- |
|
86 | - // taxo- |
|
87 | - $subject = ''; |
|
88 | - $jumpmenu_type = substr($delta, 0, 4); |
|
89 | - $jumpmenu_name = substr($delta, 5); |
|
90 | - $active = jump_get_active_setting($delta); |
|
91 | - if ($jumpmenu_type == 'menu') { |
|
92 | - $form = jump_quickly($jumpmenu_name, 'menu', $active); |
|
65 | + } |
|
66 | + return $blocks; |
|
67 | + case 'configure': |
|
68 | + $form = array(); |
|
69 | + $form['block_settings']['jump_activepageinmenu_' . $delta] = array( |
|
70 | + '#type' => 'checkbox', |
|
71 | + '#title' => t('Show active page in jump menu.'), |
|
72 | + '#default_value' => variable_get('jump_activepageinmenu_' . $delta, 1), |
|
73 | + '#description' => t('This setting will force the jump menu to show the current page as the default selection in this block\'s jump menu.'), |
|
74 | + ); |
|
75 | + // Do the rest of the form additions in hook_form_alter() since we can't do ahah here. |
|
76 | + return $form; |
|
77 | + case 'save': |
|
78 | + variable_set('jump_activepageinmenu_' . $delta, $edit['jump_activepageinmenu_' . $delta]); |
|
79 | + variable_set('jump_use_js_' . $delta, $edit['jump_use_js_' . $delta]); |
|
80 | + variable_set('jump_add_select_' . $delta, $edit['jump_add_select_' . $delta]); |
|
81 | + variable_set('jump_add_select_text_' . $delta, $edit['jump_add_select_text_' . $delta]); |
|
82 | + break; |
|
83 | + case 'view': |
|
84 | + // The first 5 characters of $delta should be one of: |
|
85 | + // menu- |
|
86 | + // taxo- |
|
87 | + $subject = ''; |
|
88 | + $jumpmenu_type = substr($delta, 0, 4); |
|
89 | + $jumpmenu_name = substr($delta, 5); |
|
90 | + $active = jump_get_active_setting($delta); |
|
91 | + if ($jumpmenu_type == 'menu') { |
|
92 | + $form = jump_quickly($jumpmenu_name, 'menu', $active); |
|
93 | 93 | |
94 | - // Use the menu label as the default block subject |
|
95 | - $menus = menu_get_menus(); |
|
96 | - $subject = $menus[$jumpmenu_name]; |
|
97 | - } |
|
98 | - else if ($jumpmenu_type == 'taxo') { |
|
99 | - $form = jump_quickly($jumpmenu_name, 'taxo', $active); |
|
94 | + // Use the menu label as the default block subject |
|
95 | + $menus = menu_get_menus(); |
|
96 | + $subject = $menus[$jumpmenu_name]; |
|
97 | + } |
|
98 | + else if ($jumpmenu_type == 'taxo') { |
|
99 | + $form = jump_quickly($jumpmenu_name, 'taxo', $active); |
|
100 | 100 | |
101 | - // Use the vocabulary name as the default block subject |
|
102 | - $vocab = taxonomy_vocabulary_load($jumpmenu_name); |
|
103 | - $subject = $vocab->name; |
|
104 | - } |
|
105 | - if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
106 | - return array('subject' => $subject, 'content' => $form); |
|
107 | - break; |
|
101 | + // Use the vocabulary name as the default block subject |
|
102 | + $vocab = taxonomy_vocabulary_load($jumpmenu_name); |
|
103 | + $subject = $vocab->name; |
|
104 | + } |
|
105 | + if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
106 | + return array('subject' => $subject, 'content' => $form); |
|
107 | + break; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -309,52 +309,52 @@ discard block |
||
309 | 309 | */ |
310 | 310 | function jump_form_alter(&$form, $form_state, $form_id) { |
311 | 311 | switch ($form_id) { |
312 | - case 'block_admin_configure': |
|
313 | - if ($form['module']['#value'] === 'jump' && function_exists('ahah_helper_register')) { |
|
314 | - $delta = $form['delta']['#value']; |
|
315 | - ahah_helper_register($form, $form_state); |
|
316 | - $default_jump_use_js = (!isset($form_state['storage']['jump_use_js_' . $delta])) ? variable_get('jump_use_js_' . $delta, 0) : $form_state['storage']['jump_use_js_' . $delta]; |
|
317 | - $default_jump_add_select = (!isset($form_state['storage']['jump_add_select_' . $delta])) ? variable_get('jump_add_select_' . $delta, 0) : $form_state['storage']['jump_add_select_' . $delta]; |
|
312 | + case 'block_admin_configure': |
|
313 | + if ($form['module']['#value'] === 'jump' && function_exists('ahah_helper_register')) { |
|
314 | + $delta = $form['delta']['#value']; |
|
315 | + ahah_helper_register($form, $form_state); |
|
316 | + $default_jump_use_js = (!isset($form_state['storage']['jump_use_js_' . $delta])) ? variable_get('jump_use_js_' . $delta, 0) : $form_state['storage']['jump_use_js_' . $delta]; |
|
317 | + $default_jump_add_select = (!isset($form_state['storage']['jump_add_select_' . $delta])) ? variable_get('jump_add_select_' . $delta, 0) : $form_state['storage']['jump_add_select_' . $delta]; |
|
318 | 318 | |
319 | - $form['block_settings']['jump_wrapper'] = array( |
|
320 | - '#prefix' => '<div id="jump-wrapper">', |
|
321 | - '#suffix' => '</div>', |
|
322 | - '#type' => 'markup' |
|
323 | - ); |
|
324 | - $form['block_settings']['jump_wrapper']['jump_use_js_' . $delta] = array( |
|
319 | + $form['block_settings']['jump_wrapper'] = array( |
|
320 | + '#prefix' => '<div id="jump-wrapper">', |
|
321 | + '#suffix' => '</div>', |
|
322 | + '#type' => 'markup' |
|
323 | + ); |
|
324 | + $form['block_settings']['jump_wrapper']['jump_use_js_' . $delta] = array( |
|
325 | + '#type' => 'checkbox', |
|
326 | + '#title' => t('Hide the submit button and use Javascript to automatically jump to the selected menu item'), |
|
327 | + '#default_value' => $default_jump_use_js, |
|
328 | + '#disabled' => ($default_jump_add_select === 1) ? TRUE : FALSE, |
|
329 | + '#ahah' => array( |
|
330 | + 'event' => 'change', |
|
331 | + 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
|
332 | + 'wrapper' => 'jump-wrapper', |
|
333 | + ), |
|
334 | + ); |
|
335 | + if ($default_jump_use_js === 1) { |
|
336 | + $form['block_settings']['jump_wrapper']['jump_add_select_' . $delta] = array( |
|
325 | 337 | '#type' => 'checkbox', |
326 | - '#title' => t('Hide the submit button and use Javascript to automatically jump to the selected menu item'), |
|
327 | - '#default_value' => $default_jump_use_js, |
|
328 | - '#disabled' => ($default_jump_add_select === 1) ? TRUE : FALSE, |
|
338 | + '#title' => t('Add an empty select option into the list of options'), |
|
339 | + '#default_value' => $default_jump_add_select, |
|
340 | + '#weight' => 1, |
|
329 | 341 | '#ahah' => array( |
330 | 342 | 'event' => 'change', |
331 | 343 | 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
332 | 344 | 'wrapper' => 'jump-wrapper', |
333 | 345 | ), |
334 | 346 | ); |
335 | - if ($default_jump_use_js === 1) { |
|
336 | - $form['block_settings']['jump_wrapper']['jump_add_select_' . $delta] = array( |
|
337 | - '#type' => 'checkbox', |
|
338 | - '#title' => t('Add an empty select option into the list of options'), |
|
339 | - '#default_value' => $default_jump_add_select, |
|
340 | - '#weight' => 1, |
|
341 | - '#ahah' => array( |
|
342 | - 'event' => 'change', |
|
343 | - 'path' => ahah_helper_path(array('block_settings', 'jump_wrapper')), |
|
344 | - 'wrapper' => 'jump-wrapper', |
|
345 | - ), |
|
347 | + if ($default_jump_add_select === 1) { |
|
348 | + $form['block_settings']['jump_wrapper']['jump_add_select_text_' . $delta] = array( |
|
349 | + '#type' => 'textfield', |
|
350 | + '#title' => t('Text to use for the empty select option'), |
|
351 | + '#default_value' => variable_get('jump_add_select_text_' . $delta, t('Select Option')), |
|
352 | + '#weight' => 2 |
|
346 | 353 | ); |
347 | - if ($default_jump_add_select === 1) { |
|
348 | - $form['block_settings']['jump_wrapper']['jump_add_select_text_' . $delta] = array( |
|
349 | - '#type' => 'textfield', |
|
350 | - '#title' => t('Text to use for the empty select option'), |
|
351 | - '#default_value' => variable_get('jump_add_select_text_' . $delta, t('Select Option')), |
|
352 | - '#weight' => 2 |
|
353 | - ); |
|
354 | - } |
|
355 | 354 | } |
356 | 355 | } |
357 | - break; |
|
356 | + } |
|
357 | + break; |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 |
@@ -52,33 +52,33 @@ discard block |
||
52 | 52 | case 'list': |
53 | 53 | $blocks = array(); |
54 | 54 | foreach (menu_get_menus() as $name => $title) { |
55 | - $blocks['menu-' . $name] = array( |
|
55 | + $blocks['menu-'.$name] = array( |
|
56 | 56 | 'info' => t('Jump menu: !menu', array('!menu' => $name)) |
57 | 57 | ); |
58 | 58 | } |
59 | 59 | |
60 | 60 | $vocs = taxonomy_get_vocabularies(); |
61 | 61 | foreach ($vocs as $vid => $vocabulary) { |
62 | - $blocks['taxo-' . $vid] = array( |
|
62 | + $blocks['taxo-'.$vid] = array( |
|
63 | 63 | 'info' => t('Jump menu: !voc', array('!voc' => $vocabulary->name)) |
64 | 64 | ); |
65 | 65 | } |
66 | 66 | return $blocks; |
67 | 67 | case 'configure': |
68 | 68 | $form = array(); |
69 | - $form['block_settings']['jump_activepageinmenu_' . $delta] = array( |
|
69 | + $form['block_settings']['jump_activepageinmenu_'.$delta] = array( |
|
70 | 70 | '#type' => 'checkbox', |
71 | 71 | '#title' => t('Show active page in jump menu.'), |
72 | - '#default_value' => variable_get('jump_activepageinmenu_' . $delta, 1), |
|
72 | + '#default_value' => variable_get('jump_activepageinmenu_'.$delta, 1), |
|
73 | 73 | '#description' => t('This setting will force the jump menu to show the current page as the default selection in this block\'s jump menu.'), |
74 | 74 | ); |
75 | 75 | // Do the rest of the form additions in hook_form_alter() since we can't do ahah here. |
76 | 76 | return $form; |
77 | 77 | case 'save': |
78 | - variable_set('jump_activepageinmenu_' . $delta, $edit['jump_activepageinmenu_' . $delta]); |
|
79 | - variable_set('jump_use_js_' . $delta, $edit['jump_use_js_' . $delta]); |
|
80 | - variable_set('jump_add_select_' . $delta, $edit['jump_add_select_' . $delta]); |
|
81 | - variable_set('jump_add_select_text_' . $delta, $edit['jump_add_select_text_' . $delta]); |
|
78 | + variable_set('jump_activepageinmenu_'.$delta, $edit['jump_activepageinmenu_'.$delta]); |
|
79 | + variable_set('jump_use_js_'.$delta, $edit['jump_use_js_'.$delta]); |
|
80 | + variable_set('jump_add_select_'.$delta, $edit['jump_add_select_'.$delta]); |
|
81 | + variable_set('jump_add_select_text_'.$delta, $edit['jump_add_select_text_'.$delta]); |
|
82 | 82 | break; |
83 | 83 | case 'view': |
84 | 84 | // The first 5 characters of $delta should be one of: |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $vocab = taxonomy_vocabulary_load($jumpmenu_name); |
103 | 103 | $subject = $vocab->name; |
104 | 104 | } |
105 | - if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
105 | + if (variable_get('jump_use_js_'.$delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump').'/jump.js'); |
|
106 | 106 | return array('subject' => $subject, 'content' => $form); |
107 | 107 | break; |
108 | 108 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | function jump_quickly($name = 'navigation', $type = 'menu', $active = -1, $override = '') { |
127 | 127 | // Reconstruct the $delta |
128 | - $delta = $type . '-' . $name; |
|
128 | + $delta = $type.'-'.$name; |
|
129 | 129 | if ($active === -1) { |
130 | 130 | $active = variable_get('jump_activepageinmenu', 1); |
131 | 131 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | static $num_jump_forms = 0; |
154 | 154 | $num_jump_forms++; |
155 | 155 | |
156 | - return drupal_get_form('jump_quickly_form_' . $num_jump_forms, $options, $menu_state); |
|
156 | + return drupal_get_form('jump_quickly_form_'.$num_jump_forms, $options, $menu_state); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | '#type' => 'submit', |
189 | 189 | '#value' => t('Go') |
190 | 190 | ); |
191 | - if (variable_get('jump_use_js_' . $menu_state['delta'], 0) === 1) { |
|
191 | + if (variable_get('jump_use_js_'.$menu_state['delta'], 0) === 1) { |
|
192 | 192 | // Give each menu a unique name. |
193 | - $form['#attributes']['name'] = 'jumpquickly' . $menu_state['delta']; |
|
193 | + $form['#attributes']['name'] = 'jumpquickly'.$menu_state['delta']; |
|
194 | 194 | $form['#attributes']['class'] .= ' js-enabled'; |
195 | 195 | // unset($form['submit']); |
196 | - if (variable_get('jump_add_select_' . $menu_state['delta'], 0) === 1) { |
|
196 | + if (variable_get('jump_add_select_'.$menu_state['delta'], 0) === 1) { |
|
197 | 197 | $form['jump_goto']['#attributes']['class'] = 'first-no-jump'; |
198 | 198 | // Add the extra empty select option to the top of the array. |
199 | - $form['jump_goto']['#options'] = array('' => variable_get('jump_add_select_text_' . $menu_state['delta'], t('Select Option'))) + $options; |
|
199 | + $form['jump_goto']['#options'] = array('' => variable_get('jump_add_select_text_'.$menu_state['delta'], t('Select Option'))) + $options; |
|
200 | 200 | $form['jump_goto']['#default_value'] = (array_key_exists($default, $options)) ? $default : ''; |
201 | 201 | } |
202 | 202 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | foreach ($tree as $data) { |
250 | 250 | if (!$data['link']['hidden']) { |
251 | 251 | $href = ($data['link']['href'] == '<front>') ? $front : $data['link']['href']; |
252 | - $href = (isset($data['link']['options']['fragment'])) ? $href . '#' . $data['link']['options']['fragment'] : $href; |
|
252 | + $href = (isset($data['link']['options']['fragment'])) ? $href.'#'.$data['link']['options']['fragment'] : $href; |
|
253 | 253 | $options[$href] = $data['link']['title']; |
254 | 254 | } |
255 | 255 | } |
@@ -313,15 +313,15 @@ discard block |
||
313 | 313 | if ($form['module']['#value'] === 'jump' && function_exists('ahah_helper_register')) { |
314 | 314 | $delta = $form['delta']['#value']; |
315 | 315 | ahah_helper_register($form, $form_state); |
316 | - $default_jump_use_js = (!isset($form_state['storage']['jump_use_js_' . $delta])) ? variable_get('jump_use_js_' . $delta, 0) : $form_state['storage']['jump_use_js_' . $delta]; |
|
317 | - $default_jump_add_select = (!isset($form_state['storage']['jump_add_select_' . $delta])) ? variable_get('jump_add_select_' . $delta, 0) : $form_state['storage']['jump_add_select_' . $delta]; |
|
316 | + $default_jump_use_js = (!isset($form_state['storage']['jump_use_js_'.$delta])) ? variable_get('jump_use_js_'.$delta, 0) : $form_state['storage']['jump_use_js_'.$delta]; |
|
317 | + $default_jump_add_select = (!isset($form_state['storage']['jump_add_select_'.$delta])) ? variable_get('jump_add_select_'.$delta, 0) : $form_state['storage']['jump_add_select_'.$delta]; |
|
318 | 318 | |
319 | 319 | $form['block_settings']['jump_wrapper'] = array( |
320 | 320 | '#prefix' => '<div id="jump-wrapper">', |
321 | 321 | '#suffix' => '</div>', |
322 | 322 | '#type' => 'markup' |
323 | 323 | ); |
324 | - $form['block_settings']['jump_wrapper']['jump_use_js_' . $delta] = array( |
|
324 | + $form['block_settings']['jump_wrapper']['jump_use_js_'.$delta] = array( |
|
325 | 325 | '#type' => 'checkbox', |
326 | 326 | '#title' => t('Hide the submit button and use Javascript to automatically jump to the selected menu item'), |
327 | 327 | '#default_value' => $default_jump_use_js, |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | ), |
334 | 334 | ); |
335 | 335 | if ($default_jump_use_js === 1) { |
336 | - $form['block_settings']['jump_wrapper']['jump_add_select_' . $delta] = array( |
|
336 | + $form['block_settings']['jump_wrapper']['jump_add_select_'.$delta] = array( |
|
337 | 337 | '#type' => 'checkbox', |
338 | 338 | '#title' => t('Add an empty select option into the list of options'), |
339 | 339 | '#default_value' => $default_jump_add_select, |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | ), |
346 | 346 | ); |
347 | 347 | if ($default_jump_add_select === 1) { |
348 | - $form['block_settings']['jump_wrapper']['jump_add_select_text_' . $delta] = array( |
|
348 | + $form['block_settings']['jump_wrapper']['jump_add_select_text_'.$delta] = array( |
|
349 | 349 | '#type' => 'textfield', |
350 | 350 | '#title' => t('Text to use for the empty select option'), |
351 | - '#default_value' => variable_get('jump_add_select_text_' . $delta, t('Select Option')), |
|
351 | + '#default_value' => variable_get('jump_add_select_text_'.$delta, t('Select Option')), |
|
352 | 352 | '#weight' => 2 |
353 | 353 | ); |
354 | 354 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | function jump_get_active_setting($delta) { |
368 | 368 | $active_site_default = variable_get('jump_activepageinmenu', 1); |
369 | - $active = variable_get('jump_activepageinmenu_' . $delta, $active_site_default); |
|
369 | + $active = variable_get('jump_activepageinmenu_'.$delta, $active_site_default); |
|
370 | 370 | return $active; |
371 | 371 | } |
372 | 372 |
@@ -94,15 +94,16 @@ discard block |
||
94 | 94 | // Use the menu label as the default block subject |
95 | 95 | $menus = menu_get_menus(); |
96 | 96 | $subject = $menus[$jumpmenu_name]; |
97 | - } |
|
98 | - else if ($jumpmenu_type == 'taxo') { |
|
97 | + } else if ($jumpmenu_type == 'taxo') { |
|
99 | 98 | $form = jump_quickly($jumpmenu_name, 'taxo', $active); |
100 | 99 | |
101 | 100 | // Use the vocabulary name as the default block subject |
102 | 101 | $vocab = taxonomy_vocabulary_load($jumpmenu_name); |
103 | 102 | $subject = $vocab->name; |
104 | 103 | } |
105 | - if (variable_get('jump_use_js_' . $delta, 0) === 1) drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
104 | + if (variable_get('jump_use_js_' . $delta, 0) === 1) { |
|
105 | + drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
106 | + } |
|
106 | 107 | return array('subject' => $subject, 'content' => $form); |
107 | 108 | break; |
108 | 109 | } |
@@ -137,13 +138,11 @@ discard block |
||
137 | 138 | |
138 | 139 | if (is_array($name)) { |
139 | 140 | $options = $name; |
140 | - } |
|
141 | - else { |
|
141 | + } else { |
|
142 | 142 | $options = array(); |
143 | 143 | if ($type == 'menu') { |
144 | 144 | jump_menu_get_menu_options($options, $name); |
145 | - } |
|
146 | - elseif ($type == 'taxo') { |
|
145 | + } elseif ($type == 'taxo') { |
|
147 | 146 | jump_menu_get_taxo_options($options, $name); |
148 | 147 | } |
149 | 148 | } |
@@ -215,8 +214,7 @@ discard block |
||
215 | 214 | $fragment = explode('#', $form_state['values']['jump_goto']); |
216 | 215 | if (isset($fragment[1])) { |
217 | 216 | drupal_goto($fragment[0], NULL, $fragment[1]); |
218 | - } |
|
219 | - else { |
|
217 | + } else { |
|
220 | 218 | drupal_goto($form_state['values']['jump_goto']); |
221 | 219 | } |
222 | 220 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * messages from. |
375 | 375 | * |
376 | 376 | * @return |
377 | - * TRUE if the user is allowed to block $account, or FALSE if not. |
|
377 | + boolean TRUE if the user is allowed to block $account, or FALSE if not. |
|
378 | 378 | */ |
379 | 379 | function _pm_block_user_access($account) { |
380 | 380 | global $user; |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | * Author user object to check. |
400 | 400 | * @param $recipient |
401 | 401 | * Receiver user object to check. |
402 | - * @param $action |
|
402 | + * @param integer $action |
|
403 | 403 | * The action to be taken, defaults to PM_BLOCK_USER_DISALLOW_BLOCKING. |
404 | 404 | * |
405 | 405 | * @return |
406 | - * TRUE if a rule exists for the combination of author recipient and action. |
|
406 | + boolean TRUE if a rule exists for the combination of author recipient and action. |
|
407 | 407 | */ |
408 | 408 | function _pm_block_user_rule_exists($author, $recipient, $action = PM_BLOCK_USER_DISALLOW_BLOCKING) { |
409 | 409 | $block_actions = variable_get('pm_block_user_actions', array()); |
@@ -19,17 +19,17 @@ discard block |
||
19 | 19 | * Implements hook_help(). |
20 | 20 | */ |
21 | 21 | function pm_block_user_help($path) { |
22 | - switch ($path) { |
|
22 | + switch ($path) { |
|
23 | 23 | case 'admin/settings/messages/block': |
24 | 24 | return '<p>' . t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))) . '</p>'; |
25 | - } |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Implements hook_menu(). |
30 | 30 | */ |
31 | 31 | function pm_block_user_menu() { |
32 | - $items['messages/block/%user'] = array( |
|
32 | + $items['messages/block/%user'] = array( |
|
33 | 33 | 'title' => 'Block user messages', |
34 | 34 | 'page callback' => 'drupal_get_form', |
35 | 35 | 'page arguments' => array('pm_block_user_form', 2), |
@@ -37,61 +37,61 @@ discard block |
||
37 | 37 | 'access arguments' => array(2), |
38 | 38 | 'type' => MENU_CALLBACK, |
39 | 39 | 'weight' => -10, |
40 | - ); |
|
40 | + ); |
|
41 | 41 | |
42 | - $items['admin/settings/messages/block'] = array( |
|
42 | + $items['admin/settings/messages/block'] = array( |
|
43 | 43 | 'title' => 'User blocking rules', |
44 | 44 | 'description' => 'Configure rules for which users may block each other.', |
45 | 45 | 'page callback' => 'drupal_get_form', |
46 | 46 | 'page arguments' => array('pm_block_user_settings'), |
47 | 47 | 'access arguments' => array('administer privatemsg settings'), |
48 | 48 | 'type' => MENU_LOCAL_TASK, |
49 | - ); |
|
49 | + ); |
|
50 | 50 | |
51 | - $items['messages/block/js'] = array( |
|
51 | + $items['messages/block/js'] = array( |
|
52 | 52 | 'title' => 'Javascript block actions form', |
53 | 53 | 'page callback' => 'pm_block_user_js', |
54 | 54 | 'access arguments' => array('administer privatemsg settings'), |
55 | 55 | 'type' => MENU_CALLBACK, |
56 | - ); |
|
56 | + ); |
|
57 | 57 | |
58 | - return $items; |
|
58 | + return $items; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Menu callback for blocked user settings. |
63 | 63 | */ |
64 | 64 | function pm_block_user_settings(&$form_state) { |
65 | - drupal_add_css(drupal_get_path('module', 'pm_block_user') .'/pm_block_user.css'); |
|
66 | - // Need to cache form for AHAH, so it can be rebuilt from cache later. |
|
67 | - $form = array( |
|
65 | + drupal_add_css(drupal_get_path('module', 'pm_block_user') .'/pm_block_user.css'); |
|
66 | + // Need to cache form for AHAH, so it can be rebuilt from cache later. |
|
67 | + $form = array( |
|
68 | 68 | '#cache' => TRUE, |
69 | - ); |
|
69 | + ); |
|
70 | 70 | |
71 | - // Container for just the actions, used for AHAH. |
|
72 | - $form['block_actions'] = array( |
|
71 | + // Container for just the actions, used for AHAH. |
|
72 | + $form['block_actions'] = array( |
|
73 | 73 | '#tree' => TRUE, |
74 | 74 | '#prefix' => '<div id="block-actions">', |
75 | 75 | '#suffix' => '</div>', |
76 | 76 | '#theme' => 'pm_block_user_actions', |
77 | - ); |
|
77 | + ); |
|
78 | 78 | |
79 | - // Should we populate the form with data from $form_state or the database? |
|
80 | - if (!isset($form_state['pm_block_user']['block_actions'])) { |
|
79 | + // Should we populate the form with data from $form_state or the database? |
|
80 | + if (!isset($form_state['pm_block_user']['block_actions'])) { |
|
81 | 81 | $block_actions = variable_get('pm_block_user_actions', array()); |
82 | - } |
|
83 | - else { |
|
82 | + } |
|
83 | + else { |
|
84 | 84 | $block_actions = $form_state['pm_block_user']['block_actions']; |
85 | - } |
|
86 | - // Work through each rule, adding it as a new element in |
|
87 | - // $form['block_actions'] ready to be themed later. |
|
88 | - foreach ($block_actions as $delta => $details) { |
|
85 | + } |
|
86 | + // Work through each rule, adding it as a new element in |
|
87 | + // $form['block_actions'] ready to be themed later. |
|
88 | + foreach ($block_actions as $delta => $details) { |
|
89 | 89 | $details['delta'] = $delta; |
90 | 90 | $form['block_actions'][$delta] = _pm_block_user_actions_form($details); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - // The magic AHAH callback button that adds more rows. |
|
94 | - $form['pm_block_actions_more'] = array( |
|
93 | + // The magic AHAH callback button that adds more rows. |
|
94 | + $form['pm_block_actions_more'] = array( |
|
95 | 95 | '#type' => 'submit', |
96 | 96 | '#value' => t('More'), |
97 | 97 | '#weight' => 1, |
@@ -99,20 +99,20 @@ discard block |
||
99 | 99 | '#suffix' => '<label for="edit-pm-block-actions-more">' . t('Add new rule') . '</label></div>', |
100 | 100 | '#submit' => array('pm_block_user_more_submit'), |
101 | 101 | '#ahah' => array( |
102 | - 'path' => 'messages/block/js', |
|
103 | - 'wrapper' => 'block-actions', |
|
104 | - 'method' => 'replace', |
|
105 | - 'effect' => 'fade', |
|
102 | + 'path' => 'messages/block/js', |
|
103 | + 'wrapper' => 'block-actions', |
|
104 | + 'method' => 'replace', |
|
105 | + 'effect' => 'fade', |
|
106 | 106 | ), |
107 | - ); |
|
107 | + ); |
|
108 | 108 | |
109 | - $form['submit_form'] = array( |
|
109 | + $form['submit_form'] = array( |
|
110 | 110 | '#type' => 'submit', |
111 | 111 | '#weight' => 10, |
112 | 112 | '#value' => t('Save configuration'), |
113 | - ); |
|
113 | + ); |
|
114 | 114 | |
115 | - return $form; |
|
115 | + return $form; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -132,50 +132,50 @@ discard block |
||
132 | 132 | * Part of a form with controls for sending, receiving and actions. |
133 | 133 | */ |
134 | 134 | function _pm_block_user_actions_form($details, $blacklist = TRUE) { |
135 | - $form = array( |
|
135 | + $form = array( |
|
136 | 136 | '#tree' => TRUE, |
137 | - ); |
|
138 | - $delta = $details['delta']; |
|
139 | - // FALSE by default, or if the user has checked the 'Enabled' check box for |
|
140 | - // this row. |
|
141 | - $row_disabled = (isset($details['enabled']) ? !$details['enabled'] : FALSE); |
|
137 | + ); |
|
138 | + $delta = $details['delta']; |
|
139 | + // FALSE by default, or if the user has checked the 'Enabled' check box for |
|
140 | + // this row. |
|
141 | + $row_disabled = (isset($details['enabled']) ? !$details['enabled'] : FALSE); |
|
142 | 142 | |
143 | - $form['author'] = array( |
|
143 | + $form['author'] = array( |
|
144 | 144 | '#type' => 'select', |
145 | 145 | '#options' => user_roles(TRUE), |
146 | 146 | '#default_value' => (isset($details['author']) ? $details['author'] : DRUPAL_AUTHENTICATED_RID), |
147 | 147 | '#disabled' => $row_disabled, |
148 | - ); |
|
149 | - $form['recipient'] = array( |
|
148 | + ); |
|
149 | + $form['recipient'] = array( |
|
150 | 150 | '#type' => 'select', |
151 | 151 | '#options' => user_roles(TRUE), |
152 | 152 | '#default_value' => (isset($details['recipient']) ? $details['recipient'] : DRUPAL_AUTHENTICATED_RID), |
153 | 153 | '#disabled' => $row_disabled, |
154 | - ); |
|
154 | + ); |
|
155 | 155 | |
156 | - // Provide different action radios if we're using a whitelist or a blacklist. |
|
157 | - if ($blacklist) { |
|
156 | + // Provide different action radios if we're using a whitelist or a blacklist. |
|
157 | + if ($blacklist) { |
|
158 | 158 | $options = array( |
159 | - PM_BLOCK_USER_DISALLOW_BLOCKING => t('Disallow blocking author'), |
|
160 | - PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'), |
|
159 | + PM_BLOCK_USER_DISALLOW_BLOCKING => t('Disallow blocking author'), |
|
160 | + PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'), |
|
161 | 161 | ); |
162 | 162 | $default_value = (isset($details['action']) ? $details['action'] : PM_BLOCK_USER_DISALLOW_BLOCKING); |
163 | - } |
|
164 | - else { |
|
163 | + } |
|
164 | + else { |
|
165 | 165 | // @todo: add whitelist options/default_value here. |
166 | - } |
|
167 | - $form['action'] = array( |
|
166 | + } |
|
167 | + $form['action'] = array( |
|
168 | 168 | '#type' => 'radios', |
169 | 169 | '#options' => $options, |
170 | 170 | '#disabled' => $row_disabled, |
171 | 171 | '#default_value' => $default_value, |
172 | - ); |
|
172 | + ); |
|
173 | 173 | |
174 | - $form['enabled'] = array( |
|
174 | + $form['enabled'] = array( |
|
175 | 175 | '#type' => 'checkbox', |
176 | 176 | '#default_value' => (isset($details['enabled']) ? $details['enabled'] : TRUE), |
177 | - ); |
|
178 | - $form['remove'] = array( |
|
177 | + ); |
|
178 | + $form['remove'] = array( |
|
179 | 179 | '#type' => 'submit', |
180 | 180 | '#submit' => array('pm_block_user_remove_submit'), |
181 | 181 | '#value' => t('Remove'), |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | '#prefix' => '<div id="remove-rule-button">', |
184 | 184 | '#suffix' => '<label for="edit-remove">' . t('Remove rule') . '</label></div>', |
185 | 185 | '#ahah' => array( |
186 | - 'path' => 'messages/block/js', |
|
187 | - 'wrapper' => 'block-actions', |
|
188 | - 'method' => 'replace', |
|
189 | - 'effect' => 'fade', |
|
186 | + 'path' => 'messages/block/js', |
|
187 | + 'wrapper' => 'block-actions', |
|
188 | + 'method' => 'replace', |
|
189 | + 'effect' => 'fade', |
|
190 | 190 | ), |
191 | - ); |
|
191 | + ); |
|
192 | 192 | |
193 | - return $form; |
|
193 | + return $form; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * @see pm_block_user_remove_submit() |
200 | 200 | */ |
201 | 201 | function pm_block_user_more_submit($form, &$form_state) { |
202 | - unset($form_state['submit_handlers']); |
|
203 | - form_execute_handlers('submit', $form, $form_state); |
|
204 | - // Get the submitted actions, then put them into a special area of |
|
205 | - // the $form_state. |
|
206 | - $submitted_values = $form_state['values']; |
|
207 | - // Add an empty action. |
|
208 | - $submitted_values['block_actions'][] = array(); |
|
209 | - $form_state['pm_block_user'] = $submitted_values; |
|
210 | - // Rebuild the form by passing our $form_state through the |
|
211 | - // pm_block_user_settings() builder function. |
|
212 | - $form_state['rebuild'] = TRUE; |
|
202 | + unset($form_state['submit_handlers']); |
|
203 | + form_execute_handlers('submit', $form, $form_state); |
|
204 | + // Get the submitted actions, then put them into a special area of |
|
205 | + // the $form_state. |
|
206 | + $submitted_values = $form_state['values']; |
|
207 | + // Add an empty action. |
|
208 | + $submitted_values['block_actions'][] = array(); |
|
209 | + $form_state['pm_block_user'] = $submitted_values; |
|
210 | + // Rebuild the form by passing our $form_state through the |
|
211 | + // pm_block_user_settings() builder function. |
|
212 | + $form_state['rebuild'] = TRUE; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -218,33 +218,33 @@ discard block |
||
218 | 218 | * @see pm_block_user_more_submit() |
219 | 219 | */ |
220 | 220 | function pm_block_user_remove_submit($form, &$form_state) { |
221 | - unset($form_state['submit_handlers']); |
|
222 | - form_execute_handlers('submit', $form, $form_state); |
|
223 | - $submitted_values = $form_state['values']; |
|
224 | - // Remove the requested action. |
|
225 | - $delta = $form_state['clicked_button']['#parents'][1]; |
|
226 | - unset($submitted_values['block_actions'][$delta]); |
|
227 | - $form_state['pm_block_user'] = $submitted_values; |
|
228 | - $form_state['rebuild'] = TRUE; |
|
221 | + unset($form_state['submit_handlers']); |
|
222 | + form_execute_handlers('submit', $form, $form_state); |
|
223 | + $submitted_values = $form_state['values']; |
|
224 | + // Remove the requested action. |
|
225 | + $delta = $form_state['clicked_button']['#parents'][1]; |
|
226 | + unset($submitted_values['block_actions'][$delta]); |
|
227 | + $form_state['pm_block_user'] = $submitted_values; |
|
228 | + $form_state['rebuild'] = TRUE; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | 232 | * Submit handler for admin form. |
233 | 233 | */ |
234 | 234 | function pm_block_user_settings_submit($form, &$form_state) { |
235 | - // We don't want it to submit when we're adding/removing actions. |
|
236 | - if ($form_state['clicked_button']['#id'] == 'edit-submit-form') { |
|
235 | + // We don't want it to submit when we're adding/removing actions. |
|
236 | + if ($form_state['clicked_button']['#id'] == 'edit-submit-form') { |
|
237 | 237 | // If the form's 'block_actions' aren't set, the user has deleted all the |
238 | 238 | // rows in the table, so we save an empty array to stop errors in the form |
239 | 239 | // builder. |
240 | 240 | if (isset($form_state['values']['block_actions'])) { |
241 | - variable_set('pm_block_user_actions', _pm_block_user_settings_filter($form_state['values']['block_actions'])); |
|
241 | + variable_set('pm_block_user_actions', _pm_block_user_settings_filter($form_state['values']['block_actions'])); |
|
242 | 242 | } |
243 | 243 | else { |
244 | - variable_set('pm_block_user_actions', array()); |
|
244 | + variable_set('pm_block_user_actions', array()); |
|
245 | 245 | } |
246 | 246 | drupal_set_message(t('The configuration options have been saved.')); |
247 | - } |
|
247 | + } |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -259,60 +259,60 @@ discard block |
||
259 | 259 | * @see pm_block_user_settings_submit() |
260 | 260 | */ |
261 | 261 | function _pm_block_user_settings_filter($settings) { |
262 | - // Add-in the names of any settings to be saved into the array below. |
|
263 | - $save_keys = array('author', 'recipient', 'action', 'enabled'); |
|
264 | - $matching = array(); |
|
265 | - // Run through each of the keys we want to save, creating a new array. |
|
266 | - // It's not possible to simply check for unwanted values and unset() them as |
|
267 | - // the array is multi-dimensional. |
|
268 | - foreach ($save_keys as $save_key) { |
|
262 | + // Add-in the names of any settings to be saved into the array below. |
|
263 | + $save_keys = array('author', 'recipient', 'action', 'enabled'); |
|
264 | + $matching = array(); |
|
265 | + // Run through each of the keys we want to save, creating a new array. |
|
266 | + // It's not possible to simply check for unwanted values and unset() them as |
|
267 | + // the array is multi-dimensional. |
|
268 | + foreach ($save_keys as $save_key) { |
|
269 | 269 | if (isset($settings[$save_key])) { |
270 | - $matching[$save_key] = $settings[$save_key]; |
|
270 | + $matching[$save_key] = $settings[$save_key]; |
|
271 | + } |
|
271 | 272 | } |
272 | - } |
|
273 | - if (count($matching) > 0) { |
|
273 | + if (count($matching) > 0) { |
|
274 | 274 | return $matching; |
275 | - } |
|
276 | - else { |
|
275 | + } |
|
276 | + else { |
|
277 | 277 | return array_map('_pm_block_user_settings_filter', $settings); |
278 | - } |
|
278 | + } |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Menu callback for AHAH handling. |
283 | 283 | */ |
284 | 284 | function pm_block_user_js() { |
285 | - // See: http://drupal.org/node/331941 for the philosophy of Drupal AHAH. |
|
286 | - $form_state = array('storage' => NULL, 'submitted' => FALSE); |
|
287 | - $form_build_id = $_POST['form_build_id']; |
|
288 | - $form = form_get_cache($form_build_id, $form_state); |
|
289 | - $args = $form['#parameters']; |
|
290 | - $form_id = array_shift($args); |
|
291 | - $form['#post'] = $_POST; |
|
292 | - $form['#redirect'] = FALSE; |
|
293 | - $form['#programmed'] = FALSE; |
|
294 | - $form_state['post'] = $_POST; |
|
295 | - drupal_process_form($form_id, $form, $form_state); |
|
296 | - $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); |
|
297 | - $output_form = $form['block_actions']; |
|
298 | - unset($output_form['#prefix'], $output_form['#suffix']); // Prevent duplicate wrappers. |
|
299 | - $output = theme('status_messages') . drupal_render($output_form); |
|
300 | - |
|
301 | - // Hack to make behaviours attach to new HTML controls (delete buttons in |
|
302 | - // this case). |
|
303 | - $javascript = drupal_add_js(NULL, NULL, 'header'); |
|
304 | - drupal_json(array('status' => TRUE, 'data' => $output)); |
|
285 | + // See: http://drupal.org/node/331941 for the philosophy of Drupal AHAH. |
|
286 | + $form_state = array('storage' => NULL, 'submitted' => FALSE); |
|
287 | + $form_build_id = $_POST['form_build_id']; |
|
288 | + $form = form_get_cache($form_build_id, $form_state); |
|
289 | + $args = $form['#parameters']; |
|
290 | + $form_id = array_shift($args); |
|
291 | + $form['#post'] = $_POST; |
|
292 | + $form['#redirect'] = FALSE; |
|
293 | + $form['#programmed'] = FALSE; |
|
294 | + $form_state['post'] = $_POST; |
|
295 | + drupal_process_form($form_id, $form, $form_state); |
|
296 | + $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); |
|
297 | + $output_form = $form['block_actions']; |
|
298 | + unset($output_form['#prefix'], $output_form['#suffix']); // Prevent duplicate wrappers. |
|
299 | + $output = theme('status_messages') . drupal_render($output_form); |
|
300 | + |
|
301 | + // Hack to make behaviours attach to new HTML controls (delete buttons in |
|
302 | + // this case). |
|
303 | + $javascript = drupal_add_js(NULL, NULL, 'header'); |
|
304 | + drupal_json(array('status' => TRUE, 'data' => $output)); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Implements hook_theme(). |
309 | 309 | */ |
310 | 310 | function pm_block_user_theme() { |
311 | - return array( |
|
311 | + return array( |
|
312 | 312 | 'pm_block_user_actions' => array( |
313 | - 'arguments' => array('form' => NULL), |
|
313 | + 'arguments' => array('form' => NULL), |
|
314 | 314 | ), |
315 | - ); |
|
315 | + ); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -321,49 +321,49 @@ discard block |
||
321 | 321 | * @ingroup themeable |
322 | 322 | */ |
323 | 323 | function theme_pm_block_user_actions($form) { |
324 | - $rows = array(); |
|
325 | - $headers = array( |
|
324 | + $rows = array(); |
|
325 | + $headers = array( |
|
326 | 326 | t('If the author has the role'), |
327 | 327 | t('And the recipient has the role'), |
328 | 328 | t('Action'), |
329 | 329 | t('Enabled'), |
330 | 330 | '', |
331 | - ); |
|
332 | - $form_data = element_children($form); |
|
331 | + ); |
|
332 | + $form_data = element_children($form); |
|
333 | 333 | |
334 | - foreach ($form_data as $key) { |
|
334 | + foreach ($form_data as $key) { |
|
335 | 335 | // Build the table row. |
336 | 336 | $row = array( |
337 | - 'data' => array( |
|
337 | + 'data' => array( |
|
338 | 338 | array('data' => drupal_render($form[$key]['author'])), |
339 | 339 | array('data' => drupal_render($form[$key]['recipient'])), |
340 | 340 | array('data' => drupal_render($form[$key]['action'])), |
341 | 341 | array('data' => drupal_render($form[$key]['enabled'])), |
342 | 342 | array('data' => drupal_render($form[$key]['remove'])), |
343 | - ), |
|
343 | + ), |
|
344 | 344 | ); |
345 | 345 | |
346 | 346 | // Add additional attributes to the row, such as a class for this row. |
347 | 347 | if (isset($form[$key]['#attributes'])) { |
348 | - $row = array_merge($row, $form[$key]['#attributes']); |
|
348 | + $row = array_merge($row, $form[$key]['#attributes']); |
|
349 | 349 | } |
350 | 350 | $rows[] = $row; |
351 | - } |
|
351 | + } |
|
352 | 352 | |
353 | - // If there are no rows, output some instructions for the user. |
|
354 | - if (empty($form_data)) { |
|
353 | + // If there are no rows, output some instructions for the user. |
|
354 | + if (empty($form_data)) { |
|
355 | 355 | $rows[] = array( |
356 | - array( |
|
356 | + array( |
|
357 | 357 | 'data' => t("No rules have been added. All users may block private messages from each other. To limit which users may be blocked, click 'Add new rule'."), |
358 | 358 | 'colspan' => '5', |
359 | - ), |
|
359 | + ), |
|
360 | 360 | ); |
361 | - } |
|
361 | + } |
|
362 | 362 | |
363 | - $output = theme('table', $headers, $rows); |
|
364 | - $output .= drupal_render($form); |
|
363 | + $output = theme('table', $headers, $rows); |
|
364 | + $output .= drupal_render($form); |
|
365 | 365 | |
366 | - return $output; |
|
366 | + return $output; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | * TRUE if the user is allowed to block $account, or FALSE if not. |
378 | 378 | */ |
379 | 379 | function _pm_block_user_access($account) { |
380 | - global $user; |
|
381 | - if (!privatemsg_user_access('read privatemsg', $user)) { |
|
380 | + global $user; |
|
381 | + if (!privatemsg_user_access('read privatemsg', $user)) { |
|
382 | 382 | return FALSE; |
383 | - } |
|
384 | - if (_pm_block_user_rule_exists($account, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) { |
|
383 | + } |
|
384 | + if (_pm_block_user_rule_exists($account, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) { |
|
385 | 385 | return FALSE; |
386 | - } |
|
387 | - return TRUE; |
|
386 | + } |
|
387 | + return TRUE; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -406,179 +406,179 @@ discard block |
||
406 | 406 | * TRUE if a rule exists for the combination of author recipient and action. |
407 | 407 | */ |
408 | 408 | function _pm_block_user_rule_exists($author, $recipient, $action = PM_BLOCK_USER_DISALLOW_BLOCKING) { |
409 | - $block_actions = variable_get('pm_block_user_actions', array()); |
|
410 | - foreach ($block_actions as $delta => $details) { |
|
409 | + $block_actions = variable_get('pm_block_user_actions', array()); |
|
410 | + foreach ($block_actions as $delta => $details) { |
|
411 | 411 | // If this rule doesn't relate to $action, or it's disabled |
412 | 412 | // ignore it and go to next loop iteration. |
413 | 413 | if ($details['action'] != $action || !$details['enabled']) { |
414 | - continue; |
|
414 | + continue; |
|
415 | 415 | } |
416 | 416 | // There are no rules governing user one, but user one may have roles that |
417 | 417 | // affect other users, so these exceptions are narrow in scope. |
418 | 418 | // Disallow sending affects private message authors. |
419 | 419 | if ($author->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_SENDING) { |
420 | - continue; |
|
420 | + continue; |
|
421 | 421 | } |
422 | 422 | // Disallow blocking affects private message recipients. |
423 | 423 | if ($recipient->uid == 1 && $action == PM_BLOCK_USER_DISALLOW_BLOCKING) { |
424 | - continue; |
|
424 | + continue; |
|
425 | 425 | } |
426 | 426 | // The author has a role matching the rule and so does the recipient. |
427 | 427 | if (isset($author->roles[$details['author']]) && isset($recipient->roles[$details['recipient']])) { |
428 | - return TRUE; |
|
428 | + return TRUE; |
|
429 | + } |
|
429 | 430 | } |
430 | - } |
|
431 | - return FALSE; |
|
431 | + return FALSE; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | function pm_block_user_form($form_state, $author) { |
435 | - global $user; |
|
435 | + global $user; |
|
436 | 436 | |
437 | - $form['author'] = array( |
|
437 | + $form['author'] = array( |
|
438 | 438 | '#type' => 'value', |
439 | 439 | '#value' => $author->uid, |
440 | - ); |
|
440 | + ); |
|
441 | 441 | $form['recipient'] = array( |
442 | 442 | '#type' => 'value', |
443 | 443 | '#value' => $user->uid, |
444 | - ); |
|
445 | - $form['author_name'] = array( |
|
444 | + ); |
|
445 | + $form['author_name'] = array( |
|
446 | 446 | '#type' => 'value', |
447 | 447 | '#value' => $author->name, |
448 | - ); |
|
449 | - $form['destination'] = array( |
|
448 | + ); |
|
449 | + $form['destination'] = array( |
|
450 | 450 | '#type' => 'value', |
451 | 451 | '#value' => isset($_GET['destination']) ? $_GET['destination'] : 'messages/', |
452 | - ); |
|
452 | + ); |
|
453 | 453 | |
454 | - if (db_result(db_query('SELECT COUNT(recipient) FROM {pm_block_user} WHERE author = %d AND recipient = %d', $author->uid, $user->uid))) { |
|
454 | + if (db_result(db_query('SELECT COUNT(recipient) FROM {pm_block_user} WHERE author = %d AND recipient = %d', $author->uid, $user->uid))) { |
|
455 | 455 | $form['block_action'] = array( |
456 | - '#type' => 'value', |
|
457 | - '#value' => 'unblock_user', |
|
456 | + '#type' => 'value', |
|
457 | + '#value' => 'unblock_user', |
|
458 | 458 | ); |
459 | 459 | return confirm_form($form, |
460 | - t('You have previously blocked "@author" from sending you any more messages. Are you sure you want to unblock this user?', array('@author' => $author->name)), |
|
461 | - isset($_GET['destination']) ? $_GET['destination'] : 'messages/', |
|
462 | - t('This action cannot be undone.'), |
|
463 | - t('Unblock @author', array('@author' => $author->name)), |
|
464 | - t('Cancel') |
|
460 | + t('You have previously blocked "@author" from sending you any more messages. Are you sure you want to unblock this user?', array('@author' => $author->name)), |
|
461 | + isset($_GET['destination']) ? $_GET['destination'] : 'messages/', |
|
462 | + t('This action cannot be undone.'), |
|
463 | + t('Unblock @author', array('@author' => $author->name)), |
|
464 | + t('Cancel') |
|
465 | 465 | ); |
466 | - } |
|
467 | - else { |
|
466 | + } |
|
467 | + else { |
|
468 | 468 | $form['block_action'] = array( |
469 | - '#type' => 'value', |
|
470 | - '#value' => 'block_user', |
|
469 | + '#type' => 'value', |
|
470 | + '#value' => 'block_user', |
|
471 | 471 | ); |
472 | 472 | return confirm_form($form, |
473 | - t('Are you sure you want to block "@author" from sending you any more messages?', array('@author' => $author->name)), |
|
474 | - isset($_GET['destination']) ? $_GET['destination'] : 'messages/', |
|
475 | - '', |
|
476 | - t('Block @author', array('@author' => $author->name)), |
|
477 | - t('Cancel') |
|
473 | + t('Are you sure you want to block "@author" from sending you any more messages?', array('@author' => $author->name)), |
|
474 | + isset($_GET['destination']) ? $_GET['destination'] : 'messages/', |
|
475 | + '', |
|
476 | + t('Block @author', array('@author' => $author->name)), |
|
477 | + t('Cancel') |
|
478 | 478 | ); |
479 | - } |
|
479 | + } |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
483 | 483 | * Implements hook_form_submit(). |
484 | 484 | */ |
485 | 485 | function pm_block_user_form_submit($form, &$form_state) { |
486 | - if ($form_state['values']['confirm']) { |
|
486 | + if ($form_state['values']['confirm']) { |
|
487 | 487 | switch ($form_state['values']['block_action']) { |
488 | - case 'block_user': |
|
488 | + case 'block_user': |
|
489 | 489 | db_query('INSERT INTO {pm_block_user} (author, recipient) VALUES (%d, %d)', $form_state['values']['author'], $form_state['values']['recipient']); |
490 | 490 | drupal_set_message(t('@author has been blocked from sending you any further messages.', array('@author' => $form_state['values']['author_name']))); |
491 | - break; |
|
492 | - case 'unblock_user': |
|
491 | + break; |
|
492 | + case 'unblock_user': |
|
493 | 493 | db_query('DELETE FROM {pm_block_user} WHERE author = %d AND recipient = %d', $form_state['values']['author'], $form_state['values']['recipient']); |
494 | 494 | drupal_set_message(t('@author is now allowed to send you new messages.', array('@author' => $form_state['values']['author_name']))); |
495 | - break; |
|
495 | + break; |
|
496 | + } |
|
496 | 497 | } |
497 | - } |
|
498 | - $form_state['redirect'] = $form_state['values']['destination']; |
|
498 | + $form_state['redirect'] = $form_state['values']['destination']; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
502 | 502 | * Implements hook_privatemsg_block_message(). |
503 | 503 | */ |
504 | 504 | function pm_block_user_privatemsg_block_message($author, $recipients) { |
505 | - $blocked = array(); |
|
506 | - // Loop through each recipient and ensure there is no rule blocking this |
|
507 | - // author from sending them private messages. Use a reference, so when |
|
508 | - // user_load() is needed here the array is updated, negating the need for |
|
509 | - // further calls to user_load() later in the code. |
|
510 | - foreach (array_keys($recipients) as $uid) { |
|
505 | + $blocked = array(); |
|
506 | + // Loop through each recipient and ensure there is no rule blocking this |
|
507 | + // author from sending them private messages. Use a reference, so when |
|
508 | + // user_load() is needed here the array is updated, negating the need for |
|
509 | + // further calls to user_load() later in the code. |
|
510 | + foreach (array_keys($recipients) as $uid) { |
|
511 | 511 | |
512 | 512 | // Ensure we have a recipient user object which includes roles. |
513 | 513 | if (!isset($recipients[$uid]->roles)) { |
514 | - $recipients[$uid] = user_load($uid); |
|
514 | + $recipients[$uid] = user_load($uid); |
|
515 | 515 | } |
516 | 516 | // Note: this is checks whether the author may send the message (see third |
517 | 517 | // parameter). Further below is a check whether the recipient may block it. |
518 | 518 | if (_pm_block_user_rule_exists($author, $recipients[$uid], PM_BLOCK_USER_DISALLOW_SENDING)) { |
519 | - $blocked[] = array( |
|
519 | + $blocked[] = array( |
|
520 | 520 | 'uid' => $uid, |
521 | 521 | 'message' => t('Sorry, private messaging rules forbid sending messages to !name.', array('!name' => $recipients[$uid]->name)), |
522 | - ); |
|
522 | + ); |
|
523 | + } |
|
523 | 524 | } |
524 | - } |
|
525 | 525 | |
526 | - $args = array_merge(array($author->uid), array_keys($recipients)); |
|
527 | - $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('. db_placeholders($recipients) .') GROUP BY recipient', $args); |
|
528 | - while ($row = db_fetch_array($result)) { |
|
526 | + $args = array_merge(array($author->uid), array_keys($recipients)); |
|
527 | + $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('. db_placeholders($recipients) .') GROUP BY recipient', $args); |
|
528 | + while ($row = db_fetch_array($result)) { |
|
529 | 529 | $recipient = $recipients[$row['recipient']]; |
530 | 530 | // If there's a rule disallowing blocking of this message, send it anyway. |
531 | 531 | if (_pm_block_user_rule_exists($author, $recipient, PM_BLOCK_USER_DISALLOW_BLOCKING)) { |
532 | - continue; |
|
532 | + continue; |
|
533 | 533 | } |
534 | 534 | $blocked[] = array( |
535 | - 'uid' => $row['recipient'], |
|
536 | - 'message' => t('%name has chosen to not recieve any more messages from you.', array('%name' => $recipients[$row['recipient']]->name)) |
|
535 | + 'uid' => $row['recipient'], |
|
536 | + 'message' => t('%name has chosen to not recieve any more messages from you.', array('%name' => $recipients[$row['recipient']]->name)) |
|
537 | 537 | ); |
538 | - } |
|
539 | - return $blocked; |
|
538 | + } |
|
539 | + return $blocked; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | function pm_block_user_privatemsg_sql_load_alter(&$fragments, $pmid, $uid) { |
543 | - $fragments['select'][] = 'pmbu.recipient AS is_blocked'; |
|
543 | + $fragments['select'][] = 'pmbu.recipient AS is_blocked'; |
|
544 | 544 | |
545 | - $fragments['inner_join'][] = 'LEFT JOIN {pm_block_user} pmbu ON (pm.author = pmbu.author AND pmi.uid = pmbu.recipient)'; |
|
545 | + $fragments['inner_join'][] = 'LEFT JOIN {pm_block_user} pmbu ON (pm.author = pmbu.author AND pmi.uid = pmbu.recipient)'; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
549 | 549 | * Implements hook_privatemsg_message_view_alter(). |
550 | 550 | */ |
551 | 551 | function pm_block_user_privatemsg_message_view_alter(&$vars) { |
552 | - global $user; |
|
552 | + global $user; |
|
553 | 553 | |
554 | - $author = $vars['message']['author']; |
|
555 | - if (_pm_block_user_rule_exists($author, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) { |
|
554 | + $author = $vars['message']['author']; |
|
555 | + if (_pm_block_user_rule_exists($author, $user, PM_BLOCK_USER_DISALLOW_BLOCKING)) { |
|
556 | 556 | return; |
557 | - } |
|
558 | - if (!isset($vars['message']['thread_id'])) { |
|
557 | + } |
|
558 | + if (!isset($vars['message']['thread_id'])) { |
|
559 | 559 | // No thread id, this is probably only a preview |
560 | 560 | return; |
561 | - } |
|
562 | - $thread_id = $vars['message']['thread_id']; |
|
561 | + } |
|
562 | + $thread_id = $vars['message']['thread_id']; |
|
563 | 563 | |
564 | - if ($user->uid <> $author->uid) { |
|
564 | + if ($user->uid <> $author->uid) { |
|
565 | 565 | if ($vars['message']['is_blocked']) { |
566 | - $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
566 | + $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
567 | 567 | } |
568 | 568 | else { |
569 | - $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
569 | + $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
570 | + } |
|
570 | 571 | } |
571 | - } |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
575 | 575 | * Implement hook_user(). |
576 | 576 | */ |
577 | 577 | function pm_block_user_user($op, &$edit, &$account, $category = NULL) { |
578 | - switch ($op) { |
|
579 | - case 'delete': |
|
578 | + switch ($op) { |
|
579 | + case 'delete': |
|
580 | 580 | // Delete blocking rules which involve this user. |
581 | 581 | db_query("DELETE FROM {pm_block_user} WHERE author = %d OR recipient = %d", $account->uid, $account->uid); |
582 | - break; |
|
583 | - } |
|
582 | + break; |
|
583 | + } |
|
584 | 584 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function pm_block_user_help($path) { |
22 | 22 | switch ($path) { |
23 | - case 'admin/settings/messages/block': |
|
24 | - return '<p>' . t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))) . '</p>'; |
|
23 | + case 'admin/settings/messages/block': |
|
24 | + return '<p>' . t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))) . '</p>'; |
|
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
@@ -485,14 +485,14 @@ discard block |
||
485 | 485 | function pm_block_user_form_submit($form, &$form_state) { |
486 | 486 | if ($form_state['values']['confirm']) { |
487 | 487 | switch ($form_state['values']['block_action']) { |
488 | - case 'block_user': |
|
489 | - db_query('INSERT INTO {pm_block_user} (author, recipient) VALUES (%d, %d)', $form_state['values']['author'], $form_state['values']['recipient']); |
|
490 | - drupal_set_message(t('@author has been blocked from sending you any further messages.', array('@author' => $form_state['values']['author_name']))); |
|
491 | - break; |
|
492 | - case 'unblock_user': |
|
493 | - db_query('DELETE FROM {pm_block_user} WHERE author = %d AND recipient = %d', $form_state['values']['author'], $form_state['values']['recipient']); |
|
494 | - drupal_set_message(t('@author is now allowed to send you new messages.', array('@author' => $form_state['values']['author_name']))); |
|
495 | - break; |
|
488 | + case 'block_user': |
|
489 | + db_query('INSERT INTO {pm_block_user} (author, recipient) VALUES (%d, %d)', $form_state['values']['author'], $form_state['values']['recipient']); |
|
490 | + drupal_set_message(t('@author has been blocked from sending you any further messages.', array('@author' => $form_state['values']['author_name']))); |
|
491 | + break; |
|
492 | + case 'unblock_user': |
|
493 | + db_query('DELETE FROM {pm_block_user} WHERE author = %d AND recipient = %d', $form_state['values']['author'], $form_state['values']['recipient']); |
|
494 | + drupal_set_message(t('@author is now allowed to send you new messages.', array('@author' => $form_state['values']['author_name']))); |
|
495 | + break; |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | $form_state['redirect'] = $form_state['values']['destination']; |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | */ |
577 | 577 | function pm_block_user_user($op, &$edit, &$account, $category = NULL) { |
578 | 578 | switch ($op) { |
579 | - case 'delete': |
|
580 | - // Delete blocking rules which involve this user. |
|
581 | - db_query("DELETE FROM {pm_block_user} WHERE author = %d OR recipient = %d", $account->uid, $account->uid); |
|
582 | - break; |
|
579 | + case 'delete': |
|
580 | + // Delete blocking rules which involve this user. |
|
581 | + db_query("DELETE FROM {pm_block_user} WHERE author = %d OR recipient = %d", $account->uid, $account->uid); |
|
582 | + break; |
|
583 | 583 | } |
584 | 584 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | function pm_block_user_help($path) { |
22 | 22 | switch ($path) { |
23 | 23 | case 'admin/settings/messages/block': |
24 | - return '<p>' . t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))) . '</p>'; |
|
24 | + return '<p>'.t('This area is used to define user blocking rules for the Privatemsg module. Rules allow control of who may block messages from whom. By default all users are allowed to block messages from anyone else. However, a site may have groups of users that need to contact or get information to others, for example: the site may have administrative staff or be a forum with moderators. Groups of users are defined by roles, which can be managed on the <a href="@roles">roles configuration page</a>.', array('@roles' => url('admin/user/roles'))).'</p>'; |
|
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * Menu callback for blocked user settings. |
63 | 63 | */ |
64 | 64 | function pm_block_user_settings(&$form_state) { |
65 | - drupal_add_css(drupal_get_path('module', 'pm_block_user') .'/pm_block_user.css'); |
|
65 | + drupal_add_css(drupal_get_path('module', 'pm_block_user').'/pm_block_user.css'); |
|
66 | 66 | // Need to cache form for AHAH, so it can be rebuilt from cache later. |
67 | 67 | $form = array( |
68 | 68 | '#cache' => TRUE, |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | '#value' => t('More'), |
97 | 97 | '#weight' => 1, |
98 | 98 | '#prefix' => '<div id="add-rule-button">', |
99 | - '#suffix' => '<label for="edit-pm-block-actions-more">' . t('Add new rule') . '</label></div>', |
|
99 | + '#suffix' => '<label for="edit-pm-block-actions-more">'.t('Add new rule').'</label></div>', |
|
100 | 100 | '#submit' => array('pm_block_user_more_submit'), |
101 | 101 | '#ahah' => array( |
102 | 102 | 'path' => 'messages/block/js', |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | else { |
165 | 165 | // @todo: add whitelist options/default_value here. |
166 | 166 | } |
167 | - $form['action'] = array( |
|
167 | + $form['action'] = array( |
|
168 | 168 | '#type' => 'radios', |
169 | 169 | '#options' => $options, |
170 | 170 | '#disabled' => $row_disabled, |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | '#value' => t('Remove'), |
182 | 182 | '#attributes' => array('class' => 'remove-action'), |
183 | 183 | '#prefix' => '<div id="remove-rule-button">', |
184 | - '#suffix' => '<label for="edit-remove">' . t('Remove rule') . '</label></div>', |
|
184 | + '#suffix' => '<label for="edit-remove">'.t('Remove rule').'</label></div>', |
|
185 | 185 | '#ahah' => array( |
186 | 186 | 'path' => 'messages/block/js', |
187 | 187 | 'wrapper' => 'block-actions', |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); |
297 | 297 | $output_form = $form['block_actions']; |
298 | 298 | unset($output_form['#prefix'], $output_form['#suffix']); // Prevent duplicate wrappers. |
299 | - $output = theme('status_messages') . drupal_render($output_form); |
|
299 | + $output = theme('status_messages').drupal_render($output_form); |
|
300 | 300 | |
301 | 301 | // Hack to make behaviours attach to new HTML controls (delete buttons in |
302 | 302 | // this case). |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | $args = array_merge(array($author->uid), array_keys($recipients)); |
527 | - $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('. db_placeholders($recipients) .') GROUP BY recipient', $args); |
|
527 | + $result = db_query('SELECT recipient FROM {pm_block_user} WHERE author = %d AND recipient IN ('.db_placeholders($recipients).') GROUP BY recipient', $args); |
|
528 | 528 | while ($row = db_fetch_array($result)) { |
529 | 529 | $recipient = $recipients[$row['recipient']]; |
530 | 530 | // If there's a rule disallowing blocking of this message, send it anyway. |
@@ -563,10 +563,10 @@ discard block |
||
563 | 563 | |
564 | 564 | if ($user->uid <> $author->uid) { |
565 | 565 | if ($vars['message']['is_blocked']) { |
566 | - $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
566 | + $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'.$author->uid, 'query' => 'destination=messages/view/'.$thread_id); |
|
567 | 567 | } |
568 | 568 | else { |
569 | - $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
|
569 | + $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'.$author->uid, 'query' => 'destination=messages/view/'.$thread_id); |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | } |
@@ -79,8 +79,7 @@ discard block |
||
79 | 79 | // Should we populate the form with data from $form_state or the database? |
80 | 80 | if (!isset($form_state['pm_block_user']['block_actions'])) { |
81 | 81 | $block_actions = variable_get('pm_block_user_actions', array()); |
82 | - } |
|
83 | - else { |
|
82 | + } else { |
|
84 | 83 | $block_actions = $form_state['pm_block_user']['block_actions']; |
85 | 84 | } |
86 | 85 | // Work through each rule, adding it as a new element in |
@@ -160,8 +159,7 @@ discard block |
||
160 | 159 | PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'), |
161 | 160 | ); |
162 | 161 | $default_value = (isset($details['action']) ? $details['action'] : PM_BLOCK_USER_DISALLOW_BLOCKING); |
163 | - } |
|
164 | - else { |
|
162 | + } else { |
|
165 | 163 | // @todo: add whitelist options/default_value here. |
166 | 164 | } |
167 | 165 | $form['action'] = array( |
@@ -239,8 +237,7 @@ discard block |
||
239 | 237 | // builder. |
240 | 238 | if (isset($form_state['values']['block_actions'])) { |
241 | 239 | variable_set('pm_block_user_actions', _pm_block_user_settings_filter($form_state['values']['block_actions'])); |
242 | - } |
|
243 | - else { |
|
240 | + } else { |
|
244 | 241 | variable_set('pm_block_user_actions', array()); |
245 | 242 | } |
246 | 243 | drupal_set_message(t('The configuration options have been saved.')); |
@@ -272,8 +269,7 @@ discard block |
||
272 | 269 | } |
273 | 270 | if (count($matching) > 0) { |
274 | 271 | return $matching; |
275 | - } |
|
276 | - else { |
|
272 | + } else { |
|
277 | 273 | return array_map('_pm_block_user_settings_filter', $settings); |
278 | 274 | } |
279 | 275 | } |
@@ -463,8 +459,7 @@ discard block |
||
463 | 459 | t('Unblock @author', array('@author' => $author->name)), |
464 | 460 | t('Cancel') |
465 | 461 | ); |
466 | - } |
|
467 | - else { |
|
462 | + } else { |
|
468 | 463 | $form['block_action'] = array( |
469 | 464 | '#type' => 'value', |
470 | 465 | '#value' => 'block_user', |
@@ -564,8 +559,7 @@ discard block |
||
564 | 559 | if ($user->uid <> $author->uid) { |
565 | 560 | if ($vars['message']['is_blocked']) { |
566 | 561 | $vars['message_actions']['unblock_author'] = array('title' => t('Unblock author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
567 | - } |
|
568 | - else { |
|
562 | + } else { |
|
569 | 563 | $vars['message_actions']['block_author'] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author->uid, 'query' => 'destination=messages/view/' . $thread_id); |
570 | 564 | } |
571 | 565 | } |