Projet

Général

Profil

Paste
Télécharger (4,71 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_data_export / plugins / views_data_export_plugin_style_export_csv.inc @ a2bb1a14

1
<?php
2
/**
3
 * @file
4
 * Plugin include file for export style plugin.
5
 */
6

    
7
/**
8
 * Generalized style plugin for export plugins.
9
 *
10
 * @ingroup views_style_plugins
11
 */
12
class views_data_export_plugin_style_export_csv extends views_data_export_plugin_style_export {
13

    
14
  /**
15
   * Set options fields and default values.
16
   *
17
   * @return
18
   * An array of options information.
19
   */
20
  function option_definition() {
21
    $options = parent::option_definition();
22

    
23
    $options['separator'] = array(
24
      'default' => ',',
25
      'translatable' => TRUE,
26
    );
27
    $options['quote'] = array(
28
      'default' => TRUE,
29
      'translatable' => TRUE,
30
    );
31
    $options['trim'] = array(
32
      'default' => FALSE,
33
      'translatable' => FALSE,
34
    );
35
    $options['replace_newlines'] = array(
36
      'default' => FALSE,
37
      'translatable' => FALSE,
38
    );
39
    $options['newline_replacement'] = array(
40
      'default' => ', ',
41
      'translatable' => FALSE,
42
    );
43
    $options['newline_token'] = array(
44
      'default' => 1,
45
      'translatable' => FALSE,
46
    );
47
    $options['header'] = array(
48
      'default' => TRUE,
49
      'translatable' => FALSE,
50
    );
51
    $options['keep_html'] = array(
52
      'default' => FALSE,
53
      'translatable' => FALSE,
54
    );
55
    $options['encoding'] = array(
56
      'default' => '',
57
      'translatable' => FALSE,
58
    );
59

    
60
    return $options;
61
  }
62

    
63
  /**
64
   * Options form mini callback.
65
   *
66
   * @param $form
67
   * Form array to add additional fields to.
68
   * @param $form_state
69
   * State of the form.
70
   * @return
71
   * None.
72
   */
73
  function options_form(&$form, &$form_state) {
74
    parent::options_form($form, $form_state);
75

    
76
    $form['separator'] = array(
77
      '#type' => 'textfield',
78
      '#title' => t('Separator'),
79
      '#default_value' => !empty($this->options['separator']) ? $this->options['separator'] : ',',
80
      '#description' => t('This is the separator that is used to separate fields. CSV implies comma separated fields so this should not be changed unless you have specific requirements'),
81
    );
82
    $form['quote'] = array(
83
      '#type' => 'checkbox',
84
      '#default_value' => !empty($this->options['quote']),
85
      '#title' => t('Quote values. Useful for output that might contain your separator as part of one of the values.'),
86
    );
87
    $form['trim'] = array(
88
      '#type' => 'checkbox',
89
      '#default_value' => !empty($this->options['trim']),
90
      '#title' => t('Trim whitespace from rendered fields. Can be useful for some themes where output results in extra newlines.'),
91
    );
92
    $form['replace_newlines'] = array(
93
      '#type' => 'checkbox',
94
      '#default_value' => !empty($this->options['replace_newlines']),
95
      '#title' => t('Replace newlines in rendered fields.'),
96
    );
97
    $form['newline_replacement'] = array(
98
      '#prefix' => '<div><div id="edit-options-newline-replacement">',
99
      '#suffix' => '</div></div>',
100
      '#type' => 'textfield',
101
      '#title' => t('Replacement'),
102
      '#default_value' => $this->options['newline_replacement'],
103
      '#process' => array('ctools_dependent_process'),
104
      '#dependency' => array('edit-style-options-replace-newlines' => array(TRUE)),
105
    );
106
    $form['newline_token'] = array(
107
      '#prefix' => '<div><div id="edit-options-newline-token">',
108
      '#suffix' => '</div></div>',
109
      '#type' => 'radios',
110
      '#default_value' => !empty($this->options['newline_token']) ? $this->options['newline_token'] : '0',
111
      '#title' => t('What to replace?'),
112
      '#options' => array(
113
          t('Replace only Linefeed ("\n")'),
114
          t('Replace Carriage Return plus Linefeed ("\r\n") and single Linefeed ("\n") as well')
115
       ),
116
       '#dependency' => array('edit-style-options-replace-newlines' => array(TRUE)),
117
     );
118
    $form['header'] = array(
119
      '#type' => 'checkbox',
120
      '#title' => t('Make first row a list of column headers.'),
121
      '#default_value' => !empty($this->options['header']),
122
    );
123
    $form['keep_html'] = array(
124
      '#type' => 'checkbox',
125
      '#default_value' => !empty($this->options['keep_html']),
126
      '#title' => t('Keep HTML tags.'),
127
    );
128
    $form['encoding'] = array(
129
      '#type' => 'textfield',
130
      '#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
131
      '#title' => t('Character encoding conversion'),
132
      '#description' => t('Optionally specify a character conversion that some CSV file readers need. Use "utf8_decode" for ISO-8859-1 via <a href="@utf8_decode">utf8_decode PHP function</a>, other values will be passed <a href="@iconv">iconv</a> (this requires the iconv PHP extension), empty or illegal values will leave the output as UTF-8.',
133
        array('@iconv' => 'http://www.php.net/manual/en/function.iconv.php', '@utf8_decode' => 'http://www.php.net/manual/en/function.utf8-decode.php')),
134
    );
135
  }
136
}