Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* @file
* A plugin for transforming data in rules.
*/
/**
* Implements hook_rules_action_info().
*/
function rules_data_transforms_rules_action_info() {
$defaults = array(
'group' => t('Data Transforms'),
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
),
'provides' => array(
'output_text' => array(
'type' => 'text',
'label' => t('Output text'),
),
),
);
return array(
'uppercase' => array(
'label' => t('Make uppercase'),
'base' => 'rules_data_transforms_action_uppercase',
'provides' => array(
'uppercase_text' => array(
'type' => 'text',
'label' => t('Uppercase text'),
),
),
) + $defaults,
'lowercase' => array(
'label' => t('Make lowercase'),
'base' => 'rules_data_transforms_action_lowercase',
'provides' => array(
'lowercase_text' => array(
'type' => 'text',
'label' => t('Lowercase text'),
),
),
) + $defaults,
'capitalize' => array(
'label' => t('Capitalize first word of string'),
'base' => 'rules_data_transforms_action_capitalize',
'provides' => array(
'capitalize_text' => array(
'type' => 'text',
'label' => t('Capitalize first'),
),
),
) + $defaults,
'capitalizeall' => array(
'label' => t('Capitalize all words in a string'),
'base' => 'rules_data_transforms_action_capitalizeall',
'provides' => array(
'capitalizeall_text' => array(
'type' => 'text',
'label' => t('Capitalize all'),
),
),
) + $defaults,
'decode_html_entities' => array(
'label' => t('Decode HTML entities'),
'base' => 'rules_data_transforms_action_decode_html_entities',
'provides' => array(
'decoded_text' => array(
'type' => 'text',
'label' => t('Decoded text'),
),
),
) + $defaults,
'encode_html_entities' => array(
'label' => t('Encode HTML entities'),
'base' => 'rules_data_transforms_action_encode_html_entities',
'provides' => array(
'encoded_text' => array(
'type' => 'text',
'label' => t('Encoded text'),
),
),
) + $defaults,
'strtotime' => array(
'label' => t('String to time'),
'base' => 'rules_data_transforms_action_strtotime',
'provides' => array(
'parsed_date' => array(
'type' => 'text',
'label' => t('Date'),
),
),
) + $defaults,
'implode' => array(
'label' => t('Combine list into string'),
'base' => 'rules_data_transforms_action_implode',
'parameter' => array(
'input_list' => array(
'type' => 'list<text>',
'label' => t('Input list'),
),
'gluez' => array(
'type' => 'text',
'optional' => TRUE,
'label' => t('Glue text'),
),
),
'provides' => array(
'combined_text' => array(
'type' => 'text',
'label' => t('Combined text'),
),
),
) + $defaults,
'filter_elements' => array(
'label' => t('Filter empty elements from list'),
'base' => 'rules_data_transforms_action_filter_elements',
'parameter' => array(
'input_list' => array(
'type' => 'list<text>',
'label' => t('Input list'),
),
),
'provides' => array(
'filtered_list' => array(
'type' => 'list<text>',
'label' => t('Filtered list'),
),
),
) + $defaults,
'explode' => array(
'label' => t('Explode text'),
'base' => 'rules_data_transforms_action_explode',
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
'delimiter' => array(
'type' => 'text',
'label' => t('Delimiter'),
),
'limit' => array(
'type' => 'integer',
Maria Bodalova
committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'label' => t('Limit'),
'optional' => TRUE,
),
),
'provides' => array(
'output_list' => array(
'type' => 'list<text>',
'label' => t('Output list'),
),
),
) + $defaults,
'preg_split' => array(
'label' => t('Split text by a regular expression'),
'base' => 'rules_data_transforms_action_preg_split',
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
'pattern' => array(
'type' => 'text',
'label' => t('Pattern'),
'description' => t('For example write "[\n]" if you need split at line break.'),
),
'limit' => array(
'type' => 'integer',
'label' => t('Limit'),
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
'optional' => TRUE,
),
),
'provides' => array(
'output_list' => array(
'type' => 'list<text>',
'label' => t('Output list'),
),
),
) + $defaults,
'trim' => array(
'label' => t('Trim text'),
'base' => 'rules_data_transforms_action_trim',
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
'side' => array(
'type' => 'text',
'label' => t('Side'),
'options list' => '_rules_data_transforms_side_options',
'default value' => 'both',
),
'mask' => array(
'type' => 'text',
'label' => t('mask'),
'description' => t('Leave blank to remove all types of whitespace.'),
'optional' => TRUE,
),
),
'provides' => array(
'trimmed_text' => array(
'type' => 'text',
'label' => t('Trimmed text'),
),
),
) + $defaults,
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
'substr' => array(
'label' => t('Return part of a string'),
'base' => 'rules_data_transforms_action_substr',
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
'start' => array(
'type' => 'integer',
'label' => t('Start Position'),
'description' => t('See <a href="https://api.drupal.org/api/function/drupal_substr/" target="_blank">drupal_substr</a> for more information.'),
),
'length' => array(
'type' => 'integer',
'label' => t('Length'),
'description' => t('If length is omitted, the substring starting from start until the end of the string will be returned.'),
'optional' => TRUE,
),
),
'provides' => array(
'substr_text' => array(
'type' => 'text',
'label' => t('Substring'),
),
),
) + $defaults,
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
'strip_tags' => array(
'label' => t('Remove HTML tags'),
'base' => 'rules_data_transforms_action_strip_tags',
'parameter' => array(
'input_text' => array(
'type' => 'text',
'label' => t('Input text'),
),
'allowed' => array(
'type' => 'text',
'label' => t('Allowed tags'),
'optional' => TRUE,
),
),
'provides' => array(
'stripped_text' => array(
'type' => 'text',
'label' => t('Stripped text'),
),
),
) + $defaults,
'reverse_text' => array(
'label' => t('Reverse a text string'),
'base' => 'rules_data_transforms_action_reverse_text',
'provides' => array(
'reversed_text' => array(
'type' => 'text',
'label' => t('Reversed text'),
),
),
) + $defaults,
'reverse_list' => array(
'label' => t('Reverse a list'),
'base' => 'rules_data_transforms_action_reverse_list',
'parameter' => array(
'input_list' => array(
'type' => 'list',
'label' => t('Input list'),
),
),
'provides' => array(
'reversed_list' => array(
'type' => 'list',
'label' => t('Reversed list'),
),
),
'callbacks' => array(
'info_alter' => 'rules_data_transforms_action_list_info_alter',
),
) + $defaults,
'sort_list' => array(
'label' => t('Sort a list'),
'base' => 'rules_data_transforms_action_sort_list',
'parameter' => array(
'input_list' => array(
'type' => 'list',
'label' => t('Input list'),
),
'sort_order' => array(
'type' => 'text',
'label' => t('Sort order'),
'options list' => '_rules_data_transforms_sort_options',
'default value' => SORT_REGULAR,
),
),
'provides' => array(
'sorted_list' => array(
'type' => 'list',
'label' => t('Sorted list'),
),
),
'callbacks' => array(
'info_alter' => 'rules_data_transforms_action_list_info_alter',
),
) + $defaults,
'rsort_list' => array(
'label' => t('Reverse sort a list'),
'base' => 'rules_data_transforms_action_rsort_list',
'parameter' => array(
'input_list' => array(
'type' => 'list',
'label' => t('Input list'),
),
'sort_order' => array(
'type' => 'text',
'label' => t('Sort order'),
'options list' => '_rules_data_transforms_sort_options',
'default value' => SORT_REGULAR,
),
),
'provides' => array(
'reverse_sorted_list' => array(
'type' => 'list',
'label' => t('Reverse sorted list'),
),
),
'callbacks' => array(
'info_alter' => 'rules_data_transforms_action_list_info_alter',
),
) + $defaults,
'combine_lists' => array(
'label' => t('Combine two lists'),
'base' => 'rules_data_transforms_action_combine_lists',
'parameter' => array(
'input_list_1' => array(
'type' => 'list',
'label' => t('Input list 1'),
),
'input_list_2' => array(
'type' => 'list',
'label' => t('Input list 2'),
'description' => t('List 2 will be added to the end of list 1.'),
),
),
'provides' => array(
'combined_list' => array(
'type' => 'list',
'label' => t('Combined list'),
),
),
'callbacks' => array(
'info_alter' => 'rules_data_transforms_action_list_info_alter',
),
) + $defaults,
'permute_text' => array(
'label' => t('Get permutations of string'),
'base' => 'rules_data_transforms_action_permute_text',
'provides' => array(
'permutation_list' => array(
'type' => 'list<text>',
'label' => t('Permutation list'),
),
),
) + $defaults,
'fix_nbsp' => array(
'label' => t('Replace non break space character with space character'),
'base' => 'rules_data_transforms_action_fix_nbsp',
'provides' => array(
'nbsp_fixed_text' => array(
'type' => 'text',
'label' => t('Fixed text'),
),
),
) + $defaults,
Maxim Podorov
committed
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
'get_string_url_arg' => array(
'label' => t('Get string argument from URL'),
'base' => 'rules_data_transforms_get_string_url_arg',
'parameter' => array(
'number' => array(
'type' => 'integer',
'label' => t('Argument number'),
'description' => t('For the page @path use number @number to get @result as the result.', array('@path' => '"node/1000"', '@number' => '0', '@result' => '"node"')),
),
),
'provides' => array(
'arg' => array(
'type' => 'text',
'label' => t('Argument value as string'),
),
),
) + $defaults,
'get_integer_url_arg' => array(
'label' => t('Get integer argument from URL'),
'base' => 'rules_data_transforms_get_integer_url_arg',
'parameter' => array(
'number' => array(
'type' => 'integer',
'label' => t('Argument number'),
'description' => t('For the page @path use number @number to get @result as the result.', array('@path' => '"node/1000"', '@number' => '1', '@result' => '1000')),
),
),
'provides' => array(
'arg' => array(
'type' => 'integer',
'label' => t('Argument value as integer'),
),
),
) + $defaults,
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
);
}
function rules_data_transforms_action_uppercase($input_text) {
return array('uppercase_text' => drupal_strtoupper($input_text));
}
function rules_data_transforms_action_capitalize($input_text) {
return array('capitalize_text' => drupal_ucfirst($input_text));
}
function rules_data_transforms_action_capitalizeall($input_text) {
return array('capitalizeall_text' => preg_replace('/\b(\w)/e', 'drupal_strtoupper("$1")', $input_text));
}
function rules_data_transforms_action_lowercase($input_text) {
return array('lowercase_text' => drupal_strtolower($input_text));
}
function rules_data_transforms_action_decode_html_entities($input_text) {
return array('decoded_text' => decode_entities($input_text));
}
function rules_data_transforms_action_encode_html_entities($input_text) {
return array('encoded_text' => check_plain($input_text));
}
function rules_data_transforms_action_strtotime($input_text) {
return array('parsed_date' => strtotime($input_text));
}
function rules_data_transforms_action_implode($input_list, $glue) {
return array('combined_text' => is_array($input_list) ? implode($glue, $input_list) : '');
}
function rules_data_transforms_action_explode($input_text, $delimiter, $limit) {
if (isset($limit)) {
return array('output_list' => explode($delimiter, $input_text, $limit));
}
return array('output_list' => explode($delimiter, $input_text));
}
Maria Bodalova
committed
function rules_data_transforms_action_preg_split($input_text, $pattern, $limit) {
return array(
'output_list' => isset($limit) ? preg_split('/' . $pattern . '/', $input_text, $limit) : preg_split('/' . $pattern . '/', $input_text),
);
}
function _rules_data_transforms_side_options() {
return array('left' => t('Left'), 'right' => t('Right'), 'both' => t('Both'));
}
function rules_data_transforms_action_trim($input_text, $side, $mask) {
switch ($side) {
case 'left':
$func = 'ltrim';
break;
case 'right':
$func = 'rtrim';
break;
}
if (isset($mask)) {
return array('trimmed_text' => $func($input_text, $mask));
}
return array('trimmed_text' => $func($input_text));
}
function rules_data_transforms_action_substr($input_text, $start, $length) {
return array('substr_text' => drupal_substr($input_text, $start, $length));
}
function rules_data_transforms_action_strip_tags($input_text, $allowed) {
if (isset($allowed)) {
return array('stripped_text' => strip_tags($input_text, $allowed));
}
return array('stripped_text' => strip_tags($input_text));
}
function rules_data_transforms_action_reverse_text($input_text) {
return array('reversed_text' => strrev($input_text));
}
function rules_data_transforms_action_list_info_alter(&$element_info, $element) {
$info = $element->getArgumentInfo('input_list');
if ($output['type'] == 'list') {
$output['type'] = $info['type'];
}
}
// $element_info['provides']['reversed_list']['type'] = $info['type'];
}
function rules_data_transforms_action_reverse_list($input_list) {
return array('reversed_list' => is_array($input_list) ? array_reverse($input_list) : '');
}
function _rules_data_transforms_sort_options() {
return array(
SORT_REGULAR => t('Regular'),
SORT_NUMERIC => t('Numeric'),
SORT_STRING => t('String'),
SORT_LOCALE_STRING => t('Locale'),
);
}
function rules_data_transforms_action_sort_list($input_list, $sort) {
if (is_array($input_list)) {
sort($input_list, $sort);
return array('sorted_list' => $input_list);
}
}
function rules_data_transforms_action_rsort_list($input_list, $sort) {
if (is_array($input_list)) {
rsort($input_list, $sort);
return array('reverse_sorted_list' => $input_list);
}
}
function rules_data_transforms_action_combine_lists($input_list_1, $input_list_2) {
if (is_array($input_list_1) && is_array($input_list_2)) {
foreach ($input_list_2 as $i) {
$input_list_1[] = $i;
}
return array('combined_list' => $input_list_1);
}
function rules_data_transforms_action_filter_elements($input_list) {
return array('filtered_list' => array_filter($input_list));
}
function _rules_data_transforms_permute($string) {
if (drupal_strlen($string) < 2) {
return array($string);
}
$permutations = array();
$tail = drupal_substr($string, 1);
foreach (_rules_data_transforms_permute($tail) as $permutation) {
$length = drupal_strlen($permutation);
for ($i = 0; $i <= $length; $i++) {
$permutations[] = drupal_substr($permutation, 0, $i) . $string[0] . drupal_substr($permutation, $i);
}
}
return $permutations;
}
function rules_data_transforms_action_permute_text($input_text) {
return array('permutation_list' => array_unique(_rules_data_transforms_permute($input_text)));
}
function rules_data_transforms_action_fix_nbsp($input_text) {
return array('nbsp_fixed_text' => preg_replace("/\xC2\xA0/", ' ', $input_text));
}
Maxim Podorov
committed
function rules_data_transforms_get_string_url_arg($number) {
return array('arg' => arg($number));
}
function rules_data_transforms_get_integer_url_arg($number) {
return array('arg' => intval(arg($number)));
}