Projet

Général

Profil

Paste
Télécharger (9,57 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / modules / system.rules.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Rules integration for the system module.
6
 *
7
 * @addtogroup rules
8
 *
9
 * @{
10
 */
11

    
12
/**
13
 * Implements hook_rules_file_info() on behalf of the system module.
14
 */
15
function rules_system_file_info() {
16
  return array('modules/system.eval');
17
}
18

    
19
/**
20
 * Implements hook_rules_event_info() on behalf of the system module.
21
 */
22
function rules_system_event_info() {
23
  return array(
24
    'init' => array(
25
      'label' => t('Drupal is initializing'),
26
      'group' => t('System'),
27
      'help' => t("Be aware that some actions might initialize the theme system. After that, it's impossible for any module to change the used theme."),
28
      'access callback' => 'rules_system_integration_access',
29
    ),
30
    'cron' => array(
31
      'label' => t('Cron maintenance tasks are performed'),
32
      'group' => t('System'),
33
      'access callback' => 'rules_system_integration_access',
34
    ),
35
    'watchdog' => array(
36
      'label' => t('System log entry is created'),
37
      'variables' => array(
38
        'log_entry' => array(
39
          'type' => 'log_entry',
40
          'label' => t('Log entry'),
41
        ),
42
      ),
43
      'group' => t('System'),
44
      'access callback' => 'rules_system_integration_access',
45
    ),
46
  );
47
}
48

    
49
/**
50
 * Implements hook_rules_data_info() on behalf of the system module.
51
 *
52
 * @see rules_core_modules()
53
 */
54
function rules_system_data_info() {
55
  return array(
56
    'log_entry' => array(
57
      'label' => t('watchdog log entry'),
58
      'wrap' => TRUE,
59
      'property info' => _rules_system_watchdog_log_entry_info(),
60
    ),
61
  );
62
}
63

    
64
/**
65
 * Defines property info for watchdog log entries.
66
 *
67
 * Used by the log entry data type to provide a useful metadata wrapper.
68
 */
69
function _rules_system_watchdog_log_entry_info() {
70
  return array(
71
    'type' => array(
72
      'type' => 'text',
73
      'label' => t('The category to which this message belongs'),
74
    ),
75
    'message' => array(
76
      'type' => 'text',
77
      'label' => ('Log message'),
78
      'getter callback' => 'rules_system_log_get_message',
79
      'sanitized' => TRUE,
80
    ),
81
    'severity' => array(
82
      'type' => 'integer',
83
      'label' => t('Severity'),
84
      'options list' => 'watchdog_severity_levels',
85
    ),
86
    'request_uri' => array(
87
      'type' => 'uri',
88
      'label' => t('Request uri'),
89
    ),
90
    'link' => array(
91
      'type' => 'text',
92
      'label' => t('An associated, HTML formatted link'),
93
    ),
94
  );
95
}
96

    
97
/**
98
 * Implements hook_rules_action_info() on behalf of the system module.
99
 */
100
function rules_system_action_info() {
101
  return array(
102
    'drupal_message' => array(
103
      'label' => t('Show a message on the site'),
104
      'group' => t('System'),
105
      'parameter' => array(
106
        'message' => array(
107
          'type' => 'text',
108
          'label' => t('Message'),
109
          'sanitize' => TRUE,
110
          'translatable' => TRUE,
111
        ),
112
        'type' => array(
113
          'type' => 'token',
114
          'label' => t('Message type'),
115
          'options list' => 'rules_action_drupal_message_types',
116
          'default value' => 'status',
117
          'optional' => TRUE,
118
        ),
119
        'repeat' => array(
120
          'type' => 'boolean',
121
          'label' => t('Repeat message'),
122
          'description' => t("If disabled and the message has been already shown, then the message won't be repeated."),
123
          'default value' => TRUE,
124
          'optional' => TRUE,
125
          'restriction' => 'input',
126
        ),
127
      ),
128
      'base' => 'rules_action_drupal_message',
129
      'access callback' => 'rules_system_integration_access',
130
    ),
131
    'redirect' => array(
132
      'label' => t('Page redirect'),
133
      'group' => t('System'),
134
      'parameter' => array(
135
        'url' => array(
136
          'type' => 'uri',
137
          'label' => t('URL'),
138
          'description' => t('A Drupal path, path alias, or external URL to redirect to. Enter (optional) queries after "?" and (optional) anchor after "#".'),
139
        ),
140
        'force' => array(
141
          'type' => 'boolean',
142
          'label' => t('Force redirect'),
143
          'restriction' => 'input',
144
          'description' => t("Force the redirect even if another destination parameter is present. Per default Drupal would redirect to the path given as destination parameter, in case it is set. Usually the destination parameter is set by appending it to the URL, e.g. !example_url", array('!example_url' => 'http://example.com/user/login?destination=node/2')),
145
          'optional' => TRUE,
146
          'default value' => TRUE,
147
        ),
148
        'destination' => array(
149
          'type' => 'boolean',
150
          'label' => t('Append destination parameter'),
151
          'restriction' => 'input',
152
          'description' => t('Whether to append a destination parameter to the URL, so another redirect issued later on would lead back to the origin page.'),
153
          'optional' => TRUE,
154
          'default value' => FALSE,
155
        ),
156
      ),
157
      'base' => 'rules_action_drupal_goto',
158
      'access callback' => 'rules_system_integration_access',
159
    ),
160
    'breadcrumb_set' => array(
161
      'label' => t('Set breadcrumb'),
162
      'group' => t('System'),
163
      'parameter' => array(
164
        'titles' => array(
165
          'type' => 'list<text>',
166
          'label' => t('Titles'),
167
          'description' => t('A list of titles for the breadcrumb links.'),
168
          'translatable' => TRUE,
169
        ),
170
        'paths' => array(
171
          'type' => 'list<text>',
172
          'label' => t('Paths'),
173
          'description' => t('A list of Drupal paths for the breadcrumb links, matching the order of the titles.'),
174
        ),
175
      ),
176
      'base' => 'rules_action_breadcrumb_set',
177
      'access callback' => 'rules_system_integration_access',
178
    ),
179
    'mail' => array(
180
      'label' => t('Send mail'),
181
      'group' => t('System'),
182
      'parameter' => array(
183
        'to' => array(
184
          'type' => 'text',
185
          'label' => t('To'),
186
          'description' => t('The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822.'),
187
        ),
188
        'subject' => array(
189
          'type' => 'text',
190
          'label' => t('Subject'),
191
          'description' => t("The mail's subject."),
192
          'translatable' => TRUE,
193
        ),
194
        'message' => array(
195
          'type' => 'text',
196
          'label' => t('Message'),
197
          'description' => t("The mail's message body."),
198
          'translatable' => TRUE,
199
        ),
200
        'from' => array(
201
          'type' => 'text',
202
          'label' => t('From'),
203
          'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
204
          'optional' => TRUE,
205
        ),
206
        'language' => array(
207
          'type' => 'token',
208
          'label' => t('Language'),
209
          'description' => t('If specified, the language used for getting the mail message and subject.'),
210
          'options list' => 'entity_metadata_language_list',
211
          'optional' => TRUE,
212
          'default value' => LANGUAGE_NONE,
213
          'default mode' => 'selector',
214
        ),
215
      ),
216
      'base' => 'rules_action_mail',
217
      'access callback' => 'rules_system_integration_access',
218
    ),
219
    'mail_to_users_of_role' => array(
220
      'label' => t('Send mail to all users of a role'),
221
      'group' => t('System'),
222
      'parameter' => array(
223
        'roles' => array(
224
          'type' => 'list<integer>',
225
          'label' => t('Roles'),
226
          'options list' => 'entity_metadata_user_roles',
227
          'description' => t('Select the roles whose users should receive the mail.'),
228
        ),
229
        'subject' => array(
230
          'type' => 'text',
231
          'label' => t('Subject'),
232
          'description' => t("The mail's subject."),
233
        ),
234
        'message' => array(
235
          'type' => 'text',
236
          'label' => t('Message'),
237
          'description' => t("The mail's message body."),
238
        ),
239
        'from' => array(
240
          'type' => 'text',
241
          'label' => t('From'),
242
          'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
243
          'optional' => TRUE,
244
        ),
245
      ),
246
      'base' => 'rules_action_mail_to_users_of_role',
247
      'access callback' => 'rules_system_integration_access',
248
    ),
249
    'block_ip' => array(
250
      'label' => t('Block IP address'),
251
      'group' => t('System'),
252
      'parameter' => array(
253
        'ip_address' => array(
254
          'type' => 'ip_address',
255
          'label' => t('IP address'),
256
          'description' => t('If not provided, the IP address of the current user will be used.'),
257
          'optional' => TRUE,
258
          'default value' => NULL,
259
        ),
260
      ),
261
      'base' => 'rules_action_block_ip',
262
      'access callback' => 'rules_system_integration_access',
263
    ),
264
  );
265
}
266

    
267
/**
268
 * Help callback for the "Send mail to users of a role" action.
269
 */
270
function rules_action_mail_to_users_of_role_help() {
271
  return t('WARNING: This may cause problems if there are too many users of these roles on your site, as your server may not be able to handle all the mail requests all at once.');
272
}
273

    
274
/**
275
 * System integration access callback.
276
 */
277
function rules_system_integration_access($type, $name) {
278
  return user_access('administer site configuration');
279
}
280

    
281
/**
282
 * Options list callback defining drupal_message types.
283
 */
284
function rules_action_drupal_message_types() {
285
  return array(
286
    'status' => t('Status'),
287
    'warning' => t('Warning'),
288
    'error' => t('Error'),
289
  );
290
}
291

    
292
/**
293
 * Implements hook_rules_evaluator_info() on behalf of the system module.
294
 */
295
function rules_system_evaluator_info() {
296
  return array(
297
    'token' => array(
298
      'class' => 'RulesTokenEvaluator',
299
      'type' => array('text', 'uri', 'list<text>', 'list<uri>'),
300
      'weight' => 0,
301
    ),
302
  );
303
}
304

    
305
/**
306
 * @}
307
 */