1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Rules integration for the user module.
|
6
|
*
|
7
|
* @addtogroup rules
|
8
|
*
|
9
|
* @{
|
10
|
*/
|
11
|
|
12
|
/**
|
13
|
* Implements hook_rules_file_info() on behalf of the user module.
|
14
|
*/
|
15
|
function rules_user_file_info() {
|
16
|
return array('modules/user.eval');
|
17
|
}
|
18
|
|
19
|
/**
|
20
|
* Implements hook_rules_event_info().
|
21
|
*/
|
22
|
function rules_user_event_info() {
|
23
|
return array(
|
24
|
'user_insert' => array(
|
25
|
'label' => t('After saving a new user account'),
|
26
|
'group' => t('User'),
|
27
|
'variables' => array(
|
28
|
'account' => array('type' => 'user', 'label' => t('registered user')),
|
29
|
),
|
30
|
'access callback' => 'rules_user_integration_access',
|
31
|
),
|
32
|
'user_update' => array(
|
33
|
'label' => t('After updating an existing user account'),
|
34
|
'group' => t('User'),
|
35
|
'variables' => array(
|
36
|
'account' => array('type' => 'user', 'label' => t('updated user')),
|
37
|
'account_unchanged' => array('type' => 'user', 'label' => t('unchanged user'), 'handler' => 'rules_events_entity_unchanged'),
|
38
|
),
|
39
|
'access callback' => 'rules_user_integration_access',
|
40
|
),
|
41
|
'user_presave' => array(
|
42
|
'label' => t('Before saving a user account'),
|
43
|
'group' => t('User'),
|
44
|
'variables' => array(
|
45
|
'account' => array('type' => 'user', 'label' => t('saved user'), 'skip save' => TRUE),
|
46
|
'account_unchanged' => array('type' => 'user', 'label' => t('unchanged user'), 'handler' => 'rules_events_entity_unchanged'),
|
47
|
),
|
48
|
'access callback' => 'rules_user_integration_access',
|
49
|
),
|
50
|
'user_view' => array(
|
51
|
'label' => t('User account page is viewed'),
|
52
|
'group' => t('User'),
|
53
|
'variables' => array(
|
54
|
'account' => array('type' => 'user', 'label' => t('viewed user')),
|
55
|
'view_mode' => array(
|
56
|
'type' => 'text',
|
57
|
'label' => t('view mode'),
|
58
|
'options list' => 'rules_get_entity_view_modes',
|
59
|
// Add the entity-type for the options list callback.
|
60
|
'options list entity type' => 'user',
|
61
|
),
|
62
|
),
|
63
|
'access callback' => 'rules_user_integration_access',
|
64
|
'help' => t("Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache."),
|
65
|
),
|
66
|
'user_delete' => array(
|
67
|
'label' => t('After a user account has been deleted'),
|
68
|
'group' => t('User'),
|
69
|
'variables' => array(
|
70
|
'account' => array('type' => 'user', 'label' => t('deleted user')),
|
71
|
),
|
72
|
'access callback' => 'rules_user_integration_access',
|
73
|
),
|
74
|
'user_login' => array(
|
75
|
'label' => t('User has logged in'),
|
76
|
'group' => t('User'),
|
77
|
'variables' => array(
|
78
|
'account' => array('type' => 'user', 'label' => t('logged in user')),
|
79
|
),
|
80
|
'access callback' => 'rules_user_integration_access',
|
81
|
),
|
82
|
'user_logout' => array(
|
83
|
'label' => t('User has logged out'),
|
84
|
'group' => t('User'),
|
85
|
'variables' => array(
|
86
|
'account' => array('type' => 'user', 'label' => t('logged out user')),
|
87
|
),
|
88
|
'access callback' => 'rules_user_integration_access',
|
89
|
),
|
90
|
);
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Options list for user cancel methods.
|
95
|
*
|
96
|
* @todo Use for providing a user_cancel action.
|
97
|
*/
|
98
|
function rules_user_cancel_methods() {
|
99
|
module_load_include('inc', 'user', 'user.pages');
|
100
|
foreach (user_cancel_methods() as $method => $form) {
|
101
|
$methods[$method] = $form['#title'];
|
102
|
}
|
103
|
return $methods;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* User integration access callback.
|
108
|
*/
|
109
|
function rules_user_integration_access($type, $name) {
|
110
|
if ($type == 'event' || $type == 'condition') {
|
111
|
return entity_access('view', 'user');
|
112
|
}
|
113
|
// Else return admin access.
|
114
|
return user_access('administer users');
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Implements hook_rules_condition_info() on behalf of the user module.
|
119
|
*/
|
120
|
function rules_user_condition_info() {
|
121
|
return array(
|
122
|
'user_has_role' => array(
|
123
|
'label' => t('User has role(s)'),
|
124
|
'parameter' => array(
|
125
|
'account' => array('type' => 'user', 'label' => t('User')),
|
126
|
'roles' => array(
|
127
|
'type' => 'list<integer>',
|
128
|
'label' => t('Roles'),
|
129
|
'options list' => 'rules_user_roles_options_list',
|
130
|
),
|
131
|
'operation' => array(
|
132
|
'type' => 'text',
|
133
|
'label' => t('Match roles'),
|
134
|
'options list' => 'rules_user_condition_operations',
|
135
|
'restriction' => 'input',
|
136
|
'optional' => TRUE,
|
137
|
'default value' => 'AND',
|
138
|
'description' => t('If matching against all selected roles, the user must have <em>all</em> the roles selected.'),
|
139
|
),
|
140
|
),
|
141
|
'group' => t('User'),
|
142
|
'access callback' => 'rules_user_integration_access',
|
143
|
'base' => 'rules_condition_user_has_role',
|
144
|
),
|
145
|
'user_is_blocked' => array(
|
146
|
'label' => t('User is blocked'),
|
147
|
'parameter' => array(
|
148
|
'account' => array('type' => 'user', 'label' => t('User')),
|
149
|
),
|
150
|
'group' => t('User'),
|
151
|
'access callback' => 'rules_user_integration_access',
|
152
|
'base' => 'rules_condition_user_is_blocked',
|
153
|
),
|
154
|
);
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* User has role condition help callback.
|
159
|
*/
|
160
|
function rules_condition_user_has_role_help() {
|
161
|
return t('Whether the user has the selected role(s).');
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Options list callback for the operation parameter of condition user has role.
|
166
|
*/
|
167
|
function rules_user_condition_operations() {
|
168
|
return array(
|
169
|
'AND' => t('all'),
|
170
|
'OR' => t('any'),
|
171
|
);
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Implements hook_rules_action_info() on behalf of the user module.
|
176
|
*/
|
177
|
function rules_user_action_info() {
|
178
|
$defaults = array(
|
179
|
'parameter' => array(
|
180
|
'account' => array(
|
181
|
'type' => 'user',
|
182
|
'label' => t('User'),
|
183
|
'description' => t('The user whose roles should be changed.'),
|
184
|
'save' => TRUE,
|
185
|
),
|
186
|
'roles' => array(
|
187
|
'type' => 'list<integer>',
|
188
|
'label' => t('Roles'),
|
189
|
'options list' => 'rules_user_roles_options_list',
|
190
|
),
|
191
|
),
|
192
|
'group' => t('User'),
|
193
|
'access callback' => 'rules_user_role_change_access',
|
194
|
);
|
195
|
$items['user_add_role'] = $defaults + array(
|
196
|
'label' => t('Add user role'),
|
197
|
'base' => 'rules_action_user_add_role',
|
198
|
);
|
199
|
$items['user_remove_role'] = $defaults + array(
|
200
|
'label' => t('Remove user role'),
|
201
|
'base' => 'rules_action_user_remove_role',
|
202
|
);
|
203
|
$defaults = array(
|
204
|
'parameter' => array(
|
205
|
'account' => array(
|
206
|
'type' => 'user',
|
207
|
'label' => t('User'),
|
208
|
'save' => TRUE,
|
209
|
),
|
210
|
),
|
211
|
'group' => t('User'),
|
212
|
'access callback' => 'rules_user_integration_access',
|
213
|
);
|
214
|
$items['user_block'] = $defaults + array(
|
215
|
'label' => t('Block a user'),
|
216
|
'base' => 'rules_action_user_block',
|
217
|
);
|
218
|
$items['user_unblock'] = $defaults + array(
|
219
|
'label' => t('Unblock a user'),
|
220
|
'base' => 'rules_action_user_unblock',
|
221
|
);
|
222
|
$items['user_send_account_email'] = array(
|
223
|
'label' => t('Send account e-mail'),
|
224
|
'parameter' => array(
|
225
|
'account' => array(
|
226
|
'type' => 'user',
|
227
|
'label' => t('Account'),
|
228
|
),
|
229
|
'email_type' => array(
|
230
|
'type' => 'text',
|
231
|
'label' => t('E-mail type'),
|
232
|
'description' => t("Select the e-mail based on your site's account settings to send to the user."),
|
233
|
'options list' => 'rules_user_account_email_options_list',
|
234
|
),
|
235
|
),
|
236
|
'group' => t('User'),
|
237
|
'base' => 'rules_action_user_send_account_email',
|
238
|
'access callback' => 'rules_user_integration_access',
|
239
|
);
|
240
|
return $items;
|
241
|
}
|
242
|
|
243
|
/**
|
244
|
* User integration role actions access callback.
|
245
|
*/
|
246
|
function rules_user_role_change_access() {
|
247
|
return entity_metadata_user_roles() && user_access('administer permissions');
|
248
|
}
|
249
|
|
250
|
/**
|
251
|
* Options list callback for user roles.
|
252
|
*/
|
253
|
function rules_user_roles_options_list($element) {
|
254
|
return entity_metadata_user_roles('roles', array(), $element instanceof RulesConditionInterface ? 'view' : 'edit');
|
255
|
}
|
256
|
|
257
|
/**
|
258
|
* Options list callback for user account e-mail types.
|
259
|
*
|
260
|
* @see _user_mail_notify()
|
261
|
*/
|
262
|
function rules_user_account_email_options_list() {
|
263
|
return array(
|
264
|
'register_admin_created' => t('Welcome (new user created by administrator)'),
|
265
|
'register_no_approval_required' => t('Welcome (no approval required)'),
|
266
|
'register_pending_approval' => t('Welcome (awaiting approval)'),
|
267
|
'password_reset' => t('Password recovery'),
|
268
|
'status_activated' => t('Account activation'),
|
269
|
'status_blocked' => t('Account blocked'),
|
270
|
'cancel_confirm' => t('Account cancellation confirmation'),
|
271
|
'status_canceled' => t('Account canceled'),
|
272
|
);
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* @}
|
277
|
*/
|