1 |
7b9e8704
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Convert text to upper, lower, or title case.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'form' => 'feeds_tamper_convert_case_form',
|
10 |
|
|
'callback' => 'feeds_tamper_convert_case_callback',
|
11 |
|
|
'name' => 'Convert case',
|
12 |
|
|
'multi' => 'loop',
|
13 |
|
|
'category' => 'Text',
|
14 |
|
|
);
|
15 |
|
|
|
16 |
|
|
function feeds_tamper_convert_case_form($importer, $element_key, $settings) {
|
17 |
|
|
$form = array();
|
18 |
|
|
$form['mode'] = array(
|
19 |
|
|
'#type' => 'radios',
|
20 |
|
|
'#title' => t('How to convert case'),
|
21 |
|
|
'#default_value' => isset($settings['mode']) ? $settings['mode'] : MB_CASE_TITLE,
|
22 |
|
|
'#options' => array(
|
23 |
|
|
MB_CASE_TITLE => t('Title Case'),
|
24 |
|
|
MB_CASE_LOWER => t('lower case'),
|
25 |
|
|
MB_CASE_UPPER => t('UPPER CASE'),
|
26 |
|
|
'ucfirst' => t('Sentence case'),
|
27 |
|
|
),
|
28 |
|
|
);
|
29 |
|
|
return $form;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
function feeds_tamper_convert_case_callback($result, $item_key, $element_key, &$field, $settings, $source) {
|
33 |
|
|
if ($settings['mode'] === 'ucfirst') {
|
34 |
|
|
$field = mb_strtoupper(mb_substr($field, 0, 1, 'UTF-8'), 'UTF-8') . mb_strtolower(mb_substr($field, 1, mb_strlen($field, 'UTF-8'), 'UTF-8'));
|
35 |
|
|
}
|
36 |
|
|
else {
|
37 |
|
|
$field = mb_convert_case($field, $settings['mode'], 'UTF-8');
|
38 |
|
|
}
|
39 |
|
|
} |