diff --git a/plugins/views_data_export_plugin_style_export_xml.inc b/plugins/views_data_export_plugin_style_export_xml.inc index 415537d..64c242b 100644 --- a/plugins/views_data_export_plugin_style_export_xml.inc +++ b/plugins/views_data_export_plugin_style_export_xml.inc @@ -57,6 +57,11 @@ class views_data_export_plugin_style_export_xml extends views_data_export_plugin 'translatable' => FALSE, ); + $options['cdata_wrapper'] = array( + 'default' => array(), + 'translatable' => FALSE, + ); + return $options; } @@ -106,5 +111,37 @@ class views_data_export_plugin_style_export_xml extends views_data_export_plugin '#default_value' => $this->options['item_node'], '#description' => t('The XML tag for an item node.'), ); + + $field_labels = $this->display->handler->get_field_labels(); + + if (!empty($field_labels)) { + $options = $field_labels; + + if (empty($this->options['cdata_wrapper'])) { + $this->options['cdata_wrapper'] = array(); + } + + $form['cdata_wrapper'] = array( + '#type' => 'checkboxes', + '#title' => t('Fields value to wrapped using CDATA'), + '#options' => $options, + '#default_value' => $this->options['cdata_wrapper'], + '#description' => t('If checked the fields content will be wrapped using the CDATA tag.'), + ); + } + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + * + * @param $form + * @param $form_state + */ + function options_submit(&$form, &$form_state) { + if (isset($form_state['values']['style_options']['cdata_wrapper'])) { + // Remove any options values set to 0 + $form_state['values']['style_options']['cdata_wrapper'] = array_filter($form_state['values']['style_options']['cdata_wrapper']); + } } } diff --git a/theme/views_data_export.theme.inc b/theme/views_data_export.theme.inc index a1af339..873e3f1 100644 --- a/theme/views_data_export.theme.inc +++ b/theme/views_data_export.theme.inc @@ -371,13 +371,19 @@ function template_preprocess_views_data_export_xml_body(&$vars) { foreach ($vars['themed_rows'] as $num => $row) { foreach ($row as $field => $content) { - // Prevent double encoding of the ampersand. Look for the entities produced by check_plain(). - $content = preg_replace('/&(?!(amp|quot|#039|lt|gt);)/', '&', $content); - // Convert < and > to HTML entities. - $content = str_replace( - array('<', '>'), - array('<', '>'), - $content); + if (empty($vars['options']['cdata_wrapper'][$field])) { + // Prevent double encoding of the ampersand. Look for the entities produced by check_plain(). + $content = preg_replace('/&(?!(amp|quot|#039|lt|gt);)/', '&', $content); + // Convert < and > to HTML entities. + $content = str_replace( + array('<', '>'), + array('<', '>'), + $content); + } + else { + // Escape CDATA end sequence only. + $content = '', ']]]]>', $content) . ']]>'; + } $vars['themed_rows'][$num][$field] = $content; } }