Projet

Général

Profil

Paste
Télécharger (1,35 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds_tamper / plugins / encode.inc @ d808fa20

1
<?php
2

    
3
/**
4
 * @file
5
 * Encode and Decode a text with a set of defined functions.
6
 */
7

    
8
$plugin = array(
9
  'form' => 'feeds_tamper_encode_form',
10
  'callback' => 'feeds_tamper_encode_callback',
11
  'name' => 'Encode/Decode Plugin',
12
  'multi' => 'direct',
13
  'category' => 'Text',
14
);
15

    
16
/**
17
 * Form callback for the 'encode' plugin.
18
 */
19
function feeds_tamper_encode_form($importer, $element_key, $settings) {
20
  $form = array();
21

    
22
  $form['help']['#value'] = t('Encode (or Decode) the field contents.');
23

    
24
  $form['mode'] = array(
25
    '#title' => t('Serialization mode:'),
26
    '#description' => t('Serialization/Encoding mode'),
27
    '#type' => 'radios',
28
    '#options' => array(
29
      'serialize' => t('PHP Serialize'),
30
      'unserialize' => t('PHP Unserialize'),
31
      'json_encode' => t('Json Encode'),
32
      'json_decode' => t('Json Decode'),
33
      'base64_encode' => t('Base64 Encode'),
34
      'base64_decode' => t('Base64 Decode'),
35
    ),
36
    '#default_value' => isset($settings['mode']) ? $settings['mode'] : 'serialize',
37
  );
38

    
39
  return $form;
40
}
41

    
42
/**
43
 * Callback for the 'encode' plugin.
44
 */
45
function feeds_tamper_encode_callback($source, $item_key, $element_key, &$field, array $settings) {
46
  if (empty($settings['mode'])) {
47
    $settings['mode'] = 'serialize';
48
  }
49

    
50
  $function = $settings['mode'];
51

    
52
  if (function_exists($function)) {
53
    $field = call_user_func($function, $field);
54
  }
55
}