1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Remove text or whitespace from the beginning, middle, or both sides of text.
|
6
|
*/
|
7
|
|
8
|
$plugin = array(
|
9
|
'form' => 'feeds_tamper_trim_form',
|
10
|
'callback' => 'feeds_tamper_trim_callback',
|
11
|
'name' => 'Trim',
|
12
|
'multi' => 'loop',
|
13
|
'category' => 'Text',
|
14
|
);
|
15
|
|
16
|
function feeds_tamper_trim_form($importer, $element_key, $settings) {
|
17
|
$form = array();
|
18
|
$form['mask'] = array(
|
19
|
'#type' => 'textfield',
|
20
|
'#title' => t('Characters to trim'),
|
21
|
'#default_value' => isset($settings['mask']) ? $settings['mask'] : '',
|
22
|
'#description' => t('The characters to remove from the string. If blank, then whitespace will be removed.'),
|
23
|
);
|
24
|
$form['side'] = array(
|
25
|
'#type' => 'radios',
|
26
|
'#title' => t('Side'),
|
27
|
'#default_value' => isset($settings['side']) ? $settings['side'] : 'trim',
|
28
|
'#options' => array('trim' => t('Both'), 'ltrim' => t('Left'), 'rtrim' => t('Right')),
|
29
|
);
|
30
|
return $form;
|
31
|
}
|
32
|
|
33
|
function feeds_tamper_trim_callback($result, $item_key, $element_key, &$field, $settings, $source) {
|
34
|
if (!empty($settings['mask'])) {
|
35
|
$field = $settings['side']($field, $settings['mask']);
|
36
|
}
|
37
|
else {
|
38
|
$field = $settings['side']($field);
|
39
|
}
|
40
|
}
|