summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Gilliland2009-10-01 17:45:40 (GMT)
committer James Gilliland2009-10-01 17:45:40 (GMT)
commit6003c613958419837f767ca07d0a2d67b34caa5e (patch)
tree5ee3447c883d37dd1dad2f088ec18fe17a95c445
parent3a0051aa1062b7f3e5136d826e55c936c7ca9062 (diff)
Fix #170544 Move preprocess to module.
We need to move this to work aorund a bug in core. We don't get rid of the .theme.inc because of a "bug" in views.
-rw-r--r--export/views_bonus_export.module101
-rw-r--r--export/views_bonus_export.theme.inc110
2 files changed, 109 insertions, 102 deletions
diff --git a/export/views_bonus_export.module b/export/views_bonus_export.module
index 3ce4839..f9bc75a 100644
--- a/export/views_bonus_export.module
+++ b/export/views_bonus_export.module
@@ -55,3 +55,104 @@ function theme_views_bonus_export_feed_icon($image_path, $url, $query = '', $tex
return l($image, $url, $url_options);
}
+/**
+ * Preprocess csv output template.
+ */
+function template_preprocess_views_bonus_export_csv(&$vars) {
+ drupal_set_header('Content-type: text/csv; charset=utf-8');
+
+ // TODO Replace items with themed_rows.
+ _views_bonus_export_shared_preprocess($vars);
+
+ $vars['seperator'] = $vars['options']['seperator'];
+
+ // Special handling when quoted values are involved.
+ if ($vars['options']['quote']) {
+ $wrap = '"';
+ $replace_value = '""';
+ }
+ else {
+ $wrap = '';
+ $replace_value = '';
+ }
+
+ foreach ($vars['themed_rows'] as $i => $values) {
+ foreach ($values as $j => $value) {
+ $vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, decode_entities(strip_tags($value))) . $wrap;
+ }
+ }
+}
+
+/**
+ * Preprocess txt output template.
+ */
+function template_preprocess_views_bonus_export_txt(&$vars) {
+ drupal_set_header('Content-Type: text/plain');
+ _views_bonus_export_shared_preprocess($vars);
+}
+
+/**
+ * Preprocess doc output template.
+ */
+function template_preprocess_views_bonus_export_doc(&$vars) {
+ drupal_set_header('Content-Type: application/msword');
+ _views_bonus_export_shared_preprocess($vars);
+}
+
+/**
+ * Preprocess xml output template.
+ */
+function template_preprocess_views_bonus_export_xml(&$vars) {
+ drupal_set_header('Content-Type: text/xml');
+ if (!$vars['options']['provide_file']) {
+ unset($vars['options']['filename']);
+ }
+ _views_bonus_export_shared_preprocess($vars);
+
+ foreach ($vars['themed_rows'] as $num => $row) {
+ foreach ($row as $field => $content) {
+ $vars['themed_rows'][$num][$field] = str_replace(
+ array('&', '<', '>'),
+ array('&amp;', '&lt;', '&gt;'),
+ $content);
+ }
+ }
+}
+
+/**
+ * Shared helper function for export preprocess functions.
+ */
+function _views_bonus_export_shared_preprocess(&$vars) {
+ $view = $vars['view'];
+ $fields = &$view->field;
+
+ drupal_set_header('Cache-Control: max-age=60, must-revalidate');
+ $filename = strtr(
+ $vars['options']['filename'],
+ array('%view' => check_plain($view->name))
+ );
+ if ($filename) {
+ drupal_set_header('Content-Disposition: attachment; filename="'. $filename .'"');
+ }
+
+ $rows = $vars['rows'];
+
+ $vars['header'] = array();
+ foreach ($fields as $key => $field) {
+ if (empty($field->options['exclude'])) {
+ $vars['header'][$key] = check_plain($field->label());
+ }
+ }
+
+ $vars['themed_rows'] = array();
+ $keys = array_keys($fields);
+ foreach ($rows as $num => $row) {
+ $vars['themed_rows'][$num] = array();
+
+ foreach ($keys as $id) {
+ if (empty($fields[$id]->options['exclude'])) {
+ $vars['themed_rows'][$num][$id] = $fields[$id]->theme($row);
+ }
+ }
+ }
+}
diff --git a/export/views_bonus_export.theme.inc b/export/views_bonus_export.theme.inc
index 3cc9a97..a2fbfd9 100644
--- a/export/views_bonus_export.theme.inc
+++ b/export/views_bonus_export.theme.inc
@@ -3,106 +3,12 @@
/**
* @file
* Theme related functions for processing our output style plugins.
+ * Turns out that views basically requires you to have a theme include but
+ * Drupal isn't really all that consistent actually including it. Since we
+ * absolutely must have our preprocessing run the code has been moved to the
+ * main module file. However views still requires this file to exist or
+ * throws errors.
+ *
+ * Drupal bug: http://drupal.org/node/591804
+ * Views bug: http://drupal.org/node/593336
*/
-
-/**
- * Preprocess csv output template.
- */
-function template_preprocess_views_bonus_export_csv(&$vars) {
- drupal_set_header('Content-type: text/csv; charset=utf-8');
-
- // TODO Replace items with themed_rows.
- _views_bonus_export_shared_preprocess($vars);
-
- $vars['seperator'] = $vars['options']['seperator'];
-
- // Special handling when quoted values are involved.
- if ($vars['options']['quote']) {
- $wrap = '"';
- $replace_value = '""';
- }
- else {
- $wrap = '';
- $replace_value = '';
- }
-
- foreach ($vars['themed_rows'] as $i => $values) {
- foreach ($values as $j => $value) {
- $vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, decode_entities(strip_tags($value))) . $wrap;
- }
- }
-}
-
-/**
- * Preprocess txt output template.
- */
-function template_preprocess_views_bonus_export_txt(&$vars) {
- drupal_set_header('Content-Type: text/plain');
- _views_bonus_export_shared_preprocess($vars);
-}
-
-/**
- * Preprocess doc output template.
- */
-function template_preprocess_views_bonus_export_doc(&$vars) {
- drupal_set_header('Content-Type: application/msword');
- _views_bonus_export_shared_preprocess($vars);
-}
-
-/**
- * Preprocess xml output template.
- */
-function template_preprocess_views_bonus_export_xml(&$vars) {
- drupal_set_header('Content-Type: text/xml');
- if (!$vars['options']['provide_file']) {
- unset($vars['options']['filename']);
- }
- _views_bonus_export_shared_preprocess($vars);
-
- foreach ($vars['themed_rows'] as $num => $row) {
- foreach ($row as $field => $content) {
- $vars['themed_rows'][$num][$field] = str_replace(
- array('&', '<', '>'),
- array('&amp;', '&lt;', '&gt;'),
- $content);
- }
- }
-}
-
-/**
- * Shared helper function for export preprocess functions.
- */
-function _views_bonus_export_shared_preprocess(&$vars) {
- $view = $vars['view'];
- $fields = &$view->field;
-
- drupal_set_header('Cache-Control: max-age=60, must-revalidate');
- $filename = strtr(
- $vars['options']['filename'],
- array('%view' => check_plain($view->name))
- );
- if ($filename) {
- drupal_set_header('Content-Disposition: attachment; filename="'. $filename .'"');
- }
-
- $rows = $vars['rows'];
-
- $vars['header'] = array();
- foreach ($fields as $key => $field) {
- if (empty($field->options['exclude'])) {
- $vars['header'][$key] = check_plain($field->label());
- }
- }
-
- $vars['themed_rows'] = array();
- $keys = array_keys($fields);
- foreach ($rows as $num => $row) {
- $vars['themed_rows'][$num] = array();
-
- foreach ($keys as $id) {
- if (empty($fields[$id]->options['exclude'])) {
- $vars['themed_rows'][$num][$id] = $fields[$id]->theme($row);
- }
- }
- }
-}