diff --git a/plugins/views_data_export_plugin_style_export_xml.inc b/plugins/views_data_export_plugin_style_export_xml.inc index f4bade7..fa761bf 100644 --- a/plugins/views_data_export_plugin_style_export_xml.inc +++ b/plugins/views_data_export_plugin_style_export_xml.inc @@ -32,6 +32,10 @@ class views_data_export_plugin_style_export_xml extends views_data_export_plugin 'default' => FALSE, 'translatable' => FALSE, ); + $options['no_entity_encode'] = array( + 'default' => array(), + 'translatable' => FALSE, + ); return $options; } @@ -75,5 +79,40 @@ class views_data_export_plugin_style_export_xml extends views_data_export_plugin '#title' => t('Wrap fields content with CDATA'), '#default_value' => $this->options['cdata'], ); + + $field_labels = $this->display->handler->get_field_labels(); + + if (!empty($field_labels)) { + $options = $field_labels; + if (empty($this->options['no_entity_encode'])) { + $this->options['no_entity_encode'] = array(); + } + + $form['no_entity_encode'] = array( + '#type' => 'checkboxes', + '#title' => t('Disable encoding of XML entities for these fields'), + '#options' => $options, + '#default_value' => $this->options['no_entity_encode'], + '#description' => t('If checked field contents will be outputted '. + 'without encoding of XML entities. This is '. + 'useful when when used in conjunction with a field '. + 'formatter that outputs properly formatted and '. + 'encoded XML data.'), + ); + } + } + + /** + + * 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']['no_entity_encode'])) { + // Remove any options values set to 0 + $form_state['values']['style_options']['no_entity_encode'] = array_filter($form_state['values']['style_options']['no_entity_encode']); + } } } diff --git a/theme/views_data_export.theme.inc b/theme/views_data_export.theme.inc index e590b24..8eb4937 100644 --- a/theme/views_data_export.theme.inc +++ b/theme/views_data_export.theme.inc @@ -41,7 +41,7 @@ function theme_views_data_export_message($var) { */ function theme_views_data_export_feed_icon($variables) { extract($variables, EXTR_SKIP); - $url_options = array('html' => true); + $url_options = array('html' => TRUE); if ($query) { $url_options['query'] = $query; } @@ -127,6 +127,10 @@ function template_preprocess_views_data_export_csv_header(&$vars) { function template_preprocess_views_data_export_csv_body(&$vars) { _views_data_export_body_shared_preprocess($vars); + $view = $vars['view']; + $style_options = $view->display_handler->get_option('style_options'); + $no_encode = isset($style_options['no_entity_encode']) ? $style_options['no_entity_encode'] : array(); + // Make sure we catch saved options that are misspelled. LEGACY if (isset($vars['options']['seperator'])) { $vars['options']['separator'] = $vars['options']['seperator']; @@ -148,23 +152,26 @@ function template_preprocess_views_data_export_csv_body(&$vars) { // Format row values. foreach ($vars['themed_rows'] as $i => $values) { foreach ($values as $j => $value) { - $output = decode_entities(strip_tags($value)); - if (!empty($vars['options']['trim'])) { - $output = trim($output); - } + // Perform xml entity encoding unless excluded by style options. + if (empty($no_encode[$field])) { + $output = decode_entities(strip_tags($value)); + if (!empty($vars['options']['trim'])) { + $output = trim($output); + } - if (!empty($vars['options']['encoding']) && function_exists('iconv')) { - switch($vars['options']['encoding']) { - case 'ASCII': - $converted = iconv("UTF-8", "ASCII//TRANSLIT", $output); - if ($converted !== FALSE) { - $output = $converted; - } - break; + if (!empty($vars['options']['encoding']) && function_exists('iconv')) { + switch ($vars['options']['encoding']) { + case 'ASCII': + $converted = iconv("UTF-8", "ASCII//TRANSLIT", $output); + if ($converted !== FALSE) { + $output = $converted; + } + break; + } + } + if (!empty($vars['options']['replace_newlines'])) { + $output = str_replace("\n", $vars['options']['newline_replacement'], $output); } - } - if (!empty($vars['options']['replace_newlines'])) { - $output = str_replace("\n", $vars['options']['newline_replacement'], $output); } $vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, $output) . $wrap; } @@ -373,23 +380,31 @@ function template_preprocess_views_data_export_xml_body(&$vars) { _views_data_export_header_shared_preprocess($vars); _views_data_export_body_shared_preprocess($vars); + $view = $vars['view']; + $style_options = $view->display_handler->get_option('style_options'); + $no_encode = isset($style_options['no_entity_encode']) ? $style_options['no_entity_encode'] : array(); + // Compute the tag name based on the views base table, minus any trailing 's'. $vars['item_node'] = _views_data_export_xml_tag_clean(rtrim($vars['view']->base_table, 's')); foreach ($vars['themed_rows'] as $num => $row) { foreach ($row as $field => $content) { - if (empty($vars['options']['cdata'])) { - // 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) . ']]>'; + + // Perform xml entity encoding unless excluded by style options. + if (empty($no_encode[$field])) { + if (empty($vars['options']['cdata'])) { + // 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; }